ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetConditions
TRT_ConditionsAlgs
src
TRTPhaseCondAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
TRTPhaseCondAlg.h
"
6
#include "
TRT_ConditionsData/RtRelation.h
"
7
#include "
TRT_ConditionsData/BasicRtRelation.h
"
8
#include "
InDetIdentifier/TRT_ID.h
"
9
10
TRTPhaseCondAlg::TRTPhaseCondAlg
(
const
std::string& name
11
, ISvcLocator* pSvcLocator )
12
: ::
AthCondAlgorithm
(name,pSvcLocator),
13
m_caldbtool
(
"TRT_CalDbTool"
,this),
14
m_trtId
(nullptr)
15
{
declareProperty
(
"TRTCalDbTool"
,
m_caldbtool
); }
16
17
TRTPhaseCondAlg::~TRTPhaseCondAlg
()=
default
;
18
19
StatusCode
TRTPhaseCondAlg::initialize
()
20
{
21
// Straw status
22
ATH_CHECK
(
m_caldbtool
.retrieve() );
23
24
// Read key
25
ATH_CHECK
(
m_T0ReadKey
.initialize() );
26
27
// Register write handle
28
ATH_CHECK
(
m_T0WriteKey
.initialize() );
29
30
// TRT ID helper
31
ATH_CHECK
(
detStore
()->retrieve(
m_trtId
,
"TRT_ID"
));
32
33
return
StatusCode::SUCCESS;
34
}
35
36
StatusCode
TRTPhaseCondAlg::execute
(
const
EventContext& ctx)
const
37
{
38
ATH_MSG_DEBUG
(
"execute "
<< name());
39
40
// ____________ Construct Write Cond Handle and check its validity ____________
41
42
SG::WriteCondHandle<TRTCond::AverageT0>
writeHandle{
m_T0WriteKey
, ctx};
43
44
// Do we have a valid Write Cond Handle for current time?
45
if
(writeHandle.
isValid
()) {
46
ATH_MSG_DEBUG
(
"CondHandle "
<< writeHandle.
fullKey
() <<
" is already valid."
47
<<
". In theory this should not be called, but may happen"
48
<<
" if multiple concurrent events are being processed out of order."
);
49
50
return
StatusCode::SUCCESS;
51
}
52
53
54
55
// ____________ Construct new Write Cond Object ____________
56
std::unique_ptr<TRTCond::AverageT0> writeCdo{std::make_unique<TRTCond::AverageT0>()};
57
58
59
// ____________ Average T0 for Write Cond object (code adapted from InDetCosmicsEventPhaseTool::beginRun()) _____
60
int
countAverageT0 = 0;
61
double
rtShift = 0.;
62
double
averageT0 = 0.;
63
64
for
(std::vector<Identifier>::const_iterator it =
m_trtId
->straw_layer_begin(); it !=
m_trtId
->straw_layer_end(); ++it ) {
65
66
int
nStrawsInLayer =
m_trtId
->straw_max(*it);
67
68
for
(
int
i = 0; i <= nStrawsInLayer; i++) {
69
Identifier
id
=
m_trtId
->straw_id(*it, i);
70
if
(std::abs(
m_trtId
->barrel_ec(
id
)) != 1)
continue
;
// average over barrel only
71
averageT0 +=
m_caldbtool
->getT0(
id
);
72
countAverageT0++;
73
const
TRTCond::RtRelation
* rtRelation =
m_caldbtool
->getRtRelation(
id
);
74
if
(!rtRelation) {
75
ATH_MSG_DEBUG
(
"rtRelation missing for straw "
);
76
continue
;
77
}
78
rtShift += rtRelation->
drifttime
(0.);
79
}
80
}
81
if
(countAverageT0 != 0){
82
averageT0 /= double(countAverageT0);
83
}
else
{
84
averageT0 = 0.;
85
}
86
87
if
(countAverageT0 != 0) {
88
rtShift /= double(countAverageT0);
89
}
else
{
90
rtShift = 0.;
91
}
92
93
double
evtPhaseT0 = averageT0-20.+rtShift;
// (Correction to be checked /PH)
94
95
ATH_MSG_INFO
(
" Subtracting: "
<< evtPhaseT0 <<
" ns (average T0: "
<< averageT0 <<
" ns, average t(r=0): "
<< rtShift <<
" ns )"
);
96
97
writeCdo->update(evtPhaseT0);
98
99
//__________ Assign range of writeCdo to that of the ReadHandle___________
100
EventIDRange rangeW;
101
102
SG::ReadCondHandle<StrawT0Container>
T0ReadHandle{
m_T0ReadKey
, ctx};
103
const
StrawT0Container
* T0Container{*T0ReadHandle};
104
if
(T0Container==
nullptr
) {
105
ATH_MSG_ERROR
(
"Null pointer to the straw T0 container"
);
106
return
StatusCode::FAILURE;
107
}
108
109
// Get range
110
if
(!T0ReadHandle.
range
(rangeW)) {
111
ATH_MSG_ERROR
(
"Failed to retrieve validity range for "
<< T0ReadHandle.
key
());
112
return
StatusCode::FAILURE;
113
}
114
115
116
// Record CDO
117
if
(writeHandle.
record
(rangeW,std::move(writeCdo)).isFailure()) {
118
ATH_MSG_ERROR
(
"Could not record AverageT0 "
<< writeHandle.
key
()
119
<<
" with EventRange "
<< rangeW
120
<<
" into Conditions Store"
);
121
return
StatusCode::FAILURE;
122
}
else
{
123
ATH_MSG_INFO
(
" Recorded AverageT0 "
<< writeHandle.
key
()
124
<<
" with EventRange "
<< rangeW
125
<<
" into Conditions Store"
);
126
127
}
128
return
StatusCode::SUCCESS;
129
}
130
131
StatusCode
TRTPhaseCondAlg::finalize
()
132
{
133
ATH_MSG_DEBUG
(
"finalize "
<< name());
134
return
StatusCode::SUCCESS;
135
}
136
137
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_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
BasicRtRelation.h
RtRelation.h
abstract base class for rt-relations
TRTPhaseCondAlg.h
TRT_ID.h
This is an Identifier helper class for the TRT subdetector.
AthCommonAlgorithm< Gaudi::Algorithm >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
AthCommonAlgorithm< Gaudi::Algorithm >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
Definition
AthCommonDataStore.h:95
AthCondAlgorithm
Base class for conditions algorithms.
Definition
AthCondAlgorithm.h:22
SG::ReadCondHandle
Definition
ReadCondHandle.h:40
SG::ReadCondHandle::range
bool range(EventIDRange &r)
Definition
ReadCondHandle.h:223
SG::ReadCondHandle::key
const std::string & key() const
Definition
ReadCondHandle.h:59
SG::WriteCondHandle
Definition
WriteCondHandle.h:26
SG::WriteCondHandle::key
const std::string & key() const
Definition
WriteCondHandle.h:44
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition
WriteCondHandle.h:161
SG::WriteCondHandle::isValid
bool isValid() const
Definition
WriteCondHandle.h:252
SG::WriteCondHandle::fullKey
const DataObjID & fullKey() const
Definition
WriteCondHandle.h:45
TRTCond::RtRelation
Base class for rt-relations in the TRT.
Definition
RtRelation.h:27
TRTCond::RtRelation::drifttime
virtual float drifttime(float radius) const =0
drifttime for given radius
TRTPhaseCondAlg::TRTPhaseCondAlg
TRTPhaseCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
TRTPhaseCondAlg.cxx:10
TRTPhaseCondAlg::finalize
virtual StatusCode finalize() override
Definition
TRTPhaseCondAlg.cxx:131
TRTPhaseCondAlg::m_caldbtool
ToolHandle< ITRT_CalDbTool > m_caldbtool
Definition
TRTPhaseCondAlg.h:32
TRTPhaseCondAlg::m_T0ReadKey
SG::ReadCondHandleKey< StrawT0Container > m_T0ReadKey
Definition
TRTPhaseCondAlg.h:30
TRTPhaseCondAlg::initialize
virtual StatusCode initialize() override
Definition
TRTPhaseCondAlg.cxx:19
TRTPhaseCondAlg::StrawT0Container
TRTCond::StrawT0MultChanContainer StrawT0Container
Definition
TRTPhaseCondAlg.h:20
TRTPhaseCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
TRTPhaseCondAlg.cxx:36
TRTPhaseCondAlg::m_T0WriteKey
SG::WriteCondHandleKey< TRTCond::AverageT0 > m_T0WriteKey
Definition
TRTPhaseCondAlg.h:31
TRTPhaseCondAlg::m_trtId
const TRT_ID * m_trtId
Definition
TRTPhaseCondAlg.h:33
TRTPhaseCondAlg::~TRTPhaseCondAlg
virtual ~TRTPhaseCondAlg() override
Identifier
Definition
IdentifierFieldParser.cxx:14
Generated on
for ATLAS Offline Software by
1.17.0