Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ITkPixelClusterErrorData.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 
7 #include "GaudiKernel/ISvcLocator.h"
8 
10 
11 #include <fstream>
12 #include <stdexcept>
13 
14 
15 namespace ITk
16 {
17 
19 {
20  SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
21  if(!detStore){
22  throw std::runtime_error("Could not retrieve DetectorStore");
23  }
24  StatusCode sc = detStore->retrieve(m_pixelID, "PixelID");
25  if(sc.isFailure() or (m_pixelID == nullptr)){
26  throw std::runtime_error("Could not retrieve PixelID");
27  }
28  m_constmap.resize(m_pixelID->wafer_hash_max(),std::array<float,kNParam>{});
29 }
30 
31 
32 std::pair<double,double> PixelClusterErrorData::getDelta(IdentifierHash idHash,
33  int sizePhi, double angle,
34  int sizeZ, double eta) const
35 {
36 
37  const std::array<float,kNParam> &value = m_constmap.at(idHash);
38  double period_phi = value[kPeriod_phi];
39  double period_sinheta = value[kPeriod_sinheta];
40  double delta_x_slope = value[kDelta_x_slope];
41  double delta_x_offset = value[kDelta_x_offset];
42  double delta_y_slope = value[kDelta_y_slope];
43  double delta_y_offset = value[kDelta_y_offset];
44 
45  double delta_x = delta_x_slope * fabs(angle - period_phi*(sizePhi-2)) + delta_x_offset;
46  double delta_y = delta_y_slope * fabs(sinh(fabs(eta)) - period_sinheta*(sizeZ-2)) + delta_y_offset;
47  return std::make_pair(delta_x,delta_y);
48 
49 }
50 
51 
52 
53 
54 // SET METHODS
55 
57  float period_phi, float period_sinheta,
58  float delta_x_slope, float delta_x_offset, float error_x,
59  float delta_y_slope, float delta_y_offset, float error_y)
60 {
61  setDeltaError(idHash, std::array<float, kNParam>{period_phi, period_sinheta,
62  delta_x_slope, delta_x_offset, error_x,
63  delta_y_slope, delta_y_offset, error_y});
64 }
65 
66 
67 // save all constants to file
68 void PixelClusterErrorData::print(const std::string& file) const
69 {
70  std::ofstream outfile(file.c_str());
71  for(unsigned int id_hash=0; const std::array<float, kNParam> &values : m_constmap){
72  outfile << id_hash++;
73  for (double a_val : values ) {
74  outfile << " " << a_val;
75  }
76  }
77  outfile.close();
78 }
79 
80 
81 
82 // Load ITk constants from file
83 unsigned int PixelClusterErrorData::load(const std::string& file){
84 
85  std::ifstream infile( file.c_str() );
86  unsigned int n_entries=0;
87  if(infile.is_open()){
88 
89  //
90  // Data in the file is stored in the following columns:
91  // waferID_hash : period_phi : period_sinheta : delta_x_slope : delta_x_offset : delta_error_x : delta_y_slope : delta_y_offset : delta_error_y
92  //
93 
94  int waferID_hash_int;
95  double period_phi;
96  double period_sinheta;
97  double delta_x_slope;
98  double delta_x_offset;
99  double delta_error_x;
100  double delta_y_slope;
101  double delta_y_offset;
102  double delta_error_y;
103 
104  while(!infile.eof()){
105 
106  infile >> waferID_hash_int >> period_phi >> period_sinheta >> delta_x_slope >> delta_x_offset >> delta_error_x >> delta_y_slope >> delta_y_offset >> delta_error_y;
107 
108  IdentifierHash waferID_hash(waferID_hash_int);
109  setDeltaError(waferID_hash,
110  period_phi, period_sinheta,
111  delta_x_slope, delta_x_offset, delta_error_x,
112  delta_y_slope, delta_y_offset, delta_error_y);
113  ++n_entries;
114 
115  }
116 
117  infile.close();
118 
119  } else {
120  throw std::runtime_error("ITkAnalogueClusteringConstantsFile \"" + file + "\" can not be read. Unable to proceed.");
121  }
122  return n_entries;
123 }
124 
125 } // namespace ITk
ITk::PixelClusterErrorData::kDelta_y_slope
@ kDelta_y_slope
Definition: ITkPixelClusterErrorData.h:34
ITkPixelClusterErrorData.h
run.infile
string infile
Definition: run.py:13
ITk::PixelClusterErrorData::kPeriod_phi
@ kPeriod_phi
Definition: ITkPixelClusterErrorData.h:29
athena.value
value
Definition: athena.py:124
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
ITk::PixelClusterErrorData::kDelta_x_offset
@ kDelta_x_offset
Definition: ITkPixelClusterErrorData.h:32
ITk::PixelClusterErrorData::getDelta
std::pair< double, double > getDelta(IdentifierHash idHash, int sizePhi, double angle, int sizeZ, double eta) const
Methods to access the calibration data.
Definition: ITkPixelClusterErrorData.cxx:32
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
angle
double angle(const GeoTrf::Vector2D &a, const GeoTrf::Vector2D &b)
Definition: TRTDetectorFactory_Full.cxx:73
file
TFile * file
Definition: tile_monitor.h:29
ITk::PixelClusterErrorData::print
void print(const std::string &file) const
Definition: ITkPixelClusterErrorData.cxx:68
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
ITk::PixelClusterErrorData::kDelta_y_offset
@ kDelta_y_offset
Definition: ITkPixelClusterErrorData.h:35
ITk
Definition: ITkPixelOfflineCalibCondAlg.cxx:13
PixelID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: PixelID.cxx:831
ITk::PixelClusterErrorData::m_pixelID
const PixelID * m_pixelID
Definition: ITkPixelClusterErrorData.h:85
ITk::PixelClusterErrorData::load
unsigned int load(const std::string &file)
load cluster error data from ascii file
Definition: ITkPixelClusterErrorData.cxx:83
ITk::PixelClusterErrorData::kPeriod_sinheta
@ kPeriod_sinheta
Definition: ITkPixelClusterErrorData.h:30
ITk::PixelClusterErrorData::initialize
void initialize()
Definition: ITkPixelClusterErrorData.cxx:18
ITk::PixelClusterErrorData::kDelta_x_slope
@ kDelta_x_slope
Definition: ITkPixelClusterErrorData.h:31
ITk::PixelClusterErrorData::m_constmap
std::vector< std::array< float, kNParam > > m_constmap
Definition: ITkPixelClusterErrorData.h:83
ITk::PixelClusterErrorData::setDeltaError
void setDeltaError(IdentifierHash idHash, float period_phi, float period_sinheta, float delta_x_slope, float delta_x_offset, float error_x, float delta_y_slope, float delta_y_offset, float error_y)
Definition: ITkPixelClusterErrorData.cxx:56
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
PrepareReferenceFile.outfile
outfile
Definition: PrepareReferenceFile.py:42
StoreGateSvc.h