00001 #ifndef TESTCORRECTION_CC
00002 #define TESTCORRECTION_CC
00003
00004 #include "TestCorrection.h"
00005
00006 #include "TCanvas.h"
00007 #include "TLegend.h"
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 TestCorrection::TestCorrection(const edm::ParameterSet& iConfig) :
00021 MuScleFitBase( iConfig )
00022 {
00023
00024 TFile * outputFile = new TFile(theRootFileName_.c_str(), "RECREATE");
00025 theFiles_.push_back(outputFile);
00026
00027
00028 outputFile->cd();
00029 MuScleFitUtils::resfind = iConfig.getParameter<std::vector<int> >("resfind");
00030 fillHistoMap(outputFile, 0);
00031 uncorrectedPt_ = new TH1F("uncorrectedPt", "uncorrected pt", 1000, 0, 100);
00032 uncorrectedPtVsEta_ = new TProfile("uncorrectedPtVsEta", "uncorrected pt vs eta", 1000, 0, 100, -3., 3.);
00033 correctedPt_ = new TH1F("correctedPt", "corrected pt", 1000, 0, 100);
00034 correctedPtVsEta_ = new TProfile("correctedPtVsEta", "corrected pt vs eta", 1000, 0, 100, -3., 3.);
00035 eventCounter_ = 0;
00036
00037 corrector_.reset(new MomentumScaleCorrector( iConfig.getUntrackedParameter<std::string>("CorrectionsIdentifier") ) );
00038 std::cout << "corrector_ = " << &*corrector_ << std::endl;
00039 resolution_.reset(new ResolutionFunction(iConfig.getUntrackedParameter<std::string>("ResolutionsIdentifier") ) );
00040 std::cout << "resolution_ = " << &*resolution_ << std::endl;
00041 background_.reset(new BackgroundFunction(iConfig.getUntrackedParameter<std::string>("BackgroundIdentifier") ) );
00042
00043
00044
00045 MuScleFitUtils::resolutionFunction = resolution_->function(0);
00046 MuScleFitUtils::resolutionFunctionForVec = resolutionFunctionVecService( resolution_->identifiers()[0] );
00047
00048 MuScleFitUtils::parResol = resolution_->parameters();
00049 }
00050
00051 TestCorrection::~TestCorrection()
00052 {
00053 theFiles_[0]->cd();
00054 TCanvas canvas("ptComparison","pt comparison", 1000, 800);
00055 canvas.cd();
00056 uncorrectedPt_->GetXaxis()->SetTitle("Pt(GeV)");
00057 correctedPt_->SetLineColor(kRed);
00058 TLegend * legend = new TLegend(0.7,0.71,0.98,1.);
00059 legend->SetTextSize(0.02);
00060 legend->SetFillColor(0);
00061 legend->AddEntry(uncorrectedPt_, "original pt");
00062 legend->AddEntry(correctedPt_, "corrected pt");
00063 uncorrectedPt_->Draw();
00064 correctedPt_->Draw("same");
00065 legend->Draw("same");
00066
00067 canvas.Write();
00068 uncorrectedPt_->Write();
00069 uncorrectedPtVsEta_->Write();
00070 correctedPt_->Write();
00071 correctedPtVsEta_->Write();
00072
00073 writeHistoMap(0);
00074 theFiles_[0]->Close();
00075
00076 std::cout << "Total analyzed events = " << eventCounter_ << std::endl;
00077 }
00078
00079
00080
00081
00082
00083
00084 void TestCorrection::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00085 using namespace edm;
00086
00087 initialize(iSetup);
00088
00089 ++eventCounter_;
00090 if ( eventCounter_%100 == 0 ) {
00091 std::cout << "Event number " << eventCounter_ << std::endl;
00092 }
00093
00094
00095
00096
00097 std::vector<reco::LeafCandidate> muons;
00098
00099 if (theMuonType_==1) {
00100 Handle<reco::MuonCollection> glbMuons;
00101 iEvent.getByLabel (theMuonLabel_, glbMuons);
00102 muons = fillMuonCollection(*glbMuons);
00103 }
00104 else if (theMuonType_==2) {
00105 Handle<reco::TrackCollection> saMuons;
00106 iEvent.getByLabel (theMuonLabel_, saMuons);
00107 muons = fillMuonCollection(*saMuons);
00108 }
00109 else if (theMuonType_==3) {
00110 Handle<reco::TrackCollection> tracks;
00111 iEvent.getByLabel (theMuonLabel_, tracks);
00112 muons = fillMuonCollection(*tracks);
00113 }
00114
00115
00116
00117 std::pair <reco::Particle::LorentzVector, reco::Particle::LorentzVector> recMuFromBestRes =
00118 MuScleFitUtils::findBestRecoRes (muons);
00119 if (MuScleFitUtils::ResFound) {
00120 MuScleFitUtils::SavedPair.push_back( std::make_pair (recMuFromBestRes.first, recMuFromBestRes.second) );
00121 } else {
00122 MuScleFitUtils::SavedPair.push_back( std::make_pair (lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.)) );
00123 }
00124
00125
00126
00127 if (MuScleFitUtils::ResFound) {
00128
00129
00130
00131
00132
00133
00134
00135 lorentzVector recMu1 = correctMuon(recMu1);
00136 lorentzVector recMu2 = correctMuon(recMu2);
00137
00138 reco::Particle::LorentzVector bestRecRes (recMu1+recMu2);
00139
00140
00141
00142 mapHisto_["hRecBestMu"]->Fill(recMu1);
00143 if ((std::abs(recMu1.eta())<2.5) && (recMu1.pt()>2.5)) {
00144 mapHisto_["hRecBestMu_Acc"]->Fill(recMu1);
00145 }
00146 mapHisto_["hRecBestMu"]->Fill(recMu2);
00147 if ((std::abs(recMu2.eta())<2.5) && (recMu2.pt()>2.5)) {
00148 mapHisto_["hRecBestMu_Acc"]->Fill(recMu2);
00149 }
00150 mapHisto_["hDeltaRecBestMu"]->Fill(recMu1, recMu2);
00151
00152 mapHisto_["hRecBestRes"]->Fill(bestRecRes);
00153 if ((std::abs(recMu1.eta())<2.5) && (recMu1.pt()>2.5) && (std::abs(recMu2.eta())<2.5) && (recMu2.pt()>2.5)){
00154 mapHisto_["hRecBestRes_Acc"]->Fill(bestRecRes);
00155
00156 mapHisto_["hRecBestResVSMu"]->Fill (recMu1, bestRecRes, -1);
00157 mapHisto_["hRecBestResVSMu"]->Fill (recMu2, bestRecRes, +1);
00158 }
00159 }
00160
00161
00162 std::vector<reco::LeafCandidate>::const_iterator recMuon = muons.begin();
00163 int muonCount = 0;
00164 for ( ; recMuon!=muons.end(); ++recMuon, ++muonCount ) {
00165
00166
00167 uncorrectedPt_->Fill(recMuon->pt());
00168 uncorrectedPtVsEta_->Fill(recMuon->pt(), recMuon->eta());
00169
00170
00171 std::cout << "correcting muon["<<muonCount<<"] with pt = " << recMuon->pt() << std::endl;
00172 double corrPt = (*corrector_)(*recMuon);
00173 std::cout << "to pt = " << corrPt << std::endl;
00174 correctedPt_->Fill(corrPt);
00175 correctedPtVsEta_->Fill(corrPt, recMuon->eta());
00176
00177 }
00178 }
00179
00180 lorentzVector TestCorrection::correctMuon( const lorentzVector & muon ) {
00181 double corrPt = corrector_->correct(muon);
00182 double ptEtaPhiE[4] = {corrPt, muon.Eta(), muon.Phi(), muon.E()};
00183 return MuScleFitUtils::fromPtEtaPhiToPxPyPz(ptEtaPhiE);
00184 }
00185
00186
00187 void TestCorrection::initialize(const edm::EventSetup&)
00188 {
00189
00190
00191 readProbabilityDistributionsFromFile();
00192 }
00193
00194 #endif // TESTCORRECTION_CC