30 const G4ThreeVector& localPosition,
32 const unsigned int version{copyNumber / 0x01000000};
35 return ldmx::HcalID{Index(copyNumber).field2(), Index(copyNumber).field1(),
36 Index(copyNumber).field0()};
38 const auto& geometry = getCondition<ldmx::HcalGeometry>(
40 unsigned int stripID = 0;
41 const unsigned int section = copyNumber / 1000;
42 const unsigned int layer = copyNumber % 1000;
45 if (section == ldmx::HcalID::BACK) {
46 if (geometry.backLayerIsHorizontal(layer)) {
47 stripID = int((localPosition.y() + scint->GetYHalfLength()) / 50.0);
49 stripID = int((localPosition.x() + scint->GetXHalfLength()) / 50.0);
52 stripID = int((localPosition.z() + scint->GetZHalfLength()) / 50.0);
59 G4double edep = aStep->GetTotalEnergyDeposit();
63 if (verboseLevel > 2) {
64 std::cout <<
"CalorimeterSD skipping step with zero edep." << std::endl
98 G4double birksFactor(1.0);
99 G4double stepLength = aStep->GetStepLength() / CLHEP::cm;
102 if (stepLength > 1.0e-6) {
103 G4double rho = aStep->GetPreStepPoint()->GetMaterial()->GetDensity() /
104 (CLHEP::g / CLHEP::cm3);
105 G4double dedx = edep / (rho * stepLength);
106 birksFactor = 1.0 / (1.0 + birksc1_ * dedx + birksc2_ * dedx * dedx);
107 if (aStep->GetTrack()->GetDefinition() == G4Gamma::GammaDefinition())
109 if (aStep->GetTrack()->GetDefinition() == G4Neutron::NeutronDefinition())
120 G4Box* scint =
nullptr;
123 const auto* preStepPoint = aStep->GetPreStepPoint();
125 const auto& touchableHandle = preStepPoint->GetTouchableHandle();
126 if (touchableHandle) {
127 const auto* volume = touchableHandle->GetVolume();
130 const auto* logicalVolume = volume->GetLogicalVolume();
132 auto* solid = logicalVolume->GetSolid();
134 scint =
static_cast<G4Box*
>(solid);
143 G4StepPoint* prePoint = aStep->GetPreStepPoint();
144 G4StepPoint* postPoint = aStep->GetPostStepPoint();
153 auto touchableHistory{prePoint->GetTouchableHandle()->GetHistory()};
155 auto topTransform{touchableHistory->GetTopTransform()};
156 G4ThreeVector position =
157 0.5 * (prePoint->GetPosition() + postPoint->GetPosition());
158 G4ThreeVector localPosition = topTransform.TransformPoint(position);
159 hit.setPosition(position[0], position[1], position[2]);
165 int copyNum = touchableHistory->GetVolume(2)->GetCopyNo();
175 const G4Track* track = aStep->GetTrack();
176 int track_id = track->GetTrackID();
177 hit.addContrib(
getTrackMap().findIncident(track_id), track_id,
178 track->GetParticleDefinition()->GetPDGEncoding(), edep,
179 track->GetGlobalTime());
184 hit.setPathLength(stepLength * CLHEP::cm / CLHEP::mm);
185 hit.setVelocity(track->GetVelocity());
186 const auto& geometry = getCondition<ldmx::HcalGeometry>(
190 const auto localPreStepPoint{
191 topTransform.TransformPoint(prePoint->GetPosition())};
192 const auto localPostStepPoint{
193 topTransform.TransformPoint(postPoint->GetPosition())};
197 auto localPrePositionRotated{geometry.rotateGlobalToLocalBarPosition(
198 {localPreStepPoint[0], localPreStepPoint[1], localPreStepPoint[2]}, id)};
200 auto localPostPositionRotated{geometry.rotateGlobalToLocalBarPosition(
201 {localPostStepPoint[0], localPostStepPoint[1], localPostStepPoint[2]},
203 hit.setPreStepPosition(localPrePositionRotated[0], localPrePositionRotated[1],
204 localPrePositionRotated[2]);
205 hit.setPostStepPosition(localPostPositionRotated[0],
206 localPostPositionRotated[1],
207 localPostPositionRotated[2]);
208 hit.setPreStepTime(prePoint->GetGlobalTime());
209 hit.setPostStepTime(postPoint->GetGlobalTime());
211 if (this->verboseLevel > 2) {