Jpp 20.0.0-195-g190c9e876
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
15
16#include "JTrigger/JHit.hh"
18#include "JTrigger/JHitL0.hh"
19#include "JTrigger/JHitL1.hh"
20#include "JTrigger/JHitR1.hh"
21#include "JTrigger/JBuildL0.hh"
22#include "JTrigger/JBuildL2.hh"
24#include "JTrigger/JMatch3G.hh"
25#include "JTrigger/JBind2nd.hh"
26
28
29#include "JFit/JFitToolkit.hh"
30#include "JFit/JEstimator.hh"
31#include "JFit/JPoint4E.hh"
32#include "JFit/JModel.hh"
33#include "JFit/JSimplex.hh"
35
40
47
50
52
54#include "JTools/JRange.hh"
55
56
57/**
58 * \author adomi, vcarretero
59 */
60namespace JRECONSTRUCTION {}
61namespace JPP { using namespace JRECONSTRUCTION; }
62
63namespace JRECONSTRUCTION {
64
69 using JFIT::JPoint4D;
70 using JFIT::JPoint4E;
71 using JFIT::JGandalf;
72 using JFIT::JRegressor;
74
75 /**
76 * class to handle the second position fit of the shower reconstruction, mainly dedicated for ORCA
77 */
79
81 public JRegressor<JPoint4E, JGandalf>
82
83 {
87 using JRegressor_t::operator();
88
90
91 public:
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 */
112 input_type(const JDAQEventHeader& header, const JEvt& in, const coverage_type& coverage) :
113 JDAQEventHeader(header),
114 in(in),
116 {}
117
121 };
122
123 /**
124 * Parameterized constructor
125 *
126 * \param parameters struct that holds default-optimized parameters for the reconstruction
127 * \param storage storage
128 * \param pmtParameters PMT parameters
129 * \param debug debug
130 */
132 const storage_type& storage,
134 const int debug = 0):
136 JRegressor_t(storage),
138 {
139 using namespace JPP;
140
141 JRegressor_t::T_ns.setRange(parameters.TMin_ns, parameters.TMax_ns);
142 JRegressor_t::Vmax_npe = VMax_npe;
143 JRegressor_t::MAXIMUM_ITERATIONS = NMax;
144 JRegressor_t::EPSILON = 1e-3;
145 JRegressor_t::debug = debug;
146
147 if (Emin_GeV > Emax_GeV || En <= 1) {
148 THROW(JException, "Invalid energy input " << Emin_GeV << ' ' << Emax_GeV << ' ' << En);
149 }
150
151 const double base = std::pow((Emax_GeV / Emin_GeV), 1.0 / (En - 1));
152
153 for (int i = 0; i != En; ++i) {
154 Ev.push_back(Emin_GeV * std::pow(base, i));
155 }
156
157 this->parameters.resize(5);
158
159 this->parameters[0] = JPoint4E::pX();
160 this->parameters[1] = JPoint4E::pY();
161 this->parameters[2] = JPoint4E::pZ();
162 this->parameters[3] = JPoint4E::pT();
163 this->parameters[4] = JPoint4E::pE();
164 }
165
166 /**
167 * Get input data.
168 *
169 * \param router module router
170 * \param summary summary data
171 * \param event event
172 * \param in start values
173 * \param coverage coverage
174 * \return input data
175 */
177 const JSummaryRouter& summary,
178 const JDAQEvent& event,
179 const JEvt& in,
180 const coverage_type& coverage) const
181 {
182 using namespace std;
183 using namespace JPP;
184 using namespace JTRIGGER;
185
186 const JBuildL0<JHitL0> buildL0;
187
188 input_type input(event.getDAQEventHeader(), in, coverage);
189
190 vector<JHitL0> data;
191
192 buildL0(JDAQTimeslice(event, true), router, back_inserter(data));
193
194 for (const auto& hit : data) {
195
196 const JPMTIdentifier id(hit.getModuleID(), hit.getPMTAddress());
197
199
200 const int type = wip.getType();
201 const double QE = wip.QE;
202 const double R_Hz = summary.getRate(hit.getPMTIdentifier(), this->R_Hz);
203
204 input.data.push_back(hit_type(hit, type, QE, R_Hz));
205 }
206
207 return input;
208 }
209 /**
210 * Fit function.
211 *
212 * \param input input data
213 * \return fit results
214 */
216
217 using namespace std;
218 using namespace JFIT;
219 using namespace JGEOMETRY3D;
220
222 JEvt out;
223
224 const buffer_type& data = input.data;
225
226 // select start values
227
228 JEvt in = input.in;
229
231
232 if (!in.empty()) {
233 in.select(JHistory::is_event(in.begin()->getHistory()));
234 }
235
236 for (JEvt::const_iterator shower = in.begin(); shower != in.end(); ++shower) {
237
238 JPoint4D vx(getPosition(*shower), shower->getT());
239
240 const JFIT::JModel<JPoint4D> match(vx, DMax_m, JRegressor_t::T_ns);
241
242 buffer_type buffer;
243
244 for (buffer_type::const_iterator i = data.begin(); i != data.end(); ++i) {
245
246 if (match(*i)) {
247 buffer.push_back(*i);
248 }
249 }
250
251 // select first hit
252
253 sort(buffer.begin(), buffer.end(), JHitL0::compare);
254
255 vector<hit_type>::iterator __end = unique(buffer.begin(), buffer.end(), equal_to<JDAQPMTIdentifier>());
256
257 const int NDF = distance(buffer.begin(), __end) - this->parameters.size();
258
259 if (NDF > 0) {
260
261 // set fit parameters
262 for (vector<double>::iterator e = Ev.begin(); e != Ev.end(); ++e) {
263
264 JPoint4E sh(vx, *e);
265
266 double chi2 = (*this)(sh, buffer.begin(), __end);
267
268 JShower3D result(JVertex3D(this->value.getPosition(), this->value.getT()), JDirection3D());
269
270 out.push_back(getFit(JHistory(shower->getHistory(), event()), result, getQuality(chi2), NDF, this->value.getE()));
271
272 // set additional values
273 out.rbegin()->setW(JPP_COVERAGE_ORIENTATION, input.coverage.orientation);
274 out.rbegin()->setW(JPP_COVERAGE_POSITION, input.coverage.position);
275
276 }
277 }
278 }
279
280 // apply default sorter
281
282 sort(out.begin(), out.end(), qualitySorter);
283
284 copy(input.in.begin(), input.in.end(), back_inserter(out));
285
286 return out;
287 }
288
290 };
291}
292
293#endif
294
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:24
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 JPP_COVERAGE_POSITION
coverage of dynamic position calibration of this event
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