Jpp
Functions
JTurbot2D.cc File Reference
#include <string>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <vector>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TF1.h"
#include "JDAQ/JDAQEvent.hh"
#include "JDAQ/JDAQTimeslice.hh"
#include "JDAQ/JDAQEvaluator.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JDAQHitRouter.hh"
#include "JDetector/JPMTParametersMap.hh"
#include "JTrigger/JBuildL0.hh"
#include "JTrigger/JBuildL1.hh"
#include "JLang/JSinglePointer.hh"
#include "JGizmo/JManager.hh"
#include "JROOT/JROOTClassSelector.hh"
#include "JSupport/JSingleFileScanner.hh"
#include "JSupport/JTreeScannerInterface.hh"
#include "JSupport/JTreeScanner.hh"
#include "JSupport/JAutoTreeScanner.hh"
#include "JSupport/JSupport.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

Example program to search for out of sync shifts around integral timeslices evolving over time.

Author
shallmann

Definition in file JTurbot2D.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 44 of file JTurbot2D.cc.

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(JBuildL1Parameters(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 }
JManager
Auxiliary class to manage set of histograms.
Definition: JHistogramToolkit.hh:160
KM3NETDAQ::JDAQEvent
DAQ Event.
Definition: JDAQEvent.hh:34
JLANG::JType
Auxiliary class for a type holder.
Definition: JType.hh:19
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:456
std::vector
Definition: JSTDTypes.hh:12
KM3NETDAQ::JDAQChronometer::getFrameIndex
int getFrameIndex() const
Get frame index.
Definition: JDAQChronometer.hh:132
JSUPPORT::JLimit_t
JLimit JLimit_t
Type definition of limit.
Definition: JLimit.hh:215
JTOOLS::j
int j
Definition: JPolint.hh:634
KM3NETDAQ::JDAQTimeslice
Data time slice.
Definition: JDAQTimeslice.hh:36
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
NOTICE
#define NOTICE(A)
Definition: JMessage.hh:64
KM3NETDAQ::getFrameTime
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
KM3NETDAQ::JDAQTriggeredHit
DAQ triggered hit.
Definition: JDAQTriggeredHit.hh:25
debug
int debug
debug level
Definition: JSirene.cc:59
KM3NETDAQ::JDAQEvent::const_iterator
Template const_iterator.
Definition: JDAQEvent.hh:69
KM3NETDAQ::JDAQTriggerCounter::next
JTriggerCounter_t next()
Increment trigger counter.
Definition: JDAQTriggerCounter.hh:120
JAANET::getTime
double getTime(const Hit &hit)
Get true time of hit.
Definition: JAAnetToolkit.hh:87
std::map
Definition: JSTDTypes.hh:16
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JSUPPORT::JSingleFileScanner<>