ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetAlignAlgs
InDetAlignGenAlgs
src
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
12
#include "
InDetIdentifier/PixelID.h
"
13
#include "
InDetIdentifier/SCT_ID.h
"
14
#include "
DetDescrConditions/DetCondCFloat.h
"
15
#include "
InDetAlignGenAlgs/SiDistWriteAlg.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
29
declareProperty
(
"Print"
,
m_par_print
);
30
declareProperty
(
"ReadFile"
,
m_par_readfile
);
31
declareProperty
(
"ArraySize"
,
m_par_size
);
32
declareProperty
(
"KeyName"
,
m_par_distkey
);
33
}
34
35
SiDistWriteAlg::~SiDistWriteAlg
()
36
{}
37
38
StatusCode
SiDistWriteAlg::initialize
()
39
{
40
ATH_MSG_DEBUG
(
"SiDistWriteAlg::initialize()"
);
41
// check StoreGate service available
42
ATH_CHECK
(
evtStore
().retrieve());
43
44
// get detector store
45
ATH_CHECK
(
detStore
().retrieve());
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
);
58
if
(
m_par_print
)
ATH_MSG_DEBUG
(
59
"Distortion information will be printed on first event"
);
60
return
StatusCode::SUCCESS;
61
}
62
63
StatusCode
SiDistWriteAlg::finalize
() {
64
return
StatusCode::SUCCESS;
65
}
66
67
StatusCode
SiDistWriteAlg::execute
(
const
EventContext&
/*ctx*/
) {
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
76
bool
SiDistWriteAlg::readFile
() {
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
105
Identifier
identifier;
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) {
147
identifier=
m_pixid
->wafer_id(bec,layer,
phi
,
eta
);
148
}
else
if
(det==2) {
149
identifier=
m_sctid
->wafer_id(bec,layer,
phi
,
eta
,side);
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
159
void
SiDistWriteAlg::print
() {
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
}
eta
Scalar eta() const
pseudorapidity method
Definition
AmgMatrixBasePlugin.h:83
phi
Scalar phi() const
phi method
Definition
AmgMatrixBasePlugin.h:67
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
DetCondCFloat.h
PixelID.h
This is an Identifier helper class for the Pixel subdetector.
SCT_ID.h
This is an Identifier helper class for the SCT subdetector.
SiDistWriteAlg.h
y
#define y
x
#define x
z
#define z
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AthCommonAlgorithm< Gaudi::Algorithm >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
AthCommonAlgorithm< Gaudi::Algorithm >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
AthCommonAlgorithm< Gaudi::Algorithm >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
Definition
AthCommonDataStore.h:95
DetCondCFloat
DetCondCFloat is a class to hold sets of Identifiers and arrays of floats for detector element specif...
Definition
DetCondCFloat.h:45
DetCondCFloat::print2
void print2() const
Definition
DetCondCFloat.cxx:61
Identifier32::value_type
unsigned int value_type
Definition
Identifier32.h:31
SiDistWriteAlg::execute
StatusCode execute(const EventContext &ctx)
Execute method.
Definition
SiDistWriteAlg.cxx:67
SiDistWriteAlg::m_par_readfile
std::string m_par_readfile
Definition
SiDistWriteAlg.h:33
SiDistWriteAlg::print
void print()
Definition
SiDistWriteAlg.cxx:159
SiDistWriteAlg::m_sctid
const SCT_ID * m_sctid
Definition
SiDistWriteAlg.h:28
SiDistWriteAlg::makeIdent
bool makeIdent(const std::string &ident, const Identifier32::value_type identhash, Identifier &identifier)
Definition
SiDistWriteAlg.cxx:131
SiDistWriteAlg::m_par_distkey
std::string m_par_distkey
Definition
SiDistWriteAlg.h:34
SiDistWriteAlg::m_pixid
const PixelID * m_pixid
Definition
SiDistWriteAlg.h:27
SiDistWriteAlg::finalize
StatusCode finalize()
Definition
SiDistWriteAlg.cxx:63
SiDistWriteAlg::readFile
bool readFile()
Definition
SiDistWriteAlg.cxx:76
SiDistWriteAlg::~SiDistWriteAlg
~SiDistWriteAlg()
Definition
SiDistWriteAlg.cxx:35
SiDistWriteAlg::m_par_print
bool m_par_print
Definition
SiDistWriteAlg.h:31
SiDistWriteAlg::SiDistWriteAlg
SiDistWriteAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
SiDistWriteAlg.cxx:17
SiDistWriteAlg::m_par_size
int m_par_size
Definition
SiDistWriteAlg.h:32
SiDistWriteAlg::m_first
bool m_first
Definition
SiDistWriteAlg.h:29
SiDistWriteAlg::initialize
StatusCode initialize()
Definition
SiDistWriteAlg.cxx:38
Identifier
Definition
IdentifierFieldParser.cxx:14
Generated on
for ATLAS Offline Software by
1.17.0