void chi2(int xmin = 0, int xmax = 200, TString filename="../DsubMC/met2j0bIso2ewkScale_0_200.root", int nparam = 2){ RooAbsData::ErrorType errorType = RooAbsData::SumW2; file = new TFile(filename); RooRealVar* h = new RooRealVar("h","h",xmin,xmax); //Get Data TH1D* hData = file->Get("dataih"); hData->SetName("hData"); //hData->Draw(); RooDataHist* data = new RooDataHist("data","data",*h,hData); //Get Summed MC TH1D* hMC = file->Get("hh"); hMC->SetName("hMC"); hMC->Draw(); RooDataHist rdhMC("MC","MC",*h,hMC); RooHistPdf pdfMC("MCpdf","MCpdf",*h,rdhMC); //make (plot) the curves RooPlot* hFrame = h->frame(Name("hFrame")); data->plotOn(hFrame,RooFit::DataError(errorType)); pdfMC.plotOn(hFrame,ProjWData(*data),Components(pdfMC),Name("h_total")); //Determine Chi^2 double chi2fit = hFrame->chiSquare("h_total", "h_data", nparam); cout<<"Chi 2 / dof: "<<chi2fit<<endl; //Determine K-S double ks = hMC->KolmogorovTest(hData); cout<<"Kolmogorov-Smirnov: "<<ks<<endl; }
void doJob(std::string name,std::string nominame){ std::vector<TH1D*> histUp = hists("up","Up"); std::vector<TH1D*> histDown = hists("down","Down"); TH1D * nominal = GetNominal(nominame); TH1D * h = new TH1D(name.c_str(), name.c_str(), histUp[0]->GetXaxis()->GetNbins(), -1.,1.); cout<<"before loop "<<h->GetXaxis()->GetNbins()<<endl; for(int iBin = 0; iBin < h->GetXaxis()->GetNbins(); iBin++){ double sum = 0; cout<<"Bin "<<iBin+1<<"\t"<<histDown.size()<<"\t"<<histUp.size()<<endl; for(unsigned int i = 0; i < histDown.size(); i++){ cout<<"---------- file "<< i+1<<"\t"<<histDown[i]<<"\t"<<histUp[i]<<endl; cout<<nominal->GetBinContent(iBin + 1)<<"\t"<<histDown[i]->GetXaxis()->GetNbins()<<endl; cout<<"\t"<<histUp[i]->GetBinContent(iBin + 1)<<endl; cout<<histDown[i]->GetBinContent(iBin + 1); double iDown = fabs(histDown[i]->GetBinContent(iBin + 1) - nominal->GetBinContent(iBin + 1)); double iUp = fabs(histUp[i]->GetBinContent(iBin + 1) - nominal->GetBinContent(iBin + 1)); double iAvg = (iUp + iDown)/2.; sum+= pow(iAvg,2); cout<<iDown<<"\t"<<iUp<<"\t"<<iAvg<<"\t"<<sum<<endl; } h->SetBinContent(iBin + 1, nominal->GetBinContent(iBin + 1)); h->SetBinError(iBin + 1, sqrt(sum)); } cout<<"After loop"<<endl; TFile * final = new TFile(name.c_str(),"recreate"); TDirectory * d = final->mkdir("Default_allW"); h->SetName("Default_allWcosTheta"); d->cd(); h->Write(); final->Close();
TH1D *makeDiffHist(TH1D* hData, TH1D* hFit, const TString name) { TH1D *hDiff = (TH1D*)hData->Clone("hDiff"); hDiff->SetName(name); for(Int_t ibin=1; ibin<=hData->GetNbinsX(); ibin++) { Double_t diff=0; Double_t err=0; if(hData->GetBinContent(ibin)!=0) { diff = hFit->GetBinContent(ibin)/hData->GetBinContent(ibin); err = hFit->GetBinError(ibin)/hData->GetBinContent(ibin); } hDiff->SetBinContent(ibin,diff); hDiff->SetBinError(ibin,err); } hDiff->GetYaxis()->SetTitleOffset(0.55); hDiff->GetYaxis()->SetTitleSize(0.13); hDiff->GetYaxis()->SetLabelSize(0.10); hDiff->GetYaxis()->SetNdivisions(104); hDiff->GetYaxis()->CenterTitle(); hDiff->GetXaxis()->SetTitleOffset(1.2); hDiff->GetXaxis()->SetTitleSize(0.13); hDiff->GetXaxis()->SetLabelSize(0.12); hDiff->GetXaxis()->CenterTitle(); return hDiff; }
/////////////////////////////////////////////////////////////////// //////// Go4 GUI example script fft.C // J.Adamczewski, gsi, 30 May 2012 // NOTE: to be run in Go4 GUI local command line only! // NEVER call this script in remote analysis process!!! /////// Functionality: // perfroms fft on histogram of name1 using the option as explained in root TVirtualFFT:FFT /////// Usage: // The draw flag switches if the results are displayed each time this macro is called // if display is switched off, the result histogram is just updated in browser and existing displays /////// Bool_t fft(const char* name1, Option_t* opt = "R2C M", Bool_t draw=kTRUE) { if(TGo4AbstractInterface::Instance()==0 || go4!=TGo4AbstractInterface::Instance()) { std::cout <<"FATAL: Go4 gui macro executed outside Go4 GUI!! returning." << std::endl; return kFALSE; } TString newname; TString fullname1 = go4->FindItem(name1); TObject* ob1 = go4->GetObject(fullname1,1000); // 1000=timeout to get object from analysis in ms if ((ob1==0) || !ob1->InheritsFrom("TH1")) { std::cout <<"fft could not get histogram "<<fullname1 << std::endl; return kFALSE; } if(ob1->InheritsFrom("TH2") || ob1->InheritsFrom("TH3")){ // 2d std::cout <<"fft does not support 2d/3d histogram "<<fullname1 << std::endl; return kFALSE; } TH1* his1=(TH1*)ob1; TString n1=his1->GetName(); TString t1=his1->GetTitle(); newname.Form("_fft_%s",opt); TString finalname = n1+newname; TString finaltitle = t1+newname; // do fft here: Int_t N = his1->GetNbinsX(); TH1D* result = new TH1D(finalname, finaltitle,N,0,N); result->SetName(finalname); result->SetTitle(finaltitle); result->Reset(""); Double_t *in = new Double_t[N]; // since we do not know type of input histo, we copy contents to Double array: for(Int_t ix=0; ix<N;++ix) { in[ix]=his1->GetBinContent(ix+1); } TVirtualFFT *thefft = TVirtualFFT::FFT(1, &N, opt); thefft->SetPoints(in); thefft->Transform(); Double_t re, im; for (Int_t i=0; i<N; i++) { thefft->GetPointComplex(i, re, im); result->SetBinContent(i+1,TMath::Sqrt(re*re + im*im)); } result->SetDirectory(0); TString rname = go4->SaveToMemory("FFT", result, kTRUE); std::cout<< "Saved result histogram to " << rname.Data() <<std::endl; if(draw){ ViewPanelHandle vpanel = go4->StartViewPanel(); go4->DrawItem(rname, vpanel); } return kTRUE; }
void ProcYields::Proc_hPhi(hel_t hel/*=UNPOL*/){ Info(TString::Format("Proc_hPhi(%s)",helTitle[hel].Data()), ""); TDirectory* dir_phi=NULL; if (hel==UNPOL) { dir_phi = _dirQ2W->mkdir("hPhi"); }else if(hel==POS||hel==NEG){ dir_phi = _dirQ2W->mkdir(TString::Format("hPhi_%s",helTitle[hel].Data())); } TDirectory* dir_varset=NULL; for (Int_t iVarset=0;iVarset<nVARSET;iVarset++){ dir_varset = dir_phi->mkdir(TString::Format("Varset%d", iVarset+1)); dir_varset->cd(); //!Get relevent h5D THnSparse* hY5D = NULL; if (hel==UNPOL) { //! To make hphi from ACC_CORR evts hY5D = (THnSparseF*)_dirQ2W->Get(TString::Format("hY5D/Varset%d/hY5D_ACC_CORR",iVarset+1)); //! To make hphi from FULL evts //hY5D = (THnSparseF*)_dirQ2W->Get(TString::Format("hY5D/Varset%d/hY5D_FULL",iVarset+1)); //! To make hphi from TH evts //hY5D = (THnSparseF*)_dirQ2W->Get(TString::Format("hY5D/Varset%d/hY5D_TH",iVarset+1)); }else if (hel==POS||hel==NEG){ //! To make hphi from ACC_CORR evts hY5D = (THnSparseF*)_dirQ2W->Get(TString::Format("hY5D_%s/Varset%d/hY5D_ACC_CORR",helTitle[hel].Data(),iVarset+1)); //! To make hphi from FULL evts //hY5D = (THnSparseF*)_dirQ2W->Get(TString::Format("hY5D_%s/Varset%d/hY5D_FULL",helTitle[hel].Data(),iVarset+1)); //! To make hphi from TH evts //hY5D = (THnSparseF*)_dirQ2W->Get(TString::Format("hY5D_%s/Varset%d/hY5D_TH",helTitle[hel].Data(),iVarset+1)); } //! PROJECT phi bins for each VAR TDirectory* dir_var=NULL; for(Int_t iVar=0; iVar<nVAR; iVar++){ if (iVar==ALPHA || iVar==M1 || iVar==M2 || iVar==PHI) continue; dir_var = dir_varset->mkdir(varName[iVar].Data()); dir_var->cd(); int nvarbins = hY5D->GetAxis(iVar)->GetNbins(); //! Loop over number of bins in Var and make phi projections for each for (int ivarbin=0; ivarbin<nvarbins; ivarbin++){ Float_t varbin_lowedge = hY5D->GetAxis(iVar)->GetBinLowEdge(ivarbin+1); Float_t varbin_highedge = varbin_lowedge + hY5D->GetAxis(iVar)->GetBinWidth(ivarbin+1); //! Create Phi projection histogram hY5D->GetAxis(iVar)->SetRange(ivarbin+1, ivarbin+1); TH1D* hphi = (TH1D*)hY5D->Projection(PHI,"E"); hphi->Sumw2(); TString name = TString::Format("hphi_proj_%02d",ivarbin+1); TString title = TString::Format("#phi projection for %s = [%.2f,%.2f) | h=%s | top=%s | q2w = %s", varTitle[iVarset][iVar].Data(), varbin_lowedge, varbin_highedge, helTitle[hel].Data(), _topList.Data(), _Q2Wdirname); hphi->SetName(name); hphi->SetTitle(title); }//end nvarbins loop }//end nVAR loop }//end nVARSET loop Info(TString::Format("Proc_hPhi(%s)",helTitle[hel].Data()), "done\n"); }
void DynamicExec() { // Example of function called when a mouse event occurs in a pad. // When moving the mouse in the canvas, a second canvas shows the // projection along X of the bin corresponding to the Y position // of the mouse. The resulting histogram is fitted with a gaussian. // A "dynamic" line shows the current bin position in Y. // This more elaborated example can be used as a starting point // to develop more powerful interactive applications exploiting CINT // as a development engine. // // Author: Rene Brun TObject *select = gPad->GetSelected(); if(!select) return; if (!select->InheritsFrom("TH2")) {gPad->SetUniqueID(0); return;} TH2 *h = (TH2*)select; gPad->GetCanvas()->FeedbackMode(kTRUE); //erase old position and draw a line at current position int pyold = gPad->GetUniqueID(); int px = gPad->GetEventX(); int py = gPad->GetEventY(); float uxmin = gPad->GetUxmin(); float uxmax = gPad->GetUxmax(); int pxmin = gPad->XtoAbsPixel(uxmin); int pxmax = gPad->XtoAbsPixel(uxmax); if(pyold) gVirtualX->DrawLine(pxmin,pyold,pxmax,pyold); gVirtualX->DrawLine(pxmin,py,pxmax,py); gPad->SetUniqueID(py); Float_t upy = gPad->AbsPixeltoY(py); Float_t y = gPad->PadtoY(upy); //create or set the new canvas c2 TVirtualPad *padsav = gPad; TCanvas *c2 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c2"); if(c2) delete c2->GetPrimitive("Projection"); else c2 = new TCanvas("c2","Projection Canvas",710,10,700,500); c2->SetGrid(); c2->cd(); //draw slice corresponding to mouse position Int_t biny = h->GetYaxis()->FindBin(y); TH1D *hp = h->ProjectionX("",biny,biny); hp->SetFillColor(38); char title[80]; sprintf(title,"Projection of biny=%d",biny); hp->SetName("Projection"); hp->SetTitle(title); hp->Fit("gaus","ql"); hp->GetFunction("gaus")->SetLineColor(kRed); hp->GetFunction("gaus")->SetLineWidth(6); c2->Update(); padsav->cd(); }
TH1D* GetRawBackground1D(int itrg, int jass) { TH2D* hbackground = (TH2D*) GetRawBackground2D(itrg,jass); TH1D* hbackphi = (TH1D*)hbackground->ProjectionY(Form("backphi_trg%d_ass%d",itrg,jass),hbackground->GetXaxis()->FindBin(detaprojmin),hbackground->GetXaxis()->FindBin(detaprojmax),"e"); hbackphi->Scale(hbackground->GetXaxis()->GetBinWidth(1)); hbackphi->GetXaxis()->CenterTitle(); hbackphi->GetYaxis()->CenterTitle(); hbackphi->SetYTitle("B(#Delta#phi)"); hbackphi->SetName(Form("backphi_scale_trg%d_ass%d",itrg,jass)); return hbackphi; }
TH1D* GetRawSignal1D(int itrg, int jass) { TH2D* hsignal = GetRawSignal2D(itrg,jass); TH1D* hsignalphi = (TH1D*)hsignal->ProjectionY(Form("signalphi_trg%d_ass%d",itrg,jass),hsignal->GetXaxis()->FindBin(detaprojmin),hsignal->GetXaxis()->FindBin(detaprojmax),"e"); hsignalphi->Scale(hsignal->GetXaxis()->GetBinWidth(1)); hsignalphi->GetXaxis()->CenterTitle(); hsignalphi->GetYaxis()->CenterTitle(); hsignalphi->SetYTitle("S(#Delta#phi)"); hsignalphi->SetName(Form("signalphi_scale_trg%d_ass%d",itrg,jass)); return hsignalphi; }
void fixLeptonBJet(char* filename) { TH1D *lb; TFile f(filename, "UPDATE"); f.GetObject("HypLeptonBAjetMass", lb); if (lb) { cout << "HypLeptonBAjetMass found, saving as HypLeptonBjetMass\n"; lb->SetName("HypLeptonBjetMass"); lb->Write(); } f.Close(); }
TH1D *getErrorBand(TH1* h) { TH1D *hErr = (TH1D*) h->Clone(); hErr->SetName("hErr"); for (int i=0;i<h->GetNbinsX();i++) { double var = h->GetBinContent(i); double varErr = h->GetBinError(i); hErr->SetBinContent(i,var); hErr->SetBinError(i,var*0.1); } return hErr; }
void run() { // gROOT->ProcessLine(".L /Users/jdolen/Dropbox/Code/MyAnalysisRootFunctions_NEW.C"); // gROOT->ProcessLine(".L /Users/jdolen/Dropbox/Code/JMAR/TopTagging/MyFunctions_TopTag.C"); TFile *out = new TFile("ModMass_2015_09_22.root","RECREATE"); // TFile *F_qcdpt170 = new TFile("ntuples/ntuple_QCD_Pt_170to300_RunIISpring15DR74-Asympt50ns_2015_09_22.root"); TFile *F_qcdpt300 = new TFile("ntuples/ntuple_QCD_Pt_300to470_RunIISpring15DR74-Asympt50ns_2015_09_22c.root"); TFile *F_qcdpt470 = new TFile("ntuples/ntuple_QCD_Pt_470to600_RunIISpring15DR74-Asympt50ns_2015_09_22.root"); TFile *F_qcdpt600 = new TFile("ntuples/ntuple_QCD_Pt_600to800_RunIISpring15DR74-Asympt50ns_2015_09_22c.root"); TFile *F_qcdpt800 = new TFile("ntuples/ntuple_QCD_Pt_800to1000_RunIISpring15DR74-Asympt50ns_2015_09_22b.root"); TFile *F_qcdpt1000 = new TFile("ntuples/ntuple_QCD_Pt_1000to1400_RunIISpring15DR74-Asympt50ns_2015_09_22.root"); TFile *F_qcdpt1400 = new TFile("ntuples/ntuple_QCD_Pt_1400to1800_RunIISpring15DR74-Asympt50ns_2015_09_22.root"); TFile *F_qcdpt1800 = new TFile("ntuples/ntuple_QCD_Pt_1800to2400_RunIISpring15DR74-Asympt50ns_2015_09_22.root"); TFile *F_qcdpt2400 = new TFile("ntuples/ntuple_QCD_Pt_2400to3200_RunIISpring15DR74-Asympt50ns_2015_09_22.root"); TFile *F_qcdpt3200 = new TFile("ntuples/ntuple_QCD_Pt_3200toInf_RunIISpring15DR74-Asympt50ns_2015_09_22.root"); std::vector <TFile* > rootFiles; // rootFiles.push_back( F_qcdpt170 ); // rootFiles.push_back( F_qcdpt300 ); rootFiles.push_back( F_qcdpt470 ); rootFiles.push_back( F_qcdpt600 ); rootFiles.push_back( F_qcdpt800 ); rootFiles.push_back( F_qcdpt1000 ); rootFiles.push_back( F_qcdpt1400 ); rootFiles.push_back( F_qcdpt1800 ); rootFiles.push_back( F_qcdpt2400 ); rootFiles.push_back( F_qcdpt3200 ); // for (unsigned int i=0; i<rootFiles.size(); i++){ // TH1D * h1 = (TH1D*) rootFiles[i] -> Get( "h_mAK8_ModMass" ); // cout<<h1->Integral()<<endl; // } vector <string> histnames; histnames.push_back("h_mAK8_ModMass"); histnames.push_back("h_mSDropAK8_ModMass"); histnames.push_back("h_mAK8_ModMass_jet0"); histnames.push_back("h_mSDropAK8_ModMass_jet0"); histnames.push_back("h_mAK8_ModMass_jet1"); histnames.push_back("h_mSDropAK8_ModMass_jet1"); out->cd(); for (unsigned int i=0; i<histnames.size(); i++) { TH1D * hist = scaleHistsFromPtHatRootFilesReturnHist( histnames[i].c_str(), rootFiles) ; hist->SetName(histnames[i].c_str()); hist->Write(); } out->Write(); out->Close(); }
void SaveClosure(TH1D* prediction, TH1D* expectation, TDirectory* Folder) // prediction durch expectation { TH1D* Closure = (TH1D*) prediction->Clone(); Closure->Divide(prediction,expectation,1,1,"B"); TString title = prediction->GetTitle(); title +="_closure"; // title = "#mu & e Control-Sample Ratio in Search Bins; Search bins; #mu / e CS"; Closure->SetTitle(title); title = prediction->GetName(); title+="_closure"; Closure->SetName(title); Folder->cd(); Closure->Write(); }
// A function to rebin a histogram with incresingly larger bins. // It is useful for histograms of momentum, energy etc, where // particles/events become less and less frequent as the quantity // increases. TH1D* StepRebin(TH1D *inhisto, int stepPeriod=1) { TH1D *first = new TH1D(*inhisto); int ninbins = inhisto->GetNbinsX(); first->SetName("first"); int sbin=1+stepPeriod; for ( int i=1; i<ninbins; i++ ) // Actually no need to go up to ninbins for ( int j=0; j<stepPeriod; ++j ) { if ( inhisto->GetBinCenter(sbin) > inhisto->GetBinLowEdge(ninbins) ) continue; TH1D *second = CombineBins(*first, inhisto->GetBinCenter(sbin), inhisto->GetBinCenter(sbin+i)); delete first; second->SetName("second"); sbin = (sbin+i+1); TH1D *first = new TH1D(*second); delete second; first->SetName("first"); } return first; }
void CompareCFLADiffCuts() { TFile newFile("~/Analysis/lambda/AliAnalysisLambda/Results/2016-01/15-NoOppChargeCut/All/CFs.root"); TDirectory *newDir = newFile.GetDirectory("Merged"); vector<TH1D*> newCFs; newCFs.push_back((TH1D*)newDir->Get("CFLamALam010")); newCFs.push_back((TH1D*)newDir->Get("CFLamALam1030")); newCFs.push_back((TH1D*)newDir->Get("CFLamALam3050")); TFile oldFile("~/Analysis/lambda/AliAnalysisLambda/Results/2016-01/08-NewAvgSepCuts/All/CFs.root"); TDirectory *oldDir = oldFile.GetDirectory("Merged"); vector<TH1D*> oldCFs; oldCFs.push_back((TH1D*)oldDir->Get("CFLamALam010")); oldCFs.push_back((TH1D*)oldDir->Get("CFLamALam1030")); oldCFs.push_back((TH1D*)oldDir->Get("CFLamALam3050")); TFile *compareFile = new TFile("Compare.root","update"); TDirectory *dir = compareFile->GetDirectory("Delta"); if(!dir) dir = compareFile->mkdir("Delta"); for(UInt_t i = 0; i < newCFs.size(); i++) { // TH1D *ratio = (TH1D*)newCFs[i]->Clone(); // TString name = ratio->GetName(); // ratio->SetName(name + "Ratio"); // ratio->SetTitle(name + "Ratio"); // ratio->Divide(oldCFs[i]); // TH1D *barlowRatio = ComputeRogerBarlowRatio(newCFs[i], oldCFs[i]); // barlowRatio->SetName(name + "BarlowRatio"); // barlowRatio->SetTitle(name + "BarlowRatio"); TString name = newCFs[i]->GetName(); TH1D *barlowDifference = ComputeRogerBarlowDifference(newCFs[i], oldCFs[i]); barlowDifference->SetName(name + "BarlowDifference"); barlowDifference->SetTitle(name + "BarlowDifference"); dir->cd(); // ratio->Write(); // barlowRatio->Write(); barlowDifference->Write(barlowDifference->GetName(), TObject::kOverwrite); Chi2TestWithZero(barlowDifference); FitWithConstant(barlowDifference, compareFile); // LookAtMean(barlowDifference); RebinHist(barlowDifference, compareFile); ManuallyRebin(barlowDifference, compareFile); } compareFile->Close(); }
TFile *createRootFile(TString fileName,TString STlepCut,TString HTCut,TH1D *hIn,TString histoName) { TH1::SetDefaultSumw2(); TFile *fout = new TFile(fileName,"UPDATE"); fout->mkdir("ANplots"+STlepCut+"_NOLPsecondD"+HTCut); fout->ls(); fout->cd("ANplots"+STlepCut+"_NOLPsecondD"+HTCut); fout->pwd(); TH1D *hOut = (TH1D*)hIn->Clone(histoName); hOut->SetName(histoName); hOut->Write(histoName); fout->Close(); return fout; }
void exec2() { if (!gPad) { Error("exec2", "gPad is null, you are not supposed to run this macro"); return; } TObject *select = gPad->GetSelected(); if(!select) return; if (!select->InheritsFrom(TH2::Class())) {gPad->SetUniqueID(0); return;} gPad->GetCanvas()->FeedbackMode(kTRUE); //erase old position and draw a line at current position int pyold = gPad->GetUniqueID(); int px = gPad->GetEventX(); int py = gPad->GetEventY(); float uxmin = gPad->GetUxmin(); float uxmax = gPad->GetUxmax(); int pxmin = gPad->XtoAbsPixel(uxmin); int pxmax = gPad->XtoAbsPixel(uxmax); if(pyold) gVirtualX->DrawLine(pxmin,pyold,pxmax,pyold); gVirtualX->DrawLine(pxmin,py,pxmax,py); gPad->SetUniqueID(py); Float_t upy = gPad->AbsPixeltoY(py); Float_t y = gPad->PadtoY(upy); //create or set the new canvas c2 TVirtualPad *padsav = gPad; TCanvas *c2 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c2"); if(c2) delete c2->GetPrimitive("Projection"); else c2 = new TCanvas("c2"); c2->cd(); //draw slice corresponding to mouse position TH2 *h = (TH2*)select; Int_t biny = h->GetYaxis()->FindBin(y); TH1D *hp = h->ProjectionX("",biny,biny); char title[80]; sprintf(title,"Projection of biny=%d",biny); hp->SetName("Projection"); hp->SetTitle(title); hp->Fit("gaus","ql"); c2->Update(); padsav->cd(); }
TH1D* readTH1(const TString &fileName, const TString &histName, const TString &newHistName, bool useCurrentStyle) { TFile f(fileName,"READ"); TH1D *h = 0; f.GetObject(histName,h); if( h ) { h->SetDirectory(0); if( useCurrentStyle ) h->UseCurrentStyle(); if( newHistName.Length() ) h->SetName(newHistName); } else { std::cerr << "ERROR in FileOps::readTH1: Histogram with name '" << histName << "' does not exist in file '" << fileName << "'\n."; f.Close(); exit(-1); } f.Close(); return h; }
// Draw 1D histos TH1D *plot1Dhisto(double intLumi,TFile *fileName,TString folderName,TString histoName,int color,int rebin,float xMin,float xMax,TString xName, TString yName,TString sampleName,bool mc) { TH1D *hTemp = (TH1D*)fileName->Get(folderName+"/"+histoName); hTemp->SetName(histoName+"_"+sampleName); if (mc){ hTemp->Scale(intLumi/100.); } hTemp->Rebin(rebin); hTemp->SetLineColor(color); hTemp->SetLineWidth(5); hTemp->GetXaxis()->SetRangeUser(xMin,xMax); hTemp->GetXaxis()->SetTitle(xName); hTemp->GetXaxis()->SetTitleSize(0.06); hTemp->GetXaxis()->SetLabelSize(0.06); hTemp->GetYaxis()->SetTitle(yName); hTemp->GetYaxis()->SetTitleSize(0.06); hTemp->GetYaxis()->SetLabelSize(0.06); hTemp->SetTitleOffset(1.5, "Y"); // last/first bin: put over/underflow hTemp->SetBinContent(hTemp->FindBin(xMax),hTemp->Integral(hTemp->FindBin(xMax),hTemp->GetNbinsX()+1)); hTemp->SetBinContent(hTemp->FindBin(xMin),hTemp->Integral(-1,hTemp->FindBin(xMin))); hTemp->SetBinError(hTemp->FindBin(xMax),sqrt(hTemp->Integral(hTemp->FindBin(xMax),hTemp->GetNbinsX()+1))); hTemp->SetBinError(hTemp->FindBin(xMin),sqrt(hTemp->Integral(-1,hTemp->FindBin(xMin)))); //fileName->Close(); /* if (histoName != "LP_tot") { if (histoName != "SumLepPt_tot") { if ((folderName == "ANplots150_NOLP")) { hTemp->GetXaxis()->SetRangeUser(0.,300.); } if ((folderName == "ANplots250_NOLP")) { hTemp->GetXaxis()->SetRangeUser(0.,400.); } if ((folderName == "ANplots350_NOLP")) { hTemp->GetXaxis()->SetRangeUser(0.,500.); } if ((folderName == "ANplots450_NOLP")) { hTemp->GetXaxis()->SetRangeUser(0.,1000.); } } else { if ((folderName == "ANplots150_NOLP")) { hTemp->GetXaxis()->SetRangeUser(100.,300.); } if ((folderName == "ANplots250_NOLP")) { hTemp->GetXaxis()->SetRangeUser(200.,400.); } if ((folderName == "ANplots350_NOLP")) { hTemp->GetXaxis()->SetRangeUser(300.,500.); } if ((folderName == "ANplots450_NOLP")) { hTemp->GetXaxis()->SetRangeUser(400.,1000.); } } } */ return hTemp; } // ~ end of plot1Dhisto function
TH1D *plotIso(TTree *tSig,TString var,TString weight, TString etcut, TString htcut, TString njetcut, TString ph, TString bin,Double_t xmax, Int_t icol) { TCut etcut20=weight+" * ("+etcut+htcut+" && "+njetcut+")"; TCut conv1=weight+" * ("+etcut+htcut+" &&"+njetcut+" && mHits<=1)"; TCut conv2=weight+" * ("+etcut+htcut+" && "+njetcut+"&& mHits<=1)"; TCut conv3=weight+" * ("+etcut+htcut+" && "+njetcut+"&& mHits<=1 && (dcot>0.02 || dcot<-0.02 || dist>0.02 || dist<-0.02))"; TCanvas *c = getaCanvas(ph+var+etcut+htcut+"hsqrti"); tSig->Draw(var+">>hsqrti"+bin,conv3); TH1D *hsqrt = (TH1D*)gDirectory->Get("hsqrti"); hsqrt->SetName(ph+var+htcut+"hsqrti"); hsqrt->SetLineColor(icol); hsqrt->SetLineWidth(3); c->Close(); return hsqrt; }
TH1D *LPFilter( TH1D *hin , Double_t Cend ) { if (Cend==-1.0) Cend = CPF ; Double_t RCns = 50. * Cend * 1.e-3 ; Double_t At = hin->GetBinCenter(2) - hin->GetBinCenter(1) ; Double_t alfa = At/(RCns + At) ; TH1D *hout = (TH1D *) hin->Clone(); hout->Reset(); hout->SetTitle( Form("C=%d pF",TMath::Nint(Cend)) ) ; hout->SetName( Form("C=%d pF",TMath::Nint(Cend)) ) ; hout->SetBinContent(1, hin->GetBinContent(1) ); for ( Int_t i=2 ; i<=hin->GetNbinsX() ; i++ ) { Double_t val = (1.0-alfa)*hout->GetBinContent(i-1) + alfa*hin->GetBinContent(i) ; hout->SetBinContent(i,val); } return hout ; }
TH1D* momResHist(TFile* f, int i) { Double_t xbins[33] = {0,0.2,0.4,0.6,0.8, 1.0,1.6,2.2,2.8,3.4, 4.4,5.4,6.0,8.0,10.0, 12.0,14.0,18.0,22.0,26.0, 30.0,36.0,42.0,50.0,55.0, 60.0,70.0,80.0,100.0,120.0, 140.0,160.0,200.0}; TH3F *hRes3D = (TH3F*) f->Get("trkEffAnalyzer/hresStoR3D"); double feta = 2.4; int binMaxEta = hRes3D->GetXaxis()->FindBin(feta); int binMinEta = hRes3D->GetXaxis()->FindBin(-1.0*feta); hRes3D->GetXaxis()->SetRange(binMinEta,binMaxEta); TH2D *hRes2D = (TH2D*) hRes3D->Project3D("zy"); // zy: rec-> y axis, sim -> x axis hRes2D->SetName("hRes2D"); hRes2D->FitSlicesY(0,0,-1,10); TH1D *h1 = (TH1D*)gDirectory->Get("hRes2D_1"); TH1D *h2 = (TH1D*)gDirectory->Get("hRes2D_2"); h1->Rebin(32,Form("h1new%d",i),xbins); h2->Rebin(32,Form("h2new%d",i),xbins); TH1D* h1new = (TH1D*) gDirectory->Get(Form("h1new%d",i)); TH1D* h2new = (TH1D*) gDirectory->Get(Form("h2new%d",i)); TH1D *momres = (TH1D*) h2new->Clone("momres"); momres->SetName(Form("momres_%d",i)); momres->SetMaximum(0.15); momres->SetMinimum(0.0); momres->SetTitle("Momentum resolution;p_{T} [GeV/c]"); momres->SetStats(0); momres->SetMarkerStyle(20); momres->Divide(h1new); return momres; }
ConvertSpectraNameTOF(const Char_t *fileoutname) { TFile *toffile = TFile::Open(toffilename); TFile *fileout = TFile::Open(fileoutname, "RECREATE"); TH1D *hSpectrum; for (Int_t part = 2; part < AliPID::kSPECIES; part++) { for (Int_t charge = 0; charge < 2; charge++) { for (Int_t icent = 0; icent < 9; icent++) { hSpectrum = GetTOFSpectrum(toffile, part, charge, icent); if (!hSpectrum) continue; hSpectrum->SetName(Form("cent%d_%s_%s", icent, AliPID::ParticleName(part), chargeName[charge])); fileout->cd(); hSpectrum->Write(); } } } fileout->Close(); }
// -- Draw 1D histos TH1D *plot1Dhisto(double intLumi,TFile *fileName,TString folderName,TString histoName,int color,int rebin,float xMin,float xMax,TString xName, TString yName,TString sampleName,bool mc) { TH1D *hTemp = (TH1D*)fileName->Get(folderName+"/"+histoName); hTemp->SetName(histoName+"_"+sampleName); // hTemp->Sumw2(); if (mc) { hTemp->Scale(intLumi/100.); } hTemp->Rebin(rebin); hTemp->SetLineColor(color); hTemp->SetLineWidth(3); hTemp->GetXaxis()->SetRangeUser(xMin,xMax); hTemp->GetXaxis()->SetTitle(xName); hTemp->GetYaxis()->SetTitle(yName); // last bin: put put overflow hTemp->SetBinContent(hTemp->FindBin(xMax),hTemp->Integral(hTemp->FindBin(xMax),hTemp->GetNbinsX()+1)); // cout << "Nbins=" << hTemp->GetNbinsX() << "\n"; return hTemp; } // ~ end of plot1Dhisto function
void ChangeDataTreeName(std::string suffix){ // Define names TString filename = "", treename = "", histname = ""; filename.Form("central_%s.root",suffix.c_str()); treename.Form("id_%s",suffix.c_str()); histname.Form("sumOfMcWeights_%s",suffix.c_str()); TString _pathFile(string(getenv("WORKAREA")) + "/histoAna" + "/SusyAna/histos_110312_13fb_n0111_DD_MMtrial9_SYS_HFT/HFTOutputs_merge/"); filename = _pathFile+filename; cout << "open " << filename << endl; // Open file TFile* file = new TFile(filename,"UPDATE"); if(file->IsOpen()==kFALSE){ cerr << "Cannot open file " << filename << endl; abort(); } file->ls(); TTree* treeOriginal = (TTree*) file->Get(treename); TH1D* histOriginal = (TH1D*) file->Get(histname); TTree* treeNew = (TTree*) treeOriginal->Clone(); TH1D* histNew = (TH1D*) histOriginal->Clone(); // Set-Write-Delete histNew->SetName ("sumOfMcWeights_Data" ); histNew->SetTitle("sumOfMcWeights_Data" ); histNew->Write ("",TObject::kOverwrite); treeNew->SetName ("id_Data" ); treeNew->SetTitle("id_Data" ); treeNew->Write ("",TObject::kOverwrite); file->Delete (histname+";1" ); file->Delete (treename+";1" ); // Close file file->Close(); }
void RebinHist(TH1D* h1, TFile *out) { // This rebinning method doesn't work // It needs to divide by the entries to make an average // Also, it doesn't include error weighting. cout<<"Rebinning histogram"<<endl; Int_t nBins = h1->GetNbinsX(); TH1D *rebinHist = (TH1D*) h1->Clone(); rebinHist->Rebin(nBins/2); // TFile out("Compare.root","update"); TDirectory *dir = out->GetDirectory("Rebin"); if(!dir) dir = out->mkdir("Rebin"); dir->cd(); TString histName = h1->GetName(); histName += "Rebin"; rebinHist->SetName(histName); rebinHist->SetTitle(histName); rebinHist->SetDirectory(0); rebinHist->Write(rebinHist->GetName(), TObject::kOverwrite); // out->Close(); }
void fitpapvar(const char* infilename, const char* histname) { TFile* infile = new TFile(Form("%s",infilename),"read"); TH1D* hcf = (TH1D*)infile->Get(histname); hcf->GetXaxis()->SetRangeUser(0,2); TF1 *fc2 = new TF1("fc2","[3]+[2]*TMath::Gaus(x,[0],[1])",0.4,1); fc2->SetParameters(1.5,0.3,-0.2,1); // TF1 *fc2 = new TF1("fc2","[1]+[0]*x*x",0,1); // fc2->SetParameters(-0.01,1.0); // TF1 *fc2 = new TF1("fc2","[2]+[1]*x*x*x*x*x",0,1); // fc2->SetParameters(-0.01,0.01,1.0); // TF1 *fc2 = new TF1("fc2","[3]+[2]*x*x+[1]*x*x*x+[0]*x*x*x*x",0.,1); // fc2->SetParameters(-0.01,0.01,1.0,1.0); hcf->Fit("fc2","r","",0.3,1); TH1D* hnew = new TH1D("hnew","hnew",hcf->GetNbinsX(),0,1); for(int i=1;i<=hcf->GetNbinsX();++i){ // cout << i << endl; // cout << hcf->GetBinContent(i)/fc2->Eval(2.*i/hcf->GetNbinsX()) << endl; // cout << hcf->GetBinContent(i) << endl; // cout << fc2->Eval(2.*i/hcf->GetNbinsX()) << endl << endl; hnew->SetBinContent(i, hcf->GetBinContent(i)/fc2->Eval(1.*i/hcf->GetNbinsX())); hnew->SetBinError(i, hcf->GetBinError(i)); } hnew->Draw("same"); fc2->Draw("same"); hnew->SetName(Form("divp4%s",histname)); TFile* ofile = new TFile(Form("divp4%s",infilename),"update"); hnew->Write(); hcf->Write(); ofile->Close(); }
void balanceMetVsAj(TString infname = "dj_HCPR-J50U-hiGoodMergedTracks_OfficialSelv2_Final0_120_50.root", TCut myCut = "cent<30", char *title = "",bool drawLegend = false, bool drawSys = true ) { // =========================================================== // Get Input // =========================================================== TFile *inf = new TFile(infname); TTree *t = (TTree*)inf->Get("ntjt"); t->SetAlias("metxMergedAll","(metOutOfConex0+metOutOfConex1+metOutOfConex2+metOutOfConex3+metOutOfConex4+metOutOfConex5)"); t->SetAlias("metxMerged0","(metOutOfConex0)"); t->SetAlias("metxMerged1","(metOutOfConex1)"); t->SetAlias("metxMerged2","(metOutOfConex2)"); t->SetAlias("metxMerged3","(metOutOfConex3)"); t->SetAlias("metxMerged4","(metOutOfConex4+metOutOfConex5)"); // =========================================================== // Analysis Setup // =========================================================== const int nBin = 5; double bins[nBin+1] = {0.5,1.0,1.5,4,8,1000}; int colors[5] = {kBlue-10,kYellow-7, kOrange-2,kGreen-5,kRed-3}; const int nBinAj = 4; double ajBins[nBinAj+1] = {0.0001,0.11,0.22,0.33,0.49999}; // Selection cut TCut evtCut = "nljet>120&&abs(nljetacorr)<2&&aljet>50&&abs(aljetacorr)<2&&jdphi>2./3*TMath::Pi()&&!maskEvt"; // TCut evtCut = "nljet>120&&abs(nljetacorr)<2&&aljet>50&&abs(aljetacorr)<2&&jdphi>3&&!maskEvt"; cout << "Sel evt: " << t->GetEntries(evtCut&&myCut) << endl; // =========================================================== // Find Average Weights // =========================================================== TH1D *hw[nBinAj]; float meanWt[nBinAj]; for ( int iaj = 0 ; iaj< nBinAj ; iaj++) { hw[iaj] = new TH1D(Form("hw_aj%d",iaj),"",1000,0,100); TCut ajCut = Form("Aj>%f && Aj<%f", ajBins[iaj],ajBins[iaj+1]); t->Draw(Form("weight>>hw_aj%d",iaj), evtCut&&myCut&&ajCut); meanWt[iaj] = hw[iaj]->GetMean(); cout << " <Weight>: " << meanWt[iaj] << endl; } // =========================================================== // Draw Weighted Averages // =========================================================== TH1D *ppos[nBin]; TH1D *pneg[nBin]; TH1D *pe[nBin]; for (int i=0;i<nBin;i++) { TH1D *h1 = new TH1D(Form("h1%d",i),"",nBinAj,ajBins); TH1D *h2 = new TH1D(Form("h2%d",i),"",nBinAj,ajBins); TH1D *he[nBinAj]; // ================================= // Get Weighted Mean for each Aj bin // ================================= h1->Sumw2(); h2->Sumw2(); t->Draw(Form("Aj>>h1%d",i), "weight"*(evtCut&&myCut)); t->Draw(Form("Aj>>h2%d",i), Form("((-weight*metxMerged%d))",i)*(evtCut&&myCut)); pe[i]=(TH1D*)h2->Clone(); pe[i]->SetName(Form("p%d",i)); pe[i]->Divide(h1); ppos[i] = new TH1D(Form("ppos%d",i),"",nBinAj,ajBins); ppos[i]->SetLineColor(1); ppos[i]->SetMarkerColor(colors[i]); ppos[i]->SetFillColor(colors[i]); ppos[i]->SetFillStyle(1001); pneg[i] = new TH1D(Form("pneg%d",i),"",nBinAj,ajBins); pneg[i]->SetLineColor(1); pneg[i]->SetMarkerColor(colors[i]); pneg[i]->SetFillColor(colors[i]); pneg[i]->SetFillStyle(1001); // ================================= // Caculated Stat Error of the Mean // ================================= cout << "Stat Error for pt bin " << i << ": "; for ( int iaj = 0 ; iaj< nBinAj ; iaj++) { he[iaj] = new TH1D(Form("he%d_aj%d",i,iaj),"",100,-200,200); TCut ajCut = Form("Aj>%f && Aj<%f", ajBins[iaj],ajBins[iaj+1]); t->Draw(Form("((metxMerged%d))>>he%d_aj%d",i,i,iaj), "weight" * evtCut&&myCut&&ajCut); float theError = he[iaj]->GetRMS()/ (sqrt(he[iaj]->GetEntries())); cout << theError << " "; pe[i]->SetBinError(iaj+1, theError); } cout << endl; } // Stack for (int i=nBin-1;i>=0;i--) { for(int iaj = 0 ; iaj< nBinAj ; iaj++) { double posVal=0, negVal=0; double posValErr=0, negValErr=0; if (i!=nBin-1) { posVal = ppos[i+1]->GetBinContent(iaj+1); posValErr = ppos[i+1]->GetBinError(iaj+1); negVal = pneg[i+1]->GetBinContent(iaj+1); negValErr = pneg[i+1]->GetBinError(iaj+1); } if (pe[i]->GetBinContent(iaj+1)<0) { negVal+=pe[i]->GetBinContent(iaj+1); negValErr=pe[i]->GetBinError(iaj+1); posValErr=0; } else if (pe[i]->GetBinContent(iaj+1)>0) { posVal+=pe[i]->GetBinContent(iaj+1); posValErr=pe[i]->GetBinError(iaj+1); negValErr=0; } ppos[i]->SetBinContent(iaj+1,posVal); ppos[i]->SetBinError(iaj+1,posValErr); pneg[i]->SetBinContent(iaj+1,negVal); pneg[i]->SetBinError(iaj+1,negValErr); } } TH1D *pall; TH1D *pallE; TH1D *h1 = new TH1D(Form("hAll1"),"",nBinAj,ajBins); TH1D *h2 = new TH1D(Form("hAll2"),"",nBinAj,ajBins); h1->Sumw2(); h2->Sumw2(); t->Draw(Form("Aj>>hAll1"), "weight"*(evtCut&&myCut)); t->Draw(Form("Aj>>hAll2"), Form("((-weight*metxMergedAll))")*(evtCut&&myCut)); pall=(TH1D*)h2->Clone(); pall->SetName("pall"); pall->Divide(h1); // replace the sys error from pallE to pall TH1D *he[nBinAj]; cout << "Stat Error for All pt: "; for ( int iaj = 0 ; iaj< nBinAj ; iaj++) { he[iaj] = new TH1D(Form("heAll_aj%d",iaj),"",100,-200,200); TCut ajCut = Form("Aj>%f && Aj<%f", ajBins[iaj],ajBins[iaj+1]); t->Draw(Form("((metxMergedAll))>>heAll_aj%d",iaj), "weight" * evtCut&&myCut&&ajCut); float theError = he[iaj]->GetRMS()/ (sqrt(he[iaj]->GetEntries())); cout << theError << " "; pall->SetBinError(iaj+1, theError); } cout << endl; pall->SetXTitle("A_{J}"); pall->SetYTitle("<#slash{p}_{T}^{#parallel}> (GeV/c)"); pall->GetXaxis()->CenterTitle(); pall->GetYaxis()->CenterTitle(); pall->GetXaxis()->SetLabelSize(22); pall->GetXaxis()->SetLabelFont(43); pall->GetXaxis()->SetTitleSize(24); pall->GetXaxis()->SetTitleFont(43); pall->GetYaxis()->SetLabelSize(22); pall->GetYaxis()->SetLabelFont(43); pall->GetYaxis()->SetTitleSize(24); pall->GetYaxis()->SetTitleFont(43); pall->GetXaxis()->SetTitleOffset(1.8); pall->GetYaxis()->SetTitleOffset(2.4); pall->SetNdivisions(505); pall->SetAxisRange(-59.9,59.9,"Y"); pall->SetMarkerSize(1); pall->Draw("E"); float addSys = 0; if ( drawSys==1) addSys=0; // No sys error at this moment // ==================== // Finally Draw // ==================== for (int i=0;i<nBin;++i) { ppos[i]->SetLineWidth(1); ppos[i]->Draw("hist same"); pneg[i]->SetLineWidth(1); pneg[i]->Draw("hist same"); } // ==================== // Draw Statistical Error bars // ==================== for (int i=0;i<nBin;++i) { if ( i==0 ) drawErrorShift(ppos[i],-0.016, addSys); if ( i==1 || i==4) drawErrorShift(ppos[i],-0.008,addSys); if ( i==2 ) drawErrorShift(ppos[i],0.008,addSys); if ( i==3 ) drawErrorShift(ppos[i],0.016,addSys); if ( i==0 ) drawErrorShift(pneg[i],-0.016, addSys); if ( i==1 || i==4) drawErrorShift(pneg[i],-0.008,addSys); if ( i==2 ) drawErrorShift(pneg[i],0.008,addSys); if ( i==3 ) drawErrorShift(pneg[i],0.016,addSys); } pall->Draw("E same"); // ==================== // Draw Systematic Errors // ==================== if (drawSys == 1) { for(int i = 0; i < nBinAj; ++i){ double x = pall->GetBinCenter(i+1); double y = pall->GetBinContent(i+1); // Quote the difference between GEN and RECO in >8 Bin (20%) before adjusting eff as systematics double err = fabs(pe[nBin-1]->GetBinContent(i+1)*0.2); DrawTick(y,err,err,x,1,0.02,1); } } // ==================== // Draw Legend // ==================== TLegend *leg = new TLegend(0.10,0.68,0.70,0.96); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetTextFont(63); leg->SetTextSize(16); leg->AddEntry(pall,Form("> %.1f GeV/c",bins[0]),"pl"); for (int i=0;i<nBin;++i) { if (i!=nBin-1){ leg->AddEntry(ppos[i],Form("%.1f - %.1f GeV/c",bins[i],bins[i+1]),"f"); } else { leg->AddEntry(ppos[i],Form("> %.1f GeV/c",bins[i]),"f"); } } if (drawLegend) leg->Draw(); TLine * l0 = new TLine(0,0,0.5,0); l0->SetLineStyle(2); l0->Draw(); TLine * l1 = new TLine(0.0001,-10,0.0001,10); l1->Draw(); TText *titleText = new TText(0.3,30,title); titleText->Draw(); }
TH1D *haddHistos(TFile *fileName,TString histoName,vector<TString> ST,vector<TString> HT) { TH1::SetDefaultSumw2(); TH1D *hInit = (TH1D*)fileName->Get("ANplots"+ST[0]+"_NOLPsecondD"+HT[0]+"/"+histoName); hInit->SetName(histoName); // ---- loop over all the STbins for (int iST=0; iST<ST.size(); iST++) { if (ST.size()>1) { TH1D *hTempST = (TH1D*)fileName->Get("ANplots"+ST[iST]+"_NOLPsecondD"+HT[iHT]+"/"+histoName); hInit->Add(hInit,hTempST,1.,1.); } // ---- loop over all the STbins for (int iHT=0; iHT<HT.size(); iHT++) { if (HT.size()>1) { TH1D *hTempHT = (TH1D*)fileName->Get("ANplots"+ST[iST]+"_NOLPsecondD"+HT[iHT]+"/"+histoName); hInit->Add(hInit,hTempHT,1.,1.); } } // --- end of looping over HTbins } // --- end of looping over STbins return hInit; }
void MuMu_Analysis::Terminate() { // The Terminate() function is the last function to be called during // a query. It always runs on the client, it can be used to present // the results graphically or save the results to file. TH1D *DataEff; DataEff = (TH1D*)IsoStudiesData0->Clone(); DataEff->SetTitle("DataIsoEff"); DataEff->SetName("DataIsoEff"); for(int bin=1; bin<IsoStudiesData0->GetNbinsX()+1; bin++){ double eff=IsoStudiesData1->GetBinContent(bin)/IsoStudiesData0->GetBinContent(bin); double binerr=sqrt((1-eff)/IsoStudiesData1->GetBinContent(bin)); DataEff->SetBinContent(bin, eff); DataEff->SetBinError(bin, binerr); } TH1D *ZMCEff; ZMCEff = (TH1D*)IsoStudiesZMC0->Clone(); ZMCEff->SetTitle("ZMCIsoEff"); ZMCEff->SetName("ZMCIsoEff"); for(int bin=1; bin<IsoStudiesZMC0->GetNbinsX()+1; bin++){ double eff=IsoStudiesZMC1->GetBinContent(bin)/IsoStudiesZMC0->GetBinContent(bin); double binerr=sqrt((1-eff)/IsoStudiesZMC1->GetBinContent(bin)); ZMCEff->SetBinContent(bin, eff); ZMCEff->SetBinError(bin, binerr); } TH1D *ttMCEff; ttMCEff = (TH1D*)IsoStudiesttMC0->Clone(); ttMCEff->SetTitle("ttMCIsoEff"); ttMCEff->SetName("ttMCIsoEff"); for(int bin=1; bin<IsoStudiesttMC0->GetNbinsX()+1; bin++){ double eff=IsoStudiesttMC1->GetBinContent(bin)/IsoStudiesttMC0->GetBinContent(bin); double binerr=sqrt((1-eff)/IsoStudiesttMC1->GetBinContent(bin)); ttMCEff->SetBinContent(bin, eff); ttMCEff->SetBinError(bin, binerr); } bool probefirst=true; TH1D ratioh = ratiohisto(DataEff, ZMCEff); ratioh.SetName("Ratio"); ratioh.SetTitle("Ratio"); TCanvas *c = new TCanvas("Isolation Eff", "Isolation Eff"); c->cd(); TString lep; TFile *f; if(probefirst)lep= "1stLep"; else lep= "2ndLep"; TString add="2jets"; f = new TFile("MuMu_Analysis_IsoStudies_"+lep+add+".root","RECREATE"); IsoStudiesData1->Write(); IsoStudiesData0->Write(); DataEff->Write(); DataEff->Draw(); c->Print("eps/MuMuDataEff"+lep+add+".eps"); IsoStudiesZMC0->Write(); IsoStudiesZMC1->Write(); ZMCEff->Write(); ZMCEff->Draw(); c->Print("eps/MuMuMCZEff"+lep+add+".eps"); IsoStudiesttMC0->Write(); IsoStudiesttMC1->Write(); ttMCEff->Write(); ratioh.Write(); ratioh.Draw(); c->Print("eps/MuMuRatio"+lep+add+".eps"); DataEff->Draw(); ZMCEff->SetLineColor(kRed); ZMCEff->Draw("same"); c->Print("eps/MuMuDataMc"+lep+add+".eps"); c->Write(); f->Close(); std::vector<TString> samples; samples.push_back("mumu_dymumu1020.root"); samples.push_back("mumu_dymumu2050.root"); samples.push_back("mumu_dymumu50inf.root"); }
TH1D *haddHistos(TFile *fileName,TString histoName,TString ST,vector<TString> HT) { TH1::SetDefaultSumw2(); fileName->ls(); TH1D *hInit = (TH1D*)fileName->Get("ANplots"+ST+"_NOLPsecondD"+HT[0]+"/"+histoName); hInit->SetName(histoName); cout << "IN-1" << "\n"; // ---- loop over all the STbins for (int iHT=0; iHT<HT.size(); iHT++) { cout << "iHT " << iHT << "\n"; if ((HT.size()>1) && (iHT>0)) { TH1D *hTempHT = (TH1D*)fileName->Get("ANplots"+ST+"_NOLPsecondD"+HT[iHT]+"/"+histoName); hInit->Add(hInit,hTempHT,1.,1.); } } // --- end of looping over HTbins return hInit; }