Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <memory>
00011 #include <string>
00012
00013
00014 #include "FWCore/Framework/interface/EDProducer.h"
00015
00016 #include "FWCore/Framework/interface/Event.h"
00017 #include "FWCore/Framework/interface/MakerMacros.h"
00018
00019 #include "FWCore/Framework/interface/ESHandle.h"
00020
00021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00022
00023 #include "SimTracker/TrackAssociation/interface/TrackAssociatorBase.h"
00024 #include "SimTracker/Records/interface/TrackAssociatorRecord.h"
00025
00026 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
00027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00028
00029
00030
00031
00032
00033 class TrackAssociatorEDProducer : public edm::EDProducer {
00034 public:
00035 explicit TrackAssociatorEDProducer(const edm::ParameterSet&);
00036 ~TrackAssociatorEDProducer();
00037
00038 private:
00039 virtual void beginJob() {}
00040 virtual void produce(edm::Event&, const edm::EventSetup&);
00041 virtual void endJob() ;
00042
00043 edm::ESHandle<TrackAssociatorBase> theAssociator;
00044 bool first;
00045 edm::InputTag label_tr;
00046 edm::InputTag label_tp;
00047 std::string associator;
00048 bool theIgnoremissingtrackcollection;
00049 };
00050
00051 TrackAssociatorEDProducer::TrackAssociatorEDProducer(const edm::ParameterSet& pset):
00052 first(true),
00053 label_tr(pset.getParameter< edm::InputTag >("label_tr")),
00054 label_tp(pset.getParameter< edm::InputTag >("label_tp")),
00055 associator(pset.getParameter< std::string >("associator")),
00056 theIgnoremissingtrackcollection(pset.getUntrackedParameter<bool>("ignoremissingtrackcollection",false))
00057 {
00058 produces<reco::SimToRecoCollection>();
00059 produces<reco::RecoToSimCollection>();
00060 }
00061
00062
00063 TrackAssociatorEDProducer::~TrackAssociatorEDProducer() {
00064
00065 }
00066
00067
00068
00069
00070
00071
00072
00073 void
00074 TrackAssociatorEDProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
00075 using namespace edm;
00076 if(first){
00077 iSetup.get<TrackAssociatorRecord>().get(associator,theAssociator);
00078 first = false;
00079 }
00080 Handle<TrackingParticleCollection> TPCollection ;
00081 iEvent.getByLabel(label_tp, TPCollection);
00082
00083 Handle<edm::View<reco::Track> > trackCollection;
00084 bool trackAvailable = iEvent.getByLabel (label_tr, trackCollection );
00085
00086 std::auto_ptr<reco::RecoToSimCollection> rts;
00087 std::auto_ptr<reco::SimToRecoCollection> str;
00088
00089 if (theIgnoremissingtrackcollection && !trackAvailable){
00090
00091
00092 }else{
00093
00094 LogTrace("TrackValidator") << "Calling associateRecoToSim method" << "\n";
00095 reco::RecoToSimCollection recSimColl=theAssociator->associateRecoToSim(trackCollection,
00096 TPCollection,
00097 &iEvent);
00098 LogTrace("TrackValidator") << "Calling associateSimToReco method" << "\n";
00099 reco::SimToRecoCollection simRecColl=theAssociator->associateSimToReco(trackCollection,
00100 TPCollection,
00101 &iEvent);
00102
00103 rts.reset(new reco::RecoToSimCollection(recSimColl));
00104 str.reset(new reco::SimToRecoCollection(simRecColl));
00105
00106 iEvent.put(rts);
00107 iEvent.put(str);
00108 }
00109 }
00110
00111
00112
00113
00114 void
00115 TrackAssociatorEDProducer::endJob() {
00116 }
00117
00118
00119 DEFINE_FWK_MODULE(TrackAssociatorEDProducer);