ATLAS Offline Software
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
23 Trk::CompoundLayerMaterialCreator::CompoundLayerMaterialCreator(const std::string& t, const std::string& n, const IInterface* p)
24 : AthAlgTool(t,n,p),
25  m_fullCompoundCalculation(false)
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, xMin = 10e10, lMin = 10e10, aMin = 10e10, zMin = 10e10, rMin = 10e10;
105  double tMax = 0., xMax = 0., lMax = 0., aMax = 0., zMax = 0., rMax = 0.;
106 
107  // first loop to get the min/max values
108  for (const auto & mo : materialMatrix)
109  for (const auto & mi : mo) {
110  if (mi){
111  const Trk::MaterialProperties& mp = (*mi);
112  // macro defined in GeometryStatics
113  minMaxValue(tMin, tMax, mp.thickness());
114  minMaxValue(xMin, xMax, mp.x0());
115  minMaxValue(lMin, lMax, mp.l0());
116  minMaxValue(aMin, aMax, mp.averageA());
117  minMaxValue(zMin, zMax, mp.averageZ());
118  minMaxValue(rMin, rMax, mp.averageRho());
119  }
120  }
121 
122  ATH_MSG_DEBUG( "Preparing the store: min/max values for t, x0, l0, a, z, rho estimated." );
123 
124 
125  // the bin matrices in the store
126  Trk::ValueMatrix binMatrix( lBinUtility.max(1)+1, Trk::ValueVector(lBinUtility.max(0)+1, static_cast<unsigned char>(0) ) );
127  // 255 bins, the 0 bin indicates empy
128  Trk::ValueStore tStore, xStore, lStore, aStore, zStore, rStore;
129  // set the store min, max
130  tStore.valueMin = tMin;
131  xStore.valueMin = xMin;
132  lStore.valueMin = lMin;
133  aStore.valueMin = aMin;
134  zStore.valueMin = zMin;
135  rStore.valueMin = rMin;
136  tStore.valueStep = fabs(tMin-tMax)<10e-8 ? 0. : (tMax-tMin)/double(static_cast<int>(UCHAR_MAX)-1);
137  xStore.valueStep = (xMax-xMin)/double(static_cast<int>(UCHAR_MAX)-1);
138  lStore.valueStep = (lMax-lMin)/double(static_cast<int>(UCHAR_MAX)-1);
139  aStore.valueStep = (aMax-aMin)/double(static_cast<int>(UCHAR_MAX)-1);
140  zStore.valueStep = (zMax-zMin)/double(static_cast<int>(UCHAR_MAX)-1);
141  rStore.valueStep = (rMax-rMin)/double(static_cast<int>(UCHAR_MAX)-1);
142 
143  ATH_MSG_VERBOSE(" - t [ min/max/step ] = " << tMin << " / " << tMax << " / " << tStore.valueStep );
144  ATH_MSG_VERBOSE(" - x0 [ min/max/step ] = " << xMin << " / " << xMax << " / " << xStore.valueStep );
145  ATH_MSG_VERBOSE(" - l0 [ min/max/step ] = " << lMin << " / " << lMax << " / " << lStore.valueStep );
146  ATH_MSG_VERBOSE(" - a [ min/max/step ] = " << aMin << " / " << aMax << " / " << aStore.valueStep );
147  ATH_MSG_VERBOSE(" - z [ min/max/step ] = " << zMin << " / " << zMax << " / " << zStore.valueStep );
148  ATH_MSG_VERBOSE(" - rho [ min/max/step ] = " << rMin << " / " << rMax << " / " << rStore.valueStep );
149 
150  // set the initally empty - thickness store can be empty
151  if (tStore.valueStep > 0.)
152  tStore.valueBinMatrix = binMatrix;
153  else
154  ATH_MSG_VERBOSE("Thickness has been estimated to be constant - matrix is not prepared.");
155  xStore.valueBinMatrix = binMatrix;
156  lStore.valueBinMatrix = binMatrix;
157  aStore.valueBinMatrix = binMatrix;
158  zStore.valueBinMatrix = binMatrix;
159  rStore.valueBinMatrix = binMatrix;
160 
161  ATH_MSG_VERBOSE( "Material stores prepared, now preparing composition matrix." );
162 
163  // the compound material
164  std::vector< std::vector< Trk::MaterialComposition > > compositionMatrix( lBinUtility.max(1)+1, std::vector< Trk::MaterialComposition >( lBinUtility.max(0)+1, Trk::MaterialComposition()) );
165 
166  ATH_MSG_VERBOSE( "Composition matrix created." );
167 
168  // second loop : assign the bins & and copy the material composition
169  size_t obin = 0;
170  for (const auto & mo : materialMatrix){
171  size_t ibin =0;
172  for (const auto & mi : mo) {
173  if (mi){
174  const Trk::MaterialProperties& mp = (*mi);
175  if (tStore.valueStep > 0.) tStore.valueBinMatrix[obin][ibin] = static_cast<unsigned char>(std::lrint(mp.thickness()/tStore.valueStep)+1);
176  xStore.valueBinMatrix[obin][ibin] = static_cast<unsigned char>(std::lrint(mp.x0()/xStore.valueStep)+1);
177  lStore.valueBinMatrix[obin][ibin] = static_cast<unsigned char>(std::lrint(mp.l0()/lStore.valueStep)+1);
178  aStore.valueBinMatrix[obin][ibin] = static_cast<unsigned char>(std::lrint(mp.averageA()/aStore.valueStep)+1);
179  zStore.valueBinMatrix[obin][ibin] = static_cast<unsigned char>(std::lrint(mp.averageZ()/zStore.valueStep)+1);
180  rStore.valueBinMatrix[obin][ibin] = static_cast<unsigned char>(std::lrint(mp.averageRho()/rStore.valueStep)+1);
181  // set the material composition
182  if (mp.material().composition) {
183  compositionMatrix[obin][ibin] = Trk::MaterialComposition(*(mp.material().composition));
184  ATH_MSG_VERBOSE(" - composition is copied.");
185  }
186  }
187  ++ibin;
188  }
189  ++obin;
190  }
191  ATH_MSG_VERBOSE( "Returning the new compound material." );
192 
193  // now create the compound material propertis
194  return new Trk::CompoundLayerMaterial(lBinUtility, tStore, xStore, lStore, aStore, zStore, rStore, compositionMatrix, m_fullCompoundCalculation);
195 
196 }
197 
198 
199 
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
Trk::MaterialProperties::averageA
float averageA() const
Return the average A of the material [gram/mole].
Trk::ValueStore::valueStep
float valueStep
Definition: CompoundLayerMaterial.h:34
Trk::BinUtility::max
size_t max(size_t ba=0) const
First bin maximal value.
Definition: BinUtility.h:215
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
minMaxValue
#define minMaxValue(currentMin, currentMax, test)
Definition: CompoundLayerMaterialCreator.h:23
Trk::ILayerMaterialCreator::m_layerMaterialDirectory
std::string m_layerMaterialDirectory
Definition: ILayerMaterialCreator.h:56
BinUtility.h
Trk::CompoundLayerMaterialCreator::createCompoundLayerMaterial
LayerMaterialProperties * createCompoundLayerMaterial(const MaterialPropertiesMatrix &lmm, const BinUtility &lmbu) const
private method that can be called by both create/convertLayerMaterial
Definition: CompoundLayerMaterialCreator.cxx:99
Trk::MaterialProperties::averageRho
float averageRho() const
Return the average density of the material.
Trk::CompoundLayerMaterial
Definition: CompoundLayerMaterial.h:60
Trk::MaterialProperties::x0
float x0() const
Return the radiation length.
Trk::LayerMaterialProperties::material
virtual const MaterialProperties * material(size_t ib0, size_t ib1) const =0
Direct access via bins to the MaterialProperties.
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trk::MaterialProperties::material
const Material & material() const
Return the stored Material.
Trk::MaterialComposition
Definition: Material.h:60
Trk::ILayerMaterialCreator::m_layerMaterialName
std::string m_layerMaterialName
Definition: ILayerMaterialCreator.h:55
Trk::MaterialPropertiesVector
std::vector< const MaterialProperties * > MaterialPropertiesVector
Useful typedefs.
Definition: MaterialProperties.h:133
CompoundLayerMaterial.h
Trk::MaterialProperties::thickness
float thickness() const
Return the thickness in mm.
GeometryStatics.h
Trk::ValueStore
Definition: CompoundLayerMaterial.h:32
Trk::ValueStore::valueBinMatrix
ValueMatrix valueBinMatrix
Definition: CompoundLayerMaterial.h:35
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
Trk::LayerMaterialRecord::associatedLayerMaterial
const MaterialPropertiesMatrix & associatedLayerMaterial() const
return method for the LayerMaterial
Definition: LayerMaterialRecord.h:129
Trk::LayerMaterialRecord::binUtility
const Trk::BinUtility * binUtility() const
return the BinUtility
Definition: LayerMaterialRecord.h:138
LayerMaterialRecord.h
beamspotman.n
n
Definition: beamspotman.py:731
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Trk::LayerMaterialProperties
Definition: LayerMaterialProperties.h:62
Trk::CompoundLayerMaterialCreator::CompoundLayerMaterialCreator
CompoundLayerMaterialCreator(const std::string &, const std::string &, const IInterface *)
Constructor.
Definition: CompoundLayerMaterialCreator.cxx:23
Trk::CompoundLayerMaterialCreator::~CompoundLayerMaterialCreator
~CompoundLayerMaterialCreator()
Destructor.
Trk::LayerMaterialProperties::binUtility
virtual const BinUtility * binUtility() const =0
Return the BinUtility.
Trk::BinUtility
Definition: BinUtility.h:39
Trk::LayerMaterialRecord
Definition: LayerMaterialRecord.h:42
Trk::CompoundLayerMaterialCreator::convertLayerMaterial
LayerMaterialProperties * convertLayerMaterial(const LayerMaterialProperties &lmr) const
create layer material properties from layer material properties - simply clones
Definition: CompoundLayerMaterialCreator.cxx:55
Trk::MaterialPropertiesMatrix
std::vector< std::vector< const MaterialProperties * > > MaterialPropertiesMatrix
Definition: ILayerMaterialAnalyser.h:23
Trk::MaterialProperties
Definition: MaterialProperties.h:40
Trk::ValueMatrix
std::vector< ValueVector > ValueMatrix
Definition: CompoundLayerMaterial.h:30
Trk::CompoundLayerMaterialCreator::m_fullCompoundCalculation
bool m_fullCompoundCalculation
Definition: CompoundLayerMaterialCreator.h:61
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::MaterialProperties::averageZ
float averageZ() const
Returns the average Z of the material.
Trk::LayerMaterialProperties::clone
virtual LayerMaterialProperties * clone() const =0
Pseudo-Constructor clone()
Trk::Material::composition
MaterialComposition * composition
Definition: Material.h:126
Trk::ValueVector
std::vector< unsigned char > ValueVector
Definition: CompoundLayerMaterial.h:29
Trk::ValueStore::valueMin
float valueMin
Definition: CompoundLayerMaterial.h:33
Trk::CompoundLayerMaterialCreator::createLayerMaterial
LayerMaterialProperties * createLayerMaterial(const LayerMaterialRecord &lmr) const
process the material properties
Definition: CompoundLayerMaterialCreator.cxx:39
CompoundLayerMaterialCreator.h
AthAlgTool
Definition: AthAlgTool.h:26
Trk::MaterialProperties::l0
float l0() const
Return the nuclear interaction length.
LayerMaterialProperties.h