Jpp  16.0.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JCalibrateToT.cc File Reference

Monitoring of PMT time-over-threshold distributions. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <limits>
#include "TROOT.h"
#include "TFile.h"
#include "TH2D.h"
#include "km3net-dataformat/online/JDAQ.hh"
#include "km3net-dataformat/online/JDAQHeader.hh"
#include "JDAQ/JDAQTimesliceIO.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JTrigger/JHitR0.hh"
#include "JTrigger/JMatchL0.hh"
#include "JTrigger/JSuperFrame1D.hh"
#include "JTrigger/JSuperFrame2D.hh"
#include "JTrigger/JPreprocessor.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JMeta.hh"
#include "JROOT/JManager.hh"
#include "JMath/JMathToolkit.hh"
#include "JROOT/JROOTClassSelector.hh"
#include "JROOT/JRootToolkit.hh"
#include "JROOT/JRootFileWriter.hh"
#include "JLang/JObjectMultiplexer.hh"
#include "JTrigger/JTriggerParameters.hh"
#include "JSupport/JTriggerParametersSupportkit.hh"
#include "JCalibrate/JCalibrateToT.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Monitoring of PMT time-over-threshold distributions.

Author
mkarel

Definition in file JCalibrateToT.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 47 of file JCalibrateToT.cc.

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  cout.tie(&cerr);
88 
89  //-----------------------------------------------------------
90  // check the input parameters
91  //-----------------------------------------------------------
92 
93  if (!T_ns.is_valid()) {
94  FATAL("Invalid time window [ns] " << T_ns << endl);
95  }
96 
97  if (selector == JDAQTimeslice ::Class_Name() ||
98  selector == JDAQTimesliceL1::Class_Name()) {
99 
101 
102  try {
103  parameters = getTriggerParameters(inputFile);
104  }
105  catch(const JException& error) {
106  FATAL("No trigger parameters from input." << endl);
107  }
108 
109  if ((selector == JDAQTimeslice ::Class_Name() && parameters.writeL1.prescale > 0) ||
110  (selector == JDAQTimesliceL1::Class_Name())) {
111 
112  if (parameters.TMaxLocal_ns < T_ns.getUpperLimit()) {
113  FATAL("Option -T <T_ns> = " << T_ns.getUpperLimit() << " is larger than in the trigger " << parameters.TMaxLocal_ns << endl);
114  }
115  }
116  }
117 
118  if (!multiplicity.is_valid()) { FATAL("Invalid multiplicity " << multiplicity << endl); }
119  if ( multiplicity.getLowerLimit() < 1) { FATAL("Invalid multiplicity " << multiplicity << endl); }
120 
121  //-----------------------------------------------------------
122  // load detector file
123  //-----------------------------------------------------------
124 
126 
127  try {
128  load(detectorFile, detector);
129  }
130  catch(const JException& error) {
131  FATAL(error);
132  }
133 
134  if (detector.empty()) {
135  FATAL("Empty detector." << endl);
136  }
137 
138  const JModuleRouter router(detector);
139 
140  //-----------------------------------------------------------
141  // initialise histograms
142  //-----------------------------------------------------------
143 
144  const double zmin = -0.5; // [ns]
145  const double zmax = 256.5; // [ns]
146  const int nz = (int) ((zmax-zmin) / 1.0);
147 
148  JManager<int, TH2D> manager(new TH2D(MAKE_CSTRING("%" << _2SToT), NULL, NUMBER_OF_PMTS, -0.5, NUMBER_OF_PMTS-0.5, nz, zmin, zmax));
149 
150  typedef JHitR0 hit_type;
151  typedef JSuperFrame2D<hit_type> JSuperFrame2D_t;
152  typedef JSuperFrame1D<hit_type> JSuperFrame1D_t;
153 
154  const JMatchL0<hit_type> match(T_ns.getUpperLimit()); // time window self-coincidences [ns]
155 
156  const double deadTime_ns = deadTime_us * 1e3;
157 
159 
160 
161  TFile out(outputFile.c_str(), "recreate");
162 
163  putObject(out, JMeta(argc, argv));
164 
165  JDAQHeader header;
166 
167  for (counter_type counter = 0; in.hasNext() && counter != inputFile.getLimit(); ++counter) {
168 
169  STATUS("event: " << setw(10) << counter << '\r'); DEBUG(endl);
170 
171  const JDAQTimeslice* timeslice = in.next();
172 
173  if (header.getDetectorID() != timeslice->getDetectorID() ||
174  header.getRunNumber () != timeslice->getRunNumber ()) {
175 
176  header = timeslice->getDAQHeader();
177 
178  putObject(out, header);
179  }
180 
181  for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
182 
183  if (router.hasModule(frame->getModuleID())) {
184 
185  TH2D* h2 = manager[frame->getModuleID()];
186  const JModule& module = router.getModule(frame->getModuleID());
187 
188  JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*frame, module);
189 
190  buffer.preprocess(option, match);
191 
192  JSuperFrame1D_t& data = JSuperFrame1D_t::multiplex(buffer);
193 
194  vector<double> t0(NUMBER_OF_PMTS, numeric_limits<double>::lowest());
195 
196  for (JSuperFrame1D_t::const_iterator p = data.begin(); p != data.end(); ) {
197 
198  JSuperFrame1D_t::const_iterator q = p;
199 
200  // reject genuine coincidences
201 
202  double ct_max = -1.0;
203  double dt_min = numeric_limits<double>::max();
204 
205  while (++q != data.end() && q->getT() - p->getT() < T_ns.getUpperLimit()) {
206 
207  const double ct = getDot(module.getPMT(p->getPMT()), module.getPMT(q->getPMT()));
208  const double dt = q->getT() - p->getT();
209 
210  if (ct > ct_max) {
211  ct_max = ct;
212  }
213 
214  if (dt < dt_min) {
215  dt_min = dt;
216  }
217  }
218 
219  if (multiplicity(distance(p,q)) && ct_max < ctMax && dt_min > T_ns.getLowerLimit()) {
220 
221  for (JSuperFrame1D_t::const_iterator i = p; i != q; ++i) {
222 
223  if (i->getT() > t0[i->getPMT()] + deadTime_ns) {
224  h2->Fill(i->getPMT(), i->getToT());
225  }
226 
227  t0[i->getPMT()] = i->getT();
228  }
229  }
230 
231  p = q;
232  }
233  }
234  }
235  }
236 
237  STATUS(endl);
238 
239  out << manager;
240 
241  out.Close();
242  out.Write();
243 }
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:1500
General exception.
Definition: JException.hh:23
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:151
Long64_t counter_type
Type definition for counter.
Auxiliary class for multiplexing object iterators.
string outputFile
int getRunNumber() const
Get run number.
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
Detector file.
Definition: JHead.hh:224
Reduced data structure for L0 hit.
Definition: JHitR0.hh:25
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
Data time slice.
int debug
debug level
Definition: JSirene.cc:63
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
#define FATAL(A)
Definition: JMessage.hh:67
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.
const JDAQHeader & getDAQHeader() const
Get DAQ header.
Definition: JDAQHeader.hh:49
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
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
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 source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:42
Auxiliary class for specifying the way of pre-processing of hits.
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.