Go to the documentation of this file.00001
00002
00003
00004
00005
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <memory>
00019 #include <string>
00020
00021
00022 #include "FWCore/Framework/interface/Frameworkfwd.h"
00023 #include "FWCore/Framework/interface/EDProducer.h"
00024
00025 #include "FWCore/Framework/interface/Event.h"
00026 #include "FWCore/Framework/interface/MakerMacros.h"
00027
00028 #include "FWCore/Utilities/interface/InputTag.h"
00029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00030
00031 #include "DataFormats/MuonReco/interface/Muon.h"
00032 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00033 #include "DataFormats/Candidate/interface/LeafCandidate.h"
00034
00035 #include "DataFormats/TrackReco/interface/Track.h"
00036 #include "DataFormats/PatCandidates/interface/Muon.h"
00037 #include "DataFormats/PatCandidates/interface/CompositeCandidate.h"
00038
00039 #include "MuonAnalysis/MomentumScaleCalibration/interface/Functions.h"
00040
00041 #include "CondFormats/RecoMuonObjects/interface/MuScleFitDBobject.h"
00042 #include "CondFormats/DataRecord/interface/MuScleFitDBobjectRcd.h"
00043
00044 #include "FWCore/Framework/interface/EventSetup.h"
00045 #include "FWCore/Framework/interface/ESHandle.h"
00046 #include "MuonAnalysis/MomentumScaleCalibration/interface/MomentumScaleCorrector.h"
00047
00048 class MuScleFitMuonProducer : public edm::EDProducer {
00049 public:
00050 explicit MuScleFitMuonProducer(const edm::ParameterSet&);
00051 ~MuScleFitMuonProducer();
00052
00053 private:
00054 virtual void beginJob() ;
00055 virtual void produce(edm::Event&, const edm::EventSetup&);
00056 virtual void endJob() ;
00057 template<class T> std::auto_ptr<T> applyCorrection(const edm::Handle<T> & allMuons);
00058
00059 edm::InputTag theMuonLabel_;
00060 bool patMuons_;
00061 edm::ESHandle<MuScleFitDBobject> dbObject_;
00062 std::string dbObjectLabel_;
00063 unsigned long long dbObjectCacheId_;
00064 boost::shared_ptr<MomentumScaleCorrector> corrector_;
00065 };
00066
00067 MuScleFitMuonProducer::MuScleFitMuonProducer(const edm::ParameterSet& iConfig) :
00068 theMuonLabel_( iConfig.getParameter<edm::InputTag>( "MuonLabel" ) ),
00069 patMuons_( iConfig.getParameter<bool>( "PatMuons" ) ),
00070 dbObjectLabel_( iConfig.getUntrackedParameter<std::string>("DbObjectLabel", "") ),
00071 dbObjectCacheId_(0)
00072 {
00073 if ( patMuons_ == true ) {
00074 produces<pat::MuonCollection>();
00075 } else {
00076 produces<reco::MuonCollection>();
00077 }
00078 }
00079
00080
00081 MuScleFitMuonProducer::~MuScleFitMuonProducer()
00082 {
00083 }
00084
00085
00086 template<class T>
00087 std::auto_ptr<T> MuScleFitMuonProducer::applyCorrection(const edm::Handle<T> & allMuons)
00088 {
00089 std::auto_ptr<T> pOut(new T);
00090
00091
00092 for( typename T::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon ) {
00093
00094
00095 double pt = (*corrector_)(*muon);
00096
00097 double eta = muon->eta();
00098 double phi = muon->phi();
00099
00100 typename T::value_type * newMuon = muon->clone();
00101 newMuon->setP4( reco::Particle::PolarLorentzVector( pt, eta, phi, muon->mass() ) );
00102
00103 pOut->push_back(*newMuon);
00104 }
00105 return pOut;
00106 }
00107
00108
00109 void MuScleFitMuonProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00110 {
00111 unsigned long long dbObjectCacheId = iSetup.get<MuScleFitDBobjectRcd>().cacheIdentifier();
00112 if ( dbObjectCacheId != dbObjectCacheId_ ) {
00113 if ( dbObjectLabel_ != "" ) {
00114 iSetup.get<MuScleFitDBobjectRcd>().get(dbObjectLabel_, dbObject_);
00115 } else {
00116 iSetup.get<MuScleFitDBobjectRcd>().get(dbObject_);
00117 }
00118 }
00119
00120
00121
00122
00123
00124 corrector_.reset(new MomentumScaleCorrector( dbObject_.product() ) );
00125
00126 if( patMuons_ == true ) {
00127 edm::Handle<pat::MuonCollection> allMuons;
00128 iEvent.getByLabel (theMuonLabel_, allMuons);
00129 iEvent.put(applyCorrection(allMuons));
00130 }
00131 else {
00132 edm::Handle<reco::MuonCollection> allMuons;
00133 iEvent.getByLabel (theMuonLabel_, allMuons);
00134 iEvent.put(applyCorrection(allMuons));
00135 }
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 }
00158
00159
00160 void
00161 MuScleFitMuonProducer::beginJob()
00162 {
00163 }
00164
00165
00166 void
00167 MuScleFitMuonProducer::endJob()
00168 {
00169 }
00170
00171
00172 DEFINE_FWK_MODULE(MuScleFitMuonProducer);