Jpp  master_rocky-37-gf0c5bc59d
the software that should make you happy
JDK.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <cmath>
6 
11 
15 #include "JSupport/JSupport.hh"
16 #include "JSupport/JMeta.hh"
17 
18 #include "JAAnet/JAAnetToolkit.hh"
19 
20 #include "Jeep/JParser.hh"
21 #include "Jeep/JMessage.hh"
22 
23 
24 /**
25  * \file
26  *
27  * Example program to filter out-of-time hits in Evt data.
28  * \author mdejong
29  */
30 int main(int argc, char **argv)
31 {
32  using namespace std;
33  using namespace JPP;
34  using namespace KM3NETDAQ;
35 
36  JMultipleFileScanner<Evt> inputFile;
38  JLimit_t& numberOfEvents = inputFile.getLimit();
39  double T_ns;
40  int debug;
41 
42  try {
43 
44  JParser<> zap("Example program to filter out-of-time hits in Evt data.");
45 
46  zap['f'] = make_field(inputFile);
47  zap['o'] = make_field(outputFile);
48  zap['n'] = make_field(numberOfEvents) = JLimit::max();
49  zap['T'] = make_field(T_ns) = getFrameTime();
50  zap['d'] = make_field(debug) = 2;
51 
52  zap(argc, argv);
53  }
54  catch(const exception& error) {
55  FATAL(error.what() << endl);
56  }
57 
58  outputFile.open();
59 
60  if (!outputFile.is_open()) {
61  FATAL("Error opening file " << outputFile << endl);
62  }
63 
64  outputFile.put(JMeta(argc, argv));
65  outputFile.put(getHeader(inputFile));
66 
67  long long int number_of_hits[] = { 0, 0 };
68 
69  while (inputFile.hasNext()) {
70 
71  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
72 
73  Evt* evt = inputFile.next();
74 
75  number_of_hits[0] += evt->mc_hits.size();
76 
77  double t0 = numeric_limits<double>::max();
78 
79  for (vector<Hit>::iterator hit = evt->mc_hits.begin(); hit != evt->mc_hits.end(); ++hit) {
80  if (getTime(*hit) < t0) {
81  t0 = getTime(*hit);
82  }
83  }
84 
85  vector<Hit>::iterator __end = evt->mc_hits.end();
86 
87  for (vector<Hit>::iterator hit = evt->mc_hits.begin(); hit != __end; ) {
88  if (getTime(*hit) <= t0 + T_ns)
89  ++hit;
90  else
91  iter_swap(hit, --__end);
92  }
93 
94  number_of_hits[1] += distance(__end, evt->mc_hits.end());
95 
96  evt->mc_hits.erase(__end, evt->mc_hits.end());
97 
98  outputFile.put(*evt);
99  }
100  STATUS(endl);
101 
102  cout << "Number of hits processed/removed " << number_of_hits[0] << "/" << number_of_hits[1] << endl;
103 
105 
106  io >> outputFile;
107 
108  outputFile.close();
109 }
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
string outputFile
int main(int argc, char **argv)
Definition: JDK.cc:30
Recording of objects on file according a format that follows from the file name extension.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define STATUS(A)
Definition: JMessage.hh:63
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
ROOT I/O of application specific meta data.
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
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.
Utility class to parse command line options.
Definition: JParser.hh:1698
Object writing to file.
virtual bool hasNext() override
Check availability of next element.
counter_type getCounter() const
Get counter.
virtual const pointer_type & next() override
Get next element.
double getTime(const Hit &hit)
Get true time of hit.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
Definition: JSTDTypes.hh:14
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:21
std::vector< Hit > mc_hits
MC: list of MC truth hits.
Definition: Evt.hh:48
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