Jpp
JPMTRouter.cc
Go to the documentation of this file.
1 
2 
3 #include <string>
4 #include <iostream>
5 #include <iomanip>
6 #include <map>
7 
8 #include "TROOT.h"
9 #include "TFile.h"
10 #include "TH2D.h"
11 
12 #include "evt/Head.hh"
13 #include "evt/Evt.hh"
14 #include "evt/Hit.hh"
15 
16 #include "JDetector/JDetector.hh"
18 #include "JDetector/JPMTRouter.hh"
19 #include "JDetector/JTimeRange.hh"
20 
22 #include "JSupport/JSupport.hh"
23 
24 #include "Jeep/JTimer.hh"
25 #include "Jeep/JParser.hh"
26 #include "Jeep/JMessage.hh"
27 
28 
29 /**
30  * \file
31  *
32  * Example program to determine speed of JDETECTOR::JPMTRouter.
33  * \author mdejong
34  */
35 int main(int argc, char **argv)
36 {
37  using namespace std;
38  using namespace JPP;
39 
40  JMultipleFileScanner<Evt> inputFile;
41  JLimit_t& numberOfEvents = inputFile.getLimit();
42  string outputFile;
43  string detectorFile;
44  int debug;
45 
46  try {
47 
48  JParser<> zap("Example program to determine speed of PMT router.");
49 
50  zap['f'] = make_field(inputFile);
51  zap['o'] = make_field(outputFile) = "router.root";
52  zap['a'] = make_field(detectorFile);
53  zap['n'] = make_field(numberOfEvents) = JLimit::max();
54  zap['d'] = make_field(debug) = 1;
55 
56  zap(argc, argv);
57  }
58  catch(const exception& error) {
59  FATAL(error.what() << endl);
60  }
61 
62 
63 
64  cout.tie(&cerr);
65 
66  JDetector detector;
67 
68  try {
69  load(detectorFile, detector);
70  }
71  catch(const JException& error) {
72  FATAL(error);
73  }
74 
75  const JPMTRouter router(detector);
76 
77  typedef map<int, JModuleLocation> map_t;
78 
79  map_t zmap;
80 
81  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
82  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
83  zmap[pmt->getID()] = module->getLocation();
84  }
85  }
86 
87  typedef JTOOLS::JRange<int> JRange_t;
88 
89  JRange_t floor = JRange_t::DEFAULT_RANGE;
90  JRange_t string = JRange_t::DEFAULT_RANGE;
91 
92  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
93  floor .include(module->getFloor());
94  string.include(module->getString());
95  }
96 
97  NOTICE("String " << string.getLowerLimit() << " - " << string.getUpperLimit() << endl);
98  NOTICE("Floor " << floor .getLowerLimit() << " - " << floor .getUpperLimit() << endl);
99 
100 
101  TFile out(outputFile.c_str(), "recreate");
102 
103  TH2D h1("h1", NULL,
104  string.getLength() + 1,
105  string.getLowerLimit() - 0.5,
106  string.getUpperLimit() + 0.5,
107  floor.getLength() + 1,
108  floor.getLowerLimit() - 0.5,
109  floor.getUpperLimit() + 0.5);
110 
111  TH2D h2("h2", NULL,
112  string.getLength() + 1,
113  string.getLowerLimit() - 0.5,
114  string.getUpperLimit() + 0.5,
115  floor.getLength() + 1,
116  floor.getLowerLimit() - 0.5,
117  floor.getUpperLimit() + 0.5);
118 
119  JTimer t1("map");
120  JTimer t2("router");
121 
122  while (inputFile.hasNext()) {
123 
124  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
125 
126  const Evt* event = inputFile.next();
127 
128  t1.start();
129 
130  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
131 
132  const JModuleLocation& pos = zmap[hit->pmt_id];
133 
134  h1.Fill((double) pos.getString(), (double) pos.getFloor());
135  }
136 
137  t1.stop();
138  }
139  STATUS(endl);
140 
141  inputFile.rewind();
142 
143  while (inputFile.hasNext()) {
144 
145  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
146 
147  const Evt* event = inputFile.next();
148 
149  t2.start();
150 
151  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
152 
153  const JModuleLocation& pos = router.getParentModule(hit->pmt_id);
154 
155  h2.Fill((double) pos.getString(), (double) pos.getFloor());
156  }
157 
158  t2.stop();
159  }
160  STATUS(endl);
161 
162  t1.print(cout);
163  t2.print(cout);
164 
165  out.Write();
166  out.Close();
167 }
main
int main(int argc, char **argv)
Definition: JPMTRouter.cc:35
JTOOLS::JRange::include
range_type include(argument_type x)
Include given value to range.
Definition: JRange.hh:388
JMessage.hh
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:456
std::vector
Definition: JSTDTypes.hh:12
JTOOLS::JRange< int >
JSUPPORT::JLimit_t
JLimit JLimit_t
Type definition of limit.
Definition: JLimit.hh:215
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
NOTICE
#define NOTICE(A)
Definition: JMessage.hh:64
JTimeRange.hh
JSupport.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
debug
int debug
debug level
Definition: JSirene.cc:59
JSUPPORT::JLimit::getLimit
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
JMultipleFileScanner.hh
std::map
Definition: JSTDTypes.hh:16
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JParser.hh
JDetectorToolkit.hh
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
JPMTRouter.hh
std
Definition: jaanetDictionary.h:36
JTimer.hh
JDetector.hh
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37