This question is about the TGraph constructor taking a file name as input.
TGraph(const char* filename, const char* format = "%lg %lg", Option_t* option = "")
Is there a convenient way to have this function skip the first line (or first n lines) of the file? This would be really convenient as it could store header information.
Thanks in advance!
I use the TTree and TNtuple ReadFile method to read the text files, then make TGraphs from that.
http://root.cern.ch/root/html/TTree.html#TTree:ReadFile
Here’s one of my methods that uses the technique:
http://bazaar.launchpad.net/~jfcaron/+junk/Proto2BeamTest2/view/head:/t2x.C#L118
The key is the ReadFile method, which ignores lines starting with #, and then using the TNtuple::Draw method with “x:y” so that it doesn’t make a histogram but a Graph in memory. Then you can to TNtuple::GetV1(), GetV2() to get the vectors of values to construct your own TGraph.
Jean-François
Regarding the construction of a TGraph directly from file, I think that if you simply start the line with a character different from a digit, ROOT will understand and skip it. From the few tests I have made, it doesn’t even need to be the first line, you can put text in a line between data.