CMS 3D CMS Logo

EgAmbiguityTools.cc
Go to the documentation of this file.
7 
8 #include <algorithm>
9 
10 using namespace edm;
11 using namespace std;
12 using namespace reco;
13 
14 namespace egamma {
15 
17  return (std::abs(e1.eSuperClusterOverP() - 1) < std::abs(e2.eSuperClusterOverP() - 1));
18  }
19 
21  // retreive first valid hit
22  int gsfHitCounter1 = 0;
23  for (auto const& elHit : e1.gsfTrack()->recHits()) {
24  if (elHit->isValid())
25  break;
26  gsfHitCounter1++;
27  }
28 
29  int gsfHitCounter2 = 0;
30  for (auto const& elHit : e2.gsfTrack()->recHits()) {
31  if (elHit->isValid())
32  break;
33  gsfHitCounter2++;
34  }
35 
36  uint32_t gsfHit1 = e1.gsfTrack()->hitPattern().getHitPattern(HitPattern::TRACK_HITS, gsfHitCounter1);
37  uint32_t gsfHit2 = e2.gsfTrack()->hitPattern().getHitPattern(HitPattern::TRACK_HITS, gsfHitCounter2);
38 
39  if (HitPattern::getSubStructure(gsfHit1) != HitPattern::getSubStructure(gsfHit2)) {
40  return (HitPattern::getSubStructure(gsfHit1) < HitPattern::getSubStructure(gsfHit2));
41  } else if (HitPattern::getLayer(gsfHit1) != HitPattern::getLayer(gsfHit2)) {
42  return (HitPattern::getLayer(gsfHit1) < HitPattern::getLayer(gsfHit2));
43  } else {
44  return isBetterElectron(e1, e2);
45  }
46  }
47 
48  int sharedHits(const GsfTrackRef& gsfTrackRef1, const GsfTrackRef& gsfTrackRef2) {
49  //get the Hit Pattern for the gsfTracks
50  HitPattern const& gsfHitPattern1 = gsfTrackRef1->hitPattern();
51  HitPattern const& gsfHitPattern2 = gsfTrackRef2->hitPattern();
52 
53  unsigned int shared = 0;
54 
55  int gsfHitCounter1 = 0;
56  for (trackingRecHit_iterator elHitsIt1 = gsfTrackRef1->recHitsBegin(); elHitsIt1 != gsfTrackRef1->recHitsEnd();
57  elHitsIt1++, gsfHitCounter1++) {
58  if (!(*elHitsIt1)->isValid()) {
59  //count only valid Hits
60  continue;
61  }
62  //if (gsfHitCounter1>1) continue; // test only the first hit of the track 1
63  uint32_t gsfHit = gsfHitPattern1.getHitPattern(HitPattern::TRACK_HITS, gsfHitCounter1);
64  if (!(HitPattern::pixelHitFilter(gsfHit) || HitPattern::stripTIBHitFilter(gsfHit) ||
65  HitPattern::stripTOBHitFilter(gsfHit) || HitPattern::stripTECHitFilter(gsfHit) ||
66  HitPattern::stripTIDHitFilter(gsfHit))) {
67  continue;
68  }
69 
70  int gsfHitsCounter2 = 0;
71  for (trackingRecHit_iterator gsfHitsIt2 = gsfTrackRef2->recHitsBegin(); gsfHitsIt2 != gsfTrackRef2->recHitsEnd();
72  gsfHitsIt2++, gsfHitsCounter2++) {
73  if (!(**gsfHitsIt2).isValid()) {
74  //count only valid Hits
75  continue;
76  }
77  uint32_t gsfHit2 = gsfHitPattern2.getHitPattern(HitPattern::TRACK_HITS, gsfHitsCounter2);
78  if (!(HitPattern::pixelHitFilter(gsfHit2) || HitPattern::stripTIBHitFilter(gsfHit2) ||
79  HitPattern::stripTOBHitFilter(gsfHit2) || HitPattern::stripTECHitFilter(gsfHit2) ||
80  HitPattern::stripTIDHitFilter(gsfHit2))) {
81  continue;
82  }
83  if ((*elHitsIt1)->sharesInput(&(**gsfHitsIt2), TrackingRecHit::some)) {
84  //if (comp.equals(&(**elHitsIt1),&(**gsfHitsIt2))) {
86  shared++;
87  }
88  } //gsfHits2 iterator
89  } //gsfHits1 iterator
90 
91  //std::cout << "[sharedHits] number of shared hits " << shared << std::endl;
92  return shared;
93  }
94 
95  int sharedDets(const GsfTrackRef& gsfTrackRef1, const GsfTrackRef& gsfTrackRef2) {
96  //get the Hit Pattern for the gsfTracks
97  const HitPattern& gsfHitPattern1 = gsfTrackRef1->hitPattern();
98  const HitPattern& gsfHitPattern2 = gsfTrackRef2->hitPattern();
99 
100  unsigned int shared = 0;
101 
102  int gsfHitCounter1 = 0;
103  for (trackingRecHit_iterator elHitsIt1 = gsfTrackRef1->recHitsBegin(); elHitsIt1 != gsfTrackRef1->recHitsEnd();
104  elHitsIt1++, gsfHitCounter1++) {
105  if (!((**elHitsIt1).isValid())) {
106  //count only valid Hits
107  continue;
108  }
109  //if (gsfHitCounter1>1) continue; // to test only the first hit of the track 1
110  uint32_t gsfHit = gsfHitPattern1.getHitPattern(HitPattern::TRACK_HITS, gsfHitCounter1);
111  if (!(HitPattern::pixelHitFilter(gsfHit) || HitPattern::stripTIBHitFilter(gsfHit) ||
112  HitPattern::stripTOBHitFilter(gsfHit) || HitPattern::stripTECHitFilter(gsfHit) ||
113  HitPattern::stripTIDHitFilter(gsfHit))) {
114  continue;
115  }
116 
117  int gsfHitsCounter2 = 0;
118  for (trackingRecHit_iterator gsfHitsIt2 = gsfTrackRef2->recHitsBegin(); gsfHitsIt2 != gsfTrackRef2->recHitsEnd();
119  gsfHitsIt2++, gsfHitsCounter2++) {
120  if (!((**gsfHitsIt2).isValid())) {
121  //count only valid Hits!
122  continue;
123  }
124 
125  uint32_t gsfHit2 = gsfHitPattern2.getHitPattern(HitPattern::TRACK_HITS, gsfHitsCounter2);
126  if (!(HitPattern::pixelHitFilter(gsfHit2) || HitPattern::stripTIBHitFilter(gsfHit2) ||
127  HitPattern::stripTOBHitFilter(gsfHit2) || HitPattern::stripTECHitFilter(gsfHit2) ||
128  HitPattern::stripTIDHitFilter(gsfHit2)))
129  continue;
130  if ((**elHitsIt1).geographicalId() == (**gsfHitsIt2).geographicalId())
131  shared++;
132  } //gsfHits2 iterator
133  } //gsfHits1 iterator
134 
135  //std::cout << "[sharedHits] number of shared dets " << shared << std::endl;
136  //return shared/min(gsfTrackRef1->numberOfValidHits(),gsfTrackRef2->numberOfValidHits());
137  return shared;
138  }
139 
140  float sharedEnergy(CaloCluster const& clu1,
141  CaloCluster const& clu2,
144  double fractionShared = 0;
145 
146  for (auto const& h1 : clu1.hitsAndFractions()) {
147  for (auto const& h2 : clu2.hitsAndFractions()) {
148  if (h1.first != h2.first)
149  continue;
150 
151  // here we have common Xtal id
153  if (h1.first.subdetId() == EcalBarrel) {
154  if ((itt = barrelRecHits.find(h1.first)) != barrelRecHits.end())
155  fractionShared += itt->energy();
156  } else if (h1.first.subdetId() == EcalEndcap) {
157  if ((itt = endcapRecHits.find(h1.first)) != endcapRecHits.end())
158  fractionShared += itt->energy();
159  }
160  }
161  }
162 
163  //std::cout << "[sharedEnergy] shared energy /min(energy1,energy2) " << fractionShared << std::endl;
164  return fractionShared;
165  }
166 
167  float sharedEnergy(SuperClusterRef const& sc1,
168  SuperClusterRef const& sc2,
171  double energyShared = 0;
172  for (CaloCluster_iterator icl1 = sc1->clustersBegin(); icl1 != sc1->clustersEnd(); icl1++) {
173  for (CaloCluster_iterator icl2 = sc2->clustersBegin(); icl2 != sc2->clustersEnd(); icl2++) {
174  energyShared += sharedEnergy(**icl1, **icl2, barrelRecHits, endcapRecHits);
175  }
176  }
177  return energyShared;
178  }
179 
180 } // namespace egamma
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:209
std::vector< EcalRecHit >::const_iterator const_iterator
float eSuperClusterOverP() const
Definition: GsfElectron.h:221
int sharedDets(reco::GsfTrackRef const &, reco::GsfTrackRef const &)
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
Definition: GsfElectron.h:156
bool isBetterElectron(reco::GsfElectron const &, reco::GsfElectron const &)
bool isInnermostElectron(reco::GsfElectron const &, reco::GsfElectron const &)
constexpr uint8_t getLayer(uint32_t detId)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
uint16_t getHitPattern(HitCategory category, int position) const
Definition: HitPattern.h:537
float sharedEnergy(reco::CaloCluster const &clu1, reco::CaloCluster const &clu2, EcalRecHitCollection const &barrelRecHits, EcalRecHitCollection const &endcapRecHits)
fixed size matrix
HLT enums.