ATLAS Offline Software
TRT_DriftCircleToolCosmics.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_DriftCircleToolCosmics
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"
23 
25 #include "InDetIdentifier/TRT_ID.h"
27 
31 
32 #include "StoreGate/ReadHandle.h"
33 
36 // Constructior
38 
40 (const std::string& t,
41  const std::string& n,
42  const IInterface* p ):
43  AthAlgTool(t,n,p)
44 {
45  declareInterface<ITRT_DriftCircleTool>(this);
46 }
47 
49 // Destructor
51 
53 
55 // Test validity gate
57 bool InDet::TRT_DriftCircleToolCosmics::passValidityGate(unsigned int word, float lowGate, float highGate, float t0) const
58 {
59  bool foundInterval = false;
60  unsigned mask = 0x02000000;
61  int i = 0;
62  while ( !foundInterval && (i < 24) ) {
63  if (word & mask) {
64  float thisTime = ((0.5+i)*3.125)-t0;
65  if (thisTime >= lowGate && thisTime <= highGate) foundInterval = true;
66  }
67  mask >>= 1;
68  if (i == 7 || i == 15)
69  mask >>= 1;
70  i++;
71  }
72  return foundInterval;
73 }
74 
75 
77 // Initialisation
79 
81 {
82 
84 
85  // Get DriftFunction tool
86  //
87  if ( m_driftFunctionTool.retrieve().isFailure() ) {
88  ATH_MSG_FATAL(m_driftFunctionTool.propertyName() << ": Failed to retrieve tool " << m_driftFunctionTool.type());
89  return StatusCode::FAILURE;
90  }
91  ATH_MSG_DEBUG(m_driftFunctionTool.propertyName() << ": Retrieved tool " << m_driftFunctionTool.type());
92 
93  // Get TRT ID helper
94  sc = detStore()->retrieve(m_trtid,"TRT_ID");
95  if ( sc.isFailure() ) {
96  ATH_MSG_FATAL( "Could not retrieve TRT ID helper." );
97  return sc;
98  }
99 
101  if ( m_ConditionsSummary.retrieve().isFailure() ) {
102  ATH_MSG_FATAL("Failed to retrieve "<< m_ConditionsSummary);
103  return StatusCode::FAILURE;
104  }
105  ATH_MSG_DEBUG( "Retrieved service " << m_ConditionsSummary);
106  }
107 
108  // Initialize Read handle key
110 
111  // Initialize readCondHandle key
113 
114  return sc;
115 }
116 
118 // Finalize
120 
122 {
123  StatusCode sc = AthAlgTool::finalize(); return sc;
124 }
125 
127 // Trk::TRT_DriftCircles collection production
129 
132  const EventContext& ctx,
133  DataPool<TRT_DriftCircle>* /*dataItemsPool*/,
134  const bool /* _getTRTBadChannel */) const
135 {
136 
137  //Initialise a new TRT_DriftCircleCollection
138  InDet::TRT_DriftCircleCollection* rio = nullptr;
139 
140  if (!rdo) {
141  ATH_MSG_ERROR("empty collection at input");
142  return rio;
143  }
144 
145  SG::ReadHandle<ComTime> theComTime(m_evtPhaseKey, ctx);
146 
148  const InDetDD::TRT_DetElementCollection* elements(trtDetEleHandle->getElements());
149  if (not trtDetEleHandle.isValid() or elements==nullptr) {
150  ATH_MSG_FATAL(m_trtDetEleContKey.fullKey() << " is not available.");
151  return rio;
152  }
153 
154  float timecor=0.;
155  if (theComTime.isValid()) {
156  timecor = theComTime->getTime() + m_global_offset;
157  ATH_MSG_VERBOSE("Retrieved event phase with name "
158  << theComTime.key() <<" found! Time="<<timecor);
159  }else{
160  ATH_MSG_VERBOSE("Event phase not found with name "<<theComTime.key()<<"!!!");
161  timecor=m_global_offset; // cannot correct drifttime
162  }
163 
165  if(rb!=re) {
166 
167  //Get the BaseElement and the rio of the collection
168  IdentifierHash IHc = rdo ->identifyHash();
169  const InDetDD::TRT_BaseElement* pE = elements->getDetectorElement(IHc);
170  rio = new InDet::TRT_DriftCircleCollection(IHc);
171  rio->setIdentifier(rdo->identify());
172  rio->reserve( std::distance(rb, re) );
173 
174 
175  // Loop through all RDOs in the collection
176  //
177 
178  for(r=rb; r!=re; ++r) {
179 
180  Identifier id = (*r)->identify();
181  int LTbin = (*r)->driftTimeBin();
182  bool isOK =true;
183  double t0 =0.;
184  double rawTime = m_driftFunctionTool->rawTime(LTbin);
185  double radius =0.;
186  double driftTime =0.;
187  unsigned int word = (*r)->getWord();
188 
189  //
190  //Get straw status
191  int strawstat=1;
192 
194  if(m_ConditionsSummary->getStatus(id, ctx) != TRTCond::StrawStatus::Good) {
195  strawstat = 0;
196  }
197  if(!strawstat) continue;
198  }
199 
200  //correct for phase
201  rawTime-=timecor;
202 
203  // ToT and HT Corrections
204 
205  bool isArgonStraw=true;
206  if (m_useToTCorrection) rawTime -= m_driftFunctionTool->driftTimeToTCorrection((*r)->timeOverThreshold(), id, isArgonStraw);
207  if (m_useHTCorrection && (*r)->highLevel()) rawTime += m_driftFunctionTool->driftTimeHTCorrection(id, isArgonStraw);
208 
209  //make tube hit if first bin is high and no later LE appears
210  if( LTbin==0 || LTbin==24 ) {
211  isOK=false;
212  } else {
213  radius = m_driftFunctionTool->driftRadius(rawTime,id,t0,isOK);
214  driftTime = rawTime-t0;
215  }
216 
217  if(!isOK) word &= 0xF7FFFFFF;
218  else word |= 0x08000000;
219 
220 
221  //std::vector<Identifier> dvi // we dont need this ;
222  ATH_MSG_VERBOSE( " id " << m_trtid->layer_or_wheel(id)
223  << " " << m_trtid->straw_layer(id)
224  << " " << m_trtid->straw(id)
225  << " time bin " << LTbin
226  << " timecor " << timecor
227  << " corrected time " << rawTime );
228 
229  double error=0;
230  if(Mode<2) {
231  error = m_driftFunctionTool->errorOfDriftRadius(driftTime,id) ;
232  }
233 
234  ATH_MSG_VERBOSE(" hit OK " << isOK << " t0 " << t0
235  << " drifttime " << driftTime
236  << " radius " << radius << " error " << error);
237 
238  if( !isOK || (error==0.&&Mode<2) ) //Drifttime out of range. Make wirehit
239  {
240  ATH_MSG_VERBOSE(" Making wirehit.");
241  radius = 0.;
242  error = 4./sqrt(12.);
243  }
244 
245  auto errmat = Amg::MatrixX(1,1); ;
246  (errmat)(0,0) = error*error;
247 
248  Amg::Vector2D loc(radius,0.);
249 
250  // if(Mode<1) dvi.push_back(id); we dont need this
251 
253  new InDet::TRT_DriftCircle(id, loc, std::move(errmat), pE, word);
254 
255  if (tdc) {
256 
258  // setting the index (via -> size) has to be done just before the push_back! (for safety)
259  tdc->setHashAndIndex(rio->identifyHash(), rio->size());
260  rio->push_back(tdc);
261 
262  }else{
263  if(strawstat){
264  tdc->setHashAndIndex(rio->identifyHash(), rio->size());
265  rio->push_back(tdc);
266  } else {
267  ATH_MSG_VERBOSE(" Delete hit on bad channel ");
268  delete tdc;
269  }
270  }
271 
272  } else{
273  ATH_MSG_ERROR("Could not create InDet::TRT_DriftCircle object !");
274  }
275  }
276  }
277  return rio;
278 }
279 
280 
InDet::TRT_DriftCircleToolCosmics::convert
virtual InDet::TRT_DriftCircleCollection * convert(int, const InDetRawDataCollection< TRT_RDORawData > *, const EventContext &ctx, DataPool< TRT_DriftCircle > *dataItemsPool, const bool CTBBadChannels) const
make the conversion from RDOs to DriftCircles
Definition: TRT_DriftCircleToolCosmics.cxx:130
beamspotman.r
def r
Definition: beamspotman.py:676
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
IInDetConditionsTool.h
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ComTime::getTime
double getTime() const
Definition: ComTime.h:44
WriteCellNoiseToCool.rb
rb
Definition: WriteCellNoiseToCool.py:229
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
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_DriftCircleToolCosmics::m_trtid
const TRT_ID * m_trtid
TRT id helper handle.
Definition: TRT_DriftCircleToolCosmics.h:89
TRT_RDORawData.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
InDet::TRT_DriftCircle
Definition: TRT_DriftCircle.h:32
ReadCondHandle.h
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
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
InDet::TRT_DriftCircleToolCosmics::m_useHTCorrection
BooleanProperty m_useHTCorrection
Definition: TRT_DriftCircleToolCosmics.h:94
InDetRawDataCollection::identifyHash
virtual IdentifierHash identifyHash() const override final
InDet::TRT_DriftCircleToolCosmics::m_global_offset
FloatProperty m_global_offset
Definition: TRT_DriftCircleToolCosmics.h:90
GeoPrimitives.h
InDet::TRT_DriftCircleToolCosmics::m_evtPhaseKey
SG::ReadHandleKey< ComTime > m_evtPhaseKey
Definition: TRT_DriftCircleToolCosmics.h:75
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
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
InDetRawDataCollection
Definition: InDetRawDataCollection.h:31
InDet::TRT_DriftCircleToolCosmics::m_ConditionsSummary
ToolHandle< ITRT_StrawStatusSummaryTool > m_ConditionsSummary
Definition: TRT_DriftCircleToolCosmics.h:84
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
InDet::TRT_DriftCircleToolCosmics::passValidityGate
virtual bool passValidityGate(unsigned int word, float lowGate, float highGate, float t0) const
test validity gate for corrected drift times
Definition: TRT_DriftCircleToolCosmics.cxx:57
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
TRT_ID::straw_layer
int straw_layer(const Identifier &id) const
Definition: TRT_ID.h:893
TRT_ID::layer_or_wheel
int layer_or_wheel(const Identifier &id) const
Definition: TRT_ID.h:884
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TRT_DriftCircle.h
TRTCond::StrawStatus::Good
@ Good
Definition: StrawStatus.h:18
TRT_BaseElement.h
EventPrimitives.h
ITRT_DriftFunctionTool.h
InDet::TRT_DriftCircleCollection
Trk::PrepRawDataCollection< TRT_DriftCircle > TRT_DriftCircleCollection
Definition: TRT_DriftCircleCollection.h:26
EventContainers::Mode
Mode
Definition: IdentifiableContainerBase.h:13
InDet::TRT_DriftCircleToolCosmics::m_useToTCorrection
BooleanProperty m_useToTCorrection
Definition: TRT_DriftCircleToolCosmics.h:92
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
InDet::TRT_DriftCircleToolCosmics::initialize
virtual StatusCode initialize()
initialize needed services
Definition: TRT_DriftCircleToolCosmics.cxx:80
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
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.
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_DriftCircleToolCosmics::finalize
virtual StatusCode finalize()
finalize
Definition: TRT_DriftCircleToolCosmics.cxx:121
InDetDD::TRT_DetElementCollection
Class to hold collection of TRT detector elements.
Definition: TRT_DetElementCollection.h:28
ReadHandle.h
Handle class for reading from StoreGate.
TRT_DriftCircleToolCosmics.h
AthAlgTool
Definition: AthAlgTool.h:26
InDet::TRT_DriftCircleToolCosmics::m_trtDetEleContKey
SG::ReadCondHandleKey< InDetDD::TRT_DetElementContainer > m_trtDetEleContKey
Definition: TRT_DriftCircleToolCosmics.h:78
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
InDet::TRT_DriftCircleToolCosmics::m_driftFunctionTool
ToolHandle< ITRT_DriftFunctionTool > m_driftFunctionTool
Definition: TRT_DriftCircleToolCosmics.h:82
get_generator_info.error
error
Definition: get_generator_info.py:40
TRT_DriftCircleCollection.h
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
InDet::TRT_DriftCircleToolCosmics::m_useConditionsStatus
BooleanProperty m_useConditionsStatus
Definition: TRT_DriftCircleToolCosmics.h:87
InDet::TRT_DriftCircleToolCosmics::~TRT_DriftCircleToolCosmics
virtual ~TRT_DriftCircleToolCosmics()
constructor
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
InDet::TRT_DriftCircleToolCosmics::TRT_DriftCircleToolCosmics
TRT_DriftCircleToolCosmics(const std::string &, const std::string &, const IInterface *)
constructor
Definition: TRT_DriftCircleToolCosmics.cxx:40
Identifier
Definition: IdentifierFieldParser.cxx:14