Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEvt.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <algorithm>
6 
7 #include "TROOT.h"
8 #include "TFile.h"
9 
10 #include "evt/Head.hh"
11 #include "evt/Evt.hh"
12 #include "evt/io_ascii.hh"
13 #include "evt/io_jpp.hh"
14 
15 #include "JAAnet/JHead.hh"
16 #include "JAAnet/JHeadToolkit.hh"
17 
18 #include "JDAQ/JDAQEvent.hh"
19 
21 #include "JSupport/JTreeScanner.hh"
25 #include "JSupport/JSupport.hh"
26 #include "JSupport/JMeta.hh"
27 
28 #include "JFit/JEvt.hh"
29 #include "JFit/JEvtToolkit.hh"
30 
31 #include "Jeep/JeepToolkit.hh"
32 #include "Jeep/JParser.hh"
33 #include "Jeep/JMessage.hh"
34 
35 
36 /**
37  * \author mdejong
38  */
39 
40 /**
41  * Auxiliary program to convert fit results to AAnet format.
42  */
43 int main(int argc, char **argv)
44 {
45  using namespace std;
46  using namespace JPP;
47 
48  JMultipleFileScanner<> inputFile;
49  JFileRecorder<JTYPELIST<Head, Evt, JMeta>::typelist> outputFile;
50  JLimit_t& numberOfEvents = inputFile.getLimit();
51  JQualitySorter qualitySorter;
52  size_t numberOfFits;
53  int debug;
54 
55  try {
56 
57  JParser<> zap("Auxiliary program to convert fit results to AAnet format.\
58  \nThe option -L corresponds to the names of a shared library \
59  \nand function so to rearrange the order of fit results.");
60 
61  zap['f'] = make_field(inputFile);
62  zap['o'] = make_field(outputFile) = "aanet.root";
63  zap['n'] = make_field(numberOfEvents) = JLimit::max();
65  zap['N'] = make_field(numberOfFits) = 0;
66  zap['d'] = make_field(debug) = 2;
67 
68  zap(argc, argv);
69  }
70  catch(const exception& error) {
71  FATAL(error.what() << endl);
72  }
73 
74  using namespace KM3NETDAQ;
75 
76  typedef JParallelFileScanner< JTypeList<JDAQEvent, JEvt> > JParallelFileScanner_t;
77  typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
78 
79  outputFile.open();
80 
81  Head header;
82 
83  try {
84  header = getHeader(inputFile);
85  } catch(const exception& error) {}
86  {
87  JHead buffer(header);
88 
89  buffer.DAQ.livetime_s = getLivetime(inputFile.begin(), inputFile.end());
90 
91  push(buffer, &JHead::DAQ);
92  copy(buffer, header);
93  }
94 
95  outputFile.put(header);
96 
97 
98  outputFile.put(JMeta(argc, argv));
99 
100 
101  counter_type number_of_events = 0;
102 
103  for (JMultipleFileScanner<>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
104 
105  STATUS("Processing: " << *i << endl);
106 
107  JParallelFileScanner_t in(*i);
108  JTreeScanner<Evt> mc(*i);
109 
110  Vec center(0,0,0);
111 
112  int mc_run_id = 0;
113 
114  try {
115 
116  const JHead head(getHeader(*i));
117 
118  center = get<Vec>(head);
119  mc_run_id = head.start_run.run_id;
120 
121  } catch(const exception& error) {}
122 
123 
124  while (in.hasNext()) {
125 
126  STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
127 
128  multi_pointer_type ps = in.next();
129 
130  JDAQEvent* tev = ps;
131  JEvt* evt = ps;
132 
133  JEvt::iterator __end = evt->end();
134 
135  if (numberOfFits > 0) {
136  advance(__end = evt->begin(), min(numberOfFits, evt->size()));
137  }
138 
139  if (qualitySorter.is_valid()) {
140  partial_sort(evt->begin(), __end, evt->end(), qualitySorter);
141  }
142 
143  Evt out;
144 
145  if (mc.getEntries() != 0) {
146 
147  Evt* event = mc.getEntry(tev->getCounter());
148 
149  if (event != NULL) {
150 
151  out = *event;
152 
153  if (out.mc_run_id == 0) {
154  out.mc_run_id = mc_run_id;
155  }
156 
157  for (vector<Trk>::iterator i = out.mc_trks.begin(); i != out.mc_trks.end(); ++i) {
158  i->pos += center;
159  }
160  }
161  }
162 
163  read(out, *tev);
164 
165  for (JEvt::const_iterator fit = evt->begin(); fit != __end; ++fit) {
166 
167  Trk tr;
168 
169  tr.id = out.trks.size() + 1;
170  tr.pos = Vec(fit->getX(), fit->getY(), fit->getZ());
171  tr.dir = Vec(fit->getDX(), fit->getDY(), fit->getDZ());
172  tr.t = fit->getT();
173  tr.E = fit->getE();
174  tr.lik = fit->getQ();
175 
176  tr.rec_type = JPP_RECONSTRUCTION_TYPE;
177 
178  for (JHistory::const_iterator i = fit->getHistory().begin(); i != fit->getHistory().end(); ++i) {
179  tr.rec_stages.push_back(i->type);
180  }
181 
182  for (int i = 0; i != fit->getN(); ++i) {
183  tr.fitinf.push_back(fit->getW(i));
184  }
185 
186  out.trks.push_back(tr);
187  }
188 
189  out.id = ++number_of_events;
190 
191  outputFile.put(out);
192  }
193  }
194 
195  STATUS(endl);
196 
197  JMultipleFileScanner<JMeta> io(inputFile);
198 
199  io >> outputFile;
200 
201  outputFile.close();
202 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:71
Utility class to parse command line options.
Definition: JParser.hh:1410
#define STATUS(A)
Definition: JMessage.hh:61
Recording of objects on file according a format that follows from the file name extension.
Structure to store the ToT mean and standard deviation of the hits produced by a nanobeacon in a sour...
void push(JHead &header, T JHead::*p)
Push data of JHead for subsequent copy to Head.
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:64
Long64_t counter_type
Type definition for counter.
Definition: JCounter.hh:24
double livetime_s
Live time [s].
Definition: JHead.hh:684
string outputFile
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
JLimit JLimit_t
Type definition of limit.
Definition: JLimit.hh:214
std::istream & read(std::istream &in, JContainer_t< TString, JAllocator_t > &object, const JBool< false > &option)
Auxiliary method for reading if TString does not exist.
Definition: JParser.hh:720
const_iterator< T > end() const
Get end of data.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
Auxiliary methods for handling file names, type names and environment.
JAANET::start_run start_run
Definition: JHead.hh:851
Parallel scanning of objects from a single file or multiple files according a format that follows fro...
ROOT I/O of application specific meta data.
Support methods.
int debug
debug level
Definition: JSirene.cc:59
General purpose messaging.
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
Definition: JCounter.hh:35
Monte Carlo run header.
Definition: JHead.hh:727
int run_id
MC run number.
Definition: JHead.hh:89
#define FATAL(A)
Definition: JMessage.hh:65
double getLivetime(const std::string &file_name)
Get data taking live time.
Utility class to parse command line options.
ROOT TTree parameter settings.
bool qualitySorter(const JFIT::JFit &first, const JFIT::JFit &second)
Comparison of fit results.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:40
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:72
JAANET::DAQ DAQ
Definition: JHead.hh:870
JTriggerCounter_t getCounter() const
Get trigger counter.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60
static const int JPP_RECONSTRUCTION_TYPE
Jpp reconstruction type for AAnet.
int main(int argc, char *argv[])
Definition: Main.cpp:15