Jpp test-rotations-new
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 <iostream>
5#include <vector>
6#include <algorithm>
7#include <functional>
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{
49
50 /**
51 * class to handle first step of the shower reconstruction in ORCA:
52 * it reconstructs the shower vertex, intended as the shower brightest point, as the barycenter of the hits
53 */
54
56 {
57
58 public:
59
62
63 /**
64 * Input data type.
65 **/
66 struct input_type :
67 public JDAQEventHeader
68 {
69 /**
70 * Default constructor.
71 */
73 {}
74 /**
75 * Constructor.
76 *
77 * \param header header
78 * \param coverage coverage
79 */
81 JDAQEventHeader(header),
83 {}
84
88 };
89
90 /**
91 * Parameterized constructor
92 *
93 * \param parameters struct that holds default-optimized parameters for the reconstruction.
94 * \param debug debug
95 */
96
98 const int debug = 0):
100 {}
101
102 /**
103 * Get input data.
104 *
105 * \param router module router
106 * \param event event
107 * \param coverage coverage
108 * \return input data
109 */
110 input_type getInput(const JModuleRouter& router, const KM3NETDAQ::JDAQEvent& event, const coverage_type& coverage) const
111 {
112 using namespace std;
113 using namespace JTRIGGER;
114 using namespace KM3NETDAQ;
115
116
117 const JBuildL0<hit_type> buildL0;
119
120 input_type input(event.getDAQEventHeader(), coverage);
121
122 buffer_type& dataL0 = input.dataL0;
123 buffer_type& dataL1 = input.dataL1;
124
125 buffer_type buffer;
126
127
128 buildL0(JDAQTimeslice(event, true), router, back_inserter(buffer)); // true => snapshot
129 buildL2(JDAQTimeslice(event, false), router, back_inserter(dataL1)); // false => triggered
130
131 copy(dataL1.begin(), dataL1.end(), back_inserter(dataL0));
132
133 if(dataL1.size() <= numberOfL1){
134 for (buffer_type::const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
135 if (find_if(dataL1.begin(), dataL1.end(), match_t(*i, TMaxExtra_ns)) == dataL1.end()) {
136 dataL0.push_back(*i);
137 }
138 }
139 }
140 return input;
141 }
142 /**
143 * Fit function.
144 *
145 * \param input input data
146 * \return fit results
147 */
149 {
150 using namespace std;
151 using namespace JPP;
152
153 const double STANDARD_DEVIATIONS = 3.0;
154
155 typedef JEstimator<JPoint4D> JEstimator_t;
156
157 JEvent event(JSHOWERPREFIT);
158
159 JEvt out;
160
161 const buffer_type& dataL0 = input.dataL0;
162 const buffer_type& dataL1 = input.dataL1;
163
164 const JMatch3G<hit_type> match3G(DMax_m, TMaxExtra_ns); // causality relation for showers
165
166 for (buffer_type::const_iterator root = dataL1.begin(); root != dataL1.end(); ++root) {
167
168 buffer_type data(1, *root);
169
170 JBinder2nd<hit_type> matching = JBind2nd(match3G, *root);
171
172 for (buffer_type::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
173
174 if(( root->getModuleIdentifier() != i->getModuleIdentifier() ) && matching(*i)){
175 data.push_back(*i);
176 }
177 }
178
179 buffer_type::iterator __end1 = clusterizeWeight(data.begin() + 1, data.end(), match3G);
180
181 // 4D fit
182 JEstimator_t fit;
183 JPoint4D vx;
184 double chi2 = numeric_limits<double>::max();
185 int NDF = distance(data.begin(), __end1) - JEstimator_t::NUMBER_OF_PARAMETERS;
186 int N = getCount(data.begin(), __end1);
187
188 if(NDF > 0){
189 if(distance(data.begin(), __end1) <= factoryLimit){
190
191 double ymin = numeric_limits<double>::max();
192
193 buffer_type::iterator __end2 = __end1;
194
195 for (int n = 0; n <= numberOfOutliers && distance(data.begin(), __end2) >
196 JEstimator_t::NUMBER_OF_PARAMETERS; ++n, --__end2) {
197
198 sort(data.begin() + 1, __end1, hit_type::compare);
199
200 do {
201 try {
202
203 fit(data.begin(), __end2);
204
205 double y = getChi2(fit, data.begin(), __end2, sigma_ns);
206
207 if (y < ymin) {
208 ymin = y;
209 vx = fit;
210 chi2 = ymin;
211 NDF = distance(data.begin(), __end2) - JEstimator_t::NUMBER_OF_PARAMETERS;
212 N = getCount(data.begin(), __end2);
213 }
214 }
215 catch(JException& error) { }
216
217 } while (next_permutation(data.begin() + 1, __end2, __end1, hit_type::compare));
218
219 ymin -= STANDARD_DEVIATIONS * STANDARD_DEVIATIONS;
220 }
221
222 } else {
223
224 const int number_of_outliers = distance(data.begin(), __end1) - JEstimator_t::NUMBER_OF_PARAMETERS - 1;
225
226 buffer_type::iterator __end2 = __end1;
227
228 for (int n = 0; n <= number_of_outliers; ++n) {
229
230 try{
231
232 fit(data.begin(), __end2);
233 vx = fit;
234 chi2 = getChi2(fit, data.begin(), __end2, sigma_ns);
235 NDF = distance(data.begin(), __end2) - JEstimator_t::NUMBER_OF_PARAMETERS;
236 N = getCount(data.begin(), __end2);
237
238 }
239 catch(const JException& error){ }
240
241 double ymax = 0;
242 buffer_type::iterator imax = __end2;
243
244 for (buffer_type::iterator i = data.begin() + 1; i != __end2; ++i) {
245
246 double y = getChi2(fit, *i, sigma_ns);
247
248 if (y > ymax) {
249 ymax = y;
250 imax = i;
251 }
252 }
253
254 if (ymax > STANDARD_DEVIATIONS * STANDARD_DEVIATIONS) {
255 --__end2;
256 swap(*imax, *__end2);
257 } else {
258 break;
259 }
260 }
261 }
262
263 out.push_back(getFit(event(), JTrack3D(vx, JGEOMETRY3D::JVersor3Z()), getQuality(chi2, N), NDF));
264
265 // set additional values
266
267 out.rbegin()->setW(JPP_COVERAGE_ORIENTATION, input.coverage.orientation);
268 out.rbegin()->setW(JPP_COVERAGE_POSITION, input.coverage.position);
269
270 }
271 }
272
274
275 size_t solutions = out.size();
276
277 for(size_t i=0; i < solutions; i++){
278 for(int x = -pos_grid_m; x < pos_grid_m + pos_step_m/2.; x += pos_step_m){
279 for(int y = -pos_grid_m; y < pos_grid_m + pos_step_m/2.; y += pos_step_m){
280 for(int z = -pos_grid_m; z < pos_grid_m + pos_step_m/2.; z += pos_step_m){
281 for(int t = -time_grid_ns; t < time_grid_ns + time_step_ns/2.; t += time_step_ns){
282 if (x != 0 || y != 0 || z != 0 || t != 0) {
283
284 out.push_back(getFit(event(),
285 JTrack3D(JPoint4D(getPosition(out[i]) + JPosition3D(x,y,z), out[i].getT()+t), JVersor3Z()),
286 0,
287 0));
288
289 // set additional values
290
291 out.rbegin()->setW(JPP_COVERAGE_ORIENTATION, input.coverage.orientation);
292 out.rbegin()->setW(JPP_COVERAGE_POSITION, input.coverage.position);
293
294 }
295 }
296 }
297 }
298 }
299 }
300 //sorting
301
302 if (numberOfPrefits > 0) {
303
304 // apply default sorter
305
306 JFIT::JEvt::iterator __end = out.end();
307
308 if (numberOfPrefits < out.size()) {
309
310 advance(__end = out.begin(), numberOfPrefits);
311
312 partial_sort(out.begin(), __end, out.end(), qualitySorter);
313
314 out.erase(__end, out.end());
315
316 } else {
317
318 sort(out.begin(), __end, qualitySorter);
319 }
320
321 } else {
322
323 sort(out.begin(), out.end(), qualitySorter);
324 }
325
326 return out;
327 }
328
329 /**
330 * Auxiliary class to match hit to root hit.
331 */
332 struct match_t {
333 /**
334 * Constructor.
335 *
336 * \param root root hit
337 * \param TMax_ns maximal time [ns]
338 */
339 match_t(const hit_type& root, const double TMax_ns) :
340 root(root),
342 {}
343
344 /**
345 * Test match.
346 *
347 * \param hit hit
348 * \return true if mach; else false
349 */
350 bool operator()(const hit_type& hit) const
351 {
352 return root.getModuleID() == hit.getModuleID() && fabs(root.getT() - hit.getT()) <= TMax_ns;
353 }
354
356 double TMax_ns;
357 };
358 };
359}
360
361#endif
362
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:72
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:24
The template JSharedPointer class can be used to share a pointer to an object.
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:35
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 JSHOWERPREFIT
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
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).
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.
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:36
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:203
Data structure for L2 parameters.