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 
137 #ifdef EDM_ML_DEBUG
138  if (debug) {
139  for (unsigned int i=0; i<vdets.size(); i++) {
140  std::cout << "HcalDetId in " <<2*ieta+1 << "x" << 2*iphi+1 << " " << (HcalDetId) vdets[i] << std::endl;
141  }
142  }
143 #endif
144  double maxNearP = -1.0;
145  reco::TrackBase::TrackQuality trackQuality_=reco::TrackBase::qualityByName(theTrackQuality);
146 
147  reco::TrackCollection::const_iterator trkItr2;
148  for (trkItr2 = trkCollection->begin(); trkItr2 != trkCollection->end(); ++trkItr2) {
149 
150  const reco::Track* pTrack2 = &(*trkItr2);
151 
152  bool trkQuality = (trackQuality_ != reco::TrackBase::undefQuality) ?
153  (pTrack2->quality(trackQuality_)) : true;
154  if ( (trkItr2 != trkItr) && trkQuality ) {
155  std::pair<math::XYZPoint,bool> info = spr::propagateHCAL(pTrack2,bField);
156  const GlobalPoint point2(info.first.x(),info.first.y(),info.first.z());
157 
158 #ifdef EDM_ML_DEBUG
159  if (debug) {
160  std::cout << "Track2 (p,eta,phi) " << pTrack2->p() << " " << pTrack2->eta() << " " << pTrack2->phi() << std::endl;
161  }
162 #endif
163  if (info.second) {
164  const DetId anyCell = gHB->getClosestCell(point2);
165  if (!spr::chargeIsolation(anyCell,vdets)) {
166  if(maxNearP<pTrack2->p()) maxNearP=pTrack2->p();
167  }
168 #ifdef EDM_ML_DEBUG
169  if (debug){
170  std::cout << "maxNearP " << maxNearP << " thisCell "
171  << (HcalDetId)anyCell << " ("
172  << info.first.x() << "," << info.first.y() <<","
173  << info.first.z() << ")" << std::endl;
174  }
175 #endif
176  }
177  }
178  }
179  return maxNearP;
180  }
181 
182  bool chargeIsolation(const DetId anyCell, std::vector<DetId>& vdets) {
183  bool isIsolated = true;
184  for (unsigned int i=0; i<vdets.size(); i++){
185  if (anyCell == vdets[i] ) {
186  isIsolated = false;
187  break;
188  }
189  }
190  return isIsolated;
191  }
192 
193  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) {
194 
195  nNearTRKs=0;
196  nLayers_maxNearP=0;
197  trkQual_maxNearP=-1;
198  maxNearP_goodTrk = -999.0;
199  double maxNearP = -999.0;
200  reco::TrackBase::TrackQuality trackQuality_= reco::TrackBase::qualityByName(theTrackQuality);
201 
202  // Iterate over tracks
203  reco::TrackCollection::const_iterator trkItr2;
204  for( trkItr2 = trkCollection->begin();
205  trkItr2 != trkCollection->end(); ++trkItr2){
206 
207  // Get track
208  const reco::Track* pTrack2 = &(*trkItr2);
209 
210  // Get track qual, nlayers, and hit pattern
211  bool trkQuality = (trackQuality_ != reco::TrackBase::undefQuality) ?
212  (pTrack2->quality(trackQuality_)) : true;
213  if (trkQuality) trkQual_maxNearP = 1;
214  const reco::HitPattern& hitp = pTrack2->hitPattern();
215  nLayers_maxNearP = hitp.trackerLayersWithMeasurement() ;
216 
217  // Skip if the neighboring track candidate is the iso-track
218  // candidate
219  if (trkItr2 != trkItr) {
220 
221  // Get propagator
222  const FreeTrajectoryState fts2 = associator.getFreeTrajectoryState(iSetup, *pTrack2);
223  TrackDetMatchInfo info2 = associator.associate(iEvent, iSetup, fts2, parameters_);
224 
225  // Make sure it reaches Hcal
226  if (info2.isGoodHcal ) {
227 
228  const GlobalPoint point2(info2.trkGlobPosAtHcal.x(),
229  info2.trkGlobPosAtHcal.y(),
230  info2.trkGlobPosAtHcal.z());
231 
232  int isConeChargedIso = spr::coneChargeIsolation(hpoint1, point2, trackMom, dR);
233 
234  if (isConeChargedIso==0) {
235  nNearTRKs++;
236  if(maxNearP<pTrack2->p()) {
237  maxNearP=pTrack2->p();
238  if (trkQual_maxNearP>0 && nLayers_maxNearP>7 && maxNearP_goodTrk<pTrack2->p()) {
239  maxNearP_goodTrk=pTrack2->p();
240  }
241  }
242  }
243  }
244  }
245  } // Iterate over track loop
246 
247  return maxNearP;
248  }
249 
250  double chargeIsolationCone(unsigned int trkIndex, std::vector<spr::propagatedTrackDirection> & trkDirs, double dR, int & nNearTRKs, bool debug) {
251 
252  double maxNearP = -1.0;
253  nNearTRKs = 0;
254  if (trkDirs[trkIndex].okHCAL) {
255 #ifdef EDM_ML_DEBUG
256  if (debug) std::cout << "chargeIsolationCone with " << trkDirs.size() << " tracks " << std::endl;
257 #endif
258  for (unsigned int indx=0; indx<trkDirs.size(); ++indx) {
259  if (indx != trkIndex && trkDirs[indx].ok && trkDirs[indx].okHCAL) {
260  int isConeChargedIso = spr::coneChargeIsolation(trkDirs[trkIndex].pointHCAL, trkDirs[indx].pointHCAL, trkDirs[trkIndex].directionHCAL, dR);
261  if (isConeChargedIso==0) {
262  nNearTRKs++;
263  const reco::Track* pTrack = &(*(trkDirs[indx].trkItr));
264  if (maxNearP < pTrack->p()) maxNearP = pTrack->p();
265  }
266  }
267  }
268  }
269 #ifdef EDM_ML_DEBUG
270  if (debug) std::cout << "chargeIsolationCone Track " << trkDirs[trkIndex].okHCAL << " maxNearP " << maxNearP << std::endl;
271 #endif
272  return maxNearP;
273  }
274 
275  std::pair<double,double> chargeIsolationCone(unsigned int trkIndex, std::vector<spr::propagatedTrackDirection> & trkDirs, double dR, bool debug) {
276 
277  double maxNearP = -1.0;
278  double sumP = 0;
279  if (trkDirs[trkIndex].okHCAL) {
280 #ifdef EDM_ML_DEBUG
281  if (debug) std::cout << "chargeIsolationCone with " << trkDirs.size() << " tracks " << std::endl;
282 #endif
283  for (unsigned int indx=0; indx<trkDirs.size(); ++indx) {
284  if (indx != trkIndex && trkDirs[indx].ok && trkDirs[indx].okHCAL) {
285  int isConeChargedIso = spr::coneChargeIsolation(trkDirs[trkIndex].pointHCAL, trkDirs[indx].pointHCAL, trkDirs[trkIndex].directionHCAL, dR);
286  if (isConeChargedIso==0) {
287  const reco::Track* pTrack = &(*(trkDirs[indx].trkItr));
288  sumP += (pTrack->p());
289  if (maxNearP < pTrack->p()) maxNearP = pTrack->p();
290  }
291  }
292  }
293  }
294 #ifdef EDM_ML_DEBUG
295  if (debug) std::cout << "chargeIsolationCone Track " << trkDirs[trkIndex].okHCAL << " maxNearP " << maxNearP << ":" << sumP <<std::endl;
296 #endif
297  return std::pair<double,double>(maxNearP,sumP);
298  }
299 
300  int coneChargeIsolation(const GlobalPoint& hpoint1, const GlobalPoint& point2, const GlobalVector& trackMom, double dR) {
301 
302  int isIsolated = 1;
303  if (spr::getDistInPlaneTrackDir(hpoint1, trackMom, point2) > dR) isIsolated = 1;
304  else isIsolated = 0;
305  return isIsolated;
306  }
307 
308 }
double p() const
momentum vector magnitude
Definition: TrackBase.h:648
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:678
double chargeIsolationCone(unsigned int trkIndex, std::vector< spr::propagatedTrackDirection > &trkDirs, double dR, int &nNearTRKs, bool debug=false)
int trackerLayersWithMeasurement() const
Definition: HitPattern.cc:557
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:224
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:684
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:134
#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:479
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:543
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)