Jpp 20.0.0-195-g190c9e876
the software that should make you happy
Loading...
Searching...
No Matches
software/JReconstruction/JMuonCompass.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <vector>
5#include <algorithm>
6#include <memory>
7
8#include "TROOT.h"
9#include "TFile.h"
10#include "TH2D.h"
11
14
15#include "JDAQ/JDAQEventIO.hh"
17
22
24
25#include "JTrigger/JHit.hh"
26#include "JTrigger/JFrame.hh"
28#include "JTrigger/JHitL0.hh"
29#include "JTrigger/JBuildL0.hh"
31
32#include "JSupport/JSupport.hh"
36#include "JSupport/JMeta.hh"
37
42
43#include "JROOT/JRootToolkit.hh"
44
45#include "Jeep/JParser.hh"
46#include "Jeep/JMessage.hh"
47
48/**
49 * \file
50 *
51 * Program to perform compass calibration using reconstructed muon trajectories.
52 *
53 * \author mdejong
54 */
55int main(int argc, char **argv)
56{
57 using namespace std;
58 using namespace JPP;
59 using namespace KM3NETDAQ;
60
61 typedef JParallelFileScanner< JTypeList<JDAQEvent, JFIT::JEvt> > JParallelFileScanner_t;
62 typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
63 typedef JMultipleFileScanner<calibration_types> JCalibration_t;
64
65 JParallelFileScanner_t inputFile;
66 string outputFile;
67 JLimit_t& numberOfEvents = inputFile.getLimit();
68 string detectorFile;
69 JCalibration_t calibrationFile;
70 double Tmax_s;
71 string pdfFile;
72 JMuonGandalfParameters_t parameters;
73 JPMTParametersMap pmtParameters;
74 int debug;
75
76 try {
77
78 parameters.numberOfPrefits = 1;
79
80 JParser<> zap("Program to perform compass calibration using reconstructed muon trajectories.");
81
82 zap['f'] = make_field(inputFile);
83 zap['o'] = make_field(outputFile) = "compass.root";
84 zap['a'] = make_field(detectorFile);
85 zap['n'] = make_field(numberOfEvents) = JLimit::max();
86 zap['+'] = make_field(calibrationFile, "dynamical calibration data") = JPARSER::initialised();
87 zap['T'] = make_field(Tmax_s, "dynamical update time [s]") = 100.0;
88 zap['F'] = make_field(pdfFile, "PDFs");
89 zap['@'] = make_field(parameters, "fit parameters") = JPARSER::initialised();
90 zap['P'] = make_field(pmtParameters, "PMT parameters") = JPARSER::initialised();
91 zap['d'] = make_field(debug) = 1;
92
93 zap(argc, argv);
94 }
95 catch(const exception& error) {
96 FATAL(error.what() << endl);
97 }
98
99
100 if (parameters.numberOfPrefits != 1) {
101 WARNING("Number of prefits " << parameters.numberOfPrefits << " != " << 1 << endl);
102 }
103
105
106 try {
107 load(detectorFile, detector);
108 }
109 catch(const JException& error) {
110 FATAL(error);
111 }
112
113 unique_ptr<JDynamics> dynamics;
114
115 if (!calibrationFile.empty()) {
116
117 try {
118
119 dynamics.reset(new JDynamics(detector, Tmax_s));
120
121 dynamics->load(calibrationFile);
122 }
123 catch(const exception& error) {
124 FATAL(error.what());
125 }
126 }
127
128 const JModuleRouter router(dynamics ? dynamics->getDetector() : detector);
129
130 JSummaryFileRouter summary(inputFile);
131
132 const JMuonGandalf::storage_type storage(pdfFile, JTimeRange(parameters.TMin_ns, parameters.TMax_ns), parameters.TTS_ns);
133
134 JMuonGandalf fit(parameters, storage, pmtParameters, debug);
135
136 typedef vector<JHitL0> JDataL0_t;
137 typedef vector<JHitW0> JDataW0_t;
138
139 const JBuildL0<JHitL0> buildL0;
140
141 const int nx = getNumberOfModules(detector, true);
142 const int ny = 101;
143
144 TH2D h2(h2_t, NULL, nx, -0.5, nx - 0.5, ny, -PI, +PI);
145
146 while (inputFile.hasNext()) {
147
148 STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
149
150 multi_pointer_type ps = inputFile.next();
151
152 JDAQEvent* tev = ps;
153 JFIT::JEvt* in = ps;
154
155 summary.update(*tev);
156
157 if (dynamics) {
158 dynamics->update(*tev);
159 }
160
161 in->select(parameters.numberOfPrefits, qualitySorter);
162
163 JDataL0_t dataL0;
164
165 buildL0(*tev, router, true, back_inserter(dataL0));
166
167 for (JFIT::JEvt::const_iterator track = in->begin(); track != in->end(); ++track) {
168
169 const JRotation3D R (getDirection(*track));
170 const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
171 JRange<double> Z_m;
172
173 if (track->hasW(JSTART_LENGTH_METRES)) {
174 Z_m = JZRange(0.0, track->getW(JSTART_LENGTH_METRES)) + JRange<double>(parameters.ZMin_m, parameters.ZMax_m);
175 }
176
177 const JFIT::JModel<JLine1Z> match(tz, parameters.roadWidth_m, JRange<double>(parameters.TMin_ns, parameters.TMax_ns), Z_m);
178
179 // hit selection based on start value
180
182
183 for (JDataL0_t::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
184
185 const JPMTIdentifier id(i->getModuleID(), i->getPMTAddress());
186
187 const JPMTParameters& wip = pmtParameters.getPMTParameters(id);
188
189 const int type = wip.getType();
190 const double QE = wip.QE;
191 const double R_Hz = summary.getRate(i->getPMTIdentifier(), parameters.R_Hz);
192
193 JHitW0 hit(*i, type, QE, R_Hz);
194
195 hit.rotate(R);
196
197 if (match(hit)) {
198 data[hit.getModuleID()].push_back(hit);
199 }
200 }
201
202 const JLine3Z ta(tz);
203
204 for (auto& i : data) {
205
206 const JModule& module = router.getModule(i.first);
207
208 // select first hit
209
210 sort(i.second.begin(), i.second.end(), JHitL0::compare);
211
212 JDataW0_t::iterator __end = unique(i.second.begin(), i.second.end(), equal_to<JDAQPMTIdentifier>());
213
214 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
215
216 const double x = router.getIndex(i.first);
217 const double y = h2.GetYaxis()->GetBinCenter(iy);
218
219 const JRotation3Z Rz(y);
220
221 double chi2 = 0.0;
222
223 for (JDataW0_t::const_iterator p = i.second.begin(); p != __end; ++p) {
224
225 JHitW0 hit(*p);
226
227 hit.rotate_back(R);
228
229 hit.sub(module.getPosition());
230 hit.rotate(Rz);
231 hit.add(module.getPosition());
232
233 hit.rotate(R);
234
235 chi2 += fit(ta, hit);
236 }
237
238 h2.Fill(x, y, chi2);
239 }
240 }
241 }
242 }
243 STATUS(endl);
244
245 TFile out(outputFile.c_str(), "recreate");
246
247 putObject(out, JMeta(argc, argv));
248
249 out << h2;
250
251 out.Write();
252 out.Close();
253}
string outputFile
Data structure for detector geometry and calibration.
Dynamic detector calibration.
Basic data structure for L0 hit.
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
#define WARNING(A)
Definition JMessage.hh:65
ROOT I/O of application specific meta data.
Direct access to module in detector data structure.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
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
ROOT TTree parameter settings of various packages.
Basic data structure for time and time over threshold information of hit.
Detector data structure.
Definition JDetector.hh:96
Router for direct addressing of module data in detector data structure.
const int getIndex(const JObjectID &id) const
Get index of module.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition JModule.hh:76
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
JAxis3D & rotate(const JRotation3D &R)
Rotate axis.
Definition JAxis3D.hh:225
JPosition3D & rotate(const JRotation3D &R)
Rotate.
const JPosition3D & getPosition() const
Get position.
Rotation around Z-axis.
JVector3D & add(const JVector3D &vector)
Add vector.
Definition JVector3D.hh:142
JVector3D & sub(const JVector3D &vector)
Subtract vector.
Definition JVector3D.hh:158
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
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 JDAQPMTIdentifier &id) const
Get rate.
Range of values.
Definition JRange.hh:42
Template L0 hit builder.
Definition JBuildL0.hh:38
int getModuleID() const
Get module identifier.
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.
JTOOLS::JRange< double > JTimeRange
Type definition for time range (unit [s]).
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.
const char *const h2_t
Name of histogram with results from JMuonCompass.cc.
bool putObject(TDirectory &dir, const TObject &object)
Write object to ROOT directory.
static const JModuleCounter getNumberOfModules
Function object to count unique modules.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
int main(int argc, char **argv)
Detector file.
Definition JHead.hh:227
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
Auxiliary data structure for sorting of hits.
Definition JHitL0.hh:85