File indexing completed on 2025-08-06 08:18:55
0001 #include "PHG4ConeSteppingAction.h"
0002 #include "PHG4ConeDetector.h"
0003
0004 #include <g4main/PHG4Hit.h>
0005 #include <g4main/PHG4HitContainer.h>
0006 #include <g4main/PHG4Hitv1.h>
0007 #include <g4main/PHG4Shower.h>
0008 #include <g4main/PHG4SteppingAction.h> // for PHG4SteppingAction
0009 #include <g4main/PHG4TrackUserInfoV1.h>
0010
0011 #include <phool/getClass.h>
0012
0013 #include <Geant4/G4ParticleDefinition.hh> // for G4ParticleDefinition
0014 #include <Geant4/G4Step.hh>
0015 #include <Geant4/G4StepPoint.hh> // for G4StepPoint
0016 #include <Geant4/G4StepStatus.hh> // for fGeomBoundary, fUndefined
0017 #include <Geant4/G4String.hh> // for G4String
0018 #include <Geant4/G4SystemOfUnits.hh> // for cm, nanosecond, GeV
0019 #include <Geant4/G4ThreeVector.hh> // for G4ThreeVector
0020 #include <Geant4/G4TouchableHandle.hh> // for G4TouchableHandle
0021 #include <Geant4/G4Track.hh> // for G4Track
0022 #include <Geant4/G4TrackStatus.hh> // for fStopAndKill
0023 #include <Geant4/G4Types.hh> // for G4double
0024 #include <Geant4/G4VTouchable.hh> // for G4VTouchable
0025 #include <Geant4/G4VUserTrackInformation.hh> // for G4VUserTrackInformation
0026
0027 #include <iostream>
0028 #include <string> // for string, operator+, oper...
0029
0030 class G4VPhysicalVolume;
0031 class PHCompositeNode;
0032
0033 using namespace std;
0034
0035 PHG4ConeSteppingAction::PHG4ConeSteppingAction(PHG4ConeDetector* detector)
0036 : PHG4SteppingAction(detector->GetName())
0037 , detector_(detector)
0038 , hits_(nullptr)
0039 , hit(nullptr)
0040 , saveshower(nullptr)
0041 {
0042 }
0043
0044 PHG4ConeSteppingAction::~PHG4ConeSteppingAction()
0045 {
0046
0047
0048
0049
0050 delete hit;
0051 }
0052
0053
0054 bool PHG4ConeSteppingAction::UserSteppingAction(const G4Step* aStep, bool )
0055 {
0056
0057 G4VPhysicalVolume* volume = aStep->GetPreStepPoint()->GetTouchableHandle()->GetVolume();
0058
0059
0060 G4double edep = aStep->GetTotalEnergyDeposit() / GeV;
0061
0062 const G4Track* aTrack = aStep->GetTrack();
0063
0064 int layer_id = detector_->get_Layer();
0065
0066 if (detector_->IsInConeActive(volume))
0067 {
0068 bool geantino = false;
0069
0070
0071
0072 if (aTrack->GetParticleDefinition()->GetPDGEncoding() == 0 &&
0073 aTrack->GetParticleDefinition()->GetParticleName().find("geantino") != string::npos)
0074 {
0075 geantino = true;
0076 }
0077 G4StepPoint* prePoint = aStep->GetPreStepPoint();
0078 G4StepPoint* postPoint = aStep->GetPostStepPoint();
0079
0080
0081
0082 switch (prePoint->GetStepStatus())
0083 {
0084 case fGeomBoundary:
0085 case fUndefined:
0086 if (!hit)
0087 {
0088 hit = new PHG4Hitv1();
0089 }
0090
0091 hit->set_x(0, prePoint->GetPosition().x() / cm);
0092 hit->set_y(0, prePoint->GetPosition().y() / cm);
0093 hit->set_z(0, prePoint->GetPosition().z() / cm);
0094
0095 hit->set_t(0, prePoint->GetGlobalTime() / nanosecond);
0096
0097 hit->set_trkid(aTrack->GetTrackID());
0098
0099 hit->set_edep(0);
0100
0101 if (G4VUserTrackInformation* p = aTrack->GetUserInformation())
0102 {
0103 if (PHG4TrackUserInfoV1* pp = dynamic_cast<PHG4TrackUserInfoV1*>(p))
0104 {
0105 hit->set_trkid(pp->GetUserTrackId());
0106 hit->set_shower_id(pp->GetShower()->get_id());
0107 saveshower = pp->GetShower();
0108 }
0109 }
0110
0111 break;
0112 default:
0113 break;
0114 }
0115
0116
0117
0118 hit->set_x(1, postPoint->GetPosition().x() / cm);
0119 hit->set_y(1, postPoint->GetPosition().y() / cm);
0120 hit->set_z(1, postPoint->GetPosition().z() / cm);
0121
0122 hit->set_t(1, postPoint->GetGlobalTime() / nanosecond);
0123
0124 hit->set_edep(hit->get_edep() + edep);
0125 if (geantino)
0126 {
0127 hit->set_edep(-1);
0128 }
0129 if (edep > 0)
0130 {
0131 if (G4VUserTrackInformation* p = aTrack->GetUserInformation())
0132 {
0133 if (PHG4TrackUserInfoV1* pp = dynamic_cast<PHG4TrackUserInfoV1*>(p))
0134 {
0135 pp->SetKeep(1);
0136 }
0137 }
0138 }
0139
0140
0141
0142
0143
0144
0145
0146 if (postPoint->GetStepStatus() == fGeomBoundary || postPoint->GetStepStatus() == fWorldBoundary || aTrack->GetTrackStatus() == fStopAndKill)
0147 {
0148
0149 if (hit->get_edep())
0150 {
0151 hits_->AddHit(layer_id, hit);
0152 if (saveshower)
0153 {
0154 saveshower->add_g4hit_id(hits_->GetID(), hit->get_hit_id());
0155 }
0156
0157
0158 hit = nullptr;
0159 }
0160 else
0161 {
0162
0163
0164
0165 hit->Reset();
0166 }
0167 }
0168
0169 return true;
0170 }
0171 else
0172 {
0173 return false;
0174 }
0175 }
0176
0177
0178 void PHG4ConeSteppingAction::SetInterfacePointers(PHCompositeNode* topNode)
0179 {
0180 string hitnodename;
0181 if (detector_->SuperDetector() != "NONE")
0182 {
0183 hitnodename = "G4HIT_" + detector_->SuperDetector();
0184 }
0185 else
0186 {
0187 hitnodename = "G4HIT_" + detector_->GetName();
0188 }
0189
0190
0191 hits_ = findNode::getClass<PHG4HitContainer>(topNode, hitnodename);
0192
0193
0194 if (!hits_)
0195 {
0196 std::cout << "PHG4ConeSteppingAction::SetTopNode - unable to find " << hitnodename << std::endl;
0197 }
0198 }