ATLAS Offline Software
Loading...
Searching...
No Matches
CompoundLayerMaterialCreator.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6// CompoundLayerMaterialCreator.cxx, (c) ATLAS Detector software
8
9// STL
10#include <cmath>
11
12#include <sstream>
13// Trk include
20
21
22// constructor
23Trk::CompoundLayerMaterialCreator::CompoundLayerMaterialCreator(const std::string& t, const std::string& n, const IInterface* p)
24: AthAlgTool(t,n,p)
25{
26 declareInterface<Trk::ILayerMaterialCreator>(this);
27 // give the map a name
28 declareProperty("LayerMaterialName" , m_layerMaterialName);
29 declareProperty("LayerMaterialDirectory" , m_layerMaterialDirectory);
30}
31
32
34{
35 // get the material matrix
36 const Trk::MaterialPropertiesMatrix& materialMatrix = lmr.associatedLayerMaterial();
37 // get the bin untility
38 const Trk::BinUtility* binUtility = lmr.binUtility();
39 // if there's no bin utility - bail out
40 if (!binUtility){
41 ATH_MSG_WARNING( "No BinUtility given - Bailing out." );
42 return nullptr;
43 } else
44 ATH_MSG_DEBUG( "BinUtility provided, creating binned array in dimensions " << binUtility->max(0)+1 << " x " << binUtility->max(1)+1 );
45 // return the created compound material
46 return createCompoundLayerMaterial(materialMatrix,*binUtility);
47}
48
50{
51
52 // the return object
53 Trk::LayerMaterialProperties* bLayerMaterial = nullptr;
54 // get the binUtility of the LayerMaterialProperties
55 const Trk::BinUtility* bUtility = lmProperties.binUtility();
56 // we have a bin utility, get the matrix and fill it
57 if (bUtility){
58 // prepare the matrix
59 // nF x nS
60 size_t nBins0 = bUtility->max(0)+1;
61 size_t nBins1 = bUtility->max(1)+1;
62 // create the MaterialMatrix
63 Trk::MaterialPropertiesMatrix materialMatrix;
64 materialMatrix.reserve(nBins1);
65 // fill the matrix
66 for (size_t ibin1 = 0; ibin1 < nBins1; ++ibin1) {
67 // create the vector first
68 Trk::MaterialPropertiesVector materialVector;
69 materialVector.reserve(nBins0);
70 // loop over local 1 bins
71 for (size_t ibin0 = 0; ibin0 < nBins0; ++ibin0) {
72 // get the material from the properties and push them into the matrix (no cloning !)
73 const Trk::MaterialProperties* mProperties = lmProperties.material(ibin0,ibin1);
74 materialVector.push_back(mProperties);
75 }
76 // now pus the vector into the matrix
77 materialMatrix.push_back(materialVector);
78 }
79
80 // create the material
81 ATH_MSG_VERBOSE("Converting the MaterialPropertiesMatrix into a CompressedLayerMaterial.");
82 bLayerMaterial = createCompoundLayerMaterial(materialMatrix,*bUtility);
83
84 } else {
85 // must be homogenous material, can be transformed into a 0-bin material, would be silly though
86 ATH_MSG_DEBUG("No BinUtility provided - return a simple clone.");
87 bLayerMaterial = lmProperties.clone();
88 }
89 //
90 return bLayerMaterial;
91}
92
94{
95
96
97 // analyse the material bins
98 double tMin = 10e10;
99 double xMin = 10e10;
100 double lMin = 10e10;
101 double aMin = 10e10;
102 double zMin = 10e10;
103 double rMin = 10e10;
104 double tMax = 0.;
105 double xMax = 0.;
106 double lMax = 0.;
107 double aMax = 0.;
108 double zMax = 0.;
109 double rMax = 0.;
110
111 // first loop to get the min/max values
112 for (const auto & mo : materialMatrix)
113 for (const auto & mi : mo) {
114 if (mi){
115 const Trk::MaterialProperties& mp = (*mi);
116 // macro defined in GeometryStatics
117 minMaxValue(tMin, tMax, mp.thickness());
118 minMaxValue(xMin, xMax, mp.x0());
119 minMaxValue(lMin, lMax, mp.l0());
120 minMaxValue(aMin, aMax, mp.averageA());
121 minMaxValue(zMin, zMax, mp.averageZ());
122 minMaxValue(rMin, rMax, mp.averageRho());
123 }
124 }
125
126 ATH_MSG_DEBUG( "Preparing the store: min/max values for t, x0, l0, a, z, rho estimated." );
127
128
129 // the bin matrices in the store
130 Trk::ValueMatrix binMatrix( lBinUtility.max(1)+1, Trk::ValueVector(lBinUtility.max(0)+1, static_cast<unsigned char>(0) ) );
131 // 255 bins, the 0 bin indicates empy
132 Trk::ValueStore tStore;
133 Trk::ValueStore xStore;
134 Trk::ValueStore lStore;
135 Trk::ValueStore aStore;
136 Trk::ValueStore zStore;
137 Trk::ValueStore rStore;
138 // set the store min, max
139 tStore.valueMin = tMin;
140 xStore.valueMin = xMin;
141 lStore.valueMin = lMin;
142 aStore.valueMin = aMin;
143 zStore.valueMin = zMin;
144 rStore.valueMin = rMin;
145 tStore.valueStep = fabs(tMin-tMax)<10e-8 ? 0. : (tMax-tMin)/double(static_cast<int>(UCHAR_MAX)-1);
146 xStore.valueStep = (xMax-xMin)/double(static_cast<int>(UCHAR_MAX)-1);
147 lStore.valueStep = (lMax-lMin)/double(static_cast<int>(UCHAR_MAX)-1);
148 aStore.valueStep = (aMax-aMin)/double(static_cast<int>(UCHAR_MAX)-1);
149 zStore.valueStep = (zMax-zMin)/double(static_cast<int>(UCHAR_MAX)-1);
150 rStore.valueStep = (rMax-rMin)/double(static_cast<int>(UCHAR_MAX)-1);
151
152 ATH_MSG_VERBOSE(" - t [ min/max/step ] = " << tMin << " / " << tMax << " / " << tStore.valueStep );
153 ATH_MSG_VERBOSE(" - x0 [ min/max/step ] = " << xMin << " / " << xMax << " / " << xStore.valueStep );
154 ATH_MSG_VERBOSE(" - l0 [ min/max/step ] = " << lMin << " / " << lMax << " / " << lStore.valueStep );
155 ATH_MSG_VERBOSE(" - a [ min/max/step ] = " << aMin << " / " << aMax << " / " << aStore.valueStep );
156 ATH_MSG_VERBOSE(" - z [ min/max/step ] = " << zMin << " / " << zMax << " / " << zStore.valueStep );
157 ATH_MSG_VERBOSE(" - rho [ min/max/step ] = " << rMin << " / " << rMax << " / " << rStore.valueStep );
158
159 // set the initally empty - thickness store can be empty
160 if (tStore.valueStep > 0.)
161 tStore.valueBinMatrix = binMatrix;
162 else
163 ATH_MSG_VERBOSE("Thickness has been estimated to be constant - matrix is not prepared.");
164 xStore.valueBinMatrix = binMatrix;
165 lStore.valueBinMatrix = binMatrix;
166 aStore.valueBinMatrix = binMatrix;
167 zStore.valueBinMatrix = binMatrix;
168 rStore.valueBinMatrix = binMatrix;
169
170 ATH_MSG_VERBOSE( "Material stores prepared, now preparing composition matrix." );
171
172 // the compound material
173 std::vector< std::vector< Trk::MaterialComposition > > compositionMatrix( lBinUtility.max(1)+1, std::vector< Trk::MaterialComposition >( lBinUtility.max(0)+1, Trk::MaterialComposition()) );
174
175 ATH_MSG_VERBOSE( "Composition matrix created." );
176
177 // second loop : assign the bins & and copy the material composition
178 size_t obin = 0;
179 for (const auto & mo : materialMatrix){
180 size_t ibin =0;
181 for (const auto & mi : mo) {
182 if (mi){
183 const Trk::MaterialProperties& mp = (*mi);
184 if (tStore.valueStep > 0.) tStore.valueBinMatrix[obin][ibin] = static_cast<unsigned char>(std::lrint(mp.thickness()/tStore.valueStep)+1);
185 xStore.valueBinMatrix[obin][ibin] = static_cast<unsigned char>(std::lrint(mp.x0()/xStore.valueStep)+1);
186 lStore.valueBinMatrix[obin][ibin] = static_cast<unsigned char>(std::lrint(mp.l0()/lStore.valueStep)+1);
187 aStore.valueBinMatrix[obin][ibin] = static_cast<unsigned char>(std::lrint(mp.averageA()/aStore.valueStep)+1);
188 zStore.valueBinMatrix[obin][ibin] = static_cast<unsigned char>(std::lrint(mp.averageZ()/zStore.valueStep)+1);
189 rStore.valueBinMatrix[obin][ibin] = static_cast<unsigned char>(std::lrint(mp.averageRho()/rStore.valueStep)+1);
190 // set the material composition
191 if (mp.material().composition) {
192 compositionMatrix[obin][ibin] = Trk::MaterialComposition(*(mp.material().composition));
193 ATH_MSG_VERBOSE(" - composition is copied.");
194 }
195 }
196 ++ibin;
197 }
198 ++obin;
199 }
200 ATH_MSG_VERBOSE( "Returning the new compound material." );
201
202 // now create the compound material propertis
203 return new Trk::CompoundLayerMaterial(lBinUtility, tStore, xStore, lStore, aStore, zStore, rStore, compositionMatrix, m_fullCompoundCalculation);
204
205}
206
207
208
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define minMaxValue(currentMin, currentMax, test)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
A generic symmetric BinUtility, for fully symmetric binning in terms of binning grid and binning type...
Definition BinUtility.h:39
size_t max(size_t ba=0) const
First bin maximal value.
Definition BinUtility.h:212
CompoundLayerMaterialCreator(const std::string &, const std::string &, const IInterface *)
Constructor.
LayerMaterialProperties * createLayerMaterial(const LayerMaterialRecord &lmr) const
process the material properties
LayerMaterialProperties * createCompoundLayerMaterial(const MaterialPropertiesMatrix &lmm, const BinUtility &lmbu) const
private method that can be called by both create/convertLayerMaterial
LayerMaterialProperties * convertLayerMaterial(const LayerMaterialProperties &lmr) const
create layer material properties from layer material properties - simply clones
It extends the LayerMaterialProperties base class, and has a intrinsic accuracy of about 0....
This virtual base class encapsulates the logics to build pre/post/full update material for Layer stru...
virtual LayerMaterialProperties * clone() const =0
Pseudo-Constructor clone().
virtual const BinUtility * binUtility() const =0
Return the BinUtility.
virtual const MaterialProperties * material(size_t ib0, size_t ib1) const =0
Direct access via bins to the MaterialProperties.
Helper Class to record the material during the GeantinoNtupleMappingProcess.
const MaterialPropertiesMatrix & associatedLayerMaterial() const
return method for the LayerMaterial
const Trk::BinUtility * binUtility() const
return the BinUtility
Material with information about thickness of material.
float averageRho() const
Return the average density of the material.
float averageA() const
Return the average A of the material [gram/mole].
float averageZ() const
Returns the average Z of the material.
const Material & material() const
Return the stored Material.
float l0() const
Return the nuclear interaction length.
float x0() const
Return the radiation length.
float thickness() const
Return the thickness in mm.
MaterialComposition * composition
Definition Material.h:127
std::vector< ValueVector > ValueMatrix
std::vector< const MaterialProperties * > MaterialPropertiesVector
Useful typedefs.
std::vector< unsigned char > ValueVector
std::vector< std::vector< const MaterialProperties * > > MaterialPropertiesMatrix