CMS 3D CMS Logo

PATLostTracks.cc
Go to the documentation of this file.
1 #include <string>
2 
27 
28 namespace {
29  bool passesQuality(const reco::Track& trk, const std::vector<reco::TrackBase::TrackQuality>& allowedQuals) {
30  for (const auto& qual : allowedQuals) {
31  if (trk.quality(qual))
32  return true;
33  }
34  return false;
35  }
36 } // namespace
37 
38 namespace pat {
40  public:
41  explicit PATLostTracks(const edm::ParameterSet&);
42  ~PATLostTracks() override;
43 
44  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
45 
46  private:
48  bool passTrkCuts(const reco::Track& tr) const;
49  void addPackedCandidate(std::vector<pat::PackedCandidate>& cands,
50  const reco::TrackRef& trk,
51  const reco::VertexRef& pvSlimmed,
52  const reco::VertexRefProd& pvSlimmedColl,
53  const reco::Vertex& pvOrig,
54  const TrkStatus trkStatus,
56 
57  private:
66  const double minPt_;
67  const double minHits_;
68  const double minPixelHits_;
69  const double minPtToStoreProps_;
70  const int covarianceVersion_;
71  const int covarianceSchema_;
72  std::vector<reco::TrackBase::TrackQuality> qualsToAutoAccept_;
75  };
76 } // namespace pat
77 
79  : cands_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("inputCandidates"))),
80  map_(consumes<edm::Association<pat::PackedCandidateCollection>>(
81  iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
82  tracks_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("inputTracks"))),
83  vertices_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("secondaryVertices"))),
84  kshorts_(consumes<reco::VertexCompositeCandidateCollection>(iConfig.getParameter<edm::InputTag>("kshorts"))),
85  lambdas_(consumes<reco::VertexCompositeCandidateCollection>(iConfig.getParameter<edm::InputTag>("lambdas"))),
86  pv_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("primaryVertices"))),
87  pvOrigs_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("originalVertices"))),
88  minPt_(iConfig.getParameter<double>("minPt")),
89  minHits_(iConfig.getParameter<uint32_t>("minHits")),
90  minPixelHits_(iConfig.getParameter<uint32_t>("minPixelHits")),
91  minPtToStoreProps_(iConfig.getParameter<double>("minPtToStoreProps")),
92  covarianceVersion_(iConfig.getParameter<int>("covarianceVersion")),
93  covarianceSchema_(iConfig.getParameter<int>("covarianceSchema")),
94  muons_(consumes<reco::MuonCollection>(iConfig.getParameter<edm::InputTag>("muons"))),
95  passThroughCut_(iConfig.getParameter<std::string>("passThroughCut")) {
96  std::vector<std::string> trkQuals(iConfig.getParameter<std::vector<std::string>>("qualsToAutoAccept"));
98  trkQuals.begin(), trkQuals.end(), std::back_inserter(qualsToAutoAccept_), reco::TrackBase::qualityByName);
99 
101  qualsToAutoAccept_.end()) {
102  std::ostringstream msg;
103  msg << " PATLostTracks has a quality requirement which resolves to undefQuality. This usually means a typo and is "
104  "therefore treated a config error\nquality requirements:\n ";
105  for (const auto& trkQual : trkQuals)
106  msg << trkQual << " ";
107  throw cms::Exception("Configuration") << msg.str();
108  }
109 
110  produces<std::vector<reco::Track>>();
111  produces<std::vector<pat::PackedCandidate>>();
112  produces<std::vector<pat::PackedCandidate>>("eleTracks");
113  produces<edm::Association<pat::PackedCandidateCollection>>();
114 }
115 
117 
120  iEvent.getByToken(cands_, cands);
121 
123  iEvent.getByToken(map_, pf2pc);
124 
126  iEvent.getByToken(tracks_, tracks);
127 
129  iEvent.getByToken(vertices_, vertices);
130 
132  iEvent.getByToken(muons_, muons);
133 
135  iEvent.getByToken(kshorts_, kshorts);
137  iEvent.getByToken(lambdas_, lambdas);
138 
140  iEvent.getByToken(pv_, pvs);
141  reco::VertexRef pv(pvs.id());
142  reco::VertexRefProd pvRefProd(pvs);
143  if (!pvs->empty()) {
144  pv = reco::VertexRef(pvs, 0);
145  }
147  iEvent.getByToken(pvOrigs_, pvOrigs);
148  const reco::Vertex& pvOrig = (*pvOrigs)[0];
149 
150  auto outPtrTrks = std::make_unique<std::vector<reco::Track>>();
151  auto outPtrTrksAsCands = std::make_unique<std::vector<pat::PackedCandidate>>();
152  auto outPtrEleTrksAsCands = std::make_unique<std::vector<pat::PackedCandidate>>();
153 
154  std::vector<TrkStatus> trkStatus(tracks->size(), TrkStatus::NOTUSED);
155  //Mark all tracks used in candidates
156  //check if packed candidates are storing the tracks by seeing if number of hits >0
157  //currently we dont use that information though
158  //electrons will never store their track (they store the GSF track)
159  for (unsigned int ic = 0, nc = cands->size(); ic < nc; ++ic) {
161  const reco::PFCandidate& cand = (*cands)[ic];
162  if (cand.charge() && cand.trackRef().isNonnull() && cand.trackRef().id() == tracks.id()) {
163  if (cand.pdgId() == 11)
164  trkStatus[cand.trackRef().key()] = TrkStatus::PFELECTRON;
165  else if (cand.pdgId() == -11)
166  trkStatus[cand.trackRef().key()] = TrkStatus::PFPOSITRON;
167  else if ((*pf2pc)[r]->numberOfHits() > 0)
168  trkStatus[cand.trackRef().key()] = TrkStatus::PFCAND;
169  else
170  trkStatus[cand.trackRef().key()] = TrkStatus::PFCANDNOTRKPROPS;
171  }
172  }
173 
174  //Mark all tracks used in secondary vertices
175  for (const auto& secVert : *vertices) {
176  for (auto trkIt = secVert.tracks_begin(); trkIt != secVert.tracks_end(); trkIt++) {
177  if (trkStatus[trkIt->key()] == TrkStatus::NOTUSED)
178  trkStatus[trkIt->key()] = TrkStatus::VTX;
179  }
180  }
181  for (const auto& v0 : *kshorts) {
182  for (size_t dIdx = 0; dIdx < v0.numberOfDaughters(); dIdx++) {
183  size_t key = (dynamic_cast<const reco::RecoChargedCandidate*>(v0.daughter(dIdx)))->track().key();
184  if (trkStatus[key] == TrkStatus::NOTUSED)
185  trkStatus[key] = TrkStatus::VTX;
186  }
187  }
188  for (const auto& v0 : *lambdas) {
189  for (size_t dIdx = 0; dIdx < v0.numberOfDaughters(); dIdx++) {
190  size_t key = (dynamic_cast<const reco::RecoChargedCandidate*>(v0.daughter(dIdx)))->track().key();
191  if (trkStatus[key] == TrkStatus::NOTUSED)
192  trkStatus[key] = TrkStatus::VTX;
193  }
194  }
195  std::vector<int> mapping(tracks->size(), -1);
196  int lostTrkIndx = 0;
197  for (unsigned int trkIndx = 0; trkIndx < tracks->size(); trkIndx++) {
198  reco::TrackRef trk(tracks, trkIndx);
199  if (trkStatus[trkIndx] == TrkStatus::VTX || (trkStatus[trkIndx] == TrkStatus::NOTUSED && passTrkCuts(*trk))) {
200  outPtrTrks->emplace_back(*trk);
201  addPackedCandidate(*outPtrTrksAsCands, trk, pv, pvRefProd, pvOrig, trkStatus[trkIndx], muons);
202 
203  //for creating the reco::Track -> pat::PackedCandidate map
204  //not done for the lostTrack:eleTracks collection
205  mapping[trkIndx] = lostTrkIndx;
206  lostTrkIndx++;
207  } else if ((trkStatus[trkIndx] == TrkStatus::PFELECTRON || trkStatus[trkIndx] == TrkStatus::PFPOSITRON) &&
208  passTrkCuts(*trk)) {
209  addPackedCandidate(*outPtrEleTrksAsCands, trk, pv, pvRefProd, pvOrig, trkStatus[trkIndx], muons);
210  }
211  }
212 
213  iEvent.put(std::move(outPtrTrks));
214  iEvent.put(std::move(outPtrEleTrksAsCands), "eleTracks");
216  auto tk2pc = std::make_unique<edm::Association<pat::PackedCandidateCollection>>(oh);
218  tk2pcFiller.insert(tracks, mapping.begin(), mapping.end());
219  tk2pcFiller.fill();
220  iEvent.put(std::move(tk2pc));
221 }
222 
224  const bool passTrkHits = tr.pt() > minPt_ && tr.numberOfValidHits() >= minHits_ &&
225  tr.hitPattern().numberOfValidPixelHits() >= minPixelHits_;
226  const bool passTrkQual = passesQuality(tr, qualsToAutoAccept_);
227 
228  return passTrkHits || passTrkQual || passThroughCut_(tr);
229 }
230 
231 void pat::PATLostTracks::addPackedCandidate(std::vector<pat::PackedCandidate>& cands,
232  const reco::TrackRef& trk,
233  const reco::VertexRef& pvSlimmed,
234  const reco::VertexRefProd& pvSlimmedColl,
235  const reco::Vertex& pvOrig,
236  const pat::PATLostTracks::TrkStatus trkStatus,
238  const float mass = 0.13957018;
239 
240  int id = 211 * trk->charge();
241  if (trkStatus == TrkStatus::PFELECTRON)
242  id = 11;
243  else if (trkStatus == TrkStatus::PFPOSITRON)
244  id = -11;
245 
246  // assign the proper pdgId for tracks that are reconstructed as a muon
247  for (auto& mu : *muons) {
248  if (reco::TrackRef(mu.innerTrack()) == trk) {
249  id = -13 * trk->charge();
250  break;
251  }
252  }
253 
255  int nlost = trk->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS);
256  if (nlost == 0) {
257  if (trk->hitPattern().hasValidHitInPixelLayer(PixelSubdetector::SubDetector::PixelBarrel, 1)) {
259  }
260  } else {
262  }
263 
264  reco::Candidate::PolarLorentzVector p4(trk->pt(), trk->eta(), trk->phi(), mass);
265  cands.emplace_back(
266  pat::PackedCandidate(p4, trk->vertex(), trk->pt(), trk->eta(), trk->phi(), id, pvSlimmedColl, pvSlimmed.key()));
267 
268  if (trk->quality(reco::TrackBase::highPurity))
269  cands.back().setTrackHighPurity(true);
270  else
271  cands.back().setTrackHighPurity(false);
272 
273  cands.back().setLostInnerHits(lostHits);
274  if (trk->pt() > minPtToStoreProps_ || trkStatus == TrkStatus::VTX)
275  cands.back().setTrackProperties(*trk, covarianceSchema_, covarianceVersion_);
276  if (pvOrig.trackWeight(trk) > 0.5) {
277  cands.back().setAssociationQuality(pat::PackedCandidate::UsedInFitTight);
278  }
279 }
280 
281 using pat::PATLostTracks;
edm::RefProd< VertexCollection >
edm::StreamID
Definition: StreamID.h:30
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
V0Monitor_cff.v0
v0
Definition: V0Monitor_cff.py:7
Muon.h
edm::Association::Filler
Definition: Association.h:78
pat::PATLostTracks::TrkStatus::PFCAND
pat::PATLostTracks::minPtToStoreProps_
const double minPtToStoreProps_
Definition: PATLostTracks.cc:69
pat::PATLostTracks::tracks_
const edm::EDGetTokenT< reco::TrackCollection > tracks_
Definition: PATLostTracks.cc:60
ESHandle.h
PFCandidate.h
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
pat::PATLostTracks::TrkStatus::PFPOSITRON
pat::PackedCandidate::oneLostInnerHit
Definition: PackedCandidate.h:802
edm::EDGetTokenT< reco::PFCandidateCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::TrackBase::undefQuality
Definition: TrackBase.h:151
reco::Candidate::PolarLorentzVector
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:38
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
lostTracks_cfi.lambdas
lambdas
Definition: lostTracks_cfi.py:9
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
pat::PATLostTracks::pv_
const edm::EDGetTokenT< reco::VertexCollection > pv_
Definition: PATLostTracks.cc:64
pat::PackedCandidate::moreLostInnerHits
Definition: PackedCandidate.h:803
pat::PATLostTracks::PATLostTracks
PATLostTracks(const edm::ParameterSet &)
Definition: PATLostTracks.cc:78
pat::PATLostTracks::passThroughCut_
StringCutObjectSelector< reco::Track, false > passThroughCut_
Definition: PATLostTracks.cc:74
mps_check.msg
tuple msg
Definition: mps_check.py:285
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
Association.h
pat::PATLostTracks::covarianceVersion_
const int covarianceVersion_
Definition: PATLostTracks.cc:70
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::Handle< reco::MuonCollection >
reco::TrackBase::numberOfValidHits
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:798
pat::PATLostTracks
Definition: PATLostTracks.cc:39
pat::PATLostTracks::minHits_
const double minHits_
Definition: PATLostTracks.cc:67
pat::PATLostTracks::TrkStatus
TrkStatus
Definition: PATLostTracks.cc:47
edm::Ref< TrackCollection >
pat::PackedCandidate::validHitInFirstPixelBarrelLayer
Definition: PackedCandidate.h:799
reco::TrackBase::pt
double pt() const
track transverse momentum
Definition: TrackBase.h:637
GeomDetEnumerators::PixelBarrel
Definition: GeomDetEnumerators.h:11
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
pat::PATLostTracks::TrkStatus::VTX
reco::Track
Definition: Track.h:27
pat::PATLostTracks::minPixelHits_
const double minPixelHits_
Definition: PATLostTracks.cc:68
pat::MuonCollection
std::vector< Muon > MuonCollection
Definition: Muon.h:35
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
pat::PATLostTracks::minPt_
const double minPt_
Definition: PATLostTracks.cc:66
edm::global::EDProducer
Definition: EDProducer.h:32
pat::PackedCandidate::noLostInnerHits
Definition: PackedCandidate.h:800
pat::PATLostTracks::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: PATLostTracks.cc:118
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
pat::PATLostTracks::muons_
const edm::EDGetTokenT< reco::MuonCollection > muons_
Definition: PATLostTracks.cc:73
HLT_FULL_cff.cands
cands
Definition: HLT_FULL_cff.py:15142
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
pat::PackedCandidate::LostInnerHits
LostInnerHits
Enumerator specifying the.
Definition: PackedCandidate.h:798
pat::PackedCandidate
Definition: PackedCandidate.h:22
PackedCandidate.h
reco::VertexRef
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
lostTracks_cfi.kshorts
kshorts
Definition: lostTracks_cfi.py:8
cand
Definition: decayParser.h:32
pat::PATLostTracks::qualsToAutoAccept_
std::vector< reco::TrackBase::TrackQuality > qualsToAutoAccept_
Definition: PATLostTracks.cc:72
createfilelist.int
int
Definition: createfilelist.py:10
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
iEvent
int iEvent
Definition: GenABIO.cc:224
pat::PATLostTracks::pvOrigs_
const edm::EDGetTokenT< reco::VertexCollection > pvOrigs_
Definition: PATLostTracks.cc:65
p4
double p4[4]
Definition: TauolaWrapper.h:92
GsfTrack.h
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
Jet.h
FSQDQM_cfi.pvs
pvs
Definition: FSQDQM_cfi.py:12
l1t::PFCandidateCollection
std::vector< l1t::PFCandidate > PFCandidateCollection
Definition: PFCandidate.h:57
pat::PATLostTracks::lambdas_
const edm::EDGetTokenT< reco::VertexCompositeCandidateCollection > lambdas_
Definition: PATLostTracks.cc:63
pat::PATLostTracks::addPackedCandidate
void addPackedCandidate(std::vector< pat::PackedCandidate > &cands, const reco::TrackRef &trk, const reco::VertexRef &pvSlimmed, const reco::VertexRefProd &pvSlimmedColl, const reco::Vertex &pvOrig, const TrkStatus trkStatus, edm::Handle< reco::MuonCollection > muons) const
Definition: PATLostTracks.cc:231
pat::PackedCandidateCollection
std::vector< pat::PackedCandidate > PackedCandidateCollection
Definition: PackedCandidate.h:1130
alignCSCRings.r
r
Definition: alignCSCRings.py:93
reco::VertexCompositeCandidateCollection
std::vector< VertexCompositeCandidate > VertexCompositeCandidateCollection
collection of Candidate objects
Definition: VertexCompositeCandidateFwd.h:19
pat::PATLostTracks::TrkStatus::PFCANDNOTRKPROPS
reco::TrackBase::qualityByName
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
VertexFwd.h
reco::Vertex::trackWeight
float trackWeight(const TREF &r) const
returns the weight with which a Track has contributed to the vertex-fit.
Definition: Vertex.h:85
pat::PATLostTracks::TrkStatus::NOTUSED
reco::TrackBase::hitPattern
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:504
pat::PATLostTracks::vertices_
const edm::EDGetTokenT< reco::VertexCollection > vertices_
Definition: PATLostTracks.cc:61
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::OrphanHandle
Definition: EDProductfwd.h:39
StringCutObjectSelector.h
RecoChargedCandidate.h
Frameworkfwd.h
pat::PATLostTracks::TrkStatus::PFELECTRON
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
electrons_cff.lostHits
lostHits
Definition: electrons_cff.py:428
pat::PATLostTracks::kshorts_
const edm::EDGetTokenT< reco::VertexCompositeCandidateCollection > kshorts_
Definition: PATLostTracks.cc:62
StringCutObjectSelector< reco::Track, false >
pat::PATLostTracks::covarianceSchema_
const int covarianceSchema_
Definition: PATLostTracks.cc:71
Exception
Definition: hltDiff.cc:246
reco::HitPattern::MISSING_INNER_HITS
Definition: HitPattern.h:155
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
reco::HitPattern::numberOfValidPixelHits
int numberOfValidPixelHits() const
Definition: HitPattern.h:800
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
edm::Ref::key
key_type key() const
Accessor for product key.
Definition: Ref.h:250
Candidate.h
View.h
ParameterSet.h
EDProducer.h
pat::PATLostTracks::~PATLostTracks
~PATLostTracks() override
Definition: PATLostTracks.cc:116
pat::PATLostTracks::cands_
const edm::EDGetTokenT< reco::PFCandidateCollection > cands_
Definition: PATLostTracks.cc:58
edm::Event
Definition: Event.h:73
pat::PackedCandidate::UsedInFitTight
Definition: PackedCandidate.h:727
crabWrapper.key
key
Definition: crabWrapper.py:19
pat::PATLostTracks::passTrkCuts
bool passTrkCuts(const reco::Track &tr) const
Definition: PATLostTracks.cc:223
taus_updatedMVAIds_cff.mapping
mapping
Definition: taus_updatedMVAIds_cff.py:29
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
reco::Vertex
Definition: Vertex.h:35
pat::PATLostTracks::map_
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > map_
Definition: PATLostTracks.cc:59
PFCandidateFwd.h
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7
reco::TrackBase::highPurity
Definition: TrackBase.h:154