]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG4/PartCorrBase/AliIsolationCut.cxx
Fix Coverity
[u/mrichter/AliRoot.git] / PWG4 / PartCorrBase / AliIsolationCut.cxx
index ad2891ddaa2357cd2bcc693068e2309d68c80841..a46fb9c67c7cb0f0cb9dc45f13058a31ad145e06 100755 (executable)
@@ -30,7 +30,6 @@
   
   
 // --- ROOT system --- 
-//#include <Riostream.h>
 #include <TLorentzVector.h>
 #include <TObjArray.h>
 
 #include "AliVCluster.h"
 #include "AliCaloTrackReader.h"
 #include "AliMixedEvent.h"
+#include "AliCaloPID.h"
 
 ClassImp(AliIsolationCut)
   
-//____________________________________________________________________________
-  AliIsolationCut::AliIsolationCut() : 
-    TObject(),
-    fConeSize(0.),fPtThreshold(0.), fSumPtThreshold(0.), fPtFraction(0.), fICMethod(0),fPartInCone(0)
+//____________________________________
+AliIsolationCut::AliIsolationCut() : 
+TObject(),
+fConeSize(0.),
+fPtThreshold(0.), 
+fSumPtThreshold(0.), 
+fPtFraction(0.), 
+fICMethod(0),
+fPartInCone(0)
+
 {
   //default ctor
   
   //Initialize parameters
   InitParameters();
-
+  
 }
 
-//____________________________________________________________________________
+//____________________________________________
 TString AliIsolationCut::GetICParametersList()
 {
   //Put data member values in string to keep in output container
@@ -78,11 +83,11 @@ TString AliIsolationCut::GetICParametersList()
   parList+=onePar ;
   snprintf(onePar,buffersize,"fPartInCone=%d \n",fPartInCone) ;
   parList+=onePar ;
-
+  
   return parList; 
 }
 
-//____________________________________________________________________________
+//____________________________________
 void AliIsolationCut::InitParameters()
 {
   //Initialize the parameters of the analysis.
@@ -96,11 +101,18 @@ void AliIsolationCut::InitParameters()
   
 }
 
