#include <MuonAnalysis/MomentumScaleCalibration/plugins/TestCorrection.cc>
Description: <one line="" class="" summary>="">
Implementation: <Notes on="" implementation>="">
Definition at line 62 of file TestCorrection.cc.
TestCorrection::TestCorrection | ( | const edm::ParameterSet & | iConfig | ) | [explicit] |
Definition at line 116 of file TestCorrection.cc.
References background_, correctedPt_, correctedPtVsEta_, corrector_, gather_cfg::cout, eventCounter_, MuScleFitBase::fillHistoMap(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), download_sqlite_cfg::outputFile, MuScleFitUtils::parResol, MuScleFitUtils::resfind, resolution_, MuScleFitUtils::resolutionFunction, MuScleFitUtils::resolutionFunctionForVec, resolutionFunctionVecService(), AlCaHLTBitMon_QueryRunRegistry::string, MuScleFitBase::theFiles_, MuScleFitBase::theRootFileName_, uncorrectedPt_, and uncorrectedPtVsEta_.
: MuScleFitBase( iConfig ) { //now do what ever initialization is needed TFile * outputFile = new TFile(theRootFileName_.c_str(), "RECREATE"); theFiles_.push_back(outputFile); // outputFile_ = new TFile(theRootFileName_.c_str(), "RECREATE"); // outputFile_->cd(); outputFile->cd(); MuScleFitUtils::resfind = iConfig.getParameter<std::vector<int> >("resfind"); fillHistoMap(outputFile, 0); uncorrectedPt_ = new TH1F("uncorrectedPt", "uncorrected pt", 1000, 0, 100); uncorrectedPtVsEta_ = new TProfile("uncorrectedPtVsEta", "uncorrected pt vs eta", 1000, 0, 100, -3., 3.); correctedPt_ = new TH1F("correctedPt", "corrected pt", 1000, 0, 100); correctedPtVsEta_ = new TProfile("correctedPtVsEta", "corrected pt vs eta", 1000, 0, 100, -3., 3.); eventCounter_ = 0; // Create the corrector and set the parameters corrector_.reset(new MomentumScaleCorrector( iConfig.getUntrackedParameter<std::string>("CorrectionsIdentifier") ) ); std::cout << "corrector_ = " << &*corrector_ << std::endl; resolution_.reset(new ResolutionFunction(iConfig.getUntrackedParameter<std::string>("ResolutionsIdentifier") ) ); std::cout << "resolution_ = " << &*resolution_ << std::endl; background_.reset(new BackgroundFunction(iConfig.getUntrackedParameter<std::string>("BackgroundIdentifier") ) ); // Initialize the parameters of MuScleFitUtils from those saved in the functions. // MuScleFitUtils::parScale = corrector_.getFunction(0)->parameters(); MuScleFitUtils::resolutionFunction = resolution_->function(0); MuScleFitUtils::resolutionFunctionForVec = resolutionFunctionVecService( resolution_->identifiers()[0] ); MuScleFitUtils::parResol = resolution_->parameters(); }
TestCorrection::~TestCorrection | ( | ) |
Definition at line 147 of file TestCorrection.cc.
References svgfig::canvas(), correctedPt_, correctedPtVsEta_, gather_cfg::cout, eventCounter_, MuScleFitBase::theFiles_, uncorrectedPt_, uncorrectedPtVsEta_, and MuScleFitBase::writeHistoMap().
{ theFiles_[0]->cd(); TCanvas canvas("ptComparison","pt comparison", 1000, 800); canvas.cd(); uncorrectedPt_->GetXaxis()->SetTitle("Pt(GeV)"); correctedPt_->SetLineColor(kRed); TLegend * legend = new TLegend(0.7,0.71,0.98,1.); legend->SetTextSize(0.02); legend->SetFillColor(0); // Have a white background legend->AddEntry(uncorrectedPt_, "original pt"); legend->AddEntry(correctedPt_, "corrected pt"); uncorrectedPt_->Draw(); correctedPt_->Draw("same"); legend->Draw("same"); canvas.Write(); uncorrectedPt_->Write(); uncorrectedPtVsEta_->Write(); correctedPt_->Write(); correctedPtVsEta_->Write(); writeHistoMap(0); theFiles_[0]->Close(); std::cout << "Total analyzed events = " << eventCounter_ << std::endl; }
TestCorrection::TestCorrection | ( | const edm::ParameterSet & | ) | [explicit] |
TestCorrection::~TestCorrection | ( | ) |
void TestCorrection::analyze | ( | const edm::Event & | iEvent, |
const edm::EventSetup & | iSetup | ||
) | [private, virtual] |
Implements edm::EDAnalyzer.
Definition at line 180 of file TestCorrection.cc.
References abs, correctedPt_, correctedPtVsEta_, correctMuon(), gather_cfg::cout, eventCounter_, fillMuonCollection(), MuScleFitUtils::findBestRecoRes(), edm::Event::getByLabel(), initialize(), MuScleFitBase::mapHisto_, patZpeak::muons, MuScleFitUtils::ResFound, MuScleFitUtils::SavedPair, MuScleFitBase::theMuonLabel_, MuScleFitBase::theMuonType_, testEve_cfg::tracks, uncorrectedPt_, and uncorrectedPtVsEta_.
{ using namespace edm; initialize(iSetup); ++eventCounter_; if ( eventCounter_%100 == 0 ) { std::cout << "Event number " << eventCounter_ << std::endl; } // Take the reco-muons, depending on the type selected in the cfg // -------------------------------------------------------------- std::vector<reco::LeafCandidate> muons; if (theMuonType_==1) { // GlobalMuons Handle<reco::MuonCollection> glbMuons; iEvent.getByLabel (theMuonLabel_, glbMuons); muons = fillMuonCollection(*glbMuons); } else if (theMuonType_==2) { // StandaloneMuons Handle<reco::TrackCollection> saMuons; iEvent.getByLabel (theMuonLabel_, saMuons); muons = fillMuonCollection(*saMuons); } else if (theMuonType_==3) { // Tracker tracks Handle<reco::TrackCollection> tracks; iEvent.getByLabel (theMuonLabel_, tracks); muons = fillMuonCollection(*tracks); } // Find the two muons from the resonance, and set ResFound bool // ------------------------------------------------------------ std::pair <reco::Particle::LorentzVector, reco::Particle::LorentzVector> recMuFromBestRes = MuScleFitUtils::findBestRecoRes (muons); if (MuScleFitUtils::ResFound) { MuScleFitUtils::SavedPair.push_back( std::make_pair (recMuFromBestRes.first, recMuFromBestRes.second) ); } else { MuScleFitUtils::SavedPair.push_back( std::make_pair (lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.)) ); } // If resonance found, do the hard work // ------------------------------------ if (MuScleFitUtils::ResFound) { // Find weight and reference mass for this muon pair // ------------------------------------------------- // double weight = MuScleFitUtils::computeWeight ((recMu1+recMu2).mass()); // Use the correction function to correct the pt scale of the muons. Note that this takes into // account the corrections from all iterations. lorentzVector recMu1 = correctMuon(recMu1); lorentzVector recMu2 = correctMuon(recMu2); reco::Particle::LorentzVector bestRecRes (recMu1+recMu2); //Fill histograms //------------------ mapHisto_["hRecBestMu"]->Fill(recMu1); if ((std::abs(recMu1.eta())<2.5) && (recMu1.pt()>2.5)) { mapHisto_["hRecBestMu_Acc"]->Fill(recMu1); } mapHisto_["hRecBestMu"]->Fill(recMu2); if ((std::abs(recMu2.eta())<2.5) && (recMu2.pt()>2.5)) { mapHisto_["hRecBestMu_Acc"]->Fill(recMu2); } mapHisto_["hDeltaRecBestMu"]->Fill(recMu1, recMu2); mapHisto_["hRecBestRes"]->Fill(bestRecRes); if ((std::abs(recMu1.eta())<2.5) && (recMu1.pt()>2.5) && (std::abs(recMu2.eta())<2.5) && (recMu2.pt()>2.5)){ mapHisto_["hRecBestRes_Acc"]->Fill(bestRecRes); // Fill histogram of Res mass vs muon variable mapHisto_["hRecBestResVSMu"]->Fill (recMu1, bestRecRes, -1); mapHisto_["hRecBestResVSMu"]->Fill (recMu2, bestRecRes, +1); } } // Loop on the recMuons std::vector<reco::LeafCandidate>::const_iterator recMuon = muons.begin(); int muonCount = 0; for ( ; recMuon!=muons.end(); ++recMuon, ++muonCount ) { // Fill the histogram with uncorrected pt values uncorrectedPt_->Fill(recMuon->pt()); uncorrectedPtVsEta_->Fill(recMuon->pt(), recMuon->eta()); // Fill the histogram with corrected pt values std::cout << "correcting muon["<<muonCount<<"] with pt = " << recMuon->pt() << std::endl; double corrPt = (*corrector_)(*recMuon); std::cout << "to pt = " << corrPt << std::endl; correctedPt_->Fill(corrPt); correctedPtVsEta_->Fill(corrPt, recMuon->eta()); // correctedPt_->Fill(recMuon->pt()); } }
virtual void TestCorrection::analyze | ( | const edm::Event & | , |
const edm::EventSetup & | |||
) | [private, virtual] |
Implements edm::EDAnalyzer.
lorentzVector TestCorrection::correctMuon | ( | const lorentzVector & | muon | ) | [private] |
Definition at line 276 of file TestCorrection.cc.
References corrector_, and fromPtEtaPhiToPxPyPz().
Referenced by analyze().
{ double corrPt = corrector_->correct(muon); double ptEtaPhiE[4] = {corrPt, muon.Eta(), muon.Phi(), muon.E()}; return MuScleFitUtils::fromPtEtaPhiToPxPyPz(ptEtaPhiE); }
lorentzVector TestCorrection::correctMuon | ( | const lorentzVector & | muon | ) | [private] |
virtual void TestCorrection::endJob | ( | void | ) | [inline, private, virtual] |
virtual void TestCorrection::endJob | ( | void | ) | [inline, private, virtual] |
std::vector<reco::LeafCandidate> TestCorrection::fillMuonCollection | ( | const std::vector< T > & | tracks | ) | [inline, private] |
Definition at line 69 of file TestCorrection.h.
References RPCpg::mu, metsig::muon, patZpeak::muons, and mathSSE::sqrt().
{ std::vector<reco::LeafCandidate> muons; typename std::vector<T>::const_iterator track; for (track = tracks.begin(); track != tracks.end(); ++track){ // Where 0.011163612 is the squared muon mass. reco::Particle::LorentzVector mu(track->px(),track->py(),track->pz(), sqrt(track->p()*track->p() + 0.011163612)); reco::LeafCandidate muon(track->charge(),mu); // Store muon // ---------- muons.push_back (muon); } return muons; }
std::vector<reco::LeafCandidate> TestCorrection::fillMuonCollection | ( | const std::vector< T > & | tracks | ) | [inline, private] |
Definition at line 72 of file TestCorrection.cc.
References RPCpg::mu, metsig::muon, patZpeak::muons, and mathSSE::sqrt().
Referenced by analyze().
{ std::vector<reco::LeafCandidate> muons; typename std::vector<T>::const_iterator track; for (track = tracks.begin(); track != tracks.end(); ++track){ // Where 0.011163612 is the squared muon mass. reco::Particle::LorentzVector mu(track->px(),track->py(),track->pz(), sqrt(track->p()*track->p() + 0.011163612)); reco::LeafCandidate muon(track->charge(),mu); // Store muon // ---------- muons.push_back (muon); } return muons; }
virtual void TestCorrection::initialize | ( | const edm::EventSetup & | ) | [private, virtual] |
void TestCorrection::initialize | ( | const edm::EventSetup & | ) | [private, virtual] |
Definition at line 283 of file TestCorrection.cc.
References MuScleFitBase::readProbabilityDistributionsFromFile().
Referenced by analyze().
{ // Read the pdf from root file. They are used by massProb when finding the muon pair, needed // for the mass histograms. readProbabilityDistributionsFromFile(); }
std::auto_ptr< BackgroundFunction > TestCorrection::background_ [private] |
Definition at line 101 of file TestCorrection.cc.
Referenced by TestCorrection().
TH1F * TestCorrection::correctedPt_ [private] |
Definition at line 94 of file TestCorrection.cc.
Referenced by analyze(), TestCorrection(), and ~TestCorrection().
TProfile * TestCorrection::correctedPtVsEta_ [private] |
Definition at line 95 of file TestCorrection.cc.
Referenced by analyze(), TestCorrection(), and ~TestCorrection().
std::auto_ptr< MomentumScaleCorrector > TestCorrection::corrector_ [private] |
Definition at line 99 of file TestCorrection.cc.
Referenced by correctMuon(), and TestCorrection().
int TestCorrection::eventCounter_ [private] |
Definition at line 97 of file TestCorrection.cc.
Referenced by analyze(), TestCorrection(), and ~TestCorrection().
std::auto_ptr< ResolutionFunction > TestCorrection::resolution_ [private] |
Definition at line 100 of file TestCorrection.cc.
Referenced by TestCorrection().
TH1F * TestCorrection::uncorrectedPt_ [private] |
Definition at line 92 of file TestCorrection.cc.
Referenced by analyze(), TestCorrection(), and ~TestCorrection().
TProfile * TestCorrection::uncorrectedPtVsEta_ [private] |
Definition at line 93 of file TestCorrection.cc.
Referenced by analyze(), TestCorrection(), and ~TestCorrection().