ATLAS Offline Software
Loading...
Searching...
No Matches
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
27
31
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
57bool 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
83 StatusCode sc = AthAlgTool::initialize();
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
109 ATH_CHECK(m_evtPhaseKey.initialize());
110
111 // Initialize readCondHandle key
112 ATH_CHECK(m_trtDetEleContKey.initialize());
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
130InDet::TRT_DriftCircleCollection* InDet::TRT_DriftCircleToolCosmics::convert(int Mode,
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
const boost::regex re(r_e)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
static Double_t t0
Handle class for reading from StoreGate.
This is an Identifier helper class for the TRT subdetector.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
a typed memory pool that saves time spent allocation small object.
Definition DataPool.h:63
DataModel_detail::const_iterator< DataVector > const_iterator
Standard const_iterator.
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
This is a "hash" representation of an Identifier.
Virtual base class of TRT readout elements.
Class to hold collection of TRT detector elements.
const TRT_BaseElement * getDetectorElement(const IdentifierHash &hash) const
virtual Identifier identify() const override final
virtual IdentifierHash identifyHash() const override final
virtual bool passValidityGate(unsigned int word, float lowGate, float highGate, float t0) const
test validity gate for corrected drift times
SG::ReadCondHandleKey< InDetDD::TRT_DetElementContainer > m_trtDetEleContKey
SG::ReadHandleKey< ComTime > m_evtPhaseKey
ToolHandle< ITRT_DriftFunctionTool > m_driftFunctionTool
ToolHandle< ITRT_StrawStatusSummaryTool > m_ConditionsSummary
TRT_DriftCircleToolCosmics(const std::string &, const std::string &, const IInterface *)
constructor
virtual StatusCode initialize()
initialize needed services
virtual ~TRT_DriftCircleToolCosmics()
constructor
const TRT_ID * m_trtid
TRT id helper handle.
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
virtual bool isValid() override final
Can the handle be successfully dereferenced?
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
void setHashAndIndex(unsigned short collHash, unsigned short objIndex)
TEMP for testing: might make some classes friends later ...
int r
Definition globals.cxx:22
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, 2, 1 > Vector2D