ATLAS Offline Software
LayerMaterialAnalyser.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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"
22 #include "TrkSurfaces/DiscBounds.h"
23 // Event & GeoPrimitives
26 // Gaudi
27 #include "GaudiKernel/ITHistSvc.h"
28 // ROOT
29 #include "TTree.h"
30 
31 
32 // constructor
33 Trk::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),
44  m_layerDimension0(0.),
45  m_layerDimension1(0.),
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 ------------------------------------------
93  m_validationTree = new TTree(m_validationTreeName.c_str(), m_validationTreeDescription.c_str());
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(), (const std::vector< std::vector< unsigned int > >*)&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();
231  m_layerDimension1 = cb->halflengthZ();
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 
LAYERMAXBINS
#define LAYERMAXBINS
Definition: LayerMaterialAnalyser.h:20
Trk::LayerMaterialAnalyser::~LayerMaterialAnalyser
~LayerMaterialAnalyser()
Destructor.
Trk::AmgMatrix
AmgMatrix(3, 3) NeutralParticleParameterCalculator
Definition: NeutralParticleParameterCalculator.cxx:233
Trk::MaterialProperties::averageA
float averageA() const
Return the average A of the material [gram/mole].
Trk::LayerMaterialAnalyser::m_validationTreeName
std::string m_validationTreeName
validation tree name - to be accessed by this from root
Definition: LayerMaterialAnalyser.h:75
DiscBounds.h
Trk::LayerMaterialAnalyser::m_layerMaterialName
std::string m_layerMaterialName
Definition: LayerMaterialAnalyser.h:72
Surface.h
MaterialProperties.h
Trk::BinUtility::max
size_t max(size_t ba=0) const
First bin maximal value.
Definition: BinUtility.h:215
Trk::LayerMaterialAnalyser::m_validationTreeDescription
std::string m_validationTreeDescription
validation tree description - second argument in TTree
Definition: LayerMaterialAnalyser.h:76
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloCondBlobAlgs_fillNoiseFromASCII.db
db
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:43
Trk::LayerMaterialAnalyser::analyseLayerMaterial
StatusCode analyseLayerMaterial(const Layer &lay) const
process the layer - after material creation and loading
Definition: LayerMaterialAnalyser.cxx:152
BinUtility.h
Trk::MaterialProperties::averageRho
float averageRho() const
Return the average density of the material.
Layer.h
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
Trk::Surface::center
const Amg::Vector3D & center() const
Returns the center position of the Surface.
Trk::MaterialProperties::material
const Material & material() const
Return the stored Material.
CompoundLayerMaterial.h
Trk::MaterialProperties::thickness
float thickness() const
Return the thickness in mm.
Trk::LayerMaterialAnalyser::finalize
StatusCode finalize()
AlgTool finalize method.
Definition: LayerMaterialAnalyser.cxx:133
GeoPrimitives.h
LayerMaterialAnalyser.h
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Trk::LayerMaterialRecord::associatedLayerMaterial
const MaterialPropertiesMatrix & associatedLayerMaterial() const
return method for the LayerMaterial
Definition: LayerMaterialRecord.h:129
LayerMaterialRecord.h
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Trk::CylinderBounds
Definition: CylinderBounds.h:46
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
Trk::LayerMaterialProperties
Definition: LayerMaterialProperties.h:62
Trk::LayerMaterialAnalyser::initialize
StatusCode initialize()
AlgTool initialize method.
Definition: LayerMaterialAnalyser.cxx:74
Trk::LayerMaterialAnalyser::m_validationTreeFolder
std::string m_validationTreeFolder
stream/folder to for the TTree to be written out
Definition: LayerMaterialAnalyser.h:77
BinnedLayerMaterial.h
Trk::BinnedLayerMaterial
Definition: BinnedLayerMaterial.h:33
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::BinnedLayerMaterial::fullMaterial
const MaterialPropertiesMatrix & fullMaterial() const
Return method for full material description of the Layer - for all bins.
Definition: BinnedLayerMaterial.h:124
EventPrimitives.h
Trk::Surface::bounds
virtual const SurfaceBounds & bounds() const =0
Surface Bounds method.
Trk::LayerMaterialRecord::binCounts
const std::vector< std::vector< unsigned int > > & binCounts() const
return method for the events used for this
Definition: LayerMaterialRecord.h:134
Trk::MaterialPropertiesMatrix
std::vector< std::vector< const MaterialProperties * > > MaterialPropertiesMatrix
Definition: ILayerMaterialAnalyser.h:23
CylinderBounds.h
Trk::MaterialProperties
Definition: MaterialProperties.h:40
dqt_zlumi_pandas.bin1
bin1
Definition: dqt_zlumi_pandas.py:336
Trk::MaterialProperties::averageZ
float averageZ() const
Returns the average Z of the material.
Trk::SurfaceType::Disc
@ Disc
Trk::SurfaceType::Cylinder
@ Cylinder
Trk::Material::composition
MaterialComposition * composition
Definition: Material.h:126
Trk::LayerMaterialAnalyser::analyse
StatusCode analyse(const Layer &lay, const MaterialPropertiesMatrix &lmr, const std::vector< std::vector< unsigned int > > *bCounter=0) const
Definition: LayerMaterialAnalyser.cxx:201
AthAlgTool
Definition: AthAlgTool.h:26
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
Trk::MaterialProperties::l0
float l0() const
Return the nuclear interaction length.
Trk::Surface::transform
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
Trk::Surface::type
constexpr virtual SurfaceType type() const =0
Returns the Surface type to avoid dynamic casts.
LayerMaterialProperties.h
Trk::DiscBounds
Definition: DiscBounds.h:44
Trk::CylinderBounds::halflengthZ
double halflengthZ() const
This method returns the halflengthZ.
Trk::CylinderBounds::r
virtual double r() const override final
This method returns the radius.
Trk::LayerMaterialAnalyser::LayerMaterialAnalyser
LayerMaterialAnalyser(const std::string &, const std::string &, const IInterface *)
Constructor.
Definition: LayerMaterialAnalyser.cxx:33
Trk::Layer
Definition: Layer.h:73