Jpp
Functions
JTriggerTester.cc File Reference
#include <string>
#include <iostream>
#include <iomanip>
#include <utility>
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "km3net-dataformat/offline/Hit.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JHeadToolkit.hh"
#include "km3net-dataformat/online/JDAQ.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JPMTRouter.hh"
#include "JDetector/JModuleRouter.hh"
#include "JDetector/JK40Rates.hh"
#include "JDetector/JPMTParametersMap.hh"
#include "JDetector/JPMTParametersToolkit.hh"
#include "JTrigger/JTriggerParameters.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JSupport/JSupport.hh"
#include "JTools/JHashMap.hh"
#include "JTools/JWeight.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

Auxiliary program to verify processing of Monte Carlo events.

Note that the available options are identical to those of JTriggerEfficiency.cc.

Author
mdejong

Definition in file JTriggerTester.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 81 of file JTriggerTester.cc.

82 {
83  using namespace std;
84  using namespace JPP;
85 
86  JMultipleFileScanner<Evt> inputFile;
87  JLimit_t& numberOfEvents = inputFile.getLimit();
88  string detectorFileA;
89  string detectorFileB;
90  JTriggerParameters parameters;
91  JPMTParametersMap pmtParameters;
92  JK40Rates rates_Hz;
93  int debug;
94 
95  try {
96 
97  JParser<> zap("Auxiliary program to verify processing of Monte Carlo events.");
98 
99  zap['f'] = make_field(inputFile, "input file (output of detector simulation)");
100  zap['n'] = make_field(numberOfEvents) = JLimit::max();
101  zap['a'] = make_field(detectorFileA, "detector used for converion from Monte Carlo truth to raw data.");
102  zap['b'] = make_field(detectorFileB, "detector used for conversion of raw data to calibrated data.") = "";
103  zap['@'] = make_field(parameters, "Trigger parameters (or corresponding file name)") = JPARSER::initialised();
104  zap['P'] = make_field(pmtParameters, "PMT simulation data (or corresponding file name)") = JPARSER::initialised();
105  zap['B'] = make_field(rates_Hz, "background rates [Hz]") = JPARSER::initialised();
106  zap['d'] = make_field(debug, "debug") = 2;
107 
108  zap(argc, argv);
109  }
110  catch(const exception &error) {
111  FATAL(error.what() << endl);
112  }
113 
114  cout.tie(&cerr);
115 
116  if (detectorFileB == "") {
117  detectorFileB = detectorFileA;
118  }
119 
120 
121  JDetector detectorA;
122  JDetector detectorB;
123 
124  try {
125  load(detectorFileA, detectorA);
126  load(detectorFileB, detectorB);
127  }
128  catch(const JException& error) {
129  FATAL(error);
130  }
131 
132  NOTICE("Number of modules in detector A <" << detectorFileA << ">: " << setw(4) << detectorA.size() << endl);
133  NOTICE("Number of modules in detector B <" << detectorFileB << ">: " << setw(4) << detectorB.size() << endl);
134 
135  JPMTParametersMap::Throw(true);
136 
137  if (!pmtParameters.is_valid()) {
138  FATAL("Invalid PMT parameters " << pmtParameters << endl);
139  }
140 
141  if (pmtParameters.getQE() != 1.0) {
142 
143  NOTICE("Correct background rates with global efficiency " << pmtParameters.getQE() << endl);
144 
145  rates_Hz.correct(pmtParameters.getQE());
146 
147  NOTICE("Back ground rates: " << rates_Hz << endl);
148  }
149 
150  const JPMTRouter pmtRouter (detectorA);
151  const JModuleRouter moduleRouter(detectorB);
152 
153  parameters.set(getMaximalDistance(detectorB));
154 
155  DEBUG("Trigger:" << endl << parameters << endl);
156  DEBUG("PMT parameters:" << endl << pmtParameters << endl);
157 
158  Head header;
159 
160  try {
161  header = getHeader(inputFile);
162  }
163  catch(const JException& error) {
164  FATAL(error);
165  }
166 
167  const JPosition3D center = get<JPosition3D>(header);
168 
169  NOTICE("Apply detector offset from Monte Carlo run header (" << center << ")" << endl);
170 
171  detectorA -= center;
172  detectorB -= center;
173 
178 
179  while (inputFile.hasNext()) {
180 
181  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r');
182 
183  Evt* event = inputFile.next();
184 
185  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
186 
187  if (!pmtRouter.hasPMT(hit->pmt_id)) {
188 
189  miss[hit->pmt_id].put(hit->pure_a);
190 
191  continue;
192  }
193 
194  const JPMTIdentifier pmt = pmtRouter.getIdentifier(hit->pmt_id);
195 
196  if (!moduleRouter.hasModule(pmt.getID())) {
197 
198  lost[pmt].put(hit->pure_a);
199 
200  continue;
201  }
202 
203  const double t0 = hit->pure_t;
204  const double t1 = putTime(t0, pmtRouter .getPMT(hit->pmt_id));
205  const double t2 = getTime(t1, moduleRouter.getPMT(pmt));
206 
207  if (fabs(t2 - t0) > parameters.TMaxLocal_ns) {
208 
209  slip[pmt].put(hit->pure_a);
210  }
211 
212  const JPMTParameters data = pmtParameters.getPMTParameters(pmt);
213  const double P = getSurvivalProbability(data);
214 
215  npe[pmt][0].put(hit->pure_a);
216  npe[pmt][1].put(hit->pure_a * P);
217  npe[pmt][2].put(hit->pure_a * P * data.QE);
218  }
219  }
220  STATUS(endl);
221 
222 
223  NOTICE("Number of PMTs absent in detector A: " << setw(6) << miss.size() << endl);
224 
225  for (JHashMap<int, JWeight>::const_iterator i = miss.begin(); i != miss.end(); ++i) {
226  DEBUG(setw(5) << i->first << ' ' << FIXED(8,0) << i->second.getTotal() << endl);
227  }
228 
229  NOTICE("Number of PMTs absent in detector B: " << setw(6) << lost.size() << endl);
230 
231  for (JHashMap<JPMTIdentifier, JWeight>::const_iterator i = lost.begin(); i != lost.end(); ++i) {
232  DEBUG(setw(8) << i->first.getModuleID() << "[" << setw(2) << i->first.getPMTAddress() << "] " << FIXED(8,0) << i->second.getTotal() << endl);
233  }
234 
235  NOTICE("Number of PMTs with t0 detector A - B > " << FIXED(4,1) << parameters.TMaxLocal_ns << " [ns]: " << setw(6) << slip.size() << endl);
236 
237  for (JHashMap<JPMTIdentifier, JWeight>::const_iterator i = slip.begin(); i != slip.end(); ++i) {
238  DEBUG(setw(8) << i->first.getModuleID() << "[" << setw(2) << i->first.getPMTAddress() << "] " << FIXED(8,0) << i->second.getTotal() << endl);
239  }
240 
241 
242  NOTICE("Number of true photo-electrons, passed threshold and survived QE." << endl);
243 
244  tuple_type total;
245 
246  for (JHashMap<JPMTIdentifier, tuple_type>::const_iterator p = npe.begin(); p != npe.end(); ++p) {
247 
248  DEBUG(setw(8) << p->first.getModuleID() << "[" << setw(2) << p->first.getPMTAddress() << "]");
249 
250  for (size_t i = 0; i != p->second.size(); ++i) {
251  DEBUG(' ' << FIXED(8,0) << p->second[i].getTotal());
252  }
253  DEBUG(endl);
254 
255  for (size_t i = 0; i != p->second.size(); ++i) {
256  total[i].put(p->second[i].getTotal());
257  }
258  }
259 
260  NOTICE(setw(12) << "total");
261 
262  for (size_t i = 0; i != total.size(); ++i) {
263  NOTICE(' ' << FIXED(8,0) << total[i].getTotal());
264  }
265 
266  NOTICE(endl);
267 }
JDETECTOR::getMaximalDistance
double getMaximalDistance(const JDetector &detector)
Get maximal distance between modules in detector.
Definition: JDetectorToolkit.hh:78
JSUPPORT::JLimit
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
FIXED
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:481
JTRIGGER::JTriggerParameters::set
void set(const double DMax_m=0.0)
Set dependent trigger parameters.
Definition: JTriggerParameters.hh:141
JDETECTOR::JPMTParametersMap::getQE
double getQE(const JPMTIdentifier &id) const
Get QE of given PMT.
Definition: JPMTParametersMap.hh:162
JTRIGGER::JTriggerParameters::TMaxLocal_ns
double TMaxLocal_ns
maximal time difference between L0 hits for L1
Definition: JTriggerParameters.hh:322
JTRIGGER::JTriggerParameters
Data structure for all trigger parameters.
Definition: JTriggerParameters.hh:116
JDETECTOR::getSurvivalProbability
double getSurvivalProbability(const JPMTParameters &parameters)
Get model dependent probability that a one photo-electron hit survives the simulation of the PMT assu...
Definition: JPMTParametersToolkit.hh:32
JPARSER::initialised
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:63
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:476
JDETECTOR::putTime
double putTime(const T &t1, const JCalibration &cal)
Get de-calibrated time.
Definition: JDetector/JCalibration.hh:216
std::vector
Definition: JSTDTypes.hh:12
JTOOLS::JHashMap
General purpose class for hash map of (key, value) pairs.
Definition: JHashMap.hh:53
Evt
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
NOTICE
#define NOTICE(A)
Definition: JMessage.hh:64
JDETECTOR::JPMTRouter
Router for direct addressing of PMT data in detector data structure.
Definition: JPMTRouter.hh:33
JTOOLS::JMappableCollection::put
void put(typename JClass< key_type > ::argument_type key, typename JClass< mapped_type >::argument_type value)
Put pair-wise element (key,value) into collection.
Definition: JMappableCollection.hh:76
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JDETECTOR::JK40Rates
Auxiliary class for K40 rates.
Definition: JK40Rates.hh:41
JSUPPORT::getHeader
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Definition: JMonteCarloFileSupportkit.hh:458
JSUPPORT::JMultipleFileScanner::getCounter
counter_type getCounter() const
Get counter.
Definition: JMultipleFileScanner.hh:323
debug
int debug
debug level
Definition: JSirene.cc:59
JSUPPORT::JMultipleFileScanner::next
virtual const pointer_type & next()
Get next element.
Definition: JMultipleFileScanner.hh:398
JGEOMETRY3D::JPosition3D
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
JLANG::JObjectID::getID
int getID() const
Get identifier.
Definition: JObjectID.hh:55
Head
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:39
JDETECTOR::JPMTParametersMap
Auxiliary class for map of PMT parameters.
Definition: JPMTParametersMap.hh:88
JAANET::getTime
double getTime(const Hit &hit)
Get true time of hit.
Definition: JAAnetToolkit.hh:87
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JSUPPORT::JMultipleFileScanner::hasNext
virtual bool hasNext()
Check availability of next element.
Definition: JMultipleFileScanner.hh:350
JDETECTOR::JPMTParametersMap::getPMTParameters
const JPMTParameters & getPMTParameters(const JPMTIdentifier &id) const
Get PMT parameters.
Definition: JPMTParametersMap.hh:139
JDETECTOR::JModuleRouter
Router for direct addressing of module data in detector data structure.
Definition: JModuleRouter.hh:34
JTOOLS::JHashMap::const_iterator
container_type::const_iterator const_iterator
Definition: JHashMap.hh:66
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JDETECTOR::JPMTIdentifier
PMT identifier.
Definition: JPMTIdentifier.hh:30
JSUPPORT::JMultipleFileScanner
General purpose class for object reading from a list of file names.
Definition: JMultipleFileScanner.hh:167
JDETECTOR::JDetector
Detector data structure.
Definition: JDetector.hh:80
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
JDETECTOR::JK40Rates::correct
void correct(const double QE)
Correct rates for global efficiency,.
Definition: JK40Rates.hh:145
JDETECTOR::JPMTParametersMap::is_valid
bool is_valid() const
Check validity of PMT parameters.
Definition: JPMTParametersMap.hh:242
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
JDETECTOR::JPMTParameters::QE
double QE
relative quantum efficiency
Definition: JPMTParameters.hh:216
JDETECTOR::JPMTParameters
Data structure for PMT parameters.
Definition: JPMTParameters.hh:29
JLANG::JException
General exception.
Definition: JException.hh:23