10#include "GaudiKernel/SystemOfUnits.h"
32#ifdef TRKDETDESCR_MEMUSAGE
60 return StatusCode::SUCCESS;
71 if (retrieveCode.isFailure()){
72 ATH_MSG_INFO(
"Could not retrieve mapping volume from tracking geometry. Exiting.");
77 ATH_MSG_VERBOSE(
"Mapping volume correctly retrieved from tracking geometry");
86 (*m_elementTable) += (*eTableEvent);
91 int associatedSteps = 0;
96 if (materialStepCollection.
isValid() && !materialStepCollection->empty()){
99 size_t materialSteps = materialStepCollection->size();
100 ATH_MSG_DEBUG(
"[+] Successfully read "<< materialSteps <<
" geantino steps");
103 double dirx = (*materialStepCollection)[materialSteps-1]->hitX();
104 double diry = (*materialStepCollection)[materialSteps-1]->hitY();
105 double dirz = (*materialStepCollection)[materialSteps-1]->hitZ();
112 return StatusCode::SUCCESS;
125 std::vector< std::pair<const Trk::Layer*, Amg::Vector3D> > layersAndHits;
132 ATH_MSG_VERBOSE(
"[+] Extrapolation to layers did succeed and found " << nLayersHit <<
" layers.");
134 layersAndHits.reserve(nLayersHit);
142 parameters = es.parameters;
144 const Trk::Surface& pSurface = parameters->associatedSurface();
157 std::pair<const Trk::Layer*, Amg::Vector3D> layerHitPair(
158 mLayer, parameters->position());
160 << ++ilayer <<
" with index "
164 layersAndHits.push_back(layerHitPair);
173 if (layersAndHits.empty()){
175 return StatusCode::SUCCESS;
179 size_t currentLayer = 0;
183 ATH_MSG_VERBOSE(
"[L] starting from layer " << currentLayer <<
" from layer collection for this step.");
185 double t = step->steplength();
197 if (currentLayer < nLayersHit-1) {
199 double currentDistance = (pos-layersAndHits[currentLayer].second).
mag();
201 for (
size_t testLayer = (currentLayer+1); testLayer < nLayersHit; ++testLayer){
203 double testDistance = (pos-layersAndHits[testLayer].second).
mag();
204 ATH_MSG_VERBOSE(
"[L] Testing layer " << testLayer <<
" from layer collection for this step.");
206 if ( testDistance < currentDistance ){
208 ATH_MSG_VERBOSE(
"[L] Skipping over to current layer " << testLayer <<
" because " << testDistance <<
" < " << currentDistance);
210 currentLayer = testLayer;
211 currentDistance = testDistance;
219 const Trk::Layer* assignedLayer = layersAndHits[currentLayer].first;
220 Amg::Vector3D assignedPosition = layersAndHits[currentLayer].second;
225 associateHit(*assignedLayer, pos, assignedPosition, t, step->fullMaterial());
232 for (
auto& lhp : layersAndHits){
238 (*clIter).second.associateEmptyHit(lhp.second);
239 ATH_MSG_VERBOSE(
"- to layer with index "<< lhp.first->layerIndex().value() <<
" with empty hit detected.");
241 ATH_MSG_WARNING(
"- no Layer found in the associated map! Should not happen.");
246 if (associatedSteps) {
247 ATH_MSG_VERBOSE(
"There are associated steps, need to call finalizeEvent() & record to the MaterialMapper.");
265 return StatusCode::SUCCESS;
289 (*clIter).second.associateGeantinoHit(positionOnLayer, stepl, mat);
290 ATH_MSG_VERBOSE(
"- associate Geantino Information at intersection [r/z] = " << positionOnLayer.perp() <<
"/"<< positionOnLayer.z() );
292 ATH_MSG_VERBOSE(
"- associate Geantino Information ( s, s/x0 , x0 , l0, a, z, rho ) = "
293 << stepl <<
", "<< stepl/mat.X0 <<
", "<< mat.X0 <<
", "<< mat.L0 <<
", "<< mat.A <<
", "<< mat.Z <<
", "<< mat.rho );
298 ATH_MSG_VERBOSE(
"- to layer with index "<< layer->layerIndex().value() <<
" from '"<< associatedVolume->
volumeName() <<
"'.");
307 ATH_MSG_WARNING(
"- associate hit - the layer with index " << layer->layerIndex().value() <<
" was not found - should not happen!");
318 if (!propSet)
return;
324 if (confinedLayers) {
326 std::span<Trk::Layer * const> layers = confinedLayers->
arrayObjects();
327 ATH_MSG_INFO(
"--> found : "<< layers.size() <<
"confined Layers");
332 if (layer && (*layer).layerIndex().value() ) {
333 ATH_MSG_INFO(
" > LayerIndex: "<< (*layer).layerIndex() );
337 auto curIt = propSet->find((*layer).layerIndex());
338 if (curIt != propSet->end()) {
339 ATH_MSG_INFO(
"LayerMaterial assigned for Layer with index: "<< (*layer).layerIndex() );
341 layer->assignMaterialProperties(*((*curIt).second), 1.);
350 if (confinedVolumes) {
352 std::span<Trk::TrackingVolume * const> volumes = confinedVolumes->
arrayObjects();
353 ATH_MSG_INFO(
"--> found : "<< volumes.size() <<
"confined TrackingVolumes");
355 for (
const auto & volume : volumes) {
367 ATH_MSG_INFO(
"========================================================================================= ");
370#ifdef TRKDETDESCR_MEMUSAGE
371 m_memoryLogger.refresh(getpid());
372 ATH_MSG_INFO(
"[ memory usage ] Start building of material maps: " );
377 std::map< std::string, Trk::LayerMaterialMap* > layerMaterialMaps;
379 ATH_MSG_INFO(
"-> Creating material map '"<< lmcIter->layerMaterialName() <<
"' from creator "<< lmcIter.typeAndName() );
393 std::string vName = eVolume ? (eVolume->
volumeName()) :
" BoundaryCollection ";
394 ATH_MSG_INFO(
"Finalize MaterialAssociation for Layer "<< layerKey.
value() <<
" in " << vName );
406#ifdef TRKDETDESCR_MEMUSAGE
407 m_memoryLogger.refresh(getpid());
408 ATH_MSG_INFO(
"[ memory usage ] Before building the map for Layer "<< layerKey.
value() );
412#ifdef TRKDETDESCR_MEMUSAGE
413 m_memoryLogger.refresh(getpid());
414 ATH_MSG_INFO(
"[ memory usage ] After building the map for Layer "<< layerKey.
value() );
420 (*layerMaterialMaps[lmcIter->layerMaterialName()])[layerKey.
value()] = lMaterial;
422 if (analyse && lMaterial && (
m_layerMaterialAnalysers[ilmc]->analyseLayerMaterial(*layer, *lMaterial)).isFailure() )
423 ATH_MSG_WARNING(
"Could not analyse created LayerMaterialProperties for layer "<< layerKey.
value() );
428 ATH_MSG_INFO(
"Finalize map synchronization and write the maps to the DetectorStore.");
430 for (
auto& ilmIter : layerMaterialMaps ){
433 auto tElementTable = std::make_shared<Trk::ElementTable>(*
m_elementTable);
434 ilmIter.second->updateElementTable(tElementTable);
435 if (ilmIter.second->elementTable()){
436 ATH_MSG_INFO(
"ElementTable for LayerMaterialMap '" << ilmIter.first <<
"' found and syncrhonized." );
441 if ( (
detStore()->record(ilmIter.second, ilmIter.first,
false)).isFailure()){
442 ATH_MSG_ERROR(
"Writing of LayerMaterialMap with name '" << ilmIter.first <<
"' was not successful." );
443 delete ilmIter.second;
444 }
else ATH_MSG_INFO(
"LayerMaterialMap: " << ilmIter.first <<
" written to the DetectorStore!" );
448#ifdef TRKDETDESCR_MEMUSAGE
449 m_memoryLogger.refresh(getpid());
450 ATH_MSG_INFO(
"[ memory usage ] At the end of the material map creation.");
454 ATH_MSG_INFO(
"========================================================================================= " );
459 ATH_MSG_INFO(
"========================================================================================= " );
461 return StatusCode::SUCCESS;
485 return StatusCode::SUCCESS;
492 int sublevel = lvl+1;
494 for (
int indent=0; indent<sublevel; ++indent)
496 std::cout <<
"TrackingVolume name: "<< tvol.
volumeName() << std::endl;
499 std::vector<const Trk::Layer*> volumeLayers;
503 if (confinedLayers) {
505 std::span<Trk::Layer const * const> layers = confinedLayers->
arrayObjects();
506 for (
int indent=0; indent<sublevel; ++indent)
508 std::cout <<
"- found : "<< layers.size() <<
"confined Layers"<< std::endl;
510 auto clIter = layers.begin();
511 auto clIterE = layers.end();
512 for ( ; clIter != clIterE; ++clIter ) {
514 const Amg::Vector3D& sReferencePoint = (*clIter)->surfaceRepresentation().globalReferencePoint();
516 if ((*clIter)->layerMaterialProperties() && insideMappingVolume)
517 volumeLayers.push_back((*clIter));
522 for (
auto& lIter : volumeLayers )
527 if (confinedVolumes) {
528 std::span<Trk::TrackingVolume const * const> volumes = confinedVolumes->
arrayObjects();
530 for (
int indent=0; indent<sublevel; ++indent)
532 std::cout <<
"- found : "<< volumes.size() <<
"confined TrackingVolumes"<< std::endl;
534 auto volumesIter = volumes.begin();
535 for (; volumesIter != volumes.end(); ++volumesIter)
554 if (layerMaterialBinUtility){
558 layerMaterialBinUtility,
566 std::stringstream
msg;
568 throw std::runtime_error(
msg.str());
Scalar eta() const
pseudorapidity method
Scalar mag() const
mag method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
const ServiceHandle< StoreGateSvc > & detStore() const
virtual bool isValid() override final
Can the handle be successfully dereferenced?
It is used in the Mapping process ( using MaterialSteps ), the validation and recostruction ( using M...
A generic symmetric BinUtility, for fully symmetric binning in terms of binning grid and binning type...
Binned Array for avoiding map searches/.
virtual std::span< T *const > arrayObjects()=0
Return all objects of the Array non-const we can still modify the T.
It extends the LayerMaterialProperties base class.
virtual const BinUtility * binUtility() const override
Return the BinUtility.
LayerIndex for the identification of layers in a simplified detector geometry of Cylinders and Discs.
int value() const
layerIndex expressed in an integer
This class extends the DataVector<Trk::LayerMaterialProperties> by an elementTable;.
This virtual base class encapsulates the logics to build pre/post/full update material for Layer stru...
Helper Class to record the material during the GeantinoNtupleMappingProcess.
Base Class for a Detector Layer in the Tracking realm.
const LayerMaterialProperties * layerMaterialProperties() const
getting the LayerMaterialProperties including full/pre/post update
const LayerIndex & layerIndex() const
get the layerIndex
double thickness() const
Return the Thickness of the Layer.
std::map< const Layer *, LayerMaterialRecord > m_layerRecords
this is the general record for the search
double m_accumulatedMaterialXX0
the accumulated material information
std::map< const Layer *, bool > m_layersRecordedPerEvent
these are the layers hit per event - for empty hit scaling
ToolHandle< IMaterialMapper > m_materialMapper
void throwFailedToGetTrackingGeometry() const
void registerVolume(const Trk::TrackingVolume &tvol, int lvl)
Output information with Level.
Gaudi::Property< double > m_etaCutOff
general steering
SG::ReadHandleKey< Trk::ElementTable > m_inputEventElementTable
StatusCode finalize()
standard Athena-Algorithm method
ToolHandleArray< ILayerMaterialAnalyser > m_layerMaterialAnalysers
Trk::ElementTable * m_elementTable
the accumulated element table
void insertLayerMaterialRecord(const Trk::Layer &lay)
const Trk::TrackingVolume * m_mappingVolume
SG::ReadCondHandleKey< TrackingGeometry > m_trackingGeometryReadKey
StatusCode initialize()
standard Athena-Algorithm method
Gaudi::Property< int > m_etaSide
needed for debugging: -1 negative | 0 all | 1 positive
SG::ReadHandleKey< MaterialStepCollection > m_inputMaterialStepCollection
output / input steering
const TrackingGeometry & trackingGeometry() const
StatusCode handleTrackingGeometry()
Retrieve the TrackingGeometry and its informations.
void assignLayerMaterialProperties(Trk::TrackingVolume &tvol, Trk::LayerMaterialMap *propSet)
create the LayerMaterialRecord */
Gaudi::Property< int > m_associationType
ToolHandleArray< ILayerMaterialCreator > m_layerMaterialCreators
StatusCode execute(const EventContext &ctx)
standard Athena-Algorithm method
bool associateHit(const Trk::Layer &tvol, const Amg::Vector3D &pos, const Amg::Vector3D &layerHitPosition, double stepl, const Trk::Material &mat)
Associate the Step to the Layer.
ToolHandle< ILayerMaterialAnalyser > m_layerMaterialRecordAnalyser
ToolHandle< IExtrapolationEngine > m_extrapolationEngine
Gaudi::Property< std::string > m_mappingVolumeName
Gaudi::Property< bool > m_mapComposition
Gaudi::Property< bool > m_mapMaterial
Mapper and Inspector.
Gaudi::Property< double > m_useLayerThickness
is needed for the recording of MaterialProperties from Geant4 and read them in with the mapping algor...
A common object to be contained by.
Abstract Base Class for tracking surfaces.
const Trk::Layer * associatedLayer() const
return the associated Layer
const Trk::MaterialLayer * materialLayer() const
return the material Layer
Full Volume description used in Tracking, it inherits from Volume to get the geometrical structure,...
const LayerArray * confinedLayers() const
Return the subLayer array.
const TrackingVolumeArray * confinedVolumes() const
Return the subLayer array.
const std::string & volumeName() const
Returns the VolumeName - for debug reason, might be depreciated later.
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Eigen::Matrix< double, 3, 1 > Vector3D
const Amg::Vector3D & direction() const
Method to retrieve the direction at the Intersection.
ParametersBase< NeutralParametersDim, Neutral > NeutralParameters
CurvilinearParametersT< NeutralParametersDim, Neutral, PlaneSurface > NeutralCurvilinearParameters