]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliAODRecoDecay.cxx
The total mult in V0 became float number.
[u/mrichter/AliRoot.git] / STEER / AliAODRecoDecay.cxx
index 31d07920424a67e4b82213b609554db59c38995c..6037574daba23f680ebaa9084476fde079c500c1 100644 (file)
 
 #include <TDatabasePDG.h>
 #include <TVector3.h>
-#include "AliVParticle.h"
+#include <TClonesArray.h>
+#include "AliLog.h"
+#include "AliVTrack.h"
+#include "AliAODMCParticle.h"
 #include "AliAODRecoDecay.h"
 
 ClassImp(AliAODRecoDecay)
 
 //--------------------------------------------------------------------------
 AliAODRecoDecay::AliAODRecoDecay() :
-  AliVParticle(),
+  AliVTrack(),
   fSecondaryVtx(0x0),
   fOwnSecondaryVtx(0x0),
   fCharge(0),
@@ -49,7 +52,7 @@ AliAODRecoDecay::AliAODRecoDecay(AliAODVertex *vtx2,Int_t nprongs,
                                 Short_t charge,
                                 Double_t *px,Double_t *py,Double_t *pz,
                                 Double_t *d0) :
-  AliVParticle(),
+  AliVTrack(),
   fSecondaryVtx(vtx2),
   fOwnSecondaryVtx(0x0),
   fCharge(charge),
@@ -79,7 +82,7 @@ AliAODRecoDecay::AliAODRecoDecay(AliAODVertex *vtx2,Int_t nprongs,
 AliAODRecoDecay::AliAODRecoDecay(AliAODVertex *vtx2,Int_t nprongs,
                                 Short_t charge,
                                 Double_t *d0) :
-  AliVParticle(),
+  AliVTrack(),
   fSecondaryVtx(vtx2),
   fOwnSecondaryVtx(0x0),
   fCharge(charge),
@@ -99,7 +102,7 @@ AliAODRecoDecay::AliAODRecoDecay(AliAODVertex *vtx2,Int_t nprongs,
 }
 //--------------------------------------------------------------------------
 AliAODRecoDecay::AliAODRecoDecay(const AliAODRecoDecay &source) :
-  AliVParticle(source),
+  AliVTrack(source),
   fSecondaryVtx(source.fSecondaryVtx),
   fOwnSecondaryVtx(source.fOwnSecondaryVtx),
   fCharge(source.fCharge),
@@ -114,23 +117,23 @@ AliAODRecoDecay::AliAODRecoDecay(const AliAODRecoDecay &source) :
   // Copy constructor
   //
   if(source.GetNProngs()>0) {
-    fd0 = new Double_t[GetNProngs()];
-    memcpy(fd0,source.fd0,GetNProngs()*sizeof(Double_t));
+    fd0 = new Double32_t[GetNProngs()];
+    memcpy(fd0,source.fd0,GetNProngs()*sizeof(Double32_t));
     if(source.fPx) {
-      fPx = new Double_t[GetNProngs()];
-      fPy = new Double_t[GetNProngs()];
-      fPz = new Double_t[GetNProngs()];
-      memcpy(fPx,source.fPx,GetNProngs()*sizeof(Double_t));
-      memcpy(fPy,source.fPy,GetNProngs()*sizeof(Double_t));
-      memcpy(fPz,source.fPz,GetNProngs()*sizeof(Double_t));
+      fPx = new Double32_t[GetNProngs()];
+      fPy = new Double32_t[GetNProngs()];
+      fPz = new Double32_t[GetNProngs()];
+      memcpy(fPx,source.fPx,GetNProngs()*sizeof(Double32_t));
+      memcpy(fPy,source.fPy,GetNProngs()*sizeof(Double32_t));
+      memcpy(fPz,source.fPz,GetNProngs()*sizeof(Double32_t));
     }
     if(source.fPID) {
-      fPID = new Double_t[5*GetNProngs()];
-      memcpy(fPID,source.fPID,GetNProngs()*sizeof(Double_t));
+      fPID = new Double32_t[fNPID];
+      memcpy(fPID,source.fPID,fNPID*sizeof(Double32_t));
     }
     if(source.fDCA) {
-      fDCA = new Double_t[GetNProngs()*(GetNProngs()-1)/2];
-      memcpy(fDCA,source.fDCA,(GetNProngs()*(GetNProngs()-1)/2)*sizeof(Double_t));
+      fDCA = new Double32_t[fNDCA];
+      memcpy(fDCA,source.fDCA,fNDCA*sizeof(Double32_t));
     }
   }
 }
