]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EVGEN/AliGenParam.cxx
Merging the VirtualMC branch to the main development branch (HEAD)
[u/mrichter/AliRoot.git] / EVGEN / AliGenParam.cxx
index 3ca54db3b3161e94687a0ee813a95585d6415d1c..45d628b0363b5b670d67cbcfd7315043f4e9d0dd 100644 (file)
 
 /*
 $Log$
+Revision 1.36.6.3  2002/10/10 16:40:08  hristov
+Updating VirtualMC to v3-09-02
+
+Revision 1.39  2002/09/16 08:21:16  morsch
+Use TDatabasePDG::Instance();
+
+Revision 1.38  2002/05/30 14:59:12  morsch
+Check geometrical acceptance. (G. Martinez)
+
+Revision 1.37  2002/04/17 10:20:44  morsch
+Coding Rule violations corrected.
+
+Revision 1.36  2002/02/08 16:50:50  morsch
+Add name and title in constructor.
+
+Revision 1.35  2002/01/21 10:02:40  morsch
+ty is Double_t
+Abort if too high rapidity causes numerical paroblem. User has to specify
+meaningful y-range.
+
+Revision 1.34  2001/11/27 13:13:07  morsch
+Maximum lifetime for long-lived particles to be put on the stack is parameter.
+It can be set via SetMaximumLifetime(..).
+
+Revision 1.33  2001/10/21 18:35:56  hristov
+Several pointers were set to zero in the default constructors to avoid memory management problems
+
+Revision 1.32  2001/07/27 17:09:36  morsch
+Use local SetTrack, KeepTrack and SetHighWaterMark methods
+to delegate either to local stack or to stack owned by AliRun.
+(Piotr Skowronski, A.M.)
+
+Revision 1.31  2001/07/13 10:58:54  morsch
+- Some coded moved to AliGenMC
+- Improved handling of secondary vertices.
+
+Revision 1.30  2001/06/15 07:55:04  morsch
+Put only first generation decay products on the stack.
+
+Revision 1.29  2001/03/27 10:58:41  morsch
+Initialize decayer before generation. Important if run inside cocktail.
+
 Revision 1.28  2001/03/09 13:01:41  morsch
 - enum constants for paramterisation type (particle family) moved to AliGen*lib.h
 - use AliGenGSIlib::kUpsilon, AliGenPHOSlib::kEtaPrime to access the constants
@@ -78,6 +120,14 @@ Introduction of the Copyright and cvs Log
 
 */
 
+
+
+// Class to generate particles from using paramtrized pT and y distributions.
+// Distributions are obtained from pointer to object of type AliGenLib.
+// (For example AliGenMUONlib)
+// Decays are performed using Pythia.
+// andreas.morsch@cern.ch
+
 #include "AliGenParam.h"
 #include "AliDecayerPythia.h"
 #include "AliGenMUONlib.h"
@@ -108,20 +158,20 @@ AliGenParam::AliGenParam()
     fYPara  = 0;
     fParam  = 0;
     fAnalog = kAnalog;
-    SetCutOnChild();
-    SetChildMomentumRange();
-    SetChildPtRange();
-    SetChildPhiRange();
-    SetChildThetaRange();  
     SetDeltaPt();
 //
 // Set random number generator   
     sRandom = fRandom;
+    fDecayer = 0;
+
+
 }
 
