EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParticleMCS.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ParticleMCS.cxx
1 
11 
12 #include <iomanip>
13 #include <iostream>
14 
15 #include <TMath.h>
16 
17 namespace Smear {
18 
20 : status(0)
21 , id(0)
22 , px(0.)
23 , py(0.)
24 , pz(0.)
25 , E(0.)
26 , pt(0.)
27 , p(0.)
28 , theta(0.)
29 , phi(0.)
30 , numSigma( std::nan("") )
31 , numSigmaType(0)
32 {
33 }
34 
35 ParticleMCS::ParticleMCS(const TLorentzVector& ep, int pdg, int stat)
36 : status(stat)
37 , id(pdg)
38 , px(ep.Px())
39 , py(ep.Py())
40 , pz(ep.Pz())
41 , E(ep.E())
42 , pt(ep.Pt())
43 , p(ep.P())
44 , theta(ep.Theta())
45 , phi(ep.Phi())
46 , numSigma( std::nan("") )
47 , numSigmaType(0)
48 {
49 }
50 
52 }
53 
54 TLorentzVector ParticleMCS::Get4Vector() const {
55  return TLorentzVector(px, py, pz, E);
56 }
57 
58 void ParticleMCS::Print(Option_t* /* unused */) const {
59  // Store initial flags for cout so we can restore them later.
60  std::ios_base::fmtflags ff = std::cout.flags();
61  // Configure flags for output
62  std::cout.setf(std::ios_base::fixed, std::ios_base::basefield);
63  std::cout.precision(4);
64  // Output values.
65  std::cout <<
66  std::setw(3) << status <<
67  std::setw(12) << id <<
68  std::setw(10) << px <<
69  std::setw(10) << py <<
70  std::setw(10) << pz <<
71  std::setw(10) << E << std::endl;
72  // Restore initial cout flags.
73  std::cout.flags(ff);
74 }
75 
76 Double_t ParticleMCS::GetEta() const {
77  // The default value of -19 is used in the main eRHIC code,
78  // so use that for consistency.
79  double eta(-19.);
80  const double theta = GetTheta();
81  if (theta > 0. && theta < TMath::Pi() && !TMath::IsNaN(theta)) {
82  eta = -log(tan(theta / 2.));
83  } // if
84  return eta;
85 }
86 
87 Double_t ParticleMCS::GetRapidity() const {
88  // The default value of -19 is used in the main eRHIC code,
89  // so use that for consistency.
90  double y(-19.);
91  // Be careful here, as the energy and momentum can become
92  // smeared such that the stored E < pz, giving NaN when
93  // taking a log of a negative.
94  // In that case, return the default value.
95  // E > pz already takes care of the case if E is NaN, so
96  // no need to check that again.
97  if (E > pz && !TMath::IsNaN(pz)) {
98  y = 0.5 * log((E + pz) / (E - pz));
99  } // if
100  return y;
101 }
102 
103  // -----------------------------------------------------------
104 
105  Double_t ParticleMCS::GetPx() const {
106  return p * sin(theta) * cos(phi);
107  }
108 
109  Double_t ParticleMCS::GetPy() const {
110  return p * sin(theta) * sin(phi);
111  }
112 
113  Double_t ParticleMCS::GetPz() const {
114  return pz;
115  }
116 
117  Double_t ParticleMCS::GetE() const {
118  return E;
119  }
120 
121  Double_t ParticleMCS::GetM() const {
122  return sqrt(pow(E, 2.) - pow(p, 2.));
123  }
124 
125  Double_t ParticleMCS::GetPt() const {
126  return pt;
127  }
128 
129  TVector3 ParticleMCS::GetVertex() const {
130  return TVector3();
131  }
132 
133  Double_t ParticleMCS::GetP() const {
134  return p;
135  }
136 
137  Double_t ParticleMCS::GetTheta() const {
138  return theta;
139  }
140 
141  Double_t ParticleMCS::GetPhi() const {
142  return phi;
143  }
144 
145  UShort_t ParticleMCS::GetStatus() const {
146  return status;
147  }
148 
149  double ParticleMCS::GetNumSigma() const {
150  return numSigma;
151  }
152 
154  return numSigmaType;
155  }
156 
157  bool ParticleMCS::IsSmeared() const { return kParticleSmeared; }
158  bool ParticleMCS::IsESmeared() const { return kESmeared; }
159  bool ParticleMCS::IsPSmeared() const { return kPSmeared; }
160  bool ParticleMCS::IsPtSmeared() const { return kPtSmeared; }
161  bool ParticleMCS::IsPxSmeared() const { return kPxSmeared; }
162  bool ParticleMCS::IsPySmeared() const { return kPySmeared; }
163  bool ParticleMCS::IsPzSmeared() const { return kPzSmeared; }
165  bool ParticleMCS::IsPhiSmeared() const { return kPhiSmeared; }
166  bool ParticleMCS::IsIdSmeared() const { return kIdSmeared; }
168 
169  // -----------------------------------------------------------
170  void ParticleMCS::SetVariable( const double z, const KinType kin) {
171  switch (kin) {
172  case kE:
173  SetE(z); break;
174  case kP:
175  SetP(z); break;
176  case kTheta:
177  SetTheta(z); break;
178  case kPhi:
179  SetPhi(z); break;
180  case kPz:
181  SetPz(z); break;
182  case kPt:
183  SetPt(z); break;
184  default:
185  break;
186  } // switch
187  }
188 
189  void ParticleMCS::SetE(const Double_t value, const bool CheckSetSmearFlag){
190  if ( kESmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear E twice");
191  else kESmeared = true;
192  E = value;
193  }
194 
195  void ParticleMCS::SetP(Double_t value, const bool CheckSetSmearFlag){
196  if ( kPSmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear P twice");
197  else kPSmeared = true;
198  p = value;
199  }
200 
201  void ParticleMCS::SetPt(Double_t value, const bool CheckSetSmearFlag){
202  if ( kPtSmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear Pt twice");
203  else kPtSmeared = true;
204  pt = value;
205  }
206 
207  void ParticleMCS::SetPx(Double_t value, const bool CheckSetSmearFlag){
208  if ( kPxSmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear Px twice");
209  else kPxSmeared = true;
210  px = value;
211  }
212 
213  void ParticleMCS::SetPy(Double_t value, const bool CheckSetSmearFlag){
214  if ( kPySmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear Py twice");
215  else kPySmeared = true;
216  py = value;
217  }
218 
219  void ParticleMCS::SetPz(Double_t value, const bool CheckSetSmearFlag){
220  if ( kPzSmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear Pz twice");
221  else kPzSmeared = true;
222  pz = value;
223  }
224 
225  void ParticleMCS::SetPhi(Double_t value, const bool CheckSetSmearFlag){
226  if ( kPhiSmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear Phi twice");
227  else kPhiSmeared = true;
228  phi = value;
229  }
230 
231  void ParticleMCS::SetTheta(Double_t value, const bool CheckSetSmearFlag){
232  if ( kThetaSmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear Theta twice");
233  else kThetaSmeared = true;
234  theta = value;
235  }
236 
237  void ParticleMCS::SetId(Int_t i, const bool CheckSetSmearFlag){
238  if ( kIdSmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear Id twice");
239  else kIdSmeared = true;
240  id = i;
241  }
242 
243  void ParticleMCS::SetStatus(Int_t i) {
244  status = i;
245  }
246 
247  void ParticleMCS::SetNumSigma( const double d, const bool CheckSetSmearFlag){
248  if ( kNumSigmaSmeared && CheckSetSmearFlag ) throw std::runtime_error ("Attempting to smear numSigma twice");
249  else kNumSigmaSmeared = true;
250  numSigma = d;
251  }
252 
253  void ParticleMCS::SetNumSigmaType( const int i){
254  numSigmaType = i;
255  }
256 
258  return ::erhic::Pid(id);
259  }
260 
262  double fault(0.);
263  if (kE == kin && GetE() < 0.) {
264  SetE(fault, false);
265  } else if (kP == kin && GetP() < 0.) {
266  SetP(fault, false);
267  } else if (kPt == kin && GetPt() < 0.) {
268  SetPt(fault, false);
269  }
270  }
271 
272  void ParticleMCS::SetSmeared( bool flag) {kParticleSmeared=flag;}
273  void ParticleMCS::SetESmeared( bool flag) {kESmeared=flag;}
274  void ParticleMCS::SetPSmeared( bool flag) {kPSmeared=flag;}
275  void ParticleMCS::SetPtSmeared( bool flag) {kPtSmeared=flag;}
276  void ParticleMCS::SetPxSmeared( bool flag) {kPxSmeared=flag;}
277  void ParticleMCS::SetPySmeared( bool flag) {kPySmeared=flag;}
278  void ParticleMCS::SetPzSmeared( bool flag) {kPzSmeared=flag;}
280  void ParticleMCS::SetPhiSmeared( bool flag) {kPhiSmeared=flag;}
281  void ParticleMCS::SetIdSmeared( bool flag) {kIdSmeared=flag;}
283 
284 } // namespace Smear