Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
dst.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <set>
5#include <algorithm>
6
7#include "TROOT.h"
8#include "TFile.h"
9
15
18
19#include "JDAQ/JDAQEventIO.hh"
20
22
26#include "JSupport/JSupport.hh"
27#include "JSupport/JMeta.hh"
28
29#include "Jeep/JStatus.hh"
30#include "Jeep/JParser.hh"
31#include "Jeep/JMessage.hh"
32
33namespace {
34
35 enum bits_t {
36 CLEAR_MC_HITS, //!< remove Monte Carlo hits
37 CLEAR_MC_TRKS, //!< remove Monte Carlo final state tracks except outgoig lepton
38 CLEAR_DAQ_HITS, //!< remove DAQ hits
39 CLEAR_INTERMEDIATE_FITS, //!< remove intermediate fits
40 CLEAR_ALL_BUT_BEST_FITS //!< remove all but best fits
41 };
42
43 /**
44 * Write bits to output stream.
45 *
46 * \param out output stream
47 * \param object bits
48 * \return output stream
49 */
50 inline std::ostream& operator<<(std::ostream& out, const bits_t& object)
51 {
52#define PRINT_BIT(OUT, A) OUT << (int) A << " -> " << #A << std::endl;
53
54 PRINT_BIT(out, CLEAR_MC_HITS);
55 PRINT_BIT(out, CLEAR_MC_TRKS);
56 PRINT_BIT(out, CLEAR_DAQ_HITS);
57 PRINT_BIT(out, CLEAR_INTERMEDIATE_FITS);
58 PRINT_BIT(out, CLEAR_ALL_BUT_BEST_FITS);
59
60#undef PRINT_BIT
61
62 return out;
63 }
64}
65
66/**
67 * \file
68 * Application for writing DST.
69 *
70 * \author mdejong
71 */
72int main(int argc, char **argv)
73{
74 using namespace std;
75 using namespace JPP;
76 using namespace KM3NETDAQ;
77
79
80 typedef JTriggeredFileScanner<JEvt, JMultipleFileScanner> JTriggeredFileScanner_t;
81 typedef JTriggeredFileScanner_t::multi_pointer_type multi_pointer_type;
82
83 JTriggeredFileScanner_t inputFile;
84 JLimit_t& numberOfEvents = inputFile.getLimit();
86 JStatus option;
87 set<int> keep;
88 int debug;
89
90 try {
91
92 JParser<> zap("Application for writing DST.");
93
94 zap['f'] = make_field(inputFile);
95 zap['o'] = make_field(outputFile);
96 zap['n'] = make_field(numberOfEvents) = JLimit::max();
97 zap['O'] = make_field(option, "bit pattern: " << endl << bits_t()) = 0xFF;
98 zap['k'] = make_field(keep, "keep results of selected applications") = JPARSER::initialised();
99 zap['d'] = make_field(debug) = 2;
100
101 zap(argc, argv);
102 }
103 catch(const exception& error) {
104 FATAL(error.what() << endl);
105 }
106
107
108 outputFile.open();
109
110 outputFile.put(JMeta(argc, argv));
111
112 for (JTriggerCounter_t counter = 0; inputFile.hasNext(); counter += 1) {
113
114 STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
115
116 multi_pointer_type ps = inputFile.next();
117
118 JEvt* evt = ps;
119 JDAQEvent* tev = ps;
120 Evt* event = ps;
121
122 if (option.has(CLEAR_MC_HITS)) {
123 event->mc_hits.clear();
124 }
125
126 if (option.has(CLEAR_MC_TRKS)) {
127
128 vector<Trk>::iterator __end = partition(event->mc_trks.begin(), event->mc_trks.end(), [](const Trk& trk) { return is_initialstate(trk) || is_muonbundle(trk); });
129
130 if (has_neutrino(*event)) {
131
132 const int id = get_neutrino(*event).id;
133
134 __end = partition(__end, event->mc_trks.end(), [id](const Trk& trk) { return is_lepton(trk) && trk.mother_id == id; });
135 }
136
137 event->mc_trks.erase(__end, event->mc_trks.end());
138 }
139
140 if (option.has(CLEAR_DAQ_HITS)) {
141 *tev = JDAQEvent(tev->getDAQEventHeader());
142 }
143
144 if (option.has(CLEAR_INTERMEDIATE_FITS) ||
145 option.has(CLEAR_ALL_BUT_BEST_FITS)) {
146
147 JEvt::iterator __end = partition(evt->begin(), evt->end(), make_predicate(&JFit::getStatus, (int) COMPLETE_CHAIN, JComparison::eq()));
148
149 if (option.has(CLEAR_ALL_BUT_BEST_FITS) && evt->begin() != __end) {
150 __end = next(evt->begin());
151 }
152
153 if (!keep.empty()) {
154 for (JEvt::iterator i = evt->begin(), __q = __end; i != __q; ++i) {
155 __end = partition(__end, evt->end(), [i, keep](const JFit& fit) { return i->getHistory().match(fit.getHistory()) && keep.count(fit.getHistory().rbegin()->type) != 0; });
156 }
157 }
158
159 evt->erase(__end, evt->end());
160 }
161
162 // Set the event counter to the index of the Monte Carlo event in the output.
163
164 tev->setCounter(counter);
165
166 outputFile.put(*event);
167 outputFile.put(*tev);
168 outputFile.put(*evt);
169 }
170 STATUS(endl);
171
173
174 io >> outputFile;
175
176 outputFile.close();
177}
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
string outputFile
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.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
ROOT TTree parameter settings of various packages.
Synchronously read DAQ events and Monte Carlo events (and optionally other events).
int getStatus() const
Get status of the fit; negative values should refer to a bad fit.
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.
const JDAQEventHeader & getDAQEventHeader() const
Get DAQ event header.
void setCounter(const JTriggerCounter_t counter)
Set trigger counter.
int main(int argc, char **argv)
Definition dst.cc:72
#define PRINT_BIT(OUT, A)
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
JWriter & operator<<(JWriter &out, const JDAQChronometer &chronometer)
Write DAQ chronometer to output.
unsigned long long int JTriggerCounter_t
Type definition of trigger counter.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
Acoustic event fit.
Acoustic single fit.
Auxiliary class for handling status.
Definition JStatus.hh:39
bool has(const int bit) const
Test PMT status.
Definition JStatus.hh:120
Type list.
Definition JTypeList.hh:23
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
const JLimit & getLimit() const
Get limit.
Definition JLimit.hh:84
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 class to synchronously read DAQ events and Monte Carlo events (and optionally other events)...
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition Trk.hh:15
int id
track identifier
Definition Trk.hh:16