I improved (by a factor 2.5) the speed of the MatchToMC method
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliAODRecoCascadeHF.cxx
index 53de3598229b5cc80f2728e8ba9f06c38b71cbcc..4316981f8ce47c24edb44a9356a904cf2b2b7c55 100644 (file)
 //
 // Class for AOD reconstructed heavy-flavour cascades
 //
-// Author: X-M. Zhang, zhangxm@iop.ccnu.edu.cn
+// Author: X-M. Zhang, zhangxm@iopp.ccnu.edu.cn
 /////////////////////////////////////////////////////////////
 
 #include <TVector3.h>
 #include <TDatabasePDG.h>
+#include <TClonesArray.h>
+#include "AliAODMCParticle.h"
 #include "AliAODRecoDecay.h"
 #include "AliAODVertex.h"
 #include "AliAODRecoDecayHF2Prong.h"
@@ -116,6 +118,49 @@ Double_t AliAODRecoCascadeHF::InvMassDstarKpipi() const
 
   return minv;
 }
+//----------------------------------------------------------------------------
+Int_t AliAODRecoCascadeHF::MatchToMC(Int_t pdgabs,Int_t pdgabs2prong,
+                                    TClonesArray *mcArray) const
+{
+  //
+  // Check if this candidate is matched to a MC signal
+  // If no, return -1
+  // If yes, return label (>=0) of the AliAODMCParticle
+  // 
+
+  if(pdgabs!=413) {
+    printf("Only D*+ implemented\n"); 
+    return -1;
+  }
+
+  Int_t ndg=GetNDaughters();
+  if(!ndg) {
+    AliError("No daughters available");
+    return -1;
+  }
+  
+  AliAODRecoDecayHF2Prong *the2Prong = Get2Prong();
+  Int_t lab2Prong = the2Prong->MatchToMC(pdgabs2prong,mcArray);
+
+  if(lab2Prong<0) return -1;
+
+  Int_t dgLabels[10];
+
+  // loop on daughters and write labels
+  for(Int_t i=0; i<ndg; i++) {
+    AliVTrack *trk = (AliVTrack*)GetDaughter(i);
+    Int_t lab = trk->GetLabel();
+    if(lab==-1) { // this daughter is the 2prong
+      lab=lab2Prong;
+    } else if(lab<-1) {
+      printf("daughter with negative label\n");
+      continue;
+    }
+    dgLabels[i] = lab;
+  }
+
+  return AliAODRecoDecay::MatchToMC(pdgabs,mcArray,dgLabels,ndg);
+}
 //-----------------------------------------------------------------------------
 Bool_t AliAODRecoCascadeHF::SelectDstar(const Double_t *cutsDstar,
                                        const Double_t *cutsD0,