#include "TGraphErrors.h" #include "TF1.h" #include "TF2.h" #include "TF3.h" #include "TRandom.h" #include "TCanvas.h" #include "TLegend.h" #include "TMath.h" void draw_Performance(Int_t nevent=-1) { //==========Style of the plot============ gStyle->SetPalette(1); gStyle->SetOptTitle(1); gStyle->SetTitleOffset(.85, "X"); gStyle->SetTitleOffset(.85, "Y"); gStyle->SetTitleSize(.04, "X"); gStyle->SetTitleSize(.04, "Y"); gStyle->SetLabelSize(.04, "X"); gStyle->SetLabelSize(.04, "Y"); gStyle->SetHistLineWidth(2); gStyle->SetOptFit(1); gStyle->SetOptStat(0); //=======Reading the root file DD4HEP=========== TFile* file = new TFile("bremge2v.root"); // Tree with tracks and hits // Create the tree reader and its data containers TTree* t = (TTree*)file->Get("bremTree"); // Declare the variable to store the branch data Double_t phot_en; // Make sure the type matches the branch type // Set the branch address to read into the variable 'phot_en' t->SetBranchAddress("phot_en", &phot_en); const int ngraph = 2; TCanvas* c[ngraph]; for (int i = 0; i < ngraph; ++i) { c[i] = new TCanvas(Form("c%d", i), Form("c%d", i), 1200, 1000); c[i]->SetMargin(0.09, 0.1, 0.1, 0.06); } TH1F* hist = new TH1F("hist", "Photon_Energy", 100, 0, 10); hist->GetXaxis()->SetTitle("E(GeV)"); hist->GetYaxis()->SetTitle("Counts)"); hist->GetXaxis()->CenterTitle(); for (int i = 0; i < t->GetEntries(); i++) { t->GetEntry(i); hist->Fill(phot_en); } c[0]->cd(); hist->Draw(); c[0]->SaveAs("hist_distribution.png"); // Open the ROOT file containing the histogram TFile* file1 = TFile::Open("totdeposit.root"); file1->ls(); TH1F *h1 = (TH1F*)file1->Get("h1E"); // Plot the histogram h1E on a separate canvas //TCanvas* c1 = new TCanvas("c1", "h1E Canvas", 800, 600); h1->GetXaxis()->SetTitle("E(GeV)"); h1->GetYaxis()->SetTitle("Counts"); c[1]->cd(); h1->Draw(); TH1F* resultHist = dynamic_cast(hist->Clone("resultHist")); resultHist->Divide(h1); // Create a canvas to draw the resulting histogram TCanvas* c2 = new TCanvas("c2", "Resulting Histogram", 800, 600); c2->SetMargin(0.09, 0.1, 0.1, 0.06); // Draw and save the resulting histogram c2->cd(); resultHist->GetXaxis()->SetTitle("E(GeV)"); resultHist->GetYaxis()->SetTitle("Counts"); resultHist->Draw(); c2->SaveAs("Resulting_Histogram.png"); }