Jpp  17.3.1
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 
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:1517
General exception.
Definition: JException.hh:23
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
range_type & include(argument_type x)
Include given value to range.
Definition: JRange.hh:397
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
string outputFile
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:1993
Auxiliary class for CPU timing and usage.
Definition: JTimer.hh:32
#define NOTICE(A)
Definition: JMessage.hh:64
#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.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
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