Jpp  17.3.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JCalibrateToT.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <limits>
6 
7 #include "TROOT.h"
8 #include "TFile.h"
9 #include "TH2D.h"
10 
13 
14 #include "JDAQ/JDAQTimesliceIO.hh"
15 #include "JDetector/JDetector.hh"
18 #include "JTrigger/JHitR0.hh"
19 #include "JTrigger/JMatchL0.hh"
24 #include "JSupport/JSupport.hh"
25 #include "JSupport/JMeta.hh"
26 #include "JROOT/JManager.hh"
27 #include "JMath/JMathToolkit.hh"
28 
30 #include "JROOT/JRootToolkit.hh"
31 #include "JROOT/JRootFileWriter.hh"
36 
37 #include "Jeep/JPrint.hh"
38 #include "Jeep/JParser.hh"
39 #include "Jeep/JMessage.hh"
40 
41 /**
42  * \file
43  *
44  * Monitoring of PMT time-over-threshold distributions.
45  * \author mkarel
46  */
47 int main(int argc, char **argv)
48 {
49  using namespace std;
50  using namespace JPP;
51  using namespace KM3NETDAQ;
52 
54  JLimit_t& numberOfEvents = inputFile.getLimit();
55  string outputFile;
56  string detectorFile;
57  JRange<double> T_ns;
58  double ctMax;
59  JRange<int> multiplicity;
60  double deadTime_us;
61  JROOTClassSelector selector;
62  JPreprocessor option;
63  int debug;
64 
65  try {
66 
67  JParser<> zap("Monitoring of PMT time-over-threshold distributions.");
68 
69  zap['f'] = make_field(inputFile, "input file.");
70  zap['o'] = make_field(outputFile, "output file.") = "calibrate_tot.root";
71  zap['n'] = make_field(numberOfEvents) = JLimit::max();
72  zap['a'] = make_field(detectorFile, "detector file.");
73  zap['T'] = make_field(T_ns, "time window [ns].") = JRange<double>(10.0, 25.0);
74  zap['c'] = make_field(ctMax, "maximal cosine space angle between PMT axes.") = 0.0;
75  zap['M'] = make_field(multiplicity, "multiplicity range of hits on DOM.") = JRange<int>(1, 2);
76  zap['D'] = make_field(deadTime_us, "L0 dead time (us)") = 10;
77  zap['C'] = make_field(selector, "timeslice selector, e.g. JDAQTimesliceL1.") = getROOTClassSelection<JDAQTimesliceTypes_t>();
78  zap['O'] = make_field(option, "hit pre-processing option.") = JPreprocessor::getOptions();
79  zap['d'] = make_field(debug, "debug flag.") = 1;
80 
81  zap(argc, argv);
82  }
83  catch(const exception &error) {
84  FATAL(error.what() << endl);
85  }
86 
87 
88  //-----------------------------------------------------------
89  // check the input parameters
90  //-----------------------------------------------------------
91 
92  if (!T_ns.is_valid()) {
93  FATAL("Invalid time window [ns] " << T_ns << endl);
94  }
95 
96  if (selector == JDAQTimeslice ::Class_Name() ||
97  selector == JDAQTimesliceL1::Class_Name()) {
98 
100 
101  try {
102  parameters = getTriggerParameters(inputFile);
103  }
104  catch(const JException& error) {
105  FATAL("No trigger parameters from input." << endl);
106  }
107 
108  if ((selector == JDAQTimeslice ::Class_Name() && parameters.writeL1.prescale > 0) ||
109  (selector == JDAQTimesliceL1::Class_Name())) {
110 
111  if (parameters.TMaxLocal_ns < T_ns.getUpperLimit()) {
112  FATAL("Option -T <T_ns> = " << T_ns.getUpperLimit() << " is larger than in the trigger " << parameters.TMaxLocal_ns << endl);
113  }
114  }
115  }
116 
117  if (!multiplicity.is_valid()) { FATAL("Invalid multiplicity " << multiplicity << endl); }
118  if ( multiplicity.getLowerLimit() < 1) { FATAL("Invalid multiplicity " << multiplicity << endl); }
119 
120  //-----------------------------------------------------------
121  // load detector file
122  //-----------------------------------------------------------
123 
125 
126  try {
127  load(detectorFile, detector);
128  }
129  catch(const JException& error) {
130  FATAL(error);
131  }
132 
133  if (detector.empty()) {
134  FATAL("Empty detector." << endl);
135  }
136 
137  const JModuleRouter router(detector);
138 
139  //-----------------------------------------------------------
140  // initialise histograms
141  //-----------------------------------------------------------
142 
143  const double zmin = -0.5; // [ns]
144  const double zmax = 256.5; // [ns]
145  const int nz = (int) ((zmax-zmin) / 1.0);
146 
147  JManager<int, TH2D> manager(new TH2D(MAKE_CSTRING("%" << _2SToT), NULL, NUMBER_OF_PMTS, -0.5, NUMBER_OF_PMTS-0.5, nz, zmin, zmax));
148 
149  typedef JHitR0 hit_type;
150  typedef JSuperFrame2D<hit_type> JSuperFrame2D_t;
151  typedef JSuperFrame1D<hit_type> JSuperFrame1D_t;
152 
153  const JMatchL0<hit_type> match(T_ns.getUpperLimit()); // time window self-coincidences [ns]
154 
155  const double deadTime_ns = deadTime_us * 1e3;
156 
158 
159 
160  TFile out(outputFile.c_str(), "recreate");
161 
162  putObject(out, JMeta(argc, argv));
163 
164  JDAQHeader header;
165 
166  for (counter_type counter = 0; in.hasNext() && counter != inputFile.getLimit(); ++counter) {
167 
168  STATUS("event: " << setw(10) << counter << '\r'); DEBUG(endl);
169 
170  const JDAQTimeslice* timeslice = in.next();
171 
172  if (header.getDetectorID() != timeslice->getDetectorID() ||
173  header.getRunNumber () != timeslice->getRunNumber ()) {
174 
175  header = timeslice->getDAQHeader();
176 
177  putObject(out, header);
178  }
179 
180  for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
181 
182  if (router.hasModule(frame->getModuleID())) {
183 
184  TH2D* h2 = manager[frame->getModuleID()];
185  const JModule& module = router.getModule(frame->getModuleID());
186 
187  JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*frame, module);
188 
189  buffer.preprocess(option, match);
190 
191  JSuperFrame1D_t& data = JSuperFrame1D_t::multiplex(buffer);
192 
193  vector<double> t0(NUMBER_OF_PMTS, numeric_limits<double>::lowest());
194 
195  for (JSuperFrame1D_t::const_iterator p = data.begin(); p != data.end(); ) {
196 
197  JSuperFrame1D_t::const_iterator q = p;
198 
199  // reject genuine coincidences
200 
201  double ct_max = -1.0;
202  double dt_min = numeric_limits<double>::max();
203 
204  while (++q != data.end() && q->getT() - p->getT() < T_ns.getUpperLimit()) {
205 
206  const double ct = getDot(module.getPMT(p->getPMT()), module.getPMT(q->getPMT()));
207  const double dt = q->getT() - p->getT();
208 
209  if (ct > ct_max) {
210  ct_max = ct;
211  }
212 
213  if (dt < dt_min) {
214  dt_min = dt;
215  }
216  }
217 
218  if (multiplicity(distance(p,q)) && ct_max < ctMax && dt_min > T_ns.getLowerLimit()) {
219 
220  for (JSuperFrame1D_t::const_iterator i = p; i != q; ++i) {
221 
222  if (i->getT() > t0[i->getPMT()] + deadTime_ns) {
223  h2->Fill(i->getPMT(), i->getToT());
224  }
225 
226  t0[i->getPMT()] = i->getT();
227  }
228  }
229 
230  p = q;
231  }
232  }
233  }
234  }
235 
236  STATUS(endl);
237 
238  out << manager;
239 
240  out.Close();
241  out.Write();
242 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Utility class to parse command line options.
Definition: JParser.hh:1517
Auxiliaries for pre-processing of hits.
General exception.
Definition: JException.hh:23
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
Auxiliary methods for geometrical methods.
Basic data structure for L0 hit.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition: JModule.hh:68
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
int getDetectorID() const
Get detector identifier.
double getDot(const JNeutrinoDirection &first, const JNeutrinoDirection &second)
Dot product.
Definition: JAstronomy.hh:409
L0 match criterion.
Definition: JMatchL0.hh:27
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
Auxiliary class to select ROOT class based on class name.
Router for direct addressing of module data in detector data structure.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
Long64_t counter_type
Type definition for counter.
Dynamic ROOT object management.
Auxiliary class for multiplexing object iterators.
string outputFile
int getRunNumber() const
Get run number.
Data structure for detector geometry and calibration.
1-dimensional frame with time calibrated data from one optical module.
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
I/O formatting auxiliaries.
Detector file.
Definition: JHead.hh:226
Reduced data structure for L0 hit.
Definition: JHitR0.hh:25
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
ROOT I/O of application specific meta data.
Data time slice.
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
Definition: JManager.hh:295
virtual const pointer_type & next() override
Get next element.
Match operator for consecutive hits.
virtual bool hasNext() override
Check availability of next element.
bool putObject(TDirectory &dir, const TObject &object)
Write object to ROOT directory.
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:173
General purpose messaging.
#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.
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.
const JDAQHeader & getDAQHeader() const
Get DAQ header.
Definition: JDAQHeader.hh:49
bool hasModule(const JObjectID &id) const
Has module.
static const char *const _2SToT
Histogram naming.
2-dimensional frame with time calibrated data from one optical module.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
do set_variable DETECTOR_TXT $WORKDIR detector
KM3NeT DAQ constants, bit handling, etc.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
Auxiliary class for specifying the way of pre-processing of hits.
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62