CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackAndVertexUnpacker.cc
Go to the documentation of this file.
1 
13 
14 //#include "DataFormats/Common/interface/ValueMap.h"
15 //#include "DataFormats/Common/interface/View.h"
16 //#include "DataFormats/PatCandidates/interface/Vertexing.h"
17 
21 
22 //#include "PhysicsTools/PatAlgos/interface/VertexingHelper.h"
23 
24 
25 namespace pat {
26 
28 
29 
30  public:
31 
32  explicit PATTrackAndVertexUnpacker(const edm::ParameterSet & iConfig);
34 
35  virtual void produce(edm::Event & iEvent, const edm::EventSetup& iSetup) override;
36 
37  private:
38  typedef std::vector<edm::InputTag> VInputTag;
39  // configurables
44 
45  };
46 
47 }
48 
50 
51 PATTrackAndVertexUnpacker::PATTrackAndVertexUnpacker(const edm::ParameterSet& iConfig) :
52  Cands_(consumes< std::vector<pat::PackedCandidate> >(iConfig.getParameter<edm::InputTag>("packedCandidates"))),
53  PVs_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("slimmedVertices"))),
54  AdditionalTracks_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("additionalTracks")))
55 {
56  produces<reco::TrackCollection>();
57  produces<reco::VertexCollection>();
58 }
59 
60 
62 }
63 
64 
66  using namespace edm; using namespace std; using namespace reco;
68  iEvent.getByToken(Cands_, cands);
70  iEvent.getByToken(PVs_, pvs);
71  Handle<TrackCollection> addTracks;
72  iEvent.getByToken(AdditionalTracks_, addTracks);
73 
74  std::auto_ptr< std::vector<reco::Track> > outTks( new std::vector<reco::Track> );
75  std::vector<unsigned int> asso;
76  unsigned int j=0;
77  for(unsigned int i=0;i<cands->size();i++) {
78  const pat::PackedCandidate & c = (*cands)[i];
79  if(c.charge() != 0 && c.pt() > 0.95){
80  outTks->push_back(c.pseudoTrack());
82  {
83  asso.push_back(j);
84  }
85  j++;
86  }
87  }
88  reco::Vertex pv = (*pvs)[0];
89  std::auto_ptr< std::vector<reco::Vertex> > outPv( new std::vector<reco::Vertex> );
90  for(unsigned int i = 0; i < addTracks->size(); i++) {
91  outTks->push_back((*addTracks)[i]);
92  }
93  edm::OrphanHandle< std::vector<reco::Track> > oh = iEvent.put( outTks );
94  for(unsigned int i=0;i<asso.size();i++)
95  {
96  TrackRef r(oh,asso[i]);
97  TrackBaseRef rr(r);
98  pv.add(rr);
99  }
100  outPv->push_back(pv);
101  iEvent.put(outPv);
102 }
103 
104 
106 
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
edm::EDGetTokenT< reco::TrackCollection > AdditionalTracks_
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
virtual float pt() const
transverse momentum
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
int j
Definition: DBlmapReader.cc:9
virtual int charge() const
electric charge
std::vector< edm::InputTag > VInputTag
edm::EDGetTokenT< std::vector< pat::PackedCandidate > > Cands_
PATTrackAndVertexUnpacker(const edm::ParameterSet &iConfig)
edm::EDGetTokenT< reco::VertexCollection > PVs_
const PVAssoc fromPV() const
virtual reco::Track pseudoTrack() const
Return by value (no caching heavy function) a pseudo track made with candidate kinematics, parameterized error for eta,phi,pt and full IP covariance.