-AliGenParam::AliGenParam(Int_t npart, AliGenLib * Library,  Int_t param, char* tname):AliGenerator(npart)
+AliGenParam::AliGenParam(Int_t npart, AliGenLib * Library,  Int_t param, char* tname):AliGenMC(npart)
 {
 // Constructor using number of particles parameterisation id and library
+    fName = "Param";
+    fTitle= "Particle Generator using pT and y parameterisation";
     
     fPtParaFunc = Library->GetPt(param, tname);
     fYParaFunc  = Library->GetY (param, tname);
@@ -131,14 +181,7 @@ AliGenParam::AliGenParam(Int_t npart, AliGenLib * Library,  Int_t param, char* t
     fYPara  = 0;
     fParam  = param;
     fAnalog = kAnalog;
-    fChildSelect.Set(5);
-    for (Int_t i=0; i<5; i++) fChildSelect[i]=0;
     SetForceDecay();
-    SetCutOnChild();
-    SetChildMomentumRange();
-    SetChildPtRange();
-    SetChildPhiRange();
-    SetChildThetaRange(); 
     SetDeltaPt(); 
 //
 // Set random number generator   
@@ -147,10 +190,13 @@ AliGenParam::AliGenParam(Int_t npart, AliGenLib * Library,  Int_t param, char* t
 
 //____________________________________________________________
 
-AliGenParam::AliGenParam(Int_t npart, Int_t param, char* tname):AliGenerator(npart)
+AliGenParam::AliGenParam(Int_t npart, Int_t param, char* tname):AliGenMC(npart)
 {
 // Constructor using parameterisation id and number of particles
-//      
+//
+    fName = "Param";
+    fTitle= "Particle Generator using pT and y parameterisation";
+      
     AliGenLib* pLibrary = new AliGenMUONlib();
  
     fPtParaFunc = pLibrary->GetPt(param, tname);
@@ -176,10 +222,13 @@ AliGenParam::AliGenParam(Int_t npart, Int_t param,
                          Double_t (*PtPara) (Double_t*, Double_t*),
                          Double_t (*YPara ) (Double_t* ,Double_t*),
                         Int_t    (*IpPara) (TRandom *))                 
-    :AliGenerator(npart)
+    :AliGenMC(npart)
 {
 // Constructor
 // Gines Martinez 1/10/99 
+    fName = "Param";
+    fTitle= "Particle Generator using pT and y parameterisation";
+
     fPtParaFunc = PtPara; 
     fYParaFunc  = YPara;  
     fIpParaFunc = IpPara;
@@ -200,9 +249,10 @@ AliGenParam::AliGenParam(Int_t npart, Int_t param,
 }
 
 
-AliGenParam::AliGenParam(const AliGenParam & Paramd)
+AliGenParam::AliGenParam(const AliGenParam & Param)
 {
 // copy constructor
+    Param.Copy(*this);
 }
 
 //____________________________________________________________
@@ -262,34 +312,7 @@ void AliGenParam::Init()
     fDecayer->Init();
 
 //
-    switch (fForceDecay) 
-    {
-    case kSemiElectronic:
-    case kDiElectron:
-    case kBJpsiDiElectron:
-    case kBPsiPrimeDiElectron:
-       fChildSelect[0]=11;     
-       break;
-    case kSemiMuonic:
-    case kDiMuon:
-    case kBJpsiDiMuon:
-    case kBPsiPrimeDiMuon:
-       fChildSelect[0]=13;
-       break;
-    case kPiToMu:
-       fChildSelect[0]=13;
-       break;
-    case kKaToMu:
-       fChildSelect[0]=13;
-       break;
-    case kHadronicD:
-// Implement me !!
-       break;
-    case kNoDecay:
-       break;
-    case kAll:
-       break;
-    }
+    AliGenMC::Init();
 }
 
 //____________________________________________________________
@@ -314,35 +337,28 @@ void AliGenParam::Generate()
   Float_t pt, pl, ptot;       // Transverse, logitudinal and total momenta of the parent particle
   Float_t phi, theta;         // Phi and theta spherical angles of the parent particle momentum
   Float_t p[3], pc[3], 
-          och[3], pch[10][3]; // Momentum, polarisation and origin of the children particles from lujet
-  Float_t ty, xmt;
-  Int_t nt, i, j, kfch[10];
+          och[3];             // Momentum, polarisation and origin of the children particles from lujet
+  Double_t ty, xmt;
+  Int_t nt, i, j;
   Float_t  wgtp, wgtch;
   Double_t dummy;
   static TClonesArray *particles;
   //
-  if(!particles) particles=new TClonesArray("TParticle",1000);
-
-  static TDatabasePDG *pDataBase = new TDatabasePDG();
-  if(!pDataBase) pDataBase = new TDatabasePDG();
+  if(!particles) particles = new TClonesArray("TParticle",1000);
+  
+  TDatabasePDG *pDataBase = TDatabasePDG::Instance();
   //
   Float_t random[6];
  
 // Calculating vertex position per event
   for (j=0;j<3;j++) origin0[j]=fOrigin[j];
   if(fVertexSmear==kPerEvent) {
-//      Rndm(random,6);
-//      for (j=0;j<3;j++) {
-//       origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
-//           TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
-//           TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
-//      }
-//    }
       Vertex();
       for (j=0;j<3;j++) origin0[j]=fVertex[j];
   }
   
   Int_t ipa=0;
+  
 // Generating fNpart particles
   while (ipa<fNpart) {
       while(1) {
@@ -352,14 +368,14 @@ void AliGenParam::Generate()
          fChildWeight=(fDecayer->GetPartialBranchingRatio(iPart))*fParentWeight;          
          TParticlePDG *particle = pDataBase->GetParticle(iPart);
          Float_t am = particle->Mass();
-
+         
          Rndm(random,2);
 //
 // phi
          phi=fPhiMin+random[0]*(fPhiMax-fPhiMin);
 //
 // y
-         ty=Float_t(TMath::TanH(fYPara->GetRandom()));
+         ty = TMath::TanH(fYPara->GetRandom());
 //
 // pT
          if (fAnalog == kAnalog) {
@@ -373,7 +389,12 @@ void AliGenParam::Generate()
              wgtch=fChildWeight*fPtParaFunc(& ptd, &dummy);
          }
          xmt=sqrt(pt*pt+am*am);
-      if (TMath::Abs(ty)==1) ty=0;
+         if (TMath::Abs(ty)==1.) {
+             ty=0.;
+             Fatal("AliGenParam", 
+                   "Division by 0: Please check you rapidity range !");
+         }
+         
          pl=xmt*ty/sqrt(1.-ty*ty);
          theta=TMath::ATan2(pt,pl);
 // Cut on theta
@@ -381,6 +402,7 @@ void AliGenParam::Generate()
          ptot=TMath::Sqrt(pt*pt+pl*pl);
 // Cut on momentum
          if(ptot<fPMin || ptot>fPMax) continue;
+//
          p[0]=pt*TMath::Cos(phi);
          p[1]=pt*TMath::Sin(phi);
          p[2]=pl;
@@ -400,6 +422,7 @@ void AliGenParam::Generate()
 // if fForceDecay == none Primary particle is tracked by GEANT 
 // (In the latest, make sure that GEANT actually does all the decays you want)   
 //
+
          if (fForceDecay != kNoDecay) {
 // Using lujet to decay particle
              Float_t energy=TMath::Sqrt(ptot*ptot+am*am);
@@ -408,66 +431,124 @@ void AliGenParam::Generate()
 //
 // select decay particles
              Int_t np=fDecayer->ImportParticles(particles);
+
+             //  Selecting  GeometryAcceptance for particles fPdgCodeParticleforAcceptanceCut;
+             if (fGeometryAcceptance) 
+               if (!CheckAcceptanceGeometry(np,particles)) continue;
              Int_t ncsel=0;
-             for (i = 1; i<np; i++) {
-                 TParticle *  iparticle = (TParticle *) particles->At(i);
-                 Int_t kf = iparticle->GetPdgCode();
+             Int_t* pFlag      = new Int_t[np];
+             Int_t* pParent    = new Int_t[np];
+             Int_t* pSelected  = new Int_t[np];
+             Int_t* trackIt    = new Int_t[np];
+
+             for (i=0; i<np; i++) {
+                 pFlag[i]     =  0;
+                 pSelected[i] =  0;
+                 pParent[i]   = -1;
+             }
+             
+             if (np >1) {
+                 TParticle* iparticle =  (TParticle *) particles->At(0);
+                 Int_t ipF, ipL;
+                 for (i = 1; i<np ; i++) {
+                     trackIt[i] = 1;
+                     iparticle = (TParticle *) particles->At(i);
+                     Int_t kf = iparticle->GetPdgCode();
+                     Int_t ks = iparticle->GetStatusCode();
+// flagged particle
+
+                     if (pFlag[i] == 1) {
+                         ipF = iparticle->GetFirstDaughter();
+                         ipL = iparticle->GetLastDaughter();   
+                         if (ipF > 0) for (j=ipF-1; j<ipL; j++) pFlag[j]=1;
+                         continue;
+                     }
+
+// flag decay products of particles with long life-time (c tau > .3 mum)                     
+                     
+                     if (ks != 1) { 
+//                       TParticlePDG *particle = pDataBase->GetParticle(kf);
+                         
+                         Double_t lifeTime = fDecayer->GetLifetime(kf);
+//                       Double_t mass     = particle->Mass();
+//                       Double_t width    = particle->Width();
+                         if (lifeTime > (Double_t) fMaxLifeTime) {
+                             ipF = iparticle->GetFirstDaughter();
+                             ipL = iparticle->GetLastDaughter();       
+                             if (ipF > 0) for (j=ipF-1; j<ipL; j++) pFlag[j]=1;
+                         } else{
+                             trackIt[i]     = 0;
+                             pSelected[i]   = 1;
+                         }
+                     } // ks==1 ?
 //
 // children
-                 if (ChildSelected(TMath::Abs(kf)) || fForceDecay == kAll)
-                 {
-                     pc[0]=iparticle->Px();
-                     pc[1]=iparticle->Py();
-                     pc[2]=iparticle->Pz();
-                     och[0]=origin0[0]+iparticle->Vx()/10;
-                     och[1]=origin0[1]+iparticle->Vy()/10;
-                     och[2]=origin0[2]+iparticle->Vz()/10;
-                     if (fCutOnChild) {
-                         Float_t ptChild=TMath::Sqrt(pc[0]*pc[0]+pc[1]*pc[1]);
-                         Float_t pChild=TMath::Sqrt(ptChild*ptChild+pc[2]*pc[2]);
-                         Float_t thetaChild=TMath::ATan2(ptChild,pc[2]);
-                         Float_t phiChild=TMath::ATan2(pc[1],pc[0]);
-                         Bool_t childok = 
-                             ((ptChild    > fChildPtMin    && ptChild    <fChildPtMax)      &&
-                              (pChild     > fChildPMin     && pChild     <fChildPMax)       &&
-                              (thetaChild > fChildThetaMin && thetaChild <fChildThetaMax)   &&
-                              (phiChild   > fChildPhiMin   && phiChild   <fChildPhiMax));
-                         if(childok)
-                         {
-                             pch[ncsel][0]=pc[0];
-                             pch[ncsel][1]=pc[1];
-                             pch[ncsel][2]=pc[2];
-                             kfch[ncsel]=kf;
-                             ncsel++;
+                     
+                     if (ChildSelected(TMath::Abs(kf)) || fForceDecay == kAll && trackIt[i])
+                     {
+                         if (fCutOnChild) {
+                             pc[0]=iparticle->Px();
+                             pc[1]=iparticle->Py();
+                             pc[2]=iparticle->Pz();
+                             Bool_t  childok = KinematicSelection(iparticle, 1);
+                             if(childok) {
+                                 pSelected[i]  = 1;
+                                 ncsel++;
+                             } else {
+                                 ncsel=-1;
+                                 break;
+                             } // child kine cuts
                          } else {
-                             ncsel=-1;
-                             break;
-                         } // child kine cuts
-                     } else {
-                         pch[ncsel][0]=pc[0];
-                         pch[ncsel][1]=pc[1];
-                         pch[ncsel][2]=pc[2];
-                         kfch[ncsel]=kf;
-                         ncsel++;
-                     } // if child selection
-                 } // select muon
-             } // decay particle loop
+                             pSelected[i]  = 1;
+                             ncsel++;
+                         } // if child selection
+                     } // select muon
+                 } // decay particle loop
+             } // if decay products
+             
              Int_t iparent;
              if ((fCutOnChild && ncsel >0) || !fCutOnChild){
                  ipa++;
 //
-// parent
-                 gAlice->
-                     SetTrack(0,-1,iPart,p,origin0,polar,0,kPPrimary,nt,wgtp);
-                 iparent=nt;
-                 gAlice->KeepTrack(nt); 
-                 for (i=0; i< ncsel; i++) {
-                     gAlice->SetTrack(fTrackIt,iparent,kfch[i],
-                                      &pch[i][0],och,polar,
-                                      0,kPDecay,nt,wgtch);
-                     gAlice->KeepTrack(nt); 
-                 }
+// Parent
+                 SetTrack(0, -1, iPart, p, origin0, polar, 0, kPPrimary, nt, wgtp);
+                 pParent[0] = nt;
+                 KeepTrack(nt); 
+//
+// Decay Products
+//               
+                 for (i = 1; i < np; i++) {
+                     if (pSelected[i]) {
+                         TParticle* iparticle = (TParticle *) particles->At(i);
+                         Int_t kf  = iparticle->GetPdgCode();
+                         Int_t ipa = iparticle->GetFirstMother()-1;
+                         
+                         och[0] = origin0[0]+iparticle->Vx()/10;
+                         och[1] = origin0[1]+iparticle->Vy()/10;
+                         och[2] = origin0[2]+iparticle->Vz()/10;
+                         pc[0]  = iparticle->Px();
+                         pc[1]  = iparticle->Py();
+                         pc[2]  = iparticle->Pz();
+                         
+                         if (ipa > -1) {
+                             iparent = pParent[ipa];
+                         } else {
+                             iparent = -1;
+                         }
+                        
+                         SetTrack(fTrackIt*trackIt[i], iparent, kf,
+                                          pc, och, polar,
+                                          0, kPDecay, nt, wgtch);
+                         pParent[i] = nt;
+                         KeepTrack(nt); 
+                     } // Selected
+                 } // Particle loop 
              }  // Decays by Lujet
+             particles->Clear();
+             if (pFlag)      delete[] pFlag;
+             if (pParent)    delete[] pParent;
+             if (pSelected)  delete[] pSelected;          
+             if (trackIt)    delete[] trackIt;
          } // kinematic selection
          else  // nodecay option, so parent will be tracked by GEANT (pions, kaons, eta, omegas, baryons)
          {
@@ -478,49 +559,9 @@ void AliGenParam::Generate()
          break;
     } // while
   } // event loop
-  gAlice->SetHighWaterMark(nt);
-  
-}
-
-Bool_t AliGenParam::ChildSelected(Int_t ip)
-{
-// True if particle is in list of selected children
-    for (Int_t i=0; i<5; i++)
-    {
-       if (fChildSelect[i]==ip) return kTRUE;
-    }
-    return kFALSE;
+  SetHighWaterMark(nt);
 }
 
-Bool_t AliGenParam::KinematicSelection(TParticle *particle)
-{
-// Perform kinematic cuts
-    Float_t px=particle->Px();
-    Float_t py=particle->Py();
-    Float_t pz=particle->Pz();
-//
-// momentum cut
-    Float_t p=TMath::Sqrt(px*px+py*py+pz*pz);
-    if (p > fPMax || p < fPMin) 
-    {
-//     printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax);
-       return kFALSE;
-    }
-    Float_t pt=TMath::Sqrt(px*px+py*py);
-    
-//
-// theta cut
-    Float_t  theta = Float_t(TMath::ATan2(Double_t(pt),Double_t(p)));
-    if (theta > fThetaMax || theta < fThetaMin) 
-    {
-//     printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax);
-       return kFALSE;
-    }
-
-    return kTRUE;
-}
-
-
 AliGenParam& AliGenParam::operator=(const  AliGenParam& rhs)
 {
 // Assignment operator