10#include "GaudiKernel/SystemOfUnits.h"
33#ifdef TRKDETDESCR_MEMUSAGE
58#ifdef TRKDETDESCR_MEMUSAGE
113 return StatusCode::SUCCESS;
124 if (retrieveCode.isFailure()){
125 ATH_MSG_INFO(
"Could not retrieve mapping volume from tracking geometry. Exiting.");
130 ATH_MSG_VERBOSE(
"Mapping volume correctly retrieved from tracking geometry");
139 (*m_elementTable) += (*eTableEvent);
144 int associatedSteps = 0;
149 if (materialStepCollection.
isValid() && !materialStepCollection->empty()){
152 size_t materialSteps = materialStepCollection->size();
153 ATH_MSG_DEBUG(
"[+] Successfully read "<< materialSteps <<
" geantino steps");
156 double dirx = (*materialStepCollection)[materialSteps-1]->hitX();
157 double diry = (*materialStepCollection)[materialSteps-1]->hitY();
158 double dirz = (*materialStepCollection)[materialSteps-1]->hitZ();
161 double eta = direction.eta();
165 return StatusCode::SUCCESS;
178 std::vector< std::pair<const Trk::Layer*, Amg::Vector3D> > layersAndHits;
185 ATH_MSG_VERBOSE(
"[+] Extrapolation to layers did succeed and found " << nLayersHit <<
" layers.");
187 layersAndHits.reserve(nLayersHit);
195 parameters = es.parameters;
197 const Trk::Surface& pSurface = parameters->associatedSurface();
210 std::pair<const Trk::Layer*, Amg::Vector3D> layerHitPair(
211 mLayer, parameters->position());
213 << ++ilayer <<
" with index "
217 layersAndHits.push_back(layerHitPair);
226 if (layersAndHits.empty()){
228 return StatusCode::SUCCESS;
232 size_t currentLayer = 0;
236 ATH_MSG_VERBOSE(
"[L] starting from layer " << currentLayer <<
" from layer collection for this step.");
238 double t = step->steplength();
250 if (currentLayer < nLayersHit-1) {
252 double currentDistance = (pos-layersAndHits[currentLayer].second).
mag();
254 for (
size_t testLayer = (currentLayer+1); testLayer < nLayersHit; ++testLayer){
256 double testDistance = (pos-layersAndHits[testLayer].second).
mag();
257 ATH_MSG_VERBOSE(
"[L] Testing layer " << testLayer <<
" from layer collection for this step.");
259 if ( testDistance < currentDistance ){
261 ATH_MSG_VERBOSE(
"[L] Skipping over to current layer " << testLayer <<
" because " << testDistance <<
" < " << currentDistance);
263 currentLayer = testLayer;
264 currentDistance = testDistance;
272 const Trk::Layer* assignedLayer = layersAndHits[currentLayer].first;
273 Amg::Vector3D assignedPosition = layersAndHits[currentLayer].second;
278 associateHit(*assignedLayer, pos, assignedPosition, t, step->fullMaterial());
285 for (
auto& lhp : layersAndHits){
291 (*clIter).second.associateEmptyHit(lhp.second);
292 ATH_MSG_VERBOSE(
"- to layer with index "<< lhp.first->layerIndex().value() <<
" with empty hit detected.");
294 ATH_MSG_WARNING(
"- no Layer found in the associated map! Should not happen.");
299 if (associatedSteps) {
300 ATH_MSG_VERBOSE(
"There are associated steps, need to call finalizeEvent() & record to the MaterialMapper.");
318 return StatusCode::SUCCESS;
342 (*clIter).second.associateGeantinoHit(positionOnLayer, stepl, mat);
343 ATH_MSG_VERBOSE(
"- associate Geantino Information at intersection [r/z] = " << positionOnLayer.perp() <<
"/"<< positionOnLayer.z() );
345 ATH_MSG_VERBOSE(
"- associate Geantino Information ( s, s/x0 , x0 , l0, a, z, rho ) = "
346 << stepl <<
", "<< stepl/mat.X0 <<
", "<< mat.X0 <<
", "<< mat.L0 <<
", "<< mat.A <<
", "<< mat.Z <<
", "<< mat.rho );
351 ATH_MSG_VERBOSE(
"- to layer with index "<< layer->layerIndex().value() <<
" from '"<< associatedVolume->
volumeName() <<
"'.");
360 ATH_MSG_WARNING(
"- associate hit - the layer with index " << layer->layerIndex().value() <<
" was not found - should not happen!");
371 if (!propSet)
return;
377 if (confinedLayers) {
379 std::span<Trk::Layer * const> layers = confinedLayers->
arrayObjects();
380 ATH_MSG_INFO(
"--> found : "<< layers.size() <<
"confined Layers");
385 if (layer && (*layer).layerIndex().value() ) {
386 ATH_MSG_INFO(
" > LayerIndex: "<< (*layer).layerIndex() );
390 auto curIt = propSet->find((*layer).layerIndex());
391 if (curIt != propSet->end()) {
392 ATH_MSG_INFO(
"LayerMaterial assigned for Layer with index: "<< (*layer).layerIndex() );
394 layer->assignMaterialProperties(*((*curIt).second), 1.);
403 if (confinedVolumes) {
405 std::span<Trk::TrackingVolume * const> volumes = confinedVolumes->
arrayObjects();
406 ATH_MSG_INFO(
"--> found : "<< volumes.size() <<
"confined TrackingVolumes");
408 for (
const auto & volume : volumes) {
420 ATH_MSG_INFO(
"========================================================================================= ");
423#ifdef TRKDETDESCR_MEMUSAGE
424 m_memoryLogger.refresh(getpid());
425 ATH_MSG_INFO(
"[ memory usage ] Start building of material maps: " );
430 std::map< std::string, Trk::LayerMaterialMap* > layerMaterialMaps;
432 ATH_MSG_INFO(
"-> Creating material map '"<< lmcIter->layerMaterialName() <<
"' from creator "<< lmcIter.typeAndName() );
446 std::string vName = eVolume ? (eVolume->
volumeName()) :
" BoundaryCollection ";
447 ATH_MSG_INFO(
"Finalize MaterialAssociation for Layer "<< layerKey.
value() <<
" in " << vName );
459#ifdef TRKDETDESCR_MEMUSAGE
460 m_memoryLogger.refresh(getpid());
461 ATH_MSG_INFO(
"[ memory usage ] Before building the map for Layer "<< layerKey.
value() );
465#ifdef TRKDETDESCR_MEMUSAGE
466 m_memoryLogger.refresh(getpid());
467 ATH_MSG_INFO(
"[ memory usage ] After building the map for Layer "<< layerKey.
value() );
473 (*layerMaterialMaps[lmcIter->layerMaterialName()])[layerKey.
value()] = lMaterial;
475 if (analyse && lMaterial && (
m_layerMaterialAnalysers[ilmc]->analyseLayerMaterial(*layer, *lMaterial)).isFailure() )
476 ATH_MSG_WARNING(
"Could not analyse created LayerMaterialProperties for layer "<< layerKey.
value() );
481 ATH_MSG_INFO(
"Finalize map synchronization and write the maps to the DetectorStore.");
483 for (
auto& ilmIter : layerMaterialMaps ){
486 auto tElementTable = std::make_shared<Trk::ElementTable>(*
m_elementTable);
487 ilmIter.second->updateElementTable(tElementTable);
488 if (ilmIter.second->elementTable()){
489 ATH_MSG_INFO(
"ElementTable for LayerMaterialMap '" << ilmIter.first <<
"' found and syncrhonized." );
494 if ( (
detStore()->record(ilmIter.second, ilmIter.first,
false)).isFailure()){
495 ATH_MSG_ERROR(
"Writing of LayerMaterialMap with name '" << ilmIter.first <<
"' was not successful." );
496 delete ilmIter.second;
497 }
else ATH_MSG_INFO(
"LayerMaterialMap: " << ilmIter.first <<
" written to the DetectorStore!" );
501#ifdef TRKDETDESCR_MEMUSAGE
502 m_memoryLogger.refresh(getpid());
503 ATH_MSG_INFO(
"[ memory usage ] At the end of the material map creation.");
507 ATH_MSG_INFO(
"========================================================================================= " );
512 ATH_MSG_INFO(
"========================================================================================= " );
514 return StatusCode::SUCCESS;
538 return StatusCode::SUCCESS;
545 int sublevel = lvl+1;
547 for (
int indent=0; indent<sublevel; ++indent)
549 std::cout <<
"TrackingVolume name: "<< tvol.
volumeName() << std::endl;
552 std::vector<const Trk::Layer*> volumeLayers;
556 if (confinedLayers) {
558 std::span<Trk::Layer const * const> layers = confinedLayers->
arrayObjects();
559 for (
int indent=0; indent<sublevel; ++indent)
561 std::cout <<
"- found : "<< layers.size() <<
"confined Layers"<< std::endl;
563 auto clIter = layers.begin();
564 auto clIterE = layers.end();
565 for ( ; clIter != clIterE; ++clIter ) {
567 const Amg::Vector3D& sReferencePoint = (*clIter)->surfaceRepresentation().globalReferencePoint();
569 if ((*clIter)->layerMaterialProperties() && insideMappingVolume)
570 volumeLayers.push_back((*clIter));
575 for (
auto& lIter : volumeLayers )
580 if (confinedVolumes) {
581 std::span<Trk::TrackingVolume const * const> volumes = confinedVolumes->
arrayObjects();
583 for (
int indent=0; indent<sublevel; ++indent)
585 std::cout <<
"- found : "<< volumes.size() <<
"confined TrackingVolumes"<< std::endl;
587 auto volumesIter = volumes.begin();
588 for (; volumesIter != volumes.end(); ++volumesIter)
607 if (layerMaterialBinUtility){
610 layerMaterialBinUtility,
618 std::stringstream
msg;
620 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)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
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
bool m_useLayerThickness
use the actual layer thickness
MaterialMapping(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
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.
double m_minCompositionFraction
minimal fraction to be accounted for the composition recording
SG::ReadHandleKey< Trk::ElementTable > m_inputEventElementTable
input event table
int m_etaSide
needed for debugging: -1 negative | 0 all | 1 positive
StatusCode finalize()
standard Athena-Algorithm method
ToolHandleArray< ILayerMaterialAnalyser > m_layerMaterialAnalysers
Trk::ElementTable * m_elementTable
the accumulated element table
bool m_mapMaterial
Mapper and Inspector.
void insertLayerMaterialRecord(const Trk::Layer &lay)
const Trk::TrackingVolume * m_mappingVolume
SG::ReadCondHandleKey< TrackingGeometry > m_trackingGeometryReadKey
StatusCode initialize()
standard Athena-Algorithm method
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 */
ToolHandleArray< ILayerMaterialCreator > m_layerMaterialCreators
int m_layerMaterialScreenOutput
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
~MaterialMapping()
Default Destructor.
StatusCode execute()
standard Athena-Algorithm method
ToolHandle< IExtrapolationEngine > m_extrapolationEngine
std::string m_mappingVolumeName
double m_etaCutOff
general steering
bool m_mapComposition
map the composition of the material
bool m_checkForEmptyHits
use extrapoaltion engine to check for empty hits
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
ParametersBase< NeutralParametersDim, Neutral > NeutralParameters
CurvilinearParametersT< NeutralParametersDim, Neutral, PlaneSurface > NeutralCurvilinearParameters