CMS 3D CMS Logo

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