CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackMCQuality.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TrackMCQuality
4 // Class: TrackMCQuality
5 //
13 //
14 // Original Author: Jean-Roch Vlimant
15 // Created: Fri Mar 27 15:19:03 CET 2009
16 // $Id: TrackMCQuality.cc,v 1.1 2009/03/31 12:30:02 vlimant Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
27 
30 
33 
36 
39 
40 //
41 // class decleration
42 //
43 
45  public:
46  explicit TrackMCQuality(const edm::ParameterSet&);
48 
49  private:
50  virtual void beginJob() ;
51  virtual void produce(edm::Event&, const edm::EventSetup&);
52  virtual void endJob() ;
53 
54  // ----------member data ---------------------------
55 
59  std::string associator;
60 };
61 
62 //
63 // constants, enums and typedefs
64 //
65 
66 
67 //
68 // static data member definitions
69 //
70 
71 //
72 // constructors and destructor
73 //
75  label_tr(pset.getParameter< edm::InputTag >("label_tr")),
76  label_tp(pset.getParameter< edm::InputTag >("label_tp")),
77  associator(pset.getParameter< std::string >("associator"))
78 {
79 
80  produces<reco::TrackCollection>();
81 }
82 
83 
85 {
86 }
87 
88 
89 //
90 // member functions
91 //
92 
93 // ------------ method called to produce the data ------------
94 void
96 {
97 
99 
100 
101  using namespace edm;
104 
105  Handle<edm::View<reco::Track> > trackCollection;
106  iEvent.getByLabel (label_tr, trackCollection );
107 
108  reco::RecoToSimCollection recSimColl=theAssociator->associateRecoToSim(trackCollection,
109  TPCollection,
110  &iEvent);
111 
112  //then loop the track collection
113  std::auto_ptr<reco::TrackCollection> outTracks(new reco::TrackCollection(trackCollection->size()));
114 
115  for (unsigned int iT=0;iT!=trackCollection->size();++iT){
116  edm::RefToBase<reco::Track> track(trackCollection, iT);
117  bool matched=false;
118  //find it in the map
119  if (recSimColl.find(track)!=recSimColl.end()){
120  // you can get the data if you want
121  std::vector<std::pair<TrackingParticleRef, double> > tp= recSimColl[track];
122  matched=true;
123  }
124  else{
125  matched=false;
126  }
127 
128  //copy the track into the new container
129  (*outTracks)[iT] = reco::Track(*track);
130  if (matched){
131  (*outTracks)[iT].setQuality(reco::TrackBase::qualitySize); //is not assigned to any quality. use it as a fake/matched flag
132  }
133  }
134 
135  iEvent.put(outTracks);
136 }
137 
138 // ------------ method called once each job just before starting event loop ------------
139 void
141 {
142 }
143 
144 // ------------ method called once each job just after ending the event loop ------------
145 void
147 }
148 
149 //define this as a plug-in
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void produce(edm::Event &, const edm::EventSetup &)
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
std::string associator
virtual void beginJob()
virtual void endJob()
TrackMCQuality(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:243
edm::InputTag label_tr
edm::InputTag label_tp
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
const T & get() const
Definition: EventSetup.h:55
edm::ESHandle< TrackAssociatorBase > theAssociator