Dear root experts
I have an input root file with several trees, called ch0…ch9
I do each tree friends of each other to be able to do some arithmetics. In reality I only need each channel to be made friends with only one other tree at a time.
I found that when the list of friends of the current tree grows, so does the execution time. I have the following code:
#include <iostream>
#include <vector>
#include "TFile.h"
#include "TTree.h"
#include "TString.h"
#include "TStyle.h"
#include "TSystem.h"
#include "TH1.h"
#include "TH2.h"
#include "TLegend.h"
#include "TMath.h"
void Alignment( TString fnm ) {
TFile *fin = new TFile( fnm ) ;
//Signal threshold
vector<Double_t> vVmin ;
vVmin.push_back(0.02) ; //ch0
vVmin.push_back(0.02) ; //ch1
vVmin.push_back(0.02) ; //ch2
vVmin.push_back(0.02) ; //ch3
vVmin.push_back(0.02) ; //ch4
vVmin.push_back(0.02) ; //ch5
vVmin.push_back(0.00) ; //ch6
vVmin.push_back(0.05) ; //ch7
vVmin.push_back(0.05) ; //ch8
vVmin.push_back(0.05) ; //ch9
Int_t NPads=vVmin.size() ;
vector<TTree *> vch ;
for (Int_t it=0;it<NPads;it++) {
TTree *tree = (TTree *) fin->Get( Form("ch%d",it) ) ;
vch.push_back( tree ) ;
}
Int_t Nevs = vch[0]->GetEntries();
TH1D *h = new TH1D("h","",100,0,Nevs) ;
TH2D *hal = new TH2D("hal","alignment",NPads, -0.5,NPads-0.5,NPads, -0.5,NPads-0.5) ;
for ( Int_t ix=0 ; ix<NPads ; ix++ ) {
for ( Int_t iy=0 ; iy<ix ; iy++ ) {
if (ix==iy) continue;
vch[ix]->AddFriend( vch[iy],Form("ch%d",iy) );
TString sel = Form( "NPeaks==1 && -(Vmin-BlineMean)<%f && ch%d->NPeaks==1 && -(ch%d->Vmin-ch%d->BlineMean)<%f" , vVmin[ix] , iy ,iy,iy,vVmin[iy]);
vch[ix]->Draw("event>>h",sel,"goff") ;
Int_t ncoinc = TMath::Nint( h->GetEntries() ) ;
hal->SetBinContent(ix+1,iy+1,ncoinc) ;
cout<<"Done ... h("<<ix<<","<<iy<<")="<<ncoinc<<endl;
h->Reset();
TTree *oldfr = (TTree*) vch[ix]->GetListOfFriends()->FindObject(Form("ch%d",iy));
vch[ix]->GetListOfFriends()->Remove(oldfr);
}
}
hal->SetMinimum(-0.01);
hal->Draw("colz");
When the last 2 lines in the loop (those containing “TTree *oldfr” and “Remove(oldfr)”) are there the execution takes few seconds. Without these 2 lines, the execution took almost 1 h.
Is this a normal behaviour? Why a long list of friends does slow down the execution even if only 2 of those trees are involved each time?
Thank you very much
Marcos
Please read tips for efficient and successful posting and posting code
Please fill also the fields below. Note that root -b -q
will tell you this info, and starting from 6.28/06 upwards, you can call .forum bug
from the ROOT prompt to pre-populate a topic.
_ROOT Version: 6.24/08
_Platform: Ubuntu 22.04.4 LTS
_Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0