25 #include "GaudiKernel/SystemOfUnits.h"
30 m_materialMapper(
"Trk::MaterialMapper/MappingMaterialMapper"),
31 m_maxMaterialValidationEvents(25000),
35 m_runNativeNavigation(true),
60 ATH_CHECK( m_trackingGeometryReadKey.initialize(!m_trackingGeometryReadKey.key().empty()) );
62 if ( (m_materialMapper.retrieve()).isFailure() )
66 m_flatDist =
new Rndm::Numbers(randSvc(), Rndm::Flat(0.,1.));
67 return StatusCode::SUCCESS;
73 ATH_MSG_VERBOSE(
"MaterialValidation execute() start ================================================" );
76 double eta = m_etaMin + (m_etaMax-m_etaMin)*m_flatDist->shoot();
78 double phi =
M_PI * ( 2*m_flatDist->shoot() - 1.);
85 ATH_MSG_DEBUG(
"[>] Start mapping event with phi | eta = " <<
phi <<
" | " << direction.eta());
95 ATH_MSG_DEBUG(
"[<] Finishing event with collected path [X0] = " << m_accTinX0);
96 return StatusCode::SUCCESS;
104 std::map<double, Trk::AssociatedMaterial> collectedMaterial;
113 if (m_runNativeNavigation){
117 for (
auto& lCandidate : layerIntersections ) {
120 double pathLength = lCandidate.intersection.pathLength;
122 if (
layer->layerMaterialProperties()){
126 double stepLength = mprop->
thickness()*fabs(
layer->surfaceRepresentation().pathCorrection(lCandidate.intersection.position,direction));
132 Amg::Vector3D lastPosition = !collectedMaterial.empty() ? collectedMaterial.rbegin()->second.materialPosition() : (position + direction.unit());
136 if (!boundaryIntersections.empty()){
138 lastPosition = boundaryIntersections.begin()->intersection.
position;
144 double pathLength = (lastPosition-position).
mag();
157 std::map<double, std::pair<const Trk::Layer*, Amg::Vector3D> > intersectedLayers;
164 auto layIter =
layers.begin();
165 auto layIterE =
layers.end();
166 for ( ; layIter != layIterE; ++layIter){
167 if ( (*layIter)->layerMaterialProperties() ){
168 Trk::Intersection lsIntersection = (*layIter)->surfaceRepresentation().straightLineIntersection(position, direction,
true,
true);
169 if (lsIntersection.
valid){
170 intersectedLayers[lsIntersection.
pathLength] = std::pair<const Trk::Layer*, Amg::Vector3D>(*layIter,lsIntersection.
position);
173 Amg::Vector3D mposition = (*layIter)->surfaceRepresentation().transform().inverse()*lsIntersection.
position;
176 double stepLength = mprop->
thickness()*fabs((*layIter)->surfaceRepresentation().pathCorrection(lsIntersection.
position,direction));
194 Amg::Vector3D lastPosition = !intersectedLayers.empty() ? (*(--(intersectedLayers.end()))).
second.second : position;
196 std::map<double, Trk::VolumeExit > volumeExits;
199 for (
size_t ib = 0;
ib < bSurfaces.size(); ++
ib){
201 if ( !bSurfaces[
ib]->surfaceRepresentation().isOnSurface(lastPosition,
true, 0.1, 0.1) ){
202 Trk::Intersection evIntersection = bSurfaces[
ib]->surfaceRepresentation().straightLineIntersection(lastPosition, direction,
true,
true);
205 if (evIntersection.
valid){
217 if (!volumeExits.empty()){
223 ATH_MSG_VERBOSE(
"[>>>>] The boundary surface has an associated layer, collect material from there");
225 double pathToExit = (closestVolumeExit.
vExit-lastPosition).
mag();
233 if (closestVolumeExit.
nVolume != &tvol && closestVolumeExit.
nVolume) {
239 ATH_MSG_VERBOSE(
"[>>>>] No exit found from Volume '" << tvol.
volumeName() <<
"' - starting radius = " << lastPosition.perp() );
247 ATH_MSG_DEBUG(
"[>>>] Collecting materials from "<< collectedMaterial.size() <<
" layers");
249 auto cmIter = collectedMaterial.begin();
250 auto cmIterE = collectedMaterial.end();
251 for ( ; cmIter != cmIterE; ++cmIter ){
252 m_materialMapper->recordMaterialHit(cmIter->second, cmIter->second.materialPosition());
253 m_accTinX0 += cmIter->second.steplengthInX0();
254 int layerIndex = cmIter->second.associatedLayer() ? cmIter->second.associatedLayer()->layerIndex().value() : 0;
255 ATH_MSG_DEBUG(
"[>>>] Accumulate pathLength/X0 on layer with index " << layerIndex <<
" - t/X0 (total so far) = " << cmIter->second.steplengthInX0() <<
" (" << m_accTinX0 <<
")");
257 std::string surfaceType =
258 cmIter->second.associatedLayer()->surfaceRepresentation().type() ==
260 ?
"Cylinder at radius = "
261 :
"Disc at z-position = ";
262 std::string layerType =
263 cmIter->second.associatedLayer()->surfaceArray() ?
"Active "
266 cmIter->second.associatedLayer()->surfaceRepresentation().type() ==
268 ? cmIter->second.associatedLayer()
269 ->surfaceRepresentation()
272 : cmIter->second.associatedLayer()
273 ->surfaceRepresentation()
278 ATH_MSG_DEBUG(
" Distance to origin is " << cmIter->second.materialPosition().mag() );
291 return StatusCode::SUCCESS;
295 std::stringstream
msg;
296 msg <<
"Failed to get conditions data " << m_trackingGeometryReadKey.key() <<
".";
297 throw std::runtime_error(
msg.str());