Jpp test-rotations-old-533-g2bdbdb559
the software that should make you happy
Loading...
Searching...
No Matches
JSpark.cc File Reference

Program to monitor variables for spark removal 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 "JROOT/JManager.hh"
#include "JReconstruction/JSparkSummary.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 monitor variables for spark removal in offline files.

The variable definition is given in JSparkSummary class.

Author
vcarretero

Definition in file software/JReconstruction/JSpark.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 45 of file software/JReconstruction/JSpark.cc.

46{
47 using namespace std;
48 using namespace JPP;
49 using namespace KM3NETDAQ;
50
51 //typedef JTYPELIST<JMeta, TTree>::typelist typelist;
52
56 JLimit_t& numberOfEvents = inputFile.getLimit();
57 string detectorFile;
58 double Tmax_s;
59 int debug;
60
61 try {
62
63
64 JParser<> zap("Program to monitor variables for spark removal in offline files. The variable definition is given in JSparkSummary class.");
65
66 zap['f'] = make_field(inputFile);
67 zap['n'] = make_field(numberOfEvents) = JLimit::max();
68 zap['a'] = make_field(detectorFile);
69 zap['+'] = make_field(calibrationFile) = JPARSER::initialised();
70 zap['T'] = make_field(Tmax_s) = 100.0;
71 zap['o'] = make_field(outputFile);
72 zap['d'] = make_field(debug) = 2;
73
74 zap(argc, argv);
75 }
76 catch(const exception& error) {
77 FATAL(error.what() << endl);
78 }
79
81
82 try {
83 load(detectorFile, detector);
84 }
85 catch(const JException& error) {
86 FATAL(error);
87 }
88
90
91 unique_ptr<JDynamics> dynamics;
92
93 try {
94
95 dynamics.reset(new JDynamics(detector, Tmax_s));
96
97 dynamics->load(calibrationFile);
98 }
99 catch(const exception& error) {
100 if (!calibrationFile.empty()) {
101 FATAL(error.what());
102 }
103 }
104
105 JSummaryFileRouter summary(inputFile);
106
107 const JModuleRouter router(detector);
108
109 outputFile.open();
110 outputFile.put(JMeta(argc, argv));
111
112 for (JTreeScanner<Evt> in(inputFile, numberOfEvents); in.hasNext(); ) {
113
114 STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
115
117
118 const Evt* evt = in.next();
119
120 summary.update(JDAQChronometer(evt->det_id,
121 evt->run_id,
122 evt->frame_index,
123 JDAQUTCExtended(evt->t.GetSec(), evt->t.GetNanoSec() / 16)));
124
125 // Computation of max pmt getting a hit in a DOM for a given event, snapshot and triggered
127
128 for (const Hit& hit : evt->hits) {
129 bool valid = true;
130 if(router.hasModule(hit.dom_id)){
131
132 const JDAQSummaryFrame& frame = summary.getSummaryFrame(hit.dom_id);
133 const JModule& module = router.getModule(hit.dom_id);
134
135 valid = (getDAQStatus(frame, module, hit.channel_id) && // check UDP
136 getPMTStatus(frame, module, hit.channel_id) && // check if disabled, HRV or FIFO (almost) full
137 frame[hit.channel_id].is_valid() && // check if valid pmt
138 !module.getPMT(hit.channel_id).has(PMT_DISABLE)); // check if disabled pmt
139
140 }
141 if(valid){
142 snapshot[hit.dom_id].insert(hit.channel_id);
143
144 if(hit.trig) trigger[hit.dom_id].insert(hit.channel_id);
145 }
146
147 }
148
149 for (const auto& [dom_id, pmt_set] : snapshot) {
150 if (pmt_set.size() > spark.nMaxPMT_snapshot) {
151
152 spark.nMaxPMT_snapshot = pmt_set.size();
154
155 }
156 }
157
158 for (const auto& [dom_id, pmt_set] : trigger) {
159 if (pmt_set.size() > spark.nMaxPMT_trigger) {
160
161 spark.nMaxPMT_trigger = pmt_set.size();
163
164 }
165 }
166
167 //Computation of the minimal distance from jshower vertex to a module
168
169 if (dynamics) {
170 dynamics->update(evt->t.GetSec());
171 }
172
173 if (has_reconstructed_jppshower(*evt)) {
174
175 const Trk trk = get_best_reconstructed_jppshower(*evt);
176 const JTrack3D ts = getTrack(trk);
177
178 if (trk.status != TRK_ST_UNDEFINED) {
179
180 for (const auto& module : (dynamics ? dynamics->getDetector() : detector)) {
181
182 if (module.getFloor() != 0) {
183
184 const double D = getDistance(module.getPosition(), ts.getPosition());
185
186 if (D < spark.Dmin) {
187
188 spark.Dmin = D;
189 spark.Dmin_ModuleID = module.getID();
190
191 }
192 }
193 }
194 }
195 }
196 outputFile.put(spark);
197 }
198
199 JSingleFileScanner<JMeta> io(inputFile);
200
201 io >> outputFile;
202 STATUS(endl);
203 outputFile.close();
204
205}
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
int getFloor() const
Get floor number.
Definition JLocation.hh:146
Router for direct addressing of module data in detector data structure.
Data structure for a composite optical module.
Definition JModule.hh:75
const JPosition3D & getPosition() const
Get position.
General exception.
Definition JException.hh:24
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.
Object reading from a list of files.
File router for fast addressing of summary data.
Template definition for direct access of elements in ROOT TChain.
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)
JTrack3E getTrack(const Trk &track)
Get track.
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).
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< Hit > hits
list of hits
Definition Evt.hh:38
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
int dom_id
module identifier from the data (unique in the detector).
Definition Hit.hh:14
ULong64_t trig
non-zero if the hit is a trigger hit.
Definition Hit.hh:18
unsigned int channel_id
PMT channel id {0,1, .., 30} local to moduke.
Definition Hit.hh:15
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 spark removal summary data.
int nMaxPMT_trigger_ModuleID
DOM ID with maximum number of PMT triggered.
size_t nMaxPMT_trigger
maximum number of PMT with at least one triggered hit in any DOM
size_t nMaxPMT_snapshot
maximum number of PMT with at least one hit in any DOM
double Dmin
Minimum distance from reconstructed shower vertex to any DOM [m].
int Dmin_ModuleID
DOM ID corresponding to the DOM at Dmin_DOM.
int nMaxPMT_snapshot_ModuleID
DOM ID with maximum number of PMT hits in the snapshot.
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
int status
MC or reconstruction status code, see km3net-dataformat/definitions/trkmembers.csv for values.
Definition Trk.hh:28
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:14