Hi to all. I’m really a newbie and it’s my first approach to ROOT.
I’m trying to undestand the logics so what I wish to do is only to read a CSV file (in form N_ID, column1, column2, column3), show the content of the file within an arbitrary range (from N_ID=a to N_ID=b) and print a graph of the corresponding colums.
Hmmm, actually because you want to filter your data, I think you may have a look on RDataFrame (search for CSV). I did not try but this should work
auto tdf = ROOT::RDF::MakeCsvDataFrame("file.csv");
auto filteredEvents =
tdf.Filter("N_ID>=a && N_ID<=b");
auto g = filteredEvents.Graph("column1","column2");
g->Draw();
I tried but I received this error: “libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: Error reading headers of CSV file”.
These are the CSV (Hit.c, please change the extension in .csv) file and the ROOT code I used:
{
auto tdf = ROOT::RDF::MakeCsvDataFrame(“Hit.csv”);
auto filteredEvents =
tdf.Filter(“hit_id>=1 && hit_id<=20”);
auto g = filteredEvents.Graph(“ch0”,“ch1”);
g->Draw();
}
First, your csv file is not really clean. Remove the first lines and name properly your column in order in works “automatically”. Currently, RDataFrame cannot guess what is the name of your column. I attach an exampleHit.c (5.9 KB)
Then, it seems that the “Graph” method has been added recently and so I cannot test on my ROOT version (6.16/00). @dpiparo may confirm.
So if you do not use the ROOT master version, you may want to plot a TH2F. If so, this piece of code works (with the good CSV file)
{
auto tdf = ROOT::RDF::MakeCsvDataFrame("Hit.csv");
auto filteredEvents = tdf.Filter("hit_id>5 && hit_id<10");
auto h = filteredEvents.Histo2D({"h", "h", 100,0,1000,100,0.,1.},"ch0","value");
h->Draw("col");
}
Otherwise, you will need to parse yourself the CSV file, to store all the values in vectors and then to plot what you want using TGraph. TO know how to do, you can see this tutorial (you have to adapt the part where x and y arrays are filled).