CMS 3D CMS Logo

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