ATLAS Offline Software
Loading...
Searching...
No Matches
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"
9
10TRTPhaseCondAlg::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
18
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
36StatusCode TRTPhaseCondAlg::execute(const EventContext& ctx) const
37{
38 ATH_MSG_DEBUG("execute " << name());
39
40 // ____________ Construct Write Cond Handle and check its validity ____________
41
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
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
132{
133 ATH_MSG_DEBUG("finalize " << name());
134 return StatusCode::SUCCESS;
135}
136
137
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
abstract base class for rt-relations
This is an Identifier helper class for the TRT subdetector.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
Base class for conditions algorithms.
bool range(EventIDRange &r)
const std::string & key() const
const std::string & key() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
Base class for rt-relations in the TRT.
Definition RtRelation.h:27
virtual float drifttime(float radius) const =0
drifttime for given radius
TRTPhaseCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode finalize() override
ToolHandle< ITRT_CalDbTool > m_caldbtool
SG::ReadCondHandleKey< StrawT0Container > m_T0ReadKey
virtual StatusCode initialize() override
TRTCond::StrawT0MultChanContainer StrawT0Container
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteCondHandleKey< TRTCond::AverageT0 > m_T0WriteKey
const TRT_ID * m_trtId
virtual ~TRTPhaseCondAlg() override