CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

DistortedMuonProducerFromDB Class Reference

Inheritance diagram for DistortedMuonProducerFromDB:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 DistortedMuonProducerFromDB (const edm::ParameterSet &)
 ~DistortedMuonProducerFromDB ()

Private Member Functions

virtual void beginRun (edm::Run &, const edm::EventSetup &)
virtual void endJob ()
virtual void produce (edm::Event &, const edm::EventSetup &)

Private Attributes

std::string dbDataResolutionLabel_
std::string dbMCResolutionLabel_
std::string dbScaleLabel_
edm::InputTag genMatchMapTag_
std::auto_ptr
< MomentumScaleCorrector
momCorrector_
std::auto_ptr< ResolutionFunctionmomResolutionData_
std::auto_ptr< ResolutionFunctionmomResolutionMC_
edm::InputTag muonTag_

Detailed Description

Definition at line 13 of file DistortedMuonProducerFromDB.cc.


Constructor & Destructor Documentation

DistortedMuonProducerFromDB::DistortedMuonProducerFromDB ( const edm::ParameterSet pset) [explicit]

Definition at line 51 of file DistortedMuonProducerFromDB.cc.

References dbDataResolutionLabel_, dbMCResolutionLabel_, dbScaleLabel_, edm::ParameterSet::getUntrackedParameter(), and muonTag_.

                                                                                    {

  // What is being produced
      produces<std::vector<reco::Muon> >();

  // Input products
      muonTag_ = pset.getUntrackedParameter<edm::InputTag> ("MuonTag", edm::InputTag("muons"));
      dbScaleLabel_ = pset.getUntrackedParameter<std::string> ("DBScaleLabel", "scale");
      dbDataResolutionLabel_ = pset.getUntrackedParameter<std::string> ("DBDataResolutionLabel", "datareso");
      dbMCResolutionLabel_ = pset.getUntrackedParameter<std::string> ("DBMCResolutionLabel", "mcreso");

} 
DistortedMuonProducerFromDB::~DistortedMuonProducerFromDB ( )

Definition at line 65 of file DistortedMuonProducerFromDB.cc.

                                                         {
}

Member Function Documentation

void DistortedMuonProducerFromDB::beginRun ( edm::Run ,
const edm::EventSetup iSetup 
) [private, virtual]

Reimplemented from edm::EDProducer.

Definition at line 69 of file DistortedMuonProducerFromDB.cc.

References dbDataResolutionLabel_, dbMCResolutionLabel_, dbScaleLabel_, edm::EventSetup::get(), LogTrace, momCorrector_, momResolutionData_, momResolutionMC_, and edm::ESHandle< T >::product().

                                                                               {
      edm::ESHandle<MuScleFitDBobject> dbObject1;
      iSetup.get<MuScleFitDBobjectRcd>().get(dbScaleLabel_,dbObject1);
      momCorrector_.reset(new MomentumScaleCorrector(dbObject1.product()));

      LogTrace("") << ">>> Using database for momentum scale corrections !!";

      edm::ESHandle<MuScleFitDBobject> dbObject2;
      iSetup.get<MuScleFitDBobjectRcd>().get(dbDataResolutionLabel_, dbObject2);
      momResolutionData_.reset(new ResolutionFunction(dbObject2.product()));

      edm::ESHandle<MuScleFitDBobject> dbObject3;
      iSetup.get<MuScleFitDBobjectRcd>().get(dbMCResolutionLabel_, dbObject3);
      momResolutionMC_.reset(new ResolutionFunction(dbObject3.product()));

      LogTrace("") << ">>> Using database for momentum resolution corrections !!";
}
void DistortedMuonProducerFromDB::endJob ( void  ) [private, virtual]

Reimplemented from edm::EDProducer.

Definition at line 88 of file DistortedMuonProducerFromDB.cc.

                                        {
}
void DistortedMuonProducerFromDB::produce ( edm::Event ev,
const edm::EventSetup iSetup 
) [private, virtual]

Implements edm::EDProducer.

Definition at line 92 of file DistortedMuonProducerFromDB.cc.

References edm::Event::getByLabel(), i, edm::EventBase::isRealData(), LogTrace, momResolutionData_, momResolutionMC_, RPCpg::mu, muonTag_, MuonAlignmentFromReference_cff::newmuons, funct::pow(), edm::Event::put(), reco::LeafCandidate::setP4(), edm::shift, and mathSSE::sqrt().

                                                                                   {

      if (ev.isRealData()) return;

      // Muon collection
      edm::Handle<edm::View<reco::Muon> > muonCollection;
      if (!ev.getByLabel(muonTag_, muonCollection)) {
            edm::LogError("") << ">>> Muon collection does not exist !!!";
            return;
      }
      unsigned int muonCollectionSize = muonCollection->size();

      std::auto_ptr<reco::MuonCollection> newmuons (new reco::MuonCollection);

      for (unsigned int i=0; i<muonCollectionSize; i++) {
            edm::RefToBase<reco::Muon> mu = muonCollection->refAt(i);

            // Set shift
            double shift = (*momCorrector_)(*mu) - mu->pt();
            LogTrace("") << "\tmomentumScaleShift= " << shift << " [GeV]"; 

            // Set resolutions
            double sigma = pow(momResolutionData_->sigmaPt(*mu),2) -
                              pow(momResolutionMC_->sigmaPt(*mu),2);
            if (sigma>0.) sigma = sqrt(sigma); else sigma = 0.;
            LogTrace("") << "\tPt additional smearing= " << sigma << " [GeV]"; 

            // Gaussian Random number for smearing
            double rndg = CLHEP::RandGauss::shoot();
            
            // New muon
            double ptmu = mu->pt();
            ptmu += shift + sigma*rndg;
            reco::Muon* newmu = mu->clone();
            newmu->setP4 (
                  reco::Particle::PolarLorentzVector (
                        ptmu, mu->eta(), mu->phi(), mu->mass()
                  )
            );
            newmuons->push_back(*newmu);

      }

      ev.put(newmuons);
}

Member Data Documentation

Definition at line 27 of file DistortedMuonProducerFromDB.cc.

Referenced by beginRun(), and DistortedMuonProducerFromDB().

Definition at line 28 of file DistortedMuonProducerFromDB.cc.

Referenced by beginRun(), and DistortedMuonProducerFromDB().

Definition at line 26 of file DistortedMuonProducerFromDB.cc.

Referenced by beginRun(), and DistortedMuonProducerFromDB().

Definition at line 24 of file DistortedMuonProducerFromDB.cc.

Definition at line 30 of file DistortedMuonProducerFromDB.cc.

Referenced by beginRun().

Definition at line 31 of file DistortedMuonProducerFromDB.cc.

Referenced by beginRun(), and produce().

Definition at line 32 of file DistortedMuonProducerFromDB.cc.

Referenced by beginRun(), and produce().

Definition at line 23 of file DistortedMuonProducerFromDB.cc.

Referenced by DistortedMuonProducerFromDB(), and produce().