Hi Dave,
I have modified your example below to be a script executable
from an interactive Root session.
do
root > .x Dave.C
root > tree->Draw("test.fE");
We give a complete example of TClonesArray with a Tree at
$ROOTSYS/test/mainEvent.cxx, Event.cxx
Rene Brun
//------------script Dave.C
{
// load library libPhysics that contains TLorentzVector
// this lib is not linked by default
gSystem->Load("libPhysics");
// create file and tree...
TFile *f = new TFile("zzz.root", "RECREATE");
TTree *tree = new TTree("T", "Testing TClonesArrays");
// create pointer to TClonesArray
TClonesArray *a = new TClonesArray("TLorentzVector");
TClonesArray &aa = *a;
// define branch in tree by passing the address of the pointer to the
// TClonesArray...
tree->Branch("test", &a);
// create 1000 TLorentzVectors in a loop.
for (Int_t i=0;i<1000;i++) {
new(aa[i]) TLorentzVector(1,2,3,i);
}
// fill tree... (likely to be in a loop)
tree->Fill();
// write tree to file...
f->Write();
//delete f;
}
Dave Ireland wrote:
>
> Hi,
>
> This is basically a plea for advice from a novice, so I apologise in
> advance if there is a simple answer. I have scoured the ROOT website and
> others, so this is really a last resort!
>
> After successfully creating a tree of TLorentzVectors, I want to extend
> this to create a simple tree of TClonesArrays of TLorentzVectors, so I
> try to do this using the following code:-
>
> // create file and tree...
> TFile *f = new TFile("zzz", "RECREATE");
> TTree *tree = new TTree("T", "Testing TClonesArrays");
>
> // create pointer to TClonesArray
> TClonesArray *a = new TClonesArray("TLorentzVector");
>
> // define branch in tree by passing the address of the pointer to the
> // TClonesArray...
> tree->Branch("test branch", &a);
>
> // create TLorentzVectors by some means (eventually to be part of a
> loop), e.g.
> TLorentzVector *p = new TLorentzVector(1,2,3,4);
>
> //*****
> //***** WHAT CODE SHOULD GO HERE TO INSERT THE TLorentzVector OBJECT
> //***** INTO THE TClonesArray?????
> //*****
> //*****
>
> // fill tree...
> tree->Fill();
>
> // write tree to file...
> f->Write();
>
> I have tried a few things, none of which were successful. I would be
> grateful for any suggestions.
>
> Cheers,
>
> Dave
>
> --------------------------------------------------------------------------------
>
> Dave Ireland <d.ireland@physics.gla.ac.uk>
> Nuclear Physics Group
> Department of Physics and Astronomy
> University of Glasgow
>
> Dave Ireland
> Nuclear Physics Group <d.ireland@physics.gla.ac.uk>
> Department of Physics and Astronomy
> University of Glasgow
> University Avenue Fax: (+44/0) 141 330 5889
> Glasgow Work: (+44/0) 141 339 8855 ext. 0981
> Scotland Netscape Conference Address
> G12 8QQ
> Great Britain
> Additional Information:
> Last Name Ireland
> First Name Dave
> Version 2.1
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:37 MET