Jpp 20.0.0-195-g190c9e876
the software that should make you happy
Loading...
Searching...
No Matches
examples/JDynamics/JConvertEvt.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5#include <algorithm>
6#include <memory>
7
8#include "TROOT.h"
9#include "TFile.h"
10
14
21
23
24#include "JCompass/JSupport.hh"
25
27
28#include "JTrigger/JHit.hh"
30
31#include "JAAnet/JHead.hh"
34
35#include "JDAQ/JDAQEventIO.hh"
37
43#include "JSupport/JSupport.hh"
44#include "JSupport/JMeta.hh"
45
46#include "Jeep/JeepToolkit.hh"
47#include "Jeep/JParser.hh"
48#include "Jeep/JMessage.hh"
49
50
51/**
52 * \file
53 * Auxiliary program to convert trigger files to Evt format.
54 *
55 * \author mdejong, jseneca
56 */
57int main(int argc, char **argv)
58{
59 using namespace std;
60 using namespace JPP;
61 using namespace KM3NETDAQ;
62
63 typedef JMultipleFileScanner<calibration_types> JCalibration_t;
64
65 JMultipleFileScanner<> inputFile;
67 JLimit_t& numberOfEvents = inputFile.getLimit();
68 string detectorFile;
69 JCalibration_t calibrationFile;
70 double Tmax_s;
71 JPMTParametersMap pmtParameters;
72 int debug;
73
74 try {
75
76 JParser<> zap("Auxiliary program to convert fit results to Evt format.\
77 \nThe option -L corresponds to the name of a shared library \
78 \nand function so to rearrange the order of fit results.");
79
80 zap['f'] = make_field(inputFile);
81 zap['o'] = make_field(outputFile) = "aanet.root";
82 zap['n'] = make_field(numberOfEvents) = JLimit::max();
83 zap['a'] = make_field(detectorFile) = "";
84 zap['+'] = make_field(calibrationFile) = JPARSER::initialised();
85 zap['T'] = make_field(Tmax_s) = 100.0;
86 zap['P'] = make_field(pmtParameters, "PMT simulation data (or corresponding file name)") = JPARSER::initialised();
87 zap['d'] = make_field(debug) = 2;
88
89 zap(argc, argv);
90 }
91 catch(const exception& error) {
92 FATAL(error.what() << endl);
93 }
94
95
97 typedef JSingleFileScanner_t::pointer_type pointer_type;
98
99
101
102 if (detectorFile != "") {
103 try {
104 load(detectorFile, detector);
105 }
106 catch(const JException& error) {
107 FATAL(error);
108 }
109 }
110
111 unique_ptr<JDynamics> dynamics;
112
113 try {
114
115 dynamics.reset(new JDynamics(detector, Tmax_s));
116
117 dynamics->load(calibrationFile);
118 }
119 catch(const exception& error) {
120 if (!calibrationFile.empty()) {
121 FATAL(error.what());
122 }
123 }
124
125
126 const JPMTRouter pmt_router(dynamics ? dynamics->getDetector() : detector);
127 const JModuleRouter mod_router(dynamics ? dynamics->getDetector() : detector);
128
129
130 outputFile.open();
131
132 Head header;
133
134 try {
135 header = getHeader(inputFile);
136 } catch(const exception& error) {}
137 {
138 JAANET::JHead buffer(header);
139
140 buffer.DAQ.livetime_s = getLivetime(inputFile.begin(), inputFile.end());
141 buffer.push(&JAANET::JHead::DAQ);
142
143 copy(buffer, header);
144 }
145
146 outputFile.put(header);
147
148
149 outputFile.put(JMeta(argc, argv));
150
151
152 counter_type number_of_events = 0;
153
154 for (JMultipleFileScanner<>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
155
156 STATUS("Processing: " << *i << endl);
157
159 JTreeScanner<Evt> mc(*i);
160
161 in.setLimit(inputFile.getLimit());
162
163 Vec offset(0,0,0);
164
165 int mc_run_id = 0;
166
167 try {
168
169 const JAANET::JHead head(getHeader(*i));
170
171 offset = getOffset(head);
172 mc_run_id = head.start_run.run_id;
173
174 } catch(const exception& error) {}
175
176
177 while (in.hasNext()) {
178
179 STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
180
181 pointer_type ps = in.next();
182
183 JDAQEvent* tev = ps;
184
185 if (dynamics) {
186 dynamics->update(*tev); // update detector
187 }
188
189 Evt out; // output event
190
191 if (mc.getEntries() != 0) {
192
193 Evt* event = mc.getEntry(tev->getCounter());
194
195 if (event != NULL) {
196
197 out = *event; // import Monte Carlo true data
198
199 if (out.mc_run_id == 0) {
200 out.mc_run_id = mc_run_id;
201 }
202
203 for (vector<Trk>::iterator i = out.mc_trks.begin(); i != out.mc_trks.end(); ++i) {
204 i->pos += offset; // offset true positions
205 }
206 }
207 }
208
209 read(out, *tev); // import DAQ data
210
211 if (!pmt_router->empty()) { // import calibration data
212
213 for (vector<Hit>::iterator i = out.mc_hits.begin(); i != out.mc_hits.end(); ++i) {
214
215 if (pmt_router.hasPMT(i->pmt_id)) {
216
217 const JPMTAddress address = pmt_router.getAddress(i->pmt_id);
218 const JPMTIdentifier id = pmt_router.getIdentifier(address);
219 const JPMT& pmt = pmt_router.getPMT(address);
220
221 i->dom_id = id.getID();
222 i->channel_id = id.getPMTAddress();
223 i->pos = getPosition (pmt);
224 i->dir = getDirection(pmt);
225
226 } else {
227
228 FATAL("Missing PMT" << i->pmt_id << endl);
229 }
230 }
231 }
232
233 if (!mod_router->empty()) { // import calibration data
234
235 for (vector<Hit>::iterator i = out.hits.begin(); i != out.hits.end(); ++i) {
236
237 if (mod_router.hasModule(i->dom_id)) {
238
239 const JPMTIdentifier id(i->dom_id, i->channel_id);
240
241 const JPMTParameters& parameters = pmtParameters.getPMTParameters(id);
242 const JPMTAnalogueSignalProcessor cpu(parameters);
243
244 const JPMT& pmt = mod_router.getPMT(id);
245
247
248 const JTRIGGER::JHit hit(getTime(i->tdc, pmt.getCalibration()), i->tot);
249
250 i->pmt_id = pmt.getID();
251 i->pos = getPosition (pmt);
252 i->dir = getDirection(pmt);
253 i->t = hit.getT();
254 i->tot = hit.getToT();
255 i->a = cpu.getNPE(i->tot);
256
257 } else {
258
259 FATAL("Missing module " << i->dom_id << endl);
260 }
261 }
262 }
263
264 out.id = ++number_of_events;
265
266 outputFile.put(out);
267 }
268 }
269
270 STATUS(endl);
271
273
274 io >> outputFile;
275
276 outputFile.close();
277}
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
ROOT TTree parameter settings.
ROOT TTree parameter settings.
string outputFile
Data structure for detector geometry and calibration.
Dynamic detector calibration.
Recording of objects on file according a format that follows from the file name extension.
Tools for handling different hit types.
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:74
ROOT I/O of application specific meta data.
Direct access to module in detector data structure.
PMT analogue signal processor.
Direct access to PMT 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.
Basic data structure for time and time over threshold information of hit.
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:1601
JAANET::DAQ DAQ
Definition JHead.hh:1625
void push(T JHead::*pd)
Push given data member to Head.
Definition JHead.hh:1374
const JCalibration & getCalibration() const
Get calibration.
Detector data structure.
Definition JDetector.hh:96
Router for direct addressing of module data in detector data structure.
const JPMT & getPMT(const JPMTIdentifier &id) const
Get PMT parameters.
bool hasModule(const JObjectID &id) const
Has module.
Address of PMT in detector data structure.
Auxiliary class for map of PMT parameters.
const JPMTParameters & getPMTParameters(const JPMTIdentifier &id) const
Get PMT parameters.
Data structure for PMT parameters.
bool slewing
time slewing of analogue signal
Router for direct addressing of PMT data in detector data structure.
Definition JPMTRouter.hh:37
bool hasPMT(const JObjectID &id) const
Has PMT.
const JPMT & getPMT(const JPMTAddress &address) const
Get PMT.
Definition JPMTRouter.hh:92
JPMTIdentifier getIdentifier(const JPMTAddress &address) const
Get identifier of PMT.
const JPMTAddress & getAddress(const JObjectID &id) const
Get address of PMT.
Definition JPMTRouter.hh:80
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.
General purpose class for object reading from a list of file names.
Object reading from a list of files.
Template definition for direct access of elements in ROOT TChain.
Hit data structure.
static void setSlewing(const bool slewing)
Set slewing option.
double getToT() const
Get calibrated time over threshold of hit.
double getT() const
Get calibrated time of hit.
JTriggerCounter_t getCounter() const
Get trigger counter.
int main(int argc, char **argv)
JDirection3D getDirection(const Vec &dir)
Get direction.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
JPosition3D getPosition(const Vec &pos)
Get position.
Vec getOffset(const JHead &header)
Get offset.
std::istream & read(std::istream &in, JTestSummary &summary)
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).
Long64_t counter_type
Type definition for counter.
double getLivetime(const std::string &file_name)
Get data taking live time.
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
const char * getTime()
Get current local time conform ISO-8601 standard.
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
std::vector< Hit > hits
list of hits
Definition Evt.hh:38
int mc_run_id
MC run identifier.
Definition Evt.hh:27
std::vector< Hit > mc_hits
MC: list of MC truth hits.
Definition Evt.hh:48
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
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
virtual double getNPE(const double tot_ns) const override
Get number of photo-electrons.
Dynamic detector calibration.
Definition JDynamics.hh:81
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
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
Auxiliary base class for file name.
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition Vec.hh:13