Jpp  19.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
examples/JSirene/JDomino.cc File Reference

Example program to verify Monte Carlo data. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JHeadToolkit.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JPMTRouter.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JSupport/JSupport.hh"
#include "JLang/JPredicate.hh"
#include "JTools/JRange.hh"
#include "JROOT/JManager.hh"
#include "JROOT/JRootToolkit.hh"
#include "JGizmo/JGizmoToolkit.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 verify Monte Carlo data.

Author
mdejong

Definition in file examples/JSirene/JDomino.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 45 of file examples/JSirene/JDomino.cc.

46 {
47  using namespace std;
48  using namespace JPP;
49 
50  typedef JRange<size_t> JRange_t;
51 
52  JMultipleFileScanner<Evt> inputFile;
53  JLimit_t& numberOfEvents = inputFile.getLimit();
54  string outputFile;
55  string detectorFile;
56  JRange_t M;
57  unsigned int L_cut;
58  int debug;
59 
60  try {
61 
62  JParser<> zap("Example program to verify Monte Carlo data.");
63 
64  zap['f'] = make_field(inputFile);
65  zap['n'] = make_field(numberOfEvents) = JLimit::max();
66  zap['o'] = make_field(outputFile) = "domino.root";
67  zap['a'] = make_field(detectorFile);
68  zap['M'] = make_field(M) = JRange_t();
69  zap['m'] = make_field(L_cut) = 1;
70  zap['d'] = make_field(debug) = 2;
71 
72  zap(argc, argv);
73  }
74  catch(const exception &error) {
75  FATAL(error.what() << endl);
76  }
77 
78 
80 
81  if (detectorFile != "") {
82 
83  try {
84  load(detectorFile, detector);
85  }
86  catch(const JException& error) {
87  FATAL(error);
88  }
89  }
90 
91  const JPMTRouter router(detector);
92 
93  const JHead header = getHeader(inputFile);
94  const Vec offset = getOffset(header);
95 
96  NOTICE("Apply detector offset " << offset << endl);
97 
98  detector -= getPosition(offset);
99 
101 
102  double x = -100.0;
103 
104  for ( ; x < -10.0; x += 5.0) { X.push_back(x); }
105  for ( ; x < +20.0; x += 1.0) { X.push_back(x); }
106  for ( ; x < +50.0; x += 2.0) { X.push_back(x); }
107  for ( ; x < +100.0; x += 5.0) { X.push_back(x); }
108  for ( ; x < +250.0; x += 10.0) { X.push_back(x); }
109  for ( ; x < +500.0; x += 25.0) { X.push_back(x); }
110  for ( ; x < +900.0; x += 50.0) { X.push_back(x); }
111 
112  JManager<int, TH1D> H1(new TH1D("h[%]", NULL, X.size() - 1, X.data()));
113 
114  map<int, int> npe;
115 
116  size_t number_of_events = 0;
117 
118  while (inputFile.hasNext()) {
119 
120  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
121 
122  const Evt* event = inputFile.next();
123 
124  if (!event->mc_hits.empty()) {
125  ++number_of_events;
126  }
127 
128  size_t number_of_muons = 0;
129 
130  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
131  if (is_muon(*track)) {
132  number_of_muons += 1;
133  }
134  }
135 
136  if (!M(number_of_muons)) {
137  continue;
138  }
139 
140  if (event->mc_hits.size() < L_cut) continue; //simple multiplicity cut
141 
142  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
143 
144  npe[hit->type] += hit->a;
145 
146  const double t1 = getTime(*hit);
147 
148  vector<Trk>::const_iterator track = find_if(event->mc_trks.begin(),
149  event->mc_trks.end(),
150  make_predicate(&Trk::id, hit->origin));
151 
152  if (track != event->mc_trks.end() && is_muon(*track)) {
153 
154  const JTrack3E muon = getTrack(*track);
155 
156  if (router.hasPMT(hit->pmt_id)) {
157 
158  const JPMT& pmt = router.getPMT(hit->pmt_id);
159  const double t0 = muon.getT(pmt);
160 
161  H1[pmt.getID()]->Fill(t1 - t0, hit->a);
162 
163  H1->Fill(t1 - t0, hit->a);
164  }
165  }
166  }
167  }
168  STATUS(endl);
169 
170  if (number_of_events != 0) {
171 
172  const double W = 1.0 / (double) number_of_events;
173 
174  convertToPDF(*H1, "WE", W);
175 
176  for (auto& i : H1) {
177  convertToPDF(*i.second, "WE", W);
178  }
179  }
180 
181  if (debug >= status_t) {
182 
183  cout << "photon-electron statistics" << endl;
184 
185  for (const auto& i : npe) {
186  cout << setw(3) << i.first << ' ' << setw(6) << i.second << endl;
187  }
188  }
189 
190  TFile out(outputFile.c_str(), "recreate");
191 
192  out << *H1 << H1;
193 
194  out.Write();
195  out.Close();
196 }
Router for direct addressing of PMT data in detector data structure.
Definition: JPMTRouter.hh:35
Utility class to parse command line options.
Definition: JParser.hh:1711
General exception.
Definition: JException.hh:24
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
Vec getOffset(const JHead &header)
Get offset.
JTrack3E getTrack(const Trk &track)
Get track.
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
bool is_muon(const Trk &track)
Test whether given track is a (anti-)muon.
double getTime(const Hit &hit)
Get true time of hit.
string outputFile
3D track with energy.
Definition: JTrack3E.hh:30
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
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:12
Type definition of range.
Definition: JHead.hh:41
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
Detector file.
Definition: JHead.hh:226
status
Definition: JMessage.hh:30
Monte Carlo run header.
Definition: JHead.hh:1234
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
int getID() const
Get identifier.
Definition: JObjectID.hh:50
void convertToPDF(TH1 &h1, const std::string &option="NW", const double factor=1.0)
Convert 1D histogram to PDF.
Data structure for PMT geometry, calibration and status.
Definition: JPMT.hh:43
JPosition3D getPosition(const Vec &pos)
Get position.
#define NOTICE(A)
Definition: JMessage.hh:64
double getT(const JVector3D &pos) const
Get arrival time of Cherenkov light at given position.
Definition: JTrack3D.hh:126
Range of values.
Definition: JRange.hh:38
#define FATAL(A)
Definition: JMessage.hh:67
int id
track identifier
Definition: Trk.hh:16
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.
no fit printf nominal n $STRING awk v X
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
do set_variable DETECTOR_TXT $WORKDIR detector
int debug
debug level
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62