@@ -44,7 +44,7 @@ ldmx::HcalID HcalSD::decodeCopyNumber(const std::uint32_t copyNumber,
4444
4545 // 5cm wide bars are HARD-CODED
4646 if (section == ldmx::HcalID::BACK) {
47- if (geometry.layerIsHorizontal (layer)) {
47+ if (geometry.backLayerIsHorizontal (layer)) {
4848 stripID = int ((localPosition.y () + scint->GetYHalfLength ()) / 50.0 );
4949 } else {
5050 stripID = int ((localPosition.x () + scint->GetXHalfLength ()) / 50.0 );
@@ -169,75 +169,34 @@ G4bool HcalSD::ProcessHits(G4Step* aStep, G4TouchableHistory* ROhist) {
169169 // Convert back to mm
170170 hit.setPathLength (stepLength * CLHEP::cm / CLHEP::mm);
171171 hit.setVelocity (track->GetVelocity ());
172- // Convert pre/post step position from global coordinates to coordinates within the
173- // scintillator bar
174- const auto localPreStepPoint{topTransform.TransformPoint (prePoint->GetPosition ())};
175- const auto localPostStepPoint{topTransform.TransformPoint (postPoint->GetPosition ())};
176-
177- /* *
178- * topTransform translates to the local bar but does not do the rotation
179- * (this is because we don't do a rotation when placing the bars in the GDML)
180- *
181- * the logic below does the rotation to the local coordiates where
182- * x : short transverse side of bar
183- * y : long transverse side of bar
184- * z : along length of bar
185- *
186- * a lot of this logic could (and should) probably be moved into the geometry
187- * condition for the HCal so that it is more easily maintainable
188- *
189- * @note This logic only applies to the v14 and prototype detector; however,
190- * support for v12 is not broken because no studies using these pre/post step
191- * positions have been (or should be) done with the v12 detector.
192- */
193- const auto & geometry = getCondition<ldmx::HcalGeometry>(
172+ const auto &geometry = getCondition<ldmx::HcalGeometry>(
194173 ldmx::HcalGeometry::CONDITIONS_OBJECT_NAME);
195- switch (id.getSection ()) {
196- case ldmx::HcalID::BACK :
197- if (geometry.layerIsHorizontal (id.layer ())) {
198- hit.setPreStepPosition (localPreStepPoint[2 ], localPreStepPoint[1 ], localPreStepPoint[0 ]);
199- hit.setPostStepPosition (localPostStepPoint[2 ], localPostStepPoint[1 ], localPostStepPoint[0 ]);
200- } else {
201- hit.setPreStepPosition (localPreStepPoint[2 ], localPreStepPoint[0 ], localPreStepPoint[1 ]);
202- hit.setPostStepPosition (localPostStepPoint[2 ], localPostStepPoint[0 ], localPostStepPoint[1 ]);
203- }
204- break ;
205- case ldmx::HcalID::TOP :
206- case ldmx::HcalID::BOTTOM :
207- if (id.layer () % 2 == 0 ) {
208- hit.setPreStepPosition (localPreStepPoint[1 ], localPreStepPoint[2 ], localPreStepPoint[0 ]);
209- hit.setPostStepPosition (localPostStepPoint[1 ], localPostStepPoint[2 ], localPostStepPoint[0 ]);
210- } else {
211- hit.setPreStepPosition (localPreStepPoint[1 ], localPreStepPoint[0 ], localPreStepPoint[2 ]);
212- hit.setPostStepPosition (localPostStepPoint[1 ], localPostStepPoint[0 ], localPostStepPoint[2 ]);
213- }
214- break ;
215- case ldmx::HcalID::RIGHT :
216- case ldmx::HcalID::LEFT :
217- if (id.layer () % 2 == 0 ) {
218- hit.setPreStepPosition (localPreStepPoint[0 ], localPreStepPoint[2 ], localPreStepPoint[1 ]);
219- hit.setPostStepPosition (localPostStepPoint[0 ], localPostStepPoint[2 ], localPostStepPoint[1 ]);
220- } else {
221- hit.setPreStepPosition (localPreStepPoint[0 ], localPreStepPoint[1 ], localPreStepPoint[2 ]);
222- hit.setPostStepPosition (localPostStepPoint[0 ], localPostStepPoint[1 ], localPostStepPoint[2 ]);
223- }
224- break ;
225- default :
226- EXCEPTION_RAISE (" HcalSDHit" ," Found an unknown HCal section" );
227- }
174+ // Convert pre/post step position from global coordinates to coordinates
175+ // within the scintillator bar
176+ const auto localPreStepPoint{
177+ topTransform.TransformPoint (prePoint->GetPosition ())};
178+ const auto localPostStepPoint{
179+ topTransform.TransformPoint (postPoint->GetPosition ())};
180+
181+ // And rotate them to a local coordinate system for the bar that always has
182+ // the same x/y/z definitions (see HcalGeometry for details)
183+ auto localPrePositionRotated{geometry.rotateGlobalToLocalBarPosition (
184+ {localPreStepPoint[0 ], localPreStepPoint[1 ], localPreStepPoint[2 ]}, id)};
185+
186+ auto localPostPositionRotated{geometry.rotateGlobalToLocalBarPosition (
187+ {localPostStepPoint[0 ], localPostStepPoint[1 ], localPostStepPoint[2 ]},
188+ id)};
189+ hit.setPreStepPosition (localPrePositionRotated[0 ], localPrePositionRotated[1 ],
190+ localPrePositionRotated[2 ]);
191+ hit.setPostStepPosition (localPostPositionRotated[0 ],
192+ localPostPositionRotated[1 ],
193+ localPostPositionRotated[2 ]);
228194 hit.setPreStepTime (prePoint->GetGlobalTime ());
229195 hit.setPostStepTime (postPoint->GetGlobalTime ());
230196
231- // do we want to set the hit coordinate in the middle of the absorber?
232- // G4ThreeVector volumePosition =
233- // aStep->GetPreStepPoint()->GetTouchableHandle()->GetHistory()->GetTopTransform().Inverse().TransformPoint(G4ThreeVector());
234- // if (section==ldmx::HcalID::BACK) hit->setPosition(position[0], position[1],
235- // volumePosition.z()); elseif (section==ldmx::HcalID::TOP ||
236- // section==ldmx::HcalID::BOTTOM) hit->setPosition(position[0], volumePosition.y(),
237- // position[2]); elseif (section==ldmx::HcalID::LEFT || section==ldmx::HcalID::RIGHT)
238- // hit->setPosition(volumePosition.x(),position[1] , position[2]);
239-
240- if (this ->verboseLevel > 2 ) { hit.Print (); }
197+ if (this ->verboseLevel > 2 ) {
198+ hit.Print ();
199+ }
241200
242201 return true ;
243202}
0 commit comments