Jpp
JMuonSimplex.hh
Go to the documentation of this file.
1 #ifndef JMUONSIMPLEX_INCLUDE
2 #define JMUONSIMPLEX_INCLUDE
3 
4 #include <string>
5 #include <iostream>
6 #include <iomanip>
7 #include <vector>
8 #include <algorithm>
9 
10 #include "JDAQ/JDAQTimeslice.hh"
11 #include "JDAQ/JDAQSummaryslice.hh"
12 
13 #include "JTrigger/JHit.hh"
14 #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 
22 #include "JFit/JLine1Z.hh"
23 #include "JFit/JLine1ZEstimator.hh"
24 #include "JFit/JFitToolkit.hh"
25 #include "JFit/JEvt.hh"
26 #include "JFit/JEvtToolkit.hh"
27 #include "JFit/JFitParameters.hh"
28 #include "JFit/JFitStatus.hh"
29 #include "JFit/JLine3Z.hh"
30 #include "JFit/JModel.hh"
31 #include "JFit/JSimplex.hh"
32 #include "JFit/JLine3ZRegressor.hh"
34 
35 #include "JGeometry3D/JOmega3D.hh"
37 
38 #include "JLang/JSharedPointer.hh"
39 
40 /**
41  * \author mdejong, gmaggi
42  */
43 
44 namespace JFIT
45 {
46  /**
47  * class to handle the Simplex angular reconstruction.
48  * this should be combined with JMuonPrefit first, and subsequently with JMuonGandalf to achieve an optimal angular resolution.
49  */
51  {
52  private:
55 
56  public:
57 
58  /**
59  * Default constructor
60  */
62  {}
63 
64  /**
65  * Parameterized constructor
66  *
67  * \param router JSharedPointer of JModuleRouter, this is built via detector file.
68  * \param parameters struct that holds default-optimized parameters for the reconstruction, for ARCA and ORCA configuration.
69  */
71  const JFIT::JMuonSimplexParameters_t &parameters):
72  router_(router),
73  parameters_(parameters)
74  {}
75 
77  {}
78  /**
79  * Declaration of Member function that actually performs the reconstruction
80  *
81  * \param timeSlice which is contructed via a JDAQEvent
82  * \param InPreFits input JEvt which is a container of prefits, normally JMuonPrefit
83  * \param OutFits non const JEvt.
84  */
85  void
86  getJEvt(const KM3NETDAQ::JDAQTimeslice &timeSlice,
87  JFIT::JEvt &InPreFits, // <- this parameter is declared as non const on purpose, see the algorthm below.
88  JFIT::JEvt &OutFits) const;
89 
90  };
91 }
92 
93 
94 /**
95  * Member function definition
96  */
97 void
99  JFIT::JEvt &InPreFits,
100  JFIT::JEvt &OutFits) const
101 {
102  if ( InPreFits.empty() ) return;
103 
104  const bool useL0 = parameters_.useL0;
105  const bool reprocess = parameters_.reprocess;
106  const double sigma_ns = parameters_.sigma_ns;
107  const size_t numberOfPrefits = parameters_.numberOfPrefits;
108  const double Tmax_ns = parameters_.Tmax_ns;
109  const double roadWidth_m = parameters_.roadWidth_m;
110  const double ctMin = parameters_.ctMin;
111 
112  typedef std::vector<JTRIGGER::JHitL0> JDataL0_t;
113  typedef std::vector<JTRIGGER::JHitL1> JDataL1_t;
114  typedef std::vector<JTRIGGER::JHitR1> JDataR1_t;
115 
118  const JTRIGGER::JBuildL2<JTRIGGER::JHitL1> buildL2(JTRIGGER::JL2Parameters(2, Tmax_ns, ctMin));
119 
121 
122  JRegressor_t fit(sigma_ns);
123 
124  fit.estimator.reset(new JMEstimatorLorentzian());
125 
126  //JRegressor_t::debug = debug;
127  JRegressor_t::MAXIMUM_ITERATIONS = 10000;
128 
129  const double TMAX_NS = 50.0; //[ns]
130 
131  JEvt::iterator __end = InPreFits.end();
132 
133  if (reprocess) {
134  __end = std::partition(InPreFits.begin(), __end, JHistory::is_not_event(JFIT::JMUONSIMPLEX));
135  }
136 
137  if (InPreFits.begin() != __end) {
138 
139  std::copy(InPreFits.begin(), __end, std::back_inserter(OutFits));
140 
141  if (numberOfPrefits > 0) {
142  std::advance(__end = InPreFits.begin(), std::min(numberOfPrefits, OutFits.size()));
143  }
144 
145  std::partial_sort(InPreFits.begin(), __end, InPreFits.end(), qualitySorter);
146 
147  __end = std::partition( InPreFits.begin(), __end,
148  JFIT::JHistory::is_event(InPreFits.begin()->getHistory())
149  );
150 
151  JDataL0_t dataL0;
152  JDataL1_t dataL1;
153 
154  for (KM3NETDAQ::JDAQTimeslice::const_iterator i = timeSlice.begin();
155  i != timeSlice.end(); ++i) {
156 
157  if (router_->hasModule(i->getModuleID())) {
158 
159  buffer(*i, router_->getModule(i->getModuleID()));
160 
161  buildL0(buffer, std::back_inserter(dataL0));
162  buildL2(buffer, std::back_inserter(dataL1));
163  }
164  }
165 
166  JDataR1_t data;
167 
168  for (JFIT::JEvt::const_iterator track = InPreFits.begin(); track != __end; ++track) {
169 
171  const JFIT::JLine1Z tz(getPosition (*track).rotate(R), track->getT());
172  const JFIT::JModel<JFIT::JLine1Z> match(tz, roadWidth_m, JTimeRange(-TMAX_NS, +TMAX_NS));
173 
174  data.clear();
175 
176  for (JDataL1_t::const_iterator i = dataL1.begin(); i != dataL1.end(); ++i) {
177 
178  JTRIGGER::JHitR1 hit(*i);
179 
180  hit.rotate(R);
181 
182  if (match(hit)) {
183  data.push_back(hit);
184  }
185  }
186 
187  if (useL0) {
188 
189  data.reserve(data.size() + dataL0.size());
190 
191  JDataR1_t::iterator __end1 = data.end();
192 
193  for (JDataL0_t::iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
194 
195  if ( std::find_if( data.begin(), __end1,
196  std::bind2nd(std::equal_to<KM3NETDAQ::JDAQModuleIdentifier>(), i->getModuleID()))
197  == __end1) {
198 
199  JTRIGGER::JHitR1 hit(*i);
200 
201  hit.rotate(R);
202 
203  if (match(hit)) {
204  data.push_back(hit);
205  }
206  }
207  }
208  }
209 
210  fit.step.resize(5);
211 
212  fit.step[0] = JFIT::JLine3Z( JFIT::JLine1Z( JGEOMETRY3D::JVector3D(0.5, 0.0, 0.0), 0.0) );
213  fit.step[1] = JFIT::JLine3Z( JFIT::JLine1Z( JGEOMETRY3D::JVector3D(0.0, 0.5, 0.0), 0.0) );
214  fit.step[2] = JFIT::JLine3Z( JFIT::JLine1Z( JGEOMETRY3D::JVector3D(0.0, 0.0, 0.0), 1.0) );
215  fit.step[3] = JFIT::JLine3Z( JFIT::JLine1Z( JGEOMETRY3D::JVector3D(), 0.0), JGEOMETRY3D::JVersor3Z(0.005, 0.0) );
216  fit.step[4] = JFIT::JLine3Z( JFIT::JLine1Z( JGEOMETRY3D::JVector3D(), 0.0), JGEOMETRY3D::JVersor3Z(0.0, 0.005) );
217 
218  const int NDF = JFIT::getCount(data.begin(), data.end()) - fit.step.size();
219 
220  if (NDF >= 0) {
221 
222  const double chi2 = fit( JFIT::JLine3Z(tz), data.begin(), data.end() );
223 
224  JGEOMETRY3D::JTrack3D track3D(fit.value);
225 
226  track3D.rotate_back(R);
227 
228  const double energy(0);
229  OutFits.push_back( JFIT::getFit(JFIT::JHistory(track->getHistory()).add(JFIT::JFitApplication_t::JMUONSIMPLEX), track3D,
230  JFIT::getQuality(chi2, NDF), NDF,energy,JFIT::JFitStatus_t::OKAY) );
231  }
232  }
233 
234  // apply default sorter
235 
236  std::sort(OutFits.begin(), OutFits.end(), qualitySorter);
237  }
238 
239 }
240 
241 
242 #endif
JFIT::JMEstimatorLorentzian
Lorentzian M-estimator.
Definition: JMEstimator.hh:79
JFIT::JMUONSIMPLEX
JSimplex.cc.
Definition: JFitApplications.hh:24
JFIT::JMuonSimplex::parameters_
JFIT::JMuonSimplexParameters_t parameters_
Definition: JMuonSimplex.hh:54
JFIT::JMuonSimplex::~JMuonSimplex
~JMuonSimplex()
Definition: JMuonSimplex.hh:76
JLine3Z.hh
JSuperFrame2D.hh
JFIT
Auxiliary classes and methods for linear and iterative data regression.
Definition: JEnergy.hh:15
JFIT::JLine3Z
Data structure for fit of straight line in positive z-direction.
Definition: JLine3Z.hh:35
JMuonSimplexParameters_t.hh
JTRIGGER::JL2Parameters
Data structure for L2 parameters.
Definition: JTriggerParameters.hh:33
JROOT::advance
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
Definition: JCounter.hh:35
JFitToolkit.hh
JLine3ZRegressor.hh
JGEOMETRY3D::JVersor3Z
Data structure for normalised vector in positive z-direction.
Definition: JVersor3Z.hh:37
JFitStatus.hh
JDETECTOR::JModuleRouter::getModule
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Definition: JModuleRouter.hh:89
JTimeslice.hh
JFIT::JMuonSimplexParameters_t::useL0
bool useL0
Definition: JMuonSimplexParameters_t.hh:17
JSharedPointer.hh
JSimplex.hh
std::vector
Definition: JSTDTypes.hh:12
JEvtToolkit.hh
KM3NETDAQ::JDAQTimeslice
Data time slice.
Definition: JDAQTimeslice.hh:36
JFIT::JMuonSimplexParameters_t::Tmax_ns
double Tmax_ns
Definition: JMuonSimplexParameters_t.hh:19
JDAQTimeslice.hh
JFIT::JEvt
Data structure for set of track fit results.
Definition: JEvt.hh:292
JAANET::copy
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:152
JDAQSummaryslice.hh
JGEOMETRY3D::JPosition3D::rotate
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Definition: JPosition3D.hh:185
JTOOLS::JTimeRange
JRange< double > JTimeRange
Type definition for time range.
Definition: JTools/JTimeRange.hh:19
JEvt.hh
JFIT::JMuonSimplexParameters_t::sigma_ns
double sigma_ns
Definition: JMuonSimplexParameters_t.hh:16
JFIT::JModel
Auxiliary class to match data points with given model.
Definition: JModel.hh:27
JTRIGGER::JBuildL0
Template L0 hit builder.
Definition: JBuildL0.hh:34
JBuildL0.hh
JGEOMETRY3D::JVector3D
Data structure for vector in three dimensions.
Definition: JVector3D.hh:33
JFIT::qualitySorter
bool qualitySorter(const JFit &first, const JFit &second)
Comparison of fit results.
Definition: JEvtToolkit.hh:223
JFIT::JMuonSimplexParameters_t::reprocess
bool reprocess
Definition: JMuonSimplexParameters_t.hh:22
JLine1ZEstimator.hh
JHit.hh
JFIT::JRegressor
Template definition of a data regressor of given model.
Definition: JRegressor.hh:68
JFIT::JHistory::is_event
Auxiliary class to test history.
Definition: JHistory.hh:101
JHitR1.hh
JBuildL2.hh
JFIT::JLine1Z
Data structure for fit of straight line paralel to z-axis.
Definition: JLine1Z.hh:27
JFIT::JHistory::is_not_event
Auxiliary class to test history.
Definition: JHistory.hh:149
JHitL1.hh
JModel.hh
JTRIGGER::JHitR1
Reduced data structure for L1 hit.
Definition: JHitR1.hh:31
JFitParameters.hh
JFIT::JMuonSimplexParameters_t::roadWidth_m
double roadWidth_m
Definition: JMuonSimplexParameters_t.hh:21
JFIT::JMuonSimplexParameters_t
Definition: JMuonSimplexParameters_t.hh:13
JRotation3D.hh
JDETECTOR::JModuleRouter::hasModule
bool hasModule(const JObjectID &id) const
Has module.
Definition: JModuleRouter.hh:101
JFIT::JMuonSimplex
class to handle the Simplex angular reconstruction.
Definition: JMuonSimplex.hh:50
JGEOMETRY3D::JTrack3D
3D track.
Definition: JTrack3D.hh:30
JFIT::JMuonSimplex::getJEvt
void getJEvt(const KM3NETDAQ::JDAQTimeslice &timeSlice, JFIT::JEvt &InPreFits, JFIT::JEvt &OutFits) const
Declaration of Member function that actually performs the reconstruction.
Definition: JMuonSimplex.hh:98
JFIT::getFit
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:116
JFIT::JHistory
Container for historical events.
Definition: JHistory.hh:95
JHitL0.hh
JTRIGGER::JSuperFrame2D
2-dimensional frame with time calibrated data from one optical module.
Definition: JSuperFrame2D.hh:41
JFIT::getQuality
double getQuality(const double chi2, const int NDF)
Get quality of fit.
Definition: JEvtToolkit.hh:195
JFIT::JMuonSimplex::router_
JLANG::JSharedPointer< const JDETECTOR::JModuleRouter > router_
Definition: JMuonSimplex.hh:53
JFIT::getPosition
JPosition3D getPosition(const JFit &fit)
Get position.
Definition: JEvtToolkit.hh:63
JFIT::JMuonSimplex::JMuonSimplex
JMuonSimplex(const JLANG::JSharedPointer< const JDETECTOR::JModuleRouter > &router, const JFIT::JMuonSimplexParameters_t &parameters)
Parameterized constructor.
Definition: JMuonSimplex.hh:70
JFIT::JMuonSimplexParameters_t::numberOfPrefits
size_t numberOfPrefits
Definition: JMuonSimplexParameters_t.hh:18
JFIT::JMuonSimplex::JMuonSimplex
JMuonSimplex()
Default constructor.
Definition: JMuonSimplex.hh:61
JFIT::getDirection
JDirection3D getDirection(const JFit &fit)
Get direction.
Definition: JEvtToolkit.hh:75
JGEOMETRY3D::JRotation3D
Rotation matrix.
Definition: JRotation3D.hh:111
JFIT::getCount
int getCount(const JHitL0 &hit)
Get hit count.
Definition: JEvtToolkit.hh:728
JLine1Z.hh
JLANG::JSharedPointer< const JDETECTOR::JModuleRouter >
JOmega3D.hh
JFIT::OKAY
Definition: JFitStatus.hh:22
JFIT::JMuonSimplexParameters_t::ctMin
double ctMin
Definition: JMuonSimplexParameters_t.hh:20
JTRIGGER::JBuildL2
Template L2 builder.
Definition: JBuildL2.hh:45