Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
31 
33 
34 #include "Jeep/JMessage.hh"
35 
36 
37 /**
38  * \author mdejong, gmaggi
39  */
40 
41 namespace JRECONSTRUCTION {}
42 namespace JPP { using namespace JRECONSTRUCTION; }
43 
44 namespace JRECONSTRUCTION {
45 
47  using JFIT::JRegressor;
48  using JFIT::JLine3Z;
49  using JFIT::JSimplex;
50 
51 
52  /**
53  * Wrapper class to make intermediate fit of muon trajectory.
54  *
55  * The JMuonSimplex fit uses one or more start values (usually taken from the output of JMuonPrefit) and
56  * produces new start values for subsequent fits (usually JMuonGandalf).\n
57  * All hits of which the PMT position lies within a set road width (JMuonSimplexParameters_t::roadWidth_m) and
58  * time is within a set window (JMuonSimplexParameters_t::TMin_ns, JMuonSimplexParameters_t::TMax_ns) around the Cherenkov hypothesis are taken.\n
59  * In case there are multiple hits from the same PMT is the specified window,
60  * the first hit is taken and the other hits are discarded.\n
61  * The chi-squared is based on an M-estimator of the time residuals.\n
62  */
63  struct JMuonSimplex :
65  public JRegressor<JLine3Z, JSimplex>
66  {
70 
71  using JRegressor_t::operator();
72 
73  /**
74  * Constructor
75  *
76  * \param parameters parameters
77  * \param router module router
78  * \param debug debug
79  */
81  const JModuleRouter& router,
82  const int debug = 0) :
83  JMuonSimplexParameters_t(parameters),
84  JRegressor_t(parameters.sigma_ns),
85  router(router)
86  {
87  using namespace JPP;
88 
89  this->estimator.reset(new JMEstimatorLorentzian());
90 
93  }
94 
95 
96  /**
97  * Fit function.
98  *
99  * \param event event
100  * \param in start values
101  * \return fit results
102  */
104  {
105  using namespace std;
106  using namespace JPP;
107 
108  const JBuildL0<hit_type> buildL0;
110 
111  buffer_type dataL0;
112  buffer_type dataL1;
113 
114  const KM3NETDAQ::JDAQTimeslice timeslice(event, true);
115  JSuperFrame2D<JHit> buffer;
116 
117  for (JDAQTimeslice::const_iterator i = timeslice.begin(); i != timeslice.end(); ++i) {
118 
119  if (router.hasModule(i->getModuleID())) {
120 
121  buffer(*i, router.getModule(i->getModuleID()));
122 
123  if (useL0) {
124  buildL0(buffer, back_inserter(dataL0));
125  }
126  {
127  buildL2(buffer, back_inserter(dataL1));
128  }
129  }
130  }
131 
132  return (*this)(dataL0, dataL1, in);
133  }
134 
135 
136  /**
137  * Fit function.
138  *
139  * \param dataL0 L0 hit data
140  * \param dataL1 L1 hit data
141  * \param in start values
142  * \return fit results
143  */
144  JEvt operator()(const buffer_type& dataL0,
145  const buffer_type& dataL1,
146  const JEvt& in)
147  {
148  using namespace std;
149  using namespace JPP;
150 
151  JEvt out;
152 
153  buffer_type data;
154 
155  data.reserve(dataL0.size() +
156  dataL1.size());
157 
158 
159  for (JEvt::const_iterator track = in.begin(); track != in.end(); ++track) {
160 
161  const JRotation3D R (getDirection(*track));
162  const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
164 
165  data.clear();
166 
167  for (buffer_type::const_iterator i = dataL1.begin(); i != dataL1.end(); ++i) {
168 
169  hit_type hit(*i);
170 
171  hit.rotate(R);
172 
173  if (match(hit)) {
174  data.push_back(hit);
175  }
176  }
177 
178  if (useL0) {
179 
180  buffer_type::iterator __end = data.end();
181 
182  for (buffer_type::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
183 
184  if (find_if(data.begin(), __end, bind2nd(equal_to<JDAQModuleIdentifier>(), i->getModuleID())) == __end) {
185 
186  hit_type hit(*i);
187 
188  hit.rotate(R);
189 
190  if (match(hit)) {
191  data.push_back(hit);
192  }
193  }
194  }
195  }
196 
197 
198  this->step.resize(5);
199 
200  this->step[0] = JLine3Z(JLine1Z(JVector3D(0.5, 0.0, 0.0), 0.0));
201  this->step[1] = JLine3Z(JLine1Z(JVector3D(0.0, 0.5, 0.0), 0.0));
202  this->step[2] = JLine3Z(JLine1Z(JVector3D(0.0, 0.0, 0.0), 1.0));
203  this->step[3] = JLine3Z(JLine1Z(JVector3D(), 0.0), JVersor3Z(0.005, 0.0));
204  this->step[4] = JLine3Z(JLine1Z(JVector3D(), 0.0), JVersor3Z(0.0, 0.005));
205 
206  const int NDF = getCount(data.begin(), data.end()) - this->step.size();
207 
208  if (NDF > 0) {
209 
210  const double chi2 = (*this)(JLine3Z(tz), data.begin(), data.end());
211 
212  JTrack3D tb(this->value);
213 
214  tb.rotate_back(R);
215 
216  out.push_back(getFit(JHistory(track->getHistory()).add(JMUONSIMPLEX), tb, getQuality(chi2, NDF), NDF));
217 
218  out.rbegin()->setW(track->getW());
219  }
220  }
221 
222  return out;
223  }
224 
225 
227  };
228 }
229 
230 #endif
Auxiliary methods to evaluate Poisson probabilities and chi2.
static int debug
debug level (default is off).
Definition: JMessage.hh:45
Data regression method for JFIT::JLine3Z.
Template definition of a data regressor of given model.
Definition: JRegressor.hh:68
JEvt operator()(const buffer_type &dataL0, const buffer_type &dataL1, const JEvt &in)
Fit function.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
const JModuleRouter & router
Router for direct addressing of module data in detector data structure.
Rotation matrix.
Definition: JRotation3D.hh:111
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
*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
Template specialisation of class JModel to match hit with muon trajectory along z-axis.
Definition: JFit/JModel.hh:34
Data structure for fit of straight line in positive z-direction.
Definition: JLine3Z.hh:35
double getQuality(const double chi2, const int N, const int NDF)
Get quality of fit.
Definition: JEvtToolkit.hh:206
JRange< double > JTimeRange
Type definition for time range.
Template L2 builder.
Definition: JBuildL2.hh:45
Data structure for vector in three dimensions.
Definition: JVector3D.hh:33
Wrapper class to make intermediate fit of muon trajectory.
Definition: JMuonSimplex.hh:63
Regressor function object for JLine3Z fit using JSimplex minimiser.
JRegressor< JLine3Z, JSimplex > JRegressor_t
Definition: JMuonSimplex.hh:67
Data time slice.
JEvt operator()(const KM3NETDAQ::JDAQEvent &event, const JEvt &in)
Fit function.
int debug
debug level
Definition: JSirene.cc:61
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:40
General purpose messaging.
Direct access to module in detector data structure.
std::vector< hit_type > buffer_type
Definition: JMuonSimplex.hh:69
Data structure for L2 parameters.
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.
Definition: JEvtToolkit.hh:126
Reduced data structure for L1 hit.
JFIT::JHistory JHistory
Definition: JHistory.hh:283
Data structure for set of track fit results.
Definition: JEvt.hh:294
static const int JMUONSIMPLEX
Simple fit method based on Powell&#39;s algorithm, see reference: Numerical Recipes in C++...
Definition: JSimplex.hh:42
Data structure for fit of straight line paralel to z-axis.
Definition: JLine1Z.hh:27
bool hasModule(const JObjectID &id) const
Has module.
int getCount(const T &hit)
Get hit count.
JMuonSimplex(const JMuonSimplexParameters_t &parameters, const JModuleRouter &router, const int debug=0)
Constructor.
Definition: JMuonSimplex.hh:80
2-dimensional frame with time calibrated data from one optical module.
Reduced data structure for L1 hit.
Definition: JHitR1.hh:31
JDirection3D getDirection(const Vec &v)
Get direction.
static int MAXIMUM_ITERATIONS
maximal number of iterations
Definition: JSimplex.hh:237
Template L0 hit builder.
Definition: JBuildL0.hh:35
Data structure for normalised vector in positive z-direction.
Definition: JVersor3Z.hh:37
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Definition: JPosition3D.hh:185
Maximum likelihood estimator (M-estimators).
Lorentzian M-estimator.
Definition: JMEstimator.hh:79
JPosition3D getPosition(const Vec &v)
Get position.