Jpp  debug
the software that should make you happy
JMuonSimplex.hh
Go to the documentation of this file.
1 #ifndef __JRECONSTRUCTION__JMUONSIMPLEX__
2 #define __JRECONSTRUCTION__JMUONSIMPLEX__
3 
4 #include <iostream>
5 #include <iomanip>
6 #include <vector>
7 #include <algorithm>
8 
12 
13 #include "JTrigger/JHitR1.hh"
15 #include "JTrigger/JBuildL0.hh"
16 #include "JTrigger/JBuildL2.hh"
17 
18 #include "JFit/JFitToolkit.hh"
19 #include "JFit/JLine1Z.hh"
20 #include "JFit/JLine3Z.hh"
21 #include "JFit/JModel.hh"
22 #include "JFit/JSimplex.hh"
23 #include "JFit/JLine3ZRegressor.hh"
24 #include "JFit/JMEstimator.hh"
25 
26 #include "JReconstruction/JEvt.hh"
29 
30 #include "JLang/JPredicate.hh"
31 
33 
35 
36 #include "Jeep/JMessage.hh"
37 
38 
39 /**
40  * \author mdejong, gmaggi
41  */
42 
43 namespace JRECONSTRUCTION {}
44 namespace JPP { using namespace JRECONSTRUCTION; }
45 
46 namespace JRECONSTRUCTION {
47 
49  using JFIT::JRegressor;
50  using JFIT::JLine3Z;
51  using JFIT::JSimplex;
52 
53 
54  /**
55  * Wrapper class to make intermediate fit of muon trajectory.
56  *
57  * The JMuonSimplex fit uses one or more start values (usually taken from the output of JMuonPrefit) and
58  * produces new start values for subsequent fits (usually JMuonGandalf).\n
59  * All hits of which the PMT position lies within a set road width (JMuonSimplexParameters_t::roadWidth_m) and
60  * time is within a set window (JMuonSimplexParameters_t::TMin_ns, JMuonSimplexParameters_t::TMax_ns) around the Cherenkov hypothesis are taken.\n
61  * In case there are multiple hits from the same PMT is the specified window,
62  * the first hit is taken and the other hits are discarded.\n
63  * The chi-squared is based on an M-estimator of the time residuals.\n
64  */
65  struct JMuonSimplex :
67  public JRegressor<JLine3Z, JSimplex>
68  {
72 
73  using JRegressor_t::operator();
74 
75  /**
76  * Constructor
77  *
78  * \param parameters parameters
79  * \param router module router
80  * \param debug debug
81  */
83  const JModuleRouter& router,
84  const int debug = 0) :
85  JMuonSimplexParameters_t(parameters),
86  JRegressor_t(parameters.sigma_ns),
87  router(router)
88  {
89  using namespace JFIT;
90 
91  this->estimator.reset(new JMEstimatorLorentzian());
92 
94  JRegressor_t::MAXIMUM_ITERATIONS = NMax;
95  }
96 
97 
98  /**
99  * Fit function.
100  *
101  * \param event event
102  * \param in start values
103  * \return fit results
104  */
105  JEvt operator()(const KM3NETDAQ::JDAQEvent& event, const JEvt& in)
106  {
107  using namespace std;
108  using namespace JFIT;
109  using namespace JTRIGGER;
110 
111  const JBuildL0<hit_type> buildL0;
113 
114  buffer_type dataL0;
115  buffer_type dataL1;
116 
117  const KM3NETDAQ::JDAQTimeslice timeslice(event, true);
118  JSuperFrame2D<JHit> buffer;
119 
120  for (JDAQTimeslice::const_iterator i = timeslice.begin(); i != timeslice.end(); ++i) {
121 
122  if (router.hasModule(i->getModuleID())) {
123 
124  buffer(*i, router.getModule(i->getModuleID()));
125 
126  if (useL0) {
127  buildL0(buffer, back_inserter(dataL0));
128  }
129  {
130  buildL2(buffer, back_inserter(dataL1));
131  }
132  }
133  }
134 
135  return (*this)(dataL0, dataL1, in);
136  }
137 
138 
139  /**
140  * Fit function.
141  *
142  * \param dataL0 L0 hit data
143  * \param dataL1 L1 hit data
144  * \param in start values
145  * \return fit results
146  */
147  JEvt operator()(const buffer_type& dataL0,
148  const buffer_type& dataL1,
149  const JEvt& in)
150  {
151  using namespace std;
152  using namespace JFIT;
153  using namespace JGEOMETRY3D;
154  using namespace JLANG;
155 
156  JEvt out;
157 
159 
160  data.reserve(dataL0.size() +
161  dataL1.size());
162 
163 
164  for (JEvt::const_iterator track = in.begin(); track != in.end(); ++track) {
165 
166  const JRotation3D R (getDirection(*track));
167  const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
169 
170  data.clear();
171 
172  for (buffer_type::const_iterator i = dataL1.begin(); i != dataL1.end(); ++i) {
173 
174  hit_type hit(*i);
175 
176  hit.rotate(R);
177 
178  if (match(hit)) {
179  data.push_back(hit);
180  }
181  }
182 
183  if (useL0) {
184 
185  buffer_type::iterator __end = data.end();
186 
187  for (buffer_type::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
188 
189  if (find_if(data.begin(), __end, make_predicate(&hit_type::getModuleID, i->getModuleID())) == __end) {
190 
191  hit_type hit(*i);
192 
193  hit.rotate(R);
194 
195  if (match(hit)) {
196  data.push_back(hit);
197  }
198  }
199  }
200  }
201 
202 
203  this->step.resize(5);
204 
205  this->step[0] = JLine3Z(JLine1Z(JVector3D(0.5, 0.0, 0.0), 0.0));
206  this->step[1] = JLine3Z(JLine1Z(JVector3D(0.0, 0.5, 0.0), 0.0));
207  this->step[2] = JLine3Z(JLine1Z(JVector3D(0.0, 0.0, 0.0), 1.0));
208  this->step[3] = JLine3Z(JLine1Z(JVector3D(), 0.0), JVersor3Z(0.005, 0.0));
209  this->step[4] = JLine3Z(JLine1Z(JVector3D(), 0.0), JVersor3Z(0.0, 0.005));
210 
211  const int NDF = getCount(data.begin(), data.end()) - this->step.size();
212 
213  if (NDF > 0) {
214 
215  const double chi2 = (*this)(JLine3Z(tz), data.begin(), data.end());
216 
217  JTrack3D tb(this->value);
218 
219  tb.rotate_back(R);
220 
221  out.push_back(getFit(JHistory(track->getHistory()).add(JMUONSIMPLEX), tb, getQuality(chi2, NDF), NDF));
222 
223  out.rbegin()->setW(track->getW());
224  }
225  }
226 
227  return out;
228  }
229 
230 
232  };
233 }
234 
235 #endif
Auxiliary methods to evaluate Poisson probabilities and chi2.
Reduced data structure for L1 hit.
Data regression method for JFIT::JLine3Z.
Maximum likelihood estimator (M-estimators).
General purpose messaging.
int debug
debug level
Definition: JSirene.cc:69
Direct access to module in detector data structure.
Router for direct addressing of module data in detector data structure.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
bool hasModule(const JObjectID &id) const
Has module.
Data structure for set of track fit results.
Data structure for fit of straight line paralel to z-axis.
Definition: JLine1Z.hh:29
Data structure for fit of straight line in positive z-direction.
Definition: JLine3Z.hh:40
Simple fit method based on Powell's algorithm, see reference: Numerical Recipes in C++,...
Definition: JSimplex.hh:44
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Definition: JPosition3D.hh:186
Rotation matrix.
Definition: JRotation3D.hh:114
Data structure for vector in three dimensions.
Definition: JVector3D.hh:36
Data structure for normalised vector in positive z-direction.
Definition: JVersor3Z.hh:41
Template L0 hit builder.
Definition: JBuildL0.hh:38
Template L2 builder.
Definition: JBuildL2.hh:49
Reduced data structure for L1 hit.
Definition: JHitR1.hh:35
2-dimensional frame with time calibrated data from one optical module.
int getModuleID() const
Get module identifier.
static const int JMUONSIMPLEX
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.
JTOOLS::JRange< double > JTimeRange
Type definition for time range (unit [s]).
Auxiliary classes and methods for linear and iterative data regression.
Definition: JEnergy.hh:15
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition: JAngle3D.hh:19
Auxiliary classes and methods for language specific functionality.
size_t getCount(const array_type< T > &buffer, const JCompare_t &compare)
Count number of unique values.
Definition: JVectorize.hh:261
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Model fits to data.
JFIT::JHistory JHistory
Definition: JHistory.hh:354
Auxiliary classes and methods for triggering.
Definition: JSTDTypes.hh:14
JHistory & add(const int type)
Add event to history.
Definition: JHistory.hh:295
Lorentzian M-estimator.
Definition: JMEstimator.hh:67
Template specialisation of class JModel to match hit with muon trajectory along z-axis.
Definition: JFit/JModel.hh:36
Regressor function object for JLine3Z fit using JSimplex minimiser.
Template definition of a data regressor of given model.
Definition: JRegressor.hh:70
double TMax_ns
maximal time w.r.t. Cherenkov hypothesis [ns]
double TMaxLocal_ns
time window for local coincidences [ns]
double TMin_ns
minimal time w.r.t. Cherenkov hypothesis [ns]
double ctMin
minimal cosine space angle between PMT axes
Wrapper class to make intermediate fit of muon trajectory.
Definition: JMuonSimplex.hh:68
JEvt operator()(const KM3NETDAQ::JDAQEvent &event, const JEvt &in)
Fit function.
JEvt operator()(const buffer_type &dataL0, const buffer_type &dataL1, const JEvt &in)
Fit function.
const JModuleRouter & router
JMuonSimplex(const JMuonSimplexParameters_t &parameters, const JModuleRouter &router, const int debug=0)
Constructor.
Definition: JMuonSimplex.hh:82
std::vector< hit_type > buffer_type
Definition: JMuonSimplex.hh:71
JRegressor< JLine3Z, JSimplex > JRegressor_t
Definition: JMuonSimplex.hh:69
Data structure for L2 parameters.