Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTriggerReprocessor.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 
11 #include "JDAQ/JDAQTimesliceIO.hh"
12 #include "JDAQ/JDAQEventIO.hh"
14 #include "JDAQ/JDAQEvaluator.hh"
15 
16 #include "JDetector/JDetector.hh"
19 
20 #include "JTrigger/JHit.hh"
21 #include "JTrigger/JHitToolkit.hh"
24 #include "JTrigger/JTimeslice.hh"
25 #include "JTrigger/JHitL0.hh"
26 #include "JTrigger/JHitL1.hh"
27 #include "JTrigger/JBuildL1.hh"
28 #include "JTrigger/JBuildL2.hh"
32 #include "JTrigger/JTriggerBits.hh"
36 #include "JTrigger/JTimesliceL1.hh"
39 
40 #include "JLang/JPipe.hh"
42 
44 #include "JSupport/JTreeScanner.hh"
46 #include "JSupport/JSupport.hh"
47 #include "JSupport/JMeta.hh"
49 
50 #include "Jeep/JParser.hh"
51 #include "Jeep/JMessage.hh"
52 
53 
54 /**
55  * \file
56  * Auxiliary program to re-trigger KM3NETDAQ::JDAQEvent data.
57  * \author mdejong
58  */
59 int main(int argc, char **argv)
60 {
61  using namespace std;
62  using namespace JPP;
63  using namespace KM3NETDAQ;
64 
65  typedef JAllTypes_t typelist;
66 
69  JLimit_t& numberOfEvents = inputFile.getLimit();
70  string detectorFile;
72  bool reuse_parameters;
73  JROOTClassSelection selection = getROOTClassSelection<typelist>();
74  int debug;
75 
76  try {
77 
78  JParser<> zap("Auxiliary program to re-trigger event data.");
79 
80  zap['f'] = make_field(inputFile);
81  zap['o'] = make_field(outputFile) = "trigger_reprocessor.root";
82  zap['n'] = make_field(numberOfEvents) = JLimit::max();
83  zap['a'] = make_field(detectorFile);
85  zap['U'] = make_field(reuse_parameters);
86  zap['C'] = make_field(selection) = JPARSER::initialised();
87  zap['d'] = make_field(debug) = 0;
88 
89  zap(argc, argv);
90  }
91  catch(const exception &error) {
92  FATAL(error.what() << endl);
93  }
94 
95 
96  cout.tie(&cerr);
97 
99 
100  DEBUG("Frame time [ms] " << getFrameTime() * 1e-6 << endl);
101  DEBUG("Reset time [ms] " << getRTS() * 1e-6 << endl);
102  DEBUG("Trigger" << endl << parameters << endl);
103 
105 
106  try {
107  load(detectorFile, detector);
108  }
109  catch(const JException& error) {
110  FATAL(error);
111  }
112 
113  if (reuse_parameters) {
114 
115  try {
116 
117  parameters = getTriggerParameters(inputFile);
118 
119  NOTICE("Set trigger parameters from input." << endl);
120  }
121  catch(const JException& error) {
122  FATAL("No trigger parameters from input." << endl);
123  }
124  }
125 
127 
128  const JModuleRouter moduleRouter(detector);
129 
130  if (parameters.writeSummary()) { WARNING("Discard writeSummary option during reprocesing of data." << endl); }
131  if (parameters.writeL1()) { WARNING("Discard writeL1 option during reprocesing of data." << endl); }
132  if (parameters.writeL2()) { WARNING("Discard writeL2 option during reprocesing of data." << endl); }
133  if (parameters.writeSN()) { WARNING("Discard writeSN option during reprocesing of data." << endl); }
134 
135  //typedef JHit hit_type;
136  //typedef int hit_type;
137  typedef double hit_type;
138 
139  typedef JSuperFrame1D<hit_type> JSuperFrame1D_t;
140  typedef JSuperFrame2D<hit_type> JSuperFrame2D_t;
141  typedef JTimeslice <hit_type> JTimeslice_t;
142  typedef JBuildL1 <hit_type> JBuildL1_t;
143  typedef JBuildL2 <hit_type> JBuildL2_t;
144 
145  const JBuildL1_t buildL1(parameters);
146  const JBuildL2_t buildL2(parameters.L2);
147 
148  JTimesliceRouter timesliceRouter(parameters.numberOfBins);
149 
150  const JTrigger3DMuon trigger3DMuon (parameters);
151  const JTrigger3DShower trigger3DShower(parameters);
152  const JTriggerMXShower triggerMXShower(parameters, detector);
153 
154 
155  outputFile.open();
156 
157  if (!outputFile.is_open()) {
158  FATAL("Error opening file " << outputFile << endl);
159  }
160 
161  outputFile.put(JMeta(argc, argv));
162  outputFile.put(parameters);
163 
164 
166 
168 
169  if (scan.getEntries() == 0) {
170  FATAL("No summary data." << endl);
171  }
172 
173  while (inputFile.hasNext()) {
174 
175  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
176 
177  JDAQEvent* evt = inputFile.next();
178  Long64_t index = scan.find(*evt);
179  JDAQSummaryslice* summary = scan.getEntry(index);
180 
181  if (evt->getFrameIndex() != summary->getFrameIndex()) {
182  DEBUG("Frame indices " << evt->getFrameIndex() << " != " << summary->getFrameIndex() << endl);
183  }
184 
185  JDAQTimeslice timeslice(*evt, *summary);
186 
187  DEBUG(timeslice << endl);
188 
189  timesliceRouter.configure(timeslice);
190 
191 
192  JTimeslice_t timesliceL0(timeslice.getDAQChronometer());
193  JTimeslice_t timesliceL1(timeslice.getDAQChronometer());
194  JTimeslice_t timesliceL2(timeslice.getDAQChronometer());
195 
196  for (JDAQTimeslice::const_iterator super_frame = timeslice.begin(); super_frame != timeslice.end(); ++super_frame) {
197 
198  if (moduleRouter.hasModule(super_frame->getModuleID())) {
199 
200  // calibration
201 
202  const JModule& module = moduleRouter.getModule(super_frame->getModuleID());
203  JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*super_frame, module);
204 
205  // Apply high-rate veto
206 
207  buffer.applyHighRateVeto(parameters.highRateVeto_Hz);
208 
209  // L0
210 
211  timesliceL0.push_back(JSuperFrame1D_t(buffer));
212 
213  // L1
214 
215  timesliceL1.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(),
216  super_frame->getModuleIdentifier(),
217  module.getPosition()));
218 
219  buildL1(*timesliceL0.rbegin(), back_inserter(*timesliceL1.rbegin()));
220 
221  // L2
222 
223  timesliceL2.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(),
224  super_frame->getModuleIdentifier(),
225  module.getPosition()));
226 
227  buildL2(buffer, *timesliceL1.rbegin(), back_inserter(*timesliceL2.rbegin()));
228  }
229  }
230 
231 
232  // Trigger
233 
234  JTriggerInput trigger_input(timesliceL2);
235  JTriggerOutput trigger_output;
236 
237  trigger3DMuon (trigger_input, back_inserter(trigger_output));
238  trigger3DShower(trigger_input, back_inserter(trigger_output));
239  triggerMXShower(trigger_input, timesliceL0, back_inserter(trigger_output));
240 
241  trigger_output.merge(JEventOverlap(parameters.TMaxEvent_ns));
242 
243  DEBUG("Number of triggers: " << trigger_output.size() << endl);
244 
245  for (JTriggerOutput::const_iterator event = trigger_output.begin(); event != trigger_output.end(); ++event) {
246 
247  JTriggeredEvent tev(*event,
248  timesliceRouter,
249  moduleRouter,
250  parameters.TMaxLocal_ns,
252 
253  tev.setCounter(evt->getCounter());
254 
255  outputFile.put(tev);
256  }
257  }
258  STATUS(endl);
259 
260  JSingleFileScanner<typelist> io(inputFile);
261 
262  selection.remove<JDAQEvent>();
263 
264  io | JValve<typelist>(selection) | outputFile;
265 
266  outputFile.close();
267 }
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
#define WARNING(A)
Definition: JMessage.hh:65
debug
Definition: JMessage.hh:29
ROOT TTree parameter settings.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition: JModule.hh:50
void configure(const JDAQTimeslice &timeslice)
Configure.
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:80
Recording of objects on file according a format that follows from the file name extension.
Router for direct addressing of module data in detector data structure.
Auxiliary class for ROOT class selection.
*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
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:63
Basic data structure for time and time over threshold information of hit.
string outputFile
Template definition for direct access of elements in ROOT TChain.
Definition: JTreeScanner.hh:91
Data structure for detector geometry and calibration.
Tools for handling different hit types.
Auxiliary class for selection of data type.
int getFrameIndex() const
Get frame index.
1-dimensional frame with time calibrated data from one optical module.
JTimeRange getTimeRange(const Evt &event)
Get time range (i.e. time between earliest and latest hit) of Monte Carlo event.
Basic data structure for L0 hit.
Type list.
Definition: JTypeList.hh:22
void setDAQLongprint(const bool option)
Set DAQ print option.
Definition: JDAQPrint.hh:28
Scanning of objects from a single file according a format that follows from the extension of each fil...
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Template L2 builder.
Definition: JBuildL2.hh:45
double getMaximalDistance(const JDetector &detector)
Get maximal distance between modules in detector.
Detector file.
Definition: JHead.hh:130
void merge(const JMatch_t &match)
Merge events.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
Router for fast addressing of hits in KM3NETDAQ::JDAQTimeslice data structure as a function of the op...
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
Implementation of pipe operation for object iterators.
ROOT I/O of application specific meta data.
#define NOTICE(A)
Definition: JMessage.hh:64
const JDAQChronometer & getDAQChronometer() const
Get DAQ chronometer.
Data time slice.
Auxiliary class to build JDAQEvent for a triggered event.
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level
Definition: JSirene.cc:61
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:129
General purpose messaging.
Template L1 hit builder.
Definition: JBuildL1.hh:85
#define FATAL(A)
Definition: JMessage.hh:67
Direct access to module in detector data structure.
void setCounter(const JTriggerCounter_t counter)
Set trigger counter.
double getRTS()
Get TDC dynamic range.
Definition: JDAQClock.hh:173
Utility class to parse command line options.
bool hasModule(const JObjectID &id) const
Has module.
2-dimensional frame with time calibrated data from one optical module.
Data structure for input to trigger algorithm.
Object reading from a list of files.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
Setting of trigger bits.
KM3NeT DAQ constants, bit handling, etc.
Match of two events considering overlap in time.
JTriggerCounter_t getCounter() const
Get trigger counter.
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.
Basic data structure for L1 hit.
JTriggerCounter_t next()
Increment trigger counter.
Time slice with calibrated data.
Definition: JTimeslice.hh:26
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
int main(int argc, char *argv[])
Definition: Main.cpp:15