Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JCalibrateNB.cc
Go to the documentation of this file.
1 #include <iostream>
2 
3 #include "JDAQ/JDAQEventIO.hh"
4 #include "Jeep/JParser.hh"
5 #include "JSupport/JSupport.hh"
8 #include "JTrigger/JHitL0.hh"
9 #include "JTrigger/JBuildL0.hh"
10 #include "JDetector/JDetector.hh"
13 #include "JROOT/JManager.hh"
14 #include "JPhysics/JDispersion.hh"
15 #include "JTrigger/JPMTSelector.hh"
16 #include "JTools/JCombinatorics.hh"
17 #include "JMath/JMathToolkit.hh"
18 
19 #include "JNanobeacon.hh"
20 
21 #include "TH1.h"
22 #include "TH2.h"
23 #include "TFile.h"
24 
25 using namespace std;
26 using namespace JPP;
27 using namespace JDETECTOR;
28 using namespace KM3NETDAQ;
29 using namespace JNANOBEACON;
30 
31 int main(int argc , char** argv){
32 
34  JLimit_t& numberOfEvents = inputFiles.getLimit();
35  string detectorFile;
36  string outFile;
38  double depth;
39  double wavelength;
40  JPMTSelector selector;
41  JPMTSelector default_pmts;
42 
43  default_pmts.push_back(JPMTIdentifier_t(-1,0));
44  default_pmts.push_back(JPMTIdentifier_t(-1,3));
45  default_pmts.push_back(JPMTIdentifier_t(-1,4));
46 
47  try {
48 
49  JParser<> zap;
50 
51  zap['f'] = make_field(inputFiles );
52  zap['a'] = make_field(detectorFile );
53  zap['n'] = make_field(numberOfEvents ) = JLimit::max();
54  zap['o'] = make_field(outFile ) = "out.root";
55  zap['h'] = make_field(depth , "detector depth [m]" ) = 2500.0;
56  zap['l'] = make_field(wavelength , "LED wavelength [nm]") = 400.0;
57  zap['T'] = make_field(selector ) = default_pmts; // for example '-1 0 -1 3 -1 4', to select PMTs 0, 3 and 4 on every DOM
58 
59  zap(argc,argv);
60  }
61  catch(const exception &error) {
62  ERROR(error.what() << endl);
63  }
64 
65  typedef JHitL0 JHit_t;
66  typedef vector<JHit_t> JHitBuffer;
67 
68  JBuildL0<JHit_t> builder;
69 
70  JHitBuffer triggerBuffer;
71  JHitBuffer snapshotBuffer;
72 
73  load(detectorFile , detector);
74 
75  JModuleRouter moduleRouter(detector);
76 
77  JDispersion jd (0.1 * depth);
78 
79  double cw = getSpeedOfLight() / jd.getIndexOfRefractionGroup(wavelength);
80 
81  int num_of_floors = getNumberOfFloors(detector);
82  JCombinatorics c(num_of_floors);
83  int npairs = c.getNumberOfPairs();
85 
86  JManager < int, TH2D >* timeDifferences;
87  timeDifferences = new JManager < int, TH2D > ( new TH2D("%", "", npairs, 0.5, npairs+0.5, 501, -250.5, 250.5) );
88 
89  while(inputFiles.hasNext()){
90 
91  JDAQEvent* event = inputFiles.next();
92 
93  triggerBuffer .clear();
94  snapshotBuffer.clear();
95 
96  builder(*event, moduleRouter, true , back_inserter(snapshotBuffer));
97  builder(*event, moduleRouter, false , back_inserter( triggerBuffer));
98 
99  JHitBuffer::iterator __end = partition(triggerBuffer.begin(), triggerBuffer.end(), selector);
100  if(triggerBuffer.begin() != __end){
101 
102  sort(triggerBuffer.begin(), __end, less<JHit>());
103  JHitBuffer::iterator triggeredHit = triggerBuffer.begin();
104 
105  if( moduleRouter.hasModule( triggeredHit -> getModuleID() ) ){
106  const JModule& triggeredModule = moduleRouter.getModule( triggeredHit -> getModuleID() );
107 
108  for(JHitBuffer::const_iterator snapshotHit = snapshotBuffer.begin(); snapshotHit != snapshotBuffer.end(); ++snapshotHit){
109 
110  if( moduleRouter.hasModule( snapshotHit -> getModuleID() ) ){
111  const JModule& snapshotModule = moduleRouter.getModule( snapshotHit -> getModuleID() );
112 
113  if( triggeredModule.getString() == snapshotModule.getString() ){
114 
115  //double ToF = triggeredHit->getDistance(*snapshotHit) / cw;
116  double Dt = snapshotHit->getT() - triggeredHit->getT();
117  double ToF = getDistance( triggeredHit->getPosition(), snapshotHit->getPosition() ) / cw;
118  //indexes are pairs running from 0-17 between 0-152, while floors are 1-18 and bins are 1-153
119  int xbin = c.getIndex( triggeredModule.getFloor()-1 , snapshotModule.getFloor()-1 ) + 1;
120  if( triggeredModule.getFloor() < snapshotModule.getFloor() ){
121  (*timeDifferences)[triggeredModule.getString()]->Fill(xbin,Dt-ToF);
122  }
123  }
124  } else {
125  FATAL("JModuleRouter trying to access non existing identifier: " << snapshotHit->getModuleID() );
126  }
127  }
128 
129  } else {
130  FATAL("JModuleRouter trying to access non existing identifier: " << triggeredHit->getModuleID() );
131  }
132  }
133  }
134  TFile output(outFile.c_str() , "recreate") ;
135  timeDifferences -> Write(output);
136 }
Auxiliary class to set-up Hit.
Definition: JHit_t.hh:25
Utility class to parse command line options.
Definition: JParser.hh:1500
Auxiliary class to convert pair of indices to unique index and back.
ROOT TTree parameter settings of various packages.
Auxiliary methods for geometrical methods.
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition: JModule.hh:57
Depth.
Definition: JHead.hh:891
Detector data structure.
Definition: JDetector.hh:80
Implementation of dispersion for water in deep sea.
Definition: JDispersion.hh:26
Router for direct addressing of module data in detector data structure.
Dynamic ROOT object management.
Data structure for detector geometry and calibration.
void sort(JComparator_t comparator)
Sort address pairs.
double getDistance(const JFirst_t &first, const JSecond_t &second)
Get distance between objects.
Basic data structure for L0 hit.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
virtual bool hasNext() override
Check availability of next element.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int getIndex(const int first, const int second) const
Get index of pair of indices.
#define ERROR(A)
Definition: JMessage.hh:66
int getNumberOfFloors(const JDetector &detector)
Get number of floors.
Support methods.
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Direct access to module in detector data structure.
int getString() const
Get string number.
Definition: JLocation.hh:134
virtual double getIndexOfRefractionGroup(const double lambda) const
Index of refraction for group velocity.
const double getSpeedOfLight()
Get speed of light.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
Data structure for L0 hit.
Definition: JHitL0.hh:27
virtual const pointer_type & next() override
Get next element.
bool hasModule(const JObjectID &id) const
Has module.
bool comparepair(const pair_type &A, const pair_type &B)
Definition: JNanobeacon.hh:10
Template L0 hit builder.
Definition: JBuildL0.hh:35
do set_variable DETECTOR_TXT $WORKDIR detector
Auxiliary data structure for set of PMT identifiers.
Definition: JPMTSelector.hh:25
unsigned int getNumberOfPairs() const
Get number of pairs.
int main(int argc, char *argv[])
Definition: Main.cpp:15