Jpp 20.0.0-rc.8
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
16#include "JLang/JStatus.hh"
17
20
21#include "JDAQ/JDAQEventIO.hh"
22
24
28#include "JSupport/JSupport.hh"
29#include "JSupport/JMeta.hh"
30
31#include "Jeep/JParser.hh"
32#include "Jeep/JMessage.hh"
33
34namespace {
35
36 enum bits_t {
37 CLEAR_MC_HITS, //!< remove Monte Carlo hits
38 CLEAR_MC_TRKS, //!< remove Monte Carlo final state tracks except outgoig lepton
39 CLEAR_DAQ_HITS, //!< remove DAQ hits
40 CLEAR_INTERMEDIATE_FITS, //!< remove intermediate fits
41 CLEAR_ALL_BUT_BEST_FITS //!< remove all but best fits
42 };
43
44 /**
45 * Write bits to output stream.
46 *
47 * \param out output stream
48 * \param object bits
49 * \return output stream
50 */
51 inline std::ostream& operator<<(std::ostream& out, const bits_t& object)
52 {
53#define PRINT_BIT(OUT, A) OUT << (int) A << " -> " << #A << std::endl;
54
55 PRINT_BIT(out, CLEAR_MC_HITS);
56 PRINT_BIT(out, CLEAR_MC_TRKS);
57 PRINT_BIT(out, CLEAR_DAQ_HITS);
58 PRINT_BIT(out, CLEAR_INTERMEDIATE_FITS);
59 PRINT_BIT(out, CLEAR_ALL_BUT_BEST_FITS);
60
61#undef PRINT_BIT
62
63 return out;
64 }
65}
66
67/**
68 * \file
69 * Application for writing DST.
70 *
71 * \author mdejong
72 */
73int main(int argc, char **argv)
74{
75 using namespace std;
76 using namespace JPP;
77 using namespace KM3NETDAQ;
78
80
81 typedef JTriggeredFileScanner<JEvt, JMultipleFileScanner> JTriggeredFileScanner_t;
82 typedef JTriggeredFileScanner_t::multi_pointer_type multi_pointer_type;
83
84 JTriggeredFileScanner_t inputFile;
85 JLimit_t& numberOfEvents = inputFile.getLimit();
87 JStatus option;
88 set<int> keep;
89 int debug;
90
91 try {
92
93 JParser<> zap("Application for writing DST.");
94
95 zap['f'] = make_field(inputFile);
96 zap['o'] = make_field(outputFile);
97 zap['n'] = make_field(numberOfEvents) = JLimit::max();
98 zap['O'] = make_field(option, "bit pattern: " << endl << bits_t()) = 0xFF;
99 zap['k'] = make_field(keep, "keep results of selected applications") = JPARSER::initialised();
100 zap['d'] = make_field(debug) = 2;
101
102 zap(argc, argv);
103 }
104 catch(const exception& error) {
105 FATAL(error.what() << endl);
106 }
107
108
109 outputFile.open();
110
111 outputFile.put(JMeta(argc, argv));
112
113 for (JTriggerCounter_t counter = 0; inputFile.hasNext(); counter += 1) {
114
115 STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
116
117 multi_pointer_type ps = inputFile.next();
118
119 JEvt* evt = ps;
120 JDAQEvent* tev = ps;
121 Evt* event = ps;
122
123 if (option.has(CLEAR_MC_HITS)) {
124 event->mc_hits.clear();
125 }
126
127 if (option.has(CLEAR_MC_TRKS)) {
128
129 vector<Trk>::iterator __end = partition(event->mc_trks.begin(), event->mc_trks.end(), [](const Trk& trk) { return is_initialstate(trk) || is_muonbundle(trk); });
130
131 if (has_neutrino(*event)) {
132
133 const int id = get_neutrino(*event).id;
134
135 __end = partition(__end, event->mc_trks.end(), [id](const Trk& trk) { return is_lepton(trk) && trk.mother_id == id; });
136 }
137
138 event->mc_trks.erase(__end, event->mc_trks.end());
139 }
140
141 if (option.has(CLEAR_DAQ_HITS)) {
142 *tev = JDAQEvent(tev->getDAQEventHeader());
143 }
144
145 if (option.has(CLEAR_INTERMEDIATE_FITS) ||
146 option.has(CLEAR_ALL_BUT_BEST_FITS)) {
147
148 JEvt::iterator __end = partition(evt->begin(), evt->end(), make_predicate(&JFit::getStatus, (int) COMPLETE_CHAIN, JComparison::eq()));
149
150 if (option.has(CLEAR_ALL_BUT_BEST_FITS) && evt->begin() != __end) {
151 __end = next(evt->begin());
152 }
153
154 if (!keep.empty()) {
155 for (JEvt::iterator i = evt->begin(), __q = __end; i != __q; ++i) {
156 __end = partition(__end, evt->end(), [i, keep](const JFit& fit) { return i->getHistory().match(fit.getHistory()) && keep.count(fit.getHistory().rbegin()->type) != 0; });
157 }
158 }
159
160 evt->erase(__end, evt->end());
161 }
162
163 // Set the event counter to the index of the Monte Carlo event in the output.
164
165 tev->setCounter(counter);
166
167 outputFile.put(*event);
168 outputFile.put(*tev);
169 outputFile.put(*evt);
170 }
171 STATUS(endl);
172
174
175 io >> outputFile;
176
177 outputFile.close();
178}
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:73
#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:31
bool has(const int bit) const
Test PMT status.
Definition JStatus.hh:198
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