Reading from two TTrees

Hello,

I am trying to read simultaeouly from two tree with the same number of events, t1 and t2, but the variable taken from t1 are not correctly retrieved (cout yields “0” for zet[4] and aoq[4]). I have checked their type in t1, and they are really array of doubles.

Do you see the reason?
Thanks in advance.
Anna

[code]
#include <TStyle.h>
#include <TCanvas.h>
#include <TMath.h>
#include <TGraph2D.h>
#include <TH2Poly.h>
#include <TClonesArray.h>
#include
#include
#include
#include
#include <TVector3.h>
#include <TString.h>
#include <TROOT.h>
#include <TRint.h>
#include <TTree.h>
#include <TFile.h>
#include <TCutG.h>
#include <TChain.h>
#include <TH1F.h>
#include <TH2.h>
#include <TH2F.h>
#include <TF1.h>
#include <TH3.h>
#include <TH3F.h>
#include <TF3.h>
#include <TMarker3DBox.h>
#include <TStyle.h>
#include <TCanvas.h>
#include <TMath.h>
#include <TGraph.h>
#include <TGraph2D.h>
#include <TRandom2.h>
#include <TStyle.h>
#include <TF2.h>
#include <TH1.h>
#include <TMinuit.h>
#include <TVirtualFitter.h>
#include <TFitter.h>
#include <TPolyLine3D.h>
#include <TH2Poly.h>
#include <TLine.h>
#include <TArc.h>
#include
#include <TPolyMarker.h>
#include
using namespace std;
void analysis_SRC()
{
TChaint1=new TChain(“tree”,“tree”);
TChain
t2=new TChain(“tree”,“tree”);
for(int i=19; i<22; i++)
{
t2->Add(Form(“rootfiles/psp15%04d_minos.root”,i));
t1->Add(Form(“rootfiles/psp15%04d_brips.root”,i));
}

vector<double> *parFit2=0;
vector<double> *parFit4=0;
int NumberTracks;
double aoq[6];
double zet[6];


TBranch* bparFit2;
TBranch* bparFit4;
TBranch* bNumberTracks;
TBranch* bzet;
TBranch* baoq;
t1->SetBranchAddress("BigRIPSBeam.zet",zet,&bzet);
t1->SetBranchAddress("BigRIPSBeam.aoq",aoq,&baoq);
t2->SetBranchAddress("parFit2",&parFit2,&bparFit2);
t2->SetBranchAddress("parFit4",&parFit4,&bparFit4);
t2->SetBranchAddress("NumberTracks",&NumberTracks,&bNumberTracks);

for(int i=0; i<t1->GetEntries(); i++)
{
	t1->GetEntry(i);
	t2->GetEntry(i);
	cout<<i<<" "<<zet[4]<<" "<<aoq[4]<<endl;
}

}[/code]

Hi,

What is the result of tree->Print() for t1? (i.e. what is the actual content of the BigRIPSBeam)? …

Philippe.

Hello,

Here is the output of t1->Print().

Anna


*Chain :tree : rootfiles/psp150019_brips.root *


Warning in TClass::TClass: no dictionary for class TArtEventInfo is available
Warning in TClass::TClass: no dictionary for class TArtPPAC is available
Warning in TClass::TClass: no dictionary for class TArtDataObject is available
Warning in TClass::TClass: no dictionary for class TArtPlastic is available
Warning in TClass::TClass: no dictionary for class TArtIC is available
Warning in TClass::TClass: no dictionary for class TArtFocalPlane is available
Warning in TClass::TClass: no dictionary for class TArtRIPS is available
Warning in TClass::TClass: no dictionary for class TArtTOF is available
Warning in TClass::TClass: no dictionary for class TArtBeam is available


*Tree :tree : tree *
*Entries : 709955 : Total = 9035991011 bytes File Size = 1852339291 *

  •    :          : Tree compression factor =   4.88                       *
    

.
.
.
.
.
.
.

*Br 127 :BigRIPSBeam : Int_t BigRIPSBeam_ *
*Entries : 709955 : Total Size= 5767560 bytes File Size = 912496 *
*Baskets : 273 : Basket Size= 32000 bytes Compression= 6.25 *

