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; }
// 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; }
///----------------------------------------------------------------------------- Double_t effSigma(RooAbsPdf *pdf, RooRealVar *obs, Int_t nbins) { TH1 *hist = pdf->createHistogram(obs->GetName(), nbins); hist->Scale(nbins); return effSigma( hist); }
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 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 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"); } } }
void rescaleBoundaryHists(std::string infile, int numSamples=-1){ TFile* f = new TFile(infile.c_str(), "UPDATE"); TDirectory* dir = 0; TIter dir_it(f->GetListOfKeys()); TKey* dir_k; while ((dir_k = (TKey *)dir_it())) { if (TString(dir_k->GetClassName()) != "TDirectoryFile") continue; std::string dir_name = std::string(dir_k->GetTitle()); if(dir_name == "") continue; dir = (TDirectory*)dir_k->ReadObj(); if(dir == 0) continue; TIter hist_it(dir->GetListOfKeys(), kIterBackward); TKey* hist_k; while ((hist_k = (TKey *)hist_it())) { std::string hist_name = (hist_k->GetTitle()); if (hist_name.find("_HI") != std::string::npos || hist_name.find("_LOW") != std::string::npos || hist_name.find("h_n_mt2bins") != std::string::npos) { TH1* h = (TH1*)hist_k->ReadObj(); if(numSamples==-1) h->Scale(1.0/h->GetEntries()); else h->Scale(1.0/numSamples); dir->cd(); h->Write("",TObject::kOverwrite); } } } delete dir; gDirectory->GetList()->Delete(); f->Write("",TObject::kOverwrite); f->Close(); delete f; }
TH1* makeCDF(TH1* h) { TString sName(TString(h->GetName())+TString("_CDF")); TString sTitle(TString(h->GetTitle())+TString(" CDF")); TH1* hOut = (TH1*) h->Clone(sName); hOut->SetTitle(sTitle); hOut->Reset(); double cdf = 0; for (int ibin=0; ibin < h->GetNbinsX()+2; ++ibin) { cdf += h->GetBinContent(ibin); hOut->SetBinContent(ibin,cdf); } hOut->Scale(1.0/(h->Integral(0,h->GetNbinsX()+1))); return hOut; }
void plotter::draw_delta_rel(TH1* hist_, TH1* result_, TString file_name){ TH1* hist = (TH1*) hist_->Clone("hist"); TH1* result = (TH1*) result_->Clone("result"); hist->Divide(result); hist->Scale(100); TCanvas *c= new TCanvas("Particle Level","",600,600); gPad->SetLeftMargin(0.15); hist->SetTitle(file_name); hist->GetXaxis()->SetTitle("Leading-jet mass [GeV]"); hist->GetYaxis()->SetTitle("relative uncertainty [%]"); hist->GetYaxis()->SetTitleOffset(1.5); hist->GetYaxis()->SetNdivisions(505); hist->SetFillColor(810); hist->SetLineColor(810); hist->Draw("HIST"); gPad->RedrawAxis(); c->SaveAs(directory + file_name + ".pdf"); delete c; }
//________________________________________________________ Int_t GFOverlay::AddHistsAt(const TObjArray &hists, const TObjArray &legends, Int_t layer,Int_t pos) { // hists and legends must have same length, but might have gaps... // return number of hists found and added Int_t nHists = 0; for (Int_t iHist = 0; iHist < hists.GetEntriesFast(); ++iHist) { TH1 *hist = static_cast<TH1*>(hists[iHist]); if (!hist) continue; if (fNormalise && hist->GetEntries()) { hist->Scale(1./hist->GetEntries()); } fHistMan->AddHistSame(hist, layer, pos, (legends[iHist] ? legends[iHist]->GetName() : 0)); ++nHists; } return nHists; }
std::shared_ptr<TH1> getHistogram(const std::string& name, const std::vector<Input>& inputs, int type) { TH1* h = nullptr; for (const auto& input: inputs) { if (input.type != type) continue; TH1* f = static_cast<TH1*>(input.file->Get(name.c_str())); f->Scale(input.cross_section / (input.generated_events * input.top_pt_weight)); if (! h) { h = static_cast<TH1*>(f->Clone()); h->SetDirectory(NULL); } else h->Add(f); } return std::shared_ptr<TH1>(h); }
// 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; }
// Called just after the main event loop // Can be used to write things out, dump a summary etc // Return non-zero to indicate a problem int IslandAmplitude::AfterLastEntry(TGlobalData* gData,const TSetupData *setup){ // Print extra info if we're debugging this module: if(Debug()){ cout<<"-----IslandAmplitude::AfterLastEntry(): I'm debugging!"<<endl; } double run_norm = fAmpNorm->Integral(0,-1); for(mapSH_t::iterator it = fAmpHist.begin(); it != fAmpHist.end(); ++it) { TH1F* h = it->second; TObject* obj = h->Clone((std::string(h->GetName()) + "_RunNorm").c_str()); TH1* hn = static_cast<TH1*>(obj); hn->SetTitle((std::string(h->GetTitle()) + " (run normalized)").c_str()); hn->Scale(1.0/run_norm); } for(mapSH_t::iterator it = fAmpHistNorm.begin(); it != fAmpHistNorm.end(); ++it) it->second->Scale(1.0/fNProcessed); return 0; }
TH1 *Draw(const plotVar_t& pv, const TCut& cut, const TCut& cutSQ ) { cout << "\tDrawing " << pv.plotvar << " for sample = " << info_.samplename << " ... "; TString hname = TString("th1")+ pv.outfile + Form("%d",info_.index); TH1 *histo = new TH1D(hname, hname, pv.NBINS, pv.MINRange, pv.MAXRange); assert(histo); histo->Sumw2(); assert(tree_); cout << tree_->Draw(pv.plotvar+TString(">>")+hname, cut, "goff") << " events" << endl; if (strlen((const char *)cutSQ)) { hname = TString("th1") + pv.outfile + Form("%d",info_.index) + TString("SQ"); TH1 *histoSQ = new TH1D(hname, hname, pv.NBINS, pv.MINRange, pv.MAXRange); tree_->Draw(pv.plotvar+TString(">>")+hname, cutSQ, "goff"); for(int hi=1;hi<=pv.NBINS;hi++) { histo->SetBinError(hi,sqrt(histoSQ->GetBinContent(hi))); } delete histoSQ; } if (info_.nMCevents) histo->Scale(info_.xsecpblumi*info_.otherscale/(double)info_.nMCevents); return histo; }
int studyWtaunu(){//main std::vector<std::string> Wfiles; Wfiles.push_back("WJetsToLNu-v1_taunu"); Wfiles.push_back("WJetsToLNu-v2_taunu"); Wfiles.push_back("W1JetsToLNu_taunu"); Wfiles.push_back("W2JetsToLNu_taunu"); Wfiles.push_back("W3JetsToLNu_taunu"); Wfiles.push_back("W4JetsToLNu_taunu"); Wfiles.push_back("EWK-W2jminus_taunu"); Wfiles.push_back("EWK-W2jplus_taunu"); std::string folder = "output/nunu/Skim/MET130/"; //std::string folder = "output/nunu/Skim/MET130/tmp/"; std::string suffix = ""; const unsigned nWFiles = Wfiles.size(); TFile *fW[nWFiles]; double lLumi = 19619.; double w_normalisation[nWFiles]; for (unsigned iN(0); iN<6;++iN){ w_normalisation[iN] = 37509/76102995.0; } w_normalisation[6] = 4.09/4696648; w_normalisation[7] = 6.48/6776164; TCanvas *myc = new TCanvas("myc","",4); gStyle->SetOptStat("euoi"); myc->Divide(2,3); std::ostringstream lPath; const unsigned nHists2D = 1; const unsigned nHists1D = 5; const unsigned nHists = nHists1D+nHists2D; //std::string lHistName[nHists] = {"Gen/taupt","Gen/taueta","Gen/tauptvseta"}; std::string lHistName[nHists] = {"Gen/tauptvseta","Gen/taupt","Gen/taueta","n_jets","Gen/recotaupt","Gen/recotaueta"}; double minX[nHists] = {-4,0,-4,0,0,-3}; double maxX[nHists] = {4,250,4,10,250,3}; int logy[nHists] = {0,1,0,1,1,1}; int rebin[nHists] = {1,5,2,1,5,2}; std::vector<std::string> selections; selections.push_back("HLTMetClean"); selections.push_back("LeptonVeto"); //selections.push_back("WSelection"); selections.push_back("JetPair"); //selections.push_back("AN"); selections.push_back("DEta"); selections.push_back("MET"); selections.push_back("TightMjj"); selections.push_back("DPhiSIGNAL_noCJV"); //selections.push_back("DPhiQCD_noCJV"); //selections.push_back("CJVfail"); //selections.push_back("DPhiSIGNAL_CJVfail"); //selections.push_back("DPhiQCD_CJVfail"); selections.push_back("CJVpass"); selections.push_back("DPhiSIGNAL_CJVpass"); //selections.push_back("DPhiQCD_CJVpass"); const unsigned nSel = selections.size(); TH1 *hist[nHists]; TH1 *hist_ewk[nHists]; TLegend *leg; double error[nHists]; double integral[nHists]; double error_ewk[nHists]; double integral_ewk[nHists]; int bin_ptmin = 0; int bin_etamin = 0; int bin_etamax = 0; std::ofstream lOutfile; lOutfile.open("EventNumbers_taunu.txt"); lOutfile << "Selection & n$_{\\tau}^{acc}$ & n$_{tot}$ & n$_{\\tau}^{acc}$/n$_{tot}$ & n$_{\\tau}^{reco}$ & n$_{\\tau}^{reco}$/n$_{tot}$ \\\\" << std::endl; for (unsigned iS(0); iS<nSel; ++iS){//loop on selections lPath.str(""); lPath << "../" << folder << "/MC_"; lOutfile << selections[iS] << " & $ " ; for (unsigned iP(0); iP<nHists; ++iP){//loop on points //get histograms for (unsigned iW(0); iW<nWFiles; ++iW){//loop on w files fW[iW] = TFile::Open((lPath.str()+Wfiles[iW]+".root").c_str()); //fW[iW]->cd((lSelection[iS]+"/weights/").c_str()); //if (iP < 2) fW[iW]->cd((selections[iS]+"/").c_str()); //else fW[iW]->cd((selections[iS]+"/weights/").c_str()); if (iW==0 || iW==6) { if (iP<nHists2D) { if (iW==0) hist[iP] = (TH2F*)gDirectory->Get(lHistName[iP].c_str())->Clone(); if (iW==6) hist_ewk[iP] = (TH2F*)gDirectory->Get(lHistName[iP].c_str())->Clone(); } else { if (iW==0) hist[iP] = (TH1F*)gDirectory->Get(lHistName[iP].c_str())->Clone(); if (iW==6) hist_ewk[iP] = (TH1F*)gDirectory->Get(lHistName[iP].c_str())->Clone(); } //hist[iP]->Sumw2(); if (iW==0) hist[iP]->Scale(lLumi*w_normalisation[iW]); if (iW==6) hist_ewk[iP]->Scale(lLumi*w_normalisation[iW]); } if (iW>0) { TH1 *lTmpHist = 0; if (iP<nHists2D) { lTmpHist = (TH2F*)gDirectory->Get(lHistName[iP].c_str()); } else { lTmpHist = (TH1F*)gDirectory->Get(lHistName[iP].c_str()); } lTmpHist->Scale(lLumi*w_normalisation[iW]); hist[iP]->Add(lTmpHist); if (iW==7) { hist_ewk[iP]->Add(lTmpHist); } } }//loop on w hists //std::cout << " -- total entries = " << hist[iP]->Integral() //<< std::endl; if (iP==0 && iS==0){ for (int iX(0); iX<hist[iP]->GetNbinsX()+2; ++iX){ double eta = hist[iP]->GetXaxis()->GetBinLowEdge(iX); if (eta <= -2.3) bin_etamin=iX; else if (eta <= 2.3) { bin_etamax=iX; } else break; } for (int iY(0); iY<hist[iP]->GetNbinsY()+2; ++iY){ double pT = hist[iP]->GetYaxis()->GetBinLowEdge(iY); if (pT <= 20) { bin_ptmin = iY; } else break; } std::cout << " -- Found bin edges : " << bin_etamin << " (" << hist[iP]->GetXaxis()->GetBinLowEdge(bin_etamin) << ") " << bin_etamax << "(" << hist[iP]->GetXaxis()->GetBinUpEdge(bin_etamax) << ") " << bin_ptmin << " (" << hist[iP]->GetYaxis()->GetBinLowEdge(bin_ptmin) << ")" << std::endl; } error[iP] = 0; error_ewk[iP] = 0; if (iP>0) integral[iP] = hist[iP]->IntegralAndError(0,hist[iP]->GetNbinsX()+1,error[iP]); else integral[iP] = dynamic_cast<TH2F*>(hist[iP])->IntegralAndError(bin_etamin,bin_etamax,bin_ptmin,hist[iP]->GetNbinsY()+1,error[iP]); if (iP>0) integral_ewk[iP] = hist_ewk[iP]->IntegralAndError(0,hist_ewk[iP]->GetNbinsX(),error_ewk[iP]); else integral_ewk[iP] = dynamic_cast<TH2F*>(hist_ewk[iP])->IntegralAndError(bin_etamin,bin_etamax,bin_ptmin,hist[iP]->GetNbinsY()+1,error_ewk[iP]); std::cout << selections[iS] << " " << lHistName[iP] << " " << integral[iP] << " +/- " << error[iP] << std::endl; if (iP==0) lOutfile << std::setprecision(3) << integral[iP] << " \\pm " << error[iP] ; //<< "$ & $ " //<< integral_ewk[iP] << " \\pm " << error_ewk[iP] ; if (iP==3){ double ratio = integral[0]/integral[3]; double ratioerr = ratio*sqrt(pow(error[0]/integral[0],2)+pow(error[3]/integral[3]-2*error[0]*error[3]/(integral[0]*integral[3]),2)); lOutfile << " $ & $ " << integral[iP] << " \\pm " << error[iP] << " $ & $ " << ratio << " \\pm " << ratioerr ; } if (iP==4){ double ratio = integral[4]/integral[3]; double ratioerr = ratio*sqrt(pow(error[4]/integral[4],2)+pow(error[3]/integral[3]-2*error[4]*error[3]/(integral[4]*integral[3]),2)); lOutfile << " $ & $ " << integral[iP] << " \\pm " << error[iP] << " $ & $ " << ratio << " \\pm " << ratioerr << " $ \\\\" << std::endl; } myc->cd(iP+1); //hist[iP]->RebinY(10); if (iP==0) { hist[iP]->GetXaxis()->SetTitle("#eta (#tau genjet)"); hist[iP]->GetYaxis()->SetTitle("p_{T}(#tau genjet) (GeV)"); } else if (iP==1) { hist[iP]->GetXaxis()->SetTitle("p_{T}(#tau genjet) (GeV)"); } else if (iP==2) { hist[iP]->GetXaxis()->SetTitle("#eta (#tau genjet)"); } else if (iP==3) { hist[iP]->GetXaxis()->SetTitle("Jet multiplicity"); } else if (iP==4) { hist[iP]->GetXaxis()->SetTitle("p_{T}(#tau recojet) (GeV)"); } else if (iP==5) { hist[iP]->GetXaxis()->SetTitle("#eta (#tau recojet)"); } hist[iP]->SetTitle(("MC W#rightarrow #tau#nu, "+selections[iS]).c_str()); hist[iP]->SetLineColor(1); hist[iP]->SetMarkerColor(1); hist[iP]->SetMarkerStyle(20); hist_ewk[iP]->SetLineColor(6); hist_ewk[iP]->SetMarkerColor(6); hist_ewk[iP]->SetMarkerStyle(22); gPad->SetLogy(logy[iP]); if (iP<nHists2D) { dynamic_cast<TH2F*>(hist[iP])->RebinX(2); dynamic_cast<TH2F*>(hist[iP])->RebinY(5); hist[iP]->GetYaxis()->SetRangeUser(0,250); hist[iP]->Draw("colz"); //hist_ewk[iP]->Draw("same"); } else { hist[iP]->Rebin(rebin[iP]); hist[iP]->GetXaxis()->SetRangeUser(minX[iP],maxX[iP]); hist[iP]->Draw("PE"); hist_ewk[iP]->Draw("PEsame"); if (iP==1) { leg = new TLegend(0.3,0.7,0.6,0.89); leg->SetFillColor(10); leg->AddEntry(hist[iP],"W#rightarrow #tau#nu QCD+EWK","P"); leg->AddEntry(hist_ewk[iP],"W#rightarrow #tau#nu EWK","P"); } leg->Draw("same"); } //if (iP==0) gStyle->SetStatX(0.89); gStyle->SetStatY(0.89); //else hist[iP]->Draw("histsame"); }//loop on histos myc->Update(); myc->Print(("Wtau_"+selections[iS]+".pdf").c_str()); }//loop on selections lOutfile.close(); return 0; }//main
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; }
void ttreesToHistograms() { //******************************************************************** //**** Variables ****// cout << "Loading variables into vectors..." << endl; vector<TString> fileName; fileName.push_back( "rootfiles0/PhotonJetPt15_Summer09.root" );//file0 fileName.push_back( "rootfiles0/PhotonJetPt30_Summer09.root" );//file1 fileName.push_back( "rootfiles0/PhotonJetPt80_Summer09.root" );//file2 fileName.push_back( "rootfiles0/PhotonJetPt170_Summer09.root" );//file3 fileName.push_back( "rootfiles0/PhotonJetPt300_Summer09.root" );//file4 fileName.push_back( "rootfiles0/PhotonJetPt470_Summer09.root" );//file5 fileName.push_back( "rootfiles0/PhotonJetPt800_Summer09.root" );//file6 TString treeName = "TreePhotonJet"; TString outputFileName = "PhotonJetHists-2009-09-02-matchesReco.root"; //********************************* //**** Set Scale // The following 4 number set the scale // example: // scale = (integrated luminosity (1/pb))*(cross section (pb))*(filter eff)/(events analyzed) float invLuminosityToScaleTo = 200; // in pb-1 vector<float> crossSection; crossSection.push_back( 2.887E5 -3.222E4 ); // in pb crossSection.push_back( 3.222E4 -1.010E3 ); crossSection.push_back( 1.010E3 -5.143E1 ); crossSection.push_back( 5.143E1 -4.193E0 ); crossSection.push_back( 4.193E0 -4.515E-1 ); crossSection.push_back( 4.515E-1 -2.003E-2 ); crossSection.push_back( 2.003E-2 ); vector<float> filterEffeciency; filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); vector<float> eventsAnalyzied; eventsAnalyzied.push_back( 1073270 ); eventsAnalyzied.push_back( 1088546 ); eventsAnalyzied.push_back( 993509 ); eventsAnalyzied.push_back( 1483940 ); eventsAnalyzied.push_back( 1024589 ); eventsAnalyzied.push_back( 1014413 ); eventsAnalyzied.push_back( 1216320 ); // END of setting scale //********************************* //********************************* //**** Set Cuts ****// // Variables will be plotted for each "location" vector<TString> locationCut; locationCut.push_back( "abs(hardGenPhoton_eta)>1.55&&abs(hardGenPhoton_eta)<2.5" ); locationCut.push_back( "abs(hardGenPhoton_eta)<1.45" ); vector<TString> locationName; locationName.push_back( "Endcap" ); locationName.push_back( "Barrel" ); // These cuts will be merged into one giant cut, applied to all plots for all files vector<TString> cuts; cuts.push_back( "hardGenPhoton_et>15.0&&photon_et>15.0&&photon_matches_hardGen>0.5" ); // These cuts will be applied only to corresponding file vector<TString> fileCuts; fileCuts.push_back( "event_genEventScale>15&&event_genEventScale<30" ); //file0 fileCuts.push_back( "event_genEventScale>30&&event_genEventScale<80" ); //file1 fileCuts.push_back( "event_genEventScale>80&&event_genEventScale<170" ); //file2 fileCuts.push_back( "event_genEventScale>170&&event_genEventScale<300" ); //file3 fileCuts.push_back( "event_genEventScale>300&&event_genEventScale<470" ); //file4 fileCuts.push_back( "event_genEventScale>470&&event_genEventScale<800" ); //file5 fileCuts.push_back( "event_genEventScale>800&&event_genEventScale<1400" ); //file6 //**** END of setting cuts //********************************* //********************************* int locationVariablesToPlot[2][2]; // [a][b], a=number of locations, b=2 (for min,max range of variables to plot) locationVariablesToPlot[0][0] = 16; // Endcap locationVariablesToPlot[0][1] = 35; locationVariablesToPlot[1][0] = 16; // Barrel locationVariablesToPlot[1][1] = 35; /*locationVariablesToPlot[2][0] = 0; locationVariablesToPlot[2][1] = 4; locationVariablesToPlot[3][0] = 0; locationVariablesToPlot[3][1] = 4; locationVariablesToPlot[4][0] = 0; locationVariablesToPlot[4][1] = 4; locationVariablesToPlot[5][0] = 0; locationVariablesToPlot[5][1] = 4; locationVariablesToPlot[6][0] = 0; locationVariablesToPlot[6][1] = 4; locationVariablesToPlot[7][0] = 0; locationVariablesToPlot[7][1] = 4;*/ // Variables you want plotted vector<TString> variableToPlot; // --- the following require gen level info variableToPlot.push_back( "hardGenPhoton_et" ); // 0 variableToPlot.push_back( "hardGenPhoton_eta" ); variableToPlot.push_back( "hardGenPhoton_phi" ); variableToPlot.push_back( "fmod(hardGenPhoton_phi+3.141592,20.0*3.141592/180.0)-10.0*3.141592/180.0" ); variableToPlot.push_back( "abs(hardGenPhoton_eta)" ); // 4 variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy" ); variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy:hardGenPhoton_energy" ); variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy:abs(hardGenPhoton_eta)" ); variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy:hardGenPhoton_phiMod" ); variableToPlot.push_back( "photon_hadronicOverEm:hardGenPhoton_et" ); variableToPlot.push_back( "photon_hadronicOverEm:abs(hardGenPhoton_eta)" ); // 10 variableToPlot.push_back( "photon_hadronicOverEm:hardGenPhoton_phiMod" ); variableToPlot.push_back( "photon_eta-hardGenPhoton_eta" ); variableToPlot.push_back( "photon_eta-hardGenPhoton_eta:hardGenPhoton_et" ); variableToPlot.push_back( "photon_eta-hardGenPhoton_eta:abs(hardGenPhoton_eta)" ); variableToPlot.push_back( "deltaPhiGenRecPhoton" ); // 15 // --- the following require only rec photons variableToPlot.push_back( "photon_et" ); // 16 variableToPlot.push_back( "photon_eta" ); variableToPlot.push_back( "photon_phi" ); variableToPlot.push_back( "fmod(photon_phi+3.141592,20.0*3.141592/180.0)-10.0*3.141592/180.0" ); variableToPlot.push_back( "abs(photon_eta)" ); // 20 variableToPlot.push_back( "photon_r9" ); variableToPlot.push_back( "photon_ecalRecHitSumEtConeDR03" ); variableToPlot.push_back( "photon_hcalTowerSumEtConeDR03" ); variableToPlot.push_back( "photon_trkSumPtSolidConeDR03" ); variableToPlot.push_back( "photon_trkSumPtHollowConeDR03" ); //25 variableToPlot.push_back( "photon_nTrkSolidConeDR03" ); variableToPlot.push_back( "photon_nTrkHollowConeDR03" ); variableToPlot.push_back( "photon_hadronicOverEm" ); variableToPlot.push_back( "photon_r2x5" ); variableToPlot.push_back( "photon_ecalRecHitSumEtConeDR03/photon_et" ); // 30 variableToPlot.push_back( "photon_hcalTowerSumEtConeDR03/photon_et" ); variableToPlot.push_back( "photon_trkSumPtSolidConeDR03/photon_et" ); variableToPlot.push_back( "photon_trkSumPtHollowConeDR03/photon_et" ); // --- the following require jets /*variableToPlot.push_back( "calcDeltaPhi(photon_phi,jet_phi)" ); variableToPlot.push_back( "calcDeltaPhi(photon_phi,jet2_phi)" ); // 35 variableToPlot.push_back( "calcDeltaPhi(jet_phi,jet2_phi)" );*/ variableToPlot.push_back( "(photon_et-jet_et)/photon_et" ); variableToPlot.push_back( "jet2_et/photon_et" ); // Histograms for the above variables vector<TH1*> histogram; // --- the following require gen level info histogram.push_back( new TH1F("photonGenEt", "Photon E_{T} ;E_{T} (GeV);entries per 15 GeV", 50, 0, 750) ); // 0 histogram.push_back( new TH1F("photonGenEta", "Photon #eta ;#eta;entries per 0.1 bin", 61, -3.05, 3.05) ); histogram.push_back( new TH1F("photonGenPhi", "Photon #phi ;#phi;entries per bin", 62, (-1.-1./30.)*TMath::Pi(), (1.+1./30.)*TMath::Pi()) ); histogram.push_back( new TH1F("photonGenPhiMod", "Photon #phi_{mod} ", 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329) ); histogram.push_back( new TH1F("photonGenAbsEta", "Photon |#eta| ", 51, 0.00, 2.55) ); histogram.push_back( new TH1F("photonDeltaE", "(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) ", 50, -0.8, 0.3) ); histogram.push_back( new TH2F("photonDeltaE_vs_E","(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) vs E(#gamma_{gen}) ", 50, 0, 3000, 50, -0.8, 0.3) ); histogram.push_back( new TH2F("photonDeltaE_vs_AbsEta","(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) vs |#eta(#gamma_{gen}|) ", 51, 0.0, 2.5, 50, -0.8, 0.3) ); histogram.push_back( new TH2F("photonDeltaE_vs_PhiMod","(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) vs #phi_{mod}(#gamma_{gen}) ", 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329, 50, -0.9, 0.2) ); histogram.push_back( new TH2F("photonHoverE_vs_Et", "H/E vs E_{T}(#gamma_{gen}) ", 50, 0, 1000, 50, 0.0, 0.2) ); histogram.push_back( new TH2F("photonHoverE_vs_AbsEta", "H/E vs |#eta(#gamma_{gen})| ", 51, 0.0, 2.5, 50, 0.0, 0.2) ); histogram.push_back( new TH2F("photonHoverE_vs_PhiMod", "H/E vs #phi_{mod}(#gamma_{gen}) ", 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329, 50, 0.0, 0.2) ); histogram.push_back( new TH1F("photonDeltaEta", "#Delta#eta(#gamma_{rec},#gamma_{gen}) ;#Delta#eta(#gamma_{rec},#gamma_{gen});entries/bin", 41, -0.01, 0.01) ); histogram.push_back( new TH2F("photonDeltaEta_vs_Et", "#Delta#eta(#gamma_{rec},#gamma_{gen}) vs E_{T}(#gamma_{gen}) ", 50, 0, 1000, 41, -0.1, 0.1) ); histogram.push_back( new TH2F("photonDeltaEta_vs_AbsEta","#Delta#eta(#gamma_{rec},#gamma_{gen}) vs #eta(#gamma_{gen})", 51, 0.0, 2.55, 41, -0.1, 0.1) ); histogram.push_back( new TH1F("photonDeltaPhi", "#Delta#phi(#gamma_{rec},#gamma_{gen}) ;#Delta#phi(#gamma_{rec},#gamma_{gen});entries/bin", 41, 0.0, 0.01) ); // 15 // --- the following require only rec photons histogram.push_back( new TH1F("photonEt", "Photon E_{T} ;E_{T} (GeV);entries per 15 GeV", 50, 0, 750 ) ); // 16 histogram.push_back( new TH1F("photonEta", "Photon #eta ;#eta;entries per 0.1" , 61, -3.05, 3.05) ); histogram.push_back( new TH1F("photonPhi", "Photon #phi ;#phi;entries per bin" , 62, (-1.-1./30.)*TMath::Pi(), (1.+1./30.)*TMath::Pi()) ); histogram.push_back( new TH1F("photonPhiMod", "Photon #phi_{mod} " , 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329) ); histogram.push_back( new TH1F("photonAbsEta", "Photon |#eta| " , 51, 0.00, 2.55) ); // 20 histogram.push_back( new TH1F("photonR9", "R9 = E(3x3) / E(SuperCluster) ;R9;entries/bin" , 50, 0.6, 1.0) ); histogram.push_back( new TH1F("photonEcalIso", "#SigmaEcal Rec Hit E_{T} in Hollow #DeltaR cone " , 50, 0 , 15) ); histogram.push_back( new TH1F("photonHcalIso", "#SigmaHcal Rec Hit E_{T} in Hollow #DeltaR cone " , 50, 0 , 15) ); histogram.push_back( new TH1F("photonTrackSolidIso", "#Sigmatrack p_{T} in Solid #DeltaR cone " , 50, 0 , 15) ); histogram.push_back( new TH1F("photonTrackHollowIso", "#Sigmatrack p{T} in Hollow #DeltaR cone " , 50, 0 , 15) ); // 25 histogram.push_back( new TH1F("photonTrackCountSolid", "Number of tracks in Solid #DeltaR cone ;Number of Tracks;entries/bin" , 25, -0.5, 24.5) ); histogram.push_back( new TH1F("photonTrackCountHollow", "Number of tracks in Hollow #DeltaR cone ;Number of Tracks;entries/bin", 25, -0.5, 24.5) ); histogram.push_back( new TH1F("photonHoverE", "Hadronic / EM ", 50, 0.0, 0.2) ); histogram.push_back( new TH1F("photonScSeedE2x5over5x5", "E2x5/E5x5 " , 50, 0.6, 1.0) ); histogram.push_back( new TH1F("photonEcalIsoOverE", "#SigmaEcal Rec Hit E_{T} in #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) ); // 30 histogram.push_back( new TH1F("photonHcalIsoOverE", "#SigmaHcal Rec Hit E_{T} in #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) ); histogram.push_back( new TH1F("photonTrackSolidIsoOverE" , "#SigmaTrack p_{T} in #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) ); histogram.push_back( new TH1F("photonTrackHollowIsoOverE", "#SigmaTrack p_{T} in Hollow #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) ); // --- the following require jets /*histogram.push_back( new TH1F("h_deltaPhi_photon_jet", "#Delta#phi between Highest E_{T} #gamma and jet;#Delta#phi(#gamma,1^{st} jet)" , 50, 0, 3.1415926) ); histogram.push_back( new TH1F("h_deltaPhi_photon_jet2","#Delta#phi between Highest E_{T} #gamma and 2^{nd} highest jet;#Delta#phi(#gamma,2^{nd} jet)", 50, 0, 3.1415926) ); histogram.push_back( new TH1F("h_deltaPhi_jet_jet2" , "#Delta#phi between Highest E_{T} jet and 2^{nd} jet;#Delta#phi(1^{st} jet,2^{nd} jet)" , 50, 0, 3.1415926) );*/ histogram.push_back( new TH1F("h_deltaEt_photon_jet" , "(E_{T}(#gamma)-E_{T}(jet))/E_{T}(#gamma) when #Delta#phi(#gamma,1^{st} jet) > 2.8;#DeltaE_{T}(#gamma,1^{st} jet)/E_{T}(#gamma)", 20, -1.0, 1.0) ); histogram.push_back( new TH1F("h_jet2_etOverPhotonEt", "E_{T}(2^{nd} highest jet) / E_{T}(#gamma);E_{T}(2^{nd} Jet)/E_{T}(#gamma)", 20, 0.0, 4.0) ); //**** END of Variables ****// //******************************************************************** //******************************************************************** //**** Main part of Program ****// // Human error checking if (variableToPlot.size() != histogram.size() ) { cout << "Should have equal entries in histogram and variableToPlot vector." << endl; return; } if (fileName.size() > crossSection.size() ) { cout << "Should have equal entries in fileName and crossSection vetor." << endl; return; } if (fileName.size() > fileCuts.size() ) { cout << "Should have equal entries in fileName and fileCuts vector." << endl; return; } // Combine all the cuts into one cout << endl << "Cuts that will be applied to everything: " << endl << " "; TCut allCuts = ""; for (int i =0; i<cuts.size(); i++) { allCuts += cuts[i]; if (i>0) cout << "&&"; cout << "(" << cuts[i] << ")"; } cout << endl << endl; // Open the files & set their scales cout << endl << "Histograms will be scaled to " << invLuminosityToScaleTo << "pb-1 " << endl; cout << "Looking for TTree named \"" << treeName << "\" in files..." << endl; vector<float> fileScale; TList *fileList = new TList(); for (int i=0; i < fileName.size(); i++) { TFile* currentFile = TFile::Open(fileName[i]); fileList->Add(currentFile); float currentScale = crossSection[i]*invLuminosityToScaleTo*filterEffeciency[i]/eventsAnalyzied[i]; fileScale.push_back( currentScale ); // Display entries in that file's TTree TTree* tree; currentFile->GetObject(treeName, tree); cout << "file" << i <<": " << fileName[i] << " contains " << tree->GetEntries(allCuts) << " entries, and will be scaled by " << currentScale << endl; } cout << endl << endl; //Create output file TFile *outputFile = TFile::Open( outputFileName, "RECREATE" ); //************************************************************ // Core of the Script // // Loop over locations for (int l=0; l<locationName.size(); l++) { TString currentLocation = locationName[l]; TCut currentCuts = allCuts; currentCuts += locationCut[l]; cout << "Creating plots for " << currentLocation << ", " << locationCut[l] << endl; // Loop over variables to plot for (int i=0; i<variableToPlot.size(); i++) { // should we plot this variable for this location? if (i<locationVariablesToPlot[l][0] || i>locationVariablesToPlot[l][1]) continue; TString currentHistType = histogram[i]->IsA()->GetName(); TString currentHistName = TString(histogram[i]->GetName()) + "_" + currentLocation; TString currentHistTitle = TString(histogram[i]->GetTitle()) + "(" + currentLocation + ")"; cout << " " << variableToPlot[i] << " >> " << currentHistName; TString currentHistDrawOpt; if (currentHistType=="TH2F") { currentHistDrawOpt="goffbox"; } else { currentHistDrawOpt="egoff"; } TH1* currentHist = (TH1*)histogram[i]->Clone(currentHistName); // Creates clone with name currentHistName currentHist->Sumw2(); // store errors currentHist->SetTitle(currentHistTitle); //cout << " from file"; // Plot from the first file int f = 0; //cout << f; TTree *tree; TFile *current_file = (TFile*)fileList->First(); current_file->cd(); current_file->GetObject(treeName, tree); tree->Draw(variableToPlot[i]+">>"+currentHistName,currentCuts+TCut(fileCuts[f]),currentHistDrawOpt); currentHist->Scale(fileScale[f]); f++; // Loop over files current_file = (TFile*)fileList->After( current_file ); while ( current_file ) { current_file->cd(); //cout << ", file" << f; current_file->GetObject(treeName, tree); TString tempHistName = currentHistName+"Temp"; TH1* tempHist = (TH1*)currentHist->Clone(tempHistName); tree->Draw(variableToPlot[i]+">>"+tempHistName,currentCuts+TCut(fileCuts[f]),currentHistDrawOpt); tempHist->Scale(fileScale[f]); currentHist->Add(tempHist); tempHist->Delete(); current_file = (TFile*)fileList->After( current_file ); f++; } // End of loop over files outputFile->cd(); currentHist->Write(); cout << endl; } // End of loop over variabls to plot } // End of loop over locations // END of Core of Script // //************************************************************ cout << endl; cout << "Wrote file " << outputFileName << endl; cout << endl; outputFile->Close(); }
//void LeptonEnergy(const char *inputFile = "sourceFiles/LO/ttbar_LO_total.root") void LeptonEnergy(const TString & file) { //const char *inputFile = Form("/home/tjkim/work/pheno/topmass/sourceFiles/LO/fromSayaka/ttbar_%s.root",file.Data()); //gSystem->Load("/export/apps/delphes//libDelphes"); const char *inputFile = Form("/data/users/seohyun/analysis/ttbar_%s.root",file.Data()); gSystem->Load("/home/seohyun/delphes/libDelphes.so"); /* TFile *f2 = TFile::Open("weightfunc2.root"); TFile *f3 = TFile::Open("weightfunc3.root"); TFile *f5 = TFile::Open("weightfunc5.root"); TFile *f15 = TFile::Open("weightfunc15.root"); const int nmass = 151; float mymass[ nmass ]; float integral2[ nmass ]; float integral3[ nmass ]; float integral5[ nmass ]; float integral15[ nmass ]; for(int i=0; i < nmass ; i++){ integral2[i] = 0.0; integral3[i] = 0.0; integral5[i] = 0.0; integral15[i] = 0.0; } TGraph * g2[nmass]; TGraph * g3[nmass]; TGraph * g5[nmass]; TGraph * g15[nmass]; TIter next(f2->GetListOfKeys()); TKey *key; int i = 0; while( (key = (TKey*) next())) { TClass *cl = gROOT->GetClass( key->GetClassName()); if( !cl->InheritsFrom("TGraph")) continue; g2[i] = (TGraph*) key->ReadObj(); string mass = g2[i]->GetName(); float temp = atof(mass.c_str()); mymass[i] = temp; i++; } TIter next(f3->GetListOfKeys()); i = 0; while( (key = (TKey*) next())) { TClass *cl = gROOT->GetClass( key->GetClassName()); if( !cl->InheritsFrom("TGraph")) continue; g3[i] = (TGraph*) key->ReadObj(); i++; } TIter next(f5->GetListOfKeys()); i = 0; while( (key = (TKey*) next())) { TClass *cl = gROOT->GetClass( key->GetClassName()); if( !cl->InheritsFrom("TGraph")) continue; g5[i] = (TGraph*) key->ReadObj(); i++; } TIter next(f15->GetListOfKeys()); i = 0; while( (key = (TKey*) next())) { TClass *cl = gROOT->GetClass( key->GetClassName()); if( !cl->InheritsFrom("TGraph")) continue; g15[i] = (TGraph*) key->ReadObj(); i++; } TFile * res = TFile::Open("hist_LO_res_v3.root"); TH1F * h_acc = (TH1F*) res->Get("h_totalacc_lepton"); */ //TFile* f = TFile::Open("hist_LO_res_60.root", "recreate"); TFile* f = TFile::Open(Form("170717/hist_%s.root",file.Data()), "recreate"); // Create chain of root trees TChain chain("Delphes"); chain.Add(inputFile); // Create object of class ExRootTreeReader ExRootTreeReader *treeReader = new ExRootTreeReader(&chain); Long64_t numberOfEntries = treeReader->GetEntries(); // Get pointers to branches used in this analysis TClonesArray *branchParticle = treeReader->UseBranch("Particle"); TClonesArray *branchMuon = treeReader->UseBranch("Muon"); TClonesArray *branchElectron = treeReader->UseBranch("Electron"); TClonesArray *branchJet = treeReader->UseBranch("Jet"); TClonesArray *branchEvent = treeReader->UseBranch("Event"); GenParticle *particle; GenParticle *daughter1; GenParticle *daughter2; GenParticle *granddaughter1_1; GenParticle *granddaughter1_2; GenParticle *granddaughter2_1; GenParticle *granddaughter2_2; GenParticle *genelectron; GenParticle *genmuon; LHEFEvent * event; // Create TTree //Float_t Muon_E; //Float_t Electron_E; //Float_t Lepton_E; //Float_t Lepton_E_reco; //TTree * tree = new TTree("tree","lepton energy"); //tree->Branch("Lepton_E",&Lepton_E,"Lepton_E/F"); //tree->Branch("Lepton_E_reco",&Lepton_E_reco,"Lepton_E_reco/F"); //tree->Branch("Muon_E",&Muon_E,"Muon_E/F"); //tree->Branch("Electron_E",&Electron_E,"Electron_E/F"); // Book histograms TH1 * channel = new TH1F("channel", "ttbar event categorization", 7, 0.0, 7.0); TH1 * h_muon_energy = new TH1F("h_muon_energy", "muon energy distribution", 5000, 0, 500); TH1 * h_electron_energy = new TH1F("h_electron_energy", "electron energy distribution", 5000, 0, 500); TH1 * h_lepton_energy = new TH1F("h_lepton_energy", "lepton energy distribution", 5000, 0, 500); //TH1 * h_muon_energy_acc = new TH1F("h_muon_energy_acc", "muon energy distribution", 5000, 0, 500); //TH1 * h_electron_energy_acc = new TH1F("h_electron_energy_acc", "electron energy distribution", 5000, 0, 500); TH1 * h_lepton_energy_acc = new TH1F("h_lepton_energy_acc", "lepton energy distribution", 5000, 0, 500); //TH1 * h_muon_energy_reco = new TH1F("h_muon_energy_reco", "muon energy distribution at RECO", 5000, 0, 500); //TH1 * h_electron_energy_reco = new TH1F("h_electron_energy_reco", "electron energy distribution at RECO", 5000, 0, 500); TH1 * h_lepton_energy_reco = new TH1F("h_lepton_energy_reco", "lepton energy distribution at RECO", 5000, 0, 500); TH2 * h2_lepton_energy_response = new TH2F("h2_lepton_energy_response", "lepton energy response", 5000, 0, 500,5000,0,500); //TH1 * h_muon_energy_reco_S2 = new TH1F("h_muon_energy_reco_S2", "muon energy distribution at RECO", 5000, 0, 500); //TH1 * h_electron_energy_reco_S2 = new TH1F("h_electron_energy_reco_S2", "electron energy distribution at RECO", 5000, 0, 500); //TH1 * h_lepton_energy_reco_S2 = new TH1F("h_lepton_energy_reco_S2", "lepton energy distribution at RECO", 5000, 0, 500); //TH1 * h_lepton_nbjets_reco_S2 = new TH1F("h_lepton_nbjets_reco_S2","number of b jets",5,0,5); //TH1 * h_muon_energy_reco_final = new TH1F("h_muon_energy_reco_final", "muon energy distribution at RECO", 5000, 0, 500); //TH1 * h_electron_energy_reco_final = new TH1F("h_electron_energy_reco_final", "electron energy distribution at RECO", 5000, 0, 500); TH1 * h_lepton_energy_reco_final = new TH1F("h_lepton_energy_reco_final", "lepton energy distribution at RECO", 5000, 0, 500); TH2 * h2_lepton_energy_final_response = new TH2F("h2_lepton_energy_final_response", "lepton energy response", 5000, 0, 500,5000,0,500); //std::vector<float> lepton_E; //std::vector<float> lepton_E_final; int ndileptonic = 0; //ee, mm, tautau int ndileptonic2 = 0; //ee, mm, tau->ee, mm int ndileptonic3 = 0; //ee, mm int nsemileptonic = 0; int nsemileptonic2 = 0; int nsemileptonic3 = 0; int nhadronic = 0; // Loop over all events for(Int_t entry = 0; entry < numberOfEntries; ++entry) { //if( entry == 100000) break; if( entry%1000 == 0) cout << "starting with " << entry << endl; // Load selected branches with data from specified event treeReader->ReadEntry(entry); int nmuons = 0; int nelectrons= 0; int ntaumuons = 0; int ntauelectrons= 0; int ntaus = 0 ; int nhadrons = 0 ; // If event contains at least 1 particle int ntop = 0; double genweight = 1.0; if(branchEvent->GetEntries() > 0) { event = (LHEFEvent * ) branchEvent->At(0); genweight = event->Weight; //cout << "event number = " << event->Number << endl; //cout << "event weight = " << event->Weight << endl; } //Lepton_E = -1.0; if(branchParticle->GetEntries() > 0) { for(int i = 0; i < branchParticle->GetEntriesFast() ; i++){ if(ntop == 2) break; particle = (GenParticle *) branchParticle->At(i); int status = particle->Status; bool LO = true; //if( LO ) cout << "THIS IS LO..." << endl; if( status != 3) continue; int id = particle->PID; double gen_pt = particle->PT; double gen_eta = particle->Eta; //Leading order if( LO) { if( abs(id) == 11 ){ genelectron = particle; double energy = genelectron->E; h_electron_energy->Fill( energy, genweight ); h_lepton_energy->Fill( energy, genweight ); //Lepton_E = energy; //for(int i=0; i < nmass; i++){ // float w = g2[i]->Eval( energy ); // integral2[i] = integral2[i] + w ; //} //lepton_E.push_back( energy ); if( energy > 20 && fabs(gen_eta) < 2.4) { //h_electron_energy_acc->Fill( energy, genweight ); h_lepton_energy_acc->Fill( energy, genweight ); nmuons++; } //daughter1 = (GenParticle*) branchParticle->At( particle->D1); //daughter2 = (GenParticle*) branchParticle->At( particle->D2); //int d1_id = abs(daughter1->PID); //int d2_id = abs(daughter2->PID); //cout << "electron daughter " << d1_id << " , " << d2_id << endl; }else if( abs(id) == 13 ){ genmuon = particle; double energy = genmuon->E; h_muon_energy->Fill( energy, genweight ); h_lepton_energy->Fill( energy, genweight ); //Lepton_E = energy; //for(int i=0; i < nmass; i++){ // float w = g2[i]->Eval( energy ); // integral2[i] = integral2[i] + w ; //} //lepton_E.push_back( energy ); if( energy > 20 && fabs(gen_eta) < 2.4) { //h_muon_energy_acc->Fill( energy, genweight ); h_lepton_energy_acc->Fill( energy, genweight ); nelectrons++; } //int d1_id = -1; //int d2_id = -1; //if( particle->D1 >= branchParticle->GetEntries()){ // daughter1 = (GenParticle*) branchParticle->At( particle->D1); // int d1_id = abs(daughter1->PID); //} //if( particle->D1 >= branchParticle->GetEntries()){ // daughter1 = (GenParticle*) branchParticle->At( particle->D1); // int d1_id = abs(daughter1->PID); //} //cout << "muon daughter " << d1_id << " , " << d2_id << endl; } //NLO }else if( abs(id) == 6 ) { ntop++; particle = (GenParticle*) branchParticle->At( i ) ; if( particle->D1 >= branchParticle->GetEntries() ) continue; bool lasttop = false ; while( !lasttop ){ if( particle->D1 >= branchParticle->GetEntries() ) break; GenParticle * d = (GenParticle *) branchParticle->At( particle->D1 ); if( abs(d->PID) != 6 ) { lasttop = true; } else { particle = d ; } } if( particle->D1 >= branchParticle->GetEntries() || particle->D2 >= branchParticle->GetEntries() ){ continue; } daughter1 = (GenParticle*) branchParticle->At( particle->D1) ; daughter2 = (GenParticle*) branchParticle->At( particle->D2) ; bool lastW = false; int d1_id = abs(daughter1->PID); int d2_id = abs(daughter2->PID); //cout << "top daughter " << d1_id << " , " << d2_id << endl; while( !lastW) { if( daughter1->D1 >= branchParticle->GetEntries() ) break; GenParticle * d = (GenParticle *) branchParticle->At( daughter1->D1 ); if( abs(d->PID) != 24 ) { lastW = true; } else { daughter1 = d ; } } if( daughter1->D1 >= branchParticle->GetEntries() || daughter1->D2 >= branchParticle->GetEntries() ){ continue; } granddaughter1_1 = (GenParticle*) branchParticle->At( daughter1->D1) ; granddaughter1_2 = (GenParticle*) branchParticle->At( daughter1->D2) ; granddaughter2_1 = (GenParticle*) branchParticle->At( daughter2->D1) ; granddaughter2_2 = (GenParticle*) branchParticle->At( daughter2->D2) ; int gd1_1_id = abs(granddaughter1_1->PID); int gd1_2_id = abs(granddaughter1_2->PID); int gd2_1_id = abs(granddaughter2_1->PID); int gd2_2_id = abs(granddaughter2_2->PID); //cout << "W daughters = " << gd1_1_id << " , " << gd1_2_id << " , " << gd2_1_id << " , " << gd2_2_id << endl; int W_dau_status = granddaughter1_1->Status ; //if( gd1_1_id > gd1_2_id ) cout << "Something is WRONG ! " << endl; GenParticle * le = (GenParticle * ) branchParticle->At( granddaughter1_1->D1 ); //GenParticle * leda = (GenParticle * ) branchParticle->At( le->D1); if( gd1_1_id == 11 || gd1_1_id == 13 ){ cout << le->D1 << " , " << le->D2 << endl; // cout << " original id and status = " << gd1_1_id << " , " << W_dau_status << " le id and status = " << le->PID << " , " << le->Status << " leda id and status = " << leda->PID << " , " << leda->Status << endl; } if( gd1_1_id == 11 ) { nelectrons++; //genelectron = granddaughter1_2; genelectron = le; } else if( gd1_1_id == 13 ) { nmuons++; //genmuon = granddaughter1_2; genmuon = le; } else if( gd1_1_id == 15 ) { ntaus++; /* if( granddaughter1_2->D1 >= branchParticle->GetEntries() || granddaughter1_2->D2 >= branchParticle->GetEntries() ){ continue; } GenParticle * taudaughter1 = (GenParticle*) branchParticle->At( granddaughter1_2->D1) ; GenParticle * taudaughter2 = (GenParticle*) branchParticle->At( granddaughter1_2->D2) ; int taud1_id = abs(taudaughter1->PID); int taud2_id = abs(taudaughter2->PID); //cout << "tau daughter = " << taud1_id << " " << taud2_id << endl; if( taud1_id == 11 || taud1_id == 12 ) ntauelectrons++; else if( taud1_id == 13 || taud1_id == 14 ) ntaumuons++; else if( taud1_id == 15 || taud1_id == 16 ) { if( taudaughter1->D1 >= branchParticle->GetEntries() || taudaughter1->D2 >= branchParticle->GetEntries() ){ continue; } GenParticle * taugranddaughter1 = (GenParticle*) branchParticle->At( taudaughter1->D1) ; GenParticle * taugranddaughter2 = (GenParticle*) branchParticle->At( taudaughter1->D2) ; int taugd1_id = abs(taugranddaughter1->PID); int taugd2_id = abs(taugranddaughter2->PID); //cout << "tau grand daughter = " << taugd1_id << " " << taugd2_id << endl; if( taugd1_id == 11 || taugd1_id == 12 ) ntauelectrons++; else if( taugd1_id == 13 || taugd1_id == 14 ) ntaumuons++; ㅜㅜ else { continue; } } else { continue; } */ }else{ nhadrons++; } //cout << "nelectrons = " << nelectrons << " nmuons = " << nmuons << " ntaus = " << ntaus << " nhadrons = " << nhadrons << endl; } } } if( LO ){ }else{ int remaining = 0 ; int nleptons = nelectrons + nmuons + ntaus; if( nleptons == 2 && nhadrons == 0){ //cout << "dilepton" << endl; ndileptonic++; if( ntaus ==0 || ( ntaus == 1 && (ntauelectrons+ntaumuons) == 1) || (ntaus == 2 && (ntauelectrons+ntaumuons) == 2) ) { ndileptonic2++; } if( ntaus == 0) ndileptonic3++; }else if( nleptons == 1 && nhadrons == 1){ //cout << "lepton+jets" << endl; nsemileptonic++; if( ntaus ==0 || ( ntaus == 1 && (ntauelectrons+ntaumuons) == 1) ) nsemileptonic2++; if( ntaus == 0 ) { nsemileptonic3++; if( nmuons ) { h_muon_energy->Fill(genmuon->E, genweight); h_lepton_energy->Fill(genmuon->E, genweight); } if( nelectrons ) { h_electron_energy->Fill(genelectron->E, genweight); h_lepton_energy->Fill(genelectron->E, genweight); } } }else if ( nleptons == 0 && nhadrons == 2 ){ //cout << "hadronic" << endl; nhadronic++; }else{ //cout << "remaining" << endl; remaining++; } } Muon * mymuon; Electron * myelectron; bool passmuon = false; bool passelectron = false; if(branchMuon->GetEntries() > 0) { bool mymuonpass = false; for(int i = 0; i < branchMuon->GetEntriesFast() ; i++){ Muon * muon = (Muon *) branchMuon->At(i); if( muon->P4().E() > 20 && fabs( muon->P4().Eta() < 2.4) ){ mymuon = muon; mymuonpass = true; } break; } if( mymuonpass && ( nmuons > 0 || nelectrons > 0 ) ){ //h_muon_energy_reco->Fill(mymuon->P4().E(), genweight); h_lepton_energy_reco->Fill(mymuon->P4().E(), genweight); h2_lepton_energy_response->Fill(mymuon->P4().E(), genmuon->E, genweight); passmuon = true; } } if(branchElectron->GetEntries() > 0) { bool myelectronpass = false; for(int i = 0; i < branchElectron->GetEntriesFast() ; i++){ Electron * electron = (Electron *) branchElectron->At(i); if( electron->P4().E() > 20 && fabs( electron->P4().Eta() < 2.4) ){ myelectron = electron; myelectronpass = true; } break; } if( myelectronpass && ( nmuons > 0 || nelectrons > 0 ) ){ //h_electron_energy_reco->Fill(myelectron->P4().E(), genweight); h_lepton_energy_reco->Fill(myelectron->P4().E(), genweight); h2_lepton_energy_response->Fill(myelectron->P4().E(), genelectron->E, genweight); passelectron = true; } } if(branchJet->GetEntries() > 0 ) { int njets = 0; int nbjets = 0; for(int i = 0; i < branchJet->GetEntriesFast() ; i++){ Jet * jet = (Jet *) branchJet->At(i); if( jet->P4().Pt() > 30 && fabs( jet->P4().Eta() < 2.5) ){ njets++; if( jet->BTag ) nbjets++; } } } //Muon_E = -9.0; //Electron_E = -9.0; //Lepton_E_reco = -1.0; float Energy = 9.0; if( passelectron && !passmuon && njets >= 4){ float myele_energy = myelectron->P4().E(); //h_electron_energy_reco_S2->Fill(myele_energy, genweight); //h_lepton_energy_reco_S2->Fill(myele_energy, genweight); //h_lepton_nbjets_reco_S2->Fill(nbjets); if( nbjets >= 2 ){ //h_electron_energy_reco_final->Fill(myele_energy, genweight); h_lepton_energy_reco_final->Fill(myele_energy, genweight); h2_lepton_energy_final_response->Fill(myele_energy, genelectron->E, genweight); } //lepton_E_final.push_back( myelectron->P4().E() ); //for(int i=0; i < nmass; i++){ // float corr = 1.0/ h_acc->Interpolate( myelectron->P4().E() ); // float w = g2[i]->Eval( myelectron->P4().E() ); //integral2[i] = integral2[i] + w*corr ; //} //Electron_E = myele_energy; //Lepton_E_reco = myele_energy; } if( passmuon && !passelectron && njets >= 4){ float mymuon_energy = mymuon->P4().E(); //h_muon_energy_reco_S2->Fill(mymuon_energy, genweight); //h_lepton_energy_reco_S2->Fill(mymuon_energy, genweight); //h_lepton_nbjets_reco_S2->Fill(nbjets); if( nbjets >= 2 ){ // h_muon_energy_reco_final->Fill(mymuon_energy, genweight); h_lepton_energy_reco_final->Fill(mymuon_energy, genweight); h2_lepton_energy_final_response->Fill(mymuon_energy, genmuon->E, genweight); } //lepton_E_final.push_back( mymuon->P4().E() ); //for(int i=0; i < nmass; i++){ // float corr = 1.0/ h_acc->Interpolate( mymuon->P4().E() ); // float w = g2[i]->Eval( mymuon->P4().E() ); //integral2[i] = integral2[i] + w*corr ; //} //Muon_E = mymuon_energy; //Lepton_E_reco = mymuon_energy; } /* for(int i=0; i < nmass; i++){ //for(int i=0; i < 0; i++){ float lenergy = -9; if( Muon_E > 0 && Electron_E < 0 ) lenergy = Muon_E; if( Muon_E < 0 && Electron_E > 0 ) lenergy = Electron_E; float acc = h_acc->Interpolate( lenergy ); integral2[i] = integral2[i] + g2[i]->Eval( lenergy ) /acc ; integral3[i] = integral3[i] + g3[i]->Eval( lenergy ) /acc ; integral5[i] = integral5[i] + g5[i]->Eval( lenergy ) /acc ; integral15[i] = integral15[i] + g15[i]->Eval( lenergy ) /acc ; } */ //if( passmuon && passelectron) cout << "Lepton E = " << Lepton_E << endl; //tree->Fill(); } //tree->Print(); // for(int m=0; m < nmass; m++){ // for(int i=0; i < 400;i++){ // float bincenter = h_lepton_energy->GetBinCenter(i+1); // float binconten = h_lepton_energy->GetBinContent(i+1); // float weight_value = g2[m]->Eval( bincenter ); // integral2[m] = integral2[m] + weight_value*binconten; // } // } /* for(int m=0; m < nmass; m++){ for(int i=0; i < lepton_E_final.size() ;i++){ float energy = lepton_E_final[i]; float corr = 1.0/ h_acc->Interpolate( energy ); float weight_value2 = g2[m]->Eval( bincenter ); float weight_value3 = g3[m]->Eval( bincenter ); float weight_value5 = g5[m]->Eval( bincenter ); float weight_value15 = g15[m]->Eval( bincenter ); integral2[m] = integral2[m] + weight_value2*corr; integral3[m] = integral3[m] + weight_value3*corr; integral5[m] = integral5[m] + weight_value5*corr; integral15[m] = integral15[m] + weight_value15*corr; } } TGraph * final2 = new TGraph(); TGraph * final3 = new TGraph(); TGraph * final5 = new TGraph(); TGraph * final15 = new TGraph(); for (Int_t i=0;i<nmass;i++) { final2->SetPoint(i, mymass[i], integral2[i]); final3->SetPoint(i, mymass[i], integral3[i]); final5->SetPoint(i, mymass[i], integral5[i]); final15->SetPoint(i, mymass[i], integral15[i]); } final2->SetName("n2"); final3->SetName("n3"); final5->SetName("n5"); final15->SetName("n15"); final2->Write(); final3->Write(); final5->Write(); final15->Write(); */ if( remaining != 0 ) cout << "Someting is wrong" << endl; //TCanvas * c = new TCanvas("c","c",1000,600); channel->SetBinContent(1,ndileptonic); channel->SetBinContent(2,ndileptonic2); channel->SetBinContent(3,ndileptonic3); channel->SetBinContent(4,nsemileptonic); channel->SetBinContent(5,nsemileptonic2); channel->SetBinContent(6,nsemileptonic3); channel->SetBinContent(7,nhadronic); channel->GetXaxis()->SetBinLabel(1,"Dileptonic"); channel->GetXaxis()->SetBinLabel(2,"DileptonicTau"); channel->GetXaxis()->SetBinLabel(3,"DileptonicNoTau"); channel->GetXaxis()->SetBinLabel(4,"Semileptonic"); channel->GetXaxis()->SetBinLabel(5,"SemileptonicTau"); channel->GetXaxis()->SetBinLabel(6,"SemileptonicNoTau"); channel->GetXaxis()->SetBinLabel(7,"Hadronic"); //int nBins = 400; //h_lepton_energy->AddBinContent(nBins, h_lepton_energy->GetBinContent(nBins+1)); //h_lepton_energy_reco_final->AddBinContent(nBins, h_lepton_energy_reco_final->GetBinContent(nBins+1)); // Show resulting histograms channel->SetStats(0000); double scale = 1.0/numberOfEntries; channel->Scale( scale ); //channel->Draw("HText0"); /* channel->Write(); h_muon_energy->Write(); h_electron_energy->Write(); h_lepton_energy->Write(); h_muon_energy_acc->Write(); h_electron_energy_acc->Write(); h_lepton_energy_acc->Write(); h_muon_energy_reco->Write(); h_electron_energy_reco->Write(); h_lepton_energy_reco->Write(); h_muon_energy_reco_final->Write(); h_electron_energy_reco_final->Write(); h_lepton_energy_reco_final->Write(); */ f->Write(); f->Close(); }
// --------------------------------------------------------------------------------------------- // returns scaling (change in normalization, in log 10) or -666 if failed // optional parameter accepts the desired unit prefix (in log 10) int adjustUnits( TH1& h1, int forceNewPrefix = -666) { if( h1.GetDimension() != 1) {cerr<<"ERROR! 'adjustUnits' works only for 1D histograms!"<<endl; return -666;} bool forced = forceNewPrefix != -666; TString ss( h1.GetYaxis()->GetTitle() ); ss.ReplaceAll ("_{T}", "_%@#"); // otherwise it messes up the reg. exp. // all backslashes are doubled, to get by the compiler string parsing, leaving \[ for TRegexp --> literal [s & ]s int iOpenBracket = ss.Index (TRegexp ("\\[[^\\]]*\\][^\\[\\]]*$"));// That is, the start of the last square brackets int iCloseBracket = ss.Last(']'); // no need for quotes with char if( iOpenBracket < 0 || iCloseBracket <= iOpenBracket ) { // can't find units return -666; } Double_t oldMax = h1.GetMaximum(); h1.SetMaximum(); // unsets Double_t max = h1.GetMaximum(); Double_t max10 = TMath::Log10( max ); if( -3 < max10 && max10 < 3 && ! forced ) return 0; // no rescaling needed // parse input units TString inputUnits = ss( 1+iOpenBracket, -1 + iCloseBracket - iOpenBracket); int curPrefix = 0, prefixLength = 0; if( inputUnits.BeginsWith( "m" ) ) {curPrefix = -3; prefixLength = 1;} if( inputUnits.BeginsWith( "#mu" ) ) {curPrefix = -6; prefixLength = 3;} if( inputUnits.BeginsWith( "n" ) ) {curPrefix = -9; prefixLength = 1;} if( inputUnits.BeginsWith( "p" ) ) {curPrefix = -12; prefixLength = 1;} if( inputUnits.BeginsWith( "f" ) ) {curPrefix = -15; prefixLength = 1;} if( inputUnits.BeginsWith( "k" ) ) {curPrefix = 3; prefixLength = 1;} // add more as needed.... TString baseUnit( inputUnits( prefixLength, inputUnits.Length() - prefixLength ) ); // find target units int iNewPrefix = 3 * TMath::Floor( 0.5 + (curPrefix + max10)/3. ); if( forced ) iNewPrefix = forceNewPrefix; // prepare new units and scaling TString sNewPrefix; int scale10 = 1; if( iNewPrefix > 3 ) {cerr<<"adjustUnits - NYI for >kilo"<<endl;} if( iNewPrefix >= 3 ) {sNewPrefix = "k"; scale10 = curPrefix - 3;} if( -15 < iNewPrefix && iNewPrefix < 3 ) scale10 = curPrefix- iNewPrefix; if( iNewPrefix == 0 ) sNewPrefix = ""; if( iNewPrefix == -3 ) sNewPrefix = "m"; if( iNewPrefix == -6 ) sNewPrefix = "#mu"; if( iNewPrefix == -9 ) sNewPrefix = "n"; if( iNewPrefix == -12 ) sNewPrefix = "p"; if( iNewPrefix < -15 ) {cerr<<"adjustUnits - NYI for <femto"<<endl;} if( iNewPrefix <= -15 ) {sNewPrefix = "f"; scale10 = curPrefix + 15;} // sanity checks if( forced && forceNewPrefix != 0 && sNewPrefix == "" ) { cerr<<"adjustUnits - illegal new prefix forced!"<<endl; return -666; } if( scale10 == 0 && ! forced ) {cerr<<"Bug in adjustUnits? scale10 == 0 .... "<<endl; return -666;} // good to go - changing the histogram Double_t scale = TMath::Power( 10, scale10 ); h1.Scale( scale ); h1.SetMaximum( oldMax * scale ); h1.GetYaxis()->SetTitle( ss( 0, iOpenBracket + 1 ) + sNewPrefix + baseUnit + ss( iCloseBracket, ss.Length() - iCloseBracket ) ); return scale10; }
/** * Add the bin histograms to our summary stacks * * @param bin Bin stack * @param i Current off-set in the stacks * @param measured All measured @f$ P(N_{ch})@f$ * @param truth All MC truth @f$ P(N_{ch})@f$ * @param accepted All MC accepted @f$ P(N_{ch})@f$ * @param unfolded All unfolded @f$ P(N_{ch})@f$ * @param corrected All corrected @f$ P(N_{ch})@f$ * @param result The result in this bin */ void Bin2Stack(const THStack* bin, Int_t i, THStack* measured, THStack* truth, THStack* accepted, THStack* unfolded, THStack* corrected, TH1*& result) { Int_t open, closed; Double_t factor; Float_t size; BinAttributes(i, open, closed, size, factor); TIter next(bin->GetHists()); TH1* h = 0; while ((h = static_cast<TH1*>(next()))) { THStack* tmp = 0; Int_t col = h->GetMarkerColor(); Int_t sty = 0; switch (col) { case kColorMeasured: tmp = measured; sty = closed; break; case kColorTruth: tmp = truth; sty = open; break; case kColorAccepted: tmp = accepted; sty = open; break; case kColorUnfolded: tmp = unfolded; sty = closed; break; case kColorCorrected: tmp = corrected; sty = closed; break; default: continue; } // Now clone, and add to the appropriate stack TH1* cln = static_cast<TH1*>(h->Clone(h->GetName())); cln->SetDirectory(0); cln->SetMarkerStyle(sty); cln->SetMarkerSize(size); cln->Scale(factor); // Scale by 10^i if (col == kColorCorrected) result = cln; // Make sure we do not get the old legend TObject* tst = cln->FindObject("legend"); if (tst) cln->GetListOfFunctions()->Remove(tst); tmp->Add(cln, next.GetOption()); } // Add entries to our stacks TString txt = bin->GetTitle(); if (i == 0) txt.Append(" (#times1)"); else if (i == 1) txt.Append(" (#times10)"); else txt.Append(Form(" (#times10^{%d})", i)); THStack* stacks[] = { measured, truth, accepted, unfolded, corrected, 0 }; THStack** pstack = stacks; while (*pstack) { TLegend* leg = StackLegend(*pstack); pstack++; if (!leg) continue; TObject* dummy = 0; TLegendEntry* e = leg->AddEntry(dummy, txt, "p"); e->SetMarkerStyle(closed); e->SetMarkerSize(1.2*size); e->SetMarkerColor(kBlack); e->SetFillColor(0); e->SetFillStyle(0); e->SetLineColor(kBlack); } }
void Fit(TString SIGNAL,TString HISTO,double scaleSGN) { gROOT->ForceStyle(); TFile *fDat = TFile::Open("Histo_flatTree_data_tmva"+SIGNAL+".root"); TFile *fBkg = TFile::Open("Histo_flatTree_qcd_weights_tmva"+SIGNAL+".root"); TFile *fSgn = TFile::Open("Histo_flatTree_"+SIGNAL+"_weights_tmva"+SIGNAL+".root"); TH1 *hDat = (TH1*)fDat->Get(HISTO); TH1 *hBkgRaw = (TH1*)fBkg->Get(HISTO); TH1 *hSgn = (TH1*)fSgn->Get(HISTO); TH1 *hDat_JESlo = (TH1*)fDat->Get(HISTO+"_JESlo"); TH1 *hBkgRaw_JESlo = (TH1*)fBkg->Get(HISTO+"_JESlo"); TH1 *hSgn_JESlo = (TH1*)fSgn->Get(HISTO+"_JESlo"); TH1 *hDat_JESup = (TH1*)fDat->Get(HISTO+"_JESup"); TH1 *hBkgRaw_JESup = (TH1*)fBkg->Get(HISTO+"_JESup"); TH1 *hSgn_JESup = (TH1*)fSgn->Get(HISTO+"_JESup"); TH1F *hBkg = (TH1F*)hBkgRaw->Clone("Bkg"); TH1F *hBkg_JESlo = (TH1F*)hBkgRaw_JESlo->Clone("Bkg_JESlo"); TH1F *hBkg_JESup = (TH1F*)hBkgRaw_JESup->Clone("Bkg_JESup"); hBkg->Smooth(2); hBkg_JESlo->Smooth(2); hBkg_JESup->Smooth(2); hSgn->Smooth(2); hSgn_JESlo->Smooth(2); hSgn_JESup->Smooth(2); double lumi = 4967; hBkg->Scale(lumi); hBkg_JESlo->Scale(lumi); hBkg_JESup->Scale(lumi); double k_factor = hDat->Integral()/hBkg->Integral(); double k_factor_JESlo = hDat->Integral()/hBkg_JESlo->Integral(); double k_factor_JESup = hDat->Integral()/hBkg_JESup->Integral(); hBkg->Scale(k_factor); cout<<"Signal entries = "<<hSgn->GetEntries()<<endl; hSgn->Scale(lumi/scaleSGN); hBkg_JESlo->Scale(k_factor_JESlo); hSgn_JESlo->Scale(lumi/scaleSGN); hBkg_JESup->Scale(k_factor_JESup); hSgn_JESup->Scale(lumi/scaleSGN); hSgn_JESlo->Scale(hSgn->Integral()/hSgn_JESlo->Integral()); hSgn_JESup->Scale(hSgn->Integral()/hSgn_JESup->Integral()); TH1 *hBkg_STATlo = (TH1*)hBkg->Clone(HISTO+"_STATlo"); TH1 *hSgn_STATlo = (TH1*)hSgn->Clone(HISTO+"_STATlo"); TH1 *hBkg_STATup = (TH1*)hBkg->Clone(HISTO+"_STATup"); TH1 *hSgn_STATup = (TH1*)hSgn->Clone(HISTO+"_STATup"); float y1,e1; for(int i=0;i<hBkg->GetNbinsX();i++) { y1 = hBkg->GetBinContent(i+1); e1 = hBkg->GetBinError(i+1); hBkg_STATlo->SetBinContent(i+1,y1-e1); hBkg_STATup->SetBinContent(i+1,y1+e1); y1 = hSgn->GetBinContent(i+1); e1 = hSgn->GetBinError(i+1); hSgn_STATlo->SetBinContent(i+1,y1-e1); hSgn_STATup->SetBinContent(i+1,y1+e1); } hBkg_STATlo->Scale(hBkg->Integral()/hBkg_STATlo->Integral()); hBkg_STATup->Scale(hBkg->Integral()/hBkg_STATup->Integral()); hSgn_STATlo->Scale(hSgn->Integral()/hSgn_STATlo->Integral()); hSgn_STATup->Scale(hSgn->Integral()/hSgn_STATup->Integral()); double xMIN = hBkg->GetBinLowEdge(1); double xMAX = hBkg->GetBinLowEdge(hBkg->GetNbinsX()+1); double xMIN2 = hDat->GetBinLowEdge(hDat->FindFirstBinAbove(0.5)); double xMAX2 = hDat->GetBinLowEdge(hDat->FindLastBinAbove(0.5)+1); RooRealVar x("x","x",xMIN2,xMAX2); RooDataHist data("data","dataset with x",x,hDat); RooDataHist bkg("qcd","bkg with x",x,hBkg); RooDataHist sgn("signal","sgn with x",x,hSgn); RooHistPdf bkgPDF("bkgPDF","bkgPDF",x,bkg,0); RooHistPdf sgnPDF("sgnPDF","sgnPDF",x,sgn,0); RooRealVar f("f","f",0,0.,1.); RooAddPdf model("model","model",RooArgList(sgnPDF,bkgPDF),RooArgList(f)); RooFitResult* r = model.fitTo(data,Save()); r->Print("v"); double N = hDat->Integral(); double B = hBkg->Integral(); double S = hSgn->Integral(); double m = f.getVal(); double e = f.getError(); cout<<"k-factor = "<<k_factor<<endl; cout<<N<<" "<<B<<" "<<S<<endl; cout<<"Total cross section = "<<N/lumi<<" pb"<<endl; cout<<"Model cross section = "<<S/lumi<<" pb"<<endl; cout<<"Fitted signal strength = "<<m*N/S<<endl; cout<<"Fitted signal error = "<<e*N/S<<endl; double p = 0.95; double xup = (N/S)*(m+sqrt(2.)*e*TMath::ErfInverse((1-p)*TMath::Erf(m/e)+p)); cout<<"Bayesian Upper limit = "<<xup<<endl; RooPlot* frame1 = x.frame(); data.plotOn(frame1); model.plotOn(frame1,Components("sgnPDF*"),LineStyle(1),LineWidth(2),LineColor(kGreen+1)); model.plotOn(frame1,Components("bkgPDF*"),LineStyle(1),LineWidth(2),LineColor(kRed)); model.plotOn(frame1,LineStyle(1),LineWidth(2),LineColor(kBlue)); //cout<<frame1->chiSquare()<<endl; RooHist* hresid = frame1->residHist(); RooHist* hpull = frame1->pullHist(); RooPlot* frame2 = x.frame(Title("Residual Distribution")); frame2->addPlotable(hresid,"P") ; // Create a new frame to draw the pull distribution and add the distribution to the frame RooPlot* frame3 = x.frame(Title("Pull Distribution")); frame3->addPlotable(hpull,"P"); TCanvas* cFit = new TCanvas("fitANN_"+SIGNAL,"fitANN_"+SIGNAL,900,600); gPad->SetLogy(); frame1->SetMaximum(1e+4); frame1->SetMinimum(0.5); frame1->GetXaxis()->SetTitle("ANN Output"); frame1->GetYaxis()->SetTitle("Events"); frame1->Draw(); cout<<frame1->nameOf(3)<<endl; TLegend *leg = new TLegend(0.7,0.65,0.9,0.9); leg->SetHeader(SIGNAL); leg->AddEntry(frame1->findObject("h_data"),"data","P"); leg->AddEntry(frame1->findObject("model_Norm[x]"),"QCD+Signal","L"); leg->AddEntry(frame1->findObject("model_Norm[x]_Comp[bkgPDF*]"),"QCD","L"); leg->AddEntry(frame1->findObject("model_Norm[x]_Comp[sgnPDF*]"),"Signal","L"); leg->SetFillColor(0); leg->SetBorderSize(0); leg->SetTextFont(42); leg->SetTextSize(0.04); leg->Draw(); TCanvas* cPull = new TCanvas("pullANN_"+SIGNAL,"pullANN_"+SIGNAL,900,400); frame3->GetXaxis()->SetTitle("ANN Output"); frame3->GetYaxis()->SetTitle("Pull"); frame3->Draw(); cout<<"Creating datacard"<<endl; ofstream datacard; datacard.open("datacard_"+SIGNAL+"_"+HISTO+".txt"); datacard.setf(ios::right); datacard<<"imax 1"<<"\n"; datacard<<"jmax 1"<<"\n"; datacard<<"kmax *"<<"\n"; datacard<<"----------------"<<"\n"; datacard<<"shapes * * "<<SIGNAL+"_"+HISTO+"_input.root $PROCESS $PROCESS_$SYSTEMATIC"<<"\n"; datacard<<"----------------"<<"\n"; datacard<<"bin 1"<<"\n"; datacard<<"observation "<<N<<"\n"; datacard<<"----------------"<<"\n"; datacard<<"bin 1 1"<<"\n"; datacard<<"process signal background "<<"\n"; datacard<<"process 0 1"<<"\n"; datacard<<"rate "<<S<<" "<<B<<"\n"; datacard<<"----------------"<<"\n"; datacard<<"lumi lnN 1.022 1.022"<<"\n"; datacard<<"jes shape 1 1"<<"\n"; datacard<<"mcstat shape 1 1"<<"\n"; datacard<<"jer shape 0 0"<<"\n"; datacard.close(); TFile *out = new TFile(SIGNAL+"_"+HISTO+"_input.root","RECREATE"); out->cd(); hDat->Write("data_obs"); hBkg->Write("background"); hSgn->Write("signal"); hDat_JESlo->Write("data_obs_jesDown"); hBkg_JESlo->Write("background_jesDown"); hBkg_STATlo->Write("background_mcstatDown"); hSgn_STATlo->Write("signal_mcstatDown"); hSgn_JESlo->Write("signal_jesDown"); hDat_JESup->Write("data_obs_jesUp"); hBkg_JESup->Write("background_jesUp"); hBkg_STATup->Write("background_mcstatUp"); hSgn_JESup->Write("signal_jesUp"); hSgn_STATup->Write("signal_mcstatUp"); //----- JER placeholder ---------------- hBkg_JESlo->Write("background_jerDown"); hSgn_JESlo->Write("signal_jerDown"); hBkg_JESup->Write("background_jerUp"); hSgn_JESup->Write("signal_jerUp"); }
void dNdEta_ThreeMethods_FullTrackingRebinned_DividedByMidRapidValue() { //=========Macro generated from canvas: MyCanvas/MyCanvas //========= (Thu Dec 10 11:52:00 2009) by ROOT version5.22/00d gROOT->Reset(); gROOT->ProcessLine(".x rootlogon.C"); gStyle->SetTitleYOffset(1.4); TCanvas *MyCanvas = new TCanvas("MyCanvas", "Final result",1,360,550,600); TH1 *corr_result_all = new TH1D("corr_result_all","",14,-3.5,3.5); corr_result_all->GetXaxis()->SetRange(2,13); // ========================= Cluster Counting ======================= corr_result_all->SetBinContent(4,4.043821); // -2.0 to -1.5 corr_result_all->SetBinContent(5,3.821537); // -1.5 to -1.0 corr_result_all->SetBinContent(6,3.611029); // -1.0 to -0.5 corr_result_all->SetBinContent(7,3.501129); // -0.5 to 0.0 corr_result_all->SetBinContent(8,3.51732); corr_result_all->SetBinContent(9,3.632249); corr_result_all->SetBinContent(10,3.747706); corr_result_all->SetBinContent(11,4.01596); corr_result_all->SetBinError(4,0.177928124); corr_result_all->SetBinError(5,0.168147628); corr_result_all->SetBinError(6,0.158885276); corr_result_all->SetBinError(7,0.154049676); corr_result_all->SetBinError(8,0.15476208); corr_result_all->SetBinError(9,0.159818956); corr_result_all->SetBinError(10,0.164899064); corr_result_all->SetBinError(11,0.17670224); /* corr_result_all->SetBinContent(4,3.954); // -2.0 to -1.5 corr_result_all->SetBinContent(5,3.770); // -1.5 to -1.0 corr_result_all->SetBinContent(6,3.607); // -1.0 to -0.5 corr_result_all->SetBinContent(7,3.548); // -0.5 to 0.0 corr_result_all->SetBinContent(8,3.567); corr_result_all->SetBinContent(9,3.681); corr_result_all->SetBinContent(10,3.791); corr_result_all->SetBinContent(11,4.025); corr_result_all->SetBinError(4,0.1779); corr_result_all->SetBinError(5,0.1697); corr_result_all->SetBinError(6,0.1623); corr_result_all->SetBinError(7,0.1597); corr_result_all->SetBinError(8,0.1605); corr_result_all->SetBinError(9,0.1657); corr_result_all->SetBinError(10,0.1706); corr_result_all->SetBinError(11,0.1811); */ corr_result_all->SetMarkerStyle(20); //corr_result_all->SetMarkerSize(1.5); // use rootlogon size corr_result_all->SetMarkerColor(kRed); corr_result_all->SetLineColor(2); corr_result_all->GetYaxis()->SetTitle("dN_{ch}/d#eta/dN_{ch,mid}/d#eta"); corr_result_all->GetXaxis()->SetTitle("#eta"); corr_result_all->GetXaxis()->CenterTitle(); corr_result_all->GetYaxis()->CenterTitle(); corr_result_all->GetXaxis()->SetNdivisions(405); //corr_result_all->GetYaxis()->SetNdivisions(1005); corr_result_all->GetYaxis()->SetNdivisions(506); Float_t midrapid = 0.5*(corr_result_all->GetBinContent(7)+corr_result_all->GetBinContent(8)); cout<<"mid rapid value = "<<midrapid<<endl; corr_result_all->Scale(1/midrapid); corr_result_all->SetMinimum(0.95); corr_result_all->SetMaximum(1.3); corr_result_all->Draw("pz"); // ======= YJ Tracklet three layer combination averaged (updated with dead modules..) ====== // 1 2 3 4 5 6 7 8 9 10 11 12 Double_t xAxis5[13] = {-3, -2.5, -2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2, 2.5, 3}; TH1 *hMeasuredFinal = new TH1D("hMeasuredFinal","",12, xAxis5); hMeasuredFinal->SetBinContent(3,3.7459); hMeasuredFinal->SetBinContent(4,3.65462); hMeasuredFinal->SetBinContent(5,3.55475); hMeasuredFinal->SetBinContent(6,3.45008); hMeasuredFinal->SetBinContent(7,3.44329); hMeasuredFinal->SetBinContent(8,3.5244); hMeasuredFinal->SetBinContent(9,3.59575); hMeasuredFinal->SetBinContent(10,3.6612); hMeasuredFinal->SetBinError(3,0.142344); hMeasuredFinal->SetBinError(4,0.138876); hMeasuredFinal->SetBinError(5,0.13508); hMeasuredFinal->SetBinError(6,0.131103); hMeasuredFinal->SetBinError(7,0.130845); hMeasuredFinal->SetBinError(8,0.133927); hMeasuredFinal->SetBinError(9,0.136638); hMeasuredFinal->SetBinError(10,0.139126); hMeasuredFinal->SetMarkerColor(kBlue); hMeasuredFinal->SetLineColor(4); hMeasuredFinal->SetMarkerStyle(21); //hMeasuredFinal->SetMarkerSize(1.5); // use rootlogon size midrapid = 0.5*(hMeasuredFinal->GetBinContent(6)+hMeasuredFinal->GetBinContent(7)); cout<<"mid rapid value = "<<midrapid<<endl; hMeasuredFinal->Scale(1/midrapid); hMeasuredFinal->Draw("pzsame"); /// ==================================================== Ferenc's dN/dEta (rebinned) Double_t xAxis6[13] = {-3, -2.5, -2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2, 2.5, 3}; TH1 *hMeasuredFinal2 = new TH1D("hMeasuredFinal2","",12, xAxis6); // Hight Stat hMeasuredFinal2->SetBinContent(2,3.65413); hMeasuredFinal2->SetBinContent(3,3.68883); hMeasuredFinal2->SetBinContent(4,3.73805); hMeasuredFinal2->SetBinContent(5,3.62817); hMeasuredFinal2->SetBinContent(6,3.52704); hMeasuredFinal2->SetBinContent(7,3.47443); hMeasuredFinal2->SetBinContent(8,3.63319); hMeasuredFinal2->SetBinContent(9,3.7577); hMeasuredFinal2->SetBinContent(10,3.67975); hMeasuredFinal2->SetBinContent(11,3.65413); // Systematic error of 3.1% --> to 2.4% hMeasuredFinal2->SetBinError(2,0.08769912); hMeasuredFinal2->SetBinError(3,0.08853192); hMeasuredFinal2->SetBinError(4,0.0897132); hMeasuredFinal2->SetBinError(5,0.08707608); hMeasuredFinal2->SetBinError(6,0.08464896); hMeasuredFinal2->SetBinError(7,0.08338632); hMeasuredFinal2->SetBinError(8,0.08719656); hMeasuredFinal2->SetBinError(9,0.0901848); hMeasuredFinal2->SetBinError(10,0.088314); hMeasuredFinal2->SetBinError(11,0.08769912); /* // Systematic error of 3.1% --> to 2.3% hMeasuredFinal2->SetBinError(2,0.084045); hMeasuredFinal2->SetBinError(3,0.0848431); hMeasuredFinal2->SetBinError(4,0.0859752); hMeasuredFinal2->SetBinError(5,0.0834479); hMeasuredFinal2->SetBinError(6,0.0811219); hMeasuredFinal2->SetBinError(7,0.0799119); hMeasuredFinal2->SetBinError(8,0.0835634); hMeasuredFinal2->SetBinError(9,0.0864271); hMeasuredFinal2->SetBinError(10,0.0846342); hMeasuredFinal2->SetBinError(11,0.084045); */ hMeasuredFinal2->SetMarkerColor(kBlack); hMeasuredFinal2->SetLineColor(1); hMeasuredFinal2->SetMarkerStyle(22); //hMeasuredFinal2->SetMarkerSize(1.5); use root logon size midrapid = 0.5*(hMeasuredFinal2->GetBinContent(6)+hMeasuredFinal2->GetBinContent(7)); cout<<"mid rapid value = "<<midrapid<<endl; hMeasuredFinal2->Scale(1/midrapid); hMeasuredFinal2->Draw("pzsame"); // ================== 2.36 TeV // ========================= Cluster Counting ======================= TH1 *corr_result_all236 = new TH1D("corr_result_all236","",14,-3.5,3.5); corr_result_all236->GetXaxis()->SetRange(2,13); corr_result_all236->SetBinContent(4,5.203552); corr_result_all236->SetBinContent(5,4.913457); corr_result_all236->SetBinContent(6,4.710017); corr_result_all236->SetBinContent(7,4.44485); corr_result_all236->SetBinContent(8,4.448675); corr_result_all236->SetBinContent(9,4.659581); corr_result_all236->SetBinContent(10,4.856712); corr_result_all236->SetBinContent(11,5.065867); corr_result_all236->SetBinError(4,0.23416); corr_result_all236->SetBinError(5,0.221106); corr_result_all236->SetBinError(6,0.211951); corr_result_all236->SetBinError(7,0.200018); corr_result_all236->SetBinError(8,0.20019); corr_result_all236->SetBinError(9,0.209681); corr_result_all236->SetBinError(10,0.218552); corr_result_all236->SetBinError(11,0.227964); corr_result_all236->SetMarkerColor(kRed); corr_result_all236->SetLineColor(2); corr_result_all236->SetMarkerStyle(24); midrapid = 0.5*(corr_result_all236->GetBinContent(7)+corr_result_all236->GetBinContent(8)); cout<<"mid rapid value = "<<midrapid<<endl; corr_result_all236->Scale(1./midrapid); corr_result_all236->Draw("pzsame"); /// ==================================================== Yenjie 2.36 TeV // 1 2 3 4 5 6 7 8 9 10 11 12 TH1 *hTracklet236 = new TH1D("hTracklet236","",12, xAxis5); hTracklet236->SetBinContent(3,4.73663); hTracklet236->SetBinContent(4,4.69978); hTracklet236->SetBinContent(5,4.61061); hTracklet236->SetBinContent(6,4.40814); hTracklet236->SetBinContent(7,4.38437); hTracklet236->SetBinContent(8,4.51905); hTracklet236->SetBinContent(9,4.6502); hTracklet236->SetBinContent(10,4.80977); // 4.8 % Systematic Error hTracklet236->SetBinError(3,0.179992); hTracklet236->SetBinError(4,0.178592); hTracklet236->SetBinError(5,0.175203); hTracklet236->SetBinError(6,0.167509); hTracklet236->SetBinError(7,0.166606); hTracklet236->SetBinError(8,0.171724); hTracklet236->SetBinError(9,0.176707); hTracklet236->SetBinError(10,0.182771); hTracklet236->SetMarkerColor(4); hTracklet236->SetLineColor(4); hTracklet236->SetMarkerStyle(kOpenSquare); //hTracklet236->SetMarkerSize(1.5); // use rootlogon size midrapid = 0.5*(hTracklet236->GetBinContent(6)+hTracklet236->GetBinContent(7)); cout<<"mid rapid value = "<<midrapid<<endl; hTracklet236->Scale(1./midrapid); hTracklet236->Draw("pzsame"); /// ==================================================== Ferenc's dN/dEta (rebinned) Double_t xAxis7[13] = {-3, -2.5, -2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2, 2.5, 3}; TH1 *hMeasuredFinal2236 = new TH1D("hMeasuredFinal2","",12, xAxis7); hMeasuredFinal2236->SetBinContent(2,4.9689); hMeasuredFinal2236->SetBinContent(3,4.93581); hMeasuredFinal2236->SetBinContent(4,4.67197); hMeasuredFinal2236->SetBinContent(5,4.70044); hMeasuredFinal2236->SetBinContent(6,4.52142); hMeasuredFinal2236->SetBinContent(7,4.55674); hMeasuredFinal2236->SetBinContent(8,4.61255); hMeasuredFinal2236->SetBinContent(9,4.67611); hMeasuredFinal2236->SetBinContent(10,4.87402); hMeasuredFinal2236->SetBinContent(11,4.96891); // Systematic error of 3.1% --> 2.3% hMeasuredFinal2236->SetBinError(2,0.114285); hMeasuredFinal2236->SetBinError(3,0.113524); hMeasuredFinal2236->SetBinError(4,0.107455); hMeasuredFinal2236->SetBinError(5,0.10811); hMeasuredFinal2236->SetBinError(6,0.103993); hMeasuredFinal2236->SetBinError(7,0.104805); hMeasuredFinal2236->SetBinError(8,0.106089); hMeasuredFinal2236->SetBinError(9,0.107551); hMeasuredFinal2236->SetBinError(10,0.112102); hMeasuredFinal2236->SetBinError(11,0.114285); hMeasuredFinal2236->SetMarkerColor(kBlack); hMeasuredFinal2236->SetLineColor(1); hMeasuredFinal2236->SetMarkerStyle(26); //hMeasuredFinal2->SetMarkerSize(1.5); use root logon size midrapid = 0.5*(hMeasuredFinal2236->GetBinContent(6)+hMeasuredFinal2236->GetBinContent(7)); cout<<"mid rapid value = "<<midrapid<<endl; hMeasuredFinal2236->Scale(1./midrapid); //hMeasuredFinal2236->Scale(1/4.53908); hMeasuredFinal2236->Draw("pzsame"); /// ==================================================== UA5 Data TH1F* hEta_UA5_NSD = new TH1F("hEta_UA5_NSD",";#eta;dN/d#eta",50,-3,3); // positive eta hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(0.125),3.48); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(0.375),3.38); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(0.625),3.52); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(0.875),3.68); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(1.125),3.71); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(1.375),3.86); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(1.625),3.76); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(1.875),3.66); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(2.125),3.72); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(2.375),3.69); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(2.625),3.56); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(2.875),3.41); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(3.125),3.15); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(0.125),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(0.375),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(0.625),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(0.875),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(1.125),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(1.375),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(1.625),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(1.875),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(2.125),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(2.375),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(2.625),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(2.875),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(3.125),0.07); //negative eta hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(-0.125),3.48); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(-0.375),3.38); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(-0.625),3.52); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(-0.875),3.68); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(-1.125),3.71); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(-1.375),3.86); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(-1.625),3.76); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(-1.875),3.66); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(-2.125),3.72); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(-2.375),3.69); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(-2.625),3.56); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(-2.875),3.41); hEta_UA5_NSD->SetBinContent(hEta_UA5_NSD->FindBin(-3.125),3.15); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(-0.125),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(-0.375),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(-0.625),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(-0.875),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(-1.125),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(-1.375),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(-1.625),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(-1.875),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(-2.125),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(-2.375),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(-2.625),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(-2.875),0.07); hEta_UA5_NSD->SetBinError(hEta_UA5_NSD->FindBin(-3.125),0.07); hEta_UA5_NSD->SetMarkerStyle(25); hEta_UA5_NSD->SetMarkerSize(1.0); //hEta_UA5_NSD->Draw("psame"); //TLegend *leg = new TLegend(0.20,0.27,0.53,0.47,NULL,"brNDC"); //TLegend *leg = new TLegend(0.20,0.35,0.53,0.47,NULL,"brNDC"); Float_t ywidth = 0.045*4; //TLegend *leg = new TLegend(0.27,0.26,0.70,0.26+ywidth,NULL,"brNDC"); //TLegend *leg = new TLegend(0.39,0.21,0.82,0.21+ywidth,NULL,"brNDC"); TLegend *leg = new TLegend(0.45,0.753,0.892,0.93,NULL,"brNDC"); //leg->SetNColumns(2); leg->SetBorderSize(0); leg->SetMargin(0.5); leg->SetTextFont(62); leg->SetLineColor(1); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetTextSize(0.03); leg->SetHeader(" 2.36 TeV"); leg->AddEntry(corr_result_all236,"Hit counting","P"); leg->AddEntry(hTracklet236,"Tracklet","P"); leg->AddEntry(hMeasuredFinal2236,"Global tracking","P"); //cout<<"Number of column "<<leg->GetNColumns()<<endl; /* leg->AddEntry(corr_result_all236,"","P"); leg->AddEntry(hTracklet236,"","P"); leg->AddEntry(hMeasuredFinal2236,"","P"); */ //TLegend *leg2 = new TLegend(0.20,0.22,0.53,0.35,NULL,"brNDC"); //TLegend *leg2 = new TLegend(0.50,0.26,0.93,0.47,NULL,"brNDC"); //TLegend *leg2 = new TLegend(0.39,0.26,0.82,0.26+ywidth,NULL,"brNDC"); //TLegend *leg2 = new TLegend(0.27,0.21,0.70,0.21+ywidth,NULL,"brNDC"); TLegend *leg2 = new TLegend(0.35,0.75,0.782,0.932,NULL,"brNDC"); leg2->SetMargin(0.37); leg2->SetBorderSize(0); leg2->SetTextFont(62); leg2->SetLineColor(1); leg2->SetLineStyle(1); leg2->SetLineWidth(1); leg2->SetFillColor(0); //leg2->SetFillStyle(1001); leg2->SetFillStyle(0); leg2->SetTextSize(0.03); leg2->SetHeader(" 0.9 TeV"); leg2->AddEntry(corr_result_all,"","P"); leg2->AddEntry(hMeasuredFinal,"","P"); leg2->AddEntry(hMeasuredFinal2,"","P"); leg->Draw(); leg2->Draw(); printFinalCanvases(MyCanvas,"dNdeta_ThreeMethods_Divided",0,2); }
//______________________________________________________________________________ void PIDEnergy() { // Main method. Char_t tmp[256]; // load CaLib gSystem->Load("libCaLib.so"); // general configuration const Char_t* data = "Data.PID.E0"; const Char_t* hName = "CaLib_PID_Energy_Proton_PID_Energy"; // configuration (December 2007) //const Char_t calibration[] = "LD2_Dec_07"; //const Char_t filePat[] = "/usr/puma_scratch0/werthm/A2/Dec_07/AR/out/ARHistograms_CB_RUN.root"; //const Char_t mcFile[] = "/usr/panther_scratch0/werthm/A2/Dec_07/MC/calibration/all.root"; // configuration (February 2009) //const Char_t calibration[] = "LD2_Feb_09"; //const Char_t filePat[] = "/usr/puma_scratch0/werthm/A2/Feb_09/AR/out/ARHistograms_CB_RUN.root"; //const Char_t mcFile[] = "/usr/panther_scratch0/werthm/A2/Feb_09/MC/calibration/all.root"; // configuration (May 2009) const Char_t calibration[] = "LD2_May_09"; const Char_t filePat[] = "/usr/puma_scratch0/werthm/A2/May_09/AR/out/ARHistograms_CB_RUN.root"; const Char_t mcFile[] = "/usr/panther_scratch0/werthm/A2/May_09/MC/calibration/all.root"; // get number of sets Int_t nSets = TCMySQLManager::GetManager()->GetNsets(data, calibration); // create canvas Int_t n = TMath::Sqrt(nSets); TCanvas* cOverview = new TCanvas("c", "c", 1200, 900); cOverview->Divide(n, nSets / n + 1); // create arrays Double_t* pos = new Double_t[nSets+1]; Double_t* fwhm = new Double_t[nSets+1]; // total sum histogram TH1* hTot = 0; // load MC histo TFile* fMC = new TFile(mcFile); TH2* hMC2 = (TH2*) fMC->Get(hName); TH1* hMC = hMC2->ProjectionX("mc"); hMC->SetLineColor(kBlue); // loop over sets for (Int_t i = 0; i < nSets; i++) { // create file manager TCFileManager m(data, calibration, 1, &i, filePat); // get histo TH2* h2 = (TH2*) m.GetHistogram(hName); // skip empty histo if (!h2) continue; // project histo sprintf(tmp, "Proj_%d", i); TH1* h = (TH1*) h2->ProjectionX(tmp); //TH1* h = (TH1*) h2->ProjectionX(tmp, 9, 9); //h->Rebin(4); // add to total histogram if (!hTot) hTot = (TH1*) h->Clone(); else hTot->Add(h); // fit histo cOverview->cd(i+1); h->SetLineColor(kBlack); h->Draw(); hMC->Scale(h->GetMaximum()/hMC->GetMaximum()); hMC->DrawCopy("same"); } }
// Histograms will be scaled by x-section, Nevents, Luminosity, // filter-efficiency if InputType is supplied // TH1 *get(const string &path, TFile *input, const InputType &input_type = UNKNOWN) { TObject *object = input->Get(path.c_str()); if (!object) { cerr << "failed to get: " << path << endl; return 0; } TH1 *hist = dynamic_cast<TH1 *>(object->Clone()); if (!hist) { cerr << "object does not seem to be TH1" << endl; return 0; } switch(input_type) { case QCD_BC_PT20_30: { hist->Scale(2.361e8 * luminosity * 5.9e-4 / 2071515); break; } case QCD_BC_PT30_80: { hist->Scale(5.944e7 * luminosity * 2.42e-3 / 2009881); break; } case QCD_BC_PT80_170: { hist->Scale(8.982e5 * luminosity * 1.05e-2 / 1071954); break; } case QCD_EM_PT20_30: { hist->Scale(2.361e8 * luminosity * 1.06e-2 / 35577687); break; } case QCD_EM_PT30_80: { hist->Scale(5.944e7 * luminosity * 6.1e-2 / 55173330); break; } case QCD_EM_PT80_170: { hist->Scale(8.982e5 * luminosity * 1.59e-1 / 7852884); break; } case TTJETS: { // Use NLO x-section: 157.5 instead of LO: 94.76 // hist->Scale(157.5 * luminosity * 1.0 / 2748612); break; } case ZJETS: { // Use NLO x-section: 3048 instead of LO: 2475 // hist->Scale(3048 * luminosity * 1.0 / 29414670); break; } case WJETS: { // Use NLO x-section: 31314 instead of LO: 27770 // hist->Scale(31314 * luminosity * 1.0 / 39705660); break; } case RERECO: // Fall through case PROMPT: // Do nothing break; default: { cerr << "unknown type: can not scale the plot" << endl; break; } } if (UNKNOWN != input_type) style(hist, input_type); return hist; }
void QAtracklets(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("etaphiTracklets"); TH1 *pdtin = (TH1 *)hdtin->ProjectionY("pdtin_tracklets"); pdtin->SetMarkerStyle(20); pdtin->SetMarkerSize(1.); pdtin->SetMarkerColor(kAzure-3); hdtin->Scale(1. / hdtin->GetEntries()); pdtin->Scale(1. / hdtin->GetEntries()); TFile *fmcin = TFile::Open(fmc); TList *lmcin = (TList *)fmcin->Get("clist"); if(!lmcin) { std::cout << "NOLIST" << std::endl; } lmcin->ls(); TH2 *hmcin = (TH2 *)lmcin->FindObject("etaphiTracklets"); if(!hmcin) { std::cout << "NO H!! etaphiTracklets" << std::endl; } TH1 *pmcin = (TH1 *)hmcin->ProjectionY("pmcin_tracklets"); pmcin->SetLineColor(kRed+1); pmcin->SetFillStyle(1001); pmcin->SetFillColorAlpha(kRed+1, 0.1); hmcin->Scale(1. / hmcin->GetEntries()); pmcin->Scale(1. / hmcin->GetEntries()); /* pdtin->Scale(pmcin->Integral(pmcin->FindBin(0. + 0.001), pmcin->FindBin(1. - 0.001)) / pdtin->Integral(pdtin->FindBin(0. + 0.001), pdtin->FindBin(1. - 0.001))); */ TCanvas *cData = new TCanvas("cTrackletData", "cTrackletData", 800, 800); // cData->SetLogz(); TH1 * hfr = cData->DrawFrame(-2.5, 0., 2.5, 2. * TMath::Pi()); hfr->SetTitle(";#eta;#varphi"); hdtin->Draw("same,col"); cData->SaveAs(canvasPrefix+"trackletData.pdf"); TCanvas *cMC = new TCanvas("cTrackletMC", "cTrackletMC", 800, 800); // cMC->SetLogz(); hfr = cMC->DrawFrame(-2.5, 0., 2.5, 2. * TMath::Pi()); hfr->SetTitle(";#eta;#varphi"); hmcin->Draw("same,col"); cMC->SaveAs(canvasPrefix+"trackletMC.pdf"); TCanvas *cPhi = new TCanvas("cTrackletPhi", "cTrackletPhi", 800, 800); // cPhi->SetLogy(); hfr = cPhi->DrawFrame(0., 0., 2. * TMath::Pi(), 0.01); hfr->SetTitle(";#varphi;"); pdtin->DrawCopy("same"); pmcin->DrawCopy("same,histo"); TLegend *legend = new TLegend(0.20, 0.18+0.63, 0.50, 0.30+0.63); legend->SetFillColor(0); legend->SetBorderSize(0); legend->SetTextFont(42); legend->SetTextSize(0.04); legend->AddEntry(pdtin, "data", "pl"); legend->AddEntry(pmcin, "Monte Carlo", "l"); legend->Draw("same"); cPhi->SaveAs(canvasPrefix+"trackletPhi.pdf"); TCanvas *cPhir = new TCanvas("cTrackletPhir", "cTrackletPhir", 800, 800); // cPhi->SetLogy(); hfr = cPhir->DrawFrame(0., 0.5, 2. * TMath::Pi(), 1.5); hfr->SetTitle(";#varphi;data / Monte Carlo"); pdtin->Divide(pmcin); pdtin->Draw("same"); cPhir->SaveAs(canvasPrefix+"trackletPhir.pdf"); }
void patBJetVertex_efficiencies() { // define proper canvas style setNiceStyle(); gStyle->SetOptStat(0); // open file TFile* file = new TFile("analyzePatBJetVertex.root"); unsigned int j = 0; for(const char **algo = algos; *algo; algo++, j++) { TLegend *legend[3] = { 0, 0, 0 }; // draw canvas with efficiencies TCanvas *canv; canv = new TCanvas(*algo, Form("%s efficiencies", algoNames[j]), 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/%s_%s", directory, *algo, *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.3, 0.4, 0.58, 0.58); 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(); } }
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; }
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 makeSystPlot( TFile * f, TString oldFolder, RooWorkspace *WS, string channel, string syst, int toMassNo, int fromMassNo) //massNo 0-51, see xSec7TeV.h { RooArgList * hobs = new RooArgList("hobs"); RooRealVar BDT("CMS_vhbb_BDT_Zll", "CMS_vhbb_BDT_Zll", -1, 1);///OLD VARIABLE NAME HERE hobs->add(*WS->var("CMS_vhbb_BDT_Zll")); ///NEW VARIABLE NAME HERE RooWorkspace *tempWS = (RooWorkspace*) f->Get(oldFolder.Data()); TString systT(syst); TString chanT(channel); bool writeIt = 1; if(chanT.Contains("QCD") || chanT.Contains("Wj")) if(!(systT.Contains("stat"))) writeIt = 0; if((kount < 3) && (channel=="data_obs")) { kount++; std::string namen = channel; std::cout << "reading WS "<< oldFolder.Data() << std::endl; std::cout << namen << std::endl; RooDataHist* tempRooDataHistNom = (RooDataHist*) tempWS->data(namen.c_str()); TH1 *tempHistNom = tempRooDataHistNom->createHistogram(namen.c_str(),BDT,Binning(bins)); std::cout << namen << std::endl; RooDataHist *DHnom = new RooDataHist(channel.c_str(),"",*hobs,tempHistNom); WS->import(*(new RooHistPdf(channel.c_str(),"",*hobs,*DHnom))); } if (channel!="data_obs") { std::string nameUp; std::string namen; std::string nameDown; if((syst == "stat")) { if(IFILE.Contains("7TeV")) { nameUp = channel + "CMS_vhbb_stats_" + channel + "_" + oldFolder.Data() + "Up"; namen = channel; nameDown = channel + "CMS_vhbb_stats_" + channel + "_" + oldFolder.Data() + "Down"; } if(IFILE.Contains("8TeV")) { nameUp = channel + "CMS_vhbb_stats_" + channel + "_" + oldFolder.Data() + "Up"; namen = channel; nameDown = channel + "CMS_vhbb_stats_" + channel + "_" + oldFolder.Data() + "Down"; } } else { nameUp = channel + "CMS_" + syst + "Up"; namen = channel; nameDown = channel + "CMS_" + syst + "Down"; } if((syst == "ZJModel")) { if(IFILE.Contains("7TeV")) { nameUp = channel + "CMS_vhbb_ZJModel_" + oldFolder.Data() + "_7TeVUp"; namen = channel; nameDown = channel + "CMS_vhbb_ZJModel_" + oldFolder.Data() + "_7TeVDown"; } if(IFILE.Contains("8TeV")) { nameUp = channel + "CMS_vhbb_ZJModel_" + oldFolder.Data() + "_8TeVUp"; namen = channel; nameDown = channel + "CMS_vhbb_ZJModel_" + oldFolder.Data() + "_8TeVDown"; } } if(writeIt) { RooDataHist* tempRooDataHistUp = (RooDataHist*) tempWS->data(nameUp.c_str()); RooDataHist* tempRooDataHistDown = (RooDataHist*) tempWS->data(nameDown.c_str()); RooDataHist* tempRooDataHistNom = (RooDataHist*) tempWS->data(namen.c_str()); std::cout << oldFolder.Data() << std::endl; std::cout << nameUp.c_str() << std::endl; TH1 *tempHistUp = tempRooDataHistUp->createHistogram(nameUp.c_str(),BDT,Binning(bins)); TH1 *tempHistDown = tempRooDataHistDown->createHistogram(nameDown.c_str(),BDT,Binning(bins)); std::cout << namen.c_str() << std::endl; TH1 *tempHistNom = tempRooDataHistNom->createHistogram(namen.c_str(),BDT,Binning(bins)); if(chanT.Contains("VH") && IFILE.Contains("7TeV")) { tempHistUp->Scale(xSec7ZH[toMassNo]/xSec7ZH[fromMassNo]); tempHistDown->Scale(xSec7ZH[toMassNo]/xSec7ZH[fromMassNo]); tempHistNom->Scale(xSec7ZH[toMassNo]/xSec7ZH[fromMassNo]); } if(chanT.Contains("VH") && IFILE.Contains("8TeV")) { tempHistUp->Scale(xSec8ZH[toMassNo]/xSec8ZH[fromMassNo]); tempHistDown->Scale(xSec8ZH[toMassNo]/xSec8ZH[fromMassNo]); tempHistNom->Scale(xSec8ZH[toMassNo]/xSec8ZH[fromMassNo]); } std::cout<< "channel--> " << channel << std::endl; tempHistUp->SetLineColor(kRed); tempHistUp->SetLineWidth(3); tempHistUp->SetFillColor(0); tempHistDown->SetLineColor(kBlue); tempHistDown->SetFillColor(0); tempHistDown->SetLineWidth(3); tempHistNom->SetFillColor(0); tempHistNom->SetMarkerStyle(20); tempHistUp->SetTitle((channel + syst).c_str()); RooDataHist *DHnom; RooDataHist *DHup = new RooDataHist(nameUp.c_str(),"",*hobs,tempHistUp); if(kount2 < 3) DHnom = new RooDataHist(namen.c_str(),"",*hobs,tempHistNom); RooDataHist *DHdown = new RooDataHist(nameDown.c_str(),"",*hobs,tempHistDown); WS->import(*(new RooHistPdf(nameUp.c_str(),"",*hobs,*DHup))); WS->import(*(new RooHistPdf(nameDown.c_str(),"",*hobs,*DHdown))); if(kount2 < 3){ WS->import(*(new RooHistPdf(namen.c_str(),"",*hobs,*DHnom))); kount2++;} } } }