Jpp  18.5.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPMTRouter.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <map>
5 
6 #include "TROOT.h"
7 #include "TFile.h"
8 #include "TH2D.h"
9 
13 
14 #include "JDetector/JDetector.hh"
16 #include "JDetector/JPMTRouter.hh"
17 #include "JDetector/JTimeRange.hh"
18 
20 #include "JSupport/JSupport.hh"
21 
22 #include "Jeep/JTimer.hh"
23 #include "Jeep/JParser.hh"
24 #include "Jeep/JMessage.hh"
25 
26 
27 /**
28  * \file
29  *
30  * Example program to determine speed of JDETECTOR::JPMTRouter.
31  * \author mdejong
32  */
33 int main(int argc, char **argv)
34 {
35  using namespace std;
36  using namespace JPP;
37 
38  JMultipleFileScanner<Evt> inputFile;
39  JLimit_t& numberOfEvents = inputFile.getLimit();
40  string outputFile;
41  string detectorFile;
42  int debug;
43 
44  try {
45 
46  JParser<> zap("Example program to determine speed of PMT router.");
47 
48  zap['f'] = make_field(inputFile);
49  zap['o'] = make_field(outputFile) = "router.root";
50  zap['a'] = make_field(detectorFile);
51  zap['n'] = make_field(numberOfEvents) = JLimit::max();
52  zap['d'] = make_field(debug) = 1;
53 
54  zap(argc, argv);
55  }
56  catch(const exception& error) {
57  FATAL(error.what() << endl);
58  }
59 
60 
62 
63  try {
64  load(detectorFile, detector);
65  }
66  catch(const JException& error) {
67  FATAL(error);
68  }
69 
70  const JPMTRouter router(detector);
71 
72  typedef map<int, JLocation> map_t;
73 
74  map_t zmap;
75 
76  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
77  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
78  zmap[pmt->getID()] = module->getLocation();
79  }
80  }
81 
83 
84  JRange_t floor = JRange_t::DEFAULT_RANGE();
85  JRange_t string = JRange_t::DEFAULT_RANGE();
86 
87  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
88  floor .include(module->getFloor());
89  string.include(module->getString());
90  }
91 
92  NOTICE("String " << string.getLowerLimit() << " - " << string.getUpperLimit() << endl);
93  NOTICE("Floor " << floor .getLowerLimit() << " - " << floor .getUpperLimit() << endl);
94 
95 
96  TFile out(outputFile.c_str(), "recreate");
97 
98  TH2D h1("h1", NULL,
99  string.getLength() + 1,
100  string.getLowerLimit() - 0.5,
101  string.getUpperLimit() + 0.5,
102  floor.getLength() + 1,
103  floor.getLowerLimit() - 0.5,
104  floor.getUpperLimit() + 0.5);
105 
106  TH2D h2("h2", NULL,
107  string.getLength() + 1,
108  string.getLowerLimit() - 0.5,
109  string.getUpperLimit() + 0.5,
110  floor.getLength() + 1,
111  floor.getLowerLimit() - 0.5,
112  floor.getUpperLimit() + 0.5);
113 
114  JTimer t1("map");
115  JTimer t2("router");
116 
117  while (inputFile.hasNext()) {
118 
119  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
120 
121  const Evt* event = inputFile.next();
122 
123  t1.start();
124 
125  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
126 
127  const JLocation& pos = zmap[hit->pmt_id];
128 
129  h1.Fill((double) pos.getString(), (double) pos.getFloor());
130  }
131 
132  t1.stop();
133  }
134  STATUS(endl);
135 
136  inputFile.rewind();
137 
138  while (inputFile.hasNext()) {
139 
140  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
141 
142  const Evt* event = inputFile.next();
143 
144  t2.start();
145 
146  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
147 
148  const JLocation& pos = router.getParentModule(hit->pmt_id);
149 
150  h2.Fill((double) pos.getString(), (double) pos.getFloor());
151  }
152 
153  t2.stop();
154  }
155  STATUS(endl);
156 
157  t1.print(cout);
158  t2.print(cout);
159 
160  out.Write();
161  out.Close();
162 }
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:24
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
void print(std::ostream &out, const JScale_t scale=milli_t) const
Print timer data.
Definition: JTimer.hh:161
string outputFile
Data structure for detector geometry and calibration.
void stop()
Stop timer.
Definition: JTimer.hh:113
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Type definition of range.
Definition: JHead.hh:41
Detector file.
Definition: JHead.hh:226
Logical location of module.
Definition: JLocation.hh:37
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
const JModule & getParentModule(const JObjectID &id) const
Get parent module.
Definition: JPMTRouter.hh:164
Auxiliary class for CPU timing and usage.
Definition: JTimer.hh:32
#define NOTICE(A)
Definition: JMessage.hh:64
Direct access to PMT in detector data structure.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
int getString() const
Get string number.
Definition: JLocation.hh:134
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.
Utility class to parse command line options.
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
void start()
Start timer.
Definition: JTimer.hh:89
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62