Jpp  pmt_effective_area_update_2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Jaws.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <vector>
5 #include <map>
6 #include <bitset>
7 
10 
11 #include "JDAQ/JDAQTimesliceIO.hh"
13 #include "JSupport/JSupport.hh"
16 #include "JTools/JRange.hh"
17 #include "JSystem/JKeypress.hh"
18 #include "Jeep/JPrint.hh"
19 #include "Jeep/JParser.hh"
20 #include "Jeep/JMessage.hh"
21 
22 
23 namespace {
24 
25  using KM3NETDAQ::JDAQHit;
26 
27  /**
28  * Auxiliary class to search for periodic hits.
29  */
30  struct JPeriod {
31  /**
32  * Default constructor.
33  */
34  JPeriod() :
35  period(-1),
36  margin(-1)
37  {}
38 
39 
40  /**
41  * Constructor.
42  *
43  * \param period period [ns]
44  * \param margin margin [ns]
45  */
46  JPeriod(int period,
47  int margin) :
48  period(period),
49  margin(margin)
50  {}
51 
52  /**
53  * Check compliance with periodicity.
54  *
55  * \param first first hit
56  * \param second second hit
57  * \return true if periodic; else false
58  */
59  bool operator()(const JDAQHit& first, const JDAQHit& second) const
60  {
61  const int t1 = (second.getT() - first.getT()) % period;
62 
63  return (t1 <= margin || t1 >= period - margin);
64  }
65 
66  /**
67  * Read periodicity from input stream.
68  *
69  * \param in input stream
70  * \param object periodicity
71  * \return input stream
72  */
73  friend std::istream& operator>>(std::istream& in, JPeriod& object)
74  {
75  return in >> object.period >> object.margin;
76  }
77 
78  /**
79  * Write periodicity to output stream.
80  *
81  * \param out output stream
82  * \param object periodicity
83  * \return output stream
84  */
85  friend std::ostream& operator<<(std::ostream& out, const JPeriod& object)
86  {
87  return out << object.period << ' ' << object.margin;
88  }
89 
90  int period;
91  int margin;
92  };
93 }
94 
95 
96 /**
97  * \file
98  * Example program to search for spurious hits.
99  * \author mdejong
100  */
101 int main(int argc, char **argv)
102 {
103  using namespace std;
104  using namespace JPP;
105  using namespace KM3NETDAQ;
106 
107  typedef JRange<int> JRange_t;
108 
110  JLimit_t& numberOfEvents = inputFile.getLimit();
111  JROOTClassSelector selector;
112  JRange_t ToT_ns;
113  JPeriod is_periodic;
114  int numberOfHits;
115  int numberOfColumns;
117  int debug;
118 
119  try {
120 
121  JParser<> zap("Example program to search for spurious hits.");
122 
123  zap['f'] = make_field(inputFile, "input file).");
124  zap['n'] = make_field(numberOfEvents) = JLimit::max();
125  zap['C'] = make_field(selector, "timeslice selector, e.g. JDAQTimeslice.") = getROOTClassSelection<JDAQTimesliceTypes_t>();
126  zap['T'] = make_field(ToT_ns, "time-over-threshold range [ns]");
127  zap['p'] = make_field(is_periodic, "periodicity");
128  zap['M'] = make_field(numberOfHits, "minimum number of hits for periodicity");
129  zap['N'] = make_field(numberOfColumns, "number of columns for printing") = 5;
130  zap['V'] = make_field(veto, "veto PMT from analysis") = JPARSER::initialised();
131  zap['d'] = make_field(debug, "debug.") = 3;
132 
133  zap(argc, argv);
134  }
135  catch(const exception& error) {
136  FATAL(error.what() << endl);
137  }
138 
139 
140  cout.tie(&cerr);
141 
143 
144  for (counter_type counter = 0; in.hasNext() && counter != inputFile.getLimit(); ++counter) {
145 
146  STATUS("event: " << setw(10) << counter << '\r'); DEBUG(endl);
147 
148  const JDAQTimeslice* timeslice = in.next();
149 
150  for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
151 
152  // organise data per PMT
153 
154  typedef vector<JDAQHit> buffer1D_type;
155  typedef vector<buffer1D_type> buffer2D_type;
156 
157  buffer2D_type buffer(numeric_limits<JDAQHit::JPMT_t>::max(), buffer1D_type());
158 
159  for (JDAQFrame::const_iterator hit = frame->begin(); hit != frame->end(); ++hit) {
160  buffer[hit->getPMT()].push_back(*hit);
161  }
162 
163  // detection of perodic signal
164 
166 
167  for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
168 
169  if (!buffer[pmt].empty()) {
170 
171  const JDAQPMTIdentifier id(frame->getModuleID(), pmt);
172 
173  for (buffer1D_type::iterator i = buffer[pmt].begin(); i != buffer[pmt].end(); ) {
174 
175  if (ToT_ns(i->getToT())) {
176 
177  buffer1D_type::iterator p = i;
178 
179  for (++p; p != buffer[pmt].end() && ToT_ns(p->getToT()) && is_periodic(*i, *p); ++p) {}
180 
181  if (distance(i, p) >= numberOfHits) {
182  top[id].push_back(*i);
183  }
184 
185  i = p;
186 
187  } else {
188 
189  ++i;
190  }
191  }
192  }
193  }
194 
195 
196  if (debug >= debug_t) {
197 
198  for (map<JDAQPMTIdentifier, vector<JDAQHit> >::const_iterator i = top.begin(); i != top.end(); ++i) {
199 
200  if (veto.count(i->first) == 0) {
201 
202  const int pmt = i->first.getPMTAddress();
203 
204  cout << timeslice->getRunNumber() << '/' << FILL(6,'0') << timeslice->getFrameIndex() << FILL() << ' '
205  << setw(9) << i->first.getModuleID() << '.' << FILL(2,'0') << i->first.getPMTAddress() << FILL() << ' '
206  << setw(1) << frame->testHighRateVeto(pmt)
207  << setw(1) << frame->testFIFOStatus (pmt) << endl;
208 
209  int count = 0;
210 
211  string eol = "";
212 
213  for (JDAQFrame::const_iterator hit = frame->begin(); hit != frame->end(); ++hit) {
214 
215  const bool has_pmt = (hit->getPMT() == i->first.getPMTAddress());
216  const bool has_hit = (find(i->second.begin(), i->second.end(), *hit) != i->second.end());
217 
218  if (has_pmt) {
219 
220  if (has_hit) {
221  eol = "*";
222  }
223 
224  cout << setw(10) << hit->getT() << ' ' << setw(3) << (int) hit->getToT() << ' ' << RESET;
225 
226  if ((++count % numberOfColumns) == 0) {
227 
228  cout << eol << endl;
229 
230  eol = "";
231  }
232  }
233  }
234 
235  cout << endl << "press any key to continue> " << flush;
236 
237  JKeypress(false).get();
238 
239  cout << endl;
240  }
241  }
242  }
243  }
244  }
245  STATUS(endl);
246 }
Utility class to parse command line options.
Definition: JParser.hh:1500
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
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.
#define STATUS(A)
Definition: JMessage.hh:63
Auxiliary class to select ROOT class based on class name.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
Long64_t counter_type
Type definition for counter.
Auxiliary class for multiplexing object iterators.
JTDC_t getT() const
Get time.
Definition: JDAQHit.hh:86
int getRunNumber() const
Get run number.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
int getFrameIndex() const
Get frame index.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
I/O formatting auxiliaries.
char get()
Get single character.
Definition: JKeypress.hh:74
Keyboard settings for unbuffered input.
Hit data structure.
Definition: JDAQHit.hh:34
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
Enable unbuffered terminal input.
Definition: JKeypress.hh:32
Data time slice.
virtual const pointer_type & next() override
Get next element.
int debug
debug level
Definition: JSirene.cc:63
virtual bool hasNext() override
Check availability of next element.
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
Definition: JHead.hh:1618
std::vector< int > count
Definition: JAlgorithm.hh:180
Auxiliary class to define a range between two values.
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
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:40