Jpp  16.0.3
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
examples/JDynamics/JConvertEvt.cc File Reference

Auxiliary program to convert trigger files to Evt format. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <memory>
#include "TROOT.h"
#include "TFile.h"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "km3net-dataformat/offline/io_online.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JPMTRouter.hh"
#include "JDetector/JModuleRouter.hh"
#include "JDetector/JPMTParametersMap.hh"
#include "JDetector/JPMTAnalogueSignalProcessor.hh"
#include "JDynamics/JDynamics.hh"
#include "JCompass/JSupport.hh"
#include "JAcoustics/JSupport.hh"
#include "JTrigger/JHit.hh"
#include "JTrigger/JHitToolkit.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JHeadToolkit.hh"
#include "JAAnet/JAAnetToolkit.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)
 

Detailed Description

Auxiliary program to convert trigger files to Evt format.

Author
mdejong, jseneca

Definition in file examples/JDynamics/JConvertEvt.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 57 of file examples/JDynamics/JConvertEvt.cc.

58 {
59  using namespace std;
60  using namespace JPP;
61  using namespace KM3NETDAQ;
62 
64  JACOUSTICS::JEvt>::typelist calibration_types;
65  typedef JMultipleFileScanner<calibration_types> JCalibration_t;
66 
67  JMultipleFileScanner<> inputFile;
69  JLimit_t& numberOfEvents = inputFile.getLimit();
70  string detectorFile;
71  JCalibration_t calibrationFile;
72  double Tmax_s;
73  JPMTParametersMap pmtParameters;
74  int debug;
75 
76  try {
77 
78  JParser<> zap("Auxiliary program to convert fit results to Evt format.\
79  \nThe option -L corresponds to the name of a shared library \
80  \nand function so to rearrange the order of fit results.");
81 
82  zap['f'] = make_field(inputFile);
83  zap['o'] = make_field(outputFile) = "aanet.root";
84  zap['n'] = make_field(numberOfEvents) = JLimit::max();
85  zap['a'] = make_field(detectorFile) = "";
86  zap['+'] = make_field(calibrationFile) = JPARSER::initialised();
87  zap['T'] = make_field(Tmax_s) = 100.0;
88  zap['P'] = make_field(pmtParameters, "PMT simulation data (or corresponding file name)") = JPARSER::initialised();
89  zap['d'] = make_field(debug) = 2;
90 
91  zap(argc, argv);
92  }
93  catch(const exception& error) {
94  FATAL(error.what() << endl);
95  }
96 
97 
99  typedef JSingleFileScanner_t::pointer_type pointer_type;
100 
101 
103 
104  if (detectorFile != "") {
105  try {
106  load(detectorFile, detector);
107  }
108  catch(const JException& error) {
109  FATAL(error);
110  }
111  }
112 
113  getMechanics.load(detector.getID());
114 
115  unique_ptr<JDynamics> dynamics;
116 
117  try {
118 
119  dynamics.reset(new JDynamics(detector, Tmax_s));
120 
121  dynamics->load(calibrationFile);
122  }
123  catch(const exception& error) {
124  if (!calibrationFile.empty()) {
125  FATAL(error.what());
126  }
127  }
128 
129 
130  const JPMTRouter pmt_router(dynamics ? dynamics->getDetector() : detector);
131  const JModuleRouter mod_router(dynamics ? dynamics->getDetector() : detector);
132 
133 
134  outputFile.open();
135 
136  Head header;
137 
138  try {
139  header = getHeader(inputFile);
140  } catch(const exception& error) {}
141  {
142  JAANET::JHead buffer(header);
143 
144  buffer.DAQ.livetime_s = getLivetime(inputFile.begin(), inputFile.end());
145  buffer.push(&JAANET::JHead::DAQ);
146 
147  copy(buffer, header);
148  }
149 
150  outputFile.put(header);
151 
152 
153  outputFile.put(JMeta(argc, argv));
154 
155 
156  counter_type number_of_events = 0;
157 
158  for (JMultipleFileScanner<>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
159 
160  STATUS("Processing: " << *i << endl);
161 
163  JTreeScanner<Evt> mc(*i);
164 
165  in.setLimit(inputFile.getLimit());
166 
167  Vec center(0,0,0);
168 
169  int mc_run_id = 0;
170 
171  try {
172 
173  const JAANET::JHead head(getHeader(*i));
174 
175  center = get<Vec>(head);
176  mc_run_id = head.start_run.run_id;
177 
178  } catch(const exception& error) {}
179 
180 
181  while (in.hasNext()) {
182 
183  STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
184 
185  pointer_type ps = in.next();
186 
187  JDAQEvent* tev = ps;
188 
189  if (dynamics) {
190  dynamics->update(*tev); // update detector
191  }
192 
193  Evt out; // output event
194 
195  if (mc.getEntries() != 0) {
196 
197  Evt* event = mc.getEntry(tev->getCounter());
198 
199  if (event != NULL) {
200 
201  out = *event; // import Monte Carlo true data
202 
203  if (out.mc_run_id == 0) {
204  out.mc_run_id = mc_run_id;
205  }
206 
207  for (vector<Trk>::iterator i = out.mc_trks.begin(); i != out.mc_trks.end(); ++i) {
208  i->pos += center; // offset true positions
209  }
210  }
211  }
212 
213  read(out, *tev); // import DAQ data
214 
215  if (!pmt_router->empty()) { // import calibration data
216 
217  for (vector<Hit>::iterator i = out.mc_hits.begin(); i != out.mc_hits.end(); ++i) {
218 
219  if (pmt_router.hasPMT(i->pmt_id)) {
220 
221  const JPMTAddress address = pmt_router.getAddress(i->pmt_id);
222  const JPMTIdentifier id = pmt_router.getIdentifier(address);
223  const JPMT& pmt = pmt_router.getPMT(address);
224 
225  i->dom_id = id.getID();
226  i->channel_id = id.getPMTAddress();
227  i->pos = getPosition (pmt);
228  i->dir = getDirection(pmt);
229 
230  } else {
231 
232  FATAL("Missing PMT" << i->pmt_id << endl);
233  }
234  }
235  }
236 
237  if (!mod_router->empty()) { // import calibration data
238 
239  for (vector<Hit>::iterator i = out.hits.begin(); i != out.hits.end(); ++i) {
240 
241  if (mod_router.hasModule(i->dom_id)) {
242 
243  const JPMTIdentifier id(i->dom_id, i->channel_id);
244 
245  const JPMTParameters& parameters = pmtParameters.getPMTParameters(id);
246  const JPMTAnalogueSignalProcessor cpu(parameters);
247 
248  const JPMT& pmt = mod_router.getPMT(id);
249 
251 
252  const JTRIGGER::JHit hit(getTime(i->tdc, pmt.getCalibration()), i->tot);
253 
254  i->pmt_id = pmt.getID();
255  i->pos = getPosition (pmt);
256  i->dir = getDirection(pmt);
257  i->t = hit.getT();
258  i->tot = hit.getToT();
259  i->a = cpu.getNPE(i->tot);
260 
261  } else {
262 
263  FATAL("Missing module " << i->dom_id << endl);
264  }
265  }
266  }
267 
268  out.id = ++number_of_events;
269 
270  outputFile.put(out);
271  }
272  }
273 
274  STATUS(endl);
275 
277 
278  io >> outputFile;
279 
280  outputFile.close();
281 }
Router for direct addressing of PMT data in detector data structure.
Definition: JPMTRouter.hh:35
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
std::istream & read(std::istream &in, JTestSummary &summary, const char delimiter= ' ')
Read test summary.
static void setSlewing(const bool slewing)
Set slewing option.
static JDetectorMechanics getMechanics
Function object to get string mechanics.
Definition: JMechanics.hh:243
const JCalibration & getCalibration() const
Get calibration.
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Hit data structure.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
Long64_t counter_type
Type definition for counter.
double getTime(const Hit &hit)
Get true time of hit.
string outputFile
Auxiliary base class for file name.
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
bool slewing
time slewing of analogue signal
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:12
Detector file.
Definition: JHead.hh:224
JDirection3D getDirection(const Vec &dir)
Get direction.
Acoustic event fit.
int mc_run_id
MC run identifier.
Definition: Evt.hh:26
Auxiliary class for recursive type list generation.
Definition: JTypeList.hh:351
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int getID() const
Get identifier.
Definition: JObjectID.hh:50
Data structure for PMT geometry, calibration and status.
Definition: JPMT.hh:43
JPosition3D getPosition(const Vec &pos)
Get position.
Auxiliary class for map of PMT parameters.
void load(const std::string &file_name)
Load mechanical model parameters from file.
Definition: JMechanics.hh:142
int debug
debug level
Definition: JSirene.cc:63
Monte Carlo run header.
Definition: JHead.hh:1164
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:67
#define FATAL(A)
Definition: JMessage.hh:67
Dynamic detector calibration.
Definition: JDynamics.hh:62
Address of PMT in detector data structure.
Definition: JPMTAddress.hh:32
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
double getLivetime(const std::string &file_name)
Get data taking live time.
General purpose class for object reading from a list of file names.
std::vector< Hit > mc_hits
MC: list of MC truth hits.
Definition: Evt.hh:45
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:139
int id
offline event identifier
Definition: Evt.hh:21
Orientation of module.
Object reading from a list of files.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
Data structure for PMT parameters.
std::vector< Hit > hits
list of hits
Definition: Evt.hh:35
do set_variable DETECTOR_TXT $WORKDIR detector
JAANET::DAQ DAQ
Definition: JHead.hh:1476
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:42
JTriggerCounter_t getCounter() const
Get trigger counter.
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
Definition: Evt.hh:46
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19
then usage $script< detector file >< tripodfile >< stage > input file nInput files correspond to the output of JAcousticsEventBuilder[.sh] nFirst stage eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY eval JPrintDetector a $DETECTOR O CAN source JAcoustics sh $DETECTOR_ID typeset A CONFIGURATION for key in Tmax_s