]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EVGEN/AliGenBox.cxx
Overlaps corrected, new shape of sectors
[u/mrichter/AliRoot.git] / EVGEN / AliGenBox.cxx
index 56c8e735b552dae3fbb4ff776831af675e94869a..197a8c09b82aa1b5be1a2142595b8c586d7f9005 100644 (file)
 #include "AliGenBox.h"
 #include "AliRun.h"
 #include "AliGenEventHeader.h"
+#include "TDatabasePDG.h"
+#include "AliPDG.h"
 
 ClassImp(AliGenBox)
 
 //_____________________________________________________________________________
 AliGenBox::AliGenBox()
-    :AliGenerator()
+    :AliGenerator(), 
+     fIpart(0),
+     fEtaMin(0),
+     fEtaMax(0)
 {
   //
   // Default constructor
   //
-  fIpart=0;
 }
 
 //_____________________________________________________________________________
 AliGenBox::AliGenBox(Int_t npart)
-  :AliGenerator(npart)
+    :AliGenerator(npart),
+     fIpart(kProton),
+     fEtaMin(0),
+     fEtaMax(0)
 {
   //
   // Standard constructor
   //
   fName  = "Box";
   fTitle = "Box particle generator";
-  // Generate Proton by default
-  fIpart=kProton;
 }
 
 //_____________________________________________________________________________
 
-void AliGenBox::Generate()
+void AliGenBox::Generate() {
+  //
+  // Generate one trigger (fNpart particles)
+  //
+  GenerateN(1);
+}
+//_____________________________________________________________________________
+void AliGenBox::GenerateN(Int_t ntimes)
 {
   //
-  // Generate one trigger
+  // Generate ntimes triggers
+  //   total ntimes*fNpart particles
   //
   
     Float_t polar[3]= {0,0,0};
   //
     Float_t origin[3];
+    Float_t time;
     Float_t p[3];
     Int_t i, j, nt;
     Double_t pmom, theta, phi, pt;
+    Double_t y, mt;
     //
     Float_t random[6];
   //
     for (j=0;j<3;j++) origin[j]=fOrigin[j];
+    time = fTimeOrigin;
     if(fVertexSmear==kPerEvent) {
        Vertex();
        for (j=0;j<3;j++) origin[j]=fVertex[j];
+       time = fTime;
     }
 
-    for(i=0;i<fNpart;i++) {
+    Double_t m = TDatabasePDG::Instance()->GetParticle(fIpart)->Mass();
+
+    Int_t mult = fNpart*ntimes;
+    for(i=0;i<mult;i++) {
        Rndm(random,3);
-       theta=fThetaMin+random[0]*(fThetaMax-fThetaMin);
-       if(TestBit(kMomentumRange)) {
-           pmom=fPMin+random[1]*(fPMax-fPMin);
-           pt=pmom*TMath::Sin(theta);
+       
+       if (TestBit(kYRange)) {
+           y = fYMin+random[0]*(fYMax-fYMin);
+       
+           if(TestBit(kMomentumRange)) {
+               pmom=fPMin+random[1]*(fPMax-fPMin);
+               mt = TMath::Sqrt(pmom*pmom+m*m)/TMath::CosH(y);
+               pt = TMath::Sqrt(mt*mt - m*m);
+           } else {
+               pt=fPtMin+random[1]*(fPtMax-fPtMin);
+               mt=TMath::Sqrt(pt*pt+m*m);
+           }
+
+           phi=fPhiMin+random[2]*(fPhiMax-fPhiMin);
+           p[0] = pt*TMath::Cos(phi);
+           p[1] = pt*TMath::Sin(phi);
+           p[2] = mt*TMath::SinH(y);
        } else {
+           if (TestBit(kThetaRange)) {
+               theta = fThetaMin+random[0]*(fThetaMax-fThetaMin);
+           } else {
+               Float_t eta = fEtaMin+random[0]*(fEtaMax-fEtaMin);
+               theta = 2. * TMath::ATan(TMath::Exp(-eta));
+           }
+       
+           if(TestBit(kMomentumRange)) {
+               pmom=fPMin+random[1]*(fPMax-fPMin);
+               pt=pmom*TMath::Sin(theta);
+           } else {
+
+               pt=fPtMin+random[1]*(fPtMax-fPtMin);
+               pmom=pt/TMath::Sin(theta);
+           }
 
-           pt=fPtMin+random[1]*(fPtMax-fPtMin);
-           pmom=pt/TMath::Sin(theta);
+           phi=fPhiMin+random[2]*(fPhiMax-fPhiMin);
+           p[0] = pt*TMath::Cos(phi);
+           p[1] = pt*TMath::Sin(phi);
+           p[2] = pmom*TMath::Cos(theta);
        }
-       phi=fPhiMin+random[2]*(fPhiMax-fPhiMin);
-       p[0] = pt*TMath::Cos(phi);
-       p[1] = pt*TMath::Sin(phi);
-       p[2] = pmom*TMath::Cos(theta);
 
        if(fVertexSmear==kPerTrack) {
            Rndm(random,6);
@@ -100,13 +147,27 @@ void AliGenBox::Generate()
                origin[j]=fOrigin[j]+fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
                    TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
            }
+
+           Rndm(random,2);
+           time = fTimeOrigin + fOsigma[2]/TMath::Ccgs()*
+             TMath::Cos(2*random[0]*TMath::Pi())*
+             TMath::Sqrt(-2*TMath::Log(random[1]));
        }
-       PushTrack(fTrackIt,-1,fIpart,p,origin,polar,0,kPPrimary,nt);
+       PushTrack(fTrackIt,-1,fIpart,p,origin,polar,time,kPPrimary,nt, 1., 1);
     }
 
     AliGenEventHeader* header = new AliGenEventHeader("BOX");
     header->SetPrimaryVertex(fVertex);
-    gAlice->SetGenEventHeader(header); 
+    header->SetNProduced(mult);
+    header->SetInteractionTime(fTime);
+    
+ // Passes header either to the container or to gAlice
+    if (fContainer) {
+        header->SetName(fName);
+       fContainer->AddHeader(header);
+    } else {
+       gAlice->SetGenEventHeader(header);      
+    }
 }
 
 //_____________________________________________________________________________
@@ -118,5 +179,9 @@ void AliGenBox::Init()
     Fatal("Init","You should not set the momentum range and the pt range!\n");
   if((!TestBit(kPtRange))&&(!TestBit(kMomentumRange))) 
     Fatal("Init","You should set either the momentum or the pt range!\n");
+  if((TestBit(kYRange)&&TestBit(kThetaRange)) || (TestBit(kYRange)&&TestBit(kEtaRange)) || (TestBit(kEtaRange)&&TestBit(kThetaRange)) )
+    Fatal("Init","You should only set the range of one of these variables: y, eta or theta\n");
+  if((!TestBit(kYRange)) && (!TestBit(kEtaRange)) && (!TestBit(kThetaRange)) )
+    Fatal("Init","You should set the range of one of these variables: y, eta or theta\n");
 }