Jpp  16.0.0-rc.2
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 "JROOT/JManager.hh"
14 #include "JROOT/JRootToolkit.hh"
15 
16 #include "JDAQ/JDAQEventIO.hh"
17 #include "JDetector/JDetector.hh"
21 
23 #include "JSupport/JSupport.hh"
24 
25 #include "Jeep/JParser.hh"
26 #include "Jeep/JMessage.hh"
27 
28 
29 /**
30  * \file
31  *
32  * Example program to histogram string and floor hits.
33  * \author mdejong
34  */
35 int main(int argc, char **argv)
36 {
37  using namespace std;
38  using namespace JPP;
39  using namespace KM3NETDAQ;
40 
42  JLimit_t& numberOfEvents = inputFile.getLimit();
43  string outputFile;
44  string detectorFile;
45  int debug;
46 
47  try {
48 
49  JParser<> zap("Example program to histogram string and floor hits.");
50 
51  zap['f'] = make_field(inputFile);
52  zap['o'] = make_field(outputFile) = "router.root";
53  zap['a'] = make_field(detectorFile);
54  zap['n'] = make_field(numberOfEvents) = JLimit::max();
55  zap['d'] = make_field(debug) = 2;
56 
57  zap(argc, argv);
58  }
59  catch(const exception& error) {
60  FATAL(error.what() << endl);
61  }
62 
63 
64 
65 
66  cout.tie(&cerr);
67 
68 
70 
71  try {
72  load(detectorFile, detector);
73  }
74  catch(const JException& error) {
75  FATAL(error);
76  }
77 
79 
80  const JDAQHitRouter router(detector);
81  const JStringRouter string(detector);
82 
83 
84  TH1D h1("h1", NULL, 100, 0.0, 1.0e1);
85 
86  JManager<int, TH2D> H2(new TH2D("h2[%]", NULL,
88  range.getUpperLimit(), 1 - 0.5, range.getUpperLimit() + 0.5));
89 
90  for (Int_t i = 1; i <= H2->GetXaxis()->GetNbins(); ++i) {
91  H2->GetXaxis()->SetBinLabel(i, MAKE_CSTRING(string.at(i-1)));
92  }
93  for (Int_t i = 1; i <= H2->GetYaxis()->GetNbins(); ++i) {
94  H2->GetYaxis()->SetBinLabel(i, MAKE_CSTRING(i));
95  }
96 
97  TH2D* h3 = (TH2D*) H2->Clone("h3");
98 
99  while (inputFile.hasNext()) {
100 
101  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
102 
103  JDAQEvent* event = inputFile.next();
104 
105  JTimeRange tx = JTimeRange::DEFAULT_RANGE;
106 
107  {
108  typedef JDAQTriggeredHit JHit_t;
109 
110  for (JDAQEvent::const_iterator<JHit_t> hit = event->begin<JHit_t>(); hit != event->end<JHit_t>(); ++hit) {
111 
112  const JPMTChannel& channel = router.getPMTChannel(*hit);
113 
114  H2->Fill((double) string.getIndex(channel.getString()), (double) channel.getFloor());
115 
116  for (int i = 0; i != NUMBER_OF_TRIGGER_BITS; ++i) {
117  if (hit->hasTriggerBit(i)) {
118  H2[i]->Fill((double) string.getIndex(channel.getString()), (double) channel.getFloor());
119  }
120  }
121 
122  tx.include(getTime(*hit, router.getPMT(*hit)));
123  }
124  }
125 
126  h1.Fill(tx.getLength() * 1.0e-3);
127 
128  {
129  typedef JDAQSnapshotHit JHit_t;
130 
131  for (JDAQEvent::const_iterator<JHit_t> hit = event->begin<JHit_t>(); hit != event->end<JHit_t>(); ++hit) {
132 
133  const JPMTChannel& channel = router.getPMTChannel(*hit);
134 
135  h3->Fill((double) string.getIndex(channel.getString()), (double) channel.getFloor());
136  }
137  }
138  }
139  STATUS(endl);
140 
141  TFile out(outputFile.c_str(), "recreate");
142 
143  out << h1;
144  out << *H2;
145  out << H2;
146  out << *h3;
147 
148  out.Write();
149  out.Close();
150 }
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:30
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
static const unsigned int NUMBER_OF_TRIGGER_BITS
Number of trigger bits.
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
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:71
Dynamic ROOT object management.
double getTime(const Hit &hit)
Get true time of hit.
string outputFile
floor_range getRangeOfFloors(const JDetector &detector)
Get range of floors.
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
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
Detector file.
Definition: JHead.hh:224
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
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...
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
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.
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
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.