*Br 128 :BigRIPSBeam.fUniqueID : UInt_t fUniqueID[BigRIPSBeam_] *
*Entries : 709955 : Total Size= 19896126 bytes File Size = 1058081 *
*Baskets : 146 : Basket Size= 312320 bytes Compression= 18.80 *

*Br 129 :BigRIPSBeam.fBits : UInt_t fBits[BigRIPSBeam_] *
*Entries : 709955 : Total Size= 19895526 bytes File Size = 1075018 *
*Baskets : 146 : Basket Size= 312320 bytes Compression= 18.50 *

*Br 130 :BigRIPSBeam.id : Int_t id[BigRIPSBeam_] *
*Entries : 709955 : Total Size= 19895076 bytes File Size = 1061538 *
*Baskets : 146 : Basket Size= 312320 bytes Compression= 18.74 *

*Br 131 :BigRIPSBeam.fpl : Int_t fpl[BigRIPSBeam_] *
*Entries : 709955 : Total Size= 19895226 bytes File Size = 1061516 *
*Baskets : 146 : Basket Size= 312320 bytes Compression= 18.74 *

*Br 132 :BigRIPSBeam.name : TString name[BigRIPSBeam_] *
*Entries : 709955 : Total Size= 213005578 bytes File Size = 4283735 *
*Baskets : 168 : Basket Size= 3345920 bytes Compression= 49.72 *

*Br 133 :BigRIPSBeam.fDataState : Int_t fDataState[BigRIPSBeam_] *
*Entries : 709955 : Total Size= 19896276 bytes File Size = 1062595 *
*Baskets : 146 : Basket Size= 312320 bytes Compression= 18.72 *

*Br 134 :BigRIPSBeam.brho : Double_t brho[BigRIPSBeam_] *
*Entries : 709955 : Total Size= 36935184 bytes File Size = 21825605 *
*Baskets : 154 : Basket Size= 580096 bytes Compression= 1.69 *

*Br 135 :BigRIPSBeam.aoq : Double_t aoq[BigRIPSBeam_] *
*Entries : 709955 : Total Size= 36935026 bytes File Size = 32023175 *
*Baskets : 154 : Basket Size= 580096 bytes Compression= 1.15 *

*Br 136 :BigRIPSBeam.zet : Double_t zet[BigRIPSBeam_] *
*Entries : 709955 : Total Size= 36935026 bytes File Size = 23084430 *
*Baskets : 154 : Basket Size= 580096 bytes Compression= 1.60 *

*Br 137 :BigRIPSBeam.beta : Double_t beta[BigRIPSBeam_] *
*Entries : 709955 : Total Size= 36935184 bytes File Size = 20915167 *
*Baskets : 154 : Basket Size= 580096 bytes Compression= 1.77 *

*Br 138 :BigRIPSBeam.clight : Double_t clight[BigRIPSBeam_] *
*Entries : 709955 : Total Size= 36935500 bytes File Size = 1382867 *
*Baskets : 154 : Basket Size= 580096 bytes Compression= 26.71 *

*Br 139 :BigRIPSBeam.mnucleon : Double_t mnucleon[BigRIPSBeam_] *
*Entries : 709955 : Total Size= 36935816 bytes File Size = 1400057 *
*Baskets : 154 : Basket Size= 580096 bytes Compression= 26.38 *

*Br 140 :BigRIPSBeam.nrips : Int_t nrips[BigRIPSBeam_] *
*Entries : 709955 : Total Size= 19895526 bytes File Size = 1076303 *
*Baskets : 146 : Basket Size= 312320 bytes Compression= 18.48 *

*Br 141 :BigRIPSBeam.ripsname[2] : TString ripsname[BigRIPSBeam_] *
*Entries : 709955 : Total Size= 62488171 bytes File Size = 1960233 *
*Baskets : 99 : Basket Size= 981504 bytes Compression= 31.88 *

*Br 142 :BigRIPSBeam.tofname : TString tofname[BigRIPSBeam_] *
*Entries : 709955 : Total Size= 68877591 bytes File Size = 5311573 *
*Baskets : 101 : Basket Size= 1081856 bytes Compression= 12.97 *

