Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JConvertDusj.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 "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JHeadToolkit.hh"
#include "JDAQ/JDAQEventIO.hh"
#include "JDAQ/JDAQSummarysliceIO.hh"
#include "JSupport/JSingleFileScanner.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 "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 data to Dusj format. More...
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Auxiliary program to convert data to Dusj format.

Author
mdejong

Definition at line 45 of file JConvertDusj.cc.

46 {
47  using namespace std;
48  using namespace JPP;
49  using namespace KM3NETDAQ;
50 
53  JLimit_t& numberOfEvents = inputFile.getLimit();
54  string detectorFile;
55  int debug;
56 
57  try {
58 
59  JParser<> zap("Auxiliary program to convert data to Dusj format.");
60 
61  zap['f'] = make_field(inputFile);
62  zap['o'] = make_field(outputFile) = "dusj.evt";
63  zap['a'] = make_field(detectorFile);
64  zap['n'] = make_field(numberOfEvents) = JLimit::max();
65  zap['d'] = make_field(debug) = 2;
66 
67  zap(argc, argv);
68  }
69  catch(const exception& error) {
70  FATAL(error.what() << endl);
71  }
72 
73 
75 
76  try {
77  load(detectorFile, detector);
78  }
79  catch(const JException& error) {
80  FATAL(error);
81  }
82 
83  const JModuleRouter router(detector);
84 
85 
86  outputFile.open();
87 
88  Vec center(0,0,0);
89 
90  int mc_run_id = 0;
91 
92  Head header;
93 
94  try {
95 
96  header = getHeader(inputFile);
97 
98  JHead buffer(header);
99 
100  center = get<Vec>(buffer);
101  mc_run_id = buffer.start_run.run_id;
102 
103  } catch(const exception& error) {
104 
105  JHead buffer(header);
106 
107  buffer.start_run.run_id = getRunNumber<JDAQSummaryslice>(inputFile);
108  buffer.push(&JHead::start_run);
109 
110  copy(buffer, header);
111  }
112  {
113  JHead buffer(header);
114 
115  buffer.DAQ.livetime_s = getLivetime(inputFile);
116  buffer.push(&JHead::DAQ);
117 
118  copy(buffer, header);
119  }
120 
121  outputFile.put(header);
122  outputFile.put(JMeta(argc, argv));
123 
124  for (JTreeScanner<Evt> mc(inputFile); inputFile.hasNext(); ) {
125 
126  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
127 
128  JDAQEvent* tev = inputFile.next();
129 
130  Evt out;
131 
132  if (mc.getEntries() != 0) {
133 
134  Evt* event = mc.getEntry(tev->getCounter());
135 
136  if (event != NULL) {
137 
138  out = *event;
139 
140  if (out.mc_run_id == 0) {
141  out.mc_run_id = mc_run_id;
142  }
143 
144  for (vector<Trk>::iterator i = out.mc_trks.begin(); i != out.mc_trks.end(); ++i) {
145  i->pos += center;
146  }
147  }
148 
149  } else {
150 
151  out.mc_id = inputFile.getCounter();
152  out.mc_run_id = tev->getRunNumber();
153  }
154 
155  read(out, *tev);
156 
157  out.hits.clear();
158 
160 
161  const JModule& module = router.getModule(i->getModuleID());
162  const JPMT& pmt = module.getPMT (i->getPMT());
163 
164  Hit hit;
165 
166  hit.id = out.hits.size() + 1;
167  hit.dom_id = i->getModuleID();
168  //hit.channel_id = i->getPMT();
169  //hit.tdc = i->getT();
170  //hit.tot = i->getToT();
171  hit.pmt_id = pmt.getID();
172  hit.t = i->getT(); // getTime(i->getT(), pmt.getCalibration());
173  hit.a = i->getToT(); // getToT (i->getToT(), pmt.getCalibration());
174  //hit.pos = Vec(pmt.getX(), pmt.getY(), pmt.getZ());
175  //hit.dir = Vec(pmt.getDX(), pmt.getDY(), pmt.getDZ());
176 
177  out.hits.push_back(hit);
178  }
179 
180  // time offset
181 
182  double t0 = numeric_limits<double>::max();
183 
184  for (vector<Hit>::const_iterator i = out.hits.begin(); i != out.hits.end(); ++i) {
185  if (t0 > i->t) {
186  t0 = i->t;
187  }
188  }
189 
190  for (vector<Hit>::iterator i = out.hits.begin(); i != out.hits.end(); ++i) {
191  i->t -= t0;
192  }
193 
194  if (out.mc_t > 0.0 && t0 != numeric_limits<double>::max()) {
195  out.mc_t -= t0;
196  }
197 
198  out.id = inputFile.getCounter();
199 
200  outputFile.put(out);
201  }
202 
203  STATUS(endl);
204  /*
205  JSingleFileScanner<JTYPELIST<JDAQSummaryslice, JMeta>::typelist> io(inputFile);
206 
207  io >> outputFile;
208  */
209  outputFile.close();
210 }
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
General exception.
Definition: JException.hh:23
DAQ key hit.
Definition: JDAQKeyHit.hh:19
Data structure for a composite optical module.
Definition: JModule.hh:50
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:80
Template const_iterator.
Definition: JDAQEvent.hh:68
bool read(Vec &v, std::istream &is)
Read a Vec(tor) from a stream.
Definition: io_ascii.hh:139
Router for direct addressing of module data in detector data structure.
int pmt_id
global PMT identifier as found in evt files
Definition: Hit.hh:20
string outputFile
int getRunNumber() const
Get run number.
esac $JPP_DIR examples JDetector JTransitTime o $OUTPUT_FILE n N $NPE T $TTS_NS d $DEBUG for HISTOGRAM in tts tt2 pmt
Definition: JTransitTime.sh:36
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
const_iterator< T > end() const
Get end of data.
double a
hit amplitude (in p.e.)
Definition: Hit.hh:24
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:12
Detector file.
Definition: JHead.hh:130
int mc_run_id
MC run identifier.
Definition: Evt.hh:26
const_iterator< T > begin() const
Get begin of data.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
int mc_id
identifier of the MC event (as found in ascii or antcc file).
Definition: Evt.hh:23
int getID() const
Get identifier.
Definition: JObjectID.hh:55
Data structure for PMT geometry and calibration.
Definition: JPMT.hh:47
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level
Definition: JSirene.cc:61
int id
Definition: Hit.hh:11
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:174
double mc_t
MC: time of the mc event.
Definition: Evt.hh:43
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
Definition: Hit.hh:8
double getLivetime(const std::string &file_name)
Get data taking live time.
double t
hit time (from calibration or MC truth)
Definition: Hit.hh:23
int dom_id
module identifier from the data (unique in the detector).
Definition: Hit.hh:14
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
Object reading from a list of files.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
std::vector< Hit > hits
list of hits
Definition: Evt.hh:35
JTriggerCounter_t getCounter() const
Get trigger counter.
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
Definition: Evt.hh:45
JTriggerCounter_t next()
Increment trigger counter.
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