Jpp 21.0.1
the software that should make you happy
Loading...
Searching...
No Matches
JShowerPointSimplex.hh
Go to the documentation of this file.
1#ifndef JSHOWERPOINTSIMPLEX_INCLUDE
2#define JSHOWERPOINTSIMPLEX_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/JHitR1.hh"
19#include "JTrigger/JBuildL0.hh"
20#include "JTrigger/JBuildL2.hh"
22#include "JTrigger/JMatch3G.hh"
23#include "JTrigger/JBind2nd.hh"
24
25#include "JFit/JFitToolkit.hh"
26#include "JFit/JEstimator.hh"
27#include "JFit/JPoint4D.hh"
28#include "JFit/JModel.hh"
29#include "JFit/JSimplex.hh"
30#include "JFit/JGandalf.hh"
32
36
37#include "JLang/JPredicate.hh"
38
45
49
51
52#include "JMath/JWatershed.hh"
53
55#include "JTools/JRange.hh"
56
57/**
58 * \author adomi, vcarretero
59 */
60namespace JRECONSTRUCTION {}
61namespace JPP { using namespace JRECONSTRUCTION; }
62
63namespace JRECONSTRUCTION {
64
68 using JFIT::JPoint4D;
69 using JFIT::JGandalf;
70 using JFIT::JRegressor;
71
72 /**
73 * class to handle the second position fit of the shower reconstruction, mainly dedicated for ORCA
74 */
76
78 public JRegressor<JPoint4D, JGandalf>
79 {
80 public:
84
85 using JRegressor_t::operator();
86
87 /**
88 * Input data type.
89 */
90 struct input_type :
91 public JDAQEventHeader
92 {
93 /**
94 * Default constructor.
95 */
97 {}
98
99
100 /**
101 * Constructor.
102 *
103 * \param header header
104 * \param in start values
105 * \param coverage coverage
106 */
107 input_type(const JDAQEventHeader& header, const JEvt& in, const coverage_type& coverage) :
108 JDAQEventHeader(header),
109 in(in),
111 {}
112
117 };
118
119 public:
120
121 /**
122 * Parameterized constructor
123 *
124 * \param parameters struct that holds default-optimized parameters for the reconstruction.
125 * \param debug debug
126 */
128 const int debug = 0):
130 JRegressor_t(parameters.sigma_ns)
131 {
132 using namespace JPP;
133
134 JRegressor_t::debug = debug;
135 JRegressor_t::MAXIMUM_ITERATIONS = NMax;
136 JRegressor_t::EPSILON = 1e-4;
137
138 this->estimator.reset(getMEstimator(parameters.mestimator));
139 this->parameters.resize(4);
140 this->parameters[0] = JPoint4D::pX();
141 this->parameters[1] = JPoint4D::pY();
142 this->parameters[2] = JPoint4D::pZ();
143 this->parameters[3] = JPoint4D::pT();
144 }
145 /**
146 * Get input data.
147 *
148 * \param router module router
149 * \param event event
150 * \param in start values
151 * \param coverage coverage
152 * \return input data
153 */
154 input_type getInput(const JModuleRouter& router, const KM3NETDAQ::JDAQEvent& event, const JEvt& in, const coverage_type& coverage) const
155 {
156 using namespace std;
157 using namespace KM3NETDAQ;
158 using namespace JTRIGGER;
159 const JBuildL0<hit_type> buildL0;
161
162 input_type input(event.getDAQEventHeader(), in, coverage);
163
164 buffer_type& dataL0 = input.dataL0;
165 buffer_type& dataL1 = input.dataL1;
166
167 buildL0(JDAQTimeslice(event, true), router, back_inserter(dataL0));
168 buildL2(JDAQTimeslice(event, false), router, back_inserter(dataL1)); // false = triggered
169
170 return input;
171 }
172
173 /**
174 * Fit function.
175 *
176 * \param input input data
177 * \return fit results
178 */
180 {
181 using namespace std;
182 using namespace JPP;
183
185
186 JEvt out;
187
188 const buffer_type& dataL0 = input.dataL0;
189 const buffer_type& dataL1 = input.dataL1;
190
191 // select start values
192
193 JEvt in = input.in;
194
196
197 if (!in.empty()) {
198 in.select(JHistory::is_event(in.begin()->getHistory()));
199 }
200
201 for (JEvt::const_iterator shower = in.begin(); shower != in.end(); ++shower) {
202
203 JPoint4D vx(getPosition(*shower), shower->getT());
204
206
207 buffer_type data;
208
209 data.reserve(dataL0.size() + dataL1.size());
210
211 for (buffer_type::const_iterator i = dataL1.begin(); i != dataL1.end(); ++i) {
212
213 if (match(*i)) {
214 data.push_back(*i);
215 }
216 }
217
218 buffer_type::iterator __end = data.end();
219
220 for (buffer_type::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
221 if (find_if(data.begin(), __end, make_predicate(&hit_type::getModuleID, i->getModuleID())) == __end) {
222 if (match(*i)) {
223 data.push_back(*i);
224 }
225 }
226 }
227
228 const int NDF = getCount(data.begin(), data.end()) - this->parameters.size();
229
230 if (NDF > 0) {
231
232 double chi2 = (*this)(vx, data.begin(), data.end());
233
234 JShower3D result(JVertex3D(this->value.getPosition(), this->value.getT()), JDirection3D());
235
236 out.push_back(getFit(JHistory(shower->getHistory(), event()), result, getQuality(chi2, NDF), NDF, shower->getE()));
237
238 // set additional values
239
240 out.rbegin()->setW(JPP_COVERAGE_ORIENTATION, input.coverage.orientation);
241 out.rbegin()->setW(JPP_COVERAGE_POSITION, input.coverage.position);
242 }
243 }
244
245
246 if (numberOfPostfits > 0) {
247
248 auto __end = out.begin();
249
250 if (Qwatershed > 0.0) {
251
252 __end = watershed(out.begin(),
253 out.end(),
254 [](const JFit& fit) { return fit.getQ(); },
255 [](const JFit& first, const JFit& second) { return getPoint(first).get4Distance(getPoint(second)); },
256 Qwatershed,
258
259 } else {
260
261 advance(__end = out.begin(), min(numberOfPostfits, out.size()));
262
263 partial_sort(out.begin(), __end, out.end(), qualitySorter);
264 }
265
266 out.erase(__end, out.end());
267
268 } else {
269
270 sort(out.begin(), out.end(), qualitySorter);
271 }
272
273 copy(input.in.begin(), input.in.end(), back_inserter(out));
274
275 return out;
276 }
277
278
279 };
280}
281#endif
282
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.
Auxiliary methods to evaluate Poisson probabilities and chi2.
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.
Basic data structure for time and time over threshold information of hit.
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.
Data structure for track fit results with history and optional associated values.
Fit method based on the Levenberg-Marquardt method.
Definition JGandalf.hh:87
Data structure for vertex fit.
Definition JPoint4D.hh:24
static parameter_type pT()
Definition JPoint4D.hh:73
static parameter_type pZ()
Definition JPoint4D.hh:72
static parameter_type pX()
Definition JPoint4D.hh:70
static parameter_type pY()
Definition JPoint4D.hh:71
Data structure for direction in three dimensions.
class to handle the second position fit of the shower reconstruction, mainly dedicated for ORCA
JRegressor< JPoint4D, JGandalf > JRegressor_t
JEvt operator()(const input_type &input)
Fit function.
JShowerPointSimplex(const JShowerPointSimplexParameters_t &parameters, const int debug=0)
Parameterized constructor.
input_type getInput(const JModuleRouter &router, const KM3NETDAQ::JDAQEvent &event, const JEvt &in, const coverage_type &coverage) const
Get input data.
Template L0 hit builder.
Definition JBuildL0.hh:38
Template L2 builder.
Definition JBuildL2.hh:49
Reduced data structure for L1 hit.
Definition JHitR1.hh:38
const JDAQEventHeader & getDAQEventHeader() const
Get DAQ event header.
int getModuleID() const
Get module identifier.
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
JMEstimator * getMEstimator(const int type)
Get M-Estimator.
size_t getCount(const array_type< T > &buffer, const JCompare_t &compare)
Count number of unique values.
T watershed(T __begin, T __end, const JFunction_t &getValue, const JDistance_t &getDistance, double Y, int N=std::numeric_limits< int >::max())
Watershed algorithm.
Definition JWatershed.hh:29
JTOOLS::JRange< double > JTimeRange
Type definition for time range (unit [ns]).
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.
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
return result
Definition JPolint.hh:862
Auxiliary classes and methods for triggering.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
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 TMin_ns
minimum time for local coincidences [ns]
double TMaxLocal_ns
time window for local coincidences [ns]
double TMax_ns
maximum time for local coincidences [ns]
double ctMin
minimal cosine space angle between PMT axes
double DMax_m
maximal distance to optical module [m]
input_type(const JDAQEventHeader &header, const JEvt &in, const coverage_type &coverage)
Constructor.
Data structure for L2 parameters.