- fix counting if primary particles
authormorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 31 Oct 2010 11:21:45 +0000 (11:21 +0000)
committermorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 31 Oct 2010 11:21:45 +0000 (11:21 +0000)
- protection against empty events
(C. Loizides)

TUHKMgen/AliGenUHKM.cxx
TUHKMgen/TUHKMgen.cxx

index 324bab7..bf16aac 100755 (executable)
@@ -332,20 +332,23 @@ void AliGenUHKM::Generate()
 
   fTrials = 0;
 
-  Int_t nt  = 0;
-
-  fUHKMgen->GenerateEvent();
-  fTrials++;
-
-  fUHKMgen->ImportParticles(&fParticles,"All");
-
-  Int_t np = fParticles.GetEntriesFast();
-
+  Int_t nt  =  0;
+  Int_t np  = -1;
+  while (np <= 0 && fTrials < 100) {
+    fUHKMgen->GenerateEvent();
+    fTrials++;
+    fUHKMgen->ImportParticles(&fParticles,"All");
+    np = fParticles.GetEntriesFast();
+  }
+  if (np <= 0) {
+    AliFatal(Form("Attempted %d trials, giving up", fTrials));
+    return;
+  }
 
   Int_t* idsOnStack = new Int_t[np];
   Int_t* newPos     = new Int_t[np];
   for(Int_t i=0; i<np; i++) newPos[i] = i;
-
+  
   //_________ Loop for particle selection
   for(Int_t i=0; i<np; i++) {
     TParticle *iparticle = (TParticle*)fParticles.At(i);
@@ -359,26 +362,26 @@ void AliGenUHKM::Generate()
       // Add it only once with coordinates not
       // smeared with primary vertex position
       Float_t p[3] = {p[0] = iparticle->Px(),
-                      p[1] = iparticle->Py(),
-                      p[2] = iparticle->Pz()};
+                     p[1] = iparticle->Py(),
+                     p[2] = iparticle->Pz()};
       mass = TDatabasePDG::Instance()->GetParticle(kf)->Mass();
       energy = sqrt(mass*mass + p[0]*p[0] + p[1]*p[1] + p[2]*p[2]);
       v[0] = iparticle->Vx();
       v[1] = iparticle->Vy();
       v[2] = iparticle->Vz();
       Float_t time = iparticle->T();
-
+      
       Int_t imo = -1;
       if(hasMother) {
-        imo = iparticle->GetFirstMother(); //index of mother particle in fParticles
+       imo = iparticle->GetFirstMother(); //index of mother particle in fParticles
       } // if has mother
       Bool_t trackFlag = kFALSE;   // tFlag is kFALSE --> do not track the particle
       
       PushTrack(trackFlag, (imo>=0 ? idsOnStack[imo] : imo), kf,
-                p[0], p[1], p[2], energy,
-                v[0], v[1], v[2], time,
-                polar[0], polar[1], polar[2],
-                (hasMother ? kPDecay : kPNoProcess), nt);
+               p[0], p[1], p[2], energy,
+               v[0], v[1], v[2], time,
+               polar[0], polar[1], polar[2],
+               (hasMother ? kPDecay : kPNoProcess), nt);
       idsOnStack[i] = nt;
       
       fNprimaries++;
@@ -394,54 +397,54 @@ void AliGenUHKM::Generate()
       //   this one will be tracked
       
       Float_t p[3] = {p[0] = iparticle->Px(),
-                      p[1] = iparticle->Py(),
-                      p[2] = iparticle->Pz()};
+                     p[1] = iparticle->Py(),
+                     p[2] = iparticle->Pz()};
       mass = TDatabasePDG::Instance()->GetParticle(kf)->Mass();
       energy = sqrt(mass*mass + p[0]*p[0] + p[1]*p[1] + p[2]*p[2]);
       v[0] = iparticle->Vx();
       v[1] = iparticle->Vy();
       v[2] = iparticle->Vz();
-
+      
       Int_t type    = iparticle->GetStatusCode(); // 1-from jet / 0-from hydro 
       Int_t coeffT=1;
       if(type==1) coeffT=-1; //to separate particles from jets
       
-
+      
       Int_t imo = -1;
       
       if(hasMother) {
-        imo = iparticle->GetFirstMother();
+       imo = iparticle->GetFirstMother();
       } // if has mother
       
       Bool_t trackFlag = kFALSE;  // tFlag = kFALSE --> do not track this one, its for femtoscopy
       PushTrack(trackFlag, (imo>=0 ? idsOnStack[imo] : imo), kf,
-                p[0], p[1], p[2], energy,
-                v[0], v[1], v[2], (iparticle->T())*coeffT,
-                polar[0], polar[1], polar[2],
-                hasMother ? kPDecay:kPNoProcess, nt);
+               p[0], p[1], p[2], energy,
+               v[0], v[1], v[2], (iparticle->T())*coeffT,
+               polar[0], polar[1], polar[2],
+               hasMother ? kPDecay:kPNoProcess, nt);
       
       idsOnStack[i] = nt;
       fNprimaries++;
       KeepTrack(nt);
-
+      
       origin[0] = origin0[0]+v[0];
       origin[1] = origin0[1]+v[1];
       origin[2] = origin0[2]+v[2];
       imo = nt;
       
       trackFlag = kTRUE;    // tFlag = kTRUE --> track this one
-
+      
       PushTrack(trackFlag, imo, kf,
-                p[0], p[1], p[2], energy,
-                origin[0], origin[1], origin[2], iparticle->T(),
-                polar[0], polar[1], polar[2],
-                hasMother ? kPDecay:kPNoProcess, nt);
+               p[0], p[1], p[2], energy,
+               origin[0], origin[1], origin[2], iparticle->T(),
+               polar[0], polar[1], polar[2],
+               hasMother ? kPDecay:kPNoProcess, nt);
       
       fNprimaries++;
       KeepTrack(nt);
     }
   }
-
+  
   SetHighWaterMark(fNprimaries);
 
   TArrayF eventVertex;
index cf81d4a..3fee931 100755 (executable)
@@ -284,13 +284,13 @@ Int_t TUHKMgen::ImportParticles(TClonesArray *particles, const Option_t* option)
     Int_t type = it->GetType();  
       
     if (im1> -1) {
-     // particle not a primary -> set the daughter indexes for the mother particle"<< endl;
+      // particle not a primary -> set the daughter indexes for the mother particle"<< endl;
       TParticle *mother = (TParticle*) (particlesR.UncheckedAt(im1));
       mother->SetLastDaughter(nump);
       if(mother->GetFirstDaughter()==-1)
        mother->SetFirstDaughter(nump);
-    }
-      
+    } else 
+      ++numprim;
     
     new (particlesR[nump]) TParticle(it->Encoding(), type,                                             //pdg,stat
                                     im1, im2, id1, id2,                                                //m1,m2,d1,d2