Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTurbot2D.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <limits>
6 #include <map>
7 #include <vector>
8 
9 #include "TROOT.h"
10 #include "TFile.h"
11 #include "TH1D.h"
12 #include "TH2D.h"
13 #include "TF1.h"
14 
15 #include "JDAQ/JDAQEventIO.hh"
16 #include "JDAQ/JDAQTimesliceIO.hh"
17 #include "JDAQ/JDAQEvaluator.hh"
18 #include "JDetector/JDetector.hh"
22 #include "JTrigger/JBuildL0.hh"
23 #include "JTrigger/JBuildL1.hh"
24 #include "JLang/JSinglePointer.hh"
25 #include "JROOT/JManager.hh"
29 #include "JSupport/JTreeScanner.hh"
31 #include "JSupport/JSupport.hh"
32 
33 #include "Jeep/JPrint.hh"
34 #include "Jeep/JParser.hh"
35 #include "Jeep/JMessage.hh"
36 
37 
38 /**
39  * \file
40  *
41  * Example program to search for out of sync shifts around integral timeslices evolving over time.
42  * \author shallmann
43  */
44 int main(int argc, char **argv)
45 {
46  using namespace std;
47  using namespace JPP;
48  using namespace KM3NETDAQ;
49 
50  JSingleFileScanner<> inputFile;
51  JLimit_t& numberOfEvents = inputFile.getLimit();
52  string outputFile;
53  string detectorFile;
54  double TMax_ns;
55  int numberOfTimeslices;
56  double binWidth_ns;
57  double binWidth_min_timeEvolution;
58  JROOTClassSelector selector;
59  int debug;
60 
61  try {
62 
63  JParser<> zap("Example program to search for out of sync shifts around integral timeslices evolving over time.");
64 
65  zap['f'] = make_field(inputFile);
66  zap['o'] = make_field(outputFile) = "";
67  zap['a'] = make_field(detectorFile);
68  zap['n'] = make_field(numberOfEvents) = JLimit::max();
69  zap['T'] = make_field(TMax_ns) = 20.0;
70  zap['N'] = make_field(numberOfTimeslices) = 40;
71  zap['W'] = make_field(binWidth_ns) = 10e3;
72  zap['M'] = make_field(binWidth_min_timeEvolution) = 2;
73  zap['C'] = make_field(selector) = "", getROOTClassSelection<JDAQTimesliceTypes_t>();
74  zap['d'] = make_field(debug) = 2;
75 
76  zap(argc, argv);
77  }
78  catch(const exception& error) {
79  FATAL(error.what() << endl);
80  }
81 
82 
83 
84  cout.tie(&cerr);
85 
86 
87  map<int, int> MASK; // mask PMTs with permament high-rate veto.
88 
89  const int WR = 0x80000000; // White Rabbit
90 
91  MASK[808969848] = 0x00000020; // floor 03, pmt 05
92  MASK[809544061] = 0x00000080; // floor 05, pmt 07
93  MASK[808432835] = 0x00004000; // floor 18, pmt 14
94 
95 
97 
98  try {
99  load(detectorFile, detector);
100  }
101  catch(const JException& error) {
102  FATAL(error);
103  }
104 
105  const JDAQHitRouter router(detector);
106 
107 
108  typedef double hit_type;
109 
110  JBuildL0<hit_type> buildL0;
111  JBuildL1<hit_type> buildL1(JBuildL1Parameters(TMax_ns, true));
112  vector <hit_type> data;
113 
115 
117 
119 
120  if (selector == "") {
121 
122  if ((ps = new JTreeScanner< JAssertConversion<JDAQTimesliceSN, JDAQTimeslice> >(inputFile))->getEntries() != 0 ||
123  (ps = new JTreeScanner< JAssertConversion<JDAQTimesliceL2, JDAQTimeslice> >(inputFile))->getEntries() != 0 ||
124  (ps = new JTreeScanner< JAssertConversion<JDAQTimesliceL1, JDAQTimeslice> >(inputFile))->getEntries() != 0 ||
125  (ps = new JTreeScanner< JAssertConversion<JDAQTimeslice, JDAQTimeslice> >(inputFile))->getEntries() != 0 ||
126  (ps = new JTreeScanner< JAssertConversion<JDAQTimesliceL0, JDAQTimeslice> >(inputFile))->getEntries() != 0) {
127  } else {
128  FATAL("No timeslice data." << endl);
129  }
130 
131  NOTICE("Selected class " << ps->getClassName() << endl);
132 
133  } else {
134 
135  ps = zmap[selector];
136 
137  ps->configure(inputFile);
138  }
139 
140  typedef JManager<int, TH2D> JManager_t;
141 
142  // shift in integer time slices
143  const Double_t ymin = -(numberOfTimeslices + 0.5);
144  const Double_t ymax = +(numberOfTimeslices + 0.5);
145  const Int_t ny = (Int_t) (ymax - ymin);
146  // time in M minute binning
147  const Double_t xmin = inputFile.getLimit().min()*getFrameTime()*1e-9;// time of first event - offset
148  const Double_t xmax = min(inputFile.getLimit().max(), ps->getEntries())*getFrameTime()*1e-9; // time of last event
149  const Int_t nx = (Int_t) ((xmax - xmin) / (60*binWidth_min_timeEvolution)) + 1;
150 
151  JManager_t manager(new TH2D("M2D_%", ";time [s];shift [timeslices]", nx, xmin, xmax, ny, ymin, ymax));
152 
153  typedef map<int, vector<double> > map_type; // frame index -> event times
154 
155  map_type buffer;
156 
157  for (JTreeScanner<JDAQEvent> in(inputFile.getFilename(), inputFile.getLimit()); in.hasNext(); ) {
158 
159  STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
160 
161  JDAQEvent* event = in.next();
162 
163  // Average time of triggered hits
164 
165  double t0 = 0.0;
166 
167  for (JDAQEvent::const_iterator<JDAQTriggeredHit> hit = event->begin<JDAQTriggeredHit>(); hit != event->end<JDAQTriggeredHit>(); ++hit) {
168  t0 += getTime(*hit, router.getPMT(*hit));
169  }
170 
171  t0 /= event->size<JDAQTriggeredHit>();
172  t0 += event->getFrameIndex() * getFrameTime();
173 
174  buffer[event->getFrameIndex()].push_back(t0);
175  }
176  STATUS(endl);
177 
178 
179  while (ps->hasNext()) {
180 
181  STATUS("event: " << setw(10) << ps->getCounter() << '\r'); DEBUG(endl);
182 
183  JDAQTimeslice* timeslice = ps->next();
184 
185  map_type::const_iterator p = buffer.lower_bound(timeslice->getFrameIndex() - numberOfTimeslices);
186  map_type::const_iterator q = buffer.upper_bound(timeslice->getFrameIndex() + numberOfTimeslices);
187 
188  int number_of_events = 0;
189 
190  for (map_type::const_iterator i = p; i != q; ++i) {
191  number_of_events += i->second.size();
192  }
193 
194  if (number_of_events == 0) {
195  continue;
196  }
197 
198  for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
199 
200  // Test that none of the PMTs has high-rate veto.
201 
202  if ((frame->getStatus() & ~MASK[frame->getModuleID()] & ~WR) == 0) {
203 
204  data.clear();
205 
206  buildL1(*frame, router.getModule(frame->getModuleID()), back_inserter(data));
207 
208  TH2D* h2 = manager[frame->getModuleID()];
209 
210  for (vector<hit_type>::const_iterator hit = data.begin(); hit != data.end(); ++hit) {
211 
212  const double t1 = *hit + frame->getFrameIndex() * getFrameTime();
213 
214  for (map_type::const_iterator i = p; i != q; ++i) {
215  for (map_type::mapped_type::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
216 
217  const double t0 = *j;
218 
219  // fill only shift is near integer time slice
220  const double timeFromInt = (t1 - t0)/getFrameTime() - round((t1 - t0)/getFrameTime());
221  if ( abs(timeFromInt)*getFrameTime() < binWidth_ns/2. ){
222  h2->Fill(timeslice->getFrameIndex() * getFrameTime() * 1e-9, round(t1 - t0)/getFrameTime());
223  }
224  }
225  }
226  }
227  }
228  }
229  }
230  STATUS(endl);
231 
232  if (outputFile != "") {
233  manager.Write(outputFile.c_str());
234  }
235 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
Direct access to PMT data in detector data structure for DAQ hits.
void clear()
Clear data.
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:80
Template const_iterator.
Definition: JDAQEvent.hh:68
Auxiliary class to select ROOT class based on class name.
Auxialiary class to assert type conversion.
Definition: JConversion.hh:66
const JModule & getModule(const JDAQKeyHit &hit) const
Get module parameters.
Dynamic ROOT object management.
Auxiliary class for a type holder.
Definition: JType.hh:19
double getTime(const Hit &hit)
Get true time of hit.
string outputFile
Template definition for direct access of elements in ROOT TChain.
Definition: JTreeScanner.hh:91
Data structure for detector geometry and calibration.
Simple wrapper around JModuleRouter class for direct addressing of PMT data in detector data structur...
int getFrameIndex() const
Get frame index.
The template JSinglePointer class can be used to hold a pointer to an object.
Scanning of objects from a single file according a format that follows from the extension of each fil...
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:196
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
#define NOTICE(A)
Definition: JMessage.hh:64
Data time slice.
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
Auxiliary class to select JTreeScanner based on ROOT class name.
Template L1 hit builder.
Definition: JBuildL1.hh:85
#define FATAL(A)
Definition: JMessage.hh:67
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
Auxiliary data structure for L1 build parameters.
Definition: JBuildL1.hh:37
int j
Definition: JPolint.hh:666
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
Template L0 hit builder.
Definition: JBuildL0.hh:35
do set_variable DETECTOR_TXT $WORKDIR detector
const JPMT & getPMT(const JDAQKeyHit &hit) const
Get PMT parameters.
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:38
Q WR
Definition: JDataQuality.sh:53