Jpp  master_rocky-43-ge265d140c
the software that should make you happy
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 }
int main(int argc, char **argv)
Definition: JCalibrateNB.cc:31
Data structure for detector geometry and calibration.
Basic data structure for L0 hit.
Dynamic ROOT object management.
Auxiliary methods for geometrical methods.
#define ERROR(A)
Definition: JMessage.hh:66
#define FATAL(A)
Definition: JMessage.hh:67
Direct access to module in detector data structure.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
Support methods.
ROOT TTree parameter settings of various packages.
Detector data structure.
Definition: JDetector.hh:96
int getFloor() const
Get floor number.
Definition: JLocation.hh:146
int getString() const
Get string number.
Definition: JLocation.hh:135
Router for direct addressing of module data in detector data structure.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
bool hasModule(const JObjectID &id) const
Has module.
Data structure for a composite optical module.
Definition: JModule.hh:75
Utility class to parse command line options.
Definition: JParser.hh:1698
virtual double getIndexOfRefractionGroup(const double lambda) const
Index of refraction for group velocity.
Implementation of dispersion for water in deep sea.
Definition: JDispersion.hh:28
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys.
Definition: JManager.hh:47
General purpose class for object reading from a list of file names.
virtual bool hasNext() override
Check availability of next element.
virtual const pointer_type & next() override
Get next element.
Auxiliary class to convert pair of indices to unique index and back.
int getIndex(const int first, const int second) const
Get index of pair of indices.
void sort(JComparator_t comparator)
Sort address pairs.
size_t getNumberOfPairs() const
Get number of pairs.
Template L0 hit builder.
Definition: JBuildL0.hh:38
Data structure for L0 hit.
Definition: JHitL0.hh:31
file Auxiliary data structures and methods for detector calibration.
Definition: JAnchor.hh:12
int getNumberOfFloors(const JDetector &detector)
Get number of floors.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
double getDistance(const JFirst_t &first, const JSecond_t &second)
Get distance between objects.
bool comparepair(const pair_type &A, const pair_type &B)
Definition: JNanobeacon.hh:10
const double getSpeedOfLight()
Get speed of light.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
Definition: JSTDTypes.hh:14
Depth.
Definition: JHead.hh:980
Detector file.
Definition: JHead.hh:227
Auxiliary class to set-up Hit.
Definition: JSirene.hh:58
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:45
Auxiliary data structure for set of PMT identifiers.
Definition: JPMTSelector.hh:28