CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackAssociatorEDProducer.cc
Go to the documentation of this file.
1 //
2 // Original Author: Stefano Magni
3 // Created: Fri Mar 9 10:52:11 CET 2007
4 //
5 //
6 
7 
8 // system include files
9 #include <memory>
10 #include <string>
11 
12 // user include files
14 
17 
19 
21 
24 
27 
29 
30 
31 
32 //
33 // class decleration
34 //
35 
37 public:
40 
41 private:
42  virtual void beginJob() override {}
43  virtual void produce(edm::Event&, const edm::EventSetup&) override;
44  virtual void endJob() override ;
45 
47  bool first;
52 
55 
56 };
57 
59  first(true),
60  label_tr(pset.getParameter< edm::InputTag >("label_tr")),
61  label_tp(pset.getParameter< edm::InputTag >("label_tp")),
62  associator(pset.getParameter< std::string >("associator")),
63  theIgnoremissingtrackcollection(pset.getUntrackedParameter<bool>("ignoremissingtrackcollection",false))
64 {
65  produces<reco::SimToRecoCollection>();
66  produces<reco::RecoToSimCollection>();
67 
68  TPCollectionToken_ = consumes<TrackingParticleCollection>(pset.getParameter< edm::InputTag >("label_tp"));
69  trackCollectionToken_ = consumes<edm::View<reco::Track> >(pset.getParameter< edm::InputTag >("label_tr"));
70 
71 }
72 
73 
75 
76 }
77 
78 
79 //
80 // member functions
81 //
82 
83 // ------------ method called to produce the data ------------
84 void
86  using namespace edm;
87  if(first){
89  first = false;
90  }
92  // iEvent.getByLabel(label_tp, TPCollection);
94 
95  Handle<edm::View<reco::Track> > trackCollection;
96  // bool trackAvailable = iEvent.getByLabel (label_tr, trackCollection );
97  bool trackAvailable = iEvent.getByToken(trackCollectionToken_, trackCollection );
98 
99  std::auto_ptr<reco::RecoToSimCollection> rts;
100  std::auto_ptr<reco::SimToRecoCollection> str;
101 
102  if (theIgnoremissingtrackcollection && !trackAvailable){
103  //the track collection is not in the event and we're being told to ignore this.
104  //do not output anything to the event, other wise this would be considered as inefficiency.
105  } else {
106  //associate tracks
107  LogTrace("TrackValidator") << "Calling associateRecoToSim method" << "\n";
108  reco::RecoToSimCollection recSimColl=theAssociator->associateRecoToSim(trackCollection,
109  TPCollection,
110  &iEvent, &iSetup);
111  LogTrace("TrackValidator") << "Calling associateSimToReco method" << "\n";
112  reco::SimToRecoCollection simRecColl=theAssociator->associateSimToReco(trackCollection,
113  TPCollection,
114  &iEvent, &iSetup);
115 
116  rts.reset(new reco::RecoToSimCollection(recSimColl));
117  str.reset(new reco::SimToRecoCollection(simRecColl));
118 
119  iEvent.put(rts);
120  iEvent.put(str);
121  }
122 }
123 
124 // ------------ method called once each job just before starting event loop ------------
125 
126 // ------------ method called once each job just after ending the event loop ------------
127 void
129 }
130 
131 //define this as a plug-in
edm::EDGetTokenT< edm::View< reco::Track > > trackCollectionToken_
T getParameter(std::string const &) const
virtual void beginJob() override
virtual void produce(edm::Event &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
TrackAssociatorEDProducer(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:230
edm::ESHandle< TrackAssociatorBase > theAssociator
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
bool first
Definition: L1TdeRCT.cc:75
#define LogTrace(id)
const T & get() const
Definition: EventSetup.h:55
volatile std::atomic< bool > shutdown_flag false
edm::EDGetTokenT< TrackingParticleCollection > TPCollectionToken_