Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JTriggerTester.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5#include <utility>
6
10
11#include "JAAnet/JHead.hh"
14
15#include "JPhysics/JK40Rates.hh"
16
24
26
29#include "JSupport/JSupport.hh"
30
31#include "JTools/JHashMap.hh"
32#include "JTools/JWeight.hh"
33#include "JTools/JQuantile.hh"
34
35#include "Jeep/JPrint.hh"
36#include "Jeep/JParser.hh"
37#include "Jeep/JMessage.hh"
38
39namespace {
40
41 using namespace JPP;
42
43 /**
44 * Auxiliary data structure for monitoring number of photo-electrons.
45 */
46 struct tuple_type :
47 public std::vector<JWeight>
48 {
49 /**
50 * Default constructor.
51 */
52 tuple_type() :
53 std::vector<JWeight> (3, JWeight())
54 {}
55 };
56
57
58 /**
59 * Hash for PMT identifier
60 */
61 struct JHashEvaluator_t {
62 /**
63 * Get hash value.
64 *
65 * \param pmt PMT identifier
66 * \return hash value
67 */
68 inline int operator()(const JPMTIdentifier& pmt) const
69 {
70 return pmt.getID() * KM3NETDAQ::NUMBER_OF_PMTS + pmt.getPMTAddress();
71 }
72 };
73}
74
75
76/**
77 * \file
78 * Auxiliary program to verify processing of Monte Carlo events.
79 *
80 * Note that the available options are identical to those of JTriggerEfficiency.cc.
81 *
82 * \author mdejong
83 */
84int main(int argc, char **argv)
85{
86 using namespace std;
87 using namespace JPP;
88
90 JLimit_t& numberOfEvents = inputFile.getLimit();
91 string detectorFileA;
92 string detectorFileB;
93 JTriggerParameters parameters;
94 JPMTParametersMap pmtParameters;
95 JK40Rates rates_Hz;
96 int debug;
97
98 try {
99
100 JParser<> zap("Auxiliary program to verify processing of Monte Carlo events.");
101
102 zap['f'] = make_field(inputFile, "input file (output of detector simulation)");
103 zap['n'] = make_field(numberOfEvents) = JLimit::max();
104 zap['a'] = make_field(detectorFileA, "detector used for converion from Monte Carlo truth to raw data.");
105 zap['b'] = make_field(detectorFileB, "detector used for conversion of raw data to calibrated data.") = "";
106 zap['@'] = make_field(parameters, "Trigger parameters (or corresponding file name)") = JPARSER::initialised();
107 zap['P'] = make_field(pmtParameters, "PMT simulation data (or corresponding file name)") = JPARSER::initialised();
108 zap['B'] = make_field(rates_Hz, "background rates [Hz]") = JPARSER::initialised();
109 zap['d'] = make_field(debug, "debug") = 2;
110
111 zap(argc, argv);
112 }
113 catch(const exception &error) {
114 FATAL(error.what() << endl);
115 }
116
117
118 if (detectorFileB == "") {
119 detectorFileB = detectorFileA;
120 }
121
122
123 JDetector detectorA;
124 JDetector detectorB;
125
126 try {
127 load(detectorFileA, detectorA);
128 load(detectorFileB, detectorB);
129 }
130 catch(const JException& error) {
131 FATAL(error);
132 }
133
134 NOTICE("Number of modules in detector A <" << detectorFileA << ">: " << setw(4) << detectorA.size() << endl);
135 NOTICE("Number of modules in detector B <" << detectorFileB << ">: " << setw(4) << detectorB.size() << endl);
136
138
139 if (!pmtParameters.is_valid()) {
140 FATAL("Invalid PMT parameters " << pmtParameters << endl);
141 }
142
143 if (pmtParameters.getQE() != 1.0) {
144
145 NOTICE("Correct background rates with global efficiency " << pmtParameters.getQE() << endl);
146
147 rates_Hz.correct(pmtParameters.getQE());
148
149 NOTICE("Back ground rates: " << rates_Hz << endl);
150 }
151
152 const JPMTRouter pmtRouter (detectorA);
153 const JModuleRouter moduleRouter(detectorB);
154
155 parameters.set(getMaximalDistance(detectorB));
156
157 DEBUG("Trigger:" << endl << parameters << endl);
158 DEBUG("PMT parameters:" << endl << pmtParameters << endl);
159
160 Head header;
161
162 try {
163 header = getHeader(inputFile);
164 }
165 catch(const JException& error) {
166 FATAL(error);
167 }
168
169
174
175 JQuantile QT;
176
177 while (inputFile.hasNext()) {
178
179 STATUS("event: " << setw(10) << inputFile.getCounter() << '\r');
180
181 Evt* event = inputFile.next();
182
183 if (!event->mc_hits.empty()) {
184 QT.put(getTimeRange(*event).getLength());
185 }
186
187 for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
188
189 if (!pmtRouter.hasPMT(hit->pmt_id)) {
190
191 miss[hit->pmt_id].put(getNPE(*hit));
192
193 continue;
194 }
195
196 const JPMTIdentifier pmt = pmtRouter.getIdentifier(hit->pmt_id);
197
198 if (!moduleRouter.hasModule(pmt.getID())) {
199
200 lost[pmt].put(getNPE(*hit));
201
202 continue;
203 }
204
205 const double t0 = getTime(*hit);
206 const double t1 = putTime(t0, pmtRouter .getPMT(hit->pmt_id));
207 const double t2 = getTime(t1, moduleRouter.getPMT(pmt));
208
209 if (fabs(t2 - t0) > parameters.TMaxLocal_ns) {
210 slip[pmt].put(getNPE(*hit));
211 }
212
213 const JPMTParameters data = pmtParameters.getPMTParameters(pmt);
214 const double P = getSurvivalProbability(data);
215
216 npe[pmt][0].put(getNPE(*hit));
217 npe[pmt][1].put(getNPE(*hit) * P);
218 npe[pmt][2].put(getNPE(*hit) * P * data.QE);
219 }
220 }
221 STATUS(endl);
222
223
224 NOTICE("Number of PMTs absent in detector A: " << setw(6) << miss.size() << endl);
225
226 for (JHashMap<int, JWeight>::const_iterator i = miss.begin(); i != miss.end(); ++i) {
227 DEBUG(setw(5) << i->first << ' ' << FIXED(8,0) << i->second.getTotal() << endl);
228 }
229
230 NOTICE("Number of PMTs absent in detector B: " << setw(6) << lost.size() << endl);
231
232 for (JHashMap<JPMTIdentifier, JWeight>::const_iterator i = lost.begin(); i != lost.end(); ++i) {
233 DEBUG(setw(8) << i->first.getModuleID() << "[" << setw(2) << i->first.getPMTAddress() << "] " << FIXED(8,0) << i->second.getTotal() << endl);
234 }
235
236 NOTICE("Number of PMTs with t0 detector A - B > " << FIXED(4,1) << parameters.TMaxLocal_ns << " [ns]: " << setw(6) << slip.size() << endl);
237
238 for (JHashMap<JPMTIdentifier, JWeight>::const_iterator i = slip.begin(); i != slip.end(); ++i) {
239 DEBUG(setw(8) << i->first.getModuleID() << "[" << setw(2) << i->first.getPMTAddress() << "] " << FIXED(8,0) << i->second.getTotal() << endl);
240 }
241
242
243 NOTICE("Number of true photo-electrons, passed threshold and survived QE." << endl);
244
245 tuple_type total;
246
247 for (JHashMap<JPMTIdentifier, tuple_type>::const_iterator p = npe.begin(); p != npe.end(); ++p) {
248
249 DEBUG(setw(8) << p->first.getModuleID() << "[" << setw(2) << p->first.getPMTAddress() << "]");
250
251 for (size_t i = 0; i != p->second.size(); ++i) {
252 DEBUG(' ' << FIXED(8,0) << p->second[i].getTotal());
253 }
254 DEBUG(endl);
255
256 for (size_t i = 0; i != p->second.size(); ++i) {
257 total[i].put(p->second[i].getTotal());
258 }
259 }
260
261 NOTICE(setw(12) << "total");
262
263 for (size_t i = 0; i != total.size(); ++i) {
264 NOTICE(' ' << FIXED(8,0) << total[i].getTotal());
265 }
266
267 NOTICE(endl);
268
269 NOTICE("Time range of hits [ns]: " << QT.getXmin() << " - " << QT.getXmax() << endl);
270}
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
KM3NeT DAQ constants, bit handling, etc.
Data structure for detector geometry and calibration.
General purpose class for hash map of unique elements.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#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.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Direct access to PMT 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)
Detector data structure.
Definition JDetector.hh:96
Router for direct addressing of module data in detector data structure.
const JPMT & getPMT(const JPMTIdentifier &id) const
Get PMT parameters.
bool hasModule(const JObjectID &id) const
Has module.
int getPMTAddress() const
Get PMT address (= TDC).
Auxiliary class for map of PMT parameters.
const JPMTParameters & getPMTParameters(const JPMTIdentifier &id) const
Get PMT parameters.
double getQE(const JPMTIdentifier &id) const
Get QE of given PMT.
bool is_valid() const
Check validity of PMT parameters.
Data structure for PMT parameters.
Router for direct addressing of PMT data in detector data structure.
Definition JPMTRouter.hh:37
bool hasPMT(const JObjectID &id) const
Has PMT.
JPMTIdentifier getIdentifier(const JPMTAddress &address) const
Get identifier of PMT.
General exception.
Definition JException.hh:24
int getID() const
Get identifier.
Definition JObjectID.hh:50
static void Throw(const bool option)
Enable/disable throw option.
Definition JThrow.hh:37
Utility class to parse command line options.
Definition JParser.hh:1698
General purpose class for object reading from a list of file names.
virtual bool hasNext() override
Check availability of next element.
counter_type getCounter() const
Get counter.
virtual const pointer_type & next() override
Get next element.
T getLength() const
Get length (difference between upper and lower limit).
Definition JRange.hh:289
JTimeRange getTimeRange(const Evt &event)
Get time range (i.e. time between earliest and latest hit) of Monte Carlo event.
double getNPE(const Hit &hit)
Get true charge of hit.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
double getSurvivalProbability(const JPMTParameters &parameters)
Get model dependent probability that a one photo-electron hit survives the simulation of the PMT assu...
double getMaximalDistance(const JDetector &detector, const bool option=false)
Get maximal distance between modules in detector.
double putTime(const T &t1, const JCalibration &cal)
Get de-calibrated time.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
const char * getTime()
Get current local time conform ISO-8601 standard.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition Head.hh:65
Auxiliary data structure to unify weights of acoustics data according to the number of pings per emit...
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
Auxiliary class for K40 rates.
Definition JK40Rates.hh:41
void correct(const double QE)
Correct rates for global efficiency,.
Definition JK40Rates.hh:130
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
General purpose class for hash map of unique keys.
Definition JHashMap.hh:75
container_type::const_iterator const_iterator
Definition JHashMap.hh:86
void put(typename JClass< key_type > ::argument_type key, typename JClass< mapped_type >::argument_type value)
Put pair-wise element (key,value) into collection.
Auxiliary data structure for running average, standard deviation and quantiles.
Definition JQuantile.hh:46
double getXmin() const
Get minimum value.
Definition JQuantile.hh:208
void put(const double x, const double w=1.0)
Put value.
Definition JQuantile.hh:133
double getXmax() const
Get maximum value.
Definition JQuantile.hh:219