CMS 3D CMS Logo

GsfElectronTools.cc
Go to the documentation of this file.
8 
9 namespace egamma {
10 
11  using namespace reco;
12 
13  //=======================================================================================
14  // Code from Puneeth Kalavase
15  //=======================================================================================
16 
17  std::pair<TrackRef, float> getClosestCtfToGsf(GsfTrackRef const& gsfTrackRef,
18  edm::Handle<reco::TrackCollection> const& ctfTracksH) {
19  float maxFracShared = 0;
20  TrackRef ctfTrackRef = TrackRef();
21  const TrackCollection* ctfTrackCollection = ctfTracksH.product();
22 
23  // get the Hit Pattern for the gsfTrack
24  const HitPattern& gsfHitPattern = gsfTrackRef->hitPattern();
25 
26  unsigned int counter = 0;
27  for (auto ctfTkIter = ctfTrackCollection->begin(); ctfTkIter != ctfTrackCollection->end(); ctfTkIter++, counter++) {
28  double dEta = gsfTrackRef->eta() - ctfTkIter->eta();
29  double dPhi = gsfTrackRef->phi() - ctfTkIter->phi();
30  double pi = acos(-1.);
31  if (std::abs(dPhi) > pi)
32  dPhi = 2 * pi - std::abs(dPhi);
33 
34  // dont want to look at every single track in the event!
35  if (sqrt(dEta * dEta + dPhi * dPhi) > 0.3)
36  continue;
37 
38  unsigned int shared = 0;
39  int gsfHitCounter = 0;
40  int numGsfInnerHits = 0;
41  int numCtfInnerHits = 0;
42  // get the CTF Track Hit Pattern
43  const HitPattern& ctfHitPattern = ctfTkIter->hitPattern();
44 
45  for (auto elHitsIt = gsfTrackRef->recHitsBegin(); elHitsIt != gsfTrackRef->recHitsEnd();
46  elHitsIt++, gsfHitCounter++) {
47  if (!((**elHitsIt).isValid())) //count only valid Hits
48  {
49  continue;
50  }
51 
52  // look only in the pixels/TIB/TID
53  uint32_t gsfHit = gsfHitPattern.getHitPattern(HitPattern::TRACK_HITS, gsfHitCounter);
56  continue;
57  }
58 
59  numGsfInnerHits++;
60 
61  int ctfHitsCounter = 0;
62  numCtfInnerHits = 0;
63  for (auto ctfHitsIt = ctfTkIter->recHitsBegin(); ctfHitsIt != ctfTkIter->recHitsEnd();
64  ctfHitsIt++, ctfHitsCounter++) {
65  if (!((**ctfHitsIt).isValid())) //count only valid Hits!
66  {
67  continue;
68  }
69 
70  uint32_t ctfHit = ctfHitPattern.getHitPattern(HitPattern::TRACK_HITS, ctfHitsCounter);
73  continue;
74  }
75 
76  numCtfInnerHits++;
77 
78  if ((**elHitsIt).sharesInput(&(**ctfHitsIt), TrackingRecHit::all)) {
79  shared++;
80  break;
81  }
82 
83  } //ctfHits iterator
84 
85  } //gsfHits iterator
86 
87  if ((numGsfInnerHits == 0) || (numCtfInnerHits == 0)) {
88  continue;
89  }
90 
91  if (static_cast<float>(shared) / std::min(numGsfInnerHits, numCtfInnerHits) > maxFracShared) {
92  maxFracShared = static_cast<float>(shared) / std::min(numGsfInnerHits, numCtfInnerHits);
93  ctfTrackRef = TrackRef(ctfTracksH, counter);
94  }
95 
96  } //ctfTrack iterator
97 
98  return make_pair(ctfTrackRef, maxFracShared);
99  }
100 
101 } // namespace egamma
static bool pixelHitFilter(uint16_t pattern)
Definition: HitPattern.h:574
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
const Double_t pi
uint16_t hitPattern[ARRAY_LENGTH]
Definition: HitPattern.h:491
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T min(T a, T b)
Definition: MathUtil.h:58
T const * product() const
Definition: Handle.h:69
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
static bool stripTIBHitFilter(uint16_t pattern)
Definition: HitPattern.h:609
fixed size matrix
std::pair< reco::TrackRef, float > getClosestCtfToGsf(reco::GsfTrackRef const &, edm::Handle< reco::TrackCollection > const &ctfTracksH)
uint16_t getHitPattern(HitCategory category, int position) const
Definition: HitPattern.h:531
static bool stripTIDHitFilter(uint16_t pattern)
Definition: HitPattern.h:613