A simple one. You must be very careful with the structs.
You can only have in the same branch data types of the same sizeof.
Rene Brun
typedef struct{
int eventnr;
int count;
float meas[100];
} event_struct;
void struct()
{
TFile f("struct.root","recreate");
TTree T("T","test struct");
event_struct event;
T.Branch("first",&event.eventnr,"eventnr/I:count/I:meas[count]/F");
for (Int_t i=0;i<1000;i++) {
event.eventnr = i;
event.count = 100*gRandom->Rndm();
for (Int_t j=0;j<event.count;j++) event.meas[j] = i+j;
T.Fill();
}
T.Print();
T.Write();
}
On Sun, 29 Oct 2000, Stephen Adler wrote:
> Thanks Rene,
>
> Do you have an example of a structure? .i.e.
>
>
> {
> TFile *f = new TFile("peter.root","recreate");
> Int_t nPhot;
> struct PhotStr {
> Float_t E;
> Float_t Px;
> Float_t Py;
> Float_t Pz;
> Float_t Arm;
> Float_t PhotProb;
> } Phot[500];
>
> TTree* nEmcPhotons = new TTree("nEmcPhotons","EMC Photons");
>
> //
> // How would the branch creation code be modified below?
> //
>
> nEmcPhotons->Branch("nPhot",&nPhot,"nPhot/I");
> nEmcPhotons->Branch("E",E,"E[nPhot]/F");
> nEmcPhotons->Branch("Px",Px,"Px[nPhot]/F");
> nEmcPhotons->Branch("Py",Py,"Py[nPhot]/F");
> nEmcPhotons->Branch("Pz",Pz,"Pz[nPhot]/F");
> nEmcPhotons->Branch("Arm", Arm,"Arm[nPhot]/F");
> nEmcPhotons->Branch("PhotProb", PhotProb,"PhotProb[nPhot]/F");
>
> for (Int_t i=0;i<1000;i++) {
> nPhot = 500*gRandom->Rndm();
> for (Int_t j=0;j<nPhot;j++) {
> Phot[j].E = j;
> Phot[j].Px = j+1;
> Phot[j].Py = j+2;
> Phot[j].Pz = j+3;
> Phot[j].Arm = j+4;
> Phot[j].PhotProb = j+5;
> }
> nEmcPhotons->Fill();
> }
> nEmcPhotons->Print();
> nEmcPhotons->Write();
> f->Close();
> delete f;
> }
>
>
> On Oct 29, 10:05pm, Rene Brun wrote:
> > Subject: Re: [ROOT] variable length "arrays"
> > Hi Stephen,
> > You can find an example below
> >
> > Rene Brun
> >
> >
> >
> > {
> > TFile *f = new TFile("peter.root","recreate");
> > Int_t nPhot;
> > Float_t E[500];
> > Float_t Px[500];
> > Float_t Py[500];
> > Float_t Pz[500];
> > Float_t Arm[500];
> > Float_t PhotProb[500];
> >
> > TTree* nEmcPhotons = new TTree("nEmcPhotons","EMC Photons");
> > nEmcPhotons->Branch("nPhot",&nPhot,"nPhot/I");
> > nEmcPhotons->Branch("E",E,"E[nPhot]/F");
> > nEmcPhotons->Branch("Px",Px,"Px[nPhot]/F");
> > nEmcPhotons->Branch("Py",Py,"Py[nPhot]/F");
> > nEmcPhotons->Branch("Pz",Pz,"Pz[nPhot]/F");
> > nEmcPhotons->Branch("Arm", Arm,"Arm[nPhot]/F");
> > nEmcPhotons->Branch("PhotProb", PhotProb,"PhotProb[nPhot]/F");
> >
> > for (Int_t i=0;i<1000;i++) {
> > nPhot = 500*gRandom->Rndm();
> > for (Int_t j=0;j<nPhot;j++) {
> > E[j] = j;
> > Px[j] = j+1;
> > Py[j] = j+2;
> > Pz[j] = j+3;
> > Arm[j] = j+4;
> > PhotProb[j] = j+5;
> > }
> > nEmcPhotons->Fill();
> > }
> > nEmcPhotons->Print();
> > nEmcPhotons->Write();
> > f->Close();
> > delete f;
> > }
> >
> > On Sun, 29 Oct 2000, Stephen Adler wrote:
> >
> > > I'm trying to build a root tree with variable length arrays. In the
> > > old days of paw/ntuples, using column wise ntuples, one was able to
> > > define an array with a length as in
> > >
> > > alen[0:250],tracks[1:alen]
> > >
> > > or something like that. I can't remember the paw/ntuple columb-wise
> > > syntax becuase I haven't used it in years. In anycase, I want to do
> > > the same with a root tree. Do I define a branch inside a branch or
> > > something like that?
> > >
> > > Cheers. Steve.
> > >
> >-- End of excerpt from Rene Brun
>
>
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:36 MET