ATLAS Offline Software
TrkDetDescrTPCnvTest.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // TrkDetDescrTPCnvTest.cxx, (c) ATLAS Detector software
8 
9 // Trk includes
11 // general Trk & TrkGeometry includes
22 #include "TrkGeometry/Material.h"
23 #include <climits>
24 
25 Trk::TrkDetDescrTPCnvTest::TrkDetDescrTPCnvTest(const std::string& name, ISvcLocator* pSvcLocator) :
26  Trk::TrkDetDescrUnitTestBase(name, pSvcLocator),
27  m_writeMode(true),
28  m_materialStepCollectionName("RandomMaterialSteps"),
29  m_layerMaterialCollectionName("RandomLayerMaterialMap"),
30  m_elementTableName("RandomElementTable")
31 {
32 
33  declareProperty("WriteMode", m_writeMode);
34  // collection names
35  declareProperty("MaterialStepCollection", m_materialStepCollectionName);
37  declareProperty("ElementTable", m_elementTableName);
38 }
39 
41 {
42  ATH_MSG_VERBOSE("Running the TrkDetDescrTPCnvTest Test");
43 
44  // ----------------- WRITE MODE -----------------
45  if (m_writeMode){
46 
47  ATH_MSG_VERBOSE("Test is running in write mode - writing out a file.");
48 
49  // The Material STEP collection
51  for (size_t it = 0; it < TrkDetDescrUnitTestBase::m_numTests; ++it ){
61  }
62 
63 
64  ATH_MSG_VERBOSE("Recording MaterialStepCollection '" << m_materialStepCollectionName << "'.");
65 
66  if (!m_materialStepCollectionName.empty() && (evtStore()->record(msCollection, m_materialStepCollectionName)).isFailure() ) {
67  ATH_MSG_WARNING("Could not record the material collection " << m_materialStepCollectionName);
68  return StatusCode::FAILURE;
69  }
70 
71  ATH_MSG_VERBOSE("Recording LayerMaterialMap '" << m_layerMaterialCollectionName << "'.");
72 
73  // The LayerMaterialMap
74  std::unique_ptr<Trk::LayerMaterialMap> lmMap(new Trk::LayerMaterialMap);
75 
76  // (e) element Table
77  Trk::ElementTable* eTable = new Trk::ElementTable();
81  1,
82  TrkDetDescrUnitTestBase::m_flatDist->shoot()),"TestMaterial1");
86  2,
87  TrkDetDescrUnitTestBase::m_flatDist->shoot()),"TestMaterial2");
91  3,
92  TrkDetDescrUnitTestBase::m_flatDist->shoot()),"TestMaterial3");
93 
94  if ( !m_elementTableName.empty() && (evtStore()->record(eTable, m_elementTableName)).isFailure() ) {
95  ATH_MSG_WARNING("Could not record the element table " << m_elementTableName);
96  return StatusCode::FAILURE;
97  }
98 
99  // (a) homogeneous material
107  (*lmMap)[Trk::LayerIndex(1)] = hml;
108 
109  // (b) binned material
110  Trk::BinUtility rPhiZUtility(200,-M_PI, M_PI, Trk::closed, Trk::binRPhi);
111  rPhiZUtility += Trk::BinUtility(300,-250.,250., Trk::open, Trk::binZ);
112  std::vector< std::vector< const Trk::MaterialProperties* > > materialMatrix(300, std::vector<const Trk::MaterialProperties*>(200, (Trk::MaterialProperties*)nullptr) );
113  for (size_t iob = 0; iob < 300; ++iob)
114  for (size_t iib = 0; iib < 200; ++iib)
115  materialMatrix[iob][iib] = new Trk::MaterialProperties(TrkDetDescrUnitTestBase::m_flatDist->shoot(),
121  (*lmMap)[Trk::LayerIndex(2)] = new Trk::BinnedLayerMaterial(rPhiZUtility, materialMatrix, TrkDetDescrUnitTestBase::m_flatDist->shoot()) ;
122 
123  // (c) compressed material
124  Trk::BinUtility zUtility(200,-100,100, Trk::open, Trk::binZ);
125 
126  std::vector< const Trk::MaterialProperties*> materialVector;
127  std::vector< unsigned short int > materialIndices;
128  materialVector.reserve(200);
129  materialIndices.reserve(200);
130  for (size_t iib = 0; iib < 200; ++iib){
131  materialIndices.push_back(int(TrkDetDescrUnitTestBase::m_flatDist->shoot()*200));
132  materialVector.push_back(new Trk::MaterialProperties(TrkDetDescrUnitTestBase::m_flatDist->shoot(),
138 
139  }
140  (*lmMap)[Trk::LayerIndex(3)] = new Trk::CompressedLayerMaterial(zUtility, materialVector, materialIndices);
141 
142  // (d) compound material
143  Trk::BinUtility zUtilityC(200,-100,100, Trk::open, Trk::binZ);
144 
145 
146  Trk::ValueMatrix thicknessMatrix;
147  Trk::ValueMatrix x0Matrix;
148  Trk::ValueMatrix l0Matrix;
149  Trk::ValueMatrix aMatrix;
150  Trk::ValueMatrix zMatrix;
151  Trk::ValueMatrix rhoMatrix;
152  thicknessMatrix.reserve(25);
153  x0Matrix.reserve(25);
154  l0Matrix.reserve(25);
155  aMatrix.reserve(25);
156  zMatrix.reserve(25);
157  rhoMatrix.reserve(25);
158 
159  std::vector< std::vector< Trk::MaterialComposition > > materialCompositionMatrix;
160 
161  for (size_t iob = 0; iob < 200; ++iob){
162  // the vectors
163  std::vector<unsigned char> thicknessVector; thicknessVector.reserve(25);
164  std::vector<unsigned char> x0Vector; x0Vector.reserve(25);
165  std::vector<unsigned char> l0Vector; l0Vector.reserve(25);
166  std::vector<unsigned char> aVector; aVector.reserve(25);
167  std::vector<unsigned char> zVector; zVector.reserve(25);
168  std::vector<unsigned char> rhoVector; rhoVector.reserve(25);
169  std::vector< Trk::MaterialComposition > materialCompositionVector;
170  materialCompositionVector.reserve(25);
171  for (size_t iib = 0; iib < 25; ++iib){
172  x0Vector.push_back((unsigned char)(TrkDetDescrUnitTestBase::m_flatDist->shoot()*UCHAR_MAX));
173  l0Vector.push_back((unsigned char)(TrkDetDescrUnitTestBase::m_flatDist->shoot()*UCHAR_MAX));
174  aVector.push_back((unsigned char)(TrkDetDescrUnitTestBase::m_flatDist->shoot()*UCHAR_MAX));
175  zVector.push_back((unsigned char)(TrkDetDescrUnitTestBase::m_flatDist->shoot()*UCHAR_MAX));
176  rhoVector.push_back((unsigned char)(TrkDetDescrUnitTestBase::m_flatDist->shoot()*UCHAR_MAX));
177  std::vector< Trk::ElementFraction > elements;
178  for (size_t iic = 0; iic < 5; ++iic){
179  elements.emplace_back((unsigned char)(TrkDetDescrUnitTestBase::m_flatDist->shoot()*UCHAR_MAX),
180  (unsigned char)(TrkDetDescrUnitTestBase::m_flatDist->shoot()*UCHAR_MAX));
181  }
182  materialCompositionVector.emplace_back(elements);
183  }
184  thicknessMatrix.push_back(thicknessVector);
185  x0Matrix.push_back(x0Vector);
186  l0Matrix.push_back(l0Vector);
187  aMatrix.push_back(aVector);
188  zMatrix.push_back(zVector);
189  rhoMatrix.push_back(rhoVector);
190  materialCompositionMatrix.push_back(materialCompositionVector);
191  }
192 
193  Trk::ValueStore thicknessBins;
194  thicknessBins.valueMin = 0.;
195  thicknessBins.valueStep = TrkDetDescrUnitTestBase::m_flatDist->shoot();
196  thicknessBins.valueBinMatrix = thicknessMatrix;
197 
198  Trk::ValueStore x0Bins;
199  x0Bins.valueMin = 0.;
201  x0Bins.valueBinMatrix = x0Matrix;
202 
203 
204  Trk::ValueStore l0Bins;
205  l0Bins.valueMin = 0.;
207  l0Bins.valueBinMatrix = l0Matrix;
208 
209  Trk::ValueStore aBins;
210  aBins.valueMin = 0.;
212  aBins.valueBinMatrix = aMatrix;
213 
215  zBins.valueMin = 0.;
216  zBins.valueStep = TrkDetDescrUnitTestBase::m_flatDist->shoot();
217  zBins.valueBinMatrix = zMatrix;
218 
219  Trk::ValueStore rhoBins;
220  rhoBins.valueMin = 0.;
222  rhoBins.valueBinMatrix = rhoMatrix;
223 
224  (*lmMap)[Trk::LayerIndex(3)] = new Trk::CompoundLayerMaterial(zUtilityC,
225  thicknessBins,
226  x0Bins,
227  l0Bins,
228  aBins,
229  zBins,
230  rhoBins,
231  materialCompositionMatrix);
232 
233  Trk::SharedObject<const Trk::ElementTable> sharedElementTable(new Trk::ElementTable(*eTable));
234  lmMap->updateElementTable(sharedElementTable);
235 
236  if ( (evtStore()->record(lmMap.release(), m_layerMaterialCollectionName)).isFailure() ) {
237  ATH_MSG_WARNING("Could not record the material collection " << m_layerMaterialCollectionName);
238  return StatusCode::FAILURE;
239  }
240  } else {
241  //
242  ATH_MSG_VERBOSE("Test is running in READ mode, reading in a file.");
243 
244  // ----------------- READ MODE -----------------
245  const Trk::LayerMaterialMap* lmMap = nullptr;
246  if ( (evtStore()->retrieve(lmMap, m_layerMaterialCollectionName)).isFailure() ) {
247  ATH_MSG_WARNING("Could not read the material collection " << m_layerMaterialCollectionName);
248  return StatusCode::FAILURE;
249  } else
250  ATH_MSG_INFO("Successfully read a LayerMaterialMap with size " << lmMap->size());
251 
252  }
253 
254  return StatusCode::SUCCESS;
255 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ElementTable.h
Trk::TrkDetDescrUnitTestBase::m_flatDist
Rndm::Numbers * m_flatDist
Definition: TrkDetDescrUnitTestBase.h:58
Trk::TrkDetDescrUnitTestBase::m_numTests
size_t m_numTests
number of tests
Definition: TrkDetDescrUnitTestBase.h:61
Trk::ValueStore::valueStep
float valueStep
Definition: CompoundLayerMaterial.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
MaterialProperties.h
TrkDetDescrTPCnvTest.h
Trk::binZ
@ binZ
Definition: BinningType.h:49
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::TrkDetDescrUnitTestBase
Definition: TrkDetDescrUnitTestBase.h:27
BinUtility.h
skel.it
it
Definition: skel.GENtoEVGEN.py:396
M_PI
#define M_PI
Definition: ActiveFraction.h:11
Trk::LayerMaterialMap::updateElementTable
void updateElementTable(const SharedObject< const ElementTable > &eTable)
update method
Definition: LayerMaterialMap.h:66
MaterialStepCollection.h
Trk::TrkDetDescrTPCnvTest::m_layerMaterialCollectionName
std::string m_layerMaterialCollectionName
Definition: TrkDetDescrTPCnvTest.h:40
Trk::closed
@ closed
Definition: BinningType.h:41
HomogeneousLayerMaterial.h
Trk::MaterialStepCollection
DataVector< Trk::MaterialStep > MaterialStepCollection
Definition: MaterialStepCollection.h:17
Trk::CompoundLayerMaterial
Definition: CompoundLayerMaterial.h:60
Trk::TrkDetDescrTPCnvTest::m_elementTableName
std::string m_elementTableName
Definition: TrkDetDescrTPCnvTest.h:41
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trk::LayerMaterialMap
Definition: LayerMaterialMap.h:32
CompoundLayerMaterial.h
Trk::CompressedLayerMaterial
Definition: CompressedLayerMaterial.h:31
Trk::MaterialStep
Definition: MaterialStep.h:34
Trk::ValueStore
Definition: CompoundLayerMaterial.h:32
Trk::ValueStore::valueBinMatrix
ValueMatrix valueBinMatrix
Definition: CompoundLayerMaterial.h:35
Trk::LayerIndex
Definition: LayerIndex.h:37
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
BinnedLayerMaterial.h
Trk::BinnedLayerMaterial
Definition: BinnedLayerMaterial.h:33
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SharedObject.h
Trk::TrkDetDescrTPCnvTest::TrkDetDescrTPCnvTest
TrkDetDescrTPCnvTest(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
Definition: TrkDetDescrTPCnvTest.cxx:25
MakeTH3DFromTH2Ds.zBins
list zBins
Definition: MakeTH3DFromTH2Ds.py:86
Trk::BinUtility
Definition: BinUtility.h:39
Trk::TrkDetDescrTPCnvTest::m_writeMode
bool m_writeMode
Definition: TrkDetDescrTPCnvTest.h:37
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
LayerMaterialMap.h
Trk::TrkDetDescrTPCnvTest::m_materialStepCollectionName
std::string m_materialStepCollectionName
Definition: TrkDetDescrTPCnvTest.h:39
Trk::open
@ open
Definition: BinningType.h:40
Trk::MaterialProperties
Definition: MaterialProperties.h:40
Trk::SharedObject
std::shared_ptr< T > SharedObject
Definition: SharedObject.h:24
Trk::ElementTable
Definition: ElementTable.h:24
Trk::ValueMatrix
std::vector< ValueVector > ValueMatrix
Definition: CompoundLayerMaterial.h:30
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::binRPhi
@ binRPhi
Definition: BinningType.h:52
Trk::ValueStore::valueMin
float valueMin
Definition: CompoundLayerMaterial.h:33
Trk::Material
Definition: Material.h:116
Trk::HomogeneousLayerMaterial
Definition: HomogeneousLayerMaterial.h:53
Trk::TrkDetDescrTPCnvTest::runTest
StatusCode runTest()
Definition: TrkDetDescrTPCnvTest.cxx:40
Material.h
Trk::ElementTable::addElement
void addElement(const Material &mat, const std::string &mname="")
Add material to the Table - if the elment is already filled ignore.
Definition: ElementTable.h:75
CompressedLayerMaterial.h