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() || !std::binary_search(algosToRej.begin(), algosToRej.end(), trk.algo());
184 }
185 
187  auto const& cuts = isBarrel ? cfg_.barrelCuts : cfg_.endcapCuts;
190 
191  if (!tracksCached) {
193  tracksCached = true;
194  }
195 
196  return preselectedTracks;
197 }
EleTkIsolFromCands::passTrackPreselection
static bool passTrackPreselection(const reco::TrackBase &trk, float trkPt, const TrkCuts &cuts)
Definition: EleTkIsolFromCands.cc:163
edm::soa::col::Vz
Definition: KinematicColumns.h:14
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
EleTkIsolFromCands::TrkCuts::maxDPtPt
float maxDPtPt
Definition: EleTkIsolFromCands.h:56
reco::TrackBase::ptError
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:754
EleTkIsolFromCands::passPIDVeto
static bool passPIDVeto(const int pdgId, const EleTkIsolFromCands::PIDVeto pidVeto)
Definition: EleTkIsolFromCands.cc:130
EleTkIsolFromCands::preselectTracks
static TrackTable preselectTracks(reco::TrackCollection const &tracks, TrkCuts const &cuts)
Definition: EleTkIsolFromCands.cc:50
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
EleTkIsolFromCands::TrkCuts::minHits
float minHits
Definition: EleTkIsolFromCands.h:54
EleTkIsolFromCands::TrkCuts::allowedQualities
std::vector< reco::TrackBase::TrackQuality > allowedQualities
Definition: EleTkIsolFromCands.h:57
EleTkIsolFromCands::PIDVeto::NONE
EleTkIsolFromCands::pidVetoFromStr
static PIDVeto pidVetoFromStr(const std::string &vetoStr)
Definition: EleTkIsolFromCands.cc:150
EleTkIsolFromCands::TrkCuts::pSetDescript
static edm::ParameterSetDescription pSetDescript()
Definition: EleTkIsolFromCands.cc:28
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EleTkIsolFromCands::PIDVeto::NONELES
HIPAlignmentAlgorithm_cfi.algoName
algoName
Definition: HIPAlignmentAlgorithm_cfi.py:5
reco::TrackBase::numberOfValidHits
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:798
EleTkIsolFromCands::PIDVeto::ELES
reco::TrackBase::pt
double pt() const
track transverse momentum
Definition: TrackBase.h:637
EleTkIsolFromCands::TrkCuts::TrkCuts
TrkCuts(const edm::ParameterSet &para)
Definition: EleTkIsolFromCands.cc:5
EleTkIsolFromCands::Output
Definition: EleTkIsolFromCands.h:88
EleTkIsolFromCands::PIDVeto
PIDVeto
Definition: EleTkIsolFromCands.h:71
Track.h
edm::soa::col
Definition: KinematicColumns.h:8
EleTkIsolFromCands::TrkCuts::maxDR2
float maxDR2
Definition: EleTkIsolFromCands.h:51
reco::TrackBase::vz
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:661
EleTkIsolFromCands::preselectTracksFromCands
static TrackTable preselectTracksFromCands(pat::PackedCandidateCollection const &cands, TrkCuts const &cuts, PIDVeto=PIDVeto::NONE)
Definition: EleTkIsolFromCands.cc:74
PVValHelper::eta
Definition: PVValidationHelpers.h:69
reco::Track
Definition: Track.h:27
EleTkIsolFromCands::getPreselectedTracks
TrackTable const & getPreselectedTracks(bool isBarrel)
Definition: EleTkIsolFromCands.cc:186
reco::TrackBase::phi
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:649
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PixelPluginsPhase0_cfi.isBarrel
isBarrel
Definition: PixelPluginsPhase0_cfi.py:17
HLT_FULL_cff.cands
cands
Definition: HLT_FULL_cff.py:15208
EleTkIsolFromCands::operator()
Output operator()(const reco::TrackBase &electronTrack)
Definition: EleTkIsolFromCands.cc:102
EleTkIsolFromCands::passQual
static bool passQual(const reco::TrackBase &trk, const std::vector< reco::TrackBase::TrackQuality > &quals)
Definition: EleTkIsolFromCands.cc:169
edm::ParameterSet
Definition: ParameterSet.h:47
EleTkIsolFromCands::TrkCuts::minDR2
float minDR2
Definition: EleTkIsolFromCands.h:50
EleTkIsolFromCands::cfg_
Configuration const & cfg_
Definition: EleTkIsolFromCands.h:123
EleTkIsolFromCands.h
EleTkIsolFromCands::tracksCachedForBarrelCuts_
bool tracksCachedForBarrelCuts_
Definition: EleTkIsolFromCands.h:131
deltaR.h
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
EleTkIsolFromCands::Configuration::barrelCuts
const TrkCuts barrelCuts
Definition: EleTkIsolFromCands.h:67
reco::TrackBase::eta
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
edm::soa::col::Eta
Definition: KinematicColumns.h:10
cand
Definition: decayParser.h:32
reco::TrackBase
Definition: TrackBase.h:62
EleTkIsolFromCands::passAlgo
static bool passAlgo(const reco::TrackBase &trk, const std::vector< reco::TrackBase::TrackAlgorithm > &algosToRej)
Definition: EleTkIsolFromCands.cc:181
EleTkIsolFromCands::pSetDescript
static edm::ParameterSetDescription pSetDescript()
Definition: EleTkIsolFromCands.cc:43
EgammaValidation_cff.pdgId
pdgId
Definition: EgammaValidation_cff.py:118
EleTkIsolFromCands::Configuration::endcapCuts
const TrkCuts endcapCuts
Definition: EleTkIsolFromCands.h:68
pat::PackedCandidateCollection
std::vector< pat::PackedCandidate > PackedCandidateCollection
Definition: PackedCandidate.h:1130
reco::TrackBase::algo
TrackAlgorithm algo() const
Definition: TrackBase.h:547
EleTkIsolFromCands::TrkCuts::minPt
float minPt
Definition: EleTkIsolFromCands.h:49
reco::TrackBase::qualityByName
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
DDAxes::phi
EleTkIsolFromCands::cands_
pat::PackedCandidateCollection const * cands_
Definition: EleTkIsolFromCands.h:127
reco::TrackBase::hitPattern
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:504
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
heppy_batch.val
val
Definition: heppy_batch.py:351
eostools.move
def move(src, dest)
Definition: eostools.py:511
HLT_FULL_cff.dEta
dEta
Definition: HLT_FULL_cff.py:13767
Exception
Definition: hltDiff.cc:246
EleTkIsolFromCands::TrkCuts
Definition: EleTkIsolFromCands.h:48
EleTkIsolFromCands::preselectedTracksWithBarrelCuts_
TrackTable preselectedTracksWithBarrelCuts_
Definition: EleTkIsolFromCands.h:129
edm::soa::Table< edm::soa::col::Pt, edm::soa::col::Eta, edm::soa::col::Phi, edm::soa::col::Vz >
EleTkIsolFromCands::TrkCuts::algosToReject
std::vector< reco::TrackBase::TrackAlgorithm > algosToReject
Definition: EleTkIsolFromCands.h:58
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::soa::col::Pt
Definition: KinematicColumns.h:19
EleTkIsolFromCands::TrkCuts::maxDZ
float maxDZ
Definition: EleTkIsolFromCands.h:53
reco::HitPattern::numberOfValidPixelHits
int numberOfValidPixelHits() const
Definition: HitPattern.h:800
reco::TrackBase::algoByName
static TrackAlgorithm algoByName(const std::string &name)
Definition: TrackBase.cc:137
L1TMuonDQMOffline_cfi.cuts
cuts
Definition: L1TMuonDQMOffline_cfi.py:41
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
EleTkIsolFromCands::preselectedTracksWithEndcapCuts_
TrackTable preselectedTracksWithEndcapCuts_
Definition: EleTkIsolFromCands.h:130
PbPb_ZMuSkimMuonDPG_cff.veto
veto
Definition: PbPb_ZMuSkimMuonDPG_cff.py:61
listHistos.trackPt
trackPt
Definition: listHistos.py:120
reco::TrackBase::quality
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:552
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
EleTkIsolFromCands::TrkCuts::minDEta
float minDEta
Definition: EleTkIsolFromCands.h:52
edm::soa::col::Phi
Definition: KinematicColumns.h:11
EleTkIsolFromCands::tracks_
reco::TrackCollection const * tracks_
Definition: EleTkIsolFromCands.h:126
EleTkIsolFromCands::tracksCachedForEndcapCuts_
bool tracksCachedForEndcapCuts_
Definition: EleTkIsolFromCands.h:132
EleTkIsolFromCands::pidVeto_
const PIDVeto pidVeto_
Definition: EleTkIsolFromCands.h:128
EleTkIsolFromCands::TrkCuts::minPixelHits
float minPixelHits
Definition: EleTkIsolFromCands.h:55