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

Example program to test conversion between Monte Carlo and DAQ times. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "km3net-dataformat/offline/Hit.hh"
#include "km3net-dataformat/offline/io_online.hh"
#include "km3net-dataformat/tools/time_converter.hh"
#include "JDAQ/JDAQEventIO.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JSupport/JTriggeredFileScanner.hh"
#include "JSupport/JMonteCarloFileSupportkit.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 test conversion between Monte Carlo and DAQ times.

Author
mdejong

Definition in file JTimeConverter.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 70 of file JTimeConverter.cc.

71 {
72  using namespace std;
73  using namespace JPP;
74  using namespace KM3NETDAQ;
75 
76  JTriggeredFileScanner<> inputFile;
77  JLimit_t& numberOfEvents = inputFile.getLimit();
78  string detectorFile;
79  double Tmax_ns;
80  int debug;
81 
82  try {
83 
84  JParser<> zap("Example program to test conversion between Monte Carlo and DAQ times.");
85 
86  zap['f'] = make_field(inputFile);
87  zap['a'] = make_field(detectorFile);
88  zap['n'] = make_field(numberOfEvents) = JLimit::max();
89  zap['T'] = make_field(Tmax_ns) = 20.0;
90  zap['d'] = make_field(debug) = 3;
91 
92  zap(argc, argv);
93  }
94  catch(const exception &error) {
95  FATAL(error.what() << endl);
96  }
97 
98 
99  using namespace KM3NETDAQ;
100 
101  cout.tie(&cerr);
102 
103 
105 
106  try {
107  load(detectorFile, detector);
108  }
109  catch(const JException& error) {
110  FATAL(error);
111  }
112 
113  const JModuleRouter router(detector);
114 
115 
116  //typedef JDAQSnapshotHit JHit_t;
117  typedef JDAQTriggeredHit JHit_t;
118 
119  while (inputFile.hasNext()) {
120 
121  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
122 
123  JTriggeredFileScanner<>::multi_pointer_type ps = inputFile.next();
124 
125  const JDAQEvent* tev = ps;
126  const Evt* event = ps;
127 
128  ASSERT(!tev->empty<JHit_t>());
129 
130  typedef map<int, set<double> > map_type;
131 
132  map_type mc;
133  map_type data;
134 
135  for (vector<Hit>::const_iterator i = event->mc_hits.begin(); i != event->mc_hits.end(); ++i) {
136 
137  if (!is_noise(*i)) {
138 
139  DEBUG("Hit (MC): " << setw(5) << i->pmt_id << ' ' << FIXED(6,1) << getTime(*i) << endl);
140 
141  mc[i->pmt_id].insert(getTime(*i));
142  }
143  }
144 
145  for (int test : {1, 2} ) {
146 
147  DEBUG("Test "<< test << endl);
148 
149  data.clear();
150 
151  time_converter converter;
152 
153  if (test == 1) {
154 
155  converter = time_converter(*event, *tev);
156 
157  for (JDAQEvent::const_iterator<JHit_t> i = tev->begin<JHit_t>(); i != tev->end<JHit_t>(); ++i) {
158 
159  const JModule& module = router.getModule(i->getModuleID());
160  const JPMT& pmt = module.getPMT(i->getPMT());
161 
162  data[pmt.getID()].insert(converter.getTime(getTime(*i, pmt)));
163  }
164 
165  } else if (test == 2) {
166 
167  Evt evt = *event;
168 
169  read(evt, *tev);
170 
171  converter = time_converter(evt);
172 
173  for (vector<Hit>::const_iterator i = evt.hits.begin(); i != evt.hits.end(); ++i) {
174 
175  if (i->trig != 0) {
176 
177  const JModule& module = router.getModule(i->dom_id);
178  const JPMT& pmt = module.getPMT(i->channel_id);
179 
180  data[pmt.getID()].insert(converter.getTime(getTime(i->tdc, pmt)));
181  //data[pmt.getID()].insert(converter.getTime(getTime(i->tdc, pmt)));
182  }
183  }
184  }
185 
186  for (map_type::const_iterator i = data.begin(); i != data.end(); ++i) {
187  for (set<double>::const_iterator hit = i->second.begin(); hit != i->second.end(); ++hit) {
188  DEBUG("Hit (DAQ): " << setw(5) << i->first << ' ' << FIXED(6,1) << *hit << endl);
189  }
190  }
191 
192  int number_of_hits = 0;
193 
194  for (map_type::const_iterator p = mc.begin(), q = data.begin(); ; ++p, ++q) {
195 
196  while (p != mc.end() && q != data.end() && p->first < q->first) { ++p; }
197  while (p != mc.end() && q != data.end() && q->first < p->first) { ++q; }
198 
199  if (p == mc.end() || q == data.end()) {
200  break;
201  }
202 
203  if (p->first == q->first) {
204  number_of_hits += get_count(p->second, q->second, Tmax_ns);
205  }
206  }
207 
208  NOTICE("Number of hits " << setw(5) << number_of_hits << '/' << setw(5) << tev->size<JHit_t>() << endl);
209 
210  ASSERT(number_of_hits != 0);
211  }
212  }
213 
214  ASSERT(inputFile.getCounter() != 0);
215 
216  return 0;
217 }
Auxiliary class to set-up Hit.
Definition: JHit_t.hh:25
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::istream & read(std::istream &in, JTestSummary &summary, const char delimiter= ' ')
Read test summary.
bool empty() const
Check emptyness of hit container.
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
Template const_iterator.
Definition: JDAQEvent.hh:68
Router for direct addressing of module data in detector data structure.
Auxiliary class to synchronously read DAQ events and Monte Carlo events (and optionally other events)...
Auxiliary class to convert DAQ hit time to/from Monte Carlo hit time.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
double getTime(const Hit &hit)
Get true time of hit.
unsigned int size() const
Get number of hits.
bool is_noise(const Hit &hit)
Verify hit origin.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
const_iterator< T > end() const
Get end of data.
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
Detector file.
Definition: JHead.hh:224
const_iterator< T > begin() const
Get begin of data.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int getID() const
Get identifier.
Definition: JObjectID.hh:50
Data structure for PMT geometry, calibration and status.
Definition: JPMT.hh:43
#define NOTICE(A)
Definition: JMessage.hh:64
int debug
debug level
Definition: JSirene.cc:63
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.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
std::vector< Hit > hits
list of hits
Definition: Evt.hh:35
do set_variable DETECTOR_TXT $WORKDIR detector
General purpose class for multiple pointers.
double getTime() const
Get DAQ/trigger time minus Monte Carlo time.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19