Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FermiMotion.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FermiMotion.cc
1 // Discribtion:This code is used to add Fermimotion p_F to spectator neutrons
2 
3 
4 //include the header file here
5 #include "FermiMotion.h"
6 
7 #include <phool/phool.h>
8 
9 #include <gsl/gsl_rng.h>
10 
11 #include <HepMC/GenEvent.h>
12 #include <HepMC/GenParticle.h> // for GenParticle
13 #include <HepMC/GenVertex.h> // for GenVertex, GenVertex::part...
14 #include <HepMC/HeavyIon.h> // for HeavyIon
15 #include <HepMC/SimpleVector.h> // for FourVector
16 
17 #include <CLHEP/Vector/LorentzVector.h>
18 
19 #include <cmath>
20 #include <cstdlib> // for exit
21 #include <iostream>
22 
23 //____________________________________________________________________________..
24 
25 //this method is use to find out the spectator neutron loss prob
26 //using the parameterization in the PHENIX Glauber
27 //Monte Carlo code written by Klaus Reygers to model
28 //the loss of forward
29 //neutrons into the ZDC due to larger fragments
30 
31 //Assume Au for now
32 //make sure b is in fm
33 double ploss(double b)
34 {
35  // para
36  double p0 = 0.3305;
37  double p1 = 0.0127;
38  double p2 = 17.;
39  double p3 = 2.;
40  double ploss = p0 + b * p1 + exp((b - p2) / p3);
41 
42  return ploss;
43 }
44 
45 //this method is use to generate and random p_F
46 //along a random direction and add it to the momentum
47 //assume Au for now
48 CLHEP::HepLorentzVector pwithpF(CLHEP::HepLorentzVector p, gsl_rng *RandomGenerator, int id, double pTspec, double bphi)
49 {
50  //id should be either 2112 or 2212
51  if (!((id == 2112) || (id == 2212)))
52  {
53  std::cout << "wrong pid" << std::endl;
54  return p;
55  }
56  //find pF max using Thomas-Fermi model, assume using Au.
57  float pFmax = 0.28315;
58  if (id == 2212) pFmax = 0.23276;
59  //now generate the random p assuming probability is propotional to p^2dp
60  //CLHEP::RandGeneral seems to be a better way to do it
61  float pF = pFmax * pow(gsl_rng_uniform_pos(RandomGenerator), 1.0 / 3.0);
62  float cotheta = (gsl_rng_uniform_pos(RandomGenerator) - 0.5) * 2;
63  float phi = gsl_rng_uniform_pos(RandomGenerator) * 2 * M_PI;
64  float pFx = pF * sqrt(1 - cotheta * cotheta) * cos(phi);
65  float pFy = pF * sqrt(1 - cotheta * cotheta) * sin(phi);
66  float pFz = pF * cotheta;
67  float pSx = pTspec * cos(bphi);
68  float pSy = pTspec * sin(bphi);
69 
70  if (p.pz() < 0) {
71  pSx *= -1;
72  pSy *= -1;
73 
74  }
75 
76  //now add the pF to p
77  float px = p.px() + pFx + pSx;
78  float py = p.py() + pFy + pSy;
79  float pz = p.pz() + pFz;
80  //calculate the total energy
81  float const nrm = 0.938;
82  float e = sqrt(px * px + py * py + pz * pz + nrm * nrm);
83 
84  CLHEP::HepLorentzVector pwithpF(px, py, pz, e);
85  return pwithpF;
86 }
87 
88 int FermiMotion(HepMC::GenEvent *event, gsl_rng *RandomGenerator, double pTspec)
89 {
90  //find ploss
91  //std::cout<<"getting b"<<std::endl;
92  HepMC::HeavyIon *hi = event->heavy_ion();
93  if (! hi)
94  {
95  std::cout << PHWHERE << ": Fermi Motion Afterburner needs the Heavy Ion Event Info, GenEvent::heavy_ion() returns NULL" << std::endl;
96  exit(1);
97  }
98  double b = hi->impact_parameter();
99  double bphi = hi->event_plane_angle();
100  double pnl = ploss(b);
101  //now loop over all particles and find spectator neutrons
102 
103  for (HepMC::GenEvent::particle_const_iterator p = event->particles_begin(), prev = event->particles_end(); p != event->particles_end(); prev = p, ++p)
104  {
105  //if not final state continue
106  if ((*p)->status() != 1) continue;
107  int id = (*p)->pdg_id();
108  //if not neutron, skip
109  if (!((id == 2112) || (id == 2212))) continue;
110 
111  //spectator neutron should have px==0&&py==0
112  HepMC::GenParticle *n = (*p);
113  float p_x = n->momentum().px();
114  float p_y = n->momentum().py();
115  if (!(p_x == 0 && p_y == 0)) continue;
116 
117  if (id == 2112)
118  {
119  //std::cout<<"after: "<<n->barcode()<<std::endl;
120  if (pnl > gsl_rng_uniform_pos(RandomGenerator))
121  {
122 
123 
124  //remove particle here
125  delete ((*p)->production_vertex())->remove_particle(*p);
126  //std::cout<<"removing: "<<n->barcode()<<std::endl;
127  p = prev;
128  continue;
129  }
130  }
131 
132  //add pF to the remaining
133 
134  CLHEP::HepLorentzVector p0(n->momentum().px(), n->momentum().py(), n->momentum().pz(), n->momentum().e());
135  CLHEP::HepLorentzVector newp = pwithpF(p0, RandomGenerator, id, pTspec, bphi);
136  (*p)->set_momentum(newp);
137  }
138 
139  return 0;
140 }