Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
JFIT::JMuonPrefit Class Reference

class to handle Prefit angular reconstruction. More...

#include <JMuonPrefit.hh>

Public Member Functions

 JMuonPrefit ()
 Default constructor. More...
 
 JMuonPrefit (const JLANG::JSharedPointer< const JDETECTOR::JModuleRouter > &router, const JFIT::JMuonPrefitParameters_t &parameters)
 Parameterized constructor. More...
 
 JMuonPrefit (const JLANG::JSharedPointer< const JDETECTOR::JModuleRouter > &router, const JFIT::JMuonPrefitParameters_t &parameters, const JGEOMETRY3D::JOmega3D &omega)
 Parameterized constructor. More...
 
 ~JMuonPrefit ()
 
void getJEvt (const KM3NETDAQ::JDAQTimeslice &timeSliceBuildL0, const KM3NETDAQ::JDAQTimeslice &timeSliceBuildL2, JFIT::JEvt &out) const
 Declaration Member function that actually performs the reconstruction. More...
 

Static Public Member Functions

static bool cmz (const JTRIGGER::JHitR1 &first, const JTRIGGER::JHitR1 &second)
 Sort hits according times corrected for position along z-axis. More...
 

Private Attributes

JLANG::JSharedPointer< const
JDETECTOR::JModuleRouter
router_
 
JFIT::JMuonPrefitParameters_t parameters_
 
JGEOMETRY3D::JOmega3D omega_
 

Detailed Description

class to handle Prefit angular reconstruction.

this should be combined with JMuonSimplex and JMuonGandalf to achieve an optimal angular resolution.

Definition at line 53 of file JMuonPrefit.hh.

Constructor & Destructor Documentation

JFIT::JMuonPrefit::JMuonPrefit ( )
inline

Default constructor.

Definition at line 66 of file JMuonPrefit.hh.

67  {}
JFIT::JMuonPrefit::JMuonPrefit ( const JLANG::JSharedPointer< const JDETECTOR::JModuleRouter > &  router,
const JFIT::JMuonPrefitParameters_t parameters 
)
inline

Parameterized constructor.

Parameters
routerJSharedPointer of JModuleRouter, this is built via detector file.
parametersstruct that holds default-optimized parameters for the reconstruction, for ARCA and ORCA configuration.

Definition at line 75 of file JMuonPrefit.hh.

76  :
77  router_(router),
78  parameters_(parameters),
79  omega_(parameters.gridAngle_deg* JTOOLS::PI/180.0)
80  {}
static const double PI
Constants.
Definition: JConstants.hh:20
JGEOMETRY3D::JOmega3D omega_
Definition: JMuonPrefit.hh:58
JFIT::JMuonPrefitParameters_t parameters_
Definition: JMuonPrefit.hh:57
JLANG::JSharedPointer< const JDETECTOR::JModuleRouter > router_
Definition: JMuonPrefit.hh:56
JFIT::JMuonPrefit::JMuonPrefit ( const JLANG::JSharedPointer< const JDETECTOR::JModuleRouter > &  router,
const JFIT::JMuonPrefitParameters_t parameters,
const JGEOMETRY3D::JOmega3D omega 
)
inline

Parameterized constructor.

Parameters
routerJSharedPointer of JModuleRouter, this is built via detector file.
parametersstruct that holds default-optimized parameters for the reconstruction, for ARCA and ORCA configuration.
omegawhich is constructed by gridAngle_deg (part of JMuonPrefitParameters_t)

Definition at line 90 of file JMuonPrefit.hh.

92  :
93  router_(router),
94  parameters_(parameters),
95  omega_(omega)
96  {}
JGEOMETRY3D::JOmega3D omega_
Definition: JMuonPrefit.hh:58
JFIT::JMuonPrefitParameters_t parameters_
Definition: JMuonPrefit.hh:57
JLANG::JSharedPointer< const JDETECTOR::JModuleRouter > router_
Definition: JMuonPrefit.hh:56
JFIT::JMuonPrefit::~JMuonPrefit ( )
inline

