Jpp 20.0.0-195-g190c9e876
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
13
16
18
19#include "JTrigger/JHitR0.hh"
20#include "JTrigger/JBuildL0.hh"
21
23
24#include "JFit/JPMTW0.hh"
26#include "JFit/JFitToolkit.hh"
27#include "JFit/JPoint4D.hh"
28#include "JFit/JModel.hh"
29#include "JFit/JGandalf.hh"
30
37
38
39/**
40 * \author adomi, vcarretero
41 */
42namespace JRECONSTRUCTION {}
43namespace JPP { using namespace JRECONSTRUCTION; }
44
45namespace JRECONSTRUCTION {
46
52 using JFIT::JRegressor;
53 using JFIT::JEnergy;
54 using JFIT::JShower3EZ;
55 using JFIT::JGandalf;
57
58
59 /**
60 * class to handle the direction fit of the shower reconstruction, mainly dedicated for ORCA
61 */
62 class JShowerFit :
64 public JRegressor<JShower3EZ, JGandalf>
65 {
66
70 using JRegressor_t::operator();
71
72 public:
73
74
75 /**
76 * Input data type.
77 */
78 struct input_type :
79 public JDAQEventHeader
80 {
81 /**
82 * Default constructor.
83 */
85 {}
86
87
88 /**
89 * Constructor.
90 *
91 * \param header header
92 * \param in start values
93 * \param coverage coverage
94 */
96 const JEvt& in,
97 const coverage_type& coverage) :
98 JDAQEventHeader(header),
99 in(in),
101 {}
102
106 };
107
108 /**
109 * Parameterized constructor
110 *
111 * \param parameters parameters
112 * \param storage storage
113 * \param pmtParameters PMT parameters
114 * \param correct energy correction
115 * \param debug debug
116 */
118 const storage_type& storage,
121 const int debug = 0):
122 JShowerFitParameters_t(parameters),
123 JRegressor_t (storage),
126 {
127 using namespace JPP;
128
129 JRegressor_t::debug = debug;
130 JRegressor_t::T_ns.setRange(parameters.TMin_ns, parameters.TMax_ns);
131 JRegressor_t::Vmax_npe = parameters.Vmax_npe;
132 JRegressor_t::MAXIMUM_ITERATIONS = 1000;
133 JRegressor_t::EPSILON = 1e-3;
134 JRegressor_t::EPSILON_ABSOLUTE = true;
135
136 this->parameters.resize(3);
137
138 this->parameters[0] = JShower3EZ::pDX();
139 this->parameters[1] = JShower3EZ::pDY();
140 this->parameters[2] = JShower3EZ::pE();
141
142 this->estimator.reset(getMEstimator(parameters.mestimator));
143 }
144
145 /**
146 * Get input data.
147 *
148 * \param router module router
149 * \param summary summary data
150 * \param event event
151 * \param in start values
152 * \param coverage coverage
153 * \return input data
154 */
156 const JSummaryRouter& summary,
157 const JDAQEvent& event,
158 const JEvt& in,
159 const coverage_type& coverage) const
160 {
161 using namespace std;
162 using namespace JTRIGGER;
163
164 input_type input(event.getDAQEventHeader(), in, coverage);
165
166 const JBuildL0 <JHitR0> buildL0;
168
169 const JDAQTimeslice timeslice(event, true);
170
171 JSuperFrame2D<JHit> buffer;
172
173 for (JDAQTimeslice::const_iterator i = timeslice.begin(); i != timeslice.end(); ++i) {
174
175 if (router.hasModule(i->getModuleID())) {
176
177 buffer(*i, router.getModule(i->getModuleID()));
178
179 buildL0(buffer, back_inserter(data[i->getModuleID()]));
180 }
181 }
182
183 for (const auto& module : router.getReference()) {
184 if (!module.empty()) {
185 input.data.push_back(module_type(module, summary.getSummaryFrame(module.getID(), R_Hz), data[module.getID()]));
186 }
187 }
188
189 return input;
190 }
191
192 /**
193 * Fit function.
194 *
195 * \param input input data
196 * \return fit results
197 */
199 {
200 using namespace std;
201 using namespace JPP;
202
204
205 JEvt out;
206
207 JEvt in = input.in;
208
210
211 if (!in.empty()) {
212 in.select(JHistory::is_event(in.begin()->getHistory()));
213 }
214
215 for (JEvt::const_iterator shower = in.begin(); shower != in.end(); ++shower) {
216
217 vector<JPMTW0> data;
218
219 const JPosition3D vertex(getPosition(*shower));
220 const double time = shower->getT();
221 const double distance = DMax_m + DStep_m * log10(shower->getE());
222 const JRotation3D R(getDirection(*shower));
223
224 for (const auto& module : input.data) {
225
226 JPosition3D pos(module->getPosition());
227
228 pos.sub(vertex);
229
230 if (pos.getLength() < distance) {
231
232 for (size_t i = 0; i != module->size(); ++i) {
233
234 if (module.getStatus(i)) {
235
236 const double t1 = time + pos.getLength() * getInverseSpeedOfLight() * getIndexOfRefraction();
237
238 struct {
239
240 bool operator()(const JHitR0& hit) const
241 {
242 return (hit.getPMT() == pmt && T_ns(hit.getT()));
243 }
244
245 const JTimeRange T_ns;
246 const size_t pmt;
247
248 } match = { JRegressor_t::T_ns + t1, i };
249
250 const JPMTIdentifier id(module->getID(), i);
251
253
254 const size_t ns = count_if(module.begin(), module.end(), match);
255 const double QE = wip.QE;
256
257 JPMT pmt = module->getPMT(i);
258
259 pmt.sub(vertex);
260 pmt.rotate(R);
261
262 data.push_back(JPMTW0(pmt, QE, module.frame.getRate(i), ns));
263 }
264 }
265 }
266 }
267
268
269 double chi2 = (*this)(JShower3EZ(JVertex3D(JVector3D(0,0,0), shower->getT()), JVersor3Z(),
270 shower->getE()), data.begin(), data.end());
271
272 double NDF = getCount(data.begin(), data.end()) - this->parameters.size();
273
274 JShower3E result(JShower3D(this->value.getVertex(), this->value.getDirection()), correct(this->value.getE()));
275
276 // check error matrix
277 bool status = true;
278
279 for (size_t i = 0; i != this->V.size(); ++i) {
280 if (std::isnan(this->V(i,i)) || this->V(i,i) < 0.0) {
281 status = false;
282 }
283 }
284
285 if (status) {
286
287 result.rotate_back(R);
288
289 result.add(vertex.getPosition());
290
291 out.push_back(getFit(JHistory(shower->getHistory(), event()), result, getQuality(chi2), NDF, result.getE()));
292
293 out.rbegin()->setV(this->V.size(), this->V);
294 out.rbegin()->setW(JSHOWERFIT_ENERGY, this->value.getE()); // Uncorrected Energy
295 out.rbegin()->setW(JPP_COVERAGE_ORIENTATION, input.coverage.orientation);
296 out.rbegin()->setW(JPP_COVERAGE_POSITION, input.coverage.position);
297 }
298 }
299
300 // apply default sorter
301
302 sort(out.begin(), out.end(), qualitySorter);
303
304 copy(input.in.begin(), input.in.end(), back_inserter(out));
305
306 return out;
307 }
308
309
312 };
313}
314
315#endif
316
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 JObjectID &id) const
Has module.
const JModule & getModule(const JObjectID &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:65
JEvt operator()(const input_type &input)
Fit function.
std::vector< module_type > detector_type
Definition JShowerFit.hh:69
JRegressor< JShower3EZ, JGandalf > JRegressor_t
Definition JShowerFit.hh:67
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:27
JPMT_t getPMT() const
Get PMT.
Definition JHitR0.hh:60
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_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:95