void testRoot() { //Fill a 1-D histogram from a parametric function // To see the output of this macro, click begin_html <a href="gif/fillrandom.gif">here</a>. end_html //Author: Rene Brun TCanvas *c1 = new TCanvas("c1","The FillRandom example",200,10,700,900); c1->SetFillColor(18); TPad* pad1 = new TPad("pad1","The pad with the function",0.05,0.50,0.95,0.95,21); TPad* pad2 = new TPad("pad2","The pad with the histogram",0.05,0.05,0.95,0.45,21); pad1->Draw(); pad2->Draw(); pad1->cd(); gBenchmark->Start("fillrandom"); // // A function (any dimension) or a formula may reference // an already defined formula // TFormula* form1 = new TFormula("form1","abs(sin(x)/x)"); TF1* sqroot = new TF1("sqroot","x*gaus(0) + [3]*form1",0,10); sqroot->SetParameters(10,4,1,20); pad1->SetGridx(); pad1->SetGridy(); pad1->GetFrame()->SetFillColor(42); pad1->GetFrame()->SetBorderMode(-1); pad1->GetFrame()->SetBorderSize(5); sqroot->SetLineColor(4); sqroot->SetLineWidth(6); sqroot->Draw(); TPaveLabel* lfunction = new TPaveLabel(5,39,9.8,46,"The sqroot function"); lfunction->SetFillColor(41); lfunction->Draw(); c1->Update(); // // Create a one dimensional histogram (one float per bin) // and fill it following the distribution in function sqroot. // pad2->cd(); pad2->GetFrame()->SetFillColor(42); pad2->GetFrame()->SetBorderMode(-1); pad2->GetFrame()->SetBorderSize(5); TH1F* h1f = new TH1F("h1f","Test random numbers",200,0,10); h1f->SetFillColor(45); h1f->FillRandom("sqroot",10000); h1f->Draw(); c1->Update(); // // Open a ROOT file and save the formula, function and histogram // TFile myfile("fillrandom.root","RECREATE"); form1->Write(); sqroot->Write(); h1f->Write(); gBenchmark->Show("fillrandom"); }
void TestWrite(const char *fname) { TFile fr(fname,"new"); TF1 *f = 0; f = new TF1("f1","sin(x)"); f->Write();delete f; f = new TF1("f2","sin(x)*x"); f->Write();delete f; f = new TF1("f3","sin(x)+x"); f->Write();delete f; f = new TF1("f4","tan(x)/x"); f->Write();delete f; f = new TF1("f5","x*x*x"); f->Write();delete f; f = new TF1("f6","xpol1"); f->SetParameters(1,2,3,4,5); f->Write();delete f; f = new TF1("f7","xpol2"); f->SetParameters(1,2,3,4,5); f->Write();delete f; f = new TF1("f8","xpol3"); f->SetParameters(1,2,3,4,5); f->Write();delete f; fr.Close(); }
void EfficiencyFit(TString inputdata="ROOTfiles/MCstudiesPP_Fine.root", TString label="PP_Fine"){ gStyle->SetTextSize(0.05); gStyle->SetTextFont(42); gStyle->SetPadRightMargin(0.043); gStyle->SetPadLeftMargin(0.18); gStyle->SetPadTopMargin(0.1); gStyle->SetPadBottomMargin(0.145); gStyle->SetTitleX(.0f); TFile* inf = new TFile(inputdata.Data()); TH1D* hEff = (TH1D*)inf->Get("hEff"); TCanvas* c= new TCanvas(Form("c"),"",600,600); hEff->Draw(); TF1 *myfit = new TF1("myfit","[0]+[1]*x+x*x*[2]+x*x*x*[3]+x*x*x*x*[4]", 7, 50); //TF1 *myfit = new TF1("myfit","[0]+[1]*x+x*x*[2]+x*x*x*[3]", 7, 50); //TF1 *myfit = new TF1("myfit","[0]+[1]*x+x*x*[2]", 7, 50); hEff->Fit("myfit","L q","",7,50); hEff->Fit("myfit","L q","",7,50); hEff->Fit("myfit","L q","",7,50); hEff->Fit("myfit","L m","",7,50); double par0=myfit->GetParameter(0); double par1=myfit->GetParameter(1); double par2=myfit->GetParameter(2); double par3=myfit->GetParameter(3); double par4=myfit->GetParameter(4); TString myEffWeight=Form("(%e+%e*Bpt+Bpt*Bpt*%e+Bpt*Bpt*Bpt*%e+Bpt*Bpt*Bpt*Bpt*%e)",par0,par1,par2,par3,par4); std::cout<<myEffWeight<<std::endl; c->SaveAs(Form("plotEffFit/%s.png", label.Data())); TFile *fout=new TFile(Form("plotEffFit/%s.root", label.Data()),"recreate"); fout->cd(); hEff->Write(); myfit->Write(); fout->Close(); }
void FitWithConstant(TH1D* h1, TFile *out) { Double_t fitRangeLow = 0.; Double_t fitRangeHigh = .4; TF1 *f = new TF1("f","[0]", fitRangeLow, fitRangeHigh); Int_t binLow = h1->FindBin(fitRangeLow); Int_t binHigh = h1->FindBin(fitRangeHigh); cout<<"\t\t********************Fitting with a constant value********************"<<endl<<endl;; h1->Fit(f, "R0"); TString fitName = h1->GetName(); fitName += "Fit"; f->SetName(fitName); f->SetTitle(fitName); // TFile out("Compare.root","update"); TDirectory *dir = out->GetDirectory("Fit"); if(!dir) dir = out->mkdir("Fit"); dir->cd(); // f->SetDirectory(0); f->Write(f->GetName(), TObject::kOverwrite); // out->Close(); }
void fitBjetJES(int ppPbPb=1, int cbinlo=12, int cbinhi=40){ if(!ppPbPb){ cbinlo=0; cbinhi=40; } gStyle->SetOptTitle(0); gStyle->SetOptStat(0); TFile *fL; if(!ppPbPb)fL=new TFile("histos/ppMC_hiReco_jetTrig_highPurity_JEC.root"); else fL=new TFile("histos/PbPbQCDMC_pt30by3_ipHICalibCentWeight.root"); // these are dummy files for pp TFile *fB=new TFile("histos/PbPbBMC_pt30by3_ipHICalibCentWeight.root"); TFile *fC=new TFile("histos/PbPbCMC_pt30by3_ipHICalibCentWeight.root"); TNtuple *tL = (TNtuple*) fL->Get("nt"); TNtuple *tB = (TNtuple*) fB->Get("nt"); TNtuple *tC = (TNtuple*) fC->Get("nt"); float jtptL, refptL, jtetaL, weightL, refparton_flavorForBL, binL; tL->SetBranchAddress("jtpt",&jtptL); tL->SetBranchAddress("jteta",&jtetaL); tL->SetBranchAddress("refpt",&refptL); tL->SetBranchAddress("weight",&weightL); if(ppPbPb)tL->SetBranchAddress("bin",&binL); tL->SetBranchAddress("refparton_flavorForB",&refparton_flavorForBL); float jtptB, refptB, jtetaB, weightB, refparton_flavorForBB, binB; tB->SetBranchAddress("jtpt",&jtptB); tB->SetBranchAddress("jteta",&jtetaB); tB->SetBranchAddress("refpt",&refptB); tB->SetBranchAddress("weight",&weightB); if(ppPbPb)tB->SetBranchAddress("bin",&binB); tB->SetBranchAddress("refparton_flavorForB",&refparton_flavorForBB); float jtptC, refptC, jtetaC, weightC, refparton_flavorForBC, binC; tC->SetBranchAddress("jtpt",&jtptC); tC->SetBranchAddress("jteta",&jtetaC); tC->SetBranchAddress("refpt",&refptC); tC->SetBranchAddress("weight",&weightC); if(ppPbPb)tC->SetBranchAddress("bin",&binC); tC->SetBranchAddress("refparton_flavorForB",&refparton_flavorForBC); TProfile *hL = new TProfile("hL","hL",250,50,300,0,10); TProfile *hB = new TProfile("hB","hB",250,50,300,0,10); TProfile *hC = new TProfile("hC","hC",250,50,300,0,10); hL->Sumw2(),hB->Sumw2(),hC->Sumw2(); for(int i=0;i<tL->GetEntries();i++){ tL->GetEntry(i); if(!ppPbPb) binL=39; if(fabs(jtetaL)<2 && binL>=cbinlo && binL<cbinhi) hL->Fill(refptL,jtptL/refptL,weightL); if(!ppPbPb){ if(fabs(jtetaL)<2 && binL>=cbinlo && binL<cbinhi && abs(refparton_flavorForBL)==5) hB->Fill(refptL,jtptL/refptL,weightL); if(fabs(jtetaL)<2 && binL>=cbinlo && binL<cbinhi && abs(refparton_flavorForBL)==4) hC->Fill(refptL,jtptL/refptL,weightL); } } if(ppPbPb){ for(int i=0;i<tB->GetEntries();i++){ tB->GetEntry(i); if(fabs(jtetaB)<2 && binB>=cbinlo && binB<cbinhi && abs(refparton_flavorForBB)==5) hB->Fill(refptB,jtptB/refptB,weightB); } for(int i=0;i<tC->GetEntries();i++){ tC->GetEntry(i); if(fabs(jtetaC)<2 && binC>=cbinlo && binC<cbinhi && abs(refparton_flavorForBC)==4) hC->Fill(refptC,jtptC/refptC,weightC); } } hL->SetMinimum(0.); hL->SetLineColor(kBlue); hB->SetLineColor(kRed); hC->SetLineColor(kGreen); hL->SetMarkerColor(kBlue); hB->SetMarkerColor(kRed); hC->SetMarkerColor(kGreen); //hL->SetMarkerStyle(4); //hB->SetMarkerStyle(4); //hC->SetMarkerStyle(4); hL->SetXTitle("genJet p_{T} (GeV/c)"); hL->SetYTitle("<reco p_{T} / gen p_{T} >"); hL->GetXaxis()->SetRangeUser(50.,199.999); hL->GetYaxis()->SetRangeUser(0.5,1.05); TCanvas *c1=new TCanvas("c1","c1",800,600); c1->SetGridx(1); c1->SetGridy(1); hL->Draw("e1"); hB->Draw("e1,same"); hC->Draw("e1,same"); TLegend *leg=new TLegend(0.4,0.15,0.9,0.45); leg->SetBorderSize(0); leg->SetFillStyle(0); if(ppPbPb&&cbinlo==0&&cbinhi==40)leg->SetHeader("Pythia+Hydjet, 0-100%"); leg->AddEntry(hL,"Inclusive jets","pl"); leg->AddEntry(hC,"c-jets","pl"); leg->AddEntry(hB,"b-jets","pl"); leg->Draw(); TCanvas *c2=new TCanvas("c2","c2",1); /* TH1F *hL2 = (TH1F*)hL->Clone("hL2"); TH1F *hB2 = (TH1F*)hB->Clone("hB2"); hL2->Add(hB2,-1); hL2->Draw(); */ TH1F *hcorr = new TH1F("hcorr","hcorr",250,50,300); hcorr->Sumw2(); for(int i=0;i<hL->GetNbinsX();i++){ cout<<" b resp "<<hB->GetBinContent(i+1)<<endl; cout<<" l resp "<<hL->GetBinContent(i+1)<<endl; cout<<" l offset "<<1.-hL->GetBinContent(i+1)<<endl; cout<<" corrected b resp "<<hB->GetBinContent(i+1)+1.-hL->GetBinContent(i+1)<<endl; float jesOffset = 1.-hL->GetBinContent(i+1); hcorr->SetBinContent(i+1,hB->GetBinContent(i+1)+jesOffset); hcorr->SetBinError(i+1,sqrt(hB->GetBinError(i+1)*hB->GetBinError(i+1)+hL->GetBinError(i+1)*hL->GetBinError(i+1))); } hcorr->SetMinimum(0.5); hcorr->SetMaximum(1.1); hcorr->SetLineColor(kRed); hcorr->SetMarkerColor(kRed); hcorr->SetMarkerStyle(4); hcorr->Draw(); TF1 *fCorr = new TF1("fCorr","[0]+[1]*log(x)+[2]*log(x)*log(x)",50,300); fCorr->SetLineWidth(1); fCorr->SetLineColor(kBlue); hcorr->Fit(fCorr); TFile *fout; if(ppPbPb) fout =new TFile(Form("bJEShistos/bJetScale_PbPb_Cent_fineBin_%d_%d.root",cbinlo,cbinhi),"recreate"); else fout =new TFile("bJEShistos/bJetScale_PP_fineBin.root","recreate"); hcorr->Write(); fCorr->Write(); fout->Close(); }
void histoLoader_new(char* arg){ //Take the arguments and save them into respective strings std::string infileName, outfileName; std::string inF, outF; std::string inPrefix, outPrefix; std::string layers; std::istringstream stm(arg); inPrefix = "/home/p180f/Do_Jo_Ol_Ma/Analysis/MainProcedure/testMain/analysisRoot/"; outPrefix = "/home/p180f/Do_Jo_Ol_Ma/Analysis/MainProcedure/testMain/moliRoot/"; outF = "moli_all.root"; outfileName = outPrefix + outF; Double_t p0 = 248.5; Double_t p1 = 222; Double_t p2 = 275; int i = 0; Double_t thetaRMS[4]; while(true){ if( std::getline(stm, layers, ' ') ){ inF = "errorAnalysis_" + layers + "layers.root"; infileName = inPrefix + inF; TFile *inFile = new TFile(infileName.c_str()); TF1 *func = (TF1*)inFile->Get("gausFuncCuts"); Double_t RMS1; Double_t RMS2; RMS1 = TMath::Abs(func->GetParameter("Sigma1")); RMS2 = TMath::Abs(func->GetParameter("Sigma2")); std::cout << "RMS1_" << i << " = " << RMS1 << std::endl; std::cout << "RMS2_" << i << " = " << RMS2 << std::endl; if( RMS1 > RMS2 ){ thetaRMS[i] = RMS2; } else thetaRMS[i] = RMS1; inFile->Close(); } else break; i++; } TFile *outFile = new TFile(outfileName.c_str(), "RECREATE"); Double_t x_data[4] = {2.54 / 4, 2.54 / 2, 2.54*3/4, 2.54}; Double_t xerr[4] = {0.005, 0.005, 0.005, 0.005}; Double_t yerr[4] = {0.197, 0.272, 0.351, 0.136}; Double_t x0[20] = {0}; Double_t y0[20] = {0}; Double_t x1[20] = {0}; Double_t y1[20] = {0}; Double_t x2[20] = {0}; Double_t y2[20] = {0}; int j=1; for (Double_t h=0.15; j<20; j++) { x0[j] = h; y0[j] = moliFunc(x0[j], p0); h+=0.15; std::cout << "x0[" << j << "] = " << x0[j] << std::endl; std::cout << "y0[" << j << "] = " << y0[j] << std::endl; } int k=1; for (Double_t h=0.15; k<20; k++) { x1[k] = h; y1[k] = moliFunc(x1[k], p1); h+=0.15; std::cout << "x1[" << k << "] = " << x1[k] << std::endl; std::cout << "y1[" << k << "] = " << y1[k] << std::endl; } int l=1; for (Double_t h=0.15; l<20; l++) { x2[l] = h; y2[l] = moliFunc(x2[l], p2); h+=0.15; std::cout << "x2[" << l << "] = " << x2[l] << std::endl; std::cout << "y2[" << l << "] = " << y2[l] << std::endl; } TGraph *moliGraph0 = new TGraph(20, x0, y0); TGraph *moliGraph1 = new TGraph(20, x1, y1); TGraph *moliGraph2 = new TGraph(20, x2, y2); TGraphErrors *dataGraph = new TGraphErrors(4, x_data, thetaRMS, xerr, yerr); TF1 *moliFit = new TF1("moliFit", moliFunc_Fit, 0, 10, 1); moliFit->SetLineColor(6); moliFit->SetLineWidth(2); moliFit->SetParameters(0, 13.6); moliFit->SetParNames("Constant"); moliFit->SetParLimits(0, 0, 30); // moliFit->SetParLimits(1, 0, 0.25); dataGraph->Fit("moliFit"); std::cout << "thetaRMS[0] = " << thetaRMS[0] << std::endl; std::cout << "thetaRMS[1] = " << thetaRMS[1] << std::endl; std::cout << "thetaRMS[2] = " << thetaRMS[2] << std::endl; std::cout << "thetaRMS[3] = " << thetaRMS[3] << std::endl; //std::cout << "thetaRMS[4] = " << thetaRMS[4] << std::endl; moliGraph0->SetLineColor(2); moliGraph0->SetLineWidth(1.5); moliGraph1->SetLineColor(8); moliGraph1->SetLineWidth(1.5); moliGraph2->SetLineColor(9); moliGraph2->SetLineWidth(1.5); dataGraph ->SetMarkerStyle(22); moliGraph0->Draw("AC"); moliGraph1->Draw("PC"); moliGraph2->Draw("PC"); dataGraph->Draw("P"); //moliFit->Draw("*"); TLegend *leg = new TLegend(0.1, 0.7, 0.48, 0.9); leg->SetHeader("Legend"); // gStyle->SetLegendFillColor(0); leg->AddEntry(moliGraph1, "Moliere Distribution for p = 222 MeV/c", "LP"); leg->AddEntry(moliGraph0, "Moliere Distribution for p = 248.5 MeV/c", "LP"); leg->AddEntry(moliGraph2, "Moliere Distribution for p = 275 MeV/c", "LP"); leg->AddEntry(dataGraph, "The angular RMS for varying Pb thicknesses", "LP"); leg->AddEntry(moliFit, "The angular RMS data fit to the Moliere Distribution", "LP"); leg->Draw(); moliGraph0->Write(); moliGraph1->Write(); moliGraph2->Write(); moliFit->Write(); dataGraph->Write(); outFile->Close(); }
TF1* GeneralCorrectionFunction( double ChannelRangeMin, double ChannelRangeMax,double ChannelPeakPos , TH2D *h2DInputForCorrection , int LineIndex, TString InputType="T10DeriMaxEnergy", TString CorrNumber="1", double XRangeMin=0, double XRangeMax=300, TString FitFuncCorr="pol2", double FitCorrRangeMin=10, double FitCorrRangeMax= 270, double TresholdForCorrection=10, TString FitFuncSlicesString="gaus(0)+[3]+gaus(4)" ) { h2DInputForCorrection->GetYaxis()->SetRangeUser(ChannelRangeMin,ChannelRangeMax); char buf[60]; sprintf(buf, "hMaxCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex); TH1D *hMaxPosManually=new TH1D(buf,"",h2DInputForCorrection->GetNbinsX(),h2DInputForCorrection->GetXaxis()->GetXmin(),h2DInputForCorrection->GetXaxis()->GetXmax()); sprintf(buf, "hMaxFitCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex); TH1D *hMaxPosManuallyFit=new TH1D(buf,"",h2DInputForCorrection->GetNbinsX(),h2DInputForCorrection->GetXaxis()->GetXmin(),h2DInputForCorrection->GetXaxis()->GetXmax()); sprintf(buf, "hGausSigmaCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex); TH1D *hGausSigmaManually=new TH1D(buf,"",h2DInputForCorrection->GetNbinsX(),h2DInputForCorrection->GetXaxis()->GetXmin(),h2DInputForCorrection->GetXaxis()->GetXmax()); for(int binX = h2DInputForCorrection->GetXaxis()->FindBin(XRangeMin);binX <= h2DInputForCorrection->GetXaxis()->FindBin(XRangeMax);binX++) //for(int binX = h2DInputForCorrection->GetXaxis()->FindBin(200);binX <= h2DInputForCorrection->GetXaxis()->FindBin(200);binX++) { TH1D *hProfileY =h2DInputForCorrection->ProjectionY("_py",binX,binX); double MaxValue=hProfileY->GetBinCenter(hProfileY->GetMaximumBin()); //hMaxPosManually->SetBinContent(binX, MaxValue); //h2DInputForCorrection //cout <<hProfileY->GetEntries()<<endl; //TF1* FitFuncSlices = new TF1("FitFuncSlices","gaus(0)+[3]",MaxValue-20,MaxValue+20); //cout << TMath::Max(MaxValue-20,double(ChannelRangeMin)) << "\t" << TMath::Min(MaxValue+20,double(ChannelRangeMax)) << "\t"<<endl; TF1* FitFuncGausSlices = new TF1("FitFuncGausSlices","gaus(0)",TMath::Max(MaxValue-20,double(ChannelRangeMin)),TMath::Min(MaxValue+20,double(ChannelRangeMax))); FitFuncGausSlices->SetParameters(hProfileY->GetBinContent(hProfileY->GetMaximumBin()),MaxValue,4); hProfileY->Fit(FitFuncGausSlices,"RNIQ"); TF1* FitFuncSlices = new TF1("FitFuncSlices",FitFuncSlicesString.Data(),TMath::Max(MaxValue-3*FitFuncGausSlices->GetParameter(2),double(ChannelRangeMin)),TMath::Min(MaxValue+3*FitFuncGausSlices->GetParameter(2),double(ChannelRangeMax))); FitFuncSlices->SetParameters(FitFuncGausSlices->GetParameter(0),FitFuncGausSlices->GetParameter(1),FitFuncGausSlices->GetParameter(2),10,10,FitFuncGausSlices->GetParameter(1)-5,5); FitFuncSlices->SetParLimits(0,FitFuncGausSlices->GetParameter(0)*0.8,FitFuncGausSlices->GetParameter(0)*1.5); FitFuncSlices->SetParLimits(1,TMath::Max(FitFuncGausSlices->GetParameter(1)-10,double(ChannelRangeMin)),TMath::Min(FitFuncGausSlices->GetParameter(1)+10,double(ChannelRangeMax))); FitFuncSlices->SetParLimits(2,0,FitFuncGausSlices->GetParameter(2)*2); FitFuncSlices->SetParLimits(3,0,500); FitFuncSlices->SetParLimits(4,0,FitFuncGausSlices->GetParameter(0)*0.3); FitFuncSlices->SetParLimits(5,TMath::Max(FitFuncGausSlices->GetParameter(1)-10,double(ChannelRangeMin)),TMath::Min(MaxValue-1,double(ChannelRangeMax))); FitFuncSlices->SetParLimits(6,0,10); hProfileY->Fit(FitFuncSlices,"RINQ"); //hProfileY->DrawCopy(); //cout <<MaxValue<<" " << FitFuncSlices->GetParameter(1) << " " << FitFuncSlices->GetParError(1) <<endl; //cout <<MaxValue<<" " << FitFuncSlices->GetParameter(1) << " " << FitFuncSlices->GetMaximumX() <<endl; hMaxPosManually->SetBinContent(binX, (FitFuncSlices->GetParameter(1))/ChannelPeakPos); hMaxPosManually->SetBinError(binX, FitFuncSlices->GetParError(1)/ChannelPeakPos); hGausSigmaManually->SetBinContent(binX, FitFuncSlices->GetParameter(2)); hGausSigmaManually->SetBinError(binX, FitFuncSlices->GetParError(2)); if(FitFuncSlices->GetParameter(2)<TresholdForCorrection && FitFuncSlices->GetParError(2)<5) { hMaxPosManuallyFit->SetBinContent(binX, (FitFuncSlices->GetParameter(1))/ChannelPeakPos); hMaxPosManuallyFit->SetBinError(binX, FitFuncSlices->GetParError(1)/ChannelPeakPos); } //hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->SetBinError(binX, FitFuncSlices->GetParameter(2)/ChannelPeakPos); hProfileY->Delete(); //cin.ignore(); } //write histos to file //sprintf(buf, "hMaxCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex); hMaxPosManually->Write(0,TObject::kOverwrite); //sprintf(buf, "hGausSigmaCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex); hGausSigmaManually->Write(0,TObject::kOverwrite); hMaxPosManuallyFit->Write(0,TObject::kOverwrite); sprintf(buf, "funcCorr%s_%sNorm_%d",CorrNumber.Data(),InputType.Data(),LineIndex); //fit corr function and write it to file TF1 *funcCorrNorm = new TF1(buf,FitFuncCorr.Data(),FitCorrRangeMin,FitCorrRangeMax); funcCorrNorm->SetParameters(1,0,-0); funcCorrNorm->SetParLimits(0,0.8,1); //funcCorrNorm->SetParLimits(2,-1E5,0); //if(LineIndex==2) // hMaxPosManuallyFit->Fit(funcCorrNorm,"RBI"); //else hMaxPosManuallyFit->Fit(funcCorrNorm,"RBQI"); sprintf(buf, "funcCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex); TF1 *funcCorr = new TF1(buf,FitFuncCorr.Data(),FitCorrRangeMin,FitCorrRangeMax); for(int i= 0; i<funcCorr->GetNpar();i++) { funcCorr->SetParameter(i,funcCorrNorm->GetParameter(i)*ChannelPeakPos); } //sprintf(buf, "funcCorr%s_%sNorm_%d",CorrNumber.Data(),InputType.Data(),LineIndex); funcCorrNorm->Write(0,TObject::kOverwrite); //sprintf(buf, "funcCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex); funcCorr->Write(0,TObject::kOverwrite); h2DInputForCorrection->GetYaxis()->UnZoom(); return funcCorr; }
//___________________________________________________________________ Int_t studyBinZero(TString pathData, TString fileNameData, TString listName = "", Double_t etaLow = -0.9, Double_t etaUp = 0.9, Double_t lowerCentrality = -2, Double_t upperCentrality = -2) { PrintSettingsAxisRangeForMultiplicityAxisForMB(); TString pathNameData = Form("%s/%s", pathData.Data(), fileNameData.Data()); if (listName == "") { listName = pathNameData; listName.Replace(0, listName.Last('/') + 1, ""); listName.ReplaceAll(".root", ""); } TObjArray* histList = 0x0; TFile* f = TFile::Open(pathNameData.Data()); if (!f) { std::cout << std::endl; std::cout << "Failed to open file \"" << pathNameData.Data() << "\"!" << std::endl; return -1; } histList = (TObjArray*)(f->Get(listName.Data())); if (!histList) { std::cout << std::endl; std::cout << "Failed to load list \"" << listName.Data() << "\"!" << std::endl; return -1; } // Extract the data histograms TH1* hNumEventsTriggerSel = dynamic_cast<TH1*>(histList->FindObject("fhEventsTriggerSel")); TH1* hNumEventsTriggerSelVtxCut = dynamic_cast<TH1*>(histList->FindObject("fhEventsTriggerSelVtxCut")); TH1* hNumEventsTriggerSelVtxCutZ= dynamic_cast<TH1*>(histList->FindObject("fhEventsProcessedNoPileUpRejection")); TH1* hNumEventsTriggerSelVtxCutZPileUpRej= dynamic_cast<TH1*>(histList->FindObject("fhEventsProcessed")); THnSparse* hDataTriggerSel = dynamic_cast<THnSparse*>(histList->FindObject("fChargedGenPrimariesTriggerSel")); THnSparse* hDataTriggerSelVtxCut = dynamic_cast<THnSparse*>(histList->FindObject("fChargedGenPrimariesTriggerSelVtxCut")); THnSparse* hDataTriggerSelVtxCutZ = dynamic_cast<THnSparse*>(histList->FindObject("fChargedGenPrimariesTriggerSelVtxCutZ")); THnSparse* hDataTriggerSelVtxCutZPileUpRej = dynamic_cast<THnSparse*>(histList->FindObject("fChargedGenPrimariesTriggerSelVtxCutZPileUpRej")); setSparseErrors(hDataTriggerSel); setSparseErrors(hDataTriggerSelVtxCut); setSparseErrors(hDataTriggerSelVtxCutZ); setSparseErrors(hDataTriggerSelVtxCutZPileUpRej); // Set multiplicity range, if desired. Note that mult and pT axes are the same for all histos Int_t lowerCentralityBinLimit = -1; Int_t upperCentralityBinLimit = -2; Bool_t restrictCentralityAxis = kFALSE; Double_t actualLowerCentrality = -1.; Double_t actualUpperCentrality = -1.; if (lowerCentrality >= -1 && upperCentrality >= -1) { // Add subtract a very small number to avoid problems with values right on the border between to bins lowerCentralityBinLimit = hNumEventsTriggerSel->GetXaxis()->FindFixBin(lowerCentrality + 0.001); upperCentralityBinLimit = hNumEventsTriggerSel->GetXaxis()->FindFixBin(upperCentrality - 0.001); // Check if the values look reasonable if (lowerCentralityBinLimit <= upperCentralityBinLimit && lowerCentralityBinLimit >= 1 && upperCentralityBinLimit <= hNumEventsTriggerSel->GetXaxis()->GetNbins()) { actualLowerCentrality = hNumEventsTriggerSel->GetXaxis()->GetBinLowEdge(lowerCentralityBinLimit); actualUpperCentrality = hNumEventsTriggerSel->GetXaxis()->GetBinUpEdge(upperCentralityBinLimit); restrictCentralityAxis = kTRUE; } else { std::cout << std::endl; std::cout << "Requested centrality range out of limits or upper and lower limit are switched!" << std::endl; return -1; } } if (!restrictCentralityAxis) GetAxisRangeForMultiplicityAxisForMB(hNumEventsTriggerSel->GetXaxis(), lowerCentralityBinLimit, upperCentralityBinLimit); hNumEventsTriggerSel->GetXaxis()->SetRange(lowerCentralityBinLimit, upperCentralityBinLimit); actualLowerCentrality = hNumEventsTriggerSel->GetXaxis()->GetBinLowEdge(hNumEventsTriggerSel->GetXaxis()->GetFirst()); actualUpperCentrality = hNumEventsTriggerSel->GetXaxis()->GetBinUpEdge(hNumEventsTriggerSel->GetXaxis()->GetLast()); std::cout << "centrality: "; if (restrictCentralityAxis) { std::cout << actualLowerCentrality << " - " << actualUpperCentrality << std::endl; std::cout << "WARNING: Does it really make sense to restrict the centrality? Usually, centrality estimators imply centrality >= 0!" << std::endl; } else std::cout << "MB (" << actualLowerCentrality << " - " << actualUpperCentrality << ")" << std::endl; if (restrictCentralityAxis) { hDataTriggerSel->GetAxis(iMult)->SetRange(lowerCentralityBinLimit, upperCentralityBinLimit); hDataTriggerSelVtxCut->GetAxis(iMult)->SetRange(lowerCentralityBinLimit, upperCentralityBinLimit); hDataTriggerSelVtxCutZ->GetAxis(iMult)->SetRange(lowerCentralityBinLimit, upperCentralityBinLimit); hDataTriggerSelVtxCutZPileUpRej->GetAxis(iMult)->SetRange(lowerCentralityBinLimit, upperCentralityBinLimit); } // Restrict eta range const Int_t lowerEtaBinLimit = hDataTriggerSel->GetAxis(iEta)->FindFixBin(etaLow + 0.0001); const Int_t upperEtaBinLimit = hDataTriggerSel->GetAxis(iEta)->FindFixBin(etaUp - 0.0001); const Double_t actualLowerEta = hDataTriggerSel->GetAxis(iEta)->GetBinLowEdge(lowerEtaBinLimit); const Double_t actualUpperEta = hDataTriggerSel->GetAxis(iEta)->GetBinUpEdge(upperEtaBinLimit); std::cout << "Eta: "; std::cout << actualLowerEta << " - " << actualUpperEta << std::endl; Bool_t symmetricInEta = TMath::Abs(TMath::Abs(actualLowerEta) - TMath::Abs(actualUpperEta)) < 1e-6; TString etaRange = symmetricInEta ? Form("|#it{#eta}| < %.1f", TMath::Abs(actualLowerEta)) : Form("%.1f < #it{#eta} < %.1f", actualLowerEta, actualUpperEta); hDataTriggerSel->GetAxis(iEta)->SetRange(lowerEtaBinLimit, upperEtaBinLimit); hDataTriggerSelVtxCut->GetAxis(iEta)->SetRange(lowerEtaBinLimit, upperEtaBinLimit); hDataTriggerSelVtxCutZ->GetAxis(iEta)->SetRange(lowerEtaBinLimit, upperEtaBinLimit); hDataTriggerSelVtxCutZPileUpRej->GetAxis(iEta)->SetRange(lowerEtaBinLimit, upperEtaBinLimit); // Obtain number of events for each class // Note: Under- and overflow automatically taken into account for unrestricted axis by using -1 and -2 for limits const Double_t numEvtsTriggerSel = hNumEventsTriggerSel->Integral(lowerCentralityBinLimit, upperCentralityBinLimit); const Double_t numEvtsTriggerSelVtxCut = hNumEventsTriggerSelVtxCut->Integral(lowerCentralityBinLimit, upperCentralityBinLimit); const Double_t numEvtsTriggerSelVtxCutZ = hNumEventsTriggerSelVtxCutZ->Integral(lowerCentralityBinLimit, upperCentralityBinLimit); const Double_t numEvtsTriggerSelVtxCutZPileUpRej = hNumEventsTriggerSelVtxCutZPileUpRej->Integral(lowerCentralityBinLimit, upperCentralityBinLimit); // Project pT spectra TH1D* hSpectraTriggerSel = (TH1D*)hDataTriggerSel->Projection(iPt, "e"); TH1D* hSpectraTriggerSelVtxCut = (TH1D*)hDataTriggerSelVtxCut->Projection(iPt, "e"); TH1D* hSpectraTriggerSelVtxCutZ = (TH1D*)hDataTriggerSelVtxCutZ->Projection(iPt, "e"); TH1D* hSpectraTriggerSelVtxCutZPileUpRej = (TH1D*)hDataTriggerSelVtxCutZPileUpRej->Projection(iPt, "e"); // Normalise histos to 1/Nevt dN/dPt normaliseHist(hSpectraTriggerSel, numEvtsTriggerSel); normaliseHist(hSpectraTriggerSelVtxCut, numEvtsTriggerSelVtxCut); normaliseHist(hSpectraTriggerSelVtxCutZ, numEvtsTriggerSelVtxCutZ); normaliseHist(hSpectraTriggerSelVtxCutZPileUpRej, numEvtsTriggerSelVtxCutZPileUpRej); setupHist(hSpectraTriggerSel, kBlack, "Trigger selection"); setupHist(hSpectraTriggerSelVtxCut, kRed, "& vertex cut"); setupHist(hSpectraTriggerSelVtxCutZ, kBlue, "& vertex #it{z} cut"); setupHist(hSpectraTriggerSelVtxCutZPileUpRej, kGreen, "& pile-up rejection"); TCanvas* canvSpectra = new TCanvas("canvSpectra", "Spectra", 760, 420); canvSpectra->SetLogx(); canvSpectra->SetLogy(); canvSpectra->SetGrid(0, 0); SetCanvasMargins(canvSpectra); TLegend* leg = new TLegend(0.14, 0.26, 0.62, 0.55); leg->SetHeader(Form("MC pp #sqrt{s}=7 TeV, inclusive, %s", etaRange.Data())); leg->AddEntry(hSpectraTriggerSel, "", "l"); leg->AddEntry(hSpectraTriggerSelVtxCut, "", "l"); leg->AddEntry(hSpectraTriggerSelVtxCutZ, "", "l"); if (drawPileUp) leg->AddEntry(hSpectraTriggerSelVtxCutZPileUpRej, "", "l"); SetupLegend(leg); leg->SetMargin(0.15); hSpectraTriggerSel->Draw(); hSpectraTriggerSelVtxCut->Draw("same"); hSpectraTriggerSelVtxCutZ->Draw("same"); if (drawPileUp) hSpectraTriggerSelVtxCutZPileUpRej->Draw("same"); leg->Draw("same"); // Ratios (take binomial errors, since real sub-samples) TH1D* hRatioVtxCut = new TH1D(*hSpectraTriggerSelVtxCut); hRatioVtxCut->SetName("hRatioVtxCut"); setupHist(hRatioVtxCut, kBlack, "MB & vtx / MB"); hRatioVtxCut->GetYaxis()->SetTitle("1/#it{N}_{evt} d#it{N}/d#it{p}_{T}^{gen} ratio"); hRatioVtxCut->Divide(hRatioVtxCut, hSpectraTriggerSel, 1., 1., "B"); hRatioVtxCut->GetYaxis()->SetRangeUser(1.08, 1.14); // Mean ratio of spectra and of Nevt TF1* funcRatioVtxCut = new TF1("funcRatioVtxCut", "pol0", 0.15, hRatioVtxCut->GetXaxis()->GetBinUpEdge(hSpectraTriggerSelVtxCut->FindLastBinAbove(0))); funcRatioVtxCut->SetLineWidth(2); funcRatioVtxCut->SetLineColor(kRed); hRatioVtxCut->Fit(funcRatioVtxCut, "N"); const Double_t meanRatioVtxCut = funcRatioVtxCut->GetParameter(0); const Double_t ratioNevtVtxCut = numEvtsTriggerSelVtxCut > 0 ? numEvtsTriggerSel / numEvtsTriggerSelVtxCut : -1.; const Double_t doubleRatioMinusOne = meanRatioVtxCut > 0 ? (ratioNevtVtxCut / meanRatioVtxCut - 1.) : -999.; TH1D* hRatioVtxCutZ = new TH1D(*hSpectraTriggerSelVtxCutZ); hRatioVtxCutZ->SetName("hRatioVtxCutZ"); setupHist(hRatioVtxCutZ, kBlack, "MB & vtx & #it{z} vtx / MB & vtx"); hRatioVtxCutZ->GetYaxis()->SetTitle("1/#it{N}_{evt} d#it{N}/d#it{p}_{T}^{gen} ratio"); hRatioVtxCutZ->Divide(hRatioVtxCutZ, hSpectraTriggerSelVtxCut, 1., 1., "B"); hRatioVtxCutZ->GetYaxis()->SetRangeUser(0.95, 1.05); // Mean ratio of spectra and of Nevt TF1* funcRatioVtxCutZ = new TF1("funcRatioVtxCutZ", "pol0", 0.15, hRatioVtxCutZ->GetXaxis()->GetBinUpEdge(hSpectraTriggerSelVtxCutZ->FindLastBinAbove(0))); hRatioVtxCutZ->Fit(funcRatioVtxCutZ, "N"); funcRatioVtxCutZ->SetLineWidth(2); funcRatioVtxCutZ->SetLineColor(kRed); const Double_t meanRatioVtxCutZ = funcRatioVtxCutZ->GetParameter(0); const Double_t ratioNevtVtxCutZ = numEvtsTriggerSelVtxCutZ > 0 ? numEvtsTriggerSelVtxCut / numEvtsTriggerSelVtxCutZ : -1.; TH1D* hRatioPileUp = new TH1D(*hSpectraTriggerSelVtxCutZPileUpRej); hRatioPileUp->SetName("hRatioPileUp"); setupHist(hRatioPileUp, kBlack, "MB & vtx & #it{z} vtx & pile-up / MB & vtx & #it{z} vtx"); hRatioPileUp->GetYaxis()->SetTitle("1/#it{N}_{evt} d#it{N}/d#it{p}_{T}^{gen} ratio"); hRatioPileUp->Divide(hRatioPileUp, hSpectraTriggerSelVtxCutZ, 1., 1., "B"); /* TF1* funcRatioPileUp = new TF1("funcRatioPileUp", "pol0", 0.15, hRatioPileUp->GetXaxis()->GetBinUpEdge(hSpectraTriggerSelVtxCutZPileUpRej->FindLastBinAbove(0))); hRatioPileUp->Fit(funcRatioPileUp, "N");*/ ClearTitleFromHistoInCanvas(canvSpectra); TCanvas* canvRatioVtx = new TCanvas("canvRatioVtx", "Ratio vertex", 760, 420); canvRatioVtx->SetLogx(); canvRatioVtx->SetGrid(0, 1); SetCanvasMargins(canvRatioVtx); hRatioVtxCut->Draw(); funcRatioVtxCut->Draw("same"); TLegend* leg2 = new TLegend(0.22, 0.7, drawPileUp ? 0.87 : 0.72, 0.9); leg2->SetHeader(Form("MC pp #sqrt{s}=7 TeV, inclusive, %s", etaRange.Data())); leg2->AddEntry(hRatioVtxCut, "", "l"); SetupLegend(leg2); leg2->SetMargin(0.1); leg2->Draw("same"); ClearTitleFromHistoInCanvas(canvRatioVtx); TCanvas* canvRatioOther = new TCanvas("canvRatioOther", "Ratio others", 760, 420); canvRatioOther->SetLogx(); canvRatioOther->SetGrid(0, 1); SetCanvasMargins(canvRatioOther); hRatioVtxCutZ->Draw(); if (drawPileUp) hRatioPileUp->Draw("same"); TLegend* leg3 = new TLegend(0.22, drawPileUp ? 0.63 : 0.7, drawPileUp ? 0.87 : 0.72, 0.9); leg3->SetHeader(Form("MC pp #sqrt{s}=7 TeV, inclusive, %s", etaRange.Data())); leg3->AddEntry(hRatioVtxCutZ, "", "l"); if (drawPileUp) leg3->AddEntry(hRatioPileUp, "", "l"); SetupLegend(leg3); leg3->SetMargin(0.1); leg3->Draw("same"); ClearTitleFromHistoInCanvas(canvRatioOther); printf("meanRatioVtxCut %f <-> ratioNevtVtxCut %f => meanRatioVtxCutZ/ratioNevtVtxCutZ - 1 = %f\nmeanRatioVtxCutZ %f <-> ratioNevtVtxCutZ %f\n", meanRatioVtxCut, ratioNevtVtxCut, doubleRatioMinusOne, meanRatioVtxCutZ, ratioNevtVtxCutZ); TNamed* settings = new TNamed( Form("Settings: Data file \"%s\", lowerEta %.2f, uppEta %.2f, lowerCentrality %.3f, upperCentrality %.3f, doubleRatioMinusOne %.4f\n", pathNameData.Data(), etaLow, etaUp, lowerCentrality, upperCentrality, doubleRatioMinusOne), ""); // Save results to file TString saveFileName = pathNameData; saveFileName = Form("%s_binZeroStudy.root", saveFileName.ReplaceAll(".root", "").Data()); TFile *saveFile = TFile::Open(saveFileName.Data(), "RECREATE"); saveFile->cd(); hSpectraTriggerSel->Write(); hSpectraTriggerSelVtxCut->Write(); hSpectraTriggerSelVtxCutZ->Write(); hSpectraTriggerSelVtxCutZPileUpRej->Write(); hRatioVtxCut->Write(); hRatioVtxCutZ->Write(); hRatioPileUp->Write(); funcRatioVtxCut->Write(); funcRatioVtxCutZ->Write(); canvSpectra->Write(); canvRatioVtx->Write(); canvRatioOther->Write(); settings->Write(); saveFile->Close(); TString temp = saveFileName; canvRatioVtx->SaveAs(Form("%s", temp.ReplaceAll(".root", "_ratioVtx.pdf").Data())); temp = saveFileName; canvRatioOther->SaveAs(Form("%s", temp.ReplaceAll(".root", "_ratioOther.pdf").Data())); PrintSettingsAxisRangeForMultiplicityAxisForMB(); return 0; }
TF1 *fit(TTree *nt, TTree *ntMC, Double_t ptmin, Double_t ptmax, int isMC,bool isPbPb,TF1* &total,Float_t centmin, Float_t centmax) { //cout<<cut.Data()<<endl; static Int_t count=0; count++; TCanvas* c= new TCanvas(Form("c%d",count),"",600,600); TH1D* h = new TH1D(Form("h%d",count),"",nbinsmasshisto,minhisto,maxhisto); // TF1* f = new TF1(Form("f%d",count),"[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]) + [3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5]) + [6]*Gaus(x,[7],[8])/(sqrt(2*3.14159)*[8]) + [9]+[10]*x "); // TF1* f = new TF1(Form("f%d",count),"[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]) + [3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5]) + [9]+[10]*x "); TF1* f = new TF1(Form("f%d",count),"[0]*TMath::Erf((x-[1])/[2]) + [0] + [9]+[10]*x "); if(isMC==1) nt->Project(Form("h%d",count),"Bmass",Form("%s*(%s&&Bpt>%f&&Bpt<%f)","1",seldata.Data(),ptmin,ptmax)); else nt->Project(Form("h%d",count),"Bmass",Form("(%s&&Bpt>%f&&Bpt<%f)",seldata.Data(),ptmin,ptmax)); clean0(h); h->Draw(); f->SetParLimits(0, 1e-2, 1e4); f->SetParLimits(1, 5.02, 5.06); f->SetParLimits(2, 0.001, 0.1); f->SetParLimits(3, 1e-2, 1e4); f->SetParLimits(4, 5.06, 5.10); f->SetParLimits(5, 0.001, 0.1); f->SetParLimits(6, 0, 1e4); f->SetParLimits(7, 5.3, 5.4); f->SetParLimits(8, 0.001, 0.5); f->SetParLimits(9, 0, 1e5); f->SetParLimits(10, -500, 100); f->SetParameter(0,1e2); f->SetParameter(1,5.03); f->SetParameter(2,0.05); f->SetParameter(0,1e2); f->SetParameter(1,5.03); f->SetParameter(2,0.05); f->SetParameter(3,1e2); f->SetParameter(4,5.07); f->SetParameter(5,0.05); f->SetParameter(6,1e2); f->SetParameter(7,5.35); f->SetParameter(8,0.05); f->SetParameter(9,1e3); f->SetParameter(10,-1); //error fn f->SetParLimits(0, 1e1, 1e3); f->SetParLimits(1, 5., 5.3); f->SetParLimits(2, -10, 0); f->SetParameter(0,100); f->SetParameter(1,5.1); f->SetParameter(2,0); h->GetEntries(); h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x"); background->SetParameter(0,f->GetParameter(9)); background->SetParameter(1,f->GetParameter(10)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); // TF1 *mass = new TF1(Form("fmass%d",count),"[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]) + [3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5]) + [6]*Gaus(x,[7],[8])/(sqrt(2*3.14159)*[8])"); // mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(3),f->GetParameter(4),f->GetParameter(5),f->GetParameter(6),f->GetParameter(7),f->GetParameter(8)); //TF1 *mass = new TF1(Form("fmass%d",count),"[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]) + [3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5])"); //mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(3),f->GetParameter(4),f->GetParameter(5)); TF1 *mass = new TF1(Form("fmass%d",count),"[0]*TMath::Erf((x-[1])/[2]) + [0]"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2)); //mass->SetParError(0,f->GetParError(0)); //mass->SetParError(1,f->GetParError(1)); //mass->SetParError(2,f->GetParError(2)); mass->SetLineColor(2); h->SetXTitle("m_{#mu#muK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0); TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Peaking BG","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); TLatex* texCms = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); texCms->SetNDC(); texCms->SetTextAlign(12); texCms->SetTextSize(0.04); texCms->SetTextFont(42); texCms->Draw(); TLatex* texCol; if(collisionsystem=="pp"||collisionsystem=="PP") texCol= new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV","pp")); else texCol= new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV","PbPb")); texCol->SetNDC(); texCol->SetTextAlign(32); texCol->SetTextSize(0.04); texCol->SetTextFont(42); texCol->Draw(); TLatex* tex; tex = new TLatex(0.22,0.78,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); if(centMax>0){ TString texper="%"; tex = new TLatex(0.22,0.71,Form("Centrality %.0f-%.0f%s",centMin,centMax,texper.Data()));//0.2612903,0.8425793 tex->SetNDC(); tex->SetTextColor(1); tex->SetTextFont(42); tex->SetTextSize(0.045); tex->SetLineWidth(2); tex->Draw(); } tex = new TLatex(0.22,0.83,"|y| < 2.4"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); total=f; h->Write(); f->Write(); if(!isPbPb) c->SaveAs(Form("plotNP/BMass%s_%d.pdf",collisionsystem.Data(),count)); else c->SaveAs(Form("plotNP/BMass%s_%.0f_%.0f_%d.pdf",collisionsystem.Data(),centMin,centMax,count)); return mass; }
int makeInvMassHistosNoBGKK(){ //Set global style stuff gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetPalette(1); gStyle->SetCanvasColor(kWhite); gStyle->SetCanvasBorderMode(0); gStyle->SetPadBorderMode(0); gStyle->SetTitleBorderSize(0); gStyle->SetOptStat(0); gStyle->SetOptFit(1); gStyle->SetErrorX(0); gStyle->SetTitleW(0.9); gStyle->SetTitleSize(0.05, "xyz"); gStyle->SetTitleSize(0.06, "h"); int NUM_PT_BINS = 20; int NUM_MASS_BINS = 1000; double MASS_LOW = 0.0; double MASS_HIGH = 2.0; string particles [8]; particles[0] = "K*^{+} + K*^{0}"; particles[1] = "K*^{-} + #bar{K}*^{0}"; particles[2] = "K*^{+}"; particles[3] = "K*^{-}"; particles[4] = "K*^{0}"; particles[5] = "#bar{K}*^{0}"; particles[6] = "K*^{0} + #bar{K}*^{0}"; particles[7] = "K*^{+} + K*^{-}"; //at decay point // string folder = "/Users/jtblair/Downloads/kstar_data/decayed/pt02/"; //reconstructed string folder = "/Users/jtblair/Downloads/kstar_data/reconstructed/pt02/"; string files[20]; files[0] = "invm_[0.0,0.2].dat"; files[1] = "invm_[0.2,0.4].dat"; files[2] = "invm_[0.4,0.6].dat"; files[3] = "invm_[0.6,0.8].dat"; files[4] = "invm_[0.8,1.0].dat"; files[5] = "invm_[1.0,1.2].dat"; files[6] = "invm_[1.2,1.4].dat"; files[7] = "invm_[1.4,1.6].dat"; files[8] = "invm_[1.6,1.8].dat"; files[9] = "invm_[1.8,2.0].dat"; files[10] = "invm_[2.0,2.2].dat"; files[11] = "invm_[2.2,2.4].dat"; files[12] = "invm_[2.4,2.6].dat"; files[13] = "invm_[2.6,2.8].dat"; files[14] = "invm_[2.8,3.0].dat"; files[15] = "invm_[3.0,3.2].dat"; files[16] = "invm_[3.2,3.4].dat"; files[17] = "invm_[3.4,3.6].dat"; files[18] = "invm_[3.6,3.8].dat"; files[19] = "invm_[3.8,4.0].dat"; /* string files[8]; files[0] = "invm_[0.0,0.5].dat"; files[1] = "invm_[0.5,1.0].dat"; files[2] = "invm_[1.0,1.5].dat"; files[3] = "invm_[1.5,2.0].dat"; files[4] = "invm_[2.0,2.5].dat"; files[5] = "invm_[2.5,3.0].dat"; files[6] = "invm_[3.0,3.5].dat"; files[7] = "invm_[3.5,4.0].dat"; */ Int_t PARTICLE_NUM = 5; TFile *output = new TFile("20170721_KKbarAdded2_fixedwidth42_recon_pf100_scaled_error05.root", "RECREATE"); TH1D *kstar0mass = new TH1D("kstar0mass", Form("Fit value of M*_{0} vs. p_{T} for %s", particles[PARTICLE_NUM].c_str()), NUM_PT_BINS, 0.0, 4.0); TH1D *kstar0width = new TH1D("kstar0width", Form("#Gamma_{tot}(M=M*_{0}) vs p_{T} for %s", particles[PARTICLE_NUM].c_str()), NUM_PT_BINS, 0.0, 4.0); TH1D *kstar0collWidth = new TH1D("kstar0collWidth", Form("Fit value of #Gamma_{coll} component vs. p_{T} for %s", particles[PARTICLE_NUM].c_str()), NUM_PT_BINS,0.0, 4.0); TH1D *kstar0decWidth = new TH1D("kstar0decWidth", Form("#Gamma_{dec}(M=M*_{0}) component vs. p_{T} for %s;p_{T} (GeV/c);Width (GeV/c^2)", particles[PARTICLE_NUM].c_str()), NUM_PT_BINS,0.0, 4.0); kstar0mass->GetXaxis()->SetTitle("p_{T} (GeV/c)"); kstar0mass->GetYaxis()->SetTitle("Mass (GeV/c^{2})"); kstar0width->GetXaxis()->SetTitle("p_{T} (GeV/c)"); kstar0width->GetYaxis()->SetTitle("Width (GeV/c^2)"); kstar0collWidth->GetXaxis()->SetTitle("p_{T} (GeV/c)"); kstar0collWidth->GetYaxis()->SetTitle("Width (GeV/c^2)"); kstar0mass->SetStats(kFALSE); kstar0width->SetStats(kFALSE); kstar0collWidth->SetStats(kFALSE); kstar0decWidth->SetStats(kFALSE); TF1 *massline = new TF1("massline", "[0]", 0.0, 4.0); massline->SetParameter(0, 0.892); massline->SetLineColor(2); massline->SetLineStyle(7); TF1 *widthline = new TF1("widthline", "[0]", 0.0, 4.0); widthline->SetParameter(0, 0.042); double mass = 0.0, width = 0.0, collWidth = 0.0, massBG=0.0; double massError = 0.0, widthError= 0.0, collWidthError = 0.0, massBGError=0.0; TCanvas *canvas[9]; TCanvas *diffCanvas[9]; TPaveStats *st; TPad *pad; //ofstream integrals; //integrals.open("kstarbar_integrals.txt"); for(int nfile = 0; nfile < NUM_PT_BINS; nfile++){ double meanPT = (double)(nfile*2+1)/10.0; string filename = folder+files[nfile]; string ptLower = filename.substr(filename.find("[")+1, 3); string ptHigher = filename.substr(filename.find(",")+1, 3); TH1D* histos[8]; TH1D* newHistos[8]; TH1D* diffHistos[8]; TH1D* bg[8]; for(int i=0; i<8; i++){ if(nfile<5){ histos[i] = new TH1D(Form("ptbin0%dparticle%d",nfile*2+1, i), Form("Invariant Mass for (%s), %s < p_{T} < %s",particles[i].c_str(), ptLower.c_str(), ptHigher.c_str()), NUM_MASS_BINS, MASS_LOW, MASS_HIGH); newHistos[i] = new TH1D(Form("newptbin0%dparticle%d",nfile*2+1, i), Form("Invariant Mass for (%s), %s < p_{T} < %s",particles[i].c_str(), ptLower.c_str(), ptHigher.c_str()), 250, MASS_LOW, MASS_HIGH); }else{ histos[i] = new TH1D(Form("ptbin%dparticle%d",nfile*2+1, i), Form("Invariant Mass for (%s), %s < p_{T} < %s",particles[i].c_str(), ptLower.c_str(), ptHigher.c_str()), NUM_MASS_BINS, MASS_LOW, MASS_HIGH); newHistos[i] = new TH1D(Form("newptbin%dparticle%d",nfile*2+1, i), Form("Invariant Mass for (%s), %s < p_{T} < %s",particles[i].c_str(), ptLower.c_str(), ptHigher.c_str()), 250, MASS_LOW, MASS_HIGH); } histos[i]->GetXaxis()->SetTitle("Invariant Mass (GeV/c^{2})"); histos[i]->GetYaxis()->SetTitle("Counts"); } ifstream input; input.open(filename.c_str()); string line = ""; if(input.good()){ getline(input, line); } double massBin=0.0; double invMass[8]; for(int i=0; i<8; i++){ invMass[i] = 0.0; } int lineNumber = 1; while(1){ input >> massBin >> invMass[0] >> invMass[1] >> invMass[2] >> invMass[3] >> invMass[4] >> invMass[5] >> invMass[6] >> invMass[7]; if(!input.good())break; for(int i =0; i<8; i++){ histos[i]->SetBinContent(lineNumber, invMass[i]/500.0); } if(lineNumber > 440 && lineNumber < 460 && nfile==6){ // printf("mass: %.12f invMass[6]: %.12f\n", massBin, invMass[6]); } lineNumber++; } printf("****** Fits for file: %s ******\n", filename.c_str()); for(int i=PARTICLE_NUM; i<PARTICLE_NUM+1; i++){ //add the K*0 distribution to the K*0bar (K*0 = 4 for decay, K*0 = 3 for reconstructed) histos[i]->Add(histos[3]); if(nfile==0){ canvas[i] = new TCanvas(Form("c%i", i),Form("c%i", i), 0,0,900,900); canvas[i]->Divide(5,4); diffCanvas[i] = new TCanvas(Form("diffC%i", i),Form("diffC%i", i), 0,0,900,900); diffCanvas[i]->Divide(5,4); } //rebin //histos[i]->Sumw2(); histos[i]->Rebin(4); //Fixing the errors to a percentage of the signal region: for(int ibin=1; ibin < histos[i]->GetNbinsX(); ibin++){ histos[i]->SetBinError(ibin, histos[i]->GetBinContent((int)(0.892*(250.0/2.0)))*0.05); newHistos[i]->SetBinContent(ibin, histos[i]->GetBinContent(ibin)); newHistos[i]->SetBinError(ibin, histos[i]->GetBinError(ibin)); } pad = (TPad*)canvas[i]->cd(nfile+1); histos[i]->SetLineColor(1); histos[i]->SetLineWidth(1); histos[i]->GetXaxis()->SetRangeUser(0.7, 1.2); histos[i]->GetYaxis()->SetRangeUser(0, 1.5*histos[i]->GetBinContent(histos[i]->GetMaximumBin())); //histos[i]->SetStats(kFALSE); //histos[i]->Draw("HIST"); printf("mean PT: %f\n", meanPT); TF1 *fit = new TF1(Form("fitPTbin%d00particle%d", nfile*2+1, i), FitFunRelBW, 0.68, 1.05, 5); //TF1 *fit = new TF1(Form("fitPTbin%d00particle%d", nfile*2+1, i), "gaus(0)", 0.86, 0.92); fit->SetParNames("BW Area", "Mass", "Width", "PT", "Temp"); fit->SetParameters(TMath::Power(10.0, (float)(nfile)/1.7), 0.89, 0.1, 0.5, 0.130); //fit->SetParNames("BW Area", "Mass", "Width"); //fit->SetParameters(100, 0.89, 0.0474); //fit->SetParLimits(0, -10, 1.5e9); Float_t max = histos[i]->GetXaxis()->GetBinCenter(histos[i]->GetMaximumBin()); //if(max < 0.91 && max > 0.892){ // fit->SetParLimits(1, max-0.001, max+0.001); //}else{ fit->SetParLimits(1, 0.82, 0.98); //} //fit->SetParLimits(2, 0.005, 0.15); fit->FixParameter(2, 0.042); fit->FixParameter(3, meanPT); //fit->SetParLimits(4, 0.05, 0.2); fit->FixParameter(4, 0.100001); fit->SetLineColor(2); printf("%s\n", fit->GetName()); histos[i]->Fit(Form("fitPTbin%d00particle%d", nfile*2+1, i), "BRIM", "SAME"); TVirtualFitter *fitter = TVirtualFitter::GetFitter(); histos[i]->SetStats(1); histos[i]->Draw(); gPad->Update(); pad->Update(); st = (TPaveStats*)histos[i]->FindObject("stats"); st->SetX1NDC(0.524); st->SetY1NDC(0.680); st->SetX2NDC(0.884); st->SetY2NDC(0.876); //fit->Draw("SAME"); //histos[i]->Draw(); gPad->Update(); pad->Update(); printf("\n"); diffHistos[i] = (TH1D*)histos[i]->Clone(Form("diffPTbin%d00particl%d", nfile*2+1, i)); diffHistos[i]->Add(fit, -1); diffCanvas[i]->cd(nfile+1); diffHistos[i]->Draw("HIST E"); diffHistos[i]->Write(); //counting bins Float_t integral = histos[i]->Integral(1, 500)*500.0; //integrals << integral <<" \n"; histos[i]->Write(); fit->Write(); //Do mass and width vs. pT plots just for K*0 if(i==PARTICLE_NUM){ mass = fit->GetParameter(1); massError = fit->GetParError(1); collWidth = fit->GetParameter(2); collWidthError = fit->GetParError(2); width = Gamma(mass, collWidth); kstar0mass->SetBinContent(nfile+1, mass); kstar0mass->SetBinError(nfile+1, massError); kstar0width->SetBinContent(nfile+1, width); Double_t widthError = TMath::Sqrt((GammaDerivative(mass)**2)*fitter->GetCovarianceMatrixElement(1,1) + fitter->GetCovarianceMatrixElement(2,2) + 2.0*GammaDerivative(mass)*fitter->GetCovarianceMatrixElement(1,2)); kstar0width->SetBinError(nfile+1, widthError); kstar0collWidth->SetBinContent(nfile+1, collWidth); kstar0collWidth->SetBinError(nfile+1, collWidthError); kstar0decWidth->SetBinContent(nfile+1, width - collWidth); Double_t decWidthError = TMath::Sqrt((GammaDerivative(mass)**2)*fitter->GetCovarianceMatrixElement(1,1)); kstar0decWidth->SetBinError(nfile+1, decWidthError); if(nfile==4){ TCanvas *singlecanvas = new TCanvas("singlecanvas", "singlecanvas", 0,0,600,600); singlecanvas->cd(); printf("Got here! \n"); histos[i]->Draw("HIST E SAME"); fit->SetLineColor(8); fit->SetLineStyle(1); fit->Draw("SAME"); if(fitter){ printf("sig11: %f, sig12: %f, sig21: %f, sig22: %f GammaDer(0.8): %f GammaDer(0.85): %f GammaDer(0.9): %f\n", TMath::Sqrt(fitter->GetCovarianceMatrixElement(1,1)), fitter->GetCovarianceMatrixElement(2,1), fitter->GetCovarianceMatrixElement(1,2), TMath::Sqrt(fitter->GetCovarianceMatrixElement(2,2)), GammaDerivative(0.8), GammaDerivative(0.85), GammaDerivative(0.9)); } } } } printf("************************************************************\n"); } //integrals.close(); /* TH2D *gammaPlot = new TH2D("gammaPlot", "#Gamma_{tot}(M_{0}*);M_{0}*;#Gamma_{coll};#Gamma_{tot}", 100, 0.82, 0.9, 100, 0.0, 0.08); for(int im = 0; im<100; im++){ for(int ig = 0; ig < 100; ig++){ gammaPlot->SetBinContent(im+1, ig+1, Gamma(((0.9-0.82)/(100.0))*((double)(im)) + 0.82, ((0.08)/100.0)*((double)(ig)))); } } TH1D *gammaMassDpnd = gammaPlot->ProjectionX("gammaMassDpnd"); */ TCanvas *masscanvas = new TCanvas("masscanvas", "masscanvas", 50,50, 600, 600); masscanvas->cd(); kstar0mass->Draw(); massline->Draw("SAME"); masscanvas->Write(); for(int i=PARTICLE_NUM; i<PARTICLE_NUM+1; i++){ canvas[i]->Write(); } kstar0mass->Write(); kstar0collWidth->Write(); kstar0decWidth->Write(); kstar0width->Write(); // gammaPlot->Write(); // gammaMassDpnd->Write(); }
TF1 *fit(TTree *nt,TTree *ntMC,double ptmin,double ptmax, bool ispPb, int count){ //cout<<cut.Data()<<endl; //static int count=0; //count++; TCanvas *c= new TCanvas(Form("c%d",count),"",600,600); TH1D *h = new TH1D(Form("h%d",count),"",50,5,6); TH1D *hMC = new TH1D(Form("hMC%d",count),"",50,5,6); TString iNP="7.26667e+00*Gaus(x,5.10472e+00,2.63158e-02)/(sqrt(2*3.14159)*2.63158e-02)+4.99089e+01*Gaus(x,4.96473e+00,9.56645e-02)/(sqrt(2*3.14159)*9.56645e-02)+3.94417e-01*(3.74282e+01*Gaus(x,5.34796e+00,3.11510e-02)+1.14713e+01*Gaus(x,5.42190e+00,1.00544e-01))"; TF1 *f = new TF1(Form("f%d",count),"[0]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*("+iNP+")"); nt->Project(Form("h%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); clean0(h); TH1D *hraw = new TH1D(Form("hraw%d",count),"",50,5,6); clean0(hraw); hraw = (TH1D*)h->Clone(Form("hraw%d",count)); h->Draw(); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParLimits(8,0.01,0.05); f->SetParLimits(7,0,1); f->SetParLimits(5,0,1000); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(8,setparam3); f->FixParameter(1,fixparam1); h->GetEntries(); hMC->Fit(Form("f%d",count),"q","",5,6); hMC->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L m","",5,6); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(7,f->GetParameter(7)); f->FixParameter(8,f->GetParameter(8)); h->Fit(Form("f%d",count),"q","",5,6); h->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L m","",5,6); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); cout <<h->GetEntries()<<endl; // function for background shape plotting. take the fit result from f TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); // function for signal shape plotting. take the fit result from f TF1 *Bkpi = new TF1(Form("fBkpi%d",count),"[0]*("+iNP+")"); Bkpi->SetParameter(0,f->GetParameter(5)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetFillColor(kGreen+1); // Bkpi->SetRange(5.00,5.28); Bkpi->SetRange(5.00,6.00); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3004); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1(Form("fmass%d",count),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(7,f->GetParError(7)); mass->SetParError(8,f->GetParError(8)); mass->SetLineColor(2); mass->SetLineStyle(2); // cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl; h->SetMarkerStyle(24); h->SetStats(0); h->Draw("e"); h->SetXTitle("M_{B} (GeV/c^{2})"); h->SetYTitle("Entries / (20 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetTitleOffset(1.5,"Y"); h->SetAxisRange(0,h->GetMaximum()*1.2,"Y"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); hraw->Draw("same"); double yield = mass->Integral(5,6)/0.02; double yieldErr = mass->Integral(5,6)/0.02*mass->GetParError(0)/mass->GetParameter(0); // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.89); leg->AddEntry(h,"CMS Preliminary",""); leg->AddEntry(h,"pPb #sqrt{s_{NN}} = 5.02 TeV",""); leg->AddEntry(h,Form("%.0f < p_{T}^{B} < %.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->AddEntry(Bkpi,"Non-prompt J/#psi","f"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(h,"B meson",""); leg2->AddEntry(h,Form("M_{B} = %.2f #pm %.2f MeV/c^{2}",mass->GetParameter(1)*1000.,mass->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{B} = %.0f #pm %.0f", yield, yieldErr),""); leg2->Draw(); if(ispPb)c->SaveAs(Form("../ResultsBplus/BMass-%d.pdf",count)); else c->SaveAs(Form("../ResultsBplus_pp/BMass-%d.pdf",count)); h->Write(); hMC->Write(); f->Write(); background->Write(); Bkpi->Write(); mass->Write(); hraw->Write(); return mass; }
void DoTDeriMax1090Correction(TString SpectrumFileInput = "/lustre/miifs05/scratch/him-specf/hyp/steinen/COSYBeamtestAna/COSYnewMogon/June2014/COSYJune2014Dataset11_200,100,0,5339_SR1.root", TString FitFileInput = "/lustre/miifs05/scratch/him-specf/hyp/steinen/COSYBeamtestAna/COSYnewMogon/Fit/FitCOSYJune2014Dataset11_200,100,0,5339_SR1.root") { TH2D *hSpectrumTDeriMax1090_EnergyChannel; TH2D *hSpectrumTDeriMax1090Rel_EnergyChannel; TH2D *hSpectrumT1090_EnergyChannelCorr1; TNtuple *DataNTuple; TFile *SpectrumInput = new TFile(SpectrumFileInput.Data()); hSpectrumTDeriMax1090_EnergyChannel = (TH2D*) SpectrumInput->Get("Histograms/Energy_DeriMaxT90/Energy_DeriMaxT90_01"); hSpectrumTDeriMax1090_EnergyChannel->SetDirectory(0); hSpectrumTDeriMax1090Rel_EnergyChannel = (TH2D*) SpectrumInput->Get("Histograms/Energy_DeriMaxT90Rel/Energy_DeriMaxT90Rel_01"); hSpectrumTDeriMax1090Rel_EnergyChannel->SetDirectory(0); hSpectrumT1090_EnergyChannelCorr1 = (TH2D*) SpectrumInput->Get("Histograms/EnergyRt1090/EnergyRt1090CorrectionRt_01"); hSpectrumT1090_EnergyChannelCorr1->SetDirectory(0); SpectrumInput->Close(); //hSpectrumTDeriMax1090_EnergyChannel->Draw("colz"); TFile *FitInput = new TFile(FitFileInput.Data(),"Update"); DataNTuple = (TNtuple*)FitInput->Get("DataNTuple"); DataNTuple->Scan(); Int_t entries = (Int_t)DataNTuple->GetEntries(); cout<<"Number of Entries: "<<entries<< endl; const int entriesArrayValue =entries; TF1 *FitFunc[entriesArrayValue]; float Energy=0; float ChannelPeakPos=0; float ChannelRangeMin=0; float ChannelRangeMax=0; DataNTuple->SetBranchAddress("Energy",&Energy); DataNTuple->SetBranchAddress("ChannelPeakPos",&ChannelPeakPos); DataNTuple->SetBranchAddress("ChannelRangeMin",&ChannelRangeMin); DataNTuple->SetBranchAddress("ChannelRangeMax",&ChannelRangeMax); TCanvas* can=new TCanvas(); gPad->SetLogz(); hSpectrumTDeriMax1090_EnergyChannel->GetXaxis()->SetRangeUser(-30,250); hSpectrumTDeriMax1090Rel_EnergyChannel->GetXaxis()->SetRangeUser(-0.1,0.95); for (Int_t ki=0;ki<entries;ki++) { DataNTuple->GetEntry(ki); //if (int(Energy) == 1332) //if (int(Energy) == 510) //if (ki == entries-1) { cout << ChannelRangeMin << " " << ChannelRangeMax << endl; //first correction via TDeriMaxT90Rel hSpectrumTDeriMax1090_EnergyChannel->GetYaxis()->SetRangeUser(ChannelRangeMin,ChannelRangeMax); hSpectrumTDeriMax1090Rel_EnergyChannel->GetYaxis()->SetRangeUser(ChannelRangeMin,ChannelRangeMax); //TF1* FitFuncSlices = new TF1("FitFuncSlices","gaus(0)+pol0(3)",ChannelRangeMin,ChannelRangeMax); //FitFuncSlices->SetParameters(1000,ChannelPeakPos-10,4,10); //FitFuncSlices->SetParLimits(1,ChannelRangeMin,ChannelRangeMax); //FitFuncSlices->SetParLimits(2,0,10); //FitFuncSlices->SetParLimits(3,0,100); //gDirectory->ls(); TH1D *hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually=new TH1D("hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually","",hSpectrumTDeriMax1090Rel_EnergyChannel->GetNbinsX(),-0.3,1.3); //cout <<hSpectrumTDeriMax1090_EnergyChannel_MaxPos->GetEntries()<< endl; for(int binX = hSpectrumTDeriMax1090Rel_EnergyChannel->GetXaxis()->FindBin(-0.1);binX <= hSpectrumTDeriMax1090Rel_EnergyChannel->GetXaxis()->FindBin(0.90);binX++) { cout << "binx " << binX << endl; TH1D *hProfileY =hSpectrumTDeriMax1090Rel_EnergyChannel->ProjectionY("_py",binX,binX); double MaxValue=hProfileY->GetBinCenter(hProfileY->GetMaximumBin()); TF1* FitFuncSlices = new TF1("FitFuncSlices","gaus(0)+[3]",MaxValue-20,MaxValue+20); TF1* FitFuncGausSlices = new TF1("FitFuncGausSlices","gaus(0)",MaxValue-20,MaxValue+20); FitFuncGausSlices->SetParameters(hProfileY->GetBinContent(hProfileY->GetMaximumBin()),MaxValue,4); hProfileY->Fit(FitFuncGausSlices,"RNQ"); FitFuncSlices->SetParameters(FitFuncGausSlices->GetParameter(0),FitFuncGausSlices->GetParameter(1),FitFuncGausSlices->GetParameter(2),10); FitFuncSlices->SetParLimits(0,0,10000); FitFuncSlices->SetParLimits(1,MaxValue-10,MaxValue+10); FitFuncSlices->SetParLimits(2,0,10); FitFuncSlices->SetParLimits(3,0,100); hProfileY->Fit(FitFuncSlices,"RNQ"); cout <<MaxValue<<" " << FitFuncSlices->GetParameter(1) << " " << FitFuncSlices->GetParError(1) <<endl; hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->SetBinContent(binX, FitFuncSlices->GetParameter(1)); hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->SetBinError(binX, FitFuncSlices->GetParError(1)); } hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->GetYaxis()->SetRangeUser(ChannelPeakPos-100,ChannelPeakPos+50); hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->GetXaxis()->SetRangeUser(-0.05,0.9); TF1 * funcCorrConst = new TF1("funcCorrConst","pol0",-0.03,0.03); funcCorrConst->SetLineColor(kRed); TF1 * funcCorrPol = new TF1("funcCorrPol",PolPiecewise,-0.05,0.9,6); funcCorrPol->SetLineColor(kBlue); funcCorrPol->SetParameter(0,0.04); funcCorrPol->SetParameter(1,ChannelPeakPos); hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->Fit(funcCorrConst,"R"); hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->Fit(funcCorrPol,"R+"); TCanvas* can2=new TCanvas(); gPad->SetLogz(); hSpectrumTDeriMax1090Rel_EnergyChannel->Draw("colz"); funcCorrPol->DrawCopy("same"); for(int i = 7;i>0;i--) funcCorrPol->SetParameter(i,funcCorrPol->GetParameter(i)/funcCorrPol->GetParameter(1)); funcCorrPol->Print(); char buf[20]; sprintf(buf, "funcCorrNorm_%d",ki); funcCorrPol->Write(buf,TObject::kOverwrite); funcCorrConst->Delete(); funcCorrPol->Delete(); //second correction via T1090 (after first) hSpectrumT1090_EnergyChannelCorr1->GetYaxis()->SetRangeUser(ChannelRangeMin,ChannelRangeMax); //TF1* FitFuncSlices = new TF1("FitFuncSlices","gaus(0)+pol0(3)",ChannelRangeMin,ChannelRangeMax); //FitFuncSlices->SetParameters(1000,ChannelPeakPos-10,4,10); //FitFuncSlices->SetParLimits(1,ChannelRangeMin,ChannelRangeMax); //FitFuncSlices->SetParLimits(2,0,10); //FitFuncSlices->SetParLimits(3,0,100); //gDirectory->ls(); TH1D *hSpectrumT1090_EnergyChannelCorr1_MaxPosManually=new TH1D("hSpectrumT1090_EnergyChannelCorr1_MaxPosManually","",hSpectrumT1090_EnergyChannelCorr1->GetNbinsX(),0,1000); //cout <<hSpectrumTDeriMax1090_EnergyChannel_MaxPos->GetEntries()<< endl; for(int binX = hSpectrumT1090_EnergyChannelCorr1->GetXaxis()->FindBin(30);binX <= hSpectrumT1090_EnergyChannelCorr1->GetXaxis()->FindBin(500);binX++) { cout << "binx " << binX << endl; TH1D *hProfileY =hSpectrumT1090_EnergyChannelCorr1->ProjectionY("_py",binX,binX); //hProfileY->Draw(); //return 0; double MaxValue=hProfileY->GetBinCenter(hProfileY->GetMaximumBin()); FitFuncSlices = new TF1("FitFuncSlices","gaus(0)+[3]",MaxValue-20,MaxValue+20); FitFuncGausSlices = new TF1("FitFuncGausSlices","gaus(0)",MaxValue-20,MaxValue+20); FitFuncGausSlices->SetParameters(hProfileY->GetBinContent(hProfileY->GetMaximumBin()),MaxValue,4); hProfileY->Fit(FitFuncGausSlices,"RNQ"); FitFuncSlices->SetParameters(FitFuncGausSlices->GetParameter(0),FitFuncGausSlices->GetParameter(1),FitFuncGausSlices->GetParameter(2),10); FitFuncSlices->SetParLimits(0,0,10000); FitFuncSlices->SetParLimits(1,MaxValue-10,MaxValue+10); FitFuncSlices->SetParLimits(2,0,10); FitFuncSlices->SetParLimits(3,0,100); hProfileY->Fit(FitFuncSlices,"RNQ"); cout <<MaxValue<<" " << FitFuncSlices->GetParameter(1) << " " << FitFuncSlices->GetParError(1) <<endl; hSpectrumT1090_EnergyChannelCorr1_MaxPosManually->SetBinContent(binX, FitFuncSlices->GetParameter(1)); hSpectrumT1090_EnergyChannelCorr1_MaxPosManually->SetBinError(binX, FitFuncSlices->GetParError(1)); } hSpectrumT1090_EnergyChannelCorr1_MaxPosManually->GetYaxis()->SetRangeUser(ChannelPeakPos-100,ChannelPeakPos+50); hSpectrumT1090_EnergyChannelCorr1_MaxPosManually->GetXaxis()->SetRangeUser(30,500); new TCanvas(); hSpectrumT1090_EnergyChannelCorr1_MaxPosManually->Draw(); TF1 * funcCorrConst = new TF1("funcCorrConst","pol0",50,350); funcCorrConst->SetLineColor(kRed); TF1 * funcCorrPol = new TF1("funcCorrPol","pol6",50,300); funcCorrPol->SetLineColor(kBlue); funcCorrPol->SetParameter(0,0.04); funcCorrPol->SetParameter(1,ChannelPeakPos); hSpectrumT1090_EnergyChannelCorr1_MaxPosManually->Fit(funcCorrConst,"R"); hSpectrumT1090_EnergyChannelCorr1_MaxPosManually->Fit(funcCorrPol,"R+"); TCanvas* can2=new TCanvas(); gPad->SetLogz(); hSpectrumT1090_EnergyChannelCorr1->Draw("colz"); funcCorrPol->DrawCopy("same"); for(int i = 7;i>=0;i--) funcCorrPol->SetParameter(i,funcCorrPol->GetParameter(i)/funcCorrConst->GetParameter(0)); funcCorrPol->Print(); char buf[20]; sprintf(buf, "funcCorr2Norm_%d",ki); funcCorrPol->Write(buf,TObject::kOverwrite); funcCorrConst->Delete(); funcCorrPol->Delete(); //return 0; } } //can->ls(); gDirectory->Delete("ncCorrPol;1"); FitInput->ls(); //TCanvas* can3=new TCanvas(); //hSpectrumTDeriMax1090_EnergyChannel->ProfileX()->Draw(); //hSpectrumTDeriMax1090Rel_EnergyChannel->ProfileX()->Draw(); //hSpectrumTDeriMax1090Rel_EnergyChannel->Fit("pol3"); FitInput->Close(); }
void ll_matrix::matrix_calibration::run_calibration_old( TString basename ) { vector<double> masses; vector<double> cal; vector<double> cal_sigma; // vector<double> cal_sigma; vector<TH1F*> min_like; vector<TH1F*> sigma; vector<TH1F*> pull; int mass_index = 0; for( int idx = 0 ; idx < int( d_sample->samples.size() ) ; idx++ ) { if( d_sample->samples[idx].mass == 0 ) continue; double mass = d_sample->samples[idx].mass; ostringstream input_file_name; input_file_name << basename << "_ensemble_m" << mass << ".root"; TFile * input_file = TFile::Open( input_file_name.str().c_str() , input_file_name.str().c_str() , "read" ); ostringstream name , fit_name , fit_pull; name << "graph_name_" << mass; fit_name << "fit_name_" << mass; fit_pull << "fit_pull_" << mass; masses.push_back( mass ); min_like.push_back( new TH1F( name.str().c_str() , name.str().c_str() , 600 , 0 , 600 ) ); sigma.push_back( new TH1F( fit_name.str().c_str() , fit_name.str().c_str() , 200 , -100 , 100 ) ); pull.push_back( new TH1F( fit_pull.str().c_str() , fit_pull.str().c_str() , 100 , -5 , 5 ) ); for( int ens_no = 0 ; ens_no < NUMBER_OF_ENSEMBLES ; ens_no++ ) { input_file->cd(); ostringstream ens_name; ens_name << basename << "_ll_mass_" << mass << "_ens_" << ens_no; TGraphErrors * temp_graph = (TGraphErrors*) input_file->Get( ens_name.str().c_str() ); if( !temp_graph ) continue; double calib_parms[2] = { 0. , 1. }; // cout << " is this where things break ? " << endl; pair<double,double> mfit = fit_pol2( temp_graph , calib_parms , 1. ); if( mfit.first > 0. ) { min_like[mass_index]->Fill( mfit.first ); sigma[mass_index]->Fill( mfit.second ); pull[mass_index]->Fill( ( mfit.first - mass ) / mfit.second ); } } mass_index++; } ostringstream output_filename; output_filename << "calibration_" << basename << "_" << NUMBER_PER_ENSEMBLES << "_" << NUMBER_OF_ENSEMBLES << ".root"; cout << "done with loop " << endl; TFile * outputfile = new TFile( output_filename.str().c_str() , "recreate" ); outputfile->cd(); for( int idx = 0 ; idx < mass_index ; idx++ ) { min_like[idx]->Write(); sigma[idx]->Write(); pull[idx]->Write(); if( NUMBER_OF_ENSEMBLES > 1 ) { double temp_sigma = 0.; double temp_value = 0. , pull_temp_value = 0.; if( USE_MEAN_RMS ) { temp_value = min_like[idx]->GetMean(); temp_sigma = min_like[idx]->GetRMS(); pull_temp_value = ( temp_value - masses[idx] ) / min_like[idx]->GetRMS() ; } else { double max_val = min_like[idx]->GetBinCenter( min_like[idx]->GetMaximumBin() ); min_like[idx]->Fit( "gaus" , "Q" , "" , max_val - 50. , max_val + 50. ); TF1 * func_cal = min_like[idx]->GetFunction( "gaus" ); temp_value = func_cal->GetParameter( 1 ); temp_sigma = func_cal->GetParameter( 2 ); pull_temp_value = ( temp_value - masses[idx] ) / func_cal->GetParameter( 2 ); } cal.push_back( temp_value ); cal_sigma.push_back( temp_sigma ); } cout << d_sample->samples[idx].mass << " GeV & " << min_like[idx]->GetMean() << " GeV & " << min_like[idx]->GetRMS() << " GeV & " << pull[idx]->GetMean() << " & " << pull[idx]->GetRMS() << " \\ " << endl; } cout << " got here " << LOWEST_MASS << " " << HIGHEST_MASS << endl; TF1 * ideal = new TF1( "ideal" , pol1 , LOWEST_MASS - 175. - 5. , HIGHEST_MASS - 175. + 5. , 2 ); ideal->SetParameters( 0, 1 ); ideal->Write(); TGraphErrors calib( NUMBER_OF_TEMPLATES ); RenameGraph( calib , "calibration" ); TGraphErrors pull_mean( NUMBER_OF_TEMPLATES ); RenameGraph( pull_mean , "pull_mean" ); TGraphErrors pull_rms( NUMBER_OF_TEMPLATES ); RenameGraph( pull_rms , "pull_rms" ); TGraphErrors fit_mass_width( NUMBER_OF_TEMPLATES ); RenameGraph( fit_mass_width , "fit_mass_width" ); TGraphErrors survival_rate( NUMBER_OF_TEMPLATES ); RenameGraph( survival_rate , "survival_rate" ); double point_width = .5; for( int i = 0 ; i < NUMBER_OF_TEMPLATES ; i++ ) { double mass_diff = d_sample->samples[i].mass - 175 ; calib.SetPoint( i , mass_diff , ( cal[i] - 175 ) ); calib.SetPointError( i , point_width , cal_sigma[i] / TMath::Sqrt( NUMBER_OF_ENSEMBLES ) ); pull_mean.SetPoint( i , d_sample->samples[i].mass , pull[i]->GetMean() ); pull_mean.SetPointError( i , point_width , pull[i]->GetRMS() / TMath::Sqrt( NUMBER_OF_ENSEMBLES ) ); pull_rms.SetPoint( i , d_sample->samples[i].mass , pull[i]->GetRMS() ); pull_rms.SetPointError( i , point_width , pull[i]->GetRMS() / TMath::Sqrt( 2. * NUMBER_OF_ENSEMBLES ) ); fit_mass_width.SetPoint( i , d_sample->samples[i].mass , sigma[i]->GetMean() ); fit_mass_width.SetPointError( i , point_width , sigma[i]->GetRMS() / TMath::Sqrt( NUMBER_OF_ENSEMBLES ) ); survival_rate.SetPoint( i , d_sample->samples[i].mass , min_like[i]->GetEntries() / NUMBER_OF_ENSEMBLES ); } calib.Write(); pull_mean.Write(); pull_rms.Write(); fit_mass_width.Write(); survival_rate.Write(); outputfile->Close(); }
void AccTimesEff::Loop() { TStopwatch timer; timer.Start(); // parameters ///////////////////////////////////////////////////////////// vector<TString> files; files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-500_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9999ev.root"); files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-750_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_10000ev.root"); files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-1000_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9998ev.root"); files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-1250_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9998ev.root"); files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-1500_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9997ev.root"); files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-1750_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9997ev.root"); files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-2000_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9999ev.root"); files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-2500_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9999ev.root"); files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-3000_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_10000ev.root"); files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-3500_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9898ev.root"); files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-4000_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9998ev.root"); files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-5000_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9966ev.root"); string outfileName = "accTimesEffHistos"; // output file formats const bool saveSpec = 0; const bool saveAsPdf = 0; const bool saveAsPng = 1; const bool saveAsRoot = 0; TString plotDir = "./plots/"; int font = 42; //62 // selection cuts ///////////////////////////////////////////////////////// float elePtCut = 35.; float muPtCut = 35.; float minInvMass = 0.; TH1::SetDefaultSumw2(kTRUE); /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// TH1F *hGenEvts = new TH1F("hGenEvts", "hGenEvts", 145, 0., 5010.); hGenEvts->GetXaxis()->SetTitle("M_{Z'}^{truth}"); hGenEvts->GetXaxis()->SetTitleFont(font); hGenEvts->GetXaxis()->SetLabelFont(font); hGenEvts->GetYaxis()->SetTitle("Events"); hGenEvts->GetYaxis()->SetTitleFont(font); hGenEvts->GetYaxis()->SetLabelFont(font); hGenEvts->GetYaxis()->SetTitleOffset(1.2); hGenEvts->SetLineColor(kBlack); hGenEvts->SetLineWidth(2); hGenEvts->SetMarkerStyle(20); hGenEvts->SetMarkerColor(kBlack); TH1F *hGenEvtsEleInAcc = (TH1F*)hGenEvts->Clone("hGenEvtsEleInAcc"); TH1F *hGenEvtsEleInAccEB = (TH1F*)hGenEvts->Clone("hGenEvtsEleInAccEB"); TH1F *hGenEvtsEleInAccEE = (TH1F*)hGenEvts->Clone("hGenEvtsEleInAccEE"); TH1F *hGenEvtsMuInAcc = (TH1F*)hGenEvts->Clone("hGenEvtsMuInAcc"); TH1F *hGenEvtsInAcc = (TH1F*)hGenEvts->Clone("hGenEvtsInAcc"); TH1F *hTrgEvts = (TH1F*)hGenEvts->Clone("hTrgEvts"); hTrgEvts->SetTitle("hTrgEvts"); TH1F *hRecoEvts = (TH1F*)hGenEvts->Clone("hRecoEvts"); hRecoEvts->SetTitle("hRecoEvts"); TH1F *hRecoEvtsEB = (TH1F*)hRecoEvts->Clone("hRecoEvtsEB"); TH1F *hRecoEvtsEE = (TH1F*)hRecoEvts->Clone("hRecoEvtsEE"); TH1F *hRecoEleEvts = (TH1F*)hRecoEvts->Clone("hRecoEleEvts"); TH1F *hRecoEleEvtsEB = (TH1F*)hRecoEvts->Clone("hRecoEleEvtsEB"); TH1F *hRecoEleEvtsEE = (TH1F*)hRecoEvts->Clone("hRecoEleEvtsEE"); TH1F *hRecoMuEvts = (TH1F*)hRecoEvts->Clone("hRecoMuEvts"); TH1F *hRecoNoTrgEvts = (TH1F*)hGenEvts->Clone("hRecoNoTrgEvts"); hRecoNoTrgEvts->SetTitle("hRecoNoTrgEvts"); TH1F *hRecoNoTrgEvtsEB = (TH1F*)hRecoNoTrgEvts->Clone("hRecoNoTrgEvtsEB"); TH1F *hRecoNoTrgEvtsEE = (TH1F*)hRecoNoTrgEvts->Clone("hRecoNoTrgEvtsEE"); TH1F *hRecoNoTrgEleEvts = (TH1F*)hRecoNoTrgEvts->Clone("hRecoNoTrgEleEvts"); TH1F *hRecoNoTrgEleEvtsEB = (TH1F*)hRecoNoTrgEvts->Clone("hRecoNoTrgEleEvtsEB"); TH1F *hRecoNoTrgEleEvtsEE = (TH1F*)hRecoNoTrgEvts->Clone("hRecoNoTrgEleEvtsEE"); TH1F *hRecoNoTrgMuEvts = (TH1F*)hRecoNoTrgEvts->Clone("hRecoNoTrgMuEvts"); TH1F* hAcc; TH1F* hAccEle; TH1F* hAccEleEB; TH1F* hAccEleEE; TH1F* hAccMu; TH1F* hAccTimesTrgEff; TH1F* hTrgEff; TH1F* hAccTimesEff; TH1F* hAccTimesEffEB; TH1F* hAccTimesEffEE; TH1F* hAccTimesEffEle; TH1F* hAccTimesEffEleEB; TH1F* hAccTimesEffEleEE; TH1F* hAccTimesEffMu; TH1F* hAccTimesEffNoTrg; //TH1F* hAccTimesEffNoTrgEB; //TH1F* hAccTimesEffNoTrgEE; TH1F* hAccTimesEffNoTrgEle; TH1F* hAccTimesEffNoTrgEleEB; TH1F* hAccTimesEffNoTrgEleEE; TH1F* hAccTimesEffNoTrgMu; TH1F* hEffAftTrg; TH1F* hEffAftTrgEle; TH1F* hEffAftTrgEleEB; TH1F* hEffAftTrgEleEE; TH1F* hEffAftTrgMu; TH1F* hTrgRecoVsReco; //TH1F* hTrgRecoVsRecoEB; //TH1F* hTrgRecoVsRecoEE; TH1F* hTrgRecoVsRecoEle; TH1F* hTrgRecoVsRecoEleEB; TH1F* hTrgRecoVsRecoEleEE; TH1F* hTrgRecoVsRecoMu; // output file stringstream ssOutfile; ssOutfile << outfileName << ".root"; TFile *output = new TFile(ssOutfile.str().c_str(), "recreate"); /////////////////////////////////////////////////////////////////////////// //LOOP OVER FILES /////////////////////////////////////////////////////////////////////////// for (unsigned int p = 0; p < files.size(); ++p) { TFile* input = new TFile(files[p]); TTree *thetree = (TTree*)input->Get("gsfcheckerjob/tree"); Init(thetree); Long64_t nentries = fChain->GetEntriesFast(); cout << nentries << " events" << endl; unsigned int evCounter = 0; ///////////////////////////////////////////////////////////////////////////////////////////// //LOOP OVER EVENTS ///////////////////////////////////////////////////////////////////////////////////////////// //nentries = 10000; for (Long64_t jentry = 0; jentry < nentries; ++jentry) { Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; fChain->GetEntry(jentry); // if (Cut(ientry) < 0) continue; //if (jentry % 50000 == 0) cout << "Processing event " << jentry << endl; thetree->GetEntry(jentry); // fill the gen histograms hGenEvts->Fill(genelemom_mass[0]); // fill the acc histograms if (hardGenEle_pt[0] > elePtCut) { if (fabs(hardGenEle_eta[0]) < 1.442) { hGenEvtsEleInAcc->Fill(genelemom_mass[0]); hGenEvtsEleInAccEB->Fill(genelemom_mass[0]); } else if (fabs(hardGenEle_eta[0]) > 1.56 && fabs(hardGenEle_eta[0]) < 2.5) { hGenEvtsEleInAcc->Fill(genelemom_mass[0]); hGenEvtsEleInAccEE->Fill(genelemom_mass[0]); } } if (hardGenMu_pt[0] > muPtCut && fabs(hardGenMu_eta[0]) < 2.4) { hGenEvtsMuInAcc->Fill(genelemom_mass[0]); if (fabs(hardGenEle_eta[0]) < 1.442 || (fabs(hardGenEle_eta[0]) > 1.56 && fabs(hardGenEle_eta[0]) < 2.5)) { if (hardGenEle_pt[0] > elePtCut) hGenEvtsInAcc->Fill(genelemom_mass[0]); } } // trigger? if (HLT_Mu22_Photon22_CaloIdL) hTrgEvts->Fill(genelemom_mass[0]); // at least one gsf electron and one muon above the threshold if (gsf_size < 1 || muon_size < 1) continue; vector<int> GSF_passHEEP; vector<int> MU_passGOOD; ///////////////////////////////////////////////////////////////////////////////////////////// //loop over electrons for (int j = 0; j < gsf_size; ++j) { //cleaning: fake electrons from muons bool fakeEle = false; for (int k = 0; k < muon_size; ++k) { float DeltaR = deltaR(gsf_eta[j], gsf_phi[j], muon_eta[k], muon_phi[k]); if (DeltaR < 0.1) { fakeEle = true; break; } } if (fakeEle) continue; if (PassHEEP(j)) GSF_passHEEP.push_back(j); } //loop over muons for (int j = 0; j < muon_size; ++j) { if (PassHighPtMu(j)) MU_passGOOD.push_back(j); } if (GSF_passHEEP.size() == 1) { if (HLT_Mu22_Photon22_CaloIdL) { hRecoEleEvts->Fill(genelemom_mass[0]); if (fabs(gsfsc_eta[GSF_passHEEP[0]]) < 1.5) hRecoEleEvtsEB->Fill(genelemom_mass[0]); if (fabs(gsfsc_eta[GSF_passHEEP[0]]) > 1.5) hRecoEleEvtsEE->Fill(genelemom_mass[0]); } hRecoNoTrgEleEvts->Fill(genelemom_mass[0]); if (fabs(gsfsc_eta[GSF_passHEEP[0]]) < 1.5) hRecoNoTrgEleEvtsEB->Fill(genelemom_mass[0]); if (fabs(gsfsc_eta[GSF_passHEEP[0]]) > 1.5) hRecoNoTrgEleEvtsEE->Fill(genelemom_mass[0]); } if (MU_passGOOD.size() == 1) { if (HLT_Mu22_Photon22_CaloIdL) hRecoMuEvts->Fill(genelemom_mass[0]); hRecoNoTrgMuEvts->Fill(genelemom_mass[0]); } // veto when there are more than one good candidates if (GSF_passHEEP.size() != 1 || MU_passGOOD.size() != 1) continue; //HEEP ele + GOOD muon TLorentzVector ele1; TLorentzVector mu1; ele1.SetPtEtaPhiM(gsf_gsfet[GSF_passHEEP[0]], gsf_eta[GSF_passHEEP[0]], gsf_phi[GSF_passHEEP[0]], 0.000511); mu1.SetPtEtaPhiM(muon_pt[MU_passGOOD[0]], muon_eta[MU_passGOOD[0]], muon_phi[MU_passGOOD[0]], 0.10566); double invMass = (ele1 + mu1).M(); //MASS CUT if (invMass < minInvMass) continue; if (HLT_Mu22_Photon22_CaloIdL) { hRecoEvts->Fill(genelemom_mass[0]); if (fabs(gsfsc_eta[GSF_passHEEP[0]]) < 1.5) hRecoEvtsEB->Fill(genelemom_mass[0]); if (fabs(gsfsc_eta[GSF_passHEEP[0]]) > 1.5) hRecoEvtsEE->Fill(genelemom_mass[0]); } hRecoNoTrgEvts->Fill(genelemom_mass[0]); if (fabs(gsfsc_eta[GSF_passHEEP[0]]) < 1.5) hRecoNoTrgEvtsEB->Fill(genelemom_mass[0]); if (fabs(gsfsc_eta[GSF_passHEEP[0]]) > 1.5) hRecoNoTrgEvtsEE->Fill(genelemom_mass[0]); ++evCounter; /////////////////////////////////////////////////////////////////////// } //END LOOP OVER EVENTS ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// } //END LOOP OVER FILES ////////////////////////////////////////////////////////////////////////// hAcc = (TH1F*)hGenEvtsInAcc->Clone("hAcc"); hAccEle = (TH1F*)hGenEvtsEleInAcc->Clone("hAccEle"); hAccEleEB = (TH1F*)hGenEvtsEleInAccEB->Clone("hAccEleEB"); hAccEleEE = (TH1F*)hGenEvtsEleInAccEE->Clone("hAccEleEE"); hAccMu = (TH1F*)hGenEvtsMuInAcc->Clone("hAccMu"); hAccTimesTrgEff = (TH1F*)hTrgEvts->Clone("hAccTimesTrgEff"); hTrgEff = (TH1F*)hTrgEvts->Clone("hTrgEff"); hAccTimesEff = (TH1F*)hRecoEvts->Clone("hAccTimesEff"); hAccTimesEffEB = (TH1F*)hRecoEvtsEB->Clone("hAccTimesEffEB"); hAccTimesEffEE = (TH1F*)hRecoEvtsEE->Clone("hAccTimesEffEE"); hAccTimesEffEle = (TH1F*)hRecoEleEvts->Clone("hAccTimesEffEle"); hAccTimesEffEleEB = (TH1F*)hRecoEleEvtsEB->Clone("hAccTimesEffEleEB"); hAccTimesEffEleEE = (TH1F*)hRecoEleEvtsEE->Clone("hAccTimesEffEleEE"); hAccTimesEffMu = (TH1F*)hRecoMuEvts->Clone("hAccTimesEffMu"); hAccTimesEffNoTrg = (TH1F*)hRecoNoTrgEvts->Clone("hAccTimesEffNoTrg"); //hAccTimesEffNoTrgEB = (TH1F*)hRecoNoTrgEvtsEB->Clone("hAccTimesEffNoTrgEB"); //hAccTimesEffNoTrgEE = (TH1F*)hRecoNoTrgEvtsEE->Clone("hAccTimesEffNoTrgEE"); hAccTimesEffNoTrgEle = (TH1F*)hRecoNoTrgEleEvts->Clone("hAccTimesEffNoTrgEle"); hAccTimesEffNoTrgEleEB = (TH1F*)hRecoNoTrgEleEvtsEB->Clone("hAccTimesEffNoTrgEleEB"); hAccTimesEffNoTrgEleEE = (TH1F*)hRecoNoTrgEleEvtsEE->Clone("hAccTimesEffNoTrgEleEE"); hAccTimesEffNoTrgMu = (TH1F*)hRecoNoTrgMuEvts->Clone("hAccTimesEffNoTrgMu"); hEffAftTrg = (TH1F*)hRecoEvts->Clone("hAccTimesEff"); hEffAftTrgEle = (TH1F*)hRecoEleEvts->Clone("hAccTimesEffEle"); hEffAftTrgEleEB = (TH1F*)hRecoEleEvtsEB->Clone("hAccTimesEffEleEB"); hEffAftTrgEleEE = (TH1F*)hRecoEleEvtsEE->Clone("hAccTimesEffEleEE"); hEffAftTrgMu = (TH1F*)hRecoMuEvts->Clone("hAccTimesEffMu"); hTrgRecoVsReco = (TH1F*)hRecoEvts->Clone("hTrgRecoVsReco"); //hTrgRecoVsRecoEB = (TH1F*)hRecoEvtsEB->Clone("hTrgRecoVsRecoEB"); //hTrgRecoVsRecoEE = (TH1F*)hRecoEvtsEE->Clone("hTrgRecoVsRecoEE"); hTrgRecoVsRecoEle = (TH1F*)hRecoEleEvts->Clone("hTrgRecoVsRecoEle"); hTrgRecoVsRecoEleEB = (TH1F*)hRecoEleEvtsEB->Clone("hTrgRecoVsRecoEleEB"); hTrgRecoVsRecoEleEE = (TH1F*)hRecoEleEvtsEE->Clone("hTrgRecoVsRecoEleEE"); hTrgRecoVsRecoMu = (TH1F*)hRecoMuEvts->Clone("hTrgRecoVsRecoMu"); hAcc->Divide(hGenEvts); hAccEle->Divide(hGenEvts); hAccEleEB->Divide(hGenEvts); hAccEleEE->Divide(hGenEvts); hAccMu->Divide(hGenEvts); hAccTimesTrgEff->Divide(hGenEvts); hTrgEff->Divide(hGenEvtsInAcc); hAccTimesEff->Divide(hGenEvts); hAccTimesEffEB->Divide(hGenEvts); hAccTimesEffEE->Divide(hGenEvts); hAccTimesEffEle->Divide(hGenEvts); hAccTimesEffEleEB->Divide(hGenEvts); hAccTimesEffEleEE->Divide(hGenEvts); hAccTimesEffMu->Divide(hGenEvts); hAccTimesEffNoTrg->Divide(hGenEvts); //hAccTimesEffNoTrgEB->Divide(hGenEvts); //hAccTimesEffNoTrgEE->Divide(hGenEvts); hAccTimesEffNoTrgEle->Divide(hGenEvts); hAccTimesEffNoTrgEleEB->Divide(hGenEvts); hAccTimesEffNoTrgEleEE->Divide(hGenEvts); hAccTimesEffNoTrgMu->Divide(hGenEvts); hEffAftTrg->Divide(hTrgEvts); hEffAftTrgEle->Divide(hTrgEvts); hEffAftTrgEleEB->Divide(hTrgEvts); hEffAftTrgEleEE->Divide(hTrgEvts); hEffAftTrgMu->Divide(hTrgEvts); hTrgRecoVsReco->Divide(hRecoNoTrgEvts); //hTrgRecoVsRecoEB->Divide(hRecoNoTrgEvtsEB); //hTrgRecoVsRecoEE->Divide(hRecoNoTrgEvtsEE); hTrgRecoVsRecoEle->Divide(hRecoNoTrgEleEvts); hTrgRecoVsRecoEleEB->Divide(hRecoNoTrgEleEvtsEB); hTrgRecoVsRecoEleEE->Divide(hRecoNoTrgEleEvtsEE); hTrgRecoVsRecoMu->Divide(hRecoNoTrgMuEvts); // plot TCanvas *accTimesEffPlot = new TCanvas("accTimesEffPlot", "acc x eff", 100, 100, 600, 600); TPad *accTimesEffPad = new TPad("accTimesEffPad", "acc x eff pad", 0., 0., 1., 1.); accTimesEffPad->SetBottomMargin(0.12); accTimesEffPad->SetBorderMode(0); accTimesEffPad->SetBorderSize(2); accTimesEffPad->SetFrameBorderMode(0); accTimesEffPad->SetFillColor(0); accTimesEffPad->SetFrameFillColor(0); accTimesEffPad->SetLeftMargin(0.11); accTimesEffPad->SetRightMargin(0.09); accTimesEffPad->SetTopMargin(0.08); accTimesEffPad->SetTickx(1); accTimesEffPad->SetTicky(1); accTimesEffPad->Draw(); accTimesEffPad->cd(); gStyle->SetTitleFont(font); gStyle->SetLabelFont(font); gStyle->SetLegendFont(font); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetOptFit(1111); gStyle->SetTitleXOffset(1.); gStyle->SetTitleYOffset(1.3); gPad->SetTicks(1, 1); gPad->SetGrid(1, 1); TH1F* hAccTimesEff2 = (TH1F*)hAccTimesEff->Clone("hAccTimesEff2"); TF1 *fitFunc = new TF1("fitFunc", "[0] + [1]/ (x + [2]) + [3]*x", 10., 5010.); //TF1 *fitFuncEB = new TF1("fitFuncEB", "[0] + [1]/ (x + [2])", 10., 5010.); TF1 *fitFuncEB = new TF1("fitFuncEB", "[0] + [1]/ (x + [2]) + [3]*x", 10., 5010.); TF1 *fitFuncEE = new TF1("fitFuncEE", "[0] + [1]/ (x*x + [2])", 10., 5010.); fitFunc->SetLineColor(kBlue); fitFuncEB->SetLineColor(kBlue); fitFuncEE->SetLineColor(kBlue); hAccTimesEff->Fit("fitFunc", "", "", 480., 5010.); hAccTimesEffEB->Fit("fitFuncEB", "", "", 480., 5010.); hAccTimesEffEE->Fit("fitFuncEE", "", "", 480., 5010.); cout << "Chi^2 / NDF: " << fitFunc->GetChisquare() << " / " << fitFunc->GetNDF() << ", prob: " << fitFunc->GetProb() << endl; cout << "Chi^2 / NDF EB: " << fitFuncEB->GetChisquare() << " / " << fitFuncEB->GetNDF() << ", prob: " << fitFuncEB->GetProb() << endl; cout << "Chi^2 / NDF EE: " << fitFuncEE->GetChisquare() << " / " << fitFuncEE->GetNDF() << ", prob: " << fitFuncEE->GetProb() << endl; hAccTimesEff->GetYaxis()->SetTitle("acc x eff"); hAccTimesEff->GetYaxis()->SetRangeUser(0., 1.); hAccTimesEff->Draw(); TLatex *tex = new TLatex(0.22, 0.21, "P(M|p0,p1,p2,p3) = p0 + #frac{p1}{M+p2} + p3*M"); tex->SetNDC(); tex->SetTextFont(font); tex->SetLineWidth(2); tex->SetTextSize(0.03); tex->Draw(); tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV"); tex->DrawLatex(0.17, 0.85, "trg + electron + muon"); TCanvas *accTimesEffPlotEB = new TCanvas("accTimesEffPlotEB", "acc x eff, barrel electron + muon", 100, 100, 600, 600); TPad *accTimesEffPadEB = (TPad*)accTimesEffPad->Clone("accTimesEffPadEB"); accTimesEffPadEB->Draw(); accTimesEffPadEB->cd(); hAccTimesEffEB->GetYaxis()->SetTitle("acc x eff"); hAccTimesEffEB->GetYaxis()->SetRangeUser(0., 1.); hAccTimesEffEB->Draw(); tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV"); //tex->DrawLatex(0.46, 0.21, "P(M|p0,p1,p2) = p0 + #frac{p1}{M+p2}"); tex->DrawLatex(0.22, 0.21, "P(M|p0,p1,p2,p3) = p0 + #frac{p1}{M+p2} + p3*M"); tex->DrawLatex(0.17, 0.85, "trg + barrel electron + muon"); TCanvas *accTimesEffPlotEE = new TCanvas("accTimesEffPlotEE", "acc x eff, endcap electron + muon", 100, 100, 600, 600); TPad *accTimesEffPadEE = (TPad*)accTimesEffPad->Clone("accTimesEffPadEE"); accTimesEffPadEE->Draw(); accTimesEffPadEE->cd(); hAccTimesEffEE->GetYaxis()->SetTitle("acc x eff"); hAccTimesEffEE->GetYaxis()->SetRangeUser(0., 1.); hAccTimesEffEE->Draw(); tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV"); tex->DrawLatex(0.45, 0.38, "P(M|p0,p1,p2) = p0 + #frac{p1}{M^{2}+p2}"); tex->DrawLatex(0.17, 0.85, "trg + endcap electron + muon"); TCanvas *accTimesEffObjPlot = new TCanvas("accTimesEffObjPlot", "acc x eff, objects", 100, 100, 600, 600); TPad *accTimesEffObjPad = (TPad*)accTimesEffPad->Clone("accTimesEffObjPad"); accTimesEffObjPad->Draw(); accTimesEffObjPad->cd(); hAccTimesEffEle->GetYaxis()->SetTitle("acc x eff"); hAccTimesEffEle->GetYaxis()->SetRangeUser(0., 1.); hAccTimesEffEle->SetMarkerStyle(kFullSquare); hAccTimesEffEle->SetMarkerColor(kViolet); hAccTimesEffEle->SetLineColor(kViolet); hAccTimesEffEle->Draw(); hAccTimesEffEleEB->SetMarkerStyle(kFullTriangleUp); hAccTimesEffEleEB->SetMarkerColor(kRed); hAccTimesEffEleEB->SetLineColor(kRed); hAccTimesEffEleEB->Draw("same"); hAccTimesEffEleEE->SetMarkerStyle(kFullTriangleDown); hAccTimesEffEleEE->SetMarkerColor(kBlue); hAccTimesEffEleEE->SetLineColor(kBlue); hAccTimesEffEleEE->Draw("same"); hAccTimesEffMu->SetMarkerStyle(34); hAccTimesEffMu->SetMarkerColor(kGreen+1); hAccTimesEffMu->SetLineColor(kGreen+1); hAccTimesEffMu->Draw("same"); hAccTimesEff2->Draw("same"); TLegend* legend = new TLegend(0.592, 0.279, 0.881, 0.467); legend->SetTextFont(font); legend->SetTextSize(0.03); legend->SetBorderSize(0); legend->SetLineColor(1); legend->SetLineStyle(1); legend->SetLineWidth(1); legend->SetFillColor(19); legend->SetFillStyle(0); legend->AddEntry(hAccTimesEff, "total acc x eff"); legend->AddEntry(hAccTimesEffMu, "muons"); legend->AddEntry(hAccTimesEffEle, "all electrons"); legend->AddEntry(hAccTimesEffEleEB, "barrel electrons"); legend->AddEntry(hAccTimesEffEleEE, "endcap electrons"); legend->Draw("same"); tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV"); tex->DrawLatex(0.17, 0.85, "trg: HLT_Mu22_Photon22_CaloIdL"); // acc x eff with no trg applied TCanvas *accTimesEffNoTrgObjPlot = new TCanvas("accTimesEffNoTrgObjPlot", "acc x eff, no trigger, objects", 100, 100, 600, 600); TPad *accTimesEffNoTrgObjPad = (TPad*)accTimesEffPad->Clone("accTimesEffNoTrgObjPad"); accTimesEffNoTrgObjPad->Draw(); accTimesEffNoTrgObjPad->cd(); hAccTimesEffNoTrgEle->GetYaxis()->SetTitle("acc x eff"); hAccTimesEffNoTrgEle->GetYaxis()->SetRangeUser(0., 1.); hAccTimesEffNoTrgEle->SetMarkerStyle(kFullSquare); hAccTimesEffNoTrgEle->SetMarkerColor(kViolet); hAccTimesEffNoTrgEle->SetLineColor(kViolet); hAccTimesEffNoTrgEle->Draw(); hAccTimesEffNoTrgEleEB->SetMarkerStyle(kFullTriangleUp); hAccTimesEffNoTrgEleEB->SetMarkerColor(kRed); hAccTimesEffNoTrgEleEB->SetLineColor(kRed); hAccTimesEffNoTrgEleEB->Draw("same"); hAccTimesEffNoTrgEleEE->SetMarkerStyle(kFullTriangleDown); hAccTimesEffNoTrgEleEE->SetMarkerColor(kBlue); hAccTimesEffNoTrgEleEE->SetLineColor(kBlue); hAccTimesEffNoTrgEleEE->Draw("same"); hAccTimesEffNoTrgMu->SetMarkerStyle(34); hAccTimesEffNoTrgMu->SetMarkerColor(kGreen+1); hAccTimesEffNoTrgMu->SetLineColor(kGreen+1); hAccTimesEffNoTrgMu->Draw("same"); hAccTimesEffNoTrg->Draw("same"); TLegend* accXeffNoTrg = (TLegend*)legend->Clone("effAftTrgLegend"); accXeffNoTrg->Clear(); accXeffNoTrg->AddEntry(hAccTimesEffNoTrg, "total acc x eff"); accXeffNoTrg->AddEntry(hAccTimesEffNoTrgMu, "muons"); accXeffNoTrg->AddEntry(hAccTimesEffNoTrgEle, "all electrons"); accXeffNoTrg->AddEntry(hAccTimesEffNoTrgEleEB, "barrel electrons"); accXeffNoTrg->AddEntry(hAccTimesEffNoTrgEleEE, "endcap electrons"); accXeffNoTrg->Draw("same"); tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV"); tex->DrawLatex(0.17, 0.85, "trg: none"); // efficiency on triggered events TCanvas *effAftTrgPlot = new TCanvas("effAftTrgPlot", "efficiency after trigger", 100, 100, 600, 600); TPad *effAftTrgPad = (TPad*)accTimesEffPad->Clone("effAftTrgPad"); effAftTrgPad->Draw(); effAftTrgPad->cd(); hEffAftTrgEle->GetYaxis()->SetTitle("eff"); hEffAftTrgEle->GetYaxis()->SetRangeUser(0., 1.); hEffAftTrgEle->SetMarkerStyle(kFullSquare); hEffAftTrgEle->SetMarkerColor(kViolet); hEffAftTrgEle->SetLineColor(kViolet); hEffAftTrgEle->Draw(); hEffAftTrgEleEB->SetMarkerStyle(kFullTriangleUp); hEffAftTrgEleEB->SetMarkerColor(kRed); hEffAftTrgEleEB->SetLineColor(kRed); hEffAftTrgEleEB->Draw("same"); hEffAftTrgEleEE->SetMarkerStyle(kFullTriangleDown); hEffAftTrgEleEE->SetMarkerColor(kBlue); hEffAftTrgEleEE->SetLineColor(kBlue); hEffAftTrgEleEE->Draw("same"); hEffAftTrgMu->SetMarkerStyle(34); hEffAftTrgMu->SetMarkerColor(kGreen+1); hEffAftTrgMu->SetLineColor(kGreen+1); hEffAftTrgMu->Draw("same"); hEffAftTrg->Draw("same"); TLegend* effAftTrgLegend = (TLegend*)legend->Clone("effAftTrgLegend"); effAftTrgLegend->Clear(); effAftTrgLegend->AddEntry(hEffAftTrg, "total eff after trigger"); effAftTrgLegend->AddEntry(hEffAftTrgMu, "muons"); effAftTrgLegend->AddEntry(hEffAftTrgEle, "all electrons"); effAftTrgLegend->AddEntry(hEffAftTrgEleEB, "barrel electrons"); effAftTrgLegend->AddEntry(hEffAftTrgEleEE, "endcap electrons"); effAftTrgLegend->Draw("same"); tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV"); tex->DrawLatex(0.14, 0.15, "trg: HLT_Mu22_Photon22_CaloIdL"); // acceptance TCanvas *accPlot = new TCanvas("accPlot", "acc", 100, 100, 600, 600); TPad *accPad = (TPad*)accTimesEffPad->Clone("accPad"); accPad->Draw(); accPad->cd(); hAcc->GetYaxis()->SetTitle("acc"); hAcc->GetYaxis()->SetRangeUser(0., 1.); hAccEle->SetMarkerStyle(kFullSquare); hAccEle->SetMarkerColor(kViolet); hAccEle->SetLineColor(kViolet); hAccEle->Draw(); hAccEleEB->SetMarkerStyle(kFullTriangleUp); hAccEleEB->SetMarkerColor(kRed); hAccEleEB->SetLineColor(kRed); hAccEleEB->Draw("same"); hAccEleEE->SetMarkerStyle(kFullTriangleDown); hAccEleEE->SetMarkerColor(kBlue); hAccEleEE->SetLineColor(kBlue); hAccEleEE->Draw("same"); hAccMu->SetMarkerStyle(34); hAccMu->SetMarkerColor(kGreen+1); hAccMu->SetLineColor(kGreen+1); hAccMu->Draw("same"); hAcc->Draw("same"); TLegend* accLegend = (TLegend*)legend->Clone("accLegend"); accLegend->Clear(); accLegend->AddEntry(hAcc, "total acceptance"); accLegend->AddEntry(hAccMu, "muons"); accLegend->AddEntry(hAccEle, "all electrons"); accLegend->AddEntry(hAccEleEB, "barrel electrons"); accLegend->AddEntry(hAccEleEE, "endcap electrons"); accLegend->Draw("same"); tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV"); // reco with trg vs. reco TCanvas *trgRecoVsRecoPlot = new TCanvas("trgRecoVsRecoPlot", "reco with trg vs. reco", 100, 100, 600, 600); TPad *trgRecoVsRecoPad = (TPad*)accTimesEffPad->Clone("trgRecoVsRecoPad"); trgRecoVsRecoPad->Draw(); trgRecoVsRecoPad->cd(); hTrgRecoVsRecoEle->GetYaxis()->SetTitle("eff"); hTrgRecoVsRecoEle->GetYaxis()->SetRangeUser(0., 1.); hTrgRecoVsRecoEle->SetMarkerStyle(kFullSquare); hTrgRecoVsRecoEle->SetMarkerColor(kViolet); hTrgRecoVsRecoEle->SetLineColor(kViolet); hTrgRecoVsRecoEle->Draw(); //hTrgRecoVsRecoEleEB->SetMarkerStyle(kFullTriangleUp); //hTrgRecoVsRecoEleEB->SetMarkerColor(kRed); //hTrgRecoVsRecoEleEB->SetLineColor(kRed); //hTrgRecoVsRecoEleEB->Draw("same"); //hTrgRecoVsRecoEleEE->SetMarkerStyle(kFullTriangleDown); //hTrgRecoVsRecoEleEE->SetMarkerColor(kBlue); //hTrgRecoVsRecoEleEE->SetLineColor(kBlue); //hTrgRecoVsRecoEleEE->Draw("same"); hTrgRecoVsRecoMu->SetMarkerStyle(34); hTrgRecoVsRecoMu->SetMarkerColor(kGreen+1); hTrgRecoVsRecoMu->SetLineColor(kGreen+1); hTrgRecoVsRecoMu->Draw("same"); hTrgRecoVsReco->Draw("same"); TLegend* trgRecoVsRecoLegend = (TLegend*)legend->Clone("trgRecoVsRecoLegend"); trgRecoVsRecoLegend->Clear(); trgRecoVsRecoLegend->AddEntry(hTrgRecoVsReco, "total"); trgRecoVsRecoLegend->AddEntry(hTrgRecoVsRecoMu, "muons"); trgRecoVsRecoLegend->AddEntry(hTrgRecoVsRecoEle, "electrons"); //trgRecoVsRecoLegend->AddEntry(hTrgRecoVsRecoEleEB, "barrel electrons"); //trgRecoVsRecoLegend->AddEntry(hTrgRecoVsRecoEleEE, "endcap electrons"); trgRecoVsRecoLegend->Draw("same"); tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV"); TCanvas *accTimesTrgEffPlot = new TCanvas("accTimesTrgEffPlot", "acc x trigger eff", 100, 100, 600, 600); TPad *accTimesTrgEffPad = (TPad*)accTimesEffPad->Clone("accTimesTrgEffPad"); accTimesTrgEffPad->Draw(); accTimesTrgEffPad->cd(); hAccTimesTrgEff->GetYaxis()->SetTitle("acc x trg eff"); hAccTimesTrgEff->GetYaxis()->SetRangeUser(0., 1.); hAccTimesTrgEff->SetMarkerStyle(20); hAccTimesTrgEff->SetMarkerColor(kCyan); hAccTimesTrgEff->SetLineColor(kCyan); hAccTimesTrgEff->Draw(); hTrgEff->SetMarkerStyle(21); hTrgEff->SetMarkerColor(kMagenta); hTrgEff->SetLineColor(kMagenta); hTrgEff->Draw("same"); TLegend* trgLegend = (TLegend*)legend->Clone("trgLegend"); trgLegend->Clear(); trgLegend->AddEntry(hTrgEff, "trigger eff in acc"); trgLegend->AddEntry(hAccTimesTrgEff, "acc x trigger eff"); trgLegend->Draw("same"); tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV"); // safe in various file formats if (saveSpec) { if (saveAsPdf) { accTimesTrgEffPlot->Print(plotDir + accTimesTrgEffPlot->GetName() + ".pdf", "pdf"); accTimesEffPlot->Print(plotDir + accTimesEffPlot->GetName() + ".pdf", "pdf"); accTimesEffPlotEB->Print(plotDir + accTimesEffPlotEB->GetName() + ".pdf", "pdf"); accTimesEffPlotEE->Print(plotDir + accTimesEffPlotEE->GetName() + ".pdf", "pdf"); accTimesEffObjPlot->Print(plotDir + accTimesEffObjPlot->GetName() + ".pdf", "pdf"); accTimesEffNoTrgObjPlot->Print(plotDir + accTimesEffNoTrgObjPlot->GetName() + ".pdf", "pdf"); effAftTrgPlot->Print(plotDir + effAftTrgPlot->GetName() + ".pdf", "pdf"); trgRecoVsRecoPlot->Print(plotDir + trgRecoVsRecoPlot->GetName() + ".pdf", "pdf"); accPlot->Print(plotDir + accPlot->GetName() + ".pdf", "pdf"); } if (saveAsPng) { accTimesTrgEffPlot->Print(plotDir + accTimesTrgEffPlot->GetName() + ".png", "png"); accTimesEffPlot->Print(plotDir + accTimesEffPlot->GetName() + ".png", "png"); accTimesEffPlotEB->Print(plotDir + accTimesEffPlotEB->GetName() + ".png", "png"); accTimesEffPlotEE->Print(plotDir + accTimesEffPlotEE->GetName() + ".png", "png"); accTimesEffObjPlot->Print(plotDir + accTimesEffObjPlot->GetName() + ".png", "png"); accTimesEffNoTrgObjPlot->Print(plotDir + accTimesEffNoTrgObjPlot->GetName() + ".png", "png"); effAftTrgPlot->Print(plotDir + effAftTrgPlot->GetName() + ".png", "png"); trgRecoVsRecoPlot->Print(plotDir + trgRecoVsRecoPlot->GetName() + ".png", "png"); accPlot->Print(plotDir + accPlot->GetName() + ".png", "png"); } if (saveAsRoot) { accTimesTrgEffPlot->Print(plotDir + accTimesTrgEffPlot->GetName() + ".root", "root"); accTimesEffPlot->Print(plotDir + accTimesEffPlot->GetName() + ".root", "root"); accTimesEffPlotEB->Print(plotDir + accTimesEffPlotEB->GetName() + ".root", "root"); accTimesEffPlotEE->Print(plotDir + accTimesEffPlotEE->GetName() + ".root", "root"); accTimesEffObjPlot->Print(plotDir + accTimesEffObjPlot->GetName() + ".root", "root"); accTimesEffNoTrgObjPlot->Print(plotDir + accTimesEffNoTrgObjPlot->GetName() + ".root", "root"); effAftTrgPlot->Print(plotDir + effAftTrgPlot->GetName() + ".root", "root"); trgRecoVsRecoPlot->Print(plotDir + trgRecoVsRecoPlot->GetName() + ".root", "root"); accPlot->Print(plotDir + accPlot->GetName() + ".root", "root"); } } // write histos to file output->cd(); hGenEvts->Write(); hGenEvtsEleInAcc->Write(); hGenEvtsEleInAccEB->Write(); hGenEvtsEleInAccEE->Write(); hGenEvtsMuInAcc->Write(); hGenEvtsInAcc->Write(); hTrgEvts->Write(); hRecoEvts->Write(); hRecoEvtsEB->Write(); hRecoEvtsEE->Write(); hRecoEleEvts->Write(); hRecoEleEvtsEB->Write(); hRecoEleEvtsEE->Write(); hRecoMuEvts->Write(); hAccEle->Write(); hAccEleEB->Write(); hAccEleEE->Write(); hAccMu->Write(); hAccTimesTrgEff->Write(); hTrgEff->Write(); hAccTimesEff->Write(); hAccTimesEffEB->Write(); hAccTimesEffEE->Write(); hAccTimesEffEle->Write(); hAccTimesEffEleEB->Write(); hAccTimesEffEleEE->Write(); hAccTimesEffMu->Write(); hEffAftTrg->Write(); hEffAftTrgEle->Write(); hEffAftTrgEleEB->Write(); hEffAftTrgEleEE->Write(); hEffAftTrgMu->Write(); fitFunc->Write(); fitFuncEB->Write(); fitFuncEE->Write(); output->Close(); timer.Stop(); timer.Print(); }
void fit(int fitType, bool ispp) { if(fitType==1) { histname = "BmassBpPi"; } else if(fitType==2) { histname = "BmassBpK_tkmatch"; } else if(fitType==3) { histname = "BmassB0K_tkmatch"; } TFile* outf; if(ispp) outf = new TFile(Form("plotspp/%s.root", histname.Data()), "recreate"); else outf = new TFile(Form("plotsPbPb/%s.root", histname.Data()), "recreate"); gStyle->SetOptStat(0); TFile* inf; if(ispp) inf = new TFile(infilepp.Data()); else inf = new TFile(infilePbPb.Data()); TH1D* h = (TH1D*)inf->Get(histname.Data()); h->GetXaxis()->SetRangeUser(minhisto, maxhisto); TH1D* hempty = new TH1D("", "", 50, minhisto, maxhisto); TCanvas* c = new TCanvas("c", "", 600, 600); c->cd(); TF1* f = new TF1(Form("f"),"[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]) + [3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5]) + [9]+[10]*x "); f->SetParLimits(0, 1e-3, 1e3); f->SetParLimits(1, 4.9, 5.2); f->SetParLimits(2, 0.001, 0.1); f->SetParLimits(3, 1e-3, 1e3); f->SetParLimits(4, 4.9, 5.2); f->SetParLimits(5, 0.001, 0.1); f->SetParLimits(9, 0, 1e2); f->SetParLimits(10, -10, 10); f->SetParameter(0,1e2); f->SetParameter(1,5.11); f->SetParameter(2,0.05); f->SetParameter(3,1e2); f->SetParameter(4,4.98); f->SetParameter(5,0.05); f->SetParameter(9,1e3); f->SetParameter(10,0); if(fitType==1) { f->SetParLimits(0, 0, 1e4); f->SetParLimits(1, 5.2, 5.6); f->SetParLimits(2, 0.0001, 0.5); f->SetParameter(0,1e2); f->SetParameter(1,5.35); f->SetParameter(2,0.05); f->SetParLimits(3, 0, 1e4); f->SetParLimits(4, 5.2, 5.6); f->SetParLimits(5, 0.0001, 0.5); f->SetParameter(3,1e2); f->SetParameter(4,5.35); f->SetParameter(5,0.05); } //h->Fit(Form("f"),"q","",minhisto,maxhisto); //h->Fit(Form("f"),"q","",minhisto,maxhisto); //h->Fit(Form("f"),"L q","",minhisto,maxhisto); //h->Fit(Form("f"),"L m","",minhisto,maxhisto); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); hempty->SetMaximum(h->GetMaximum()*1.4); hempty->SetXTitle("m_{#mu#muK} (GeV/c^{2})"); hempty->SetYTitle("Entries / (5 MeV/c^{2})"); hempty->GetXaxis()->CenterTitle(); hempty->GetYaxis()->CenterTitle(); hempty->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); hempty->GetXaxis()->SetTitleOffset(1.3); hempty->GetYaxis()->SetTitleOffset(1.3); hempty->GetXaxis()->SetLabelOffset(0.007); hempty->GetYaxis()->SetLabelOffset(0.007); hempty->GetXaxis()->SetTitleSize(0.045); hempty->GetYaxis()->SetTitleSize(0.045); hempty->GetXaxis()->SetTitleFont(42); hempty->GetYaxis()->SetTitleFont(42); hempty->GetXaxis()->SetLabelFont(42); hempty->GetYaxis()->SetLabelFont(42); hempty->GetXaxis()->SetLabelSize(0.04); hempty->GetYaxis()->SetLabelSize(0.04); hempty->SetMarkerSize(0.01); hempty->SetMarkerStyle(20); hempty->Draw(); h->Draw("same e"); //f->Draw("same"); TLegend* leg = new TLegend(0.45,0.79,0.65,0.89,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); if(fitType==1) leg->AddEntry(h,"B^{+} to Jpsi Pi","p"); if(fitType==2) leg->AddEntry(h,"B^{+} to Jpsi and various K","p"); if(fitType==3) leg->AddEntry(h,"B^{0} to Jpsi and various K","p"); TLatex * tlatex; if(ispp) tlatex=new TLatex(0.48,0.89,"pp MC"); else tlatex=new TLatex(0.48,0.89,"PbPb MC"); tlatex->SetNDC(); tlatex->SetTextColor(1); tlatex->SetTextFont(42); tlatex->SetTextSize(0.04); tlatex->Draw(); //leg->AddEntry(f,"Fit","l"); leg->Draw("same"); outf->cd(); h->Write(); f->Write(); if(ispp) c->SaveAs(Form("plotspp/%s.png", histname.Data())); else c->SaveAs(Form("plotsPbPb/%s.png", histname.Data())); }
int main(int argc, char **argv) { // one or two input files assert(argc == 2 || argc == 3); // if not one or two input files -> abort std::auto_ptr<TFile> inFile(new TFile(argv[1])); assert(inFile.get()); TH2D *th2 = dynamic_cast<TH2D*>(inFile->Get("jets")); assert(th2); th2->Sumw2(); if (argc == 3) { std::auto_ptr<TFile> inFile2(new TFile(argv[2])); assert(inFile2.get()); TH2D *th2b = dynamic_cast<TH2D*>(inFile2->Get("jets")); assert(th2b); th2b->Sumw2(); th2->SetName("jets_ratio"); th2->Divide(th2b); // if there is a second input file, divide the histogram of the b jet pt/eta through the histogram of the non-b jet pt/eta } TFile g("out.root", "RECREATE"); //rootfile with control plots //create histogram that will contain the eta values of the jets for a certain ptbin (the real value of eta is transformed between -1 and 1 because the Chebychev polynominial is only defined on that range) TH1D *th1[th2->GetNbinsY()]; for(int i = 0; i < th2->GetNbinsY(); i++) { th1[i] = new TH1D(Form("ptslice%d", i), "slice",th2->GetNbinsX(), -1.0, +1.0); //number of bins related to number of etabins in histoJetEtaPt.C th1[i]->SetDirectory(0); } ///////////////// define the fitfunction for the eta distribution in a certain pt slice TF1 *cheb = new TF1("ChebS8", "[0] +" "[1] * (2 * (x^2) - 1) + " "[2] * (8 * (x^4) - 8 * (x^2) + 1) + " "[3] * (32 * (x^6) - 48 * (x^4) + 18 * (x^2) - 1) + " "[4] * (128 * (x^8) - 256 * (x^6) + 160 * (x^4) - 32 * (x^2) + 1) +" "[5] * (512 * (x^10) - 1280 * (x^8) + 1120 * (x^6) - 400 * (x^4) + 50 * (x^2) - 1) +" "[6] * (2048 * (x^12) - 6144 * (x^10) + 6912 * (x^8) - 3584 * (x^6) + 840 * (x^4) - 72 * (x^2) + 1)", -1.0, +1.0); cheb->SetParLimits(0, 0.0, 100000.0); ///////////////// fit the etadistributions for each ptslice and fill the distributions of the fitcoefficients for the different pt slices TH1D *coeffs[7]; for(int i = 0; i < 7; i++) { coeffs[i] = new TH1D(Form("coeff%d", i), "coeffs", th2->GetNbinsY()-2, 0.5, th2->GetNbinsY()-2 + 0.5); //for each coefficient create a histogram with the number of ptbins coeffs[i]->SetDirectory(0); } std::cout << "number of ptbins: " << th2->GetNbinsY() << std::endl; std::cout << "number of etabins: " << th2->GetNbinsX() << std::endl; for(int y = 1; y <= th2->GetNbinsY()-2; y++) { //loop over ptbins for(int x = 1; x <= th2->GetNbinsX(); x++) //loop over etabins { th1[y]->SetBinContent(x, th2->GetBinContent(x, y)); // weight! } th1[y]->SetDirectory(&g); th1[y]->Fit(cheb, "QRNB"); // fit the new histogram with the crazy fitfunction! th1[y]->Write(); cheb->SetName(Form("cheb%d", y)); cheb->Write(); for(int i = 0; i < 7; i++) { coeffs[i]->SetBinContent(y, cheb->GetParameter(i)); coeffs[i]->SetBinError(y, cheb->GetParError(i)); } } ///////////////// fit the coefficients as function of pt double params[7][6]; TF1 *pol[7]; for(int i = 0; i < 7; i++) { //the following piece of code is not relevant: expo, arg and f1 not used afterwards and coeffs[i] is refitted with pol5 /*coeffs[i]->Fit("expo", "Q0"); TF1 *f1 = coeffs[i]->GetFunction("expo"); double expo, arg; if (f1->GetParameter(0) >= -100000.0) { expo = std::exp(f1->GetParameter(0)); arg = f1->GetParameter(1); } else { coeffs[i]->Scale(-1.0); coeffs[i]->Fit("expo", "Q0"); f1 = coeffs[i]->GetFunction("expo"); expo = -std::exp(f1->GetParameter(0)); arg = f1->GetParameter(1); coeffs[i]->Scale(-1.0); }*/ coeffs[i]->Fit("pol5", "0B"); pol[i] = coeffs[i]->GetFunction("pol5"); pol[i]->SetName(Form("pol%d", i)); pol[i]->Write(); for(int j = 0; j < 6; j++) params[i][j] = pol[i]->GetParameter(j); } ///////////////// store the fit"function" in the histogram and calculate the chi2 double chi2 = 0.0; int ndf = 0; TH2D *th2c = new TH2D(*th2); th2c->SetName("fit"); for(int y = 1; y <= th2->GetNbinsY(); y++) { // ptbins int ry = y > th2->GetNbinsY()-4 ? th2->GetNbinsY()-4 : y; for(int x = 1; x <= th2->GetNbinsX(); x++) { // etabins //std::cout << "original histo, now in ptbin y: " << y << " (ry: " << ry <<") and etabin x: " << x << std::endl; //using the coefficients of the fitted functions, the value is calculated (this value will be close to the original value in case 1 rootfile is given and will the close to the original value of the divided histograms if 2 rootfiles are given) double val = compute(params, (x - 0.5) /(0.5*(float) th2->GetNbinsX()) - 1.0, ry); //std::cout << "val " << val << " for " << (x - 0.5) / 25.0 - 1.0 << " and for ry: " << ry << std::endl; if (val < 0) val = 0; double error = th2->GetBinError(x, y); if (error > 0 && val > 0) { double chi = th2->GetBinContent(x, y) - val; chi2 += chi * chi / val; ndf++; } th2c->SetBinContent(x, y, val); } } std::cout << "chi2/ndf(" << ndf << "): " << (chi2 / ndf) << std::endl; ///////////////// writing histos for(int i = 0; i < 7; i++) { coeffs[i]->SetDirectory(&g); coeffs[i]->Write(); } th2->SetDirectory(&g); th2->Write(); //write the original histogram (or the result of the two histograms divided by eachother) th2c->SetDirectory(&g); th2c->Write(); //write the histogram with the new weights g.Close(); ///////////////// writing relevant parameters for reweighting std::ofstream of("out.txt"); of << std::setprecision(16); for(int i = 0; i < 7; i++) for(int j = 0; j < 6; j++) of << params[i][j] << (j < 5 ? "\t" : "\n"); of.close(); return 0; }
void produceTF() { gROOT->SetBatch(); setTDRStyle(); TChain ch("trGEN"); ch.Add("runTEST_MERGED/ST_FCNC-TH_Tleptonic_HTobb_eta_hut-MadGraph5-pythia8/data.root"); ch.Add("runTEST_MERGED/ST_FCNC-TH_Tleptonic_HTobb_eta_hct-MadGraph5-pythia8/data.root"); float dMetPx, dMetPy; float dTopLepBJetPx, dTopLepBJetPy, dTopLepBJetPz, dTopLepBJetE; float dHiggsBJet1Px, dHiggsBJet1Py, dHiggsBJet1Pz, dHiggsBJet1E; float dHiggsBJet2Px, dHiggsBJet2Py, dHiggsBJet2Pz, dHiggsBJet2E; float dElecPx, dElecPy, dElecPz, dElecE; float dMuonPx, dMuonPy, dMuonPz, dMuonE; float TopLepWM, TopLepRecM, TopHadRecM, HiggsRecM; ch.SetBranchAddress("dMetPx",&dMetPx); ch.SetBranchAddress("dMetPy",&dMetPy); ch.SetBranchAddress("dTopLepBJetPx",&dTopLepBJetPx); ch.SetBranchAddress("dTopLepBJetPy",&dTopLepBJetPy); ch.SetBranchAddress("dTopLepBJetPz",&dTopLepBJetPz); ch.SetBranchAddress("dTopLepBJetE",&dTopLepBJetE); ch.SetBranchAddress("dHiggsBJet1Px",&dHiggsBJet1Px); ch.SetBranchAddress("dHiggsBJet1Py",&dHiggsBJet1Py); ch.SetBranchAddress("dHiggsBJet1Pz",&dHiggsBJet1Pz); ch.SetBranchAddress("dHiggsBJet1E",&dHiggsBJet1E); ch.SetBranchAddress("dHiggsBJet2Px",&dHiggsBJet2Px); ch.SetBranchAddress("dHiggsBJet2Py",&dHiggsBJet2Py); ch.SetBranchAddress("dHiggsBJet2Pz",&dHiggsBJet2Pz); ch.SetBranchAddress("dHiggsBJet2E",&dHiggsBJet2E); ch.SetBranchAddress("dElecPx",&dElecPx); ch.SetBranchAddress("dElecPy",&dElecPy); ch.SetBranchAddress("dElecPz",&dElecPz); ch.SetBranchAddress("dElecE",&dElecE); ch.SetBranchAddress("dMuonPx",&dMuonPx); ch.SetBranchAddress("dMuonPy",&dMuonPy); ch.SetBranchAddress("dMuonPz",&dMuonPz); ch.SetBranchAddress("dMuonE",&dMuonE); ch.SetBranchAddress("TopLepWM",&TopLepWM); ch.SetBranchAddress("TopLepRecM",&TopLepRecM); ch.SetBranchAddress("HiggsRecM",&HiggsRecM); int nHist = 0; TH1D *h[1000]; std::string hName[1000]; std::string hLab[1000]; TFile *fOut = new TFile("pdf.root","RECREATE"); h[nHist] = new TH1D("h_TopLepRecM","h_TopLepRecM",100,80.,260.); h[nHist]->Sumw2(); hName[nHist] = "TopLepRecM"; hLab[nHist] = "m(t) [GeV]"; nHist++; h[nHist] = new TH1D("h_TopLepWM","h_TopLepWM",100,60.,100.); h[nHist]->Sumw2(); hName[nHist] = "TopLepWM"; hLab[nHist] = "m(W) [GeV]"; nHist++; h[nHist] = new TH1D("h_HiggsRecM","h_HiggsRecM",100,20.,220.); h[nHist]->Sumw2(); hName[nHist] = "HiggsRecM"; hLab[nHist] = "m(H) [GeV]"; nHist++; h[nHist] = new TH1D("h_dMetPx","h_dMetPx",100,-140.,140.); h[nHist]->Sumw2(); hName[nHist] = "dMetPx"; hLab[nHist] = "MetPx_{gen} - MetPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMetPy","h_dMetPy",100,-140.,140.); h[nHist]->Sumw2(); hName[nHist] = "dMetPy"; hLab[nHist] = "MetPy_{gen} - MetPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetPx","h_dBJetPx",100,-60.,60.); h[nHist]->Sumw2(); hName[nHist] = "dBJetPx"; hLab[nHist] = "BJetPx_{gen} - BJetPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetPy","h_dBJetPy",100,-60.,60.); h[nHist]->Sumw2(); hName[nHist] = "dBJetPy"; hLab[nHist] = "BJetPy_{gen} - BJetPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetPz","h_dBJetPz",100,-80.,80.); h[nHist]->Sumw2(); hName[nHist] = "dBJetPz"; hLab[nHist] = "BJetPz_{gen} - BJetPz_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetE","h_dBJetE",100,-300.,120.); h[nHist]->Sumw2(); hName[nHist] = "dBJetE"; hLab[nHist] = "BJetE_{gen} - BJetE_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecPx","h_dElecPx",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dElecPx"; hLab[nHist] = "ElecPx_{gen} - ElecPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecPy","h_dElecPy",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dElecPy"; hLab[nHist] = "ElecPy_{gen} - ElecPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecPz","h_dElecPz",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dElecPz"; hLab[nHist] = "ElecPz_{gen} - ElecPz_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecE","h_dElecE",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dElecE"; hLab[nHist] = "ElecE_{gen} - ElecE_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonPx","h_dMuonPx",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dMuonPx"; hLab[nHist] = "MuonPx_{gen} - MuonPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonPy","h_dMuonPy",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dMuonPy"; hLab[nHist] = "MuonPy_{gen} - MuonPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonPz","h_dMuonPz",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dMuonPz"; hLab[nHist] = "MuonPz_{gen} - MuonPz_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonE","h_dMuonE",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dMuonE"; hLab[nHist] = "MuonE_{gen} - MuonE_{reco} [GeV]"; nHist++; int nev = ch.GetEntries(); TRandom3 *rnd = new TRandom3(); for(int i=0;i<nev;i++) { ch.GetEntry(i); for(int ih=0;ih<nHist;ih++) { if( hName[ih] == "TopLepRecM" ) h[ih]->Fill(TopLepRecM); else if( hName[ih] == "TopLepWM" ) h[ih]->Fill(TopLepWM); else if( hName[ih] == "HiggsRecM" ) h[ih]->Fill(HiggsRecM); else if( hName[ih] == "dMetPx" ) h[ih]->Fill(dMetPx); else if( hName[ih] == "dMetPy" ) h[ih]->Fill(dMetPy); else if( hName[ih] == "dBJetPx" ) {h[ih]->Fill(dHiggsBJet1Px);h[ih]->Fill(dHiggsBJet2Px);h[ih]->Fill(dTopLepBJetPx);} else if( hName[ih] == "dBJetPy" ) {h[ih]->Fill(dHiggsBJet1Py);h[ih]->Fill(dHiggsBJet2Py);h[ih]->Fill(dTopLepBJetPy);} else if( hName[ih] == "dBJetPz" ) {h[ih]->Fill(dHiggsBJet1Pz);h[ih]->Fill(dHiggsBJet2Pz);h[ih]->Fill(dTopLepBJetPz);} else if( hName[ih] == "dBJetE" ) {h[ih]->Fill(dHiggsBJet1E);h[ih]->Fill(dHiggsBJet2E);h[ih]->Fill(dTopLepBJetE);} else if( hName[ih] == "dElecPx" ) {h[ih]->Fill(dElecPx);} else if( hName[ih] == "dElecPy" ) {h[ih]->Fill(dElecPy);} else if( hName[ih] == "dElecPz" ) {h[ih]->Fill(dElecPz);} else if( hName[ih] == "dElecE" ) {h[ih]->Fill(dElecE);} else if( hName[ih] == "dMuonPx" ) {h[ih]->Fill(dMuonPx);} else if( hName[ih] == "dMuonPy" ) {h[ih]->Fill(dMuonPy);} else if( hName[ih] == "dMuonPz" ) {h[ih]->Fill(dMuonPz);} else if( hName[ih] == "dMuonE" ) {h[ih]->Fill(dMuonE);} } } delete rnd; // Plots TCanvas *c1 = new TCanvas(); c1->Draw(); c1->cd(); TPad *c1_1; gStyle->SetHistTopMargin(0); for(int i=0;i<nHist;i++) { // addbin(h[i]); h[i]->Scale(1./h[i]->Integral()); h[i]->Scale(1./h[i]->GetMaximum()); h[i]->SetLineWidth(2); h[i]->SetLineColor(kRed); h[i]->SetMarkerColor(kRed); h[i]->SetMarkerStyle(20); h[i]->Draw("hist e1"); h[i]->GetXaxis()->SetTitle(hLab[i].c_str()); // h[i]->GetYaxis()->SetTitle("Normalized to unity"); float max = h[i]->GetMaximum(); h[i]->SetMaximum(1.2*max); if( hName[i] == "TopLepWM" || hName[i] == "TopLepM" ) { std::string funcName = hName[i]+"_Fit"; TF1 *func = new TF1(funcName.c_str(),BW,h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins()),3); double mean = 80.4; if( hName[i] == "TopLepM" ) mean = 173.0; double sigma = 2.0; if( hName[i] == "TopLepM" ) sigma = 2.0; func->SetParameter(0,mean); func->SetParName(0,"mean"); func->SetParameter(1,sigma); func->SetParName(1,"sigma"); func->SetParameter(2,1.0); func->SetParName(2,"constant"); func->FixParameter(2,1.); h[i]->Fit(funcName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->Write(); std::string funcGausName = hName[i]+"_Gaus"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"gaus(0)",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); funcGaus->Write(); } if( hName[i] == "dMetPx" || hName[i] == "dMetPy" ) { double mean = 0.; double sigma = 50.; std::string funcGausName = hName[i]+"_Gaus"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); funcGaus->SetParameter(3,0.5); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "dBJetPx" || hName[i] == "dBJetPy" || hName[i] == "dBJetPz" || hName[i] == "dBJetE" ) { double mean = 0.; double sigma = 20.; std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[12]*(gaus(0)+gaus(3)+gaus(6)+gaus(9))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(12,1.0); funcGaus->SetParameter(0,1.0); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] == "dBJetPz" ) funcGaus->SetParameter(0,0.6); if( hName[i] == "dBJetE" ) funcGaus->SetParameter(0,0.6); funcGaus->SetParameter(3,0.3); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); if( hName[i] == "dBJetPz" ) funcGaus->SetParameter(3,0.15); if( hName[i] == "dBJetE" ) funcGaus->SetParameter(3,0.3); if( hName[i] == "dBJetE" ) funcGaus->SetParameter(5,sigma*4); if( hName[i] == "dBJetPy" ) funcGaus->SetParameter(3,0.2); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); if( hName[i] == "dBJetPz" ) funcGaus->SetParameter(8,sigma/3.); funcGaus->SetParameter(9,0.5); funcGaus->SetParameter(10,mean); funcGaus->SetParameter(11,sigma); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); if( hName[i] == "dBJetE" ) { c1->Update(); TPaveStats *st = (TPaveStats*)h[i]->FindObject("stats"); st->SetX1NDC(0.20); st->SetX2NDC(0.47); } fit->Draw("same"); fit->SetParameter(12,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "dElecPx" || hName[i] == "dElecPy" || hName[i] == "dElecPz" || hName[i] == "dElecE" ) { double mean = 0.; double sigma = 1.; std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3)+gaus(6))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] == "dElecPz" ) funcGaus->SetParameter(0,0.8); funcGaus->SetParameter(3,0.3); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); if( hName[i] == "dElecPz" ) funcGaus->SetParameter(3,0.15); if( hName[i] == "dElecE" ) funcGaus->SetParameter(3,0.1); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "dMuonPx" || hName[i] == "dMuonPy" || hName[i] == "dMuonPz" || hName[i] == "dMuonE" ) { double mean = 0.; double sigma = 1.; std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3)+gaus(6))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] == "dMuonPz" ) funcGaus->SetParameter(0,0.8); funcGaus->SetParameter(3,0.3); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); if( hName[i] == "dMuonPz" ) funcGaus->SetParameter(3,0.2); if( hName[i] == "dMuonE" ) funcGaus->SetParameter(3,0.1); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "HiggsRecM" || hName[i] == "TopLepRecM" ) { double mean = 125.; double sigma = 10.; if( hName[i] == "TopLepRecM" ) { mean = 170; sigma = 20; } std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3)+gaus(6))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] != "TopLepRecM" ) funcGaus->FixParameter(0,0.7); funcGaus->SetParameter(3,0.3); if( hName[i] == "TopLepRecM" ) funcGaus->SetParameter(3,0.7); if( hName[i] == "TopLepRecM" ) funcGaus->SetParameter(4,150); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } std::string figName = "pics/"+hName[i]+".eps"; c1->Print(figName.c_str()); c1->Clear(); } fOut->Write(); fOut->Close(); gApplication->Terminate(); }
void theoryBin(TDirectory *din, TDirectory *dth, TDirectory *dout) { float etamin, etamax; assert(sscanf(din->GetName(),"Eta_%f-%f",&etamin,&etamax)==2); sscanf(din->GetName(),"Eta_%f-%f",&etamin,&etamax); int ieta = int((0.5*(etamin+etamax))/0.5); int jeta = (_jp_algo=="AK7" ? min(4,ieta) : ieta); // inclusive jets TH1D *hpt = (TH1D*)din->Get("hpt"); assert(hpt); // theory curves // http://www-ekp.physik.uni-karlsruhe.de/~rabbertz/fastNLO_LHC/InclusiveJets/ // -> fnl2342_cteq66_aspdf_full.root // Numbering scheme explained in // https://twiki.cern.ch/twiki/bin/view/CMS/CMSfastNLO // 2-point to 6-point theory uncertainty: // h200X00->h300X09, h400X00->h300X08 TH1D *hnlo(0);//, *hpdfup(0), *hpdfdw(0), *hscup(0), *hscdw(0);//, *herr(0); cout << din->GetName() << " ieta="<<ieta<< " jeta="<<jeta << endl; TH1D *hmc = (TH1D*)dth->Get("hpt_g0tw"); assert(hmc); /* int S = (_jp_algo=="AK7" ? 1 : 3); TH1D *hnlo_cteq = (TH1D*)dnlo0->Get(Form("h%d00%d00",S,jeta+1)); assert(hnlo_cteq); hnlo_cteq->Scale(1000.); // CTEQ10 TH1D *hnlo_ct10 = (TH1D*)dnlo1->Get(Form("h300%d00",jeta+1)); TH1D *hpdfup_ct10 = (TH1D*)dnlo1->Get(Form("h300%d02",jeta+1)); TH1D *hpdfdw_ct10 = (TH1D*)dnlo1->Get(Form("h300%d01",jeta+1)); TH1D *hscup_ct10 = (TH1D*)dnlo1->Get(Form("h300%d09",jeta+1)); TH1D *hscdw_ct10 = (TH1D*)dnlo1->Get(Form("h300%d08",jeta+1)); assert(hnlo_ct10); assert(hpdfup_ct10); assert(hpdfdw_ct10); assert(hscup_ct10); assert(hscdw_ct10); hnlo_ct10->Scale(1000.); hpdfup_ct10->Scale(1./1.65); hpdfdw_ct10->Scale(1./1.65); // MSTW2008 TH1D *hnlo_mstw = (TH1D*)dnlo2->Get(Form("h%d00%d00",S,jeta+1)); assert(hnlo_mstw); hnlo_mstw->Scale(1000.); // NNPDF2010 TH1D *hnlo_nnpdf = (TH1D*)dnlo3->Get(Form("h%d00%d00",S,jeta+1)); assert(hnlo_nnpdf); hnlo_nnpdf->Scale(1000.); // HERA10 TH1D *hnlo_hera = (TH1D*)dnlo4->Get(Form("h%d00%d00",S,jeta+1)); TH1D *hpdfup_hera = (TH1D*)dnlo4->Get(Form("h%d00%d02",S,jeta+1)); TH1D *hpdfdw_hera = (TH1D*)dnlo4->Get(Form("h%d00%d01",S,jeta+1)); assert(hnlo_hera); assert(hpdfup_hera); assert(hpdfdw_hera); hnlo_hera->Scale(1000.); // alpha-S TH1D *hasup = (TH1D*)das->Get(Form("h300%d02",ieta+1)); TH1D *hasdw = (TH1D*)das->Get(Form("h300%d01",ieta+1)); assert(hasup); assert(hasdw); TH1D *hnp = (TH1D*)dnp->Get(Form("corr%d",min(int(etamin/0.5+0.5),5))); if (!hnp) cout << "eta: " << etamin << " " << etamax << endl; assert(hnp); */ // make sure new histograms get created in the output file dout->cd(); /* TH1D *hnpup(0), *hnpdw(0), *hsysup(0), *hsysdw(0); { // Move CTEQ6.6 hnlo_cteq = (TH1D*)hnlo_cteq->Clone("hnlo0_ct10k"); hnlo_ct10 = (TH1D*)hnlo_ct10->Clone("hnlo0_ct10"); hnlo_mstw = (TH1D*)hnlo_mstw->Clone("hnlo0_mstw"); hnlo_nnpdf = (TH1D*)hnlo_nnpdf->Clone("hnlo0_nnpdf"); hnlo_hera = (TH1D*)hnlo_hera->Clone("hnlo0_hera"); // Determine PDF4LHC from CT10, MSTW08, NNPDF10 hnlo = (TH1D*)hnlo_ct10->Clone("hnlo0"); // central PDF again later hpdfup = (TH1D*)hpdfup_ct10->Clone("hpdfup"); // central PDF hpdfdw = (TH1D*)hpdfdw_ct10->Clone("hpdfdw"); // central PDF for (int i = 1; i != hnlo->GetNbinsX()+1; ++i) { // Sanity checks assert(hpdfup_ct10->GetBinContent(i)>=0); assert(hpdfdw_ct10->GetBinContent(i)<=0); } hscup = (TH1D*)hscup_ct10->Clone("hscup"); // central PDF hscdw = (TH1D*)hscdw_ct10->Clone("hscdw"); // central PDF hasup = (TH1D*)hasup->Clone("hasup"); hasdw = (TH1D*)hasdw->Clone("hasdw"); hnp = (TH1D*)hnp->Clone("hnpcorr"); hnpup = (TH1D*)hnlo->Clone("hnpup"); hnpdw = (TH1D*)hnlo->Clone("hnpdw"); hsysup = (TH1D*)hnlo->Clone("hsysup"); hsysdw = (TH1D*)hnlo->Clone("hsysdw"); } */ /* // Patch up the hnp to adapt the wrong binning at low pT if (true) { // patch hnp TH1D *hnp_tmp = (TH1D*)hnlo->Clone("hnp_tmp"); for (int i = 1; i != hnlo->GetNbinsX()+1; ++i) { double x = hnlo->GetBinCenter(i); int j1 = hnp->FindBin(x); double x1 = hnp->GetBinCenter(j1); double y1 = hnp->GetBinContent(j1); double ey1 = hnp->GetBinError(j1); int j2 = (x>x1? j1+1 : j1-1); double x2 = hnp->GetBinCenter(j2); double y2 = hnp->GetBinContent(j2); double ey2 = hnp->GetBinError(j2); double y = y1 + (y2-y1) / (x2-x1) * (x-x1); double ey = ey1 + (ey2-ey1) / (x2-x1) * (x-x1); hnp_tmp->SetBinContent(i, y); hnp_tmp->SetBinError(i, ey); } // for i delete hnp; hnp = hnp_tmp; hnp->SetName("hnpcorr"); } // patch hnp */ /* // Turn NP uncertainty into uncertainty histogram for (int i = 1; i != hnlo->GetNbinsX()+1; ++i) { int j = hnp->FindBin(hnlo->GetBinCenter(i)); hnpup->SetBinContent(i, +hnp->GetBinError(j)/hnp->GetBinContent(j)); hnpup->SetBinError(i, 0.); hnpdw->SetBinContent(i, -hnp->GetBinError(j)/hnp->GetBinContent(j)); hnpdw->SetBinError(i, 0.); if (!(hnp->GetBinLowEdge(j)>=hnlo->GetBinLowEdge(i)) || !(hnp->GetBinLowEdge(j+1)<=hnlo->GetBinLowEdge(i+1))) { cout << Form("hnlo = [%1.0f,%1.0f]; hnp = [%1.0f,%1.0f]", hnlo->GetBinLowEdge(i), hnlo->GetBinLowEdge(i+1), hnp->GetBinLowEdge(j), hnp->GetBinLowEdge(j+1)) << endl; if (hnlo->GetBinLowEdge(i)>100 && hnlo->GetBinLowEdge(i)<2500.) { assert(hnp->GetBinLowEdge(j)>=hnlo->GetBinLowEdge(i)); assert(hnp->GetBinLowEdge(j+1)<=hnlo->GetBinLowEdge(i+1)); } } } // for i */ /* for (int i = 1; i != hnlo->GetNbinsX()+1; ++i) { double x = hnlo->GetBinCenter(i); int i1 = hnpup->FindBin(x); double y1a = hnpup->GetBinContent(i1); double y1b = hnpdw->GetBinContent(i1); int i2 = hscup->FindBin(x); double y2a = hscup->GetBinContent(i2); double y2b = hscdw->GetBinContent(i2); int i3 = hpdfup->FindBin(x); double y3a = hpdfup->GetBinContent(i3); double y3b = hpdfdw->GetBinContent(i3); int i4 = hasup->FindBin(x); double y4a = hasup->GetBinContent(i4); double y4b = hasdw->GetBinContent(i4); double errup = sqrt(pow(max3(y1a,y1b,0),2) + pow(max3(y2a,y2b,0),2) + pow(max3(y3a,y3b,0),2) + pow(max3(y4a,y4b,0),2)); double errdw = sqrt(pow(min3(y1a,y1b,0),2) + pow(min3(y2a,y2b,0),2) + pow(min3(y3a,y3b,0),2) + pow(min3(y4a,y4b,0),2)); hsysup->SetBinContent(i, errup); hsysup->SetBinError(i, 0.); hpdfup->SetBinError(i, 0.); hscup->SetBinError(i, 0.); hasup->SetBinError(i, 0); hsysdw->SetBinContent(i, -errdw); hsysdw->SetBinError(i, 0.); hpdfdw->SetBinError(i, 0.); hscdw->SetBinError(i, 0.); hasdw->SetBinError(i, 0); } // for i */ /* for (int i = 1; i != hnlo_ct10->GetNbinsX()+1; ++i) { double x = hnlo_ct10->GetBinCenter(i); int jnp = hnp->FindBin(x); double np = hnp->GetBinContent(jnp); int j = hnlo_ct10->FindBin(x); hnlo->SetBinContent(j, 1e-3*hnlo->GetBinContent(j)*np); int jc = hnlo_ct10->FindBin(x); hnlo_ct10->SetBinContent(jc, 1e-3*hnlo_ct10->GetBinContent(jc)*np); int jk = hnlo_cteq->FindBin(x); hnlo_cteq->SetBinContent(jk, 1e-3*hnlo_cteq->GetBinContent(jk)*np); int jm = hnlo_mstw->FindBin(x); hnlo_mstw->SetBinContent(jm, 1e-3*hnlo_mstw->GetBinContent(jm)*np); int jn = hnlo_nnpdf->FindBin(x); hnlo_nnpdf->SetBinContent(jn, 1e-3*hnlo_nnpdf->GetBinContent(jn)*np); int jh = hnlo_hera->FindBin(x); hnlo_hera->SetBinContent(jh, 1e-3*hnlo_hera->GetBinContent(jh)*np); // hnlo->SetBinError(j, 0.); hnlo_ct10->SetBinError(jc, 0.); hnlo_cteq->SetBinError(jk, 0.); hnlo_mstw->SetBinError(jm, 0.); hnlo_nnpdf->SetBinError(jn, 0.); hnlo_hera->SetBinError(jh, 0.); } */ // initial fit of the NLO curve TF1 *fnlo = new TF1("fnlo", "[0]*exp([1]/x)*pow(x,[2])" "*pow(1-x*cosh([4])/3500.,[3])", 10., 1000.); fnlo->SetParameters(2e14,-18,-5.2,8.9,0.5*ieta); fnlo->FixParameter(4,0.5*ieta); hnlo = hmc; hnlo->Fit(fnlo,"QRN"); // Graph of theory points with centered bins const double minerr = 0.02; TGraphErrors *gnlo = new TGraphErrors(0); TGraphErrors *gnlo2 = new TGraphErrors(0); // above + minerr TGraphErrors *gnlocut = new TGraphErrors(0); // only up to expected pT gnlo->SetName("gnlo"); gnlo2->SetName("gnlo2"); gnlocut->SetName("gnlocut"); for (int i = 1; i != hnlo->GetNbinsX()+1; ++i) { double y = hnlo->GetBinContent(i); double dy = hnlo->GetBinError(i); double ptmin = hnlo->GetBinLowEdge(i); double ptmax = hnlo->GetBinLowEdge(i+1); double y0 = fnlo->Integral(ptmin, ptmax) / (ptmax - ptmin); double x = fnlo->GetX(y0, ptmin, ptmax); int n = gnlo->GetN(); tools::SetPoint(gnlo, n, x, y, 0, dy); tools::SetPoint(gnlo2, n, x, y, 0, tools::oplus(dy, minerr*y)); if (y*(ptmax-ptmin) > 0.0001) { // for 10/fb int m = gnlocut->GetN(); tools::SetPoint(gnlocut, m, x, y, 0, 0); } } gnlo2->Fit(fnlo,"QRN"); // Divide graph with fit to check stability TGraphErrors *gnlofit = new TGraphErrors(0); gnlofit->SetName("gnlofit"); for (int i = 0; i != gnlo->GetN(); ++i) { double x, y, ex, ey; tools::GetPoint(gnlo, i, x, y, ex, ey); double f = fnlo->Eval(x); tools::SetPoint(gnlofit, i, x, y/f, ex, ey/f); } // Rebin theory to match data bins TH1D *hnlo0 = hnlo; hnlo0->SetName("hnlo0"); hnlo = tools::Rebin(hnlo0, hpt); hnlo->SetName("hnlo"); // Same for earlier 2010 and 2011 studies to get a matching theory set // (moved from PDF4LHC to CT10 since 2010) if (false) { // Match this to drawSummary.C inputs TDirectory *curdir = gDirectory; TFile *fin2010 = new TFile("../pfjet/output-DATA-4c.root","READ"); assert(fin2010 && !fin2010->IsZombie()); assert(fin2010->cd("Standard")); fin2010->cd("Standard"); assert(gDirectory->cd(din->GetName())); gDirectory->cd(din->GetName()); TDirectory *din2010 = gDirectory; TH1D *hpt2010 = (TH1D*)din2010->Get("hpt"); curdir->cd(); TH1D *hnlo2010 = tools::Rebin(hnlo0, hpt2010); hnlo2010->SetName("hnlo2010"); hnlo2010->Write(); } if (false) { // Match this to drawSummary.C inputs TDirectory *curdir = gDirectory; TFile *fin2011 = new TFile("backup/oct26/output-DATA-4c.root","READ"); assert(fin2011 && !fin2011->IsZombie()); assert(fin2011->cd("Standard")); fin2011->cd("Standard"); assert(gDirectory->cd(din->GetName())); gDirectory->cd(din->GetName()); TDirectory *din2011 = gDirectory; TH1D *hpt2011 = (TH1D*)din2011->Get("hpt"); curdir->cd(); TH1D *hnlo2011 = tools::Rebin(hnlo0, hpt2011); hnlo2011->SetName("hnlo2011"); hnlo2011->Write(); } /* { TH1D *hnlo0_cteq = hnlo_cteq; hnlo0_cteq->SetName("hnlo0_ct10k"); hnlo_cteq = tools::Rebin(hnlo0_cteq, hpt); hnlo_cteq->SetName("hnlo_ct10k"); // TH1D *hnlo0_ct10 = hnlo_ct10; hnlo0_ct10->SetName("hnlo0_ct10"); hnlo_ct10 = tools::Rebin(hnlo0_ct10, hpt); hnlo_ct10->SetName("hnlo_ct10"); // TH1D *hnlo0_mstw = hnlo_mstw; hnlo0_mstw->SetName("hnlo0_mstw"); hnlo_mstw = tools::Rebin(hnlo0_mstw, hpt); hnlo_mstw->SetName("hnlo_mstw"); // TH1D *hnlo0_nnpdf = hnlo_nnpdf; hnlo0_nnpdf->SetName("hnlo0_nnpdf"); hnlo_nnpdf = tools::Rebin(hnlo0_nnpdf, hpt); hnlo_nnpdf->SetName("hnlo_nnpdf"); // TH1D *hnlo0_hera = hnlo_hera; hnlo0_hera->SetName("hnlo0_hera"); hnlo_hera = tools::Rebin(hnlo0_hera, hpt); hnlo_hera->SetName("hnlo_hera"); } */ dout->cd(); gnlo->Write(); gnlocut->Write(); gnlofit->Write(); fnlo->Write(); din->cd(); } // theoryBin
void massfitvn_Jpsi() { double fit_range_low = 2.6; double fit_range_high = 3.5; double JPsi_mass = 3.097; int npt = 7; TFile* file1 = TFile::Open("HM185_JpsivnHist_etagap1p5_v30_eff_extdeta.root"); TFile ofile("v2vspt_fromfit_jpsi_HM185_250_deta1p5_doubleCB_v30_eff_exp_extdeta.root","RECREATE"); //v12 double alpha_fit[14] = {4.30986,3.50841,3.03436,2.73741,2.37934,2.10685,2.03615}; double n_fit[14] = {1.88853,1.9839,2.03198,2.07295,2.11001,2.15234,2.10154}; TF1* fmasssig[9]; TF1* fmassbkg[9]; TF1* fmasstotal[9]; TF1* fvn[9]; double pt[13]; double KET_ncq[13]; double v2[13]; double v2e[13]; double v2_bkg[13]; double v2_ncq[13]; double v2e_ncq[13]; double ptbin[14] = {0.2, 1.8, 3.0, 4.5, 6.0, 8.0, 10, 20}; double a[13]; double b[13]; double sigfrac[13]; TCanvas* c[10]; for(int i=0;i<npt;i++) { c[i] = new TCanvas(Form("c_%d",i),Form("c_%d",i),800,400); c[i]->Divide(2,1); } for(int i=0;i<npt;i++) { c[i]->cd(1)->SetTopMargin(0.06); c[i]->cd(1)->SetLeftMargin(0.18); c[i]->cd(1)->SetRightMargin(0.043); c[i]->cd(1)->SetBottomMargin(0.145); c[i]->cd(2)->SetTopMargin(0.06); c[i]->cd(2)->SetLeftMargin(0.18); c[i]->cd(2)->SetRightMargin(0.043); c[i]->cd(2)->SetBottomMargin(0.145); } TCanvas* c2 = new TCanvas("c2","c2",100,100); TLatex* tex = new TLatex; tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.045); tex->SetLineWidth(2); TLatex* texCMS = new TLatex; texCMS->SetNDC(); texCMS->SetTextFont(42); texCMS->SetTextSize(0.05); texCMS->SetTextAlign(12); TH1D* hist = new TH1D("hist","",10,2.6,3.5); hist->SetLineWidth(0); //hist->GetYaxis()->SetRangeUser(0,0.3); hist->GetXaxis()->SetTitle("#it{m}_{#mu#mu} (GeV)"); hist->GetYaxis()->SetTitle("v_{2}^{S+B}"); hist->GetXaxis()->CenterTitle(); hist->GetYaxis()->CenterTitle(); hist->GetXaxis()->SetTitleOffset(1.3); hist->GetYaxis()->SetTitleOffset(2); hist->GetXaxis()->SetLabelOffset(0.007); hist->GetYaxis()->SetLabelOffset(0.007); hist->GetXaxis()->SetTitleSize(0.045); hist->GetYaxis()->SetTitleSize(0.045); hist->GetXaxis()->SetTitleFont(42); hist->GetYaxis()->SetTitleFont(42); hist->GetXaxis()->SetLabelFont(42); hist->GetYaxis()->SetLabelFont(42); hist->GetXaxis()->SetLabelSize(0.04); hist->GetYaxis()->SetLabelSize(0.04); hist->SetMinimum(0.01); hist->SetMaximum(0.33); c2->cd(); hist->Draw(); for(int i=0;i<npt;i++) { TH1D* h_data = (TH1D*)file1->Get(Form("massjpsi_pt%d",i)); h_data->SetMinimum(0); h_data->SetMarkerSize(0.8); h_data->SetMarkerStyle(20); h_data->SetLineWidth(1); h_data->SetOption("e"); h_data->Rebin(2); h_data->GetXaxis()->SetRangeUser(2.6,3.5); h_data->GetXaxis()->SetTitle("#it{m}_{#mu#mu} (GeV)"); h_data->GetYaxis()->SetTitle("Entries / 10 MeV"); h_data->GetXaxis()->CenterTitle(); h_data->GetYaxis()->CenterTitle(); h_data->GetXaxis()->SetTitleOffset(1.3); h_data->GetYaxis()->SetTitleOffset(2); h_data->GetXaxis()->SetLabelOffset(0.007); h_data->GetYaxis()->SetLabelOffset(0.007); h_data->GetXaxis()->SetTitleSize(0.045); h_data->GetYaxis()->SetTitleSize(0.045); h_data->GetXaxis()->SetTitleFont(42); h_data->GetYaxis()->SetTitleFont(42); h_data->GetXaxis()->SetLabelFont(42); h_data->GetYaxis()->SetLabelFont(42); h_data->GetXaxis()->SetLabelSize(0.04); h_data->GetYaxis()->SetLabelSize(0.04); h_data->GetXaxis()->SetNoExponent(true); ((TGaxis*)h_data->GetXaxis())->SetMaxDigits(7); h_data->SetMaximum(h_data->GetMaximum()*1.5); TH1D* h_pt = (TH1D*)file1->Get(Form("Ptjpsi_eff_pt%d",i)); TH1D* h_KET = (TH1D*)file1->Get(Form("KETjpsi_eff_pt%d",i)); pt[i] = h_pt->GetMean(); KET_ncq[i] = h_KET->GetMean()/2.0; c[i]->cd(1); /*p definitions [0] CB1 yield; [1] Common mean of CB and Gaus; [2] CB1 sigma; [3] CB n; [4] CB alpha; [5] CB2 yield; [6] CB2 sigma; [7-10] poly 3; [11] v2 signal; [12-13] v2 bkg; */ TF1* f = new TF1(Form("f_%d",i), crystalball_function_total, fit_range_low, fit_range_high, 11); f->SetLineColor(2); f->SetLineWidth(1); f->SetParNames("CB1_Yield","common_mean","CB1_sigma","CB_N","CB_Alpha","CB2_Yield","CB2_Sigma","Pol0","Pol1","Pol2","Pol3"); //first fit data mass signal + bkg f->SetParameter(0,10000.); f->SetParameter(1,JPsi_mass); f->SetParameter(2,0.03); f->SetParameter(3,1.0); f->SetParameter(4,1.0); f->SetParameter(5,10000); f->SetParameter(6,0.03); f->SetParLimits(2,0.01,0.1); f->SetParLimits(6,0.01,0.1); //fix alpha & n from MC f->FixParameter(4,alpha_fit[i]); f->FixParameter(3,n_fit[i]); f->FixParameter(1,JPsi_mass); //for first few attempt fix mean of gaussian to get reasonable estimation of other pars; later open it up h_data->Fit(Form("f_%d",i),"q","",fit_range_low,fit_range_high); h_data->Fit(Form("f_%d",i),"q","",fit_range_low,fit_range_high); f->ReleaseParameter(1); //now let gaussian mean float h_data->Fit(Form("f_%d",i),"L q","",fit_range_low,fit_range_high); h_data->Fit(Form("f_%d",i),"L q","",fit_range_low,fit_range_high); h_data->Fit(Form("f_%d",i),"L m","",fit_range_low,fit_range_high); //draw D0 signal separately TF1* f1 = new TF1(Form("f_sig_%d",i), crystalball_function_signal, fit_range_low, fit_range_high, 7); f1->SetLineColor(kOrange-3); f1->SetLineWidth(1); f1->SetLineStyle(2); f1->SetFillColorAlpha(kOrange-3,0.3); f1->SetFillStyle(1001); f1->FixParameter(0,f->GetParameter(0)); f1->FixParameter(1,f->GetParameter(1)); f1->FixParameter(2,f->GetParameter(2)); f1->FixParameter(3,f->GetParameter(3)); f1->FixParameter(4,f->GetParameter(4)); f1->FixParameter(5,f->GetParameter(5)); f1->FixParameter(6,f->GetParameter(6)); fmasssig[i] = (TF1*)f1->Clone(); fmasssig[i]->SetName(Form("masssigfcn_pt%d",i)); fmasssig[i]->Write(); f1->Draw("LSAME"); //draw poly bkg separately TF1* f3 = new TF1(Form("f_bkg_%d",i),"[7] + [8]*x + [9]*x*x + [10]*x*x*x", fit_range_low, fit_range_high); f3->SetLineColor(4); f3->SetLineWidth(1); f3->SetLineStyle(2); f3->FixParameter(7,f->GetParameter(7)); f3->FixParameter(8,f->GetParameter(8)); f3->FixParameter(9,f->GetParameter(9)); f3->FixParameter(10,f->GetParameter(10)); fmassbkg[i] = (TF1*)f3->Clone(); fmassbkg[i]->SetName(Form("massbkgfcn_pt%d",i)); fmassbkg[i]->Write(); f3->Draw("LSAME"); tex->DrawLatex(0.22,0.86,"185 #leq N_{trk}^{offline} < 250"); tex->DrawLatex(0.22,0.80,Form("%.1f < p_{T} < %.1f GeV",ptbin[i],ptbin[i+1])); tex->DrawLatex(0.22,0.74,"-2.86 < y_{cm} < -1.86 or 0.94 < y_{cm} < 1.94"); texCMS->DrawLatex(.18,.97,"#font[61]{CMS} #it{Preliminary}"); //texCMS->DrawLatex(.18,.97,"#font[61]{CMS}"); texCMS->DrawLatex(0.73,0.97, "#scale[0.8]{pPb 8.16 TeV}"); TLegend* leg = new TLegend(0.21,0.4,0.5,0.65,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.045); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h_data,"data","p"); leg->AddEntry(f,"Fit","L"); leg->AddEntry(f1,"J/#psi Signal","f"); leg->AddEntry(f3,"Combinatorial","l"); leg->Draw("SAME"); sigfrac[i] = f1->Integral(2.94,3.24)/f->Integral(2.94,3.24); //c->Print(Form("plots/massfit_pt%d.pdf",i)); //fit vn //[9] is vn_sig //[10-11] is vn bkg, const + linear vn(pT) TGraphErrors* vn_data = (TGraphErrors*)file1->Get(Form("v2_mass_pt%d",i)); c[i]->cd(2); hist->Draw(); TF1* fmass_combinemassvnfit = new TF1(Form("fmass_combinemassvnfit_%d",i),crystalball_function_total, fit_range_low, fit_range_high, 11); TF1* fvn_combinemassvnfit = new TF1(Form("fvn_combinemassvnfit_%d",i), crystalball_function_v2, fit_range_low, fit_range_high, 15); fmass_combinemassvnfit->SetLineColor(2); fmass_combinemassvnfit->SetLineWidth(1); fvn_combinemassvnfit->SetLineColor(2); fvn_combinemassvnfit->SetLineWidth(1); ROOT::Math::WrappedMultiTF1 wfmass_combinemassvnfit(*fmass_combinemassvnfit,1); ROOT::Math::WrappedMultiTF1 wfvn_combinemassvnfit(*fvn_combinemassvnfit,1); ROOT::Fit::DataOptions opt; ROOT::Fit::DataRange range_massfit; range_massfit.SetRange(fit_range_low,fit_range_high); ROOT::Fit::BinData datamass(opt,range_massfit); ROOT::Fit::FillData(datamass, h_data); ROOT::Fit::DataRange range_vnfit; range_vnfit.SetRange(fit_range_low,fit_range_high); ROOT::Fit::BinData datavn(opt,range_vnfit); ROOT::Fit::FillData(datavn, vn_data); ROOT::Fit::Chi2Function chi2_B(datamass, wfmass_combinemassvnfit); ROOT::Fit::Chi2Function chi2_SB(datavn, wfvn_combinemassvnfit); GlobalChi2_poly3bkg_floatwidth globalChi2(chi2_B, chi2_SB); ROOT::Fit::Fitter fitter; const int Npar = 15; double par0[Npar]; for( int ipar = 0; ipar < f->GetNpar(); ipar++ ) par0[ipar] = f->GetParameter(ipar); par0[11] = 0.01; par0[12] = 0.10; par0[13] = 0.05; par0[14] = 0.01; fitter.Config().SetParamsSettings(Npar,par0); // fix parameter fitter.Config().ParSettings(0).Fix(); fitter.Config().ParSettings(1).Fix(); fitter.Config().ParSettings(2).Fix(); fitter.Config().ParSettings(3).Fix(); fitter.Config().ParSettings(4).Fix(); fitter.Config().ParSettings(5).Fix(); fitter.Config().ParSettings(6).Fix(); fitter.Config().ParSettings(7).Fix(); fitter.Config().ParSettings(8).Fix(); fitter.Config().ParSettings(9).Fix(); fitter.Config().ParSettings(10).Fix(); fitter.Config().MinimizerOptions().SetPrintLevel(0); fitter.Config().SetMinimizer("Minuit2","Migrad"); fitter.FitFCN(Npar,globalChi2,0,datamass.Size()+datavn.Size(),true); ROOT::Fit::FitResult result = fitter.Result(); result.Print(std::cout); fmass_combinemassvnfit->SetFitResult( result, iparmassfit_poly3bkg_floatwidth); fmass_combinemassvnfit->SetRange(range_massfit().first, range_massfit().second); fmass_combinemassvnfit->SetLineColor(kRed); h_data->GetListOfFunctions()->Add(fmass_combinemassvnfit); //c->cd(); //h_data->Draw(); fvn_combinemassvnfit->SetFitResult( result, iparvnfit_poly3bkg_floatwidth); fvn_combinemassvnfit->SetRange(range_vnfit().first, range_vnfit().second); fvn_combinemassvnfit->SetLineColor(2); //fvn_combinemassvnfit->SetLineStyle(2); vn_data->GetListOfFunctions()->Add(fvn_combinemassvnfit); vn_data->SetTitle(""); vn_data->SetMarkerSize(0.8); vn_data->SetLineWidth(1); //c1->cd(); vn_data->Draw("PESAME"); fvn[i] = (TF1*)fvn_combinemassvnfit->Clone(); fvn[i]->SetName(Form("vnfit_pt%d",i)); fvn[i]->Write(); fmasstotal[i] = (TF1*)fmass_combinemassvnfit->Clone(); fmasstotal[i]->SetName(Form("masstotalfcn_pt%d",i)); fmasstotal[i]->Write(); tex->DrawLatex(0.22,0.86,"185 #leq N_{trk}^{offline} < 250"); tex->DrawLatex(0.22,0.80,Form("%.1f < p_{T} < %.1f GeV",ptbin[i],ptbin[i+1])); //tex->DrawLatex(0.22,0.74,"1.4 < |y_{cm}+0.46| < 2.4"); tex->DrawLatex(0.22,0.74,"-2.86 < y_{cm} < -1.86 or 0.94 < y_{cm} < 1.94"); //tex->DrawLatex(0.22,0.68,"|#Delta#eta| > 2"); //texCMS->DrawLatex(.18,.97,"#font[61]{CMS}"); texCMS->DrawLatex(.18,.97,"#font[61]{CMS} #it{Preliminary}"); texCMS->DrawLatex(0.73,0.97, "#scale[0.8]{pPb 8.16 TeV}"); v2[i] = fvn_combinemassvnfit->GetParameter(11); v2e[i] = fvn_combinemassvnfit->GetParError(11); v2_bkg[i] = fvn_combinemassvnfit->GetParameter(12) + fvn_combinemassvnfit->GetParameter(13) * JPsi_mass; v2_ncq[i] = v2[i]/2.0; v2e_ncq[i] = v2e[i]/2.0; a[i] = fvn_combinemassvnfit->GetParameter(12); b[i] = fvn_combinemassvnfit->GetParameter(13); TF1* fvnbkg = new TF1(Form("fvnbkg_%d",1),"( [0] + [1] * x)", fit_range_low, fit_range_high); fvnbkg->FixParameter(0,fvn_combinemassvnfit->GetParameter(12)); fvnbkg->FixParameter(1,fvn_combinemassvnfit->GetParameter(13)); fvnbkg->SetName(Form("fvnbkg_fcn_pt%d",i)); fvnbkg->Write(); fvnbkg->SetLineStyle(7); //fvnbkg->Draw("LSAME"); TF1* fvnsig = new TF1(Form("fvnsig_%d",i),function_v2_sig,fit_range_low,fit_range_high,12); for(int k=0;k<12;k++) { fvnsig->FixParameter(k,fvn_combinemassvnfit->GetParameter(k)); } fvnsig->SetLineColor(kOrange-3); fvnsig->SetLineWidth(1); fvnsig->SetLineStyle(2); fvnsig->SetFillColorAlpha(kOrange-3,0.3); fvnsig->SetFillStyle(1001); //fvnsig->Draw("LSAME"); TLegend* leg1 = new TLegend(0.72,0.525,0.91,0.65,NULL,"brNDC"); leg1->SetBorderSize(0); leg1->SetTextSize(0.045); leg1->SetTextFont(42); leg1->SetFillStyle(0); leg1->AddEntry(h_data,"data","p"); leg1->AddEntry(fvn_combinemassvnfit,"Fit","l"); //leg1->AddEntry(fvnsig,"#alpha(#it{m}_{#mu#mu})v_{2}^{S}","f"); leg1->Draw("SAME"); double xmass[200]; double pullmass[200]; float Chi2=0; int ndf = (fit_range_high - fit_range_low)/0.01 - 8; for(int k=0;k<h_data->GetNbinsX();k++) { xmass[k] = h_data->GetBinCenter(k); pullmass[k] = (h_data->GetBinContent(k) - fmass_combinemassvnfit->Eval(xmass[k]))/h_data->GetBinError(k); if(fabs(pullmass[k])<5) { //cout<<pullmass[k]<<endl; Chi2 += pullmass[k]*pullmass[k]; } } c[i]->cd(1); tex->DrawLatex(0.22,0.67,Form("#chi^{2}/ndf = %.0f/%d",Chi2,ndf)); double xv2[200]; double pullv2[200]; double v2y[200]; float Chi2v2=0; int ndfv2 = 8 - 4; //Nbin - Npar for(int k=0;k<vn_data->GetN()-1;k++) { vn_data->GetPoint(k,xv2[k],v2y[k]); //xv2[k] = vn_dara->GetBinCenter(k); pullv2[k] = (v2y[k] - fvn_combinemassvnfit->Eval(xv2[k]))/vn_data->GetErrorY(k); cout<<k<<": "<<pullv2[k]<<endl; if(fabs(pullv2[k])<1000) { //cout<<pullmass[k]<<endl; Chi2v2 += pullv2[k]*pullv2[k]; } cout<<"fcn: "<<fvn_combinemassvnfit->Eval(xv2[k])<<endl; cout<<"data: "<<v2y[k]<<endl; } c[i]->cd(2); tex->DrawLatex(0.22,0.67,Form("#chi^{2}/ndf = %.1f/%d",Chi2v2,ndfv2)); } for(int i=0;i<npt;i++) { c[i]->Print(Form("plots/v30/eff/exp/JPsi_mass_vnfit_combine_pt%d.pdf",i)); c[i]->Print(Form("plots/v30/eff/exp/JPsi_mass_vnfit_combine_pt%d.gif",i)); } TGraphErrors* v2plot = new TGraphErrors(npt,pt,v2,0,v2e); TGraphErrors* v2ncqplot = new TGraphErrors(npt,KET_ncq,v2_ncq,0,v2e_ncq); TGraphErrors* v2bkgplot = new TGraphErrors(npt,pt,v2_bkg,0,0); v2plot->SetName("v2vspt"); v2ncqplot->SetName("v2vsKET_ncq"); v2bkgplot->SetName("v2bkgvspt"); v2plot->Write(); v2ncqplot->Write(); v2bkgplot->Write(); }
void SiCalibrator::MatchPeaks() { Load(); char tmpname[255]; sprintf(tmpname,"/SumCalData_th%dd%ds%dt%d.root",thresh,decay,shaping,top); std::string fname = tmpname; std::string filename = mypath; filename.append(fname); TFile *myfile = new TFile(filename.c_str(),"RECREATE"); int nbins; for (int src=0; src < CalData.size(); src++) { if (CalData[src].hSource != 0) { CalData[src].hSource->SetDirectory(myfile); CalData[src].hSource->Write(); for (int ch=0; ch<CalData[src].sourcedata.size(); ch++) { TH1D* hbi = CalData[src].hSource->ProjectionY("hb",ch+1,ch+1); nbins = hbi->GetNbinsX(); CalData[src].sourcedata[ch].fpol1 = 0; if (hbi->Integral(1,nbins) > 0) { sprintf(tmpname,"fs%dch%d",src,ch); TF1* f = new TF1(tmpname,fitf,0,16000,4); CalData[src].sourcedata[ch].fpol1 = f; // Build spectrum fit function f->FixParameter(0,src); f->FixParameter(1,0); //f->SetParLimits(1,-30,30); f->SetParameter(2,0.2); f->SetParameter(3,1); f->SetNpx(1000); double scale = hbi->GetMaximum()/f->GetMaximum(); f->FixParameter(3,scale); f->SetParameter(2,minimize(f,hbi,2,0.1,0.3)); //f->ReleaseParameter(2); //f->ReleaseParameter(1); //hbi->Draw(); //hbi->Fit(f,"LL","",thresh+50,16000); //cout << f->GetChisquare()/f->GetNDF() << endl; //f->FixParameter(1,f->GetParameter(1)); //f->FixParameter(2,f->GetParameter(2)); //f->SetParameter(3,minimize(f,hbi,3,scale*0.1,scale*5)); //f->ReleaseParameter(3); //f->SetParLimits(3,scale*0.1,scale*5); /* double slope = f->GetParameter(2); if (slope < 0.2 || slope > 0.25) { cout << "src " << src; cout << " ch " << ch; cout << " cnts " << hbi->Integral(1,nbins); cout << " pol1" << slope << endl; //hbi->Draw(); //return; } */ //hbi->Fit(f,"LL","",thresh+50,16000); //cout << f->GetChisquare()/f->GetNDF() << endl; //hbi->Fit(f,"","",150,16000); //f->Draw("same"); /* if (src == 1 && ch==13) { hbi->Draw(); f->Draw("same"); return; } */ f->Write(); } } } } for (int src=0; src < CalData.size(); src++) { if (CalData[src].hSource != 0) { sprintf(tmpname,"hp1_%d",src); CalData[src].hp1 = new TH1D(tmpname,tmpname,CalData[src].sourcedata.size(),0,CalData[src].sourcedata.size()); for (int ch=0; ch<CalData[src].sourcedata.size(); ch++) { if (CalData[src].sourcedata[ch].fpol1 != 0) { TF1* f = CalData[src].sourcedata[ch].fpol1; CalData[src].hp1->SetBinContent(ch+1,f->GetParameter(2)); } } CalData[src].hp1->Write(); /* TCanvas* c = new TCanvas(); c->Divide(1,2); c->cd(1); CalData[src].hSource->Draw("COLZ"); c->cd(2); CalData[src].hp1->Draw(); */ } } myfile->Close(); delete myfile; }