Division of Histogram

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
hist1


#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");

  
 
	}

I guess that might be possible but @moneta will know better.
Also, note you draw a TH1F with option COLZ which is not valid for 1D histogram.

Hi,
After performing a manipulation of the histograms, like dividing them, the number of entries is computed as the number of effective entries of th histograms ( (total sum of weight)^2/(total sum of weight^2). So looking at your histogram it is expected that you have a value of 54

Lorenzo

Ok Thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.