CMS 3D CMS Logo

ChargeIsolationExtra.cc
Go to the documentation of this file.
9 
10 #include <iostream>
11 
12 //#define EDM_ML_DEBUG
13 
14 namespace spr {
15 
17  const edm::EventSetup& iSetup,
18  CaloNavigator<DetId>& theNavigator,
19  reco::TrackCollection::const_iterator trkItr,
21  const CaloSubdetectorGeometry* gEB,
22  const CaloSubdetectorGeometry* gEE,
24  TrackAssociatorParameters& parameters_,
25  int ieta,
26  int iphi,
27  const std::string& theTrackQuality,
28  bool
29 #ifdef EDM_ML_DEBUG
30  debug
31 #endif
32  ) {
33 
34  double maxNearP = -1.0;
35  reco::TrackBase::TrackQuality trackQuality_ = reco::TrackBase::qualityByName(theTrackQuality);
36 
37  // const DetId anyCell,
38  reco::TrackCollection::const_iterator trkItr2;
39  for (trkItr2 = trkCollection->begin(); trkItr2 != trkCollection->end(); ++trkItr2) {
40  const reco::Track* pTrack2 = &(*trkItr2);
41 
42  bool trkQuality = pTrack2->quality(trackQuality_);
43  if ((trkItr2 != trkItr) && trkQuality) {
44  const FreeTrajectoryState fts2 = associator.getFreeTrajectoryState(iSetup, *pTrack2);
45  TrackDetMatchInfo info2 = associator.associate(iEvent, iSetup, fts2, parameters_);
46  const GlobalPoint point2(info2.trkGlobPosAtEcal.x(), info2.trkGlobPosAtEcal.y(), info2.trkGlobPosAtEcal.z());
47 
48  if (info2.isGoodEcal) {
49  if (std::abs(point2.eta()) < spr::etaBEEcal) {
50  const DetId anyCell = gEB->getClosestCell(point2);
51 #ifdef EDM_ML_DEBUG
52  if (debug)
53  std::cout << "chargeIsolation:: EB cell " << (EBDetId)(anyCell) << " for pt " << pTrack2->p()
54  << std::endl;
55 #endif
56  if (!spr::chargeIsolation(anyCell, theNavigator, ieta, iphi)) {
57  if (maxNearP < pTrack2->p())
58  maxNearP = pTrack2->p();
59  }
60  } else {
61  const DetId anyCell = gEE->getClosestCell(point2);
62 #ifdef EDM_ML_DEBUG
63  if (debug)
64  std::cout << "chargeIsolation:: EE cell " << (EEDetId)(anyCell) << " for pt " << pTrack2->p()
65  << std::endl;
66 #endif
67  if (!spr::chargeIsolation(anyCell, theNavigator, ieta, iphi)) {
68  if (maxNearP < pTrack2->p())
69  maxNearP = pTrack2->p();
70  }
71  }
72  } //info2.isGoodEcal
73  }
74  }
75  return maxNearP;
76  }
77 
78  //===========================================================================================================
79 
80  bool chargeIsolation(const DetId anyCell, CaloNavigator<DetId>& navigator, int ieta, int iphi) {
81  bool isIsolated = false;
82 
83  DetId thisDet;
84 
85  for (int dx = -ieta; dx < ieta + 1; ++dx) {
86  for (int dy = -iphi; dy < iphi + 1; ++dy) {
87  thisDet = navigator.offsetBy(dx, dy);
88  navigator.home();
89 
90  if (thisDet != DetId(0)) {
91  if (thisDet == anyCell) {
92  isIsolated = false;
93  return isIsolated;
94  }
95  }
96  }
97  }
98  return isIsolated;
99  }
100 
101  //===========================================================================================================
102 
104  const edm::EventSetup& iSetup,
105  const DetId& coreDet,
106  reco::TrackCollection::const_iterator trkItr,
108  const CaloGeometry* geo,
109  const CaloTopology* caloTopology,
111  TrackAssociatorParameters& parameters_,
112  int ieta,
113  int iphi,
114  const std::string& theTrackQuality,
115  bool debug) {
118 
119  std::vector<DetId> vdets = spr::matrixECALIds(coreDet, ieta, iphi, geo, caloTopology, debug);
120 #ifdef EDM_ML_DEBUG
121  if (debug)
122  std::cout << "chargeIsolation:: eta/phi/dets " << ieta << " " << iphi << " " << vdets.size() << std::endl;
123 #endif
124  double maxNearP = -1.0;
125  reco::TrackBase::TrackQuality trackQuality_ = reco::TrackBase::qualityByName(theTrackQuality);
126 
127  // const DetId anyCell,
128  reco::TrackCollection::const_iterator trkItr2;
129  for (trkItr2 = trkCollection->begin(); trkItr2 != trkCollection->end(); ++trkItr2) {
130  const reco::Track* pTrack2 = &(*trkItr2);
131 
132  bool trkQuality = pTrack2->quality(trackQuality_);
133  if ((trkItr2 != trkItr) && trkQuality) {
134  const FreeTrajectoryState fts2 = associator.getFreeTrajectoryState(iSetup, *pTrack2);
135  TrackDetMatchInfo info2 = associator.associate(iEvent, iSetup, fts2, parameters_);
136  const GlobalPoint point2(info2.trkGlobPosAtEcal.x(), info2.trkGlobPosAtEcal.y(), info2.trkGlobPosAtEcal.z());
137 
138  if (info2.isGoodEcal) {
139  if (std::abs(point2.eta()) < spr::etaBEEcal) {
140  const DetId anyCell = barrelGeom->getClosestCell(point2);
141 #ifdef EDM_ML_DEBUG
142  if (debug)
143  std::cout << "chargeIsolation:: EB cell " << (EBDetId)(anyCell) << " for pt " << pTrack2->p()
144  << std::endl;
145 #endif
146  if (!spr::chargeIsolation(anyCell, vdets)) {
147  if (maxNearP < pTrack2->p())
148  maxNearP = pTrack2->p();
149  }
150  } else {
151  const DetId anyCell = endcapGeom->getClosestCell(point2);
152 #ifdef EDM_ML_DEBUG
153  if (debug)
154  std::cout << "chargeIsolation:: EE cell " << (EEDetId)(anyCell) << " for pt " << pTrack2->p()
155  << std::endl;
156 #endif
157  if (!spr::chargeIsolation(anyCell, vdets)) {
158  if (maxNearP < pTrack2->p())
159  maxNearP = pTrack2->p();
160  }
161  }
162  } //info2.isGoodEcal
163  }
164  }
165  return maxNearP;
166  }
167 
168  //===========================================================================================================
169 
171  const edm::EventSetup& iSetup,
172  reco::TrackCollection::const_iterator trkItr,
174  const DetId ClosestCell,
175  const HcalTopology* topology,
176  const CaloSubdetectorGeometry* gHB,
178  TrackAssociatorParameters& parameters_,
179  int ieta,
180  int iphi,
181  const std::string& theTrackQuality,
182  bool debug) {
183  std::vector<DetId> dets(1, ClosestCell);
184 
185 #ifdef EDM_ML_DEBUG
186  if (debug)
187  std::cout << (HcalDetId)ClosestCell << std::endl;
188 #endif
189  std::vector<DetId> vdets = spr::matrixHCALIds(dets, topology, ieta, iphi, false, debug);
190 
191 #ifdef EDM_ML_DEBUG
192  if (debug) {
193  for (unsigned int i = 0; i < vdets.size(); i++) {
194  std::cout << "HcalDetId in " << 2 * ieta + 1 << "x" << 2 * iphi + 1 << " " << (HcalDetId)vdets[i] << std::endl;
195  }
196  }
197 #endif
198  double maxNearP = -1.0;
199  reco::TrackBase::TrackQuality trackQuality_ = reco::TrackBase::qualityByName(theTrackQuality);
200 
201  reco::TrackCollection::const_iterator trkItr2;
202  for (trkItr2 = trkCollection->begin(); trkItr2 != trkCollection->end(); ++trkItr2) {
203  const reco::Track* pTrack2 = &(*trkItr2);
204 
205  bool trkQuality = pTrack2->quality(trackQuality_);
206  if ((trkItr2 != trkItr) && trkQuality) {
207  const FreeTrajectoryState fts2 = associator.getFreeTrajectoryState(iSetup, *pTrack2);
208  TrackDetMatchInfo info2 = associator.associate(iEvent, iSetup, fts2, parameters_);
209  const GlobalPoint point2(info2.trkGlobPosAtHcal.x(), info2.trkGlobPosAtHcal.y(), info2.trkGlobPosAtHcal.z());
210 
211 #ifdef EDM_ML_DEBUG
212  if (debug) {
213  std::cout << "Track2 (p,eta,phi) " << pTrack2->p() << " " << pTrack2->eta() << " " << pTrack2->phi()
214  << std::endl;
215  }
216 #endif
217  if (info2.isGoodHcal) {
218  const DetId anyCell = gHB->getClosestCell(point2);
219 #ifdef EDM_ML_DEBUG
220  if (debug)
221  std::cout << "chargeIsolation:: HCAL cell " << (HcalDetId)(anyCell) << " for pt " << pTrack2->p()
222  << std::endl;
223 #endif
224  if (!spr::chargeIsolation(anyCell, vdets)) {
225  if (maxNearP < pTrack2->p())
226  maxNearP = pTrack2->p();
227  }
228 #ifdef EDM_ML_DEBUG
229  if (debug) {
230  std::cout << "maxNearP " << maxNearP << " thisCell " << (HcalDetId)anyCell << " ("
231  << info2.trkGlobPosAtHcal.x() << "," << info2.trkGlobPosAtHcal.y() << ","
232  << info2.trkGlobPosAtHcal.z() << ")" << std::endl;
233  }
234 #endif
235  }
236  }
237  }
238  return maxNearP;
239  }
240 
241 } // namespace spr
double p() const
momentum vector magnitude
Definition: TrackBase.h:599
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
static const double etaBEEcal
Definition: CaloConstants.h:12
CaloTopology const * topology(0)
void matrixECALIds(const DetId &det, int ieta, int iphi, const CaloGeometry *geo, const CaloTopology *caloTopology, std::vector< DetId > &vdets, bool debug=false, bool igNoreTransition=true)
bool chargeIsolation(const DetId anyCell, std::vector< DetId > &vdets)
TrackQuality
track quality
Definition: TrackBase.h:150
static FreeTrajectoryState getFreeTrajectoryState(const edm::EventSetup &, const reco::Track &)
get FreeTrajectoryState from different track representations
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:614
math::XYZPoint trkGlobPosAtHcal
T offsetBy(int deltaX, int deltaY) const
Free movement of arbitray steps.
Definition: CaloNavigator.h:67
double chargeIsolationEcal(unsigned int trkIndex, std::vector< spr::propagatedTrackID > &vdetIds, const CaloGeometry *geo, const CaloTopology *caloTopology, int ieta, int iphi, bool debug=false)
int iEvent
Definition: GenABIO.cc:224
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:617
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual DetId getClosestCell(const GlobalPoint &r) const
void home() const
move the navigator back to the starting point
Definition: CaloNavigator.h:97
Definition: DetId.h:17
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
#define debug
Definition: HDRShower.cc:19
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:531
std::vector< DetId > matrixHCALIds(std::vector< DetId > &dets, const HcalTopology *topology, int ieta, int iphi, bool includeHO=false, bool debug=false)
#define EDM_ML_DEBUG
TrackDetMatchInfo associate(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const AssociatorParameters &)
math::XYZPoint trkGlobPosAtEcal
Track position at different parts of the calorimeter.
double chargeIsolationHcal(unsigned int trkIndex, std::vector< spr::propagatedTrackID > &vdetIds, const HcalTopology *topology, int ieta, int iphi, bool debug=false)