CMS 3D CMS Logo

EleTkIsolFromCands.cc
Go to the documentation of this file.
4 
6 {
7  minPt = para.getParameter<double>("minPt");
8  auto sq = [](double val){return val*val;};
9  minDR2 = sq(para.getParameter<double>("minDR"));
10  maxDR2 = sq(para.getParameter<double>("maxDR"));
11  minDEta = para.getParameter<double>("minDEta");
12  maxDZ = para.getParameter<double>("maxDZ");
13  minHits = para.getParameter<int>("minHits");
14  minPixelHits = para.getParameter<int>("minPixelHits");
15  maxDPtPt = para.getParameter<double>("maxDPtPt");
16 
17  auto qualNames = para.getParameter<std::vector<std::string> >("allowedQualities");
18  auto algoNames = para.getParameter<std::vector<std::string> >("algosToReject");
19 
20  for(auto& qualName : qualNames){
22  }
23  for(auto& algoName : algoNames){
25  }
26  std::sort(algosToReject.begin(),algosToReject.end());
27 
28 }
29 
31 {
33  desc.add<double>("minPt",1.0);
34  desc.add<double>("maxDR",0.3);
35  desc.add<double>("minDR",0.000);
36  desc.add<double>("minDEta",0.005);
37  desc.add<double>("maxDZ",0.1);
38  desc.add<double>("maxDPtPt",-1);
39  desc.add<int>("minHits",8);
40  desc.add<int>("minPixelHits",1);
41  desc.add<std::vector<std::string> >("allowedQualities");
42  desc.add<std::vector<std::string> >("algosToReject");
43  return desc;
44 }
45 
47  barrelCuts_(para.getParameter<edm::ParameterSet>("barrelCuts")),
48  endcapCuts_(para.getParameter<edm::ParameterSet>("endcapCuts"))
49 {
50 
51 
52 }
53 
55 {
57  desc.add("barrelCuts",TrkCuts::pSetDescript());
58  desc.add("endcapCuts",TrkCuts::pSetDescript());
59  return desc;
60 }
61 
62 std::pair<int,double>
65  const PIDVeto pidVeto)const
66 {
67  return calIsol(eleTrk.eta(),eleTrk.phi(),eleTrk.vz(),cands,pidVeto);
68 }
69 
70 std::pair<int,double>
71 EleTkIsolFromCands::calIsol(const double eleEta,const double elePhi,
72  const double eleVZ,
74  const PIDVeto pidVeto)const
75 {
76  double ptSum=0.;
77  int nrTrks=0;
78 
79  const TrkCuts& cuts = std::abs(eleEta)<1.5 ? barrelCuts_ : endcapCuts_;
80 
81  for(auto& cand : cands){
82  if(cand.hasTrackDetails() && cand.charge()!=0 && passPIDVeto(cand.pdgId(),pidVeto)){
83  const reco::Track& trk = cand.pseudoTrack();
84  if(passTrkSel(trk,trk.pt(),cuts,eleEta,elePhi,eleVZ)){
85  ptSum+=trk.pt();
86  nrTrks++;
87  }
88  }
89  }
90  return {nrTrks,ptSum};
91 }
92 
93 
94 
95 std::pair<int,double>
97  const reco::TrackCollection& tracks)const
98 {
99  return calIsol(eleTrk.eta(),eleTrk.phi(),eleTrk.vz(),tracks);
100 }
101 
102 std::pair<int,double>
103 EleTkIsolFromCands::calIsol(const double eleEta,const double elePhi,
104  const double eleVZ,
105  const reco::TrackCollection& tracks)const
106 {
107  double ptSum=0.;
108  int nrTrks=0;
109 
110  const TrkCuts& cuts = std::abs(eleEta)<1.5 ? barrelCuts_ : endcapCuts_;
111 
112  for(auto& trk : tracks){
113  if(passTrkSel(trk,trk.pt(),cuts,eleEta,elePhi,eleVZ)){
114  ptSum+=trk.pt();
115  nrTrks++;
116  }
117  }
118  return {nrTrks,ptSum};
119 }
120 
122 {
123  int pidAbs = std::abs(pdgId);
124  switch (veto){
125  case PIDVeto::NONE:
126  return true;
127  case PIDVeto::ELES:
128  if(pidAbs==11) return false;
129  else return true;
130  case PIDVeto::NONELES:
131  if(pidAbs==11) return true;
132  else return false;
133  }
134  throw cms::Exception("CodeError") <<
135  "invalid PIDVeto "<<static_cast<int>(veto)<<", "<<
136  "this is likely due to some static casting of invalid ints somewhere";
137 }
138 
140 {
141  if(vetoStr=="NONE") return PIDVeto::NONE;
142  else if(vetoStr=="ELES") return PIDVeto::ELES;
143  else if(vetoStr=="NONELES") return PIDVeto::NONELES;
144  else{
145  throw cms::Exception("CodeError") <<"unrecognised string "<<vetoStr<<", either a typo or this function needs to be updated";
146  }
147 }
148 
150  const double trkPt,const TrkCuts& cuts,
151  const double eleEta,const double elePhi,
152  const double eleVZ)
153 {
154  const float dR2 = reco::deltaR2(eleEta,elePhi,trk.eta(),trk.phi());
155  const float dEta = trk.eta()-eleEta;
156  const float dZ = eleVZ - trk.vz();
157 
158  return dR2>=cuts.minDR2 && dR2<=cuts.maxDR2 &&
159  std::abs(dEta)>=cuts.minDEta &&
160  std::abs(dZ)<cuts.maxDZ &&
161  trk.hitPattern().numberOfValidHits() >= cuts.minHits &&
163  (trk.ptError()/trkPt < cuts.maxDPtPt || cuts.maxDPtPt<0) &&
164  passQual(trk,cuts.allowedQualities) &&
165  passAlgo(trk,cuts.algosToReject) &&
166  trkPt > cuts.minPt;
167 }
168 
169 
170 
173  const std::vector<reco::TrackBase::TrackQuality>& quals)
174 {
175  if(quals.empty()) return true;
176 
177  for(auto qual : quals) {
178  if(trk.quality(qual)) return true;
179  }
180 
181  return false;
182 }
183 
186  const std::vector<reco::TrackBase::TrackAlgorithm>& algosToRej)
187 {
188  return algosToRej.empty() || !std::binary_search(algosToRej.begin(),algosToRej.end(),trk.algo());
189 }
190 
T getParameter(std::string const &) const
TrkCuts(const edm::ParameterSet &para)
int numberOfValidHits() const
Definition: HitPattern.h:823
static edm::ParameterSetDescription pSetDescript()
std::vector< pat::PackedCandidate > PackedCandidateCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:645
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:497
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:651
std::vector< reco::TrackBase::TrackAlgorithm > algosToReject
double pt() const
track transverse momentum
Definition: TrackBase.h:621
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:763
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static edm::ParameterSetDescription pSetDescript()
std::pair< int, double > calIsol(const reco::TrackBase &trk, const pat::PackedCandidateCollection &cands, const PIDVeto=PIDVeto::NONE) const
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static bool passQual(const reco::TrackBase &trk, const std::vector< reco::TrackBase::TrackQuality > &quals)
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:669
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:446
static PIDVeto pidVetoFromStr(const std::string &vetoStr)
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:510
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
HLT enums.
static TrackAlgorithm algoByName(const std::string &name)
Definition: TrackBase.cc:137
int numberOfValidPixelHits() const
Definition: HitPattern.h:838
static bool passTrkSel(const reco::TrackBase &trk, const double trkPt, const TrkCuts &cuts, const double eleEta, const double elePhi, const double eleVZ)
EleTkIsolFromCands(const edm::ParameterSet &para)
static bool passPIDVeto(const int pdgId, const EleTkIsolFromCands::PIDVeto pidVeto)