Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JTimeConverter.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <map>
5#include <set>
6
12#include "JDAQ/JDAQEventIO.hh"
13
15
19
22#include "JSupport/JSupport.hh"
23
24#include "Jeep/JPrint.hh"
25#include "Jeep/JParser.hh"
26#include "Jeep/JMessage.hh"
27
28
29namespace {
30
31 /**
32 * Count number of coincident hits.
33 *
34 * \param data1 first data set
35 * \param data2 second data set
36 * \param Tmax_ns time window [ns]
37 * \return number of hits
38 */
39 inline int get_count(const std::set<double>& data1,
40 const std::set<double>& data2,
41 const double Tmax_ns)
42 {
43 int number_of_hits = 0;
44
45 for (std::set<double>::const_iterator p = data1.begin(), q = data2.begin(); ; ++p, ++q) {
46
47 while (p != data1.end() && q != data2.end() && *p < *q - Tmax_ns) { ++p; }
48 while (p != data1.end() && q != data2.end() && *q < *p - Tmax_ns) { ++q; }
49
50 if (p == data1.end() || q == data2.end()) {
51 break;
52 }
53
54 if (fabs(*p - *q) <= Tmax_ns) {
55 ++number_of_hits;
56 }
57 }
58
59 return number_of_hits;
60 }
61}
62
63
64/**
65 * \file
66 *
67 * Example program to test conversion between Monte Carlo and DAQ times.
68 * \author mdejong
69 */
70int main(int argc, char **argv)
71{
72 using namespace std;
73 using namespace JPP;
74 using namespace KM3NETDAQ;
75
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
103
104 try {
105 load(detectorFile, detector);
106 }
107 catch(const JException& error) {
108 FATAL(error);
109 }
110
111 const JModuleRouter router(detector);
112
113
114 //typedef JDAQSnapshotHit JHit_t;
115 typedef JDAQTriggeredHit JHit_t;
116
117 while (inputFile.hasNext()) {
118
119 STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
120
122
123 const JDAQEvent* tev = ps;
124 const Evt* event = ps;
125
126 ASSERT(!tev->empty<JHit_t>());
127
129
130 map_type mc;
131 map_type data;
132
133 for (vector<Hit>::const_iterator i = event->mc_hits.begin(); i != event->mc_hits.end(); ++i) {
134
135 if (!is_noise(*i)) {
136
137 DEBUG("Hit (MC): " << setw(5) << i->pmt_id << ' ' << FIXED(6,1) << getTime(*i) << endl);
138
139 mc[i->pmt_id].insert(getTime(*i));
140 }
141 }
142
143 for (int test : {1, 2} ) {
144
145 DEBUG("Test "<< test << endl);
146
147 data.clear();
148
149 time_converter converter;
150
151 if (test == 1) {
152
153 converter = time_converter(*event, *tev);
154
155 for (JDAQEvent::const_iterator<JHit_t> i = tev->begin<JHit_t>(); i != tev->end<JHit_t>(); ++i) {
156
157 const JModule& module = router.getModule(i->getModuleID());
158 const JPMT& pmt = module.getPMT(i->getPMT());
159
160 data[pmt.getID()].insert(converter.getTime(getTime(*i, pmt)));
161 }
162
163 } else if (test == 2) {
164
165 Evt evt = *event;
166
167 read(evt, *tev);
168
169 converter = time_converter(evt);
170
171 for (vector<Hit>::const_iterator i = evt.hits.begin(); i != evt.hits.end(); ++i) {
172
173 if (i->trig != 0) {
174
175 const JModule& module = router.getModule(i->dom_id);
176 const JPMT& pmt = module.getPMT(i->channel_id);
177
178 data[pmt.getID()].insert(converter.getTime(getTime(i->tdc, pmt)));
179 }
180 }
181 }
182
183 for (map_type::const_iterator i = data.begin(); i != data.end(); ++i) {
184 for (set<double>::const_iterator hit = i->second.begin(); hit != i->second.end(); ++hit) {
185 DEBUG("Hit (DAQ): " << setw(5) << i->first << ' ' << FIXED(6,1) << *hit << endl);
186 }
187 }
188
189 int number_of_hits = 0;
190
191 for (map_type::const_iterator p = mc.begin(), q = data.begin(); ; ++p, ++q) {
192
193 while (p != mc.end() && q != data.end() && p->first < q->first) { ++p; }
194 while (p != mc.end() && q != data.end() && q->first < p->first) { ++q; }
195
196 if (p == mc.end() || q == data.end()) {
197 break;
198 }
199
200 if (p->first == q->first) {
201 number_of_hits += get_count(p->second, q->second, Tmax_ns);
202 }
203 }
204
205 NOTICE("Number of hits " << setw(5) << number_of_hits << '/' << setw(5) << tev->size<JHit_t>() << endl);
206
207 ASSERT(number_of_hits != 0);
208 }
209 }
210
211 ASSERT(inputFile.getCounter() != 0);
212
213 return 0;
214}
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
Data structure for detector geometry and calibration.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Direct access to module in detector data structure.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
I/O formatting auxiliaries.
ROOT TTree parameter settings of various packages.
int main(int argc, char **argv)
Synchronously read DAQ events and Monte Carlo events (and optionally other events).
Detector data structure.
Definition JDetector.hh:96
Router for direct addressing of module data in detector data structure.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition JModule.hh:75
Data structure for PMT geometry, calibration and status.
Definition JPMT.hh:49
General exception.
Definition JException.hh:24
int getID() const
Get identifier.
Definition JObjectID.hh:50
Utility class to parse command line options.
Definition JParser.hh:1698
counter_type getCounter() const
Get counter.
Template const_iterator.
Definition JDAQEvent.hh:68
const_iterator< T > end() const
Get end of data.
unsigned int size() const
Get number of hits.
const_iterator< T > begin() const
Get begin of data.
bool empty() const
Check emptyness of hit container.
Auxiliary class to convert DAQ hit time to/from Monte Carlo hit time.
double getTime() const
Get DAQ/trigger time minus Monte Carlo time.
bool is_noise(const Hit &hit)
Verify hit origin.
std::istream & read(std::istream &in, JTestSummary &summary, const char delimiter=' ')
Read test summary.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
const char * getTime()
Get current local time conform ISO-8601 standard.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
std::map< int, range_type > map_type
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
std::vector< Hit > hits
list of hits
Definition Evt.hh:38
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Detector file.
Definition JHead.hh:227
General purpose class for multiple pointers.
Auxiliary class to set-up Hit.
Definition JSirene.hh:58
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45
static counter_type max()
Get maximum counter value.
Definition JLimit.hh:128
Auxiliary class to synchronously read DAQ events and Monte Carlo events (and optionally other events)...
virtual bool hasNext() override
Check availability of next element.
virtual const multi_pointer_type & next() override
Get next element.
Auxiliary include file for time conversion between DAQ/trigger hit and Monte Carlo hit.