TH1* getHistogram(TFile* inputFile, const std::string& channel, double massPoint, const std::string& directory, const std::string& histogramName, double metResolution) { std::string process = ""; if ( massPoint < 95. ) process = "ZToTauTau"; else process = Form("HToTauTau_M-%1.0f", massPoint); std::string metResolution_label = ""; if ( metResolution > 0. ) metResolution_label = Form("pfMEtRes%1.0f", metResolution); else metResolution_label = "pfMEtResMC"; std::vector<TH1*> histograms; std::string directory_process = //Form("DQMData/%s/%s/%s/%s/plotEntryType1", process.data(), channel.data(), metResolution_label.data(), directory.data()); Form("DQMData/%s/%s/%s/plotEntryType1", process.data(), channel.data(), directory.data()); histograms.push_back(getHistogram(inputFile, directory_process, histogramName)); TH1* histogramSum = NULL; for ( std::vector<TH1*>::const_iterator histogram = histograms.begin(); histogram != histograms.end(); ++histogram ) { if ( !histogramSum ) { std::string histogramSumName = std::string((*histogram)->GetName()).append("_summed"); histogramSum = (TH1*)(*histogram)->Clone(histogramSumName.data()); } else { histogramSum->Add(*histogram); } } assert(histogramSum); if ( !histogramSum->GetSumw2N() ) histogramSum->Sumw2(); if ( histogramSum->Integral() > 0. ) histogramSum->Scale(1./histogramSum->Integral()); return histogramSum; }
void QAvertex(const Char_t *fdata, const Char_t *fmc) { style(); TFile *fdtin = TFile::Open(fdata); TList *ldtin = (TList *)fdtin->Get("clist"); TH2 *hdtin = (TH2 *)ldtin->FindObject("zv"); TH1 *hdt = (TH1 *)ldtin->FindObject("zvNoSel"); SetHistoStyle(hdt, 20, kRed+1); hdt->Scale(1. / hdt->Integral()); TH1 *hdt0010 = hdtin->ProjectionX("hdt0010", 1, 4); SetHistoStyle(hdt0010, 20, kRed+1); hdt0010->Scale(1. / hdt0010->Integral()); TH1 *hdt7080 = hdtin->ProjectionX("hdt7080", 11, 11); SetHistoStyle(hdt7080, 25, kAzure-3); hdt7080->Scale(1. / hdt7080->Integral()); TFile *fmcin = TFile::Open(fmc); TList *lmcin = (TList *)fmcin->Get("clist"); TH1 *hmc = (TH1 *)lmcin->FindObject("zvNoSel"); SetHistoStyle(hmc, 25, kAzure-3); hmc->Scale(1. / hmc->Integral()); TCanvas *c = new TCanvas("cVertex", "cVertex", 800, 800); TH1 * hfr = c->DrawFrame(-20., 0., 20., 0.1); hfr->SetTitle(";#it{z}_{vtx};"); hdt0010->Draw("same"); hdt7080->Draw("same"); TLegend *legend = new TLegend(0.20, 0.18+0.60, 0.50, 0.30+0.60); legend->SetFillColor(0); legend->SetBorderSize(0); legend->SetTextFont(42); legend->SetTextSize(0.04); legend->AddEntry(hdt0010, "0-10%", "p"); legend->AddEntry(hdt7080, "70-80%", "p"); legend->Draw("same"); c->SaveAs(canvasPrefix+"vertex.pdf"); TCanvas *c1 = new TCanvas("cVertexDataMC", "cVertexDataMC", 800, 800); hfr = c1->DrawFrame(-20., 0., 20., 0.1); hfr->SetTitle(";#it{z}_{vtx};"); hdt->Draw("same"); hmc->Draw("same"); legend = new TLegend(0.20, 0.18+0.60, 0.50, 0.30+0.60); legend->SetFillColor(0); legend->SetBorderSize(0); legend->SetTextFont(42); legend->SetTextSize(0.04); legend->AddEntry(hdt, "data", "p"); legend->AddEntry(hmc, "Monte Carlo", "p"); legend->Draw("same"); c1->SaveAs(canvasPrefix+"vertexDataMC.pdf"); //return 0; }
// PValue for finding a local p-value as observed in 'bin' or worse void ToyExperiments::printGlobalPValueOfLocalFluctuation(unsigned int bin, unsigned int nExperiments) const { std::cout << "Determining global p-value for observed fluctuation in bin " << bin << " from " << nExperiments << " toy experiments ... " << std::flush; // Find the predicted yields that correspond // to the local p-value 'localPValue' std::vector<unsigned int> limitYields = yields(localPValue(bin,observedYields_.at(bin))); TH1* hIsAbovePValue = new TH1D("hIsAbovePValue","",2,0,2); const double minCorr = findMinValidRandomNumberForCorrelatedUncertainties(); for(unsigned int p = 0; p < nExperiments; ++p) { bool isAbovePValue = false; double rCorr = rand_->Gaus(0.,1.); while( rCorr <= minCorr ) { rCorr = rand_->Gaus(0.,1.); } for(unsigned int b = 0; b < Parameters::nBins(); ++b) { double prediction = -1.; bool negativePrediction = true; while( negativePrediction ) { double rUncorr = rand_->Gaus(0.,1.); double uncorrVar = rUncorr * uncorrelatedUncerts_.at(b); double corrVar = rCorr * correlatedUncerts_.at(b); prediction = meanPredictions_.at(b) + uncorrVar + corrVar; if( prediction >= 0. ) { negativePrediction = false; } } double predictedYield = rand_->Poisson(prediction); if( predictedYield >= limitYields.at(b) ) { isAbovePValue = true; break; } } if( isAbovePValue ) { hIsAbovePValue->Fill(1); } else { hIsAbovePValue->Fill(0); } } std::cout << "ok" << std::endl; double lpv = localPValue(bin,observedYields_.at(bin)); double gpUncorr = 1. - pow(1.-lpv,Parameters::nBins()); double gpCorr = hIsAbovePValue->Integral(2,2)/hIsAbovePValue->Integral(1,2); std::cout << "\n\n----- Global p-value for observed fluctuation in bin " << bin << " -----" << std::endl; std::cout << " local p-value : " << lpv << " (" << TMath::NormQuantile(1.-lpv) << "sig)" << std::endl; std::cout << " global p-value (without correlations) : " << gpUncorr << " (" << TMath::NormQuantile(1.-gpUncorr) << "sig)" << std::endl; std::cout << " global p-value (including correlations) : " << gpCorr << " (" << TMath::NormQuantile(1.-gpCorr) << "sig)" << std::endl; }
void cutFlow(bool eff = false) { using namespace std; double integral, preInt = 1.0; vector<pair<string,TFile*> > fnames; vector<pair<string,string> > hnames; hnames.push_back(pair<string,string>("none","hNu/cut0_none/mWR")); hnames.push_back(pair<string,string>("LLJJ Pt","hNu/cut1_LLJJpt/mWR")); hnames.push_back(pair<string,string>("trig","hNu/cut2_TrigMatches/mWR")); hnames.push_back(pair<string,string>("vertex","hNu/cut3_Vertex/mWR")); hnames.push_back(pair<string,string>("mu1 pt","hNu/cut4_Mu1HighPt/mWR")); hnames.push_back(pair<string,string>("Mll","hNu/cut5_diLmass/mWR")); hnames.push_back(pair<string,string>("MWR","hNu/cut6_mWRmass/mWR")); fnames.push_back(pair<string,TFile*>("ttbar powheg", new TFile("/local/cms/user/pastika/heavynu/heavynu_2011Bg_summer11_TTTo2L2Nu2B_7TeV-powheg-pythia6.root"))); fnames.push_back(pair<string,TFile*>("ttbar madgraph", new TFile("/local/cms/user/dahmes/wr2011/bgMC/Summer11/aug30/ttbar-PFJets.root"))); fnames.push_back(pair<string,TFile*>("Z+Jets sherpa", new TFile("/local/cms/user/pastika/heavynu/heavynu_2011Bg_summer11_DYToLL_M-50_7TeV-sherpa.root"))); fnames.push_back(pair<string,TFile*>("W+Jets sherpa", new TFile("/local/cms/user/pastika/heavynu/heavynu_2011Bg_summer11_WToLNu_7TeV-sherpa.root"))); fnames.push_back(pair<string,TFile*>("ZZ", new TFile("/local/cms/user/pastika/heavynu/heavynu_2011Bg_summer11_ZZ_TuneZ2_7TeV_pythia6_tauola.root"))); fnames.push_back(pair<string,TFile*>("WZ", new TFile("/local/cms/user/pastika/heavynu/heavynu_2011Bg_summer11_WZ_TuneZ2_7TeV_pythia6_tauola.root"))); fnames.push_back(pair<string,TFile*>("WW", new TFile("/local/cms/user/pastika/heavynu/heavynu_2011Bg_summer11_WW_TuneZ2_7TeV_pythia6_tauola.root"))); fnames.push_back(pair<string,TFile*>("tW", new TFile("/local/cms/user/pastika/heavynu/heavynu_2011Bg_summer11_T_TuneZ2_tW-channel-DR_7TeV-powheg-tauola.root"))); fnames.push_back(pair<string,TFile*>("tbarW", new TFile("/local/cms/user/pastika/heavynu/heavynu_2011Bg_summer11_Tbar_TuneZ2_tW-channel-DR_7TeV-powheg-tauola.root"))); printf("%8s", "cut"); for(vector<pair<string,TFile*> >::const_iterator i = fnames.begin(); i != fnames.end(); i++) { printf(eff?" & %15s ":" & %15s", i->first.c_str()); } printf(" \\\\ \\hline\n"); for(vector<pair<string,string> >::const_iterator j = hnames.begin(); j != hnames.end(); j++) { printf("%8s", j->first.c_str()); for(vector<pair<string,TFile*> >::const_iterator i = fnames.begin(); i != fnames.end(); i++) { TH1* h = (TH1*)i->second->Get(j->second.c_str()); integral = h->Integral(0, h->GetNbinsX()+1); printf((j == hnames.begin() && eff)?" & %15.0f ":" & %15.0f", integral); if(j != hnames.begin() && eff) { TH1* hpre = (TH1*)i->second->Get((j-1)->second.c_str()); preInt = hpre->Integral(0, h->GetNbinsX()+1); printf(" (%4.2f)", integral/preInt); } } printf(" \\\\ \\hline\n"); } }
void fadc_fit_heights(std::string fadc_id,std::string hist_type) { /*****************************************************************/ // Prepare the canvas gStyle->SetOptFit(1111); TCanvas *AlCapCanvas = (TCanvas *) gROOT->GetListOfCanvases()->At(0); AlCapCanvas->Clear(); AlCapCanvas->Divide(4,2); // gROOT->ProcessLine(".L common/get_histogram.C"); // get_histogram() is called here /*****************************************************************/ const int n_channels = 8; std::string bank_names[n_channels] = {"Na", "Nb", "Nc", "Nd", "Ne", "Nf", "Ng", "Nh"}; std::string name; double mean = 0; double rms = 0; for (int iChn = 0; iChn < n_channels; iChn++) { name=bank_names[iChn]+fadc_id; TH1* hist = get_histogram(name, hist_type); mean = hist->GetMean(); rms = hist->GetRMS(); AlCapCanvas->cd(iChn+1); if (hist->Integral()!=0) { TF1* gaus = new TF1("gaus","gaus",mean-rms,mean+rms); hist->Fit("gaus","Q"); hist->GetXaxis()->SetRange(mean-2*rms,mean+2*rms); hist->Draw(); } } }
void makeplotTwo(TH1& hist1, TH1& hist2, const char* plotname, int logy) { hist1.SetLineColor(4); hist1.SetMarkerColor(4); gStyle->SetOptStat(0); TCanvas* can = new TCanvas( plotname, plotname, 500, 500); hist1.Draw( ); hist2.Draw( "same" ); TLegend *leg = new TLegend(0.55,0.8,0.89,0.92); leg->AddEntry( &hist1,"Reconstructed","LP"); leg->AddEntry( &hist2,"Generated","L"); leg->SetFillColor(0); leg->SetLineColor(0); leg->Draw(); can->SetLogy( logy ); if(logy==2) hist1.GetYaxis()->SetMoreLogLabels(); std::string plot(cmEnergy); plot.append(plotname); can->SaveAs( (plot+".eps").c_str() ); can->SaveAs( (plot+".gif").c_str() ); can->SaveAs( (plot+".root").c_str() ); // delete can; cout << hist1.Integral() << endl; }
// show the histogram in first slot, try a Gaussian fit with given parameters void PRadHistCanvas::UpdateHist(int index, TObject *tob, int range_min, int range_max) { --index; if(index < 0 || index >= canvases.size()) return; canvases[index]->cd(); canvases[index]->SetGrid(); gPad->SetLogy(); TH1 *hist = (TH1*)tob; hist->GetXaxis()->SetRangeUser(hist->FindFirstBinAbove(0,1) - 10, hist->FindLastBinAbove(0,1) + 10); hist->GetXaxis()->SetLabelSize(HIST_LABEL_SIZE); hist->GetYaxis()->SetLabelSize(HIST_LABEL_SIZE); // try to fit gaussian in certain range if(range_max > range_min && hist->Integral(range_min, range_max + 1) > 0) { TF1 *fit = new TF1("", "gaus", range_min, range_max); fit->SetLineColor(kRed); fit->SetLineWidth(2); hist->Fit(fit,"qlR"); } hist->SetFillColor(fillColors[index]); hist->Draw(); canvases[index]->Refresh(); }
// Extract and merge histograms in range [from, to) (to is not included) // TH1 *merge(const string &path, TFile **input, const int &from, const int &to, const bool &do_normalize = false) { TH1 *result = 0; for(int i = from; to > i; ++i) { TH1 *hist = get(path, input[i], i); if (!hist) { cerr << "failed to extract: " << path << endl; continue; } if (!result) result = dynamic_cast<TH1 *>(hist->Clone()); else result->Add(hist); } if (do_normalize && result && result->GetEntries()) { result->Scale(1. / result->Integral()); } return result; }
void makeplotThree(TH1& hist1, TH1& hist2, TH1& hist3, const char* plotname, int log) { hist1.SetLineColor(4); hist1.SetMarkerColor(4); hist3.SetLineColor(2); hist3.SetMarkerColor(2); gStyle->SetOptStat(0); TCanvas* can = new TCanvas( plotname, plotname, 500, 500); hist1.Draw( ); hist2.Draw( "same" ); hist3.Draw( "same" ); TLegend *leg = new TLegend(0.48,0.7,0.89,0.92); leg->AddEntry( &hist1,"CaloJet","LP"); leg->AddEntry( &hist3,"PF Jet","LP"); leg->AddEntry( &hist2,"GenJet","L"); leg->SetFillColor(0); leg->SetLineColor(0); leg->Draw(); can->SetLogy( log ); if(log==2) { can->SetLogy( 1 ); hist1.GetYaxis()->SetMoreLogLabels(); } std::string plot("ratio-"); plot.append(plotname); can->SaveAs( (plot+".eps").c_str() ); can->SaveAs( (plot+".gif").c_str() ); can->SaveAs( (plot+".root").c_str() ); // delete can; cout << hist1.Integral() << endl; }
void QAcentrality(const Char_t *fdata) { style(); TFile *fin = TFile::Open(fdata); TList *lin = (TList *)fin->Get("clist"); lin->ls(); TH1 *hin = (TH1 *)lin->FindObject("EvCentrDist"); Float_t sum = 1.2 * hin->Integral(hin->FindBin(0.1), hin->FindBin(79.9)); hin->Scale(1. / sum); SetHistoStyle(hin, 20, kRed+1); TCanvas *c = new TCanvas("cQAcentrality", "cQAcentrality", 800, 800); TH1 * hfr = c->DrawFrame(0., 0.005, 100., 0.015); hfr->SetTitle(";centrality percentile;events"); hin->Draw("same"); c->SaveAs(canvasPrefix+"centrality.pdf"); TH2 *hinv0 = (TH2 *)lin->FindObject("V0"); TCanvas *cv0 = new TCanvas("cQAcentralityV0", "cQAcentralityV0", 800, 800); cv0->SetLogx(); cv0->SetLogz(); // TH1 * hfrv0 = cv0->DrawFrame(100., -0.5, 50000., 10.5); // DrawBinLabelsY(hfrv0, kTRUE); // hfrv0->SetTitle(";V0 signal;"); //hinv0->Draw("same,col"); hinv0->Draw("col"); cv0->SaveAs(canvasPrefix+"centralityV0.pdf"); }
void GetSigEfficiency(TString path, TString tag){ setTDRStyle(); //gStyle->SetPalette(1); TFile * file = new TFile(path); TH1* hnsig = (TH1F*)file->Get(("eventcutflow")); float nsig = float(hnsig->GetBinContent(2)); TString hist = tag + "MassRegion/h_Nelectrons_" + tag + "MassRegion"; TH1* h = (TH1*)file->Get(hist.Data()); cout << h << endl; cout << h->Integral() << endl; cout << nsig << endl; cout << "Total efficiency " << tag << " = " << 100* (h->Integral() / nsig) << endl; }
void compareDYTemplates(TString baseURL="~/scratch0/top-newjec/syst_plotter.root") { TString ch[]={"ee","mumu"}; TString categs[]={"eq1jets",""}; for(size_t ich=0; ich<2; ich++) { for(size_t icat=0; icat<2; icat++) { TObjArray lowMet = getDistributionFromPlotter(ch[ich]+"_"+categs[icat]+"lowmetdilarccosine",baseURL); TH1 *lowMetH = (TH1 *) ((TList *)lowMet.At(3))->At(3); formatPlot(lowMetH,1,1,1,24,0,false,false,1,1,1); lowMetH->SetTitle("E_{T}^{miss}<30 GeV/c^{2}"); lowMetH->Scale(1./lowMetH->Integral()); TObjArray highMet = getDistributionFromPlotter(ch[ich]+"_"+categs[icat]+"dilarccosine",baseURL); TH1 *highMetH = (TH1 *) ((TList *)highMet.At(3))->At(3); formatPlot(highMetH,1,1,1,20,0,false,false,1,1,1); highMetH->SetTitle("E_{T}^{miss}>30 GeV/c^{2}"); highMetH->Scale(1./highMetH->Integral()); TString channelTitle(ich==0 ? "ee" : "#mu#mu"); if(categs[icat]=="eq1jets") channelTitle += "+ 1 jet"; else channelTitle += "+ #geq 2 jets"; //draw TString plot(ch[ich]+categs[icat]+"_anglecomparison"); TCanvas *cnv = getNewCanvas(plot+"c",plot+"c",false); cnv->Clear(); cnv->SetWindowSize(600,600); cnv->cd(); TList *mc = new TList; mc->Add(lowMetH); TList *data = new TList; data->Add(highMetH); TList *spimpose = new TList; TLegend *leg=showPlotsAndMCtoDataComparison(cnv,*mc,*spimpose,*data,false); TPad *p=(TPad *)cnv->cd(1); formatForCmsPublic(p,leg,"CMS simulation, " + channelTitle, 4); cnv->SaveAs(plot+".C"); cnv->SaveAs(plot+".pdf"); cnv->SaveAs(plot+".png"); } } }
TH1* getMonitorElement(TFile* inputFile, const TString& dqmDirectoryName, const char* processName, const TString& meName) { TString meName_full = TString("DQMData/tauFakeRate/harvested").Append("/").Append(processName).Append("/").Append(dqmDirectoryName).Append("/").Append(meName); //TString meName_full = TString("DQMData").Append("/").Append(dqmDirectoryName).Append("/").Append(meName); std::cout << "meName_full = " << meName_full << std::endl; TH1* me = (TH1*)inputFile->Get(meName_full); std::cout << "me = " << me << std::endl; std::cout << "integral = " << me->Integral() << std::endl; return me; }
double IntegralStack(THStack* stack) { double val=0; TList* list = stack->GetHists(); TIter it(list, true); TObject* obj=0; while( (obj = it.Next()) ) { TH1* h = dynamic_cast<TH1*>(obj); val += h->Integral(); } return val; }
TEST_F(EvalHistMethods, CreateHistogram1D) { evaluator->SetNormalizationBuffer(norm); evaluator->SetParameterBuffer(params); TH1* hist = evaluator->CreateHistogram(); EXPECT_EQ(2, hist->GetNbinsX()); ASSERT_FLOAT_EQ(1.0, hist->Integral("width")); ASSERT_FLOAT_EQ(1.6, hist->GetBinContent(hist->FindBin(0.25))); ASSERT_FLOAT_EQ(0.4, hist->GetBinContent(hist->FindBin(0.75))); delete hist; }
void makeplot(TH1& hist, const char* plotname, const char* option, int log) { gStyle->SetOptStat(0); TCanvas* can = new TCanvas( plotname, plotname, 500, 500); hist.Draw( option ); can->SetLogy( log ); std::string plot(cmEnergy); plot.append(plotname); can->SaveAs( (plot+".eps").c_str() ); can->SaveAs( (plot+".gif").c_str() ); can->SaveAs( (plot+".root").c_str() ); // delete can; cout << hist.Integral() << endl; }
TH1D * myReweightor(TH2D* ttMtop2D, std::pair<TF1, WeightFunctionCreator*> weightFunc, TString Name){ TH1D * res = new TH1D(Name, Name, ttMtop2D->GetYaxis()->GetNbins(), ttMtop2D->GetYaxis()->GetXmin(), ttMtop2D->GetYaxis()->GetXmax()); for(int i = 1; i < (res->GetXaxis()->GetNbins() + 1); i++){ double nSignal = 0; gROOT->cd(); TH1* hithrecbin = ttMtop2D->ProjectionX("_pX", i, i, "o"); hithrecbin->Multiply(&(weightFunc.first), 1); nSignal = hithrecbin->Integral(); if (hithrecbin != NULL) delete hithrecbin; res->SetBinContent(i, nSignal); } return res; }
void fit() { FILE *ofile; ofile = fopen("xsect-integrated-me.txt","w"); TFile *_file0 = TFile::Open("h3maker-hn.root","update"); _file0->Delete("*_f;*"); TH2 *h2xsect = new TH2("hq2wXsect","Q^2:W",32,1.6,3.2,7,1.5,5.1); Double_t qbinedges[] = { 1.5, 1.6, 1.8, 2.1, 2.4, 2.76, 3.3, 5.1 }; h2xsect->GetYaxis()->Set(7,qbinedges); TH3 *h3 = (TH3*)_file0->Get("hq2wmmp"); int qbins = h3->GetZaxis()->GetNbins(); int wbins = h3->GetYaxis()->GetNbins(); fprintf(ofile, "W\tQ2\txsect\terror\tpol4p0\tpol4p1\tpol4p2\tpol4p3\tpol4p4\tgN\tgM\tgS\n"); for (int iq = 0; iq < qbins; iq++) { TString hsn = TString::Format("hs%d",iq); THStack *hs = (THStack*)_file0->Get(hsn.Data()); TIter next(hs->GetHists()); //while (TObject *obj = next()) { //TH1 *h = (TH1*)obj; while (TH1 *h = (TH1*)next()) { float *wq = getwq(h); float wval = wq[0]; float qval = wq[1]; fitmmp(h); TH1 *htmp = (TH1*)h->Clone("hbgsubtracted"); TF1 *fbg = (TF1*)h->GetListOfFunctions()->FindObject("fbg"); htmp->Add(fbg,-1); double N = htmp->Integral(34,43); double qwidth = h3->GetZaxis()->GetBinWidth(iq+1); int wbin = h3->GetYaxis()->FindBin(wval); double wwidth = h3->GetYaxis()->GetBinWidth(wbin); double xsect = N/(0.891*wwidth*qwidth*19.844); double err2 = 0; for (int immp = 34; immp < 44; immp++) err2 += htmp->GetBinError(immp)*htmp->GetBinError(immp); //fprintf(ofile, "%.3f\t%.3f\t%.0f\t%.0f",wval,qval,xsect/(1e6), sqrt(err2)/(1e6)); fprintf(ofile, "%.3f\t%.3f\t%.3e\t%.3e",wval,qval,xsect/(1e6), sqrt(err2)/(1e6)); TF1 *ftmp = (TF1*)h->GetListOfFunctions()->At(0); int npar = ftmp->GetNpar(); for (int ipar = 0; ipar < npar; ipar++) fprintf(ofile, "\t%.3e", ftmp->GetParameter(ipar)); fprintf(ofile, "\n"); } hsn.Append("_f"); _file0->WriteObject(hs,hsn.Data()); delete hs; } fclose(ofile); delete _file0; }
TH1 *computeEffVsCut(TH1 *discrShape, double total) { TH1 *h = discrShape->Clone(Form("%s_effVsCut", discrShape->GetName())); h->Sumw2(); h->SetMaximum(1.5); h->SetMinimum(1e-3); unsigned int n = h->GetNbinsX(); for(unsigned int bin = 1; bin <= n; bin++) { double efficiency = h->Integral(bin, n + 1) / total; double error = sqrt(efficiency * (1 - efficiency) / total); h->SetBinContent(bin, efficiency); h->SetBinError(bin, error); } return h; }
TH1* getHistogram(TFile* inputFile, const TString& dqmDirectory, const TString& meName) { TString histogramName = dqmDirectory; if ( histogramName.Length() > 0 && !histogramName.EndsWith("/") ) histogramName.Append("/"); histogramName.Append(meName); TH1* histogram = (TH1*)inputFile->Get(histogramName.Data()); std::cout << "histogramName = " << histogramName.Data() << ": histogram = " << histogram; if ( histogram ) std::cout << ", integral = " << histogram->Integral(); std::cout << std::endl; if ( !histogram->GetSumw2N() ) histogram->Sumw2(); if ( histogram->GetDimension() == 1 ) histogram->Rebin(5); return histogram; }
// Do the loop here, so that we can use options like "errors" void Draw( const TString & xTitle = "", const TString & yTitle = "", const bool errors = false ) { // Create a new THStack so that it handle tha maximum // THStack stack(name_, title_); THStack * stack = new THStack(name_, title_); int colorIndex = 0; if( !(histoList_.empty()) ) { std::vector<TH1*>::iterator histoIter = histoList_.begin(); for( ; histoIter != histoList_.end(); ++histoIter, ++colorIndex ) { TH1 * histo = *histoIter; if(errors) histo->Sumw2(); // histo->SetNormFactor(1); if( colorIndex < 4 ) histo->SetLineColor(colors_[colorIndex]); else histo->SetLineColor(colorIndex); // Draw and get the maximum value TString normalizedHistoName(histo->GetName()); TH1 * normalizedHisto = (TH1*)histo->Clone(normalizedHistoName+"clone"); normalizedHisto->Scale(1/normalizedHisto->Integral()); stack->Add(normalizedHisto); } // Take the maximum of all the drawed histograms // First we need to draw the histogram, or getAxis() will return 0... (see root code...) canvas_->Draw(); canvas_->cd(); stack->Draw("nostack"); stack->GetYaxis()->SetTitleOffset(1.2); stack->GetYaxis()->SetTitle(yTitle); stack->GetXaxis()->SetTitle(xTitle); stack->GetXaxis()->SetTitleColor(kBlack); stack->Draw("nostack"); legend_->Draw("same"); canvas_->Update(); canvas_->Draw(); canvas_->ForceUpdate(); //canvas_->Print("test.pdf"); canvas_->Write(); } }
TH1* getMonitorElement(TFile* inputFile, const TString& dqmDirectory, const char* dqmSubDirectory, const TString& meName) { TString meName_full = TString("DQMData").Append("/"); if ( dqmDirectory != "") meName_full.Append(dqmDirectory).Append("/"); meName_full.Append(dqmSubDirectory).Append("/").Append(meName); std::cout << "meName_full = " << meName_full << std::endl; TH1* me = (TH1*)inputFile->Get(meName_full); std::cout << "me = " << me << std::endl; //if ( !me->GetSumw2() ) me->Sumw2(); me->Sumw2(); me->Rebin(2); me->Scale(1./me->Integral()); me->SetMaximum(1.); me->SetStats(false); return me; }
void patBJetTracks_efficiencies() { // define proper canvas style setNiceStyle(); gStyle->SetOptStat(0); // open file TFile* file = new TFile("analyzePatBJetTracks.root"); TLegend *legend[3] = { 0, 0, 0 }; // draw canvas with efficiencies TCanvas *canv; canv = new TCanvas("canv0", "hand-crafted track counting efficiencies", 800, 300); canv->Divide(3, 1); TH1 *total = (TH1*)file->Get(Form("%s/flavours", directory)); TH1 *effVsCutB = 0; unsigned int i = 0; for(const char **flavour = flavours; *flavour; flavour++, i++) { TH1 *h = (TH1*)file->Get(Form("%s/trackIPSig_%s", directory, *flavour)); TH1 *discrShape = (TH1*)h->Clone(Form("%s_discrShape", h->GetName())); discrShape->Scale(1.0 / discrShape->Integral()); discrShape->SetMaximum(discrShape->GetMaximum() * 5); TH1 *effVsCut = computeEffVsCut(h, total->GetBinContent(4 - i)); TH1 *effVsBEff = 0; if (flavour == flavours) // b-jets effVsCutB = effVsCut; else effVsBEff = computeEffVsBEff(effVsCut, effVsCutB); discrShape->SetTitle("discriminator shape"); effVsCut->SetTitle("efficiency versus discriminator cut"); if (effVsBEff) effVsBEff->SetTitle("mistag versus b efficiency"); setHistStyle(discrShape); setHistStyle(effVsCut); setHistStyle(effVsBEff); canv->cd(1); gPad->SetLogy(1); gPad->SetGridy(1); discrShape->SetLineColor(i + 1); discrShape->SetMarkerColor(i + 1); discrShape->Draw(i > 0 ? "same" : ""); if (!legend[0]) legend[0] = new TLegend(0.5, 0.7, 0.78, 0.88); legend[0]->AddEntry(discrShape, *flavour); canv->cd(2); gPad->SetLogy(1); gPad->SetGridy(1); effVsCut->SetLineColor(i + 1); effVsCut->SetMarkerColor(i + 1); effVsCut->Draw(i > 0 ? "same" : ""); if (!legend[1]) legend[1] = new TLegend(0.12, 0.12, 0.40, 0.30); legend[1]->AddEntry(effVsCut, *flavour); if (!effVsBEff) continue; canv->cd(3); gPad->SetLogy(1); gPad->SetGridx(1); gPad->SetGridy(1); effVsBEff->SetLineColor(i + 1); effVsBEff->SetMarkerColor(i + 1); effVsBEff->Draw(i > 1 ? "same" : ""); if (!legend[2]) legend[2] = new TLegend(0.12, 0.7, 0.40, 0.88); legend[2]->AddEntry(effVsBEff, *flavour); } canv->cd(1); legend[0]->Draw(); canv->cd(2); legend[1]->Draw(); canv->cd(3); legend[2]->Draw(); //////////////////////////////////////////// // canvas to compare negative tagger with light flavour mistag TCanvas *canv; canv = new TCanvas("canv1", "comparing light flavour mistag with negative tagger", 530, 300); canv->Divide(2, 1); TH1 *h1 = (TH1*)file->Get(Form("%s/trackIPSig_udsg", directory)); TH1 *h2 = (TH1*)file->Get(Form("%s/negativeIPSig_all", directory)); h2 = invertHisto(h2); // invert x-axis TH1 *discrShape1 = (TH1*)h1->Clone("discrShape1"); TH1 *discrShape2 = (TH1*)h2->Clone("discrShape2"); discrShape1->Scale(1.0 / discrShape1->Integral()); discrShape1->SetMaximum(discrShape1->GetMaximum() * 5); discrShape2->Scale(1.0 / discrShape2->Integral()); TH1 *effVsCut1 = computeEffVsCut(h1, total->GetBinContent(2)); TH1 *effVsCut2 = computeEffVsCut(h2, total->GetBinContent(1)); discrShape1->SetTitle("discriminator shape"); effVsCut1->SetTitle("efficiency versus discriminator cut"); setHistStyle(discrShape1); setHistStyle(discrShape2); setHistStyle(effVsCut1); setHistStyle(effVsCut2); canv->cd(1); gPad->SetLogy(1); gPad->SetGridy(1); discrShape1->SetLineColor(1); discrShape1->SetMarkerColor(1); discrShape2->SetLineColor(2); discrShape2->SetMarkerColor(2); discrShape1->Draw(); discrShape2->Draw("same"); TLegend *l = new TLegend(0.5, 0.7, 0.78, 0.88); l->AddEntry(discrShape1, "udsg"); l->AddEntry(discrShape2, "inv. neg"); l->Draw(); canv->cd(2); gPad->SetLogy(1); gPad->SetGridy(1); effVsCut1->SetLineColor(1); effVsCut1->SetMarkerColor(1); effVsCut2->SetLineColor(2); effVsCut2->SetMarkerColor(2); effVsCut1->Draw(); effVsCut2->Draw("same"); l = new TLegend(0.5, 0.7, 0.78, 0.88); l->AddEntry(effVsCut1, "udsg"); l->AddEntry(effVsCut2, "inv. neg"); l->Draw(); }
void Draw( const TString & xTitle = "", const TString & yTitle = "", const bool errors = false ) { canvas_->cd(); if( !(histoList_.empty()) ) { TString mergedName = histoList_[0]->GetName(); mergedName+="_Merged"; TH1 * histo_Merged = (TH1*)histoList_[0]->Clone(mergedName); histo_Merged->Reset(); std::vector<TH1*>::iterator histoIter = histoList_.begin(); int scaleFactorIndex = 0; for( ; histoIter != histoList_.end(); ++histoIter, ++scaleFactorIndex ) { TH1 * histo = *histoIter; if( scaleFactor[scaleFactorIndex] != 0 ) histo_Merged->Add(histo, scaleFactor[scaleFactorIndex]/histo->Integral()); else histo_Merged->Add(histo); } if(errors) histo_Merged->Sumw2(); histo_Merged->GetXaxis()->SetTitle(xTitle); histo_Merged->GetYaxis()->SetTitleOffset(1.2); histo_Merged->GetYaxis()->SetTitle(yTitle); histo_Merged->Draw(); canvas_->Draw(); canvas_->Write(); } }
TH1 * UnfoldMe_MB2(const Char_t *data, const Char_t *mc, const Char_t *anatag, Int_t bin, Bool_t useMBcorr , Bool_t usecorrfit , Bool_t ismc , Float_t smooth , Int_t iter , Int_t regul , Float_t weight , Bool_t bayesian , Int_t nloop ) { // MF comments: // usedMBcorr: changes the matrix used for unfonding, from effMatrix to bin matrix (I think this is just to use mult dependent v s mb correction_) // usecorrfit: if I understand correctly, fits the response matrix and uses fit to extrapolate it TFile *fdt =0; if (ismc) fdt = TFile::Open(data); else fdt = TFile::Open(data); TFile *fmc = TFile::Open(mc); TList *ldt = (TList *)fdt->Get(Form("%s", anatag)); TList *lmc = (TList *)fmc->Get(Form("%s", anatag)); TH2 *hmatdt = (TH2 *)ldt->FindObject(Form(responseMatrix, bin)); TH2 *hmatmc = 0; if (useMBcorr){ hmatmc = (TH2 *)lmc->FindObject("effMatrix"); std::cout << "USING MB" << std::endl; } else { hmatmc = (TH2 *)lmc->FindObject(Form(responseMatrix, bin)); } TH1 *hdata = hmatdt->ProjectionY("hdata"); // TH1 *hdata = hmatdt->ProjectionY("htrue"); // For truth Only Calculations hdata->Sumw2(); hdata->SetBinContent(1, 0.); hdata->SetBinError(1, 0.); // hdata->Scale(1. / hdata->Integral()); hdata->SetMarkerStyle(25); TH1 *htrue = hmatdt->ProjectionX("htrue"); htrue->Sumw2(); // htrue->Scale(1. / htrue->Integral()); htrue->SetMarkerStyle(7); htrue->SetMarkerColor(2); htrue->SetBinContent(1, 0.); htrue->SetBinError(1, 0.); TH2 *hcorr = (TH2 *)hmatmc->Clone("hcorr"); TH1 *hinit = (TH1 *)hdata->Clone("hinit"); TH1 *hresu = (TH1 *)hdata->Clone("hresu"); TH1 *hbias = (TH1 *)hdata->Clone("hbias"); hresu->SetMarkerStyle(20); hresu->SetMarkerColor(4); hresu->Reset(); TH1 *hnum = hcorr->ProjectionY("hnum"); TH1 *hden = hcorr->ProjectionY("hden"); TH1 *heff = hcorr->ProjectionY("heff"); hnum->Reset(); hnum->Sumw2(); hden->Reset(); hden->Sumw2(); heff->Reset(); for (Int_t i = 0; i < heff->GetNbinsX(); i++) { Float_t int1 = hcorr->Integral(i + 1, i + 1, 0, -1); if (int1 <= 0.) continue; Float_t int2 = hcorr->Integral(i + 1, i + 1, 2, -1); hnum->SetBinContent(i + 1, int2); hnum->SetBinError(i + 1, TMath::Sqrt(int2)); hden->SetBinContent(i + 1, int1); hden->SetBinError(i + 1, TMath::Sqrt(int1)); } TCanvas *cEfficiency = new TCanvas("cEfficiency", "cEfficiency"); cEfficiency->SetLogx(); cEfficiency->SetLogy(); heff->Divide(hnum, hden, 1., 1., "B"); heff->Draw(); #if 0 for (Int_t ii = 0; ii < heff->GetNbinsX(); ii++) { heff->SetBinContent(ii + 1, 1.); heff->SetBinError(ii + 1, 0.); } #endif for (Int_t i = 0; i < hcorr->GetNbinsX(); i++) { hcorr->SetBinContent(i + 1, 1, 0.); hcorr->SetBinError(i + 1, 1, 0.); } for (Int_t i = 0; i < hcorr->GetNbinsY(); i++) { hcorr->SetBinContent(1, i + 1, 0.); hcorr->SetBinError(1, i + 1, 0.); } TH2 *hcorrfit = ReturnCorrFromFit(hcorr); // Docs from AliUnfolding //Int_t AliUnfolding::Unfold(TH2* correlation, TH1* efficiency, TH1* measured, TH1* initialConditions, TH1* result, Bool_t check) // unfolds with unfolding method fgMethodType // // parameters: // correlation: response matrix as measured vs. generated // efficiency: (optional) efficiency that is applied on the unfolded spectrum, i.e. it has to be in unfolded variables. If 0 no efficiency is applied. // measured: the measured spectrum // initialConditions: (optional) initial conditions for the unfolding. if 0 the measured spectrum is used as initial conditions. // result: target for the unfolded result // check: depends on the unfolding method, see comments in specific functions for (Int_t iloop = 0; iloop < nloop; iloop++) { if (bayesian) { AliUnfolding::SetUnfoldingMethod(AliUnfolding::kBayesian); AliUnfolding::SetBayesianParameters(smooth, iter); } else { AliUnfolding::SetUnfoldingMethod(AliUnfolding::kChi2Minimization); AliUnfolding::SetChi2Regularization(AliUnfolding::RegularizationType(regul), weight); } AliUnfolding::SetSkip0BinInChi2(kTRUE); AliUnfolding::SetSkipBinsBegin(1); AliUnfolding::SetNbins(150, 150); AliUnfolding::Unfold(usecorrfit ? hcorrfit : hcorr, heff, hdata, hinit, hresu); hinit = (TH1 *)hresu->Clone(Form("hinit_%d", iloop)); } printf("hdata->Integral(2, -1) = %f\n", hdata->Integral(2, -1)); printf("hresu->Integral(2, -1) = %f\n", hresu->Integral(2, -1)); TCanvas *cUnfolded = new TCanvas ("cUnfolded", "cUnfolded", 400, 800); cUnfolded->Divide(1, 2); cUnfolded->cd(1)->SetLogx(); cUnfolded->cd(1)->SetLogy(); hdata->Draw(); hresu->Draw("same"); htrue->Draw("same"); cUnfolded->cd(2)->SetLogx(); cUnfolded->cd(2)->DrawFrame(1., 0, 300., 10); TH1 *hrat = (TH1 *)hresu->Clone("hrat"); hrat->Divide(htrue); hrat->Draw("same"); TH1 *htrig = (TH1 *)hresu->Clone("htrig"); htrig->Multiply(heff); Float_t dndeta_resu = 0.; Float_t integr_resu = 0.; Float_t dndeta_trig = 0.; Float_t integr_trig = 0.; for (Int_t i = 1; i < hresu->GetNbinsX(); i++) { dndeta_resu += hresu->GetBinContent(i + 1) * hresu->GetBinLowEdge(i + 1); integr_resu += hresu->GetBinContent(i + 1); dndeta_trig += htrig->GetBinContent(i + 1) * htrig->GetBinLowEdge(i + 1); integr_trig += htrig->GetBinContent(i + 1); } cUnfolded->SaveAs("unfold_efficiency.pdf"); integr_eff = integr_trig / integr_resu; integr_eff_err = TMath::Sqrt(integr_eff * (1. - integr_eff) / integr_resu); dndeta_eff = dndeta_trig / dndeta_resu; dndeta_eff_err = TMath::Sqrt(dndeta_eff * (1. - dndeta_eff) / dndeta_resu); printf("INEL > 0 efficiency: %.3f +- %.3f\n", integr_eff, integr_eff_err); printf("dN/dEta correction: %.3f +- %.3f\n", dndeta_eff, dndeta_eff_err); return hresu; }
int main(int argc, char** argv) { WTempForCombination3D input7; WTempForCombination3D input8; WTempForCombination3D input7tmp; WTempForCombination3D input8tmp; TH1* bkginsignal7 = 0; //for t-processes other than munub TH1* bkg7 = 0; // for non-t processes TH1* bkginsignal8 = 0; //for t-processes other than munub TH1* bkg8 = 0; // for non-t processes bool singleMatrix = false; bool is2Drecgen = false; bool do3D = false; int muRebin = 1; int eRebin = 1; double f0mu = 0; double flmu = 0; double fmu = 1.; double nwmu = -1.; std::vector<std::string> namings7; //electron channel namings7.push_back(string("die")); namings7.push_back(string("ehad")); namings7.push_back(string("etau")); namings7.push_back("mue"); std::vector<std::string> namings8; namings8.push_back(string("dimu")); namings8.push_back(string("muhad")); namings8.push_back(string("mutau")); namings8.push_back("mue"); TFile * file = 0; int iRandom = 0; for (int f = 1; f < argc; f++) { std::string arg_fth(*(argv + f)); if (iRandom == 0) cout << f << " ---- " << arg_fth << endl; if (arg_fth == "fzRef") { f++; std::string out(*(argv + f)); f0mu = atof(out.c_str()); } else if (arg_fth == "flRef") { f++; std::string out(*(argv + f)); flmu = atof(out.c_str()); } else if (arg_fth == "fRef") { f++; std::string out(*(argv + f)); fmu = atof(out.c_str()); } else if (arg_fth == "nwRef") { f++; std::string out(*(argv + f)); nwmu = atof(out.c_str()); } else if (arg_fth == "signal7") { f++; std::string out(*(argv + f)); if (iRandom == 0) cout << "signal7" << endl; file = new TFile(out.c_str(), "read"); bool muonfile = false; for (unsigned int i = 0; i < namings7.size(); i++) { int pos = string(file->GetName()).find(namings7[i].c_str()); muonfile = (pos >= 0 && pos < string(file->GetName()).size()); if (muonfile) { if (iRandom == 0) { cout << "I am in signal7 (electron) channel and I accept "; cout << file->GetName() << " as signal" << endl; } break; } } if (!do3D || (do3D && !muonfile)) { input7tmp.rest.signalIID.push_back(((TH2*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta2D"))->RebinY(eRebin)); if (iRandom == 0) cout << input7tmp.rest.signalIID.at(input7tmp.rest.signalIID.size() - 1)->GetName() << endl; if (iRandom == 0) cout << "signal2D integral 7: " << input7tmp.rest.signalIID.at(input7tmp.rest.signalIID.size() - 1)->Integral() << endl; } if (do3D && muonfile) { if (iRandom == 0) cout << " in 3D :-)" << endl; input7tmp.rest.signalIIID.push_back(((TH3D*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta3D"))->Rebin3D(1, eRebin, 1, "newname")); if (iRandom == 0) cout << input7tmp.rest.signalIIID.at(input7tmp.rest.signalIIID.size() - 1) << endl; } if (iRandom == 0) if (input7tmp.rest.signalIID.size()) cout << input7tmp.rest.signalIID.at(input7tmp.rest.signalIID.size() - 1)->GetNbinsY() << endl; if (bkginsignal7 == 0) bkginsignal7 = (((TH1*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta"))->Rebin(eRebin)); else bkginsignal7->Add(((TH1*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta"))->Rebin(eRebin)); } else if (arg_fth == "signal8") { f++; std::string out(*(argv + f)); if (iRandom == 0) cout << "signal8" << endl; file = new TFile(out.c_str(), "read"); bool muonfile = false; for (unsigned int i = 0; i < namings8.size(); i++) { int pos = string(file->GetName()).find(namings8[i].c_str()); muonfile = (pos >= 0 && pos < string(file->GetName()).size()); if (muonfile) { if (iRandom == 0) cout << "I am in signal8 (muon) channel and I accept "; if (iRandom == 0) cout << file->GetName() << " as signal" << endl; break; } } if (!do3D || (do3D && !muonfile)) { input8tmp.rest.signalIID.push_back(((TH2*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta2D"))->RebinY(muRebin)); if (iRandom == 0) { cout << input8tmp.rest.signalIID.at(input8tmp.rest.signalIID.size() - 1)->GetName() << endl; cout << "signal2D integral 8: " << input8tmp.rest.signalIID.at(input8tmp.rest.signalIID.size() - 1)->Integral() << endl; } } if (do3D && muonfile) { if (iRandom == 0) cout << " in 3D :-)" << endl; input8tmp.rest.signalIIID.push_back(((TH3D*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta3D"))->Rebin3D(1, muRebin, 1, "newname")); if (iRandom == 0) cout << input8tmp.rest.signalIIID.at(input8tmp.rest.signalIIID.size() - 1) << endl; } if (input8tmp.rest.signalIID.size()) if (iRandom == 0) cout << input8tmp.rest.signalIID.at(input8tmp.rest.signalIID.size() - 1)->GetNbinsY() << endl; if (bkginsignal8 == 0) bkginsignal8 = (((TH1*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta"))->Rebin(muRebin)); else bkginsignal8->Add(((TH1*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta"))->Rebin(muRebin)); } else if (arg_fth == "data7") { f++; std::string out(*(argv + f)); if (iRandom == 0) cout << "data 7" << endl; file = new TFile(out.c_str(), "read"); input7tmp.rest.data = ((TH1*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta"))->Rebin(eRebin); } else if (arg_fth == "data8") { f++; std::string out(*(argv + f)); if (iRandom == 0) cout << "data 8" << endl; file = new TFile(out.c_str(), "read"); input8tmp.rest.data = ((TH1*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta"))->Rebin(muRebin); } else if (arg_fth == "bkg7") { f++; std::string out(*(argv + f)); if (iRandom == 0) cout << "bkg 7" << endl; file = new TFile(out.c_str(), "read"); // if (bkg7 == NULL) { // cout << "here .." << endl; // bkg7 = ((TH1*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta"))->Rebin(1); // } else { // bkg7->Add(((TH1*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta"))->Rebin(1)); // } bool myQCD = (out.find("_QCD.root") > 0 && fabs(out.find("_QCD.root")) < out.size()); if (iRandom == 0) cout << file->GetName() << "\tmyQCD: " << myQCD << endl; TH1 * tmpQCD = 0; if (myQCD) { tmpQCD = ((TH1*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta"))->Rebin(eRebin); if (iRandom == 0) cout << "tmpQCD: " << tmpQCD << endl; tmpQCD->Scale(107.5 / tmpQCD->Integral()); if (iRandom == 0) cout << out << "\thas " << tmpQCD->GetEntries() << " entries but " << tmpQCD->Integral() << " integral" << endl; } if (bkg7 == NULL) { if (iRandom == 0) cout << "here .." << endl; if (myQCD) bkg7 = tmpQCD; else bkg7 = ((TH1*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta"))->Rebin(eRebin); } else { if (myQCD) bkg7->Add(tmpQCD); else bkg7->Add(((TH1*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta"))->Rebin(eRebin)); } } else if (arg_fth == "bkg8") { f++; std::string out(*(argv + f)); if (iRandom == 0) cout << "bkg 8" << endl; file = new TFile(out.c_str(), "read"); if (bkg8 == NULL) { if (iRandom == 0) cout << "here .." << endl; bkg8 = ((TH1*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta"))->Rebin(muRebin); } else { bkg8->Add(((TH1*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta"))->Rebin(muRebin)); } } else if (arg_fth == "wtemplate7") { f++; std::string out(*(argv + f)); if (iRandom == 0) cout << "w template 7" << endl; file = new TFile(out.c_str(), "read"); // input7tmp.Wtemplate = ((TH1*) file->Get("btag10")); // input7tmp.Wtemplate = ((TH1*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta")); input7tmp.Wtemplate = ((TH1*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta")); input7tmp.Wtemplate->Rebin(eRebin); } else if (arg_fth == "wtemplate8") { f++; std::string out(*(argv + f)); if (iRandom == 0) cout << "w template 8" << endl; file = new TFile(out.c_str(), "read"); input8tmp.Wtemplate = ((TH1*) file->Get("DefaultTrue_allW/DefaultTrue_allWcosTheta")); input8tmp.Wtemplate->Rebin(muRebin); } else if (arg_fth == "singleMatrix") { f++; if (iRandom == 0) cout << "singleMatrix" << endl; std::string out(*(argv + f)); if (out == "true") singleMatrix = true; } else if (arg_fth == "is2Drecgen") { f++; if (iRandom == 0) cout << "is2Drecgen" << endl; std::string out(*(argv + f)); if (out == "yes" || out == "Yes" || out == "Y" || out == "y" || out == "YES") is2Drecgen = true; } else if (arg_fth == "do3D") { f++; if (iRandom == 0) cout << "do3D" << endl; std::string out(*(argv + f)); if (out == "yes" || out == "Yes" || out == "Y" || out == "y" || out == "YES") do3D = true; } else if (arg_fth == "nPE") { f++; if (iRandom == 0) cout << "nPE" << endl; std::string out(*(argv + f)); iRandom = (int) atof(out.c_str()); } } #ifndef Syst if (iRandom == 0) { cout << "7: " << bkg7 << "\t" << input7tmp.rest.data << "\t" << input7tmp.Wtemplate << endl; cout << "8: " << bkg8 << "\t" << input8tmp.rest.data << "\t" << input8tmp.Wtemplate << endl; } input7tmp.Wtemplate->Sumw2(); input7tmp.Wtemplate->Scale((double) 1. / (double) input7tmp.Wtemplate->Integral()); input8tmp.Wtemplate->Sumw2(); input8tmp.Wtemplate->Scale((double) 1. / (double) input8tmp.Wtemplate->Integral()); if (iRandom != 0) { if (iRandom == 1) { cout << "------------------------------" << endl; cout << "I will randomize the histogram" << endl; cout << "PE Number is " << iRandom << endl; cout << "------------------------------" << endl; } if (is2Drecgen && !singleMatrix && do3D) { for (unsigned int i = 0; i < input7tmp.rest.signalIID.size(); i++) { input7.rest.signalIID.push_back((TH2*) MakeRandomHistogram(input7tmp.rest.signalIID[i], iRandom, 2)); } for (unsigned int i = 0; i < input7tmp.rest.signalIIID.size(); i++) { input7.rest.signalIIID.push_back((TH3*) MakeRandomHistogram(input7tmp.rest.signalIIID[i], iRandom, 3)); } for (unsigned int i = 0; i < input8tmp.rest.signalIID.size(); i++) { input8.rest.signalIID.push_back((TH2*) MakeRandomHistogram(input8tmp.rest.signalIID[i], iRandom, 2)); } for (unsigned int i = 0; i < input8tmp.rest.signalIIID.size(); i++) { input8.rest.signalIIID.push_back((TH3*) MakeRandomHistogram(input8tmp.rest.signalIIID[i], iRandom, 3)); } } } else { input7.rest.signalIID = input7tmp.rest.signalIID; input7.rest.signalIIID = input7tmp.rest.signalIIID; input8.rest.signalIID = input8tmp.rest.signalIID; input8.rest.signalIIID = input8tmp.rest.signalIIID; } input7.rest.data = input7tmp.rest.data; input8.rest.data = input8tmp.rest.data; input7.Wtemplate = input7tmp.Wtemplate; input8.Wtemplate = input8tmp.Wtemplate; double x[8] = {0.722384, 0.308293, 0, 0, 1., 1., 1., 1.}; double xerr[8] = {-1., -1., -1., -1., -1., -1., -1., -1.}; double correlation; if (is2Drecgen && !singleMatrix && do3D) { if (iRandom == 0) { cout << "In Bias fit: \n\tsize of 2D signal at 7 TeV is " << input7.rest.signalIID.size() << "\n\tsize of 3D signal at 7 TeV is " << input7.rest.signalIIID.size() << endl; cout << "In Bias fit: \n\tsize of 2D signal at 8 TeV is " << input8.rest.signalIID.size() << "\n\tsize of 3D signal at 8 TeV is " << input8.rest.signalIIID.size() << endl; } if (bkg7 != NULL && bkginsignal7 != NULL) { bkg7->Add(bkginsignal7); } else if (bkg7 == NULL && bkginsignal7 != NULL) { bkg7 = (TH1*) bkginsignal7->Clone("myBkg7"); } input7.rest.nonRWs = bkg7; if (bkg8 != NULL && bkginsignal8 != NULL) { bkg8->Add(bkginsignal8); } else if (bkg8 == NULL && bkginsignal8 != NULL) { bkg8 = (TH1*) bkginsignal8->Clone("myBkg8"); } input8.rest.nonRWs = bkg8; if (iRandom == 0) cout << "Here" << endl; std::pair<ROOT::Math::Functor, LucaLikelihood*> myLL = LucaLikelihood::getLucaLikelihoodForBias("LL", input7, input8, false); if (iRandom == 0) { cout << "before get minimum simple: " << endl; cout << "bkg bins 7: " << input7.rest.nonRWs->GetNbinsX() << endl; cout << "bkg bins 8: " << input8.rest.nonRWs->GetNbinsX() << endl; cout << "w bins 7: " << input7.Wtemplate->GetNbinsX() << endl; cout << "w bins 8: " << input8.Wtemplate->GetNbinsX() << endl; cout << "data bins 7: " << input7.rest.data->GetNbinsX() << endl; cout << "data bins 8: " << input8.rest.data->GetNbinsX() << endl; } GetMinimumLuca(myLL.first, x, xerr, correlation, true, f0mu, flmu, fmu, nwmu); delete myLL.second; } else { cout << "Not implemented yet!" << endl; } #endif #ifdef Syst cout << "7: " << bkg7 << "\t" << input7.rest.data << "\t" << input7.Wtemplate << endl; cout << "8: " << bkg8 << "\t" << input8.rest.data << "\t" << input8.Wtemplate << endl; input7.Wtemplate->Sumw2(); input7.Wtemplate->Scale((double) 1. / (double) input7.Wtemplate->Integral()); double x[5] = {0.7, 0.3, 1., 1., 1.,}; double xerr[5] = {-1., -1., -1., -1., -1.,}; double correlation; cout << "In Syst fit: \n\tsize of 2D signal at 7 TeV is " << input7.rest.signalIID.size() << "\n\tsize of 3D signal at 7 TeV is " << input7.rest.signalIIID.size() << endl; cout << "In Syst fit: \n\tsize of 2D signal at 8 TeV is " << input8.rest.signalIID.size() << "\n\tsize of 3D signal at 8 TeV is " << input8.rest.signalIIID.size() << endl; cout << "nbin signal 7: " << input7.rest.signalIID[0]->GetYaxis()->GetNbins() << endl; cout << "nbin signal 8: " << input8.rest.signalIID[0]->GetYaxis()->GetNbins() << endl; TH1* Signal1D7 = 0; TH1* Signal1D8 = 0; stringstream s; for (unsigned int p = 0; p < input7.rest.signalIID.size(); p++) { s.str(""); s << p << "7_pY"; if (Signal1D7 == 0) Signal1D7 = (TH1*) input7.rest.signalIID.at(p)->ProjectionY(s.str().c_str()); else Signal1D7->Add((TH1*) input7.rest.signalIID.at(p)->ProjectionY(s.str().c_str())); } s.str(""); for (unsigned int p = 0; p < input8.rest.signalIID.size(); p++) { s.str(""); s << p << "8_pY"; if (Signal1D8 == 0) Signal1D8 = (TH1*) input8.rest.signalIID.at(p)->ProjectionY(s.str().c_str()); else Signal1D8->Add((TH1*) input8.rest.signalIID.at(p)->ProjectionY(s.str().c_str())); } cout << "signal done" << endl; #ifndef IJES cout << "-- " << bkginsignal8->Integral() << endl; cout << "-- " << bkg8->Integral() << endl; if (bkginsignal8 != NULL) { if (bkg8 != NULL) { bkg8->Add(bkginsignal8); } else { bkg8 = bkginsignal8; } } #endif #ifdef IJES if (bkginsignal8 != NULL) // bkg->Add(bkginsignal8); Signal1D8->Add(bkginsignal8); #endif if (bkginsignal7 != NULL) // bkg->Add(bkginsignal7); Signal1D7->Add(bkginsignal7); InputForCombination1D IDin8; IDin8.name = "IDin8"; IDin8.data = input8.rest.data; IDin8.nonRWs = bkg8; IDin8.signalID = Signal1D8; WTempForCombination1D IDin7; IDin7.rest.name = "IDin7"; IDin7.rest.data = input7.rest.data; IDin7.rest.nonRWs = bkg7; IDin7.rest.signalID = Signal1D7; IDin7.Wtemplate = input7.Wtemplate; cout << "8TeV Info: \n\tnData: " << IDin8.data->Integral() << "\n\tnSignal: " << IDin8.signalID->Integral() << "\n\tnBkg: " << IDin8.nonRWs->Integral() << endl; cout << "7TeV Info: \n\tnData: " << IDin7.rest.data->Integral() << "\n\tnSignal: " << IDin7.rest.signalID->Integral() << "\n\tnBkg: " << IDin7.rest.nonRWs->Integral() << endl; std::pair<ROOT::Math::Functor, LucaLikelihood*> myLL = LucaLikelihood::getLucaLikelihoodForSyst("LL", IDin7, IDin8, true); GetMinimumSystCombined(myLL.first, x, xerr, correlation, true); cout << "----- systematics: " << endl; double f00 = 0.713279; double fl0 = 0.293116; double f0n = 0.707345; double fln = 0.296289; cout << "\nDelF0 = " << x[0] - f0n << " +/- " << xerr[0]* 0.114023 / 0.0217699 << endl; cout << "\nDelFL = " << x[1] - fln << " +/- " << xerr[1]* 0.0687606 / 0.0207235 << endl; cout << "\nF0 = " << x[0] - f0n + f00 << " +/- " << xerr[0]* 0.114023 / 0.0217699 << endl; cout << "\nFL = " << x[1] - fln + fl0 << " +/- " << xerr[1]* 0.0687606 / 0.0207235 << endl; delete myLL.second; #endif return 0; }
TH1 * UnfoldMe(Char_t *data, Char_t *mc, Char_t *anatag, Int_t bin, Bool_t useMBcorr = kTRUE, Bool_t usecorrfit = kFALSE, Bool_t ismc = kFALSE, Float_t smooth = 0.001, Int_t iter = 50, Int_t regul = AliUnfolding::kPowerLaw, Float_t weight = 100., Bool_t bayesian = kTRUE, Int_t nloop = 1) { if (ismc) TFile *fdt = TFile::Open(data); else TFile *fdt = TFile::Open(data); TFile *fmc = TFile::Open(mc); TList *ldt = (TList *)fdt->Get(Form("clist_%s", anatag)); TList *lmc = (TList *)fmc->Get(Form("clist_%s", anatag)); TH2 *hmatdt = (TH2 *)ldt->FindObject(Form("b%d_corrMatrix", bin)); if (useMBcorr) TH2 *hmatmc = (TH2 *)lmc->FindObject("effMatrix"); else TH2 *hmatmc = (TH2 *)lmc->FindObject(Form("b%d_corrMatrix", bin)); TH1 *hdata = hmatdt->ProjectionY("hdata"); hdata->Sumw2(); hdata->SetBinContent(1, 0.); hdata->SetBinError(1, 0.); // hdata->Scale(1. / hdata->Integral()); hdata->SetMarkerStyle(25); TH1 *htrue = hmatdt->ProjectionX("htrue"); htrue->Sumw2(); // htrue->Scale(1. / htrue->Integral()); htrue->SetMarkerStyle(7); htrue->SetMarkerColor(2); htrue->SetBinContent(1, 0.); htrue->SetBinError(1, 0.); TH2 *hcorr = (TH2 *)hmatmc->Clone("hcorr"); TH1 *hinit = (TH1 *)hdata->Clone("hinit"); TH1 *hresu = (TH1 *)hdata->Clone("hresu"); TH1 *hbias = (TH1 *)hdata->Clone("hbias"); hresu->SetMarkerStyle(20); hresu->SetMarkerColor(4); hresu->Reset(); TH1 *hnum = hcorr->ProjectionY("hnum"); TH1 *hden = hcorr->ProjectionY("hden"); TH1 *heff = hcorr->ProjectionY("heff"); hnum->Reset(); hnum->Sumw2(); hden->Reset(); hden->Sumw2(); heff->Reset(); for (Int_t i = 0; i < heff->GetNbinsX(); i++) { Float_t int1 = hcorr->Integral(i + 1, i + 1, 0, -1); if (int1 <= 0.) continue; Float_t int2 = hcorr->Integral(i + 1, i + 1, 2, -1); hnum->SetBinContent(i + 1, int2); hnum->SetBinError(i + 1, TMath::Sqrt(int2)); hden->SetBinContent(i + 1, int1); hden->SetBinError(i + 1, TMath::Sqrt(int1)); } new TCanvas("cEfficiency"); heff->Divide(hnum, hden, 1., 1., "B"); heff->Draw(); #if 0 for (Int_t ii = 0; ii < heff->GetNbinsX(); ii++) { heff->SetBinContent(ii + 1, 1.); heff->SetBinError(ii + 1, 0.); } #endif for (Int_t i = 0; i < hcorr->GetNbinsX(); i++) { hcorr->SetBinContent(i + 1, 1, 0.); hcorr->SetBinError(i + 1, 1, 0.); } for (Int_t i = 0; i < hcorr->GetNbinsY(); i++) { hcorr->SetBinContent(1, i + 1, 0.); hcorr->SetBinError(1, i + 1, 0.); } TH2 *hcorrfit = ReturnCorrFromFit(hcorr); for (Int_t iloop = 0; iloop < nloop; iloop++) { if (bayesian) { AliUnfolding::SetUnfoldingMethod(AliUnfolding::kBayesian); AliUnfolding::SetBayesianParameters(smooth, iter); } else { AliUnfolding::SetUnfoldingMethod(AliUnfolding::kChi2Minimization); AliUnfolding::SetChi2Regularization(regul, weight); } AliUnfolding::SetSkip0BinInChi2(kTRUE); AliUnfolding::SetSkipBinsBegin(1); AliUnfolding::SetNbins(150, 150); AliUnfolding::Unfold(usecorrfit ? hcorrfit : hcorr, heff, hdata, hinit, hresu); hinit = (TH1 *)hresu->Clone(Form("hinit_%d", iloop)); } printf("hdata->Integral(2, -1) = %f\n", hdata->Integral(2, -1)); printf("hresu->Integral(2, -1) = %f\n", hresu->Integral(2, -1)); TCanvas *cUnfolded = new TCanvas ("cUnfolded", "", 400, 800); cUnfolded->Divide(1, 2); cUnfolded->cd(1)->SetLogx(); cUnfolded->cd(1)->SetLogy(); hdata->Draw(); hresu->Draw("same"); htrue->Draw("same"); cUnfolded->cd(2)->SetLogx(); cUnfolded->cd(2)->DrawFrame(1., 0.75, 300., 1.25); TH1 *hrat = (TH1 *)hresu->Clone("hrat"); hrat->Divide(htrue); hrat->Draw("same"); TH1 *htrig = (TH1 *)hresu->Clone("htrig"); htrig->Multiply(heff); Float_t dndeta_resu = 0.; Float_t integr_resu = 0.; Float_t dndeta_trig = 0.; Float_t integr_trig = 0.; for (Int_t i = 1; i < hresu->GetNbinsX(); i++) { dndeta_resu += hresu->GetBinContent(i + 1) * hresu->GetBinLowEdge(i + 1); integr_resu += hresu->GetBinContent(i + 1); dndeta_trig += htrig->GetBinContent(i + 1) * htrig->GetBinLowEdge(i + 1); integr_trig += htrig->GetBinContent(i + 1); } // dndeta_resu /= integr_resu; // dndeta_trig /= integr_trig; integr_eff = integr_trig / integr_resu; integr_eff_err = TMath::Sqrt(integr_eff * (1. - integr_eff) / integr_resu); dndeta_eff = dndeta_trig / dndeta_resu; dndeta_eff_err = TMath::Sqrt(dndeta_eff * (1. - dndeta_eff) / dndeta_resu); printf("INEL > 0 efficiency: %.3f +- %.3f\n", integr_eff, integr_eff_err); printf("dN/dEta correction: %.3f +- %.3f\n", dndeta_eff, dndeta_eff_err); return hresu; }
void makePlot(const std::string& inputFilePath, const std::string& canvasName, const std::string& sample, int massPoint, const std::string& channel, double k, const std::string& inputFileName, const std::string& outputFilePath, const std::string& outputFileName) { std::string inputFileName_full = Form("%s%s", inputFilePath.data(), inputFileName.data()); TFile* inputFile = new TFile(inputFileName_full.data()); if ( !inputFile ) { std::cerr << "Failed to open input file = " << inputFileName_full << " !!" << std::endl; assert(0); } inputFile->ls(); TCanvas* canvas = dynamic_cast<TCanvas*>(inputFile->Get(canvasName.data())); if ( !canvas ) { std::cerr << "Failed to load canvas = " << canvasName << " !!" << std::endl; assert(0); } int idxPad = -1; if ( massPoint == 90 ) idxPad = 1; if ( massPoint == 125 ) idxPad = 2; if ( massPoint == 200 ) idxPad = 3; if ( massPoint == 300 ) idxPad = 4; if ( massPoint == 500 ) idxPad = 5; if ( massPoint == 800 ) idxPad = 6; if ( !(idxPad >= 1 && idxPad <= 6) ) { std::cerr << "Invalid sample = " << sample << " !!" << std::endl; assert(0); } TVirtualPad* pad = canvas->GetPad(idxPad); std::cout << "pad = " << pad << ": ClassName = " << pad->ClassName() << std::endl; TCanvas* canvas_new = new TCanvas("canvas_new", "canvas_new", 900, 800); canvas_new->SetFillColor(10); canvas_new->SetBorderSize(2); canvas_new->SetTopMargin(0.065); canvas_new->SetLeftMargin(0.17); canvas_new->SetBottomMargin(0.165); canvas_new->SetRightMargin(0.015); canvas_new->SetLogx(true); canvas_new->SetLogy(true); canvas_new->Draw(); canvas_new->cd(); //TList* pad_primitives = canvas->GetListOfPrimitives(); TList* pad_primitives = pad->GetListOfPrimitives(); TH1* histogramCA = 0; TH1* histogramSVfit = 0; TH1* histogramSVfitMEMkEq0 = 0; TH1* histogramSVfitMEMkNeq0 = 0; TIter pad_nextObj(pad_primitives); while ( TObject* obj = pad_nextObj() ) { std::string objName = ""; if ( dynamic_cast<TNamed*>(obj) ) objName = (dynamic_cast<TNamed*>(obj))->GetName(); std::cout << "obj = " << obj << ": name = " << objName << ", type = " << obj->ClassName() << std::endl; TH1* tmpHistogram = dynamic_cast<TH1*>(obj); if ( tmpHistogram ) { std::cout << "tmpHistogram:" << " fillColor = " << tmpHistogram->GetFillColor() << ", fillStyle = " << tmpHistogram->GetFillStyle() << "," << " lineColor = " << tmpHistogram->GetLineColor() << ", lineStyle = " << tmpHistogram->GetLineStyle() << ", lineWidth = " << tmpHistogram->GetLineWidth() << "," << " markerColor = " << tmpHistogram->GetMarkerColor() << ", markerStyle = " << tmpHistogram->GetMarkerStyle() << ", markerSize = " << tmpHistogram->GetMarkerSize() << "," << " integral = " << tmpHistogram->Integral() << std::endl; std::cout << "(mean = " << tmpHistogram->GetMean() << ", rms = " << tmpHistogram->GetRMS() << ": rms/mean = " << (tmpHistogram->GetRMS()/tmpHistogram->GetMean()) << ")" << std::endl; if ( tmpHistogram->GetLineColor() == 416 ) histogramCA = tmpHistogram; if ( tmpHistogram->GetLineColor() == 600 ) histogramSVfit = tmpHistogram; if ( tmpHistogram->GetLineColor() == 616 ) histogramSVfitMEMkEq0 = tmpHistogram; if ( tmpHistogram->GetLineColor() == 632 ) histogramSVfitMEMkNeq0 = tmpHistogram; } } if ( !(histogramCA && histogramSVfit && histogramSVfitMEMkEq0 && histogramSVfitMEMkNeq0) ) { std::cerr << "Failed to load histograms !!" << std::endl; assert(0); } //gStyle->SetLineStyleString(2,"40 10 10 10 10 10 10 10"); //gStyle->SetLineStyleString(3,"25 15"); //gStyle->SetLineStyleString(4,"60 25"); //int colors[4] = { kBlack, kGreen - 6, kBlue - 7, kMagenta - 7 }; int colors[4] = { 28, kGreen - 6, kBlue - 7, kBlack }; //int lineStyles[4] = { 2, 3, 4, 1 }; int lineStyles[4] = { 7, 1, 1, 1 }; //int lineWidths[4] = { 3, 3, 4, 3 }; int lineWidths[4] = { 3, 3, 1, 1 }; int markerStyles[4] = { 20, 25, 21, 24 }; int markerSizes[4] = { 2, 2, 2, 2 }; histogramCA->SetFillColor(0); histogramCA->SetFillStyle(0); histogramCA->SetLineColor(colors[0]); histogramCA->SetLineStyle(lineStyles[0]); histogramCA->SetLineWidth(lineWidths[0]); histogramCA->SetMarkerColor(colors[0]); histogramCA->SetMarkerStyle(markerStyles[0]); histogramCA->SetMarkerSize(markerSizes[0]); histogramSVfit->SetFillColor(0); histogramSVfit->SetFillStyle(0); histogramSVfit->SetLineColor(colors[1]); histogramSVfit->SetLineStyle(lineStyles[1]); histogramSVfit->SetLineWidth(lineWidths[1]); histogramSVfit->SetMarkerColor(colors[1]); histogramSVfit->SetMarkerStyle(markerStyles[1]); histogramSVfit->SetMarkerSize(markerSizes[1]); histogramSVfitMEMkEq0->SetFillColor(0); histogramSVfitMEMkEq0->SetFillStyle(0); histogramSVfitMEMkEq0->SetLineColor(colors[2]); histogramSVfitMEMkEq0->SetLineStyle(lineStyles[2]); histogramSVfitMEMkEq0->SetLineWidth(lineWidths[2]); histogramSVfitMEMkEq0->SetMarkerColor(colors[2]); histogramSVfitMEMkEq0->SetMarkerStyle(markerStyles[2]); histogramSVfitMEMkEq0->SetMarkerSize(markerSizes[2]); // CV: fix pathological bins at high mass for which dN/dm increases int numBins = histogramSVfitMEMkEq0->GetNbinsX(); for ( int idxBin = 1; idxBin <= numBins; ++idxBin ) { double binCenter = histogramSVfitMEMkEq0->GetBinCenter(idxBin); if ( (channel == "#tau_{h}#tau_{h}" && massPoint == 500 && binCenter > 1500.) || (channel == "#tau_{h}#tau_{h}" && massPoint == 800 && binCenter > 2000.) || (channel == "#mu#tau_{h}" && massPoint == 500 && binCenter > 1500.) || (channel == "#mu#tau_{h}" && massPoint == 800 && binCenter > 2500.) ) { histogramSVfitMEMkEq0->SetBinContent(idxBin, 0.); } } histogramSVfitMEMkNeq0->SetFillColor(0); histogramSVfitMEMkNeq0->SetFillStyle(0); histogramSVfitMEMkNeq0->SetLineColor(colors[3]); histogramSVfitMEMkNeq0->SetLineStyle(lineStyles[3]); histogramSVfitMEMkNeq0->SetLineWidth(lineWidths[3]); histogramSVfitMEMkNeq0->SetMarkerColor(colors[3]); histogramSVfitMEMkNeq0->SetMarkerStyle(markerStyles[3]); histogramSVfitMEMkNeq0->SetMarkerSize(markerSizes[3]); TAxis* xAxis = histogramCA->GetXaxis(); xAxis->SetTitle("m_{#tau#tau} [GeV]"); xAxis->SetTitleOffset(1.15); xAxis->SetTitleSize(0.070); xAxis->SetTitleFont(42); xAxis->SetLabelOffset(0.010); xAxis->SetLabelSize(0.055); xAxis->SetLabelFont(42); xAxis->SetTickLength(0.040); xAxis->SetNdivisions(510); //double xMin = 20.; //double xMax = xAxis->GetXmax(); //xAxis->SetRangeUser(xMin, xMax); TAxis* yAxis = histogramCA->GetYaxis(); yAxis->SetTitle("dN/dm_{#tau#tau} [1/GeV]"); yAxis->SetTitleOffset(1.20); yAxis->SetTitleSize(0.070); yAxis->SetTitleFont(42); yAxis->SetLabelOffset(0.010); yAxis->SetLabelSize(0.055); yAxis->SetLabelFont(42); yAxis->SetTickLength(0.040); yAxis->SetNdivisions(505); double massPoint_double = 0.; if ( massPoint == 90 ) massPoint_double = 91.2; else massPoint_double = massPoint; double dLog = (TMath::Log(5.*massPoint_double) - TMath::Log(50.))/25.; // xMin = 50, xMax = 5*massPoint, numBins = 25 double binWidth = TMath::Exp(TMath::Log(massPoint_double) + 0.5*dLog) - TMath::Exp(TMath::Log(massPoint_double) - 0.5*dLog); double sf_binWidth = 1./binWidth; std::cout << "massPoint = " << massPoint << ": sf_binWidth = " << sf_binWidth << std::endl; histogramCA->SetTitle(""); histogramCA->SetStats(false); histogramCA->SetMaximum(sf_binWidth*0.79); histogramCA->SetMinimum(sf_binWidth*1.1e-4); histogramCA->Draw("hist"); histogramSVfit->Draw("histsame"); //histogramSVfitMEMkEq0->Draw("histsame"); histogramSVfitMEMkEq0->Draw("epsame"); //histogramSVfitMEMkNeq0->Draw("histsame"); histogramSVfitMEMkNeq0->Draw("epsame"); histogramCA->Draw("axissame"); //TPaveText* label_sample = new TPaveText(0.21, 0.86, 0.46, 0.94, "NDC"); TPaveText* label_sample = new TPaveText(0.1700, 0.9475, 0.4600, 1.0375, "NDC"); label_sample->SetFillStyle(0); label_sample->SetBorderSize(0); label_sample->AddText(sample.data()); label_sample->SetTextFont(42); label_sample->SetTextSize(0.055); label_sample->SetTextColor(1); label_sample->SetTextAlign(13); label_sample->Draw(); //TLegend* legend_new = new TLegend(0.225, 0.52, 0.41, 0.82, NULL, "brNDC"); TLegend* legend_new = new TLegend(0.30, 0.30, 0.80, 0.80, NULL, "brNDC"); legend_new->SetFillColor(10); legend_new->SetFillStyle(0); legend_new->SetBorderSize(0); legend_new->SetTextFont(42); legend_new->SetTextSize(0.055); legend_new->SetTextColor(1); legend_new->SetMargin(0.20); legend_new->AddEntry(histogramCA, "CA", "l"); legend_new->AddEntry(histogramSVfit, "SVfit", "l"); //legend_new->AddEntry(histogramSVfitMEMkEq0, "SVfitMEM (k=0)", "l"); legend_new->AddEntry(histogramSVfitMEMkEq0, "SVfitMEM (k=0)", "p"); //legend_new->AddEntry(histogramSVfitMEMkNeq0, Form("SVfitMEM(k=%1.0f)", k), "l"); legend_new->AddEntry(histogramSVfitMEMkNeq0, Form("SVfitMEM (k=%1.0f)", k), "p"); //legend_new->Draw(); double label_channel_y0; if ( channel == "e#mu" ) label_channel_y0 = 0.9275; else if ( channel == "#mu#tau_{h}" ) label_channel_y0 = 0.9400; else if ( channel == "#tau_{h}#tau_{h}" ) label_channel_y0 = 0.9350; else { std::cerr << "Invalid channel = " << channel << " !!" << std::endl; assert(0); } TPaveText* label_channel = new TPaveText(0.895, label_channel_y0, 0.975, label_channel_y0 + 0.055, "NDC"); label_channel->SetFillStyle(0); label_channel->SetBorderSize(0); label_channel->AddText(channel.data()); label_channel->SetTextFont(62); label_channel->SetTextSize(0.055); label_channel->SetTextColor(1); label_channel->SetTextAlign(31); label_channel->Draw(); canvas_new->Update(); std::string outputFileName_full = Form("%s%s", outputFilePath.data(), outputFileName.data()); size_t idx = outputFileName_full.find_last_of('.'); std::string outputFileName_plot = std::string(outputFileName_full, 0, idx); canvas_new->Print(std::string(outputFileName_plot).append(".pdf").data()); canvas_new->Print(std::string(outputFileName_plot).append(".root").data()); std::string channel_string; if ( channel == "e#mu" ) channel_string = "emu"; else if ( channel == "#mu#tau_{h}" ) channel_string = "muhad"; else if ( channel == "#tau_{h}#tau_{h}" ) channel_string = "hadhad"; else { std::cerr << "Invalid channel = " << channel << " !!" << std::endl; assert(0); } std::string outputFileName_legend = Form("makeSVfitMEM_PerformancePlots_legend_%s.pdf", channel_string.data()); makePlot_legend(legend_new, outputFilePath, outputFileName_legend); delete label_sample; delete legend_new; delete label_channel; delete canvas_new; delete inputFile; }
void EMuSigEff() { vector <int> masses; masses.push_back(40); masses.push_back(50); masses.push_back(60); masses.push_back(70); masses.push_back(80); masses.push_back(90); masses.push_back(100); masses.push_back(125); masses.push_back(150); masses.push_back(175); masses.push_back(200); masses.push_back(250); masses.push_back(300); masses.push_back(350); masses.push_back(400); masses.push_back(500); vector <TString> smasses; smasses.push_back("40"); smasses.push_back("50"); smasses.push_back("60"); smasses.push_back("70"); smasses.push_back("80"); smasses.push_back("90"); smasses.push_back("100"); smasses.push_back("125"); smasses.push_back("150"); smasses.push_back("175"); smasses.push_back("200"); smasses.push_back("250"); smasses.push_back("300"); smasses.push_back("350"); smasses.push_back("400"); smasses.push_back("500"); for(unsigned int i = 0 ; i < masses.size(); ++i) { TString im = smasses.at(i); TFile * file1 = new TFile(("/home/jalmond/HeavyNeutrino/Analysis/LQanalyzer/data/output/SSElectronMuon/HNEMu_SKHNmue" + im + "_nocut_5_3_14.root").Data()); TFile * file2 = new TFile(("/home/jalmond/HeavyNeutrino/Analysis/LQanalyzer/data/output/SSElectronMuon/HNEMu_SKHNemu" + im + "_nocut_5_3_14.root").Data()); TString cut = "SS_highmass_exc";// + im; //cut = "SS_highmass"; // if(i < 5) cut = "SS_lowmass_" + im; //if(i < 5) cut = "SS_lowmass_80_2"; TString hist = (cut + "/h_Nelectrons_"+cut); TH1* hnsig = (TH1F*)file1->Get(("CutFlow/_eventcutflow")); TH1* hnsig2 = (TH1F*)file2->Get(("CutFlow/_eventcutflow")); float nsig = float(hnsig->GetBinContent(2)); float nsig2= float(hnsig2->GetBinContent(2)); TH1* hpass = (TH1F*)file1->Get(hist); TH1* hpass2 = (TH1F*)file2->Get(hist); cout << " \n ------- " << endl; cout << " Mass = " << masses.at(i) << endl; cout << "mu eacceptance = " << hpass->Integral()/nsig << endl; cout << "emu acceptance = " << hpass2->Integral()/nsig2 << endl; hpass->Add(hpass2,1.); double err ; hpass->IntegralAndError(1, hpass->GetNbinsX()+1, err , ""); cout << "Average = " << hpass->Integral()/(nsig + nsig2) << endl; cout << "%err = " << 100*err/(hpass->Integral())<< endl;; } }
int main(int argc, char** argv) { TH1* data; std::vector<TH2*> signalIID; // for munub t-processes std::vector<TH3*> signalIIID; // for munub t-processes TH1* bkginsignal = 0; //for t-processes other than munub TH1* bkg = 0; // for non-t processes TH1* wtemplate = 0; bool do3D = true; int nReBin = 10; TFile * file = 0; std::vector<double> pars; double nTop7 = 1.; double nW8 = 0; double nW7 = 0; // cout << pars[0] << "\t" << pars[1] << "\t" << pars[2] << "\t" << pars[3] << "\t" << endl; double delStatF0 = 0; double delStatFL = 0; double delSystF0 = 0; double delSystFL = 0; double F0_ = 0; double FL_ = 0; double delTotF0 = 0; double delTotFL = 0; string channel = ""; std::vector<string> namings; std::map<string, double> sampleinfo; double iRandom = 0; string addname = ""; for (int f = 1; f < argc; f++) { std::string arg_fth(*(argv + f)); cout << f << " ---- " << arg_fth << endl; if (arg_fth == "channel") { f++; std::string out(*(argv + f)); channel = out; //e-mu namings.push_back(string("di") + channel); namings.push_back(channel + string("had")); namings.push_back(channel + string("tau")); namings.push_back("mue"); } else if (arg_fth == "FL") { f++; std::string out(*(argv + f)); FL_ = atof(out.c_str()); } else if (arg_fth == "F0") { f++; std::string out(*(argv + f)); F0_ = atof(out.c_str()); } else if (arg_fth == "F0Stat") { f++; std::string out(*(argv + f)); delStatF0 = atof(out.c_str()); } else if (arg_fth == "FLStat") { f++; std::string out(*(argv + f)); delStatFL = atof(out.c_str()); } else if (arg_fth == "F0Syst") { f++; std::string out(*(argv + f)); delSystF0 = atof(out.c_str()); } else if (arg_fth == "FLSyst") { f++; std::string out(*(argv + f)); delSystFL = atof(out.c_str()); } else if (arg_fth == "F0Tot") { f++; std::string out(*(argv + f)); delTotF0 = atof(out.c_str()); } else if (arg_fth == "FLTot") { f++; std::string out(*(argv + f)); delTotFL = atof(out.c_str()); } else if (arg_fth == "nW7") { f++; std::string out(*(argv + f)); nW7 = atof(out.c_str()); } else if (arg_fth == "ntop7") { f++; std::string out(*(argv + f)); nTop7 = atof(out.c_str()); } else if (arg_fth == "signal") { f++; std::string out(*(argv + f)); file = new TFile(out.c_str(), "read"); bool muonfile = false; for (unsigned int i = 0; i < namings.size(); i++) { int pos = string(file->GetName()).find(namings[i].c_str()); muonfile = (pos >= 0 && pos < string(file->GetName()).size()); if (muonfile) { if (iRandom == 0) { cout << "I am in " << channel << " channel and I accept "; cout << file->GetName() << " as signal" << endl; } break; } } if (!do3D || (do3D && !muonfile)) { signalIID.push_back(((TH2*) file->Get("Default_allW/Default_allWcosTheta2D"))->RebinY(nReBin)); // signalIID.at(signalIID.size() - 1)->Scale(ratio); // cout << signalIID.at(signalIID.size() - 1)->GetName() << endl; }// else // signalIID.push_back(((TH2*) ((TH3D*) file->Get("Default_allW/Default_allWcosTheta3D"))->Project3D("yx"))->Rebin2D(1,1)); if (do3D && muonfile) { // cout << " in 3D :-)" << endl; signalIIID.push_back(((TH3D*) file->Get("Default_allW/Default_allWcosTheta3D"))->Rebin3D(1, nReBin, 1, "newname")); // cout << signalIIID.at(signalIIID.size() - 1) << endl; // signalIIID.at(signalIIID.size() - 1)->Scale(ratio); } if (bkginsignal == 0) bkginsignal = (((TH1*) file->Get("Default_allW/Default_allWcosTheta"))->Rebin(nReBin)); else bkginsignal->Add(((TH1*) file->Get("Default_allW/Default_allWcosTheta"))->Rebin(nReBin)); TH1 * myTemp = (TH1*) (((TH1*) file->Get("Default_allW/Default_allWcosTheta")))->Clone("myTemp"); if (iRandom == 0) { if (!muonfile) { cout << " : " << signalIID.at(signalIID.size() - 1)->Integral() << " + " << myTemp->Integral() << " = " << signalIID.at(signalIID.size() - 1)->Integral() + myTemp->Integral() << endl; sampleinfo[out] = signalIID.at(signalIID.size() - 1)->Integral() + myTemp->Integral(); } else if (do3D) { cout << " : " << signalIIID.at(signalIIID.size() - 1)->Integral() << " + " << myTemp->Integral() << " = " << signalIIID.at(signalIIID.size() - 1)->Integral() + myTemp->Integral() << endl; sampleinfo[out] = signalIIID.at(signalIIID.size() - 1)->Integral() + myTemp->Integral(); } } delete myTemp; } else if (arg_fth == "data") { f++; std::string out(*(argv + f)); cout << "data" << endl; file = new TFile(out.c_str(), "read"); data = ((TH1*) file->Get("Default_allW/Default_allWcosTheta"))->Rebin(nReBin); cout << data << endl; } else if (arg_fth == "bkg") { f++; std::string out(*(argv + f)); cout << "bkg" << endl; file = new TFile(out.c_str(), "read"); if (bkg == NULL) { cout << "here .." << endl; bkg = ((TH1*) file->Get("Default_allW/Default_allWcosTheta"))->Rebin(nReBin); } else { bkg->Add(((TH1*) file->Get("Default_allW/Default_allWcosTheta"))->Rebin(nReBin)); } } else if (arg_fth == "wtemplate") { f++; std::string out(*(argv + f)); cout << "w template" << endl; file = new TFile(out.c_str(), "read"); cout << out << "\t"; wtemplate = ((TH1*) file->Get("Default_allW/Default_allWcosTheta")); cout << wtemplate << endl; wtemplate->Rebin(nReBin); } else if (arg_fth == "name") { f++; std::string out(*(argv + f)); addname = out; } } cout << bkg << "\t" << data << "\t" << wtemplate << endl; wtemplate->Sumw2(); wtemplate->Scale((double) 1. / (double) wtemplate->Integral()); data->Print(); cout << "In Bias fit: \n\tsize of 2D signal is " << signalIID.size() << "\n\tsize of 3D signal is " << signalIIID.size() << endl; cout << "bkginsignal: " << bkginsignal->Integral() << " bkg: " << bkg->Integral() << endl; if (bkg != NULL && bkginsignal != NULL) { bkg->Add(bkginsignal); } else if (bkg == NULL && bkginsignal != NULL) { bkg = (TH1*) bkginsignal->Clone("myBkg"); } // bkg->Scale(ratio); cout << "bkg: " << bkg->Integral() << " data: " << data->Integral() << " signal: "; double nSignal = 0; for (unsigned int p = 0; p < signalIID.size(); p++) { nSignal += signalIID[p]->Integral(); // cout << signalIID[p]->Integral() << endl; } for (unsigned int p = 0; p < signalIIID.size(); p++) { nSignal += signalIIID[p]->Integral(); // cout << signalIIID[p]->Integral() << endl; } cout << nSignal << endl; WTempForCombination3D my3DInput; my3DInput.Wtemplate = (TH1*) wtemplate->Clone("Wtemp_Syst"); //normal my3DInput.rest.data = data; my3DInput.rest.nonRWs = bkg; my3DInput.rest.signalIID = signalIID; my3DInput.rest.signalIIID = signalIIID; pars.push_back(F0_); pars.push_back(FL_); pars.push_back(nTop7); pars.push_back(nW7); ChiSquaredCaculatorAndPlotter myChi2Syst(channel + string("_Chi2Syst_") + addname, pars, my3DInput, delSystF0, delSystFL); myChi2Syst.PrintOut(); cout << "ChiSquared: " << myChi2Syst.GetChiSquared() << endl; cout << "NormalChiSquared: " << myChi2Syst.GetNormalizedChiSquared() << endl; myChi2Syst.WriteInfo(); my3DInput.Wtemplate = (TH1*) wtemplate->Clone("Wtemp_Stat"); //normal ChiSquaredCaculatorAndPlotter myChi2Stat(channel + string("_Chi2Stat_") + addname, pars, my3DInput, delStatF0, delStatFL); myChi2Stat.PrintOut(); cout << "ChiSquared: " << myChi2Stat.GetChiSquared() << endl; cout << "NormalChiSquared: " << myChi2Stat.GetNormalizedChiSquared() << endl; myChi2Stat.WriteInfo(); my3DInput.Wtemplate = (TH1*) wtemplate->Clone("Wtemp_total"); //normal ChiSquaredCaculatorAndPlotter myChi2total(channel + string("_Chi2total_") + addname, pars, my3DInput, delTotF0, delTotFL); myChi2total.PrintOut(); cout << "ChiSquared: " << myChi2total.GetChiSquared() << endl; cout << "NormalChiSquared: " << myChi2total.GetNormalizedChiSquared() << endl; myChi2total.WriteInfo(); return 0; }