Jpp  pmt_effective_area_update_2
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 "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 45 of file JCalibrateToT.cc.

46 {
47  using namespace std;
48  using namespace JPP;
49  using namespace KM3NETDAQ;
50 
52  JLimit_t& numberOfEvents = inputFile.getLimit();
53  string outputFile;
54  string detectorFile;
55  JRange<double> T_ns;
56  double ctMax;
57  JRange<int> multiplicity;
58  double deadTime_us;
59  JROOTClassSelector selector;
60  JPreprocessor option;
61  int debug;
62 
63  try {
64 
65  JParser<> zap("Monitoring of PMT time-over-threshold distributions.");
66 
67  zap['f'] = make_field(inputFile, "input file.");
68  zap['o'] = make_field(outputFile, "output file.") = "calibrate_tot.root";
69  zap['n'] = make_field(numberOfEvents) = JLimit::max();
70  zap['a'] = make_field(detectorFile, "detector file.");
71  zap['T'] = make_field(T_ns, "time window [ns].") = JRange<double>(10.0, 25.0);
72  zap['c'] = make_field(ctMax, "maximal cosine space angle between PMT axes.") = 0.0;
73  zap['M'] = make_field(multiplicity, "multiplicity range of hits on DOM.") = JRange<int>(1, 2);
74  zap['D'] = make_field(deadTime_us, "L0 dead time (us)") = 10;
75  zap['C'] = make_field(selector, "timeslice selector, e.g. JDAQTimesliceL1.") = getROOTClassSelection<JDAQTimesliceTypes_t>();
76  zap['O'] = make_field(option, "hit pre-processing option.") = JPreprocessor::getOptions();
77  zap['d'] = make_field(debug, "debug flag.") = 1;
78 
79  zap(argc, argv);
80  }
81  catch(const exception &error) {
82  FATAL(error.what() << endl);
83  }
84 
85  cout.tie(&cerr);
86 
87  //-----------------------------------------------------------
88  // check the input parameters
89  //-----------------------------------------------------------
90 
91  if (!T_ns.is_valid()) {
92  FATAL("Invalid time window [ns] " << T_ns << endl);
93  }
94 
95  if (selector == JDAQTimeslice ::Class_Name() ||
96  selector == JDAQTimesliceL1::Class_Name()) {
97 
99 
100  try {
101  parameters = getTriggerParameters(inputFile);
102  }
103  catch(const JException& error) {
104  FATAL("No trigger parameters from input." << endl);
105  }
106 
107  if ((selector == JDAQTimeslice ::Class_Name() && parameters.writeL1.prescale > 0) ||
108  (selector == JDAQTimesliceL1::Class_Name())) {
109 
110  if (parameters.TMaxLocal_ns < T_ns.getUpperLimit()) {
111  FATAL("Option -T <T_ns> = " << T_ns.getUpperLimit() << " is larger than in the trigger " << parameters.TMaxLocal_ns << endl);
112  }
113  }
114  }
115 
116  if (!multiplicity.is_valid()) { FATAL("Invalid multiplicity " << multiplicity << endl); }
117  if ( multiplicity.getLowerLimit() < 1) { FATAL("Invalid multiplicity " << multiplicity << endl); }
118 
119  //-----------------------------------------------------------
120  // load detector file
121  //-----------------------------------------------------------
122 
124 
125  try {
126  load(detectorFile, detector);
127  }
128  catch(const JException& error) {
129  FATAL(error);
130  }
131 
132  if (detector.empty()) {
133  FATAL("Empty detector." << endl);
134  }
135 
136  const JModuleRouter router(detector);
137 
138  //-----------------------------------------------------------
139  // initialise histograms
140  //-----------------------------------------------------------
141 
142  const double zmin = -0.5; // [ns]
143  const double zmax = 256.5; // [ns]
144  const int nz = (int) ((zmax-zmin) / 1.0);
145 
146  JManager<int, TH2D> manager(new TH2D(MAKE_CSTRING("%" << _2SToT), NULL, NUMBER_OF_PMTS, -0.5, NUMBER_OF_PMTS-0.5, nz, zmin, zmax));
147 
148  typedef JHitR0 hit_type;
149  typedef JSuperFrame2D<hit_type> JSuperFrame2D_t;
150  typedef JSuperFrame1D<hit_type> JSuperFrame1D_t;
151 
152  const JMatchL0<hit_type> match(T_ns.getUpperLimit()); // time window self-coincidences [ns]
153 
154  const double deadTime_ns = deadTime_us * 1e3;
155 
157 
158 
159  TFile out(outputFile.c_str(), "recreate");
160 
161  putObject(&out, JMeta(argc, argv));
162 
163  JDAQHeader header;
164 
165  for (counter_type counter = 0; in.hasNext() && counter != inputFile.getLimit(); ++counter) {
166 
167  STATUS("event: " << setw(10) << counter << '\r'); DEBUG(endl);
168 
169  const JDAQTimeslice* timeslice = in.next();
170 
171  if (header.getDetectorID() != timeslice->getDetectorID() ||
172  header.getRunNumber () != timeslice->getRunNumber ()) {
173 
174  header = timeslice->getDAQHeader();
175 
176  putObject(&out, header);
177  }
178 
179  for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
180 
181  if (router.hasModule(frame->getModuleID())) {
182 
183  TH2D* h2 = manager[frame->getModuleID()];
184  const JModule& module = router.getModule(frame->getModuleID());
185 
186  JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*frame, module);
187 
188  buffer.preprocess(option, match);
189 
190  JSuperFrame1D_t& data = JSuperFrame1D_t::multiplex(buffer);
191 
192  vector<double> t0(NUMBER_OF_PMTS, numeric_limits<double>::lowest());
193 
194  for (JSuperFrame1D_t::const_iterator p = data.begin(), __end = data.end() - 1; p != __end; ) {
195 
196  JSuperFrame1D_t::const_iterator q = p;
197 
198  // reject genuine coincidences
199 
200  double ct_max = -1.0;
201  double dt_min = numeric_limits<double>::max();
202 
203  while (++q != __end && q->getT() - p->getT() < T_ns.getUpperLimit()) {
204 
205  const double ct = getDot(module.getPMT(p->getPMT()), module.getPMT(q->getPMT()));
206  const double dt = q->getT() - p->getT();
207 
208  if (ct > ct_max) {
209  ct_max = ct;
210  }
211 
212  if (dt < dt_min) {
213  dt_min = dt;
214  }
215  }
216 
217  if (multiplicity(distance(p,q)) && ct_max < ctMax && dt_min > T_ns.getLowerLimit()) {
218 
219  for (JSuperFrame1D_t::const_iterator __p = p; __p != q; ++__p) {
220 
221  if (__p->getT() > t0[__p->getPMT()] + deadTime_ns) {
222  h2->Fill(__p->getPMT(), __p->getToT());
223  }
224 
225  t0[__p->getPMT()] = __p->getT();
226  }
227  }
228 
229  p = q;
230  }
231  }
232  }
233  }
234 
235  STATUS(endl);
236 
237  out << manager;
238 
239  out.Close();
240  out.Write();
241 }
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:66
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:81
Auxiliary class to select ROOT class based on class name.
Router for direct addressing of module data in detector data structure.
bool putObject(TDirectory *dir, const TObject &object)
Write object to ROOT directory.
*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:196
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
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:163
#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:40
Auxiliary class for specifying the way of pre-processing of hits.
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.