@@ -150,23 +153,29 @@ AliAODRecoDecay &AliAODRecoDecay::operator=(const AliAODRecoDecay &source)
   fEventNumber = source.fEventNumber;
   fRunNumber = source.fRunNumber;
   if(source.GetNProngs()>0) {
-    fd0 = new Double_t[GetNProngs()];
-    memcpy(fd0,source.fd0,GetNProngs()*sizeof(Double_t));
+    if(fd0)delete [] fd0; 
+    fd0 = new Double32_t[GetNProngs()];
+    memcpy(fd0,source.fd0,GetNProngs()*sizeof(Double32_t));
     if(source.fPx) {
-      fPx = new Double_t[GetNProngs()];
-      fPy = new Double_t[GetNProngs()];
-      fPz = new Double_t[GetNProngs()];
-      memcpy(fPx,source.fPx,GetNProngs()*sizeof(Double_t));
-      memcpy(fPy,source.fPy,GetNProngs()*sizeof(Double_t));
-      memcpy(fPz,source.fPz,GetNProngs()*sizeof(Double_t));
+      if(fPx) delete [] fPx; 
+      fPx = new Double32_t[GetNProngs()];
+      if(fPy) delete [] fPy; 
+      fPy = new Double32_t[GetNProngs()];
+      if(fPz) delete [] fPz; 
+      fPz = new Double32_t[GetNProngs()];
+      memcpy(fPx,source.fPx,GetNProngs()*sizeof(Double32_t));
+      memcpy(fPy,source.fPy,GetNProngs()*sizeof(Double32_t));
+      memcpy(fPz,source.fPz,GetNProngs()*sizeof(Double32_t));
     }
     if(source.fPID) {
-      fPID = new Double_t[5*GetNProngs()];
-      memcpy(fPID,source.fPID,GetNProngs()*sizeof(Double_t));
+      if(fPID) delete [] fPID; 
+      fPID = new Double32_t[fNPID];
+      memcpy(fPID,source.fPID,fNPID*sizeof(Double32_t));
     }
     if(source.fDCA) {
-      fDCA = new Double_t[GetNProngs()*(GetNProngs()-1)/2];
-      memcpy(fDCA,source.fDCA,(GetNProngs()*(GetNProngs()-1)/2)*sizeof(Double32_t));
+      if(fDCA) delete [] fDCA; 
+      fDCA = new Double32_t[fNDCA];
+      memcpy(fDCA,source.fDCA,fNDCA*sizeof(Double32_t));
     }
   }
   return *this;
@@ -305,17 +314,113 @@ Double_t AliAODRecoDecay::EProng(Int_t ip,UInt_t pdg) const
   Double_t mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
   return TMath::Sqrt(mass*mass+PProng(ip)*PProng(ip));
 }
