Jpp  15.0.1-rc.1-highqe
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPMTRouter.cc File Reference

Example program to determine speed of JDETECTOR::JPMTRouter. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include "TROOT.h"
#include "TFile.h"
#include "TH2D.h"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "km3net-dataformat/offline/Hit.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JPMTRouter.hh"
#include "JDetector/JTimeRange.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JSupport.hh"
#include "Jeep/JTimer.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 determine speed of JDETECTOR::JPMTRouter.

Author
mdejong

Definition in file JPMTRouter.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 33 of file JPMTRouter.cc.

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 
61 
62  cout.tie(&cerr);
63 
65 
66  try {
67  load(detectorFile, detector);
68  }
69  catch(const JException& error) {
70  FATAL(error);
71  }
72 
73  const JPMTRouter router(detector);
74 
75  typedef map<int, JLocation> map_t;
76 
77  map_t zmap;
78 
79  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
80  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
81  zmap[pmt->getID()] = module->getLocation();
82  }
83  }
84 
85  typedef JTOOLS::JRange<int> JRange_t;
86 
87  JRange_t floor = JRange_t::DEFAULT_RANGE;
88  JRange_t string = JRange_t::DEFAULT_RANGE;
89 
90  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
91  floor .include(module->getFloor());
92  string.include(module->getString());
93  }
94 
95  NOTICE("String " << string.getLowerLimit() << " - " << string.getUpperLimit() << endl);
96  NOTICE("Floor " << floor .getLowerLimit() << " - " << floor .getUpperLimit() << endl);
97 
98 
99  TFile out(outputFile.c_str(), "recreate");
100 
101  TH2D h1("h1", NULL,
102  string.getLength() + 1,
103  string.getLowerLimit() - 0.5,
104  string.getUpperLimit() + 0.5,
105  floor.getLength() + 1,
106  floor.getLowerLimit() - 0.5,
107  floor.getUpperLimit() + 0.5);
108 
109  TH2D h2("h2", NULL,
110  string.getLength() + 1,
111  string.getLowerLimit() - 0.5,
112  string.getUpperLimit() + 0.5,
113  floor.getLength() + 1,
114  floor.getLowerLimit() - 0.5,
115  floor.getUpperLimit() + 0.5);
116 
117  JTimer t1("map");
118  JTimer t2("router");
119 
120  while (inputFile.hasNext()) {
121 
122  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
123 
124  const Evt* event = inputFile.next();
125 
126  t1.start();
127 
128  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
129 
130  const JLocation& pos = zmap[hit->pmt_id];
131 
132  h1.Fill((double) pos.getString(), (double) pos.getFloor());
133  }
134 
135  t1.stop();
136  }
137  STATUS(endl);
138 
139  inputFile.rewind();
140 
141  while (inputFile.hasNext()) {
142 
143  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
144 
145  const Evt* event = inputFile.next();
146 
147  t2.start();
148 
149  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
150 
151  const JLocation& pos = router.getParentModule(hit->pmt_id);
152 
153  h2.Fill((double) pos.getString(), (double) pos.getFloor());
154  }
155 
156  t2.stop();
157  }
158  STATUS(endl);
159 
160  t1.print(cout);
161  t2.print(cout);
162 
163  out.Write();
164  out.Close();
165 }
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
range_type include(argument_type x)
Include given value to range.
Definition: JRange.hh:398
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
string outputFile
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Detector file.
Definition: JHead.hh:196
Logical location of module.
Definition: JLocation.hh:37
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
Auxiliary class for CPU timing and usage.
Definition: JTimer.hh:32
#define NOTICE(A)
Definition: JMessage.hh:64
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
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.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
do set_variable DETECTOR_TXT $WORKDIR detector
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19