Jpp 20.0.0-195-g190c9e876
the software that should make you happy
Loading...
Searching...
No Matches
JMuonGandalf.hh
Go to the documentation of this file.
1#ifndef __JRECONSTRUCTION__JMUONGANDALF__
2#define __JRECONSTRUCTION__JMUONGANDALF__
3
4#include <string>
5#include <iostream>
6#include <iomanip>
7#include <vector>
8#include <algorithm>
9
10#include "TMatrixDSym.h"
11#include "TMatrixDSymEigen.h"
12
16
17#include "JTrigger/JHitL0.hh"
18#include "JTrigger/JBuildL0.hh"
19
20#include "JFit/JFitToolkit.hh"
21#include "JFit/JLine1Z.hh"
22#include "JFit/JLine3Z.hh"
23#include "JFit/JModel.hh"
24#include "JFit/JGandalf.hh"
26
31
32#include "JPhysics/JPDFTable.hh"
34#include "JPhysics/JGeane.hh"
35
38
40
42
44
45#include "JTools/JRange.hh"
46
47#include "Jeep/JMessage.hh"
48
49
50/**
51 * \author mdejong, gmaggi
52 */
53
54namespace JRECONSTRUCTION {}
55namespace JPP { using namespace JRECONSTRUCTION; }
56
57namespace JRECONSTRUCTION {
58
63 using JFIT::JRegressor;
64 using JFIT::JLine3Z;
65 using JFIT::JGandalf;
66 using JFIT::JTimeRange;
68
69
70 /**
71 * Wrapper class to make final fit of muon trajectory.
72 *
73 * The JMuonGandalf fit uses one or more start values (usually taken from the output of JMuonSimplex).\n
74 * All hits of which the PMT position lies within a set road width (JMuonGandalfParameters_t::roadWidth_m) and
75 * time is within a set window (JMuonGandalfParameters_t::TMin_ns, JMuonGandalfParameters_t::TMax_ns) around the Cherenkov hypothesis are taken.\n
76 * In case there are multiple hits from the same PMT is the specified window,
77 * the first hit is taken and the other hits are discarded.\n
78 * The PDF is accordingly evaluated, i.e.\ the normalised probability for a first hit at the given time of the hit is taken.
79 * The normalisation is consistently based on the specified time window.\n
80 * Note that this hit selection is unbiased with respect to the PDF of a single PMT.
81 */
82 struct JMuonGandalf :
84 public JRegressor<JLine3Z, JGandalf>
85 {
89
90 using JRegressor_t::operator();
91
92 /**
93 * Input data type.
94 */
95 struct input_type :
96 public JDAQEventHeader
97 {
98 /**
99 * Default constructor.
100 */
102 {}
103
104
105 /**
106 * Constructor.
107 *
108 * \param header header
109 * \param in start values
110 * \param coverage coverage
111 */
113 const JEvt& in,
114 const coverage_type& coverage) :
115 JDAQEventHeader(header),
116 in(in),
118 {}
119
123 };
124
125
126 /**
127 * Constructor
128 *
129 * \param parameters parameters
130 * \param storage storage
131 * \param pmtParameters PMT parameters
132 * \param debug debug
133 */
135 const storage_type& storage,
137 const int debug = 0) :
138 JMuonGandalfParameters_t(parameters),
139 JRegressor_t(storage),
141 {
142 if (this->getRmax() < roadWidth_m) {
143 roadWidth_m = this->getRmax();
144 }
145
146 JRegressor_t::debug = debug;
147 JRegressor_t::Vmax_npe = VMax_npe;
148 JRegressor_t::MAXIMUM_ITERATIONS = NMax;
149
150 this->parameters.resize(5);
151
152 this->parameters[0] = JLine3Z::pX();
153 this->parameters[1] = JLine3Z::pY();
154 this->parameters[2] = JLine3Z::pT();
155 this->parameters[3] = JLine3Z::pDX();
156 this->parameters[4] = JLine3Z::pDY();
157 }
158
159
160 /**
161 * Get input data.
162 *
163 * \param router module router
164 * \param summary summary data
165 * \param event event
166 * \param in start values
167 * \param coverage coverage
168 * \return input data
169 */
171 const JSummaryRouter& summary,
172 const JDAQEvent& event,
173 const JEvt& in,
174 const coverage_type& coverage) const
175 {
176 using namespace std;
177 using namespace JPP;
178
179 const JBuildL0<JHitL0> buildL0;
180
181 input_type input(event.getDAQEventHeader(), in, coverage);
182
183 vector<JHitL0> data;
184
185 buildL0(event, router, true, back_inserter(data));
186
187 for (auto& hit : data) {
188
189 const JPMTIdentifier id(hit.getModuleID(), hit.getPMTAddress());
190
192
193 const int type = wip.getType();
194 const double QE = wip.QE;
195 const double R_Hz = summary.getRate(hit.getPMTIdentifier(), this->R_Hz);
196
197 input.data.push_back(hit_type(hit, type, QE, R_Hz));
198 }
199
200 return input;
201 }
202
203
204 /**
205 * Fit function.
206 *
207 * \param input input data
208 * \return fit results
209 */
211 {
212 using namespace std;
213 using namespace JFIT;
214 using namespace JGEOMETRY3D;
215
216 JEvent event(JMUONGANDALF);
217
218 JEvt out;
219
220 const buffer_type& data = input.data;
221
222 // select start values
223
224 JEvt in = input.in;
225
227
228 if (!in.empty()) {
229 in.select(JHistory::is_event(in.begin()->getHistory()));
230 }
231
232 for (JEvt::const_iterator track = in.begin(); track != in.end(); ++track) {
233
234 const JRotation3D R (getDirection(*track));
235 const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
236 JRange<double> Z_m;
237
238 if (track->getW(JSTART_LENGTH_METRES, 0.0) > 0.0) {
239 Z_m = JZRange(track->getW(JSTART_ZMIN_M) + ZMin_m,
240 track->getW(JSTART_ZMAX_M) + ZMax_m);
241 }
242
243 const JModel<JLine1Z> match(tz, roadWidth_m, T_ns, Z_m);
244
245 // hit selection based on start value
246
247 buffer_type buffer;
248
249 for (buffer_type::const_iterator i = data.begin(); i != data.end(); ++i) {
250
251 hit_type hit(*i);
252
253 hit.rotate(R);
254
255 if (match(hit)) {
256 buffer.push_back(hit);
257 }
258 }
259
260 // select first hit
261
262 sort(buffer.begin(), buffer.end(), JHitL0::compare);
263
264 buffer_type::iterator __end = unique(buffer.begin(), buffer.end(), equal_to<JDAQPMTIdentifier>());
265
266
267 const int NDF = distance(buffer.begin(), __end) - this->parameters.size();
268
269 if (NDF > 0) {
270
271 // set fit parameters
272
273 if (this->JMuonGandalfParameters_t::E_GeV > 0.1)
274 JRegressor_t::E_GeV = this->JMuonGandalfParameters_t::E_GeV;
275 else
276 JRegressor_t::E_GeV = track->getE();
277
278 const double chi2 = (*this)(JLine3Z(tz), buffer.begin(), __end);
279
280 // check error matrix
281
282 bool status = true;
283
284 for (size_t i = 0; i != this->V.size(); ++i) {
285 if (std::isnan(this->V(i,i)) || this->V(i,i) <= 0.0) {
286 status = false;
287 }
288 }
289
290 if (status) {
291
292 JTrack3D tb(this->value);
293
294 tb.rotate_back(R);
295
296 out.push_back(getFit(JHistory(track->getHistory(), event()), tb, getQuality(chi2), NDF));
297
298 // set additional values
299
300 const size_t N = this->V.size();
301
302 TMatrixDSym M(N);
303
304 for (size_t row = 0; row != N; ++row) {
305 for (size_t col = 0; col != N; ++col) {
306 M(row,col) = this->V(row,col);
307 }
308 }
309
310 const TMatrixDSymEigen E(M);
311 const TVectorD& Y = E.GetEigenValues();
312
313 out.rbegin()->setV(this->V.size(), this->V);
314
315 out.rbegin()->setW(track->getW());
316 out.rbegin()->setW(JGANDALF_BETA0_RAD, sqrt(this->error.getDX() * this->error.getDX() +
317 this->error.getDY() * this->error.getDY()));
318 out.rbegin()->setW(JGANDALF_BETA1_RAD, sqrt(this->error.getDX() * this->error.getDY()));
319 out.rbegin()->setW(JGANDALF_NUMBER_OF_HITS, distance(buffer.begin(), __end));
320 out.rbegin()->setW(JGANDALF_LAMBDA, Y.GetNrows() != 0 ? Y[0] : 0.0);
321 out.rbegin()->setW(JGANDALF_NUMBER_OF_ITERATIONS, this->numberOfIterations);
322 out.rbegin()->setW(JPP_COVERAGE_ORIENTATION, input.coverage.orientation);
323 out.rbegin()->setW(JPP_COVERAGE_POSITION, input.coverage.position);
324 }
325 }
326 }
327
328 {
329 for (JEvt::iterator i = out.begin(); i != out.end(); ++i) {
330
331 double Q = numeric_limits<double>::max();
332
333 for (JEvt::iterator p = out.begin(); p != out.end(); ++p) {
334 if (p != i) {
335 if (getDot(getDirection(*i), getDirection(*p)) <= cosLR) {
336 if (i->getQ() - p->getQ() < Q) {
337 Q = i->getQ() - p->getQ();
338 }
339 }
340 }
341 }
342
343 i->setW(JGANDALF_LIKELIHOOD_RATIO, Q);
344 }
345 }
346
347 // apply default sorter
348
349 sort(out.begin(), out.end(), qualitySorter);
350
351 copy(input.in.begin(), input.in.end(), back_inserter(out));
352
353 return out;
354 }
355
357 };
358}
359
360#endif
361
Coverage of dynamical detector calibration.
Auxiliary methods to evaluate Poisson probabilities and chi2.
Energy loss of muon.
Basic data structure for L0 hit.
Data regression method for JFIT::JLine3Z.
General purpose messaging.
int debug
debug level
Definition JSirene.cc:74
Direct access to module in detector data structure.
Auxiliary methods for PDF calculations.
Auxiliary class to define a range between two values.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
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.
Fit method based on the Levenberg-Marquardt method.
Definition JGandalf.hh:87
Data structure for fit of straight line paralel to z-axis.
Definition JLine1Z.hh:29
static parameter_type pY()
Definition JLine1Z.hh:181
static parameter_type pX()
Definition JLine1Z.hh:180
static parameter_type pT()
Definition JLine1Z.hh:182
Data structure for fit of straight line in positive z-direction.
Definition JLine3Z.hh:40
static parameter_type pDY()
Definition JLine3Z.hh:320
static parameter_type pDX()
Definition JLine3Z.hh:319
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.
Auxiliary class for a hit with background rate value.
Definition JHitW0.hh:25
Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure as a functio...
double getRate(const JDAQPMTIdentifier &id) const
Get rate.
Template L0 hit builder.
Definition JBuildL0.hh:38
const JDAQEventHeader & getDAQEventHeader() const
Get DAQ event header.
static const int JGANDALF_LIKELIHOOD_RATIO
likelihood ratio between this and best alternative fit see JRECONSTRUCTION::JMuonGandalf
static const int JSTART_ZMAX_M
end position of track see JRECONSTRUCTION::JMuonStart
static const int JGANDALF_LAMBDA
largest eigenvalue of error matrix see JRECONSTRUCTION::JMuonGandalf
static const int JPP_COVERAGE_POSITION
coverage of dynamic position calibration of this event
static const int JSTART_LENGTH_METRES
distance between projected positions on the track of optical modules for which the response does not ...
static const int JSTART_ZMIN_M
start position of track see JRECONSTRUCTION::JMuonStart
static const int JGANDALF_BETA0_RAD
ile KM3NeT Data Definitions v3.6.2-4-g8b3df20 https://git.km3net.de/common/km3net-dataformat
static const int JGANDALF_NUMBER_OF_ITERATIONS
number of iterations see JRECONSTRUCTION::JMuonGandalf
static const int JPP_COVERAGE_ORIENTATION
coverage of dynamic orientation calibration of this event
static const int JGANDALF_BETA1_RAD
uncertainty on the reconstructed track direction from the error matrix [rad] see JRECONSTRUCTION::JMu...
static const int JGANDALF_NUMBER_OF_HITS
number of hits see JRECONSTRUCTION::JMuonGandalf
Auxiliary classes and methods for linear and iterative data regression.
JTOOLS::JRange< double > JZRange
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition JAngle3D.hh:19
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
double getQuality(const double chi2, const int N, const int NDF)
Get quality of fit.
JPosition3D getPosition(const JFit &fit)
Get position.
JFIT::JHistory JHistory
Definition JHistory.hh:455
void copy(const JFIT::JEvt::const_iterator __begin, const JFIT::JEvt::const_iterator __end, Evt &out)
Copy tracks.
bool qualitySorter(const JFit &first, const JFit &second)
Comparison of fit results.
double getDot(const JFit &first, const JFit &second)
Get dot product.
JFit getFit(const JHistory &history, const JTrack3D &track, const double Q, const int NDF, const double energy=0.0, const int status=SINGLE_STAGE)
Get fit.
JDirection3D getDirection(const JFit &fit)
Get direction.
Model for fit to acoustics data.
Data structure for coverage of detector by dynamical calibrations.
Definition JCoverage.hh:19
double position
coverage of detector by available position calibration [0,1]
Definition JCoverage.hh:42
double orientation
coverage of detector by available orientation calibration [0,1]
Definition JCoverage.hh:41
Auxiliary class for historical event.
Definition JHistory.hh:40
Auxiliary class to test history.
Definition JHistory.hh:157
Template definition of a data regressor of given model.
Definition JRegressor.hh:70
double cosLR
maximal cosine space angle likelihood ratio test
double VMax_npe
maximum number of of photo-electrons
input_type(const JDAQEventHeader &header, const JEvt &in, const coverage_type &coverage)
Constructor.
Wrapper class to make final fit of muon trajectory.
input_type getInput(const JModuleRouter &router, const JSummaryRouter &summary, const JDAQEvent &event, const JEvt &in, const coverage_type &coverage) const
Get input data.
std::vector< hit_type > buffer_type
const JPMTParametersMap & pmtParameters
JRegressor< JLine3Z, JGandalf > JRegressor_t
JMuonGandalf(const JMuonGandalfParameters_t &parameters, const storage_type &storage, const JPMTParametersMap &pmtParameters, const int debug=0)
Constructor.
JEvt operator()(const input_type &input)
Fit function.
Auxiliary data structure for sorting of hits.
Definition JHitL0.hh:85