Jpp 20.0.0-195-g190c9e876
the software that should make you happy
Loading...
Searching...
No Matches
JCalibrateMuon.cc File Reference

Program to perform detector calibration using reconstructed muon trajectories. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <algorithm>
#include <memory>
#include "TROOT.h"
#include "TFile.h"
#include "TProfile.h"
#include "TH2D.h"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "JDAQ/JDAQEventIO.hh"
#include "JDAQ/JDAQTimesliceIO.hh"
#include "JDAQ/JDAQSummarysliceIO.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JDetector/JPMTParametersMap.hh"
#include "JDynamics/JDynamics.hh"
#include "JTrigger/JHitL0.hh"
#include "JTrigger/JBuildL0.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JParallelFileScanner.hh"
#include "JSupport/JSummaryFileRouter.hh"
#include "JSupport/JMeta.hh"
#include "JReconstruction/JEvt.hh"
#include "JReconstruction/JMuonGandalf.hh"
#include "JReconstruction/JMuonGandalfParameters_t.hh"
#include "JTools/JAbstractHistogram.hh"
#include "JROOT/JRootToolkit.hh"
#include "JROOT/JManager.hh"
#include "JCalibrate/JCalibrateMuon.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 perform detector calibration using reconstructed muon trajectories.

It is recommended to perform the detector calibration after JMuonGandalf.cc and to accordingly set option JMuonGandalfParameters_t::numberOfPrefits = 1, so that the best track from the previous output is used. Several histograms will be produced which can subsequently be processed with JHobbit.cc for the determination of the time calibration of optical modules and JFrodo.cc for the time-slewing correction.

Author
mdejong

Definition in file JCalibrateMuon.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 62 of file JCalibrateMuon.cc.

