Jpp 19.3.0-rc.1
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
51
53
55#include "JTools/JRange.hh"
57
58/**
59 * \author adomi, vcarretero
60 */
61namespace JRECONSTRUCTION {}
62namespace JPP { using namespace JRECONSTRUCTION; }
63
64namespace JRECONSTRUCTION {
65
70 using JFIT::JPoint4D;
71 using JFIT::JPoint4E;
72 using JFIT::JGandalf;
73 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();
89 public:
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 */
110 input_type(const JDAQEventHeader& header, const JEvt& in, const coverage_type& coverage) :
111 JDAQEventHeader(header),
112 in(in),
114 {}
115
119 };
120
121 /**
122 * Parameterized constructor
123 *
124 * \param parameters struct that holds default-optimized parameters for the reconstruction
125 * \param storage storage
126 * \param debug debug
127 */
129 const storage_type& storage,
130 const int debug = 0):
132 JRegressor_t(storage)
133 {
134 using namespace JPP;
135
136 JRegressor_t::T_ns.setRange(parameters.TMin_ns, parameters.TMax_ns);
137 JRegressor_t::Vmax_npe = VMax_npe;
138 JRegressor_t::MAXIMUM_ITERATIONS = NMax;
139 JRegressor_t::EPSILON = 1e-3;
140 JRegressor_t::debug = debug;
141
142 if (Emin_GeV > Emax_GeV || En <= 1) {
143 THROW(JException, "Invalid energy input " << Emin_GeV << ' ' << Emax_GeV << ' ' << En);
144 }
145
146 const double base = std::pow((Emax_GeV / Emin_GeV), 1.0 / (En - 1));
147
148 for (int i = 0; i != En; ++i) {
149 Ev.push_back(Emin_GeV * std::pow(base, i));
150 }
151
152 this->parameters.resize(5);
153
154 this->parameters[0] = JPoint4E::pX();
155 this->parameters[1] = JPoint4E::pY();
156 this->parameters[2] = JPoint4E::pZ();
157 this->parameters[3] = JPoint4E::pT();
158 this->parameters[4] = JPoint4E::pE();
159 }
160 /**
161 * Get input data.
162 *
163 * \param router module router
164 * \param summary summary data
165 * \param event event
166 * \param in start values
167 * \param coverage coverage
168 * \return input data
169 */
171 const JSummaryRouter& summary,
172 const JDAQEvent& event,
173 const JEvt& in,
174 const coverage_type& coverage) const
175 {
176 using namespace std;
177 using namespace JPP;
178 using namespace JTRIGGER;
179
180 const JBuildL0<JHitL0> buildL0;
181
182 input_type input(event.getDAQEventHeader(), in, coverage);
183
184 vector<JHitL0> data;
185 buildL0(JDAQTimeslice(event, true), router, back_inserter(data));
186
187 for (const auto& hit : data) {
188 input.data.push_back(hit_type(hit, summary.getRate(hit.getPMTIdentifier())));
189 }
190 return input;
191 }
192 /**
193 * Fit function.
194 *
195 * \param input input data
196 * \return fit results
197 */
199
200 using namespace std;
201 using namespace JFIT;
202 using namespace JGEOMETRY3D;
203
205 JEvt out;
206
207 const buffer_type& data = input.data;
208
209 // select start values
210
211 JEvt in = input.in;
212
214
215 if (!in.empty()) {
216 in.select(JHistory::is_event(in.begin()->getHistory()));
217 }
218
219 for (JEvt::const_iterator shower = in.begin(); shower != in.end(); ++shower) {
220
221 JPoint4D vx(getPosition(*shower), shower->getT());
222
223 const JFIT::JModel<JPoint4D> match(vx, DMax_m, JRegressor_t::T_ns);
224
225 buffer_type buffer;
226
227 for (buffer_type::const_iterator i = data.begin(); i != data.end(); ++i) {
228
229 if (match(*i)) {
230 buffer.push_back(*i);
231 }
232 }
233
234 // select first hit
235
236 sort(buffer.begin(), buffer.end(), JHitL0::compare);
237
238 vector<hit_type>::iterator __end = unique(buffer.begin(), buffer.end(), equal_to<JDAQPMTIdentifier>());
239
240 const int NDF = distance(buffer.begin(), __end) - this->parameters.size();
241
242 if (NDF > 0) {
243
244 // set fit parameters
245 for (vector<double>::iterator e = Ev.begin(); e != Ev.end(); ++e) {
246 JPoint4E sh(vx, *e);
247 double chi2 = (*this)(sh, buffer.begin(), __end);
248
249 JShower3E sh_fit(this->value.getPosition(), JDirection3D(),
250 this->value.getT(), this->value.getE());
251
252 out.push_back(getFit(JHistory(shower->getHistory(), event()), sh_fit,
253 getQuality(chi2), NDF, sh_fit.getE()));
254
255 // set additional values
256 out.rbegin()->setW(JPP_COVERAGE_ORIENTATION, input.coverage.orientation);
257 out.rbegin()->setW(JPP_COVERAGE_POSITION, input.coverage.position);
258
259 }
260 }
261 }
262
263 // apply default sorter
264
265 sort(out.begin(), out.end(), qualitySorter);
266
267 copy(input.in.begin(), input.in.end(), back_inserter(out));
268
269 return out;
270 }
271 };
272
273
274}
275
276#endif
277
Algorithms for hit clustering and sorting.
Coverage of dynamical detector calibration.
Auxiliary class to extract a subset of optical modules from a detector.
Data structure for detector geometry and 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:72
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.
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.
3D track with energy.
Definition JTrack3E.hh:32
double getE() const
Get energy.
Definition JTrack3E.hh:93
General exception.
Definition JException.hh:24
Auxiliary class for a hit with background rate value.
Definition JHitW0.hh:23
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.
JShowerPositionFit(const JShowerPositionFitParameters_t &parameters, const storage_type &storage, const int debug=0)
Parameterized constructor.
input_type getInput(const JModuleRouter &router, const JSummaryRouter &summary, const JDAQEvent &event, const JEvt &in, const coverage_type &coverage) const
Get input data.
Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure as a functio...
double getRate() const
Get default rate.
Template L0 hit builder.
Definition JBuildL0.hh:38
const JDAQEventHeader & getDAQEventHeader() const
Get DAQ event header.
static const int JSHOWERPOSITIONFIT
static const int JPP_COVERAGE_POSITION
coverage of dynamic position calibration from any Jpp application
static const int JPP_COVERAGE_ORIENTATION
coverage of dynamic orientation calibration from any Jpp application
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
Auxiliary classes and methods for linear and iterative data regression.
Definition JEnergy.hh:15
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).
Model fits to data.
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:405
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.
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:36
Auxiliary class to test history.
Definition JHistory.hh:136
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