Dear Experts I am trying to divide two histograms Total Energy/Photon Energy:
After division only 54 Entries are visible: Please check if this correct
#include "TGraphErrors.h"
#include "TF3.h"
#include "TRandom.h"
#include "TCanvas.h"
#include "TLegend.h"
#include "TMath.h"
void draw_Performance(Int_t nevent = -1)
{
gROOT->ForceStyle();
//==========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("CalCR1K.edm4hep.root"); // Tree with tracks and hits
// Create the tree reader and its data containers
TTreeReader myReader("events", file); // name of tree and file
TTreeReaderArray<Float_t> energy(myReader, "LumiDirectPCALHits.energy");
TH1F* h1P = new TH1F("h100", "Photon;Energy (GeV);Counts", 100, 0, 20);
//////////////////////////////////////////////////////////////////////
int count = 0;
while (myReader.Next())
{
if (nevent > 0 && count > nevent)
continue;
// MC Particle
for (int iHit = 0; iHit < energy.GetSize(); iHit++){
h1P->Fill(energy[iHit]);
count++;
}
}
h1P->Draw("colz");
h1P->GetXaxis()->SetTitle("E (GeV)");
h1P->GetXaxis()->SetRangeUser(0., 12);
h1P->SetTitle("Photon Energy");
h1P->GetYaxis()->SetTitle("Counts");
// Open the ROOT file
TFile* file1 = new TFile("output.root");
file1->ls();
TH1F * h2 = (TH1F*)file1->Get("h1E");
TCanvas* canvas = new TCanvas("canvas", "Histogram", 800, 600);
h2->Draw("hist");
h2->GetXaxis()->SetTitle("E (GeV)");
h2->GetXaxis()->SetRangeUser(0., 30);
h2->SetTitle("Total Energy");
h2->GetYaxis()->SetTitle("Counts");
// Create a new histogram for the division result
TH1F* hDivision = (TH1F*)h2->Clone("hDivision");
hDivision->Divide(h1P);
// Create a canvas and draw the graph
TCanvas* canvas1 = new TCanvas("canvas1", "Histogram", 800, 600);
hDivision->SetTitle("Ratio vs Counts");
hDivision->GetXaxis()->SetTitle("Ratio(E_Total/E_Photon)");
hDivision->GetYaxis()->SetTitle("Counts");
hDivision->Draw("colz");
}