Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JConvertEvt.cc File Reference
#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include "TROOT.h"
#include "TFile.h"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "km3net-dataformat/offline/io_ascii.hh"
#include "km3net-dataformat/offline/io_online.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JHeadToolkit.hh"
#include "JDAQ/JDAQEventIO.hh"
#include "JDAQ/JDAQSummarysliceIO.hh"
#include "JSupport/JParallelFileScanner.hh"
#include "JSupport/JTreeScanner.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JSupport/JSupportToolkit.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JMeta.hh"
#include "JReconstruction/JEvt.hh"
#include "JReconstruction/JEvtToolkit.hh"
#include "Jeep/JeepToolkit.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 Auxiliary program to convert fit results to AAnet format. More...
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Auxiliary program to convert fit results to AAnet format.

Author
mdejong

Definition at line 44 of file JConvertEvt.cc.

45 {
46  using namespace std;
47  using namespace JPP;
48 
49  JMultipleFileScanner<> inputFile;
51  JLimit_t& numberOfEvents = inputFile.getLimit();
53  size_t numberOfFits;
54  int debug;
55 
56  try {
57 
58  JParser<> zap("Auxiliary program to convert fit results to AAnet format.\
59  \nThe option -L corresponds to the names of a shared library \
60  \nand function so to rearrange the order of fit results.");
61 
62  zap['f'] = make_field(inputFile);
63  zap['o'] = make_field(outputFile) = "aanet.root";
64  zap['n'] = make_field(numberOfEvents) = JLimit::max();
66  zap['N'] = make_field(numberOfFits) = 0;
67  zap['d'] = make_field(debug) = 2;
68 
69  zap(argc, argv);
70  }
71  catch(const exception& error) {
72  FATAL(error.what() << endl);
73  }
74 
75  using namespace KM3NETDAQ;
76 
77  typedef JParallelFileScanner< JTypeList<JDAQEvent, JEvt> > JParallelFileScanner_t;
78  typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
79 
80  outputFile.open();
81 
82  Head header;
83 
84  try {
85  header = getHeader(inputFile);
86  } catch(const exception& error) {}
87  {
88  JHead buffer(header);
89 
90  buffer.DAQ.livetime_s = getLivetime(inputFile.begin(), inputFile.end());
91  buffer.push(&JHead::DAQ);
92 
93  copy(buffer, header);
94  }
95 
96  outputFile.put(header);
97 
98 
99  outputFile.put(JMeta(argc, argv));
100 
101 
102  counter_type number_of_events = 0;
103 
104  for (JMultipleFileScanner<>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
105 
106  STATUS("Processing: " << *i << endl);
107 
108  JParallelFileScanner_t in(*i);
109  JTreeScanner<Evt> mc(*i);
110 
111  Vec center(0,0,0);
112 
113  int mc_run_id = 0;
114 
115  try {
116 
117  const JHead head(getHeader(*i));
118 
119  center = get<Vec>(head);
120  mc_run_id = head.start_run.run_id;
121 
122  } catch(const exception& error) {}
123 
124 
125  while (in.hasNext()) {
126 
127  STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
128 
129  multi_pointer_type ps = in.next();
130 
131  JDAQEvent* tev = ps;
132  JEvt* evt = ps;
133 
134  JEvt::iterator __end = evt->end();
135 
136  if (numberOfFits > 0) {
137  advance(__end = evt->begin(), min(numberOfFits, evt->size()));
138  }
139 
140  if (qualitySorter.is_valid()) {
141  partial_sort(evt->begin(), __end, evt->end(), qualitySorter);
142  }
143 
144  Evt out;
145 
146  if (mc.getEntries() != 0) {
147 
148  Evt* event = mc.getEntry(tev->getCounter());
149 
150  if (event != NULL) {
151 
152  out = *event;
153 
154  if (out.mc_run_id == 0) {
155  out.mc_run_id = mc_run_id;
156  }
157 
158  for (vector<Trk>::iterator i = out.mc_trks.begin(); i != out.mc_trks.end(); ++i) {
159  i->pos += center;
160  }
161  }
162  }
163 
164  read(out, *tev);
165 
166  for (JEvt::const_iterator fit = evt->begin(); fit != __end; ++fit) {
167 
168  Trk tr;
169 
170  tr.id = out.trks.size() + 1;
171  tr.pos = Vec(fit->getX(), fit->getY(), fit->getZ());
172  tr.dir = Vec(fit->getDX(), fit->getDY(), fit->getDZ());
173  tr.t = fit->getT();
174  tr.E = fit->getE();
175  tr.lik = fit->getQ();
176 
178 
179  for (JHistory::const_iterator i = fit->getHistory().begin(); i != fit->getHistory().end(); ++i) {
180  tr.rec_stages.push_back(i->type);
181  }
182 
183  for (int i = 0; i != fit->getN(); ++i) {
184  tr.fitinf.push_back(fit->getW(i));
185  }
186 
187  out.trks.push_back(tr);
188  }
189 
190  out.id = ++number_of_events;
191 
192  outputFile.put(out);
193  }
194  }
195 
196  STATUS(endl);
197 
199 
200  io >> outputFile;
201 
202  outputFile.close();
203 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:71
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1493
double t
track time [ns] (when the particle is at pos )
Definition: Trk.hh:17
#define STATUS(A)
Definition: JMessage.hh:63
bool read(Vec &v, std::istream &is)
Read a Vec(tor) from a stream.
Definition: io_ascii.hh:139
Vec dir
track direction
Definition: Trk.hh:16
General purpose sorter of fit results.
Definition: JEvtToolkit.hh:262
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
General purpose class for parallel reading of objects from a single file or multiple files...
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:63
Long64_t counter_type
Type definition for counter.
string outputFile
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:18
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:12
int mc_run_id
MC run identifier.
Definition: Evt.hh:26
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
std::vector< double > fitinf
place to store additional fit info, for jgandalf, see JFitParameters.hh
Definition: Trk.hh:29
int debug
debug level
Definition: JSirene.cc:61
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
Monte Carlo run header.
Definition: JHead.hh:836
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:66
#define FATAL(A)
Definition: JMessage.hh:67
int id
track identifier
Definition: Trk.hh:14
Vec pos
postion of the track at time t [m]
Definition: Trk.hh:15
Data structure for set of track fit results.
Definition: JEvt.hh:294
std::vector< Trk > trks
list of reconstructed tracks (can be several because of prefits,showers, etc).
Definition: Evt.hh:36
double getLivetime(const std::string &file_name)
Get data taking live time.
std::vector< int > rec_stages
list of identifyers of succesfull fitting stages resulting in this track
Definition: Trk.hh:24
double lik
likelihood or lambda value (for aafit, lambda)
Definition: Trk.hh:21
static const int JPP_RECONSTRUCTION_TYPE
KM3NeT Data Definitions v1.2.3-3-g5bd09ee https://git.km3net.de/common/km3net-dataformat.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:153
int id
offline event identifier
Definition: Evt.hh:21
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:12
JTriggerCounter_t getCounter() const
Get trigger counter.
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
Definition: Evt.hh:45
bool qualitySorter(const JRECONSTRUCTION::JFit &first, const JRECONSTRUCTION::JFit &second)
Comparison of fit results.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
int rec_type
identifyer for the overall fitting algorithm/chain/strategy
Definition: Trk.hh:23