CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PATLostTracks.cc
Go to the documentation of this file.
1 #include <string>
2 
3 
26 
27 
28 namespace pat {
29  class PATLostTracks : public edm::EDProducer {
30  public:
31  explicit PATLostTracks(const edm::ParameterSet&);
33 
34  virtual void produce(edm::Event&, const edm::EventSetup&);
35 
36  private:
43  double minPt_;
44  double minHits_;
45  double minPixelHits_;
46  };
47 }
48 
50  Cands_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("inputCandidates"))),
51  map_(consumes<edm::Association<pat::PackedCandidateCollection> >(iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
52  Tracks_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("inputTracks"))),
53  Vertices_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("secondaryVertices"))),
54  PV_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("primaryVertices"))),
55  PVOrigs_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("originalVertices"))),
56  minPt_(iConfig.getParameter<double>("minPt")),
57  minHits_(iConfig.getParameter<uint32_t>("minHits")),
58  minPixelHits_(iConfig.getParameter<uint32_t>("minPixelHits"))
59 {
60  produces< std::vector<reco::Track> > ();
61  produces< std::vector<pat::PackedCandidate> > ();
62  produces< edm::Association<pat::PackedCandidateCollection> > ();
63 
64 }
65 
67 
69 
71  iEvent.getByToken( Cands_, cands );
72  std::vector<reco::Candidate>::const_iterator cand;
73 
75  iEvent.getByToken(map_,pf2pc);
76 
78  iEvent.getByToken( Tracks_, tracks );
79 
81  iEvent.getByToken( Vertices_, vertices );
82 
84  iEvent.getByToken( PV_, pvs );
85  reco::VertexRef PV(pvs.id());
86  reco::VertexRefProd PVRefProd(pvs);
87  if (!pvs->empty()) {
88  PV = reco::VertexRef(pvs, 0);
89  }
91  iEvent.getByToken( PVOrigs_, PVOrigs );
92  const reco::Vertex & PVOrig = (*PVOrigs)[0];
93 
94  std::auto_ptr< std::vector<reco::Track> > outPtrP( new std::vector<reco::Track> );
95  std::vector<int> used(tracks->size(),0);
96 
97  std::auto_ptr< std::vector<pat::PackedCandidate> > outPtrC( new std::vector<pat::PackedCandidate> );
98 
99  //Mark all tracks used in candidates
100  for(unsigned int ic=0, nc = cands->size(); ic < nc; ++ic) {
102  const reco::PFCandidate &cand=(*cands)[ic];
103  if (cand.charge()) {
104  if(cand.trackRef().isNonnull() && cand.trackRef().id() ==tracks.id() && (*pf2pc)[r]->numberOfHits() > 0) // also check if packed candidates are storing the tracks for this one
105  {
106  used[cand.trackRef().key()]=1;
107  }
108  }
109  }
110 
111  //Mark all tracks used in secondary vertices
112  for(unsigned int i=0; i < vertices->size(); i++){
113  const reco::Vertex & sv = (*vertices)[i];
114  for(reco::Vertex::trackRef_iterator it = sv.tracks_begin(),e=sv.tracks_end(); it!=e;it++){
115  if(used[it->key()]==0) used[it->key()]=2; // mark as white list
116  }
117  }
118 
119  std::vector<int> mapping(tracks->size(),-1);
120  int j=0;
121  for(unsigned int i=0; i < used.size(); i++)
122  {
123  const reco::Track & tr = (*tracks)[i];
124  if(used[i] == 2 ||
125  (used[i]==0 && tr.pt() > minPt_ && tr.numberOfValidHits() >= minHits_ && tr.hitPattern().numberOfValidPixelHits() >= minPixelHits_ )
126  )
127  {
128  outPtrP->push_back(tr);
129  reco::Candidate::PolarLorentzVector p4(tr.pt(),tr.eta(),tr.phi(),0.13957018);
130  outPtrC->push_back(pat::PackedCandidate(p4,tr.vertex(),tr.phi(),211*tr.charge(),PVRefProd,PV.key()));
131  outPtrC->back().setTrackProperties((*tracks)[i]);
132  if(PVOrig.trackWeight(edm::Ref<reco::TrackCollection>(tracks,i)) > 0.5) {
133  outPtrC->back().setAssociationQuality(pat::PackedCandidate::UsedInFitTight);
134  }
135 
136  mapping[i]=j;
137  j++;
138  }
139  }
140  iEvent.put(outPtrP);
142  std::auto_ptr<edm::Association<pat::PackedCandidateCollection> > tk2pc(new edm::Association<pat::PackedCandidateCollection>(oh ));
144  tk2pcFiller.insert(tracks, mapping.begin(), mapping.end());
145  tk2pcFiller.fill() ;
146  iEvent.put(tk2pc);
147 
148 }
149 
150 
151 using pat::PATLostTracks;
int i
Definition: DBlmapReader.cc:9
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:44
ProductID id() const
Definition: HandleBase.cc:15
edm::EDGetTokenT< reco::PFCandidateCollection > Cands_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< pat::PackedCandidate > PackedCandidateCollection
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:13
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:608
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
key_type key() const
Accessor for product key.
Definition: Ref.h:264
PATLostTracks(const edm::ParameterSet &)
ProductID id() const
Accessor for product ID.
Definition: Ref.h:258
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:433
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:650
int iEvent
Definition: GenABIO.cc:230
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:614
edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > map_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
float trackWeight(const TrackBaseRef &r) const
returns the weight with which a Track has contributed to the vertex-fit.
double p4[4]
Definition: TauolaWrapper.h:92
double pt() const
track transverse momentum
Definition: TrackBase.h:584
virtual int charge() const
electric charge
Definition: LeafCandidate.h:91
int j
Definition: DBlmapReader.cc:9
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:783
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:421
tuple tracks
Definition: testEve_cfg.py:39
edm::EDGetTokenT< reco::TrackCollection > Tracks_
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector&lt;TrackRef&gt;
Definition: Vertex.h:37
int numberOfValidPixelHits() const
Definition: HitPattern.h:749
int charge() const
track electric charge
Definition: TrackBase.h:530
edm::EDGetTokenT< reco::VertexCollection > PVOrigs_
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:39
edm::EDGetTokenT< reco::VertexCollection > Vertices_
virtual void produce(edm::Event &, const edm::EventSetup &)
edm::EDGetTokenT< reco::VertexCollection > PV_
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:39