Jpp 21.0.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JShowerPositionFit.hh
Go to the documentation of this file.
1#ifndef JSHOWERPOSITIONFIT_INCLUDE
2#define JSHOWERPOSITIONFIT_INCLUDE
3
4#include <string>
5#include <iostream>
6#include <set>
7#include <vector>
8#include <algorithm>
9#include <memory>
10#include <math.h>
11
12#include "TMatrixDSym.h"
13#include "TMatrixDSymEigen.h"
14
15
19
20#include "JTrigger/JHit.hh"
22#include "JTrigger/JHitL0.hh"
23#include "JTrigger/JHitL1.hh"
24#include "JTrigger/JHitR1.hh"
25#include "JTrigger/JBuildL0.hh"
26#include "JTrigger/JBuildL2.hh"
28#include "JTrigger/JMatch3G.hh"
29#include "JTrigger/JBind2nd.hh"
30
32
33#include "JFit/JFitToolkit.hh"
34#include "JFit/JEstimator.hh"
35#include "JFit/JPoint4E.hh"
36#include "JFit/JModel.hh"
37#include "JFit/JSimplex.hh"
39
44
51
54
56
58#include "JTools/JRange.hh"
59
60
61/**
62 * \author adomi, vcarretero
63 */
64namespace JRECONSTRUCTION {}
65namespace JPP { using namespace JRECONSTRUCTION; }
66
67namespace JRECONSTRUCTION {
68
73 using JFIT::JPoint4D;
74 using JFIT::JPoint4E;
75 using JFIT::JGandalf;
76 using JFIT::JRegressor;
78
79 /**
80 * class to handle the second position fit of the shower reconstruction, mainly dedicated for ORCA
81 */
83
85 public JRegressor<JPoint4E, JGandalf>
86
87 {
91 using JRegressor_t::operator();
92
94
95 public:
96 /**
97 * Input data type.
98 */
99 struct input_type :
100 public JDAQEventHeader
101 {
102 /**
103 * Default constructor.
104 */
106 {}
107
108
109 /**
110 * Constructor.
111 *
112 * \param header header
113 * \param in start values
114 * \param coverage coverage
115 */
116 input_type(const JDAQEventHeader& header, const JEvt& in, const coverage_type& coverage) :
117 JDAQEventHeader(header),
118 in(in),
120 {}
121
125 };
126
127 /**
128 * Parameterized constructor
129 *
130 * \param parameters struct that holds default-optimized parameters for the reconstruction
131 * \param storage storage
132 * \param pmtParameters PMT parameters
133 * \param debug debug
134 */
136 const storage_type& storage,
138 const int debug = 0):
140 JRegressor_t(storage),
142 {
143 using namespace JPP;
144
145 JRegressor_t::T_ns.setRange(parameters.TMin_ns, parameters.TMax_ns);
146 JRegressor_t::Vmax_npe = VMax_npe;
147 JRegressor_t::MAXIMUM_ITERATIONS = NMax;
148 JRegressor_t::EPSILON = 1e-3;
149 JRegressor_t::debug = debug;
150
151 if (Emin_GeV > Emax_GeV || En <= 1) {
152 THROW(JException, "Invalid energy input " << Emin_GeV << ' ' << Emax_GeV << ' ' << En);
153 }
154
155 const double base = std::pow((Emax_GeV / Emin_GeV), 1.0 / (En - 1));
156
157 for (int i = 0; i != En; ++i) {
158 Ev.push_back(Emin_GeV * std::pow(base, i));
159 }
160
161 this->parameters.resize(5);
162
163 this->parameters[0] = JPoint4E::pX();
164 this->parameters[1] = JPoint4E::pY();
165 this->parameters[2] = JPoint4E::pZ();
166 this->parameters[3] = JPoint4E::pT();
167 this->parameters[4] = JPoint4E::pE();
168 }
169
170 /**
171 * Get input data.
172 *
173 * \param router module router
174 * \param summary summary data
175 * \param event event
176 * \param in start values
177 * \param coverage coverage
178 * \return input data
179 */
181 const JSummaryRouter& summary,
182 const JDAQEvent& event,
183 const JEvt& in,
184 const coverage_type& coverage) const
185 {
186 using namespace std;
187 using namespace JPP;
188 using namespace JTRIGGER;
189
190 const JBuildL0<JHitL0> buildL0;
191
192 input_type input(event.getDAQEventHeader(), in, coverage);
193
194 vector<JHitL0> data;
195
196 buildL0(JDAQTimeslice(event, true), router, back_inserter(data));
197
198 for (const auto& hit : data) {
199
200 const JPMTIdentifier id(hit.getModuleID(), hit.getPMTAddress());
201
203
204 const int type = wip.getType();
205 const double QE = wip.QE;
206 const double R_Hz = summary.getRate(hit.getPMTIdentifier(), this->R_Hz);
207
208 input.data.push_back(hit_type(hit, type, QE, R_Hz));
209 }
210
211 return input;
212 }
213 /**
214 * Fit function.
215 *
216 * \param input input data
217 * \return fit results
218 */
220
221 using namespace std;
222 using namespace JFIT;
223 using namespace JGEOMETRY3D;
224
226 JEvt out;
227
228 const buffer_type& data = input.data;
229
230 // select start values
231
232 JEvt in = input.in;
233
235
236 if (!in.empty()) {
237 in.select(JHistory::is_event(in.begin()->getHistory()));
238 }
239
240 for (JEvt::const_iterator shower = in.begin(); shower != in.end(); ++shower) {
241
242 JPoint4D vx(getPosition(*shower), shower->getT());
243
244 const JFIT::JModel<JPoint4D> match(vx, DMax_m, JRegressor_t::T_ns);
245
246 buffer_type buffer;
247
248 for (buffer_type::const_iterator i = data.begin(); i != data.end(); ++i) {
249
250 if (match(*i)) {
251 buffer.push_back(*i);
252 }
253 }
254
255 // select first hit
256
257 sort(buffer.begin(), buffer.end(), JHitL0::compare);
258
259 vector<hit_type>::iterator __end = unique(buffer.begin(), buffer.end(), equal_to<JDAQPMTIdentifier>());
260
261 const int NDF = distance(buffer.begin(), __end) - this->parameters.size();
262
263 if (NDF > 0) {
264
265 // set fit parameters
266 for (vector<double>::iterator e = Ev.begin(); e != Ev.end(); ++e) {
267
268 JPoint4E sh(vx, *e);
269
270 double chi2 = (*this)(sh, buffer.begin(), __end);
271
272 JShower3D result(JVertex3D(this->value.getPosition(), this->value.getT()), JDirection3D());
273
274
275 out.push_back(getFit(JHistory(shower->getHistory(), event()), result, getQuality(chi2), NDF, this->value.getE()));
276
277 const size_t N = this->V.size();
278
279 TMatrixDSym M(N);
280
281 for (size_t row = 0; row != N; ++row) {
282 for (size_t col = 0; col != N; ++col) {
283 M(row,col) = this->V(row,col);
284 }
285 }
286
287 const TMatrixDSymEigen E(M);
288 const TVectorD& Y = E.GetEigenValues();
289
290 out.rbegin()->setV(this->V.size(), this->V);
291
292 out.rbegin()->setW(JSHOWERPOSITIONFIT_ISOTROPIC_ENERGY, this->value.getE());
293 out.rbegin()->setW(JSHOWERPOSITIONFIT_LAMBDA, Y.GetNrows() != 0 ? Y[0] : 0.0);
294
295 // set additional values
296 out.rbegin()->setW(JPP_COVERAGE_ORIENTATION, input.coverage.orientation);
297 out.rbegin()->setW(JPP_COVERAGE_POSITION, input.coverage.position);
298
299 }
300 }
301 }
302
303 // apply default sorter
304
305 sort(out.begin(), out.end(), qualitySorter);
306
307 copy(input.in.begin(), input.in.end(), back_inserter(out));
308
309 return out;
310 }
311
313 };
314}
315
316#endif
317
Algorithms for hit clustering and sorting.
Coverage of dynamical detector calibration.
Linear fit methods.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Auxiliary methods to evaluate Poisson probabilities and chi2.
Basic data structure for L0 hit.
Basic data structure for L1 hit.
Reduced data structure for L1 hit.
Match operator for Cherenkov light from shower in any direction.
int debug
debug level
Definition JSirene.cc:74
Direct access to module in detector data structure.
Auxiliary class to define a range between two values.
Data regression method for JFIT::JPoint4E from a bright point isoptropic emission PDF.
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.
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 vertex fit.
Definition JPoint4D.hh:24
Data structure for vertex fit.
Definition JPoint4E.hh:24
static parameter_type pZ()
Definition JPoint4E.hh:71
static parameter_type pX()
Definition JPoint4E.hh:69
static parameter_type pY()
Definition JPoint4E.hh:70
static parameter_type pE()
Definition JPoint4E.hh:73
static parameter_type pT()
Definition JPoint4E.hh:72
Data structure for direction in three dimensions.
General exception.
Definition JException.hh:25
Auxiliary class for a hit with background rate value.
Definition JHitW0.hh:25
class to handle the second position fit of the shower reconstruction, mainly dedicated for ORCA
JRegressor< JPoint4E, JGandalf > JRegressor_t
JEvt operator()(const input_type &input)
Fit function.
const JPMTParametersMap & pmtParameters
input_type getInput(const JModuleRouter &router, const JSummaryRouter &summary, const JDAQEvent &event, const JEvt &in, const coverage_type &coverage) const
Get input data.
JShowerPositionFit(const JShowerPositionFitParameters_t &parameters, const storage_type &storage, const JPMTParametersMap &pmtParameters, const int debug=0)
Parameterized constructor.
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 JSHOWERPOSITIONFIT_LAMBDA
largest eigenvalue of error matrix for vertex fit see JRECONSTRUCTION::JShowerPositionFit
static const int JPP_COVERAGE_POSITION
coverage of dynamic position calibration of this event
static const int JSHOWERPOSITIONFIT_ISOTROPIC_ENERGY
isotropic shower energy [GeV] see JRECONSTRUCTION::JShowerPositionFit
static const int JPP_COVERAGE_ORIENTATION
coverage of dynamic orientation calibration of this event
Auxiliary classes and methods for linear and iterative data regression.
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.
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.
return result
Definition JPolint.hh:862
if((p==this->begin() &&this->getDistance(x,(p++) ->getX()) > distance_type::precision)||(p==this->end() &&this->getDistance((--p) ->getX(), x) > distance_type::precision))
Template base class for polynomial interpolations with polynomial result.
Definition JPolint.hh:775
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 to match data points with given model.
Template definition of a data regressor of given model.
Definition JRegressor.hh:70
double VMax_npe
maximum number of of photo-electrons
double TMin_ns
minimum time for local coincidences [ns]
double TMax_ns
maximum time for local coincidences [ns]
double DMax_m
maximal distance to optical module [m]
input_type(const JDAQEventHeader &header, const JEvt &in, const coverage_type &coverage)
Constructor.
Auxiliary data structure for sorting of hits.
Definition JHitL0.hh:85