This is a protection against the case "label 0 tracks" in MC
authormorsch <andreas.morsch@cern.ch>
Fri, 7 Mar 2014 21:02:15 +0000 (22:02 +0100)
committermorsch <andreas.morsch@cern.ch>
Fri, 7 Mar 2014 21:02:15 +0000 (22:02 +0100)
Pietro Antonioli

STEER/AOD/AliAODpidUtil.cxx
STEER/ESD/AliESDpid.cxx

index 4c61bb4..f7c41b0 100644 (file)
@@ -55,40 +55,43 @@ Float_t AliAODpidUtil::GetTPCsignalTunedOnData(const AliVTrack *t) const {
     
     AliAODMCHeader *mcHeader = dynamic_cast<AliAODMCHeader*>(track->GetAODEvent()->GetList()->FindObject(AliAODMCHeader::StdBranchName()));
     if (mcHeader) {
+        
        TClonesArray *mcArray = (TClonesArray*)track->GetAODEvent()->GetList()->FindObject(AliAODMCParticle::StdBranchName());
        
        Bool_t kGood = kTRUE;
-       
-       Int_t iS = TMath::Abs(((AliAODMCParticle*)mcArray->At(TMath::Abs(t->GetLabel())))->GetPdgCode());
-       if(iS==AliPID::ParticleCode(AliPID::kElectron)){
+
+       if ( mcArray->At(TMath::Abs(t->GetLabel())) != NULL ) {  // protects against label-0 tracks e.g. the initial proton for Phythia events
+         Int_t iS = TMath::Abs(((AliAODMCParticle*)mcArray->At(TMath::Abs(t->GetLabel())))->GetPdgCode());
+         if(iS==AliPID::ParticleCode(AliPID::kElectron)){
            type = AliPID::kElectron;
-       }
-       else if(iS==AliPID::ParticleCode(AliPID::kMuon)){
+         }
+         else if(iS==AliPID::ParticleCode(AliPID::kMuon)){
            type = AliPID::kMuon;
-       }
-       else if(iS==AliPID::ParticleCode(AliPID::kPion)){
+         }
+         else if(iS==AliPID::ParticleCode(AliPID::kPion)){
            type = AliPID::kPion;
-       }
-       else if(iS==AliPID::ParticleCode(AliPID::kKaon)){
+         }
+         else if(iS==AliPID::ParticleCode(AliPID::kKaon)){
            type = AliPID::kKaon;
-       }
-       else if(iS==AliPID::ParticleCode(AliPID::kProton)){
+         }
+         else if(iS==AliPID::ParticleCode(AliPID::kProton)){
            type = AliPID::kProton;
-       }
-       else if(iS==AliPID::ParticleCode(AliPID::kDeuteron)){ // d
+         }
+         else if(iS==AliPID::ParticleCode(AliPID::kDeuteron)){ // d
            type = AliPID::kDeuteron;
-       }
-       else if(iS==AliPID::ParticleCode(AliPID::kTriton)){ // t
+         }
+         else if(iS==AliPID::ParticleCode(AliPID::kTriton)){ // t
            type = AliPID::kTriton;
-       }
-       else if(iS==AliPID::ParticleCode(AliPID::kHe3)){ // 3He
+         }
+         else if(iS==AliPID::ParticleCode(AliPID::kHe3)){ // 3He
            type = AliPID::kHe3;
-       }
-       else if(iS==AliPID::ParticleCode(AliPID::kAlpha)){ // 4He
+         }
+         else if(iS==AliPID::ParticleCode(AliPID::kAlpha)){ // 4He
            type = AliPID::kAlpha;
-       }
+         }
        else
            kGood = kFALSE;
+       } else kGood = kFALSE;
 
        if(kGood){
            //TODO maybe introduce different dEdxSources?
index 88a23dc..f62b3a3 100644 (file)
@@ -88,40 +88,41 @@ Float_t AliESDpid::GetTPCsignalTunedOnData(const AliVTrack *t) const {
        if(mcEvent){
            Bool_t kGood = kTRUE;
            AliMCParticle *MCpart = (AliMCParticle *) mcEvent->GetTrack(TMath::Abs(t->GetLabel()));
-           TParticle *part = MCpart->Particle();
-           
-           Int_t iS = TMath::Abs(part->GetPdgCode());
-
-           if(iS==AliPID::ParticleCode(AliPID::kElectron)){
+           if (MCpart != NULL) { // protect against label-0 track (initial proton in Pythia events)
+             TParticle *part = MCpart->Particle(); 
+             Int_t iS = TMath::Abs(part->GetPdgCode());
+             
+             if(iS==AliPID::ParticleCode(AliPID::kElectron)){
                type = AliPID::kElectron;
-           }
-           else if(iS==AliPID::ParticleCode(AliPID::kMuon)){
+             }
+             else if(iS==AliPID::ParticleCode(AliPID::kMuon)){
                type = AliPID::kMuon;
-           }
-           else if(iS==AliPID::ParticleCode(AliPID::kPion)){
+             }
+             else if(iS==AliPID::ParticleCode(AliPID::kPion)){
                type = AliPID::kPion;
-           }
-           else if(iS==AliPID::ParticleCode(AliPID::kKaon)){
+             }
+             else if(iS==AliPID::ParticleCode(AliPID::kKaon)){
                type = AliPID::kKaon;
-           }
-           else if(iS==AliPID::ParticleCode(AliPID::kProton)){
+             }
+             else if(iS==AliPID::ParticleCode(AliPID::kProton)){
                type = AliPID::kProton;
-           }
-           else if(iS==AliPID::ParticleCode(AliPID::kDeuteron)){ // d
+             }
+             else if(iS==AliPID::ParticleCode(AliPID::kDeuteron)){ // d
                type = AliPID::kDeuteron;
-           }
-           else if(iS==AliPID::ParticleCode(AliPID::kTriton)){ // t
+             }
+             else if(iS==AliPID::ParticleCode(AliPID::kTriton)){ // t
                type = AliPID::kTriton;
-           }
-           else if(iS==AliPID::ParticleCode(AliPID::kHe3)){ // 3He
+             }
+             else if(iS==AliPID::ParticleCode(AliPID::kHe3)){ // 3He
                type = AliPID::kHe3;
-           }
-           else if(iS==AliPID::ParticleCode(AliPID::kAlpha)){ // 4He
+             }
+             else if(iS==AliPID::ParticleCode(AliPID::kAlpha)){ // 4He
                type = AliPID::kAlpha;
-           }
-           else
+             }
+             else
                kGood = kFALSE;
-
+           } else kGood = kFALSE;
+           
            if(kGood){
         //TODO maybe introduce different dEdxSources?
         Double_t bethe = fTPCResponse.GetExpectedSignal(track, type, AliTPCPIDResponse::kdEdxDefault, this->UseTPCEtaCorrection(),