Hi Anne-Silvie,
You should not use TClonesArray::Remove when the array
is a branch of a Tree. You must find another solution.
Rene Brun
On Mon, 9 Dec 2002, Anne-Sylvie Nicollerat wrote:
> Hello,
>
> I am filling a TClonesArray with an object named TEgammaBasicClusters,
> having a TLorentzVector for one of its member variable, _Momentum.
> I would like to remove all the clusters having a _Momentum pt smaller
> than 40.
>
> For that I wrote the following code:
>
> TClonesArray *clusters=new TClonesArray("TEgammaBasicCluster");
>
> ...(the TclonesArray is then initialized reading a tree)...
> tree->SetBranchAddress("TEgammaBasicCluster",&clusters);
>
> for(Int_t i=0;i<nentries;i++)
> {
> clusters->Delete();
>
> cout << "Processing entry number " << i << " cluser size: " <<
> clusters->GetEntries() << endl;
>
> tree->GetEntry(i);
>
> for(Int_t j=0;j<clusters->GetEntries(); ++j)
> {
> TLorentzVector vec = ((TEgammaBasicCluster
> *)(*clusters)[j])->_Momentum;
> cout << "pt before: " << vec.Pt() << endl;
>
> if(vec.Pt()<40)
> {
> clusters->Remove(((TEgammaBasicCluster *)(*clusters)[j]));
> cout << "pt removed: " << vec.Pt() << endl;
> }
> cout << "********************************** " << endl;
> }
>
> Here is for instance the print statement that I get:
>
> size before 35
> pt before: 40.5209
> **********************************
> pt before: 23.9048
> pt removed: 23.9048
> **********************************
> pt before: 3.43218
> pt removed: 3.43218
> **********************************
> pt before: 6.72141
> pt removed: 6.72141
> **********************************
> pt before: 4.60063
> pt removed: 4.60063
> **********************************
> pt before: 0.577762
> pt removed: 0.577762
> **********************************
> pt before: 2.98151
> pt removed: 2.98151
> **********************************
> pt before: 1.01181
> pt removed: 1.01181
> **********************************
> pt before: 0.532288
> pt removed: 0.532288
> **********************************
> pt before: 0.314125
> pt removed: 0.314125
> **********************************
> pt before: 0.297861
> pt removed: 0.297861
> **********************************
> pt before: 0.268139
> pt removed: 0.268139
> **********************************
> pt before: 0.231922
> pt removed: 0.231922
> **********************************
> pt before: 0.638586
> pt removed: 0.638586
> **********************************
> pt before: 0.360809
> pt removed: 0.360809
> **********************************
> pt before: 0.322122
> pt removed: 0.322122
> **********************************
> pt before: 0.181829
> pt removed: 0.181829
> **********************************
> pt before: 0.205891
> pt removed: 0.205891
> **********************************
> size after 18
>
> so you see that it is reducing the size of the array from 35 to 18 but
> still all teh times it goes in the second if statement, it seems not to
> remove the clusters ?
> I was wondering if I was correctly initializing my TClonesArray ?
>
> Mabye there is a better way to do it ??
> Any idea ?
>
> Thanks a lot, cheers
>
> Anne-Sylvie
>
>
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:23 MET