-//---------------------------------------------------------------------------
-/*Int_t AliAODRecoDecay::GetIndexProng(Int_t ip) const
-{ 
-  //
-  // Index of prong ip
+//--------------------------------------------------------------------------
+Bool_t AliAODRecoDecay::GetCovarianceXYZPxPyPz(Double_t cv[21]) const {
+  //
+  // This function returns the global covariance matrix of the track params
+  // 
+  // Cov(x,x) ... :   cv[0]
+  // Cov(y,x) ... :   cv[1]  cv[2]
+  // Cov(z,x) ... :   cv[3]  cv[4]  cv[5]
+  // Cov(px,x)... :   cv[6]  cv[7]  cv[8]  cv[9]
+  // Cov(py,x)... :   cv[10] cv[11] cv[12] cv[13] cv[14]
+  // Cov(pz,x)... :   cv[15] cv[16] cv[17] cv[18] cv[19] cv[20]
+  //
+  // For XYZ we take the cov of the vertex, for PxPyPz we take the 
+  // sum of the covs of PxPyPz from the daughters, for the moment 
+  // we set the cov between position and momentum as the sum of 
+  // the same cov from the daughters.
   //
-  if(!GetNProngs()) return 999999;
-UShort_t *indices = GetSecondaryVtx()->GetIndices();
-  return indices[ip];
-}*/
+
+  Int_t j;
+  for(j=0;j<21;j++) cv[j]=0.;
+
+  if(!GetNDaughters()) {
+    AliError("No daughters available");
+    return kFALSE;
+  }
+
+  Double_t v[6];
+  AliAODVertex *secv=GetSecondaryVtx();
+  if(!secv) {
+    AliError("Vertex covariance matrix not available");
+    return kFALSE;
+  }
+  if(!secv->GetCovMatrix(v)) {
+    AliError("Vertex covariance matrix not available");
+    return kFALSE;
+  }
+
+  Double_t p[21]; for(j=0;j<21;j++) p[j]=0.;
+  Bool_t error=kFALSE;
+  for(Int_t i=1; i<GetNDaughters(); i++) {
+    AliVTrack *daugh = (AliVTrack*)GetDaughter(i);
+    Double_t dcov[21];
+    if(!daugh->GetCovarianceXYZPxPyPz(dcov)) error=kTRUE;
+    for(j=0;j<21;j++) p[j] += dcov[j];
+  }
+  if(error) {
+    AliError("No covariance for at least one daughter")
+    return kFALSE;
+  }
+
+  for(j=0; j<21; j++) {
+    if(j<6) {
+      cv[j] = v[j];
+    } else {
+      cv[j] = p[j];
+    }
+  }
+
+  return kTRUE;
+}
 //----------------------------------------------------------------------------
