CMS 3D CMS Logo

PATLostTracks.cc
Go to the documentation of this file.
1 #include <string>
2 
3 
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)) return true;
32  }
33  return false;
34  }
35 }
36 
37 namespace pat {
39  public:
40  explicit PATLostTracks(const edm::ParameterSet&);
42 
43  virtual void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
44 
45  private:
46  enum class TrkStatus {
47  NOTUSED=0,
48  PFCAND,
50  PFELECTRON,
51  PFPOSITRON,
52  VTX
53  };
54  bool passTrkCuts(const reco::Track& tr)const;
55  void addPackedCandidate(std::vector<pat::PackedCandidate>& cands,
56  const reco::TrackRef& trk,
57  const reco::VertexRef& pvSlimmed,
58  const reco::VertexRefProd& pvSlimmedColl,
59  const reco::Vertex& pvOrig,
60  const TrkStatus trkStatus)const;
61 
62  private:
71  const double minPt_;
72  const double minHits_;
73  const double minPixelHits_;
74  const double minPtToStoreProps_;
75  const int covarianceVersion_;
76  const int covarianceSchema_;
77  std::vector<reco::TrackBase::TrackQuality> qualsToAutoAccept_;
78  };
79 }
80 
82  cands_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("inputCandidates"))),
83  map_(consumes<edm::Association<pat::PackedCandidateCollection> >(iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
84  tracks_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("inputTracks"))),
85  vertices_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("secondaryVertices"))),
86  kshorts_(consumes<reco::VertexCompositeCandidateCollection>(iConfig.getParameter<edm::InputTag>("kshorts"))),
87  lambdas_(consumes<reco::VertexCompositeCandidateCollection>(iConfig.getParameter<edm::InputTag>("lambdas"))),
88  pv_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("primaryVertices"))),
89  pvOrigs_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("originalVertices"))),
90  minPt_(iConfig.getParameter<double>("minPt")),
91  minHits_(iConfig.getParameter<uint32_t>("minHits")),
92  minPixelHits_(iConfig.getParameter<uint32_t>("minPixelHits")) ,
93  minPtToStoreProps_(iConfig.getParameter<double>("minPtToStoreProps")),
94  covarianceVersion_(iConfig.getParameter<int >("covarianceVersion")),
95  covarianceSchema_(iConfig.getParameter<int >("covarianceSchema"))
96 
97 {
98  std::vector<std::string> trkQuals(iConfig.getParameter<std::vector<std::string> >("qualsToAutoAccept"));
99  std::transform(trkQuals.begin(),trkQuals.end(),std::back_inserter(qualsToAutoAccept_),reco::TrackBase::qualityByName);
100 
102  std::ostringstream msg;
103  msg<<" PATLostTracks has a quality requirement which resolves to undefQuality. This usually means a typo and is therefore treated a config error\nquality requirements:\n ";
104  for(const auto& trkQual : trkQuals) msg <<trkQual<<" ";
105  throw cms::Exception("Configuration") << msg.str();
106  }
107 
108  produces< std::vector<reco::Track> > ();
109  produces< std::vector<pat::PackedCandidate> > (); produces< std::vector<pat::PackedCandidate> > ("eleTracks");
110  produces< edm::Association<pat::PackedCandidateCollection> > ();
111 }
112 
114 
116 
118  iEvent.getByToken( cands_, cands );
119  std::vector<reco::Candidate>::const_iterator cand;
120 
122  iEvent.getByToken(map_,pf2pc);
123 
125  iEvent.getByToken( tracks_, tracks );
126 
128  iEvent.getByToken( vertices_, vertices );
129 
131  iEvent.getByToken( kshorts_, kshorts );
133  iEvent.getByToken( lambdas_, lambdas );
134 
136  iEvent.getByToken( pv_, pvs );
137  reco::VertexRef pv(pvs.id());
138  reco::VertexRefProd pvRefProd(pvs);
139  if (!pvs->empty()) {
140  pv = reco::VertexRef(pvs, 0);
141  }
143  iEvent.getByToken( pvOrigs_, pvOrigs );
144  const reco::Vertex & pvOrig = (*pvOrigs)[0];
145 
146  auto outPtrTrks = std::make_unique<std::vector<reco::Track>>();
147  auto outPtrTrksAsCands = std::make_unique<std::vector<pat::PackedCandidate>>();
148  auto outPtrEleTrksAsCands = std::make_unique<std::vector<pat::PackedCandidate>>();
149 
150  std::vector<TrkStatus> trkStatus(tracks->size(),TrkStatus::NOTUSED);
151  //Mark all tracks used in candidates
152  //check if packed candidates are storing the tracks by seeing if number of hits >0
153  //currently we dont use that information though
154  //electrons will never store their track (they store the GSF track)
155  for(unsigned int ic=0, nc = cands->size(); ic < nc; ++ic) {
157  const reco::PFCandidate &cand=(*cands)[ic];
158  if(cand.charge() && cand.trackRef().isNonnull() && cand.trackRef().id() == tracks.id() ) {
159 
160  if(cand.pdgId()==11) trkStatus[cand.trackRef().key()]=TrkStatus::PFELECTRON;
161  else if(cand.pdgId()==-11) trkStatus[cand.trackRef().key()]=TrkStatus::PFPOSITRON;
162  else if((*pf2pc)[r]->numberOfHits() > 0) trkStatus[cand.trackRef().key()]=TrkStatus::PFCAND;
163  else trkStatus[cand.trackRef().key()]=TrkStatus::PFCANDNOTRKPROPS;
164  }
165  }
166 
167  //Mark all tracks used in secondary vertices
168  for(const auto& secVert : *vertices){
169  for(auto trkIt = secVert.tracks_begin();trkIt!=secVert.tracks_end();trkIt++){
170  if(trkStatus[trkIt->key()]==TrkStatus::NOTUSED) trkStatus[trkIt->key()]=TrkStatus::VTX;
171  }
172  }
173  for(const auto& v0 : *kshorts){
174  for(size_t dIdx=0;dIdx<v0.numberOfDaughters(); dIdx++){
175  size_t key= (dynamic_cast<const reco::RecoChargedCandidate*>(v0.daughter(dIdx)))->track().key();
176  if(trkStatus[key]==TrkStatus::NOTUSED) trkStatus[key]=TrkStatus::VTX;
177  }
178  }
179  for(const auto& v0 : *lambdas){
180  for(size_t dIdx=0;dIdx<v0.numberOfDaughters(); dIdx++){
181  size_t key= (dynamic_cast<const reco::RecoChargedCandidate*>(v0.daughter(dIdx)))->track().key();
182  if(trkStatus[key]==TrkStatus::NOTUSED) trkStatus[key]=TrkStatus::VTX;
183  }
184  }
185  std::vector<int> mapping(tracks->size(),-1);
186  int lostTrkIndx=0;
187  for(unsigned int trkIndx=0; trkIndx < tracks->size(); trkIndx++){
188  reco::TrackRef trk(tracks,trkIndx);
189  if( trkStatus[trkIndx] == TrkStatus::VTX ||
190  (trkStatus[trkIndx]==TrkStatus::NOTUSED && passTrkCuts(*trk)) ) {
191 
192  outPtrTrks->emplace_back(*trk);
193  addPackedCandidate(*outPtrTrksAsCands,trk,pv,pvRefProd,pvOrig,trkStatus[trkIndx]);
194 
195  //for creating the reco::Track -> pat::PackedCandidate map
196  //not done for the lostTrack:eleTracks collection
197  mapping[trkIndx]=lostTrkIndx;
198  lostTrkIndx++;
199  }else if( (trkStatus[trkIndx]==TrkStatus::PFELECTRON || trkStatus[trkIndx]==TrkStatus::PFPOSITRON )
200  && passTrkCuts(*trk) ) {
201  addPackedCandidate(*outPtrEleTrksAsCands,trk,pv,pvRefProd,pvOrig,trkStatus[trkIndx]);
202 
203 
204  }
205  }
206 
207  iEvent.put(std::move(outPtrTrks));
208  iEvent.put(std::move(outPtrEleTrksAsCands),"eleTracks");
209  edm::OrphanHandle<pat::PackedCandidateCollection> oh = iEvent.put(std::move(outPtrTrksAsCands));
210  auto tk2pc = std::make_unique<edm::Association<pat::PackedCandidateCollection>>(oh);
212  tk2pcFiller.insert(tracks, mapping.begin(), mapping.end());
213  tk2pcFiller.fill() ;
214  iEvent.put(std::move(tk2pc));
215 }
216 
218 {
219  const bool passTrkHits = tr.pt() > minPt_ &&
220  tr.numberOfValidHits() >= minHits_ &&
222  const bool passTrkQual = passesQuality(tr,qualsToAutoAccept_);
223 
224  return passTrkHits || passTrkQual;
225 }
226 
227 void pat::PATLostTracks::addPackedCandidate(std::vector<pat::PackedCandidate>& cands,
228  const reco::TrackRef& trk,
229  const reco::VertexRef& pvSlimmed,
230  const reco::VertexRefProd& pvSlimmedColl,
231  const reco::Vertex& pvOrig,
232  const pat::PATLostTracks::TrkStatus trkStatus)const
233 {
234  const float mass = 0.13957018;
235 
236  int id=211*trk->charge();
237  if(trkStatus==TrkStatus::PFELECTRON) id=11;
238  else if(trkStatus==TrkStatus::PFPOSITRON) id=-11;
239 
240  reco::Candidate::PolarLorentzVector p4(trk->pt(),trk->eta(),trk->phi(),mass);
241  cands.emplace_back(pat::PackedCandidate(p4,trk->vertex(),
242  trk->pt(),trk->eta(),trk->phi(),
243  id,pvSlimmedColl,pvSlimmed.key()));
244 
245  if(trk->pt()>minPtToStoreProps_ || trkStatus==TrkStatus::VTX) cands.back().setTrackProperties(*trk,covarianceSchema_,covarianceVersion_);
246  if(pvOrig.trackWeight(trk) > 0.5) {
247  cands.back().setAssociationQuality(pat::PackedCandidate::UsedInFitTight);
248  }
249 }
250 
251 
252 
253 using pat::PATLostTracks;
T getParameter(std::string const &) const
int pdgId() const final
PDG identifier.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
std::vector< VertexCompositeCandidate > VertexCompositeCandidateCollection
collection of Candidate objects
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
const double minPt_
const double minPtToStoreProps_
ProductID id() const
Definition: HandleBase.cc:15
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< pat::PackedCandidate > PackedCandidateCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
const int covarianceSchema_
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
int charge() const final
electric charge
Definition: LeafCandidate.h:91
key_type key() const
Accessor for product key.
Definition: Ref.h:265
PATLostTracks(const edm::ParameterSet &)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
const int covarianceVersion_
ProductID id() const
Accessor for product ID.
Definition: Ref.h:259
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:438
const double minHits_
const edm::EDGetTokenT< reco::PFCandidateCollection > cands_
int iEvent
Definition: GenABIO.cc:230
double p4[4]
Definition: TauolaWrapper.h:92
double pt() const
track transverse momentum
Definition: TrackBase.h:621
const edm::EDGetTokenT< reco::VertexCompositeCandidateCollection > lambdas_
def pv(vc)
Definition: MetAnalyzer.py:6
virtual void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:820
float trackWeight(const TREF &r) const
returns the weight with which a Track has contributed to the vertex-fit.
Definition: Vertex.h:81
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
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) const
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:125
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > map_
bool passTrkCuts(const reco::Track &tr) const
const edm::EDGetTokenT< reco::TrackCollection > tracks_
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:446
const edm::EDGetTokenT< reco::VertexCollection > vertices_
tuple msg
Definition: mps_check.py:277
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:510
const edm::EDGetTokenT< reco::VertexCompositeCandidateCollection > kshorts_
std::vector< reco::TrackBase::TrackQuality > qualsToAutoAccept_
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
fixed size matrix
HLT enums.
int numberOfValidPixelHits() const
Definition: HitPattern.h:838
const double minPixelHits_
const edm::EDGetTokenT< reco::VertexCollection > pv_
def move(src, dest)
Definition: eostools.py:510
const edm::EDGetTokenT< reco::VertexCollection > pvOrigs_
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:39