CMS 3D CMS Logo

ChargeIsolation.cc
Go to the documentation of this file.
8 
9 #include<iostream>
10 
11 //#define EDM_ML_DEBUG
12 
13 namespace spr{
14 
15  double chargeIsolationEcal(unsigned int trkIndex, std::vector<spr::propagatedTrackID>& vdetIds, const CaloGeometry* geo, const CaloTopology* caloTopology, int ieta, int iphi, bool debug) {
16 
17  const DetId coreDet = vdetIds[trkIndex].detIdECAL;
18 #ifdef EDM_ML_DEBUG
19  if (debug) {
20  if (coreDet.subdetId() == EcalBarrel)
21  std::cout << "DetId " << (EBDetId)(coreDet) << " Flag " << vdetIds[trkIndex].okECAL << std::endl;
22  else
23  std::cout << "DetId " << (EEDetId)(coreDet) << " Flag " << vdetIds[trkIndex].okECAL << std::endl;
24  }
25 #endif
26  double maxNearP = -1.0;
27  if (vdetIds[trkIndex].okECAL) {
28  std::vector<DetId> vdets = spr::matrixECALIds(coreDet, ieta, iphi, geo, caloTopology, debug);
29 #ifdef EDM_ML_DEBUG
30  if (debug) std::cout << "chargeIsolationEcal:: eta/phi/dets " << ieta << " " << iphi << " " << vdets.size() << std::endl;
31 #endif
32 
33  for (unsigned int indx=0; indx<vdetIds.size(); ++indx) {
34  if (indx != trkIndex && vdetIds[indx].ok && vdetIds[indx].okECAL) {
35  const DetId anyCell = vdetIds[indx].detIdECAL;
36  if (!spr::chargeIsolation(anyCell,vdets)) {
37  const reco::Track* pTrack = &(*(vdetIds[indx].trkItr));
38  if (maxNearP < pTrack->p()) maxNearP = pTrack->p();
39  }
40  }
41  }
42  }
43  return maxNearP;
44  }
45 
46  double chargeIsolationEcal(const DetId& coreDet, reco::TrackCollection::const_iterator trkItr, edm::Handle<reco::TrackCollection> trkCollection, const CaloGeometry* geo, const CaloTopology* caloTopology, const MagneticField* bField, int ieta, int iphi, const std::string& theTrackQuality, bool debug) {
47 
50 
51  std::vector<DetId> vdets = spr::matrixECALIds(coreDet, ieta, iphi, geo, caloTopology, debug);
52 #ifdef EDM_ML_DEBUG
53  if (debug) std::cout << "chargeIsolation:: eta/phi/dets " << ieta << " " << iphi << " " << vdets.size() << std::endl;
54 #endif
55  double maxNearP = -1.0;
57 
58  // const DetId anyCell,
59  reco::TrackCollection::const_iterator trkItr2;
60  for (trkItr2 = trkCollection->begin(); trkItr2 != trkCollection->end(); ++trkItr2) {
61 
62  const reco::Track* pTrack2 = &(*trkItr2);
63 
64  bool trkQuality = (trackQuality_ != reco::TrackBase::undefQuality) ?
65  (pTrack2->quality(trackQuality_)) : true;
66  if ( (trkItr2 != trkItr) && trkQuality ) {
67 
68  std::pair<math::XYZPoint,bool> info = spr::propagateECAL(pTrack2,bField);
69  const GlobalPoint point2(info.first.x(),info.first.y(),info.first.z());
70 
71  if (info.second) {
72  if (std::abs(point2.eta())<spr::etaBEEcal) {
73  const DetId anyCell = barrelGeom->getClosestCell(point2);
74  if (!spr::chargeIsolation(anyCell,vdets)) {
75 #ifdef EDM_ML_DEBUG
76  if (debug) std::cout << "chargeIsolationEcal Cell " << (EBDetId)(anyCell) << " pt " << pTrack2->p() << std::endl;
77 #endif
78  if (maxNearP<pTrack2->p()) maxNearP=pTrack2->p();
79  }
80  } else {
81  if (endcapGeom) {
82  const DetId anyCell = endcapGeom->getClosestCell(point2);
83  if (!spr::chargeIsolation(anyCell,vdets)) {
84 #ifdef EDM_ML_DEBUG
85  if (debug) std::cout << "chargeIsolationEcal Cell " << (EEDetId)(anyCell) << " pt " << pTrack2->p() << std::endl;
86 #endif
87  if (maxNearP<pTrack2->p()) maxNearP=pTrack2->p();
88  }
89  }
90  }
91  } //info.second
92  }
93  }
94  return maxNearP;
95  }
96 
97  double chargeIsolationHcal(unsigned int trkIndex, std::vector<spr::propagatedTrackID> & vdetIds, const HcalTopology* topology, int ieta, int iphi, bool debug) {
98 
99  std::vector<DetId> dets(1,vdetIds[trkIndex].detIdHCAL);
100 #ifdef EDM_ML_DEBUG
101  if (debug) {
102  std::cout << "DetId " << (HcalDetId)(dets[0]) << " Flag " << vdetIds[trkIndex].okHCAL << std::endl;
103  }
104 #endif
105  double maxNearP = -1.0;
106  if (vdetIds[trkIndex].okHCAL) {
107  std::vector<DetId> vdets = spr::matrixHCALIds(dets, topology, ieta, iphi, false, debug);
108 #ifdef EDM_ML_DEBUG
109  if (debug) std::cout << "chargeIsolationHcal:: eta/phi/dets " << ieta << " " << iphi << " " << vdets.size() << std::endl;
110 #endif
111  for (unsigned indx = 0; indx<vdetIds.size(); ++indx) {
112  if (indx != trkIndex && vdetIds[indx].ok && vdetIds[indx].okHCAL) {
113  const DetId anyCell = vdetIds[indx].detIdHCAL;
114  if (!spr::chargeIsolation(anyCell,vdets)) {
115  const reco::Track* pTrack = &(*(vdetIds[indx].trkItr));
116 #ifdef EDM_ML_DEBUG
117  if (debug) std::cout << "chargeIsolationHcal Cell " << (HcalDetId)(anyCell) << " pt " << pTrack->p() << std::endl;
118 #endif
119  if (maxNearP < pTrack->p()) maxNearP = pTrack->p();
120  }
121  }
122  }
123  }
124  return maxNearP;
125  }
126 
127  //===========================================================================================================
128 
129  double chargeIsolationHcal(reco::TrackCollection::const_iterator trkItr, edm::Handle<reco::TrackCollection> trkCollection, const DetId ClosestCell, const HcalTopology* topology, const CaloSubdetectorGeometry* gHB, const MagneticField* bField, int ieta, int iphi, const std::string& theTrackQuality, bool debug) {
130 
131  std::vector<DetId> dets(1,ClosestCell);
132 #ifdef EDM_ML_DEBUG
133  if (debug) std::cout << (HcalDetId) ClosestCell << std::endl;
134 #endif
135  std::vector<DetId> vdets = spr::matrixHCALIds(dets, topology, ieta, iphi, false, debug);
136  std::vector<DetId>::iterator it;
137 
138 #ifdef EDM_ML_DEBUG
139  if (debug) {
140  for (unsigned int i=0; i<vdets.size(); i++) {
141  std::cout << "HcalDetId in " <<2*ieta+1 << "x" << 2*iphi+1 << " " << (HcalDetId) vdets[i] << std::endl;
142  }
143  }
144 #endif
145  double maxNearP = -1.0;
146  reco::TrackBase::TrackQuality trackQuality_=reco::TrackBase::qualityByName(theTrackQuality);
147 
148  reco::TrackCollection::const_iterator trkItr2;
149  for (trkItr2 = trkCollection->begin(); trkItr2 != trkCollection->end(); ++trkItr2) {
150 
151  const reco::Track* pTrack2 = &(*trkItr2);
152 
153  bool trkQuality = (trackQuality_ != reco::TrackBase::undefQuality) ?
154  (pTrack2->quality(trackQuality_)) : true;
155  if ( (trkItr2 != trkItr) && trkQuality ) {
156  std::pair<math::XYZPoint,bool> info = spr::propagateHCAL(pTrack2,bField);
157  const GlobalPoint point2(info.first.x(),info.first.y(),info.first.z());
158 
159 #ifdef EDM_ML_DEBUG
160  if (debug) {
161  std::cout << "Track2 (p,eta,phi) " << pTrack2->p() << " " << pTrack2->eta() << " " << pTrack2->phi() << std::endl;
162  }
163 #endif
164  if (info.second) {
165  const DetId anyCell = gHB->getClosestCell(point2);
166  if (!spr::chargeIsolation(anyCell,vdets)) {
167  if(maxNearP<pTrack2->p()) maxNearP=pTrack2->p();
168  }
169 #ifdef EDM_ML_DEBUG
170  if (debug){
171  std::cout << "maxNearP " << maxNearP << " thisCell "
172  << (HcalDetId)anyCell << " ("
173  << info.first.x() << "," << info.first.y() <<","
174  << info.first.z() << ")" << std::endl;
175  }
176 #endif
177  }
178  }
179  }
180  return maxNearP;
181  }
182 
183  bool chargeIsolation(const DetId anyCell, std::vector<DetId>& vdets) {
184  bool isIsolated = true;
185  for (unsigned int i=0; i<vdets.size(); i++){
186  if (anyCell == vdets[i] ) {
187  isIsolated = false;
188  break;
189  }
190  }
191  return isIsolated;
192  }
193 
194  double coneChargeIsolation(const edm::Event& iEvent, const edm::EventSetup& iSetup, reco::TrackCollection::const_iterator trkItr, edm::Handle<reco::TrackCollection> trkCollection, TrackDetectorAssociator& associator, TrackAssociatorParameters& parameters_, const std::string & theTrackQuality, int &nNearTRKs, int &nLayers_maxNearP, int &trkQual_maxNearP, double &maxNearP_goodTrk, const GlobalPoint& hpoint1, const GlobalVector& trackMom, double dR) {
195 
196  nNearTRKs=0;
197  nLayers_maxNearP=0;
198  trkQual_maxNearP=-1;
199  maxNearP_goodTrk = -999.0;
200  double maxNearP = -999.0;
201  reco::TrackBase::TrackQuality trackQuality_= reco::TrackBase::qualityByName(theTrackQuality);
202 
203  // Iterate over tracks
204  reco::TrackCollection::const_iterator trkItr2;
205  for( trkItr2 = trkCollection->begin();
206  trkItr2 != trkCollection->end(); ++trkItr2){
207 
208  // Get track
209  const reco::Track* pTrack2 = &(*trkItr2);
210 
211  // Get track qual, nlayers, and hit pattern
212  bool trkQuality = (trackQuality_ != reco::TrackBase::undefQuality) ?
213  (pTrack2->quality(trackQuality_)) : true;
214  if (trkQuality) trkQual_maxNearP = 1;
215  const reco::HitPattern& hitp = pTrack2->hitPattern();
216  nLayers_maxNearP = hitp.trackerLayersWithMeasurement() ;
217 
218  // Skip if the neighboring track candidate is the iso-track
219  // candidate
220  if (trkItr2 != trkItr) {
221 
222  // Get propagator
223  const FreeTrajectoryState fts2 = associator.getFreeTrajectoryState(iSetup, *pTrack2);
224  TrackDetMatchInfo info2 = associator.associate(iEvent, iSetup, fts2, parameters_);
225 
226  // Make sure it reaches Hcal
227  if (info2.isGoodHcal ) {
228 
229  const GlobalPoint point2(info2.trkGlobPosAtHcal.x(),
230  info2.trkGlobPosAtHcal.y(),
231  info2.trkGlobPosAtHcal.z());
232 
233  int isConeChargedIso = spr::coneChargeIsolation(hpoint1, point2, trackMom, dR);
234 
235  if (isConeChargedIso==0) {
236  nNearTRKs++;
237  if(maxNearP<pTrack2->p()) {
238  maxNearP=pTrack2->p();
239  if (trkQual_maxNearP>0 && nLayers_maxNearP>7 && maxNearP_goodTrk<pTrack2->p()) {
240  maxNearP_goodTrk=pTrack2->p();
241  }
242  }
243  }
244  }
245  }
246  } // Iterate over track loop
247 
248  return maxNearP;
249  }
250 
251  double chargeIsolationCone(unsigned int trkIndex, std::vector<spr::propagatedTrackDirection> & trkDirs, double dR, int & nNearTRKs, bool debug) {
252 
253  double maxNearP = -1.0;
254  nNearTRKs = 0;
255  if (trkDirs[trkIndex].okHCAL) {
256 #ifdef EDM_ML_DEBUG
257  if (debug) std::cout << "chargeIsolationCone with " << trkDirs.size() << " tracks " << std::endl;
258 #endif
259  for (unsigned int indx=0; indx<trkDirs.size(); ++indx) {
260  if (indx != trkIndex && trkDirs[indx].ok && trkDirs[indx].okHCAL) {
261  int isConeChargedIso = spr::coneChargeIsolation(trkDirs[trkIndex].pointHCAL, trkDirs[indx].pointHCAL, trkDirs[trkIndex].directionHCAL, dR);
262  if (isConeChargedIso==0) {
263  nNearTRKs++;
264  const reco::Track* pTrack = &(*(trkDirs[indx].trkItr));
265  if (maxNearP < pTrack->p()) maxNearP = pTrack->p();
266  }
267  }
268  }
269  }
270 #ifdef EDM_ML_DEBUG
271  if (debug) std::cout << "chargeIsolationCone Track " << trkDirs[trkIndex].okHCAL << " maxNearP " << maxNearP << std::endl;
272 #endif
273  return maxNearP;
274  }
275 
276  std::pair<double,double> chargeIsolationCone(unsigned int trkIndex, std::vector<spr::propagatedTrackDirection> & trkDirs, double dR, bool debug) {
277 
278  double maxNearP = -1.0;
279  double sumP = 0;
280  if (trkDirs[trkIndex].okHCAL) {
281 #ifdef EDM_ML_DEBUG
282  if (debug) std::cout << "chargeIsolationCone with " << trkDirs.size() << " tracks " << std::endl;
283 #endif
284  for (unsigned int indx=0; indx<trkDirs.size(); ++indx) {
285  if (indx != trkIndex && trkDirs[indx].ok && trkDirs[indx].okHCAL) {
286  int isConeChargedIso = spr::coneChargeIsolation(trkDirs[trkIndex].pointHCAL, trkDirs[indx].pointHCAL, trkDirs[trkIndex].directionHCAL, dR);
287  if (isConeChargedIso==0) {
288  const reco::Track* pTrack = &(*(trkDirs[indx].trkItr));
289  sumP += (pTrack->p());
290  if (maxNearP < pTrack->p()) maxNearP = pTrack->p();
291  }
292  }
293  }
294  }
295 #ifdef EDM_ML_DEBUG
296  if (debug) std::cout << "chargeIsolationCone Track " << trkDirs[trkIndex].okHCAL << " maxNearP " << maxNearP << ":" << sumP <<std::endl;
297 #endif
298  return std::pair<double,double>(maxNearP,sumP);
299  }
300 
301  int coneChargeIsolation(const GlobalPoint& hpoint1, const GlobalPoint& point2, const GlobalVector& trackMom, double dR) {
302 
303  int isIsolated = 1;
304  if (spr::getDistInPlaneTrackDir(hpoint1, trackMom, point2) > dR) isIsolated = 1;
305  else isIsolated = 0;
306  return isIsolated;
307  }
308 
309 }
double p() const
momentum vector magnitude
Definition: TrackBase.h:615
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:49
double coneChargeIsolation(const edm::Event &iEvent, const edm::EventSetup &iSetup, reco::TrackCollection::const_iterator trkItr, edm::Handle< reco::TrackCollection > trkCollection, TrackDetectorAssociator &associator, TrackAssociatorParameters &parameters_, const std::string &theTrackQuality, int &nNearTRKs, int &nLayers_maxNearP, int &trkQual_maxNearP, double &maxNearP_goodTrk, const GlobalPoint &hpoint1, const GlobalVector &trackMom, double dR)
static const double etaBEEcal
Definition: CaloConstants.h:12
static const TGPicture * info(bool iBackgroundIsBlack)
double getDistInPlaneTrackDir(const GlobalPoint &caloPoint, const GlobalVector &caloVector, const GlobalPoint &rechitPoint, bool debug=false)
Definition: FindDistCone.cc: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:151
std::pair< math::XYZPoint, bool > propagateHCAL(const reco::Track *, const MagneticField *, bool debug=false)
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:645
double chargeIsolationCone(unsigned int trkIndex, std::vector< spr::propagatedTrackDirection > &trkDirs, double dR, int &nNearTRKs, bool debug=false)
int trackerLayersWithMeasurement() const
Definition: HitPattern.cc:520
math::XYZPoint trkGlobPosAtHcal
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:230
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:651
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::pair< math::XYZPoint, bool > propagateECAL(const reco::Track *, const MagneticField *, bool debug=false)
virtual DetId getClosestCell(const GlobalPoint &r) const
Definition: DetId.h:18
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:125
#define debug
Definition: HDRShower.cc:19
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:446
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:510
std::vector< DetId > matrixHCALIds(std::vector< DetId > &dets, const HcalTopology *topology, int ieta, int iphi, bool includeHO=false, bool debug=false)
TrackDetMatchInfo associate(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const AssociatorParameters &)
double chargeIsolationHcal(unsigned int trkIndex, std::vector< spr::propagatedTrackID > &vdetIds, const HcalTopology *topology, int ieta, int iphi, bool debug=false)