CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ChargeIsolationExtra.cc
Go to the documentation of this file.
8 
9 #include<iostream>
10 
11 namespace spr{
12 
13  double chargeIsolation(const edm::Event& iEvent, const edm::EventSetup& iSetup, CaloNavigator<DetId>& theNavigator, reco::TrackCollection::const_iterator trkItr, edm::Handle<reco::TrackCollection> trkCollection, const CaloSubdetectorGeometry* gEB, const CaloSubdetectorGeometry* gEE, TrackDetectorAssociator& associator, TrackAssociatorParameters& parameters_, int ieta, int iphi, std::string theTrackQuality, bool debug) {
14 
15  double maxNearP = -1.0;
17 
18  // const DetId anyCell,
19  reco::TrackCollection::const_iterator trkItr2;
20  for (trkItr2 = trkCollection->begin(); trkItr2 != trkCollection->end(); ++trkItr2) {
21 
22  const reco::Track* pTrack2 = &(*trkItr2);
23 
24  bool trkQuality = pTrack2->quality(trackQuality_);
25  if ( (trkItr2 != trkItr) && trkQuality ) {
26 
27  const FreeTrajectoryState fts2 = associator.getFreeTrajectoryState(iSetup, *pTrack2);
28  TrackDetMatchInfo info2 = associator.associate(iEvent, iSetup, fts2, parameters_);
29  const GlobalPoint point2(info2.trkGlobPosAtEcal.x(),info2.trkGlobPosAtEcal.y(),info2.trkGlobPosAtEcal.z());
30 
31  if (info2.isGoodEcal ) {
32  if (std::abs(point2.eta())<1.479) {
33  const DetId anyCell = gEB->getClosestCell(point2);
34  if (debug) std::cout << "chargeIsolation:: EB cell " << (EBDetId)(anyCell) << " for pt " << pTrack2->p() << std::endl;
35  if (!spr::chargeIsolation(anyCell,theNavigator,ieta, iphi)) {
36  if (maxNearP<pTrack2->p()) maxNearP=pTrack2->p();
37  }
38  } else {
39  const DetId anyCell = gEE->getClosestCell(point2);
40  if (debug) std::cout << "chargeIsolation:: EE cell " << (EEDetId)(anyCell) << " for pt " << pTrack2->p() << std::endl;
41  if(!spr::chargeIsolation(anyCell,theNavigator,ieta, iphi)) {
42  if (maxNearP<pTrack2->p()) maxNearP=pTrack2->p();
43  }
44  }
45  } //info2.isGoodEcal
46  }
47  }
48  return maxNearP;
49  }
50 
51  //===========================================================================================================
52 
53  bool chargeIsolation(const DetId anyCell,CaloNavigator<DetId>& navigator,int ieta,int iphi) {
54 
55  bool isIsolated = false;
56 
57  DetId thisDet;
58 
59  for (int dx = -ieta; dx < ieta+1; ++dx) {
60  for (int dy = -iphi; dy < iphi+1; ++dy) {
61 
62  thisDet = navigator.offsetBy(dx, dy);
63  navigator.home();
64 
65  if (thisDet != DetId(0)) {
66  if (thisDet == anyCell) {
67  isIsolated = false;
68  return isIsolated;
69  }
70  }
71  }
72  }
73  return isIsolated;
74  }
75 
76  //===========================================================================================================
77 
78  double chargeIsolationEcal(const edm::Event& iEvent, const edm::EventSetup& iSetup, const DetId& coreDet, reco::TrackCollection::const_iterator trkItr, edm::Handle<reco::TrackCollection> trkCollection, const CaloGeometry* geo, const CaloTopology* caloTopology, TrackDetectorAssociator& associator, TrackAssociatorParameters& parameters_, int ieta, int iphi, std::string& theTrackQuality, bool debug) {
79 
80  const EcalBarrelGeometry *barrelGeom = (dynamic_cast< const EcalBarrelGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalBarrel)));
81  const EcalEndcapGeometry *endcapGeom = (dynamic_cast< const EcalEndcapGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalEndcap)));
82 
83  std::vector<DetId> vdets = spr::matrixECALIds(coreDet, ieta, iphi, geo, caloTopology, debug);
84  if (debug) std::cout << "chargeIsolation:: eta/phi/dets " << ieta << " " << iphi << " " << vdets.size() << std::endl;
85 
86  double maxNearP = -1.0;
88 
89  // const DetId anyCell,
90  reco::TrackCollection::const_iterator trkItr2;
91  for (trkItr2 = trkCollection->begin(); trkItr2 != trkCollection->end(); ++trkItr2) {
92 
93  const reco::Track* pTrack2 = &(*trkItr2);
94 
95  bool trkQuality = pTrack2->quality(trackQuality_);
96  if ( (trkItr2 != trkItr) && trkQuality ) {
97 
98  const FreeTrajectoryState fts2 = associator.getFreeTrajectoryState(iSetup, *pTrack2);
99  TrackDetMatchInfo info2 = associator.associate(iEvent, iSetup, fts2, parameters_);
100  const GlobalPoint point2(info2.trkGlobPosAtEcal.x(),info2.trkGlobPosAtEcal.y(),info2.trkGlobPosAtEcal.z());
101 
102  if (info2.isGoodEcal ) {
103  if (std::abs(point2.eta())<1.479) {
104  const DetId anyCell = barrelGeom->getClosestCell(point2);
105  if (debug) std::cout << "chargeIsolation:: EB cell " << (EBDetId)(anyCell) << " for pt " << pTrack2->p() << std::endl;
106  if (!spr::chargeIsolation(anyCell,vdets)) {
107  if (maxNearP<pTrack2->p()) maxNearP=pTrack2->p();
108  }
109  } else {
110  const DetId anyCell = endcapGeom->getClosestCell(point2);
111  if (debug) std::cout << "chargeIsolation:: EE cell " << (EEDetId)(anyCell) << " for pt " << pTrack2->p() << std::endl;
112  if (!spr::chargeIsolation(anyCell,vdets)) {
113  if (maxNearP<pTrack2->p()) maxNearP=pTrack2->p();
114  }
115  }
116  } //info2.isGoodEcal
117  }
118  }
119  return maxNearP;
120  }
121 
122  //===========================================================================================================
123 
124  double chargeIsolationHcal(const edm::Event& iEvent, const edm::EventSetup& iSetup, reco::TrackCollection::const_iterator trkItr, edm::Handle<reco::TrackCollection> trkCollection, const DetId ClosestCell, const HcalTopology* topology, const CaloSubdetectorGeometry* gHB, TrackDetectorAssociator& associator, TrackAssociatorParameters& parameters_, int ieta, int iphi, std::string& theTrackQuality, bool debug) {
125 
126  std::vector<DetId> dets(1,ClosestCell);
127 
128  if (debug) std::cout << (HcalDetId) ClosestCell << std::endl;
129 
130  std::vector<DetId> vdets = spr::matrixHCALIds(dets, topology, ieta, iphi, false, debug);
131  std::vector<DetId>::iterator it;
132 
133  if (debug) {
134  for (unsigned int i=0; i<vdets.size(); i++) {
135  std::cout << "HcalDetId in " <<2*ieta+1 << "x" << 2*iphi+1 << " " << (HcalDetId) vdets[i] << std::endl;
136  }
137  }
138 
139  double maxNearP = -1.0;
140  reco::TrackBase::TrackQuality trackQuality_=reco::TrackBase::qualityByName(theTrackQuality);
141 
142  reco::TrackCollection::const_iterator trkItr2;
143  for (trkItr2 = trkCollection->begin(); trkItr2 != trkCollection->end(); ++trkItr2) {
144 
145  const reco::Track* pTrack2 = &(*trkItr2);
146 
147  bool trkQuality = pTrack2->quality(trackQuality_);
148  if ( (trkItr2 != trkItr) && trkQuality ) {
149  const FreeTrajectoryState fts2 = associator.getFreeTrajectoryState(iSetup, *pTrack2);
150  TrackDetMatchInfo info2 = associator.associate(iEvent, iSetup, fts2, parameters_);
151  const GlobalPoint point2(info2.trkGlobPosAtHcal.x(),info2.trkGlobPosAtHcal.y(),info2.trkGlobPosAtHcal.z());
152 
153  if (debug) {
154  std::cout << "Track2 (p,eta,phi) " << pTrack2->p() << " " << pTrack2->eta() << " " << pTrack2->phi() << std::endl;
155  }
156 
157  if (info2.isGoodHcal ) {
158  const DetId anyCell = gHB->getClosestCell(point2);
159  if (debug) std::cout << "chargeIsolation:: HCAL cell " << (HcalDetId)(anyCell) << " for pt " << pTrack2->p() << std::endl;
160  if (!spr::chargeIsolation(anyCell,vdets)) {
161  if(maxNearP<pTrack2->p()) maxNearP=pTrack2->p();
162  }
163  if (debug){
164  std::cout << "maxNearP " << maxNearP << " thisCell "
165  << (HcalDetId)anyCell << " ("
166  << info2.trkGlobPosAtHcal.x() << ","
167  << info2.trkGlobPosAtHcal.y() <<","
168  << info2.trkGlobPosAtHcal.z() <<")" << std::endl;
169  }
170  }
171  }
172  }
173  return maxNearP;
174  }
175 
176 }
virtual DetId getClosestCell(const GlobalPoint &r) const
double p() const
momentum vector magnitude
Definition: TrackBase.h:602
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
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:149
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:632
math::XYZPoint trkGlobPosAtHcal
T offsetBy(int deltaX, int deltaY) const
Free movement of arbitray steps.
Definition: CaloNavigator.h:80
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:638
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: DetId.h:18
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:123
#define debug
Definition: HDRShower.cc:19
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:497
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 &)
math::XYZPoint trkGlobPosAtEcal
Track position at different parts of the calorimeter.
tuple cout
Definition: gather_cfg.py:121
double chargeIsolationHcal(unsigned int trkIndex, std::vector< spr::propagatedTrackID > &vdetIds, const HcalTopology *topology, int ieta, int iphi, bool debug=false)