ATLAS Offline Software
TRT_DriftCircleTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // Implementation file for class TRT_DriftCircleTool
8 // (c) ATLAS Detector software
10 // AlgTool used for TRT RDI collection production
12 // Version 1.0 18/02/2003 I.Gavrilenko
14 
15 #include "GaudiKernel/ISvcLocator.h"
16 #include "GaudiKernel/DataSvc.h"
17 #include "GaudiKernel/SmartDataPtr.h"
22 
23 #include "InDetIdentifier/TRT_ID.h"
24 
28 
31 // Constructior
33 
35  const std::string& n,
36  const IInterface* p ):
37  AthAlgTool(t,n,p)
38 {
39  declareInterface<ITRT_DriftCircleTool>(this);
40 }
41 
43 // Destructor
45 
47 
49 // Initialisation
51 
53 {
54 
56 
57  // Get DriftFunction tool servise
58  //
59  if ( m_driftFunctionTool.retrieve().isFailure() ) {
60  ATH_MSG_FATAL( m_driftFunctionTool.propertyName() << ": Failed to retrieve tool " << m_driftFunctionTool.type() );
61  return StatusCode::FAILURE;
62  }
63  ATH_MSG_DEBUG( m_driftFunctionTool.propertyName() << ": Retrieved tool " << m_driftFunctionTool.type() );
64 
66  if ( m_ConditionsSummary.retrieve().isFailure() ) {
67  ATH_MSG_FATAL( "Failed to retrieve "<< m_ConditionsSummary);
68  return StatusCode::FAILURE;
69  }
70  ATH_MSG_DEBUG( "Retrieved tool " << m_ConditionsSummary);
71  }
72 
73  // Get TRT ID helper
74  sc = detStore()->retrieve(m_trtid,"TRT_ID");
75  if ( sc.isFailure() ) {
76  ATH_MSG_FATAL( "Could not retrieve TRT ID helper." );
77  return sc;
78  }
79 
81  if (m_lumiDataKey.key().empty()) {
82  ATH_MSG_DEBUG("Luminosity conditions data key not set. No mu correction." );
83  }
84 
85  // Initialize readCondHandle key
87 
88  return sc;
89 }
90 
92 // Finalize
94 
96 {
98 }
99 
101 // Test validity gate
103 bool InDet::TRT_DriftCircleTool::passValidityGate(unsigned int word, float lowGate, float highGate, float t0) const
104 {
105  bool foundInterval = false;
106  unsigned mask = 0x02000000;
107  int i = 0;
108  while ( !foundInterval && (i < 24) ) {
109  if (word & mask) {
110  float thisTime = ((0.5+i)*3.125)-t0;
111  if (thisTime >= lowGate && thisTime <= highGate) foundInterval = true;
112  }
113  mask >>= 1;
114  if (i == 7 || i == 15)
115  mask >>= 1;
116  i++;
117  }
118  return foundInterval;
119 }
120 
121 
123 // Trk::TRT_DriftCircles collection production
125 
128  int Mode,
130  const EventContext& ctx,
131  DataPool<TRT_DriftCircle>* dataItemsPool,
132  const bool getTRTBadChannel) const
133 {
134 
135  //Initialise a new TRT_DriftCircleCollection
136  InDet::TRT_DriftCircleCollection* rio = nullptr;
137 
138  if (!rdo) {
139  ATH_MSG_ERROR("empty TRT raw data collection");
140  return rio;
141  }
142 
144  const InDetDD::TRT_DetElementCollection* elements(trtDetEleHandle->getElements());
145  if (not trtDetEleHandle.isValid() or elements==nullptr) {
146  ATH_MSG_FATAL(m_trtDetEleContKey.fullKey() << " is not available.");
147  return rio;
148  }
149 
150  float mu = 0;
151  if (!m_lumiDataKey.empty()) {
153  mu = lumiData->lbAverageInteractionsPerCrossing();
154  }
155 
157 
158  //Get the BaseElement and initialize the RIO collection
159  IdentifierHash IHc = rdo ->identifyHash();
160  const InDetDD::TRT_BaseElement* pE = elements->getDetectorElement(IHc);
161  rio = new InDet::TRT_DriftCircleCollection(IHc);
162  rio->setIdentifier(rdo->identify());
163  rio->reserve( std::distance(rb, re) );
164  //DataPool will own them if there.
165  if (dataItemsPool) {
166  rio->clear(SG::VIEW_ELEMENTS);
167  }
168 
169  bool isArgonStraw = false;
170  bool isGasSet = false;
171 
172  // Loop through all RDOs in the collection
173  //
174  for(r=rb; r!=re; ++r) {
175 
176  // raw data
177  Identifier id = (*r)->identify();
178  int LTbin = (*r)->driftTimeBin();
179  bool isOK =true;
180  double t0 =0.;
181  double rawTime = m_driftFunctionTool->rawTime(LTbin);
182  unsigned int word = (*r)->getWord();
183 
184  // Gas status - assumed same for all rdo's in the collection
185  if (m_useConditionsHTStatus && !isGasSet) {
186  if (m_ConditionsSummary->getStatusHT(id, ctx) == TRTCond::StrawStatus::Argon ||
187  m_ConditionsSummary->getStatusHT(id, ctx) == TRTCond::StrawStatus::Dead) {
188  isArgonStraw = true;
189  }
190  isGasSet = true;
191  }
192 
193 
194  // ToT and HT Corrections
195  if (m_useToTCorrection) {
196  rawTime -= m_driftFunctionTool->driftTimeToTCorrection((*r)->timeOverThreshold(), id, isArgonStraw);
197  }
198  if (m_useHTCorrection && (*r)->highLevel()) {
199  rawTime += m_driftFunctionTool->driftTimeHTCorrection(id, isArgonStraw);
200  }
201 
202  // calibrated data
203  double radius = 0.;
204  double driftTime = 0.;
205  if( LTbin==0 || LTbin==24) {
206  isOK=false;
207  } else {
208  bool dummy=false;
209  radius = m_driftFunctionTool->driftRadius(rawTime,id,t0,dummy,word);
210  driftTime = rawTime-t0;
211  }
212  if(!isOK) word &= 0xF7FFFFFF;
213  else word |= 0x08000000;
214 
215  // test validity gate
216  rawTime = (0.5+LTbin)*3.125; //redefine rawTime in order to keep Tier0 frozen
217  if (!isArgonStraw) {
219  // reject if first bit true
220  if ((word & 0x02000000) && m_reject_if_first_bit) continue;
221  // or if trailing edge (which is drift time + ToT) is less than min trailing edge
222  if ((rawTime + (*r)->timeOverThreshold()) < m_min_trailing_edge) continue;
223  // if leading edge is too large
224  if (rawTime > m_max_drift_time) continue;
225  }
226 
228  if(!passValidityGate(word, m_low_gate, m_high_gate, t0)) continue;
229  }
230  } else { // is argon straw, in case we want to do anything different for argon straws
232  // reject if first bit true
233  if ((word & 0x02000000) && m_reject_if_first_bit_argon) continue;
234  // or if trailing edge (which is drift time + ToT) is less than min trailing edge
235  if ((rawTime + (*r)->timeOverThreshold()) < m_min_trailing_edge_argon) continue;
236  // or if leading edge is too large
237  if (rawTime > m_max_drift_time_argon) continue;
238  }
239 
242  continue;
243  }
244  }
245 
246  // Require good straw status
247  if (m_useConditionsStatus && getTRTBadChannel) {
248  if (m_ConditionsSummary->getStatus(id,ctx) != TRTCond::StrawStatus::Good)
249  continue;
250  }
251 
252  // Error on Drift Radius
253  double error = 0;
254  // LE out of range. Make tube hit.
255  if (!isOK || Mode > 1) {
256  ATH_MSG_VERBOSE(" Making tube hit.");
257  radius = 0.;
258  error = 4. / sqrt(12.);
259  } else {
260  error =
261  m_driftFunctionTool->errorOfDriftRadius(driftTime, id, mu, word);
262  }
263 
264  // Fill the RIO collection with TRT_DriftCircle's
265  auto errmat = Amg::MatrixX(1,1);
266  errmat(0,0) = error*error;
267  Amg::Vector2D loc(radius, 0.);
268 
269  InDet::TRT_DriftCircle* tdc = nullptr;
270  //
271  if (dataItemsPool) {
272  tdc = dataItemsPool->nextElementPtr();
273  (*tdc) = InDet::TRT_DriftCircle(id, loc, std::move(errmat), pE, word);
274  } else {
275  tdc = new InDet::TRT_DriftCircle(id, loc, std::move(errmat), pE, word);
276  }
277  //
278  if (tdc) {
279  tdc->setHashAndIndex(rio->identifyHash(), rio->size());
280  rio->push_back(tdc);
281 
283  " accept hit id "
284  << m_trtid->barrel_ec(id) << " " << m_trtid->layer_or_wheel(id) << " "
285  << m_trtid->phi_module(id) << " " << m_trtid->straw_layer(id) << " "
286  << m_trtid->straw(id) << " data word " << MSG::hex << tdc->getWord()
287  << MSG::dec << " data word raw " << MSG::hex << (*r)->getWord()
288  << MSG::dec << " radius " << radius << " err " << error);
289 
290  ATH_MSG_VERBOSE(" driftTime " << tdc->rawDriftTime() << " t0 " << t0
291  << " raw time " << (0.5 + LTbin) * 3.125
292  << " ToT " << tdc->timeOverThreshold()
293  << " OK? " << isOK << " Noise? "
294  << tdc->isNoise() << " isArgon? "
295  << isArgonStraw);
296  } else {
297  ATH_MSG_ERROR("Could not create InDet::TRT_DriftCircle object !");
298  }
299  } // end loop over rdo's in the rdo collection
300 
301  return rio;
302 }
303 
InDet::TRT_DriftCircleTool::passValidityGate
virtual bool passValidityGate(unsigned int word, float lowGate, float highGate, float t0) const override
test validity gate for corrected drift times
Definition: TRT_DriftCircleTool.cxx:103
beamspotman.r
def r
Definition: beamspotman.py:676
InDet::TRT_DriftCircleTool::convert
virtual InDet::TRT_DriftCircleCollection * convert(int, const InDetRawDataCollection< TRT_RDORawData > *, const EventContext &ctx, DataPool< TRT_DriftCircle > *dataItemsPool, const bool CTBBadChannels) const override
make the conversion from RDOs to DriftCircles
Definition: TRT_DriftCircleTool.cxx:127
InDet::TRT_DriftCircleTool::m_high_gate_argon
FloatProperty m_high_gate_argon
Definition: TRT_DriftCircleTool.h:122
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:50
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
Amg::MatrixX
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Definition: EventPrimitives.h:27
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
InDet::TRT_DriftCircleTool::m_trtDetEleContKey
SG::ReadCondHandleKey< InDetDD::TRT_DetElementContainer > m_trtDetEleContKey
Definition: TRT_DriftCircleTool.h:80
WriteCellNoiseToCool.rb
rb
Definition: WriteCellNoiseToCool.py:229
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
InDet::TRT_DriftCircleTool::m_max_drift_time_argon
FloatProperty m_max_drift_time_argon
Definition: TRT_DriftCircleTool.h:108
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
InDet::TRT_DriftCircleTool::m_trtid
const TRT_ID * m_trtid
ID helper.
Definition: TRT_DriftCircleTool.h:97
InDet::TRT_DriftCircle::timeOverThreshold
double timeOverThreshold() const
returns Time over threshold in ns
initialize
void initialize()
Definition: run_EoverP.cxx:894
InDetRawDataCollection::identify
virtual Identifier identify() const override final
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
InDet::TRT_DriftCircleTool::m_ConditionsSummary
ToolHandle< ITRT_StrawStatusSummaryTool > m_ConditionsSummary
Definition: TRT_DriftCircleTool.h:86
TRT_RDORawData.h
InDet::TRT_DriftCircleTool::finalize
virtual StatusCode finalize() override
finalize
Definition: TRT_DriftCircleTool.cxx:95
InDet::TRT_DriftCircleTool::m_low_gate_argon
FloatProperty m_low_gate_argon
Definition: TRT_DriftCircleTool.h:120
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
InDet::TRT_DriftCircleTool::m_validity_gate_suppression
BooleanProperty m_validity_gate_suppression
Definition: TRT_DriftCircleTool.h:115
TRTCond::StrawStatus::Dead
@ Dead
Definition: StrawStatus.h:18
InDet::TRT_DriftCircle
Definition: TRT_DriftCircle.h:32
ReadCondHandle.h
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
InDet::TRT_DriftCircleTool::m_useConditionsHTStatus
BooleanProperty m_useConditionsHTStatus
Definition: TRT_DriftCircleTool.h:91
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
InDetRawDataCollection::identifyHash
virtual IdentifierHash identifyHash() const override final
GeoPrimitives.h
InDet::TRT_DriftCircleTool::initialize
virtual StatusCode initialize() override
initialize needed services
Definition: TRT_DriftCircleTool.cxx:52
TRT_ID::straw
int straw(const Identifier &id) const
Definition: TRT_ID.h:902
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TRT::Hit::driftTime
@ driftTime
Definition: HitInfo.h:43
TRT_DriftCircleTool.h
InDet::TRT_DriftCircleTool::~TRT_DriftCircleTool
virtual ~TRT_DriftCircleTool()
destructor
InDet::TRT_DriftCircle::isNoise
bool isNoise() const
returns true if the hit is caused by noise with a high probability.
InDet::TRT_DriftCircleTool::m_min_trailing_edge_argon
FloatProperty m_min_trailing_edge_argon
Definition: TRT_DriftCircleTool.h:104
lumiFormat.i
int i
Definition: lumiFormat.py:85
Trk::PrepRawData::setHashAndIndex
void setHashAndIndex(unsigned short collHash, unsigned short objIndex)
TEMP for testing: might make some classes friends later ...
beamspotman.n
n
Definition: beamspotman.py:731
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
InDet::TRT_DriftCircleTool::m_max_drift_time
FloatProperty m_max_drift_time
Definition: TRT_DriftCircleTool.h:106
InDet::TRT_DriftCircleTool::m_low_gate
FloatProperty m_low_gate
Definition: TRT_DriftCircleTool.h:119
InDet::TRT_DriftCircleTool::m_useToTCorrection
BooleanProperty m_useToTCorrection
Definition: TRT_DriftCircleTool.h:93
InDetRawDataCollection
Definition: InDetRawDataCollection.h:31
python.xAODType.dummy
dummy
Definition: xAODType.py:4
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
TRT_ID::straw_layer
int straw_layer(const Identifier &id) const
Definition: TRT_ID.h:893
DataPool::nextElementPtr
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
TRT_ID::layer_or_wheel
int layer_or_wheel(const Identifier &id) const
Definition: TRT_ID.h:884
InDet::TRT_DriftCircleTool::m_useHTCorrection
BooleanProperty m_useHTCorrection
Definition: TRT_DriftCircleTool.h:95
TRT_DriftCircle.h
InDet::TRT_DriftCircleTool::m_min_trailing_edge
FloatProperty m_min_trailing_edge
Definition: TRT_DriftCircleTool.h:102
InDet::TRT_DriftCircleTool::m_lumiDataKey
SG::ReadCondHandleKey< LuminosityCondData > m_lumiDataKey
Definition: TRT_DriftCircleTool.h:82
TRTCond::StrawStatus::Good
@ Good
Definition: StrawStatus.h:18
InDet::TRT_DriftCircleTool::m_reject_if_first_bit_argon
BooleanProperty m_reject_if_first_bit_argon
Definition: TRT_DriftCircleTool.h:100
EventPrimitives.h
InDet::TRT_DriftCircleTool::m_out_of_time_supression_argon
BooleanProperty m_out_of_time_supression_argon
Definition: TRT_DriftCircleTool.h:113
LuminosityCondData::lbAverageInteractionsPerCrossing
float lbAverageInteractionsPerCrossing() const
Definition: LuminosityCondData.cxx:26
InDet::TRT_DriftCircleCollection
Trk::PrepRawDataCollection< TRT_DriftCircle > TRT_DriftCircleCollection
Definition: TRT_DriftCircleCollection.h:26
EventContainers::Mode
Mode
Definition: IdentifiableContainerBase.h:13
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
InDet::TRT_DriftCircleTool::m_validity_gate_suppression_argon
BooleanProperty m_validity_gate_suppression_argon
Definition: TRT_DriftCircleTool.h:118
TRT_ID::phi_module
int phi_module(const Identifier &id) const
Definition: TRT_ID.h:875
ParticleGun_SamplingFraction.radius
radius
Definition: ParticleGun_SamplingFraction.py:96
EventInfo.h
DataVector< RawDataT >::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
InDet::TRT_DriftCircleTool::m_driftFunctionTool
ToolHandle< ITRT_DriftFunctionTool > m_driftFunctionTool
Definition: TRT_DriftCircleTool.h:84
InDet::TRT_DriftCircleTool::m_high_gate
FloatProperty m_high_gate
Definition: TRT_DriftCircleTool.h:121
InDetDD::TRT_DetElementCollection::getDetectorElement
const TRT_BaseElement * getDetectorElement(const IdentifierHash &hash) const
Definition: TRT_DetElementCollection.cxx:11
re
const boost::regex re(r_e)
DataPool
a typed memory pool that saves time spent allocation small object. This is typically used by containe...
Definition: DataPool.h:47
InDetDD::TRT_DetElementContainer::getElements
const TRT_DetElementCollection * getElements() const
Definition: TRT_DetElementContainer.cxx:29
InDet::TRT_DriftCircleTool::TRT_DriftCircleTool
TRT_DriftCircleTool(const std::string &, const std::string &, const IInterface *)
constructor
Definition: TRT_DriftCircleTool.cxx:34
InDet::TRT_DriftCircleTool::m_reject_if_first_bit
BooleanProperty m_reject_if_first_bit
Definition: TRT_DriftCircleTool.h:98
InDetDD::TRT_DetElementCollection
Class to hold collection of TRT detector elements.
Definition: TRT_DetElementCollection.h:28
InDet::TRT_DriftCircle::rawDriftTime
double rawDriftTime() const
returns the raw driftTime
AthAlgTool
Definition: AthAlgTool.h:26
InDet::TRT_DriftCircle::getWord
unsigned int getWord() const
returns the TRT dataword
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
get_generator_info.error
error
Definition: get_generator_info.py:40
InDet::TRT_DriftCircleTool::m_useConditionsStatus
BooleanProperty m_useConditionsStatus
Definition: TRT_DriftCircleTool.h:89
TRT_DriftCircleCollection.h
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
error
Definition: IImpactPoint3dEstimator.h:70
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
TRTCond::StrawStatus::Argon
@ Argon
Definition: StrawStatus.h:18
InDet::TRT_DriftCircleTool::m_out_of_time_supression
BooleanProperty m_out_of_time_supression
Definition: TRT_DriftCircleTool.h:110
DataVector< RawDataT >::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
InDetDD::TRT_BaseElement
Definition: TRT_BaseElement.h:57
Identifier
Definition: IdentifierFieldParser.cxx:14