Jpp master_rocky-44-g75b7c4f75
the software that should make you happy
Loading...
Searching...
No Matches
JMuonGandalf.hh
Go to the documentation of this file.
1#ifndef __JRECONSTRUCTION__JMUONGANDALF__
2#define __JRECONSTRUCTION__JMUONGANDALF__
3
4#include <string>
5#include <iostream>
6#include <iomanip>
7#include <vector>
8#include <algorithm>
9
13
14#include "JTrigger/JHitL0.hh"
15#include "JTrigger/JBuildL0.hh"
16
17#include "JFit/JFitToolkit.hh"
18#include "JFit/JLine1Z.hh"
19#include "JFit/JLine3Z.hh"
20#include "JFit/JModel.hh"
21#include "JFit/JGandalf.hh"
23
28
29#include "JPhysics/JPDFTable.hh"
31#include "JPhysics/JGeane.hh"
32
34
36
38
39#include "JTools/JRange.hh"
40
41#include "Jeep/JMessage.hh"
42
43
44/**
45 * \author mdejong, gmaggi
46 */
47
48namespace JRECONSTRUCTION {}
49namespace JPP { using namespace JRECONSTRUCTION; }
50
51namespace JRECONSTRUCTION {
52
55 using JFIT::JRegressor;
56 using JFIT::JLine3Z;
57 using JFIT::JGandalf;
58
59
60 /**
61 * Wrapper class to make final fit of muon trajectory.
62 *
63 * The JMuonGandalf fit uses one or more start values (usually taken from the output of JMuonSimplex).\n
64 * All hits of which the PMT position lies within a set road width (JMuonGandalfParameters_t::roadWidth_m) and
65 * time is within a set window (JMuonGandalfParameters_t::TMin_ns, JMuonGandalfParameters_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 PDF is accordingly evaluated, i.e.\ the normalised probability for a first hit at the given time of the hit is taken.
69 * The normalisation is consistently based on the specified time window.\n
70 * Note that this hit selection is unbiased with respect to the PDF of a single PMT.
71 */
72 struct JMuonGandalf :
74 public JRegressor<JLine3Z, JGandalf>
75 {
79
80 using JRegressor_t::operator();
81
82 /**
83 * Constructor
84 *
85 * \param parameters parameters
86 * \param router module router
87 * \param summary summary file router
88 * \param pdf_file PDF file
89 * \param debug debug
90 */
92 const JModuleRouter& router,
94 const std::string& pdf_file,
95 const int debug = 0) :
96 JMuonGandalfParameters_t(parameters),
97 JRegressor_t(pdf_file, parameters.TTS_ns),
98 router (router),
100 {
101 using namespace JFIT;
102
103 if (this->getRmax() < roadWidth_m) {
104 roadWidth_m = this->getRmax();
105 }
106
107 JRegressor_t::debug = debug;
108 JRegressor_t::T_ns.setRange(TMin_ns, TMax_ns);
109 JRegressor_t::Vmax_npe = VMax_npe;
110 JRegressor_t::MAXIMUM_ITERATIONS = NMax;
111
112 this->parameters.resize(5);
113
114 this->parameters[0] = JLine3Z::pX();
115 this->parameters[1] = JLine3Z::pY();
116 this->parameters[2] = JLine3Z::pT();
117 this->parameters[3] = JLine3Z::pDX();
118 this->parameters[4] = JLine3Z::pDY();
119 }
120
121
122 /**
123 * Fit function.
124 *
125 * \param event event
126 * \param in start values
127 * \return fit results
128 */
129 JEvt operator()(const KM3NETDAQ::JDAQEvent& event, const JEvt& in)
130 {
131 using namespace std;
132 using namespace JFIT;
133 using namespace JTRIGGER;
134
135 const JBuildL0<hit_type> buildL0;
136
137 buffer_type dataL0;
138
139 buildL0(event, router, true, back_inserter(dataL0));
140
141 return (*this)(dataL0, in);
142 }
143
144
145 /**
146 * Fit function.
147 *
148 * \param data hit data
149 * \param in start values
150 * \return fit results
151 */
152 JEvt operator()(const buffer_type& data, const JEvt& in)
153 {
154 using namespace std;
155 using namespace JFIT;
156 using namespace JGEOMETRY3D;
157
158 JEvt out;
159
160 for (JEvt::const_iterator track = in.begin(); track != in.end(); ++track) {
161
162 const JRotation3D R (getDirection(*track));
163 const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
164 JRange<double> Z_m;
165
166 if (track->hasW(JSTART_LENGTH_METRES) &&
167 track->getW(JSTART_LENGTH_METRES) > 0.0) {
168 Z_m = JZRange(ZMin_m, ZMax_m + track->getW(JSTART_LENGTH_METRES));
169 }
170
171 const JModel<JLine1Z> match(tz, roadWidth_m, JRegressor_t::T_ns, Z_m);
172
173 // hit selection based on start value
174
175 vector<JHitW0> buffer;
176
177 for (buffer_type::const_iterator i = data.begin(); i != data.end(); ++i) {
178
179 JHitW0 hit(*i, summary.getRate(i->getPMTIdentifier()));
180
181 hit.rotate(R);
182
183 if (match(hit)) {
184 buffer.push_back(hit);
185 }
186 }
187
188 // select first hit
189
190 sort(buffer.begin(), buffer.end(), JHitL0::compare);
191
192 vector<JHitW0>::iterator __end = unique(buffer.begin(), buffer.end(), equal_to<JDAQPMTIdentifier>());
193
194
195 const int NDF = distance(buffer.begin(), __end) - this->parameters.size();
196
197 if (NDF > 0) {
198
199 // set fit parameters
200
201 if (track->getE() > 0.1)
202 JRegressor_t::E_GeV = track->getE();
203 else
204 JRegressor_t::E_GeV = this->JMuonGandalfParameters_t::E_GeV;
205
206 const double chi2 = (*this)(JLine3Z(tz), buffer.begin(), __end);
207
208 // check error matrix
209
210 bool status = true;
211
212 for (size_t i = 0; i != this->V.size(); ++i) {
213 if (std::isnan(this->V(i,i)) || this->V(i,i) < 0.0) {
214 status = false;
215 }
216 }
217
218 if (status) {
219
220 JTrack3D tb(this->value);
221
222 tb.rotate_back(R);
223
224 out.push_back(getFit(JHistory(track->getHistory()).add(JMUONGANDALF), tb, getQuality(chi2), NDF));
225
226 // set additional values
227
228 out.rbegin()->setV(this->V.size(), this->V);
229
230 out.rbegin()->setW(track->getW());
231 out.rbegin()->setW(JGANDALF_BETA0_RAD, sqrt(this->error.getDX() * this->error.getDX() +
232 this->error.getDY() * this->error.getDY()));
233 out.rbegin()->setW(JGANDALF_BETA1_RAD, sqrt(this->error.getDX() * this->error.getDY()));
234 out.rbegin()->setW(JGANDALF_CHI2, chi2);
235 out.rbegin()->setW(JGANDALF_NUMBER_OF_HITS, distance(buffer.begin(), __end));
236 out.rbegin()->setW(JGANDALF_LAMBDA, this->lambda);
237 out.rbegin()->setW(JGANDALF_NUMBER_OF_ITERATIONS, this->numberOfIterations);
238 }
239 }
240 }
241
242 return out;
243 }
244
245
248 int debug;
249 };
250}
251
252#endif
253
Auxiliary methods to evaluate Poisson probabilities and chi2.
Energy loss of muon.
Basic data structure for L0 hit.
Data regression method for JFIT::JLine3Z.
General purpose messaging.
Direct access to module in detector data structure.
Auxiliary methods for PDF calculations.
Auxiliary class to define a range between two values.
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.
Fit method based on the Levenberg-Marquardt method.
Data structure for fit of straight line paralel to z-axis.
Definition JLine1Z.hh:29
static parameter_type pY()
Definition JLine1Z.hh:181
static parameter_type pX()
Definition JLine1Z.hh:180
static parameter_type pT()
Definition JLine1Z.hh:182
Data structure for fit of straight line in positive z-direction.
Definition JLine3Z.hh:40
static parameter_type pDY()
Definition JLine3Z.hh:320
static parameter_type pDX()
Definition JLine3Z.hh:319
JAxis3D & rotate_back(const JRotation3D &R)
Rotate back axis.
Definition JAxis3D.hh:240
JAxis3D & rotate(const JRotation3D &R)
Rotate axis.
Definition JAxis3D.hh:225
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Auxiliary class for a hit with background rate value.
Definition JHitW0.hh:23
Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure as a functio...
double getRate() const
Get default rate.
Range of values.
Definition JRange.hh:42
Template L0 hit builder.
Definition JBuildL0.hh:38
Data structure for L0 hit.
Definition JHitL0.hh:31
static const int JMUONGANDALF
static const int JGANDALF_LAMBDA
control parameter from JGandalf.cc
static const int JSTART_LENGTH_METRES
distance between first and last hits in metres from JStart.cc
static const int JGANDALF_BETA0_RAD
KM3NeT Data Definitions v3.4.0-8-ge14cb17 https://git.km3net.de/common/km3net-dataformat.
static const int JGANDALF_NUMBER_OF_ITERATIONS
number of iterations from JGandalf.cc
static const int JGANDALF_BETA1_RAD
angular resolution [rad] from JGandalf.cc
static const int JGANDALF_NUMBER_OF_HITS
number of hits from JGandalf.cc
static const int JGANDALF_CHI2
chi2 from JGandalf.cc
Auxiliary classes and methods for linear and iterative data regression.
Definition JEnergy.hh:15
JTOOLS::JRange< double > JZRange
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:354
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.
Model for fit to acoustics data.
JHistory & add(const int type)
Add event to history.
Definition JHistory.hh:295
Template definition of a data regressor of given model.
Definition JRegressor.hh:70
double TMin_ns
minimal time w.r.t. Cherenkov hypothesis [ns]
double TMax_ns
maximal time w.r.t. Cherenkov hypothesis [ns]
double VMax_npe
maximum number of of photo-electrons
Wrapper class to make final fit of muon trajectory.
JEvt operator()(const buffer_type &data, const JEvt &in)
Fit function.
std::vector< hit_type > buffer_type
JEvt operator()(const KM3NETDAQ::JDAQEvent &event, const JEvt &in)
Fit function.
const JModuleRouter & router
JRegressor< JLine3Z, JGandalf > JRegressor_t
JMuonGandalf(const JMuonGandalfParameters_t &parameters, const JModuleRouter &router, const JSummaryRouter &summary, const std::string &pdf_file, const int debug=0)
Constructor.
const JSummaryRouter & summary
Auxiliary data structure for sorting of hits.
Definition JHitL0.hh:85