63{
64 using namespace std;
65 using namespace JPP;
66 using namespace KM3NETDAQ;
67
68 typedef JParallelFileScanner< JTypeList<JDAQEvent, JFIT::JEvt> > JParallelFileScanner_t;
69 typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
70 typedef JMultipleFileScanner<calibration_types> JCalibration_t;
71 typedef JAbstractHistogram<double> histogram_type;
72
73 JParallelFileScanner_t inputFile;
74 string outputFile;
75 JLimit_t& numberOfEvents = inputFile.getLimit();
76 string detectorFile;
77 JCalibration_t calibrationFile;
78 double Tmax_s;
79 string pdfFile;
80 JMuonGandalfParameters_t parameters;
81 JPMTParametersMap pmtParameters;
82 histogram_type calibrate;
83 string target;
84 int debug;
85
86 try {
87
88 parameters.numberOfPrefits = 1;
89
90 JParser<> zap("Program to perform detector calibration using reconstructed muon trajectories.");
91
92 zap['f'] = make_field(inputFile);
93 zap['o'] = make_field(outputFile) = "gandalf.root";
94 zap['a'] = make_field(detectorFile);
95 zap['+'] = make_field(calibrationFile) = JPARSER::initialised();
96 zap['T'] = make_field(Tmax_s) = 100.0;
97 zap['n'] = make_field(numberOfEvents) = JLimit::max();
98 zap['F'] = make_field(pdfFile);
99 zap['c'] = make_field(calibrate, "histogram for time calibration.");
100 zap['P'] = make_field(pmtParameters, "PMT simulation data (or corresponding file name)") = JPARSER::initialised();
101 zap['@'] = make_field(parameters) = JPARSER::initialised();
102 zap['R'] = make_field(target, "option for time calibration.") = module_t, string_t;
103 zap['d'] = make_field(debug) = 1;
104
105 zap(argc, argv);
106 }
107 catch(const exception& error) {
108 FATAL(error.what() << endl);
109 }
110
111
112 if (!calibrate.is_valid()) {
113 FATAL("Invalid calibration data " << calibrate << endl);
114 }
115
116 if (parameters.numberOfPrefits != 1) {
117 WARNING("Number of prefits " << parameters.numberOfPrefits << " != " << 1 << endl);
118 }
119
121
122 try {
123 load(detectorFile, detector);
124 }
125 catch(const JException& error) {
126 FATAL(error);
127 }
128
129 unique_ptr<JDynamics> dynamics;
130
131 if (!calibrationFile.empty()) {
132
133 try {
134
135 dynamics.reset(new JDynamics(detector, Tmax_s));
136
137 dynamics->load(calibrationFile);
138 }
139 catch(const exception& error) {
140 FATAL(error.what());
141 }
142 }
143
144 const JRouter_t* rpm = NULL;
145
146 if (target == module_t)
147 rpm = new JModuleRouter_t(detector);
148 else if (target == string_t)
149 rpm = new JStringRouter_t(detector);
150 else
151 FATAL("No valid target; check option -R" << endl);
152
153 const JModuleRouter router(dynamics ? dynamics->getDetector() : detector);
154
155 JSummaryFileRouter summary(inputFile);
156
157 const JMuonGandalf::storage_type storage(pdfFile, JTimeRange(parameters.TMin_ns, parameters.TMax_ns), parameters.TTS_ns);
158
159 JMuonGandalf fit(parameters, storage, pmtParameters, debug);
160
161 typedef vector<JHitL0> JDataL0_t;
162 typedef vector<JHitW0> JDataW0_t;
163
164 const JBuildL0<JHitL0> buildL0;
165
166
167 typedef JManager<string, TProfile> JManager_t;
168
169 TH2D ha("ha", NULL, 256, -0.5, 255.5,
170 calibrate.getNumberOfBins(), calibrate.getLowerLimit(), calibrate.getUpperLimit());
171
172 TProfile hb("hb", NULL, 256, -0.5, 255.5);
173
174 TProfile hr("hr", NULL, 60, 0.0, 150.0);
175
176 TH2D h2("h2", NULL, rpm->getN(), -0.5, rpm->getN() - 0.5,
177 calibrate.getNumberOfBins(), calibrate.getLowerLimit(), calibrate.getUpperLimit());
178
179 JManager_t g1(new TProfile("%", NULL, rpm->getN(), -0.5, rpm->getN() - 0.5, -1.0, +1.0));
180
181
182 while (inputFile.hasNext()) {
183
184 STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
185
186 multi_pointer_type ps = inputFile.next();
187
188 JDAQEvent* tev = ps;
189 JFIT::JEvt* in = ps;
190
191 summary.update(*tev);
192
193 if (dynamics) {
194 dynamics->update(*tev);
195 }
196
197 in->select(parameters.numberOfPrefits, qualitySorter);
198
199 JDataL0_t dataL0;
200
201 buildL0(*tev, router, true, back_inserter(dataL0));
202
203 for (JFIT::JEvt::const_iterator track = in->begin(); track != in->end(); ++track) {
204
205 const JRotation3D R (getDirection(*track));
206 const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
207 JRange<double> Z_m;
208
209 if (track->hasW(JSTART_LENGTH_METRES)) {
210 Z_m = JZRange(0.0, track->getW(JSTART_LENGTH_METRES)) + JRange<double>(parameters.ZMin_m, parameters.ZMax_m);
211 }
212
213 const JFIT::JModel<JLine1Z> match(tz, parameters.roadWidth_m, JRange<double>(parameters.TMin_ns, parameters.TMax_ns), Z_m);
214
215 // hit selection based on start value
216
217 JDataW0_t data;
218
219 for (JDataL0_t::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
220
221 const JPMTIdentifier id(i->getModuleID(), i->getPMTAddress());
222
223 const JPMTParameters& wip = pmtParameters.getPMTParameters(id);
224
225 const int type = wip.getType();
226 const double QE = wip.QE;
227 const double R_Hz = summary.getRate(i->getPMTIdentifier(), parameters.R_Hz);
228
229 JHitW0 hit(*i, type, QE, R_Hz);
230
231 hit.rotate(R);
232
233 if (match(hit)) {
234 data.push_back(hit);
235 }
236 }
237
238 // select first hit
239
240 sort(data.begin(), data.end(), JHitL0::compare);
241
242 JDataW0_t::iterator __end = unique(data.begin(), data.end(), equal_to<JDAQPMTIdentifier>());
243
244
245 // set fit parameters
246
247 if (track->getE() > 0.1)
248 fit.JRegressor_t::E_GeV = track->getE();
249 else
250 fit.JRegressor_t::E_GeV = parameters.E_GeV;
251
252 set<int> buffer;
253
254 for (JDataW0_t::const_iterator hit = data.begin(); hit != __end; ++hit) {
255 buffer.insert(rpm->getIndex(hit->getModuleID()));
256 }
257
258 const JLine3Z ta(tz);
259
260 for (const int index : buffer) {
261
262 JDataW0_t::iterator q = partition(data.begin(), __end, [rpm, index](const JHitW0& hit) { return rpm->getIndex(hit.getModuleID()) != index; });
263
264 if (distance(data.begin(), q) - fit.parameters.size() > 0) {
265
266 fit(ta, data.begin(), q); // re-fit
267
268 for (JDataW0_t::const_iterator hit = q; hit != __end; ++hit) {
269
270 const double t1 = fit.value.getT(hit->getPosition());
271 JTrack3D gradient = fit(fit.value, *hit).gradient;
272
273 gradient.rotate_back(R);
274
275 ha.Fill(hit->getToT(), hit->getT1() - t1);
276 hb.Fill(hit->getToT(), gradient.getT());
277
278 hr.Fill(fit.value.getDistance(*hit), gradient.getT());
279
280 h2.Fill(index, hit->getT() - t1);
281
282 g1["T"]->Fill(index, gradient.getT());
283 g1["X"]->Fill(index, gradient.getX());
284 g1["Y"]->Fill(index, gradient.getY());
285 g1["Z"]->Fill(index, gradient.getZ());
286 }
287 }
288 }
289 }
290 }
291 STATUS(endl);
292
293 TFile out(outputFile.c_str(), "recreate");
294
295 putObject(out, JMeta(argc, argv));
296
297 out << ha;
298 out << hb;
299 out << hr;
300 out << h2;
301 out << g1;
302
303 out.Write();
304 out.Close();
305
306 delete rpm;
307}
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:74
#define WARNING(A)
Definition JMessage.hh:65
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Double_t g1(const Double_t x)
Function.
Definition JQuantiles.cc:25
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Detector data structure.
Definition JDetector.hh:96
Router for direct addressing of module data in detector data structure.
Auxiliary class for map of PMT parameters.
const JPMTParameters & getPMTParameters(const JPMTIdentifier &id) const
Get PMT parameters.
Data structure for PMT parameters.
double QE
relative quantum efficiency
int getType() const
Get type for for time-slewing correction.
Data structure for set of track fit results.
void select(const JSelector_t &selector)
Select fits.
Data structure for fit of straight line paralel to z-axis.
Definition JLine1Z.hh:29
Data structure for fit of straight line in positive z-direction.
Definition JLine3Z.hh:40
JAxis3D & rotate_back(const JRotation3D &R)
Rotate back axis.
Definition JAxis3D.hh:240
JPosition3D & rotate(const JRotation3D &R)
Rotate.
double getT(const JVector3D &pos) const
Get arrival time of Cherenkov light at given position.
Definition JTrack3D.hh:87
double getY() const
Get y position.
Definition JVector3D.hh:104
double getZ() const
Get z position.
Definition JVector3D.hh:115
double getX() const
Get x position.
Definition JVector3D.hh:94
General exception.
Definition JException.hh:24
Utility class to parse command line options.
Definition JParser.hh:1698
Auxiliary class for a hit with background rate value.
Definition JHitW0.hh:25
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys.
Definition JManager.hh:47
General purpose class for object reading from a list of file names.
General purpose class for parallel reading of objects from a single file or multiple files.
File router for fast addressing of summary data.
Range of values.
Definition JRange.hh:42
Template L0 hit builder.
Definition JBuildL0.hh:38
static const int JSTART_LENGTH_METRES
distance between projected positions on the track of optical modules for which the response does not ...
JDirection3D getDirection(const Vec &dir)
Get direction.
JPosition3D getPosition(const Vec &pos)
Get position.
static const std::string string_t
string
Definition JSydney.cc:90
JTOOLS::JRange< double > JTimeRange
Type definition for time range (unit [s]).
const char *const module_t
routing by module
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
JTOOLS::JRange< double > JZRange
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
bool qualitySorter(const JFit &first, const JFit &second)
Comparison of fit results.
bool putObject(TDirectory &dir, const TObject &object)
Write object to ROOT directory.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
Detector file.
Definition JHead.hh:227
Target.
Definition JHead.hh:300
Interface for routing module identifier to index and vice versa.
virtual int getIndex(const int id) const =0
Get index.
virtual size_t getN() const =0
Get number of indices.
Dynamic detector calibration.
Definition JDynamics.hh:81
Auxiliary class to match data points with given model.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
double TMin_ns
minimal time w.r.t. Cherenkov hypothesis [ns]
double TMax_ns
maximal time w.r.t. Cherenkov hypothesis [ns]
Wrapper class to make final fit of muon trajectory.
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
Simple data structure for histogram binning.
Auxiliary data structure for sorting of hits.
Definition JHitL0.hh:85