Dear ROOT experts,
I am posting a program which runs in ROOT v5. When I subtract two histograms, the difference does not look as it should; the two histograms have roughly the same value over a large range and yet the difference is not zero there. As the two histograms I’m subtracting come from profiles of 2D histograms, I’ve checked that the profiling is done correctly. The lines to focus on in my macro are the last 5-10. Any help is much appreciated.
Thanks,
Enny
{
gStyle->SetTitleSize(0.05,"XY");
gStyle->SetTitleOffset(.9, "XY");
gStyle->SetStatY(0.9);
gStyle->SetStatX(0.9);
hDummy = new TH2D("hDummy","hDummy",1000,0,80,1000,0,3);
hDummy->Draw("axis");
hDummy->GetXaxis()->SetTitle("TOF [ns]");
hDummy->GetYaxis()->SetTitle("Momentum [MeV/c]");
hDummy->GetXaxis()->CenterTitle();
hDummy->GetYaxis()->CenterTitle();
TCanvas *c1 = new TCanvas("c1", "c1",18,41,700,500);
c1->Range(24,50,40,70);
TH2D *Electron = new TH2D("Electron","",100,0.,2.0,100,30,60);
for(int i=0; i<1000; i++){
double d =10;
double Me=0.000511;
double p =gRandom->Uniform(0., 2.0);
double Nrandom= gRandom->Gaus(1,0.01);
double p_z = p*Nrandom;
double x = TMath::Power((p/Me),2);
double v1 = sqrt(x/(1+x));
double v = sqrt(x/(1+x))*(3*1e8);
double t = (d/v)/ 0.000000001;
double Nrandomt= gRandom->Gaus(0,0.2);
double tof= t+Nrandomt;
Electron->Fill(p_z,tof);
}
TH2D *Pion = new TH2D("Pion","",100,0.,2.0,100,30,60);
for(int i=0; i<10000; i++){
double d =10;
double Mp=0.136;
double p =gRandom->Uniform(0., 2.0);
double Nrandom= gRandom->Gaus(1,0.01);
double p_z = p*Nrandom;
double x = TMath::Power((p/Mp),2);
double v1 = sqrt(x/(1+x));
double v = sqrt(x/(1+x))*(3*1e8);
double t = (d/v)/ 0.000000001;
double Nrandomt= gRandom->Gaus(0,0.2);
double tof= t+Nrandomt;
Pion->Fill(p_z,tof);
}
Electron->Draw();
Pion->Draw("SAME");
TH1D *h1Electron = Electron->ProfileX();
h1Electron->Draw();
TH1D *h1Pion = Pion->ProfileX();
h1Pion->Draw();
h1Electron->Draw("SAME");
// h1Pion->Print("all");
// h1Electron->Print("all");
TH1D* hDiff = (TH1D*)h1Pion->Clone("hDiff");
// TH1D *hDiff = (TH1D*)
// h1Pion->Clone("hDiff");
hDiff->Add(h1Electron, -1);
hDiff->Draw("SAME");
// h1Pion->Print("all");
}
ROOT Version: 5.34
Platform: Not Provided
Compiler: Not Provided