ATLAS Offline Software
CompressedLayerMaterialCreator.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 // CompressedLayerMaterialCreator.cxx, (c) ATLAS Detector software
8 
9 // STL
10 #include <sstream>
11 // Trk include
16 
17 
18 // constructor
19 Trk::CompressedLayerMaterialCreator::CompressedLayerMaterialCreator(const std::string& t, const std::string& n, const IInterface* p)
20 : AthAlgTool(t,n,p),
21  m_compressedMaterialThickness(1.),
22  m_compressedMaterialX0Bins(256),
23  m_compressedMaterialZARhoBins(256)
24 {
25  declareInterface<Trk::ILayerMaterialCreator>(this);
26 
27  // give the map a name
28  declareProperty("LayerMaterialName" , m_layerMaterialName);
29  declareProperty("LayerMaterialDirectory" , m_layerMaterialDirectory);
30  // setup for compressed layer creation
31  declareProperty("MaterialThickness" , m_compressedMaterialThickness);
32  declareProperty("MaterialBinsX0" , m_compressedMaterialX0Bins);
33  declareProperty("MaterialBinsZARho" , m_compressedMaterialZARhoBins);
34 
35 }
36 
37 // destructor
39 = default;
40 
42 {
43  // get the material matrix
44  const Trk::MaterialPropertiesMatrix& materialProperties = lmr.associatedLayerMaterial();
45  // get the bin utility
46  const Trk::BinUtility* lBinUtility = lmr.binUtility();
47  if (lBinUtility){
48  ATH_MSG_VERBOSE("Converting the MaterialPropertiesMatrix into a CompressedLayerMaterial.");
49  return createCompressedLayerMaterial(materialProperties,*lBinUtility);
50  }
51  // we can not do anything without a bin utility
52  ATH_MSG_DEBUG("No BinUtility provided - return 0");
53  return nullptr;
54 }
55 
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 = createCompressedLayerMaterial(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  // the vector to be created and reserve the maximum
102  Trk::MaterialPropertiesVector materialVector;
103  materialVector.reserve(m_compressedMaterialZARhoBins*m_compressedMaterialX0Bins);
104  // nF x nS
105  size_t nFirstBins = lBinUtility.max(0)+1;
106  size_t nSecondBins = lBinUtility.max(1)+1;
107  // low, high boundaries
108  double x0min = 10e10;
109  double x0max = 0.;
110  double avZArhoMin = 10e10;
111  double avZArhoMax = 0.;
112  // create two maps, the compression map and the index map
113  std::vector< std::vector<unsigned short int> > materialBins;
114  // (1) FIRST LOOP, get boundaries
115  materialBins.reserve(nSecondBins);
116  for (size_t isec = 0; isec < nSecondBins; ++isec) {
117  std::vector<unsigned short int> firstbins(nFirstBins,0);
118  materialBins.push_back(firstbins);
119  // loop over the bins
120  for (size_t ifir = 0; ifir < nFirstBins; ++ifir) {
121  // get the current material properties
122  const Trk::MaterialProperties* matProp = materialProperties[isec][ifir];
123  if (matProp) {
124  double tinX0 = matProp->thicknessInX0();
125  double avZArho = matProp->zOverAtimesRho();
126  x0min = tinX0 < x0min ? tinX0 : x0min;
127  x0max = tinX0 > x0max ? tinX0 : x0max;
128  avZArhoMin = avZArho < avZArhoMin ? avZArho : avZArhoMin;
129  avZArhoMax = avZArho > avZArhoMax ? avZArho : avZArhoMax;
130  }
131  }
132  }
133  // min / max is defined, find step size
134  double stepX0 = (x0max-x0min)/m_compressedMaterialX0Bins;
135  double stepZArho = (avZArhoMax-avZArhoMin)/m_compressedMaterialZARhoBins;
136  // get the material histogram
137  std::vector< std::vector< std::vector< Trk::IndexedMaterial> > > materialHistogram;
138  materialHistogram.reserve(m_compressedMaterialZARhoBins);
139  // prepare the histogram
140  for (size_t izarho = 0; izarho < m_compressedMaterialZARhoBins; ++izarho) {
141  std::vector< std::vector < Trk::IndexedMaterial > > x0materialbins;
142  x0materialbins.reserve(m_compressedMaterialX0Bins);
143  for (size_t ix0 = 0; ix0 < m_compressedMaterialX0Bins; ++ix0) {
144  std::vector < Trk::IndexedMaterial > materialBin;
145  x0materialbins.push_back( materialBin );
146  }
147  materialHistogram.push_back(x0materialbins);
148  }
149  // fill the histogram
150  for (size_t isec = 0; isec < nSecondBins; ++isec) {
151  for (size_t ifir = 0; ifir < nFirstBins; ++ifir) {
152  // get the material properties
153  const Trk::MaterialProperties* matProp = dynamic_cast<const Trk::MaterialProperties*>(materialProperties[isec][ifir]);
154  if (matProp) {
155  // calculate the bins of the material histogram
156  double tinX0 = matProp->thicknessInX0();
157  double avZArho = matProp->zOverAtimesRho();
158  int x0bin = int( (tinX0-x0min)/stepX0 );
159  int zarhobin = int( (avZArho-avZArhoMin)/stepZArho );
160  // range protection
161  x0bin = ( (size_t)x0bin >= m_compressedMaterialX0Bins) ? m_compressedMaterialX0Bins-1 : x0bin;
162  x0bin = x0bin < 0 ? 0 : x0bin;
163  zarhobin = ( (size_t)zarhobin >= m_compressedMaterialZARhoBins) ? m_compressedMaterialZARhoBins-1 : zarhobin;
164  zarhobin = zarhobin < 0 ? 0 : zarhobin;
165  // create indexed material
166  Trk::IndexedMaterial idxMaterial{};
167  idxMaterial.materialProperties = matProp;
168  idxMaterial.firstBin = ifir;
169  idxMaterial.secondBin = isec;
170  // fill into the material histogram
171  materialHistogram[zarhobin][x0bin].push_back(idxMaterial);
172  }
173  }
174  }
175  // merge the bins and ready
176  materialVector.push_back(nullptr);
177  // prepare the histogram
178  for (size_t izarho = 0; izarho < m_compressedMaterialZARhoBins; ++izarho) {
179  for (size_t ix0 = 0; ix0 < m_compressedMaterialX0Bins; ++ix0) {
180  // get the indexed material properties
181  std::vector< Trk::IndexedMaterial > indexedMaterial = materialHistogram[izarho][ix0];
182  if (!indexedMaterial.empty()) {
183  double avT = 0.; // thickness: by default on one layer it should be the same !
184  double tinX0 = 0.;
185  double tinL0 = 0.;
186  double avA = 0.;
187  double avZ = 0.;
188  double avRho = 0.;
189  std::vector< Trk::IndexedMaterial >::iterator idmIter = indexedMaterial.begin();
190  std::vector< Trk::IndexedMaterial >::iterator idmIterEnd = indexedMaterial.end();
191  for ( ; idmIter != idmIterEnd; ++idmIter ) {
192  tinX0 += (*idmIter).materialProperties->thicknessInX0();
193  tinL0 += (*idmIter).materialProperties->thicknessInL0();
194  avA += (*idmIter).materialProperties->averageA();
195  avZ += (*idmIter).materialProperties->averageZ();
196  avRho += (*idmIter).materialProperties->averageRho();
197  }
198  double measure = 1./(indexedMaterial.size());
199  // average it
200  tinX0 *= measure;
201  tinL0 *= measure;
202  avA *= measure;
203  avZ *= measure;
204  avRho *= measure;
205  avT *= measure;
206  // compress to a model thickness [ rho affected ]
207  avRho *= avT/m_compressedMaterialThickness;
208  materialVector.push_back(new Trk::MaterialProperties(m_compressedMaterialThickness,
209  m_compressedMaterialThickness/tinX0,
210  m_compressedMaterialThickness/tinL0,
211  avA,
212  avZ,
213  avRho));
214  // now set the index
215  int matindex = int(materialVector.size()-1);
216  idmIter = indexedMaterial.begin();
217  for ( ; idmIter != idmIterEnd; ++idmIter )
218  materialBins[(*idmIter).secondBin][(*idmIter).firstBin] = matindex;
219  }
220  }
221  }
222 
223  // change the 2bin matrix to a 1bin vector (better for persistency)
224  std::vector<unsigned short int> materialBinsVector;
225  materialBinsVector.reserve( (lBinUtility.max(0)+1)*(lBinUtility.max(1)+1) );
226  std::vector< std::vector<unsigned short int> >::iterator binVecIter = materialBins.begin();
227  std::vector< std::vector<unsigned short int> >::iterator binVecIterEnd = materialBins.end();
228  for ( ; binVecIter != binVecIterEnd; ++binVecIter) {
229  std::vector<unsigned short int>::iterator binIter = (*binVecIter).begin();
230  std::vector<unsigned short int>::iterator binIterEnd = (*binVecIter).end();
231  for ( ; binIter != binIterEnd; ++binIter )
232  materialBinsVector.push_back(*binIter);
233  }
234 
236 
237  // create the compressed material
238  return new Trk::CompressedLayerMaterial(lBinUtility,materialVector,materialBinsVector);
239 }
240 
241 
242 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
Trk::CompressedLayerMaterialCreator::createLayerMaterial
LayerMaterialProperties * createLayerMaterial(const LayerMaterialRecord &lmr) const
process the material properties
Definition: CompressedLayerMaterialCreator.cxx:41
Trk::CompressedLayerMaterialCreator::convertLayerMaterial
LayerMaterialProperties * convertLayerMaterial(const LayerMaterialProperties &lmr) const
create layer material properties from layer material properties - simply clones
Definition: CompressedLayerMaterialCreator.cxx:56
Trk::CompressedLayerMaterialCreator::m_compressedMaterialThickness
double m_compressedMaterialThickness
Definition: CompressedLayerMaterialCreator.h:62
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
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
Trk::IndexedMaterial
Definition: CompressedLayerMaterialCreator.h:26
Trk::ILayerMaterialCreator::m_layerMaterialDirectory
std::string m_layerMaterialDirectory
Definition: ILayerMaterialCreator.h:56
CompressedLayerMaterialCreator.h
Trk::MaterialProperties::thicknessInX0
float thicknessInX0() const
Return the radiationlength fraction.
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::ILayerMaterialCreator::m_layerMaterialName
std::string m_layerMaterialName
Definition: ILayerMaterialCreator.h:55
Trk::MaterialPropertiesVector
std::vector< const MaterialProperties * > MaterialPropertiesVector
Useful typedefs.
Definition: MaterialProperties.h:133
Trk::CompressedLayerMaterial
Definition: CompressedLayerMaterial.h:31
Trk::CompressedLayerMaterialCreator::CompressedLayerMaterialCreator
CompressedLayerMaterialCreator(const std::string &, const std::string &, const IInterface *)
Constructor.
Definition: CompressedLayerMaterialCreator.cxx:19
Trk::CompressedLayerMaterialCreator::m_compressedMaterialZARhoBins
unsigned int m_compressedMaterialZARhoBins
Definition: CompressedLayerMaterialCreator.h:64
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::IndexedMaterial::materialProperties
const Trk::MaterialProperties * materialProperties
Definition: CompressedLayerMaterialCreator.h:29
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::MaterialPropertiesMatrix
std::vector< std::vector< const MaterialProperties * > > MaterialPropertiesMatrix
Definition: ILayerMaterialAnalyser.h:23
Trk::MaterialProperties
Definition: MaterialProperties.h:40
Trk::CompressedLayerMaterialCreator::m_compressedMaterialX0Bins
unsigned int m_compressedMaterialX0Bins
Definition: CompressedLayerMaterialCreator.h:63
Trk::LayerMaterialProperties::clone
virtual LayerMaterialProperties * clone() const =0
Pseudo-Constructor clone()
Trk::CompressedLayerMaterialCreator::~CompressedLayerMaterialCreator
~CompressedLayerMaterialCreator()
Destructor.
Trk::MaterialProperties::zOverAtimesRho
float zOverAtimesRho() const
Return the .
AthAlgTool
Definition: AthAlgTool.h:26
Trk::CompressedLayerMaterialCreator::createCompressedLayerMaterial
LayerMaterialProperties * createCompressedLayerMaterial(const MaterialPropertiesMatrix &lmm, const BinUtility &lmbu) const
private method that can be called by both create/convertLayerMaterial
Definition: CompressedLayerMaterialCreator.cxx:99
LayerMaterialProperties.h
CompressedLayerMaterial.h