TChain->AddFriend(TTree,File)

Good day,

The idea is to build TChain and then AddFriend to it (with a Tree of different structure than TChain trees) and then to plot one branch of TChain vs. One branch of TTree. Below is a piece of code used:

//--> building the TChain;
   TChain *fullNtps = new TChain("RootNtp");

   while(!files_in.eof()) { //-- Add files to TChain from the list of files;
         files_in.getline(fName,fNLength);
         fullNtps->Add(fName);
   };
   files_in.close();
   fullNtps->SetName("fullNtps");  //-- to avoid that TChain and TTree from calibntps_xxx file have the same name;
//<-- TChain is constucted;

   TChain *cloneNtps = (TChain*)fullNtps->Clone();   //-- clone TChain;
   TFile *calibF = new TFile(fileName);              //-- open Tree file;
   TTree *calibNtps = (TTree*)calibF->Get("RootNtp");

   Double_t Y1max = calibNtps->GetMaximum("WienerAmpl_chaleur")); //-- to find maximum;
   cloneNtps->AddFriend("RootNtp",fileName);
   Double_t Y2max = cloneNtps->GetMaximum("RootNtp.WienerAmpl_chaleur"));

The problem is that variables Y1max and Y2max are different, while expected to be exactly the same!
TChain though has itself branch “WienerAmpl_chaleur” but it also shows (in TreeViewer) “RootNtp.WienerAmpl_chaleur” after AddFriend() is exectued. However, both of them contain exactly the same data and different one from calibNtps->WienerAmpl_chaleur.

Did I miss something/did wrong in AddFriend() action?

ROOT 5.18, Linux SuSE 10.3, gcc (GCC) 4.2.1 (SUSE Linux)

Hi,

The TChain still get confused about which ‘Tree’ you are referring to in the AddFriend. So just make it explicit by passing the pointer:cloneNtps->AddFriend(calibNtps); // Or is it AddFriend(fullNtps) ? And since the main tree and the friend have the same name, set a Tree Friend Alias name to be able to disambiguate which one you are referring to in the formulas.cloneNtps->AddFriend(calibNtps,"aliasToFriend"); .... Double_t Y2max = cloneNtps->GetMaximum("aliasToFriend.WienerAmpl_chaleur"));

Cheers,
Philippe.

PS. Why do you need to introduce the ‘clone’ of the TChain?

Thank you! It gets better, at least now after

if I compare:

calibNtps->Draw("WienerAmpl_chaleur"); cloneNtps->Draw("calib.WienerAmpl_chaleur");

I get the same plots but still

cloneNtps->GetMaximum("calib.WienerAmpl_chaleur"); calibNtps->GetMaximum("WienerAmpl_chaleur");
give different output and even now different from

cloneNtps->GetMaximum("WienerAmpl_chaleur")

P.S. I use clone because there are several files of same structure which needs to be added as AddFriend(). To not confuse between ‘friends’ I take original TChain and at each iteration add only one friend…

Hi,

Is any of the GetMaximum values ‘correct’ (i.e. same as what the Draw claims)? Can you send an example reproducing the problem?

Cheers,
Philippe.

The value of

calibNtps->GetMaximum("WienerAmpl_chaleur");

correspond to what I see from the plots. For the code, please, see the attachment.
tchain_ttree.C (2.58 KB)

Hi,

What is the output of running this scripts? Can you send me also the data file and header files so that I can reproduce the problem?

Thanks,
Philippe.