Please read tips for efficient and successful posting and posting code
I am trying to put an array cs (which is double type) into a one-dimensional histogram, but my code have some problem,and the TH1D is like this. Can you help me to correct my code?
The following is my code:
TCanvas *c2=new TCanvas("c2","cs",600,600);
TH1D *h1=new TH1D("h1","cs",50,-5,5);
double x =cs[i];
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided
can you show the content of your array?
As for your code:
- You shouldn’t start from bin #0, so please replace
- Please move
out of the loop.
for(int i = 0; i < 50; i++) h1->SetBinContent(i + 1, cs[i]);
Thanks for your reply.This is the array:
All of your numbers are outside of (-5, +5). Then why do you try to put them in a histogram spanning (-5, +5)?
I have found this mistake and correct it and now i think it is right. Thanks for your correction.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.