ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4FCalSteppingAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4FCalSteppingAction.cc
2 
3 #include "PHG4FCalDetector.h"
4 
5 #include <g4main/PHG4Hit.h>
7 #include <g4main/PHG4Shower.h>
9 
10 #include <phool/getClass.h>
11 
12 #include <Geant4/G4Step.hh>
13 #include <Geant4/G4StepPoint.hh> // for G4StepPoint
14 #include <Geant4/G4SystemOfUnits.hh>
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 <utility> // for pair
25 
26 class G4VPhysicalVolume;
27 
28 using namespace std;
29 
31  : detector_(detector)
32  , hits_(nullptr)
33  , hit(nullptr)
34 {
35 }
36 
38 {
40 
41  int layer_id = 0;
42 
43  if ((detector_->isInScintillator(volume)) == false)
44  {
45  return;
46  }
47 
48  if ((aStep->GetTotalEnergyDeposit() / GeV) == 0.)
49  {
50  return;
51  }
52 
53  layer_id = detector_->getScintillatorLayer(volume);
54  G4StepPoint* prePoint = aStep->GetPreStepPoint();
55  // G4StepPoint* postPoint = aStep->GetPostStepPoint();
56  G4Track* aTrack = aStep->GetTrack();
57 
58  G4double x_center, y_center, z_center;
59 
60  unsigned int hit_index = detector_->computeIndex(layer_id, prePoint->GetPosition().x(), prePoint->GetPosition().y(), prePoint->GetPosition().z(), x_center, y_center, z_center);
61 
63 
64  PHG4Hit* mhit = it->second;
65  mhit->set_x(0, x_center);
66  mhit->set_y(0, y_center);
67  mhit->set_z(0, z_center);
68  mhit->set_edep((aStep->GetTotalEnergyDeposit() / GeV) + it->second->get_edep());
69 
70  // Also store the flag that we want to keep this track on output
71  //
73  {
74  // Do nothing; was assume this flag has already been set
75  if (PHG4TrackUserInfoV1* pp = dynamic_cast<PHG4TrackUserInfoV1*>(p))
76  {
77  pp->SetWanted(true);
78  }
79  else
80  {
81  std::cout << "WARNING: Unknown UserTrackInformation stored in track" << std::endl;
82  }
83  }
84  else
85  {
87  pv->SetWanted(true);
88  aTrack->SetUserInformation(pv);
89  }
90 
91  //set the track ID
92  {
93  hit->set_trkid(aTrack->GetTrackID());
95  {
96  if (PHG4TrackUserInfoV1* pp = dynamic_cast<PHG4TrackUserInfoV1*>(p))
97  {
98  mhit->set_trkid(pp->GetUserTrackId());
99  mhit->set_shower_id(pp->GetShower()->get_id());
100  }
101  }
102  }
103 
104  {
106  {
107  if (PHG4TrackUserInfoV1* pp = dynamic_cast<PHG4TrackUserInfoV1*>(p))
108  {
109  pp->GetShower()->add_g4hit_id(hits_->GetID(), mhit->get_hit_id());
110  }
111  }
112  }
113 }
114 
116 {
117  //now look for the map and grab a pointer to it.
118  hits_ = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_FCAL");
119 
120  // if we do not find the node we need to make it.
121  if (!hits_)
122  {
123  std::cout << "PHG4FCalSteppingAction::SetTopNode - unable to find G4HIT_FCAL" << std::endl;
124  }
125 }