ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4SteppingAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4SteppingAction.cc
1 
9 #include "PHG4SteppingAction.h"
10 
11 #include "PHG4Hit.h"
12 
13 #include <Geant4/G4AffineTransform.hh> // for G4AffineTransform
14 #include <Geant4/G4EmSaturation.hh>
15 #include <Geant4/G4LossTableManager.hh>
16 #include <Geant4/G4Material.hh>
17 #include <Geant4/G4MaterialPropertiesTable.hh> // for G4MaterialProperties...
18 #include <Geant4/G4NavigationHistory.hh>
19 #include <Geant4/G4ReferenceCountedHandle.hh> // for G4ReferenceCountedHa...
20 #include <Geant4/G4Step.hh>
21 #include <Geant4/G4StepPoint.hh>
22 #include <Geant4/G4String.hh> // for G4String
23 #include <Geant4/G4SystemOfUnits.hh>
24 #include <Geant4/G4ThreeVector.hh>
25 #include <Geant4/G4TouchableHandle.hh> // for G4TouchableHandle
26 #include <Geant4/G4Track.hh>
27 #include <Geant4/G4VTouchable.hh> // for G4VTouchable
28 
29 #include <algorithm>
30 #include <cassert>
31 #include <cmath> // for isfinite, NAN, sqrt
32 #include <iostream>
33 
34 using namespace std;
35 
36 PHG4SteppingAction::PHG4SteppingAction(const std::string& name, const int i)
37  : m_Verbosity(i)
38  , m_LightBalanceInnerRadius(NAN)
39  , m_LightBalanceInnerCorr(NAN)
40  , m_LightBalanceOuterRadius(NAN)
41  , m_LightBalanceOuterCorr(NAN)
42  , m_Name(name)
43 {
44 }
45 
46 double
48 {
49  // pirated from G4Scintillation::PostStepDoIt()
50 
51  double light_yield = 0;
52 
53  const G4Track* aTrack = step->GetTrack();
54  const G4Material* aMaterial = aTrack->GetMaterial();
55  G4MaterialPropertiesTable* aMaterialPropertiesTable =
56  aMaterial->GetMaterialPropertiesTable();
57  if (!aMaterialPropertiesTable)
58  {
59  string mname(aMaterial->GetName());
60 
61  std::set<std::string>::const_iterator it =
63 
65  {
67 
68  cout << "PHG4SteppingAction::GetScintLightYield - WARNING - "
69  << "can not find Material Properties Table for material " << mname
70  << ", will assume it do NOT scintillate. "
71  << "Please ignore this warning if you do not expect scintillation light from "
72  << mname << endl;
73  }
74 
75  return 0.;
76  }
77 
78  if (aMaterialPropertiesTable->ConstPropertyExists("SCINTILLATIONYIELD"))
79  {
80  light_yield = aMaterialPropertiesTable->GetConstProperty(
81  "SCINTILLATIONYIELD") *
83 
84  return light_yield;
85  } // if (aMaterialPropertiesTable->ConstPropertyExists("SCINTILLATIONYIELD"))
86  else
87  {
88  string mname(aMaterial->GetName());
89 
90  std::set<std::string>::const_iterator it =
92 
94  {
96 
97  cout << "PHG4SteppingAction::GetScintLightYield - WARNING - "
98  << "can not find scintillation light yield for material " << mname
99  << ", will assume it do NOT scintillate. "
100  << "Please ignore this warning if you do not expect scintillation light from "
101  << mname << endl;
102  }
103 
104  return 0.;
105  }
106 
107  return light_yield;
108 }
109 
110 double
112 {
114  if (emSaturation)
115  {
116  if (m_Verbosity)
117  {
118  emSaturation->SetVerbose(m_Verbosity);
119  }
120  double visen = emSaturation->VisibleEnergyDepositionAtAStep(step) / GeV;
121  return visen;
122  }
123  else
124  {
125  cout
126  << "PHG4SteppingAction::GetScintLightYield - ERROR - can NOT initialize G4EmSaturation!"
127  << endl;
128 
129  return 0.;
130  }
131 }
132 
134  const bool do_prepoint, const bool do_postpoint)
135 {
136  assert(hit);
137  assert(aStep);
138 
139  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
140  G4TouchableHandle theTouchable = preStepPoint->GetTouchableHandle();
141 
142  if (do_prepoint)
143  {
144  G4ThreeVector worldPosition = preStepPoint->GetPosition();
145  G4ThreeVector localPosition =
146  theTouchable->GetHistory()->GetTopTransform().TransformPoint(
147  worldPosition);
148 
149  hit->set_local_x(0, localPosition.x() / cm);
150  hit->set_local_y(0, localPosition.y() / cm);
151  hit->set_local_z(0, localPosition.z() / cm);
152  }
153  if (do_postpoint)
154  {
155  G4StepPoint* postPoint = aStep->GetPostStepPoint();
156 
157  G4ThreeVector worldPosition = postPoint->GetPosition();
158  G4ThreeVector localPosition =
159  theTouchable->GetHistory()->GetTopTransform().TransformPoint(
160  worldPosition);
161 
162  hit->set_local_x(1, localPosition.x() / cm);
163  hit->set_local_y(1, localPosition.y() / cm);
164  hit->set_local_z(1, localPosition.z() / cm);
165  }
166 }
167 
168 void PHG4SteppingAction::SetLightCorrection(const double inner_radius, const double inner_corr, const double outer_radius, const double outer_corr)
169 {
171  m_LightBalanceInnerCorr = inner_corr;
173  m_LightBalanceOuterCorr = outer_corr;
174  return;
175 }
176 
177 double PHG4SteppingAction::GetLightCorrection(const double xpos, const double ypos) const
178 {
179  double r = sqrt(xpos * xpos + ypos * ypos);
180  double correction = GetLightCorrection(r);
181  return correction;
182 }
183 
184 double PHG4SteppingAction::GetLightCorrection(const double r) const
185 {
186  double correction = 1.;
187  if (ValidCorrection())
188  {
191  correction = slope * r + b;
192  correction = std::min(correction, 1.);
193  correction = std::max(correction, 0.);
194  }
195  return correction;
196 }
197 
199 {
204  {
205  return true;
206  }
207  return false;
208 }