ATLAS Offline Software
TRT_DriftCircleToolCosmics.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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& n,
41  const IInterface* p ):
42  AthAlgTool(t,n,p),
43  m_driftFunctionTool("TRT_DriftFunctionTool"),
44  m_ConditionsSummary("TRT_StrawStatusSummaryTool",this),
45  m_useConditionsStatus(false),
46  m_trtid(nullptr),
47  m_global_offset(0),
48  m_useToTCorrection(false),
49  m_useHTCorrection(false)
50 
51 {
52  declareInterface<ITRT_DriftCircleTool>(this);
53  declareProperty("TRTDriftFunctionTool", m_driftFunctionTool);
54  declareProperty("ConditionsSummaryTool",m_ConditionsSummary);
55  declareProperty("UseConditionsStatus",m_useConditionsStatus);
56 
57  declareProperty("useDriftTimeToTCorrection",m_useToTCorrection);
58  declareProperty("useDriftTimeHTCorrection",m_useHTCorrection);
59  declareProperty("GlobalPhaseOffset",m_global_offset);
60 }
61 
63 // Destructor
65 
67 
69 // Test validity gate
71 bool InDet::TRT_DriftCircleToolCosmics::passValidityGate(unsigned int word, float lowGate, float highGate, float t0) const
72 {
73  bool foundInterval = false;
74  unsigned mask = 0x02000000;
75  int i = 0;
76  while ( !foundInterval && (i < 24) ) {
77  if (word & mask) {
78  float thisTime = ((0.5+i)*3.125)-t0;
79  if (thisTime >= lowGate && thisTime <= highGate) foundInterval = true;
80  }
81  mask >>= 1;
82  if (i == 7 || i == 15)
83  mask >>= 1;
84  i++;
85  }
86  return foundInterval;
87 }
88 
89 
91 // Initialisation
93 
95 {
96 
98 
99  // Get DriftFunction tool
100  //
101  if ( m_driftFunctionTool.retrieve().isFailure() ) {
102  ATH_MSG_FATAL(m_driftFunctionTool.propertyName() << ": Failed to retrieve tool " << m_driftFunctionTool.type());
103  return StatusCode::FAILURE;
104  }
105  ATH_MSG_DEBUG(m_driftFunctionTool.propertyName() << ": Retrieved tool " << m_driftFunctionTool.type());
106 
107  // Get TRT ID helper
108  sc = detStore()->retrieve(m_trtid,"TRT_ID");
109  if ( sc.isFailure() ) {
110  ATH_MSG_FATAL( "Could not retrieve TRT ID helper." );
111  return sc;
112  }
113 
115  if ( m_ConditionsSummary.retrieve().isFailure() ) {
116  ATH_MSG_FATAL("Failed to retrieve "<< m_ConditionsSummary);
117  return StatusCode::FAILURE;
118  }
119  ATH_MSG_DEBUG( "Retrieved service " << m_ConditionsSummary);
120  }
121 
122  // Initialize Read handle key
124 
125  // Initialize readCondHandle key
127 
128  return sc;
129 }
130 
132 // Finalize
134 
136 {
137  StatusCode sc = AthAlgTool::finalize(); return sc;
138 }
139 
141 // Trk::TRT_DriftCircles collection production
143 
146  const EventContext& ctx,
147  DataPool<TRT_DriftCircle>* /*dataItemsPool*/,
148  const bool /* _getTRTBadChannel */) const
149 {
150 
151  //Initialise a new TRT_DriftCircleCollection
152  InDet::TRT_DriftCircleCollection* rio = nullptr;
153 
154  if (!rdo) {
155  ATH_MSG_ERROR("empty collection at input");
156  return rio;
157  }
158 
159  SG::ReadHandle<ComTime> theComTime(m_evtPhaseKey, ctx);
160 
162  const InDetDD::TRT_DetElementCollection* elements(trtDetEleHandle->getElements());
163  if (not trtDetEleHandle.isValid() or elements==nullptr) {
164  ATH_MSG_FATAL(m_trtDetEleContKey.fullKey() << " is not available.");
165  return rio;
166  }
167 
168  float timecor=0.;
169  if (theComTime.isValid()) {
170  timecor = theComTime->getTime() + m_global_offset;
171  ATH_MSG_VERBOSE("Retrieved event phase with name "
172  << theComTime.key() <<" found! Time="<<timecor);
173  }else{
174  ATH_MSG_VERBOSE("Event phase not found with name "<<theComTime.key()<<"!!!");
175  timecor=m_global_offset; // cannot correct drifttime
176  }
177 
179  if(rb!=re) {
180 
181  //Get the BaseElement and the rio of the collection
182  IdentifierHash IHc = rdo ->identifyHash();
183  const InDetDD::TRT_BaseElement* pE = elements->getDetectorElement(IHc);
184  rio = new InDet::TRT_DriftCircleCollection(IHc);
185  rio->setIdentifier(rdo->identify());
186  rio->reserve( std::distance(rb, re) );
187 
188 
189  // Loop through all RDOs in the collection
190  //
191 
192  for(r=rb; r!=re; ++r) {
193 
194  Identifier id = (*r)->identify();
195  int LTbin = (*r)->driftTimeBin();
196  bool isOK =true;
197  double t0 =0.;
198  double rawTime = m_driftFunctionTool->rawTime(LTbin);
199  double radius =0.;
200  double driftTime =0.;
201  unsigned int word = (*r)->getWord();
202 
203  //
204  //Get straw status
205  int strawstat=1;
206 
208  if(m_ConditionsSummary->getStatus(id) != TRTCond::StrawStatus::Good) {
209  strawstat = 0;
210  }
211  if(!strawstat) continue;
212  }
213 
214  //correct for phase
215  rawTime-=timecor;
216 
217  // ToT and HT Corrections
218 
219  bool isArgonStraw=true;
220  if (m_useToTCorrection) rawTime -= m_driftFunctionTool->driftTimeToTCorrection((*r)->timeOverThreshold(), id, isArgonStraw);
221  if (m_useHTCorrection && (*r)->highLevel()) rawTime += m_driftFunctionTool->driftTimeHTCorrection(id, isArgonStraw);
222 
223  //make tube hit if first bin is high and no later LE appears
224  if( LTbin==0 || LTbin==24 ) {
225  isOK=false;
226  } else {
227  radius = m_driftFunctionTool->driftRadius(rawTime,id,t0,isOK);
228  driftTime = rawTime-t0;
229  }
230 
231  if(!isOK) word &= 0xF7FFFFFF;
232  else word |= 0x08000000;
233 
234 
235  //std::vector<Identifier> dvi // we dont need this ;
236  ATH_MSG_VERBOSE( " id " << m_trtid->layer_or_wheel(id)
237  << " " << m_trtid->straw_layer(id)
238  << " " << m_trtid->straw(id)
239  << " time bin " << LTbin
240  << " timecor " << timecor
241  << " corrected time " << rawTime );
242 
243  double error=0;
244  if(Mode<2) {
245  error = m_driftFunctionTool->errorOfDriftRadius(driftTime,id) ;
246  }
247 
248  ATH_MSG_VERBOSE(" hit OK " << isOK << " t0 " << t0
249  << " drifttime " << driftTime
250  << " radius " << radius << " error " << error);
251 
252  if( !isOK || (error==0.&&Mode<2) ) //Drifttime out of range. Make wirehit
253  {
254  ATH_MSG_VERBOSE(" Making wirehit.");
255  radius = 0.;
256  error = 4./sqrt(12.);
257  }
258 
259  auto errmat = Amg::MatrixX(1,1); ;
260  (errmat)(0,0) = error*error;
261 
262  Amg::Vector2D loc(radius,0.);
263 
264  // if(Mode<1) dvi.push_back(id); we dont need this
265 
267  new InDet::TRT_DriftCircle(id, loc, std::move(errmat), pE, word);
268 
269  if (tdc) {
270 
272  // setting the index (via -> size) has to be done just before the push_back! (for safety)
273  tdc->setHashAndIndex(rio->identifyHash(), rio->size());
274  rio->push_back(tdc);
275 
276  }else{
277  if(strawstat){
278  tdc->setHashAndIndex(rio->identifyHash(), rio->size());
279  rio->push_back(tdc);
280  } else {
281  ATH_MSG_VERBOSE(" Delete hit on bad channel ");
282  delete tdc;
283  }
284  }
285 
286  } else{
287  ATH_MSG_ERROR("Could not create InDet::TRT_DriftCircle object !");
288  }
289  }
290  }
291  return rio;
292 }
293 
294 
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:144
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:53
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:29
IInDetConditionsTool.h
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
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
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
initialize
void initialize()
Definition: run_EoverP.cxx:894
InDet::TRT_DriftCircleToolCosmics::m_useConditionsStatus
bool m_useConditionsStatus
SHall the ConditionsSummaryTool be used?
Definition: TRT_DriftCircleToolCosmics.h:81
ALFA_EventTPCnv_Dict::t0
std::vector< ALFA_RawData_p1 > t0
Definition: ALFA_EventTPCnvDict.h:42
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:205
InDet::TRT_DriftCircleToolCosmics::m_trtid
const TRT_ID * m_trtid
TRT id helper handle.
Definition: TRT_DriftCircleToolCosmics.h:82
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
InDetRawDataCollection::identifyHash
virtual IdentifierHash identifyHash() const override final
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
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:92
Trk::PrepRawData::setHashAndIndex
void setHashAndIndex(unsigned short collHash, unsigned short objIndex)
TEMP for testing: might make some classes friends later ...
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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_DriftCircleToolCosmics::m_global_offset
float m_global_offset
Global offset to TRT Phase to make TRT Calibration happy ...
Definition: TRT_DriftCircleToolCosmics.h:83
InDetRawDataCollection
Definition: InDetRawDataCollection.h:31
InDet::TRT_DriftCircleToolCosmics::m_ConditionsSummary
ToolHandle< ITRT_StrawStatusSummaryTool > m_ConditionsSummary
The ConditionsSummaryTool.
Definition: TRT_DriftCircleToolCosmics.h:79
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:71
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
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
InDet::TRT_DriftCircleToolCosmics::initialize
virtual StatusCode initialize()
initialize needed services
Definition: TRT_DriftCircleToolCosmics.cxx:94
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.
InDet::TRT_DriftCircleToolCosmics::m_useHTCorrection
bool m_useHTCorrection
Shall the High Threshold correction be used?
Definition: TRT_DriftCircleToolCosmics.h:85
InDetDD::TRT_DetElementCollection::getDetectorElement
const TRT_BaseElement * getDetectorElement(const IdentifierHash &hash) const
Definition: TRT_DetElementCollection.cxx:11
re
const boost::regex re(r_e)
InDet::TRT_DriftCircleToolCosmics::m_useToTCorrection
bool m_useToTCorrection
Shall the Time over Threshold correction be used?
Definition: TRT_DriftCircleToolCosmics.h:84
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:135
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:76
IdentifierHash
Definition: IdentifierHash.h:38
InDet::TRT_DriftCircleToolCosmics::m_driftFunctionTool
ToolHandle< ITRT_DriftFunctionTool > m_driftFunctionTool
DriftFunctionTool.
Definition: TRT_DriftCircleToolCosmics.h:78
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::~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:39