ATLAS Offline Software
Loading...
Searching...
No Matches
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
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
55 StatusCode sc = AthAlgTool::initialize();
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
80 ATH_CHECK(m_lumiDataKey.initialize ( !m_lumiDataKey.key().empty() ));
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
86 ATH_CHECK(m_trtDetEleContKey.initialize());
87
88 return sc;
89}
90
92// Finalize
94
96{
97 StatusCode sc = AthAlgTool::finalize(); return sc;
98}
99
101// Test validity gate
103bool 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
126InDet::TRT_DriftCircleCollection*
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
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
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
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
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
BooleanProperty m_useConditionsHTStatus
virtual bool passValidityGate(unsigned int word, float lowGate, float highGate, float t0) const override
test validity gate for corrected drift times
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
SG::ReadCondHandleKey< LuminosityCondData > m_lumiDataKey
BooleanProperty m_validity_gate_suppression
BooleanProperty m_reject_if_first_bit_argon
TRT_DriftCircleTool(const std::string &, const std::string &, const IInterface *)
constructor
virtual StatusCode finalize() override
finalize
virtual StatusCode initialize() override
initialize needed services
BooleanProperty m_out_of_time_supression_argon
ToolHandle< ITRT_StrawStatusSummaryTool > m_ConditionsSummary
SG::ReadCondHandleKey< InDetDD::TRT_DetElementContainer > m_trtDetEleContKey
virtual ~TRT_DriftCircleTool()
destructor
ToolHandle< ITRT_DriftFunctionTool > m_driftFunctionTool
const TRT_ID * m_trtid
ID helper.
BooleanProperty m_validity_gate_suppression_argon
unsigned int getWord() const
returns the TRT dataword
bool isNoise() const
returns true if the hit is caused by noise with a high probability.
double rawDriftTime() const
returns the raw driftTime
double timeOverThreshold() const
returns Time over threshold in ns
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
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts