//testing how the TH1::Integral() values change when a hist is scaled void scale() { gSystem->Load("../RootTools/CommonTools.C.so"); gStyle->SetOptStat("nemouri"); TH1F *h = new TH1F("H1","Test Integral",100,0,10); h->Fill (1); h->Fill (1); h->Fill (1); h->Fill (1); //TH1F *h2 = new TH1F("H2","Test Integral copy",100,0,1); //h->FillRandom("gaus",10000); //h2->FillRandom("gaus",10000); // std::cout << "nbins, Entries, Integral = " << h->GetNbinsX() << ", " // << h->GetEntries() << ", " << h->Integral("width") << std::endl; //h = (TH1F*) MakeVariableBinHist(h, 0, 0.2, 0.6, 0.8, 1, 0.1, 0.2, 0.2, 0.2); //std::cout << "nbins, Entries, Integral = " << h->GetNbinsX() << ", " // << h->GetEntries() << ", " << h->Integral("width") << std::endl; new TCanvas(); h->Draw(); //new TCanvas(); //h2->Draw(); //h->Scale(1,"width"); //this replaces the loop below /* for (int bin = 1; bin <= h->GetNbinsX(); ++bin) { const double val = h->GetBinContent(bin); const double err = h->GetBinError(bin); const double width = h->GetBinWidth(bin); h->SetBinContent(bin,val/width); h->SetBinError(bin,err/width); } */ //h->DrawClone("E"); h->Print(); std::cout << "nbins, Entries, Integral = " << h->GetNbinsX() << ", " << h->GetEntries() << ", " << h->Integral("width") << std::endl; //h->Scale(10); h->Scale(10/(double)h->Integral()); //h_copy->Scale(h2_copy->Integral()/(double) h2->Integral()); //h_copy->Draw(); std::cout << "after scaling to " << 10 << std::endl; h->Print(); std::cout << "nbins, Entries, Integral = " << h->GetNbinsX() << ", " << h->GetEntries() << ", " << h->Integral("width") << std::endl; };
void real_emission_jackknife(TString dir="real_aajj_splitted_for_jackknife", TString nameroot="outphoton_aajj_effunf_mu1", int N=20){ TFile *outfile = new TFile(Form("%s/%s_jackknifed.root",dir.Data(),nameroot.Data()),"recreate"); outfile->mkdir("effunf"); vector<TFile*> files; for (int i=1; i<=N; i++){ files.push_back(new TFile(Form("%s/%s_splitted_%d.root",dir.Data(),nameroot.Data(),i),"read")); } for (std::vector<TString>::const_iterator it = diffvariables_list.begin(); it!=diffvariables_list.end(); it++){ for (int reg=0; reg<3; reg++) { TString diffvar = *it; vector<TH1F*> histos; TString thisname = Form("htruth_%s_%d",diffvar.Data(),reg); TString thisnamedir = Form("effunf/%s",thisname.Data()); for (uint i=0; i<files.size(); i++){ histos.push_back((TH1F*)(files.at(i)->Get(thisnamedir.Data()))); } TH1F *out = JackknifammiStiHistos(histos); out->SetName(thisname.Data()); out->Print(); outfile->cd("effunf"); out->Write(); #ifdef DEBUG return; #endif } } outfile->Close(); };
void fitTF1Self() { TFile *f = TFile::Open("plainHisto.root","read"); TH1F *h = (TH1F*)f->Get("mbbReg;1"); h->Print(); TCanvas *c = new TCanvas("c1","c1"); double params[7]; fitTF1(c,*h,110,140,2.5,params,kRed); }
int execDrawString() { cernbuild(1); #ifdef ClingWorkAroundMissingDynamicScope TTree *T; gFile->GetObject("T",T); #endif T->Draw("Division"); #ifdef ClingWorkAroundMissingDynamicScope TH1F *htemp = (TH1F*)gROOT->FindObject("htemp"); #endif htemp->Print("all"); #ifdef ClingWorkAroundErracticValuePrinter printf("(int)0\n"); #endif return 0; }
void efficiency( TString denfile="60-120.root", TString numfile="orig.root", TString outfile="res.root" ) { gROOT ->Reset(); TFile * nume = new TFile(numfile); TFile * deno = new TFile(denfile); nume->cd("/"); deno->cd("/"); TString theName = "d02-x01-y01"; const TH1F *myNume; nume->GetObject(theName,myNume); myNume->Sumw2(); myNume->Print("all"); const TH1F *myDeno; deno->GetObject(theName,myDeno); myDeno->Sumw2(); myDeno->Print("all"); TH1F *Acce = (TH1F*)myNume->Clone("efficiency"); Acce->Reset(); Double_t f1(1.),f2(1.); Option_t* opt("b"); Acce->Divide(myNume,myDeno,f1,f2,opt); Acce->Print("all"); TFile * out = new TFile(outfile,"NEW"); Acce->Write(); out->Close(); }
void RAA_dataDrivenUnfoldingErrorCheck(int radius = 4, int radiusPP = 4, char* algo = (char*) "Pu", char *jet_type = (char*) "PF", int unfoldingCut = 30, char* etaWidth = (char*) "n20_eta_p20", double deltaEta = 4.0){ TStopwatch timer; timer.Start(); TH1::SetDefaultSumw2(); TH2::SetDefaultSumw2(); bool printDebug = true; // get the data and mc histograms from the output of the read macro. TDatime date;//this is just here to get them to run optimized. // Raghav's files: //TFile * fPbPb_in = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/CMSSW_5_3_18/src/Output/PbPb_CutEfficiency_YetkinCuts_matched_slantedlinecalopfpt_addingunmatched_exclusionhighertriggers_eMaxSumcand_A_R0p%d.root",radius)); // //TFile * fPP_in = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/CMSSW_5_3_18/src/Output/Pp_CutEfficiency_YetkinCuts_matched_slantedlinecalopfpt_addingunmatched_exclusionhighertriggers_eMaxSumcand_A_R0p%d.root",radius)); //TFile * fPP_in = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/CMSSW_5_3_18/src/Output/Pp_CutEfficiency_noJetID_exclusionhighertriggers_A_R0p%d.root",radius)); // Pawan's files: TFile * fPbPb_in = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/CMSSW_5_3_18/src/Output/Pawan_ntuplehistograms/PbPb_CutEfficiency_YetkinCuts_matched_slantedlinecalopfpt_addingunmatched_exclusionhighertriggers_eMaxSumcand_A_R0p%d.root",radius)); //TFile * fPP_in = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/CMSSW_5_3_18/src/Output/Pp_CutEfficiency_YetkinCuts_matched_slantedlinecalopfpt_addingunmatched_exclusionhighertriggers_eMaxSumcand_A_R0p%d.root",radius)); TFile * fPP_in = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/CMSSW_5_3_18/src/Output/Pawan_ntuplehistograms/Pp_CutEfficiency_YetkinCuts_matched_slantedlinecalopfpt_addingunmatched_exclusionhighertriggers_eMaxSumcand_A_R0p%d.root",radius)); TFile * fPbPb_MB_in = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/CMSSW_5_3_18/src/Output/PbPb_MinBiasUPC_CutEfficiency_YetkinCuts_matched_slantedlinecalopfpt_addingunmatched_exclusionhighertriggers_eMaxSumcand_A_R0p%d.root",radius)); //TH1F * htest = new TH1F("htest","",nbins_pt, boundaries_pt); //Int_t unfoldingCutBin = htest->FindBin(unfoldingCut); cout<<"after input file declaration"<<endl; // need to make sure that the file names are in prefect order so that i can run them one after another. // for the above condition, i might have to play with the date stamp. const int nbins_cent = 6; double boundaries_cent[nbins_cent+1] = {0,2,4,12,20,28,36}; double ncoll[nbins_cent+1] = {1660,1310,745,251,62.8,10.8,362.24}; // histogram declarations with the following initial appendage: d - Data, m - MC, u- Unfolded // for the MC closure test, ive kept separate // setup the radius and the eta bin loop here later. not for the time being. Aug 20th. only run the -2 < eta < 2 with the differenent centrality bins TH1F *dPbPb_TrgComb[nbins_cent+1], *dPbPb_Comb[nbins_cent+1], *dPbPb_Trg80[nbins_cent+1], *dPbPb_Trg65[nbins_cent+1], *dPbPb_Trg55[nbins_cent+1], *dPbPb_1[nbins_cent+1], *dPbPb_2[nbins_cent+1], *dPbPb_3[nbins_cent+1], *dPbPb_80[nbins_cent+1], *dPbPb_65[nbins_cent+1], *dPbPb_55[nbins_cent+1]; TH1F *mPbPb_Gen[nbins_cent+1], *mPbPb_Reco[nbins_cent+1]; TH2F *mPbPb_Matrix[nbins_cent+1], *mPbPb_Response[nbins_cent+1], *mPbPb_ResponseNorm[nbins_cent+1]; TH1F *mPbPb_mcclosure_data[nbins_cent+1]; TH2F *mPbPb_mcclosure_Matrix[nbins_cent+1],*mPbPb_mcclosure_Response[nbins_cent+1], *mPbPb_mcclosure_ResponseNorm[nbins_cent+1]; TH1F *mPbPb_mcclosure_gen[nbins_cent+1]; const int Iterations = 20; //for unfolding systematics. const int BayesIter = 4; TH1F *uPbPb_Bayes[nbins_cent+1], *uPbPb_BinByBin[nbins_cent+1], *uPbPb_SVD[nbins_cent+1]; TH1F *uPbPb_BayesianIter[nbins_cent+1][Iterations]; TH1F *dPbPb_MinBias[nbins_cent]; TH1F *dPP_1, *dPP_2, *dPP_3, *dPP_Comb; TH1F *mPP_Gen, *mPP_Reco; TH2F *mPP_Matrix, *mPP_Response,*mPP_ResponseNorm; TH1F *mPP_mcclosure_data; TH2F *mPP_mcclosure_Matrix, *mPP_mcclosure_Response,*mPP_mcclosure_ResponseNorm; TH1F *mPP_mcclosure_Gen; TH1F *uPP_Bayes, *uPP_BinByBin, *uPP_SVD; TH1F *uPP_BayesianIter[Iterations]; // would be better to read in the histograms and rebin them. come to think of it, it would be better to have them already rebinned (and properly scaled - to the level of differential cross section in what ever barns (inverse micro barns) but keep it consistent) from the read macro. // get PbPb data for(int i = 0;i<nbins_cent;i++){ if(printDebug) cout<<"cent_"<<i<<endl; dPbPb_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLTComb_R%d_n20_eta_p20_cent%d",radius,i)); //dPbPb_TrgComb[i]->Scale(4*145.156*1e6); dPbPb_TrgComb[i]->Print("base"); dPbPb_Trg80[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT80_R%d_n20_eta_p20_cent%d",radius,i)); //dPbPb_Trg80[i]->Scale(4*145.156*1e6); dPbPb_Trg80[i]->Print("base"); dPbPb_Trg65[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT65_R%d_n20_eta_p20_cent%d",radius,i)); //dPbPb_Trg65[i]->Scale(4*145.156*1e6); dPbPb_Trg65[i]->Print("base"); dPbPb_Trg55[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT55_R%d_n20_eta_p20_cent%d",radius,i)); //dPbPb_Trg55[i]->Scale(4*145.156*1e6); dPbPb_Trg55[i]->Print("base"); //dPbPb_TrgComb[i] = (TH1F*)dPbPb_Trg80[i]->Clone(Form("Jet_80_triggered_spectra_data_PbPb_cent%d",i)); //dPbPb_MinBias[i] = (TH1F*)fPbPb_MB_in->Get(Form("hpbpb_HLTComb_R%d_n20_eta_p20_cent%d",radius,i)); //dPbPb_MinBias[i]->Print("base"); dPbPb_TrgComb[i]->Scale(1./(145.156 * 1e9)); //dPbPb_MinBias[i]->Scale(1./(161.939 * 1e9)); //dPbPb_TrgComb[i]->Add(dPbPb_MinBias[i]); for(int k = 1;k<=unfoldingCut;k++) { dPbPb_TrgComb[i]->SetBinContent(k,0); dPbPb_Trg80[i]->SetBinContent(k,0); dPbPb_Trg65[i]->SetBinContent(k,0); dPbPb_Trg55[i]->SetBinContent(k,0); } } //Int_t nSVDIter = 4; if(printDebug)cout<<"loaded the data histograms PbPb"<<endl; // get PbPb MC for(int i = 0;i<nbins_cent;i++){ mPbPb_Gen[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_JetComb_gen_R%d_n20_eta_p20_cent%d",radius,i)); //mPbPb_Gen[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_gen_R%d_n20_eta_p20_cent%d",radius,i)); mPbPb_Gen[i]->Print("base"); mPbPb_Reco[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_JetComb_reco_R%d_n20_eta_p20_cent%d",radius,i)); //mPbPb_Reco[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_reco_R%d_n20_eta_p20_cent%d",radius,i)); mPbPb_Reco[i]->Print("base"); mPbPb_Matrix[i] = (TH2F*)fPbPb_in->Get(Form("hpbpb_matrix_HLT_R%d_n20_eta_p20_cent%d",radius,i)); //mPbPb_Matrix[i] = (TH2F*)fPbPb_in->Get(Form("hpbpb_matrix_R%d_n20_eta_p20_cent%d",radius,i)); mPbPb_Matrix[i]->Print("base"); mPbPb_mcclosure_data[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_mcclosure_JetComb_data_R%d_n20_eta_p20_cent%d",radius,i)); mPbPb_mcclosure_data[i]->Print("base"); mPbPb_mcclosure_gen[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_mcclosure_gen_JetComb_R%d_n20_eta_p20_cent%d",radius,i)); mPbPb_mcclosure_gen[i]->Print("base"); mPbPb_mcclosure_Matrix[i] = (TH2F*)fPbPb_in->Get(Form("hpbpb_mcclosure_matrix_HLT_R%d_n20_eta_p20_cent%d",radius,i)); mPbPb_mcclosure_Matrix[i]->Print("base"); //since SVD is very straight forward, lets do it rignt here: //get the SVD response matrix: //RooUnfoldResponse ruResponse(mPbPb_Matrix[i]->ProjectionY(),mPbPb_Matrix[i]->ProjectionX(), mPbPb_Matrix[i],"",""); //regularization parameter definition: //RooUnfoldSvd unfoldSvd(&ruResponse, dPbPb_TrgComb[i], nSVDIter); //uPbPb_SVD[i] = (TH1F*)unfoldSvd.Hreco(); // for(int k = 1;k<=unfoldingCut;k++){ // mPbPb_Gen[i]->SetBinContent(k,0); // mPbPb_Reco[i]->SetBinContent(k,0); // mPbPb_mcclosure_data[i]->SetBinContent(k,0); // mPbPb_mcclosure_gen[i]->SetBinContent(k,0); // for(int l = 1;l<=1000;l++){ // mPbPb_Matrix[i]->SetBinContent(k,l,0); // mPbPb_mcclosure_Matrix[i]->SetBinContent(k,l,0); // mPbPb_Matrix[i]->SetBinContent(l,k,0); // mPbPb_mcclosure_Matrix[i]->SetBinContent(l,k,0); // } // } //mPbPb_Response[i] = new TH2F(Form("mPbPb_Response_cent%d",i),"Response Matrix",nbins_pt,boundaries_pt,nbins_pt,boundaries_pt); //mPbPb_ResponseNorm[i] = new TH2F(Form("mPbPb_ResponseNorm_cent%d",i),"Normalized Response Matrix",nbins_pt,boundaries_pt,nbins_pt,boundaries_pt); } if(printDebug) cout<<"loaded the data and mc PbPb histograms from the files"<<endl; // get PP data if(printDebug) cout<<"Getting PP data and MC"<<endl; dPP_1 = (TH1F*)fPP_in->Get(Form("hpp_HLT80_R%d_%s",radiusPP,etaWidth)); dPP_1->Print("base"); dPP_2 = (TH1F*)fPP_in->Get(Form("hpp_HLT60_R%d_%s",radiusPP,etaWidth)); dPP_2->Print("base"); dPP_3 = (TH1F*)fPP_in->Get(Form("hpp_HLT40_R%d_%s",radiusPP,etaWidth)); dPP_3->Print("base"); dPP_Comb = (TH1F*)fPP_in->Get(Form("hpp_HLTComb_R%d_%s",radiusPP,etaWidth)); //dPP_Comb = (TH1F*)dPP_1->Clone(Form("hpp_TrgComb_R%d_n20_eta_p20",radiusPP,etaWidth)); dPP_Comb->Print("base"); dPP_Comb->Scale(1./(5.3 * 1e9)); for(int k = 1;k<=unfoldingCut;k++) { dPP_Comb->SetBinContent(k,0); dPP_1->SetBinContent(k,0); dPP_2->SetBinContent(k,0); dPP_3->SetBinContent(k,0); } // get PP MC mPP_Gen = (TH1F*)fPP_in->Get(Form("hpp_JetComb_gen_R%d_%s",radiusPP,etaWidth)); mPP_Gen->Print("base"); mPP_Reco = (TH1F*)fPP_in->Get(Form("hpp_JetComb_reco_R%d_%s",radiusPP,etaWidth)); mPP_Reco->Print("base"); mPP_Matrix = (TH2F*)fPP_in->Get(Form("hpp_matrix_HLT_R%d_%s",radiusPP,etaWidth)); mPP_Matrix->Print("base"); mPP_mcclosure_data = (TH1F*)fPP_in->Get(Form("hpp_mcclosure_JetComb_data_R%d_%s",radiusPP,etaWidth)); mPP_mcclosure_data->Print("base"); mPP_mcclosure_Matrix = (TH2F*)fPP_in->Get(Form("hpp_mcclosure_matrix_HLT_R%d_%s",radiusPP,etaWidth)); mPP_mcclosure_Matrix->Print("base"); //RooUnfoldResponse ruResponsePP(mPP_Matrix->ProjectionY(),mPP_Matrix->ProjectionX(), mPP_Matrix,"",""); //regularization parameter definition: //RooUnfoldSvd unfoldSvdPP(&ruResponsePP, dPP_Comb, nSVDIter); //uPP_SVD = (TH1F*)unfoldSvdPP.Hreco(); // for(int k = 1;k<=unfoldingCut;k++){ // mPP_Gen->SetBinContent(k,0); // mPP_Reco->SetBinContent(k,0); // mPP_mcclosure_data->SetBinContent(k,0); // for(int l = 1;l<=1000;l++){ // mPP_Matrix->SetBinContent(k,l,0); // mPP_mcclosure_Matrix->SetBinContent(k,l,0); // mPP_Matrix->SetBinContent(l,k,0); // mPP_mcclosure_Matrix->SetBinContent(l,k,0); // } // } if(printDebug) cout<<"Filling the PbPb response Matrix"<<endl; // response matrix and unfolding for PbPb // going to try it the way kurt has it. for(int i = 0;i<nbins_cent;i++){ if(printDebug) cout<<"centrality bin iteration = "<<i<<endl; TF1 *f = new TF1("f","[0]*pow(x+[2],[1])"); f->SetParameters(1e10,-8.8,40); // TH1F *hGenSpectraCorr = (TH1F*)mPbPb_Matrix[i]->ProjectionX()->Clone(Form("hGenSpectraCorr_cent%d",i)); // hGenSpectraCorr->Fit("f"," "); // hGenSpectraCorr->Fit("f","",""); // hGenSpectraCorr->Fit("f","LL"); // TH1F *fHist = functionHist(f,hGenSpectraCorr,Form("fHist_cent%d",i));// function that you get from the fitting // hGenSpectraCorr->Divide(fHist); for (int y=1;y<=mPbPb_Matrix[i]->GetNbinsY();y++) { double sum=0; for (int x=1;x<=mPbPb_Matrix[i]->GetNbinsX();x++) { if (mPbPb_Matrix[i]->GetBinContent(x,y)<=1*mPbPb_Matrix[i]->GetBinError(x,y)) { //in the above line mine had 0*getbinerror while Kurt's had 1*. mPbPb_Matrix[i]->SetBinContent(x,y,0); mPbPb_Matrix[i]->SetBinError(x,y,0); } sum+=mPbPb_Matrix[i]->GetBinContent(x,y); } for (int x=1;x<=mPbPb_Matrix[i]->GetNbinsX();x++) { double ratio = 1; // if (hGenSpectraCorr->GetBinContent(x)!=0) ratio = 1e5/hGenSpectraCorr->GetBinContent(x); mPbPb_Matrix[i]->SetBinContent(x,y,mPbPb_Matrix[i]->GetBinContent(x,y)*ratio); mPbPb_Matrix[i]->SetBinError(x,y,mPbPb_Matrix[i]->GetBinError(x,y)*ratio); } } //mPbPb_Matrix[i]->Smooth(0); // Ok major differences here between my code and Kurt in b-jet Tools under Unfold - lines 469 and above. mPbPb_Response[i] = (TH2F*)mPbPb_Matrix[i]->Clone(Form("mPbPb_Response_cent%d",i)); TH1F *hProj = (TH1F*)mPbPb_Response[i]->ProjectionY()->Clone(Form("hProj_cent%d",i)); for (int y=1;y<=mPbPb_Response[i]->GetNbinsY();y++) { double sum=0; for (int x=1;x<=mPbPb_Response[i]->GetNbinsX();x++) { if (mPbPb_Response[i]->GetBinContent(x,y)<=1*mPbPb_Response[i]->GetBinError(x,y)) { // in the above if loop, kurt has 1*error and my old had 0*error mPbPb_Response[i]->SetBinContent(x,y,0); mPbPb_Response[i]->SetBinError(x,y,0); } sum+=mPbPb_Response[i]->GetBinContent(x,y); } for (int x=1;x<=mPbPb_Response[i]->GetNbinsX();x++) { if (sum==0) continue; double ratio = 1; //if(dPbPb_TrgComb[i]->GetBinContent(y)==0) ratio = 1e-100/sum; // else ratio = dPbPb_TrgComb[i]->GetBinContent(y)/sum ratio = 1./sum; if (hProj->GetBinContent(y)==0) ratio = 1e-100/sum; else ratio = hProj->GetBinContent(y)/sum; mPbPb_Response[i]->SetBinContent(x,y,mPbPb_Response[i]->GetBinContent(x,y)*ratio); mPbPb_Response[i]->SetBinError(x,y,mPbPb_Response[i]->GetBinError(x,y)*ratio); } } mPbPb_ResponseNorm[i] = (TH2F*)mPbPb_Matrix[i]->Clone(Form("mPbPb_ResponseNorm_cent%d",i)); for (int x=1;x<=mPbPb_ResponseNorm[i]->GetNbinsX();x++) { double sum=0; for (int y=1;y<=mPbPb_ResponseNorm[i]->GetNbinsY();y++) { if (mPbPb_ResponseNorm[i]->GetBinContent(x,y)<=1*mPbPb_ResponseNorm[i]->GetBinError(x,y)) { mPbPb_ResponseNorm[i]->SetBinContent(x,y,0); mPbPb_ResponseNorm[i]->SetBinError(x,y,0); } sum+=mPbPb_ResponseNorm[i]->GetBinContent(x,y); } for (int y=1;y<=mPbPb_ResponseNorm[i]->GetNbinsY();y++) { if (sum==0) continue; double ratio = 1./sum; mPbPb_ResponseNorm[i]->SetBinContent(x,y,mPbPb_ResponseNorm[i]->GetBinContent(x,y)*ratio); mPbPb_ResponseNorm[i]->SetBinError(x,y,mPbPb_ResponseNorm[i]->GetBinError(x,y)*ratio); } } } if(printDebug) cout<<"Filling PP response Matrix"<<endl; // response matrix for pp. // Kurt doesnt have this whole hGenSpectraCorr thing in his macro. need to check why the difference exists between out codes TF1 *fpp = new TF1("fpp","[0]*pow(x+[2],[1])"); fpp->SetParameters(1e10,-8.8,40); // if(printDebug) cout<<"before getting the gen spectra corr matrix"<<endl; // TH1F *hGenSpectraCorrPP = (TH1F*)mPP_Matrix->ProjectionX()->Clone("hGenSpectraCorrPP"); // if(printDebug) cout<<"after gettign the gen spectra corr matrix"<<endl; // hGenSpectraCorrPP->Fit("f"," "); // hGenSpectraCorrPP->Fit("f","",""); // hGenSpectraCorrPP->Fit("f","LL"); // TH1F *fHistPP = functionHist(fpp,hGenSpectraCorrPP,"fHistPP");// that the function that you get from the fitting // hGenSpectraCorrPP->Divide(fHistPP); for (int y=1;y<=mPP_Matrix->GetNbinsY();y++) { double sum=0; for (int x=1;x<=mPP_Matrix->GetNbinsX();x++) { if (mPP_Matrix->GetBinContent(x,y)<=1*mPP_Matrix->GetBinError(x,y)) { mPP_Matrix->SetBinContent(x,y,0); mPP_Matrix->SetBinError(x,y,0); } sum+=mPP_Matrix->GetBinContent(x,y); } for (int x=1;x<=mPP_Matrix->GetNbinsX();x++) { double ratio = 1; // if (hGenSpectraCorrPP->GetBinContent(x)!=0) ratio = 1e5/hGenSpectraCorrPP->GetBinContent(x); mPP_Matrix->SetBinContent(x,y,mPP_Matrix->GetBinContent(x,y)*ratio); mPP_Matrix->SetBinError(x,y,mPP_Matrix->GetBinError(x,y)*ratio); } } // mPbPb_Matrix[i]->Smooth(0); // Ok major differences here between my code and Kurt in b-jet Tools under Unfold - lines 469 and above. if(printDebug) cout<<"getting the response matrix"<<endl; mPP_Response = (TH2F*)mPP_Matrix->Clone("mPP_Response"); TH1F *hProjPP = (TH1F*)mPP_Response->ProjectionY()->Clone("hProjPP"); for (int y=1;y<=mPP_Response->GetNbinsY();y++) { double sum=0; for (int x=1;x<=mPP_Response->GetNbinsX();x++) { if (mPP_Response->GetBinContent(x,y)<=1*mPP_Response->GetBinError(x,y)) { // in the above if statement, kurt has 1*error and my old has 0*error mPP_Response->SetBinContent(x,y,0); mPP_Response->SetBinError(x,y,0); } sum+=mPP_Response->GetBinContent(x,y); } for (int x=1;x<=mPP_Response->GetNbinsX();x++) { if (sum==0) continue; double ratio = 1; //if(dPbPb_TrgComb[i]->GetBinContent(y)==0) ratio = 1e-100/sum; // else ratio = dPbPb_TrgComb[i]->GetBinContent(y)/sum ratio = 1./sum; if (hProjPP->GetBinContent(y)==0) ratio = 1e-100/sum; else ratio = hProjPP->GetBinContent(y)/sum; mPP_Response->SetBinContent(x,y,mPP_Response->GetBinContent(x,y)*ratio); mPP_Response->SetBinError(x,y,mPP_Response->GetBinError(x,y)*ratio); } } if(printDebug) cout<<"getting the normalized response matrix"<<endl; mPP_ResponseNorm = (TH2F*)mPP_Matrix->Clone("mPP_ResponseNorm"); for (int x=1;x<=mPP_ResponseNorm->GetNbinsX();x++) { double sum=0; for (int y=1;y<=mPP_ResponseNorm->GetNbinsY();y++) { if (mPP_ResponseNorm->GetBinContent(x,y)<=1*mPP_ResponseNorm->GetBinError(x,y)) { mPP_ResponseNorm->SetBinContent(x,y,0); mPP_ResponseNorm->SetBinError(x,y,0); } sum+=mPP_ResponseNorm->GetBinContent(x,y); } for (int y=1;y<=mPP_ResponseNorm->GetNbinsY();y++) { if (sum==0) continue; double ratio = 1./sum; mPP_ResponseNorm->SetBinContent(x,y,mPP_ResponseNorm->GetBinContent(x,y)*ratio); mPP_ResponseNorm->SetBinError(x,y,mPP_ResponseNorm->GetBinError(x,y)*ratio); } } // scale the spectra to the respective units // for(int i = 0;i<nbins_cent;++i){ // dPbPb_TrgComb[i] = (TH1F*)dPbPb_TrgComb[i]->Rebin(nbins_pt,Form("PbPb_measured_spectra_combined_cent%d",i),boundaries_pt); // divideBinWidth(dPbPb_TrgComb[i]); // } // dPP_Comb = (TH1F*)dPP_Comb->Rebin(nbins_pt,"pp_measured_spectra_combined",boundaries_pt); // divideBinWidth(dPP_Comb); // dPP_Comb->Scale(1./ dPP_Comb->GetBinContent(nbins_pt)); // Now that we have all the response matrix for the 6 centralities in PbPb and one pp spectra lets start doing the steps: // we have 39 pt bins, so we need 1000 gaussian functions for each pt bin. Int_t unfoldingTrials = 200; Double_t meanMeasPbPb[nbins_pt][nbins_cent], sigmaMeasPbPb[nbins_pt][nbins_cent]; Double_t meanMeasPP[nbins_pt], sigmaMeasPP[nbins_pt]; Double_t meanUnfoldPbPb[nbins_pt][nbins_cent][unfoldingTrials], sigmaUnfoldPbPb[nbins_pt][nbins_cent][unfoldingTrials]; Double_t meanUnfoldPP[nbins_pt][unfoldingTrials], sigmaUnfoldPP[nbins_pt][unfoldingTrials]; TRandom3 *random = new TRandom3(0); for(int u = 0;u<unfoldingTrials;++u){ cout<<"unfolding trial no = "<<u+1<<endl; for(int j = 0;j<nbins_pt;++j){ for(int i = 0;i<nbins_cent;++i){ meanMeasPbPb[j][i] = dPbPb_TrgComb[i]->GetBinContent(j+1); sigmaMeasPbPb[j][i] = dPbPb_TrgComb[i]->GetBinError(j+1); }// centrality loop meanMeasPP[j] = dPP_Comb->GetBinContent(j+1); sigmaMeasPP[j] = dPP_Comb->GetBinContent(j+1); }// nbins_pt loop // now proceed to unfolding for each trial. for(int i = 0;i<nbins_cent;++i){ //cout<<"centrality = "<<i<<endl; TH1F * hPreUnfoldingSpectra = new TH1F("hPreUnfoldingSpectra","",nbins_pt,0,nbins_pt); TH1F * hAfterUnfoldingSpectra; for(int j = 0;j<nbins_pt;++j){ hPreUnfoldingSpectra->SetBinContent(j+1, random->Gaus(meanMeasPbPb[j][i], sigmaMeasPbPb[j][i])); hPreUnfoldingSpectra->SetBinError(j+1, sigmaMeasPbPb[j][i]/sqrt(unfoldingTrials)); //if(j==100)cout << " before unfolding bin " << j << " value = " << hPreUnfoldingSpectra->GetBinContent(j+1)<<endl; //if(j==100)cout << " before unfolding bin " << j << " error = " << hPreUnfoldingSpectra->GetBinError(j+1)<<endl; }// nbins_pt loop TH1F* hMCGen = (TH1F*)mPbPb_Response[i]->ProjectionX(); removeZero(hMCGen); //cout << " MC bin " << 100 << " value = " << hMCGen->GetBinContent(100)<<endl; bayesianUnfold myUnfoldingMulti(mPbPb_Matrix[i], hMCGen, 0); myUnfoldingMulti.unfold(hPreUnfoldingSpectra, BayesIter); hAfterUnfoldingSpectra = (TH1F*) myUnfoldingMulti.hPrior->Clone("hAfterUnfoldingSpectra"); for(int j = 0;j<nbins_pt;++j){ //if(j==100)cout << " before unfolding bin " << j << " value = " << hPreUnfoldingSpectra->GetBinContent(j+1)<<endl; //if(j==100)cout << " after unfolding bin " << j << " value = " << hAfterUnfoldingSpectra->GetBinContent(j+1)<<endl; meanUnfoldPbPb[j][i][u] = hAfterUnfoldingSpectra->GetBinContent(j+1); sigmaUnfoldPbPb[j][i][u] = hAfterUnfoldingSpectra->GetBinError(j+1); // cout << "after unfolding meanUnfoldPbPb[" << j << "][" << i << "][" << u<< "] = " <<meanUnfoldPbPb[j][i][u]<<" "; // cout << "after unfolding meanUnfoldPbPb[" << j << "][" << i << "][" << u<< "] = " <<sigmaUnfoldPbPb[j][i][u]<<endl; }// nbins_pt loop //hPreUnfoldingSpectra->Print("base"); //hAfterUnfoldingSpectra->Print("base"); delete hPreUnfoldingSpectra; delete hAfterUnfoldingSpectra; delete hMCGen; }// centrality loop cout<<"pp "<<endl; // now do it for the pp: TH1F * hPreUnfoldingSpectraPP = new TH1F("hPreUnfoldingSpectraPP","",nbins_pt,0,nbins_pt); TH1F * hAfterUnfoldingSpectraPP; for(int j = 0;j<nbins_pt;++j){ hPreUnfoldingSpectraPP->SetBinContent(j+1, random->Gaus(meanMeasPP[j], sigmaMeasPP[j])); hPreUnfoldingSpectraPP->SetBinError(j+1, sigmaMeasPP[j]/sqrt(unfoldingTrials)); }// nbins_pt loop TH1F* hMCGenPP = (TH1F*)mPP_Response->ProjectionX(); removeZero(hMCGenPP); bayesianUnfold myUnfoldingMultiPP(mPP_Matrix, hMCGenPP, 0); myUnfoldingMultiPP.unfold(hPreUnfoldingSpectraPP, BayesIter); hAfterUnfoldingSpectraPP = (TH1F*) myUnfoldingMultiPP.hPrior->Clone("hAfterUnfoldingSpectraPP"); for(int j = 0;j<nbins_pt;++j){ meanUnfoldPP[j][u] = hAfterUnfoldingSpectraPP->GetBinContent(j+1); sigmaUnfoldPP[j][u] = hAfterUnfoldingSpectraPP->GetBinError(j+1); }// nbins_pt loop delete hPreUnfoldingSpectraPP; delete hAfterUnfoldingSpectraPP; delete hMCGenPP; }// unfolding trials loop // Now that we have all the necesary values we need, lets proceed to fill a histogram with the mean values for each ptbin and get the corrected values. TH1F * hAfterUnfoldingptBinDistribution[nbins_pt]; TH1F * hCorrUnfoldingPbPb[nbins_cent]; for(int i = 0;i<nbins_cent;++i){ hCorrUnfoldingPbPb[i] = new TH1F(Form("PbPb_BayesianUnfolded_cent%d",i),"Spectra after correction", nbins_pt, 0, nbins_pt); for(int j = 0;j<nbins_pt;++j){ //hAfterUnfoldingptBinDistribution[j] = new TH1F(Form("hAfterUnfoldingptBinDistribution_ptBin%d",j),"",100, (meanMeasPbPb[j][i]-10) * sigmaMeasPbPb[j][i], (meanMeasPbPb[j][i]+10) * sigmaMeasPbPb[j][i]); hAfterUnfoldingptBinDistribution[j] = new TH1F(Form("hAfterUnfoldingptBinDistribution_ptBin%d",j),"",100, 0, 1); for(int u = 0;u<unfoldingTrials;++u){ hAfterUnfoldingptBinDistribution[j]->Fill(meanUnfoldPbPb[j][i][u]); //if(j==100) cout<< "unfolding_trial = " << u+1 << " mean unfold value = "<< meanUnfoldPbPb[j][i][u] <<endl; }// unfolding trials loop //if(j==100) cout<<"Mean of that value for pt=100 = "<< (Float_t)hAfterUnfoldingptBinDistribution[j]->GetMean() <<endl; hCorrUnfoldingPbPb[i]->SetBinContent(j+1, hAfterUnfoldingptBinDistribution[j]->GetMean()); //cout<<"centrality bin "<<i<<", pT bin "<<j<<" bin Content = "<<hCorrUnfoldingPbPb[i]->GetBinContent(j+1)<<endl; hCorrUnfoldingPbPb[i]->SetBinError(j+1, hAfterUnfoldingptBinDistribution[j]->GetRMS()); //cout<<"centrality bin "<<i<<", pT bin "<<j<<" bin Error = "<<hCorrUnfoldingPbPb[i]->GetBinError(j+1)<<endl; delete hAfterUnfoldingptBinDistribution[j]; }// nbins_pt loop }// centrality loop // similar for the pp: TH1F * hAfterUnfoldingptBinDistributionPP[nbins_pt]; TH1F * hCorrUnfoldingPP; hCorrUnfoldingPP = new TH1F("PP_BayesianUnfolded","Spectra after unfolding error correction",nbins_pt, 0, nbins_pt); for(int j = 0;j<nbins_pt;++j){ //hAfterUnfoldingptBinDistributionPP[j] = new TH1F(Form("hAfterUnfoldingptBinDistributionPP_ptBin%d",j),"",1000,(meanMeasPP[j]-10) * sigmaMeasPP[j], (meanMeasPP[j]+10) * sigmaMeasPP[j]); hAfterUnfoldingptBinDistributionPP[j] = new TH1F(Form("hAfterUnfoldingptBinDistributionPP_ptBin%d",j),"",100, 0, 1); for(int u = 0;u<unfoldingTrials;++u){ hAfterUnfoldingptBinDistributionPP[j]->Fill(meanUnfoldPP[j][u]); }// unfolding trials loop hCorrUnfoldingPP->SetBinContent(j+1, hAfterUnfoldingptBinDistributionPP[j]->GetMean()); //cout<<"PP pT bin "<<j<<" bin Content = "<<hCorrUnfoldingPP->GetBinContent(j+1)<<endl; hCorrUnfoldingPP->SetBinError(j+1, hAfterUnfoldingptBinDistributionPP[j]->GetRMS()); //cout<<"PP pT bin "<<j<<" bin Error = "<<hCorrUnfoldingPP->GetBinError(j+1)<<endl; delete hAfterUnfoldingptBinDistributionPP[j]; }// nbins_pt loop TFile f(Form("../../Output/Pawan_ntuple_PbPb_R%d_pp_R%d_%s_unfoldingCut_%d_data_driven_correction_ak%s%s_%d.root",radius, radiusPP, etaWidth ,unfoldingCut,algo,jet_type,date.GetDate()),"RECREATE"); f.cd(); for(int i = 0;i<nbins_cent;i++) { hCorrUnfoldingPbPb[i]->Scale(145.156 * 1e9); //hCorrUnfoldingPbPb[i] = (TH1F*)hCorrUnfoldingPbPb[i]->Rebin(nbins_pt_coarse, Form("PbPb_BayesianUnfolded_cent%d",i), boundaries_pt_coarse); hCorrUnfoldingPbPb[i]->Write(); hCorrUnfoldingPbPb[i]->Print("base"); dPbPb_TrgComb[i]->Scale(145.156 * 1e9); //dPbPb_TrgComb[i] = (TH1F*)dPbPb_TrgComb[i]->Rebin(nbins_pt_coarse, Form("PbPb_measured_cent%d",i), boundaries_pt_coarse); dPbPb_TrgComb[i]->Write(); dPbPb_TrgComb[i]->Print("base"); } hCorrUnfoldingPP->Scale(5.3 * 1e9); //hCorrUnfoldingPP = (TH1F*)hCorrUnfoldingPP->Rebin(nbins_pt_coarse, "PP_BayesianUnfolded", boundaries_pt_coarse); hCorrUnfoldingPP->Write(); hCorrUnfoldingPP->Print("base"); dPP_Comb->Scale(5.3 * 1e9); //dPP_Comb = (TH1F*)dPP_Comb->Rebin(nbins_pt_coarse, "PP_measured", boundaries_pt_coarse); dPP_Comb->Write(); dPP_Comb->Print("base"); f.Write(); f.Close(); timer.Stop(); if(printDebug) cout<<"CPU time (mins) = "<<(Float_t)timer.CpuTime()/60<<endl; if(printDebug) cout<<"Real tile (mins) = "<<(Float_t)timer.RealTime()/60<<endl; }
void merge_pbpb_pp_HLT(){ TH1::SetDefaultSumw2(); //TFile *fpbpb1 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PbPb/2011/data/ntuple_2011_pbpbJet80_v2.root"); //TFile *fpbpb2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PbPb/2011/data/ntuple_2011_pbpbJet65_v2.root"); //TFile *fpbpb3 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PbPb/2011/data/ntuple_2011_pbpbJet55_v2.root"); //TFile *fpp1 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_ppJet80.root"); //TFile *fpp2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_ppJet40.root"); TFile *fpp1_v2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_JEC_applied_ppJet80_v2.root"); TFile *fpp2_v2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_JEC_applied_ppJet40_v2.root"); /* TTree *jetpbpb1_v2 = (TTree*)fpbpb1->Get("jetR3"); TTree *jetpbpb2_v2 = (TTree*)fpbpb2->Get("jetR3"); TTree *jetpbpb3_v2 = (TTree*)fpbpb3->Get("jetR3"); TTree *evtpbpb1_v2 = (TTree*)fpbpb1->Get("evt"); TTree *evtpbpb2_v2 = (TTree*)fpbpb2->Get("evt"); TTree *evtpbpb3_v2 = (TTree*)fpbpb3->Get("evt"); jetpbpb1_v2->AddFriend(evtpbpb1_v2); jetpbpb2_v2->AddFriend(evtpbpb2_v2); jetpbpb3_v2->AddFriend(evtpbpb3_v2); */ //TTree *jetpp1 = (TTree*)fpp1->Get("ntjet"); // TTree *jetpp2 = (TTree*)fpp2->Get("ntjet"); TTree *jetpp1_v2 = (TTree*)fpp1_v2->Get("jetR3"); TTree *jetpp2_v2 = (TTree*)fpp2_v2->Get("jetR3"); TTree *evtpp1_v2 = (TTree*)fpp1_v2->Get("evt"); TTree *evtpp2_v2 = (TTree*)fpp2_v2->Get("evt"); jetpp1_v2->AddFriend(evtpp1_v2); jetpp2_v2->AddFriend(evtpp2_v2); //TCut pbpb3 = "abs(eta)<2&&jet55&&!jet65&&!jet80&&chMax/pt>0.01"; TCut pp3 = "abs(eta)<2&&jet40&&!jet60&&!jet80&&chMax/pt>0.01"; //TH1F *hpbpb1 = new TH1F("hpbpb1","",30,0,300); //TH1F *hpbpb2 = new TH1F("hpbpb2","",30,0,300); //TH1F *hpbpb3 = new TH1F("hpbpb3","",30,0,300); //TH1F *hpbpbComb = new TH1F("hpbpbComb","",30,0,300); TH1F *hpp1 = new TH1F("hpp1","",nbins_jetPtBin,boundaries_jetPtBin); TH1F *hpp2 = new TH1F("hpp2","",nbins_jetPtBin,boundaries_jetPtBin); TH1F *hpp3 = new TH1F("hpp3","",nbins_jetPtBin,boundaries_jetPtBin); TH1F *hppComb = new TH1F("hppComb","",nbins_jetPtBin,boundaries_jetPtBin); //get the prescl factor information. //Float_t presclpbpb3 = (Float_t)jetpbpb1_v2->GetEntries("jet80")/jetpbpb1_v2->GetEntries("jet55&&jet80"); //cout<<"pbpb prescl3 = "<<presclpbpb3<<endl;//1.99871 Float_t presclpp3 = (Float_t)jetpp1_v2->GetEntries("jet80")/jetpp1_v2->GetEntries("jet40&&jet80"); cout<<"pp prescl3 = "<<presclpp3<<endl; //9.24968 /* jetpbpb1_v2->Project("hpbpb1","pt","abs(eta)<2&&jet80&&chMax/pt>0.01"); hpbpb1->Print("base"); divideBinWidth(hpbpb1); jetpbpb2_v2->Project("hpbpb2","pt","abs(eta)<2&&jet65&&!jet80&&chMax/pt>0.01"); hpbpb2->Print("base"); divideBinWidth(hpbpb2); jetpbpb3_v2->Project("hpbpb3","pt","1.9987"*pbpb3); hpbpb3->Print("base"); divideBinWidth(hpbpb3); */ jetpp1_v2->Project("hpp1","pt","abs(eta)<2&&jet80&&chMax/pt>0.01"); hpp1->Print("base"); //divideBinWidth(hpp1); //hpp1->Scale(1./3.083e11); //hpp1->Scale(1./4); jetpp2_v2->Project("hpp2","pt","abs(eta)<2&&jet60&&!jet80&&chMax/pt>0.01"); hpp2->Print("base"); //divideBinWidth(hpp2); //hpp2->Scale(1./3.083e11); //hpp2->Scale(1./4); jetpp2_v2->Project("hpp3","pt","9.25038"*pp3); //9.25038 - ak5 //9.24955 - ak4 //9.24968 - ak3 hpp3->Print("base"); //divideBinWidth(hpp3); //hpp3->Scale(1./3.083e11); //hpp3->Scale(1./4); //scale the PbPb histograms before adding them //we have to scale them according to the lumi of the Jet80 file. // HLT file | Lumi // HLT_80 | 150 mub-1 // HLT_65 | 12.1 mub-1 // HLT_55 | 0.38 mub-1 // // therefore scale for HLT_55 = 150/0.38 = 394.73684 // scale for HLT_65 = 150/12.1 = 12.3967 //hpbpb2->Scale(12.3867); //hpbpb3->Scale(394.7368); //add the histograms /* hpbpbComb->Add(hpbpb1,1); hpbpbComb->Add(hpbpb2,1); hpbpbComb->Add(hpbpb3,1); hpbpbComb->Print("base"); */ hppComb->Add(hpp1,1); hppComb->Add(hpp2,1); hppComb->Add(hpp3,1); hppComb->Print("base"); /* TCanvas *c1 = new TCanvas("c1","",800,600); c1->SetLogy(); hpbpbComb->SetMarkerStyle(29); //hpbpbComb->SetYTitle("#frac{dN}{N_{MB} d p_{T} d #eta}"); hpbpbComb->SetYTitle("counts"); hpbpbComb->SetXTitle("Jet p_{T} GeV/c"); TF1 *fPowerLaw = new TF1("fPowerLaw","[0]*pow(x+[1],[2])"); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Draw(); hpbpb3->SetMarkerStyle(24); hpbpb3->SetMarkerColor(kRed); hpbpb3->Draw("same"); hpbpb2->SetMarkerStyle(25); hpbpb2->SetMarkerColor(kBlue); hpbpb2->Draw("same"); hpbpb1->SetMarkerStyle(26); hpbpb1->SetMarkerColor(kGreen); hpbpb1->Draw("same"); TLegend *title = myLegend(0.54,0.65,0.85,0.9); title->AddEntry(hpbpbComb,"PbPb Merged","pl"); title->AddEntry(hpbpb3,"w_{3} * (HLT_55 && !HLT_65 && !HLT_80)","pl"); title->AddEntry(hpbpb2,"HLT_65 && !HLT_80","pl"); title->AddEntry(hpbpb1,"HLT_80","pl"); title->SetTextSize(0.03); title->Draw(); drawText("PbPb 2011, 55,65 scaled",0.3,0.65,20); drawText("Anti-k_{T} PU PF Jets R = 0.3, |#eta|<2, |vz|<15",0.3,0.56,20); c1->SaveAs("pbpb_2013_pt_combined.gif","RECREATE"); */ //plot the statistical uncertainty here //statistical error/meanvalue as a function of pt for the combined spectra. /* TCanvas *c2 = new TCanvas("c2","",800,600); //TH1F* hPbPb_Uncert = (TH1F*)hpbpbComb->Clone("hPbPb_Uncert"); TH1F* hPbPb_Uncert = new TH1F("hPbPb_Uncert","",30,0,300); for(int i = 1;i<=hpbpbComb->GetNbinsX();i++){ double val = hpbpbComb->GetBinContent(i); double valErr = hpbpbComb->GetBinError(i); double uncert = (double)valErr/val; cout<<"uncert = "<<uncert<<endl; hPbPb_Uncert->SetBinContent(i,uncert); hPbPb_Uncert->SetBinError(i,0); } hPbPb_Uncert->SetYTitle("uncertainty"); hPbPb_Uncert->SetXTitle("p_{T} GeV/c"); hPbPb_Uncert->Draw(); drawText("PbPb 2011, 55,65 scaled",0.3,0.65,20); drawText("Anti-k_{T} PU PF Jets R = 0.3, |#eta|<2, |vz|<15",0.3,0.56,20); c2->SaveAs("pbpb_2013_hlt_merge_scaled_uncert.gif","RECREATE"); */ TCanvas *c2 = new TCanvas("c2","",800,600); c2->SetLogy(); TH1F* hPPComb = (TH1F*)hppComb->Clone("hPPComb"); //TH1F* hPPComb_bins = rebin_yaxian(hppComb,"hPPComb_bins"); hPPComb->Scale(1./3.083e11); hPPComb->Print("base"); hPPComb->SetYTitle("#frac{dN}{N_{MB} d p_{T} d #eta}"); hPPComb->SetXTitle("Jet p_{T} GeV/c"); //hPPComb_bins->Scale(1./3.083e11); //hPPComb_bins->Print("base"); //hPPComb_bins->Scale(1./4); //divideBinWidth(hPPComb_bins); hPPComb->Scale(1./4); divideBinWidth(hPPComb); TF1 *fPowerLaw = new TF1("fPowerLaw","[0]/pow(x,[1])"); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->SetMarkerColor(kBlue); hPPComb->SetMarkerStyle(26); hPPComb->SetTitle("PP2013 ak3PF"); hPPComb->Draw(); //hPPComb_bins->SetMarkerColor(kRed); //hPPComb_bins->SetMarkerStyle(23); //hPPComb_bins->Draw("same"); c2->SaveAs("pp_2013_ak3_pt_evt_frac_merged.gif","RECREATE"); TCanvas *c5 = new TCanvas("c5","",800,600); TH1F* hppFunc = (TH1F*)functionHist(fPowerLaw,hppComb,"Fit Function p_{T} spectra PP 2013 merged"); TH1F* hPPRatio = (TH1F*)hppComb->Clone("hPPRatio"); hPPRatio->Divide(hppFunc); hPPRatio->SetTitle("Spectra to Fit Ratio"); hPPRatio->SetXTitle("Jet p_{T} GeV/c"); hPPRatio->SetYTitle("Measured data/Fit"); hPPRatio->SetMarkerStyle(8); hPPRatio->SetMarkerColor(4); hPPRatio->Draw(); c5->SaveAs("pp_2013_merged_spectra_fit_comp.gif","RECREATE"); TFile *fpbpbunfo = TFile::Open("result-2013-akPu3PF-cent-6-isFineBin-0/pbpb_pp_merged_chmx_pt_Unfo_2013_akPu3PF_cent_6_isFineBin_0.root"); TH1F* hppUnfo = (TH1F*)fpbpbunfo->Get("Unfolded_cent6"); TH1F* hPPGen = (TH1F*)fpbpbunfo->Get("hGen_cent6"); hppUnfo->Print("base"); hPPGen->Print("base"); hPPGen->Scale(1./4); divideBinWidth(hPPGen); hppUnfo->Scale(1./3.083e11); hppUnfo->Scale(1./4); divideBinWidth(hppUnfo); hppUnfo->Divide(hPPGen); TCanvas *c6 = new TCanvas("c6","",800,600); hppUnfo->SetMarkerStyle(21); hppUnfo->SetMarkerColor(kRed); hPPGen->SetMarkerStyle(21); hPPGen->SetMarkerColor(kBlue); hppUnfo->Draw(); // hPPGen->Draw("same"); c6->SaveAs("pp_2760GeV_unfold_vs_mc.gif","RECREATE"); /* TCanvas *c7 = new TCanvas("c7","",800,600); c7->SetLogy(); hPPComb->Draw(); hPPComb->SetYTitle(""); hPPComb->SetXTitle("p_{T} GeV/c"); //hppComb->SetTitle("PP 2013 2.76 TeV ak4PF measured vs unfolded"); hPPComb->SetMarkerStyle(23); hPPComb->SetMarkerColor(kBlue); //hppUnfo->SetAxisRange(10,500,"X"); //hppUnfo->SetMarkerStyle(24); //hppUnfo->SetMarkerColor(kRed); //hppUnfo->Draw("same"); TLegend *title5 = myLegend(0.54,0.65,0.85,0.9); title5->AddEntry(hppComb,"Measured","pl"); title5->AddEntry(hppUnfo,"Bayesian iter = 4","pl"); title5->SetTextSize(0.06); title5->Draw(); gStyle->SetOptStat(0); c7->SaveAs("PP2013_measured_vs_unfolded.gif","RECREATE"); //TCanvas */ //Create output file and save them. TFile f("merge_pp_ak3_HLT_V2.root","RECREATE"); //hpbpb1->Write(); //hpbpb2->Write(); //hpbpb3->Write(); //hPPComb_bins->Write(); hpp1->Write(); hpp2->Write(); hpp3->Write(); //hpbpbComb->Write(); hppComb->Write(); //hPPComb->Write(); //hPbPb_Uncert->Write(); hPPComb->Write(); hPPGen->Write(); f.Close(); }
void test(int numbersigmas = 0, Bool_t debugtest = true) { using namespace RooFit; using namespace std; TCanvas *canvas = new TCanvas("canvas","canvas",900,100,500,500); gSystem->Load("libRooFit"); gSystem->AddIncludePath("-I$ROOFITSYS/include"); float ptbinsarray[] = {20.,40.,60.,80.,100.,120.,200.,600.}; std::vector<float> ptbins(ptbinsarray,ptbinsarray+sizeof(ptbinsarray)/sizeof(ptbinsarray[0])); std::vector<std::vector<float> > allbins; allbins.push_back(ptbins); std::vector<TString> VarString; VarString.push_back("VsPt"); std::vector<TString> HistoNameString; HistoNameString.push_back("ptbin"); std::vector<TString> GraphXTitleString; GraphXTitleString.push_back("p_{t} (GeV)"); std::vector<TString> SideBandDefinitions; SideBandDefinitions.push_back("SideBand5_10"); // ------------FOR TESTING---------------- unsigned int sidebandloopmax = 1;//5_10, 5_20, ... unsigned int templatevarsloopmax = 1;//sinin with conv safe veto, sinin, ch isol unsigned int binsloopmax = 1;//pt, eta, phi, pu //----------Open .root Templates //All the Jet Templates TFile *histojetfile = TFile::Open("/afs/cern.ch/user/c/ciperez/CMSSW_7_4_5/src/TemplateHistosJetCheckBinsEndcapsLoose.root"); //TFile *histojetdenfile = TFile::Open("/afs/cern.ch/user/c/ciperez/CMSSW_7_4_5/src/Denominator_FREndCaps.root"); // TFile *histojetdatafile = TFile::Open("/afs/cern.ch/user/c/ciperez/CMSSW_7_4_5/src/Num_Templates.root"); //Real Photon Templates TFile *historealmcfile = TFile::Open("/afs/cern.ch/user/c/ciperez/CMSSW_7_4_5/src/RealPhotonTemplatesEndCaps.root"); //--- Write NEW .root Historams for Fake Rate TFile *FRhistosfile = new TFile("FakeRatePlotsCheckBins.root","recreate"); //loop on error systematics for(unsigned int m = 0; m<templatevarsloopmax; m++) { for(unsigned int l = 0; l<binsloopmax; l++) { TMultiGraph *mg = new TMultiGraph(); TLegend *legendAllGraphs = new TLegend(0.37,0.59,0.57,0.79); legendAllGraphs->SetTextSize(0.02); legendAllGraphs->SetFillColor(kWhite); legendAllGraphs->SetLineColor(kWhite); std::vector<float> fakeratevalues; std::vector<float> fakerateptvalues; std::vector<float> fakerateerrorvalues; for(unsigned int k = 0; k<allbins[0].size()-1; k++) { // for(unsigned int k = 0;k<1;k++){ float binlow = allbins[0][k]; float binmax = allbins[0][k+1]; TString binstring = TString::Format("%4.2f_%4.2f",binlow,binmax); binstring.ReplaceAll(".00",""); binstring.ReplaceAll("-","m"); binstring.ReplaceAll(".","p"); binstring.ReplaceAll("10000","Inf"); cout<<binstring.Data()<<endl; //Histograms for templates //Get histograms from each of the histojetfiles declared earlier //Numerator Fakes - FakePhotonNumEndCaps.root - FakePhoton_num2040... TH1F *h1 = (TH1F*)histojetfile->Get(("histoSininWithPixelSeedFakeJetptbin"+binstring).Data());// .Data() changes to char* h1->Print(); //Numerator Real Photons - RealPhotonTemplatesEndCaps.root - EndCapsMCReal_20_40 TH1F *h2 = (TH1F*)historealmcfile->Get(("EndCapsMCReal_"+binstring).Data()); h2->Print(); //Numerator Templates - Num_Templates.root - num2040... TH1F *hData = (TH1F*)histojetfile->Get(("histoSininWithPixelSeedDataJetptbin"+binstring).Data()); hData->Print(); //Denominator Templates - Denominator_FREndCaps.root -FakePhoton_den2040... TH1F *hnum = (TH1F*)histojetfile->Get(("histoSininWithPixelSeedTightAndFakeJetptbin"+binstring).Data()); hnum->Print(); //avoiding 0 entries in the histograms //fake and real mc histos are the most critical for(int bincount = 1; bincount <= h1->GetNbinsX(); bincount++) { if(h1->GetBinContent(bincount) == 0.) h1->SetBinContent(bincount,1.e-6); } for(int bincount = 1; bincount <= h2->GetNbinsX(); bincount++) { if(h2->GetBinContent(bincount) == 0.) h2->SetBinContent(bincount,1.e-6); } int ndataentries = hData->GetEntries(); float sininmin = 0.; //? sigmaIetaIeta float sininmax = 0.1; //? sigmaIetaIeta // ----------------- Probability Density Function TString roofitvartitle = "#sigma_{i #eta i #eta}"; RooRealVar sinin("sinin",roofitvartitle.Data(),sininmin,sininmax); sinin.setRange("sigrange",0.018,0.06); //? this is the range because? Need to recall. //sinin.setRange("sigrange",0.005, 0.011); //Fake Template pdf RooDataHist faketemplate("faketemplate","fake template",sinin,h1); RooHistPdf fakepdf("fakepdf","test hist fake pdf",sinin,faketemplate); //Real Template pdf RooDataHist realtemplate("realtemplate","real template",sinin,h2); RooHistPdf realpdf("realpdf","test hist real pdf",sinin,realtemplate); //Data to be fitted to RooDataHist data("data","data to be fitted to",sinin,hData); //Declaration of Variables for Fake Rate RooRealVar fsig("fsig","signal fraction",0.1,0,1);// RooRealVar signum("signum","signum",0,ndataentries);// #of real contamination RooRealVar fakenum("fakenum","fakenum",0,ndataentries); //# of fake //Extend RooExtendPdf extpdfsig("Signal","extpdfsig",realpdf,signum,"sigrange"); RooExtendPdf extpdffake("Background","extpdffake",fakepdf,fakenum,"sigrange"); RooAddPdf model("model","sig + background",RooArgList(extpdfsig,extpdffake)); //----------- FITTING TO DATA ------------------- model.fitTo(data,RooFit::Minos()); //Define Plot Frame RooPlot *xframe = sinin.frame(); xframe->SetTitle(""); data.plotOn(xframe); model.plotOn(xframe); model.plotOn(xframe,Components(extpdfsig),LineColor(2),LineStyle(2)); model.plotOn(xframe,Components(extpdffake),LineColor(8),LineStyle(2)); canvas->cd(); canvas->SetGridx(true); canvas->SetGridy(true); xframe->GetXaxis()->SetRangeUser(0.,0.1); float xframemax = xframe->GetMaximum(); xframe->GetYaxis()->SetRangeUser(1.e-1,1.1*xframemax); xframe->Draw(); // ----- DEFINE LEGENDS and their position TLegend *legend = new TLegend(0.62,0.65,0.82,0.85); //Why these values? legend->SetTextSize(0.02); legend->SetFillColor(kWhite); legend->SetLineColor(kWhite); //Legend Header which tells the bin TString legendheader = "Pt (GeV):["+ binstring; legendheader.ReplaceAll("_",","); legendheader.ReplaceAll("m","-"); legendheader.ReplaceAll("p","."); legendheader.Append("]"); cout<<"legend "<<legendheader.Data()<<endl; legend->SetHeader(legendheader.Data()); TObject *objdata; //What is TObect? TObject *objmodel; TObject *objsignal; TObject *objfake; for(int i=0; i<xframe->numItems(); i++) { cout<<xframe->nameOf(i)<<endl; TString objname = xframe->nameOf(i); if(objname.Contains("data")) objdata = (TObject*)xframe->findObject(objname.Data()); if(objname.Contains("model") && !objname.Contains("Comp")) objmodel = (TObject*)xframe->findObject(objname.Data()); if(objname.Contains("model") && objname.Contains("Signal")) objsignal = (TObject*)xframe->findObject(objname.Data()); if(objname.Contains("model") && objname.Contains("Background")) objfake = (TObject*)xframe->findObject(objname.Data()); } //------ LEGEND -------- legend->AddEntry(objdata,"Data","lp"); legend->AddEntry(objsignal,"Signal","l"); legend->AddEntry(objfake,"Background","l"); legend->AddEntry(objmodel,"Signal + Background","l"); legend->Draw("same");//make them overlap for comparison canvas->Print(("Endcapfits"+binstring+".png").Data()); canvas->Print(("TemplateFitResultEndcap"+binstring+".C").Data()); float fakevalue = fakenum.getValV(); float fakeerrorhi = fakenum.getErrorHi(); float fakeerrorlo = fakenum.getErrorLo(); float fakeerrormax = max(fabs(fakeerrorhi),fabs(fakeerrorlo)); TString fakeresults = TString::Format("Fake results %f +%f %f",fakevalue,fakeerrorhi,fakeerrorlo); canvas->SetLogy(0); float sigvalue = signum.getValV(); float sigerrorhi = signum.getErrorHi(); float sigerrorlo = signum.getErrorLo(); float sigerrormax = max(fabs(sigerrorhi),fabs(sigerrorlo)); TString sigresults = TString::Format("Signal results %f +%f %f",sigvalue,sigerrorhi,sigerrorlo); cout<<"sigvalue "<<sigvalue<<" sigerrormax "<<sigerrormax<<" sigerrormax/sigvalue "<<sigerrormax/sigvalue<<endl; cout<<"fakevalue "<<fakevalue<<" fakeerrormax "<<fakeerrormax<<" fakeerrormax/fakevalue "<<fakeerrormax/fakevalue<<endl; cout<<fakeresults.Data()<<endl; cout<<sigresults.Data()<<endl; float Ratio = (fakevalue/(fakevalue+sigvalue)); float RatioError = Ratio*sqrt( ((fakeerrormax/fakevalue)*(fakeerrormax/fakevalue) + (sigerrormax/sigvalue)*(sigerrormax/sigvalue)) ); cout<<"Ratio "<<Ratio<<" +- "<<RatioError<<endl; //---------------------- FAKE RATE CALCULATOR ------------------------- //find the bin corresponding to 0.011 //int binnr = 22; int binnr = 34; //compute the integral of tight and fake in that range float numerator = hData->Integral(0,binnr); //Is the Integral function part of RooFit? float denominator = hnum->Integral(); float contamination = sigvalue; cout<<numerator<<" "<<denominator<<" "<<contamination<<endl; float fakerate = (numerator-contamination)/denominator; float fakerateerror = fakerate * sqrt( (1./numerator) + (1./denominator) + ((sigerrormax/sigvalue)*(sigerrormax/sigvalue)) ); cout<<"Here: "<<fakerate<<" "<<fakerateerror<<endl; //fakerateptvalues.push_back(hnumvspt->GetMean()); fakeratevalues.push_back(fakerate); fakerateerrorvalues.push_back(fakerateerror); cout<<""<<endl; cout<<"***********************************************************"<<endl; cout<<"So in sigmaietaieta < 0.011 there are "<<contamination<<" to subtract from "<<numerator<<endl; cout<<"and thus there are "<<(numerator-contamination)<<" total tight entries "<<endl; cout<<"and there are "<<denominator<<" entries in the tight and fake sample "<<endl; cout<<"and so the fake rate for the pt range "<<binlow<<"-"<<binmax<<" is "<<fakerate<<"+-"<<fakerateerror<<endl; cout<<"***********************************************************"<<endl; cout<<""<<endl; }//loop on all bins /* cout<<fakeratevalues.size()<<endl; for(int k=0;k<fakeratevalues.size();k++){ cout<<"Range: ["<<allbins[l][k]<<"-"<<allbins[l][k+1]<<"] --> fake rate: ("<<fakeratevalues[k]*100<<" +- "<<fakerateerrorvalues[k]*100<<")%"<<endl; }//end of loop over all fake rate values // *************************************************************-// // TGraphErrors *FRgraph = new TGraphErrors(fakeratevalues.size()); for(int k=0;k<fakeratevalues.size();k++){ cout<<(allbins[l][k+1]+allbins[l][k])/2.<<endl; FRgraph->SetPoint(k,(allbins[l][k+1]+allbins[l][k])/2.,fakeratevalues[k]); FRgraph->SetPointError(k,(allbins[l][k+1]-allbins[l][k])/2.,fakerateerrorvalues[k]); }//end of filling TGraph //// FRGraph->SetName(FakeRate.Data()); FRgraph->SetTitle(""); canvas->cd(); canvas->SetLogy(0); FRgraph->Draw("a*"); // **********************************************************-// // ***************************************** //float maxFRvalue = max_element(fakeratevalues.begin(),fakeratevalues.end()); FRgraph->GetYaxis()->SetRangeUser(0.,0.2); FRgraph->GetYaxis()->SetTitle("#epsilon_{FR}"); FRgraph->GetXaxis()->SetTitle((GraphXTitleString[l]).Data()); TString FakeRateFunctionName = " TF1 *FRfunc = new TF1(FakeRateFunctionName.Data(),"[0]+[1]/pow(x,[2])", allbins[l][0],allbins[l][fakeratevalues.size()]); FRfunc->SetParameters(1.,1.,1.); if(l==0){ FRgraph->Fit(FakeRateFunctionName.Data(),"R"); FRgraph->Fit(FakeRateFunctionName.Data()); FRfunc->Draw("same"); } // ******************************************** cout<<"***** Fit function parameters *****"<<endl; cout<<FRfunc->GetParameter(0)<<" " <<FRfunc->GetParameter(1)<<" " <<FRfunc->GetParameter(2)<<" " <<endl; cout<<"***** Fit function errors *****"<<endl; cout<<FRfunc->GetParError(0)<<" " <<FRfunc->GetParError(1)<<" " <<FRfunc->GetParError(2)<<" " <<endl; if(!debugtest){ canvas->Print(("FakeRateJetRun2012ABCD13JulLoose.png").Data(),"png"); canvas->Print(("FakeRateJetRun2012ABCD13JulLoose.gif").Data(),"gif"); canvas->Print(("FakeRateJetRun2012ABCD13JulLoose.eps").Data(),"eps"); canvas->Print(("FakeRateJetRun2012ABCD13JulLoos.pdf").Data(),"pdf"); canvas->Print(("FakeRateJetRun2012ABCD13JulLoose.C").Data(),"cxx"); } canvas->Print(("FakeRateEndCaps.png").Data(),"png"); canvas->Print(("FakeRateEndCaps.C").Data(),"cxx"); // ************************************************ if(!debugtest){ if(count == 0){ FRhistosfile->cd(); FRgraph->Write(); FRfunc->Write(); } } if(numbersigmas != 0){ FRgraph->SetLineColor(count+numbersigmas+1); FRgraph->SetMarkerColor(count+numbersigmas+1); TString numsigmastring = TString::Format("%d #sigma",count); legendAllGraphs->AddEntry(FRgraph,numsigmastring.Data(),"lep"); } mg->Add(FRgraph);*/ // }//end of loop over systematic errors if(numbersigmas != 0) { mg->Draw(); legendAllGraphs->Draw("same"); } }//end of loop over all variables (pt, eta, phi, pu) }//end of loop over template variables histojetfile->cd(); histojetfile->Close(); historealmcfile->cd(); historealmcfile->Close(); FRhistosfile->cd(); FRhistosfile->Close(); // }//end of loop over sideband definitions }//end of method
void RAA_dataDrivenUnfoldingErrorCheck_new(int radius = 3, bool isATLASCut = true) { TStopwatch timer; timer.Start(); TH1::SetDefaultSumw2(); TH2::SetDefaultSumw2(); bool printDebug = true; bool dofakeremove = false; bool do10GeVBins = true; char * scale = (char*)"NeqScale"; // 944Scale // NeqScale // NeqScalePerCent int unfoldingCut = 20; char * outLocation = (char*) "July20/"; if(isATLASCut) outLocation = (char*)"July20/ATLASCut/"; // get the data and mc histograms from the output of the read macro. TDatime date;//this is just here to get them to run optimized. // Pawan's files: //TFile * fPbPb_in = TFile::Open(Form("Pawan_TTree_PbPb_Data_MC_subid0_spectra_JetID_CutA_finebins_%s_R0p%d.root", etaWidth, radius)); //TFile * fPbPb_in = TFile::Open(Form("Pawan_TTree_PbPb_Data_MC_subid0_spectra_JetID_CutA_muMaxOverSumcandMaxLT0p975_finebins_%s_R0p%d.root", etaWidth, radius)); //TFile * fPbPb_in = TFile::Open(Form("Pawan_TTree_PbPb_Data_MC_subid0_spectra_JetID_CutA_trkMaxOverpfptGT0p02_finebins_%s_R0p%d.root", etaWidth, radius)); //TFile * fPbPb_in = TFile::Open(Form("Pawan_TTree_PbPb_Data_noPrescl_MC_subid0_spectra_JetID_CutA_finebins_%s_R0p%d.root", etaWidth, radius)); //TFile * fPbPb_in = TFile::Open(Form("Pawan_TTree_PbPb_Data_noPrescl_MC_subid0_spectra_JetID_CutA_7GeVTrackCut_finebinscut_%s_R0p%d.root", etaWidth, radius)); // get the files to perform MC closure from the fixed ntuples TFile * fPbPb_in, *fMinBias, *fPbPb_MC_in, * fTrig; if(isATLASCut) fPbPb_in = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_Data_histograms_FromForest_trkMax7OrNeMax8GeVCut_akPu%d_20_eta_20.root",radius),"r"); if(!isATLASCut) fPbPb_in = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_Data_histograms_FromForest_akPu%d_20_eta_20.root",radius),"r"); if(isATLASCut) fMinBias = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_MB_Data_histograms_FromForest_trkMax7OrNeMax8GeVCut_fix_pt15GeVCut_akPu%d_20_eta_20.root",radius)); if(!isATLASCut) fMinBias = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_MB_Data_histograms_FromForest_fix_pt15GeVCut_akPu%d_20_eta_20.root",radius)); //TFile * fPbPb_MC_in = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_MC_histograms_FromForest_pthat50andabove_akPu%d_20_eta_20.root",radius)); if(isATLASCut) fPbPb_MC_in = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_MC_histograms_FromForest_trkMax7OrNeMax8GeVCut_akPu%d_20_eta_20.root",radius),"r"); if(!isATLASCut) fPbPb_MC_in = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_MC_histograms_FromForest_akPu%d_20_eta_20.root",radius),"r"); TFile * fPP_in = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/pp_Data_histograms_FromForest_ak%d_20_eta_20.root",radius),"r"); TFile * fPP_MC_in = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/pp_MC_histograms_FromForest_ak%d_20_eta_20.root",radius),"r"); if(isATLASCut) fTrig = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_Data_nofkSub_trkMax7OrNeMax8GeVCut_new_MC_turnonCurves_R%d_20_eta_20_20150715.root",radius),"r"); if(!isATLASCut) fTrig = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_Data_nofkSub_new_MC_turnonCurves_R%d_20_eta_20_20150715.root",radius),"r"); TFile * fTrig_pp = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/pp_MC_turnonCurves_R%d_20_eta_20_20150702.root", radius),"r"); // TFile * fPPMCTrig = new TFile(Form("PP_Data_MC_turnonCurves_R%d_20_eta_20_20150618.root",radius),"r"); TH1F * hMC_turnon[nbins_cent+1], * hData_turnon[nbins_cent+1]; cout<<"after input file declaration"<<endl; // histogram declarations with the following initial appendage: d - Data, m - MC, u- Unfolded // for the MC closure test, ive kept separate TH1F *dPbPb_TrgComb[nbins_cent+1], *dPbPb_TrgCombInput[nbins_cent+1], *dPbPb_Comb[nbins_cent+1], *dPbPb_Trg80[nbins_cent+1], *dPbPb_Trg65[nbins_cent+1], *dPbPb_Trg55[nbins_cent+1], *dPbPb_1[nbins_cent+1], *dPbPb_2[nbins_cent+1], *dPbPb_3[nbins_cent+1], *dPbPb_80[nbins_cent+1], *dPbPb_65[nbins_cent+1], *dPbPb_55[nbins_cent+1]; TH1F *mPbPb_GenInput[nbins_cent+1], *mPbPb_RecoInput[nbins_cent+1]; TH1F *mPbPb_Gen[nbins_cent+1], *mPbPb_Reco[nbins_cent+1]; TH2F *mPbPb_Matrix[nbins_cent+1], * mPbPb_MatrixInput[nbins_cent+1], *mPbPb_Response[nbins_cent+1], *mPbPb_ResponseNorm[nbins_cent+1]; TH1F *mPbPb_mcclosure_data[nbins_cent+1]; TH2F *mPbPb_mcclosure_Matrix[nbins_cent+1],*mPbPb_mcclosure_Response[nbins_cent+1], *mPbPb_mcclosure_ResponseNorm[nbins_cent+1]; TH1F *mPbPb_mcclosure_gen[nbins_cent+1]; const int Iterations = 20; //for unfolding systematics. const int BayesIter = 4; TH1F *uPbPb_Bayes[nbins_cent+1], *uPbPb_BinByBin[nbins_cent+1], *uPbPb_SVD[nbins_cent+1]; TH1F *uPbPb_BayesianIter[nbins_cent+1][Iterations]; TH1F *dPbPb_MinBias[nbins_cent]; TH1F *hMinBias[nbins_cent]; TH1F *dPP_1, *dPP_2, *dPP_3, *dPP_Comb, * dPP_CombInput; TH1F *mPP_Gen, *mPP_Reco, *mPP_GenInput, *mPP_RecoInput; TH2F *mPP_Matrix, *mPP_MatrixInput, *mPP_Response,*mPP_ResponseNorm; TH1F *mPP_mcclosure_data; TH2F *mPP_mcclosure_Matrix, *mPP_mcclosure_Response,*mPP_mcclosure_ResponseNorm; TH1F *mPP_mcclosure_Gen; TH1F *uPP_Bayes, *uPP_BinByBin, *uPP_SVD; TH1F *uPP_BayesianIter[Iterations]; TH1F * hData_FaketoSub_fullbin[nbins_cent+1]; // would be better to read in the histograms and rebin them. come to think of it, it would be better to have them already rebinned (and properly scaled - to the level of differential cross section in what ever barns (inverse micro barns) but keep it consistent) from the read macro. if(radius == 2) unfoldingCut = unfoldingCut_R2; if(radius == 3) unfoldingCut = unfoldingCut_R3; if(radius == 4) unfoldingCut = unfoldingCut_R4; // TH1F * htest = new TH1F("htest","",nbins, ptbins_long); // Int_t unfoldingCutBin = htest->FindBin(unfoldingCut); //Float_t cutarray[6]={50,50,40,35,35,35}; float cutarray[nbins_cent] = {0.0,0.0,0.0,0.0,0.0,0.0}; if(radius == 2){ cutarray[0] = 50; cutarray[1] = 40; cutarray[2] = 40; cutarray[3] = 40; cutarray[4] = 30; cutarray[5] = 30; } if(radius == 3){ cutarray[0] = 55; cutarray[1] = 50; cutarray[2] = 50; cutarray[3] = 40; cutarray[4] = 35; cutarray[5] = 40; } if(radius == 4){ cutarray[0] = 70; cutarray[1] = 60; cutarray[2] = 60; cutarray[3] = 45; cutarray[4] = 40; cutarray[5] = 30; } TH1F * hDataBeforeSub[nbins_cent], * hDataAfterSub[nbins_cent]; // get PbPb data for(int i = 0;i<nbins_cent;++i){ if(printDebug) cout<<"cent_"<<i<<endl; hData_turnon[i] = (TH1F*)fTrig->Get(Form("hHist_Data_Turnon_cent%d",i)); hData_turnon[i] = (TH1F*)hData_turnon[i]->Rebin(nbins_short, Form("hData_turnon_cent%d",i), boundaries_short); //hData_turnon[i] = (TH1F*)hData_turnon[i]->Rebin(10); divideBinWidth(hData_turnon[i]); // hMinBias[i] = (TH1F*)fMinBias->Get(Form("hpbpb_noTrg_R%d_%s_cent%d",radius,etaWidth,i)); //MinBias Histo hMinBias[i] = (TH1F*)fMinBias->Get(Form("hpbpb_HLTMBwoLJSbJ_R%d_%s_cent%d",radius,etaWidth,i)); //MinBias Histo hMinBias[i]->Print("base"); dPbPb_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLTComb_%s_R%d_%s_cent%d",scale, radius,etaWidth,i)); //dPbPb_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT80_R%d_%s_cent%d",radius,etaWidth,i)); //dPbPb_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT65_R%d_%s_cent%d",radius,etaWidth,i)); //dPbPb_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT55_R%d_%s_cent%d",radius,etaWidth,i)); // dPbPb_TrgComb[i]->Scale(1./(1+0.898+0.494)/1e16); // //dPbPb_TrgComb[i]->Scale(4*145.156*1e6); dPbPb_TrgComb[i]->Print("base"); hDataBeforeSub[i] = (TH1F*)dPbPb_TrgComb[i]->Clone(Form("hData_Before_Sub_cent%d",i)); //dPbPb_TrgComb[i] = (TH1F*)fPbPb_DataCorr_in->Get(Form("Data_TrigEffCorrected_FakeSub_cent%d",i)); //dPbPb_TrgComb[i]->Print("base"); // dPbPb_JEC_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_JEC_HLTComb_R%d_%s_cent%d",radius,etaWidth,i)); // // //dPbPb_TrgComb[i]->Scale(4*145.156*1e6); // dPbPb_JEC_TrgComb[i]->Print("base"); // dPbPb_Smear_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_Smear_HLTComb_R%d_%s_cent%d",radius,etaWidth,i)); // // //dPbPb_TrgComb[i]->Scale(4*145.156*1e6); // dPbPb_Smear_TrgComb[i]->Print("base"); // dPbPb_Trg80[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT80_R%d_%s_cent%d",radius,etaWidth,i)); // //dPbPb_Trg80[i]->Scale(4*145.156*1e6); // dPbPb_Trg80[i]->Print("base"); // dPbPb_Trg65[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT65_R%d_%s_cent%d",radius,etaWidth,i)); // //dPbPb_Trg65[i]->Scale(4*145.156*1e6); // dPbPb_Trg65[i]->Print("base"); // dPbPb_Trg55[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT55_R%d_%s_cent%d",radius,etaWidth,i)); // //dPbPb_Trg55[i]->Scale(4*145.156*1e6); // dPbPb_Trg55[i]->Print("base"); // if(dotrigcor){ // doTrigCorr(dPbPb_TrgComb[i], hData_turnon[i]); // doTrigCorr(dPbPb_JEC_TrgComb[i], hData_turnon[i]); // doTrigCorr(dPbPb_Smear_TrgComb[i], hData_turnon[i]); // } //Lets do the subtraction here _Sevil // Float_t bincon=cutarray[i]; // Int_t bincut= hMinBias[i]->FindBin(bincon); // for(int k = bincut;k<=hMinBias[i]->GetNbinsX();k++) { // hMinBias[i]->SetBinContent(k,0); // hMinBias[i]->SetBinError(k,0); // } // for(int k = 1;k<=15;k++) { // hMinBias[i]->SetBinContent(k,0); // hMinBias[i]->SetBinError(k,0); // } Float_t bin_no = dPbPb_TrgComb[i]->FindBin(15); Float_t bin_end=dPbPb_TrgComb[i]->FindBin(25); Float_t bin_nomb = hMinBias[i]->FindBin(15); Float_t bin_endmb=hMinBias[i]->FindBin(25); float scalerangeweight=dPbPb_TrgComb[i]->Integral(bin_no,bin_end)/hMinBias[i]->Integral(bin_nomb,bin_endmb); // for(int j = 0; j<hMinBias[i]->GetNbinsX(); ++j) // hMinBias[i]->SetBinError(j+1, (Float_t)hMinBias[i]->GetBinError(j+1)/scalerangeweight); hMinBias[i]->Scale(scalerangeweight); if(dofakeremove) dPbPb_TrgComb[i]->Add(hMinBias[i], -1); hDataAfterSub[i] = (TH1F*)dPbPb_TrgComb[i]->Clone(Form("hData_After_Sub_cent%d",i)); // dPbPb_JEC_TrgComb[i]->Add(hMinBias[i], -1); // dPbPb_Smear_TrgComb[i]->Add(hMinBias[i], -1); // for(int j = 1; j<dPbPb_TrgComb[i]->GetNbinsX(); ++j){ // if(dPbPb_TrgComb[i]->GetBinContent(j) <= 0 ||dPbPb_JEC_TrgComb[i]->GetBinContent(j) <= 0||dPbPb_Smear_TrgComb[i]->GetBinContent(j) <= 0){ // dPbPb_TrgComb[i]->SetBinContent(j, 0); // dPbPb_JEC_TrgComb[i]->SetBinContent(j, 0); // dPbPb_Smear_TrgComb[i]->SetBinContent(j, 0); // dPbPb_TrgComb[i]->SetBinError(j, 0); // dPbPb_JEC_TrgComb[i]->SetBinError(j, 0); // dPbPb_Smear_TrgComb[i]->SetBinError(j, 0); // } // } // // lets truncate the histograms here: // cout<<" going to truncate Data histogram here cent "<<i<<endl; // dPbPb_TrgCombInput[i]->Print("base"); // dPbPb_TrgComb[i] = new TH1F(Form("PbPb_data_minbiasSub_cent%d",i),"",365, 30, 395); // Truncate1D(dPbPb_TrgCombInput[i], dPbPb_TrgComb[i]); // // dPbPb_TrgComb[i] = (TH1F*)Truncate1D(dPbPb_TrgComb[i], 340, unfoldingCutBin, 395); // // dPbPb_TrgComb[i]->Print("base"); //dPbPb_TrgComb[i] = (TH1F*)dPbPb_TrgComb[i]->Rebin(nbins, Form("PbPb_data_minbiasSub_cent%d",i), ptbins_long); dPbPb_TrgComb[i] = (TH1F*)dPbPb_TrgComb[i]->Rebin(10); dPbPb_TrgComb[i]->SetName(Form("PbPb_data_minbiasSub_cent%d",i)); divideBinWidth(dPbPb_TrgComb[i]); hMinBias[i] = (TH1F*)hMinBias[i]->Rebin(10); hDataAfterSub[i] = (TH1F*)hDataAfterSub[i]->Rebin(10); hDataBeforeSub[i] = (TH1F*)hDataBeforeSub[i]->Rebin(10); divideBinWidth(hMinBias[i]); divideBinWidth(hDataAfterSub[i]); divideBinWidth(hDataBeforeSub[i]); dPbPb_TrgComb[i]->Scale(1./(166 * 1e9)); // dPbPb_TrgComb[i]->Print("base"); } if(printDebug)cout<<"loaded the data histograms PbPb"<<endl; // get PbPb MC for(int i = 0;i<nbins_cent;i++){ // mPbPb_GenInput[i] = (TH1F*)fPbPb_MC_in->Get(Form("hpbpb_anaBin_JetComb_gen_R%d_%s_cent%d",radius,etaWidth,i)); // mPbPb_GenInput[i]->Print("base"); // mPbPb_RecoInput[i] = (TH1F*)fPbPb_MC_in->Get(Form("hpbpb_anaBin_JetComb_reco_R%d_%s_cent%d",radius,etaWidth,i)); // mPbPb_RecoInput[i]->Print("base"); // mPbPb_MatrixInput[i] = (TH2F*)fPbPb_MC_in->Get(Form("hpbpb_anaBin_matrix_HLT_R%d_%s_cent%d",radius,etaWidth,i)); // mPbPb_MatrixInput[i]->Print("base"); mPbPb_Gen[i] = (TH1F*)fPbPb_MC_in->Get(Form("hpbpb_JetComb_gen_R%d_%s_cent%d",radius,etaWidth,i)); //mPbPb_Gen[i]->Rebin(nbins, Form("mPbPb_Gen_cent%d",i), ptbins_long); mPbPb_Gen[i]->Rebin(10); divideBinWidth(mPbPb_Gen[i]); mPbPb_Gen[i]->Print("base"); mPbPb_Reco[i] = (TH1F*)fPbPb_MC_in->Get(Form("hpbpb_JetComb_reco_R%d_%s_cent%d",radius,etaWidth,i)); //mPbPb_Reco[i]->Rebin(nbins, Form("mPbPb_Reco_cent%d",i), ptbins_long); mPbPb_Reco[i]->Rebin(10); divideBinWidth(mPbPb_Reco[i]); mPbPb_Reco[i]->Print("base"); mPbPb_Matrix[i] = (TH2F*)fPbPb_MC_in->Get(Form("hpbpb_matrix_HLT_R%d_%s_cent%d",radius,etaWidth,i)); //mPbPb_Matrix[i] = (TH2F*)fPbPb_MC_in->Get(Form("hpbpb_anaBin_matrix_HLT_R%d_%s_cent%d",radius,etaWidth,i)); mPbPb_Matrix[i]->Rebin2D(10, 10); mPbPb_Matrix[i]->Print("base"); // if(etaWidth == "10_eta_10"){ // if(i == 0 && radius==2) unfoldingCutBin = htest->FindBin(30); // if(i == 1 && radius==2) unfoldingCutBin = htest->FindBin(30); // if(i == 2 && radius==2) unfoldingCutBin = htest->FindBin(30); // if(i == 3 && radius==2) unfoldingCutBin = htest->FindBin(30); // if(i == 4 && radius==2) unfoldingCutBin = htest->FindBin(30); // if(i == 5 && radius==2) unfoldingCutBin = htest->FindBin(30); // if(i == 0 && radius==3) unfoldingCutBin = htest->FindBin(40); // if(i == 1 && radius==3) unfoldingCutBin = htest->FindBin(40); // if(i == 2 && radius==3) unfoldingCutBin = htest->FindBin(30); // if(i == 3 && radius==3) unfoldingCutBin = htest->FindBin(30); // if(i == 4 && radius==3) unfoldingCutBin = htest->FindBin(30); // if(i == 5 && radius==3) unfoldingCutBin = htest->FindBin(30); // if(i == 0 && radius==4) unfoldingCutBin = htest->FindBin(50); // if(i == 1 && radius==4) unfoldingCutBin = htest->FindBin(50); // if(i == 2 && radius==4) unfoldingCutBin = htest->FindBin(40); // if(i == 3 && radius==4) unfoldingCutBin = htest->FindBin(40); // if(i == 4 && radius==4) unfoldingCutBin = htest->FindBin(30); // if(i == 5 && radius==4) unfoldingCutBin = htest->FindBin(30); // } // if(etaWidth == "10_eta_18"){ // if(i == 0 && radius==2) unfoldingCutBin = htest->FindBin(50); // if(i == 1 && radius==2) unfoldingCutBin = htest->FindBin(50); // if(i == 2 && radius==2) unfoldingCutBin = htest->FindBin(40); // if(i == 3 && radius==2) unfoldingCutBin = htest->FindBin(40); // if(i == 4 && radius==2) unfoldingCutBin = htest->FindBin(30); // if(i == 5 && radius==2) unfoldingCutBin = htest->FindBin(30); // if(i == 0 && radius==3) unfoldingCutBin = htest->FindBin(60); // if(i == 1 && radius==3) unfoldingCutBin = htest->FindBin(50); // if(i == 2 && radius==3) unfoldingCutBin = htest->FindBin(40); // if(i == 3 && radius==3) unfoldingCutBin = htest->FindBin(40); // if(i == 4 && radius==3) unfoldingCutBin = htest->FindBin(30); // if(i == 5 && radius==3) unfoldingCutBin = htest->FindBin(30); // if(i == 0 && radius==4) unfoldingCutBin = htest->FindBin(70); // if(i == 1 && radius==4) unfoldingCutBin = htest->FindBin(60); // if(i == 2 && radius==4) unfoldingCutBin = htest->FindBin(50); // if(i == 3 && radius==4) unfoldingCutBin = htest->FindBin(50); // if(i == 4 && radius==4) unfoldingCutBin = htest->FindBin(30); // if(i == 5 && radius==4) unfoldingCutBin = htest->FindBin(30); // } // if(etaWidth == "20_eta_20"){ // if(i == 0 && radius==2) unfoldingCutBin = htest->FindBin(70); // if(i == 1 && radius==2) unfoldingCutBin = htest->FindBin(60); // if(i == 2 && radius==2) unfoldingCutBin = htest->FindBin(30); // if(i == 3 && radius==2) unfoldingCutBin = htest->FindBin(30); // if(i == 4 && radius==2) unfoldingCutBin = htest->FindBin(30); // if(i == 5 && radius==2) unfoldingCutBin = htest->FindBin(30); // if(i == 0 && radius==3) unfoldingCutBin = htest->FindBin(70); // if(i == 1 && radius==3) unfoldingCutBin = htest->FindBin(60); // if(i == 2 && radius==3) unfoldingCutBin = htest->FindBin(50); // if(i == 3 && radius==3) unfoldingCutBin = htest->FindBin(30); // if(i == 4 && radius==3) unfoldingCutBin = htest->FindBin(30); // if(i == 5 && radius==3) unfoldingCutBin = htest->FindBin(30); // if(i == 0 && radius==4) unfoldingCutBin = htest->FindBin(80); // if(i == 1 && radius==4) unfoldingCutBin = htest->FindBin(60); // if(i == 2 && radius==4) unfoldingCutBin = htest->FindBin(50); // if(i == 3 && radius==4) unfoldingCutBin = htest->FindBin(30); // if(i == 4 && radius==4) unfoldingCutBin = htest->FindBin(30); // if(i == 5 && radius==4) unfoldingCutBin = htest->FindBin(30); // } int bincut = mPbPb_Gen[i]->FindBin(50); for(int k = 1;k<=bincut;k++){ // mPbPb_Gen[i]->SetBinContent(k,0); // mPbPb_Reco[i]->SetBinContent(k,0); // mPbPb_Gen[i]->SetBinError(k,0); // mPbPb_Reco[i]->SetBinError(k,0); // // set bin content matrix l,k works for(int l = 1;l<=mPbPb_Gen[i]->GetNbinsX();l++){ mPbPb_Matrix[i]->SetBinContent(l,k,0); mPbPb_Matrix[i]->SetBinError(l,k,0); } } SetUnfoldBins1D(dPbPb_TrgComb[i], 50, 350); // cout<<"going to truncate the MC histograms here."<<endl; // // mPbPb_Reco[i]->Print("base"); // // mPbPb_Reco[i] = (TH1F*)Truncate1D_anaBin(mPbPb_Reco[i], nbins, ptbins_long); // // mPbPb_Reco[i]->Print("base"); // mPbPb_GenInput[i]->Print("base"); // mPbPb_Gen[i] = new TH1F(Form("mPbPb_Gen_spectra_cent%d",i),"",nbins, ptbins_long); // Truncate1D(mPbPb_GenInput[i], mPbPb_Gen[i]); // mPbPb_Gen[i]->Print("base"); // mPbPb_RecoInput[i]->Print("base"); // mPbPb_Reco[i] = new TH1F(Form("mPbPb_REco_spectra_cent%d",i),"",nbins, ptbins_long); // Truncate1D(mPbPb_RecoInput[i], mPbPb_Reco[i]); // mPbPb_Reco[i]->Print("base"); // mPbPb_MatrixInput[i]->Print("base"); // mPbPb_Matrix[i] = new TH2F(Form("mPbPb_Response_Matrix_cent%d",i),"",nbins_truncated, ptbins_long_truncated, nbins_truncated, ptbins_long_truncated); // Truncate2D(mPbPb_MatrixInput[i], mPbPb_Matrix[i]); // mPbPb_Matrix[i]->Print("base"); } if(printDebug) cout<<"loaded the data and mc PbPb histograms from the files"<<endl; // get PP data if(printDebug) cout<<"Getting PP data and MC"<<endl; //fPP_in->ls(); // dPP_1 = (TH1F*)fPP_in->Get(Form("hpp_HLT80_R%d_%s",radius,etaWidth)); // dPP_1->Print("base"); // dPP_2 = (TH1F*)fPP_in->Get(Form("hpp_HLT60_R%d_%s",radius,etaWidth)); // dPP_2->Print("base"); // dPP_3 = (TH1F*)fPP_in->Get(Form("hpp_HLT40_R%d_%s",radius,etaWidth)); // dPP_3->Print("base"); dPP_Comb = (TH1F*)fPP_in->Get(Form("hpp_HLTComb_R%d_%s",radius,etaWidth)); //dPP_Comb = (TH1F*)dPP_1->Clone(Form("hpp_TrgComb_R%d_n20_eta_p20",radius,etaWidth)); //dPP_CombInput->Print("base"); dPP_Comb->Scale(1./(5.3 * 1e9)); // dPP_Comb = new TH1F("PP_MeasuredSpectra","",365, 30, 395); // Truncate1D(dPP_CombInput, dPP_Comb); //dPP_Comb = (TH1F*)dPP_Comb->Rebin(nbins, "PP_MeasuredSpectra", ptbins_long); dPP_Comb = (TH1F*)dPP_Comb->Rebin(10); dPP_Comb->SetName("PP_MeasuredSpectra"); divideBinWidth(dPP_Comb); dPP_Comb->Print("base"); // get PP MC // mPP_GenInput = (TH1F*)fPP_MC_in->Get(Form("hpp_anaBin_JetComb_gen_R%d_%s",radius,etaWidth)); // mPP_GenInput->Print("base"); // mPP_Gen = new TH1F("mPP_Gen_spectra","",nbins, ptbins_long); // Truncate1D(mPP_GenInput, mPP_Gen); // mPP_Gen->Print("base"); // mPP_RecoInput = (TH1F*)fPP_MC_in->Get(Form("hpp_anaBin_JetComb_reco_R%d_%s",radius,etaWidth)); // mPP_RecoInput->Print("base"); // mPP_Reco = new TH1F("mPP_Reco_spectra","",nbins, ptbins_long); // Truncate1D(mPP_RecoInput, mPP_Reco); // mPP_Reco->Print("base"); // mPP_MatrixInput = (TH2F*)fPP_MC_in->Get(Form("hpp_anaBin_matrix_HLT_R%d_%s",radius,etaWidth)); // mPP_MatrixInput->Print("base"); // mPP_Matrix = new TH2F("mPP_response_Matrix","",nbins_truncated, ptbins_long_truncated, nbins_truncated, ptbins_long_truncated); // Truncate2D(mPP_MatrixInput, mPP_Matrix); // mPP_Matrix->Print("base"); // get PP MC // change from fPP_MC_in to fPP_in to run finebinscut //mPP_Gen = (TH1F*)fPP_MC_in->Get(Form("hpp_anaBin_JetComb_gen_R%d_20_eta_20",radius)); mPP_Gen = (TH1F*)fPP_MC_in->Get(Form("hpp_JetComb_gen_R%d_20_eta_20",radius)); //mPP_Gen->Rebin(nbins, "mPP_Gen", ptbins_long); mPP_Gen->Rebin(10); divideBinWidth(mPP_Gen); mPP_Gen->Print("base"); //mPP_Reco = (TH1F*)fPP_MC_in->Get(Form("hpp_anaBin_JetComb_reco_R%d_20_eta_20",radius)); mPP_Reco = (TH1F*)fPP_MC_in->Get(Form("hpp_JetComb_reco_R%d_20_eta_20",radius)); //mPP_Gen->Rebin(nbins, "mPP_Gen", ptbins_long); mPP_Reco->Rebin(10); divideBinWidth(mPP_Reco); mPP_Reco->Print("base"); //mPP_Matrix = (TH2F*)fPP_MC_in->Get(Form("hpp_anaBin_matrix_HLT_R%d_20_eta_20",radius)); mPP_Matrix = (TH2F*)fPP_MC_in->Get(Form("hpp_matrix_HLT_R%d_20_eta_20",radius)); mPP_Matrix->Rebin2D(10, 10); mPP_Matrix->Print("base"); if(printDebug) cout<<"Filling the PbPb response Matrix"<<endl; // response matrix and unfolding for PbPb // going to try it the way kurt has its. for(int i = 0;i<nbins_cent;i++){ if(printDebug) cout<<"centrality bin iteration = "<<i<<endl; TF1 *f = new TF1("f","[0]*pow(x+[2],[1])"); f->SetParameters(1e10,-8.8,40); // TH1F *hGenSpectraCorr = (TH1F*)mPbPb_Matrix[i]->ProjectionX()->Clone(Form("hGenSpectraCorr_cent%d",i)); // hGenSpectraCorr->Fit("f"," "); // hGenSpectraCorr->Fit("f","",""); // hGenSpectraCorr->Fit("f","LL"); // TH1F *fHist = functionHist(f,hGenSpectraCorr,Form("fHist_cent%d",i));// function that you get from the fitting // hGenSpectraCorr->Divide(fHist); for (int y=1;y<=mPbPb_Matrix[i]->GetNbinsY();y++) { double sum=0; for (int x=1;x<=mPbPb_Matrix[i]->GetNbinsX();x++) { if (mPbPb_Matrix[i]->GetBinContent(x,y)<=1*mPbPb_Matrix[i]->GetBinError(x,y)) { //in the above line mine had 0*getbinerror while Kurt's had 1*. mPbPb_Matrix[i]->SetBinContent(x,y,0); mPbPb_Matrix[i]->SetBinError(x,y,0); } sum+=mPbPb_Matrix[i]->GetBinContent(x,y); } for (int x=1;x<=mPbPb_Matrix[i]->GetNbinsX();x++) { double ratio = 1; // if (hGenSpectraCorr->GetBinContent(x)!=0) ratio = 1e5/hGenSpectraCorr->GetBinContent(x); mPbPb_Matrix[i]->SetBinContent(x,y,mPbPb_Matrix[i]->GetBinContent(x,y)*ratio); mPbPb_Matrix[i]->SetBinError(x,y,mPbPb_Matrix[i]->GetBinError(x,y)*ratio); } } //mPbPb_Matrix[i]->Smooth(0); // Ok major differences here between my code and Kurt in b-jet Tools under Unfold - lines 469 and above. mPbPb_Response[i] = (TH2F*)mPbPb_Matrix[i]->Clone(Form("mPbPb_Response_cent%d",i)); TH1F *hProj = (TH1F*)mPbPb_Response[i]->ProjectionY()->Clone(Form("hProj_cent%d",i)); for (int y=1;y<=mPbPb_Response[i]->GetNbinsY();y++) { double sum=0; for (int x=1;x<=mPbPb_Response[i]->GetNbinsX();x++) { if (mPbPb_Response[i]->GetBinContent(x,y)<=1*mPbPb_Response[i]->GetBinError(x,y)) { // in the above if loop, kurt has 1*error and my old had 0*error mPbPb_Response[i]->SetBinContent(x,y,0); mPbPb_Response[i]->SetBinError(x,y,0); } sum+=mPbPb_Response[i]->GetBinContent(x,y); } for (int x=1;x<=mPbPb_Response[i]->GetNbinsX();x++) { if (sum==0) continue; double ratio = 1; //if(dPbPb_TrgComb[i]->GetBinContent(y)==0) ratio = 1e-100/sum; // else ratio = dPbPb_TrgComb[i]->GetBinContent(y)/sum ratio = 1./sum; if (hProj->GetBinContent(y)==0) ratio = 1e-100/sum; else ratio = hProj->GetBinContent(y)/sum; mPbPb_Response[i]->SetBinContent(x,y,mPbPb_Response[i]->GetBinContent(x,y)*ratio); mPbPb_Response[i]->SetBinError(x,y,mPbPb_Response[i]->GetBinError(x,y)*ratio); } } mPbPb_ResponseNorm[i] = (TH2F*)mPbPb_Matrix[i]->Clone(Form("mPbPb_ResponseNorm_cent%d",i)); for (int x=1;x<=mPbPb_ResponseNorm[i]->GetNbinsX();x++) { double sum=0; for (int y=1;y<=mPbPb_ResponseNorm[i]->GetNbinsY();y++) { if (mPbPb_ResponseNorm[i]->GetBinContent(x,y)<=1*mPbPb_ResponseNorm[i]->GetBinError(x,y)) { mPbPb_ResponseNorm[i]->SetBinContent(x,y,0); mPbPb_ResponseNorm[i]->SetBinError(x,y,0); } sum+=mPbPb_ResponseNorm[i]->GetBinContent(x,y); } for (int y=1;y<=mPbPb_ResponseNorm[i]->GetNbinsY();y++) { if (sum==0) continue; double ratio = 1./sum; mPbPb_ResponseNorm[i]->SetBinContent(x,y,mPbPb_ResponseNorm[i]->GetBinContent(x,y)*ratio); mPbPb_ResponseNorm[i]->SetBinError(x,y,mPbPb_ResponseNorm[i]->GetBinError(x,y)*ratio); } } } if(printDebug) cout<<"Filling PP response Matrix"<<endl; // response matrix for pp. // Kurt doesnt have this whole hGenSpectraCorr thing in his macro. need to check why the difference exists between out codes TF1 *fpp = new TF1("fpp","[0]*pow(x+[2],[1])"); fpp->SetParameters(1e10,-8.8,40); // if(printDebug) cout<<"before getting the gen spectra corr matrix"<<endl; // TH1F *hGenSpectraCorrPP = (TH1F*)mPP_Matrix->ProjectionX()->Clone("hGenSpectraCorrPP"); // if(printDebug) cout<<"after gettign the gen spectra corr matrix"<<endl; // hGenSpectraCorrPP->Fit("f"," "); // hGenSpectraCorrPP->Fit("f","",""); // hGenSpectraCorrPP->Fit("f","LL"); // TH1F *fHistPP = functionHist(fpp,hGenSpectraCorrPP,"fHistPP");// that the function that you get from the fitting // hGenSpectraCorrPP->Divide(fHistPP); for (int y=1;y<=mPP_Matrix->GetNbinsY();y++) { double sum=0; for (int x=1;x<=mPP_Matrix->GetNbinsX();x++) { if (mPP_Matrix->GetBinContent(x,y)<=1*mPP_Matrix->GetBinError(x,y)) { mPP_Matrix->SetBinContent(x,y,0); mPP_Matrix->SetBinError(x,y,0); } sum+=mPP_Matrix->GetBinContent(x,y); } for (int x=1;x<=mPP_Matrix->GetNbinsX();x++) { double ratio = 1; // if (hGenSpectraCorrPP->GetBinContent(x)!=0) ratio = 1e5/hGenSpectraCorrPP->GetBinContent(x); mPP_Matrix->SetBinContent(x,y,mPP_Matrix->GetBinContent(x,y)*ratio); mPP_Matrix->SetBinError(x,y,mPP_Matrix->GetBinError(x,y)*ratio); } } // mPbPb_Matrix[i]->Smooth(0); // Ok major differences here between my code and Kurt in b-jet Tools under Unfold - lines 469 and above. if(printDebug) cout<<"getting the response matrix"<<endl; mPP_Response = (TH2F*)mPP_Matrix->Clone("mPP_Response"); TH1F *hProjPP = (TH1F*)mPP_Response->ProjectionY()->Clone("hProjPP"); for (int y=1;y<=mPP_Response->GetNbinsY();y++) { double sum=0; for (int x=1;x<=mPP_Response->GetNbinsX();x++) { if (mPP_Response->GetBinContent(x,y)<=1*mPP_Response->GetBinError(x,y)) { // in the above if statement, kurt has 1*error and my old has 0*error mPP_Response->SetBinContent(x,y,0); mPP_Response->SetBinError(x,y,0); } sum+=mPP_Response->GetBinContent(x,y); } for (int x=1;x<=mPP_Response->GetNbinsX();x++) { if (sum==0) continue; double ratio = 1; //if(dPbPb_TrgComb[i]->GetBinContent(y)==0) ratio = 1e-100/sum; // else ratio = dPbPb_TrgComb[i]->GetBinContent(y)/sum ratio = 1./sum; if (hProjPP->GetBinContent(y)==0) ratio = 1e-100/sum; else ratio = hProjPP->GetBinContent(y)/sum; mPP_Response->SetBinContent(x,y,mPP_Response->GetBinContent(x,y)*ratio); mPP_Response->SetBinError(x,y,mPP_Response->GetBinError(x,y)*ratio); } } if(printDebug) cout<<"getting the normalized response matrix"<<endl; mPP_ResponseNorm = (TH2F*)mPP_Matrix->Clone("mPP_ResponseNorm"); for (int x=1;x<=mPP_ResponseNorm->GetNbinsX();x++) { double sum=0; for (int y=1;y<=mPP_ResponseNorm->GetNbinsY();y++) { if (mPP_ResponseNorm->GetBinContent(x,y)<=1*mPP_ResponseNorm->GetBinError(x,y)) { mPP_ResponseNorm->SetBinContent(x,y,0); mPP_ResponseNorm->SetBinError(x,y,0); } sum+=mPP_ResponseNorm->GetBinContent(x,y); } for (int y=1;y<=mPP_ResponseNorm->GetNbinsY();y++) { if (sum==0) continue; double ratio = 1./sum; mPP_ResponseNorm->SetBinContent(x,y,mPP_ResponseNorm->GetBinContent(x,y)*ratio); mPP_ResponseNorm->SetBinError(x,y,mPP_ResponseNorm->GetBinError(x,y)*ratio); } } // scale the spectra to the respective units // for(int i = 0;i<nbins_cent;++i){ // dPbPb_TrgComb[i] = (TH1F*)dPbPb_TrgComb[i]->Rebin(nbins,Form("PbPb_measured_spectra_combined_cent%d",i),ptbins_long); // divideBinWidth(dPbPb_TrgComb[i]); // } // dPP_Comb = (TH1F*)dPP_Comb->Rebin(nbins,"pp_measured_spectra_combined",ptbins_long); // divideBinWidth(dPP_Comb); // dPP_Comb->Scale(1./ dPP_Comb->GetBinContent(nbins)); // Now that we have all the response matrix for the 6 centralities in PbPb and one pp spectra lets start doing the steps: // we have 39 pt bins, so we need 1000 gaussian functions for each pt bin. Int_t unfoldingTrials = 1000; Double_t meanMeasPbPb[nbins][nbins_cent], sigmaMeasPbPb[nbins][nbins_cent]; Double_t meanMeasPP[nbins], sigmaMeasPP[nbins]; Double_t meanUnfoldPbPb[nbins][nbins_cent][unfoldingTrials], sigmaUnfoldPbPb[nbins][nbins_cent][unfoldingTrials]; Double_t meanUnfoldPP[nbins][unfoldingTrials], sigmaUnfoldPP[nbins][unfoldingTrials]; TRandom3 *random = new TRandom3(0); TH1F * hPbPb_beforeUnfold_Gaussian_pt150[nbins_cent]; TH1F * hPP_beforeUnfold_Gaussian_pt150; hPP_beforeUnfold_Gaussian_pt150 = new TH1F("hPP_beforeUnfold_Gaussian_pt150","",1000, 0.1 * dPP_Comb->GetBinContent(dPP_Comb->FindBin(150)) , 1.9 * dPP_Comb->GetBinContent(dPP_Comb->FindBin(150))); for(int i = 0; i<nbins_cent; ++i) hPbPb_beforeUnfold_Gaussian_pt150[i] = new TH1F(Form("hPbPb_beforeUnfold_Gaussian_pt150_cent%d",i),"Before Unfolding pt bin at 150 value spectra",1000, 0.1 * dPbPb_TrgComb[i]->GetBinContent(dPbPb_TrgComb[i]->FindBin(150)), 1.9 * dPbPb_TrgComb[i]->GetBinContent(dPbPb_TrgComb[i]->FindBin(150))); for(int u = 0;u<unfoldingTrials;++u){ cout<<"unfolding trial no = "<<u+1<<endl; for(int j = 0;j<nbins;++j){ for(int i = 0;i<nbins_cent;++i){ meanMeasPbPb[j][i] = dPbPb_TrgComb[i]->GetBinContent(j+1); sigmaMeasPbPb[j][i] = dPbPb_TrgComb[i]->GetBinError(j+1); }// centrality loop meanMeasPP[j] = dPP_Comb->GetBinContent(j+1); sigmaMeasPP[j] = dPP_Comb->GetBinError(j+1); }// nbins loop // now proceed to unfolding for each trial. for(int i = 0;i<nbins_cent;++i){ TH1F * hPreUnfoldingSpectra = new TH1F("hPreUnfoldingSpectra","",nbins,0, 1000); TH1F * hAfterUnfoldingSpectra; for(int j = 0;j<nbins;++j){ hPreUnfoldingSpectra->SetBinContent(j+1, random->Gaus(meanMeasPbPb[j][i], sigmaMeasPbPb[j][i])); hPreUnfoldingSpectra->SetBinError(j+1, sigmaMeasPbPb[j][i]/sqrt(unfoldingTrials)); if(j+1 == dPbPb_TrgComb[i]->FindBin(150)) hPbPb_beforeUnfold_Gaussian_pt150[i]->Fill(random->Gaus(meanMeasPbPb[j][i], sigmaMeasPbPb[j][i])); }// nbins loop TH1F* hMCGen = (TH1F*)mPbPb_Response[i]->ProjectionX(); removeZero(hMCGen); bayesianUnfold myUnfoldingMulti(mPbPb_Matrix[i], hMCGen, 0); myUnfoldingMulti.unfold(hPreUnfoldingSpectra, BayesIter); hAfterUnfoldingSpectra = (TH1F*) myUnfoldingMulti.hPrior->Clone("hAfterUnfoldingSpectra"); for(int j = 0;j<nbins;++j){ meanUnfoldPbPb[j][i][u] = hAfterUnfoldingSpectra->GetBinContent(j+1); sigmaUnfoldPbPb[j][i][u] = hAfterUnfoldingSpectra->GetBinError(j+1); }// nbins loop delete hPreUnfoldingSpectra; delete hAfterUnfoldingSpectra; delete hMCGen; }// centrality loop cout<<"pp "<<endl; // now do it for the pp: TH1F * hPreUnfoldingSpectraPP = new TH1F("hPreUnfoldingSpectraPP","",nbins,0, 1000); TH1F * hAfterUnfoldingSpectraPP; for(int j = 0;j<nbins;++j){ hPreUnfoldingSpectraPP->SetBinContent(j+1, random->Gaus(meanMeasPP[j], sigmaMeasPP[j])); hPreUnfoldingSpectraPP->SetBinError(j+1, sigmaMeasPP[j]/sqrt(unfoldingTrials)); if(j+1 == dPP_Comb->FindBin(150)) hPP_beforeUnfold_Gaussian_pt150->Fill(random->Gaus(meanMeasPP[j], sigmaMeasPP[j])); }// nbins loop TH1F* hMCGenPP = (TH1F*)mPP_Response->ProjectionX(); removeZero(hMCGenPP); bayesianUnfold myUnfoldingMultiPP(mPP_Matrix, hMCGenPP, 0); myUnfoldingMultiPP.unfold(hPreUnfoldingSpectraPP, BayesIter); hAfterUnfoldingSpectraPP = (TH1F*) myUnfoldingMultiPP.hPrior->Clone("hAfterUnfoldingSpectraPP"); for(int j = 0;j<nbins;++j){ meanUnfoldPP[j][u] = hAfterUnfoldingSpectraPP->GetBinContent(j+1); sigmaUnfoldPP[j][u] = hAfterUnfoldingSpectraPP->GetBinError(j+1); }// nbins loop delete hPreUnfoldingSpectraPP; delete hAfterUnfoldingSpectraPP; delete hMCGenPP; }// unfolding trials loop // Now that we have all the necesary values we need, lets proceed to fill a histogram with the mean values for each ptbin and get the corrected values. TH1F * hAfterUnfoldingptBinDistribution[nbins]; TH1F * hCorrUnfoldingPbPb[nbins_cent]; // we need to store one gaussian histogram in the root file which we can plot TH1F * hPbPb_Gaussian_pt150[nbins_cent]; TH1F * hPP_Gaussian_pt150; for(int i = 0;i<nbins_cent;++i){ hCorrUnfoldingPbPb[i] = new TH1F(Form("PbPb_BayesianUnfolded_cent%d",i),"Spectra after correction", nbins,0, 1000); hPbPb_Gaussian_pt150[i] = new TH1F(Form("PbPb_Gaussian_pt150_cent%d",i),"gaussian distribution of values at pt bin at 150",1000, 0.1 * dPbPb_TrgComb[i]->GetBinContent(dPbPb_TrgComb[i]->FindBin(150)), 1.9 * dPbPb_TrgComb[i]->GetBinContent(dPbPb_TrgComb[i]->FindBin(150))); for(int j = 0;j<nbins;++j){ hAfterUnfoldingptBinDistribution[j] = new TH1F(Form("hAfterUnfoldingptBinDistribution_ptBin%d",j),"",100, 0, 1); for(int u = 0;u<unfoldingTrials;++u){ hAfterUnfoldingptBinDistribution[j]->Fill(meanUnfoldPbPb[j][i][u]); if(j+1 == dPbPb_TrgComb[i]->FindBin(150)) hPbPb_Gaussian_pt150[i]->Fill(meanUnfoldPbPb[j][i][u]); }// unfolding trials loop hCorrUnfoldingPbPb[i]->SetBinContent(j+1, hAfterUnfoldingptBinDistribution[j]->GetMean()); hCorrUnfoldingPbPb[i]->SetBinError(j+1, hAfterUnfoldingptBinDistribution[j]->GetRMS()); delete hAfterUnfoldingptBinDistribution[j]; }// nbins loop }// centrality loop // similar for the pp: TH1F * hAfterUnfoldingptBinDistributionPP[nbins]; TH1F * hCorrUnfoldingPP; hCorrUnfoldingPP = new TH1F("PP_BayesianUnfolded","Spectra after unfolding error correction",nbins,0, 1000); hPP_Gaussian_pt150 = new TH1F("PP_Gaussian_pt100","gaussian distribution of values at pt bin at 150",1000, 0.1 * dPP_Comb->GetBinContent(dPP_Comb->FindBin(150)) , 1.9 * dPP_Comb->GetBinContent(dPP_Comb->FindBin(150))); for(int j = 0;j<nbins;++j){ hAfterUnfoldingptBinDistributionPP[j] = new TH1F(Form("hAfterUnfoldingptBinDistributionPP_ptBin%d",j),"",100, 0, 1); for(int u = 0;u<unfoldingTrials;++u){ hAfterUnfoldingptBinDistributionPP[j]->Fill(meanUnfoldPP[j][u]); if(j+1 == dPP_Comb->FindBin(150)) hPP_Gaussian_pt150->Fill(meanUnfoldPP[j][u]); }// unfolding trials loop hCorrUnfoldingPP->SetBinContent(j+1, hAfterUnfoldingptBinDistributionPP[j]->GetMean()); hCorrUnfoldingPP->SetBinError(j+1, hAfterUnfoldingptBinDistributionPP[j]->GetRMS()); delete hAfterUnfoldingptBinDistributionPP[j]; }// nbins loop TFile f(Form("July20/HiForest_%disATLASCut_%ddo10GeVBins_data_driven_correction_ak%d.root" , isATLASCut, do10GeVBins, radius),"RECREATE"); f.cd(); for(int i = 0;i<nbins_cent;i++) { //hCorrUnfoldingPbPb[i] = (TH1F*)hCorrUnfoldingPbPb[i]->Rebin(nbins_coarse, Form("PbPb_BayesianUnfolded_cent%d",i), ptbins_long_coarse); //divideBinWidth(hCorrUnfoldingPbPb[i]); //dPbPb_TrgComb[i] = (TH1F*)dPbPb_TrgComb[i]->Rebin(nbins_coarse, Form("PbPb_measured_cent%d",i), ptbins_long_coarse); //divideBinWidth(dPbPb_TrgComb[i]); hMinBias[i]->Write(); hDataBeforeSub[i]->Write(); hDataAfterSub[i]->Write(); hCorrUnfoldingPbPb[i]->Scale(166 * 1e9); hCorrUnfoldingPbPb[i]->Write(); hCorrUnfoldingPbPb[i]->Print("base"); dPbPb_TrgComb[i]->Scale(166 * 1e9); dPbPb_TrgComb[i]->SetName(Form("PbPb_data_minbiasSub_cent%d",i)); //dPbPb_TrgComb[i]->Scale(145.156 * 1e9); dPbPb_TrgComb[i]->Write(); dPbPb_TrgComb[i]->Print("base"); hPbPb_beforeUnfold_Gaussian_pt150[i]->Write(); hPbPb_beforeUnfold_Gaussian_pt150[i]->Print("base"); hPbPb_Gaussian_pt150[i]->Write(); hPbPb_Gaussian_pt150[i]->Print("base"); mPbPb_Matrix[i]->Write(); } //hCorrUnfoldingPP = (TH1F*)hCorrUnfoldingPP->Rebin(nbins_coarse, "PP_BayesianUnfolded", ptbins_long_coarse); //divideBinWidth(hCorrUnfoldingPP); //dPP_Comb = (TH1F*)dPP_Comb->Rebin(nbins_coarse, "PP_measured", ptbins_long_coarse); //divideBinWidth(dPP_Comb); hCorrUnfoldingPP->Scale(5.3 * 1e9); hCorrUnfoldingPP->Write(); hCorrUnfoldingPP->Print("base"); dPP_Comb->Scale(5.3 * 1e9); dPP_Comb->Write(); dPP_Comb->Print("base"); hPP_beforeUnfold_Gaussian_pt150->Write(); hPP_beforeUnfold_Gaussian_pt150->Print("base"); hPP_Gaussian_pt150->Write(); hPP_Gaussian_pt150->Print("base"); mPP_Matrix->Write(); f.Write(); f.Close(); // make the data driven Error correction histograms and plots here: TH1F * hError_Meas[nbins_cent+1], * hError_Fixed[nbins_cent+1]; for(int i = 0; i<nbins_cent+1; ++i){ cout<<"centrality "<<i<<endl; if(i < nbins_cent){ hError_Meas[i] = new TH1F(Form("hError_Meas_cent%d",i),"",nbins, 0, 1000); hError_Fixed[i] = new TH1F(Form("hError_Fixed_cent%d",i),"",nbins, 0, 1000); } if(i == nbins_cent){ hError_Meas[i] = new TH1F(Form("hError_PP_Meas_cent%d",i),"",nbins, 0, 1000); hError_Fixed[i] = new TH1F(Form("hError_PP_Fixed_cent%d",i),"",nbins, 0, 1000); } for(int j = 1; j<=nbins; ++j){ //cout<<"ptbins "<<j<<endl; if(i < nbins_cent){ if(dPbPb_TrgComb[i]->GetBinContent(j)!=0) hError_Meas[i]->SetBinContent(j, (float)dPbPb_TrgComb[i]->GetBinError(j)/dPbPb_TrgComb[i]->GetBinContent(j)); //hError_Meas[i]->SetBinContent(j, (float)dPbPb_TrgComb[i]->GetBinError(j)); if(hCorrUnfoldingPbPb[i]->GetBinContent(j)!=0)hError_Fixed[i]->SetBinContent(j, (float)hCorrUnfoldingPbPb[i]->GetBinError(j)/hCorrUnfoldingPbPb[i]->GetBinContent(j)); cout<<j<<" "<<hError_Fixed[i]->GetBinContent(j)<<endl; //hError_Fixed[i]->SetBinContent(j, (float)hCorrUnfoldingPbPb[i]->GetBinError(j)); } if(i == nbins_cent){ hError_Meas[i]->SetBinContent(j, (float)dPP_Comb->GetBinError(j)/dPP_Comb->GetBinContent(j)); //hError_Meas[i]->SetBinContent(j, (float)dPP_Comb->GetBinError(j)); hError_Fixed[i]->SetBinContent(j, (float)hCorrUnfoldingPP->GetBinError(j)/hCorrUnfoldingPP->GetBinContent(j)); //hError_Fixed[i]->SetBinContent(j, (float)hCorrUnfoldingPP->GetBinError(j)); } } hError_Meas[i]->SetAxisRange(50, 299, "X"); //hError_Meas[i]->Print("base"); //hError_Fixed[i]->Print("base"); //hError_Meas[i]->SetAxisRange(1e-12, 1, "Y"); } //cout<<" passed the loop"<<endl; TCanvas * cSpectra = new TCanvas("cSpectra","",1200,1000); makeMultiPanelCanvas(cSpectra,3,2,0.0,0.0,0.2,0.15,0.07); for(int i = 0; i<nbins_cent; ++i){ //cout<<i<<endl; cSpectra->cd(nbins_cent-i); cSpectra->cd(nbins_cent-i)->SetLogy(); dPbPb_TrgComb[i]->SetMarkerStyle(24); dPbPb_TrgComb[i]->SetMarkerColor(kBlack); makeHistTitle(dPbPb_TrgComb[i]," ","jet pT","dN/dpT"); dPbPb_TrgComb[i]->SetAxisRange(50, 299, "X"); dPbPb_TrgComb[i]->Draw("p"); hCorrUnfoldingPbPb[i]->SetMarkerStyle(33); hCorrUnfoldingPbPb[i]->SetMarkerColor(kRed); hCorrUnfoldingPbPb[i]->Draw("psame"); } TLegend * Spec = myLegend(0.55,0.55,0.75,0.75); cSpectra->cd(1); putCMSPrel(); Spec->AddEntry(dPbPb_TrgComb[0],"Measured","pl"); Spec->AddEntry(hCorrUnfoldingPbPb[0],"Data Driven Correction","pl"); Spec->SetTextSize(0.04); Spec->Draw(); cSpectra->SaveAs(Form("%sUnfoldingSpectra_fromDataDrivenMacro_PbPb_%s_R%d_%d_hiForest_%dGeVCut.pdf",outLocation,etaWidth,radius,date.GetDate(),unfoldingCut),"RECREATE"); TCanvas * cErrorFix = new TCanvas("cErrorFix","",1200,1000); makeMultiPanelCanvas(cErrorFix,3,2,0.0,0.0,0.2,0.15,0.07); for(int i = 0; i<nbins_cent; ++i){ //cout<<i<<endl; cErrorFix->cd(nbins_cent-i); cErrorFix->cd(nbins_cent-i)->SetLogy(); makeHistTitle(hError_Meas[i]," ","jet pT","Error/Content"); hError_Meas[i]->SetMarkerStyle(24); hError_Meas[i]->SetMarkerColor(kBlack); hError_Meas[i]->Draw("p"); hError_Fixed[i]->SetMarkerStyle(33); hError_Fixed[i]->SetMarkerColor(kRed); hError_Fixed[i]->Draw("psame"); } TLegend * err = myLegend(0.55,0.55,0.75,0.75); cErrorFix->cd(1); putCMSPrel(); err->AddEntry(hError_Meas[0],"Measured","pl"); err->AddEntry(hError_Fixed[0],"Data Driven Correction","pl"); err->SetTextSize(0.04); err->Draw(); cErrorFix->SaveAs(Form("%sUnfoldingErrorFix_fromDataDrivenMacro_PbPb_%s_R%d_%d_hiForest_%dGeVCut.pdf",outLocation,etaWidth,radius,date.GetDate(),unfoldingCut),"RECREATE"); TCanvas * cErrorFixPP = new TCanvas("cErrorFixPP","",800,600); cErrorFixPP->SetLogy(); hError_Meas[nbins_cent]->SetMarkerStyle(24); hError_Meas[nbins_cent]->SetMarkerColor(kBlack); hError_Meas[nbins_cent]->Draw("p"); hError_Fixed[nbins_cent]->SetMarkerStyle(33); hError_Fixed[nbins_cent]->SetMarkerColor(kRed); hError_Fixed[nbins_cent]->Draw("psame"); TLegend * errPP = myLegend(0.55,0.55,0.75,0.75); putCMSPrel(); errPP->AddEntry(hError_Meas[nbins_cent],"Measured","pl"); errPP->AddEntry(hError_Fixed[nbins_cent],"Data Driven Correction","pl"); errPP->SetTextSize(0.04); errPP->Draw(); cErrorFixPP->SaveAs(Form("%sUnfoldingErrorFix_fromDataDrivenMacro_PP_%s_R%d_%d_hiForest_%dGeVCut.pdf",outLocation,etaWidth,radius,date.GetDate(),unfoldingCut),"RECREATE"); timer.Stop(); if(printDebug) cout<<"CPU time (mins) = "<<(Float_t)timer.CpuTime()/60<<endl; if(printDebug) cout<<"Real tile (mins) = "<<(Float_t)timer.RealTime()/60<<endl; }
void fitSignal(){ std::string shapes_file = "mlfit.root"; std::string data_file = "param_ws.root"; std::string channel = "ch1"; TFile *dfile = TFile::Open(data_file.c_str()); TFile *sfile = TFile::Open(shapes_file.c_str()); TH1F *bkg = (TH1F*)sfile->Get(Form("shapes_fit_b/%s/total",channel.c_str())); TH1F *data = (TH1F*)dfile->Get("SR_data"); // TH1 for data TH1F *signal= (TH1F*)dfile->Get("SR_signal"); // TH1 for signal TH2F *covar = (TH2F*)sfile->Get(Form("shapes_fit_b/%s/total_covar",channel.c_str())); // bkg and covariance defined as pdf / GeV, so scale by bin widhts // int nbins = data->GetNbinsX(); if (!isTH1Input){ for (int b=1;b<=nbins;b++){ double bw = bkg->GetBinWidth(b); bkg->SetBinContent(b,bkg->GetBinContent(b)*bw); for (int j=1;j<=nbins;j++){ covar->SetBinContent(b,j,covar->GetBinContent(b,j)*bw*bw); } } } RooArgList xlist_; RooArgList olist_; RooArgList mu_; bkg->Print() ; covar->Print() ; signal->Print() ; data->Print() ; // Make a dataset (simultaneous) RooCategory sampleType("bin_number","Bin Number"); RooRealVar observation("observed","Observed Events bin",1); // You have to define the samples types first!, because RooFit suuuuucks! for (int b=1;b<=nbins;b++){ sampleType.defineType(Form("%d",b-1),b-1); sampleType.setIndex(b-1); } RooArgSet obsargset(observation,sampleType); RooDataSet obsdata("combinedData","Data in all Bins",obsargset); //obsdata.add(RooArgSet(observation,sampleType)); for (int b=1;b<=nbins;b++){ observation.setVal(data->GetBinContent(b)); sampleType.setIndex(b-1); std::cout << sampleType.getLabel() << ", " << sampleType.getIndex() << std::endl; //RooArgSet localset(observation,sampleType); //obsdata.add(localset); obsdata.add(RooArgSet(observation,sampleType)); std::cout << " Observed at " << b << ", " << observation.getVal() << std::endl; } // make a constraint term for the background, and a RooRealVar for bkg for (int b=1;b<=nbins;b++){ double bkgy = (double)bkg->GetBinContent(b); RooRealVar *mean_ = new RooRealVar(Form("exp_bin_%d_In",b),Form("expected bin %d",b),bkgy); mean_->setConstant(true); RooRealVar *x_ = new RooRealVar(Form("exp_bin_%d",b),Form("bkg bin %d",b),bkgy,0.2*bkgy,bkgy*4); std::cout << " Exp background At " << b << ", " << x_->getVal() << std::endl; xlist_.add(*x_); mu_.add(*mean_); } // constraint PDF for background // Convert TH2 -> TMatrix TMatrixDSym Tcovar(nbins); for (int i=0;i<nbins;i++){ for (int j=0;j<nbins;j++){ //if (i==j)Tcovar[i][j] = covar->GetBinContent(i+1,j+1); //else Tcovar[i][j] = 0; Tcovar[i][j] = covar->GetBinContent(i+1,j+1); } } std::cout<< "Made Covariance" << std::endl; RooMultiVarGaussian constraint_pdf("constraint_pdf","Constraint for background pdf",xlist_,mu_,Tcovar); std::cout<< "Made Covariance Gauss" << std::endl; // Make the signal component RooRealVar r("r","r",1,-5,5); RooArgList signals_; for (int b=1;b<=nbins;b++) { RooProduct *sigF = new RooProduct(Form("signal_%d",b),"signal nominal",RooArgSet(r,RooFit::RooConst(signal->GetBinContent(b)))); std::cout << " Signal At " << b << ", " << sigF->getVal() << std::endl; signals_.add(*sigF); } RooArgList plist_; RooArgList slist_; sampleType.setIndex(1); RooSimultaneous combined_pdf("combined_pdf","combined_pdf",sampleType); for (int b=1;b<=nbins;b++){ RooAddition *sum = new RooAddition(Form("splusb_bin_%d",b),Form("Signal plus background in bin %d",b),RooArgList(*((RooRealVar*)(signals_.at(b-1))),*((RooRealVar*)(xlist_.at(b-1))))); RooPoisson *pois = new RooPoisson(Form("pdf_bin_%d",b),Form("Poisson in bin %d",b),observation,(*sum)); // Who cares about poissons? //RooGaussian *pois = new RooGaussian(Form("pdf_bin_%d",b),Form("Poisson in bin %d",b),observation,(*sum),RooFit::RooConst(TMath::Sqrt(sum->getVal()))); combined_pdf.addPdf(*pois,Form("%d",b-1)); slist_.add(*sum); plist_.add(*pois); } combined_pdf.Print("v"); obsdata.Print("v"); // Make a prodpdf instread RooProdPdf combinedpdfprod("maybefinalpdf","finalpdf",RooArgList(combined_pdf,constraint_pdf)); RooAbsReal *nll_ = combined_pdf.createNLL(obsdata,RooFit::ExternalConstraints(RooArgList(constraint_pdf))); // RooMinimizer m(*nll_); m.minimize("Minuit2","minimize"); // constrained fit! r.setConstant(true); double nllMin = nll_->getVal(); TFile *fout = new TFile("simple.root","RECREATE"); TTree *tree = new TTree("limit","limit"); float deltaNLL_; float r_; tree->Branch("r",&r_,"r/F"); tree->Branch("deltaNLL",&deltaNLL_,"deltaNLL/F"); RooMinimizer mc(*nll_); //combinedpdfprod.fitTo(obsdata); // for(float rv=-2;rv<=2;rv+=0.2){ r.setVal(rv); r_=rv; mc.minimize("Minuit2","minimize"); deltaNLL_ = nll_->getVal() - nllMin; tree->Fill(); } fout->cd(); tree->Write(); fout->Close(); /* RooAbsReal *nll_ = combinedpdfprod.createNLL(obsdata); nll_->Print("v"); // Minimize RooMinimizer m(*nll_); r.setConstant(true); std::cout << combinedpdfprod.getVal() << std::endl; std::cout << constraint_pdf.getVal() << std::endl; //m.Print(); m.minimize("Minuit2","minimize"); */ }
void ppb_merge(){ TStopwatch timer; timer.Start(); //Float_t N_mb = Lumi_ppb*sigma_inelastic*1000; //Float_t Lumi_ppb = 30.9;// inverse micro barns //Float_t sigma_inelastic = 70.0;//milli barns TH1::SetDefaultSumw2(); TString inname1 = "root://eoscms//eos/cms/store/group/phys_heavyions/yjlee/pPb2013/promptReco/PA2013_HiForest_PromptReco_JSonPPb_forestv77.root"; TString inname2 = "root://eoscms//eos/cms/store/group/phys_heavyions/krajczar/inbound/mnt/hadoop/cms/store/user/krajczar/pPb_Jet40Jet60_Full_v1/mergedJet40Jet60_KK.root"; TFile *f1 = TFile::Open(inname1); TFile *f2 = TFile::Open(inname2); cout<<" File for HLT_100 HLT_80 = "<<inname1<<endl; cout<<" File for HLT_60 HLT_40 = "<<inname2<<endl; TFile *outfile = new TFile("pPbmerged_output.root","RECREATE"); TTree* jet_80 = (TTree*)f1->Get("akPu3PFJetAnalyzer/t"); TTree* jet_80_hlt = (TTree*)f1->Get("hltanalysis/HltTree"); TTree* jet_80_skim = (TTree*)f1->Get("skimanalysis/HltTree"); TTree* jet_80_evt = (TTree*)f1->Get("hiEvtAnalyzer/HiTree"); jet_80->AddFriend(jet_80_hlt); jet_80->AddFriend(jet_80_skim); jet_80->AddFriend(jet_80_evt); TTree* jet_60 = (TTree*)f2->Get("akPu3PFJetAnalyzer/t"); TTree* jet_60_hlt = (TTree*)f2->Get("hltanalysis/HltTree"); TTree* jet_60_skim = (TTree*)f2->Get("skimanalysis/HltTree"); TTree* jet_60_evt = (TTree*)f2->Get("hiEvtAnalyzer/HiTree"); jet_60->AddFriend(jet_60_hlt); jet_60->AddFriend(jet_60_skim); jet_60->AddFriend(jet_60_evt); TCut Sel = "abs(vz)<15&&pHBHENoiseFilter&&pPAcollisionEventSelectionPA"; TCut Trig_100 = "HLT_PAJet100_NoJetID_v1"; TCut Trig_80 = "HLT_PAJet80_NoJetID_v1"; TCut Trig_60 = "HLT_PAJet60_NoJetID_v1"; TCut eta = "abs(jteta)<1"; Float_t N_mb = 7.71e13; Float_t prescl3 = (Float_t)jet_80->GetEntries()/jet_80->GetEntries(Trig_60); Float_t prescl3_test = (Float_t)jet_80->GetEntries(Sel&&eta&&Trig_100)/jet_80->GetEntries(Sel&&eta&&Trig_60); const Int_t nbins = 16; const Double_t bound[nbins+1] = {30., 40., 50., 60., 70., 80., 90., 100., 110., 120., 140., 150., 160., 200., 220., 260., 300.}; TH1F *hMeas_100 = new TH1F("hMeas_100","PPb HLT_100 Measured histo",nbins,bound); TH1F *hMeas_80 = new TH1F("hMeas_80","PPb HLT_80 Measured histo",nbins,bound); TH1F *hMeas_60 = new TH1F("hMeas_60","PPb HLT_60 Measured histo",nbins,bound); TH1F *hCombined = new TH1F("hCombined","PPb Combined spectra",nbins,bound); hMeas_100->Sumw2(); hMeas_60->Sumw2(); hMeas_80->Sumw2(); jet_80->Draw("jtpt>>hMeas_100",Sel&&Trig_100&&eta); jet_80->Draw("jtpt>>hMeas_80",Sel&&!Trig_100&&Trig_80&&eta); jet_60->Draw("jtpt>>hMeas_60","1.58606"*Sel&&eta&&Trig_60&&!Trig_80&&!Trig_100); divideBinWidth(hMeas_100); divideBinWidth(hMeas_80); divideBinWidth(hMeas_60); hMeas_100->Scale(1./2); //scaling by d eta - from -1 to +1 is 2. hMeas_80->Scale(1./2); hMeas_60->Scale(1./2); hCombined->Add(hMeas_100,1); hCombined->Add(hMeas_80,1); hCombined->Add(hMeas_60,1); hCombined->Scale(1./N_mb); hMeas_100->Scale(1./N_mb); hMeas_80->Scale(1./N_mb); hMeas_60->Scale(1./N_mb); TCanvas *cMerged = new TCanvas("cMerged","Merged PPb spectra",800,600); cMerged->SetLogy(); hCombined->SetXTitle("Jet p_{T} [GeV/c]"); hCombined->SetYTitle("1/N_mb d^2N/dp_t d eta"); hCombined->SetMarkerColor(kBlack); hCombined->SetMarkerStyle(20); hCombined->SetAxisRange(30,300,"X"); hCombined->Draw(); hMeas_100->SetMarkerColor(kRed); hMeas_100->SetMarkerStyle(21); hMeas_100->Draw("same"); hMeas_80->SetMarkerColor(kBlue); hMeas_80->SetMarkerStyle(22); hMeas_80->Draw("same"); hMeas_60->SetMarkerColor(kGreen); hMeas_60->SetMarkerStyle(23); hMeas_60->Draw("same"); TLegend *leg_PPb = myLegend(0.6,0.65,0.95,0.9); leg_PPb->SetTextSize(0.05); leg_PPb->AddEntry(hCombined,"Merged PPb spectra ","pl"); leg_PPb->AddEntry(hMeas_100,"HLT_100 spectra","pl"); leg_PPb->AddEntry(hMeas_80,"HLT_80 spectra","pl"); leg_PPb->AddEntry(hMeas_60,"HLT_60 spectra","pl"); leg_PPb->Draw(); putCMSPrel(0.2,0.83,0.06); drawText("PPb AKPu3PF |eta|<1 |vz|<15",0.2,0.23,20); cMerged->SaveAs("pPb_merged.pdf","RECREATE"); hMeas_100->Write(); hCombined->Write(); hMeas_80->Write(); hMeas_60->Write(); TFile *fYaxian = TFile::Open("AkPu3PFJetRpA.root"); TH1F *Yaxian = (TH1F*)fYaxian->Get("DataJetWideBin;3"); TH1F *test = (TH1F*)Yaxian->Clone("test"); cout<<"hi"<<endl; //outfile->cd(); Yaxian->Print("base"); test->Print("base"); Yaxian->Divide(hCombined); TCanvas *yaxian = new TCanvas("yaxian","",800,600); yaxian->Divide(2,1); yaxian->cd(1); Yaxian->SetTitle("ratio of Yaxian's measured pPb spectra to Mine"); Yaxian->SetXTitle("Jet p_{T} [GeV/c]"); Yaxian->SetMarkerColor(kBlack); Yaxian->SetMarkerStyle(23); Yaxian->Draw(); yaxian->cd(2); yaxian->cd(2)->SetLogy(); test->SetMarkerStyle(22); test->SetMarkerColor(kBlack); test->SetXTitle("Jet p_{T} [GeV/c]"); test->SetYTitle("1/N_mb d^2N/dp_t d eta"); test->Draw(); hCombined->Draw("same"); TLegend *leg = myLegend(0.6,0.65,0.95,0.9); leg->SetTextSize(0.05); leg->AddEntry(hCombined,"Merged PPb spectra ","pl"); leg->AddEntry(test,"Yaxian's spectra","pl"); leg->Draw(); putCMSPrel(0.2,0.83,0.06); drawText("PPb AKPu3PF |eta|<1 |vz|<15",0.2,0.23,20); yaxian->SaveAs("Yaxian_Comparison_pPb_pt_spectra.root","RECREATE"); outfile->cd(); Yaxian->Write(); test->Write(); outfile->Write(); outfile->Close(); timer.Stop(); float rtime = timer.RealTime(); float ctime = timer.CpuTime(); std::cout<<"\t"<<std::endl; std::cout<<Form("RealTime=%f seconds, CpuTime=%f seconds",rtime,ctime)<<std::endl; std::cout<<"\t"<<std::endl; std::cout<<"Good bye : " <<"\t"<<std::endl; //define the required histograms //static const Int_t nbins = 22; //static const Double_t bound[nbins+1] = {30.,40.,50.,60.,70.,80.,90.,100.,110.,120.,130.,140.,150.,160.,180.,200.,220.,260.,300.,350.,400.,450.,500.}; }
int main() { TH1::AddDirectory(0); ModTDRStyle(); // string cfg; // The configuration file // bool do_ratio = false; // bool do_logy = true; // vector<string> datacards; // string fitresult_file = ""; // string parse_rule = ""; // string output = ""; // string text1 = ""; // string text2 = ""; // bool postfit = true; gSystem->Load("libHiggsAnalysisCombinedLimit.dylib"); ch::CombineHarvester cmb; // cmb.SetVerbosity(2); // cmb.ParseDatacard( // "output/cmshcg/summer2013/searches/hzz4l/125/hzz4l_4muS_8TeV_0.txt", // "$MASS/$ANALYSIS_$CHANNEL_$ERA_$BINID.txt"); cmb.ParseDatacard( "output/cmshcg/summer2013/searches/hzz4l/125/hzz4l_4muS_8TeV_1.txt", "$MASS/$ANALYSIS_$CHANNEL_$ERA_$BINID.txt"); // cmb.ParseDatacard( // "output/cmshcg/summer2013/searches/hzz4l/125/hzz4l_4muS_7TeV_0.txt", // "$MASS/$ANALYSIS_$CHANNEL_$ERA_$BINID.txt"); // cmb.ParseDatacard( // "output/cmshcg/summer2013/searches/hzz4l/125/hzz4l_4muS_7TeV_1.txt", // "$MASS/$ANALYSIS_$CHANNEL_$ERA_$BINID.txt"); ch::SetStandardBinNames(cmb); RooFitResult fitresult = ch::OpenFromTFile<RooFitResult>( "output/cmshcg/summer2013/searches/hzz4l/125/mlfit.root:fit_s"); auto fitparams = ch::ExtractFitParameters(fitresult); cmb.UpdateParameters(fitparams); cmb.process_rgx({".*SM"}, false); // cmb.PrintAll(); TH1F sig_shape = cmb.cp().signals().GetShape(); TH1F bkg_shape = cmb.cp().backgrounds().GetShape(); bkg_shape.Print("range"); std::cout << bkg_shape.Integral() << "\n"; TH1F data = cmb.GetObservedShape(); data.Print("range"); int rebin = 1; sig_shape.Rebin(rebin); bkg_shape.Rebin(rebin); data.Rebin(rebin); sig_shape.Scale(data.GetBinWidth(1) / sig_shape.GetBinWidth(1)); bkg_shape.Scale(data.GetBinWidth(1) / bkg_shape.GetBinWidth(1)); TCanvas* canv = new TCanvas("hzz4l", "hzz4l"); canv->cd(); std::vector<TPad*> pads = OnePad(); std::vector<TH1*> h = CreateAxisHists(1, &data); StandardAxes(h[0]->GetXaxis(), h[0]->GetYaxis(), "m_{4l}", "GeV"); h[0]->Draw("axis"); sig_shape.Add(&bkg_shape); sig_shape.SetLineColor(4); sig_shape.SetLineWidth(3); sig_shape.Draw("SAME HIST C"); bkg_shape.SetLineColor(2); bkg_shape.SetLineWidth(3); bkg_shape.Draw("SAME HIST C"); data.Draw("esamex0"); FixTopRange(pads[0], GetPadYMax(pads[0]), 0.15); DrawCMSLogo(pads[0], "CMS", "Preliminary", 11, 0.045, 0.035, 1.2); DrawTitle(pads[0], "19.7 fb^{-1} (8 TeV)", 3); DrawTitle(pads[0], "H#rightarrowZZ", 1); canv->Update(); pads[0]->RedrawAxis(); pads[0]->GetFrame()->Draw(); canv->SaveAs("hzz4l.pdf"); return 0; }
void plot_Validatin_DatavsMC(int radius = 4, std::string coll = "PP", std::string algo = "", std::string jetType = "PF", std::string DataFile = "PromptForestPP_DataJet80_ak4PF.root", std::string MCFile = "PromptForestPP_MC_ak4PF.root") { // get the data and MC histograms // these are simple histograms TFile * fData = TFile::Open(DataFile.c_str()); TH1F * pt2overpt1_Data = (TH1F*)fData->Get("pt2overpt1"); TH1F * hJetEta_Data = (TH1F*)fData->Get("hJetEta"); TH1F * hJetPhi_Data = (TH1F*)fData->Get("hJetPhi"); TH1F * hJetpT_Data = (TH1F*)fData->Get("hJetpT"); hJetpT_Data->Print("base"); TH1F * hAj_Data = (TH1F*)fData->Get("hAj"); TH1F * hDeltaPhi_Data = (TH1F*)fData->Get("hDeltaPhi"); TH1F * hevent = (TH1F*)fData->Get("hRunN_Vs_NJets"); hevent->Print("base"); TH1F * hJet80 = (TH1F*)fData->Get("hJet80"); hJet80->Print("base"); TFile * fMC = TFile::Open(MCFile.c_str()); TH1F * pt2overpt1_MC = (TH1F*)fMC->Get("pt2overpt1"); TH1F * hJetEta_MC = (TH1F*)fMC->Get("hJetEta"); TH1F * hJetPhi_MC = (TH1F*)fMC->Get("hJetPhi"); TH1F * hJetpT_MC = (TH1F*)fMC->Get("hJetpT"); TH1F * hAj_MC = (TH1F*)fMC->Get("hAj"); TH1F * hDeltaPhi_MC = (TH1F*)fMC->Get("hDeltaPhi"); // get marta's histograms TFile * fMarta = TFile::Open("AnaResultsPFvsCaloJets4M.root"); TList *lst = (TList*)fMarta->Get("anaPFvsCaloJet"); TH3F * hpT3 = (TH3F*)lst->FindObject("fh3PtTrueEtaDeltaPt"); int etabinlow = hpT3->GetYaxis()->FindBin(-2.00001); int etabinhigh = hpT3->GetYaxis()->FindBin(2.00001); TH1F * hPFCaloMatchpT = (TH1F*)hpT3->ProjectionX("hPFCaloMatchpT",etabinlow, etabinhigh); hPFCaloMatchpT->Print("base"); // plot them on top of each other. TCanvas * cAj = new TCanvas("Aj","",800,600); hAj_Data->SetMarkerStyle(20); hAj_Data->SetMarkerColor(kBlack); hAj_Data->SetAxisRange(0.0, 1.0, "X"); hAj_Data->SetYTitle("Event Fraction"); hAj_Data->SetXTitle("A_{j}"); hAj_Data->SetTitle(" "); hAj_Data->DrawNormalized(); hAj_MC->SetMarkerStyle(25); hAj_MC->SetMarkerColor(kRed); hAj_MC->DrawNormalized("same"); putCMSPrel(); //putPPLumi(); TLegend * lAj = myLegend(0.4,0.6,0.7,0.9); lAj->AddEntry("","p_{T}^{lead} > 100 GeV/c",""); lAj->AddEntry("","p_{T}^{sublead}> 40 GeV/c",""); lAj->AddEntry(hAj_Data,"Data (Jet 80 trigger)","pl"); lAj->AddEntry(hAj_MC,"MC (pthat 80)","pl"); lAj->Draw(); cAj->SaveAs(Form("Aj_datavsMC_%s_ak%s%d%s.pdf",coll.c_str(), algo.c_str(), radius, jetType.c_str()),"RECREATE"); // plot them on top of each other. TCanvas * cDeltaPhi = new TCanvas("DeltaPhi","",800,600); hDeltaPhi_Data->SetMarkerStyle(20); hDeltaPhi_Data->SetMarkerColor(kBlack); hDeltaPhi_Data->SetAxisRange(0.0, 2.5, "X"); hDeltaPhi_Data->SetYTitle("Event Fraction"); hDeltaPhi_Data->SetXTitle("DeltaPhi"); hDeltaPhi_Data->SetTitle(" "); hDeltaPhi_Data->DrawNormalized(); hDeltaPhi_MC->SetMarkerStyle(25); hDeltaPhi_MC->SetMarkerColor(kRed); hDeltaPhi_MC->DrawNormalized("same"); putCMSPrel(); //putPPLumi(); TLegend * lDeltaPhi = myLegend(0.4,0.6,0.7,0.9); lDeltaPhi->AddEntry("","p_{T}^{lead} > 100 GeV/c",""); lDeltaPhi->AddEntry("","p_{T}^{sublead}> 40 GeV/c",""); lDeltaPhi->AddEntry(hDeltaPhi_Data,"Data (Jet 80 trigger)","pl"); lDeltaPhi->AddEntry(hDeltaPhi_MC,"MC (pthat 80)","pl"); lDeltaPhi->Draw(); cDeltaPhi->SaveAs(Form("DeltaPhi_datavsMC_%s_ak%s%d%s.pdf",coll.c_str(), algo.c_str(), radius, jetType.c_str()),"RECREATE"); // plot them on top of each other. TCanvas * cpt2overpt1 = new TCanvas("pt2overpt1","",800,600); pt2overpt1_Data->SetMarkerStyle(20); pt2overpt1_Data->SetMarkerColor(kBlack); pt2overpt1_Data->SetAxisRange(0.0, 1, "X"); pt2overpt1_Data->SetYTitle("Event Fraction"); pt2overpt1_Data->SetXTitle("p_{T}^{subLead}/p_{T}^{Lead}"); pt2overpt1_Data->DrawNormalized(); pt2overpt1_MC->SetMarkerStyle(25); pt2overpt1_MC->SetMarkerColor(kRed); //pt2overpt1_MC->SetAxisRange(0.0, 1.0, "X"); pt2overpt1_MC->DrawNormalized("same"); putCMSPrel(); //putPPLumi(); TLegend * lpt2overpt1 = myLegend(0.4,0.6,0.7,0.9); lpt2overpt1->AddEntry("","p_{T}^{lead} > 100 GeV/c",""); lpt2overpt1->AddEntry("","p_{T}^{sublead}> 40 GeV/c",""); lpt2overpt1->AddEntry(pt2overpt1_Data,"Data (Jet 80 trigger)","pl"); lpt2overpt1->AddEntry(pt2overpt1_MC,"MC (pthat 80)","pl"); lpt2overpt1->Draw(); cpt2overpt1->SaveAs(Form("pt2overpt1_datavsMC_%s_ak%s%d%s.pdf",coll.c_str(), algo.c_str(), radius, jetType.c_str()),"RECREATE"); // plot them on top of each other. TCanvas * chJetpT = new TCanvas("hJetpT","",800,600); chJetpT->SetLogy(); hJetpT_Data->SetMarkerStyle(20); hJetpT_Data->SetMarkerColor(kBlack); hJetpT_Data->Rebin(5); //divideBinWidth(hJetpT_Data); hJetpT_Data->SetAxisRange(90.0, 500, "X"); hJetpT_Data->GetXaxis()->SetTitleOffset(1.3); hJetpT_Data->SetYTitle("counts"); hJetpT_Data->SetXTitle("Jet p_{T} (GeV/c)"); hJetpT_Data->SetLineColor(kBlack); //hJetpT_Data->Scale(1./2426425); hJetpT_Data->Draw(); hPFCaloMatchpT->SetMarkerStyle(33); hPFCaloMatchpT->SetMarkerColor(kBlue); divideBinWidth(hPFCaloMatchpT); //hPFCaloMatchpT->Scale(1./); //hPFCaloMatchpT->Draw("same"); // hJetpT_MC->SetMarkerStyle(25); // hJetpT_MC->SetMarkerColor(kRed); // //hJetpT_MC->SetAxisRange(0.0, 1.0, "X"); // hJetpT_MC->DrawNormalized("same"); putCMSPrel(0.15,0.93,0.04); //putPPLumi(); TLegend * lhJetpT = myLegend(0.30,0.6,0.7,0.9); // lhJetpT->AddEntry("","p_{T}^{lead} > 90 GeV",""); lhJetpT->AddEntry("","Express data, pp #sqrt{s}=5.02 TeV",""); lhJetpT->AddEntry("",Form("anti-k_{T} R=0.%d Particle Flow Jets",radius),""); lhJetpT->AddEntry("","|#eta|<2.0",""); //lhJetpT->AddEntry("","",""); lhJetpT->AddEntry(hJetpT_Data,"Data (HLT Jet80 trigger)","pl"); //lhJetpT->AddEntry(hPFCaloMatchpT,"PF-Calo Matching","pl"); lhJetpT->SetTextSize(0.04); lhJetpT->Draw(); chJetpT->SaveAs(Form("hJetpT_%s_ak%s%d%s.pdf",coll.c_str(), algo.c_str(), radius, jetType.c_str()),"RECREATE"); }
void apply_unfolding(){ TFile *unf_file = new TFile("unfolding.root","read"); TFile *outfile = new TFile("Unfolding_Results.root","recreate"); for (int i=0; i<3; i++){ for (std::vector<TString>::const_iterator diffvariable = diffvariables_list.begin(); diffvariable!=diffvariables_list.end(); diffvariable++){ if (*diffvariable=="dR") continue; TString reg; if (i==0) reg="EBEB"; else if (i==1) reg="EBEE"; else if (i==2) reg="EEEE"; RooUnfoldResponse *resp = NULL; unf_file->GetObject(Form("response_%s_%s",reg.Data(),diffvariable->Data()),resp); resp->Print(); TFile *histo_file = new TFile(Form("plots/histo_xsec_%s_%s.root",diffvariable->Data(),reg.Data()),"read"); TH1F *histo_reco = NULL; histo_file->GetObject("xsec_ngammagammayield",histo_reco); histo_reco->Print(); RooUnfoldBayes *algo = new RooUnfoldBayes(resp,histo_reco,4); TH1D *_unfolded = (TH1D*)(algo->Hreco()); _unfolded->Print(); TH1F unfolded; _unfolded->Copy(unfolded); std::map<TString,TString> translation2; translation2.insert(std::pair<TString,TString>(TString("invmass"),TString("mgg"))); translation2.insert(std::pair<TString,TString>(TString("diphotonpt"),TString("pt"))); translation2.insert(std::pair<TString,TString>(TString("costhetastar"),TString("costt"))); translation2.insert(std::pair<TString,TString>(TString("dphi"),TString("phi"))); translation2.insert(std::pair<TString,TString>(TString("dR"),TString("dR"))); unfolded.SetName(Form("Unfolding_Nevt_%s_%s",translation2[TString(diffvariable->Data())].Data(),reg.Data())); unfolded.SetTitle(Form("Unfolding_Nevt_%s_%s",translation2[TString(diffvariable->Data())].Data(),reg.Data())); unfolded.Print(); TH1F unfolded_relsyserr; unfolded.Copy(unfolded_relsyserr); unfolded_relsyserr.SetName(Form("Unfolding_RelativeSysErr_%s_%s",translation2[TString(diffvariable->Data())].Data(),reg.Data())); unfolded_relsyserr.SetTitle(Form("Unfolding_RelativeSysErr_%s_%s",translation2[TString(diffvariable->Data())].Data(),reg.Data())); unfolded_relsyserr.Reset(); unfolded_relsyserr.Print(); outfile->cd(); unfolded.Write(); unfolded_relsyserr.Write(); } } outfile->Close(); }