1D projection from a 2D histogram

Below is the code I’m trying to change from 2D histogram to 1D histogram.
What do I need to know to make the code works

Thanks

 { 
TH2D *Electron = new TH2D("Electron","",1500,0.,2.0,1500,30,60);
for(int i=0; i<10; 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,2);
    double tof= t+Nrandomt;
    
    
    Electron->Fill(p_z,tof);
    
  } 
TH1D *h1Electron = Electron->ProjectionX();
  h1Electron->Draw();
}

What’s your problem? I can’t see any obvious problem in your code.

[quote=“Hennyorlar, post:3, topic:30662, full:true”]
Thanks,

I’m trying to change the scatter plots I got from the 2D histogram to a 1D histogram

This is the 1D projection I get whenever I run the code, but I ought to be getting something that looks much like a histogram, and not what I’m seeing right now.

Here is the original 2D plot I’m trying to project.

But that looks like a histogram to me. Maybe put in more statistics or use coarser binning?

Thanks, I will do that and get back to you!

aybe put in more statistics or use coarser binning? i think so too

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