Drawing mutliples file.dat in one plot!

Good Day
Dear ROOT experts
I have file1.dat, file2.dat and …ect. All of them are two columns of data. I put them in one folder and want the macro to plot them in one Tcanvas.
Because I have recently stated to use ROOT and try to develop a script below to do the job I am looking for it .
but it gives me these errors :

:‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]

I did not understand the purpose of the infile ,fileout and fileout = “.root”
because I just want to plot all the files with the extension of .dat in one plot
I appreciate any help from you allcompelete.c (1.7 KB) file1.txt (305 Bytes) file2.txt (296 Bytes) file3.txt (296 Bytes)

Thank you in advance

You better create a TMultiGraph and add all the graphs you created in it and plot the TMultiGraph when all graphs are added.

It seems okay , but I have in actual more than 50 files.txt .so I want to develop the existed script some where here.
I would be grateful if I manage it .

Doing it for 3 file of 50 is the same … just change the ending value of loop index.

That means I did not understand how TMultiGraph could manage that.

You will have 50 graph in the TMultigraph . That might a bit too much and the plot might look a bit crowded. But you said you what on all the graphs on the same plot …

my data are very similar i just want to plot the uncertainty of the code.
but I did not get how to loop all of my files in TMultigraph ,and I have not seen an example for that.

Thank

The structure of your program should be:

  Create a TMultigraph MG

  for (all your text files) {
      read the txt file
      make a TGraph out of it
      add the TGraph into MG
  }

  Draw MG;

Thank you for this helpful structure .
I have tried to build my script on light of that structure but still I face some problem .

void test()
{
   auto plots  = new TMultiGraph();
   std::vector<std::string> listOfFiles;
  std::vectorstd::string getAllFilesInDir;
   std::string dirPath = "/JEF311/CODE/ROOT/files";
   std::vector<std::string> listOfFiles = getAllFilesInDir(dirPath);
   for (auto str : listOfFiles) {
       std::cout << str << std::endl;
       gr = new TGraph(); 
       gr->SetMarkerStyle(21);
       plots->Add(gr,"AP"); 
  }
       
   plots->Draw("AL");
}

The structure woks will but problem opening file1.txt for example like cannot open or the syntax error
I hope that I could hear from you

void Grapgs09062020()
{
   auto mg  = new TMultiGraph();   
   for (int i=1; i<2; i++){
        TGraph *gr = new TGraph("./CODE/ROOT/file"+int(i)+".txt","%lg  %lg");
	mg->Add(gr,"PL");
   }
   mg->Draw("A pmc plc");
}

Thank you in advance

Which error do you get when you try to open the txt files ?

the script:
{
auto mg = new TMultiGraph();
for (int i=1; i<=4; ){
stringstream out;
out << i;
stringstream out;
out << i;
TGraph gr = new TGraph("./scratch/spallati/nassor/WORK/PYTHON_MACROS/JEF311/CODE/ROOT/file"+out.str()+".txt");
cout << “file”+out.str()+".txt" << endl;
//mg->Add(gr,“PL”);
i++;
}
//mg->Add(gr,“PL”);
mg->Draw(“A pmc plc”);
/
}

the error:
Error: Can’t call TGraph::TGraph("./JEF311/CODE/ROOT/file"+out.str()+".txt") in current scope Grapgs09062020.c:23:
Possible candidates are…
(in TGraph)
/usr/remote/prive/root/SL6-x86_64/root_v5.34.00.Linux.SL6.4.gcc447/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(void);
/usr/remote/prive/root/SL6-x86_64/root_v5.34.00.Linux.SL6.4.gcc447/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(Int_t n);
/usr/remote/prive/root/SL6-x86_64/root_v5.34.00.Linux.SL6.4.gcc447/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(Int_t n,const Int_t* x,const Int_t* y);
/usr/remote/prive/root/SL6-x86_64/root_v5.34.00.Linux.SL6.4.gcc447/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(Int_t n,const Float_t* x,const Float_t* y);
/usr/remote/prive/root/SL6-x86_64/root_v5.34.00.Linux.SL6.4.gcc447/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(Int_t n,const Double_t* x,const Double_t* y);
/usr/remote/prive/root/SL6-x86_64/root_v5.34.00.Linux.SL6.4.gcc447/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(const TGraph& gr);
/usr/remote/prive/root/SL6-x86_64/root_v5.34.00.Linux.SL6.4.gcc447/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(const TVectorF& vx,const TVectorF& vy);
/usr/remote/prive/root/SL6-x86_64/root_v5.34.00.Linux.SL6.4.gcc447/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(const TVectorD& vx,const TVectorD& vy);
/usr/remote/prive/root/SL6-x86_64/root_v5.34.00.Linux.SL6.4.gcc447/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(const TH1* h);
/usr/remote/prive/root/SL6-x86_64/root_v5.34.00.Linux.SL6.4.gcc447/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(const TF1* f,Option_t* option="");
/usr/remote/prive/root/SL6-x86_64/root_v5.34.00.Linux.SL6.4.gcc447/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(const char* filename,const char* format="%lg %lg",Option_t* option="");

Thanks

Supposing your txt file only has 2 columns:

  Char_t filename[100];
  for (int i=1; i<=4; ++i) {
    sprintf(filename,"%s%d%s","you/long/path/and/name",i,".txt");
    TGraph *gr = new TGraph(filename);
    // ...
  }

Thank your for this proposal
Yes it fits my files content.
But it gave me:
Error in TGraph::TGraph: Cannot open file: /WORK/PYTHON_MACROS/JEF311/CODE/ROOT/file4.txt, TGraph is Zombie.

I have solved it , it was issue of looping index.
Thank you very much

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