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 
45  desc.add("barrelCuts", TrkCuts::pSetDescript());
46  desc.add("endcapCuts", TrkCuts::pSetDescript());
47  return desc;
48 }
49 
51  TrkCuts const& cuts) {
52  std::vector<float> pt;
53  std::vector<float> eta;
54  std::vector<float> phi;
55  std::vector<float> vz;
56  pt.reserve(tracks.size());
57  eta.reserve(tracks.size());
58  phi.reserve(tracks.size());
59  vz.reserve(tracks.size());
60 
61  for (auto const& trk : tracks) {
62  auto trkPt = trk.pt();
63  if (passTrackPreselection(trk, trkPt, cuts)) {
64  pt.emplace_back(trkPt);
65  eta.emplace_back(trk.eta());
66  phi.emplace_back(trk.phi());
67  vz.emplace_back(trk.vz());
68  }
69  }
70 
71  return {pt, std::move(eta), std::move(phi), std::move(vz)};
72 }
73 
75  TrkCuts const& cuts,
76  PIDVeto pidVeto) {
77  std::vector<float> pt;
78  std::vector<float> eta;
79  std::vector<float> phi;
80  std::vector<float> vz;
81  pt.reserve(cands.size());
82  eta.reserve(cands.size());
83  phi.reserve(cands.size());
84  vz.reserve(cands.size());
85 
86  for (auto const& cand : cands) {
87  if (cand.hasTrackDetails() && cand.charge() != 0 && passPIDVeto(cand.pdgId(), pidVeto)) {
88  const reco::Track& trk = cand.pseudoTrack();
89  float trkPt = trk.pt();
90  if (passTrackPreselection(trk, trkPt, cuts)) {
91  pt.emplace_back(trkPt);
92  eta.emplace_back(trk.eta());
93  phi.emplace_back(trk.phi());
94  vz.emplace_back(trk.vz());
95  }
96  }
97  }
98 
99  return {pt, std::move(eta), std::move(phi), std::move(vz)};
100 }
101 
103  using namespace edm::soa::col;
104 
105  float ptSum = 0.;
106  int nrTrks = 0;
107 
108  const float eleEta = eleTrk.eta();
109  const float elePhi = eleTrk.phi();
110  const float eleVz = eleTrk.vz();
111 
112  const bool isBarrelElectron = std::abs(eleEta) < 1.5;
113 
114  auto const& preselectedTracks = getPreselectedTracks(isBarrelElectron);
115  auto const& cuts = isBarrelElectron ? cfg_.barrelCuts : cfg_.endcapCuts;
116 
117  for (auto const& trk : preselectedTracks) {
118  const float dR2 = reco::deltaR2(eleEta, elePhi, trk.get<Eta>(), trk.get<Phi>());
119  const float dEta = trk.get<Eta>() - eleEta;
120  const float dZ = eleVz - trk.get<Vz>();
121 
122  if (dR2 >= cuts.minDR2 && dR2 <= cuts.maxDR2 && std::abs(dEta) >= cuts.minDEta && std::abs(dZ) < cuts.maxDZ) {
123  ptSum += trk.get<Pt>();
124  nrTrks++;
125  }
126  }
127  return {nrTrks, ptSum};
128 }
129 
131  int pidAbs = std::abs(pdgId);
132  switch (veto) {
133  case PIDVeto::NONE:
134  return true;
135  case PIDVeto::ELES:
136  if (pidAbs == 11)
137  return false;
138  else
139  return true;
140  case PIDVeto::NONELES:
141  if (pidAbs == 11)
142  return true;
143  else
144  return false;
145  }
146  throw cms::Exception("CodeError") << "invalid PIDVeto " << static_cast<int>(veto) << ", "
147  << "this is likely due to some static casting of invalid ints somewhere";
148 }
149 
151  if (vetoStr == "NONE")
152  return PIDVeto::NONE;
153  else if (vetoStr == "ELES")
154  return PIDVeto::ELES;
155  else if (vetoStr == "NONELES")
156  return PIDVeto::NONELES;
157  else {
158  throw cms::Exception("CodeError") << "unrecognised string " << vetoStr
159  << ", either a typo or this function needs to be updated";
160  }
161 }
162 
164  return trackPt > cuts.minPt && trk.numberOfValidHits() >= cuts.minHits &&
165  trk.hitPattern().numberOfValidPixelHits() >= cuts.minPixelHits && passQual(trk, cuts.allowedQualities) &&
166  passAlgo(trk, cuts.algosToReject) && (cuts.maxDPtPt < 0 || trk.ptError() / trackPt < cuts.maxDPtPt);
167 }
168 
169 bool EleTkIsolFromCands::passQual(const reco::TrackBase& trk, const std::vector<reco::TrackBase::TrackQuality>& quals) {
170  if (quals.empty())
171  return true;
172 
173  for (auto qual : quals) {
174  if (trk.quality(qual))
175  return true;
176  }
177 
178  return false;
179 }
180 
182  const std::vector<reco::TrackBase::TrackAlgorithm>& algosToRej) {
183  return algosToRej.empty() ||
184  //check also the originalAlgo in case the track is reconstructed by more than one
185  //reject only if both algo and originalAlgo are not acceptable
186  !(std::binary_search(algosToRej.begin(), algosToRej.end(), trk.algo()) &&
187  std::binary_search(algosToRej.begin(), algosToRej.end(), trk.originalAlgo()));
188 }
189 
191  auto const& cuts = isBarrel ? cfg_.barrelCuts : cfg_.endcapCuts;
194 
195  if (!tracksCached) {
197  tracksCached = true;
198  }
199 
200  return preselectedTracks;
201 }
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:552
int numberOfValidPixelHits() const
Definition: HitPattern.h:831
TrkCuts(const edm::ParameterSet &para)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
reco::TrackCollection const * tracks_
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:754
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:798
static bool passTrackPreselection(const reco::TrackBase &trk, float trkPt, const TrkCuts &cuts)
static edm::ParameterSetDescription pSetDescript()
std::vector< pat::PackedCandidate > PackedCandidateCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
static TrackTable preselectTracks(reco::TrackCollection const &tracks, TrkCuts const &cuts)
static bool passAlgo(const reco::TrackBase &trk, const std::vector< reco::TrackBase::TrackAlgorithm > &algosToRej)
std::vector< reco::TrackBase::TrackQuality > allowedQualities
double pt() const
track transverse momentum
Definition: TrackBase.h:637
TrackAlgorithm originalAlgo() const
Definition: TrackBase.h:548
TkSoA const *__restrict__ CAHitNtupletGeneratorKernelsGPU::QualityCuts cuts
Output operator()(const reco::TrackBase &electronTrack)
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:661
std::vector< reco::TrackBase::TrackAlgorithm > algosToReject
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:649
static edm::ParameterSetDescription pSetDescript()
TrackTable const & getPreselectedTracks(bool isBarrel)
static bool passQual(const reco::TrackBase &trk, const std::vector< reco::TrackBase::TrackQuality > &quals)
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
TrackTable preselectedTracksWithBarrelCuts_
TrackAlgorithm algo() const
Definition: TrackBase.h:547
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
auto const & tracks
cannot be loose
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:504
static PIDVeto pidVetoFromStr(const std::string &vetoStr)
static TrackTable preselectTracksFromCands(pat::PackedCandidateCollection const &cands, TrkCuts const &cuts, PIDVeto=PIDVeto::NONE)
Configuration const & cfg_
static TrackAlgorithm algoByName(const std::string &name)
Definition: TrackBase.cc:137
pat::PackedCandidateCollection const * cands_
TrackTable preselectedTracksWithEndcapCuts_
def move(src, dest)
Definition: eostools.py:511
static bool passPIDVeto(const int pdgId, const EleTkIsolFromCands::PIDVeto pidVeto)