Belle II Software  release-06-01-15
BKLMTrackFinder.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 /* Own header. */
10 #include <klm/bklm/modules/bklmTracking/BKLMTrackFinder.h>
11 
12 /* KLM headers. */
13 #include <klm/dataobjects/bklm/BKLMHit2d.h>
14 
15 /* Belle 2 headers. */
16 #include <framework/logging/Logger.h>
17 
18 using namespace Belle2;
19 using namespace std;
20 using namespace CLHEP;
21 
24 {
25 }
26 
28  m_Fitter(fitter),
29  m_globalFit(false)
30 {
31 }
32 
35 {
36 }
37 
40 {
41  m_Fitter = fitter;
43 }
44 
46 bool BKLMTrackFinder::filter(const std::list<BKLMHit2d*>& seed,
47  std::list<BKLMHit2d*>& hits,
48  std::list<BKLMHit2d*>& track)
49 {
50 
51  std::list<BKLMHit2d*>::iterator i;
52 
53  track = seed;
54 
55  if (m_Fitter == 0) {
56  B2ERROR("BKLMTrackFinder: Fitter not registered");
57  return (false);
58  }
59 
60  m_Fitter->fit(track);//fit seed
61 
62  for (i = hits.begin(); i != hits.end(); ++i) {
63 
64  // Prevent duplicate hits or hits on same layer
65  // no duplicate hit is alreday guaranteed and now we allow hits on same layer so the following is commented out
66  // bool skip = false;
67  // for (j = track.begin(); j != track.end(); ++j) {
68  // if ((*j)->getLayer() == (*i)->getLayer())
69  // skip = true;
70  // }
71  // if (skip == true)
72  // continue;
73 
74  if ((*i)->isOnStaTrack() == false) {
75  double error, sigma;
76  if (m_globalFit)
77  m_Fitter->globalDistanceToHit(*i, error, sigma);
78  else m_Fitter->distanceToHit(*i, error, sigma);
79  //B2INFO("BKLMTrackFinder" << " Error: " << error << " Sigma: " << sigma);
80  if (sigma < 5.0) {
81  track.push_back(*i);
82  }
83  }
84  }
85 
86  if (track.size() < 3)
87  return false;
88 
89  // Fit with new hits
90  double chisqr = m_Fitter->fit(track);
91  B2DEBUG(20, "BKLMTrackFinder:" << "ChiSqr: " << chisqr);
92 
93  // Do this the hard way to count each layer separately.
94  std::list<int> hitLayers;
95  for (i = track.begin(); i != track.end(); ++i) {
96  hitLayers.push_back((*i)->getLayer());
97  }
98  hitLayers.sort();
99  hitLayers.unique();
100 
101  int layers = (*(--hitLayers.end()) - * (hitLayers.begin()));
102  int noHits = hitLayers.size();
103 
104  if (noHits >= 4 && double(noHits) / double(layers) >= 0.75) {
105  return true;
106  } else {
107  return false;
108  }
109 }
bool filter(const std::list< BKLMHit2d * > &seed, std::list< BKLMHit2d * > &hits, std::list< BKLMHit2d * > &track)
find associated hits and do fit.
void registerFitter(BKLMTrackFitter *fitter)
Register a fitter if not constructed with one.
bool m_globalFit
do fit in the local system or global system false: local sys; true: global sys.
BKLMTrackFinder()
Default constructor.
BKLMTrackFitter * m_Fitter
pointer to the fitter
track fitting procedure
void setGlobalFit(bool localOrGlobal)
set the fitting mode, local system or global system
double fit(std::list< BKLMHit2d * > &listTrackPoint)
do fit and returns chi square of the fit.
double distanceToHit(BKLMHit2d *hit, double &error, double &sigma)
Distance from track to a hit in the plane of the module.
double globalDistanceToHit(BKLMHit2d *hit, double &error, double &sigma)
Distance from track to a hit in the global system.
Abstract base class for different kinds of events.