]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EVGEN/AliGenHalo.cxx
bug fixed
[u/mrichter/AliRoot.git] / EVGEN / AliGenHalo.cxx
index acaa53c8a4bef7dbef4283a8b03cf9d31ac07dab..23efa118590bb6687ac338f3cc74915810e7c9d1 100644 (file)
@@ -125,6 +125,11 @@ void AliGenHalo::Init()
     } else {
        printf("\n Opening of file %s failed,  %p ! \n ",  fFileName.Data(), (void*)fFile);
     }
+
+    if (fNskip > 0) {
+      // Skip the first fNskip events
+      SkipEvents();
+    }
 //
 //
 //
@@ -252,24 +257,22 @@ void AliGenHalo::Generate()
   static Bool_t first = kTRUE;
   static Int_t  oldID = -1;
 //
-  if (first) {
-      ReadNextParticle();
-      first = kFALSE;
-      oldID = fLossID;
-  }
-  
-  
+
+  if (first && (fNskip == 0)) ReadNextParticle();
+  first = kFALSE;
+  oldID = fLossID;
   
   while(1) {
       // Push particle to stack
       mass = TDatabasePDG::Instance()->GetParticle(fPdg)->Mass();
-      p0  = TMath::Sqrt(fEkin * fEkin + 2.* mass * fEkin);
+      p0  = TMath::Sqrt(fEkin * fEkin + 2. * mass * fEkin);
       txy = TMath::Sqrt(fDX * fDX + fDY * fDY);
-      if (txy == 1.) {
-         tz = 0;
+      if (txy > 1.) {
+         tz = 0.;
       } else {
          tz = - TMath::Sqrt(1. - txy);
       }
       p[0] =  p0 * fDX;
       p[1] =  p0 * fDY;
       p[2] =  p0 * tz;
@@ -278,8 +281,8 @@ void AliGenHalo::Generate()
       origin[1] = fYS;
       origin[2] = 1950.;
 
-      PushTrack(fTrackIt , -1, fPdg , p, origin, polar, fTS, kPNoProcess, nt, fWS);
-
+      PushTrack(fTrackIt , -1, fPdg , p, origin, polar, fTS - 1950./2.9979e10, kPNoProcess, nt, fWS);
+      
       Int_t nc = ReadNextParticle();
       
       if (fLossID != oldID || nc == 0) {
@@ -361,3 +364,40 @@ Int_t AliGenHalo::ReadNextParticle()
     fTS    *= 1.e-9;
     return (ncols);
 }
+
+void AliGenHalo::SkipEvents()
+{
+  //
+  // Skip the first fNskip events
+  Int_t skip = fNskip;
+  Int_t oldID = -1;
+
+  while (skip >= 0)
+    {
+      ReadNextParticle();
+      if (oldID != fLossID) {
+       oldID = fLossID;
+       skip--;
+      }
+    } 
+}
+void AliGenHalo::CountEvents()
+{
+    Int_t nev = 0;
+    Int_t oldID = -1;
+    Int_t nc = 1;
+    while (nc != -1)
+    {
+       nc = ReadNextParticle();
+       if (oldID != fLossID) {
+           oldID = fLossID;
+           nev++;
+           printf("Number of events %10d %10d \n", nev, oldID);
+       }
+    }
+
+
+    rewind(fFile);
+}
+
+