Dosa
June 8, 2020, 1:38pm
1
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
couet
June 8, 2020, 1:49pm
2
You better create a TMultiGraph and add all the graphs you created in it and plot the TMultiGraph when all graphs are added.
Dosa
June 8, 2020, 1:59pm
3
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 .
couet
June 8, 2020, 2:01pm
4
Dosa:
more than 50 files.txt
Doing it for 3 file of 50 is the same … just change the ending value of loop index.
Dosa
June 8, 2020, 2:06pm
5
That means I did not understand how TMultiGraph could manage that.
couet
June 8, 2020, 3:13pm
6
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 …
Dosa
June 8, 2020, 3:22pm
7
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
couet
June 8, 2020, 3:36pm
8
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;
Dosa
June 8, 2020, 6:25pm
9
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");
}
Dosa
June 9, 2020, 6:49am
11
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
couet
June 9, 2020, 12:09pm
12
Which error do you get when you try to open the txt files ?
Dosa
June 9, 2020, 12:18pm
13
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);
// ...
}
Dosa
June 9, 2020, 1:03pm
15
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.
Dosa
June 9, 2020, 1:06pm
16
I have solved it , it was issue of looping index.
Thank you very much
system
Closed
June 23, 2020, 1:06pm
17
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.