Jpp
 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/JDAQEvent.hh"
16 #include "JDAQ/JDAQTimeslice.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 "JGizmo/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 
96  JDetector detector;
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(TMax_ns, true);
112  vector <hit_type> data;
113 
115 
116  JSinglePointer< JTreeScannerInterface<JDAQTimeslice> > ps;
117 
118  JAutoTreeScanner<JDAQTimeslice> zmap = JType<JDAQTimesliceTypes_t>();
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:1410
Direct access to PMT data in detector data structure for DAQ hits.
void clear()
Clear data.
Auxiliary class to manage set of histograms.
#define STATUS(A)
Definition: JMessage.hh:61
Template const_iterator.
Definition: JDAQEvent.hh:69
Structure to store the ToT mean and standard deviation of the hits produced by a nanobeacon in a sour...
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
Data structure for detector geometry and calibration.
int getFrameIndex() const
Get frame index.
JLimit JLimit_t
Type definition of limit.
Definition: JLimit.hh:214
Scanning of objects from a single file according a format that follows from the extension of each fil...
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
#define NOTICE(A)
Definition: JMessage.hh:62
Data time slice.
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level
Definition: JSirene.cc:59
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:65
Utility class to parse command line options.
ROOT TTree parameter settings.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:72
JTriggerCounter_t next()
Increment trigger counter.
double hit_type
Definition: JDataFilter.cc:89
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60
int main(int argc, char *argv[])
Definition: Main.cpp:15