Draw Histogram from .txt file. I tried with the already available answers, but didn't work for me

___a.txt (33.0 KB)
Please read tips for efficient and successful posting and posting code

_ROOT Version: ROOT 6.14/06
_Platform:Ubuntu 18.04
Compiler: Not Provided


One possible way:

{
   int    i=0;
   FILE   *fp;
   fp = fopen("a.txt","r");

   float x;

   int n =  ??? 
   float xmin = ???  
   float xmax = ???
   
   auto h = new TH1F("h","h",n,xmin,xmax);

   while (!feof(fp)) {
      fscanf(fp,"%g\n",&x);
      i++;
      h->SetBinContent(i,x);
   }
   h->Draw();
}

{
  TTree *t = new TTree("t", "my tree");
  t->ReadFile("a.txt", "x/D");
  TCanvas *c = new TCanvas("c", "my canvas");
  c->Divide(1, 2);
  c->cd(1);
  t->Draw("x");
  gPad->SetLogy(1);
  c->cd(2);
  t->Draw("x:Entry$");
  c->cd(0);
}

Thanks. I already found the solution. But this one also working for me. Greetings.

Thank you. :slightly_smiling_face: