ATLAS Offline Software
AFPSiRowColToLocalCSTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
14 // STL includes
15 #include <list>
16 
17 #include "xAODForward/AFPSiHit.h"
19 
21 
22 #include "CLHEP/Units/SystemOfUnits.h"
24 
26  const std::string &name,
27  const IInterface *parent)
28  : base_class(type, name, parent)
29 {
30 }
31 
32 
33 void AFPSiRowColToLocalCSTool::initTransformationMatricesSize (std::list<std::vector< std::vector<ROOT::Math::Transform3D> >* >& matrices, const std::vector<int>& layersInStations)
34 {
35  const int numberOfStations = layersInStations.size();
36  std::list<std::vector< std::vector<ROOT::Math::Transform3D> >::iterator> iterators;
37 
38  // initialise number of stations in each set and prepare iterators
39  for (std::vector< std::vector<ROOT::Math::Transform3D> >* theMatrix : matrices) {
40  theMatrix->resize(numberOfStations);
41  iterators.push_back(theMatrix->begin());
42  }
43 
44  // initialise number of layers in each station
45  for (const int layersN : layersInStations)
46  for (std::vector< std::vector<ROOT::Math::Transform3D> >::iterator& matrixIter : iterators)
47  (*(matrixIter++)) = std::vector<ROOT::Math::Transform3D> (layersN);
48 }
49 
51 {
52  using TransformVec_t = std::vector<std::vector<ROOT::Math::Transform3D>>;
53 
54  std::list<TransformVec_t*> matricesForLayersInit;
55  matricesForLayersInit.push_back(&m_transformations);
56  matricesForLayersInit.push_back(&m_transformationsErr);
57 
58 
60 
61  // count total number of layers
62  unsigned int totalLayersN = 0;
63  for (const int layersN : m_numberOfLayersInStations)
64  totalLayersN += layersN;
65 
66  // --- initialise transformations for each layer in station ---
67  bool useDefualtTransformation = true;
68  if (!m_transformationsInit.empty() && !m_transformationsErrInit.empty()) {
69  // check if the number of arguments is correct for (4x3) matrices
70  if (m_transformationsInit.size() == totalLayersN*4*3) {
71  if (m_transformationsErrInit.size() == totalLayersN*4*3) {
72 
73  std::vector<double>::const_iterator valueIter = m_transformationsInit.begin();
74  for (std::vector<ROOT::Math::Transform3D>& station : m_transformations)
75  for (ROOT::Math::Transform3D& layerTransform : station) {
76  layerTransform.SetComponents(valueIter, valueIter+12);
77  valueIter += 12;
78  }
79 
80  std::vector<double>::const_iterator valueErrIter = m_transformationsErrInit.begin();
81  for (std::vector<ROOT::Math::Transform3D>& station : m_transformationsErr)
82  for (ROOT::Math::Transform3D& layerTransform : station) {
83  layerTransform.SetComponents(valueErrIter, valueErrIter+12);
84  valueErrIter += 12;
85  }
86 
87  useDefualtTransformation = false;
88  }
89  else
90  ATH_MSG_WARNING("Incorrect number of elements in transformationErr vector in job options. Should be "<<totalLayersN<<"x4x3="<<totalLayersN*4*3<<". Is "<<m_transformationsErrInit.size()<<". Will use default transformation.");
91  } // close if (m_transformationsInit.size() == totalLayersN*4*3)
92  else
93  ATH_MSG_WARNING("Incorrect number of elements in transformation vector in job options. Should be "<<totalLayersN<<"x4x3="<<totalLayersN*4*3<<". Is "<<m_transformationsInit.size()<<". Will use default transformation.");
94  } // close if (m_transformationsInit.size() && m_transformationsErrInit.size())
95  else
96  ATH_MSG_INFO("In job options m_transformationsInit and m_transformationsErrInit are not defined simultaneously, so default transformations will be used.");
97 
98  // if there were problems with job options scaling or none was defined use default values
99  if (useDefualtTransformation) {
100  //---->Extra brackets are for vexing parse issues under clang14<---
101  const ROOT::Math::Transform3D rotationA((ROOT::Math::RotationY(AFP_CONSTANTS::SiT_Plate_rot_xz))); // rotate by +14 degrees
102  const ROOT::Math::Transform3D rotationC(ROOT::Math::RotationY(-1.*AFP_CONSTANTS::SiT_Plate_rot_xz)); // rotate by -14 degrees
103 
104  const ROOT::Math::Translation3D translationA0(0, 0, 0.);
105  const ROOT::Math::Translation3D translationA1(0, 0, 1.*AFP_CONSTANTS::SiT_Plate_zsep);
106  const ROOT::Math::Translation3D translationA2(0, 0, 2.*AFP_CONSTANTS::SiT_Plate_zsep);
107  const ROOT::Math::Translation3D translationA3(0, 0, 3.*AFP_CONSTANTS::SiT_Plate_zsep);
108 
109  const ROOT::Math::Translation3D translationC0(0, 0, 0.);
110  const ROOT::Math::Translation3D translationC1(0, 0,-1.*AFP_CONSTANTS::SiT_Plate_zsep);
111  const ROOT::Math::Translation3D translationC2(0, 0,-2.*AFP_CONSTANTS::SiT_Plate_zsep);
112  const ROOT::Math::Translation3D translationC3(0, 0,-3.*AFP_CONSTANTS::SiT_Plate_zsep);
113 
114  // station 0
115  m_transformationsErr[0][0] = rotationA;
116  m_transformationsErr[0][1] = rotationA;
117  m_transformationsErr[0][2] = rotationA;
118  m_transformationsErr[0][3] = rotationA;
119 
120  m_transformations[0][0] = translationA0*m_transformationsErr[0][0];
121  m_transformations[0][1] = translationA1*m_transformationsErr[0][1];
122  m_transformations[0][2] = translationA2*m_transformationsErr[0][2];
123  m_transformations[0][3] = translationA3*m_transformationsErr[0][3];
124 
125  // station 1
126  m_transformationsErr[1][0] = rotationA;
127  m_transformationsErr[1][1] = rotationA;
128  m_transformationsErr[1][2] = rotationA;
129  m_transformationsErr[1][3] = rotationA;
130 
131  m_transformations[1][0] = translationA0*m_transformationsErr[1][0];
132  m_transformations[1][1] = translationA1*m_transformationsErr[1][1];
133  m_transformations[1][2] = translationA2*m_transformationsErr[1][2];
134  m_transformations[1][3] = translationA3*m_transformationsErr[1][3];
135 
136  // station 2
137  m_transformationsErr[2][0] = rotationC;
138  m_transformationsErr[2][1] = rotationC;
139  m_transformationsErr[2][2] = rotationC;
140  m_transformationsErr[2][3] = rotationC;
141 
142  m_transformations[2][0] = translationC0*m_transformationsErr[2][0];
143  m_transformations[2][1] = translationC1*m_transformationsErr[2][1];
144  m_transformations[2][2] = translationC2*m_transformationsErr[2][2];
145  m_transformations[2][3] = translationC3*m_transformationsErr[2][3];
146 
147  // station 3
148  m_transformationsErr[3][0] = rotationC;
149  m_transformationsErr[3][1] = rotationC;
150  m_transformationsErr[3][2] = rotationC;
151  m_transformationsErr[3][3] = rotationC;
152 
153  m_transformations[3][0] = translationC0*m_transformationsErr[3][0];
154  m_transformations[3][1] = translationC1*m_transformationsErr[3][1];
155  m_transformations[3][2] = translationC2*m_transformationsErr[3][2];
156  m_transformations[3][3] = translationC3*m_transformationsErr[3][3];
157  }
158 
159  int stationCounter(0);
160  ATH_MSG_DEBUG("The following transformation matrices will be used");
161  for (const std::vector<ROOT::Math::Transform3D>& station : m_transformations) {
162  int layersCounter (0);
163  ATH_MSG_DEBUG("Station "<<stationCounter++);
164  for (const ROOT::Math::Transform3D& layerTrans : station)
165  ATH_MSG_DEBUG ("Layer "<<layersCounter++<<" "<<layerTrans);
166  } // close for (stations)
167 
168  stationCounter = 0;
169  ATH_MSG_DEBUG("The following transformation matrices for errors will be used");
170  for (const std::vector<ROOT::Math::Transform3D>& station : m_transformationsErr) {
171  int layersCounter (0);
172  ATH_MSG_DEBUG("Station "<<stationCounter++);
173  for (const ROOT::Math::Transform3D& layerTrans : station)
174  ATH_MSG_DEBUG ("Layer "<<layersCounter++<<" "<<layerTrans);
175  } // close for (stations)
176 
177  return StatusCode::SUCCESS;
178 }
179 
181  return StatusCode::SUCCESS;
182 }
183 
184 void AFPSiRowColToLocalCSTool::fillXAOD (const int stationID, const int layerID, const ROOT::Math::XYZPoint& position, const ROOT::Math::XYZPoint& positionError, xAOD::AFPSiHitsCluster* xAODCluster) const
185 {
186  xAODCluster->setStationID(stationID);
187  xAODCluster->setPixelLayerID(layerID);
188 
189  xAODCluster->setXLocal(position.x());
190  xAODCluster->setXLocalErr(positionError.x());
191 
192  xAODCluster->setYLocal(position.y());
193  xAODCluster->setYLocalErr(positionError.y());
194 
195  xAODCluster->setZLocal(position.z());
196  xAODCluster->setZLocalErr(positionError.z());
197 }
198 
199 xAOD::AFPSiHitsCluster* AFPSiRowColToLocalCSTool::newXAODLocal (const int stationID, const int layerID, const AFP::SiLocAlignData& LA, const AFP::SiGlobAlignData& GA, const AFPSiClusterBasicObj& cluster, std::unique_ptr<xAOD::AFPSiHitsClusterContainer>& xAODContainer) const
200 {
201  float flipAC = (stationID<2 ? -1. : +1.);
202 
203  ROOT::Math::XYZPoint horizVertID ((cluster.horizID()-AFP_CONSTANTS::SiT_Pixel_amount_x)*m_pixelHorizSize, flipAC*cluster.vertID()*m_pixelVertSize, 0);
204  ROOT::Math::XYZPoint horizVertIDErr (cluster.horizIDErr()*m_pixelHorizSize, cluster.vertIDErr()*m_pixelVertSize, 0);
205 
206  try {
207  // these horrible things are needed in order to have compatibility with AFPAnalysisToolbox
208  const ROOT::Math::RotationZYX locRotation(flipAC*LA.alpha(), -1.*flipAC*LA.gamma(), LA.beta()); // ATLAS coord.
209  const ROOT::Math::Translation3D locTranslation(-1.*LA.yShift(), flipAC*LA.xShift(), flipAC*LA.zShift()); // ATLAS coord.
210  const ROOT::Math::Translation3D globTranslation(GA.xShift(), flipAC*GA.yShift(), GA.zShift()); // ATLAS coord.
211 
212  ROOT::Math::XYZPoint localCS = globTranslation*locTranslation*locRotation*m_transformations.at(stationID).at(layerID)*horizVertID;
213  ROOT::Math::XYZPoint localCSError = locRotation*m_transformationsErr.at(stationID).at(layerID)*horizVertIDErr;
214 
215  auto *xAODCluster = xAODContainer->push_back(std::make_unique<xAOD::AFPSiHitsCluster>());
216 
217  fillXAOD (stationID, layerID, localCS, localCSError, xAODCluster);
218  xAODCluster->setDepositedCharge(cluster.charge());
219  xAODCluster->setNHits(cluster.hits().size());
220 
221  ATH_MSG_DEBUG("Cluster info: station="<<stationID<<" layer="<<layerID<<" horizID="<<cluster.horizID()<<" vertID="<<cluster.vertID()<<"\tcoordinates: x="<<xAODCluster->xLocal()<<" y="<<xAODCluster->yLocal());
222  ATH_MSG_DEBUG("hits: ");
223  for (const xAOD::AFPSiHit* theHit : cluster.hits() )
224  ATH_MSG_DEBUG("("<<theHit->pixelHorizID()<<", "<<theHit->pixelVertID()<<")");
225 
226  return xAODCluster;
227  } // close try
228  catch (const std::out_of_range& outOfRange) {
229  ATH_MSG_WARNING("Transformation matrix for station or pixel ID outside expected range. Aborting transformation to xAOD.");
230  return nullptr;
231  }
232 }
233 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AFPSiRowColToLocalCSTool::m_transformationsInit
Gaudi::Property< std::vector< double > > m_transformationsInit
Vector containing initial values for m_transformations matrices.
Definition: AFPSiRowColToLocalCSTool.h:96
AFPSiRowColToLocalCSTool::AFPSiRowColToLocalCSTool
AFPSiRowColToLocalCSTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: AFPSiRowColToLocalCSTool.cxx:25
AFPSiClusterBasicObj::charge
double charge() const
charge of the cluster
Definition: AFPSiClusterBasicObj.h:62
AFPSiRowColToLocalCSTool::m_transformationsErr
std::vector< std::vector< ROOT::Math::Transform3D > > m_transformationsErr
Array of transformations that are applied to position uncertainties.
Definition: AFPSiRowColToLocalCSTool.h:103
AFP_constants.h
AFPSiRowColToLocalCSTool::m_numberOfLayersInStations
Gaudi::Property< std::vector< int > > m_numberOfLayersInStations
Vector defining number of stations and number of layers in each station.
Definition: AFPSiRowColToLocalCSTool.h:80
AFPSiRowColToLocalCSTool::m_pixelHorizSize
Gaudi::Property< double > m_pixelHorizSize
Size of the pixel in horizontal direction when mounted (default = 0.05 mm)
Definition: AFPSiRowColToLocalCSTool.h:118
xAOD::AFPSiHit_v2
Class representing a hit in silicon detector.
Definition: AFPSiHit_v2.h:30
AFP::SiGlobAlignData::yShift
double yShift() const
Definition: SiGlobAlignData.h:107
AFP_CONSTANTS::SiT_Plate_zsep
static constexpr double SiT_Plate_zsep
Definition: AFP_constants.h:45
AFPSiRowColToLocalCSTool::fillXAOD
void fillXAOD(const int stationID, const int layerID, const ROOT::Math::XYZPoint &position, const ROOT::Math::XYZPoint &positionError, xAOD::AFPSiHitsCluster *xAODCluster) const
Sets xAOD information about station, layer, position and error based on the ROOT::Math::XYZPoint obje...
Definition: AFPSiRowColToLocalCSTool.cxx:184
xAOD::AFPSiHitsCluster_v1::setXLocal
void setXLocal(float newXLocal)
Set cluster position along X axis in station local coordinate system.
AFPSiRowColToLocalCSTool::m_transformationsErrInit
Gaudi::Property< std::vector< double > > m_transformationsErrInit
Vector containing initial values for m_transformationsErr matrices.
Definition: AFPSiRowColToLocalCSTool.h:111
AFP::SiGlobAlignData::zShift
double zShift() const
Definition: SiGlobAlignData.h:108
xAOD::AFPSiHitsCluster_v1::setYLocal
void setYLocal(float newYLocal)
Set cluster position along Y axis in station local coordinate system.
xAOD::AFPSiHitsCluster_v1::setZLocalErr
void setZLocalErr(float newZLocalErr)
Set uncertainty of cluster position along Z axis in station local coordinate system.
AFP_CONSTANTS::SiT_Plate_rot_xz
static constexpr double SiT_Plate_rot_xz
Definition: AFP_constants.h:46
AFP::SiLocAlignData::alpha
double alpha() const
Rotation angle.
Definition: SiLocAlignData.h:47
AFP::SiGlobAlignData::xShift
double xShift() const
Definition: SiGlobAlignData.h:106
xAOD::AFPSiHitsCluster_v1::setZLocal
void setZLocal(float newZLocal)
Set cluster position along Z axis in station local coordinate system.
AFPSiRowColToLocalCSTool::m_transformations
std::vector< std::vector< ROOT::Math::Transform3D > > m_transformations
Array of transformations that position in each layers.
Definition: AFPSiRowColToLocalCSTool.h:88
AFPSiRowColToLocalCSTool::newXAODLocal
virtual xAOD::AFPSiHitsCluster * newXAODLocal(const int stationID, const int layerID, const AFP::SiLocAlignData &LA, const AFP::SiGlobAlignData &GA, const AFPSiClusterBasicObj &cluster, std::unique_ptr< xAOD::AFPSiHitsClusterContainer > &xAODContainer) const override
Definition: AFPSiRowColToLocalCSTool.cxx:199
AFPSiRowColToLocalCSTool.h
Header file for AFPSiRowColToLocalCSTool.
AFP::SiLocAlignData::gamma
double gamma() const
Rotation angle.
Definition: SiLocAlignData.h:53
AFPSiClusterBasicObj
Class representing basic silicon pixels cluster, designed to be used for creating the clusters.
Definition: AFPSiClusterBasicObj.h:28
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
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
AFPSiRowColToLocalCSTool::finalize
virtual StatusCode finalize() override
does nothing
Definition: AFPSiRowColToLocalCSTool.cxx:180
xAOD::AFPSiHitsCluster_v1::setStationID
void setStationID(int stationID)
Set index of the station with pixel hit.
test_pyathena.parent
parent
Definition: test_pyathena.py:15
Muon::nsw::STGTPSegments::moduleIDBits::stationID
constexpr uint8_t stationID
Large or Small wedge.
Definition: NSWSTGTPDecodeBitmaps.h:152
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
AFP::SiGlobAlignData
Definition: SiGlobAlignData.h:23
xAOD::AFPSiHitsCluster_v1::setYLocalErr
void setYLocalErr(float newYLocalErr)
Set uncertainty of cluster position along Y axis in station local coordinate system.
AFPSiClusterBasicObj::horizID
float horizID() const
horizontal position (ID number) of the cluster (float because it can be weighted mean of hits)
Definition: AFPSiClusterBasicObj.h:42
AFPSiHit.h
AFPSiClusterBasicObj::horizIDErr
float horizIDErr() const
uncertainty of horizontal position (ID number) in fraction
Definition: AFPSiClusterBasicObj.h:47
AFP_CONSTANTS::SiT_Pixel_amount_x
static constexpr double SiT_Pixel_amount_x
Definition: AFP_constants.h:56
xAOD::AFPSiHitsCluster_v1::setPixelLayerID
void setPixelLayerID(int layerID)
Method setting index of the detector layer with the cluster.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AFP::SiLocAlignData::yShift
double yShift() const
Shift of the plane in Y direction with respect to the nominal position.
Definition: SiLocAlignData.h:41
AFPSiRowColToLocalCSTool::initialize
virtual StatusCode initialize() override
Prepare transformation matrices.
Definition: AFPSiRowColToLocalCSTool.cxx:50
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
AFPSiHitContainer.h
AFPSiClusterBasicObj::vertIDErr
float vertIDErr() const
uncertainty of vertical position (ID number) in fraction
Definition: AFPSiClusterBasicObj.h:57
AFP::SiLocAlignData
Class storing information about alignment.
Definition: SiLocAlignData.h:24
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AFP::SiLocAlignData::zShift
double zShift() const
Shift of the plane in Z direction with respect to the nominal position.
Definition: SiLocAlignData.h:44
Amg::Translation3D
Eigen::Translation< double, 3 > Translation3D
Definition: GeoPrimitives.h:44
AFPSiRowColToLocalCSTool::m_pixelVertSize
Gaudi::Property< double > m_pixelVertSize
Size of the pixel in vertical direction when mounted (default = 0.25 mm)
Definition: AFPSiRowColToLocalCSTool.h:124
AFPSiRowColToLocalCSTool::initTransformationMatricesSize
void initTransformationMatricesSize(std::list< std::vector< std::vector< ROOT::Math::Transform3D > > * > &matrices, const std::vector< int > &layersInStations)
The method initialises matrices to have the size defined in layersInStations.
Definition: AFPSiRowColToLocalCSTool.cxx:33
xAOD::AFPSiHitsCluster_v1
Class representing a cluster of AFP pixel hits.
Definition: AFPSiHitsCluster_v1.h:32
AFP::SiLocAlignData::xShift
double xShift() const
Shift of the plane in X direction with respect to the nominal position.
Definition: SiLocAlignData.h:38
AFPSiClusterBasicObj::hits
std::list< const xAOD::AFPSiHit * > & hits()
list of pixels used to form the cluster
Definition: AFPSiClusterBasicObj.h:72
AFPSiClusterBasicObj::vertID
float vertID() const
vertical position (ID number) of the cluster (float because it can be weighted mean of hits)
Definition: AFPSiClusterBasicObj.h:52
xAOD::AFPSiHitsCluster_v1::setXLocalErr
void setXLocalErr(float newXLocalErr)
Set uncertainty of cluster position along X axis in station local coordinate system.
AFP::SiLocAlignData::beta
double beta() const
Rotation angle.
Definition: SiLocAlignData.h:50