Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDAQHitRouter.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 
6 #include "TROOT.h"
7 #include "TFile.h"
8 #include "TH1D.h"
9 #include "TH2D.h"
10 
11 #include "JTools/JRange.hh"
12 
13 #include "JDAQ/JDAQEventIO.hh"
14 #include "JDetector/JDetector.hh"
18 
20 #include "JSupport/JSupport.hh"
21 
22 #include "Jeep/JParser.hh"
23 #include "Jeep/JMessage.hh"
24 
25 
26 /**
27  * \file
28  *
29  * Example program to histogram string and floor hits.
30  * \author mdejong
31  */
32 int main(int argc, char **argv)
33 {
34  using namespace std;
35  using namespace JPP;
36  using namespace KM3NETDAQ;
37 
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 histogram string and floor hits.");
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) = 2;
53 
54  zap(argc, argv);
55  }
56  catch(const exception& error) {
57  FATAL(error.what() << endl);
58  }
59 
60 
61 
62 
63  cout.tie(&cerr);
64 
65 
67 
68  try {
69  load(detectorFile, detector);
70  }
71  catch(const JException& error) {
72  FATAL(error);
73  }
74 
75  const JDAQHitRouter router(detector);
76  const JStringRouter string(detector);
77 
78 
79  TFile out(outputFile.c_str(), "recreate");
80 
81  TH1D h1("h1", NULL, 100, 0.0, 1.0e1);
82  TH2D h2("h2", NULL,
85 
86  for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
87  h2.GetXaxis()->SetBinLabel(i, MAKE_CSTRING(string.at(i-1)));
88  }
89  for (Int_t i = 1; i <= h2.GetYaxis()->GetNbins(); ++i) {
90  h2.GetYaxis()->SetBinLabel(i, MAKE_CSTRING(i));
91  }
92 
93  TH2D* h3 = (TH2D*) h2.Clone("h3");
94 
95  while (inputFile.hasNext()) {
96 
97  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
98 
99  JDAQEvent* event = inputFile.next();
100 
101  JTimeRange tx = JTimeRange::DEFAULT_RANGE;
102 
103  {
104  typedef JDAQTriggeredHit JHit_t;
105 
106  for (JDAQEvent::const_iterator<JHit_t> hit = event->begin<JHit_t>(); hit != event->end<JHit_t>(); ++hit) {
107 
108  const JPMTChannel& channel = router.getPMTChannel(*hit);
109 
110  h2.Fill((double) string.getIndex(channel.getString()), (double) channel.getFloor());
111 
112  tx.include(getTime(*hit, router.getPMT(*hit)));
113  }
114  }
115 
116  h1.Fill(tx.getLength() * 1.0e-3);
117 
118  {
119  typedef JDAQSnapshotHit JHit_t;
120 
121  for (JDAQEvent::const_iterator<JHit_t> hit = event->begin<JHit_t>(); hit != event->end<JHit_t>(); ++hit) {
122 
123  const JPMTChannel& channel = router.getPMTChannel(*hit);
124 
125  h3->Fill((double) string.getIndex(channel.getString()), (double) channel.getFloor());
126  }
127  }
128  }
129  STATUS(endl);
130 
131  out.Write();
132  out.Close();
133 }
Auxiliary class to set-up Hit.
Definition: JHit_t.hh:25
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
Direct access to PMT data in detector data structure for DAQ hits.
DAQ key hit.
Definition: JDAQKeyHit.hh:19
Auxiliary class to uniquely identify PMT readout channel.
Definition: JPMTChannel.hh:28
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
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:80
Template const_iterator.
Definition: JDAQEvent.hh:68
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
double getTime(const Hit &hit)
Get true time of hit.
string outputFile
Data structure for detector geometry and calibration.
Simple wrapper around JModuleRouter class for direct addressing of PMT data in detector data structur...
T getLength() const
Get length (difference between upper and lower limit).
Definition: JRange.hh:289
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Detector file.
Definition: JHead.hh:196
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int getNumberOfFloors(const JDetector &detector)
Get number of floors.
int getIndex()
Get index for user I/O manipulation.
Definition: JManip.hh:26
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
static const JStringCounter getNumberOfStrings
Function object to count unique strings.
Direct access to string in detector data structure.
#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.
Auxiliary class to define a range between two values.
Router for mapping of string identifier to index.
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:73
do set_variable DETECTOR_TXT $WORKDIR detector
const JPMT & getPMT(const JDAQKeyHit &hit) const
Get PMT parameters.
JPMTChannel getPMTChannel(const JDAQKeyHit &hit) const
Get PMT channel.
JTriggerCounter_t next()
Increment trigger counter.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62