Jpp  18.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 
95  JPosition3D center = get<JPosition3D>(header);
96 
97  NOTICE("Apply detector offset " << center << endl);
98 
99  detector -= center;
100 
102 
103  double x = -100.0;
104 
105  for ( ; x < -10.0; x += 5.0) { X.push_back(x); }
106  for ( ; x < +20.0; x += 1.0) { X.push_back(x); }
107  for ( ; x < +50.0; x += 2.0) { X.push_back(x); }
108  for ( ; x < +100.0; x += 5.0) { X.push_back(x); }
109  for ( ; x < +250.0; x += 10.0) { X.push_back(x); }
110  for ( ; x < +500.0; x += 25.0) { X.push_back(x); }
111  for ( ; x < +900.0; x += 50.0) { X.push_back(x); }
112 
113  JManager<int, TH1D> H1(new TH1D("h[%]", NULL, X.size() - 1, X.data()));
114 
115  map<int, int> npe;
116 
117  size_t number_of_events = 0;
118 
119  while (inputFile.hasNext()) {
120 
121  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
122 
123  const Evt* event = inputFile.next();
124 
125  if (!event->mc_hits.empty()) {
126  ++number_of_events;
127  }
128 
129  size_t number_of_muons = 0;
130 
131  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
132  if (is_muon(*track)) {
133  number_of_muons += 1;
134  }
135  }
136 
137  if (!M(number_of_muons)) {
138  continue;
139  }
140 
141  if (event->mc_hits.size() < L_cut) continue; //simple multiplicity cut
142 
143  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
144 
145  npe[hit->type] += hit->a;
146 
147  const double t1 = getTime(*hit);
148 
149  vector<Trk>::const_iterator track = find_if(event->mc_trks.begin(),
150  event->mc_trks.end(),
151  make_predicate(&Trk::id, hit->origin));
152 
153  if (track != event->mc_trks.end() && is_muon(*track)) {
154 
155  const JTrack3E muon = getTrack(*track);
156 
157  if (router.hasPMT(hit->pmt_id)) {
158 
159  const JPMT& pmt = router.getPMT(hit->pmt_id);
160  const double t0 = muon.getT(pmt);
161 
162  H1[pmt.getID()]->Fill(t1 - t0, hit->a);
163 
164  H1->Fill(t1 - t0, hit->a);
165  }
166  }
167  }
168  }
169  STATUS(endl);
170 
171  if (number_of_events != 0) {
172 
173  const double W = 1.0 / (double) number_of_events;
174 
175  convertToPDF(*H1, "WE", W);
176 
177  for (auto& i : H1) {
178  convertToPDF(*i.second, "WE", W);
179  }
180  }
181 
182  if (debug >= status_t) {
183 
184  cout << "photon-electron statistics" << endl;
185 
186  for (const auto& i : npe) {
187  cout << setw(3) << i.first << ' ' << setw(6) << i.second << endl;
188  }
189  }
190 
191  TFile out(outputFile.c_str(), "recreate");
192 
193  out << *H1 << H1;
194 
195  out.Write();
196  out.Close();
197 }
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:1514
General exception.
Definition: JException.hh:23
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
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
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
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
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
#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
Monte Carlo run header.
Definition: JHead.hh:1221
#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
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
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