]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EVGEN/AliGenParam.cxx
Add name and title in constructor.
[u/mrichter/AliRoot.git] / EVGEN / AliGenParam.cxx
index 80dc91c5e01f5abe0fcc17c81c4aa63538dfda47..84340ba899994268f9457a24c27771a20e3f6417 100644 (file)
 
 /*
 $Log$
+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.
 
@@ -111,20 +135,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);
@@ -134,14 +158,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   
@@ -150,10 +167,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);
@@ -179,10 +199,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;
@@ -265,34 +288,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();
 }
 
 //____________________________________________________________
@@ -317,15 +313,15 @@ 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);
-
+  if(!particles) particles = new TClonesArray("TParticle",1000);
+  
   static TDatabasePDG *pDataBase = new TDatabasePDG();
   if(!pDataBase) pDataBase = new TDatabasePDG();
   //
@@ -334,18 +330,12 @@ void AliGenParam::Generate()
 // 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) {
@@ -355,14 +345,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) {
@@ -376,7 +366,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
@@ -384,6 +379,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;
@@ -403,6 +399,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);
@@ -412,50 +409,70 @@ void AliGenParam::Generate()
 // select decay particles
              Int_t np=fDecayer->ImportParticles(particles);
              Int_t ncsel=0;
-
+             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 = iparticle->GetFirstDaughter();
-                 Int_t ipL = iparticle->GetLastDaughter();           
-                 for (i = ipF-1; i<ipL; i++) {
+                 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)
+                     
+                     if (ChildSelected(TMath::Abs(kf)) || fForceDecay == kAll && trackIt[i])
                      {
-                         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;
+                             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 {
-                             pch[ncsel][0]=pc[0];
-                             pch[ncsel][1]=pc[1];
-                             pch[ncsel][2]=pc[2];
-                             kfch[ncsel]=kf;
+                             pSelected[i]  = 1;
                              ncsel++;
                          } // if child selection
                      } // select muon
@@ -466,18 +483,44 @@ void AliGenParam::Generate()
              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)
          {
@@ -488,49 +531,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