-//__________________________________________________________________
-void  AliIsolationCut::MakeIsolationCut(TObjArray * const plCTS,  TObjArray * const plNe, AliCaloTrackReader * const reader, 
-                                       const Bool_t bFillAOD, AliAODPWG4ParticleCorrelation  *pCandidate, 
-                                       const TString & aodArrayRefName,
-                                       Int_t & n, Int_t & nfrac, Float_t &coneptsum,  Bool_t  &isolated, Bool_t &leading) const
+//________________________________________________________________________________
+void  AliIsolationCut::MakeIsolationCut(const TObjArray * plCTS, 
+                                        const TObjArray * plNe, 
+                                        const AliCaloTrackReader * reader, 
+                                        const AliCaloPID * pid, 
+                                        const Bool_t bFillAOD, 
+                                        AliAODPWG4ParticleCorrelation  *pCandidate, 
+                                        const TString & aodArrayRefName,
+                                        Int_t & n, 
+                                        Int_t & nfrac, 
+                                        Float_t &coneptsum,  
+                                        Bool_t  &isolated) const
 {  
   //Search in cone around a candidate particle if it is isolated 
   Float_t phiC  = pCandidate->Phi() ;
@@ -116,13 +128,13 @@ void  AliIsolationCut::MakeIsolationCut(TObjArray * const plCTS,  TObjArray * co
   nfrac     = 0 ;
   coneptsum = 0.; 
   isolated  = kFALSE;
-  leading   = kTRUE;
-
+  
   //Initialize the array with refrences
   TObjArray * refclusters = 0x0;
   TObjArray * reftracks   = 0x0;
   Int_t ntrackrefs   = 0;
   Int_t nclusterrefs = 0;
+  
   //Check charged particles in cone.
   if(plCTS && (fPartInCone==kOnlyCharged || fPartInCone==kNeutralAndCharged)){
     TVector3 p3;
@@ -130,8 +142,8 @@ void  AliIsolationCut::MakeIsolationCut(TObjArray * const plCTS,  TObjArray * co
       AliAODTrack* track = (AliAODTrack *)(plCTS->At(ipr)) ; 
       //Do not count the candidate (pion, conversion photon) or the daughters of the candidate
       if(track->GetID() == pCandidate->GetTrackLabel(0) || track->GetID() == pCandidate->GetTrackLabel(1) 
-      || track->GetID() == pCandidate->GetTrackLabel(2) || track->GetID() == pCandidate->GetTrackLabel(3) 
-        ) continue ;
+         || track->GetID() == pCandidate->GetTrackLabel(2) || track->GetID() == pCandidate->GetTrackLabel(3) 
+         ) continue ;
       p3.SetXYZ(track->Px(),track->Py(),track->Pz());
       pt   = p3.Pt();
       eta  = p3.Eta();
@@ -146,15 +158,16 @@ void  AliIsolationCut::MakeIsolationCut(TObjArray * const plCTS,  TObjArray * co
         nfrac     = -1;
         coneptsum = -1;
         isolated  = kFALSE;
-       leading   = kFALSE;
         if(bFillAOD && reftracks) {
           reftracks->Clear(); 
           delete reftracks;
         }
         return ;
       }
+      
       //Check if there is any particle inside cone with pt larger than  fPtThreshold
-      rad = TMath::Sqrt((eta-etaC)*(eta-etaC)+ (phi-phiC)*(phi-phiC));
+
+      rad = Radius(etaC, phiC, eta, phi);
       
       if(rad < fConeSize){
         if(bFillAOD) {
@@ -180,7 +193,7 @@ void  AliIsolationCut::MakeIsolationCut(TObjArray * const plCTS,  TObjArray * co
   //Check neutral particles in cone.  
   if(plNe && (fPartInCone==kOnlyNeutral || fPartInCone==kNeutralAndCharged)){
          
-
+    
     TLorentzVector mom ;
     for(Int_t ipr = 0;ipr < plNe->GetEntries() ; ipr ++ ){
       AliVCluster * calo = (AliVCluster *)(plNe->At(ipr)) ;
@@ -192,11 +205,14 @@ void  AliIsolationCut::MakeIsolationCut(TObjArray * const plCTS,  TObjArray * co
       }
       
       //Do not count the candidate (photon or pi0) or the daughters of the candidate
-      if(calo->GetID() == pCandidate->GetCaloLabel(0) || calo->GetID() == pCandidate->GetCaloLabel(1)) continue ;      //Skip matched clusters with tracks
-      
-      if(calo->GetNTracksMatched() > 0) continue ; 
+      if(calo->GetID() == pCandidate->GetCaloLabel(0) || 
+         calo->GetID() == pCandidate->GetCaloLabel(1)) continue ;      
       
-      calo->GetMomentum(mom,reader->GetVertex(evtIndex)) ;//Assume that come from vertex in straight line
+      //Skip matched clusters with tracks
+      if( pid->IsTrackMatched(calo,reader->GetCaloUtils(),reader->GetInputEvent()) ) continue ;
+    
+      //Assume that come from vertex in straight line
+      calo->GetMomentum(mom,reader->GetVertex(evtIndex)) ;
       
       pt   = mom.Pt();
       eta  = mom.Eta();
@@ -204,14 +220,14 @@ void  AliIsolationCut::MakeIsolationCut(TObjArray * const plCTS,  TObjArray * co
       if(phi<0) phi+=TMath::TwoPi();
       //only loop the particle at the same side of candidate
       
-      if(TMath::Abs(phi-phiC)>TMath::PiOver2()) continue ;
       //if at the same side has particle larger than candidate, then candidate can not be the leading, skip such events
+      if(TMath::Abs(phi-phiC)>TMath::PiOver2()) continue ;
+      
       if(pt > ptC){
         n         = -1;
         nfrac     = -1;
         coneptsum = -1;
         isolated  = kFALSE;
-        leading   = kFALSE;
         if(bFillAOD){
           if(reftracks){  
             reftracks  ->Clear();
@@ -226,7 +242,9 @@ void  AliIsolationCut::MakeIsolationCut(TObjArray * const plCTS,  TObjArray * co
       }
       
       //Check if there is any particle inside cone with pt larger than  fPtThreshold
-      rad = TMath::Sqrt((eta-etaC)*(eta-etaC)+ (phi-phiC)*(phi-phiC));
+
+      rad = Radius(etaC, phiC, eta, phi);
+      
       if(rad < fConeSize){
         if(bFillAOD) {
           nclusterrefs++;
@@ -245,15 +263,15 @@ void  AliIsolationCut::MakeIsolationCut(TObjArray * const plCTS,  TObjArray * co
         if(pt > fPtThreshold )     n++;
         //if fPtFraction*ptC<fPtThreshold then consider the fPtThreshold directly
         if(fPtFraction*ptC<fPtThreshold) {
-            if(pt>fPtThreshold)    nfrac++ ;
+          if(pt>fPtThreshold)    nfrac++ ;
         }
         else {
-            if(pt>fPtFraction*ptC) nfrac++; 
+          if(pt>fPtFraction*ptC) nfrac++; 
         }
       }//in cone
     }// neutral particle loop
   }//neutrals
-
+  
   //printf("Isolation Cut: in cone with: pT>pTthres %d, pT > pTfrac*pTcandidate %d \n",n,nfrac);
   
   //Add reference arrays to AOD when filling AODs only
@@ -280,7 +298,7 @@ void  AliIsolationCut::MakeIsolationCut(TObjArray * const plCTS,  TObjArray * co
   
 }
 
-//__________________________________________________________________
+//_____________________________________________________
 void AliIsolationCut::Print(const Option_t * opt) const
 {
   
@@ -290,11 +308,30 @@ void AliIsolationCut::Print(const Option_t * opt) const
   
   printf("**** Print %s %s **** \n", GetName(), GetTitle() ) ;
   
-  printf("IC method          =     %d\n", fICMethod) ; 
-  printf("Cone Size          =     %1.2f\n", fConeSize) ; 
+  printf("IC method          =     %d\n",    fICMethod   ) ; 
+  printf("Cone Size          =     %1.2f\n", fConeSize   ) ; 
   printf("pT threshold       =     %2.1f\n", fPtThreshold) ;
-  printf("pT fraction        =     %3.1f\n", fPtFraction) ;
-  printf("particle type in cone =  %d\n",fPartInCone);
+  printf("pT fraction        =     %3.1f\n", fPtFraction ) ;
+  printf("particle type in cone =  %d\n",    fPartInCone ) ;
   printf("    \n") ;
   
 } 
+
+//___________________________________________________________________________
+Float_t AliIsolationCut::Radius(const Float_t etaC, const Float_t phiC, 
+                                const Float_t eta , const Float_t phi) const
+{
+  // Calculate the distance to trigger from any particle
+
+  Float_t dEta = etaC-eta;
+  Float_t dPhi = phiC-phi;
+  
+  if(TMath::Abs(dPhi) >= TMath::Pi()) 
+    dPhi = TMath::TwoPi()-TMath::Abs(dPhi);
+  
+  return TMath::Sqrt( dEta*dEta + dPhi*dPhi );
+  
+}
+
+
+