Definition at line 98 of file JMuonPrefit.hh.

99  {}

Member Function Documentation

void JFIT::JMuonPrefit::getJEvt ( const KM3NETDAQ::JDAQTimeslice timeSliceBuildL0,
const KM3NETDAQ::JDAQTimeslice timeSliceBuildL2,
JFIT::JEvt out 
) const

Declaration Member function that actually performs the reconstruction.

Member function definition.

Parameters
timeSliceBuildL0which is contructed via a JDAQEvent
timeSliceBuildL2which is contructed via a JDAQEvent
outnon const JEvt.

Definition at line 138 of file JMuonPrefit.hh.

141 {
142  const double sigma_ns = parameters_.sigma_ns;
143  const double gridAngle_deg = parameters_.gridAngle_deg;
144  const bool useL0 = parameters_.useL0;
145  const int numberOfOutliers = parameters_.numberOfOutliers;
146  const std::size_t numberOfPrefits = parameters_.numberOfPrefits;
147  const double Tmax_ns = parameters_.Tmax_ns;
148  const double ctMin = parameters_.ctMin;
149  const double roadWidth_m = parameters_.roadWidth_m;
150 
151  const int FACTORY_LIMIT = 8; // [unit]
152  const double STANDARD_DEVIATIONS = 3.0; // [unit]
153  const double HIT_OFF = 1.0e3 * sigma_ns * sigma_ns; // [ns^2]
154  const int NUMBER_OF_L1HITS = (useL0 ? 1 : 4);
155  const int MAXIMUM_NUMBER_OF_HITS = 50; //numeric_limits<int>::max();
156 
157  typedef std::vector<JTRIGGER::JHitL0> JDataL0_t;
158  typedef std::vector<JTRIGGER::JHitL1> JDataL1_t;
159  typedef std::vector<JTRIGGER::JHitR1> JDataR1_t;
160 
163  const JTRIGGER::JBuildL2<JTRIGGER::JHitL1> buildL2(2, Tmax_ns, ctMin);
164  const JTRIGGER::JMatch1D<JTRIGGER::JHitR1> match1D(roadWidth_m, Tmax_ns);
165  const JTRIGGER::JMatch3B<JTRIGGER::JHitL1> match3B(roadWidth_m, Tmax_ns);
166  const JFIT::JHitL1Comparator compare;
167 
168  // L1 and L0 data
169  JDataL0_t dataL0;
170  JDataL1_t dataL1;
171 
172  buildL0( timeSliceBuildL0, *router_, back_inserter(dataL0) );
173  buildL2( timeSliceBuildL2, *router_, back_inserter(dataL1) );
174 
175  // 3D cluster of unique optical modules
176 
177  JDataL1_t::iterator __end = std::unique(dataL1.begin(), dataL1.end(),
178  std::equal_to<KM3NETDAQ::JDAQModuleIdentifier>()
179  );
180 
181  __end = JTRIGGER::clusterizeWeight(dataL1.begin(), __end, match3B);
182 
183  if (std::distance(dataL1.begin(), __end) >= NUMBER_OF_L1HITS) {
184 
185  JDataR1_t data;
186 
187  for (JGEOMETRY3D::JOmega3D_t::const_iterator dir = omega_.begin(); dir != omega_.end(); ++dir) {
188 
189  const JGEOMETRY3D::JRotation3D R(*dir);
190 
191  data.clear();
192 
193  std::copy(dataL1.begin(), __end, back_inserter(data));
194 
195  for (JDataR1_t::iterator i = data.begin(); i != data.end(); ++i) {
196  i->rotate(R);
197  }
198 
199 
200  JDataR1_t::iterator __end1 = data.end();
201 
202 
203  // reduce data
204 
205  if ( std::distance(data.begin(), __end1) > MAXIMUM_NUMBER_OF_HITS ) {
206 
207  std::advance(__end1 = data.begin(), MAXIMUM_NUMBER_OF_HITS);
208 
209  std::partial_sort(data.begin(), __end1, data.end(), cmz);
210  }
211 
212 
213  // 1D cluster
214 
215  __end1 = JTRIGGER::clusterizeWeight(data.begin(), __end1, match1D);
216 
217  if ( std::distance(data.begin(), __end1) < NUMBER_OF_L1HITS ) {
218  continue;
219  }
220 
221  if (useL0) {
222 
223  data.erase(__end1, data.end());
224 
225  data.reserve(data.size() + dataL0.size());
226 
227  __end1 = data.end();
228 
229  for (JDataL0_t::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
230 
231  if ( std::find_if( data.begin(), __end1,
232  std::bind2nd(std::equal_to<KM3NETDAQ::JDAQModuleIdentifier>(), i->getModuleID())
233  ) == __end1 ){
234  JHitR1 hit(*i);
235 
236  hit.rotate(R);
237 
238  if ( std::count_if(data.begin(), __end1, JBind2nd(match1D,hit)) >= NUMBER_OF_L1HITS ) {
239  data.push_back(hit);
240  }
241  }
242  }
243 
244  __end1 = JTRIGGER::clusterize(__end1, data.end(), match1D);
245  }
246 
247 
248  if ( std::distance(data.begin(), __end1) <= JFIT::JEstimator<JLine1Z>::NUMBER_OF_PARAMETERS ) {
249  continue;
250  }
251 
252  // 1D fit
253 
254  JFIT::JLine1Z tz;
255  double chi2 = std::numeric_limits<double>::max();
256  int NDF = 0;
257  int N = 0;
258 
259  JFIT::JMatrixNZ V;
260  JFIT::JVectorNZ Y;
261 
262  if ( std::distance(data.begin(), __end1) <= FACTORY_LIMIT ) {
263 
264  double ymin = std::numeric_limits<double>::max();
265 
266  JDataR1_t::iterator __end2 = __end1;
267 
268  for (int n = 0;
269  n <= numberOfOutliers && std::distance(data.begin(), __end2) > JFIT::JEstimator<JLine1Z>::NUMBER_OF_PARAMETERS;
270  ++n, --__end2) {
271 
272  std::sort(data.begin(), __end1, compare);
273 
274  do {
275 
276  try {
277 
278  JFIT::JEstimator<JFIT::JLine1Z> fit(data.begin(), __end2);
279 
280  V.set(fit, data.begin(), __end2, gridAngle_deg, sigma_ns);
281  Y.set(fit, data.begin(), __end2);
282 
283  V.invert();
284 
285  double y = getChi2(Y, V);
286 
287  if (y <= 0.0) {
288  //std::cout<<"THIS IS A WARNING chi2(1) " << y <<std::endl;
289  //WARNING(endl << "chi2(1) " << y << endl); this gives: text+0x4320): undefined reference to `debug'
290  }else if (y < ymin) {
291  ymin = y;
292  tz = fit;
293  NDF = std::distance(data.begin(), __end2) - JFIT::JEstimator<JLine1Z>::NUMBER_OF_PARAMETERS;
294  N = JFIT::getCount(data.begin(), __end2);
295  chi2 = y;
296  }
297  }
298  catch(const JLANG::JException& error) {}
299 
300  } while ( JTOOLS::next_permutation(data.begin(), __end2, __end1, compare) );
301 
302  ymin -= STANDARD_DEVIATIONS * STANDARD_DEVIATIONS;
303  }
304 
305  }else {
306 
307  try {
308 
309  const int number_of_outliers = std::distance(data.begin(), __end1) - JFIT::JEstimator<JLine1Z>::NUMBER_OF_PARAMETERS - 1;
310 
311  JFIT::JEstimator<JLine1Z> fit(data.begin(), __end1);
312 
313  V.set(fit, data.begin(), __end1, gridAngle_deg, sigma_ns);
314  Y.set(fit, data.begin(), __end1);
315 
316  V.invert();
317 
318  NDF = std::distance(data.begin(), __end1) - JFIT::JEstimator<JFIT::JLine1Z>::NUMBER_OF_PARAMETERS;
319  N = JFIT::getCount(data.begin(), __end1);
320 
321  for (int n = 0; n <= number_of_outliers && NDF > 0; ++n, --NDF) {
322 
323  double ymax = 0.0;
324  int kill = -1;
325 
326  for (unsigned int i = 0; i != Y.size(); ++i) {
327 
328  double y = JFIT::getChi2(Y, V, i);
329 
330  if (y <= 0.0) {
331  //std::cout<<"THIS IS A WARNING chi2(1) " << y <<std::endl;
332  //WARNING(endl << "chi2(2) " << y << endl);
333  } else if (y > ymax) {
334  ymax = y;
335  kill = i;
336  }
337  }
338 
339  if (ymax < STANDARD_DEVIATIONS * STANDARD_DEVIATIONS) {
340  break;
341  }
342 
343  V.update(kill, HIT_OFF);
344 
345  fit.update(data.begin(), __end1, V);
346 
347  Y.set(fit, data.begin(), __end1);
348 
349  N -= JFIT::getCount(data[kill]);
350  }
351 
352  chi2 = JFIT::getChi2(Y, V);
353  tz = fit;
354  }
355  catch(const JLANG::JException& error) {}
356  }
357 
358  if (NDF != 0) {
359 
360  tz.rotate_back(R);
361 
362  const double energy(0);
363  out.push_back( JFIT::getFit(JHistory(JMUONPREFIT), tz, *dir, getQuality(chi2, (useL0 ? N : NDF)), NDF,
364  energy,JFIT::JFitStatus_t::OKAY) );
365  }
366 
367  }
368 
369  // apply default sorter
370 
371  if (numberOfPrefits > 0) {
372 
373  JEvt::iterator __end = out.end();
374 
375  std::advance(__end = out.begin(), std::min(numberOfPrefits, out.size()));
376 
377  std::partial_sort(out.begin(), __end, out.end(), qualitySorter);
378 
379  // add downward pointing solutions if available but absent so far
380 
381  if ( std::count_if(out.begin(), __end,
383  ) == 0) {
384 
385  JEvt::iterator __begin = __end;
386  JEvt::iterator __q = std::partition(__begin, out.end(),
388  );
389 
390  std::advance(__end = __begin, std::min(numberOfPrefits, (size_t) std::distance(__begin, __q)));
391 
392  std::partial_sort(__begin, __end, __q, qualitySorter);
393  }
394 
395  out.erase(__end, out.end());
396 
397  } else {
398 
399  std::sort(out.begin(), out.end(), qualitySorter);
400  }
401 
402  }
403 }
General exception.
Definition: JException.hh:40
1D match criterion.
Definition: JMatch1D.hh:31
Linear fit of straight line parallel to z-axis to set of hits (objects with position and time)...
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
JBinder2nd< JHit_t > JBind2nd(const JMatch< JHit_t > &match, const JHit_t &second)
Auxiliary method to create JBinder2nd object.
Definition: JBind2nd.hh:70
void set(const JVector3D &pos, T __begin, T __end, const double alpha, const double sigma)
Set co-variance matrix.
Definition: JMatrixNZ.hh:81
JPosition3D & rotate_back(const JRotation3D &R)
Rotate back.
Definition: JPosition3D.hh:199
int getCount(const JHitL0 &hit)
Get hit count.
Definition: JEvtToolkit.hh:728
Rotation matrix.
Definition: JRotation3D.hh:108
Template definition of linear fit.
Definition: JEstimator.hh:25
void update(const unsigned int k, const double extra)
Update inverted matrix at given diagonal element.
Definition: JMatrixNS.hh:208
JHitIterator_t clusterizeWeight(JHitIterator_t __begin, JHitIterator_t __end, const JMatch< JHit_t > &match)
Partition data according given binary match operator.
Definition: JAlgorithm.hh:310
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
Auxiliary class for permutations of L1 hits.
Definition: JEvtToolkit.hh:501
JHitIterator_t clusterize(JHitIterator_t __begin, JHitIterator_t __end, const JMatch< JHit_t > &match, const int Nmin=1)
Partition data according given binary match operator.
Definition: JAlgorithm.hh:45
Template L2 builder.
Definition: JBuildL2.hh:47
Determination of the time residual vector of hits for a track along z-axis (JFIT::JLine1Z).
Definition: JVectorNZ.hh:25
Determination of the co-variance matrix of hits for a track along z-axis (JFIT::JLine1Z).
Definition: JMatrixNZ.hh:28
void set(const JLine1Z &track, T __begin, T __end)
Set time residual vector.
Definition: JVectorNZ.hh:74
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
double getDZ() const
Get Z-slope.
Definition: JEvt.hh:149
JGEOMETRY3D::JOmega3D omega_
Definition: JMuonPrefit.hh:58
double getQuality(const double chi2, const int NDF)
Get quality of fit.
Definition: JEvtToolkit.hh:195
JFIT::JMuonPrefitParameters_t parameters_
Definition: JMuonPrefit.hh:57
static bool cmz(const JTRIGGER::JHitR1 &first, const JTRIGGER::JHitR1 &second)
Sort hits according times corrected for position along z-axis.
Definition: JMuonPrefit.hh:122
Data structure for fit of straight line paralel to z-axis.
Definition: JLine1Z.hh:27
JLANG::JSharedPointer< const JDETECTOR::JModuleRouter > router_
Definition: JMuonPrefit.hh:56
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:40
2-dimensional frame with time calibrated data from one optical module.
bool qualitySorter(const JFit &first, const JFit &second)
Comparison of fit results.
Definition: JEvtToolkit.hh:223
bool next_permutation(T __begin, T __last, T __end, JComparator_t compare, std::bidirectional_iterator_tag)
Implementation of method next_permutation for bidirectional iterators.
Definition: JPermutation.hh:20
Template L0 hit builder.
Definition: JBuildL0.hh:35
double getChi2(const double P)
Get chi2 corresponding to given probability.
Definition: JFitToolkit.hh:80
void invert()
Invert matrix.
Definition: JMatrixNS.hh:61
3D match criterion with road width.
Definition: JMatch3B.hh:34
static bool JFIT::JMuonPrefit::cmz ( const JTRIGGER::JHitR1 first,
const JTRIGGER::JHitR1 second 
)
inlinestatic

Sort hits according times corrected for position along z-axis.

used as a predicate in std::partial_sort

Parameters
firstfirst hit
secondsecond hit
Returns
true if first hit earlier than second hit; else false

Definition at line 122 of file JMuonPrefit.hh.

124  {
125  return (first .getT() * JTOOLS::getSpeedOfLight() - first .getZ() <
126  second.getT() * JTOOLS::getSpeedOfLight() - second.getZ());
127  }
double getT() const
Get calibrated time of hit.
Definition: JHit.hh:143
const double getSpeedOfLight()
Number of bytes in a gigabyte.
Definition: JConstants.hh:89
double getZ() const
Get z position.
Definition: JVector3D.hh:113

Member Data Documentation

JLANG::JSharedPointer<const JDETECTOR::JModuleRouter> JFIT::JMuonPrefit::router_
private

Definition at line 56 of file JMuonPrefit.hh.

JFIT::JMuonPrefitParameters_t JFIT::JMuonPrefit::parameters_
private

Definition at line 57 of file JMuonPrefit.hh.

JGEOMETRY3D::JOmega3D JFIT::JMuonPrefit::omega_
private

Definition at line 58 of file JMuonPrefit.hh.


The documentation for this class was generated from the following file: