I want to use an array of C structres to make a tree. Firstly, I define the C structre:
typedef struct {
Int_t Nrun;
Int_t Nevt;
Int_t Ndate;
Int_t Ntime;
Int_t Nhits_id;
Float_t Qsk_id[11146]; //[Nhits_id]
Float_t Tsk_id[11146]; //[Nhits_id]
Int_t Icab_id[11146]; //[Nhits_id]
}SUBEVENT;
And then I declare an array of this C structre and use it to make a tree.
void makeFOGEvent(){
SUBEVENT subEvt[501];
TFile *fogtree;
TTree *t1;
fogtree = new TFile("../data/fog.root","RECREATE");
t1 = new TTree("t1","fog tree");
TString s;
Int_t i;
//make 501 branches
//each branch helds a sub-event,i.e. a C strctre
for (i = 0; i < 501; i++){
s.Form("%d",i);
s = "subevt_"+ s;
t1->Branch(s,&subEvt[i],"Nrun/I:Nevt/I:Ndate/I:Ntime/I:Nhits_id/I:Qsk_id[Nhits_id]/F:Tsk_id[Nhits_id]/F:Icab_id[Nhits_id]/I");
}
for (i = 0; i < 100; i++){ // generate 100 events
for (Int_t j = 0; j < 501; j++){
//do assignment for subEvt[j] here
}
t1->Fill();
}
fogtree->Write();
fogtree->Close();
}
Everything goes well but the result is confusing.When I examine the tree I find that it is not properly filled as expectation. Qsk_id[] is filled properly but the contents of Tsk_id[] and Icab_id[] are always just the same as Qsk_id rather than the contents they should be filled.That’s quite strange.
Do you know what the problem is?
Thanks very much!