#include "TFile.h" #include "TCanvas.h" #include "TStyle.h" #include "TH1.h" #include "TH2.h" #include "TH3.h" #include "TGaxis.h" #include "TRandom.h" #include "TLegend.h" #include "TPaveStats.h" #include "TGraph.h" #include "TSystem.h" #include "TTree.h" #include "TTreePlayer.h" #include "TF1.h" #include "TCut.h" #include "TPaletteAxis.h" #include "TFitResult.h" #include "TMath.h" #include "TGraphQQ.h" #define n 500 int sigmaorder=16; double Ebeam=281.8; char outfileresidual[100]; char outfileqqplot[100]; double res[n], x[n]; void chi2test() { float fillcolor=0.35; TH1::AddDirectory(false); gStyle->SetOptFit(); gStyle->SetFitFormat("8.6g"); gStyle->SetOptStat(111110); sprintf(outfileresidual,"zsigmanorm_Chi2Test_Residual_Ep=%.1lf_sigma=-%d.png",Ebeam,sigmaorder); sprintf(outfileqqplot,"zsigmanorm_Chi2Test_qqplot_Ep=%.1lf_sigma=-%d.png",Ebeam,sigmaorder); TString Geant3FileName = "/Users/moneta/Downloads/ebeam281.8_eres272.65_full.root"; TString Geant4FileName = "/Users/moneta/Downloads/G4Simulation.root"; TFile *fin = TFile::Open(Geant3FileName); TFile *fin2 = TFile::Open(Geant4FileName); TGaxis::SetMaxDigits(3); if (fin == nullptr || fin2 == nullptr ) { printf("Error: cannot open the file!\n"); } else { TTree *t1=0; TTree *t2=0; fin->GetObject("h1",t1); fin2->GetObject("Tree1",t2); if (t1 == nullptr || t2 == nullptr ) { printf("Error: cannot get the trees!\n"); return; } gStyle->SetOptFit(); gStyle->SetOptStat(111110); t1->SetLineColor(kBlue); t2->SetLineColor(kGreen); TH1::StatOverflows(true); // c01->SetLogy(); t1->Draw("zint>> htemp1(500, -100., 400.)","","HIST"); TH1F *htempt1 = (TH1F*)gPad->GetPrimitive("htemp1"); t2->Draw("Zint>> htemp2(500, -100., 400.)", "","HIST SAME"); TH1F *htempt2 = (TH1F*)gPad->GetPrimitive("htemp2"); int Nentries1=htempt1->GetEntries(); int Nentries2=htempt2->GetEntries(); htempt1->Scale(1./Nentries1); htempt2->Scale(1./Nentries2); htempt1->Chi2Test(htempt2,"WW OF UF P",res); //Graph for Residuals for (Int_t i=0; iGetBinCenter(i+1); TGraph *resgr = new TGraph(n,x,res); //resgr->GetXaxis()->SetRangeUser(-100,400); //resgr->GetYaxis()->SetRangeUser(0.,0.); resgr->GetYaxis()->SetTitle("Normalized Residuals"); resgr->SetMarkerStyle(21); resgr->SetMarkerColor(2); resgr->SetMarkerSize(.9); resgr->SetTitle(""); //Quantile-Quantile plot TF1 *f = new TF1("f","TMath::Gaus(x,0,1)",-10,10); TGraphQQ *qqplot = new TGraphQQ(n,res,f); qqplot->SetMarkerStyle(20); qqplot->SetMarkerColor(2); qqplot->SetMarkerSize(.9); qqplot->SetTitle(" "); TCanvas *c01 = new TCanvas("c01","c01",1280,1024); resgr->Draw("AP"); c01->Print(outfileresidual); TCanvas *c02 = new TCanvas("c02","c02",1280,1024); qqplot->Draw("AP"); c02->Print(outfileqqplot); //delete c01; //delete c02; } }