ATLAS Offline Software
SiDistWriteAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // SiDistWriteAlg.cxx
6 // Richard Hawkings, started 27/3/07
7 // simple algorithm to manage silicon (PIXEL/SCT) module distortion data
8 
9 #include <fstream>
10 #include <iostream>
11 
13 #include "InDetIdentifier/SCT_ID.h"
16 
17 SiDistWriteAlg::SiDistWriteAlg(const std::string& name, ISvcLocator* pSvcLocator)
18  :AthAlgorithm (name, pSvcLocator),
19 
20  m_pixid(nullptr),m_sctid(nullptr),
21  m_first(true),
22  m_par_print(false),
23  m_par_size(3),
24  m_par_readfile(""),
25  m_par_distkey("/Indet/PixelDist")
26 {
27 
28 
30  declareProperty("ReadFile",m_par_readfile);
31  declareProperty("ArraySize",m_par_size);
32  declareProperty("KeyName",m_par_distkey);
33 }
34 
36 {}
37 
39 {
40  ATH_MSG_DEBUG( "SiDistWriteAlg::initialize()" );
41  // check StoreGate service available
43 
44  // get detector store
46 
47 
48  // get identifier helpers
49  if ((StatusCode::SUCCESS!=detStore()->retrieve(m_pixid)) ||
50  (StatusCode::SUCCESS!=detStore()->retrieve(m_sctid))) {
51  ATH_MSG_ERROR( "Could not get helpers from detector store");
52  }
53  ATH_MSG_DEBUG( "Distortion information in TDS at key " <<
54  m_par_distkey );
55  if (!m_par_readfile.empty())
56  ATH_MSG_DEBUG ( "Read distortion parameters from file"
57  << m_par_readfile );
59  "Distortion information will be printed on first event" );
60  return StatusCode::SUCCESS;
61 }
62 
64  return StatusCode::SUCCESS;
65 }
66 
68  if (m_first) {
69  if (!m_par_readfile.empty()) readFile();
70  if (m_par_print) print();
71  m_first=false;
72  }
73  return StatusCode::SUCCESS;
74 }
75 
77  // create structure in TDS
78  ATH_MSG_DEBUG ( "Create new DetCondCFloat of size " << m_par_size
79  << " in TDS" );
80  std::unique_ptr<DetCondCFloat> pdist(new DetCondCFloat(m_par_size,m_par_distkey));
81  // read data from text file
82  ATH_MSG_DEBUG ( "Opening text file " << m_par_readfile <<
83  " to get distortion data" );
84  std::ifstream infile;
85  infile.open(m_par_readfile.c_str());
86  if (!infile) {
87  ATH_MSG_ERROR( "Problem opening input file" );
88  return false;
89  }
90  // loop over lines in file
91  int nline=0;
92  int nadd=0;
93  while (infile) {
94  std::string tmpline;
95  std::getline(infile,tmpline);
96  if (!infile) break;
97  std::istringstream instring(tmpline);
98  std::string ident;
99  Identifier32::value_type identhash;
100  float x,y,z;
101  instring >> ident >> identhash >> x >> y >> z;
102  ATH_MSG_DEBUG( "Read identifier: " << ident << " hash " <<
103  identhash << " x" << x << " y " << y << " z " << z );
104  // construct the identifier and crosscheck
106  if (makeIdent(ident,identhash,identifier)) {
107  float fbuf[3];
108  fbuf[0]=x;
109  fbuf[1]=y;
110  fbuf[2]=z;
111  pdist->add(identifier,fbuf);
112  ++nadd;
113  } else {
114  ATH_MSG_ERROR( "Problem constructing identifier " << ident << " / " << identhash);
115  }
116  ++nline;
117  }
118  infile.close();
119  ATH_MSG_DEBUG ( "Read distortions for " << nline << " modules" <<
120  " of which " << nadd << " successfully added" );
121  // record in StoreGate
122  if (StatusCode::SUCCESS==detStore()->record(std::move(pdist),m_par_distkey)) {
123  ATH_MSG_DEBUG ( "Recorded DetCondCFloat " << m_par_distkey << " in TDS" );
124  } else {
125  ATH_MSG_ERROR("Failed to record DetCondCFloat " << m_par_distkey << " in TDS");
126  return false;
127  }
128  return true;
129 }
130 
131 bool SiDistWriteAlg::makeIdent(const std::string& ident,
132  const Identifier32::value_type identhash, Identifier& identifier) {
133  // parse the [a.b.c.d.e.f.CLHEP::g] string to extract 7 fields
134  // remove the leading [ immediately
135  std::string lident=ident.substr(1);
136  for (unsigned int i=0;i<lident.size();++i) {
137  // transform ] and . to spaces
138  if (lident[i]==']' || lident[i]=='.') lident[i]=' ';
139  }
140  std::istringstream instring(lident);
141  int atlas{},det{},bec{},layer{},phi{},eta,side{};
142  instring >> atlas >> det >> bec >> layer >> phi >> eta >> side;
143  if ((bec<-2) or (bec>2)){
144  ATH_MSG_ERROR("bec value is "<<bec);
145  }
146  if (det==1) {
148  } else if (det==2) {
150  } else {
151  ATH_MSG_ERROR( "Unknown detector type " << det);
152  return false;
153  }
154  // cross check with the supplied identifier compact value
155  // (get 32-bit part, as it's only a wafer_id)
156  return (identifier.get_identifier32().get_compact()==identhash);
157 }
158 
160  ATH_MSG_DEBUG ( "Print distortion parameters at " << m_par_distkey );
161  // retrieve distortions from Storegate and print in detail
162  const DetCondCFloat* pdist=nullptr;
163  if (StatusCode::SUCCESS==detStore()->retrieve(pdist,m_par_distkey)) {
164  pdist->print2();
165  } else {
166  ATH_MSG_ERROR( "Unable to retrieve distortion parameters " );
167  }
168 }
SiDistWriteAlg.h
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
SiDistWriteAlg::readFile
bool readFile()
Definition: SiDistWriteAlg.cxx:76
DetCondCFloat::print2
void print2() const
Definition: DetCondCFloat.cxx:61
DetCondCFloat
DetCondCFloat is a class to hold sets of Identifiers and arrays of floats for detector element specif...
Definition: DetCondCFloat.h:45
SiDistWriteAlg::~SiDistWriteAlg
~SiDistWriteAlg()
Definition: SiDistWriteAlg.cxx:35
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
SiDistWriteAlg::m_par_print
bool m_par_print
Definition: SiDistWriteAlg.h:31
run.infile
string infile
Definition: run.py:13
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
SiDistWriteAlg::m_pixid
const PixelID * m_pixid
Definition: SiDistWriteAlg.h:27
SiDistWriteAlg::m_par_distkey
std::string m_par_distkey
Definition: SiDistWriteAlg.h:34
Identifier32::value_type
unsigned int value_type
Definition: Identifier32.h:33
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
SiDistWriteAlg::m_sctid
const SCT_ID * m_sctid
Definition: SiDistWriteAlg.h:28
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
SiDistWriteAlg::execute
StatusCode execute()
Definition: SiDistWriteAlg.cxx:67
SiDistWriteAlg::m_first
bool m_first
Definition: SiDistWriteAlg.h:29
xAOD::identifier
identifier
Definition: UncalibratedMeasurement_v1.cxx:15
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
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
TRT::Hit::side
@ side
Definition: HitInfo.h:83
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
SiDistWriteAlg::SiDistWriteAlg
SiDistWriteAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SiDistWriteAlg.cxx:17
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
z
#define z
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
DetCondCFloat::add
int add(const Identifier &ident, const float *f)
Definition: DetCondCFloat.cxx:13
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
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
SiDistWriteAlg::makeIdent
bool makeIdent(const std::string &ident, const Identifier32::value_type identhash, Identifier &identifier)
Definition: SiDistWriteAlg.cxx:131
WritePulseShapeToCool.det
det
Definition: WritePulseShapeToCool.py:204
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthAlgorithm
Definition: AthAlgorithm.h:47
SiDistWriteAlg::m_par_size
int m_par_size
Definition: SiDistWriteAlg.h:32
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SiDistWriteAlg::m_par_readfile
std::string m_par_readfile
Definition: SiDistWriteAlg.h:33
TRT::Hit::ident
@ ident
Definition: HitInfo.h:77
y
#define y
SiDistWriteAlg::print
void print()
Definition: SiDistWriteAlg.cxx:159
SiDistWriteAlg::initialize
StatusCode initialize()
Definition: SiDistWriteAlg.cxx:38
DetCondCFloat.h
SCT_ID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module, int side) const
For a single side of module.
Definition: SCT_ID.h:464
SiDistWriteAlg::finalize
StatusCode finalize()
Definition: SiDistWriteAlg.cxx:63