ATLAS Offline Software
ITkPixelClusterErrorData.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 
7 #include "GaudiKernel/ISvcLocator.h"
8 
10 #include "StoreGate/StoreGateSvc.h"
11 
12 #include <fstream>
13 #include <string>
14 #include <stdexcept>
15 
16 
17 namespace ITk
18 {
19 
21 {
22  SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
23  if(!detStore){
24  throw std::runtime_error("Could not retrieve DetectorStore");
25  }
26  StatusCode sc = detStore->retrieve(m_pixelID, "PixelID");
27  if(sc.isFailure()){
28  throw std::runtime_error("Could not retrieve PixelID");
29  }
30 
31 }
32 
33 
34 std::pair<double,double> PixelClusterErrorData::getDelta(const Identifier* pixelId,
35  int sizePhi, double angle,
36  int sizeZ, double eta) const
37 {
38 
39  std::vector<double> value = m_constmap.at(*pixelId);
40  double period_phi = value[0];
41  double period_sinheta = value[1];
42  double delta_x_slope = value[2];
43  double delta_x_offset = value[3];
44  double delta_y_slope = value[5];
45  double delta_y_offset = value[6];
46 
47  double delta_x = delta_x_slope * fabs(angle - period_phi*(sizePhi-2)) + delta_x_offset;
48  double delta_y = delta_y_slope * fabs(sinh(fabs(eta)) - period_sinheta*(sizeZ-2)) + delta_y_offset;
49 
50  return std::make_pair(delta_x,delta_y);
51 
52 }
53 
54 
55 std::pair<double,double> PixelClusterErrorData::getDeltaError(const Identifier* pixelId) const
56 {
57 
58  std::vector<double> value = m_constmap.at(*pixelId);
59 
60  double delta_x_error = value[4];
61  double delta_y_error = value[7];
62 
63  return std::make_pair(delta_x_error,delta_y_error);
64 
65 }
66 
67 
68 // SET METHODS
69 
71  double period_phi, double period_sinheta,
72  double delta_x_slope, double delta_x_offset, double error_x,
73  double delta_y_slope, double delta_y_offset, double error_y)
74 {
75 
76  std::vector<double> linevalues = {period_phi, period_sinheta,
77  delta_x_slope, delta_x_offset, error_x,
78  delta_y_slope, delta_y_offset, error_y};
79 
80  m_constmap[*pixelId] = linevalues;
81 
82 }
83 
84 
85 // save all constants to file
86 void PixelClusterErrorData::print(const std::string& file) const
87 {
88 
89  std::ofstream outfile(file.c_str());
90 
91  for(const auto & x : m_constmap){
92 
93  std::vector<double> value = x.second;
94  outfile << m_pixelID->wafer_hash(x.first) << " " << value[0] << " " << value[1] << " " << value[2] << " " << value[3] << " " << value[4] << " " << value[5] << " " << value[6] << " " << value[7] << std::endl;
95 
96  }
97 
98  outfile.close();
99 }
100 
101 
102 
103 // Load ITk constants from file
104 void PixelClusterErrorData::load(const std::string& file){
105 
106  std::ifstream infile( file.c_str() );
107 
108  if(infile.is_open()){
109 
110  //
111  // Data in the file is stored in the following columns:
112  // waferID_hash : period_phi : period_sinheta : delta_x_slope : delta_x_offset : delta_error_x : delta_y_slope : delta_y_offset : delta_error_y
113  //
114 
115  int waferID_hash_int;
116  double period_phi;
117  double period_sinheta;
118  double delta_x_slope;
119  double delta_x_offset;
120  double delta_error_x;
121  double delta_y_slope;
122  double delta_y_offset;
123  double delta_error_y;
124 
125  while(!infile.eof()){
126 
127  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;
128 
129  IdentifierHash waferID_hash(waferID_hash_int);
130  Identifier pixelId = m_pixelID->wafer_id(waferID_hash);
131  setDeltaError(&pixelId,
132  period_phi, period_sinheta,
133  delta_x_slope, delta_x_offset, delta_error_x,
134  delta_y_slope, delta_y_offset, delta_error_y);
135 
136  }
137 
138  infile.close();
139 
140  } else {
141  throw std::runtime_error("ITkAnalogueClusteringConstantsFile \"" + file + "\" can not be read. Unable to proceed.");
142  }
143 
144 }
145 
146 } // namespace ITk
ITkPixelClusterErrorData.h
run.infile
string infile
Definition: run.py:13
ITk::PixelClusterErrorData::load
void load(const std::string &file)
Definition: ITkPixelClusterErrorData.cxx:104
ITk::PixelClusterErrorData::setDeltaError
void setDeltaError(const Identifier *pixelId, double period_phi, double period_sinheta, double delta_x_slope, double delta_x_offset, double error_x, double delta_y_slope, double delta_y_offset, double error_y)
Definition: ITkPixelClusterErrorData.cxx:70
athena.value
value
Definition: athena.py:124
x
#define x
PixelID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
For a single crystal.
Definition: PixelID.h:364
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
PixelID::wafer_hash
IdentifierHash wafer_hash(Identifier wafer_id) const
wafer hash from id
Definition: PixelID.h:387
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:86
ITk::PixelClusterErrorData::Initialize
void Initialize()
Definition: ITkPixelClusterErrorData.cxx:20
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
ITk::PixelClusterErrorData::getDeltaError
std::pair< double, double > getDeltaError(const Identifier *pixelId) const
Definition: ITkPixelClusterErrorData.cxx:55
ITk
Definition: ITkPixelOfflineCalibCondAlg.cxx:14
IdentifierHash.h
ITk::PixelClusterErrorData::m_pixelID
const PixelID * m_pixelID
Definition: ITkPixelClusterErrorData.h:49
ITk::PixelClusterErrorData::getDelta
std::pair< double, double > getDelta(const Identifier *pixelId, int sizePhi, double angle, int sizeZ, double eta) const
Methods to access the calibration data.
Definition: ITkPixelClusterErrorData.cxx:34
ITk::PixelClusterErrorData::m_constmap
std::map< const Identifier, std::vector< double > > m_constmap
Definition: ITkPixelClusterErrorData.h:47
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
Identifier
Definition: IdentifierFieldParser.cxx:14