Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JTriggerTester.cc File Reference

Auxiliary program to verify processing of Monte Carlo events. More...

#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 "JAAnet/JAAnetToolkit.hh"
#include "JPhysics/JK40Rates.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/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 "JTools/JQuantile.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

int main ( int  argc,
char **  argv 
)

Definition at line 84 of file JTriggerTester.cc.

85 {
86  using namespace std;
87  using namespace JPP;
88 
89  JMultipleFileScanner<Evt> inputFile;
90  JLimit_t& numberOfEvents = inputFile.getLimit();
91  string detectorFileA;
92  string detectorFileB;
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  cout.tie(&cerr);
118 
119  if (detectorFileB == "") {
120  detectorFileB = detectorFileA;
121  }
122 
123 
124  JDetector detectorA;
125  JDetector detectorB;
126 
127  try {
128  load(detectorFileA, detectorA);
129  load(detectorFileB, detectorB);
130  }
131  catch(const JException& error) {
132  FATAL(error);
133  }
134 
135  NOTICE("Number of modules in detector A <" << detectorFileA << ">: " << setw(4) << detectorA.size() << endl);
136  NOTICE("Number of modules in detector B <" << detectorFileB << ">: " << setw(4) << detectorB.size() << endl);
137 
138  JPMTParametersMap::Throw(true);
139 
140  if (!pmtParameters.is_valid()) {
141  FATAL("Invalid PMT parameters " << pmtParameters << endl);
142  }
143 
144  if (pmtParameters.getQE() != 1.0) {
145 
146  NOTICE("Correct background rates with global efficiency " << pmtParameters.getQE() << endl);
147 
148  rates_Hz.correct(pmtParameters.getQE());
149 
150  NOTICE("Back ground rates: " << rates_Hz << endl);
151  }
152 
153  const JPMTRouter pmtRouter (detectorA);
154  const JModuleRouter moduleRouter(detectorB);
155 
156  parameters.set(getMaximalDistance(detectorB));
157 
158  DEBUG("Trigger:" << endl << parameters << endl);
159  DEBUG("PMT parameters:" << endl << pmtParameters << endl);
160 
161  Head header;
162 
163  try {
164  header = getHeader(inputFile);
165  }
166  catch(const JException& error) {
167  FATAL(error);
168  }
169 
170  const JPosition3D center = get<JPosition3D>(header);
171 
172  NOTICE("Apply detector offset from Monte Carlo run header (" << center << ")" << endl);
173 
174  detectorA -= center;
175  detectorB -= center;
176 
181 
182  JQuantile QT;
183 
184  while (inputFile.hasNext()) {
185 
186  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r');
187 
188  Evt* event = inputFile.next();
189 
190  if (!event->mc_hits.empty()) {
191  QT.put(getTimeRange(*event).getLength());
192  }
193 
194  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
195 
196  if (!pmtRouter.hasPMT(hit->pmt_id)) {
197 
198  miss[hit->pmt_id].put(getNPE(*hit));
199 
200  continue;
201  }
202 
203  const JPMTIdentifier pmt = pmtRouter.getIdentifier(hit->pmt_id);
204 
205  if (!moduleRouter.hasModule(pmt.getID())) {
206 
207  lost[pmt].put(getNPE(*hit));
208 
209  continue;
210  }
211 
212  const double t0 = getTime(*hit);
213  const double t1 = putTime(t0, pmtRouter .getPMT(hit->pmt_id));
214  const double t2 = getTime(t1, moduleRouter.getPMT(pmt));
215 
216  if (fabs(t2 - t0) > parameters.TMaxLocal_ns) {
217  slip[pmt].put(getNPE(*hit));
218  }
219 
220  const JPMTParameters data = pmtParameters.getPMTParameters(pmt);
221  const double P = getSurvivalProbability(data);
222 
223  npe[pmt][0].put(getNPE(*hit));
224  npe[pmt][1].put(getNPE(*hit) * P);
225  npe[pmt][2].put(getNPE(*hit) * P * data.QE);
226  }
227  }
228  STATUS(endl);
229 
230 
231  NOTICE("Number of PMTs absent in detector A: " << setw(6) << miss.size() << endl);
232 
233  for (JHashMap<int, JWeight>::const_iterator i = miss.begin(); i != miss.end(); ++i) {
234  DEBUG(setw(5) << i->first << ' ' << FIXED(8,0) << i->second.getTotal() << endl);
235  }
236 
237  NOTICE("Number of PMTs absent in detector B: " << setw(6) << lost.size() << endl);
238 
239  for (JHashMap<JPMTIdentifier, JWeight>::const_iterator i = lost.begin(); i != lost.end(); ++i) {
240  DEBUG(setw(8) << i->first.getModuleID() << "[" << setw(2) << i->first.getPMTAddress() << "] " << FIXED(8,0) << i->second.getTotal() << endl);
241  }
242 
243  NOTICE("Number of PMTs with t0 detector A - B > " << FIXED(4,1) << parameters.TMaxLocal_ns << " [ns]: " << setw(6) << slip.size() << endl);
244 
245  for (JHashMap<JPMTIdentifier, JWeight>::const_iterator i = slip.begin(); i != slip.end(); ++i) {
246  DEBUG(setw(8) << i->first.getModuleID() << "[" << setw(2) << i->first.getPMTAddress() << "] " << FIXED(8,0) << i->second.getTotal() << endl);
247  }
248 
249 
250  NOTICE("Number of true photo-electrons, passed threshold and survived QE." << endl);
251 
252  tuple_type total;
253 
254  for (JHashMap<JPMTIdentifier, tuple_type>::const_iterator p = npe.begin(); p != npe.end(); ++p) {
255 
256  DEBUG(setw(8) << p->first.getModuleID() << "[" << setw(2) << p->first.getPMTAddress() << "]");
257 
258  for (size_t i = 0; i != p->second.size(); ++i) {
259  DEBUG(' ' << FIXED(8,0) << p->second[i].getTotal());
260  }
261  DEBUG(endl);
262 
263  for (size_t i = 0; i != p->second.size(); ++i) {
264  total[i].put(p->second[i].getTotal());
265  }
266  }
267 
268  NOTICE(setw(12) << "total");
269 
270  for (size_t i = 0; i != total.size(); ++i) {
271  NOTICE(' ' << FIXED(8,0) << total[i].getTotal());
272  }
273 
274  NOTICE(endl);
275 
276  NOTICE("Time range of hits [ns]: " << QT.getMin() << " - " << QT.getMax() << endl);
277 }
Router for direct addressing of PMT data in detector data structure.
Definition: JPMTRouter.hh:33
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
General purpose class for hash map of unique keys.
Definition: JHashMap.hh:71
Quantile calculator.
Definition: JQuantile.hh:88
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:80
Router for direct addressing of module data in detector data structure.
const JPMTParameters & getPMTParameters() const
Get PMT parameters.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:445
double getTime(const Hit &hit)
Get true time of hit.
JTimeRange getTimeRange(const Evt &event)
Get time range (i.e. time between earliest and latest hit) of Monte Carlo event.
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
double putTime(const T &t1, const JCalibration &cal)
Get de-calibrated time.
double getMaximalDistance(const JDetector &detector)
Get maximal distance between modules in detector.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int getID() const
Get identifier.
Definition: JObjectID.hh:50
#define NOTICE(A)
Definition: JMessage.hh:64
Auxiliary class for map of PMT parameters.
int debug
debug level
Definition: JSirene.cc:63
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:66
#define FATAL(A)
Definition: JMessage.hh:67
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
General purpose class for object reading from a list of file names.
double getSurvivalProbability(const JPMTParameters &parameters)
Get model dependent probability that a one photo-electron hit survives the simulation of the PMT assu...
double getNPE(const Hit &hit)
Get true charge of hit.
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
container_type::const_iterator const_iterator
Definition: JHashMap.hh:85
Data structure for PMT parameters.
double QE
relative quantum efficiency
Auxiliary class for K40 rates.
Definition: JK40Rates.hh:41
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19
then $DIR JPlotNPE PDG P
Definition: JPlotNPE-PDG.sh:60
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62