GSI Forum
GSI Helmholtzzentrum für Schwerionenforschung

Home » PANDA » PandaRoot » Analysis » How to remove a candidate
How to remove a candidate [message #14550] Wed, 27 March 2013 17:38 Go to next message
StefanoSpataro is currently offline  StefanoSpataro
Messages: 2736
Registered: June 2005
Location: Torino
first-grade participant

From: *to.infn.it
Dear analysis experts,
if I check the macros in tutorials/feb12 I can see that in order to remove a candidate from a list, it is suggested to use something like:

	for (int ii=0;ii<l.GetLength();++ii)
	{
		if (!mcm.MctMatch(l[ii],mct))
		{
			l.Remove(l[ii]);
			removed++;
		}
	}


You remove the ii element.

But if I check the old macro/run/tdrct/ macros, in the analysis it is used the following:

    int n_removed=0;
    int ii=0;    
    for (Int_t l=0;l<pp.GetLength();l++){
      ii=l-n_removed;
      if((pp[ii].GetMicroCandidate()->GetSttHits())==0){
	pp.Remove(pp[ii]);
        n_removed++;
      }
    }


Here you remove the ii=l-n_removed element.

It is not clear to me which is the correct way to remove elements in the candidate list. In particolar, once one element is removed, I would presume that the TCandList has 1 element less and the length decreases. If I remove the element 0, the "old" element 1 will become the new element "0", but in the for the index increases then I will analyse the "new" element 1 (old element 2) forgetting the "old" element 1 which now is 0.

Which is the correct way? or maybe it is better to create a new empty list and to fill it with the relevant candidates?
I am also wodering if the old analyses were bugged or not.

Thanks in advance.
Re: How to remove a candidate [message #14551 is a reply to message #14550] Wed, 27 March 2013 18:02 Go to previous messageGo to next message
Klaus Götzen is currently offline  Klaus Götzen
Messages: 293
Registered: June 2006
Location: GSI
first-grade participant
From: *adsl.alicedsl.de
Hi Stefano,


your concern ist correct. The removal process will be bugged. Let me point you to a forum message I wrote some time ago exactly concerning that topic

https://forum.gsi.de/index.php?t=tree&th=3737

To do it correctly you can either store the length of the list beforehand like

  Int_t n=l.GetLength();
  for (l=0; l<n; ++l)  
  {
    i = l-n_removed;
    if( ... Some criterion ...)
    {
      list.Remove( list[i] );
      n_removed++;
    }
  }


or (suggested by Radek) loop reversely through the list with

  for (ii=l.GetLength()-1 ; ii>=0; --ii)


Or, as you mention, fill a new empty list with the non-removed candidates.


Best,
Klaus
Re: How to remove a candidate [message #14552 is a reply to message #14551] Thu, 28 March 2013 12:03 Go to previous messageGo to next message
donghee is currently offline  donghee
Messages: 385
Registered: January 2009
Location: Germnay
first-grade participant
From: *dip.t-dialin.net
Dear PANDAroot users,

I would like to confirm Klaus's suggestion and report to get better understanding of our example code in analysis macro directory (macro/run/tdrct/).

I have tested a function, which will remove low energetic photon in the "Neutral candidate" by EMC energy cut as an example.
This function has a bug as people mentioned because it does not look all contents inside the candidate list,
they stop before arriving end of list due to wrong count in the part of "ii=l-n_removed".
So simpy you could not reach to the end of list because will skip last part according to reduced counts during remove process.

Quote:


------------------------------------------------------------------------ --------------------------------------

//this method is wrong!!!
int n_removed=0; int ii=0;
for (l=0;l<neutral2.GetLength();++l) {
ii=l-n_removed;
if(neutral2[ii].GetMicroCandidate().GetEmcRawEnergy() < 0.01 ){
neutral2.Remove(neutral2[ii]);
n_removed++;
}
}
------------------------------------------------------------------------ --------------------------------------



So change the length as total = neutral2.Getlength(), works fine.
Quote:


------------------------------------------------------------------------ --------------------------------------

//this method works
int total = neutral2.Getlength();
int n_removed=0; int ii=0;
for (l=0;l<total;++l) {
ii=l-n_removed;
if(neutral2[ii].GetMicroCandidate().GetEmcRawEnergy() < 0.01 ){
neutral2.Remove(neutral2[ii]);
n_removed++;
}
}
------------------------------------------------------------------------ --------------------------------------



In order to correct example macros in tutorials/feb12/,
one should alterantively change from [ii] to [ii--] and here you don't need to use n_removed++ any more.
This function will check all contents in the list and reach end of the list as we want.
Quote:


------------------------------------------------------------------------ --------------------------------------

//this method is correct!!!
for (ii=0;ii<neutral3.GetLength();++ii) {
if(neutral3[ii].GetMicroCandidate().GetEmcRawEnergy() < 0.01 ){
neutral3.Remove(neutral3[ii--]);

}
}

------------------------------------------------------------------------ --------------------------------------



Many of analyzer looks and use our example macros without any doubt at the beginnig.
I think that some example codes must to be fixed at least in the pandaroot/macro/


Best wishes,


Re: How to remove a candidate [message #14553 is a reply to message #14552] Thu, 28 March 2013 14:48 Go to previous messageGo to next message
StefanoSpataro is currently offline  StefanoSpataro
Messages: 2736
Registered: June 2005
Location: Torino
first-grade participant

From: *to.infn.it
Hi,
I agree with Donghee that at least in the tutorial/feb12 folder the analysis macros should be corrected, so that people do not copy the wrong code supposing it is correct. Klaus, could you please fix them?
Re: How to remove a candidate [message #14555 is a reply to message #14553] Thu, 28 March 2013 15:34 Go to previous messageGo to next message
Klaus Götzen is currently offline  Klaus Götzen
Messages: 293
Registered: June 2006
Location: GSI
first-grade participant
From: *adsl.alicedsl.de
Hi,


I also agree with Donghee and was not aware until your message, that this problem appears in the tutorial directory. When I'm back from vacations the week after next week I'll fix things there.


Best,
Klaus
Re: How to remove a candidate [message #14598 is a reply to message #14553] Wed, 10 April 2013 08:22 Go to previous message
Klaus Götzen is currently offline  Klaus Götzen
Messages: 293
Registered: June 2006
Location: GSI
first-grade participant
From: *gsi.de
Hi,


I just checked in the fixed files for the tutorial. I also exchanged the electrons in the J/psi decay by muons in the example, so that the spectra look nicer.


Best,
Klaus
Previous Topic: analysis performance and PID criteria
Next Topic: Problem with 4C-fit
Goto Forum:
  


Current Time: Thu Mar 28 11:09:23 CET 2024

Total time taken to generate the page: 0.00916 seconds