ATLAS Offline Software
Loading...
Searching...
No Matches
LayerMaterialAnalyser.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6// LayerMaterialAnalyser.cxx, (c) ATLAS Detector software
8
9// STL
10#include <sstream>
11// Trk include
19#include "TrkGeometry/Layer.h"
20#include "TrkSurfaces/Surface.h"
23// Event & GeoPrimitives
26// Gaudi
27#include "GaudiKernel/ITHistSvc.h"
28// ROOT
29#include "TTree.h"
30
31
32// constructor
33Trk::LayerMaterialAnalyser::LayerMaterialAnalyser(const std::string& t, const std::string& n, const IInterface* p)
34: AthAlgTool(t,n,p),
35 m_layerMaterialName("UnspecifiedLayerMaterialMap"),
36 m_validationTree(nullptr),
37 m_validationTreeName("LayerMaterialAnalyser"),
38 m_validationTreeDescription("LayerMaterialAnalyser information"),
39 m_validationTreeFolder("/val/LayerMaterialAnalyser"),
40 m_layerIndex(0),
41 m_layerType(0),
42 m_layerTranslation(nullptr),
43 m_layerRotation(nullptr),
46 m_layerBins(0),
47 m_layerBins0(0),
48 m_layerBins1(0),
49 m_bin0(nullptr),
50 m_bin1(nullptr),
51 m_thickness(nullptr),
52 m_X0(nullptr),
53 m_L0(nullptr),
54 m_A(nullptr),
55 m_Z(nullptr),
56 m_Rho(nullptr),
57 m_elements(nullptr),
58 m_binCounter(nullptr)
59{
60 declareInterface<Trk::ILayerMaterialAnalyser>(this);
61 // give the map a name
62 declareProperty("LayerMaterialName", m_layerMaterialName);
63 declareProperty("ValidationTreeName", m_validationTreeName);
64 declareProperty("ValidationTreeDescription", m_validationTreeDescription);
65 declareProperty("ValidationTreeFolder", m_validationTreeFolder);
66}
67
68// destructor
70= default;
71
72
73// initialize
75{
76
77 m_layerTranslation = new std::vector<float>(3, 0.);
78 m_layerRotation = new std::vector<float>(9, 0.);
79 m_bin0 = new std::vector<int>(LAYERMAXBINS, 0);
80 m_bin1 = new std::vector<int>(LAYERMAXBINS, 0);
81 m_thickness = new std::vector<float>(LAYERMAXBINS, 0.);
82 m_X0 = new std::vector<float>(LAYERMAXBINS, 0.);
83 m_L0 = new std::vector<float>(LAYERMAXBINS, 0.);
84 m_A = new std::vector<float>(LAYERMAXBINS, 0.);
85 m_Z = new std::vector<float>(LAYERMAXBINS, 0.);
86 m_Rho = new std::vector<float>(LAYERMAXBINS, 0.);
87 m_elements = new std::vector<int>(LAYERMAXBINS, 0);
88 m_binCounter = new std::vector<int>(LAYERMAXBINS, 0);
89
90 // now register the Tree
91
92 // ------------- validation section ------------------------------------------
94
95 // position coordinates of the update
96 m_validationTree->Branch("LayerIndex", &m_layerIndex );
97 m_validationTree->Branch("LayerType", &m_layerType );
98 m_validationTree->Branch("LayerTranslation", &m_layerTranslation );
99 m_validationTree->Branch("LayerRotation", &m_layerRotation );
100 m_validationTree->Branch("LayerDimension0", &m_layerDimension0 );
101 m_validationTree->Branch("LayerDimension1", &m_layerDimension1 );
102 m_validationTree->Branch("LayerBins", &m_layerBins );
103 m_validationTree->Branch("LayerBins0", &m_layerBins0 );
104 m_validationTree->Branch("LayerBins1", &m_layerBins1 );
105 m_validationTree->Branch("LayerBin0", &m_bin0 );
106 m_validationTree->Branch("LayerBin1", &m_bin1 );
107 m_validationTree->Branch("LayerBinCounter", &m_binCounter );
108 m_validationTree->Branch("LayerThickness", &m_thickness );
109 m_validationTree->Branch("LayerX0", &m_X0 );
110 m_validationTree->Branch("LayerL0", &m_L0 );
111 m_validationTree->Branch("LayerA", &m_A );
112 m_validationTree->Branch("LayerZ", &m_Z );
113 m_validationTree->Branch("LayerRo", &m_Rho );
114 m_validationTree->Branch("LayerElements", &m_elements );
115
116 // now register the Tree
117 SmartIF<ITHistSvc> tHistSvc{service("THistSvc")};
118 if (!tHistSvc) {
119 ATH_MSG_ERROR("initialize() Could not find Hist Service -> Switching ValidationMode Off !" );
120 delete m_validationTree; m_validationTree = nullptr;
121 return StatusCode::SUCCESS;
122 }
123 if ((tHistSvc->regTree(m_validationTreeFolder.c_str(), m_validationTree)).isFailure()) {
124 ATH_MSG_ERROR("initialize() Could not register the validation Tree -> Switching ValidationMode Off !" );
125 delete m_validationTree; m_validationTree = nullptr;
126 return StatusCode::SUCCESS;
127 }
128
129 return StatusCode::SUCCESS;
130}
131
132// finalize
134{
135 delete m_layerTranslation ;
136 delete m_layerRotation ;
137 delete m_bin0 ;
138 delete m_bin1 ;
139 delete m_thickness ;
140 delete m_X0 ;
141 delete m_L0 ;
142 delete m_A ;
143 delete m_Z ;
144 delete m_Rho ;
145 delete m_elements ;
146 delete m_binCounter ;
147 return StatusCode::SUCCESS;
148}
149
150
151
153{
154
155 // get the LayerMaterial
156 const Trk::LayerMaterialProperties* lMaterial = layer.layerMaterialProperties();
157 if (!lMaterial) return StatusCode::SUCCESS;
158
159 return analyseLayerMaterial(layer, *lMaterial);
160}
161
162
164{
165
166 // binned material can directly call the filling method
167 const Trk::BinnedLayerMaterial* blMaterial = dynamic_cast<const Trk::BinnedLayerMaterial*>(&lMaterial);
168 if (blMaterial) {
169 ATH_MSG_DEBUG( "Recieved BinnedLayerMaterial - analyzing it." );
170 return analyseLayerMaterial(layer, blMaterial->fullMaterial());
171 }
172
173 // we need to create a MaterialProperties matrix for this
174 const Trk::BinUtility* bUtility = lMaterial.binUtility();
175 size_t mBins0 = bUtility ? bUtility->max(0)+1 : 1;
176 size_t mBins1 = bUtility ? bUtility->max(1)+1 : 1;
177
178 Trk::MaterialPropertiesMatrix mpMatrix(mBins1, std::vector< const Trk::MaterialProperties*>(mBins0, nullptr));
179 for (size_t ibin1 = 0; ibin1 < mBins1; ++ ibin1){
180 for (size_t ibin0 = 0; ibin0 < mBins0; ++ibin0)
181 mpMatrix[ibin1][ibin0] = lMaterial.material(ibin0, ibin1);
182 }
183 // now send it to the analyser
184 return analyse(layer, mpMatrix);
185}
186
187
189{
190 ATH_MSG_DEBUG( "Recieved MaterialPropertyMatrix - analyzing it." );
191 return analyse(layer, mpMatrix);
192}
193
194
196{
197 ATH_MSG_DEBUG( "Recieved LayerMaterialRecord - analyzing it." );
198 return analyse(layer, lmRecord.associatedLayerMaterial(), &lmRecord.binCounts());
199}
200
202 const Trk::MaterialPropertiesMatrix& mpMatrix,
203 const std::vector< std::vector< unsigned int > >* bCounter ) const
204{
205
206 // general layer information
207 m_layerIndex = layer.layerIndex().value();
208 const Trk::Surface& lSurface = layer.surfaceRepresentation();
209 m_layerTranslation->at(0) = lSurface.center().x();
210 m_layerTranslation->at(1) = lSurface.center().y();
211 m_layerTranslation->at(2) = lSurface.center().z();
212
213 AmgMatrix(3,3) rMatrix = lSurface.transform().rotation();
214 m_layerRotation->at(0) = rMatrix(0,0);
215 m_layerRotation->at(1) = rMatrix(1,0);
216 m_layerRotation->at(2) = rMatrix(2,0);
217 m_layerRotation->at(3) = rMatrix(0,1);
218 m_layerRotation->at(4) = rMatrix(1,1);
219 m_layerRotation->at(5) = rMatrix(2,1);
220 m_layerRotation->at(6) = rMatrix(0,2);
221 m_layerRotation->at(7) = rMatrix(1,2);
222 m_layerRotation->at(8) = rMatrix(2,2);
223
224 // cylinder bounds
225 if ( lSurface.type() == Trk::SurfaceType::Cylinder ){
226 m_layerType = 1;
227 // cylinder bounds
228 const Trk::CylinderBounds* cb = dynamic_cast<const Trk::CylinderBounds*>(&(lSurface.bounds()));
229 if (cb){
230 m_layerDimension0 = cb->r();
232 }
233 } else if ( lSurface.type() == Trk::SurfaceType::Disc ) {
234 m_layerType = 2;
235 // disc bounds
236 const Trk::DiscBounds* db = dynamic_cast<const Trk::DiscBounds*>(&(lSurface.bounds()));
237 if (db){
238 m_layerDimension0 = db->rMin();
239 m_layerDimension1 = db->rMax();
240 }
241 }
242
243 // now get the material matrix and record all single bins;
244 m_layerBins0 = 0;
245 m_layerBins1 = 0;
246 m_layerBins = 0;
247 int bin1 = 0;
248 for (const auto & outerIter : mpMatrix){
249 int bin0 = 0;
250 for (const auto & innerIter : outerIter ){
251 m_bin0->at(m_layerBins) = bin0;
252 m_bin1->at(m_layerBins) = bin1;
253 // get the material
254 const Trk::MaterialProperties* mProperties = innerIter;
255 if (mProperties){
256 m_thickness->at(m_layerBins) = mProperties->thickness();
257 m_X0->at(m_layerBins) = mProperties->x0();
258 m_L0->at(m_layerBins) = mProperties->l0();
259 m_A->at(m_layerBins) = mProperties->averageA();
260 m_Z->at(m_layerBins) = mProperties->averageZ();
261 m_Rho->at(m_layerBins) = mProperties->averageRho();
262 m_elements->at(m_layerBins) = mProperties->material().composition ? mProperties->material().composition->size() : 0;
263 } else {
264 m_thickness->at(m_layerBins) = 0.;
265 m_X0->at(m_layerBins) = 0.;
266 m_L0->at(m_layerBins) = 0.;
267 m_A->at(m_layerBins) = 0.;
268 m_Z->at(m_layerBins) = 0.;
269 m_Rho->at(m_layerBins) = 0.;
270 m_elements->at(m_layerBins) = 0.;
271 }
272 // set the bin Counter
273 m_binCounter->at(m_layerBins) = bCounter ? (*bCounter)[bin1][bin0] : 1;
274 //
275 ++bin0;
276 if (!bin1) ++m_layerBins0;
277 ++m_layerBins;
278 }
279 ++bin1;
280 ++m_layerBins1;
281 }
282 m_validationTree->Fill();
283
284 // return 0 - since this is only an analyser
285 return StatusCode::SUCCESS;
286}
287
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
#define AmgMatrix(rows, cols)
#define LAYERMAXBINS
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
It extends the LayerMaterialProperties base class.
const MaterialPropertiesMatrix & fullMaterial() const
Return method for full material description of the Layer - for all bins.
Bounds for a cylindrical Surface.
virtual double r() const override final
This method returns the radius.
double halflengthZ() const
This method returns the halflengthZ.
Class to describe the bounds for a planar DiscSurface.
Definition DiscBounds.h:44
std::vector< int > * m_bin0
bin 0
std::vector< float > * m_Rho
gathered rho from material mapping/material properties
float m_layerDimension1
dimension 1 : cylinder z, disk r_max
LayerMaterialAnalyser(const std::string &, const std::string &, const IInterface *)
Constructor.
std::vector< int > * m_binCounter
how often was this bin hit / used
StatusCode analyse(const Layer &lay, const MaterialPropertiesMatrix &lmr, const std::vector< std::vector< unsigned int > > *bCounter=0) const
std::vector< float > * m_thickness
gathered thickness from material mapping/material properties
std::vector< float > * m_layerTranslation
center of the transform
std::vector< int > * m_bin1
bin 1
int m_layerIndex
the layer index given by the TrackingGeometry
std::vector< float > * m_A
gathered A from material mapping/material properties
std::string m_validationTreeDescription
validation tree description - second argument in TTree
std::vector< float > * m_X0
gathered X0 from material mapping/material properties
std::vector< float > * m_Z
gathered Z from material mapping/material properties
std::string m_validationTreeName
validation tree name - to be accessed by this from root
StatusCode analyseLayerMaterial(const Layer &lay) const
process the layer - after material creation and loading
float m_layerDimension0
dimension 0 : cylinder r, disk r_min
int m_layerBins1
total number of bins - loc 0
TTree * m_validationTree
The validation tree.
std::string m_validationTreeFolder
stream/folder to for the TTree to be written out
~LayerMaterialAnalyser()
Destructor.
int m_layerBins
total number of bins - loc0 * loc 1
int m_layerType
the type of the layer 1 - cylinder, 2 - disk
std::vector< float > * m_layerRotation
orientation of the layer
std::vector< int > * m_elements
gathered number of elements from material mapping/material properties
StatusCode initialize()
AlgTool initialize method.
StatusCode finalize()
AlgTool finalize method.
std::vector< float > * m_L0
gathered L0 from material mapping/material properties
int m_layerBins0
total number of bins - loc 0
This virtual base class encapsulates the logics to build pre/post/full update material for Layer stru...
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 std::vector< std::vector< unsigned int > > & binCounts() const
return method for the events used for this
const MaterialPropertiesMatrix & associatedLayerMaterial() const
return method for the LayerMaterial
Base Class for a Detector Layer in the Tracking realm.
Definition Layer.h:72
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
Abstract Base Class for tracking surfaces.
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
virtual constexpr SurfaceType type() const =0
Returns the Surface type to avoid dynamic casts.
virtual const SurfaceBounds & bounds() const =0
Surface Bounds method.
const Amg::Vector3D & center() const
Returns the center position of the Surface.
std::vector< std::vector< const MaterialProperties * > > MaterialPropertiesMatrix