Data Structure Question - Storing Data per Event

See:
ROOT User’s Guide -> Trees -> Example 2: A Tree with a C Structure -> Writing the Tree -> Adding a Branch with a Variable Length Array
Try: [code]#include “TFile.h”
#include “TTree.h”
#include “TRandom.h”

const unsigned int kMax_Ntp = 8;

struct Data {
Int_t event;
Float_t triggerTime;
UInt_t Ntp; // note: Ntp MUST be <= kMax_Ntp
Float_t pulseAmp[kMax_Ntp];
Float_t pulseTime[kMax_Ntp];
} fDataStruct;

void trial(void) {
TFile *f = TFile::Open(“fDataFile.root”, “RECREATE”);
TTree *t = new TTree(“fDataTree”, “some tp data”);

// http://root.cern.ch/root/html/TTree.html
t->Branch(“event”, &fDataStruct.event, “event/I”);
t->Branch(“triggerTime”, &fDataStruct.triggerTime, “triggerTime/F”);
t->Branch(“Ntp”, &fDataStruct.Ntp, “Ntp/i”);
t->Branch(“pulseAmp”, fDataStruct.pulseAmp, “pulseAmp[Ntp]/F”);
t->Branch(“pulseTime”, fDataStruct.pulseTime, “pulseTime[Ntp]/F”);

gRandom->SetSeed(0);
for (int i = 0; i < 1000; i++) {
fDataStruct.event = i;
fDataStruct.triggerTime = 100.0 * i;
fDataStruct.Ntp = UInt_t((1.0 + kMax_Ntp) * gRandom->Rndm());
// just a precaution (Ntp MUST be <= kMax_Ntp)
if (fDataStruct.Ntp > kMax_Ntp) fDataStruct.Ntp = kMax_Ntp;
for (int j = 0; j < ((int)(fDataStruct.Ntp)); j++) {
fDataStruct.pulseAmp[j] = gRandom->PoissonD(10);
fDataStruct.pulseTime[j] = gRandom->Gaus(10);
}
t->Fill();
}

t->Write();
delete f; // automatically deletes “t”, too
}[/code]