Belle II Software  release-08-01-10
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/KLMHit2d.h>
14 
15 /* Basf2 headers. */
16 #include <framework/logging/Logger.h>
17 
18 using namespace Belle2;
19 using namespace CLHEP;
20 
23 {
24 }
25 
27  m_Fitter(fitter),
28  m_globalFit(false)
29 {
30 }
31 
34 {
35 }
36 
39 {
40  m_Fitter = fitter;
42 }
43 
45 bool BKLMTrackFinder::filter(const std::list<KLMHit2d*>& seed,
46  std::list<KLMHit2d*>& hits,
47  std::list<KLMHit2d*>& track)
48 {
49 
50  std::list<KLMHit2d*>::iterator i;
51 
52  track = seed;
53 
54  if (m_Fitter == 0) {
55  B2ERROR("BKLMTrackFinder: Fitter not registered");
56  return (false);
57  }
58 
59  m_Fitter->fit(track);//fit seed
60 
61  for (i = hits.begin(); i != hits.end(); ++i) {
62  if ((*i)->getSubdetector() != KLMElementNumbers::c_BKLM)
63  continue;
64 
65  // Prevent duplicate hits or hits on same layer
66  // no duplicate hit is alreday guaranteed and now we allow hits on same layer so the following is commented out
67  // bool skip = false;
68  // for (j = track.begin(); j != track.end(); ++j) {
69  // if ((*j)->getLayer() == (*i)->getLayer())
70  // skip = true;
71  // }
72  // if (skip == true)
73  // continue;
74 
75  if ((*i)->isOnStaTrack() == false) {
76  double error, sigma;
77  if (m_globalFit)
78  m_Fitter->globalDistanceToHit(*i, error, sigma);
79  else m_Fitter->distanceToHit(*i, error, sigma);
80  //B2INFO("BKLMTrackFinder" << " Error: " << error << " Sigma: " << sigma);
81  if (sigma < 5.0) {
82  track.push_back(*i);
83  }
84  }
85  }
86 
87  if (track.size() < 3)
88  return false;
89 
90  // Fit with new hits
91  double chisqr = m_Fitter->fit(track);
92  B2DEBUG(20, "BKLMTrackFinder:" << "ChiSqr: " << chisqr);
93 
94  // Do this the hard way to count each layer separately.
95  std::list<int> hitLayers;
96  for (i = track.begin(); i != track.end(); ++i) {
97  hitLayers.push_back((*i)->getLayer());
98  }
99  hitLayers.sort();
100  hitLayers.unique();
101 
102  int layers = (*(--hitLayers.end()) - * (hitLayers.begin()));
103  int noHits = hitLayers.size();
104 
105  if (noHits >= 4 && double(noHits) / double(layers) >= 0.75) {
106  return true;
107  } else {
108  return false;
109  }
110 }
bool filter(const std::list< KLMHit2d * > &seed, std::list< KLMHit2d * > &hits, std::list< KLMHit2d * > &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
double fit(std::list< KLMHit2d * > &listTrackPoint)
do fit and returns chi square of the fit.
double globalDistanceToHit(KLMHit2d *hit, double &error, double &sigma)
Distance from track to a hit in the global system.
double distanceToHit(KLMHit2d *hit, double &error, double &sigma)
Distance from track to a hit in the plane of the module.
void setGlobalFit(bool localOrGlobal)
set the fitting mode, local system or global system
Abstract base class for different kinds of events.