Jpp  debug
the software that should make you happy
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"
15 #include "JTrigger/JTimeslice.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"
21 #include "JTrigger/JAlgorithm.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 
33 #include "JAAnet/JAAnetToolkit.hh"
34 
36 #include "JReconstruction/JEvt.hh"
40 
41 #include "JDetector/JDetector.hh"
43 
44 #include "JGeometry3D/JVector3D.hh"
46 #include "JGeometry3D/JOmega3D.hh"
47 #include "JGeometry3D/JTrack3D.hh"
48 #include "JGeometry3D/JTrack3E.hh"
49 #include "JGeometry3D/JShower3E.hh"
50 
51 #include "JLang/JSharedPointer.hh"
52 
53 
54 /**
55  * \author adomi
56  */
57 namespace JRECONSTRUCTION {}
58 namespace JPP { using namespace JRECONSTRUCTION; }
59 
60 namespace JRECONSTRUCTION {
61 
65  using JFIT::JRegressor;
66  using JFIT::JEnergy;
67  using JFIT::JShower3EZ;
68  using JFIT::JGandalf;
69  /**
70  * class to handle the direction fit of the shower reconstruction, mainly dedicated for ORCA
71  */
72  class JShowerFit :
74  public JRegressor<JShower3EZ, JGandalf>
75  {
76 
78  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 correct energy correction
90  * \param debug debug
91  */
93  const JModuleRouter& router,
94  const JSummaryRouter& summary,
95  const std::string pdfFile,
97  const int debug = 0):
98  JShowerFitParameters_t(parameters),
99  JRegressor_t(pdfFile),
100  router(router),
101  summary(summary),
103  {
104  using namespace JPP;
105 
107  JRegressor_t::T_ns.setRange(parameters.TMin_ns, parameters.TMax_ns);
108  JRegressor_t::Vmax_npe = parameters.Vmax_npe;
109  JRegressor_t::MAXIMUM_ITERATIONS = 1000;
110  JRegressor_t::EPSILON = 1e-3;
111  JRegressor_t::EPSILON_ABSOLUTE = true;
112 
113  this->parameters.resize(3);
114 
115  this->parameters[0] = JShower3EZ::pDX();
116  this->parameters[1] = JShower3EZ::pDY();
117  this->parameters[2] = JShower3EZ::pE();
118 
119  this->estimator.reset(getMEstimator(parameters.mestimator));
120  }
121 
122  /**
123  * Declaration of the member function that actually performs the reconstruction
124  *
125  * \param event = JDAQEvent
126  * \param in = input fits
127  */
128  JEvt operator()(const KM3NETDAQ::JDAQEvent& event, const JFIT::JEvt &in)
129  {
130  using namespace std;
131  using namespace JPP;
132 
133  typedef vector<JHitL0> JDataL0_t;
134  JBuildL0<JHitL0> buildL0;
135 
136  JEvt out;
137 
139 
140  JDataL0_t dataL0;
141 
142  buildL0(JDAQTimeslice(event, true), router, back_inserter(dataL0));
143 
144  for (JEvt::const_iterator shower = in.begin(); shower != in.end(); ++shower) {
145 
146  const JVertex3D Vertex(getPosition(*shower), shower->getT());
147 
149 
150  const double distance = DMax_m + DStep_m * log10(shower->getE());
151 
152  const JFIT::JModel<JPoint4D> match(Vertex, distance, JRegressor_t::T_ns);
153 
154  for (JDataL0_t::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
155  if (match(*i)) {
156  top.insert(i->getPMTIdentifier());
157  }
158  }
159 
160  const JDetectorSubset_t subdetector(detector, Vertex.getPosition(), distance);
161 
162  const JRotation3D R(getDirection(*shower));
163 
164  vector<JPMTW0> buffer;
165 
166  for (JDetectorSubset_t::const_iterator module = subdetector.begin();
167  module != subdetector.end(); ++module) {
168 
169  const JDAQSummaryFrame& frame = summary.getSummaryFrame(module->getID());
170 
171  JModule dom(*module);
172 
173  dom.rotate(R);
174 
175  for (size_t i = 0; i != dom.size(); ++i) {
176 
177  if (getDAQStatus(frame, *module, i) &&
178  getPMTStatus(frame, *module, i) &&
179  frame[i].is_valid() &&
180  !module->getPMT(i).has(PMT_DISABLE)) {
181  const JDAQPMTIdentifier id(module->getID(), i);
182 
183  const double rate_Hz = summary.getRate(id);
184  const size_t count = top.count(id);
185 
186  buffer.push_back(JPMTW0(dom.getPMT(i), rate_Hz, count));
187  }
188  }
189  }
190 
191  double chi2 = (*this)(JShower3EZ(JVertex3D(JVector3D(0,0,0), shower->getT()), JVersor3Z(),
192  shower->getE()), buffer.begin(), buffer.end());
193 
194  double NDF = getCount(buffer.begin(), buffer.end()) - this->parameters.size();
195 
196  JShower3E sh_fit(this->value.getPosition(), this->value.getDirection(),
197  this->value.getT(), correct(this->value.getE()));
198 
199  sh_fit.rotate_back(R);
200 
201  sh_fit.add(Vertex.getPosition());
202 
203  out.push_back(getFit(JHistory(shower->getHistory()).add(JSHOWERCOMPLETEFIT), sh_fit, getQuality(chi2),
204  NDF, sh_fit.getE()));
205  out.rbegin()->setV(this->V.size(), this->V);
206  out.rbegin()->setW(JSHOWERFIT_ENERGY, this->value.getE()); // Uncorrected Energy
207  }
208 
209  return out;
210  }
211 
215  };
216 }
217 
218 #endif
219 
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.
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.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
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
void rotate(const JRotation3D &R)
Rotate module.
Definition: JModule.hh:314
Data structure for fit of energy.
Definition: JEnergy.hh:31
Data structure for set of track fit results.
Fit method based on the Levenberg-Marquardt method.
Definition: JGandalf.hh:86
Data structure for fit of straight line in positive z-direction with energy.
Definition: JShower3EZ.hh:30
static parameter_type pE()
Definition: JShower3EZ.hh:205
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
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
Rotation matrix.
Definition: JRotation3D.hh:114
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
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:75
JRegressor< JShower3EZ, JGandalf > JRegressor_t
Definition: JShowerFit.hh:77
const JSummaryRouter & summary
Definition: JShowerFit.hh:213
JEvt operator()(const KM3NETDAQ::JDAQEvent &event, const JFIT::JEvt &in)
Declaration of the member function that actually performs the reconstruction.
Definition: JShowerFit.hh:128
JShowerFit(const JShowerFitParameters_t &parameters, const JModuleRouter &router, const JSummaryRouter &summary, const std::string pdfFile, const JShowerEnergyCorrection &correct, const int debug=0)
Parameterized constructor.
Definition: JShowerFit.hh:92
const JShowerEnergyCorrection & correct
Definition: JShowerFit.hh:214
const JModuleRouter & router
Definition: JShowerFit.hh:212
Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure as a functio...
const JDAQSummaryFrame & getSummaryFrame() const
Get default summary frame.
double getRate() const
Get default rate.
Template specialisation of L0 builder for JHitL0 data type.
Definition: JBuildL0.hh:105
Data storage class for rate measurements of all PMTs in one module.
static const int JSHOWERCOMPLETEFIT
static const int JSHOWERFIT_ENERGY
uncorrected energy [GeV] from JShowerFit.cc
JDirection3D getDirection(const Vec &dir)
Get direction.
JPosition3D getPosition(const Vec &pos)
Get position.
double getQuality(const double chi2, const int NDF)
Get quality of fit.
JFit getFit(const int id, const JMODEL::JString &string)
Get fit parameters of string.
JMEstimator * getMEstimator(const int type)
Get M-Estimator.
Definition: JMEstimator.hh:203
size_t getCount(const array_type< T > &buffer, const JCompare_t &compare)
Count number of unique values.
Definition: JVectorize.hh:261
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Model fits to data.
JFIT::JHistory JHistory
Definition: JHistory.hh:354
bool is_valid(const json &js)
Check validity of JSon data.
bool getDAQStatus(const JDAQFrameStatus &frame, const JStatus &status)
Test status of DAQ.
bool getPMTStatus(const JStatus &status)
Test status of PMT.
Definition: JSTDTypes.hh:14
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
Template specialisation of class JModel to match hit with bright point.
Definition: JFit/JModel.hh:123
Auxiliary class for handling PMT geometry, rate and response.
Definition: JPMTW0.hh:24
Regressor function object for JShower3EZ fit using JGandalf minimiser.
Template definition of a data regressor of given model.
Definition: JRegressor.hh:70
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]