Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JConvertDusj.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
13
17
18#include "JAAnet/JHead.hh"
20
21#include "JDAQ/JDAQEventIO.hh"
23
29#include "JSupport/JSupport.hh"
30#include "JSupport/JMeta.hh"
31
32#include "Jeep/JeepToolkit.hh"
33#include "Jeep/JParser.hh"
34#include "Jeep/JMessage.hh"
35
36
37/**
38 * \author mdejong
39 */
40
41/**
42 * Auxiliary program to convert data to Dusj format.
43 */
44int main(int argc, char **argv)
45{
46 using namespace std;
47 using namespace JPP;
48 using namespace KM3NETDAQ;
49
52 JLimit_t& numberOfEvents = inputFile.getLimit();
53 string detectorFile;
54 int debug;
55
56 try {
57
58 JParser<> zap("Auxiliary program to convert data to Dusj format.");
59
60 zap['f'] = make_field(inputFile);
61 zap['o'] = make_field(outputFile) = "dusj.evt";
62 zap['a'] = make_field(detectorFile);
63 zap['n'] = make_field(numberOfEvents) = JLimit::max();
64 zap['d'] = make_field(debug) = 2;
65
66 zap(argc, argv);
67 }
68 catch(const exception& error) {
69 FATAL(error.what() << endl);
70 }
71
72
74
75 try {
76 load(detectorFile, detector);
77 }
78 catch(const JException& error) {
79 FATAL(error);
80 }
81
82 const JModuleRouter router(detector);
83
84
85 outputFile.open();
86
87 Vec offset(0,0,0);
88
89 int mc_run_id = 0;
90
91 Head header;
92
93 try {
94
95 header = getHeader(inputFile);
96
97 JHead buffer(header);
98
99 offset = getOffset(buffer);
100 mc_run_id = buffer.start_run.run_id;
101
102 } catch(const exception& error) {
103
104 JHead buffer(header);
105
107 buffer.push(&JHead::start_run);
108
109 copy(buffer, header);
110 }
111 {
112 JHead buffer(header);
113
114 buffer.DAQ.livetime_s = getLivetime(inputFile);
115 buffer.push(&JHead::DAQ);
116
117 copy(buffer, header);
118 }
119
120 outputFile.put(header);
121 outputFile.put(JMeta(argc, argv));
122
123 for (JTreeScanner<Evt> mc(inputFile); inputFile.hasNext(); ) {
124
125 STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
126
127 JDAQEvent* tev = inputFile.next();
128
129 Evt out;
130
131 if (mc.getEntries() != 0) {
132
133 Evt* event = mc.getEntry(tev->getCounter());
134
135 if (event != NULL) {
136
137 out = *event;
138
139 if (out.mc_run_id == 0) {
140 out.mc_run_id = mc_run_id;
141 }
142
143 for (vector<Trk>::iterator i = out.mc_trks.begin(); i != out.mc_trks.end(); ++i) {
144 i->pos += offset;
145 }
146 }
147
148 } else {
149
150 out.mc_id = inputFile.getCounter();
151 out.mc_run_id = tev->getRunNumber();
152 }
153
154 read(out, *tev);
155
156 out.hits.clear();
157
159
160 const JModule& module = router.getModule(i->getModuleID());
161 const JPMT& pmt = module.getPMT (i->getPMT());
162
163 Hit hit;
164
165 hit.id = out.hits.size() + 1;
166 hit.dom_id = i->getModuleID();
167 //hit.channel_id = i->getPMT();
168 //hit.tdc = i->getT();
169 //hit.tot = i->getToT();
170 hit.pmt_id = pmt.getID();
171 hit.t = i->getT(); // getTime(i->getT(), pmt.getCalibration());
172 hit.a = i->getToT(); // getToT (i->getToT(), pmt.getCalibration());
173 //hit.pos = Vec(pmt.getX(), pmt.getY(), pmt.getZ());
174 //hit.dir = Vec(pmt.getDX(), pmt.getDY(), pmt.getDZ());
175
176 out.hits.push_back(hit);
177 }
178
179 // time offset
180
181 double t0 = numeric_limits<double>::max();
182
183 for (vector<Hit>::const_iterator i = out.hits.begin(); i != out.hits.end(); ++i) {
184 if (t0 > i->t) {
185 t0 = i->t;
186 }
187 }
188
189 for (vector<Hit>::iterator i = out.hits.begin(); i != out.hits.end(); ++i) {
190 i->t -= t0;
191 }
192
193 if (out.mc_t > 0.0 && t0 != numeric_limits<double>::max()) {
194 out.mc_t -= t0;
195 }
196
197 out.id = inputFile.getCounter();
198
199 outputFile.put(out);
200 }
201
202 STATUS(endl);
203 /*
204 JSingleFileScanner<JTYPELIST<JDAQSummaryslice, JMeta>::typelist> io(inputFile);
205
206 io >> outputFile;
207 */
208 outputFile.close();
209}
int main(int argc, char **argv)
Auxiliary program to convert data to Dusj format.
string outputFile
Data structure for detector geometry and calibration.
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:72
ROOT I/O of application specific meta data.
Direct access to module in detector data structure.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Scanning of objects from a single file according a format that follows from the extension of each fil...
Support methods.
ROOT TTree parameter settings of various packages.
Auxiliary methods for handling file names, type names and environment.
Monte Carlo run header.
Definition JHead.hh:1236
JAANET::start_run start_run
Definition JHead.hh:1583
JAANET::DAQ DAQ
Definition JHead.hh:1607
void push(T JHead::*pd)
Push given data member to Head.
Definition JHead.hh:1374
Detector data structure.
Definition JDetector.hh:96
Router for direct addressing of module data in detector data structure.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition JModule.hh:75
Data structure for PMT geometry, calibration and status.
Definition JPMT.hh:49
General exception.
Definition JException.hh:24
int getID() const
Get identifier.
Definition JObjectID.hh:50
Utility class to parse command line options.
Definition JParser.hh:1698
Object writing to file.
Object reading from a list of files.
virtual bool hasNext() override
Check availability of next element.
counter_type getCounter() const
Get counter.
virtual const pointer_type & next() override
Get next element.
Template definition for direct access of elements in ROOT TChain.
int getRunNumber() const
Get run number.
Template const_iterator.
Definition JDAQEvent.hh:68
const_iterator< T > end() const
Get end of data.
const_iterator< T > begin() const
Get begin of data.
JTriggerCounter_t getCounter() const
Get trigger counter.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
Vec getOffset(const JHead &header)
Get offset.
std::istream & read(std::istream &in, JTestSummary &summary, const char delimiter=' ')
Read test summary.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
double getLivetime(const std::string &file_name)
Get data taking live time.
int getRunNumber(const std::string &file_name)
Get run number for given file name of data taking run.
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
int mc_id
identifier of the MC event (as found in ascii or antcc file).
Definition Evt.hh:24
double mc_t
MC: time where the mc-event was put in the timeslice, since start of run (offset+frameidx*timeslice_d...
Definition Evt.hh:47
std::vector< Hit > hits
list of hits
Definition Evt.hh:38
int mc_run_id
MC run identifier.
Definition Evt.hh:27
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
Definition Evt.hh:49
int id
offline event identifier
Definition Evt.hh:22
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition Head.hh:65
Definition Hit.hh:10
int pmt_id
global PMT identifier as found in evt files
Definition Hit.hh:20
int dom_id
module identifier from the data (unique in the detector).
Definition Hit.hh:14
double a
hit amplitude (in p.e.)
Definition Hit.hh:24
int id
Definition Hit.hh:11
double t
hit time (from tdc+calibration or MC truth)
Definition Hit.hh:23
double livetime_s
Live time [s].
Definition JHead.hh:1053
Detector file.
Definition JHead.hh:227
int run_id
MC run number.
Definition JHead.hh:143
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45
static counter_type max()
Get maximum counter value.
Definition JLimit.hh:128
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition Vec.hh:13