Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JCalibrateMuon.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <vector>
5#include <set>
6#include <algorithm>
7#include <memory>
8
9#include "TROOT.h"
10#include "TFile.h"
11#include "TProfile.h"
12#include "TH2D.h"
13
16
17#include "JDAQ/JDAQEventIO.hh"
20
24
26
27#include "JTrigger/JHit.hh"
28#include "JTrigger/JFrame.hh"
30#include "JTrigger/JHitL0.hh"
31#include "JTrigger/JBuildL0.hh"
33
34#include "JSupport/JSupport.hh"
37#include "JSupport/JMeta.hh"
38
42
44#include "JROOT/JRootToolkit.hh"
45#include "JROOT/JManager.hh"
46
48
49#include "Jeep/JParser.hh"
50#include "Jeep/JMessage.hh"
51
52/**
53 * \file
54 *
55 * Program to perform detector calibration using reconstructed muon trajectories.
56 *
57 * It is recommended
58 * to perform the detector calibration after JMuonGandalf.cc and
59 * to accordingly set option <tt>JMuonGandalfParameters_t::numberOfPrefits = 1</tt>,
60 * so that the best track from the previous output is used.
61 * Several histograms will be produced which can subsequently be processed with JHobbit.cc for
62 * the determination of the time calibration of optical modules and JFrodo.cc for the time-slewing correction.
63 * \author mdejong
64 */
65int main(int argc, char **argv)
66{
67 using namespace std;
68 using namespace JPP;
69 using namespace KM3NETDAQ;
70
71 typedef JParallelFileScanner< JTypeList<JDAQEvent, JFIT::JEvt> > JParallelFileScanner_t;
72 typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
74 JACOUSTICS::JEvt>::typelist calibration_types;
75 typedef JMultipleFileScanner<calibration_types> JCalibration_t;
76 typedef JAbstractHistogram<double> histogram_type;
77
78 JParallelFileScanner_t inputFile;
79 string outputFile;
80 JLimit_t& numberOfEvents = inputFile.getLimit();
81 string detectorFile;
82 JCalibration_t calibrationFile;
83 double Tmax_s;
84 string pdfFile;
85 JMuonGandalfParameters_t parameters;
86 histogram_type calibrate;
87 string target;
88 int debug;
89
90 try {
91
92 parameters.numberOfPrefits = 1;
93
94 JParser<> zap("Program to perform detector calibration using reconstructed muon trajectories.");
95
96 zap['f'] = make_field(inputFile);
97 zap['o'] = make_field(outputFile) = "gandalf.root";
98 zap['a'] = make_field(detectorFile);
99 zap['+'] = make_field(calibrationFile) = JPARSER::initialised();
100 zap['T'] = make_field(Tmax_s) = 100.0;
101 zap['n'] = make_field(numberOfEvents) = JLimit::max();
102 zap['P'] = make_field(pdfFile);
103 zap['c'] = make_field(calibrate, "histogram for time calibration.");
104 zap['@'] = make_field(parameters) = JPARSER::initialised();
105 zap['R'] = make_field(target, "option for time calibration.") = module_t, string_t;
106 zap['d'] = make_field(debug) = 1;
107
108 zap(argc, argv);
109 }
110 catch(const exception& error) {
111 FATAL(error.what() << endl);
112 }
113
114
115 if (!calibrate.is_valid()) {
116 FATAL("Invalid calibration data " << calibrate << endl);
117 }
118
119 if (parameters.numberOfPrefits != 1) {
120 WARNING("Number of prefits " << parameters.numberOfPrefits << " != " << 1 << endl);
121 }
122
124
125 try {
126 load(detectorFile, detector);
127 }
128 catch(const JException& error) {
129 FATAL(error);
130 }
131
132 unique_ptr<JDynamics> dynamics;
133
134 if (!calibrationFile.empty()) {
135
136 try {
137
138 dynamics.reset(new JDynamics(detector, Tmax_s));
139
140 dynamics->load(calibrationFile);
141 }
142 catch(const exception& error) {
143 FATAL(error.what());
144 }
145 }
146
147 const JRouter_t* rpm = NULL;
148
149 if (target == module_t)
150 rpm = new JModuleRouter_t(detector);
151 else if (target == string_t)
152 rpm = new JStringRouter_t(detector);
153 else
154 FATAL("No valid target; check option -R" << endl);
155
156 const JModuleRouter router(dynamics ? dynamics->getDetector() : detector);
157
158 JSummaryFileRouter summary(inputFile, parameters.R_Hz);
159
160 const JMuonGandalf::storage_type storage(pdfFile, parameters.TTS_ns);
161
162 JMuonGandalf fit(parameters, storage, debug);
163
164 typedef vector<JHitL0> JDataL0_t;
165 typedef vector<JHitW0> JDataW0_t;
166
167 const JBuildL0<JHitL0> buildL0;
168
169
170 typedef JManager<string, TProfile> JManager_t;
171
172 TH2D ha("ha", NULL, 256, -0.5, 255.5,
173 calibrate.getNumberOfBins(), calibrate.getLowerLimit(), calibrate.getUpperLimit());
174
175 TProfile hb("hb", NULL, 256, -0.5, 255.5);
176
177 TProfile hr("hr", NULL, 60, 0.0, 150.0);
178
179 TH2D h2("h2", NULL, rpm->getN(), -0.5, rpm->getN() - 0.5,
180 calibrate.getNumberOfBins(), calibrate.getLowerLimit(), calibrate.getUpperLimit());
181
182 JManager_t g1(new TProfile("%", NULL, rpm->getN(), -0.5, rpm->getN() - 0.5, -1.0, +1.0));
183
184
185 while (inputFile.hasNext()) {
186
187 STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
188
189 multi_pointer_type ps = inputFile.next();
190
191 JDAQEvent* tev = ps;
192 JFIT::JEvt* in = ps;
193
194 summary.update(*tev);
195
196 if (dynamics) {
197 dynamics->update(*tev);
198 }
199
200 in->select(parameters.numberOfPrefits, qualitySorter);
201
202 JDataL0_t dataL0;
203
204 buildL0(*tev, router, true, back_inserter(dataL0));
205
206 for (JFIT::JEvt::const_iterator track = in->begin(); track != in->end(); ++track) {
207
208 const JRotation3D R (getDirection(*track));
209 const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
210 JRange<double> Z_m;
211
212 if (track->hasW(JSTART_LENGTH_METRES)) {
213 Z_m = JZRange(0.0, track->getW(JSTART_LENGTH_METRES)) + JRange<double>(parameters.ZMin_m, parameters.ZMax_m);
214 }
215
216 const JFIT::JModel<JLine1Z> match(tz, parameters.roadWidth_m, JRange<double>(parameters.TMin_ns, parameters.TMax_ns), Z_m);
217
218 // hit selection based on start value
219
220 JDataW0_t data;
221
222 for (JDataL0_t::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
223
224 double rate_Hz = summary.getRate(*i);
225
226 if (rate_Hz <= 0.0) {
227 rate_Hz = summary.getRate();
228 }
229
230 JHitW0 hit(*i, rate_Hz);
231
232 hit.rotate(R);
233
234 if (match(hit)) {
235 data.push_back(hit);
236 }
237 }
238
239 // select first hit
240
241 sort(data.begin(), data.end(), JHitL0::compare);
242
243 JDataW0_t::iterator __end = unique(data.begin(), data.end(), equal_to<JDAQPMTIdentifier>());
244
245
246 // set fit parameters
247
248 if (track->getE() > 0.1)
249 fit.JRegressor_t::E_GeV = track->getE();
250 else
251 fit.JRegressor_t::E_GeV = parameters.E_GeV;
252
253 set<int> buffer;
254
255 for (JDataW0_t::const_iterator hit = data.begin(); hit != __end; ++hit) {
256 buffer.insert(rpm->getIndex(hit->getModuleID()));
257 }
258
259 const JLine3Z ta(tz);
260
261 for (const int index : buffer) {
262
263 JDataW0_t::iterator q = partition(data.begin(), __end, [rpm, index](const JHitW0& hit) { return rpm->getIndex(hit.getModuleID()) != index; });
264
265 if (distance(data.begin(), q) - fit.parameters.size() > 0) {
266
267 fit(ta, data.begin(), q); // re-fit
268
269 for (JDataW0_t::const_iterator hit = q; hit != __end; ++hit) {
270
271 const double t1 = fit.value.getT(hit->getPosition());
272 JTrack3D gradient = fit(fit.value, *hit).gradient;
273
274 gradient.rotate_back(R);
275
276 ha.Fill(hit->getToT(), hit->getT1() - t1);
277 hb.Fill(hit->getToT(), gradient.getT());
278
279 hr.Fill(fit.value.getDistance(*hit), gradient.getT());
280
281 h2.Fill(index, hit->getT() - t1);
282
283 g1["T"]->Fill(index, gradient.getT());
284 g1["X"]->Fill(index, gradient.getX());
285 g1["Y"]->Fill(index, gradient.getY());
286 g1["Z"]->Fill(index, gradient.getZ());
287 }
288 }
289 }
290 }
291 }
292 STATUS(endl);
293
294 TFile out(outputFile.c_str(), "recreate");
295
296 putObject(out, JMeta(argc, argv));
297
298 out << ha;
299 out << hb;
300 out << hr;
301 out << h2;
302 out << g1;
303
304 out.Write();
305 out.Close();
306
307 delete rpm;
308}
int main(int argc, char **argv)
string outputFile
Data structure for detector geometry and calibration.
Dynamic detector calibration.
Basic data structure for L0 hit.
Dynamic ROOT object management.
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
#define WARNING(A)
Definition JMessage.hh:65
ROOT I/O of application specific meta data.
Direct access to module in detector data structure.
Parallel scanning of objects from a single file or multiple files according a format that follows fro...
Utility class to parse command line options.
#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
ROOT TTree parameter settings of various packages.
Basic data structure for time and time over threshold information of hit.
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.
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
JAxis3D & rotate(const JRotation3D &R)
Rotate axis.
Definition JAxis3D.hh:225
JPosition3D & rotate(const JRotation3D &R)
Rotate.
const JPosition3D & getPosition() const
Get position.
double getT(const JVector3D &pos) const
Get arrival time of Cherenkov light at given position.
Definition JTrack3D.hh:126
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:23
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.
void update(const JDAQHeader &header)
Update router.
double getRate() const
Get default rate.
Range of values.
Definition JRange.hh:42
Template L0 hit builder.
Definition JBuildL0.hh:38
double getT1() const
Get leading edge of hit.
double getToT() const
Get calibrated time over threshold of hit.
double getT() const
Get calibrated time of hit.
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
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
Acoustic event fit.
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.
Orientation of module.
Dynamic detector calibration.
Definition JDynamics.hh:86
Auxiliary class to match data points with given model.
Auxiliary class for recursive type list generation.
Definition JTypeList.hh:351
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