void plotYield(int ele=1) { if (ele==1) { TString fname="cs_DYee_13TeV_El3.root"; TH1D *h1Yield=loadHisto(fname,"h1Yield","h1Yield",h1dummy); TH1D *h1Signal=loadHisto(fname,"h1Signal","h1Signal",h1dummy); hsBlue.SetStyle(h1Yield); h1Yield->SetMarkerStyle(5); hsGreen.SetStyle(h1Signal); h1Yield->GetYaxis()->SetRangeUser(1e-2,1e6); h1Yield->GetYaxis()->SetTitleOffset(1.5); logAxis(h1Yield,1,niceMassAxisLabel(0,"",0),"count",""); plotHisto(h1Yield,"cYield_EE",1,1,"LPE","yield"); plotHistoSame(h1Signal,"cYield_EE","LPE1","signal"); //printHisto(h1Yield); //printHisto(h1Signal); } else if ((ele==0) || (ele==-1)) { TString tag=(ele==0) ? "csA" : "csB"; TString fname="cs_DYmm_13TeVMuApproved_" + tag + ".root"; TH1D *h1Yield=loadHisto(fname,"h1Yield","h1Yield",h1dummy); TH1D *h1Signal=loadHisto(fname,"h1Signal","h1Signal",h1dummy); hsBlue.SetStyle(h1Yield); h1Yield->SetMarkerStyle(5); hsGreen.SetStyle(h1Signal); h1Yield->GetYaxis()->SetRangeUser(1e-2,1e6); h1Yield->GetYaxis()->SetTitleOffset(1.5); logAxis(h1Yield,1,niceMassAxisLabel(1,"",0),"count",""); plotHisto(h1Yield,"cYield_MM_"+tag,1,1,"LPE","yield " + tag); plotHistoSame(h1Signal,"cYield_MM_"+tag,"LPE1","signal " + tag); } }
void checkInputs() { TFile fin("/mnt/sdc/andriusj/DY13TeV/DYanalysis-20160817/ElectronNtupler/test/Analysis_Codes/AccEff/dyee_preFSR_forAccEff_v1steps.root"); TH1D *h1effPass_new= loadHisto(fin,"h1_eff_sumPass","h1effPass_new",1,h1dummy); TH1D *h1effPass_chk= loadHisto(fin,"h1_eff_sumPass_chk","h1effPass_chk",1,h1dummy); TH1D *h1effPass_noTrigNoPU= loadHisto(fin,"h1_eff_sumPass_noTrigNoPU","h1effPass_noTrigNoPU",1,h1dummy); TH1D *h1effTot_new= loadHisto(fin, "h1_eff_sumTot", "h1effTot_new",1,h1dummy); fin.Close(); if (!h1effPass_new || !h1effPass_chk || !h1effPass_noTrigNoPU || !h1effTot_new) return; TFile fin2("/mnt/sdc/andriusj/DY13TeV/DYanalysis-20160817/ElectronNtupler/test/Analysis_Codes/AccEff/dyee_preFSR_forAccEff_v1.root"); TH1D *h1effPass_old= loadHisto(fin2,"h1_eff_sumPass","h1effPass_old",1,h1dummy); TH1D *h1effTot_old= loadHisto(fin2,"h1_eff_sumTot","h1effTot_old",1,h1dummy); fin2.Close(); if (!h1effPass_old || !h1effTot_old) return; histoStyle(h1effPass_chk,kRed,5,1); histoStyle(h1effPass_old,kBlue,7,1); plotHisto(h1effPass_new,"cCheck",1,0,"LPE1","new effPass"); plotHistoSame(h1effPass_chk,"cCheck","LPE1","new effPass (control)"); printRatio(h1effPass_chk,h1effPass_new); //plotHisto(h1effPass_noTrigNoPU,"cCmpOld",1,0,"LPE1","noTrigNoPU"); //plotHistoSame(h1effPass_old,"cCmpOld","LPE1","old effPass"); //printRatio(h1effPass_old,h1effPass_noTrigNoPU); plotHisto(h1effTot_new,"cCmpTot",1,0,"LPE1","new effTot"); plotHistoSame(h1effTot_old,"cCmpTot","LPE1","old effTot"); printRatio(h1effTot_old,h1effTot_new); }
void plotSteps() { //checkInputs(); return; TFile fin("/mnt/sdc/andriusj/DY13TeV/DYanalysis-20160817/ElectronNtupler/test/Analysis_Codes/AccEff/dyee_preFSR_forAccEff_v1steps.root"); TH1D *h1effPass_new= loadHisto(fin,"h1_eff_sumPass","h1effPass_new",1,h1dummy); TH1D *h1effPass_noPU= loadHisto(fin,"h1_eff_sumPass_noPU","h1effPass_noPU",1,h1dummy); TH1D *h1effPass_noTrigObjMatching= loadHisto(fin,"h1_eff_sumPass_noTrigObjMatching","h1effPass_noTrigObjMatching",1,h1dummy); TH1D *h1effPass_matchDR3= loadHisto(fin,"h1_eff_sumPass_matchDR3","h1effPass_matchDR3",1,h1dummy); TH1D *h1effPass_noTrig= loadHisto(fin,"h1_eff_sumPass_noTrig","h1effPass_noTrig",1,h1dummy); TH1D *h1effPass_noTrigNoPU= loadHisto(fin,"h1_eff_sumPass_noTrigNoPU","h1effPass_noTrigNoPU",1,h1dummy); //TH1D *h1effTot_new= loadHisto(fin, "h1_eff_sumTot", "h1effTot_new",1,h1dummy); fin.Close(); if (!h1effPass_new || !h1effPass_noPU || !h1effPass_noTrigObjMatching || !h1effPass_matchDR3 || !h1effPass_noTrig || !h1effPass_noTrigNoPU) { std::cout << "null ptr\n"; return; } std::vector<TH1D*> h1InfoV; std::vector<TString> infoLabelV; histoStyle(h1effPass_noPU,kRed,5,1); histoStyle(h1effPass_noTrig,kBlue,7,2); histoStyle(h1effPass_matchDR3,kGreen+1,5,1); histoStyle(h1effPass_noTrigObjMatching,kOrange,20,2); std::cout << "\nwPU effect on new effPass distribution\n"; plotHisto(h1effPass_new,"cPUnew",1,0,"LPE1","new wPU"); plotHistoSame(h1effPass_noPU,"cPUnew","LPE1","new noPU"); printRatio(h1effPass_new,h1effPass_noPU); addRatio(h1effPass_noPU,h1effPass_new,"no PU rew.",h1InfoV,infoLabelV); std::cout << "\nwPU effect on old effPass distribution\n"; plotHisto(h1effPass_noTrig,"cPUold",1,0,"LPE1","old wPU"); plotHistoSame(h1effPass_noTrigNoPU,"cPUold","LPE1","old noPU"); printRatio(h1effPass_noTrig,h1effPass_noTrigNoPU); std::cout << "\ntriggering\n"; plotHisto(h1effPass_new,"cTrig",1,0,"LPE1","new wPU"); plotHistoSame(h1effPass_noTrig,"cTrig","LPE1","no event trigger"); printRatio(h1effPass_new,h1effPass_noTrig); addRatio(h1effPass_noTrig,h1effPass_new,"no trigger",h1InfoV,infoLabelV); std::cout << "\ntrigger object matching\n"; plotHisto(h1effPass_new,"cTrigObjMatch",1,0,"LPE1","new wPU"); plotHistoSame(h1effPass_noTrigObjMatching,"cTrigObjMatch","LPE1","new, noTrigObjMatch"); printRatio(h1effPass_new,h1effPass_noTrigObjMatching); addRatio(h1effPass_noTrigObjMatching,h1effPass_new,"no trig.obj.match.",h1InfoV,infoLabelV); std::cout << "\nDR effect on new effPass distribution\n"; plotHisto(h1effPass_new,"cDR",1,0,"LPE1","new wPU, match DR1"); plotHistoSame(h1effPass_matchDR3,"cDR","LPE1","new wPU, match DR3"); printRatio(h1effPass_new,h1effPass_matchDR3); addRatio(h1effPass_matchDR3,h1effPass_new,"#DeltaR<0.3",h1InfoV,infoLabelV); //printLatex("effPassSteps.tex",h1InfoV,infoLabelV,1); plotRatios(h1InfoV,infoLabelV); }
void createSystFile(TVersion_t inpVer, CrossSection_t &eeCS, TVaried_t var, int doSave) { std::cout << "createSystFile for inpVer=" << versionName(inpVer) << "\n"; if (var!=_varRhoSyst) { std::cout << "createSystFile is not ready for var=" << variedVarName(var) << "\n"; return; } TCanvas *c= eeCS.plotCrossSection("cs"); c->Update(); TH1D *h1cs_file= cloneHisto(eeCS.h1PreFsrCS(),"h1cs_file","h1cs_file"); std::vector<TH1D*> h1RhoV; TString fname="dyee-rho-syst2.root"; TFile fin(fname); if (!fin.IsOpen()) { std::cout << "failed to open the file <" << fin.GetName() << ">\n"; return; } for (TTnPSystType_t syst= _tnpSyst_none; syst!=_tnpSyst_last; next(syst)) { TString hname="h1rho_"; if (syst==_tnpSyst_none) hname.Append("stat"); else hname.Append(tnpSystName(syst,1)); TString newHName=hname; if (syst==_tnpSyst_none) newHName.ReplaceAll("stat","orig"); TH1D *h1= loadHisto(fin,hname,newHName,1,h1dummy); h1RhoV.push_back(h1); } fin.Close(); TCanvas *cRho=NULL; if (1) { //plotHisto(eeCS.h1Rho(),"cRho",1,0,"LPE","cs version"); h1RhoV[0]->GetYaxis()->SetTitleOffset(1.6); logAxis(h1RhoV[0],1,"M_{ee} [GeV]","","\\langle\\rho\\rangle\\text{ with alt.effs}"); cRho=plotHisto(h1RhoV[0],"cRho",1,0,"LP","orig"); setLeftRightMargins(cRho,0.14,0.05); for (unsigned int i=1; i<h1RhoV.size(); i++) { TString legStr=h1RhoV[i]->GetName(); legStr.ReplaceAll("h1rho_",""); plotHistoSame(h1RhoV[i],"cRho","LP",legStr); } moveLegend(cRho,0.45,0); } std::vector<TH1D*> h1rhoRelDiffV; int absValues=1; int relativeDiff=1; deriveRelSyst(NULL,h1RhoV,h1rhoRelDiffV,relativeDiff,absValues); if (0) { std::cout << " : " << h1RhoV.size() << ", " << h1rhoRelDiffV.size() << "\n"; for (unsigned int i=0; i<h1rhoRelDiffV.size(); i++) { printRatio(h1RhoV[0], h1RhoV[i+1]); printHisto(h1rhoRelDiffV[i]); } return; } TCanvas *cRhoSyst=NULL; if (1) { TString title="uncertainty"; if (relativeDiff) title.Prepend("relative "); //h1rhoRelDiffV[0]->SetTitle(title); h1rhoRelDiffV[0]->GetYaxis()->SetRangeUser(0,0.12); h1rhoRelDiffV[0]->GetYaxis()->SetTitleOffset(1.6); TString ytitle="\\delta\\langle\\rho\\rangle"; if (relativeDiff) ytitle= "(" + ytitle + ")_{rel}"; //h1rhoRelDiffV[0]->GetYaxis()->SetTitle(ytitle); logAxis(h1rhoRelDiffV[0],3,"M_{ee} [GeV]",ytitle,title); cRhoSyst=plotHisto(h1rhoRelDiffV[0],"cRhoRelDiff",1,0,"LP", tnpSystName(TTnPSystType_t(1),1)); setLeftRightMargins(cRhoSyst,0.14,0.05); for (TTnPSystType_t syst=TTnPSystType_t(2); syst!=_tnpSyst_last; next(syst)) { plotHistoSame(h1rhoRelDiffV[syst-1],"cRhoRelDiff","LP",tnpSystName(syst,1)); } moveLegend(cRhoSyst,0.45,0.47); } std::vector<TH1D*> h1csV; eeCS.var(_varRho); for (unsigned int i=0; i<h1RhoV.size(); i++) { eeCS.h1Rho(h1RhoV[i]); TString hname="h1cs_" + tnpSystName(TTnPSystType_t(i)); TH1D *h1cs= cloneHisto(eeCS.calcCrossSection(0),hname,hname); copyStyle(h1cs,h1RhoV[i]); h1csV.push_back(h1cs); } std::cout << "h1csV.size=" << h1csV.size() << "\n"; if (1) { TCanvas *cRhoCS= plotHisto(h1cs_file,"cRhoCS",1,1,"LP","cs_file"); for (unsigned int i=0; i<h1csV.size(); i++) { plotHistoSame(h1csV[i],"cRhoCS","LP",h1csV[i]->GetName()); } cRhoCS->Update(); } std::vector<TH1D*> h1csRelDiffV; deriveRelSyst(NULL,h1csV,h1csRelDiffV,relativeDiff,absValues); TCanvas *cCSRhoUnc=NULL; if (1) { logAxis(h1csRelDiffV[0],3,"M_{ee} [GeV]", "(\\delta\\sigma)_{\\langle\\rho\\rangle\\,syst;rel}", "relative uncertainty of the cross section"); h1csRelDiffV[0]->GetYaxis()->SetRangeUser(0,0.15); h1csRelDiffV[0]->GetYaxis()->SetTitleOffset(1.6); cCSRhoUnc= plotHisto(h1csRelDiffV[0],"cCSRhoUnc",1,0,"LP", tnpSystName(TTnPSystType_t(1),1)); setLeftRightMargins(cCSRhoUnc,0.14,0.05); for (TTnPSystType_t syst=TTnPSystType_t(2); syst!=_tnpSyst_last; next(syst)) { plotHistoSame(h1csRelDiffV[syst-1],"cCSRhoUnc","LP",tnpSystName(syst,1)); } moveLegend(cCSRhoUnc,0.45,0.47); } if (1) { for (unsigned int i=0; i<h1csRelDiffV.size(); i++) { std::cout << "\n\ni=" << i << "\n"; printRatio(h1csRelDiffV[i],h1rhoRelDiffV[i]); } } if (doSave) { TString fname="dyeeCS-rhoSyst2.root"; TFile fout(fname,"RECREATE"); if (!fout.IsOpen()) { std::cout << "failed to create a file <" << fout.GetName() << ">\n"; return; } for (unsigned int ih=0; ih<h1RhoV.size(); ih++) { h1RhoV[ih]->Write(); } for (unsigned int ih=0; ih<h1rhoRelDiffV.size(); ih++) { h1rhoRelDiffV[ih]->Write(); } for (unsigned int ih=0; ih<h1csRelDiffV.size(); ih++) { h1csRelDiffV[ih]->Write(); } if (cRho) cRho->Write(); if (cRhoSyst) cRhoSyst->Write(); if (cCSRhoUnc) cCSRhoUnc->Write(); TObjString timeTag(DayAndTimeTag(0)); timeTag.Write("timeTag"); fout.Close(); std::cout << "file <" << fout.GetName() << "> created\n"; } return; }
void plotDYSignal(int print=0) { TH1D *h1signalMM4p2= loadHisto("cs_DYmm_13TeVMuApproved_csA.root","h1Signal", "h1signalMM4p2",1,h1dummy); TH1D *h1signalMM4p3= loadHisto("cs_DYmm_13TeVMuApproved_csB.root","h1Signal", "h1signalMM4p2",1,h1dummy); TH1D *h1signalEE= loadHisto("cs_DYee_13TeV_El3.root","h1Signal", "h1signalEE",1,h1dummy); double lumiMM4p2= 865.919; double lumiMM4p3= 2832.673 - lumiMM4p2; double lumiEE= 2316.969; h1signalMM4p2->Scale(1/lumiMM4p2); h1signalMM4p3->Scale(1/lumiMM4p3); h1signalEE->Scale(1/lumiEE); TString massStr= niceMassAxisLabel(2,""); //TString eemassStr= niceMassAxisLabel(0,""); //TString mmmassStr= niceMassAxisLabel(1,""); TString axisStr= ";" + massStr + ";signal yield/Lumi"; TGraphErrors *grEE= createGraph(h1signalEE,"grEE", 0); TGraphErrors *grMM4p2= createGraph(h1signalMM4p2, "grMM4p2", -1); TGraphErrors *grMM4p3= createGraph(h1signalMM4p3, "grMM4p3", 1); printHisto(h1signalEE); printHisto(h1signalMM4p2); graphStyle(grEE, kGreen+1, 7, 1, 0.8); graphStyle(grMM4p2, 46, 24, 1, 0.8); graphStyle(grMM4p3, kBlack, 20, 1, 0.8); std::vector<TCanvas*> canvasV; for (int i=0; i<5; i++) { TString canvName=""; TH2D *h2frame=NULL; TCanvas *cx= createMassFrame(i,"cSignal_", "signal" + axisStr, 2, &canvName,&h2frame); canvasV.push_back(cx); //plotHistoSame(h1csEE,canvName,"LPE1", "DY#rightarrowee"); //plotHistoSame(h1csMM,canvName,"LPE1", "DY#rightarrow#mu#mu"); plotGraphSame(grEE,canvName,"PE1", "DY#rightarrowee"); plotGraphSame(grMM4p2,canvName,"PE1", "DY#rightarrow#mu#mu (HLT4.2)"); plotGraphSame(grMM4p3,canvName,"PE1", "DY#rightarrow#mu#mu (HLT4.3)"); if (i==1) { h2frame->GetYaxis()->SetTitleOffset(1.5); setLeftMargin(cx,0.11); moveLegend(cx,0.45,0.); } if (i==4) { h2frame->GetYaxis()->SetNoExponent(false); h2frame->GetYaxis()->SetTitleOffset(1.5); setLeftMargin(cx,0.15); moveLegend(cx,0.45,0.55); } if (i==5) moveLegend(cx,0.45,0.55); } if (print==1) { TFile fout("foutCanvas_DYSignal.root","RECREATE"); SaveCanvases(canvasV,"dir-plot-DYSignal",&fout); writeTimeTag(); fout.Close(); std::cout << "file <" << fout.GetName() << "> created\n"; } }
void IPEmatch::applyMatch() { matchValue = ui.picView->getHisto(); loadHisto(); double *histoInte = (double *)malloc(256 * 3 * sizeof(double)); double *matchInte = (double *)malloc(256 * 3 * sizeof(double)); for(int i = 0; i < 3; i++) { histoInte[256 * i] = histoValue[256 * i]; matchInte[256 * i] = matchValue[256 * i]; for(int j = 256 * i + 1; j < 256 * i + 256; j++) { histoInte[j] = histoValue[j]; histoInte[j] += histoInte[j - 1]; matchInte[j] = matchValue[j]; matchInte[j] += matchInte[j - 1]; } } int ptra, ptrb;//matchInte int ptrc, ptrd;//for GML: histoInte for(int i = 0; i < 256 * 3; i++) histoData[i] = -1; if(ui.strategyBox->currentIndex() == 0) { //SML for(int i = 0; i < 3; i++) { ptra = 256 * i; ptrb = 256 * i + 1; for(int j = 256 * i; j < 256 * i + 256; j++) { while(1) { if(MathBox::eq(matchInte[ptra], matchInte[ptrb]) && ptra != ptrb) { if(ptrb != 255 + 256 * i) { ptrb++; continue; } } if((MathBox::mabs(histoInte[j] - matchInte[ptra]) < MathBox::mabs(histoInte[j] - matchInte[ptrb])) || MathBox::eq(MathBox::mabs(histoInte[j] - matchInte[ptra]), MathBox::mabs(histoInte[j] - matchInte[ptrb]))) { histoData[j] = ptra - 256 * i; break; } else { ptra = ptrb; if(ptrb != 255 +256 * i) ptrb++; } } } } } else { //GML for(int i = 0; i < 3; i++) { ptra = 256 * i; ptrb = 256 * i + 1; ptrc = 256 * i; ptrd = 256 * i + 1; histoData[256 * i] = 0; while(1) { if(MathBox::eq(matchInte[ptra], matchInte[ptrb]) && ptra != ptrb) { if(ptrb != 255 + 256 * i) { ptrb++; continue; } else { break; } } if(MathBox::mabs(matchInte[ptrb] - histoInte[ptrc]) < MathBox::mabs(matchInte[ptrb] - histoInte[ptrd]) || MathBox::eq(MathBox::mabs(histoInte[ptrb] - histoInte[ptrc]), MathBox::mabs(histoInte[ptrb] - histoInte[ptrd]))) { histoData[ptrc] = ptrb - 256 * i; ptra = ptrb; if(ptrb != 255 + 256 * i) ptrb++; else break; } else { ptrc++; ptrd++; } } histoData[255 + 256 * i] = 255; for(int j = 254 + 256 * i; j >= 256 * i; j--) { if(histoData[j] < 0) histoData[j] = histoData[j + 1]; } } } //processing image int width = mainPainter->getPixelDataWidth(); int height = mainPainter->getPixelDataHeight(); int pixelSize = width * height; GLubyte *pd = mainPainter->getPixelData(); bool RBool = ui.RCheck->isChecked(); bool GBool = ui.GCheck->isChecked(); bool BBool = ui.BCheck->isChecked(); for(int i = 0; i < pixelSize; i++) { if(RBool) pd[4 * i] = histoData[pd[4 * i]]; if(GBool) pd[4 * i + 1] = histoData[256 + pd[4 * i + 1]]; if(BBool) pd[4 * i + 2] = histoData[512 + pd[4 * i + 2]]; } //clean work free(histoInte); free(matchInte); mainPainter->changePixelData(pd); }
void closureTestCSv2(int dataUnfold=0, int compareToTheory=0) { TVersion_t inpVer=_verEl2skim3; TString inpVerTag=versionName(inpVer); TString csOutFName="csClosure_DYee_13TeV_" + inpVerTag + ".root"; const TString tag_UseData="data"; const TString tag_UseTheory="theory"; const TString tag_UseUnity="unity"; const TString tag_UseZero="zero"; const TString tag_Load="combine:"; std::vector<TString> dataInput, theoryInput; addToVector(dataInput, "cs_DYee_13TeV_El2.root h1Yield h1Bkg"); addToVector(theoryInput, "theory13TeVmm.root h1cs_theory"); std::map<TVaried_t,TString> inpHistoNames; TCSType_t csType= _csPreFsrFullSp; TString inpFName="dyee_test_dressed_El2skim3.root"; inpHistoNames[_varYield] = "h1recoSel_MWPU"; //inpHistoNames[_varBkg] = tag_UseZero; inpHistoNames[_varDetRes]= "rooUnf_detResRespPU"; inpHistoNames[_varRho] = tag_UseUnity; inpHistoNames[_varEffAcc] = "h1EffPUAcc"; inpHistoNames[_varFSRRes] = "rooUnf_fsrResp"; inpHistoNames[_varLast] = "h1_preFsr_Mweighted"; if (1) inpHistoNames[_varEffAcc] = "h1EffPUEleMatchAcc"; if (dataUnfold) { inpHistoNames[_varYield] = "data"; //inpHistoNames[_varRho] = "h1rho"; //inpHistoNames[_varRho] = "h1rho_inPostFsrAcc"; } TH1D *h1Zero= new TH1D("h1Zero","h1Zero",DYtools::nMassBins,DYtools::massBinEdges); h1Zero->SetDirectory(0); TH1D *h1Unity= cloneHisto(h1Zero,"h1Unity","h1Unity"); for (int ibin=1; ibin<=h1Unity->GetNbinsX(); ibin++) { h1Unity->SetBinContent(ibin,1.); } CrossSection_t cs("cs",inpVerTag,csType,inpVer); for (std::map<TVaried_t,TString>::const_iterator it=inpHistoNames.begin(); it!=inpHistoNames.end(); it++) { TH1D *h1tmp=NULL, *h1tmp2=NULL; std::cout << "load " << variedVarName(it->first) << " named " << it->second << "\n"; switch(it->first) { case _varYield: if (it->second == tag_UseData) { h1tmp= loadHisto(dataInput[0],dataInput[1], "h1Yield",1,h1dummy); h1tmp2=loadHisto(dataInput[0],dataInput[2], "h1Bkg",1,h1dummy); double lumi=2316.97; if (h1tmp && h1tmp2) { h1tmp->Scale(1/lumi); h1tmp2->Scale(1/lumi); } } else { h1tmp= loadHisto(inpFName,it->second, "h1Yield",1,h1dummy); h1tmp2=h1Zero; } if (!h1tmp || !h1tmp2) return; cs.h1Yield(h1tmp); cs.h1Bkg(h1tmp2); break; case _varDetRes: { RooUnfoldResponse *r= loadRooUnfoldResponse(inpFName,it->second,"detRes"); if (!r) return; cs.detRes(*r); } break; case _varRho: if (it->second == tag_UseUnity) { h1tmp= h1Unity; } else { h1tmp= loadHisto(inpFName,it->second, "h1Rho",1,h1dummy); } if (!h1tmp) return; cs.h1Rho(h1tmp); break; case _varEff: h1tmp= loadHisto(inpFName,it->second, "h1Eff",1,h1dummy); if (!h1tmp) return; cs.h1Eff(h1tmp); break; case _varEffAcc: h1tmp= loadHisto(inpFName,it->second, "h1EffAcc",1,h1dummy); if (!h1tmp) return; cs.h1EffAcc(h1tmp); break; case _varAcc: h1tmp= loadHisto(inpFName,it->second, "h1Acc",1,h1dummy); if (!h1tmp) return; cs.h1Acc(h1tmp); break; case _varFSRRes: { RooUnfoldResponse *r= loadRooUnfoldResponse(inpFName,it->second,"fsrRes"); if (!r) return; cs.fsrRes(*r); } break; case _varLast: h1tmp2= loadHisto(inpFName,it->second, "h1theory",1,h1dummy); if (!h1tmp2) return; h1tmp= perMassBinWidth(h1tmp2); cs.h1Theory(h1tmp); break; default: std::cout << "unprepared case " << variedVarName(it->first) << "\n"; return; } } TH1D* h1cs= cs.calcCrossSection(); printRatio(h1cs,cs.h1Theory()); cs.plotCrossSection(); if (1) { // unfold in 1 step TH1D* h1reco=cloneHisto(cs.h1Yield(),"h1reco","h1reco"); RooUnfoldResponse *rFull= loadRooUnfoldResponse(inpFName,"rooUnf_detResEffAccFsrResp","fullResponse"); if (!h1reco || !rFull) return; RooUnfoldBayes bayesFull( rFull, h1reco, 4); TH1D *h1UnfFull=perMassBinWidth((TH1D*)bayesFull.Hreco()); histoStyle(h1UnfFull,kOrange,5,1); plotHistoSame(h1UnfFull,"cs","LPE1","fullUnf"); printRatio(h1UnfFull,cs.h1Theory()); std::cout << "\n\ndifferent unfoldings\n"; printRatio(h1UnfFull,cs.h1PreFsrCS()); } //cs.save(csOutFName); }
int plotDYAcceptance(int analysisIs2D, const TString conf, DYTools::TRunMode_t runMode=DYTools::NORMAL_RUN, DYTools::TSystematicsStudy_t systMode=DYTools::NO_SYST, TString rndStudyStr="") { gBenchmark->Start("plotDYAcceptance"); { DYTools::printExecMode(runMode,systMode); const int debug_print=1; if (!DYTools::checkSystMode(systMode,debug_print,9, DYTools::NO_SYST, DYTools::FSR_5plus, DYTools::FSR_5minus, DYTools::FSR_RND_STUDY, DYTools::PU_RND_STUDY, DYTools::PILEUP_5plus, DYTools::PILEUP_5minus, DYTools::NO_REWEIGHT, DYTools::NO_REWEIGHT_FEWZ)) return retCodeError; } // // A note on systematics mode // - FSR_5plus, FSR_5minus should be taken care here // - PU_5plus, PU_5minus are taken care by the eventWeight, through // the PUReweight class if (!DYTools::setup(analysisIs2D)) { std::cout << "failed to initialize the analysis\n"; return retCodeError; } //-------------------------------------------------------------------------------------------------------------- // Settings //============================================================================================================== InputFileMgr_t inpMgr; if (!inpMgr.Load(conf)) return retCodeError; // no energy correction for this evaluation inpMgr.clearEnergyScaleTag(); // Construct eventSelector, update mgr and plot directory TString extraTag=rndStudyStr; EventSelector_t evtSelector(inpMgr,runMode,systMode, extraTag,"",EventSelector::_selectDefault); evtSelector.setTriggerActsOnData(false); // Acceptance is generator-level quantity and should not // depend on the pile-up. The flag is disabled. // Correction on May 01, 2014: PU should be applied at all steps EventWeight_t evWeight; if (!evWeight.init(inpMgr.puReweightFlag(),inpMgr.fewzFlag(), systMode,rndStudyStr)) { std::cout << "failed to prepare evWeight\n"; return retCodeError; } std::cout << "evWeight: "; evWeight.PrintDetails(); int useSpecWeight=1; double specWeight=1.0; const double FSRmassDiff=1.0; // FSR_RND_STUDY sets own special weights if (systMode==DYTools::FSR_5plus) { specWeight=1.05; useSpecWeight=1; } else if (systMode==DYTools::FSR_5minus) { specWeight=0.95; useSpecWeight=1; } // Prepare output directory inpMgr.constDir(systMode,1); TString outFileName=inpMgr.correctionFullFileName("acceptance",systMode,0); std::cout << "generated outFileName=<" << outFileName << ">\n"; #ifdef calculate_PreFsrAcc std::cout << dashline; std::cout << "\t\tcalculate_PreFsrAcc is defined\n"; std::cout << dashline; #endif //-------------------------------------------------------------------------------------------------------------- // Main analysis code //============================================================================================================== std::cout << mainpart; // // Set up histograms // // containers to accumulate the events std::vector<TH2D*> hvPass, hvTotal; std::vector<TH2D*> hvFail; #ifdef calculate_PreFsrAcc std::vector<TH2D*> hvPassPreFsr, hvTotalPreFsr; #endif // debug containters std::vector<TH1D*> hMassv; std::vector<TH1D*> hMassBinsv; std::vector<TH1D*> hZpeakv; TH1D *hSelEvents=NULL; // the main result of the macro createBaseH2Vec(hvPass ,"hvPass_" ,inpMgr.mcSampleNames()); createBaseH2Vec(hvTotal,"hvTotal_",inpMgr.mcSampleNames()); createBaseH2Vec(hvFail,"hvFail_",inpMgr.mcSampleNames()); #ifdef calculate_PreFsrAcc createBaseH2Vec(hvPassPreFsr ,"hvPassPreFsr_" ,inpMgr.mcSampleNames()); createBaseH2Vec(hvTotalPreFsr,"hvTotalPreFsr_",inpMgr.mcSampleNames()); #endif // debug distributions: 1GeV bins createAnyH1Vec(hMassv,"hGenMass_",inpMgr.mcSampleNames(),1990,10.,2000.,"#it{M}_{ee} [GeV]","counts/1GeV"); // debug distributions for current mass bin createBaseH1Vec(hMassBinsv,"hGenMassBins_",inpMgr.mcSampleNames()); // debug: accumulate info about the selected events in the samples hSelEvents=createAnyTH1D("hSelEvents","hSelEvents",inpMgr.mcSampleCount(),0,inpMgr.mcSampleCount(),"sampleId","event count"); // collect number of events in the Z-peak createAnyH1Vec(hZpeakv,"hZpeak_",inpMgr.mcSampleNames(),60,60.,120.,"#it{M}_{ee} [GeV]","counts/1GeV"); // // Access samples and fill histograms // AccessOrigNtuples_t accessInfo; // // loop over samples // if (DYTools::processData(runMode)) { double extraWeightFactor=1.0; EventCounterExt_t ecTotal("total"); for (unsigned int isample=0; isample<inpMgr.mcSampleCount(); ++isample) { const CSample_t *mcSample=inpMgr.mcSampleInfo(isample); std::cout << "Processing " << mcSample->getLabel() << "..." << std::endl; std::cout << " of size " << mcSample->size() << "\n"; if (mcSample->size()!=1) { std::cout << "mcSample->size is expected to be 1\n"; return retCodeError; } // accumulate info about processed files EventCounterExt_t ecSample(mcSample->name); for (unsigned int ifile=0; ifile<mcSample->size(); ++ifile) { // Read input file TFile *infile=new TFile(mcSample->getFName(ifile),"read"); if (!infile || !infile->IsOpen()) { TString skimName=inpMgr.convertSkim2Ntuple(mcSample->getFName(ifile)); std::cout << " .. failed. Trying <" << skimName << ">" << std::endl; infile= new TFile(skimName,"read"); } assert(infile->IsOpen()); std::cout << " Reading file <" << mcSample->getFName(ifile) << ">\n"; // Get the TTrees if (!accessInfo.setTree(*infile,"Events",true)) { return retCodeError; } // Find weight for events for this file // The first file in the list comes with weight 1*extraWeightFactor, // all subsequent ones are normalized to xsection and luminosity ULong_t maxEvents = accessInfo.getEntries(); // to match old version package (DYee 7TeV paper), if ((inpMgr.userKeyValueAsInt("USE7TEVMCWEIGHT")==1) && (isample==0) && (ifile==0)) { extraWeightFactor=maxEvents / (inpMgr.totalLumi() * inpMgr.mcSampleInfo(0)->getXsec(ifile)); } //std::cout << "extraWeightFactor=" << extraWeightFactor << ", chk=" << (maxEvents0/inpMgr.mcSampleInfo(0)->getXsec(ifile)) << "\n"; //const double extraWeightFactor=1.0; if (! evWeight.setWeight_and_adjustMaxEvents(maxEvents, inpMgr.totalLumi(), mcSample->getXsec(ifile), extraWeightFactor, inpMgr.selectEventsFlag())) { std::cout << "adjustMaxEvents failed\n"; return retCodeError; } std::cout << "mcSample xsec=" << mcSample->getXsec(ifile) << ", nEntries=" << maxEvents << "\n"; std::cout << " -> sample base weight is " << evWeight.baseWeight() << "\n"; // loop through events EventCounterExt_t ec(Form("%s_file%d",mcSample->name.Data(),ifile)); ec.setIgnoreScale(0); // 1 - count events, 0 - take weight in account // adjust the scale in the counter // if FEWZ weight should be considered, use evWeight.totalWeight() after // the FEWZ weight has been identified (see a line below) ec.setScale(evWeight.baseWeight()); std::cout << "numEntries = " << accessInfo.getEntriesFast() << ", " << maxEvents << " events will be used" << std::endl; for(ULong_t ientry=0; ientry<maxEvents; ientry++) { if (DYTools::isDebugMode(runMode) && (ientry>1000000)) break; // debug option //if (DYTools::isDebugMode(runMode) && (ientry>100)) break; // debug option printProgress(250000," ientry=",ientry,maxEvents); ec.numEvents_inc(); // Load generator level info accessInfo.GetGen(ientry); // If the Z->ll leptons are not electrons, discard this event. // This is needed for signal MC samples such as Madgraph Z->ll // where all 3 lepton flavors are possible if (!accessInfo.genLeptonsAreElectrons()) continue; // Load event info to get nPU accessInfo.GetInfoEntry(ientry); // FSR study correction for weight if (useSpecWeight) { evWeight.setSpecWeightValue(accessInfo,FSRmassDiff,specWeight); if ((systMode==DYTools::FSR_RND_STUDY) && (ientry<100)) { std::cout << "ientry=" << ientry << ", "; evWeight.PrintDetails(); } } // Adjust event weight // .. here "false" = "not data" evWeight.set_PU_and_FEWZ_weights(accessInfo,false); // adjust the scale in the counter to include FEWZ // (and possibly PU) weight //ec.setScale(evWeight.totalWeight()); // accumulate denominator const mithep::TGenInfo *gen= accessInfo.genPtr(); hMassv[isample]->Fill(gen->vmass, evWeight.totalWeight()); hMassBinsv[isample]->Fill(gen->vmass, evWeight.totalWeight()); hvTotal[isample]->Fill(gen->mass, fabs(gen->y), evWeight.totalWeight()); #ifdef calculate_PreFsrAcc hvTotalPreFsr[isample]->Fill(gen->vmass, fabs(gen->vy), evWeight.totalWeight()); #endif int failAcc=0; // check acceptance at Gen PostFSR level if (!evtSelector.inAcceptance(accessInfo)) { hvFail[isample]->Fill(gen->mass, fabs(gen->y), evWeight.totalWeight()); failAcc=1; } #ifdef calculate_PreFsrAcc if (evtSelector.inAcceptancePreFsr(accessInfo)) { hvPassPreFsr[isample]->Fill(gen->vmass, fabs(gen->vy), evWeight.totalWeight()); } #endif if (failAcc) continue; ec.numEventsPassedAcceptance_inc(); // accumulate denominator hvPass[isample]->Fill(gen->mass, fabs(gen->y), evWeight.totalWeight()); hSelEvents->Fill(isample,evWeight.totalWeight()); } // loop over events ec.print(2); // print info about file ecSample.add(ec); // accumulate event counts ecTotal.add(ec); infile->Close(); delete infile; } ecSample.print(2); // print info about sample evtSelector.printCounts(); } ecTotal.print(2); } // if (processData) std::cout << "outFileName=<" << outFileName << ">\n"; if (DYTools::processData(runMode)) { TFile file(outFileName,"recreate"); int res=file.IsOpen(); if (res) res=saveVec(file,hvPass,"accPassDir"); if (res) res=saveVec(file,hvTotal,"accTotalDir"); if (res) res=saveVec(file,hvFail,"accFailDir"); #ifdef calculate_PreFsrAcc if (res) res=saveVec(file,hvPassPreFsr,"accPassPreFsrDir"); if (res) res=saveVec(file,hvTotalPreFsr,"accTotalPreFsrDir"); #endif if (res) res=saveVec(file,hMassv,"mass_1GeV_bins"); if (res) res=saveVec(file,hMassBinsv,"mass_analysis_bins"); if (res) res=saveVec(file,hZpeakv,"mass_Zpeak_1GeV"); if (res) res=saveHisto(file,hSelEvents,"procFileInfo"); if (res) writeBinningArrays(file); file.Close(); if (!res) { std::cout << "error occurred during save to file <" << outFileName << ">\n"; return retCodeError; } } else { TFile file(outFileName,"read"); int res=file.IsOpen(); if (res) res=checkBinningArrays(file); if (res) res=loadVec(file,hvPass,"accPassDir"); if (res) res=loadVec(file,hvTotal,"accTotalDir"); if (res) res=loadVec(file,hvFail,"accFailDir"); #ifdef calculate_PreFsrAcc if (res) res=saveVec(file,hvPassPreFsr,"accPassPreFsrDir"); if (res) res=saveVec(file,hvTotalPreFsr,"accTotalPreFsrDir"); #endif if (res) res=loadVec(file,hMassv,"mass_1GeV_bins"); if (res) res=loadVec(file,hMassBinsv,"mass_analysis_bins"); if (res) res=loadVec(file,hZpeakv,"mass_Zpeak_1GeV"); if (res) res=loadHisto(file,&hSelEvents,"procFileInfo"); file.Close(); if (!res) { std::cout << "error occurred during save to file <" << outFileName << ">\n"; return retCodeError; } } TH2D *hSumPass_BaseH2=createBaseH2("hSumPass_baseH2","hSumPass_baseH2",1); TH2D *hSumTotal_BaseH2=createBaseH2("hSumTotal_baseH2","hSumTotal_baseH2",1); TH2D *hSumFail_BaseH2=createBaseH2("hSumFail_baseH2","hSumFail_baseH2",1); addHistos(hSumPass_BaseH2,hvPass); addHistos(hSumTotal_BaseH2,hvTotal); addHistos(hSumFail_BaseH2,hvFail); TH2D *hAcc_BaseH2 = createBaseH2("hAcceptance_baseH2","hAcc_baseH2",1); // We need the binomial error for the acceptance // eff=Pass/Tot, // (dEff)^2= (1-eff)^2/T^2 (dPass)^2 + eff^2/T^2 (dFail)^2 // (dFail)^2 = (dTot)^2 - (dPass)^2 hAcc_BaseH2->Divide(hSumPass_BaseH2,hSumTotal_BaseH2,1,1,"b"); TH2D *hSumPass=convertBaseH2actual(hSumPass_BaseH2,"hSumPass",1); TH2D *hSumFail=convertBaseH2actual(hSumFail_BaseH2,"hSumFail",1); TH2D *hSumTotal=convertBaseH2actual(hSumTotal_BaseH2,"hSumTotal",1); TH2D *hAcc=Clone(hAcc_BaseH2,"hAcceptance","hAcc"); hAcc->Divide(hSumPass,hSumTotal,1,1,"b"); #ifdef calculate_PreFsrAcc TH2D *hSumPassPreFsr_BaseH2=createBaseH2("hSumPassPreFsr_baseH2","hSumPassPreFsr_baseH2",1); TH2D *hSumTotalPreFsr_BaseH2=createBaseH2("hSumTotalPreFsr_baseH2","hSumTotalPreFsr_baseH2",1); addHistos(hSumPassPreFsr_BaseH2,hvPassPreFsr); addHistos(hSumTotalPreFsr_BaseH2,hvTotalPreFsr); TH2D *hSumPassPreFsr=convertBaseH2actual(hSumPassPreFsr_BaseH2,"hSumPassPreFsr",1); TH2D *hSumTotalPreFsr=convertBaseH2actual(hSumTotalPreFsr_BaseH2,"hSumTotalPreFsr",1); TH2D *hAccPreFsr=Clone(hSumPassPreFsr,"hAccPreFsr","hAccPreFsr"); hAccPreFsr->Divide(hSumPassPreFsr,hSumTotalPreFsr,1,1,"b"); #endif std::cout << dashline; std::cout << dashline; printHisto(hSumPass_BaseH2); printHisto(hSumTotal_BaseH2); printHisto(hAcc_BaseH2); printHisto(hSumPass); printHisto(hSumTotal); printHisto(hAcc); //printHisto(hSumFail); std::cout << dashline; #ifdef calculate_PreFsrAcc std::cout << dashline; printHisto(hSumPassPreFsr); printHisto(hSumTotalPreFsr); printHisto(hAccPreFsr); std::cout << dashline; #endif if (DYTools::processData(runMode)) { TFile file(outFileName,"update"); int res=file.IsOpen(); std::cout << "res=" << res << "\n"; if (res) res=saveHisto(file,hAcc,""); if (res) res=saveHisto(file,hSumPass,""); if (res) res=saveHisto(file,hSumTotal,""); if (res) res=saveHisto(file,hSumFail,""); #ifdef calculate_PreFsrAcc if (res) res=saveHisto(file,hAccPreFsr,""); if (res) res=saveHisto(file,hSumPassPreFsr,""); if (res) res=saveHisto(file,hSumTotalPreFsr,""); #endif file.Close(); if (!res) { std::cout << "error occurred during additional save to file <" << outFileName << ">\n"; return retCodeError; } } //-------------------------------------------------------------------------------------------------------------- // Make plots //============================================================================================================== //-------------------------------------------------------------------------------------------------------------- // Summary print out //============================================================================================================== /* cout << endl; cout << "*" << endl; cout << "* SUMMARY" << endl; cout << "*--------------------------------------------------" << endl; cout << endl; */ //gBenchmark->Show("plotDYAcceptance"); ShowBenchmarkTime("plotDYAcceptance"); return retCodeOk; }