hDiff is the subtraction of Electron from Pion. That’s working fine now, thanks to you all. Right now, I’m trying to get the actual values of hDiff and its errors, then loop over it and make a plot of momentum on the x-axis versus value/error of each point on the y-axis. This is the code I’m trying to make work:
histo2 ->hDiff->clone();
for (i=0;GetNBins;i++){
value = hDiff->GetBin(i);
error->GetBinError(i);
histo2->SetBin(value/error,i);
}
This is the larger code.
Thanks in anticipation for a favorable response
{
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,20);
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,250,30,1000);
for(int i=0; i<10000; i++){
double d =10;
double Me=0.000511;
double p =gRandom->Uniform(0., 2.0);
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,tof);
}
TH2D *Pion = new TH2D("Pion","",100,0.,2.0,250,30,1000);
for(int i=0; i<10000; i++){
double d =10;
double Mp=0.136;
double p =gRandom->Uniform(0., 2.0);
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,tof);
}
TH1D *h1Electron = Electron->ProfileX();
TH1D *h1Pion = Pion->ProfileX();
h1Pion->Print("all");
h1Electron->Print("all");
TH1D* hDiff = (TH1D*)h1Pion->Clone("hDiff");
hDiff->Add(h1Electron, -1);
hDiff->Print("all");
hDiff->Draw();
histo2 ->hDiff->clone();
for (i=0;GetNBins;i++){
value = hDiff->GetBin(i);
error->GetBinError(i);
histo2->SetBin(value/error,i);
}
histo2->Draw("SAME");
// hDiff->Print("all");
}