Jpp test-rotations-old-533-g2bdbdb559
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
37
39
41
43
44#include "JTools/JRange.hh"
45
46#include "Jeep/JMessage.hh"
47
48
49/**
50 * \author mdejong, gmaggi
51 */
52
53namespace JRECONSTRUCTION {}
54namespace JPP { using namespace JRECONSTRUCTION; }
55
56namespace JRECONSTRUCTION {
57
61 using JFIT::JRegressor;
62 using JFIT::JLine3Z;
63 using JFIT::JGandalf;
64 using JFIT::JTimeRange;
66
67
68 /**
69 * Wrapper class to make final fit of muon trajectory.
70 *
71 * The JMuonGandalf fit uses one or more start values (usually taken from the output of JMuonSimplex).\n
72 * All hits of which the PMT position lies within a set road width (JMuonGandalfParameters_t::roadWidth_m) and
73 * time is within a set window (JMuonGandalfParameters_t::TMin_ns, JMuonGandalfParameters_t::TMax_ns) around the Cherenkov hypothesis are taken.\n
74 * In case there are multiple hits from the same PMT is the specified window,
75 * the first hit is taken and the other hits are discarded.\n
76 * The PDF is accordingly evaluated, i.e.\ the normalised probability for a first hit at the given time of the hit is taken.
77 * The normalisation is consistently based on the specified time window.\n
78 * Note that this hit selection is unbiased with respect to the PDF of a single PMT.
79 */
80 struct JMuonGandalf :
82 public JRegressor<JLine3Z, JGandalf>
83 {
87
88 using JRegressor_t::operator();
89
90 /**
91 * Input data type.
92 */
93 struct input_type :
94 public JDAQEventHeader
95 {
96 /**
97 * Default constructor.
98 */
100 {}
101
102
103 /**
104 * Constructor.
105 *
106 * \param header header
107 * \param in start values
108 * \param coverage coverage
109 */
111 const JEvt& in,
112 const coverage_type& coverage) :
113 JDAQEventHeader(header),
114 in(in),
116 {}
117
121 };
122
123
124 /**
125 * Constructor
126 *
127 * \param parameters parameters
128 * \param storage storage
129 * \param debug debug
130 */
132 const storage_type& storage,
133 const int debug = 0) :
134 JMuonGandalfParameters_t(parameters),
135 JRegressor_t(storage)
136 {
137 if (this->getRmax() < roadWidth_m) {
138 roadWidth_m = this->getRmax();
139 }
140
141 JRegressor_t::debug = debug;
142 JRegressor_t::Vmax_npe = VMax_npe;
143 JRegressor_t::MAXIMUM_ITERATIONS = NMax;
144
145 this->parameters.resize(5);
146
147 this->parameters[0] = JLine3Z::pX();
148 this->parameters[1] = JLine3Z::pY();
149 this->parameters[2] = JLine3Z::pT();
150 this->parameters[3] = JLine3Z::pDX();
151 this->parameters[4] = JLine3Z::pDY();
152 }
153
154
155 /**
156 * Get input data.
157 *
158 * \param router module router
159 * \param summary summary data
160 * \param event event
161 * \param in start values
162 * \param coverage coverage
163 * \return input data
164 */
166 const JSummaryRouter& summary,
167 const JDAQEvent& event,
168 const JEvt& in,
169 const coverage_type& coverage) const
170 {
171 using namespace std;
172 using namespace JTRIGGER;
173
174 const JBuildL0<JHitL0> buildL0;
175
176 input_type input(event.getDAQEventHeader(), in, coverage);
177
178 vector<JHitL0> data;
179
180 buildL0(event, router, true, back_inserter(data));
181
182 for (const auto& hit : data) {
183 input.data.push_back(hit_type(hit, summary.getRate(hit.getPMTIdentifier(), this->R_Hz)));
184 }
185
186 return input;
187 }
188
189
190 /**
191 * Fit function.
192 *
193 * \param input input data
194 * \return fit results
195 */
197 {
198 using namespace std;
199 using namespace JFIT;
200 using namespace JGEOMETRY3D;
201
202 JEvent event(JMUONGANDALF);
203
204 JEvt out;
205
206 const buffer_type& data = input.data;
207
208 // select start values
209
210 JEvt in = input.in;
211
213
214 if (!in.empty()) {
215 in.select(JHistory::is_event(in.begin()->getHistory()));
216 }
217
218 for (JEvt::const_iterator track = in.begin(); track != in.end(); ++track) {
219
220 const JRotation3D R (getDirection(*track));
221 const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
222 JRange<double> Z_m;
223
224 if (track->getW(JSTART_LENGTH_METRES, 0.0) > 0.0) {
225 Z_m = JZRange(track->getW(JSTART_ZMIN_M) + ZMin_m,
226 track->getW(JSTART_ZMAX_M) + ZMax_m);
227 }
228
229 const JModel<JLine1Z> match(tz, roadWidth_m, T_ns, Z_m);
230
231 // hit selection based on start value
232
233 buffer_type buffer;
234
235 for (buffer_type::const_iterator i = data.begin(); i != data.end(); ++i) {
236
237 hit_type hit(*i);
238
239 hit.rotate(R);
240
241 if (match(hit)) {
242 buffer.push_back(hit);
243 }
244 }
245
246 // select first hit
247
248 sort(buffer.begin(), buffer.end(), JHitL0::compare);
249
250 buffer_type::iterator __end = unique(buffer.begin(), buffer.end(), equal_to<JDAQPMTIdentifier>());
251
252
253 const int NDF = distance(buffer.begin(), __end) - this->parameters.size();
254
255 if (NDF > 0) {
256
257 // set fit parameters
258
259 if (this->JMuonGandalfParameters_t::E_GeV > 0.1)
260 JRegressor_t::E_GeV = this->JMuonGandalfParameters_t::E_GeV;
261 else
262 JRegressor_t::E_GeV = track->getE();
263
264 const double chi2 = (*this)(JLine3Z(tz), buffer.begin(), __end);
265
266 // check error matrix
267
268 bool status = true;
269
270 for (size_t i = 0; i != this->V.size(); ++i) {
271 if (std::isnan(this->V(i,i)) || this->V(i,i) <= 0.0) {
272 status = false;
273 }
274 }
275
276 if (status) {
277
278 JTrack3D tb(this->value);
279
280 tb.rotate_back(R);
281
282 out.push_back(getFit(JHistory(track->getHistory(), event()), tb, getQuality(chi2), NDF));
283
284 // set additional values
285
286 const size_t N = this->V.size();
287
288 TMatrixDSym M(N);
289
290 for (size_t row = 0; row != N; ++row) {
291 for (size_t col = 0; col != N; ++col) {
292 M(row,col) = this->V(row,col);
293 }
294 }
295
296 const TMatrixDSymEigen E(M);
297 const TVectorD& Y = E.GetEigenValues();
298
299 out.rbegin()->setV(this->V.size(), this->V);
300
301 out.rbegin()->setW(track->getW());
302 out.rbegin()->setW(JGANDALF_BETA0_RAD, sqrt(this->error.getDX() * this->error.getDX() +
303 this->error.getDY() * this->error.getDY()));
304 out.rbegin()->setW(JGANDALF_BETA1_RAD, sqrt(this->error.getDX() * this->error.getDY()));
305 out.rbegin()->setW(JGANDALF_NUMBER_OF_HITS, distance(buffer.begin(), __end));
306 out.rbegin()->setW(JGANDALF_LAMBDA, Y.GetNrows() != 0 ? Y[0] : 0.0);
307 out.rbegin()->setW(JGANDALF_NUMBER_OF_ITERATIONS, this->numberOfIterations);
308 out.rbegin()->setW(JPP_COVERAGE_ORIENTATION, input.coverage.orientation);
309 out.rbegin()->setW(JPP_COVERAGE_POSITION, input.coverage.position);
310 }
311 }
312 }
313
314 {
315 for (JEvt::iterator i = out.begin(); i != out.end(); ++i) {
316
317 double Q = numeric_limits<double>::max();
318
319 for (JEvt::iterator p = out.begin(); p != out.end(); ++p) {
320 if (p != i) {
321 if (getDot(getDirection(*i), getDirection(*p)) <= cosLR) {
322 if (i->getQ() - p->getQ() < Q) {
323 Q = i->getQ() - p->getQ();
324 }
325 }
326 }
327 }
328
329 i->setW(JGANDALF_LIKELIHOOD_RATIO, Q);
330 }
331 }
332
333 // apply default sorter
334
335 sort(out.begin(), out.end(), qualitySorter);
336
337 copy(input.in.begin(), input.in.end(), back_inserter(out));
338
339 return out;
340 }
341 };
342}
343
344#endif
345
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:72
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.
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:23
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 from JMuonGandalf
static const int JGANDALF_LAMBDA
largest eigenvalue of error matrix from JMuonGandalf
static const int JPP_COVERAGE_POSITION
coverage of dynamic position calibration from any Jpp application
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 JGANDALF_BETA0_RAD
KM3NeT Data Definitions v3.6.1-21-g1b37f88 https://git.km3net.de/common/km3net-dataformat.
static const int JGANDALF_NUMBER_OF_ITERATIONS
number of iterations from JMuonGandalf
static const int JPP_COVERAGE_ORIENTATION
coverage of dynamic orientation calibration from any Jpp application
static const int JGANDALF_BETA1_RAD
uncertainty on the reconstructed track direction from the error matrix [rad] (to be deprecated) from ...
static const int JGANDALF_NUMBER_OF_HITS
number of hits from 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.
static const int JSTART_ZMAX_M
end position of track
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.
static const int JSTART_ZMIN_M
start position of track
JDirection3D getDirection(const JFit &fit)
Get direction.
Auxiliary classes and methods for triggering.
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
JMuonGandalf(const JMuonGandalfParameters_t &parameters, const storage_type &storage, const int debug=0)
Constructor.
JRegressor< JLine3Z, JGandalf > JRegressor_t
JEvt operator()(const input_type &input)
Fit function.
Auxiliary data structure for sorting of hits.
Definition JHitL0.hh:85