Jpp 21.0.0
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 <limits>
6#include <algorithm>
7
8#include "TROOT.h"
9#include "TFile.h"
10
16
17#include "JLang/JStatus.hh"
18
21
22#include "JDAQ/JDAQEventIO.hh"
23
25
29#include "JSupport/JSupport.hh"
30#include "JSupport/JMeta.hh"
31
32#include "Jeep/JParser.hh"
33#include "Jeep/JMessage.hh"
34
35namespace {
36
37 enum bits_t {
38 CLEAR_MC_HITS, //!< remove Monte Carlo hits
39 CLEAR_MC_TRKS, //!< remove Monte Carlo final state tracks except outgoig lepton
40 CLEAR_DAQ_HITS, //!< remove DAQ hits
41 CLEAR_INTERMEDIATE_FITS, //!< remove intermediate fits
42 CLEAR_ALL_BUT_BEST_FITS //!< remove all but best fits
43 };
44
45 /**
46 * Write bits to output stream.
47 *
48 * \param out output stream
49 * \param object bits
50 * \return output stream
51 */
52 inline std::ostream& operator<<(std::ostream& out, const bits_t& object)
53 {
54#define PRINT_BIT(OUT, A) OUT << (int) A << " -> " << #A << std::endl;
55
56 PRINT_BIT(out, CLEAR_MC_HITS);
57 PRINT_BIT(out, CLEAR_MC_TRKS);
58 PRINT_BIT(out, CLEAR_DAQ_HITS);
59 PRINT_BIT(out, CLEAR_INTERMEDIATE_FITS);
60 PRINT_BIT(out, CLEAR_ALL_BUT_BEST_FITS);
61
62#undef PRINT_BIT
63
64 return out;
65 }
66}
67
68/**
69 * \file
70 * Application for writing DST.
71 *
72 * \author mdejong
73 */
74int main(int argc, char **argv)
75{
76 using namespace std;
77 using namespace JPP;
78 using namespace KM3NETDAQ;
79
81
82 typedef JTriggeredFileScanner<JEvt, JMultipleFileScanner> JTriggeredFileScanner_t;
83 typedef JTriggeredFileScanner_t::multi_pointer_type multi_pointer_type;
84
85 JTriggeredFileScanner_t inputFile;
86 JLimit_t& numberOfEvents = inputFile.getLimit();
88 JStatus option;
89 set<int> keep;
90 bool trace;
91 double cosLR;
92 int debug;
93
94 try {
95
96 JParser<> zap("Application for writing DST.");
97
98 zap['f'] = make_field(inputFile, "output of JXXXReconstruction");
99 zap['o'] = make_field(outputFile, "events in parallel TTree's");
100 zap['n'] = make_field(numberOfEvents) = JLimit::max();
101 zap['O'] = make_field(option, "bit pattern: " << endl << bits_t()) = 0xFF;
102 zap['k'] = make_field(keep, "keep results of selected fits") = JPARSER::initialised();
103 zap['T'] = make_field(trace, "keep results of fits leading to best");
104 zap['c'] = make_field(cosLR, "re-evaluate likelihood ratio") = -1.0;
105 zap['d'] = make_field(debug) = 2;
106
107 zap(argc, argv);
108 }
109 catch(const exception& error) {
110 FATAL(error.what() << endl);
111 }
112
113
114 outputFile.open();
115
116 outputFile.put(JMeta(argc, argv));
117
118 for (JTriggerCounter_t counter = 0; inputFile.hasNext(); counter += 1) {
119
120 STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
121
122 multi_pointer_type ps = inputFile.next();
123
124 JEvt* evt = ps;
125 JDAQEvent* tev = ps;
126 Evt* event = ps;
127
128 if (option.has(CLEAR_MC_HITS)) {
129 event->mc_hits.clear();
130 }
131
132 if (option.has(CLEAR_MC_TRKS)) {
133
134 vector<Trk>::iterator __end = partition(event->mc_trks.begin(), event->mc_trks.end(), [](const Trk& trk) { return is_initialstate(trk) || is_muonbundle(trk); });
135
136 if (has_neutrino(*event)) {
137
138 const int id = get_neutrino(*event).id;
139
140 __end = partition(__end, event->mc_trks.end(), [id](const Trk& trk) { return is_lepton(trk) && trk.mother_id == id; });
141 }
142
143 event->mc_trks.erase(__end, event->mc_trks.end());
144 }
145
146 if (option.has(CLEAR_DAQ_HITS)) {
147 *tev = JDAQEvent(tev->getDAQEventHeader());
148 }
149
150 // re-run Gandalf likelihood ratio test
151
152 if (cosLR > -1.0) {
153
154 JEvt::iterator __end = partition(evt->begin(), evt->end(), make_predicate(&JFit::getStatus, (int) COMPLETE_CHAIN, JComparison::eq()));
155
156 for (JEvt::iterator i = evt->begin(); i != __end; ++i) {
157
158 double Q = numeric_limits<double>::max();
159
160 for (JEvt::iterator p = evt->begin(); p != evt->end(); ++p) {
161 if (p->getHistory().rbegin()->type == JMUONGANDALF) {
162 if (getDot(getDirection(*i), getDirection(*p)) <= cosLR) {
163 if (i->getQ() - p->getQ() < Q) {
164 Q = i->getQ() - p->getQ();
165 }
166 }
167 }
168 }
169
170 i->setW(JGANDALF_LIKELIHOOD_RATIO, Q);
171 }
172 }
173
174 if (option.has(CLEAR_INTERMEDIATE_FITS) ||
175 option.has(CLEAR_ALL_BUT_BEST_FITS)) {
176
177 JEvt::iterator __end = partition(evt->begin(), evt->end(), make_predicate(&JFit::getStatus, (int) COMPLETE_CHAIN, JComparison::eq()));
178
179 if (option.has(CLEAR_ALL_BUT_BEST_FITS) && evt->begin() != __end) {
180 __end = next(evt->begin());
181 }
182
183 if (!keep.empty()) {
184 __end = partition(__end, evt->end(), [keep](const JFit& fit) { return keep.count(fit.getHistory().rbegin()->type) != 0; });
185 }
186
187 if (trace) {
188 for (JEvt::iterator i = evt->begin(), __q = __end; i != __q; ++i) {
189 __end = partition(__end, evt->end(), [i](const JFit& fit) { return i->getHistory().match(fit.getHistory()); });
190 }
191 }
192
193 evt->erase(__end, evt->end());
194 }
195
196 // Set the event counter to the index of the Monte Carlo event in the output.
197
198 tev->setCounter(counter);
199
200 outputFile.put(*event);
201 outputFile.put(*tev);
202 outputFile.put(*evt);
203 }
204 STATUS(endl);
205
207
208 io >> outputFile;
209
210 outputFile.close();
211}
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:74
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:2107
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:1664
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.
#define PRINT_BIT(OUT, A)
static const int JGANDALF_LIKELIHOOD_RATIO
likelihood ratio between this and best alternative fit see JRECONSTRUCTION::JMuonGandalf
JDirection3D getDirection(const Vec &dir)
Get direction.
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
std::ostream & operator<<(std::ostream &out, const morphology_type &object)
Write morphology to output stream.
double getDot(const JFirst_t &first, const JSecond_t &second)
Get dot product of objects.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
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:66
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