ATLAS Offline Software
Loading...
Searching...
No Matches
CompoundLayerMaterialCreator.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 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),
26{
27 declareInterface<Trk::ILayerMaterialCreator>(this);
28 // give the map a name
29 declareProperty("LayerMaterialName" , m_layerMaterialName);
30 declareProperty("LayerMaterialDirectory" , m_layerMaterialDirectory);
31 declareProperty("FullCompoundCalculation" , m_fullCompoundCalculation);
32}
33
34// destructor
36= default;
37
38
40{
41 // get the material matrix
42 const Trk::MaterialPropertiesMatrix& materialMatrix = lmr.associatedLayerMaterial();
43 // get the bin untility
44 const Trk::BinUtility* binUtility = lmr.binUtility();
45 // if there's no bin utility - bail out
46 if (!binUtility){
47 ATH_MSG_WARNING( "No BinUtility given - Bailing out." );
48 return nullptr;
49 } else
50 ATH_MSG_DEBUG( "BinUtility provided, creating binned array in dimensions " << binUtility->max(0)+1 << " x " << binUtility->max(1)+1 );
51 // return the created compound material
52 return createCompoundLayerMaterial(materialMatrix,*binUtility);
53}
54
56{
57
58 // the return object
59 Trk::LayerMaterialProperties* bLayerMaterial = nullptr;
60 // get the binUtility of the LayerMaterialProperties
61 const Trk::BinUtility* bUtility = lmProperties.binUtility();
62 // we have a bin utility, get the matrix and fill it
63 if (bUtility){
64 // prepare the matrix
65 // nF x nS
66 size_t nBins0 = bUtility->max(0)+1;
67 size_t nBins1 = bUtility->max(1)+1;
68 // create the MaterialMatrix
69 Trk::MaterialPropertiesMatrix materialMatrix;
70 materialMatrix.reserve(nBins1);
71 // fill the matrix
72 for (size_t ibin1 = 0; ibin1 < nBins1; ++ibin1) {
73 // create the vector first
74 Trk::MaterialPropertiesVector materialVector;
75 materialVector.reserve(nBins0);
76 // loop over local 1 bins
77 for (size_t ibin0 = 0; ibin0 < nBins0; ++ibin0) {
78 // get the material from the properties and push them into the matrix (no cloning !)
79 const Trk::MaterialProperties* mProperties = lmProperties.material(ibin0,ibin1);
80 materialVector.push_back(mProperties);
81 }
82 // now pus the vector into the matrix
83 materialMatrix.push_back(materialVector);
84 }
85
86 // create the material
87 ATH_MSG_VERBOSE("Converting the MaterialPropertiesMatrix into a CompressedLayerMaterial.");
88 bLayerMaterial = createCompoundLayerMaterial(materialMatrix,*bUtility);
89
90 } else {
91 // must be homogenous material, can be transformed into a 0-bin material, would be silly though
92 ATH_MSG_DEBUG("No BinUtility provided - return a simple clone.");
93 bLayerMaterial = lmProperties.clone();
94 }
95 //
96 return bLayerMaterial;
97}
98
100{
101
102
103 // analyse the material bins
104 double tMin = 10e10;
105 double xMin = 10e10;
106 double lMin = 10e10;
107 double aMin = 10e10;
108 double zMin = 10e10;
109 double rMin = 10e10;
110 double tMax = 0.;
111 double xMax = 0.;
112 double lMax = 0.;
113 double aMax = 0.;
114 double zMax = 0.;
115 double rMax = 0.;
116
117 // first loop to get the min/max values
118 for (const auto & mo : materialMatrix)
119 for (const auto & mi : mo) {
120 if (mi){
121 const Trk::MaterialProperties& mp = (*mi);
122 // macro defined in GeometryStatics
123 minMaxValue(tMin, tMax, mp.thickness());
124 minMaxValue(xMin, xMax, mp.x0());
125 minMaxValue(lMin, lMax, mp.l0());
126 minMaxValue(aMin, aMax, mp.averageA());
127 minMaxValue(zMin, zMax, mp.averageZ());
128 minMaxValue(rMin, rMax, mp.averageRho());
129 }
130 }
131
132 ATH_MSG_DEBUG( "Preparing the store: min/max values for t, x0, l0, a, z, rho estimated." );
133
134
135 // the bin matrices in the store
136 Trk::ValueMatrix binMatrix( lBinUtility.max(1)+1, Trk::ValueVector(lBinUtility.max(0)+1, static_cast<unsigned char>(0) ) );
137 // 255 bins, the 0 bin indicates empy
138 Trk::ValueStore tStore;
139 Trk::ValueStore xStore;
140 Trk::ValueStore lStore;
141 Trk::ValueStore aStore;
142 Trk::ValueStore zStore;
143 Trk::ValueStore rStore;
144 // set the store min, max
145 tStore.valueMin = tMin;
146 xStore.valueMin = xMin;
147 lStore.valueMin = lMin;
148 aStore.valueMin = aMin;
149 zStore.valueMin = zMin;
150 rStore.valueMin = rMin;
151 tStore.valueStep = fabs(tMin-tMax)<10e-8 ? 0. : (tMax-tMin)/double(static_cast<int>(UCHAR_MAX)-1);
152 xStore.valueStep = (xMax-xMin)/double(static_cast<int>(UCHAR_MAX)-1);
153 lStore.valueStep = (lMax-lMin)/double(static_cast<int>(UCHAR_MAX)-1);
154 aStore.valueStep = (aMax-aMin)/double(static_cast<int>(UCHAR_MAX)-1);
155 zStore.valueStep = (zMax-zMin)/double(static_cast<int>(UCHAR_MAX)-1);
156 rStore.valueStep = (rMax-rMin)/double(static_cast<int>(UCHAR_MAX)-1);
157
158 ATH_MSG_VERBOSE(" - t [ min/max/step ] = " << tMin << " / " << tMax << " / " << tStore.valueStep );
159 ATH_MSG_VERBOSE(" - x0 [ min/max/step ] = " << xMin << " / " << xMax << " / " << xStore.valueStep );
160 ATH_MSG_VERBOSE(" - l0 [ min/max/step ] = " << lMin << " / " << lMax << " / " << lStore.valueStep );
161 ATH_MSG_VERBOSE(" - a [ min/max/step ] = " << aMin << " / " << aMax << " / " << aStore.valueStep );
162 ATH_MSG_VERBOSE(" - z [ min/max/step ] = " << zMin << " / " << zMax << " / " << zStore.valueStep );
163 ATH_MSG_VERBOSE(" - rho [ min/max/step ] = " << rMin << " / " << rMax << " / " << rStore.valueStep );
164
165 // set the initally empty - thickness store can be empty
166 if (tStore.valueStep > 0.)
167 tStore.valueBinMatrix = binMatrix;
168 else
169 ATH_MSG_VERBOSE("Thickness has been estimated to be constant - matrix is not prepared.");
170 xStore.valueBinMatrix = binMatrix;
171 lStore.valueBinMatrix = binMatrix;
172 aStore.valueBinMatrix = binMatrix;
173 zStore.valueBinMatrix = binMatrix;
174 rStore.valueBinMatrix = binMatrix;
175
176 ATH_MSG_VERBOSE( "Material stores prepared, now preparing composition matrix." );
177
178 // the compound material
179 std::vector< std::vector< Trk::MaterialComposition > > compositionMatrix( lBinUtility.max(1)+1, std::vector< Trk::MaterialComposition >( lBinUtility.max(0)+1, Trk::MaterialComposition()) );
180
181 ATH_MSG_VERBOSE( "Composition matrix created." );
182
183 // second loop : assign the bins & and copy the material composition
184 size_t obin = 0;
185 for (const auto & mo : materialMatrix){
186 size_t ibin =0;
187 for (const auto & mi : mo) {
188 if (mi){
189 const Trk::MaterialProperties& mp = (*mi);
190 if (tStore.valueStep > 0.) tStore.valueBinMatrix[obin][ibin] = static_cast<unsigned char>(std::lrint(mp.thickness()/tStore.valueStep)+1);
191 xStore.valueBinMatrix[obin][ibin] = static_cast<unsigned char>(std::lrint(mp.x0()/xStore.valueStep)+1);
192 lStore.valueBinMatrix[obin][ibin] = static_cast<unsigned char>(std::lrint(mp.l0()/lStore.valueStep)+1);
193 aStore.valueBinMatrix[obin][ibin] = static_cast<unsigned char>(std::lrint(mp.averageA()/aStore.valueStep)+1);
194 zStore.valueBinMatrix[obin][ibin] = static_cast<unsigned char>(std::lrint(mp.averageZ()/zStore.valueStep)+1);
195 rStore.valueBinMatrix[obin][ibin] = static_cast<unsigned char>(std::lrint(mp.averageRho()/rStore.valueStep)+1);
196 // set the material composition
197 if (mp.material().composition) {
198 compositionMatrix[obin][ibin] = Trk::MaterialComposition(*(mp.material().composition));
199 ATH_MSG_VERBOSE(" - composition is copied.");
200 }
201 }
202 ++ibin;
203 }
204 ++obin;
205 }
206 ATH_MSG_VERBOSE( "Returning the new compound material." );
207
208 // now create the compound material propertis
209 return new Trk::CompoundLayerMaterial(lBinUtility, tStore, xStore, lStore, aStore, zStore, rStore, compositionMatrix, m_fullCompoundCalculation);
210
211}
212
213
214
#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