Jpp master_rocky-44-g75b7c4f75
the software that should make you happy
Loading...
Searching...
No Matches
JShowerDirectionPrefit.hh
Go to the documentation of this file.
1#ifndef JSHOWERDIRECTIONPREFIT_INCLUDE
2#define JSHOWERDIRECTIONPREFIT_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
33
37
40
41#include "JPhysics/KM3NeT.hh"
42
49
51
52/**
53 * \author adomi, vcarretero
54 */
55namespace JRECONSTRUCTION {}
56namespace JPP { using namespace JRECONSTRUCTION; }
57
58namespace JRECONSTRUCTION {
59
62 using JFIT::JRegressor;
63 using JFIT::JEnergy;
64 using JFIT::JShower3EZ;
66
67 /**
68 * class to handle the direction fit of the shower reconstruction, mainly dedicated for ORCA
69 */
72 public JRegressor<JShower3EZ, JAbstractMinimiser>
73 {
74
76 using JRegressor_t::operator();
79
80 public:
81
82 /**
83 * Parameterized constructor
84 *
85 * \param parameters struct that holds default-optimized parameters for the reconstruction, available in $JPP_DATA.
86 * \param router module router, this is built via detector file.
87 * \param summary summary router
88 * \param pdfFile PDF file
89 * \param debug debug
90 */
92 const JModuleRouter& router,
94 const std::string pdfFile,
95 const int debug = 0):
97 JRegressor_t(pdfFile),
98 omega(parameters.scanAngle_deg * JMATH::PI / 180.0),
101 {
102 using namespace JPP;
103
104 JRegressor_t::debug = debug;
105 JRegressor_t::T_ns.setRange(parameters.TMin_ns, parameters.TMax_ns);
106 JRegressor_t::Vmax_npe = VMax_npe;
107
108 if (Emin_GeV > Emax_GeV || En <= 1) {
109 THROW(JException, "Invalid energy input " << Emin_GeV << ' ' << Emax_GeV << ' ' << En);
110 }
111
112 const double base = std::pow((Emax_GeV / Emin_GeV), 1.0 / (En - 1));
113
114 for (int i = 0; i != En; ++i) {
115 Ev.push_back(Emin_GeV * std::pow(base, i));
116 }
117 }
118
119 /**
120 * Declaration of the member function that actually performs the reconstruction
121 *
122 * \param event DAQ event
123 * \param in input fits
124 * \return result fits
125 */
127 {
128 using namespace std;
129 using namespace JPP;
130
131 typedef vector<JHitL0> JDataL0_t;
132 JBuildL0<JHitL0> buildL0;
133
134 JEvt out;
135
137
138 JDataL0_t dataL0;
139
140 buildL0(JDAQTimeslice(event, true), router, back_inserter(dataL0));
141
142 for (JEvt::const_iterator shower = in.begin(); shower != in.end(); ++shower) {
143
144 const JVertex3D Vertex(getPosition(*shower),shower->getT());
146
147 const JFIT::JModel<JPoint4D> match(Vertex, DMax_m, JRegressor_t::T_ns);
148
149 for (JDataL0_t::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
150 if (match(*i)) {
151 top.insert(i->getPMTIdentifier());
152 }
153 }
154
155 const JDetectorSubset_t subdetector(detector, Vertex.getPosition(), DMax_m);
156
157 vector<JPMTW0> data;
158 for (JDetectorSubset_t::const_iterator module = subdetector.begin(); module != subdetector.end(); ++module) {
159 const JDAQSummaryFrame& frame = summary.getSummaryFrame(module->getID());
160
161 JModule dom(*module);
162
163 for (size_t i = 0; i != dom.size(); ++i) {
164
165 if (getDAQStatus(frame, *module, i) &&
166 getPMTStatus(frame, *module, i) &&
167 frame[i].is_valid() &&
168 !module->getPMT(i).has(PMT_DISABLE)) {
169
170 const JDAQPMTIdentifier id(module->getID(), i);
171
172 const double rate_Hz = summary.getRate(id);
173 const size_t count = top.count(id);
174
175 data.push_back(JPMTW0(dom.getPMT(i), rate_Hz, count));
176 }
177 }
178 }
179
180 const JShower3EZ sh(JVertex3D(JVector3D(0,0,0), sh.getT()), JVersor3Z(), 1);
181
182 for (JOmega3D_t::const_iterator dir = omega.begin(); dir != omega.end(); ++dir) {
183 const JRotation3D R(*dir);
184 vector<double> chi2v(En, 0.0);
185 for (vector<JPMTW0>::const_iterator i = data.begin(); i != data.end(); ++i) {
186 JPMTW0 pmt = *i;
187 pmt.rotate(R);
188 JNPE_t::result_type H1 = (*this).getH1(sh, pmt);
189 JNPE_t::result_type H0 = (*this).getH0(pmt.getR()); // getH0 = Get background hypothesis value for time integrated PDF.
190 const bool hit = pmt.getN() != 0;
191 for(size_t j=0;j!=chi2v.size();++j){
192 chi2v[j]+= getChi2(get_value(H0+Ev[j]*H1), hit); // H1 is linear with E
193 }
194 }
195 //Store only the lowest chi2 for a given direction
196 auto minChi2 = std::min_element(chi2v.begin(), chi2v.end());
197 JShower3E sh_fit(Vertex, JDirection3D(*dir), Ev[minChi2-chi2v.begin()]);
198 out.push_back(getFit(JHistory(shower->getHistory()).add(JSHOWERDIRECTIONPREFIT), sh_fit, getQuality(*minChi2), data.size(), sh_fit.getE()));
199 }
200 }
201
202 return out;
203
204 }
207 };
208}
209
210#endif
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
Algorithms for hit clustering and sorting.
Auxiliary class to extract a subset of optical modules from a detector.
Data structure for detector geometry and calibration.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
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:69
Data regression method for JFIT::JShower3EZ.
Basic data structure for time and time over threshold information of hit.
Properties of KM3NeT PMT and deep-sea water.
Detector subset without binary search functionality.
Detector data structure.
Definition JDetector.hh:96
Router for direct addressing of module data in detector data structure.
Data structure for a composite optical module.
Definition JModule.hh:75
const JPMT & getPMT(const int index) const
Get PMT.
Definition JModule.hh:172
Data structure for fit of energy.
Definition JEnergy.hh:31
Data structure for set of track fit results.
Data structure for fit of straight line in positive z-direction with energy.
Definition JShower3EZ.hh:30
JAxis3D & rotate(const JRotation3D &R)
Rotate axis.
Definition JAxis3D.hh:225
Data structure for direction in three dimensions.
Direction set covering (part of) solid angle.
Definition JOmega3D.hh:68
const JPosition3D & getPosition() const
Get position.
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
Data structure for normalised vector in positive z-direction.
Definition JVersor3Z.hh:41
General exception.
Definition JException.hh:24
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
JEvt operator()(const KM3NETDAQ::JDAQEvent &event, const JFIT::JEvt &in)
Declaration of the member function that actually performs the reconstruction.
JShowerDirectionPrefit(const JShowerDirectionPrefitParameters_t &parameters, const JModuleRouter &router, const JSummaryRouter &summary, const std::string pdfFile, const int debug=0)
Parameterized constructor.
JRegressor< JShower3EZ, JAbstractMinimiser > JRegressor_t
Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure as a functio...
double getRate() const
Get default rate.
const JDAQSummaryFrame & getSummaryFrame() const
Get default summary frame.
Template L0 hit builder.
Definition JBuildL0.hh:38
Data storage class for rate measurements of all PMTs in one module.
static const int JSHOWERDIRECTIONPREFIT
double getChi2(const double P)
Get chi2 corresponding to given probability.
Auxiliary classes and methods for mathematical operations.
Definition JEigen3D.hh:88
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.
bool is_valid(const json &js)
Check validity of JSon data.
if((p==this->begin() &&this->getDistance(x,(p++) ->getX()) > distance_type::precision)||(p==this->end() &&this->getDistance((--p) ->getX(), x) > distance_type::precision))
Template base class for polynomial interpolations with polynomial result.
Definition JPolint.hh:770
int j
Definition JPolint.hh:792
JResultEvaluator< JResult_t >::result_type get_value(const JResult_t &value)
Helper method to recursively evaluate a to function value.
Definition JResult.hh:998
bool getDAQStatus(const JDAQFrameStatus &frame, const JStatus &status)
Test status of DAQ.
bool getPMTStatus(const JStatus &status)
Test status of PMT.
static const int PMT_DISABLE
KM3NeT Data Definitions v3.4.0-8-ge14cb17 https://git.km3net.de/common/km3net-dataformat.
Definition pmt_status.hh:12
Detector file.
Definition JHead.hh:227
JHistory & add(const int type)
Add event to history.
Definition JHistory.hh:295
Auxiliary class to match data points with given model.
Auxiliary class for handling PMT geometry, rate and response.
Definition JPMTW0.hh:24
int getN() const
Get number of hits.
Definition JPMTW0.hh:67
double getR() const
Get rate.
Definition JPMTW0.hh:56
Template definition of a data regressor of given model.
Definition JRegressor.hh:70