Jpp 21.0.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JShowerPrefit.hh
Go to the documentation of this file.
1#ifndef JSHOWERPREFIT_INCLUDE
2#define JSHOWERPREFIT_INCLUDE
3
4#include <vector>
5#include <algorithm>
6#include <functional>
7#include <memory>
8
11
13
14#include "JTrigger/JHit.hh"
15#include "JTrigger/JHitR1.hh"
16#include "JTrigger/JBuildL0.hh"
17#include "JTrigger/JBuildL2.hh"
19#include "JTrigger/JMatch3G.hh"
20#include "JTrigger/JBind2nd.hh"
21
23
24#include "JFit/JFitToolkit.hh"
26#include "JFit/JEstimator.hh"
27#include "JFit/JPoint4D.hh"
28
30
34
35#include "JLang/JComparator.hh"
36
38
39/**
40 * \author adomi, gmaggi, vcarretero
41 */
42
43namespace JRECONSTRUCTION
44{
48
49 /**
50 * class to handle first step of the shower reconstruction in ORCA:
51 * it reconstructs the shower vertex, intended as the shower brightest point, as the barycenter of the hits
52 */
53
55 {
56
57 public:
58
61
62 /**
63 * Input data type.
64 **/
65 struct input_type :
66 public JDAQEventHeader
67 {
68 /**
69 * Default constructor.
70 */
72 {}
73 /**
74 * Constructor.
75 *
76 * \param header header
77 * \param coverage coverage
78 */
80 JDAQEventHeader(header),
82 {}
83
87 };
88
89 /**
90 * Parameterized constructor
91 *
92 * \param parameters struct that holds default-optimized parameters for the reconstruction.
93 * \param debug debug
94 */
95
97 const int debug = 0):
99 {}
100
101 /**
102 * Get input data.
103 *
104 * \param router module router
105 * \param event event
106 * \param coverage coverage
107 * \return input data
108 */
109 input_type getInput(const JModuleRouter& router, const KM3NETDAQ::JDAQEvent& event, const coverage_type& coverage) const
110 {
111 using namespace std;
112 using namespace JTRIGGER;
113 using namespace KM3NETDAQ;
114
115
116 const JBuildL0<hit_type> buildL0;
118
119 input_type input(event.getDAQEventHeader(), coverage);
120
121 buffer_type& dataL0 = input.dataL0;
122 buffer_type& dataL1 = input.dataL1;
123
124 buffer_type buffer;
125
126
127 buildL0(JDAQTimeslice(event, true), router, back_inserter(buffer)); // true => snapshot
128 buildL2(JDAQTimeslice(event, false), router, back_inserter(dataL1)); // false => triggered
129
130 copy(dataL1.begin(), dataL1.end(), back_inserter(dataL0));
131
132 if(dataL1.size() <= numberOfL1){
133 for (buffer_type::const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
134 if (find_if(dataL1.begin(), dataL1.end(), match_t(*i, TMaxExtra_ns)) == dataL1.end()) {
135 dataL0.push_back(*i);
136 }
137 }
138 }
139 return input;
140 }
141 /**
142 * Fit function.
143 *
144 * \param input input data
145 * \return fit results
146 */
148 {
149 using namespace std;
150 using namespace JPP;
151
152 const double STANDARD_DEVIATIONS = 3.0;
153
154 typedef JEstimator<JPoint4D> JEstimator_t;
155
156 JEvent event(JSHOWERPREFIT);
157
158 JEvt out;
159
160 const buffer_type& dataL0 = input.dataL0;
161 const buffer_type& dataL1 = input.dataL1;
162
163 const JMatch3G<hit_type> match3G(DMax_m, TMaxExtra_ns); // causality relation for showers
164
165 for (buffer_type::const_iterator root = dataL1.begin(); root != dataL1.end(); ++root) {
166
167 buffer_type data(1, *root);
168
169 JBinder2nd<hit_type> matching = JBind2nd(match3G, *root);
170
171 for (buffer_type::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
172
173 if(( root->getModuleIdentifier() != i->getModuleIdentifier() ) && matching(*i)){
174 data.push_back(*i);
175 }
176 }
177
178 buffer_type::iterator __end1 = clusterizeWeight(data.begin() + 1, data.end(), match3G);
179
180 // 4D fit
181 JEstimator_t fit;
182 JPoint4D vx;
183 double chi2 = numeric_limits<double>::max();
184 int NDF = distance(data.begin(), __end1) - JEstimator_t::NUMBER_OF_PARAMETERS;
185 int N = getCount(data.begin(), __end1);
186
187 if(NDF > 0){
188 if(distance(data.begin(), __end1) <= factoryLimit){
189
190 double ymin = numeric_limits<double>::max();
191
192 buffer_type::iterator __end2 = __end1;
193
194 for (int n = 0; n <= numberOfOutliers && distance(data.begin(), __end2) >
195 JEstimator_t::NUMBER_OF_PARAMETERS; ++n, --__end2) {
196
197 sort(data.begin() + 1, __end1, hit_type::compare);
198
199 do {
200 try {
201
202 fit(data.begin(), __end2);
203
204 double y = getChi2(fit, data.begin(), __end2, sigma_ns);
205
206 if (y < ymin) {
207 ymin = y;
208 vx = fit;
209 chi2 = ymin;
210 NDF = distance(data.begin(), __end2) - JEstimator_t::NUMBER_OF_PARAMETERS;
211 N = getCount(data.begin(), __end2);
212 }
213 }
214 catch(JException& error) { }
215
216 } while (next_permutation(data.begin() + 1, __end2, __end1, hit_type::compare));
217
218 ymin -= STANDARD_DEVIATIONS * STANDARD_DEVIATIONS;
219 }
220
221 } else {
222
223 const int number_of_outliers = distance(data.begin(), __end1) - JEstimator_t::NUMBER_OF_PARAMETERS - 1;
224
225 buffer_type::iterator __end2 = __end1;
226
227 for (int n = 0; n <= number_of_outliers; ++n) {
228
229 try{
230
231 fit(data.begin(), __end2);
232 vx = fit;
233 chi2 = getChi2(fit, data.begin(), __end2, sigma_ns);
234 NDF = distance(data.begin(), __end2) - JEstimator_t::NUMBER_OF_PARAMETERS;
235 N = getCount(data.begin(), __end2);
236
237 }
238 catch(const JException& error){ }
239
240 double ymax = 0;
241 buffer_type::iterator imax = __end2;
242
243 for (buffer_type::iterator i = data.begin() + 1; i != __end2; ++i) {
244
245 double y = getChi2(fit, *i, sigma_ns);
246
247 if (y > ymax) {
248 ymax = y;
249 imax = i;
250 }
251 }
252
253 if (ymax > STANDARD_DEVIATIONS * STANDARD_DEVIATIONS) {
254 --__end2;
255 swap(*imax, *__end2);
256 } else {
257 break;
258 }
259 }
260 }
261
262 out.push_back(getFit(event(), JShower3D(vx, JGEOMETRY3D::JVersor3Z()), getQuality(chi2, N), NDF));
263
264 // set additional values
265
266 out.rbegin()->setW(JPP_COVERAGE_ORIENTATION, input.coverage.orientation);
267 out.rbegin()->setW(JPP_COVERAGE_POSITION, input.coverage.position);
268
269 }
270 }
271
273
274 size_t solutions = out.size();
275
276 for(size_t i=0; i < solutions; i++){
277 for(int x = -pos_grid_m; x < pos_grid_m + pos_step_m/2.; x += pos_step_m){
278 for(int y = -pos_grid_m; y < pos_grid_m + pos_step_m/2.; y += pos_step_m){
279 for(int z = -pos_grid_m; z < pos_grid_m + pos_step_m/2.; z += pos_step_m){
280 for(int t = -time_grid_ns; t < time_grid_ns + time_step_ns/2.; t += time_step_ns){
281 if (x != 0 || y != 0 || z != 0 || t != 0) {
282
283 out.push_back(getFit(event(),
284 JShower3D(JPoint4D(getPosition(out[i]) + JPosition3D(x,y,z), out[i].getT()+t), JVersor3Z()),
285 0,
286 0));
287
288 // set additional values
289
290 out.rbegin()->setW(JPP_COVERAGE_ORIENTATION, input.coverage.orientation);
291 out.rbegin()->setW(JPP_COVERAGE_POSITION, input.coverage.position);
292
293 }
294 }
295 }
296 }
297 }
298 }
299 //sorting
300
301 if (numberOfPrefits > 0) {
302
303 // apply default sorter
304
305 JFIT::JEvt::iterator __end = out.end();
306
307 if (numberOfPrefits < out.size()) {
308
309 advance(__end = out.begin(), numberOfPrefits);
310
311 partial_sort(out.begin(), __end, out.end(), qualitySorter);
312
313 out.erase(__end, out.end());
314
315 } else {
316
317 sort(out.begin(), __end, qualitySorter);
318 }
319
320 } else {
321
322 sort(out.begin(), out.end(), qualitySorter);
323 }
324
325 return out;
326 }
327
328 /**
329 * Auxiliary class to match hit to root hit.
330 */
331 struct match_t {
332 /**
333 * Constructor.
334 *
335 * \param root root hit
336 * \param TMax_ns maximal time [ns]
337 */
338 match_t(const hit_type& root, const double TMax_ns) :
339 root(root),
341 {}
342
343 /**
344 * Test match.
345 *
346 * \param hit hit
347 * \return true if mach; else false
348 */
349 bool operator()(const hit_type& hit) const
350 {
351 return root.getModuleID() == hit.getModuleID() && fabs(root.getT() - hit.getT()) <= TMax_ns;
352 }
353
355 double TMax_ns;
356 };
357 };
358}
359
360#endif
361
Algorithms for hit clustering and sorting.
Coverage of dynamical detector 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.
Linear fit of JFIT::JPoint4D.
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.
Template definition of linear fit.
Definition JEstimator.hh:25
Data structure for set of track fit results.
void select(const JSelector_t &selector)
Select fits.
Data structure for vertex fit.
Definition JPoint4D.hh:24
Data structure for position in three dimensions.
Data structure for normalised vector in positive z-direction.
Definition JVersor3Z.hh:41
General exception.
Definition JException.hh:25
class to handle first step of the shower reconstruction in ORCA: it reconstructs the shower vertex,...
JShowerPrefit(const JShowerPrefitParameters_t &parameters, const int debug=0)
Parameterized constructor.
input_type getInput(const JModuleRouter &router, const KM3NETDAQ::JDAQEvent &event, const coverage_type &coverage) const
Get input data.
std::vector< hit_type > buffer_type
JEvt operator()(const input_type &input)
Fit function.
Auxiliary class to convert binary JMatch operator and given hit to unary match operator.
Definition JBind2nd.hh:24
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
double getT() const
Get calibrated time of hit.
3G match criterion.
Definition JMatch3G.hh:31
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
double getChi2(const double P)
Get chi2 corresponding to given probability.
size_t getCount(const array_type< T > &buffer, const JCompare_t &compare)
Count number of unique values.
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.
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.
const int n
Definition JPolint.hh:791
bool next_permutation(T __begin, T __last, T __end, JComparator_t compare, std::bidirectional_iterator_tag)
Implementation of method next_permutation for bidirectional iterators.
Auxiliary classes and methods for triggering.
JBinder2nd< JHit_t > JBind2nd(const JMatch< JHit_t > &match, const JHit_t &second)
Auxiliary method to create JBinder2nd object.
Definition JBind2nd.hh:66
JHitIterator_t clusterizeWeight(JHitIterator_t __begin, JHitIterator_t __end, const JMatch_t &match)
Partition data according given binary match operator.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
Definition root.py:1
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
int factoryLimit
factory limit for combinatorics
double DMax_m
maximal distance to optical module [m]
double ctMin
minimal cosine space angle between PMT axes
size_t numberOfGrids
number of prefits to be used to build a grid around
double TMaxLocal_ns
time window for local coincidences [ns]
double TMaxExtra_ns
time window for extra coincidences [ns]
input_type(const JDAQEventHeader &header, const coverage_type &coverage)
Constructor.
Auxiliary class to match hit to root hit.
bool operator()(const hit_type &hit) const
Test match.
match_t(const hit_type &root, const double TMax_ns)
Constructor.
Auxiliary data structure for sorting of hits.
Definition JHitR1.hh:206
Data structure for L2 parameters.