+UChar_t  AliAODRecoDecay::GetITSClusterMap() const {
+  //
+  // We take the logical AND of the daughters cluster maps 
+  // (only if all daughters have the bit for given layer, we set the bit)
+  //
+  UChar_t map=0;
+
+  if(!GetNDaughters()) {
+    AliError("No daughters available");
+    return map;
+  }
+
+  for(Int_t l=0; l<12; l++) { // loop on ITS layers (from here we cannot know how many they are; let's put 12 to be conservative)
+    Int_t bit = 1;
+    for(Int_t i=0; i<GetNDaughters(); i++) {
+      AliVTrack *daugh = (AliVTrack*)GetDaughter(i);
+      if(!TESTBIT(daugh->GetITSClusterMap(),l)) bit=0; 
+    }
+    if(bit) SETBIT(map,l);
+  }
+
+  return map;
+}
+//--------------------------------------------------------------------------
+ULong_t AliAODRecoDecay::GetStatus() const {
+  // 
+  // Same as for ITSClusterMap
+  //
+  ULong_t status=0;
+
+  if(!GetNDaughters()) {
+    AliError("No daughters available");
+    return status;
+  }
+
+  AliVTrack *daugh0 = (AliVTrack*)GetDaughter(0);
+  status = status&(daugh0->GetStatus());
+
+  for(Int_t i=1; i<GetNDaughters(); i++) {
+    AliVTrack *daugh = (AliVTrack*)GetDaughter(i);
+    status = status&(daugh->GetStatus());
+  }
+
+  return status;
+}
+//--------------------------------------------------------------------------
 Double_t AliAODRecoDecay::ImpParXY(Double_t point[3]) const 
 {
   //
@@ -369,6 +474,124 @@ Double_t AliAODRecoDecay::InvMass2Prongs(Int_t ip1,Int_t ip2,
 
   return mass;
 }
+//----------------------------------------------------------------------------
+Int_t AliAODRecoDecay::MatchToMC(Int_t pdgabs,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(!GetNDaughters()) {
+    AliError("No daughters available");
+    return -1;
+  }
+  
+  Int_t *dgLabels = new Int_t[GetNDaughters()];
+
+  // loop on daughters and write the labels
+  for(Int_t i=0; i<GetNDaughters(); i++) {
+    AliVTrack *trk = (AliVTrack*)GetDaughter(i);
+    dgLabels[i] = trk->GetLabel();
+  }
+
+  Int_t labMother = MatchToMC(pdgabs,mcArray,dgLabels);
+
+  delete [] dgLabels; dgLabels=NULL;
+
+  return labMother;
+}
+//----------------------------------------------------------------------------
+Int_t AliAODRecoDecay::MatchToMC(Int_t pdgabs,TClonesArray *mcArray,
+                                Int_t *dgLabels) const
+{
+  //
+  // Check if this candidate is matched to a MC signal
+  // If no, return -1
+  // If yes, return label (>=0) of the AliAODMCParticle
+  // 
+
+  if(!GetNDaughters()) {
+    AliError("No daughters available");
+    return -1;
+  }
+  
+  Int_t *labMom = new Int_t[GetNDaughters()];
+  Int_t i,lab,labMother,pdgMother;
+  AliAODMCParticle *part=0;
+  Double_t pxSumDgs=0.,pySumDgs=0.,pzSumDgs=0.;
+
+  // loop on daughter labels
+  for(i=0; i<GetNDaughters(); i++) {
+    labMom[i]=-1;
+    lab = dgLabels[i];
+    if(lab<0) {
+      printf("daughter with negative label\n");
+      continue;
+    }
+    part = (AliAODMCParticle*)mcArray->At(lab);
+    if(!part) { 
+      printf("no MC particle\n");
+      continue;
+    }
+    // keep sum of daughters' momenta, to check for mom conservation
+    pxSumDgs += part->Px();
+    pySumDgs += part->Py();
+    pzSumDgs += part->Pz();
+    // for the J/psi, check that the daughters are electrons
+    if(pdgabs==443 && TMath::Abs(part->GetPdgCode())!=11) continue;
+
+    while(part->GetMother()>=0) {
+      labMother=part->GetMother();
+      part = (AliAODMCParticle*)mcArray->At(labMother);
+      if(!part) {
+       printf("no MC mother particle\n");
+       break;
+      }
+      pdgMother = TMath::Abs(part->GetPdgCode());
+      if(pdgMother==pdgabs) {
+       labMom[i]=labMother;
+       break;
+      }
+    }
+  }
+
+  // check if the candidate is signal
+  Bool_t isSignal=kTRUE;
+  labMother=labMom[0];
+  // all labels have to be the same and !=-1
+  for(i=0; i<GetNDaughters(); i++) {
+    if(labMom[i]==-1 || labMom[i]!=labMother) isSignal=kFALSE;
+  }
+
+  delete [] labMom; labMom=NULL;
+
+  if(!isSignal) return -1;
+
+  /*  
+  // check that the mother decayed in <GetNDaughters()> prongs
+  Int_t ndg = TMath::Abs(part->GetDaughter(1)-part->GetDaughter(0))+1;
+  if(ndg!=GetNDaughters()) return -1;
+  AliAODMCParticle* p1=(AliAODMCParticle*)(mcArray->At(part->GetDaughter(1)));
+  AliAODMCParticle* p0=(AliAODMCParticle*)(mcArray->At(part->GetDaughter(0)));
+  printf("pdg %d  %d %d %d   %d %d\n",part->GetDaughter(1),part->GetDaughter(0),dgLabels[0],dgLabels[1],p0->GetPdgCode(),p1->GetPdgCode());
+  */
+
+  // the above works only for non-resonant decays,
+  // it's better to check for mom conservation
+  part = (AliAODMCParticle*)mcArray->At(labMother);
+  Double_t pxMother = part->Px();
+  Double_t pyMother = part->Py();
+  Double_t pzMother = part->Pz();
+  // within 0.1%
+  if((TMath::Abs(pxMother-pxSumDgs)/(TMath::Abs(pxMother)+1.e-13)) > 0.001 &&
+     (TMath::Abs(pyMother-pySumDgs)/(TMath::Abs(pyMother)+1.e-13)) > 0.001 &&
+     (TMath::Abs(pzMother-pzSumDgs)/(TMath::Abs(pzMother)+1.e-13)) > 0.001) 
+    return -1;
+  return labMother;
+}
 //---------------------------------------------------------------------------
 void AliAODRecoDecay::Print(Option_t* /*option*/) const 
 {