]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
additional protections for MC particles: label out of range and NULL dereferencing
authormkrzewic <mkrzewic@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 28 Jul 2013 13:07:44 +0000 (13:07 +0000)
committermkrzewic <mkrzewic@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 28 Jul 2013 13:07:44 +0000 (13:07 +0000)
PWGPP/AliAnalysisTaskFilteredTree.cxx

index 7712f17ca8a296806898024c1d1937bdd1ce7219..305bed2951db59ab5459b4579476b6039ce9e533 100644 (file)
@@ -1130,6 +1130,7 @@ void AliAnalysisTaskFilteredTree::ProcessAll(AliESDEvent *const esdEvent, AliMCE
         Int_t label = TMath::Abs(track->GetLabel()); \r
         if (label >= mcStackSize) continue;\r
         particle = stack->Particle(label);\r
+        if (!particle) continue;\r
         if(particle && particle->GetPDG() && particle->GetPDG()->Charge()!=0.)\r
        {\r
          particleMother = GetMother(particle,stack);\r
@@ -1144,7 +1145,9 @@ void AliAnalysisTaskFilteredTree::ProcessAll(AliESDEvent *const esdEvent, AliMCE
        // TPC track\r
        //\r
        Int_t labelTPC = TMath::Abs(track->GetTPCLabel()); \r
+        if (labelTPC >= mcStackSize) continue;\r
         particleTPC = stack->Particle(labelTPC);\r
+        if (!particleTPC) continue;\r
         if(particleTPC && particleTPC->GetPDG() && particleTPC->GetPDG()->Charge()!=0.)\r
        {\r
          particleMotherTPC = GetMother(particleTPC,stack);\r
@@ -1161,7 +1164,7 @@ void AliAnalysisTaskFilteredTree::ProcessAll(AliESDEvent *const esdEvent, AliMCE
        //\r
         TParticle *part=0;\r
         TClonesArray *trefs=0;\r
-        Int_t status = mcEvent->GetParticleAndTR(TMath::Abs(track->GetTPCLabel()), part, trefs);\r
+        Int_t status = mcEvent->GetParticleAndTR(TMath::Abs(labelTPC), part, trefs);\r
 \r
        if(status>0 && part && trefs && part->GetPDG() && part->GetPDG()->Charge()!=0.) \r
        {\r
@@ -1243,7 +1246,9 @@ void AliAnalysisTaskFilteredTree::ProcessAll(AliESDEvent *const esdEvent, AliMCE
        // ITS track\r
        //\r
        Int_t labelITS = TMath::Abs(track->GetITSLabel()); \r
+        if (labelITS >= mcStackSize) continue;\r
         particleITS = stack->Particle(labelITS);\r
+        if (!particleITS) continue;\r
         if(particleITS && particleITS->GetPDG() && particleITS->GetPDG()->Charge()!=0.)\r
        {\r
          particleMotherITS = GetMother(particleITS,stack);\r
@@ -2212,6 +2217,8 @@ TParticle *AliAnalysisTaskFilteredTree::GetMother(TParticle *const particle, Ali
 \r
   Int_t motherLabel = TMath::Abs(particle->GetMother(0));  \r
   TParticle* mother = NULL; \r
+  Int_t mcStackSize=stack->GetNtrack();\r
+  if (motherLabel>=mcStackSize) return NULL;\r
   mother = stack->Particle(motherLabel); \r
 \r
 return mother;\r
@@ -2223,7 +2230,10 @@ Bool_t AliAnalysisTaskFilteredTree::IsFromConversion(const Int_t label, AliStack
   Bool_t isFromConversion = kFALSE;\r
 \r
   if(stack) {\r
+    Int_t mcStackSize=stack->GetNtrack();\r
+    if (label>=mcStackSize) return kFALSE;\r
     TParticle* particle = stack->Particle(label);\r
+    if (!particle) return kFALSE;\r
 \r
     if(particle && particle->GetPDG() && particle->GetPDG()->Charge()!=0) \r
     {\r
@@ -2231,6 +2241,7 @@ Bool_t AliAnalysisTaskFilteredTree::IsFromConversion(const Int_t label, AliStack
        Bool_t isPrim = stack->IsPhysicalPrimary(label);\r
 \r
        Int_t motherLabel = TMath::Abs(particle->GetMother(0));  \r
+       if (motherLabel>=mcStackSize) return kFALSE;\r
        TParticle* mother = stack->Particle(motherLabel); \r
        if(mother) {\r
           Int_t motherPdg = mother->GetPdgCode();\r
@@ -2251,7 +2262,10 @@ Bool_t AliAnalysisTaskFilteredTree::IsFromMaterial(const Int_t label, AliStack *
   Bool_t isFromMaterial = kFALSE;\r
 \r
   if(stack) {\r
+    Int_t mcStackSize=stack->GetNtrack();\r
+    if (label>=mcStackSize) return kFALSE;\r
     TParticle* particle = stack->Particle(label);\r
+    if (!particle) return kFALSE;\r
 \r
     if(particle && particle->GetPDG() && particle->GetPDG()->Charge()!=0) \r
     {\r
@@ -2259,6 +2273,7 @@ Bool_t AliAnalysisTaskFilteredTree::IsFromMaterial(const Int_t label, AliStack *
        Bool_t isPrim = stack->IsPhysicalPrimary(label);\r
 \r
        Int_t motherLabel = TMath::Abs(particle->GetMother(0));  \r
+       if (motherLabel>=mcStackSize) return kFALSE;\r
        TParticle* mother = stack->Particle(motherLabel); \r
        if(mother) {\r
           if(!isPrim && mech==13) { \r
@@ -2277,7 +2292,10 @@ Bool_t AliAnalysisTaskFilteredTree::IsFromStrangeness(const Int_t label, AliStac
   Bool_t isFromStrangeness = kFALSE;\r
 \r
   if(stack) {\r
+    Int_t mcStackSize=stack->GetNtrack();\r
+    if (label>=mcStackSize) return kFALSE;\r
     TParticle* particle = stack->Particle(label);\r
+    if (!particle) return kFALSE;\r
 \r
     if(particle && particle->GetPDG() && particle->GetPDG()->Charge()!=0) \r
     {\r
@@ -2285,6 +2303,7 @@ Bool_t AliAnalysisTaskFilteredTree::IsFromStrangeness(const Int_t label, AliStac
        Bool_t isPrim = stack->IsPhysicalPrimary(label);\r
 \r
        Int_t motherLabel = TMath::Abs(particle->GetMother(0));  \r
+       if (motherLabel>=mcStackSize) return kFALSE;\r
        TParticle* mother = stack->Particle(motherLabel); \r
        if(mother) {\r
           Int_t motherPdg = mother->GetPdgCode();\r