ATLAS Offline Software
TRTPhaseCondAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TRTPhaseCondAlg.h"
9 
11  , ISvcLocator* pSvcLocator )
12  : ::AthAlgorithm(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
26 
27  // Register write handle
29 
30  // TRT ID helper
31  ATH_CHECK(detStore()->retrieve(m_trtId,"TRT_ID"));
32 
33  return StatusCode::SUCCESS;
34 }
35 
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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TRTPhaseCondAlg.h
TRTPhaseCondAlg::initialize
virtual StatusCode initialize() override
Definition: TRTPhaseCondAlg.cxx:19
TRT_ID::straw_max
int straw_max(const Identifier &id) const
Definition: TRT_ID.cxx:996
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
RtRelation.h
abstract base class for rt-relations
skel.it
it
Definition: skel.GENtoEVGEN.py:396
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
TRTPhaseCondAlg::m_trtId
const TRT_ID * m_trtId
Definition: TRTPhaseCondAlg.h:33
BasicRtRelation.h
TRT_ID::straw_layer_end
const_id_iterator straw_layer_end(void) const
Definition: TRT_ID.h:961
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
TRTCond::RtRelation
Definition: RtRelation.h:27
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
TRTPhaseCondAlg::m_caldbtool
ToolHandle< ITRT_CalDbTool > m_caldbtool
Definition: TRTPhaseCondAlg.h:32
TRTCond::RtRelation::drifttime
virtual float drifttime(float radius) const =0
drifttime for given radius
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
TRTPhaseCondAlg::m_T0ReadKey
SG::ReadCondHandleKey< StrawT0Container > m_T0ReadKey
Definition: TRTPhaseCondAlg.h:30
TRTPhaseCondAlg::m_T0WriteKey
SG::WriteCondHandleKey< TRTCond::AverageT0 > m_T0WriteKey
Definition: TRTPhaseCondAlg.h:31
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TRT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: TRT_ID.h:866
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
AthAlgorithm
Definition: AthAlgorithm.h:47
TRTPhaseCondAlg::~TRTPhaseCondAlg
virtual ~TRTPhaseCondAlg() override
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TRTPhaseCondAlg::finalize
virtual StatusCode finalize() override
Definition: TRTPhaseCondAlg.cxx:131
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
TRTPhaseCondAlg::execute
virtual StatusCode execute() override
Definition: TRTPhaseCondAlg.cxx:36
TRTPhaseCondAlg::TRTPhaseCondAlg
TRTPhaseCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TRTPhaseCondAlg.cxx:10
TRT_ID::straw_layer_begin
const_id_iterator straw_layer_begin(void) const
Iterators over full set of straw_layer ids. Straw_layer ids are sorted.
Definition: TRT_ID.h:953
TRTCond::StrawT0MultChanContainer
Definition: StrawT0MultChanContainer.h:31
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
TRT_ID::straw_id
Identifier straw_id(int barrel_ec, int phi_module, int layer_or_wheel, int straw_layer, int straw) const
Three ways of getting id for a single straw:
Definition: TRT_ID.h:581
Identifier
Definition: IdentifierFieldParser.cxx:14