CMS 3D CMS Logo

EleTkIsolFromCands.cc
Go to the documentation of this file.
4 
6  minPt = para.getParameter<double>("minPt");
7  auto sq = [](double val) { return val * val; };
8  minDR2 = sq(para.getParameter<double>("minDR"));
9  maxDR2 = sq(para.getParameter<double>("maxDR"));
10  minDEta = para.getParameter<double>("minDEta");
11  maxDZ = para.getParameter<double>("maxDZ");
12  minHits = para.getParameter<int>("minHits");
13  minPixelHits = para.getParameter<int>("minPixelHits");
14  maxDPtPt = para.getParameter<double>("maxDPtPt");
15 
16  auto qualNames = para.getParameter<std::vector<std::string> >("allowedQualities");
17  auto algoNames = para.getParameter<std::vector<std::string> >("algosToReject");
18 
19  for (auto& qualName : qualNames) {
21  }
22  for (auto& algoName : algoNames) {
24  }
25  std::sort(algosToReject.begin(), algosToReject.end());
26 }
27 
30  desc.add<double>("minPt", 1.0);
31  desc.add<double>("maxDR", 0.3);
32  desc.add<double>("minDR", 0.000);
33  desc.add<double>("minDEta", 0.005);
34  desc.add<double>("maxDZ", 0.1);
35  desc.add<double>("maxDPtPt", -1);
36  desc.add<int>("minHits", 8);
37  desc.add<int>("minPixelHits", 1);
38  desc.add<std::vector<std::string> >("allowedQualities");
39  desc.add<std::vector<std::string> >("algosToReject");
40  return desc;
41 }
42 
44  : barrelCuts_(para.getParameter<edm::ParameterSet>("barrelCuts")),
45  endcapCuts_(para.getParameter<edm::ParameterSet>("endcapCuts")) {}
46 
49  desc.add("barrelCuts", TrkCuts::pSetDescript());
50  desc.add("endcapCuts", TrkCuts::pSetDescript());
51  return desc;
52 }
53 
54 std::pair<int, double> EleTkIsolFromCands::calIsol(const reco::TrackBase& eleTrk,
56  const PIDVeto pidVeto) const {
57  return calIsol(eleTrk.eta(), eleTrk.phi(), eleTrk.vz(), cands, pidVeto);
58 }
59 
60 std::pair<int, double> EleTkIsolFromCands::calIsol(const double eleEta,
61  const double elePhi,
62  const double eleVZ,
64  const PIDVeto pidVeto) const {
65  double ptSum = 0.;
66  int nrTrks = 0;
67 
68  const TrkCuts& cuts = std::abs(eleEta) < 1.5 ? barrelCuts_ : endcapCuts_;
69 
70  for (auto& cand : cands) {
71  if (cand.hasTrackDetails() && cand.charge() != 0 && passPIDVeto(cand.pdgId(), pidVeto)) {
72  const reco::Track& trk = cand.pseudoTrack();
73  if (passTrkSel(trk, trk.pt(), cuts, eleEta, elePhi, eleVZ)) {
74  ptSum += trk.pt();
75  nrTrks++;
76  }
77  }
78  }
79  return {nrTrks, ptSum};
80 }
81 
82 std::pair<int, double> EleTkIsolFromCands::calIsol(const reco::TrackBase& eleTrk,
83  const reco::TrackCollection& tracks) const {
84  return calIsol(eleTrk.eta(), eleTrk.phi(), eleTrk.vz(), tracks);
85 }
86 
87 std::pair<int, double> EleTkIsolFromCands::calIsol(const double eleEta,
88  const double elePhi,
89  const double eleVZ,
90  const reco::TrackCollection& tracks) const {
91  double ptSum = 0.;
92  int nrTrks = 0;
93 
94  const TrkCuts& cuts = std::abs(eleEta) < 1.5 ? barrelCuts_ : endcapCuts_;
95 
96  for (auto& trk : tracks) {
97  if (passTrkSel(trk, trk.pt(), cuts, eleEta, elePhi, eleVZ)) {
98  ptSum += trk.pt();
99  nrTrks++;
100  }
101  }
102  return {nrTrks, ptSum};
103 }
104 
106  int pidAbs = std::abs(pdgId);
107  switch (veto) {
108  case PIDVeto::NONE:
109  return true;
110  case PIDVeto::ELES:
111  if (pidAbs == 11)
112  return false;
113  else
114  return true;
115  case PIDVeto::NONELES:
116  if (pidAbs == 11)
117  return true;
118  else
119  return false;
120  }
121  throw cms::Exception("CodeError") << "invalid PIDVeto " << static_cast<int>(veto) << ", "
122  << "this is likely due to some static casting of invalid ints somewhere";
123 }
124 
126  if (vetoStr == "NONE")
127  return PIDVeto::NONE;
128  else if (vetoStr == "ELES")
129  return PIDVeto::ELES;
130  else if (vetoStr == "NONELES")
131  return PIDVeto::NONELES;
132  else {
133  throw cms::Exception("CodeError") << "unrecognised string " << vetoStr
134  << ", either a typo or this function needs to be updated";
135  }
136 }
137 
139  const double trkPt,
140  const TrkCuts& cuts,
141  const double eleEta,
142  const double elePhi,
143  const double eleVZ) {
144  const float dR2 = reco::deltaR2(eleEta, elePhi, trk.eta(), trk.phi());
145  const float dEta = trk.eta() - eleEta;
146  const float dZ = eleVZ - trk.vz();
147 
148  return dR2 >= cuts.minDR2 && dR2 <= cuts.maxDR2 && std::abs(dEta) >= cuts.minDEta && std::abs(dZ) < cuts.maxDZ &&
149  trk.hitPattern().numberOfValidHits() >= cuts.minHits &&
151  (trk.ptError() / trkPt < cuts.maxDPtPt || cuts.maxDPtPt < 0) && passQual(trk, cuts.allowedQualities) &&
152  passAlgo(trk, cuts.algosToReject) && trkPt > cuts.minPt;
153 }
154 
155 bool EleTkIsolFromCands::passQual(const reco::TrackBase& trk, const std::vector<reco::TrackBase::TrackQuality>& quals) {
156  if (quals.empty())
157  return true;
158 
159  for (auto qual : quals) {
160  if (trk.quality(qual))
161  return true;
162  }
163 
164  return false;
165 }
166 
168  const std::vector<reco::TrackBase::TrackAlgorithm>& algosToRej) {
169  return algosToRej.empty() || !std::binary_search(algosToRej.begin(), algosToRej.end(), trk.algo());
170 }
T getParameter(std::string const &) const
TrkCuts(const edm::ParameterSet &para)
int numberOfValidHits() const
Definition: HitPattern.h:787
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:614
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:526
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:617
std::vector< reco::TrackBase::TrackAlgorithm > algosToReject
double pt() const
track transverse momentum
Definition: TrackBase.h:602
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:696
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:626
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:483
static PIDVeto pidVetoFromStr(const std::string &vetoStr)
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:531
HLT enums.
static TrackAlgorithm algoByName(const std::string &name)
Definition: TrackBase.cc:137
int numberOfValidPixelHits() const
Definition: HitPattern.h:801
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)