void checkTriggers() { triggers.clear(); triggers.push_back("HLT_Mu23_TrkIsoVVL_Ele8_CaloIdL_TrackIdL_IsoVL_v*"); triggers.push_back("HLT_Mu8_TrkIsoVVL_Ele23_CaloIdL_TrackIdL_IsoVL_v*"); triggers.push_back("HLT_Ele27_eta2p1_WPLoose_Gsf_v*"); triggers.push_back("HLT_IsoMu22_v*"); triggers.push_back("HLT_IsoTkMu22_v*"); triggers.push_back("HLT_Ele23_Ele12_CaloIdL_TrackIdL_IsoVL_DZ_v*"); triggers.push_back("HLT_Mu17_TrkIsoVVL_TkMu8_TrkIsoVVL_v*"); triggers.push_back("HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_v*"); TFile* file = new TFile(_lxplus + "21Jun2016_Run2016B_PromptReco/l2loose__hadd__EpTCorr__l2tight/latino_Run2016B_PromptReco_MuonEG.root"); TH1F* selectedTriggers = (TH1F*)file->Get("selectedTriggers"); TAxis* xaxis = (TAxis*)selectedTriggers->GetXaxis(); printf("\n Checking %d triggers\n\n", (int)triggers.size()); for (int i=0; i<triggers.size(); i++) { for (int j=0; j<=selectedTriggers->GetNbinsX(); j++) { TString label = (TString)xaxis->GetBinLabel(j); if (label.Length() < 1) continue; if (triggers[i].EqualTo(label)) printf(" found [%d] %s\n", i, label.Data()); } } printf("\n"); }
TH1F* shape_histos(TH1F* hin, const TString datacard, const TString name) /* use the proper histograms and errors including shpae uncertainties as provided by combine */ { TH1F* hout = (TH1F*)hin->Clone(); hout->Clear(); TFile* mlfit = new TFile("fitresults/mlfit.root", "READ"); TH1F* shape = (TH1F*)mlfit->Get(TString("shapes_fit_s/").Append(datacard).Append("/").Append(name)); // currently problems with data and hioggsprocesses -> different name if(shape==0) std::cout << " No histogram found for " << name << std::endl; // for(int i=0; i<hout->GetNbinsX(); ++i) for(int i=1; i<hout->GetNbinsX()+1; i++) { Float_t Norig = hin->GetBinContent(i)*hin->GetBinWidth(i); Float_t Nshape = shape->GetBinContent(i); Float_t scale_err = (Nshape==0) ? 1 : Norig/Nshape; // hout->SetBinContent(i,shape->GetBinContent(i)); hout->SetBinContent(i,hin->GetBinContent(i)*hin->GetBinWidth(i)); hout->SetBinError(i,shape->GetBinError(i)*scale_err); } mlfit->Close(); return hout; }
TH1F* refill(TH1F* hin, const char* sample) /* refill histograms, for MC histograms set bin errors to zero. */ { if(hin==0){ std::cout << "hist not found: " << sample << " -- this may happen for samples of type signal." << std::endl; bool skip = false; if(std::string(sample).find("ggH")==std::string::npos){ skip == true ; } if(skip || std::string(sample).find("Zmm")==std::string::npos){ skip == true; } if(skip || std::string(sample).find("Fakes/QCD")==std::string::npos){ skip == true; } if(skip){ std::cout << "hist is not of type signal, Fakes/QCD, Zmm in mumu, close here" << std::endl; exit(1); } else{ return hin; } } TH1F* hout = (TH1F*)hin->Clone(); hout->Clear(); for(int i=0; i<hout->GetNbinsX(); ++i){ // simple refill, histograms are already devided by bin width // but for a useful lotting the bin errors for MC need to be // set to zero. hout->SetBinContent(i+1, hin->GetBinContent(i+1)); hout->SetBinError(i+1, 0.); } return hout; }
TH1F* refill(TH1F* hin, const char* sample, bool data=false) /* refill histograms, divide by bin width and correct bin errors. For MC histograms set bin errors to zero. */ { if(hin==0){ std::cout << "hist not found: " << sample << " -- close here" << std::endl; exit(1); } TH1F* hout = (TH1F*)hin->Clone(); hout->Clear(); for(int i=0; i<hout->GetNbinsX(); ++i){ if(data){ #if defined MSSM hout->SetBinContent(i+1, BLIND_DATA && blinding_MSSM(hin->GetBinCenter(i+1)) ? 0. : hin->GetBinContent(i+1)/hin->GetBinWidth(i+1)); hout->SetBinError (i+1, BLIND_DATA && blinding_MSSM(hin->GetBinCenter(i+1)) ? 0. : hin->GetBinError(i+1)/hin->GetBinWidth(i+1)); #endif } else{ hout->SetBinContent(i+1, hin->GetBinContent(i+1)/hin->GetBinWidth(i+1)); hout->SetBinError(i+1, 0.); } } return hout; }
void Difference(TH1* iH0,TH1 *iH1) { std::string lName = std::string(iH0->GetName()); //TH1F *lHDiff = new TH1F((lName+"Diff").c_str(),(lName+"Diff").c_str(),50,0,300); lHDiff->Sumw2(); TH1F *lHDiff = new TH1F((lName+"Diff").c_str(),(lName+"Diff").c_str(),iH0->GetNbinsX(),iH0->GetXaxis()->GetXmin(),iH0->GetXaxis()->GetXmax()); lHDiff->Sumw2(); lHDiff->SetFillColor(kViolet); lHDiff->SetFillStyle(1001); lHDiff->SetLineWidth(1); TH1F *lXHDiff1 = new TH1F((lName+"XDiff1").c_str(),(lName+"XDiff1").c_str(),iH0->GetNbinsX(),iH0->GetXaxis()->GetXmin(),iH0->GetXaxis()->GetXmax()); int i1 = 0; lXHDiff1->SetLineStyle(2); lXHDiff1->SetLineWidth(2); lXHDiff1->SetLineColor(kRed); lHDiff->GetYaxis()->SetRangeUser(0,2); lHDiff->GetYaxis()->SetTitleOffset(0.6); lHDiff->GetYaxis()->SetTitleSize(0.08); lHDiff->GetYaxis()->SetLabelSize(0.08); lHDiff->GetYaxis()->CenterTitle(); lHDiff->GetXaxis()->SetTitleOffset(1.2); lHDiff->GetXaxis()->SetTitleSize(0.10); lHDiff->GetXaxis()->SetLabelSize(0.08); lHDiff->GetXaxis()->SetTitle("#slash{E}_{T} [GeV]"); //lHDiff->GetXaxis()->CenterTitle(); //lHDiff->GetYaxis()->SetTitle(YLabel); for(int i0 = 0; i0 < lHDiff->GetNbinsX()+1; i0++) { double lXCenter = lHDiff->GetBinCenter(i0); double lXVal = iH0 ->GetBinContent(i0); lXHDiff1->SetBinContent(i0, 1.0); while(iH1->GetBinCenter(i1) < lXCenter) {i1++;} if(iH1->GetBinContent(i0) > 0) lHDiff->SetBinContent(i0,(lXVal-iH1->GetBinContent(i0))/(iH1->GetBinContent(i0))); if(iH1->GetBinContent(i0) > 0) lHDiff->SetBinError (i0,iH0->GetBinError(i0)/(iH1->GetBinContent(i0))); } lHDiff->SetMarkerStyle(kFullCircle); lHDiff->SetLineColor(kBlack); lHDiff->SetMarkerColor(kBlack); lHDiff->Draw("E1"); lXHDiff1->Draw("hist sames"); }
TH1F * divideHistosForRatio(TH1F * sig, TH1F * bkg) { TH1F * cloneS = (TH1F *) sig->Clone( sig->GetTitle() ); TH1F * cloneB = (TH1F *) bkg->Clone( bkg->GetTitle() ); /* for( Int_t bin = 1; bin <= cloneB->GetNbinsX(); bin++ ) cloneB->SetBinError( bin, 0. ); cloneS->Divide( cloneS, cloneB, 1, 1, "" ); */ for( Int_t bin = 1; bin <= cloneS->GetNbinsX(); bin++ ){ Double_t sv = cloneS->GetBinContent(bin); Double_t se = cloneS->GetBinError(bin); Double_t bv = cloneB->GetBinContent(bin); Double_t rat = -1.; Double_t err = 0.; if( sv != 0. && bv != 0. ) { rat = sv / bv; // err = sqrt( sv / (bv*bv) ); err = sqrt( se / (bv*bv) ); } cloneS->SetBinContent( bin, rat ); cloneS->SetBinError( bin, err ); } return cloneS; }
//Difference plotting void drawDifference(TH1* iH0,TH1 *iH1,TH1 *iHH=0,TH1 *iHL=0,TH1 *iHH1=0,TH1 *iHL1=0) { std::string lName = std::string(iH0->GetName()); TH1F *lHDiff = (TH1F*) iH0->Clone("Diff"); TH1F *lHDiffH = (TH1F*) iH0->Clone("DiffH"); TH1F *lHDiffL = (TH1F*) iH0->Clone("DiffL"); TH1F *lHDiffH1 = (TH1F*) iH0->Clone("DiffH1"); TH1F *lHDiffL1 = (TH1F*) iH0->Clone("DiffL1"); lHDiff ->SetFillColor(kViolet); lHDiff->SetFillStyle(1001); lHDiff->SetLineWidth(1); lHDiffL ->SetLineWidth(1); lHDiffL ->SetLineColor(iHL ->GetLineColor()); lHDiffH ->SetLineWidth(1); lHDiffH ->SetLineColor(iHH ->GetLineColor()); lHDiffL1->SetLineWidth(1); lHDiffL1->SetLineColor(iHL1->GetLineColor()); lHDiffH1->SetLineWidth(1); lHDiffH1->SetLineColor(iHH1->GetLineColor()); TH1F *lXHDiff1 = new TH1F((lName+"XDiff1").c_str(),(lName+"XDiff1").c_str(),iH0->GetNbinsX(),iH0->GetXaxis()->GetXmin(),iH0->GetXaxis()->GetXmax()); TH1F *lXHDiff2 = new TH1F((lName+"XDiff2").c_str(),(lName+"XDiff2").c_str(),iH0->GetNbinsX(),iH0->GetXaxis()->GetXmin(),iH0->GetXaxis()->GetXmax()); int i1 = 0; lXHDiff1->SetLineWidth(2); lXHDiff1->SetLineColor(kRed); lXHDiff2->SetLineWidth(2); lXHDiff2->SetLineColor(kRed); lXHDiff1->GetYaxis()->SetTitle("Ratio"); lXHDiff1->GetYaxis()->SetRangeUser(0.2,1.8); lXHDiff1->GetYaxis()->SetTitleOffset(0.4); lXHDiff1->GetYaxis()->SetTitleSize(0.2); lXHDiff1->GetYaxis()->SetLabelSize(0.11); for(int i0 = 0; i0 < lHDiff->GetNbinsX()+1; i0++) { double lXCenter = lHDiff->GetBinCenter(i0); double lXVal = iH0 ->GetBinContent(i0); double lXValH = iHH ->GetBinContent(i0); double lXValL = iHL ->GetBinContent(i0); double lXValH1 = iHH1 ->GetBinContent(i0); double lXValL1 = iHL1 ->GetBinContent(i0); lXHDiff1->SetBinContent(i0, 1.0); lXHDiff2->SetBinContent(i0, 1.0); while(iH1->GetBinCenter(i1) < lXCenter) {i1++;} if(iH1->GetBinContent(i0) > 0) lHDiff->SetBinContent(i0,lXVal /(iH1->GetBinContent(i0))); if(iH1->GetBinContent(i0) > 0) lHDiff->SetBinError (i0,sqrt(lXVal)/(iH1->GetBinContent(i0))); if(iH1->GetBinContent(i0) > 0) lHDiffL->SetBinContent(i0,lXValL/(iH1->GetBinContent(i0))); if(iH1->GetBinContent(i0) > 0) lHDiffH->SetBinContent(i0,lXValH/(iH1->GetBinContent(i0))); if(iH1->GetBinContent(i0) > 0) lHDiffL1->SetBinContent(i0,lXValL1/(iH1->GetBinContent(i0))); if(iH1->GetBinContent(i0) > 0) lHDiffH1->SetBinContent(i0,lXValH1/(iH1->GetBinContent(i0))); //if(iH1->GetBinContent(i0) > 0) cout << "unc" << lXVal << " -- " << sqrt(lXVal)/(iH1->GetBinContent(i0)) << endl; } lHDiff->SetMarkerStyle(kFullCircle); //lHDiff->Draw("EP"); lXHDiff1->SetStats(0); lXHDiff2->SetStats(0); lHDiff->SetStats(0); lHDiffH->SetStats(0); lHDiffL->SetStats(0); lHDiffH1->SetStats(0); lHDiffL1->SetStats(0); lXHDiff1->Draw("hist"); lXHDiff2->Draw("hist sames"); lHDiff->Draw("EP sames"); lHDiffH ->Draw("hist sames"); lHDiffL ->Draw("hist sames"); lHDiffH1->Draw("hist sames"); lHDiffL1->Draw("hist sames"); }
TH1F RestoreBinning(TH1F const& src, TH1F const& ref) { TH1F res = ref; res.Reset(); for (int x = 1; x <= res.GetNbinsX(); ++x) { res.SetBinContent(x, src.GetBinContent(x)); } return res; }
void getRecoTimesDQM(const char* fName){ // std::cout<<"File "<<fName<<std::endl; TFile* f = new TFile(fName); f->cd("/DQMData/Run 1/DQM/Run summary/TimerService/Paths"); TH1F* h = gDirectory->Get("reconstruction_step_module_total"); int n = h->GetNbinsX(); for(int i=1;i<=n;++i)std::cout<<h->GetXaxis()->GetBinLabel(i)<<" "<<h->GetBinContent(i)<<std::endl; }
double sumUpEntries(TH1F& histo){ // sum up all bin entries of histo // +1 : include overflow bin double entries=0; for(int idx=1; idx<=histo.GetNbinsX()+1; idx++){ entries+=histo.GetBinContent(idx); } return entries; }
void plotweight(int isub){ TFile *f = TFile::Open("/phenix/u/xuq/xuq/taxi/Run15pAu200FVTXClusAna503/8845/data/435527_0.root"); int ivz = 0; TH1F* h = (TH1F*)f->Get(Form("phiweight_0_0_0_%d_0_%d",ivz,isub)); TH1F* hc = (TH1F*)h->Clone("hc"); h->Rebin(4); hc->Rebin(4); for(int ibin=0;ibin<=h->GetNbinsX();ibin++){ if(h->GetBinContent(ibin)!=0) hc->SetBinContent(ibin,h->Integral()/h->GetNbinsX()/h->GetBinContent(ibin)); else hc->SetBinContent(ibin,1.); } TCanvas *c1 = new TCanvas("c1"); hc->Draw(); TCanvas *c2 = new TCanvas("c2"); h->Draw(); }
// re-fill histograms (this is only a little helper for the example histogram) TH1F* refill(TH1F* hin) { TH1F* hout = (TH1F*)hin->Clone(); hout->Clear(); for(int i=0; i<hout->GetNbinsX(); ++i){ hout->SetBinContent(i+1, hin->GetBinContent(i+1)); hout->SetBinError (i+1, 0.); } return hout; }
TH1F* GetPseudoData(TH1F* h_tt1l, TH1F* h_Wjets, TH1F* h_tt2l){ TH1F* h = (TH1F*) h_tt1l->Clone("data"); h->Add(h_Wjets); h->Add(h_tt2l); //randomisation of the histo ... for(int i=1;i<=h->GetNbinsX();i++){ h->SetBinContent(i,randomnessGenerator->Poisson(h->GetBinContent(i))); } return h; }
TH1F * getErrHist(TH1F * h, bool rel = true) { TH1F * res = (TH1F *) h->Clone("errhist"); res->Reset(); for(int j = 1; j <= res->GetNbinsX(); j++) if(rel) res->SetBinContent(j,h->GetBinError(j)/h->GetBinContent(j)); else res->SetBinContent(j,h->GetBinError(j)); return res; }
void PoissonianMagic() { TFile file_PUnum("/nfs/dust/cms/user/rathjd/VBF-LS-tau/PU/DataPUFile_22Jan2013ReReco_Run2012.root", "read"); TFile file_PUden("/nfs/dust/cms/user/rathjd/VBF-LS-tau/PU/S10MC_PUFile.root", "read"); TH1F *data = (TH1F*)file_PUnum.Get("analyzeHiMassTau/NVertices_0"); data->Scale(1/data->Integral(0,-1)); TH1F *MC = (TH1F*)file_PUden.Get("analyzeHiMassTau/NVertices_0"); MC->Scale(1/MC->Integral(0,-1)); //define empty histograms for the smeared versions TH1F *num = (TH1F*)data->Clone("ratio"); for(int i=0; i<num->GetNbinsX(); i++) num->SetBinContent(i+1,0); TH1F *den = (TH1F*)data->Clone("MC"); for(int i=0; i<den->GetNbinsX(); i++) den->SetBinContent(i+1,0); //generate the poissonian distributions for(unsigned int i=0; i<data->GetNbinsX(); i++){ TF1 *Pd = new TF1("Pd", "TMath::PoissonI(x,[0])",0,100); Pd->SetParameter(0,data->GetBinLowEdge(i+1)); std::cout<<data->GetBinLowEdge(i+1)<<std::endl; TF1 *Pm = new TF1("Pm", "TMath::PoissonI(x,[0])",0,100); Pm->SetParameter(0,MC->GetBinLowEdge(i+1)); //add up the poissonians for(unsigned int j=0; j<data->GetNbinsX(); j++){ num->SetBinContent(j+1,num->GetBinContent(j+1)+Pd->Eval(j)/Pd->Integral(0,100)*data->GetBinContent(i+1)); den->SetBinContent(j+1,den->GetBinContent(j+1)+Pm->Eval(j)/Pm->Integral(0,100)*MC->GetBinContent(i+1)); } } //make the ratio and save the result num->Divide(den); TFile *f=new TFile("PUreweightHistogram.root","RECREATE"); num->Write(); den->Write(); f->Close(); file_PUnum.Close(); file_PUden.Close(); }
void FitterCBForSignificance(){ // TFile* _shapes = new TFile("/afs/cern.ch/user/m/mgouzevi/scratch0/CMGTools/CMSSW_4_2_8/src/StatTools/BayesianDijetFit/Results/Resonance_Shapes_gg_TuneD6T_Emine2013.root"); TFile* _shapes = new TFile("/afs/cern.ch/user/m/mgouzevi/scratch0/CMGTools/CMSSW_4_2_8/src/StatTools/BayesianDijetFit/Results/Resonance_Shapes_qg_TuneD6T_Emine2013.root"); // TFile* _shapes = new TFile("/afs/cern.ch/user/m/mgouzevi/scratch0/CMGTools/CMSSW_4_2_8/src/StatTools/BayesianDijetFit/Results/Resonance_Shapes_Qstar_2012_D6T_ak5_fat30_save.root"); // TFile* _shapes = new TFile("/afs/cern.ch/user/m/mgouzevi/scratch0/CMGTools/CMSSW_4_2_8/src/StatTools/BayesianDijetFit/Results/Resonance_Shapes_RSGraviton_2012_D6T_ak5_GGtoGG_fat30_save.root"); //TFile* _shapes = new TFile("/afs/cern.ch/user/m/mgouzevi/scratch0/CMGTools/CMSSW_4_2_8/src/StatTools/BayesianDijetFit/Results/Resonance_Shapes_RSGraviton_2012_D6T_ak5_QQtoQQ_fat30_save.root"); //TFile* _shapes = new TFile("/afs/cern.ch/user/m/mgouzevi/scratch0/CMGTools/CMSSW_4_2_8/src/StatTools/BayesianDijetFit/Results/Resonance_Shapes_Qstar_ak5_fat30.root"); for (int i = 1; i < 2; i++){ TH1F* shape = (TH1F*) _shapes->Get(Form("h_qg_%d;1", 1000+i*100)); TH1F* shape_largeBinning = new TH1F("shape_large_binning", "", NBINS, BOUNDARIES); for (int j = 1; j < shape->GetNbinsX()+1; j++){ double binCenter = shape->GetBinCenter(j); double weight = shape->GetBinContent(j); double binWidth = shape->GetBinWidth(j); shape_largeBinning->Fill(binCenter, weight); // cout << "j = " << j << " binWidth = " << binWidth << " weight = " << weight << endl; shape->SetBinContent(j, weight/binWidth); } for (int j = 1; j < shape_largeBinning->GetNbinsX()+1; j++){ double weight = shape_largeBinning->GetBinContent(j); double binWidth = shape_largeBinning->GetBinWidth(j); shape_largeBinning->SetBinContent(j, weight/binWidth*1000000); } shape->Draw(); shape_largeBinning->SetLineColor(kRed); shape_largeBinning->Draw("SAME"); // FitHistWithCBShape(shape_largeBinning, 1000.+i*100); } cout << "mass\tsMean\tsSigma\tsAlphaHigh\tsAlphaLow\tsNHigh\tsNLow\tsFrac"<<endl; for (int i = 0; i < 40; i++){ cout << Masses[i] << "\t" << Means[i] << "\t" << Sigmas[i] << "\t" << alphaHights[i] << "\t\t" << alphaLows[i] << "\t" << nHighs[i] << "\t\t" << nLows[i] << "\t" << fracs[i] << endl; } }
/** * Saving Histogram Data */ void ExportHistogram(TFile* f,const char* histKey,const char* outputfile){ // Root Setup TH1F* h = (TH1F*) f->Get(histKey); // File Setup ofstream out; out.open(outputfile); out<<"Bin,Value,Error"<<endl; for (int i = 1; i < h->GetNbinsX()-1; i++){ out<<h->GetBinCenter(i)<<","<<h->GetBinContent(i)<<","<<h->GetBinError(i)<<endl; } out.close(); }
void plotweight(int isub){ TFile *f = TFile::Open("/phenix/plhf/xuq/taxi/Run15pAl200MBPro104/10241/data/438026_0.root"); //TFile *f = TFile::Open("/phenix/u/xuq/xuq/phenix/flow/PP/work/Run15pp200MinBias/output_fvtxclus.root"); int ivz = 0; if(isub!=4){ TH1F* h = (TH1F*)f->Get(Form("phiweight_0_0_0_%d_0_%d",ivz,isub)); //TH1F* h = (TH1F*)f->Get(Form("fvtxphi_%d_%d",ivz,isub)); TH1F* hc = (TH1F*)h->Clone("hc"); for(int ibin=0;ibin<=h->GetNbinsX();ibin++){ if(h->GetBinContent(ibin)!=0) hc->SetBinContent(ibin,h->Integral()/h->GetNbinsX()/h->GetBinContent(ibin)); else hc->SetBinContent(ibin,1.); } } else{ TProfile* h = (TProfile*)f->Get(Form("phiweightbbc_0_0_0_%d_0_%d",ivz,isub)); TProfile* hc = (TProfile*)h->Clone("hc"); } TCanvas *c1 = new TCanvas("c1"); hc->GetYaxis()->SetRangeUser(0,2); hc->Draw(); TLine *l1 = new TLine(-3.14,0.8,3.14,0.8); l1->SetLineStyle(2); l1->SetLineColor(2); // l1->Draw(); TLine *l2 = new TLine(-3.14,1.2,3.14,1.2); l2->SetLineStyle(2); l2->SetLineColor(2); // l2->Draw(); if(isub!=4) c1->Print(Form("FVTXweight%d.png",isub)); TCanvas *c2 = new TCanvas("c2"); h->GetXaxis()->SetRangeUser(0,64); h->GetYaxis()->SetRangeUser(0.5,3); h->Draw(); if(isub==4) c2->Print(Form("BBCweight%d.png",isub)); }
TH1F * getSystErrForRatio(TH1F * bkg) { TH1F * cloneB = (TH1F *) bkg->Clone( bkg->GetTitle() ); for ( Int_t bin = 1; bin <= cloneB->GetNbinsX(); bin++ ) { Double_t relError = ( cloneB->GetBinError(bin) / cloneB->GetBinContent(bin) ); cloneB->SetBinContent( bin, 1. ); cloneB->SetBinError( bin, relError ); } return cloneB; }
TH1F * sqSum(TH1F * h1, TH1F * h2) { TH1F * res = (TH1F *) h2->Clone("sum"); res->Reset(); for(int j = 1; j <= res->GetNbinsX(); j++) { if(h1) res->SetBinContent(j,TMath::Sqrt( TMath::Power(h1->GetBinContent(j),2) + TMath::Power(h2->GetBinContent(j),2))); else res->SetBinContent(j,h2->GetBinContent(j)); } return res; }
/// /// Make a plot out of a 1D histogram holding a 1-CL curve. /// This is a fall back function that does no fancy stuff. /// /// \param s The scanner to plot. /// \param first Set this to true for the first plotted scanner. /// void OneMinusClPlot::scan1dPlotSimple(MethodAbsScan* s, bool first, int CLsType) { if ( arg->debug ){ cout << "OneMinusClPlot::scan1dPlotSimple() : plotting "; cout << s->getName() << " (" << s->getMethodName() << ")" << endl; } m_mainCanvas->cd(); TH1F *hCL = (TH1F*)s->getHCL()->Clone(getUniqueRootName()); if (CLsType==1) hCL = (TH1F*)s->getHCLs()->Clone(getUniqueRootName()); else if (CLsType==2) hCL = (TH1F*)s->getHCLsFreq()->Clone(getUniqueRootName()); // get rid of nan and inf for ( int i=1; i<=hCL->GetNbinsX(); i++ ){ if ( hCL->GetBinContent(i)!=hCL->GetBinContent(i) || std::isinf(hCL->GetBinContent(i)) ) hCL->SetBinContent(i, 0.0); } int color = s->getLineColor(); if(CLsType==1) color = color + 2 ; hCL->SetStats(0); hCL->SetLineColor(color); hCL->SetMarkerColor(color); hCL->SetLineWidth(2); hCL->SetLineStyle(s->getLineStyle()); hCL->SetMarkerColor(color); hCL->SetMarkerStyle(8); hCL->SetMarkerSize(0.6); hCL->GetYaxis()->SetNdivisions(407, true); hCL->GetXaxis()->SetTitle(s->getScanVar1()->GetTitle()); hCL->GetYaxis()->SetTitle("1-CL"); hCL->GetXaxis()->SetLabelFont(font); hCL->GetYaxis()->SetLabelFont(font); hCL->GetXaxis()->SetTitleFont(font); hCL->GetYaxis()->SetTitleFont(font); hCL->GetXaxis()->SetTitleOffset(0.9); hCL->GetYaxis()->SetTitleOffset(0.85); hCL->GetXaxis()->SetLabelSize(labelsize); hCL->GetYaxis()->SetLabelSize(labelsize); hCL->GetXaxis()->SetTitleSize(titlesize); hCL->GetYaxis()->SetTitleSize(titlesize); if ( plotLegend && !arg->isQuickhack(22) ){ if ( arg->plotlog ) hCL->GetYaxis()->SetRangeUser(1e-3,10); else hCL->GetYaxis()->SetRangeUser(0.0,1.3); } else{ if ( arg->plotlog ) hCL->GetYaxis()->SetRangeUser(1e-3,1); else hCL->GetYaxis()->SetRangeUser(0.0,1.0); } hCL->Draw(first?"":"same"); }
/*--------------------------------------------------------------------*/ TH1F* DrawZero(TH1F *hist,Int_t nbins,Double_t lowedge,Double_t highedge) /*--------------------------------------------------------------------*/ { TH1F *hzero = new TH1F(Form("hzero_%s",hist->GetName()),"hzero",nbins,lowedge,highedge); for (Int_t i=0;i<hzero->GetNbinsX();i++){ hzero->SetBinContent(i,0.); hzero->SetBinError(i,0.); } hzero->SetLineWidth(2); hzero->SetLineStyle(9); hzero->SetLineColor(kRed); return hzero; }
int main(int argc, char* argv[]){ ic::Plot::SetTdrStyle(); TH1F data = GetFromTFile<TH1F>("datacard_m_vis_inclusive_et_2011.root", "/eleTau_inclusive", "data_obs"); TH1F zee = GetFromTFile<TH1F>("datacard_m_vis_inclusive_et_2011.root", "/eleTau_inclusive", "ZL"); double data_rate = data.Integral(); double zee_init_rate = zee.Integral(); RooRealVar x("x","mvis",data.GetBinLowEdge(1),data.GetBinLowEdge(data.GetNbinsX()+1)); RooRealVar c1("c1","c1",-10,10); RooRealVar c2("c2","c2",-1,1); RooRealVar c3("c3","c3",-1,1); RooGenericPdf bkg("bkg","exp(c1*x+c2*x*x+c3*x*x*x)",RooArgSet(x,c1,c2,c3)); RooDataHist zee_hist("zee_hist","zee_hist",RooArgSet(x),&zee); RooHistPdf zee_pdf("zee_pdf","zee_pdf",RooArgSet(x),zee_hist); ///Fit Data TCanvas C("canvas", "canvas", 800,800); RooRealVar yield("yield","yield",0.01,.9); RooAddPdf full_pdf("full_pdf","full_pdf",RooArgList(zee_pdf,bkg),RooArgList(yield)); RooDataHist data_hist("data_hist","data_hist",RooArgSet(x),&data); RooChi2Var chi("chi","chi",full_pdf,data_hist,RooFit::DataError(RooAbsData::SumW2)); RooMinuit minuit(chi); minuit.migrad(); RooPlot* plot=x.frame(); data_hist.plotOn(plot); full_pdf.plotOn(plot); full_pdf.plotOn(plot,RooFit::Components(zee_pdf),RooFit::LineColor(2)); C.Clear(); plot->SetTitle("Title"); plot->GetYaxis()->SetTitle(""); plot->GetXaxis()->SetTitle("m(e#tau)"); plot->Draw(); C.Print("plotZEE.pdf"); double fit_frac = yield.getVal(); double fit_frac_err = yield.getError(); double zee_fit_rate = data_rate * fit_frac; double err = (data_rate * fit_frac_err) / zee_init_rate; std::cout << "Scale factor: " << zee_fit_rate / zee_init_rate << " +/- " << err << std::endl; return 0; }
void printCutflowData(string s) { TFile* f = TFile::Open(s.c_str()); TList * AllKeys=f->GetListOfKeys(); int NKeys = AllKeys->GetEntries(); //cout << NKeys << endl; TIter next(AllKeys); TKey *key; vector<TKey* > cutflowKeys; for(int i =0 ; i < NKeys ; i++) { key=(TKey*)next(); string name = key->GetTitle(); if(name.find("CutFlow") != std::string::npos) { cutflowKeys.push_back(key); //cout << name << endl; } } TCanvas * c1 = new TCanvas; TH1F *h = (TH1F*)cutflowKeys[0]->ReadObj(); for(int i=1; i<cutflowKeys.size();i++) { TH1F *temp = (TH1F*)cutflowKeys[i]->ReadObj(); h->Add(temp); } int Ndecimals = 2; enum CutEnum { NxAOD=0, NDxAOD=1, ALLEVTS=2, DUPLICATE=3, TRIGGER=4, GRL=5, DQ=6, VERTEX=7, TWO_LOOSE_GAM=8, AMBIGUITY=9, TRIG_MATCH=10, GAM_TIGHTID=11, GAM_ISOLATION=12, RELPTCUTS=13, MASSCUT=14, PASSALL=15 }; TString format(" %-24s%10."); format+=Ndecimals; format+="f%11.2f%%%11.2f%%\n"; int all_bin = h->FindBin(ALLEVTS); printf(" %-24s%10s%12s%12s\n","Event selection","Nevents","Cut rej.","Tot. eff."); for (int bin=1;bin<=h->GetNbinsX();++bin) { double ntot=h->GetBinContent(all_bin), n=h->GetBinContent(bin), nprev=h->GetBinContent(bin-1); TString cutName(h->GetXaxis()->GetBinLabel(bin)); cutName.ReplaceAll("#it{m}_{#gamma#gamma}","m_yy"); if (bin==1||nprev==0||n==nprev) printf(format.Data(),cutName.Data(),n,-1e-10,n/ntot*100); else // if the cut does something, print more information printf(format.Data(),cutName.Data(),n,(n-nprev)/nprev*100,n/ntot*100); } }
RooHistPdf* GetRooHistPdf(TFile* fin, string region, string process, string varname, RooRealVar* var, float& norm, TH1F*& histo, bool do_mcstat, bool do_norm, float input_norm){ TH1F* h = GetHisto(fin,region,process,varname, norm, do_norm, input_norm); histo = h; if(do_mcstat) { //randomisation of the histo ... for(int i=1;i<=h->GetNbinsX();i++) { h->SetBinContent(i,randomnessGenerator->Gaus(h->GetBinContent(i),h->GetBinError(i))); } } string rdhname = "rdh_"+region+"_"+process; RooDataHist *rdh = new RooDataHist(rdhname.c_str(),rdhname.c_str(),RooArgList(*var),Import(*h)); string pdfname = "pdf_"+region+"_"+process; RooHistPdf *pdf = new RooHistPdf(pdfname.c_str(),pdfname.c_str(),RooArgSet(*var),*rdh); return pdf; }
/*compare the mu+had mass bin contents one to one for two versions of the analysis and print discrepant bins*/ void compareVersions(const vector<vector<string> >& versions) { const string histogramName("muHadMass"); const string canvasName(histogramName + "Canvas"); vector<vector<vector<Float_t> > > muHadMass; for (vector<vector<string> >::const_iterator iVersion = versions.begin(); iVersion != versions.end(); ++iVersion) { vector<vector<Float_t> > muHadMassThisVersion; for (vector<string>::const_iterator iFile = iVersion->begin(); iFile != iVersion->end(); ++iFile) { vector<Float_t> muHadMassThisFile; TFile file(iFile->c_str()); if (file.IsOpen()) { TCanvas* canvas = NULL; file.GetObject(canvasName.c_str(), canvas); if (canvas != NULL) { TH1F* histogram = NULL; histogram = (TH1F*)canvas->GetPrimitive(histogramName.c_str()); if (histogram != NULL) { for (Int_t iBin = 0; iBin <= (histogram->GetNbinsX() + 1); ++iBin) { muHadMassThisFile.push_back(histogram->GetBinContent(iBin)); } } else cerr << "Null histogram pointer\n"; } else cerr << "Null canvas pointer\n"; file.Close(); } else cerr << "File not open\n"; muHadMassThisVersion.push_back(muHadMassThisFile); } muHadMass.push_back(muHadMassThisVersion); } cout << "old new % difference\n"; for (unsigned int iFile = 0; iFile < versions[0].size(); ++iFile) { cout << versions[0][iFile] << endl; for (unsigned int iBin = 0; iBin < muHadMass[0][0].size(); ++iBin) { if (muHadMass[0][iFile][iBin] != muHadMass[1][iFile][iBin]) { cout << "Bin " << iBin << ": " << muHadMass[0][iFile][iBin] << " "; cout << muHadMass[1][iFile][iBin] << " "; cout << ((muHadMass[0][iFile][iBin] - muHadMass[1][iFile][iBin])/ muHadMass[0][iFile][iBin])*100 << endl; } } } }
//________________________________________________________________________________ TH1F* makeEffSyst(TString dir , TString ctr , TString acc){ TFile* f_unf = getFile("files/unfold_outputs/" + dir + "/unf_MC31_partfull_HF0_" + ctr + "_INEL_" + acc + ".root"); TH1F* eff_ctr_gen = getHist<TH1F>(*f_unf , "eff_centrSel"); TH1F* eff_trg_gen = getHist<TH1F>(*f_unf , "eff_evtSel"); TH1F* unfoldedPtr = getHist<TH1F>(*f_unf , "nch_unfoldedPtr"); TFile* f_mc = getFile("files/outputs_full/" + dir + "/effs_MC31_ferncTr_E_7_5000000_allEffs.root"); TH1F* eff_trg_reco_mc = getHist<TH1F>(*f_mc , "eff_evtSel_RECO_HF0_" + ctr + "_RECO_" + acc); TFile* f_0b = getFile("files/outputs_full/" + dir + "/effs_zerobias_ferncTr_E_7_482270.root"); TH1F* eff_trg_reco_0b = getHist<TH1F>(*f_0b , "eff_evtSel_RECO_HF0_" + ctr + "_RECO_" + acc); TH1F* eff_syst = (TH1F*) eff_trg_gen->Clone("eff_syst"); for(int i = 1 ; i <= unfoldedPtr->GetNbinsX() ; ++i){ Double_t bin = eff_trg_gen->GetBinContent(i) + eff_trg_reco_0b->GetBinContent(i) - eff_trg_reco_mc->GetBinContent(i); if(bin>1) eff_syst->SetBinContent(i,1.); else if(bin<0) eff_syst->SetBinContent(i,0.); else eff_syst->SetBinContent(i,bin); } TH1F* eff_tot = (TH1F*) eff_trg_gen->Clone("eff_tot"); eff_tot->Multiply(eff_ctr_gen,eff_syst,1,1); TH1F* nch_data_corrected = (TH1F*) unfoldedPtr->Clone("nch_data_corrected"); nch_data_corrected->Divide(nch_data_corrected , eff_tot , 1 , 1); delete f_unf ; delete eff_ctr_gen ; delete eff_trg_gen ; delete unfoldedPtr ; delete f_mc; delete eff_trg_reco_mc; delete f_0b; delete eff_trg_reco_0b; delete eff_syst; delete eff_tot; return nch_data_corrected; }
// Add a histogram to top of a stack double addHistogram(const TString & fileName, const TString & histoName, const int color, THStack & hs, const TString & leg, TLegend *legend, const float lumi, int minIntegral=1, int maxIntegral=-1 ) { TFile * inputFile= new TFile (fileName, "READ"); TH1F * histo = (TH1F*)inputFile->Get(histoName); TH1::SetDefaultSumw2(); histo->Scale(lumi); histo->SetFillColor(color); hs.Add(histo); legend->AddEntry(histo, leg, "f"); if ( maxIntegral==-1 ) maxIntegral=histo->GetNbinsX(); return histo->Integral( minIntegral, maxIntegral ); }
// void EffCompute(TH1F& h1,TH1F& h3,TH1F& h2,TH1F& h4, TGraph& g){ void EffCompute(TH1F& h1,TH1F& h3,TH1F& h2,TH1F& h4, float X[], float Y[]){ float num1=0.; float ntot1 = 0; for (int i=0; i<h1.GetNbinsX(); i++) { ntot1 += h1.GetBinContent(i+1); } for (int i=0; i<h1.GetNbinsX(); i++) { num1 += h1.GetBinContent(i+1); float n1 = num1/ntot1; h3.SetBinContent(i+1,n1); } float num2=0.; float ntot2 = 0; for (int i=0; i<h2.GetNbinsX(); i++) { ntot2 += h2.GetBinContent(i+1); } for (int i=0; i<h2.GetNbinsX(); i++) { num2 += h2.GetBinContent(i+1); float n2 = num2/ntot2; h4.SetBinContent(i+1,n2); } const int maxbin=200; // float X[maxbin]; // float Y[maxbin]; for (int i=0; i<h1.GetNbinsX(); i++) { X[i] = h3.GetBinContent(i); // std::cout<<"X "<<X[i]<<std::endl; } for (int i=0; i<h2.GetNbinsX(); i++) { Y[i] = h4.GetBinContent(i); // std::cout<<"Y "<<Y[i]<<std::endl; } TGraph* g1 = new TGraph(h1.GetNbinsX(), X, Y); // // TGraph g1(h1.GetNbinsX(), X, Y); // g = &(g1->Clone()); }
TProfile* plotIsoPerformance( TFile* ftt, const char* signal, // histogram name const char* background, // histogram name const char* name, // unique name bool reverse = false, // normally signal near zero bin, reverse means signal is around max bin double bkg_eff_min = 0, double bkg_eff_max = 1, double sig_eff_min = 0, double sig_eff_max = 0 ) { TH1F* S = dynamic_cast<TH1F*>(ftt->Get(signal)); if ( ! S ) { std::cout << "Error: histogram not found " << signal << std::endl; return 0; } TH1F* B = dynamic_cast<TH1F*>(ftt->Get(background)); if ( ! B ) { std::cout << "Error: histogram not found " << background << std::endl; return 0; } char buf[1024]; sprintf(buf,"c_%s",name); // TCanvas* c = new TCanvas(buf,buf,500,500); sprintf(buf,"p_%s",name); TProfile* p = new TProfile(buf,buf,50,bkg_eff_min,bkg_eff_max,sig_eff_min,sig_eff_max); p->SetLineColor(kBlue); p->SetLineWidth(2); p->SetMarkerStyle(20); p->SetMarkerSize(1); p->GetXaxis()->SetTitle("Background Efficiency"); p->GetYaxis()->SetTitle("Signal Efficiency"); p->SetStats(kFALSE); for( int i=0;i<=S->GetNbinsX()+1; ++i ) if ( reverse ) p->Fill(B->Integral(i,B->GetNbinsX()+1)/B->Integral(0,B->GetNbinsX()+1), S->Integral(i,S->GetNbinsX()+1)/S->Integral(0,S->GetNbinsX()+1)); else p->Fill(B->Integral(0,i)/B->Integral(0,B->GetNbinsX()+1), S->Integral(0,i)/S->Integral(0,S->GetNbinsX()+1)); // p->Draw(); return p; }