*Br 143 :BigRIPSBeam.icname : TString icname[BigRIPSBeam_] *
*Entries : 709955 : Total Size= 26285610 bytes File Size = 1498883 *
*Baskets : 149 : Basket Size= 412672 bytes Compression= 17.53 *

Hi,

You have a Branch that was created from an object. To read its content in a ‘decomposed’ fashion as you are attempting you need to switch the branch to a mode called ‘MakeClass’ by doing:t1->GetBranch("BigRIPSBeam.")->SetMakeClass(true);.

Alternatively, if you are using ROOT v6, I recommend that you use the TTreeReader.

Cheers,
Philippe.

Hello,

Thanks for the explanation. I’m currently using root v5.34.
I have added:
t1->GetBranch(“BigRIPSBeam.”)->SetMakeClass(true);
but the code blocks after “debug0” at runtime.
Than I have added:
t1->SetMakeClass(true);
but again the code blocks after “last printout” at runtime.
Here is the error message:
root [1] analysis_SRC()
debug0
debug1
debug2
Warning in TClass::TClass: no dictionary for class TArtEventInfo is available
Warning in TClass::TClass: no dictionary for class TArtPPAC is available
Warning in TClass::TClass: no dictionary for class TArtDataObject is available
Warning in TClass::TClass: no dictionary for class TArtPlastic is available
Warning in TClass::TClass: no dictionary for class TArtIC is available
Warning in TClass::TClass: no dictionary for class TArtFocalPlane is available
Warning in TClass::TClass: no dictionary for class TArtRIPS is available
Warning in TClass::TClass: no dictionary for class TArtTOF is available
Warning in TClass::TClass: no dictionary for class TArtBeam is available
last printout 709955

*** Break *** segmentation violation
Generating stack trace…
0x00000001077ad3a6 in TBranch::GetEntry(long long, int) (in libTree.so) + 326
0x00000001077beb6d in TBranchElement::GetEntry(long long, int) (in libTree.so) + 173
0x00000001077fbc98 in TTree::GetEntry(long long, int) (in libTree.so) + 168
0x000000010426f604 in analysis_SRC() (in analysis_SRC_C.so) + 1588
0x0000000104270a9e in G__analysis_SRC_C_ACLiC_dict__0_2088(G__value*, char const*, G__param*, int) (in analysis_SRC_C.so) + 14
0x0000000101107a11 in Cint::G__ExceptionWrapper(int ()(G__value, char const*, G__param*, int), G__value*, char*, G__param*, int) (in libCint.so) + 49
0x00000001011b255b in G__execute_call (in libCint.so) + 75
0x00000001011b29d2 in G__call_cppfunc (in libCint.so) + 866
0x0000000101185355 in G__interpret_func (in libCint.so) + 5445
0x0000000101173610 in G__getfunction (in libCint.so) + 5984
0x0000000101167aaf in G__getitem (in libCint.so) + 511
0x000000010116347a in G__getexpr (in libCint.so) + 30506
0x00000001011e77da in G__exec_statement (in libCint.so) + 39242
0x000000010114a144 in G__exec_tempfile_core(char const*, __sFILE*) (in libCint.so) + 1108
0x0000000101149ce6 in G__exec_tempfile_fp (in libCint.so) + 22
0x00000001011efd3a in G__process_cmd (in libCint.so) + 9402
0x00000001009efe51 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) (in libCore.so) + 817
0x000000010094be92 in TApplication::ProcessLine(char const*, bool, int*) (in libCore.so) + 1778
0x000000010181f076 in TRint::HandleTermInput() (in libRint.so) + 678
0x0000000100a299c9 in TUnixSystem::CheckDescriptors() (in libCore.so) + 313
0x0000000100a32a8b in TMacOSXSystem::DispatchOneEvent(bool) (in libCore.so) + 379
0x00000001009ac85a in TSystem::InnerLoop() (in libCore.so) + 26
0x00000001009ac757 in TSystem::Run() (in libCore.so) + 391
0x000000010094d1b4 in TApplication::Run(bool) (in libCore.so) + 36
0x000000010181e9bf in TRint::Run(bool) (in libRint.so) + 1439
0x0000000100942e1f in main (in root.exe) + 79
0x00007fff890535fd in start (in libdyld.dylib) + 1
0x0000000000000002 in

