CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/MuonAnalysis/MomentumScaleCalibration/plugins/MuScleFitMuonProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    MuScleFitMuonProducer
00004 // Class:      MuScleFitMuonProducer
00005 // 
00013 //
00014 // Original Author:  Marco De Mattia,40 3-B32,+41227671551,
00015 //         Created:  Tue Jun 22 13:50:22 CEST 2010
00016 // $Id: MuScleFitMuonProducer.cc,v 1.2 2010/09/16 13:51:59 demattia Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDProducer.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 
00031 #include "FWCore/Utilities/interface/InputTag.h"
00032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00033 
00034 #include "DataFormats/MuonReco/interface/Muon.h"
00035 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00036 #include "DataFormats/Candidate/interface/LeafCandidate.h"
00037 
00038 #include "DataFormats/TrackReco/interface/Track.h"
00039 #include "DataFormats/PatCandidates/interface/Muon.h"
00040 #include "DataFormats/PatCandidates/interface/CompositeCandidate.h"
00041 
00042 #include "MuonAnalysis/MomentumScaleCalibration/interface/Functions.h"
00043 
00044 class MuScleFitMuonProducer : public edm::EDProducer {
00045    public:
00046       explicit MuScleFitMuonProducer(const edm::ParameterSet&);
00047       ~MuScleFitMuonProducer();
00048 
00049    private:
00050       virtual void beginJob() ;
00051       virtual void produce(edm::Event&, const edm::EventSetup&);
00052       virtual void endJob() ;
00053 
00054   edm::InputTag theMuonLabel_;
00055   // Contains the numbers taken from the J/Psi
00056   // smearFunctionType7 smearFunction;
00057 };
00058 
00059 MuScleFitMuonProducer::MuScleFitMuonProducer(const edm::ParameterSet& iConfig) :
00060   theMuonLabel_( iConfig.getParameter<edm::InputTag>( "MuonLabel" ) )
00061 {
00062   produces<reco::MuonCollection>();
00063 }
00064 
00065 
00066 MuScleFitMuonProducer::~MuScleFitMuonProducer()
00067 {
00068 }
00069 
00070 // ------------ method called to produce the data  ------------
00071 void MuScleFitMuonProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00072 {
00073   edm::Handle<reco::MuonCollection> allMuons;
00074   iEvent.getByLabel (theMuonLabel_, allMuons);
00075 
00076   std::auto_ptr<reco::MuonCollection> pOut(new reco::MuonCollection);
00077 
00078   // Apply any bias and/or smearing to the events
00079   for( std::vector<reco::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon ) {
00080 
00081     double pt = muon->pt();
00082 
00083     // Biasing the MC such that it reproduces the data + the residual error
00084     double a_0 = 1.0039;
00085     // double a_1 = 0.;
00086     // // The miscalibration can be applied only for pt < 626 GeV/c
00087     // if( pt < -a_0*a_0/(4*a_1) ) {
00088     // pt = (-a_0 + sqrt(a_0*a_0 + 4*a_1*pt))/(2*a_1);
00089     // }
00090     pt = a_0*pt;
00091 
00092     // Smearing
00093     // std::cout << "smearing muon" << std::endl;
00094     // std::vector<double> par;
00095     // double * y = 0;
00096     TF1 G("G", "[0]*exp(-0.5*pow(x,2)/[1])", -5., 5.);
00097     double sigma = 0.00014; // converted from TeV^-1 to GeV^-1
00098     double norm = 1/(sqrt(2*TMath::Pi()));
00099     G.SetParameter(0,norm);
00100     G.SetParameter(1,1);
00101     // std::cout << "old pt = " << pt;
00102     pt = 1/(1/pt + sigma*G.GetRandom());
00103     // pt' = pt + sigma pt^2
00104     // pt = pt*(1-G.GetRandom());
00105     double eta = muon->eta();
00106     double phi = muon->phi();
00107     // smearFunction.smear(pt, eta, phi, y, par);
00108     // std::cout << " new pt = " << pt << std::endl;
00109 
00110     reco::Muon * newMuon = muon->clone();
00111     newMuon->setP4( reco::Particle::PolarLorentzVector( pt, eta, phi, muon->mass() ) );
00112 
00113     pOut->push_back(*newMuon);
00114   }
00115 
00116   // put into the Event
00117   // std::auto_ptr<reco::MuonCollection> pOut(new reco::MuonCollection(*allMuons));
00118   iEvent.put(pOut);
00119 }
00120 
00121 // ------------ method called once each job just before starting event loop  ------------
00122 void 
00123 MuScleFitMuonProducer::beginJob()
00124 {
00125 }
00126 
00127 // ------------ method called once each job just after ending the event loop  ------------
00128 void 
00129 MuScleFitMuonProducer::endJob()
00130 {
00131 }
00132 
00133 //define this as a plug-in
00134 DEFINE_FWK_MODULE(MuScleFitMuonProducer);