]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Add method to trace back the first common ancestor of 2 generated particles
authorgconesab <gconesab@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 16 Jan 2011 19:25:22 +0000 (19:25 +0000)
committergconesab <gconesab@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 16 Jan 2011 19:25:22 +0000 (19:25 +0000)
PWG4/PartCorrBase/AliMCAnalysisUtils.cxx
PWG4/PartCorrBase/AliMCAnalysisUtils.h

index c264e48ccbdd88e061df029326628d106229a197..d63538dc7cf3aafb27c952a9f083846e5d15aecf 100755 (executable)
@@ -105,6 +105,108 @@ Int_t AliMCAnalysisUtils::CheckOrigin(const Int_t * label, const Int_t nlabels,
        return tag ;
 }
 
+//_________________________________________________________________________
+Int_t AliMCAnalysisUtils::CheckCommonAncestor(const Int_t index1, const Int_t index2, AliCaloTrackReader* reader, 
+                                              Int_t & ancPDG, Int_t & ancStatus) {
+  //Check the first common ancestor of 2 clusters, given the most likely labels of the primaries generating such clusters.
+  Int_t label1[100];
+  Int_t label2[100];
+  label1[0]= index1;
+  label2[0]= index2;
+  Int_t counter1 = 0;
+  Int_t counter2 = 0;
+
+  if(label1[0]==label2[0]) {
+    //printf("AliMCAnalysisUtils::CheckCommonAncestor() - Already the same label: %d\n",label1[0]);
+    counter1=1;
+    counter2=1;
+  }
+  else{
+    if(reader->ReadAODMCParticles()){
+      TClonesArray * mcparticles = reader->GetAODMCParticles(0);
+      
+      Int_t label=label1[0];
+      while(label > -1 && counter1 < 99){
+        counter1++;
+        AliAODMCParticle * mom = (AliAODMCParticle *) mcparticles->At(label);
+        if(mom){
+         label  = mom->GetMother() ;
+         label1[counter1]=label;
+        }
+        //printf("\t counter %d, label %d\n", counter1,label);
+      }
+      //printf("Org label2=%d,\n",label2[0]);
+      label=label2[0];
+      while(label > -1 && counter2 < 99){
+        counter2++;
+        AliAODMCParticle * mom = (AliAODMCParticle *) mcparticles->At(label);
+        if(mom){
+          label  = mom->GetMother() ;
+          label2[counter2]=label;
+        }
+        //printf("\t counter %d, label %d\n", counter2,label);
+      }
+    }//AOD MC
+    else { //Kine stack from ESDs 
+      AliStack * stack = reader->GetStack();
+      Int_t label=label1[0];
+      while(label > -1 && counter1 < 99){
+        counter1++;
+        TParticle * mom = stack->Particle(label);
+        if(mom){
+          label  = mom->GetFirstMother() ;
+          label1[counter1]=label;
+        }
+        //printf("\t counter %d, label %d\n", counter1,label);
+      }
+      //printf("Org label2=%d,\n",label2[0]);
+      label=label2[0];
+      while(label > -1 && counter2 < 99){
+        counter2++;
+        TParticle * mom = stack->Particle(label);
+        if(mom){
+          label  = mom->GetFirstMother() ;
+          label2[counter2]=label;
+        }
+        //printf("\t counter %d, label %d\n", counter2,label);
+      }
+    }// Kine stack from ESDs
+  }//First labels not the same
+  
+  if(counter1==99 || counter2==99) printf("AliMCAnalysisUtils::CheckCommonAncestor() - Genealogy too large c1: %d, c2= %d\n", counter1, counter2);
+  //printf("CheckAncestor:\n");
+  Int_t commonparents = 0;
+  Int_t ancLabel = -1;
+  //printf("counters %d %d \n",counter1, counter2);
+  for (Int_t c1 = 0; c1 < counter1; c1++) {
+    for (Int_t c2 = 0; c2 < counter2; c2++) {
+      if(label1[c1]==label2[c2] && label1[c1]>-1) {
+        ancLabel = label1[c1];
+        commonparents++;
+        if(reader->ReadAODMCParticles()){
+          AliAODMCParticle * mom = (AliAODMCParticle *) reader->GetAODMCParticles(0)->At(label1[c1]);
+          if (mom) {
+            ancPDG    = mom->GetPdgCode();
+            ancStatus = mom->GetStatus();
+          }
+        }
+        else {
+          TParticle * mom = (reader->GetStack())->Particle(label1[c1]);
+          if (mom) {
+            ancPDG    = mom->GetPdgCode();
+            ancStatus = mom->GetStatusCode();
+          }
+        }
+        //First ancestor found, end the loops
+        counter1=0;
+        counter2=0;
+      }//Ancestor found
+    }//second cluster loop
+  }//first cluster loop
+  
+  return ancLabel;
+}
+
 //_________________________________________________________________________
 Int_t AliMCAnalysisUtils::CheckOrigin(const Int_t label, AliCaloTrackReader* reader, const Int_t input = 0) {
        //Play with the montecarlo particles if available
index dbfdbafde1b6c965cc6d18ca21e2d592165aa87e..00494e931a030fc512d4ebdf9605118a5acb37ad 100755 (executable)
@@ -44,6 +44,8 @@ class AliMCAnalysisUtils : public TObject {
                        kMCOther, kMCUnknown, kMCBadLabel};
        
        //Check only the label of the most significant particle
+  Int_t   CheckCommonAncestor(const Int_t index1, const Int_t index2, AliCaloTrackReader* reader, 
+                              Int_t & ancPDG, Int_t & ancStatus) ;
        Int_t   CheckOrigin(const Int_t label, AliCaloTrackReader * reader, const Int_t input) ;
        //Check the label of the most significant particle but do checks on the rest of the contributing labels
        Int_t   CheckOrigin(const Int_t *label, const Int_t nlabels, AliCaloTrackReader * reader, const Int_t input) ;