CINT: strange behavior of the if statement

Hello,

I’m normally not using CINT I prefer to compile my macros, but this time, I need my macro to run using:

root -l macro.C

The problem is, that when I compile the macro everything works, but with root -l macro.C it doesn’t (not surprised)

So I tried to find the problem, and seems to me that there is something wrong with the if statement. Best way to explain -> simplest non working example (sending also as an attachment):

#include <iostream>
#include "TTree.h"
#include "TFile.h"
#include "TROOT.h"
#include "TLorentzVector.h"
#include "TMath.h"

TTree* m_tree;

Int_t InfoNums[21] = {0};


Int_t           NPar;
Int_t           Type[1000];          //[NPar]
Float_t         PtGen[1000];         //[NPar]
Float_t         PhiGen[1000];        //[NPar]
Float_t         EtaGen[1000];        //[NPar]
Int_t           KMothNt[1000];       //[NPar]
Int_t           KFDauNt[1000];       //[NPar]
Int_t           KLDauNt[1000];       //[NPar]

//************************************************************************************
// returns the 4-momentum of the tau after substracting the 4-momentum of its neutrino
TLorentzVector VisiblePartP(Int_t TNum) 
{
  TLorentzVector m_p;
  Double_t x = PtGen[TNum]*cos(PhiGen[TNum]);
  Double_t y = PtGen[TNum]*sin(PhiGen[TNum]);
  Double_t z = PtGen[TNum]*sinh(EtaGen[TNum]);
  Double_t e = PtGen[TNum]*cosh(EtaGen[TNum]);

  for(Int_t j=0; j<NPar; ++j) 
  {
    if ( ( abs(Type[j])==16 ) && ( KMothNt[j] == TNum ) ) 
    {
      x = x - PtGen[j]*cos(PhiGen[j]);
      y = y - PtGen[j]*sin(PhiGen[j]);
      z = z - PtGen[j]*sinh(EtaGen[j]);
      e = e - PtGen[j]*cosh(EtaGen[j]);
    }
  }
  m_p.SetXYZT(x, y, z, e);
  return m_p;
}
//*************************************************************************************
int Initialise(char* ntupFile)
{
  TFile *m_file  = new TFile(ntupFile);
  m_tree    = (TTree*) m_file->Get("CBNT/t3333");

  //reed branches
  m_tree->SetBranchAddress("NPar" ,&NPar);
  m_tree->SetBranchAddress("Type" , Type);
  m_tree->SetBranchAddress("PtGen" , PtGen);
  m_tree->SetBranchAddress("PhiGen" , PhiGen);
  m_tree->SetBranchAddress("EtaGen" , EtaGen);
  m_tree->SetBranchAddress("KMothNt" , KMothNt);
  m_tree->SetBranchAddress("KFDauNt" ,  KFDauNt);
  m_tree->SetBranchAddress("KLDauNt" , KLDauNt);
          
  return 0;  
}

//************************************************************************************
void fillHists()
{
  for (Int_t N=0;N<m_tree->GetEntries();N++)  //loop over all events
  {
    m_tree->GetEntry(N);
    Bool_t stvar;

    Bool_t gTau;

    for (Int_t i=1;i<NPar;i++) // loop over all MC taus
    { 
      if (abs(Type[i])==15)
      {
        gTau=true;
        for (Int_t i2=KFDauNt[i];i2 <= KLDauNt[i]; i2++) if (abs(Type[i2])==15) gTau=false;
        if (gTau) 
        {  
          
          if (VisiblePartP(i).Pt()/1000 > 15 ) InfoNums[1]++; //works
          if (VisiblePartP(i).Pt()/1000 > 10 ) InfoNums[2]++; //works
          if ( fabs( VisiblePartP(i).Eta() ) <= 2.5) InfoNums[3]++; //works
          
          cout << (( VisiblePartP(i).Pt()/1000 > 10 )  &&  ( fabs( VisiblePartP(i).Eta() ) <= 2.5 ) ) << endl;
          if (     ( VisiblePartP(i).Pt()/1000 > 10 )  &&  ( fabs( VisiblePartP(i).Eta() ) <= 2.5 ) ) InfoNums[4]++;
          //this if statement doesn't work, replaced by the following 2 lines it works. ???
          //stvar =( VisiblePartP(i).Pt()/1000 > 10 ) && ( fabs( VisiblePartP(i).Eta() ) <= 2.5);
          //if ( stvar ) InfoNums[4]++;
          if ( ( VisiblePartP(i).Pt()/1000 > 15 ) && ( fabs( VisiblePartP(i).Eta() ) <= 2.5 ) ) InfoNums[5]++;
          cout << InfoNums[1] << " " << InfoNums[2] << " "<<  InfoNums[3] <<" "<<   InfoNums[4] <<" "<<   InfoNums[5] <<endl;
        }
      }
    }
  }
}
//**********************************************************************************************
int example(char* ntupFile="ntuple.root") 
{
  
  Initialise(ntupFile);
  fillHists();
  return 0;
}

the problem (in void fillHists() ):

if ( ( VisiblePartP(i).Pt()/1000 > 10 ) && ( fabs( VisiblePartP(i).Eta() ) <= 2.5 ) ) InfoNums[4]++;

doesn’t work, but replaced by:

stvar =( VisiblePartP(i).Pt()/1000 > 10 ) && ( fabs( VisiblePartP(i).Eta() ) <= 2.5);
if ( stvar ) InfoNums[4]++;

works.

So I’ll be grateful for any help.

PS: the file on which this macro should run (for instance this one):
/afs/physik.uni-freiburg.de/home/heldmann/recon/root-10.0.4/multiTopo_jobOptions_tauRec_weightToolSnippet/rome.004807.recov10.A3_Ztautau_tightfilter._00006.pool.root.root
example.C (3.44 KB)

We will investigate your problem.
Note that you can use ACLIC also in batch mode with
root -b example.C++
root -b example.C+
root -b -q example.C+

Rene

looking a bit more at your code, I see that you were using an extremely
dangerous C++ construct in your VisiblePartP function.
In addition your code was extremely inefficient because your were creating
plenty of LorentzVector objects inside the loop.
The new code below should be much much faster and secure.

Rene
example.C (3.06 KB)