]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
I improved (by a factor 2.5) the speed of the MatchToMC method
authormorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 29 Jul 2009 08:22:06 +0000 (08:22 +0000)
committermorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 29 Jul 2009 08:22:06 +0000 (08:22 +0000)
(there were unnecessary new/delete).
I changed accordingly also the class PWG3/vertexingHF/AliAODRecoCascadeHF.cxx)
[A. Dainese]

PWG3/vertexingHF/AliAODRecoCascadeHF.cxx
STEER/AliAODRecoDecay.cxx
STEER/AliAODRecoDecay.h

index 38c92f117c82660d16ab0416e3ee5984449f1dba..4316981f8ce47c24edb44a9356a904cf2b2b7c55 100644 (file)
@@ -133,7 +133,8 @@ Int_t AliAODRecoCascadeHF::MatchToMC(Int_t pdgabs,Int_t pdgabs2prong,
     return -1;
   }
 
     return -1;
   }
 
-  if(!GetNDaughters()) {
+  Int_t ndg=GetNDaughters();
+  if(!ndg) {
     AliError("No daughters available");
     return -1;
   }
     AliError("No daughters available");
     return -1;
   }
@@ -143,10 +144,10 @@ Int_t AliAODRecoCascadeHF::MatchToMC(Int_t pdgabs,Int_t pdgabs2prong,
 
   if(lab2Prong<0) return -1;
 
 
   if(lab2Prong<0) return -1;
 
-  Int_t *dgLabels = new Int_t[GetNDaughters()];
+  Int_t dgLabels[10];
 
   // loop on daughters and write labels
 
   // loop on daughters and write labels
-  for(Int_t i=0; i<GetNDaughters(); i++) {
+  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
     AliVTrack *trk = (AliVTrack*)GetDaughter(i);
     Int_t lab = trk->GetLabel();
     if(lab==-1) { // this daughter is the 2prong
@@ -158,11 +159,7 @@ Int_t AliAODRecoCascadeHF::MatchToMC(Int_t pdgabs,Int_t pdgabs2prong,
     dgLabels[i] = lab;
   }
 
     dgLabels[i] = lab;
   }
 
-  Int_t labMother = AliAODRecoDecay::MatchToMC(pdgabs,mcArray,dgLabels);
-
-  delete [] dgLabels; dgLabels=NULL;
-
-  return labMother;
+  return AliAODRecoDecay::MatchToMC(pdgabs,mcArray,dgLabels,ndg);
 }
 //-----------------------------------------------------------------------------
 Bool_t AliAODRecoCascadeHF::SelectDstar(const Double_t *cutsDstar,
 }
 //-----------------------------------------------------------------------------
 Bool_t AliAODRecoCascadeHF::SelectDstar(const Double_t *cutsDstar,
index 6037574daba23f680ebaa9084476fde079c500c1..0c5c4fc17fb1d75f451eb9c57485577be4e9776c 100644 (file)
@@ -483,28 +483,29 @@ Int_t AliAODRecoDecay::MatchToMC(Int_t pdgabs,TClonesArray *mcArray) const
   // If yes, return label (>=0) of the AliAODMCParticle
   // 
 
   // If yes, return label (>=0) of the AliAODMCParticle
   // 
 
-  if(!GetNDaughters()) {
+  Int_t ndg=GetNDaughters();
+  if(!ndg) {
     AliError("No daughters available");
     return -1;
   }
     AliError("No daughters available");
     return -1;
   }
+  if(ndg>10) {
+    AliError("Only decays with <10 daughters supported");
+    return -1;
+  }
   
   
-  Int_t *dgLabels = new Int_t[GetNDaughters()];
+  Int_t dgLabels[10];
 
   // loop on daughters and write the labels
 
   // loop on daughters and write the labels
-  for(Int_t i=0; i<GetNDaughters(); i++) {
-    AliVTrack *trk = (AliVTrack*)GetDaughter(i);
+  for(Int_t i=0; i<ndg; i++) {
+    AliAODTrack *trk = (AliAODTrack*)GetDaughter(i);
     dgLabels[i] = trk->GetLabel();
   }
 
     dgLabels[i] = trk->GetLabel();
   }
 
-  Int_t labMother = MatchToMC(pdgabs,mcArray,dgLabels);
-
-  delete [] dgLabels; dgLabels=NULL;
-
-  return labMother;
+  return MatchToMC(pdgabs,mcArray,dgLabels,ndg);
 }
 //----------------------------------------------------------------------------
 Int_t AliAODRecoDecay::MatchToMC(Int_t pdgabs,TClonesArray *mcArray,
 }
 //----------------------------------------------------------------------------
 Int_t AliAODRecoDecay::MatchToMC(Int_t pdgabs,TClonesArray *mcArray,
-                                Int_t *dgLabels) const
+                                Int_t dgLabels[10],Int_t ndg) const
 {
   //
   // Check if this candidate is matched to a MC signal
 {
   //
   // Check if this candidate is matched to a MC signal
@@ -512,78 +513,79 @@ Int_t AliAODRecoDecay::MatchToMC(Int_t pdgabs,TClonesArray *mcArray,
   // If yes, return label (>=0) of the AliAODMCParticle
   // 
 
   // 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 labMom[10];
   Int_t i,lab,labMother,pdgMother;
   AliAODMCParticle *part=0;
   Int_t i,lab,labMother,pdgMother;
   AliAODMCParticle *part=0;
+  AliAODMCParticle *mother=0;
   Double_t pxSumDgs=0.,pySumDgs=0.,pzSumDgs=0.;
 
   // loop on daughter labels
   Double_t pxSumDgs=0.,pySumDgs=0.,pzSumDgs=0.;
 
   // loop on daughter labels
-  for(i=0; i<GetNDaughters(); i++) {
+  for(i=0; i<ndg; i++) {
     labMom[i]=-1;
     lab = dgLabels[i];
     if(lab<0) {
     labMom[i]=-1;
     lab = dgLabels[i];
     if(lab<0) {
-      printf("daughter with negative label\n");
-      continue;
+      printf("daughter with negative label %d\n",lab);
+      return -1;
     }
     part = (AliAODMCParticle*)mcArray->At(lab);
     if(!part) { 
       printf("no MC particle\n");
     }
     part = (AliAODMCParticle*)mcArray->At(lab);
     if(!part) { 
       printf("no MC particle\n");
-      continue;
+      return -1;
     }
     }
-    // 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
     // for the J/psi, check that the daughters are electrons
-    if(pdgabs==443 && TMath::Abs(part->GetPdgCode())!=11) continue;
+    if(pdgabs==443) {
+      if(TMath::Abs(part->GetPdgCode())!=11) return -1;
+    }
 
 
-    while(part->GetMother()>=0) {
-      labMother=part->GetMother();
-      part = (AliAODMCParticle*)mcArray->At(labMother);
-      if(!part) {
+    mother = part;
+    while(mother->GetMother()>=0) {
+      labMother=mother->GetMother();
+      mother = (AliAODMCParticle*)mcArray->At(labMother);
+      if(!mother) {
        printf("no MC mother particle\n");
        break;
       }
        printf("no MC mother particle\n");
        break;
       }
-      pdgMother = TMath::Abs(part->GetPdgCode());
+      pdgMother = TMath::Abs(mother->GetPdgCode());
       if(pdgMother==pdgabs) {
        labMom[i]=labMother;
       if(pdgMother==pdgabs) {
        labMom[i]=labMother;
+       // keep sum of daughters' momenta, to check for mom conservation
+       pxSumDgs += part->Px();
+       pySumDgs += part->Py();
+       pzSumDgs += part->Pz();
+       break;
+      } else if(pdgMother>pdgabs || pdgMother<10) {
        break;
       }
     }
        break;
       }
     }
-  }
+    if(labMom[i]==-1) return -1; // mother PDG not ok for this daughter
+  } // end loop on daughters
 
   // check if the candidate is signal
 
   // check if the candidate is signal
-  Bool_t isSignal=kTRUE;
   labMother=labMom[0];
   // all labels have to be the same and !=-1
   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;
+  for(i=0; i<ndg; i++) {
+    if(labMom[i]==-1)        return -1;
+    if(labMom[i]!=labMother) return -1;
   }
 
   }
 
-  delete [] labMom; labMom=NULL;
-
-  if(!isSignal) return -1;
-
-  /*  
+  
+  /*
   // check that the mother decayed in <GetNDaughters()> prongs
   // 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());
+  Int_t ndg2 = TMath::Abs(mother->GetDaughter(1)-mother->GetDaughter(0))+1;
+  printf("  MC daughters %d\n",ndg2);
+  //if(ndg!=GetNDaughters()) return -1;
+  AliAODMCParticle* p1=(AliAODMCParticle*)(mcArray->At(mother->GetDaughter(1)));
+  AliAODMCParticle* p0=(AliAODMCParticle*)(mcArray->At(mother->GetDaughter(0)));
+  printf(">>>>>>>> pdg %d  %d %d %d   %d %d\n",mother->GetDaughter(0),mother->GetDaughter(1),dgLabels[0],dgLabels[1],p0->GetPdgCode(),p1->GetPdgCode());
   */
 
   // the above works only for non-resonant decays,
   // it's better to check for mom conservation
   */
 
   // 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();
+  mother = (AliAODMCParticle*)mcArray->At(labMother);
+  Double_t pxMother = mother->Px();
+  Double_t pyMother = mother->Py();
+  Double_t pzMother = mother->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 &&
   // 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 &&
index a711d0ff34b85000dd2cf9cf414123ef23c38de9..9bc67860740b28fd5f9439b612843f833461bff6 100644 (file)
@@ -52,7 +52,6 @@ class AliAODRecoDecay : public AliVTrack {
   // If no, return -1
   // If yes, return label (>=0) of the AliAODMCParticle
   Int_t    MatchToMC(Int_t pdgabs,TClonesArray *mcArray) const;
   // If no, return -1
   // If yes, return label (>=0) of the AliAODMCParticle
   Int_t    MatchToMC(Int_t pdgabs,TClonesArray *mcArray) const;
-  Int_t    MatchToMC(Int_t pdgabs,TClonesArray *mcArray,Int_t *dgLabels) const;
 
   // PID
   void      SetPID(Int_t nprongs,Double_t *pid);
 
   // PID
   void      SetPID(Int_t nprongs,Double_t *pid);
@@ -171,6 +170,9 @@ class AliAODRecoDecay : public AliVTrack {
   Int_t GetLabel() const {return -1;}
  protected:
 
   Int_t GetLabel() const {return -1;}
  protected:
 
+  Int_t    MatchToMC(Int_t pdgabs,TClonesArray *mcArray,Int_t dgLabels[10],Int_t ndg) const;
+  Int_t    MatchToMC(Int_t pdgabs,TClonesArray *mcArray,Int_t dgLabels[10]) const { return MatchToMC(pdgabs,mcArray,dgLabels,GetNDaughters()); }
+
   TRef     fSecondaryVtx;  // decay vertex
   AliAODVertex *fOwnSecondaryVtx;  // temporary solution (to work outside AliAODEvent)
   Short_t  fCharge;  // charge, use this convention for prongs charges:
   TRef     fSecondaryVtx;  // decay vertex
   AliAODVertex *fOwnSecondaryVtx;  // temporary solution (to work outside AliAODEvent)
   Short_t  fCharge;  // charge, use this convention for prongs charges: