Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JShowerPositionFit.hh
Go to the documentation of this file.
1 #ifndef JSHOWERPOSITIONFIT_INCLUDE
2 #define JSHOWERPOSITIONFIT_INCLUDE
3 
4 #include <string>
5 #include <iostream>
6 #include <set>
7 #include <vector>
8 #include <algorithm>
9 #include <memory>
10 #include <math.h>
11 
14 
15 #include "JTrigger/JHit.hh"
16 #include "JTrigger/JTimeslice.hh"
17 #include "JTrigger/JHitL0.hh"
18 #include "JTrigger/JHitL1.hh"
19 #include "JTrigger/JHitR1.hh"
20 #include "JTrigger/JBuildL0.hh"
21 #include "JTrigger/JBuildL2.hh"
22 #include "JTrigger/JAlgorithm.hh"
23 #include "JTrigger/JMatch3G.hh"
24 #include "JTrigger/JBind2nd.hh"
25 
27 
28 #include "JFit/JFitToolkit.hh"
29 #include "JFit/JEstimator.hh"
30 #include "JFit/JPoint4D.hh"
31 #include "JFit/JModel.hh"
32 #include "JFit/JSimplex.hh"
34 
36 #include "JReconstruction/JEvt.hh"
39 
40 #include "JGeometry3D/JVector3D.hh"
41 #include "JGeometry3D/JShower3D.hh"
42 #include "JGeometry3D/JShower3E.hh"
43 #include "JGeometry3D/JTrack3D.hh"
44 #include "JGeometry3D/JTrack3E.hh"
46 
48 #include "JDetector/JDetector.hh"
50 
51 #include "JTools/JPermutation.hh"
52 #include "JTools/JRange.hh"
53 #include "JLang/JSharedPointer.hh"
54 
55 /**
56  * \author adomi
57  */
58 namespace JRECONSTRUCTION {}
59 namespace JPP { using namespace JRECONSTRUCTION; }
60 
61 namespace JRECONSTRUCTION {
62 
65  using JFIT::JPoint4D;
66  using JFIT::JGandalf;
67  using JFIT::JRegressor;
68 
69  /**
70  * class to handle the second position fit of the shower reconstruction, mainly dedicated for ORCA
71  */
73 
75  public JRegressor<JPoint4D, JGandalf>
76 
77  {
78 
80  using JRegressor_t::operator();
81 
82  public:
83 
84  /**
85  * Parameterized constructor
86  *
87  * \param parameters struct that holds default-optimized parameters for the reconstruction
88  * \param router module router, this is built via detector file.
89  * \param summary summary router
90  * \param pdfFile file name with PDF
91  * \param debug debug
92  */
94  const JModuleRouter& router,
95  const JSummaryRouter& summary,
96  const std::string pdfFile,
97  const int debug = 0):
99  JRegressor_t(pdfFile, parameters.TTS_ns),
100  router(router),
101  summary(summary)
102  {
103  using namespace JPP;
104 
106  JRegressor_t::T_ns.setRange(parameters.TMin_ns, parameters.TMax_ns);
107  JRegressor_t::Vmax_npe = 20.0;
109 
110  this->parameters.resize(4);
111 
112  this->parameters[0] = JPoint4D::pX();
113  this->parameters[1] = JPoint4D::pY();
114  this->parameters[2] = JPoint4D::pZ();
115  this->parameters[3] = JPoint4D::pT();
116  }
117 
118  /**
119  * Declaration of the member function that actually performs the reconstruction
120  *
121  * \param event which is a JDAQEvent
122  * \param in input fits
123  */
125  {
126  using namespace std;
127  using namespace JPP;
128 
129  typedef vector<JHitL0> JDataL0_t;
130  const JBuildL0<JHitL0> buildL0;
131 
132  JEvt out;
133 
134  JDataL0_t dataL0;
135  buildL0(JDAQTimeslice(event, true), router, back_inserter(dataL0));
136 
137  for (JEvt::const_iterator shower = in.begin(); shower != in.end(); ++shower) {
138 
139  JPoint4D vx(getPosition(*shower), shower->getT());
140 
141  vector<JHitW0> data;
142 
144 
145  for (JDataL0_t::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
146 
147  const double rate_Hz = summary.getRate(*i);
148 
149  if (match(*i)) {
150  data.push_back(JHitW0(*i, rate_Hz));
151  }
152  }
153 
154  // select first hit
155 
156  sort(data.begin(), data.end(), compare);
157 
158  vector<JHitW0>::iterator __end = unique(data.begin(), data.end(), equal_to<JDAQPMTIdentifier>());
159 
160  const int NDF = distance(data.begin(), __end) - this->parameters.size();
161 
162  if (NDF > 0) {
163 
164  // set fit parameters
165 
166  if (shower->getE() > 0.1)
167  JRegressor_t::E_GeV = shower->getE();
168  else
170 
171  double chi2 = (*this)(vx, data.begin(), __end);
172 
173  JShower3E sh_fit(this->value.getPosition(), JDirection3D(),
174  this->value.getT(), shower->getE());
175 
176  out.push_back(getFit(JHistory(shower->getHistory()).add(JSHOWERPOSITIONFIT), sh_fit,
177  getQuality(chi2), NDF, sh_fit.getE()));
178 
179  }
180  }
181 
182  return out;
183  }
184 
185  /**
186  * Auxiliary data structure for sorting of hits.
187  */
188  static const struct {
189  /**
190  * Compare hits by PMT identifier and time.
191  *
192  * \param first first hit
193  * \param second second hit
194  * \return true if first before second; else false
195  */
196  template<class T>
197  bool operator()(const T& first, const T& second) const
198  {
199  using namespace std;
200  using namespace JPP;
201  using namespace KM3NETDAQ;
202 
203  if (equal_to<JDAQPMTIdentifier>()(first, second))
204  return less<JHit>()(first, second);
205  else
206  return less<JDAQPMTIdentifier>()(first, second);
207  }
208  } compare;
209 
212  };
213 }
214 
215 #endif
216 
Auxiliary methods to evaluate Poisson probabilities and chi2.
static int debug
debug level (default is off).
Definition: JMessage.hh:45
Template definition of a data regressor of given model.
Definition: JRegressor.hh:68
Linear fit methods.
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:33
double getQuality(const double chi2, const int NDF)
Get quality of fit.
Algorithms for hit clustering and sorting.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Template specialisation of L0 builder for JHitL0 data type.
Definition: JBuildL0.hh:102
Data structure for vertex fit.
Definition: JPoint4D.hh:22
Router for direct addressing of module data in detector data structure.
static parameter_type pT()
Definition: JPoint4D.hh:61
double getRate() const
Get default rate.
JRegressor< JPoint4D, JGandalf > JRegressor_t
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
class to handle the second position fit of the shower reconstruction, mainly dedicated for ORCA ...
Basic data structure for time and time over threshold information of hit.
static parameter_type pZ()
Definition: JPoint4D.hh:60
JEvt operator()(const KM3NETDAQ::JDAQEvent &event, const JFIT::JEvt &in)
Declaration of the member function that actually performs the reconstruction.
3D track with energy.
Definition: JTrack3E.hh:30
Data structure for detector geometry and calibration.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
Regressor function object for JPoint4D fit using JGandalf minimiser.
static const int JSHOWERPOSITIONFIT
Basic data structure for L0 hit.
Auxiliary class to extract a subset of optical modules from a detector.
static struct JRECONSTRUCTION::JShowerPositionFit::@58 compare
Auxiliary data structure for sorting of hits.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
JPosition3D getPosition(const Vec &pos)
Get position.
Data time slice.
int debug
debug level
Definition: JSirene.cc:63
Router for fast addressing of summary data in JDAQSummaryslice data structure as a function of the op...
static parameter_type pX()
Definition: JPoint4D.hh:58
static parameter_type pY()
Definition: JPoint4D.hh:59
Direct access to module in detector data structure.
Fit method based on the Levenberg-Marquardt method.
Definition: JGandalf.hh:52
static double Vmax_npe
Maximal integral of PDF [npe].
JFit getFit(const JHistory &history, const JTrack3D &track, const double Q, const int NDF, const double energy=0.0, const int status=0)
Get fit.
Reduced data structure for L1 hit.
Auxiliary class for a hit with background rate value.
Definition: JHitW0.hh:21
Data regression method for JFIT::JPoint4D from a bright point isoptropic emission PDF...
JFIT::JHistory JHistory
Definition: JHistory.hh:283
Data structure for set of track fit results.
Auxiliary class to define a range between two values.
JShowerPositionFit(const JShowerPositionFitParameters_t &parameters, const JModuleRouter &router, const JSummaryRouter &summary, const std::string pdfFile, const int debug=0)
Parameterized constructor.
static int MAXIMUM_ITERATIONS
maximal number of iterations
Definition: JGandalf.hh:248
Template specialisation of class JModel to match hit with bright point.
Definition: JFit/JModel.hh:121
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:36
Match operator for Cherenkov light from shower in any direction.
Basic data structure for L1 hit.
static JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].