+ //printf(" \t beta %1.10f gamma %f energy %f -> p_z = %f\n",beta, gamma, energy,q[2]);
+}
+
+//_____________________________________________________________________________
+void AliGenSlowNucleons::BeamCrossDivergence(Int_t iwhat, Float_t *pLab)
+{
+ // Applying beam divergence and crossing angle
+ //
+ Double_t pmod = TMath::Sqrt(pLab[0]*pLab[0]+pLab[1]*pLab[1]+pLab[2]*pLab[2]);
+
+ Double_t tetdiv = 0.;
+ Double_t fidiv = 0.;
+ if(iwhat==1){
+ tetdiv = fBeamCrossingAngle;
+ fidiv = k2PI/4.;
+ }
+ else if(iwhat==2){
+ tetdiv = fBeamDivEvent;
+ fidiv = (gRandom->Rndm())*k2PI;
+ }
+
+ Double_t tetpart = TMath::ATan2(TMath::Sqrt(pLab[0]*pLab[0]+pLab[1]*pLab[1]), pLab[2]);
+ Double_t fipart=0.;
+ if(TMath::Abs(pLab[1])>0. || TMath::Abs(pLab[0])>0.) fipart = TMath::ATan2(pLab[1], pLab[0]);
+ if(fipart<0.) {fipart = fipart+k2PI;}
+ tetdiv = tetdiv*kRaddeg;
+ fidiv = fidiv*kRaddeg;
+ tetpart = tetpart*kRaddeg;
+ fipart = fipart*kRaddeg;
+
+ Double_t angleSum[2]={0., 0.};
+ AddAngle(tetpart,fipart,tetdiv,fidiv,angleSum);
+
+ Double_t tetsum = angleSum[0];
+ Double_t fisum = angleSum[1];
+ //printf("tetpart %f fipart %f tetdiv %f fidiv %f angleSum %f %f\n",tetpart,fipart,tetdiv,fidiv,angleSum[0],angleSum[1]);
+ tetsum = tetsum*kDegrad;
+ fisum = fisum*kDegrad;
+
+ pLab[0] = pmod*TMath::Sin(tetsum)*TMath::Cos(fisum);
+ pLab[1] = pmod*TMath::Sin(tetsum)*TMath::Sin(fisum);
+ pLab[2] = pmod*TMath::Cos(tetsum);
+ if(fDebug==1){
+ if(iwhat==1) printf(" Beam crossing angle %f mrad ", fBeamCrossingAngle*1000.);
+ else if(iwhat==2) printf(" Beam divergence %f mrad ", fBeamDivEvent*1000.);
+ printf(" p = (%f, %f, %f)\n",pLab[0],pLab[1],pLab[2]);
+ }
+}
+
+//_____________________________________________________________________________
+void AliGenSlowNucleons::AddAngle(Double_t theta1, Double_t phi1,
+ Double_t theta2, Double_t phi2, Double_t *angleSum)
+{
+ // Calculating the sum of 2 angles
+ Double_t temp = -1.;
+ Double_t conv = 180./TMath::ACos(temp);
+
+ Double_t ct1 = TMath::Cos(theta1/conv);
+ Double_t st1 = TMath::Sin(theta1/conv);
+ Double_t cp1 = TMath::Cos(phi1/conv);
+ Double_t sp1 = TMath::Sin(phi1/conv);
+ Double_t ct2 = TMath::Cos(theta2/conv);
+ Double_t st2 = TMath::Sin(theta2/conv);
+ Double_t cp2 = TMath::Cos(phi2/conv);
+ Double_t sp2 = TMath::Sin(phi2/conv);
+ Double_t cx = ct1*cp1*st2*cp2+st1*cp1*ct2-sp1*st2*sp2;
+ Double_t cy = ct1*sp1*st2*cp2+st1*sp1*ct2+cp1*st2*sp2;
+ Double_t cz = ct1*ct2-st1*st2*cp2;
+
+ Double_t rtetsum = TMath::ACos(cz);
+ Double_t tetsum = conv*rtetsum;
+ if(TMath::Abs(tetsum)<1e-4 || tetsum==180.) return;
+
+ temp = cx/TMath::Sin(rtetsum);
+ if(temp>1.) temp=1.;
+ if(temp<-1.) temp=-1.;
+ Double_t fisum = conv*TMath::ACos(temp);
+ if(cy<0) {fisum = 360.-fisum;}
+
+ angleSum[0] = tetsum;
+ angleSum[1] = fisum;
+}
+
+//_____________________________________________________________________________
+void AliGenSlowNucleons::SetProcessID(Int_t nt, UInt_t process)
+{
+ // Tag the particle as
+ // gray or black
+ if (fStack)
+ fStack->Particle(nt)->SetUniqueID(process);
+ else
+ gAlice->GetMCApp()->Particle(nt)->SetUniqueID(process);