i have data that is made of 131 column, the first column is time,the other is data.So i want to draw each of the data vs time. I want to use tree.
FILE *fp;
fp=fopen(“data.txt”,“r”);
float column[131];
TTree *tree=new TTree(“tree”,“data from ascii file”);
tree->Branch(“column[0]”,&column[0],“column[0]/F”);
tree->Branch(“column[1]”,&column[1],“column[1]/F”);
……
tree->Branch(“column[130]”,&column[130],“column[130]/F”);
while(!feof(fp))
{
fscanf(fp,"%f %f %f……“,&column[0],&column[1],……,&column[130]);
tree->Fill();
}
Is there other way?
thanks!
pcanal
September 25, 2006, 2:58pm
3
Please do not post twice the same question.
Please bear with us while we come back to work after the week-end.
Philippe
[quote=“pcanal”]Please do not post twice the same question.
Please bear with us while we come back to work after the week-end.
Philippe[/quote]
Sorry !
130 Column,I must write 130 branches,it is so diffcult.
LOOP ?
for(i=0;i<130>Branch(“column[i]”,&column[i],“column[i]/F”);
ok?
Thanks!
volpig
September 26, 2006, 7:49am
5
The shortest way is fill the TTree with the array as is the array is dynamic: you must add only an integer with the length of the array:
Int_t nels = 131;
Float_t vals[131];
tree->Branch("nels",&nels,"nels/I");
tree->Branch("vals",vals,"vals[nels]/F");
for (...) {
vals[0] = ...
vals[1] = ...
...
tree->Fill();
}
[quote=“volpig”]The shortest way is fill the TTree with the array as is the array is dynamic: you must add only an integer with the length of the array:
[code]
Int_t nels = 131;
Float_t vals[131];
tree->Branch(“nels”,&nels,“nels/I”);
tree->Branch(“vals”,vals,“vals[nels]/F”);
for (…) {
vals[0] = …
vals[1] = …
…
tree->Fill();
}
[/code][/quote]
what is the meaning of
tree->Branch(“nels”,&nels,“nels/I”);
tree->Branch(“vals”,vals,“vals[nels]/F”);
thanks!
can it use tntuple?
pcanal
October 9, 2006, 2:34pm
7
Please re-read the User’s Guide chapter on TTree (you will find the detailed answer).
[quote]can it use tntuple?[/quote]TNtuple should only be used for very simple case (aka only single float variables).
Cheers,
Philippe
Please re-read the User’s Guide chapter on TTree (you will find the detailed answer).
[quote]can it use tntuple?[/quote]TNtuple should only be used for very simple case (aka only single float variables).
Cheers,
Philippe[/quote]
Thank you very much!
I have finished my work with you help!