ATLAS Offline Software
Loading...
Searching...
No Matches
CompressedLayerMaterialCreator.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// CompressedLayerMaterialCreator.cxx, (c) ATLAS Detector software
8
9// STL
10#include <sstream>
11// Trk include
16
17
18// constructor
19Trk::CompressedLayerMaterialCreator::CompressedLayerMaterialCreator(const std::string& t, const std::string& n, const IInterface* p)
20: AthAlgTool(t,n,p)
21{
22 declareInterface<Trk::ILayerMaterialCreator>(this);
23
24 // give the map a name
25 declareProperty("LayerMaterialName" , m_layerMaterialName);
26 declareProperty("LayerMaterialDirectory" , m_layerMaterialDirectory);
27}
28
30{
31 // get the material matrix
32 const Trk::MaterialPropertiesMatrix& materialProperties = lmr.associatedLayerMaterial();
33 // get the bin utility
34 const Trk::BinUtility* lBinUtility = lmr.binUtility();
35 if (lBinUtility){
36 ATH_MSG_VERBOSE("Converting the MaterialPropertiesMatrix into a CompressedLayerMaterial.");
37 return createCompressedLayerMaterial(materialProperties,*lBinUtility);
38 }
39 // we can not do anything without a bin utility
40 ATH_MSG_DEBUG("No BinUtility provided - return 0");
41 return nullptr;
42}
43
45{
46 // the return object
47 Trk::LayerMaterialProperties* bLayerMaterial = nullptr;
48 // get the binUtility of the LayerMaterialProperties
49 const Trk::BinUtility* bUtility = lmProperties.binUtility();
50 // we have a bin utility, get the matrix and fill it
51 if (bUtility){
52 // prepare the matrix
53 // nF x nS
54 size_t nBins0 = bUtility->max(0)+1;
55 size_t nBins1 = bUtility->max(1)+1;
56 // create the MaterialMatrix
57 Trk::MaterialPropertiesMatrix materialMatrix;
58 materialMatrix.reserve(nBins1);
59 // fill the matrix
60 for (size_t ibin1 = 0; ibin1 < nBins1; ++ibin1) {
61 // create the vector first
62 Trk::MaterialPropertiesVector materialVector;
63 materialVector.reserve(nBins0);
64 // loop over local 1 bins
65 for (size_t ibin0 = 0; ibin0 < nBins0; ++ibin0) {
66 // get the material from the properties and push them into the matrix (no cloning !)
67 const Trk::MaterialProperties* mProperties = lmProperties.material(ibin0,ibin1);
68 materialVector.push_back(mProperties);
69 }
70 // now pus the vector into the matrix
71 materialMatrix.push_back(materialVector);
72 }
73
74 // create the material
75 ATH_MSG_VERBOSE("Converting the MaterialPropertiesMatrix into a CompressedLayerMaterial.");
76 bLayerMaterial = createCompressedLayerMaterial(materialMatrix,*bUtility);
77
78 } else {
79 // must be homogenous material, can be transformed into a 0-bin material, would be silly though
80 ATH_MSG_DEBUG("No BinUtility provided - return a simple clone.");
81 bLayerMaterial = lmProperties.clone();
82 }
83 //
84 return bLayerMaterial;
85}
86
88{
89 // the vector to be created and reserve the maximum
90 Trk::MaterialPropertiesVector materialVector;
92 // nF x nS
93 size_t nFirstBins = lBinUtility.max(0)+1;
94 size_t nSecondBins = lBinUtility.max(1)+1;
95 // low, high boundaries
96 double x0min = 10e10;
97 double x0max = 0.;
98 double avZArhoMin = 10e10;
99 double avZArhoMax = 0.;
100 // create two maps, the compression map and the index map
101 std::vector< std::vector<unsigned short int> > materialBins;
102 // (1) FIRST LOOP, get boundaries
103 materialBins.reserve(nSecondBins);
104 for (size_t isec = 0; isec < nSecondBins; ++isec) {
105 std::vector<unsigned short int> firstbins(nFirstBins,0);
106 materialBins.push_back(firstbins);
107 // loop over the bins
108 for (size_t ifir = 0; ifir < nFirstBins; ++ifir) {
109 // get the current material properties
110 const Trk::MaterialProperties* matProp = materialProperties[isec][ifir];
111 if (matProp) {
112 double tinX0 = matProp->thicknessInX0();
113 double avZArho = matProp->zOverAtimesRho();
114 x0min = tinX0 < x0min ? tinX0 : x0min;
115 x0max = tinX0 > x0max ? tinX0 : x0max;
116 avZArhoMin = avZArho < avZArhoMin ? avZArho : avZArhoMin;
117 avZArhoMax = avZArho > avZArhoMax ? avZArho : avZArhoMax;
118 }
119 }
120 }
121 // min / max is defined, find step size
122 double stepX0 = (x0max-x0min)/m_compressedMaterialX0Bins;
123 double stepZArho = (avZArhoMax-avZArhoMin)/m_compressedMaterialZARhoBins;
124 // get the material histogram
125 std::vector< std::vector< std::vector< Trk::IndexedMaterial> > > materialHistogram;
126 materialHistogram.reserve(m_compressedMaterialZARhoBins);
127 // prepare the histogram
128 for (size_t izarho = 0; izarho < m_compressedMaterialZARhoBins; ++izarho) {
129 std::vector< std::vector < Trk::IndexedMaterial > > x0materialbins;
130 x0materialbins.reserve(m_compressedMaterialX0Bins);
131 for (size_t ix0 = 0; ix0 < m_compressedMaterialX0Bins; ++ix0) {
132 std::vector < Trk::IndexedMaterial > materialBin;
133 x0materialbins.push_back( materialBin );
134 }
135 materialHistogram.push_back(x0materialbins);
136 }
137 // fill the histogram
138 for (size_t isec = 0; isec < nSecondBins; ++isec) {
139 for (size_t ifir = 0; ifir < nFirstBins; ++ifir) {
140 // get the material properties
141 const Trk::MaterialProperties* matProp = dynamic_cast<const Trk::MaterialProperties*>(materialProperties[isec][ifir]);
142 if (matProp) {
143 // calculate the bins of the material histogram
144 double tinX0 = matProp->thicknessInX0();
145 double avZArho = matProp->zOverAtimesRho();
146 int x0bin = int( (tinX0-x0min)/stepX0 );
147 int zarhobin = int( (avZArho-avZArhoMin)/stepZArho );
148 // range protection
149 x0bin = ( (size_t)x0bin >= m_compressedMaterialX0Bins) ? m_compressedMaterialX0Bins-1 : x0bin;
150 x0bin = x0bin < 0 ? 0 : x0bin;
151 zarhobin = ( (size_t)zarhobin >= m_compressedMaterialZARhoBins) ? m_compressedMaterialZARhoBins-1 : zarhobin;
152 zarhobin = zarhobin < 0 ? 0 : zarhobin;
153 // create indexed material
154 Trk::IndexedMaterial idxMaterial{};
155 idxMaterial.materialProperties = matProp;
156 idxMaterial.firstBin = ifir;
157 idxMaterial.secondBin = isec;
158 // fill into the material histogram
159 materialHistogram[zarhobin][x0bin].push_back(idxMaterial);
160 }
161 }
162 }
163 // merge the bins and ready
164 materialVector.push_back(nullptr);
165 // prepare the histogram
166 for (size_t izarho = 0; izarho < m_compressedMaterialZARhoBins; ++izarho) {
167 for (size_t ix0 = 0; ix0 < m_compressedMaterialX0Bins; ++ix0) {
168 // get the indexed material properties
169 std::vector< Trk::IndexedMaterial > indexedMaterial = materialHistogram[izarho][ix0];
170 if (!indexedMaterial.empty()) {
171 double avT = 0.; // thickness: by default on one layer it should be the same !
172 double tinX0 = 0.;
173 double tinL0 = 0.;
174 double avA = 0.;
175 double avZ = 0.;
176 double avRho = 0.;
177 std::vector< Trk::IndexedMaterial >::iterator idmIter = indexedMaterial.begin();
178 std::vector< Trk::IndexedMaterial >::iterator idmIterEnd = indexedMaterial.end();
179 for ( ; idmIter != idmIterEnd; ++idmIter ) {
180 tinX0 += (*idmIter).materialProperties->thicknessInX0();
181 tinL0 += (*idmIter).materialProperties->thicknessInL0();
182 avA += (*idmIter).materialProperties->averageA();
183 avZ += (*idmIter).materialProperties->averageZ();
184 avRho += (*idmIter).materialProperties->averageRho();
185 }
186 double measure = 1./(indexedMaterial.size());
187 // average it
188 tinX0 *= measure;
189 tinL0 *= measure;
190 avA *= measure;
191 avZ *= measure;
192 avRho *= measure;
193 avT *= measure;
194 // compress to a model thickness [ rho affected ]
196 materialVector.push_back(new Trk::MaterialProperties(m_compressedMaterialThickness,
199 avA,
200 avZ,
201 avRho));
202 // now set the index
203 int matindex = int(materialVector.size()-1);
204 idmIter = indexedMaterial.begin();
205 for ( ; idmIter != idmIterEnd; ++idmIter )
206 materialBins[(*idmIter).secondBin][(*idmIter).firstBin] = matindex;
207 }
208 }
209 }
210
211 // change the 2bin matrix to a 1bin vector (better for persistency)
212 std::vector<unsigned short int> materialBinsVector;
213 materialBinsVector.reserve( (lBinUtility.max(0)+1)*(lBinUtility.max(1)+1) );
214 std::vector< std::vector<unsigned short int> >::iterator binVecIter = materialBins.begin();
215 std::vector< std::vector<unsigned short int> >::iterator binVecIterEnd = materialBins.end();
216 for ( ; binVecIter != binVecIterEnd; ++binVecIter) {
217 std::vector<unsigned short int>::iterator binIter = (*binVecIter).begin();
218 std::vector<unsigned short int>::iterator binIterEnd = (*binVecIter).end();
219 for ( ; binIter != binIterEnd; ++binIter )
220 materialBinsVector.push_back(*binIter);
221 }
222
224
225 // create the compressed material
226 return new Trk::CompressedLayerMaterial(lBinUtility,materialVector,materialBinsVector);
227}
228
229
230
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
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
Gaudi::Property< unsigned int > m_compressedMaterialZARhoBins
Gaudi::Property< unsigned int > m_compressedMaterialX0Bins
LayerMaterialProperties * convertLayerMaterial(const LayerMaterialProperties &lmr) const
create layer material properties from layer material properties - simply clones
CompressedLayerMaterialCreator(const std::string &, const std::string &, const IInterface *)
Constructor.
LayerMaterialProperties * createCompressedLayerMaterial(const MaterialPropertiesMatrix &lmm, const BinUtility &lmbu) const
private method that can be called by both create/convertLayerMaterial
LayerMaterialProperties * createLayerMaterial(const LayerMaterialRecord &lmr) const
process the material properties
It extends the LayerMaterialProperties base class.
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 thicknessInX0() const
Return the radiationlength fraction.
float zOverAtimesRho() const
Return the .
std::vector< const MaterialProperties * > MaterialPropertiesVector
Useful typedefs.
std::vector< std::vector< const MaterialProperties * > > MaterialPropertiesMatrix
const Trk::MaterialProperties * materialProperties