CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/SimTracker/TrackAssociation/plugins/TrackAssociatorEDProducer.cc

Go to the documentation of this file.
00001 //
00002 // Original Author:  Stefano Magni
00003 //         Created:  Fri Mar  9 10:52:11 CET 2007
00004 // $Id: TrackAssociatorEDProducer.cc,v 1.7 2009/11/13 14:15:53 fambrogl Exp $
00005 //
00006 //
00007 
00008 
00009 // system include files
00010 #include <memory>
00011 #include <string>
00012 
00013 // user include files
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 // class decleration
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 // member functions
00070 //
00071 
00072 // ------------ method called to produce the data  ------------
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      //the track collection is not in the event and we're being told to ignore this.
00091      //do not output anything to the event, other wise this would be considered as inefficiency.
00092    }else{
00093      //associate tracks
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 // ------------ method called once each job just before starting event loop  ------------
00112 
00113 // ------------ method called once each job just after ending the event loop  ------------
00114 void 
00115 TrackAssociatorEDProducer::endJob() {
00116 }
00117 
00118 //define this as a plug-in
00119 DEFINE_FWK_MODULE(TrackAssociatorEDProducer);