From 04f7a616120b130d231abd1c0d2f178d267e6107 Mon Sep 17 00:00:00 2001 From: gconesab Date: Wed, 25 Jan 2012 09:59:12 +0000 Subject: [PATCH] coverity, move similar code in several analysis code classes to a single method in the analysis base class --- .../AliAnaCaloTrackCorrBaseClass.cxx | 29 ++++++++ .../AliAnaCaloTrackCorrBaseClass.h | 3 +- .../AliAnaParticleHadronCorrelation.cxx | 66 +++++++------------ .../AliAnaParticleHadronCorrelation.h | 4 +- .../AliAnaParticleIsolation.cxx | 19 +----- 5 files changed, 60 insertions(+), 61 deletions(-) diff --git a/PWG/CaloTrackCorrBase/AliAnaCaloTrackCorrBaseClass.cxx b/PWG/CaloTrackCorrBase/AliAnaCaloTrackCorrBaseClass.cxx index 15b097757d6..68429e64d4f 100755 --- a/PWG/CaloTrackCorrBase/AliAnaCaloTrackCorrBaseClass.cxx +++ b/PWG/CaloTrackCorrBase/AliAnaCaloTrackCorrBaseClass.cxx @@ -110,6 +110,35 @@ void AliAnaCaloTrackCorrBaseClass::AddAODParticle(AliAODPWG4Particle pc) } +//_______________________________________________________________________________ +Int_t AliAnaCaloTrackCorrBaseClass::CheckMixedEventVertex(const Int_t caloLabel, + const Int_t trackLabel) +{ + // Check vertex in mixed events + + if (!GetMixedEvent()) return 1; // Not mixed event continue normal processing + + Int_t evt = -1; + + if (caloLabel >= 0 ) + { + evt = GetMixedEvent()->EventIndexForCaloCluster(caloLabel) ; + } + else if(trackLabel >= 0 ) + { + evt = GetMixedEvent()->EventIndex(trackLabel) ; + } + else + return 0; // go to next entry in the particle list + + if(evt == -1) + return 0 ; // to content coverity + + if (TMath::Abs(GetVertex(evt)[2]) > GetZvertexCut()) return -1; // Vertex out of range process next event + + return 1 ; // continue processing normally + +} //________________________________________________________________ void AliAnaCaloTrackCorrBaseClass::ConnectInputOutputAODBranches() diff --git a/PWG/CaloTrackCorrBase/AliAnaCaloTrackCorrBaseClass.h b/PWG/CaloTrackCorrBase/AliAnaCaloTrackCorrBaseClass.h index ad7d9e49721..f85b4b9c006 100755 --- a/PWG/CaloTrackCorrBase/AliAnaCaloTrackCorrBaseClass.h +++ b/PWG/CaloTrackCorrBase/AliAnaCaloTrackCorrBaseClass.h @@ -177,7 +177,8 @@ public: virtual void SetNMaxEvMix(Int_t n=20) { fNmaxMixEv = n ;} //maximal number of events for mixing virtual void SetMultiplicity(Int_t multimin, Int_t multimax) {fMinMulti = multimin ; fMaxMulti = multimax ; } - //Mixed event + //Mixed event + virtual Int_t CheckMixedEventVertex(const Int_t caloLabel, const Int_t trackLabel) ; virtual AliMixedEvent * GetMixedEvent() { return GetReader()->GetMixedEvent() ; } virtual Int_t GetNMixedEvent() const { return GetReader()->GetNMixedEvent() ; } diff --git a/PWGGA/CaloTrackCorrelations/AliAnaParticleHadronCorrelation.cxx b/PWGGA/CaloTrackCorrelations/AliAnaParticleHadronCorrelation.cxx index 92ec915242d..56b38e16b61 100755 --- a/PWGGA/CaloTrackCorrelations/AliAnaParticleHadronCorrelation.cxx +++ b/PWGGA/CaloTrackCorrelations/AliAnaParticleHadronCorrelation.cxx @@ -773,27 +773,15 @@ void AliAnaParticleHadronCorrelation::MakeAnalysisFillAOD() Double_t ptTrig = fMinTriggerPt ; fLeadingTriggerIndex = -1 ; Int_t naod = GetInputAODBranch()->GetEntriesFast() ; - for(Int_t iaod = 0; iaod < naod ; iaod++){ + for(Int_t iaod = 0; iaod < naod ; iaod++) + { AliAODPWG4ParticleCorrelation* particle = (AliAODPWG4ParticleCorrelation*) (GetInputAODBranch()->At(iaod)); - //vertex cut in case of mixing - if (GetMixedEvent()) { - Int_t evt=-1; - Int_t id =-1; - if (particle->GetCaloLabel(0) >= 0 ){ - id=particle->GetCaloLabel(0); - if(id >= 0 )evt= GetMixedEvent()-> EventIndexForCaloCluster(id) ; - } - else if(particle->GetTrackLabel(0) >= 0 ){ - id=particle->GetTrackLabel(0); - if(id >= 0 )evt= GetMixedEvent()->EventIndex(id) ; - } - else continue; - - if (TMath::Abs(GetVertex(evt)[2]) > GetZvertexCut()) - return ; - } - + // Vertex cut in case of mixing + Int_t check = CheckMixedEventVertex(particle->GetCaloLabel(0), particle->GetTrackLabel(0)); + if(check == 0) continue; + if(check == -1) return; + // find the leading particles with highest momentum if (particle->Pt() > ptTrig) { ptTrig = particle->Pt() ; @@ -848,28 +836,18 @@ void AliAnaParticleHadronCorrelation::MakeAnalysisFillHistograms() //Loop on stored AOD particles, find leading Double_t ptTrig = fMinTriggerPt; - if(fLeadingTriggerIndex < 0){//Search leading if not done before + if(fLeadingTriggerIndex < 0) + { + //Search leading if not done before Int_t naod = GetInputAODBranch()->GetEntriesFast() ; for(Int_t iaod = 0; iaod < naod ; iaod++){ //loop on input trigger AOD file AliAODPWG4ParticleCorrelation* particle = (AliAODPWG4ParticleCorrelation*) (GetInputAODBranch()->At(iaod)); - //vertex cut in case of mixing - if (GetMixedEvent()) { - Int_t evt=-1; - Int_t id =-1; - if (particle->GetCaloLabel(0) >= 0 ){ - id=particle->GetCaloLabel(0); - if(id >= 0 )evt= GetMixedEvent()-> EventIndexForCaloCluster(id) ; - } - else if(particle->GetTrackLabel(0) >= 0 ){ - id=particle->GetTrackLabel(0); - if(id >= 0 )evt= GetMixedEvent()->EventIndex(id) ; - } - else continue; - - if (TMath::Abs(GetVertex(evt)[2]) > GetZvertexCut()) - return ; - } - + + // Vertex cut in case of mixing + Int_t check = CheckMixedEventVertex(particle->GetCaloLabel(0), particle->GetTrackLabel(0)); + if(check == 0) continue; + if(check == -1) return; + //check if the particle is isolated or if we want to take the isolation into account if(OnlyIsolated() && !particle->IsIsolated()) continue; @@ -937,7 +915,8 @@ Bool_t AliAnaParticleHadronCorrelation::MakeChargedCorrelation(AliAODPWG4Partic Double_t v[3] = {0,0,0}; //vertex ; GetReader()->GetVertex(v); - if (GetMixedEvent()) { + if (GetMixedEvent()) + { evtIndex11 = GetMixedEvent()->EventIndexForCaloCluster(aodParticle->GetCaloLabel(0)) ; evtIndex12 = GetMixedEvent()->EventIndexForCaloCluster(aodParticle->GetCaloLabel(1)) ; evtIndex13 = GetMixedEvent()->EventIndex(aodParticle->GetTrackLabel(0)) ; @@ -1043,7 +1022,8 @@ Bool_t AliAnaParticleHadronCorrelation::MakeChargedCorrelation(AliAODPWG4Partic //Only for mixed event Int_t evtIndex2 = 0 ; - if (GetMixedEvent()) { + if (GetMixedEvent()) + { evtIndex2 = GetMixedEvent()->EventIndex(track->GetID()) ; if (evtIndex11 == evtIndex2 || evtIndex12 == evtIndex2 || evtIndex13 == evtIndex2 ) // photon and track from different events continue ; @@ -1239,7 +1219,8 @@ Bool_t AliAnaParticleHadronCorrelation::MakeNeutralCorrelation(AliAODPWG4Partic Int_t evtIndex11 = 0 ; Int_t evtIndex12 = 0 ; - if (GetMixedEvent()) { + if (GetMixedEvent()) + { evtIndex11 = GetMixedEvent()->EventIndexForCaloCluster(aodParticle->GetCaloLabel(0)) ; evtIndex12 = GetMixedEvent()->EventIndexForCaloCluster(aodParticle->GetCaloLabel(1)) ; } @@ -1322,7 +1303,8 @@ Bool_t AliAnaParticleHadronCorrelation::MakeNeutralCorrelation(AliAODPWG4Partic Int_t evtIndex2 = 0 ; Int_t evtIndex3 = 0 ; - if (GetMixedEvent()) { + if (GetMixedEvent()) + { evtIndex2 = GetMixedEvent()->EventIndexForCaloCluster(pi0->GetCaloLabel(0)) ; evtIndex3 = GetMixedEvent()->EventIndexForCaloCluster(pi0->GetCaloLabel(1)) ; diff --git a/PWGGA/CaloTrackCorrelations/AliAnaParticleHadronCorrelation.h b/PWGGA/CaloTrackCorrelations/AliAnaParticleHadronCorrelation.h index dd983d29851..c254356bb30 100755 --- a/PWGGA/CaloTrackCorrelations/AliAnaParticleHadronCorrelation.h +++ b/PWGGA/CaloTrackCorrelations/AliAnaParticleHadronCorrelation.h @@ -33,7 +33,7 @@ class AliAnaParticleHadronCorrelation : public AliAnaCaloTrackCorrBaseClass { virtual ~AliAnaParticleHadronCorrelation() {;} //virtual dtor // General methods - + TObjString * GetAnalysisCuts(); TList * GetCreateOutputObjects(); @@ -224,7 +224,7 @@ class AliAnaParticleHadronCorrelation : public AliAnaCaloTrackCorrBaseClass { AliAnaParticleHadronCorrelation(const AliAnaParticleHadronCorrelation & ph) ; // cpy ctor AliAnaParticleHadronCorrelation & operator = (const AliAnaParticleHadronCorrelation & ph) ;//cpy assignment - ClassDef(AliAnaParticleHadronCorrelation,9) + ClassDef(AliAnaParticleHadronCorrelation,10) } ; diff --git a/PWGGA/CaloTrackCorrelations/AliAnaParticleIsolation.cxx b/PWGGA/CaloTrackCorrelations/AliAnaParticleIsolation.cxx index 8af49aec398..04433f0dbca 100755 --- a/PWGGA/CaloTrackCorrelations/AliAnaParticleIsolation.cxx +++ b/PWGGA/CaloTrackCorrelations/AliAnaParticleIsolation.cxx @@ -797,22 +797,9 @@ void AliAnaParticleIsolation::MakeAnalysisFillAOD() continue ; //trigger should not come from underlying event //vertex cut in case of mixing - if (GetMixedEvent()) { - Int_t evt=-1; - Int_t id =-1; - if (aodinput->GetCaloLabel(0) >= 0 ){ - id=aodinput->GetCaloLabel(0); - if(id >= 0 )evt= GetMixedEvent()-> EventIndexForCaloCluster(id) ; - } - else if(aodinput->GetTrackLabel(0) >= 0 ){ - id=aodinput->GetTrackLabel(0); - if(id >= 0 )evt= GetMixedEvent()->EventIndex(id) ; - } - else continue; - - if (TMath::Abs(GetVertex(evt)[2]) > GetZvertexCut()) - return ; - } + Int_t check = CheckMixedEventVertex(aodinput->GetCaloLabel(0), aodinput->GetTrackLabel(0)); + if(check == 0) continue; + if(check == -1) return; //find the leading particles with highest momentum if ((aodinput->Pt())>ptLeading) { -- 2.43.5