Variable size leaf to single leaf, using TSelector

I’ve used the TTree::MakeSelector to create a selector class to go through some data, and only Store only the first leaf of a branch that has variable sized leafs, into a new rootfile.

Unfortunately, I’m getting only 0’s for each entry in the L.tr.ph branch… but sucessfully copying the data from L.tr.n branch into the new rootfile.

Here’s a snippet of the code I’m using…
(run using:

   TChain chain("T")
   chain.Add("ROOTfiles/happexsp_1073.root")
   chain.Process("src/ObtainData.C++")

I get no ALIC compilation errors).

I think these are the only relevant lines:

In ObtainData.C

void ObtainData::Begin(TTree *tree)
{
   Init(tree);

   TString option = GetOption();

   newFile = new TFile("clean_data.root","recreate");
   newTree = new TTree("C","Clean spectrometer data");

   newTree->Branch("L.tr.n",&L_tr_n,"L.tr.n/D");
   newTree->Branch("L.tr.ph",&L_tr_ph[0],"L.tr.ph/D");
}

Bool_t ObtainData::ProcessCut(Int_t entry) 
{
   return kTRUE;
}

void ObtainData::ProcessFill(Int_t entry)
{
  b_L_tr_ph->GetEntry(entry);
  b_L_tr_n->GetEntry(entry);
  newTree->Fill();
}

void ObtainData::Terminiate()
{
  newFile->Write();
  delete newTree;
  delete newFile;
}

In ObtainData.h

class ObtainData : public TSelector {
public :
   TTree          *fChain;   //!pointer to the analyzed TTree or TChain

   Double_t        L_tr_n;   
   Int_t           Ndata_L_tr_ph;
   Double_t        L_tr_ph[11];   //[Ndata.L.tr.ph]

   TBranch        *b_L_tr_n;   //!   
   TBranch        *b_Ndata_L_tr_ph;   //!
   TBranch        *b_L_tr_ph;   //!
   ObtainData(TTree *tree=0);
   ~ObtainData();
   void    Begin(TTree *tree);
   void    Init(TTree *tree);
   Bool_t  Notify();
   Bool_t  Process(Int_t entry) {return kTRUE;}
   Bool_t  ProcessCut(Int_t entry);
   void    ProcessFill(Int_t entry);
   void    SetOption(const char *option) { fOption = option; }
   void    SetObject(TObject *obj) { fObject = obj; }
   void    SetInputList(TList *input) {fInput = input;}
   TList  *GetOutputList() const { return fOutput; }
   void    Terminate();

   ClassDef(ObtainData,0);
};

#endif

ObtainData::ObtainData(TTree *tree)
{
  //
}

ObtainData::~ObtainData()
{
  //
}

#ifdef ObtainData_cxx
void ObtainData::Init(TTree *tree)
{   // Set branch addresses
   if (tree == 0) return;
   fChain = tree;
/*    fChain->SetMakeClass(1); */
   fChain->SetBranchAddress("L.tr.n",&L_tr_n);
   fChain->SetBranchAddress("Ndata.L.tr.ph",&Ndata_L_tr_ph);
   fChain->SetBranchAddress("L.tr.ph",L_tr_ph);

Bool_t ObtainData::Notify()
{
   b_L_tr_n = fChain->GetBranch("L.tr.n");
   b_Ndata_L_tr_ph = fChain->GetBranch("Ndata.L.tr.ph");
   b_L_tr_ph = fChain->GetBranch("L.tr.ph");

   return kTRUE
}
#endif // #ifdef ObtainData_cxx

Full code is attached… (in all its glory).
ObtainData.tar (70 KB)

Sorry… running this code using
ROOT 4.00/04
gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-49)

You do not define this branch as an array. I recommend that you use a compiled class instead of individual variables. Make sure to re-read the User’s Guide.

Cheers,
Philippe.

Well… I tried commenting out that line:

newTree->Branch("L.tr.ph",&L_tr_ph[0],"L.tr.ph/D");

and added a line to ProcessFill(Int_t entry):

   cout << "Entry " << entry << ": " << L_tr_ph[0] << endl;

All I get is 0’s for each entry. Looking at the original rootfile (ROOTfiles/happexsp_1073.root), I can do this:

   T->Draw("L.tr.ph[0]");

and I get a nice, non-zero, distribution.

I figured there was some trouble with the SetBranchAddress in the header file… I wrote a similar code using a different rootfile that uses fixed size array leaf’s with success. So, is there a problem with doing this with variable sized array leafs?

That would be weird! This remove the saving of this branch to the file?

[quote]and I get a nice, non-zero, distribution.
I figured there was some trouble with the SetBranchAddress in the header file… I wrote a similar code using a different rootfile that uses fixed size array leaf’s with success. So, is there a problem with doing this with variable sized array leafs?[/quote]
Well it seems I do not have enough information to reproduce or understand the problem. A running example would be helpfull,

Cheers,
Philippe.

I dont know if I’m confusing TLeaf’s with TBranch’s in this forum… I might be…

At any rate… discovered what the problem was with my code…

In the rootfile that I’m working with, the size of the variable size array for each event is stored in another branch (prepended with “Ndata.”). So, I need to get the size of the array before I get the array…
i.e.

b_Ndata_L_tr_ph->GetEntry(entry); // Needed this line b_L_tr_ph->GetEntry(entry);

Without that line… the Double_t array containing the b_L_tr_ph entry wasn’t obtained properly (perhaps a array size mismatch).

Thanks anyway… my bad. :blush: