Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JShowerFit.hh
Go to the documentation of this file.
1#ifndef JSHOWERFIT_INCLUDE
2#define JSHOWERFIT_INCLUDE
3
4#include <string>
5#include <iostream>
6#include <set>
7#include <vector>
8#include <algorithm>
9#include <memory>
10
13
14#include "JTrigger/JHit.hh"
16#include "JTrigger/JHitL0.hh"
17#include "JTrigger/JHitL1.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
26
28#include "JFit/JFitToolkit.hh"
29#include "JFit/JPoint4D.hh"
30#include "JFit/JModel.hh"
31#include "JFit/JGandalf.hh"
32
34
41
44
46
53
55
56
57/**
58 * \author adomi
59 */
60namespace JRECONSTRUCTION {}
61namespace JPP { using namespace JRECONSTRUCTION; }
62
63namespace JRECONSTRUCTION {
64
71 using JFIT::JRegressor;
72 using JFIT::JEnergy;
73 using JFIT::JShower3EZ;
74 using JFIT::JGandalf;
75 /**
76 * class to handle the direction fit of the shower reconstruction, mainly dedicated for ORCA
77 */
78 class JShowerFit :
80 public JRegressor<JShower3EZ, JGandalf>
81 {
82
86 using JRegressor_t::operator();
87
88 public:
89
90
91 /**
92 * Input data type.
93 */
94 struct input_type :
95 public JDAQEventHeader
96 {
97 /**
98 * Default constructor.
99 */
101 {}
102
103
104 /**
105 * Constructor.
106 *
107 * \param header header
108 * \param in start values
109 * \param coverage coverage
110 */
112 const JEvt& in,
113 const coverage_type& coverage) :
114 JDAQEventHeader(header),
115 in(in),
117 {}
118
122 };
123
124 /**
125 * Parameterized constructor
126 *
127 * \param parameters struct that holds default-optimized parameters for the reconstruction, available in $JPP_DATA.
128 * \param storage storage
129 * \param correct energy correction
130 * \param debug debug
131 */
133 const storage_type& storage,
135 const int debug = 0):
136 JShowerFitParameters_t(parameters),
137 JRegressor_t(storage),
139 {
140 using namespace JPP;
141
142 JRegressor_t::debug = debug;
143 JRegressor_t::T_ns.setRange(parameters.TMin_ns, parameters.TMax_ns);
144 JRegressor_t::Vmax_npe = parameters.Vmax_npe;
145 JRegressor_t::MAXIMUM_ITERATIONS = 1000;
146 JRegressor_t::EPSILON = 1e-3;
147 JRegressor_t::EPSILON_ABSOLUTE = true;
148
149 this->parameters.resize(3);
150
151 this->parameters[0] = JShower3EZ::pDX();
152 this->parameters[1] = JShower3EZ::pDY();
153 this->parameters[2] = JShower3EZ::pE();
154
155 this->estimator.reset(getMEstimator(parameters.mestimator));
156 }
157
158 /**
159 * Get input data.
160 *
161 * \param router module router
162 * \param summary summary data
163 * \param event event
164 * \param in start values
165 * \param coverage coverage
166 * \return input data
167 */
169 const JSummaryRouter& summary,
170 const JDAQEvent& event,
171 const JEvt& in,
172 const coverage_type& coverage)
173 {
174 using namespace std;
175 using namespace JTRIGGER;
176
177 input_type input(event.getDAQEventHeader(), in, coverage);
178
179 const JBuildL0 <JHitR0> buildL0;
181
182 const JDAQTimeslice timeslice(event, true);
183
184 JSuperFrame2D<JHit> buffer;
185
186 for (JDAQTimeslice::const_iterator i = timeslice.begin(); i != timeslice.end(); ++i) {
187
188 if (router.hasModule(i->getModuleID())) {
189
190 buffer(*i, router.getModule(i->getModuleID()));
191
192 buildL0(buffer, back_inserter(data[i->getModuleID()]));
193 }
194 }
195
196 for (const auto& module : router.getReference()) {
197 if (!module.empty()) {
198 input.data.push_back(module_type(module, summary.getSummaryFrame(module.getID()), data[module.getID()]));
199 }
200 }
201
202 return input;
203 }
204
205 /**
206 * Fit function.
207 *
208 * \param input input data
209 * \return fit results
210 */
212 {
213 using namespace std;
214 using namespace JPP;
215
217
218 JEvt out;
219
220 JEvt in = input.in;
221
223
224 if (!in.empty()) {
225 in.select(JHistory::is_event(in.begin()->getHistory()));
226 }
227
228 for (JEvt::const_iterator shower = in.begin(); shower != in.end(); ++shower) {
229
230 vector<JPMTW0> data;
231
232 const JPosition3D vertex(getPosition(*shower));
233 const double time = shower->getT();
234 const double distance = DMax_m + DStep_m * log10(shower->getE());
235 const JRotation3D R(getDirection(*shower));
236
237 for (const auto& module : input.data) {
238
239 JPosition3D pos(module->getPosition());
240 pos.sub(vertex);
241
242 if(pos.getLength() < distance){
243
244 for (size_t i = 0; i != module->size(); ++i) {
245 if (module.getStatus(i)) {
246
247 const double t1 = time + pos.getLength() * getInverseSpeedOfLight() * getIndexOfRefraction();
248
249 struct {
250
251 bool operator()(const JHitR0& hit) const
252 {
253 return (hit.getPMT() == pmt && T_ns(hit.getT()));
254 }
255
256 const JTimeRange T_ns;
257 const size_t pmt;
258
259 } match = { JRegressor_t::T_ns + t1, i };
260
261 JPMT pmt = module->getPMT(i);
262 pmt.sub(vertex);
263 pmt.rotate(R);
264
265 data.push_back(JPMTW0(pmt, module.frame.getRate(i), count_if(module.begin(), module.end(), match)));
266 }
267 }
268 }
269 }
270
271
272 double chi2 = (*this)(JShower3EZ(JVertex3D(JVector3D(0,0,0), shower->getT()), JVersor3Z(),
273 shower->getE()), data.begin(), data.end());
274
275 double NDF = getCount(data.begin(), data.end()) - this->parameters.size();
276
277 JShower3E sh_fit(this->value.getPosition(), this->value.getDirection(),
278 this->value.getT(), correct(this->value.getE()));
279
280 // check error matrix
281 bool status = true;
282
283 for (size_t i = 0; i != this->V.size(); ++i) {
284 if (std::isnan(this->V(i,i)) || this->V(i,i) < 0.0) {
285 status = false;
286 }
287 }
288
289 if (status) {
290 sh_fit.rotate_back(R);
291
292 sh_fit.add(vertex.getPosition());
293
294 out.push_back(getFit(JHistory(shower->getHistory()).add(JSHOWERCOMPLETEFIT), sh_fit, getQuality(chi2),
295 NDF, sh_fit.getE()));
296 out.rbegin()->setV(this->V.size(), this->V);
297 out.rbegin()->setW(JSHOWERFIT_ENERGY, this->value.getE()); // Uncorrected Energy
298 out.rbegin()->setW(JPP_COVERAGE_ORIENTATION, input.coverage.orientation);
299 out.rbegin()->setW(JPP_COVERAGE_POSITION, input.coverage.position);
300 }
301 }
302
303 // apply default sorter
304
305 sort(out.begin(), out.end(), qualitySorter);
306
307 copy(input.in.begin(), input.in.end(), back_inserter(out));
308
309 return out;
310 }
311
313 };
314}
315
316#endif
317
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
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.
Auxiliary methods to evaluate Poisson probabilities and chi2.
Basic data structure for L0 hit.
Basic data structure for L1 hit.
Reduced data structure for L1 hit.
Match operator for Cherenkov light from shower in any direction.
int debug
debug level
Definition JSirene.cc:72
Data regression method for JFIT::JShower3EZ.
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.
bool hasModule(const JObjectID &id) const
Has module.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for PMT geometry, calibration and status.
Definition JPMT.hh:49
Data structure for fit of energy.
Definition JEnergy.hh:31
Data structure for set of track fit results.
void select(const JSelector_t &selector)
Select fits.
Fit method based on the Levenberg-Marquardt method.
Definition JGandalf.hh:87
Data structure for fit of straight line in positive z-direction with energy.
Definition JShower3EZ.hh:30
static parameter_type pE()
static parameter_type pDY()
Definition JShower3Z.hh:172
static parameter_type pDX()
Definition JShower3Z.hh:171
Auxiliary class for correction of energy determined by JShowerEnergy.cc.
JAxis3D & rotate_back(const JRotation3D &R)
Rotate back axis.
Definition JAxis3D.hh:240
JAxis3D & rotate(const JRotation3D &R)
Rotate axis.
Definition JAxis3D.hh:225
Data structure for position in three dimensions.
const JPosition3D & getPosition() const
Get position.
JTime & add(const JTime &value)
Addition operator.
3D track with energy.
Definition JTrack3E.hh:32
double getE() const
Get energy.
Definition JTrack3E.hh:93
Data structure for vector in three dimensions.
Definition JVector3D.hh:36
double getLength() const
Get length.
Definition JVector3D.hh:246
JVector3D & sub(const JVector3D &vector)
Subtract vector.
Definition JVector3D.hh:158
Data structure for normalised vector in positive z-direction.
Definition JVersor3Z.hh:41
const JClass_t & getReference() const
Get reference to object.
Definition JReference.hh:38
class to handle the direction fit of the shower reconstruction, mainly dedicated for ORCA
Definition JShowerFit.hh:81
JEvt operator()(const input_type &input)
Fit function.
input_type getInput(const JModuleRouter &router, const JSummaryRouter &summary, const JDAQEvent &event, const JEvt &in, const coverage_type &coverage)
Get input data.
std::vector< module_type > detector_type
Definition JShowerFit.hh:85
JRegressor< JShower3EZ, JGandalf > JRegressor_t
Definition JShowerFit.hh:83
JShowerFit(const JShowerFitParameters_t &parameters, const storage_type &storage, const JShowerEnergyCorrection &correct, const int debug=0)
Parameterized constructor.
const JShowerEnergyCorrection & correct
Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure as a functio...
const JDAQSummaryFrame & getSummaryFrame() const
Get default summary frame.
Reduced data structure for L0 hit.
Definition JHitR0.hh:27
JPMT_t getPMT() const
Get PMT.
Definition JHitR0.hh:60
double getT() const
Get calibrated time of hit.
2-dimensional frame with time calibrated data from one optical module.
const JDAQEventHeader & getDAQEventHeader() const
Get DAQ event header.
Data storage class for rate measurements of all PMTs in one module.
static const int JSHOWERDIRECTIONPREFIT
static const int JSHOWERCOMPLETEFIT
static const int JPP_COVERAGE_POSITION
coverage of dynamic position calibration from any Jpp application
static const int JSHOWERFIT_ENERGY
uncorrected energy [GeV] from JShowerFit.cc
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
size_t getCount(const array_type< T > &buffer, const JCompare_t &compare)
Count number of unique values.
double getIndexOfRefraction()
Get average index of refraction of water corresponding to group velocity.
const double getInverseSpeedOfLight()
Get inverse speed of light.
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:405
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.
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
Auxiliary class to test history.
Definition JHistory.hh:136
JHistory & add(const int type)
Add event to history.
Definition JHistory.hh:346
Auxiliary class for handling PMT geometry, rate and response.
Definition JPMTW0.hh:24
Template definition of a data regressor of given model.
Definition JRegressor.hh:70
Auxiliary class for handling module response.
Definition JModuleL0.hh:45
Data structure for fit parameters.
double Vmax_npe
maximum number of of photo-electrons
double DMax_m
maximal distance to optical module [m]
double TMax_ns
maximum time for local coincidences [ns]
double TMin_ns
minimum time for local coincidences [ns]
double DStep_m
step increase for the distance to optical module [m]
input_type(const JDAQEventHeader &header, const JEvt &in, const coverage_type &coverage)
Constructor.