I don’t know how to read the .txt files in ROOT while a semicolon exists at the end of every data.
such as “2.5; 3.6; 4.5;” .
If I use “ifstream” directly, only one data can be input and end up reading immediately.
How can I solve it? Thanks for your help.
Many thanks for your reply, I try your code, seems that it can only read the first column. My “.txt” file includes 42 columns and each data with semicolon, if I want to extract the 31th column, how can I reach it or what if I want to write them to a tree with 42 branches ? Is there an examples?
Dear Wile,
Sorry for confusion, it work when I try your code " t->Draw(“x[31]”) " to plot the data
from 31th column, it’s so convenient. Although it can draw directly, can I add some plot commands. Usually I plot the histogram by using the “TH1F” and add my preferred plot commands, such as “SetMarkerColor,SetLineColor”.
Thanks for your help.
Another problem exists in my work (the same “.txt” file), as you can see the result which is signal versus time (unit is second), it can be achieved by writing the code “t->Draw(“x[36]:x[0]/50”);” [X[0]/50 means 50 bins per second]. In this way, I try the “Project()”, however, it seems not working, how can I project the tree pointer into histogram pointer while plotting signal versus time?
I refered the example ”/home/jiangjc/root-6.16.00/tutorials/tree/temperature.C“ and the new code shows below,
TTree *t = new TTree(“t”, “t”);
t->ReadFile(“sss.txt”, “x[42]/d”, ‘;’);
int Time[3]={0,0,0};
t->GetEntry(0);
Time[1]=(int)t->GetLeaf(“x[0]”)->GetValue();
t->GetEntry(t->GetEntries() - 1);
Time[2] = (int)t->GetLeaf(“x[0]”)->GetValue();
Time[2]=Time[2]+1;
Time[0]=Time[2]-Time[1];
You can use TTree::Project and/or TTree::Draw to fill a TProfile.
Search for “Making a Profile histogram” in the TTree::Draw method description.
Try something like: t->Project("h", "x[36]:x[0]", "", "prof"); // assuming "h" is a TProfile
Thanks for your reply, actually, I want to get the values of the first column and the last column for a row, I am not sure weather I can use the function (like GetValue()) to obtain the values.