Re: vectors in selection cuts in TTrees

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Thu, 30 Sep 2010 09:06:45 -0500


  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();

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.

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")

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");

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.
>
Received on Thu Sep 30 2010 - 16:06:51 CEST

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