29 const G4ThreeVector& localPosition,
31 const unsigned int version{copyNumber / 0x01000000};
34 return ldmx::HcalID{Index(copyNumber).field2(), Index(copyNumber).field1(),
35 Index(copyNumber).field0()};
39 unsigned int strip_id = 0;
40 const unsigned int section = copyNumber / 1000;
41 const unsigned int layer = copyNumber % 1000;
44 if (section == ldmx::HcalID::BACK) {
45 if (geometry.backLayerIsHorizontal(layer)) {
46 strip_id = int((localPosition.y() + scint->GetYHalfLength()) / 50.0);
48 strip_id = int((localPosition.x() + scint->GetXHalfLength()) / 50.0);
51 strip_id = int((localPosition.z() + scint->GetZHalfLength()) / 50.0);
58 G4double edep = aStep->GetTotalEnergyDeposit();
62 if (verboseLevel > 2) {
63 std::cout <<
"CalorimeterSD skipping step with zero edep." << std::endl
97 G4double birks_factor(1.0);
98 G4double step_length = aStep->GetStepLength() / CLHEP::cm;
101 if (step_length > 1.0e-6) {
102 G4double rho = aStep->GetPreStepPoint()->GetMaterial()->GetDensity() /
103 (CLHEP::g / CLHEP::cm3);
104 G4double dedx = edep / (rho * step_length);
105 birks_factor = 1.0 / (1.0 + birksc1_ * dedx + birksc2_ * dedx * dedx);
106 if (aStep->GetTrack()->GetDefinition() == G4Gamma::GammaDefinition())
108 if (aStep->GetTrack()->GetDefinition() == G4Neutron::NeutronDefinition())
113 edep *= birks_factor;
119 G4Box* scint =
nullptr;
122 const auto* pre_step_point = aStep->GetPreStepPoint();
123 if (pre_step_point) {
124 const auto& touchable_handle = pre_step_point->GetTouchableHandle();
125 if (touchable_handle) {
126 const auto* volume = touchable_handle->GetVolume();
129 const auto* logical_volume = volume->GetLogicalVolume();
130 if (logical_volume) {
131 auto* solid = logical_volume->GetSolid();
133 scint =
static_cast<G4Box*
>(solid);
142 G4StepPoint* pre_point = aStep->GetPreStepPoint();
143 G4StepPoint* post_point = aStep->GetPostStepPoint();
152 auto touchable_history{pre_point->GetTouchableHandle()->GetHistory()};
154 auto top_transform{touchable_history->GetTopTransform()};
155 G4ThreeVector position =
156 0.5 * (pre_point->GetPosition() + post_point->GetPosition());
157 G4ThreeVector local_position = top_transform.TransformPoint(position);
158 hit.
setPosition(position[0], position[1], position[2]);
164 int copy_num = touchable_history->GetVolume(2)->GetCopyNo();
174 const G4Track* track = aStep->GetTrack();
175 int track_id = track->GetTrackID();
176 hit.addContrib(
getTrackMap().findIncident(track_id), track_id,
177 track->GetParticleDefinition()->GetPDGEncoding(), edep,
178 track->GetGlobalTime());
183 hit.setPathLength(step_length * CLHEP::cm / CLHEP::mm);
184 hit.setVelocity(track->GetVelocity());
189 const auto local_pre_step_point{
190 top_transform.TransformPoint(pre_point->GetPosition())};
191 const auto local_post_step_point{
192 top_transform.TransformPoint(post_point->GetPosition())};
196 auto local_pre_position_rotated{geometry.rotateGlobalToLocalBarPosition(
197 {local_pre_step_point[0], local_pre_step_point[1],
198 local_pre_step_point[2]},
201 auto local_post_position_rotated{geometry.rotateGlobalToLocalBarPosition(
202 {local_post_step_point[0], local_post_step_point[1],
203 local_post_step_point[2]},
205 hit.setPreStepPosition(local_pre_position_rotated[0],
206 local_pre_position_rotated[1],
207 local_pre_position_rotated[2]);
208 hit.setPostStepPosition(local_post_position_rotated[0],
209 local_post_position_rotated[1],
210 local_post_position_rotated[2]);
211 hit.setPreStepTime(pre_point->GetGlobalTime());
212 hit.setPostStepTime(post_point->GetGlobalTime());
214 ldmx_log(trace) << hit;