Jpp 21.0.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JMuonSimplex.hh
Go to the documentation of this file.
1#ifndef __JRECONSTRUCTION__JMUONSIMPLEX__
2#define __JRECONSTRUCTION__JMUONSIMPLEX__
3
4#include <iostream>
5#include <iomanip>
6#include <vector>
7#include <algorithm>
8
13
14#include "JTrigger/JHitR1.hh"
16#include "JTrigger/JBuildL0.hh"
17#include "JTrigger/JBuildL2.hh"
18
19#include "JFit/JFitToolkit.hh"
20#include "JFit/JLine1Z.hh"
21#include "JFit/JLine3Z.hh"
22#include "JFit/JModel.hh"
23#include "JFit/JSimplex.hh"
25#include "JFit/JMEstimator.hh"
26
30
31#include "JLang/JPredicate.hh"
32
34
36
38
39#include "Jeep/JMessage.hh"
40
41
42/**
43 * \author mdejong, gmaggi
44 */
45
46namespace JRECONSTRUCTION {}
47namespace JPP { using namespace JRECONSTRUCTION; }
48
49namespace JRECONSTRUCTION {
50
53 using JFIT::JRegressor;
54 using JFIT::JLine3Z;
55 using JFIT::JSimplex;
57
58
59 /**
60 * Wrapper class to make intermediate fit of muon trajectory.
61 *
62 * The JMuonSimplex fit uses one or more start values (usually taken from the output of JMuonPrefit) and
63 * produces new start values for subsequent fits (usually JMuonGandalf).\n
64 * All hits of which the PMT position lies within a set road width (JMuonSimplexParameters_t::roadWidth_m) and
65 * time is within a set window (JMuonSimplexParameters_t::TMin_ns, JMuonSimplexParameters_t::TMax_ns) around the Cherenkov hypothesis are taken.\n
66 * In case there are multiple hits from the same PMT is the specified window,
67 * the first hit is taken and the other hits are discarded.\n
68 * The chi-squared is based on an M-estimator of the time residuals.\n
69 */
70 struct JMuonSimplex :
72 public JRegressor<JLine3Z, JSimplex>
73 {
77
78 using JRegressor_t::operator();
79
80 /**
81 * Input data type.
82 */
83 struct input_type :
84 public JDAQEventHeader
85 {
86 /**
87 * Default constructor.
88 */
90 {}
91
92
93 /**
94 * Constructor.
95 *
96 * \param header header
97 * \param in start values
98 * \param coverage coverage
99 */
101 const JEvt& in,
102 const coverage_type& coverage) :
103 JDAQEventHeader(header),
104 in(in),
106 {}
107
112 };
113
114
115 /**
116 * Constructor
117 *
118 * \param parameters parameters
119 * \param debug debug
120 */
122 const int debug = 0) :
123 JMuonSimplexParameters_t(parameters),
124 JRegressor_t(parameters.sigma_ns)
125 {
126 using namespace JFIT;
127
128 this->estimator.reset(getMEstimator(mestimator));
129
130 JRegressor_t::debug = debug;
131 JRegressor_t::MAXIMUM_ITERATIONS = NMax;
132 }
133
134
135 /**
136 * Get input data.
137 *
138 * \param router module router
139 * \param event event
140 * \param in start values
141 * \param coverage coverage
142 * \return input data
143 */
145 const JDAQEvent& event,
146 const JEvt& in,
147 const coverage_type& coverage) const
148 {
149 using namespace std;
150 using namespace JTRIGGER;
151 using namespace KM3NETDAQ;
152
153 const JBuildL0<hit_type> buildL0;
155
156 input_type input(event.getDAQEventHeader(), in, coverage);
157
158 buffer_type& dataL0 = input.dataL0;
159 buffer_type& dataL1 = input.dataL1;
160
161 const JDAQTimeslice timeslice(event, true);
162 JSuperFrame2D<JHit> buffer;
163
164 for (JDAQTimeslice::const_iterator i = timeslice.begin(); i != timeslice.end(); ++i) {
165
166 if (router.hasModule(i->getModuleID())) {
167
168 buffer(*i, router.getModule(i->getModuleID()));
169
170 if (useL0) {
171 buildL0(buffer, back_inserter(dataL0));
172 }
173 {
174 buildL2(buffer, back_inserter(dataL1));
175 }
176 }
177 }
178
179 return input;
180 }
181
182
183 /**
184 * Fit function.
185 *
186 * \param input input data
187 * \return fit results
188 */
190 {
191 using namespace std;
192 using namespace JFIT;
193 using namespace JGEOMETRY3D;
194 using namespace JLANG;
195
196 JEvent event(JMUONSIMPLEX);
197
198 JEvt out;
199
200 const buffer_type& dataL0 = input.dataL0;
201 const buffer_type& dataL1 = input.dataL1;
202
203 // select start values
204
205 JEvt in = input.in;
206
208
209 if (!in.empty()) {
210 in.select(JHistory::is_event(in.begin()->getHistory()));
211 }
212
213 buffer_type data;
214
215 data.reserve(dataL0.size() +
216 dataL1.size());
217
218 for (JEvt::const_iterator track = in.begin(); track != in.end(); ++track) {
219
220 const JRotation3D R (getDirection(*track));
221 const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
223
224 data.clear();
225
226 for (buffer_type::const_iterator i = dataL1.begin(); i != dataL1.end(); ++i) {
227
228 hit_type hit(*i);
229
230 hit.rotate(R);
231
232 if (match(hit)) {
233 data.push_back(hit);
234 }
235 }
236
237 if (useL0) {
238
239 buffer_type::iterator __end = data.end();
240
241 for (buffer_type::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
242
243 if (find_if(data.begin(), __end, make_predicate(&hit_type::getModuleID, i->getModuleID())) == __end) {
244
245 hit_type hit(*i);
246
247 hit.rotate(R);
248
249 if (match(hit)) {
250 data.push_back(hit);
251 }
252 }
253 }
254 }
255
256
257 this->step.resize(5);
258
259 this->step[0] = JLine3Z(JLine1Z(JVector3D(0.5, 0.0, 0.0), 0.0));
260 this->step[1] = JLine3Z(JLine1Z(JVector3D(0.0, 0.5, 0.0), 0.0));
261 this->step[2] = JLine3Z(JLine1Z(JVector3D(0.0, 0.0, 0.0), 1.0));
262 this->step[3] = JLine3Z(JLine1Z(JVector3D(), 0.0), JVersor3Z(0.005, 0.0));
263 this->step[4] = JLine3Z(JLine1Z(JVector3D(), 0.0), JVersor3Z(0.0, 0.005));
264
265 const int NDF = getCount(data.begin(), data.end()) - this->step.size();
266
267 if (NDF > 0) {
268
269 const double chi2 = (*this)(JLine3Z(tz), data.begin(), data.end());
270
271 JTrack3D tb(this->value);
272
273 tb.rotate_back(R);
274
275 out.push_back(getFit(JHistory(track->getHistory(), event()), tb, getQuality(chi2, NDF), NDF));
276
277 // set additional values
278
279 out.rbegin()->setW(track->getW());
280 out.rbegin()->setW(JPP_COVERAGE_ORIENTATION, input.coverage.orientation);
281 out.rbegin()->setW(JPP_COVERAGE_POSITION, input.coverage.position);
282 }
283 }
284
285 // apply default sorter
286
287 sort(out.begin(), out.end(), qualitySorter);
288
289 copy(input.in.begin(), input.in.end(), back_inserter(out));
290
291 return out;
292 }
293 };
294}
295
296#endif
Coverage of dynamical detector calibration.
Auxiliary methods to evaluate Poisson probabilities and chi2.
Reduced data structure for L1 hit.
Data regression method for JFIT::JLine3Z.
Maximum likelihood estimator (M-estimators).
General purpose messaging.
int debug
debug level
Definition JSirene.cc:74
Direct access to module in detector data structure.
Router for direct addressing of module data in detector data structure.
bool hasModule(const JModuleIdentifier &id) const
Has module.
const JModule & getModule(const JModuleIdentifier &id) const
Get module parameters.
Data structure for set of track fit results.
void select(const JSelector_t &selector)
Select fits.
Data structure for fit of straight line paralel to z-axis.
Definition JLine1Z.hh:29
Data structure for fit of straight line in positive z-direction.
Definition JLine3Z.hh:40
Simple fit method based on Powell's algorithm, see reference: Numerical Recipes in C++,...
Definition JSimplex.hh:44
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Data structure for vector in three dimensions.
Definition JVector3D.hh:36
Data structure for normalised vector in positive z-direction.
Definition JVersor3Z.hh:41
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
2-dimensional frame with time calibrated data from one optical module.
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
Auxiliary classes and methods for linear and iterative data regression.
JMEstimator * getMEstimator(const int type)
Get M-Estimator.
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition JAngle3D.hh:19
Auxiliary classes and methods for language specific functionality.
size_t getCount(const array_type< T > &buffer, const JCompare_t &compare)
Count number of unique values.
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.
JDirection3D getDirection(const JFit &fit)
Get direction.
Auxiliary classes and methods for triggering.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
Model for fit to acoustics data.
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
Template definition of a data regressor of given model.
Definition JRegressor.hh:70
double TMax_ns
maximal time w.r.t. Cherenkov hypothesis [ns]
double TMaxLocal_ns
time window for local coincidences [ns]
double TMin_ns
minimal time w.r.t. Cherenkov hypothesis [ns]
double ctMin
minimal cosine space angle between PMT axes
input_type(const JDAQEventHeader &header, const JEvt &in, const coverage_type &coverage)
Constructor.
Wrapper class to make intermediate fit of muon trajectory.
JRegressor< JLine3Z, JSimplex > JRegressor_t
std::vector< hit_type > buffer_type
input_type getInput(const JModuleRouter &router, const JDAQEvent &event, const JEvt &in, const coverage_type &coverage) const
Get input data.
JMuonSimplex(const JMuonSimplexParameters_t &parameters, const int debug=0)
Constructor.
JEvt operator()(const input_type &input)
Fit function.
Data structure for L2 parameters.