Problem with array of TLorentzVector in branch of TClonesArray

From: Anyes Taffard <>
Date: Mon, 02 May 2005 11:57:13 -0500


I am trying to put into a TTree a TClonesArray of a class that contains an array of TLorentzVector.

The content of the array of TLorentzVector is fine when the TTree has a branch of the class.
With root version 3.05/07, if the branch is a TClonesArray of that class, the LorentzVector are mostly empty apart for the 1st one. With root version 4.00/08, it's working fine.

I attached the code to make such a TTree.

Is there a way that I can get this to work with root 3.05/07 ?


.x run.C
tree(0); //to make tree
tree(1); //to read tree

#include "TFile.h"
#include "TChain.h"
#include "fit.hh"

0: write tree
1: read tree

void tree(int opt=0)

    Make a TTree with:
    2 branches for 2 instences of fit
    1 branche with a TClonesArray of fit. (This should contain fit1 & fit2, but it is not)

    to run do:
    .x run.C
    tree(0); //to make the TTree
    tree(1); //to read the TTree


   TFile* ff;
  TTree* tt;   

  //2 instances of fit class
  fit* _fit1;
  fit* _fit2;

  //TClone of Fit class
  TClonesArray* _fitA;
  fit* _fit;
  int _nFit;  

    ff = new TFile("tree.root","RECREATE","TTree File", 5);     tt = new TTree("t","A TTree");        

    _fit1 = new fit;
    _fit2 = new fit;
    tt->Branch("fit1.","fit",&_fit1, 32000, 1);     tt->Branch("fit2.","fit",&_fit2, 32000, 1);

    _fitA = new TClonesArray("fit");
    tt->Branch("fitA","TClonesArray",&_fitA,32000,2);     tt->Branch("nFit",&_nFit,"nFit/I");     

  else if(opt==1){//READ
    ff = new TFile("tree.root");
    tt = (TTree*) ff->Get("t");

    _fitA = new TClonesArray("fit");

    _fit1 = new fit;
    _fit2 = new fit;

    tt->SetBranchAddress("fit1.",&_fit1);     tt->SetBranchAddress("fit2.",&_fit2);

    tt->SetBranchAddress("fitA",&_fitA);     tt->SetBranchAddress("nFit",&_nFit);     



  Int_t nEntries=1;
    nEntries = tt->GetEntries();
    printf("Reading tree with %i entries\n",nEntries);     tt->Print();

  int lflag=0;
  int fCurrent=-999;


  for(int ev=0; ev<nEntries; ev++){
    printf("\n event %i \n",ev);     


      for(int kk=0; kk<2; kk++){ //make 2 instance of fit
	_fit = new ((*_fitA)[_nFit++]) fit();
	int X = ev+kk;
	if(kk==0) _fit1->x=X;
	if(kk==1) _fit2->x=X;
	for(int ii=0; ii<3; ii++){ //# of combinatorics
	  for(int jj=0; jj<4; jj++){ //4 jets in the event
	    float px,py,pz,e;
	    px = float(rand())/RAND_MAX *100;
	    py = float(rand())/RAND_MAX *100;
	    pz = float(rand())/RAND_MAX *100;
	    e  = float(rand())/RAND_MAX *100;
	    if(kk==0) _fit1->rawjets[ii][jj].SetPxPyPzE(px,py,pz,e);
	    if(kk==1) _fit2->rawjets[ii][jj].SetPxPyPzE(px,py,pz,e);
	  }//4 jets
	}//3 combo
      }//2 fit blocks

    }//FILL          if(opt==1){//READ

    if(opt==0 || opt==1){//DUMP

      for(int kk=0; kk<2; kk++){
	_fit = (fit*) _fitA->At(kk);
	for(int ii=0; ii<3; ii++){
	  printf("==>Combo %i \n",ii);
	  for(int jj=0; jj<4; jj++)
	    printf("====> Jets %i px %2.3f py %2.3f pz %2.3f e %2.3f \n",
      for(int ii=0; ii<3; ii++){
	printf("==>Combo %i \n",ii);
	for(int jj=0; jj<4; jj++)
	  printf("====>Fit1 Jets %i px %2.3f py %2.3f pz %2.3f e %2.3f \n",
      for(int ii=0; ii<3; ii++){
	printf("==>Combo %i \n",ii);
	for(int jj=0; jj<4; jj++)
	  printf("====>Fit2 Jets %i px %2.3f py %2.3f pz %2.3f e %2.3f \n",

    }//DUMP     if(opt==0) tt->Fill();
  }//evt loop



// Local version of HighLevelObjects
#include "fit.hh"


void fit::clear(){

  for(int i=0; i<24; i++){
    for(int j=0; j<4; j++){



#ifndef FIT_HH
#define FIT_HH

#include "TObject.h"
#include "TLorentzVector.h"
#include <iostream>

class fit : public TObject {
  ~fit() {};
  void clear();   

  int x;
  TLorentzVector rawjets[24][4]; //work when not using TCloneA of fit     


#include <TObjectTable.h>

const char* exec_name = gApplication->Argv(0); // the line below tells ROOT script compiler // where to look for the include files  

gSystem->SetIncludePath(" -I./include -I$CDFSOFT2_DIR/include -D__STANDARD_CPLUSPLUS -DDEFECT_NO_EXCEPTIONS ");

gInterpreter->ProcessLine(".! ps | grep root");


//tree(0); //make the ttree
//tree(1); //read it back

} Received on Mon May 02 2005 - 18:57:21 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:07 MET