Hello,
I am trying to create a TTree from .data file. In the created tree it shows a peak for zero value but I do not have that much zero values in my .data file. Also when I tries to create a Graph from TTree its showing a peak on zero (I know its a peak from that zero values in TTree).
My .data file contains the data as follows:
0.00000E+000 0.00000E+000
9.17901E-002 0.00000E+000
1.67826E+000 0.00000E+000
6.01173E+000 0.00000E+000
1.33240E+001 0.00000E+000
2.35291E+001 0.00000E+000
3.55956E+001 0.00000E+000
4.56842E+001 0.00000E+000
5.84960E+001 0.00000E+000
7.44566E+001 0.00000E+000
9.27239E+001 1.76700E+003
1.37519E+002 5.03136E+004
1.65527E+002 7.21957E+004
1.97128E+002 9.13714E+004
2.32802E+002 1.08158E+005
2.73069E+002 1.23016E+005
3.20092E+002 1.35843E+005
3.72603E+002 1.47928E+005
4.29188E+002 1.58354E+005
4.89731E+002 1.66193E+005
5.52941E+002 1.74687E+005
6.21189E+002 1.81530E+005
6.93685E+002 1.88233E+005
7.70277E+002 1.93716E+005
8.50568E+002 1.98671E+005
9.32825E+002 2.03386E+005
1.02123E+003 2.07703E+005
My code is as below:
data.h
#include “TROOT.h”
#include
class data {
public:
float Time,S0;
};
main.c
#include “data.h”
data d;
main()
{
treew();
drawGraph();
}
void treew() {
FILE *fp = fopen(“data.data”,“r”);
char line[81];
TFile *f = new TFile(“ABC.root”,“RECREATE”);
TTree *tree = new TTree(“T”,“Data from ascii file”);
tree->Branch(“Time”,&d.Time,“Time/F”);
tree->Branch(“S0”,&d.S0,“S0/F”);
// fill the tree from the values in ASCII file
while (fgets(&line,80,fp)) {
sscanf(&line[0],"%f%f",&d.Time,&d.S0);
tree->Fill();
}
// check what the tree looks like
tree->Print();
fclose(fp);
f->Write();
}
void drawGraph()
{
TGraph *gr1;
TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
dir.ReplaceAll("main.c","");
dir.ReplaceAll("/./","/");
TFile *f1 = TFile::Open("ABC.root");
TTree *T1 = (TTree*)f1->Get("T");
TCanvas *c = new TCanvas("Tree", "Tree", 0, 0, 1000, 1000);
T1->Draw("S0:Time", "", "same");
gr1 = new TGraph(T1->GetSelectedRows(),T1->GetV2(), T1->GetV1());
gr1->Sort();
gr1->SetLineColor(55);
TMultiGraph *mg = new TMultiGraph();
mg -> Add(gr1);
mg -> Draw("AC");
rootFile->Close();
}
The t and s1 values appears in TTree and Graph as shown in the file attached here with.
Please guide me how to overcome with this error OR what further modifications to be needed.
Thank you.