Could you tell me how to use correctly this command?
Cheers
Anna

void analysis_SRC()
{
TChaint1=new TChain(“tree”,“tree”);
TChain
t2=new TChain(“tree”,“tree”);
for(int i=19; i<20; i++)
{
t2->Add(Form(“rootfiles/psp15%04d_minos.root”,i));
t1->Add(Form(“rootfiles/psp15%04d_brips.root”,i));
}

vector<double> *parFit2=0;
vector<double> *parFit4=0;
int NumberTracks;
double BigRIPSBeam_aoq[6];
double BigRIPSBeam_zet[6];

//t1->Print();
TBranch* bparFit2;
TBranch* bparFit4;
TBranch* bNumberTracks;
TBranch* bBigRIPSBeam_zet;
TBranch* bBigRIPSBeam_aoq;
cout<<"debug0"<<endl;
t1->/*GetBranch("BigRIPSBeam.")->*/SetMakeClass(true);
cout<<"debug1"<<endl;
t1->SetBranchAddress("BigRIPSBeam.zet",BigRIPSBeam_zet,&bBigRIPSBeam_zet);
t1->SetBranchAddress("BigRIPSBeam.aoq",BigRIPSBeam_aoq,&bBigRIPSBeam_aoq);
cout<<"debug2"<<endl;
t2->SetBranchAddress("parFit2",&parFit2,&bparFit2);
t2->SetBranchAddress("parFit4",&parFit4,&bparFit4);
t2->SetBranchAddress("NumberTracks",&NumberTracks,&bNumberTracks);

cout<<"last printout "<<t1->GetEntries()<<endl;
for(int i=0; i<t1->GetEntries(); i++)
{
	t1->GetEntry(i);
	cout<<i<<" "<<BigRIPSBeam_zet[4]<<endl;
	t2->GetEntry(i);

}

}

[quote]t1->GetBranch(“BigRIPSBeam.”)->SetMakeClass(true);
but the code blocks after “debug0” at runtime.[/quote]Yes, I had mis-read and the ‘.’ was extraneous. It should have readt1->GetBranch("BigRIPSBeam")->SetMakeClass(true);or better :slight_smile:TBranch *b = t1->GetBranch("BigRIPSBeam"); if (!b) { printf("Error could not find the branch\n"); return; } b->SetMakeClass(true);

Note that you also might need to call SetMakeClass on other branches or the other TTree.

*** Break *** segmentation violation Generating stack trace... 0x00000001077ad3a6 in TBranch::GetEntry(long long, int) (in libTree.so) + 326

What is the largest value seen when you plot “BigRIPSBeam.@size()” ?

Cheers,
Philippe.

I see, thanks!
Now the code looks like this:

t1->GetBranch("BigRIPSBeam")->SetMakeClass(true); t1->SetBranchAddress("BigRIPSBeam.zet",BigRIPSBeam_zet,&bBigRIPSBeam_zet);

and when I print in the loop on events:

[quote]0 6.9532e-310
1 6.9532e-310
.
.
.[/quote]

So the code executes, but the branch BigRIPSBeam_zet is not correctly read.
BigRIPSBeam.@size() is 6.

Cheers,
Anna

Hi,

If [t1->SetBranchAddress("BigRIPSBeam.zet",BigRIPSBeam_zet,&(bBigRIPSBeam_zet[0]));does not work, please send me the file so that I can check directly what the issue might be.

Cheers,
Philippe.

I have tried this and several variations, without success. I enclose the code but it seems the input file is too large…is it needed to debug?
Thanks for the help!
Anna
analysis_SRC.C (3.21 KB)

Hi,

Yes, I will need access to the file. Can you provide access to it via source web or ftp server?

Thanks,
Philippe.

Here is the link to the file:
drive.google.com/file/d/0BxEp-h … sp=sharing

Anna