CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EleTkIsolFromCands.cc
Go to the documentation of this file.
2 
5 
7 {
8  minPt = para.getParameter<double>("minPt");
9  auto sq = [](double val){return val*val;};
10  minDR2 = sq(para.getParameter<double>("minDR"));
11  maxDR2 = sq(para.getParameter<double>("maxDR"));
12  minDEta = para.getParameter<double>("minDEta");
13  maxDZ = para.getParameter<double>("maxDZ");
14  minHits = para.getParameter<int>("minHits");
15  minPixelHits = para.getParameter<int>("minPixelHits");
16  maxDPtPt = para.getParameter<double>("maxDPtPt");
17 
18  auto qualNames = para.getParameter<std::vector<std::string> >("allowedQualities");
19  auto algoNames = para.getParameter<std::vector<std::string> >("algosToReject");
20 
21  for(auto& qualName : qualNames){
23  }
24  for(auto& algoName : algoNames){
25  algosToReject.push_back(reco::TrackBase::algoByName(algoName));
26  }
27  std::sort(algosToReject.begin(),algosToReject.end());
28 
29 }
30 
32 {
34  desc.add<double>("minPt",1.0);
35  desc.add<double>("maxDR",0.3);
36  desc.add<double>("minDR",0.000);
37  desc.add<double>("minDEta",0.005);
38  desc.add<double>("maxDZ",0.1);
39  desc.add<double>("maxDPtPt",-1);
40  desc.add<int>("minHits",8);
41  desc.add<int>("minPixelHits",1);
42  desc.add<std::vector<std::string> >("allowedQualities");
43  desc.add<std::vector<std::string> >("algosToReject");
44  return desc;
45 }
46 
48  barrelCuts_(para.getParameter<edm::ParameterSet>("barrelCuts")),
49  endcapCuts_(para.getParameter<edm::ParameterSet>("endcapCuts"))
50 {
51 
52 
53 }
54 
56 {
58  desc.add("barrelCuts",TrkCuts::pSetDescript());
59  desc.add("endcapCuts",TrkCuts::pSetDescript());
60  return desc;
61 }
62 
63 std::pair<int,double>
65  const pat::PackedCandidateCollection& cands,
66  const edm::View<reco::GsfElectron>& eles)
67 {
68  return calIsol(eleTrk.eta(),eleTrk.phi(),eleTrk.vz(),cands,eles);
69 }
70 
71 std::pair<int,double>
72 EleTkIsolFromCands::calIsol(const double eleEta,const double elePhi,
73  const double eleVZ,
74  const pat::PackedCandidateCollection& cands,
75  const edm::View<reco::GsfElectron>& eles)
76 {
77 
78  double ptSum=0.;
79  int nrTrks=0;
80 
81  const TrkCuts& cuts = std::abs(eleEta)<1.5 ? barrelCuts_ : endcapCuts_;
82 
83  for(auto& cand : cands){
84  if(cand.charge()!=0){
85  const reco::Track& trk = cand.pseudoTrack();
86  double trkPt = std::abs(cand.pdgId())!=11 ? trk.pt() : getTrkPt(trk,eles);
87  if(passTrkSel(trk,trkPt,cuts,eleEta,elePhi,eleVZ)){
88  ptSum+=trkPt;
89  nrTrks++;
90  }
91  }
92  }
93  return {nrTrks,ptSum};
94 }
95 
96 
98  const double trkPt,const TrkCuts& cuts,
99  const double eleEta,const double elePhi,
100  const double eleVZ)
101 {
102  const float dR2 = reco::deltaR2(eleEta,elePhi,trk.eta(),trk.phi());
103  const float dEta = trk.eta()-eleEta;
104  const float dZ = eleVZ - trk.vz();
105 
106  return dR2>=cuts.minDR2 && dR2<=cuts.maxDR2 &&
107  std::abs(dEta)>=cuts.minDEta &&
108  std::abs(dZ)<cuts.maxDZ &&
109  trk.hitPattern().numberOfValidHits() >= cuts.minHits &&
111  (trk.ptError()/trkPt < cuts.maxDPtPt || cuts.maxDPtPt<0) &&
112  passQual(trk,cuts.allowedQualities) &&
113  passAlgo(trk,cuts.algosToReject) &&
114  trkPt > cuts.minPt;
115 }
116 
117 
118 
121  const std::vector<reco::TrackBase::TrackQuality>& quals)
122 {
123  if(quals.empty()) return true;
124 
125  for(auto qual : quals) {
126  if(trk.quality(qual)) return true;
127  }
128 
129  return false;
130 }
131 
134  const std::vector<reco::TrackBase::TrackAlgorithm>& algosToRej)
135 {
136  return algosToRej.empty() || !std::binary_search(algosToRej.begin(),algosToRej.end(),trk.algo());
137 }
138 
139 //so the working theory here is that the track we have is the electrons gsf track
140 //if so, lets get the pt of the gsf track before E/p combinations
141 //if no match found to a gsf ele with a gsftrack, return the pt of the input track
144  const edm::View<reco::GsfElectron>& eles)
145 {
146  //note, the trk.eta(),trk.phi() should be identical to the gsf track eta,phi
147  //although this may not be the case due to roundings after packing
148  auto match=[](const reco::TrackBase& trk,const reco::GsfElectron& ele){
149  return std::abs(trk.eta()-ele.gsfTrack()->eta())<0.001 &&
150  reco::deltaPhi(trk.phi(),ele.gsfTrack()->phi())<0.001;// &&
151  };
152  for(auto& ele : eles){
153  if(ele.gsfTrack().isNonnull()){
154  if(match(trk,ele)){
155  return ele.gsfTrack()->pt();
156  }
157  }
158  }
159  return trk.pt();
160 
161 }
T getParameter(std::string const &) const
TrkCuts(const edm::ParameterSet &para)
static bool passTrkSel(const reco::Track &trk, const double trkPt, const TrkCuts &cuts, const double eleEta, const double elePhi, const double eleVZ)
std::pair< int, double > calIsol(const reco::TrackBase &trk, const pat::PackedCandidateCollection &cands, const edm::View< reco::GsfElectron > &eles)
int numberOfValidHits() const
Definition: HitPattern.h:823
static edm::ParameterSetDescription pSetDescript()
std::vector< pat::PackedCandidate > PackedCandidateCollection
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:640
static bool passAlgo(const reco::TrackBase &trk, const std::vector< reco::TrackBase::TrackAlgorithm > &algosToRej)
std::vector< reco::TrackBase::TrackQuality > allowedQualities
TrackAlgorithm algo() const
Definition: TrackBase.h:492
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:646
std::vector< reco::TrackBase::TrackAlgorithm > algosToReject
double pt() const
track transverse momentum
Definition: TrackBase.h:616
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:758
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static edm::ParameterSetDescription pSetDescript()
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static bool passQual(const reco::TrackBase &trk, const std::vector< reco::TrackBase::TrackQuality > &quals)
double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:664
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:125
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
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
static TrackAlgorithm algoByName(const std::string &name)
Definition: TrackBase.cc:137
int numberOfValidPixelHits() const
Definition: HitPattern.h:838
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
EleTkIsolFromCands(const edm::ParameterSet &para)
double getTrkPt(const reco::TrackBase &trk, const edm::View< reco::GsfElectron > &eles)