ATLAS Offline Software
Loading...
Searching...
No Matches
LayerMaterialAnalyser.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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) : AthAlgTool(t,n,p)
34{
35 declareInterface<Trk::ILayerMaterialAnalyser>(this);
36}
37
38
39// initialize
41{
42
43 m_layerTranslation = new std::vector<float>(3, 0.);
44 m_layerRotation = new std::vector<float>(9, 0.);
45 m_bin0 = new std::vector<int>(LAYERMAXBINS, 0);
46 m_bin1 = new std::vector<int>(LAYERMAXBINS, 0);
47 m_thickness = new std::vector<float>(LAYERMAXBINS, 0.);
48 m_X0 = new std::vector<float>(LAYERMAXBINS, 0.);
49 m_L0 = new std::vector<float>(LAYERMAXBINS, 0.);
50 m_A = new std::vector<float>(LAYERMAXBINS, 0.);
51 m_Z = new std::vector<float>(LAYERMAXBINS, 0.);
52 m_Rho = new std::vector<float>(LAYERMAXBINS, 0.);
53 m_elements = new std::vector<int>(LAYERMAXBINS, 0);
54 m_binCounter = new std::vector<int>(LAYERMAXBINS, 0);
55
56 // now register the Tree
57
58 // ------------- validation section ------------------------------------------
59 m_validationTree = new TTree(m_validationTreeName.value().c_str(),
60 m_validationTreeDescription.value().c_str());
61
62 // position coordinates of the update
63 m_validationTree->Branch("LayerIndex", &m_layerIndex );
64 m_validationTree->Branch("LayerType", &m_layerType );
65 m_validationTree->Branch("LayerTranslation", &m_layerTranslation );
66 m_validationTree->Branch("LayerRotation", &m_layerRotation );
67 m_validationTree->Branch("LayerDimension0", &m_layerDimension0 );
68 m_validationTree->Branch("LayerDimension1", &m_layerDimension1 );
69 m_validationTree->Branch("LayerBins", &m_layerBins );
70 m_validationTree->Branch("LayerBins0", &m_layerBins0 );
71 m_validationTree->Branch("LayerBins1", &m_layerBins1 );
72 m_validationTree->Branch("LayerBin0", &m_bin0 );
73 m_validationTree->Branch("LayerBin1", &m_bin1 );
74 m_validationTree->Branch("LayerBinCounter", &m_binCounter );
75 m_validationTree->Branch("LayerThickness", &m_thickness );
76 m_validationTree->Branch("LayerX0", &m_X0 );
77 m_validationTree->Branch("LayerL0", &m_L0 );
78 m_validationTree->Branch("LayerA", &m_A );
79 m_validationTree->Branch("LayerZ", &m_Z );
80 m_validationTree->Branch("LayerRo", &m_Rho );
81 m_validationTree->Branch("LayerElements", &m_elements );
82
83 // now register the Tree
84 SmartIF<ITHistSvc> tHistSvc{service("THistSvc")};
85 if (!tHistSvc) {
86 ATH_MSG_ERROR("initialize() Could not find Hist Service -> Switching ValidationMode Off !" );
87 delete m_validationTree; m_validationTree = nullptr;
88 return StatusCode::SUCCESS;
89 }
90 if ((tHistSvc->regTree(m_validationTreeFolder.value().c_str(), m_validationTree)).isFailure()) {
91 ATH_MSG_ERROR("initialize() Could not register the validation Tree -> Switching ValidationMode Off !" );
92 delete m_validationTree; m_validationTree = nullptr;
93 return StatusCode::SUCCESS;
94 }
95
96 return StatusCode::SUCCESS;
97}
98
99// finalize
101{
102 delete m_layerTranslation ;
103 delete m_layerRotation ;
104 delete m_bin0 ;
105 delete m_bin1 ;
106 delete m_thickness ;
107 delete m_X0 ;
108 delete m_L0 ;
109 delete m_A ;
110 delete m_Z ;
111 delete m_Rho ;
112 delete m_elements ;
113 delete m_binCounter ;
114 return StatusCode::SUCCESS;
115}
116
117
118
120{
121
122 // get the LayerMaterial
123 const Trk::LayerMaterialProperties* lMaterial = layer.layerMaterialProperties();
124 if (!lMaterial) return StatusCode::SUCCESS;
125
126 return analyseLayerMaterial(layer, *lMaterial);
127}
128
129
131{
132
133 // binned material can directly call the filling method
134 const Trk::BinnedLayerMaterial* blMaterial = dynamic_cast<const Trk::BinnedLayerMaterial*>(&lMaterial);
135 if (blMaterial) {
136 ATH_MSG_DEBUG( "Recieved BinnedLayerMaterial - analyzing it." );
137 return analyseLayerMaterial(layer, blMaterial->fullMaterial());
138 }
139
140 // we need to create a MaterialProperties matrix for this
141 const Trk::BinUtility* bUtility = lMaterial.binUtility();
142 size_t mBins0 = bUtility ? bUtility->max(0)+1 : 1;
143 size_t mBins1 = bUtility ? bUtility->max(1)+1 : 1;
144
145 Trk::MaterialPropertiesMatrix mpMatrix(mBins1, std::vector< const Trk::MaterialProperties*>(mBins0, nullptr));
146 for (size_t ibin1 = 0; ibin1 < mBins1; ++ ibin1){
147 for (size_t ibin0 = 0; ibin0 < mBins0; ++ibin0)
148 mpMatrix[ibin1][ibin0] = lMaterial.material(ibin0, ibin1);
149 }
150 // now send it to the analyser
151 return analyse(layer, mpMatrix);
152}
153
154
156{
157 ATH_MSG_DEBUG( "Recieved MaterialPropertyMatrix - analyzing it." );
158 return analyse(layer, mpMatrix);
159}
160
161
163{
164 ATH_MSG_DEBUG( "Recieved LayerMaterialRecord - analyzing it." );
165 return analyse(layer, lmRecord.associatedLayerMaterial(), &lmRecord.binCounts());
166}
167
169 const Trk::MaterialPropertiesMatrix& mpMatrix,
170 const std::vector< std::vector< unsigned int > >* bCounter ) const
171{
172
173 // general layer information
174 m_layerIndex = layer.layerIndex().value();
175 const Trk::Surface& lSurface = layer.surfaceRepresentation();
176 m_layerTranslation->at(0) = lSurface.center().x();
177 m_layerTranslation->at(1) = lSurface.center().y();
178 m_layerTranslation->at(2) = lSurface.center().z();
179
180 AmgMatrix(3,3) rMatrix = lSurface.transform().rotation();
181 m_layerRotation->at(0) = rMatrix(0,0);
182 m_layerRotation->at(1) = rMatrix(1,0);
183 m_layerRotation->at(2) = rMatrix(2,0);
184 m_layerRotation->at(3) = rMatrix(0,1);
185 m_layerRotation->at(4) = rMatrix(1,1);
186 m_layerRotation->at(5) = rMatrix(2,1);
187 m_layerRotation->at(6) = rMatrix(0,2);
188 m_layerRotation->at(7) = rMatrix(1,2);
189 m_layerRotation->at(8) = rMatrix(2,2);
190
191 // cylinder bounds
192 if ( lSurface.type() == Trk::SurfaceType::Cylinder ){
193 m_layerType = 1;
194 // cylinder bounds
195 const Trk::CylinderBounds* cb = dynamic_cast<const Trk::CylinderBounds*>(&(lSurface.bounds()));
196 if (cb){
197 m_layerDimension0 = cb->r();
199 }
200 } else if ( lSurface.type() == Trk::SurfaceType::Disc ) {
201 m_layerType = 2;
202 // disc bounds
203 const Trk::DiscBounds* db = dynamic_cast<const Trk::DiscBounds*>(&(lSurface.bounds()));
204 if (db){
205 m_layerDimension0 = db->rMin();
206 m_layerDimension1 = db->rMax();
207 }
208 }
209
210 // now get the material matrix and record all single bins;
211 m_layerBins0 = 0;
212 m_layerBins1 = 0;
213 m_layerBins = 0;
214 int bin1 = 0;
215 for (const auto & outerIter : mpMatrix){
216 int bin0 = 0;
217 for (const auto & innerIter : outerIter ){
218 m_bin0->at(m_layerBins) = bin0;
219 m_bin1->at(m_layerBins) = bin1;
220 // get the material
221 const Trk::MaterialProperties* mProperties = innerIter;
222 if (mProperties){
223 m_thickness->at(m_layerBins) = mProperties->thickness();
224 m_X0->at(m_layerBins) = mProperties->x0();
225 m_L0->at(m_layerBins) = mProperties->l0();
226 m_A->at(m_layerBins) = mProperties->averageA();
227 m_Z->at(m_layerBins) = mProperties->averageZ();
228 m_Rho->at(m_layerBins) = mProperties->averageRho();
229 m_elements->at(m_layerBins) = mProperties->material().composition ? mProperties->material().composition->size() : 0;
230 } else {
231 m_thickness->at(m_layerBins) = 0.;
232 m_X0->at(m_layerBins) = 0.;
233 m_L0->at(m_layerBins) = 0.;
234 m_A->at(m_layerBins) = 0.;
235 m_Z->at(m_layerBins) = 0.;
236 m_Rho->at(m_layerBins) = 0.;
237 m_elements->at(m_layerBins) = 0.;
238 }
239 // set the bin Counter
240 m_binCounter->at(m_layerBins) = bCounter ? (*bCounter)[bin1][bin0] : 1;
241 //
242 ++bin0;
243 if (!bin1) ++m_layerBins0;
244 ++m_layerBins;
245 }
246 ++bin1;
247 ++m_layerBins1;
248 }
249 m_validationTree->Fill();
250
251 // return 0 - since this is only an analyser
252 return StatusCode::SUCCESS;
253}
254
#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:
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
Gaudi::Property< std::string > m_validationTreeFolder
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::vector< float > * m_X0
gathered X0 from material mapping/material properties
std::vector< float > * m_Z
gathered Z from material mapping/material properties
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.
Gaudi::Property< std::string > m_validationTreeDescription
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
Gaudi::Property< std::string > m_validationTreeName
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.
Definition Surface.h:79
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