Jpp  master_rocky-43-ge265d140c
the software that should make you happy
JAnglerFish.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "TROOT.h"
6 #include "TFile.h"
7 #include "TH1D.h"
8 
13 
14 #include "JDAQ/JDAQTimesliceIO.hh"
16 #include "JDAQ/JDAQEventIO.hh"
18 
21 #include "JSupport/JSupport.hh"
22 #include "JSupport/JMeta.hh"
23 
24 #include "JROOT/JManager.hh"
25 
26 #include "Jeep/JParser.hh"
27 #include "Jeep/JMessage.hh"
28 
30 /**
31  * \file
32  *
33  * Example application to search for sets of consecutive hits on a given PMT,\n
34  * that are separated in time by a constant value. The number of consecutive hits\n
35  * as well as the time difference are selected from the command line.\n
36  * The searches are done within the JDAQSnapshotHits from JDAQEvents\
37  * as well as within the JDAQHits from the JDAQTimeslice data.
38  *
39  * \author rgruiz
40  */
41 int main(int argc, char **argv)
42 {
43  using namespace std;
44  using namespace JPP;
45  using namespace KM3NETDAQ;
46 
48 
49  string inputFile;
50  JLimit_t numberOfEvents;
52  string detectorFile;
53  int deltaT;
54  int multiplicity;
55  int debug;
56 
57  try {
58 
59  JParser<> zap("Program to search for sets of consecutive hits on a given PMT that are equidistant in time.");
60 
61  zap['f'] = make_field(inputFile);
62  zap['a'] = make_field(detectorFile);
63  zap['t'] = make_field(deltaT) = 255;
64  zap['m'] = make_field(multiplicity) = 3;
65  zap['o'] = make_field(outputFile) = "anglerfish.root";
66  zap['n'] = make_field(numberOfEvents) = JLimit::max();
67  zap['d'] = make_field(debug) = 1;
68 
69  zap(argc, argv);
70  }
71  catch(const exception& error) {
72  FATAL(error.what() << endl);
73  }
74 
75  outputFile.open();
76 
77  if (!outputFile.is_open()) FATAL("Error opening file " << outputFile << endl);
78 
79  outputFile.put(JMeta(argc, argv));
80 
82 
83  try {
84  load (detectorFile, detector);
85  }
86  catch(const JException & error) {
87  cerr << "FATAL ERROR. Could not open detector file '" << detectorFile << "'." << endl;
88  exit(1);
89  }
90 
91  const floor_range range = getRangeOfFloors(detector);
92 
93  const JStringRouter stringRouter(detector);
94 
95  TH1D h1 ("MEvt", "", 50, 0.5, 50.5);
96 
97  TH2D h2 ("FEvt", NULL,
98  stringRouter.size() + 0, -0.5, stringRouter.size() - 0.5,
99  range.getLength() + 1, range.getLowerLimit() - 0.5, range.getUpperLimit() + 0.5);
100 
101  TH1D h3 ("ML0" , "", 50, 0.5, 50.5);
102 
103  TH2D h4 ("FL0", NULL,
104  stringRouter.size() + 0, -0.5, stringRouter.size() - 0.5,
105  range.getLength() + 1, range.getLowerLimit() - 0.5, range.getUpperLimit() + 0.5);
106 
107  for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
108  h2.GetXaxis()->SetBinLabel(i, MAKE_CSTRING(stringRouter.at(i-1)));
109  }
110 
111  for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
112  h4.GetXaxis()->SetBinLabel(i, MAKE_CSTRING(stringRouter.at(i-1)));
113  }
114 
115  const JDAQHitRouter hitRouter(detector);
116 
117  {
118  typedef JDAQSnapshotHit JHit_t;
119  typedef vector<JHit_t> JHitBuffer;
120 
121  for (JMultipleFileScanner<JDAQEvent> in(inputFile, numberOfEvents); in.hasNext(); ){
122 
123  JDAQEvent* event = in.next();
124  JHitBuffer& buffer = event->getHits<JHit_t>();
125 
126  std::sort(buffer.begin(),buffer.end(),less<JDAQKeyHit>());
127 
128  for (JHitBuffer::const_iterator p = buffer.begin() ; p != buffer.end() ; ) {
129 
130  JHitBuffer::const_iterator q = p;
131 
132  for (JDAQHit::JTDC_t t1 = p->getT();
133  (++q != buffer.end() &&
134  q->getModuleID() == p->getModuleID() &&
135  q->getPMT() == p->getPMT() &&
136  q->getT() == t1 + deltaT);
137  t1 = q->getT()) {}
138 
139  int d = distance(p,q);
140 
141  const JPMTChannel& channel = hitRouter.getPMTChannel(*p);
142 
143  if (d >= multiplicity)
144  h2.Fill((double) stringRouter.getIndex(channel.getString()), (double) channel.getFloor());
145 
146  if (d >= 2)
147  h1.Fill(d);
148 
149  p=q;
150  }
151  }
152  }
153 
154  {
155  typedef JDAQHit JHit_t;
156  typedef vector<JHit_t> JHitBuffer;
157  typedef JSuperFrame2D<JHit_t> JSuperFrame2D_t;
158 
159  const JModuleRouter moduleRouter(detector);
160 
161  for (JMultipleFileScanner<JDAQTimeslice> in(inputFile, numberOfEvents); in.hasNext(); ) {
162 
163  JDAQTimeslice* slice = in.next();
164 
165  for(JDAQTimeslice::iterator frame = slice->begin(); frame != slice->end() ; ++frame){
166 
167  const JModule& module = moduleRouter.getModule(frame->getModuleID());
168  JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*frame, module);
169 
170  for (JSuperFrame2D_t::iterator pmt = buffer.begin() ; pmt != buffer.end() ; ++pmt) {
171 
172  for (JHitBuffer::const_iterator p = pmt->begin() ; p != pmt->end() ;) {
173 
174  JHitBuffer::const_iterator q = p;
175 
176  for (JDAQHit::JTDC_t t1 = p->getT();
177  (++q != pmt->end() &&
178  q->getT() == t1 + deltaT);
179  t1 = q->getT()) {}
180 
181  int d = distance(p,q);
182 
183  const JPMTChannel& channel = hitRouter.getPMTChannel(JDAQKeyHit(frame->getModuleID(),*p));
184 
185  if (d >= multiplicity)
186  h4.Fill((double) stringRouter.getIndex(channel.getString()), (double) channel.getFloor());
187 
188  if (d >= 2)
189  h3.Fill(d);
190 
191  p=q;
192  }
193  }
194  }
195  }
196  }
197 
198  outputFile.put(h1);
199  outputFile.put(h2);
200  outputFile.put(h3);
201  outputFile.put(h4);
202 
203  outputFile.close();
204 }
int main(int argc, char **argv)
Definition: JAnglerFish.cc:41
Direct access to PMT data in detector data structure for DAQ hits.
string outputFile
Recording of objects on file according a format that follows from the file name extension.
Dynamic ROOT object management.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
ROOT I/O of application specific meta data.
Direct access to module in detector data structure.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:72
Direct access to string in detector data structure.
ROOT TTree parameter settings of various packages.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Simple wrapper around JModuleRouter class for direct addressing of PMT data in detector data structur...
JPMTChannel getPMTChannel(const JDAQKeyHit &hit) const
Get PMT channel.
Detector data structure.
Definition: JDetector.hh:96
int getFloor() const
Get floor number.
Definition: JLocation.hh:146
int getString() const
Get string number.
Definition: JLocation.hh:135
Router for direct addressing of module data in detector data structure.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition: JModule.hh:75
Auxiliary class to uniquely identify PMT readout channel.
Definition: JPMTChannel.hh:35
General exception.
Definition: JException.hh:24
Utility class to parse command line options.
Definition: JParser.hh:1698
Object writing to file.
General purpose class for object reading from a list of file names.
virtual bool hasNext() override
Check availability of next element.
int getIndex(const T &value) const
Get index of given value.
T getLength() const
Get length (difference between upper and lower limit).
Definition: JRange.hh:289
T getLowerLimit() const
Get lower limit.
Definition: JRange.hh:202
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:213
2-dimensional frame with time calibrated data from one optical module.
Hit data structure.
Definition: JDAQHit.hh:35
unsigned int JTDC_t
leading edge [ns]
Definition: JDAQHit.hh:39
JTriggerCounter_t next()
Increment trigger counter.
floor_range getRangeOfFloors(const JDetector &detector)
Get range of floors.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
Definition: JSTDTypes.hh:14
Detector file.
Definition: JHead.hh:227
Router for mapping of string identifier to index.
Type list.
Definition: JTypeList.hh:23
Auxiliary class to set-up Hit.
Definition: JSirene.hh:58
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:45
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:72