ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4FPbScSteppingAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4FPbScSteppingAction.cc
2 #include "PHG4FPbScDetector.h"
3 
4 #include <g4main/PHG4Hit.h>
6 #include <g4main/PHG4Shower.h>
7 #include <g4main/PHG4SteppingAction.h> // for PHG4SteppingAction
9 
10 #include <phool/getClass.h>
11 
12 #include <Geant4/G4Step.hh>
13 #include <Geant4/G4StepPoint.hh> // for G4StepPoint
14 #include <Geant4/G4SystemOfUnits.hh> // for cm
15 #include <Geant4/G4ThreeVector.hh> // for G4ThreeVector
16 #include <Geant4/G4TouchableHandle.hh> // for G4TouchableHandle
17 #include <Geant4/G4Track.hh> // for G4Track
18 #include <Geant4/G4Types.hh> // for G4double
19 #include <Geant4/G4VTouchable.hh> // for G4VTouchable
20 #include <Geant4/G4VUserTrackInformation.hh> // for G4VUserTrackInformation
21 
22 #include <iostream> // for operator<<, endl, basic...
23 #include <map> // for _Rb_tree_iterator
24 #include <string> // for operator+, string, char...
25 #include <utility> // for pair
26 
27 class G4VPhysicalVolume;
28 
29 using namespace std;
30 
32  : PHG4SteppingAction(detector->GetName())
33  , detector_(detector)
34  , hits_(nullptr)
35 {
36 }
37 
39 {
41 
42  int layer_id = 0;
43 
44  if ((detector_->isInScintillator(volume)) == false)
45  {
46  return false;
47  }
48 
49  if ((aStep->GetTotalEnergyDeposit() / GeV) == 0.)
50  {
51  return false;
52  }
53 
54  layer_id = detector_->getScintillatorLayer(volume);
55 
56  G4StepPoint* prePoint = aStep->GetPreStepPoint();
57  G4StepPoint* postPoint = aStep->GetPostStepPoint();
58  G4Track* aTrack = aStep->GetTrack();
59 
60  G4double x_center, y_center, z_center;
61 
62  int hit_index = detector_->computeIndex(layer_id,
63  prePoint->GetPosition().x() / cm,
64  prePoint->GetPosition().y() / cm,
65  prePoint->GetPosition().z() / cm,
66  x_center, y_center, z_center);
67 
69 
70  PHG4Hit* mhit = it->second;
71  mhit->set_x(0, x_center);
72  mhit->set_y(0, y_center);
73  mhit->set_z(0, z_center);
74  mhit->set_edep(0);
75 
76  hit_index = detector_->computeIndex(layer_id,
77  postPoint->GetPosition().x() / cm,
78  postPoint->GetPosition().y() / cm,
79  postPoint->GetPosition().z() / cm,
80  x_center, y_center, z_center);
81 
82  it = hits_->findOrAddHit(hit_index);
83 
84  mhit = it->second;
85  mhit->set_x(1, x_center);
86  mhit->set_y(1, y_center);
87  mhit->set_z(1, z_center);
88  mhit->set_edep((aStep->GetTotalEnergyDeposit() / GeV) + it->second->get_edep());
89 
90  // Also store the flag that we want to keep this track on output
91  //
93  {
94  // Do nothing; was assume this flag has already been set
95  if (PHG4TrackUserInfoV1* pp = dynamic_cast<PHG4TrackUserInfoV1*>(p))
96  {
97  pp->SetWanted(true);
98  }
99  else
100  {
101  std::cout << "WARNING: Unknown UserTrackInformation stored in track" << std::endl;
102  }
103  }
104  else
105  {
107  pv->SetWanted(true);
108  aTrack->SetUserInformation(pv);
109  }
110 
111  //set the track ID
112  {
113  mhit->set_trkid(aTrack->GetTrackID());
115  {
116  if (PHG4TrackUserInfoV1* pp = dynamic_cast<PHG4TrackUserInfoV1*>(p))
117  {
118  mhit->set_trkid(pp->GetUserTrackId());
119  mhit->set_shower_id(pp->GetShower()->get_id());
120  }
121  }
122  }
123 
124  {
126  {
127  if (PHG4TrackUserInfoV1* pp = dynamic_cast<PHG4TrackUserInfoV1*>(p))
128  {
129  pp->GetShower()->add_g4hit_id(hits_->GetID(), mhit->get_hit_id());
130  }
131  }
132  }
133 
134  return true;
135 }
136 
138 {
139  string hitnodename = "G4HIT_" + detector_->GetName();
140  //now look for the map and grab a pointer to it.
141  hits_ = findNode::getClass<PHG4HitContainer>(topNode, hitnodename.c_str());
142 
143  // if we do not find the node we need to make it.
144  if (!hits_)
145  {
146  std::cout << "PHG4FPbScSteppingAction::SetTopNode - unable to find " << hitnodename.c_str() << std::endl;
147  }
148 }