Re: vectors in selection cuts in TTrees

From: suvayu ali <fatkasuvayu_at_gmail.com>
Date: Thu, 30 Sep 2010 12:31:20 -0700


Hi Philippe,

On 30 September 2010 07:06, Philippe Canal <pcanal_at_fnal.gov> wrote:
>  Hi,
>
> CopyTree("abs(mc_pdgId[]) == 13&&  abs(mc_pdgId[
> mc_parent_index[Iteration$][0] ])== 24")
>
> is actually equivalent to:
>
> bool keepentry = false;
> for(int i=0; i<mc_n;i++) {
>   if ( abs(mc_pdgId[i]) = 13
> && mc_parent_index->size()>0
> && mc_parent_index->at(i).size()>0
> && abs(mc_pdgId[ mc_parent_index[i][0] ])== 24 )
>   {
>      keepentry = true;
>   }
> }
> if (keepentry) newtree->Fill();
>

Okay.

> Note that CopyTree can only copy entire Events, so at best you would get a
> TTree
> with all the event when at least one 'element' match the criterium.
>

I don't want to lose any of the branches. I want to copy the entire event (meaning all branches for the matching entry). Given my intention, is my use of CopyTree correct? Or is there a more efficient way to achieve the same?

> A priori, the formula you wrote seems correct, you could try this slight
> variation:
>
>    CopyTree("abs(mc_pdgId[]) == 13&&  abs(mc_pdgId[ mc_parent_index[][0]
> ])== 24")
>

Thank you for this suggestion. It seems to gives me the desired entries. I am not clear about something though, the above formula would mean the effective loop looks something like this:

bool keepentry = false;
for(int i=0; i<mc_n;i++) {

     if ( abs(mc_pdgId[i]) = 13 && mc_parent_index->size()>0) {
      for (int j=0; j<mc_parent_index->size(); j++) {
           if (abs(mc_pdgId[ mc_parent_index[j][0] ])== 24 ) {
            keepentry = true;
           }
      }
     }

}
if (keepentry) newtree->Fill();

Although I am getting the desired result, I have a feeling it only works in my case because there is only one muon with a W boson as a parent. It might not work if there were more muons from other sources. Is my understanding correct here?

> Also you can investigate whether the formula is return the value you expect
> by using
>
>   physics->Scan("abs(mc_pdgId[]) == 13:abs(mc_pdgId[ mc_parent_index[][0]
> ])== 24:abs(mc_pdgId[]) == 13 && abs(mc_pdgId[mc_parent_index[][0] ])==
> 24");
>

This tip was incredibly useful. Thanks a lot for all the help.

> Cheers,
> Philippe.
>
>  On 9/30/10 3:11 AM, suvayu ali wrote:
>>
>> Hi ROOT users,
>>
>> I am trying to skim an ntuple based on MC data. The MC branches I am
>> using for my selection look like this,
>>
>> Int_t                           mc_n;
>> vector<int>                *mc_pdgId;
>> vector<vector<int>  >  *mc_parent_index;
>>
>> I want to make a selection equivalent to this,
>>
>>   for(int i=0; i<mc_n;i++){
>>     if (abs(mc_pdgId[i])==13) {
>>       firstparentindex.push_back(mc_parent_index[i][0]);
>>     }
>>   }
>>   if (firstparentindex.size()>0){
>>     for(int i=0; i<mc_n;i++){
>>       if (i==firstparentindex[0]&&  abs(mc_pdgId[i])==24) {
>>         ismuondecay =  true;
>>       }
>>     }
>>   }
>>
>> I wanted to avoid fiddling with MakeClass() so I tried something like
>> this,
>>
>> TTree *newTree = physics->CopyTree("abs(mc_pdgId[]) == 13&&
>> abs(mc_pdgId[ mc_parent_index[Iteration$][0] ])== 24");
>>
>> But this gives me an empty TTree! If I remove the later cut asking for
>> the parent, I do get a TTree which has W's in them. I test this by
>> looking at the histogram drawn by double clicking on the mc_pdgId
>> branch from a TBrowser.
>>
>> root [1] TBrowser b
>> root [2] htemp->Print("all")
>> TH1.Print Name  = htemp, Entries= 86496, Total sum= 86496
>>  .....
>>  fSumw[3]=0, x=-24.5
>>  fSumw[4]=349, x=-23.5
>>  .....
>>  fSumw[52]=556, x=24.5
>>  fSumw[53]=0, x=25.5
>>
>> What am I doing wrong? Thanks for any insights.
>>
>

-- 
Suvayu

Open source is the future. It sets us free.
Received on Thu Sep 30 2010 - 21:31:47 CEST

This archive was generated by hypermail 2.2.0 : Thu Sep 30 2010 - 23:50:01 CEST