Jpp 21.0.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JShowerFit.hh
Go to the documentation of this file.
1#ifndef JSHOWERFIT_INCLUDE
2#define JSHOWERFIT_INCLUDE
3
4#include <string>
5#include <iostream>
6#include <set>
7#include <vector>
8#include <algorithm>
9#include <memory>
10
11#include "TMatrixDSym.h"
12#include "TMatrixDSymEigen.h"
13
16
19
21
22#include "JTrigger/JHitR0.hh"
23#include "JTrigger/JBuildL0.hh"
24
26
27#include "JFit/JPMTW0.hh"
29#include "JFit/JFitToolkit.hh"
30#include "JFit/JPoint4D.hh"
31#include "JFit/JModel.hh"
32#include "JFit/JGandalf.hh"
33
40
41
42/**
43 * \author adomi, vcarretero
44 */
45namespace JRECONSTRUCTION {}
46namespace JPP { using namespace JRECONSTRUCTION; }
47
48namespace JRECONSTRUCTION {
49
55 using JFIT::JRegressor;
56 using JFIT::JEnergy;
57 using JFIT::JShower3EZ;
58 using JFIT::JGandalf;
60
61
62 /**
63 * class to handle the direction fit of the shower reconstruction, mainly dedicated for ORCA
64 */
65 class JShowerFit :
67 public JRegressor<JShower3EZ, JGandalf>
68 {
69
73 using JRegressor_t::operator();
74
75 public:
76
77
78 /**
79 * Input data type.
80 */
81 struct input_type :
82 public JDAQEventHeader
83 {
84 /**
85 * Default constructor.
86 */
88 {}
89
90
91 /**
92 * Constructor.
93 *
94 * \param header header
95 * \param in start values
96 * \param coverage coverage
97 */
99 const JEvt& in,
100 const coverage_type& coverage) :
101 JDAQEventHeader(header),
102 in(in),
104 {}
105
109 };
110
111 /**
112 * Parameterized constructor
113 *
114 * \param parameters parameters
115 * \param storage storage
116 * \param pmtParameters PMT parameters
117 * \param correct energy correction
118 * \param debug debug
119 */
121 const storage_type& storage,
124 const int debug = 0):
125 JShowerFitParameters_t(parameters),
126 JRegressor_t (storage),
129 {
130 using namespace JPP;
131
132 JRegressor_t::debug = debug;
133 JRegressor_t::T_ns.setRange(parameters.TMin_ns, parameters.TMax_ns);
134 JRegressor_t::Vmax_npe = parameters.Vmax_npe;
135 JRegressor_t::MAXIMUM_ITERATIONS = 1000;
136 JRegressor_t::EPSILON = 1e-3;
137 JRegressor_t::EPSILON_ABSOLUTE = true;
138
139 this->parameters.resize(3);
140
141 this->parameters[0] = JShower3EZ::pDX();
142 this->parameters[1] = JShower3EZ::pDY();
143 this->parameters[2] = JShower3EZ::pE();
144
145 this->estimator.reset(getMEstimator(parameters.mestimator));
146 }
147
148 /**
149 * Get input data.
150 *
151 * \param router module router
152 * \param summary summary data
153 * \param event event
154 * \param in start values
155 * \param coverage coverage
156 * \return input data
157 */
159 const JSummaryRouter& summary,
160 const JDAQEvent& event,
161 const JEvt& in,
162 const coverage_type& coverage) const
163 {
164 using namespace std;
165 using namespace JTRIGGER;
166
167 input_type input(event.getDAQEventHeader(), in, coverage);
168
169 const JBuildL0 <JHitR0> buildL0;
171
172 const JDAQTimeslice timeslice(event, true);
173
174 JSuperFrame2D<JHit> buffer;
175
176 for (JDAQTimeslice::const_iterator i = timeslice.begin(); i != timeslice.end(); ++i) {
177
178 if (router.hasModule(i->getModuleID())) {
179
180 buffer(*i, router.getModule(i->getModuleID()));
181
182 buildL0(buffer, back_inserter(data[i->getModuleID()]));
183 }
184 }
185
186 for (const auto& module : router.getReference()) {
187 if (!module.empty()) {
188 input.data.push_back(module_type(module, summary.getSummaryFrame(module.getID(), R_Hz), data[module.getID()]));
189 }
190 }
191
192 return input;
193 }
194
195 /**
196 * Fit function.
197 *
198 * \param input input data
199 * \return fit results
200 */
202 {
203 using namespace std;
204 using namespace JPP;
205
207
208 JEvt out;
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 shower = in.begin(); shower != in.end(); ++shower) {
219
220 vector<JPMTW0> data;
221
222 const JPosition3D vertex(getPosition(*shower));
223 const double time = shower->getT();
224 const double distance = DMax_m + DStep_m * log10(shower->getE());
225 const JRotation3D R(getDirection(*shower));
226
227 for (const auto& module : input.data) {
228
229 JPosition3D pos(module->getPosition());
230
231 pos.sub(vertex);
232
233 if (pos.getLength() < distance) {
234
235 for (size_t i = 0; i != module->size(); ++i) {
236
237 if (module.getStatus(i)) {
238
239 const double t1 = time + pos.getLength() * getInverseSpeedOfLight() * getIndexOfRefraction();
240
241 struct {
242
243 bool operator()(const JHitR0& hit) const
244 {
245 return (hit.getPMT() == pmt && T_ns(hit.getT()));
246 }
247
248 const JTimeRange T_ns;
249 const size_t pmt;
250
251 } match = { JRegressor_t::T_ns + t1, i };
252
253 const JPMTIdentifier id(module->getID(), i);
254
256
257 const size_t ns = count_if(module.begin(), module.end(), match);
258 const double QE = wip.QE;
259
260 JPMT pmt = module->getPMT(i);
261
262 pmt.sub(vertex);
263 pmt.rotate(R);
264
265 data.push_back(JPMTW0(pmt, QE, module.frame.getRate(i), ns));
266 }
267 }
268 }
269 }
270
271
272 double chi2 = (*this)(JShower3EZ(JVertex3D(JVector3D(0,0,0), shower->getT()), JVersor3Z(),
273 shower->getE()), data.begin(), data.end());
274
275 double NDF = getCount(data.begin(), data.end()) - this->parameters.size();
276
277 JShower3E result(JShower3D(this->value.getVertex(), this->value.getDirection()), correct(this->value.getE()));
278
279 // check error matrix
280 bool status = true;
281
282 for (size_t i = 0; i != this->V.size(); ++i) {
283 if (std::isnan(this->V(i,i)) || this->V(i,i) < 0.0) {
284 status = false;
285 }
286 }
287
288 if (status) {
289
290 result.rotate_back(R);
291
292 result.add(vertex.getPosition());
293
294
295 out.push_back(getFit(JHistory(shower->getHistory(), event()), result, getQuality(chi2), NDF, result.getE()));
296
297 out.rbegin()->setW(shower->getW());
298
299 const size_t N = this->V.size();
300
301 TMatrixDSym M(N);
302
303 for (size_t row = 0; row != N; ++row) {
304 for (size_t col = 0; col != N; ++col) {
305 M(row,col) = this->V(row,col);
306 }
307 }
308
309 const TMatrixDSymEigen E(M);
310 const TVectorD& Y = E.GetEigenValues();
311
312 out.rbegin()->setV(this->V.size(), this->V);
313
314 out.rbegin()->setW(JSHOWERFIT_LAMBDA, Y.GetNrows() != 0 ? Y[0] : 0.0);
315 out.rbegin()->setW(JSHOWERFIT_ENERGY, this->value.getE()); // Uncorrected Energy
316
317 out.rbegin()->setW(JPP_COVERAGE_ORIENTATION, input.coverage.orientation);
318 out.rbegin()->setW(JPP_COVERAGE_POSITION, input.coverage.position);
319
320 }
321 }
322
323 // apply default sorter
324
325 sort(out.begin(), out.end(), qualitySorter);
326
327 copy(input.in.begin(), input.in.end(), back_inserter(out));
328
329 return out;
330 }
331
332
335 };
336}
337
338#endif
339
Coverage of dynamical detector calibration.
Auxiliary methods to evaluate Poisson probabilities and chi2.
Basic data structure for L0 hit.
int debug
debug level
Definition JSirene.cc:74
Direct access to module in detector data structure.
Data regression method for JFIT::JShower3EZ.
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.
bool hasModule(const JModuleIdentifier &id) const
Has module.
const JModule & getModule(const JModuleIdentifier &id) const
Get module parameters.
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
Data structure for PMT geometry, calibration and status.
Definition JPMT.hh:49
Data structure for fit of energy.
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 in positive z-direction with energy.
Definition JShower3EZ.hh:30
static parameter_type pE()
static parameter_type pDY()
Definition JShower3Z.hh:172
static parameter_type pDX()
Definition JShower3Z.hh:171
JAxis3D & rotate(const JRotation3D &R)
Rotate axis.
Definition JAxis3D.hh:225
Data structure for position in three dimensions.
const JPosition3D & getPosition() const
Get position.
3D shower with energy.
Definition JShower3E.hh:31
Data structure for vector in three dimensions.
Definition JVector3D.hh:36
double getLength() const
Get length.
Definition JVector3D.hh:246
JVector3D & sub(const JVector3D &vector)
Subtract vector.
Definition JVector3D.hh:158
Data structure for normalised vector in positive z-direction.
Definition JVersor3Z.hh:41
const JClass_t & getReference() const
Get reference to object.
Definition JReference.hh:38
Auxiliary class for correction of energy determined by JEnergy.cc.
class to handle the direction fit of the shower reconstruction, mainly dedicated for ORCA
Definition JShowerFit.hh:68
JEvt operator()(const input_type &input)
Fit function.
std::vector< module_type > detector_type
Definition JShowerFit.hh:72
JRegressor< JShower3EZ, JGandalf > JRegressor_t
Definition JShowerFit.hh:70
const JEnergyCorrection & correct
input_type getInput(const JModuleRouter &router, const JSummaryRouter &summary, const JDAQEvent &event, const JEvt &in, const coverage_type &coverage) const
Get input data.
JShowerFit(const JShowerFitParameters_t &parameters, const storage_type &storage, const JPMTParametersMap &pmtParameters, const JEnergyCorrection &correct, const int debug=0)
Parameterized constructor.
const JPMTParametersMap & pmtParameters
Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure as a functio...
const JDAQSummaryFrame & getSummaryFrame(const JDAQModuleIdentifier &module) const
Get summary frame.
Reduced data structure for L0 hit.
Definition JHitR0.hh:29
JPMT_t getPMT() const
Get PMT.
Definition JHitR0.hh:73
double getT() const
Get calibrated time of hit.
2-dimensional frame with time calibrated data from one optical module.
const JDAQEventHeader & getDAQEventHeader() const
Get DAQ event header.
Data storage class for rate measurements of all PMTs in one module.
static const int JPP_COVERAGE_POSITION
coverage of dynamic position calibration of this event
static const int JSHOWERFIT_LAMBDA
largest eigenvalue of error matrix for direction and energy fit see JRECONSTRUCTION::JShowerFit
static const int JSHOWERFIT_ENERGY
uncorrected energy [GeV] see JRECONSTRUCTION::JShowerFit
static const int JPP_COVERAGE_ORIENTATION
coverage of dynamic orientation calibration of this event
size_t getCount(const array_type< T > &buffer, const JCompare_t &compare)
Count number of unique values.
double getIndexOfRefraction()
Get average index of refraction of water corresponding to group velocity.
const double getInverseSpeedOfLight()
Get inverse speed of light.
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.
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.
return result
Definition JPolint.hh:862
Auxiliary classes and methods for triggering.
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
Auxiliary class for handling PMT geometry, rate and response.
Definition JPMTW0.hh:24
Template definition of a data regressor of given model.
Definition JRegressor.hh:70
Auxiliary class for handling module response.
Definition JModuleL0.hh:45
Data structure for fit parameters.
double Vmax_npe
maximum number of of photo-electrons
int mestimator
M-estimator (see JFIT::JMEstimator_t)
double DMax_m
maximal distance to optical module [m]
double TMax_ns
maximum time for local coincidences [ns]
double TMin_ns
minimum time for local coincidences [ns]
double DStep_m
step increase for the distance to optical module [m]
input_type(const JDAQEventHeader &header, const JEvt &in, const coverage_type &coverage)
Constructor.
Definition JShowerFit.hh:98