Jpp 20.0.0-27-g39925593c-D
the software that should make you happy
Loading...
Searching...
No Matches
Functions
JAnalysisSummary.cc File Reference

Program to produce analysis variables in offline files. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JHeadToolkit.hh"
#include "JDAQ/JDAQSummarysliceIO.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDynamics/JDynamics.hh"
#include "JGeometry3D/JCylinder3D.hh"
#include "JROOT/JManager.hh"
#include "JReconstruction/JAnalysisSummary.hh"
#include "JSirene/JVisibleEnergyToolkit.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JSummaryFileRouter.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JMeta.hh"
#include "JTrigger/JTriggerToolkit.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

Program to produce analysis variables in offline files.

The variable definition is given in JAnalysisSummary class.

Author
vcarretero

Definition in file JAnalysisSummary.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 49 of file JAnalysisSummary.cc.

50{
51 using namespace std;
52 using namespace JPP;
53 using namespace KM3NETDAQ;
54
58 JLimit_t& numberOfEvents = inputFile.getLimit();
59 double margin;
60 string detectorFile;
61 double Tmax_s;
62 int debug;
63
64 try {
65
66
67 JParser<> zap("Program to produce analysis variables in offline files. The variable definition is given in JAnalysisSummary class.");
68
69 zap['f'] = make_field(inputFile);
70 zap['n'] = make_field(numberOfEvents) = JLimit::max();
73 zap['m'] = make_field(margin) = 20.0;
74 zap['T'] = make_field(Tmax_s) = 100.0;
76 zap['d'] = make_field(debug) = 2;
77
78 zap(argc, argv);
79 }
80 catch(const exception& error) {
81 FATAL(error.what() << endl);
82 }
83
85
86 try {
88 }
89 catch(const JException& error) {
90 FATAL(error);
91 }
92
93 JCylinder3D can(detector.begin(), detector.end());
94 can.addMargin(margin);
95
97
99
100 try {
101
102 dynamics.reset(new JDynamics(detector, Tmax_s));
103
105 }
106 catch(const exception& error) {
107 if (!calibrationFile.empty()) {
108 FATAL(error.what());
109 }
110 }
111
112 JSummaryFileRouter summary(inputFile);
113
114 const JModuleRouter router(detector);
115
116 outputFile.open();
117 outputFile.put(JMeta(argc, argv));
118
119 for (JTreeScanner<Evt> in(inputFile, numberOfEvents); in.hasNext(); ) {
120
121 STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
122
124
125 Evt* evt = in.next();
126
127
128 for (vector<Trk>::iterator track = evt->mc_trks.begin(); track != evt->mc_trks.end(); ++track) {
129 track->clearusr(); // Prevent visible energy from being calculated based on `mc_usr_keys::energy_lost_in_can`
130 }
131
132 if (has_primary(*evt)) {
133
134 analysis.visible_energy_total = getVisibleEnergy (*evt, can);
135 analysis.visible_energy_lepton = (has_leading_lepton(*evt) ?
137 0.0);
138 analysis.visible_energy_hadron = analysis.visible_energy_total - analysis.visible_energy_lepton;
139 }
140
141 summary.update(JDAQChronometer(evt->det_id,
142 evt->run_id,
143 evt->frame_index,
144 JDAQUTCExtended(evt->t.GetSec(), evt->t.GetNanoSec() / 16)));
145
146 // Computation of max pmt getting a hit in a DOM for a given event, snapshot and triggered
148
149 for (const Hit& hit : evt->hits) {
150 bool valid = true;
151 if(router.hasModule(hit.dom_id)){
152
153 const JDAQSummaryFrame& frame = summary.getSummaryFrame(hit.dom_id);
154 const JModule& module = router.getModule(hit.dom_id);
155
156 valid = (getDAQStatus(frame, module, hit.channel_id) && // check UDP
157 getPMTStatus(frame, module, hit.channel_id) && // check if disabled, HRV or FIFO (almost) full
158 frame[hit.channel_id].is_valid() && // check if valid pmt
159 !module.getPMT(hit.channel_id).has(PMT_DISABLE)); // check if disabled pmt
160
161 }
162 if(valid){
163 snapshot[hit.dom_id].insert(hit.channel_id);
164
165 if(hit.trig) trigger[hit.dom_id].insert(hit.channel_id);
166 }
167
168 }
169
170 for (const auto& [dom_id, pmt_set] : snapshot) {
171 if (pmt_set.size() > analysis.nMaxPMT_snapshot) {
172
173 analysis.nMaxPMT_snapshot = pmt_set.size();
174 analysis.nMaxPMT_snapshot_ModuleID = dom_id;
175
176 }
177 }
178
179 for (const auto& [dom_id, pmt_set] : trigger) {
180 if (pmt_set.size() > analysis.nMaxPMT_trigger) {
181
182 analysis.nMaxPMT_trigger = pmt_set.size();
183 analysis.nMaxPMT_trigger_ModuleID = dom_id;
184
185 }
186 }
187
188 //Computation of the minimal distance from jshower vertex to a module
189
190 if (dynamics) {
191 dynamics->update(evt->t.GetSec());
192 }
193
194 if (has_reconstructed_jppshower(*evt)) {
195
197 const JTrack3D ts = getTrack(trk);
198
199 if (trk.status != TRK_ST_UNDEFINED) {
200
201 for (const auto& module : (dynamics ? dynamics->getDetector() : detector)) {
202
203 if (module.getFloor() != 0) {
204
205 const double D = getDistance(module.getPosition(), ts.getPosition());
206
207 if (D < analysis.Dmin) {
208
209 analysis.Dmin = D;
210 analysis.Dmin_ModuleID = module.getID();
211
212 }
213 }
214 }
215 }
216 }
217 outputFile.put(analysis);
218 }
219
220 JSingleFileScanner<JMeta> io(inputFile);
221
222 io >> outputFile;
223 STATUS(endl);
224 outputFile.close();
225
226}
string outputFile
#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
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Detector data structure.
Definition JDetector.hh:96
const JLocation & getLocation() const
Get location.
Definition JLocation.hh:70
Router for direct addressing of module data in detector data structure.
Data structure for a composite optical module.
Definition JModule.hh:76
const JPosition3D & getPosition() const
Get position.
General exception.
Definition JException.hh:24
Template definition of a multi-dimensional oscillation probability interpolation table.
void load()
Load oscillation probability table.
File router for fast addressing of summary data.
void insert(const JMultiFunction< __JFunction_t, __JMaplist_t, __JDistance_t > &input)
Insert multidimensional input.
Data storage class for rate measurements of all PMTs in one module.
Data structure for UTC time.
uint32_t dom_id(frame_idx_t idx)
bool has_primary(const Evt &evt)
Auxiliary function to check if an event contains a primary track.
JTrack3E getTrack(const Trk &track)
Get track.
bool has_leading_lepton(const Evt &event)
Auxiliary function to check if an event contains the leading lepton of a neutrino interaction.
JDetectorsHelper & getDetector()
Auxiliary function for helper object initialisation.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
double getDistance(const JFirst_t &first, const JSecond_t &second)
Get distance between objects.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
double getVisibleEnergyLeadingLepton(const Trk &, const JCylinder3D &)
double getVisibleEnergy(const Trk &, const JCylinder3D &)
Get the visible energy of a track.
bool getDAQStatus(const JDAQFrameStatus &frame, const JStatus &status)
Test status of DAQ.
bool getPMTStatus(const JStatus &status)
Test status of PMT.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
int frame_index
from the raw data
Definition Evt.hh:29
int run_id
DAQ run identifier.
Definition Evt.hh:26
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
Definition Evt.hh:49
int det_id
detector identifier from DAQ
Definition Evt.hh:23
TTimeStamp t
UTC time of the timeslice, or the event_time for MC. (default: 01 Jan 1970 00:00:00)
Definition Evt.hh:33
Definition Hit.hh:10
The cylinder used for photon tracking.
Definition JHead.hh:575
Detector file.
Definition JHead.hh:227
Dynamic detector calibration.
Definition JDynamics.hh:86
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
Struct for storing analysis variables.
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45
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
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition Trk.hh:15
const Trk & get_best_reconstructed_jppshower(const Evt &evt)
Get best reconstructed shower.
bool has_reconstructed_jppshower(const Evt &evt)
Test whether given event has a track with shower reconstruction.
static const int TRK_ST_UNDEFINED
MC or reco status was not defined for this track.
Definition trkmembers.hh:15