Loop over TLorentzVector in TTree

hi,

i’m filling a root ntuple TTree as follows in a C++ framework:

TTree* tree= new TTree("T1","...");
TClonesArray* mc_data= new TClonesArray("TLorentzVector", 10000);
tree->Branch("mc_data", "TClonesArray", &mc_data, 32000, 0);
...
for (int index.....){
TLorentzVector a(0.0,0.0,0.0,0.0);
a.SetPxPyPzE(p.px(),p.py(),p.pz(),p.energy());
new((*mc_data) [index]) TLorentzVector(a);
}
...
tree->Fill();

if I access root and load the corresponding root file, one can use:
T1->Draw(“mc_data.M()”)
to plot the data to a histogram.

But for further analysis i would need to access the TBranch mc_data and loop over every single entry (TLorentzVector) to execute mc_data.M() and fill value by value into a TH1F?

thanks for help
Flo

Hi,

See the User’s Guide chapter on reading TTrees; see also the example $ROOTSYS/test/MainEvent.cxx; You have many options, including writing a TSelector by hand or using the result of MakeProxy.

Cheers,
Philippe.

PS. The ‘simple’ case (which does lend itself well to use Proof) is as follow:TClonesArray* mc_data = 0; tree->SetBranchAddress("mc_data",&mc_data); for(Long64_t index = 0; index < tree->GetEntries(); ++index) { tree->GetEntry(index); for(Int_t i = 0; i < mc_data->GetEntries(); ++i) { TLorentzVector *vec = (TLorentzVector*)mc_data->At(i); } }

Cheers,
Philippe.

thank you very much…this helped me a lot
best regards