ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_PrepDataToxAOD.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6// TRT_PrepDataToxAOD.cxx
7// Implementation file for class TRT_PrepDataToxAOD
9
10#include "TRT_PrepDataToxAOD.h"
11
13//#include "EventPrimitives/EventPrimitivesHelpers.h"
14
18
19
20#include "Identifier/Identifier.h"
22
23
24#include "TrkSurfaces/Surface.h"
25
29
32
33#define AUXDATA(OBJ, TYP, NAME) \
34 static const SG::AuxElement::Accessor<TYP> acc_##NAME (#NAME); acc_##NAME(*(OBJ))
35
36
38//
39// Initialize method:
40//
43{
44 ATH_MSG_DEBUG("Initialize");
45
46 //Initialize VarHandleKeys
48 ATH_CHECK(m_multiTruth.initialize(m_useTruthInfo && (not m_multiTruth.key().empty()) ));
49 ATH_CHECK(m_SDOcontainer.initialize(m_writeSDOs && (not m_SDOcontainer.key().empty()) ));
50 ATH_CHECK(m_xAodContainer.initialize());
51 ATH_CHECK(m_xAodOffset.initialize());
52
53 // --- Retrieve services and tools
54 CHECK ( detStore()->retrieve(m_TRTHelper, "TRT_ID") );
55
56 CHECK ( detStore()->retrieve(m_trtman, "TRT") );
57
58 CHECK ( m_neighbourSvc.retrieve() );
59
60 CHECK ( m_trtcaldbTool.retrieve() );
61
62 CHECK ( m_TRTStrawSummaryTool.retrieve() );
63
64 CHECK( m_driftFunctionTool.retrieve() );
65
66 return StatusCode::SUCCESS;
67}
68
70//
71// Execute method:
72//
74StatusCode TRT_PrepDataToxAOD::execute(const EventContext& ctx)
75{
76 //This is needed for the algorithm. If not there, it fails
77
79 if (not h_trtPrds.isValid()) {
80 ATH_MSG_ERROR("Cannot retrieve TRT PrepDataContainer " << m_driftcirclecontainer.key());
81 return StatusCode::FAILURE;
82 }
83
84 //This is optional for the algorithm. If not there, just print a one-time warning
85 // On ESD
86
87 const PRD_MultiTruthCollection* prdmtColl = nullptr; // to be used in the loop later
88 if (m_useTruthInfo && (!m_multiTruth.key().empty()) ) {
90 if (not h_prdmtColl.isValid()){
92 ATH_MSG_WARNING("PRD MultiTruth collection not available (" << m_multiTruth.key() << "). Skipping this info although requested.");}
93 } else {
94 prdmtColl = h_prdmtColl.cptr();
95 }
96 }
97
98 //This is optional for the algorithm. If not there, just print a one-time warning
99 // On RDO
100
101 const InDetSimDataCollection* sdoCollection = nullptr; // to be used in the loop later
102 if (m_writeSDOs && m_useTruthInfo && (!m_SDOcontainer.key().empty()) ) {
104 if (not h_sdoCollection.isValid()) {
106 ATH_MSG_WARNING("SDO Collection not available (" << m_SDOcontainer.key() << "). Skipping this info although requested.");}
107 } else{
108 sdoCollection = h_sdoCollection.cptr();
109 }
110 }
111
112
113 // Create the xAOD container and its auxiliary store:
115 ATH_CHECK(xaod.record(std::make_unique<xAOD::TrackMeasurementValidationContainer>(),std::make_unique<xAOD::TrackMeasurementValidationAuxContainer>() ) );
116
118 ATH_CHECK(offsets.record(std::make_unique<std::vector<unsigned int>>(m_TRTHelper->straw_layer_hash_max() , 0) ));
119
120 InDet::TRT_DriftCircleContainer::const_iterator it = h_trtPrds->begin();
121 InDet::TRT_DriftCircleContainer::const_iterator it_end = h_trtPrds->end();
122 unsigned int counter(0);
123 for( ; it!=it_end; ++it ) {
124
125 //Fill Offset container
126 if( m_TRTHelper->straw_layer_hash_max() <= (*it)->identifyHash() )
127 ATH_MSG_ERROR("My assumption about the maximum size of the hash was wrong");
128 (*offsets)[ (*it)->identifyHash() ] = counter;
129
130 // skip empty collections
131 if( (*it)->empty() ) continue;
132
133 // loop over collection and convert to xAOD
134 for( const auto prd : **it ){
135
136 ++counter;
137
138 // create and add xAOD object
140 xaod->push_back(xprd);
141
142 Identifier surfaceID = prd->identify();
143
144 xprd->setIdentifier(surfaceID.get_compact());
145
146
147 // Save ID info:
148 AUXDATA(xprd, int, bec) = m_TRTHelper->barrel_ec( surfaceID ) ;
149 AUXDATA(xprd, int, layer) = m_TRTHelper->layer_or_wheel(surfaceID ) ;
150 AUXDATA(xprd, int, phi_module) = m_TRTHelper->phi_module( surfaceID ) ;
151 AUXDATA(xprd, int, strawlayer) = m_TRTHelper->straw_layer( surfaceID ) ;
152 AUXDATA(xprd, int, strawnumber) = m_TRTHelper->straw( surfaceID ) ;
153 const InDetDD::TRT_BaseElement* element = m_trtman->getElement(surfaceID);
154 AUXDATA(xprd, float, strawphi) = element->center(surfaceID).phi();
155
156 int chip=0;
157 int board=-1;
158 m_neighbourSvc->getChip(surfaceID,chip);
159 if(abs(m_TRTHelper->barrel_ec(surfaceID))<2)
160 board=m_neighbourSvc->chipToBoardBarrel(chip,m_TRTHelper->layer_or_wheel(surfaceID));
161 else if (chip<12)
162 board=0;
163 else {
164 chip=chip-20;
165 board=1;
166 }
167 AUXDATA(xprd, int, TRTboard) = board ;
168 AUXDATA(xprd, int, TRTchip) = chip ;
169
170
171 //Set Local Position
172 const Amg::Vector2D& locpos = prd->localPosition();
173 float locY(0.);
174 float locX = locpos.x();
175 if ( !(std::isinf(locpos.y()) || std::isnan(locpos.y())) ){
176 if (locpos.y()>=1e-07)
177 locY=locpos.y();
178 } else {
179 locY = -9999.;
180 }
181
182 // Set local error matrix
183 xprd->setLocalPosition(locX,locY);
184
185 const Amg::MatrixX& localCov = prd->localCovariance();
186 if(localCov.size() == 1){
187 xprd->setLocalPositionError( sqrt(localCov(0,0)), 0., 0. );
188 } else if(localCov.size() == 2){
189 xprd->setLocalPositionError( sqrt(localCov(0,0)), sqrt(localCov(1,1)), sqrt(localCov(0,1)) );
190 } else {
191 xprd->setLocalPositionError(0.,0.,0.);
192 }
193
194
195 //Set Global position
196 const Amg::Vector3D gpos = prd->detectorElement()->surface(surfaceID).localToGlobal(prd->localPosition());
197 xprd->setGlobalPosition(gpos.x(),gpos.y(),gpos.z());
198
199
200 //TRT hit bit word
201 unsigned int word = prd->getWord();
202
203
204 double tot = prd->timeOverThreshold();
205 bool isvalid=false;
206 AUXDATA(xprd, float, drifttime) = prd->driftTime(isvalid) ;
207 AUXDATA(xprd, int, status) = isvalid;
208 AUXDATA(xprd, float, tot) = tot ;
209 AUXDATA(xprd, char, isHT) = prd->highLevel() ;
210 AUXDATA(xprd, float, T0) = m_trtcaldbTool->getT0(surfaceID) ;
211
212
213 // Save time info:
214 AUXDATA(xprd, float, leadingEdge) = prd->rawDriftTime();
215
216 //Drift Time corrections
217 AUXDATA(xprd, float, driftTimeToTCorrection) = m_driftFunctionTool->driftTimeToTCorrection(tot,surfaceID);
218 if(prd->highLevel()) {
219 AUXDATA(xprd, float, driftTimeHTCorrection) = m_driftFunctionTool->driftTimeHTCorrection(surfaceID);
220 }
221 else {
222 AUXDATA(xprd, float, driftTimeHTCorrection) = 0;
223 }
224
225
226 //HT Bit patterens
227 unsigned int theWord = word & 0x04020100; //HT bits mask
228 char highThreshold = 0;
229 //this is the agreed-upon binning for HT bit patterns...
230 if (theWord == 0x04000000) //pattern 1
231 highThreshold = 1;
232 else if (theWord == 0x00020000) //pattern 2
233 highThreshold = 2;
234 else if (theWord == 0x00000100) //pattern 3
235 highThreshold = 3;
236 else if (theWord == 0x04020000) //pattern 4
237 highThreshold = 4;
238 else if (theWord == 0x00020100) //pattern 5
239 highThreshold = 5;
240 else if (theWord == 0x04000100) //pattern 6
241 highThreshold = 6;
242 else if (theWord == 0x04020100) //pattern 7
243 highThreshold = 7;
244
245 AUXDATA(xprd, char, highThreshold) = highThreshold;
246
247 //Full bit patternword from the TRT
248 AUXDATA(xprd, unsigned int, bitPattern) = word;
249
250 char gas_type = kUnset;
251 if (!m_TRTStrawSummaryTool.empty()) {
252 int stat = m_TRTStrawSummaryTool->getStatusHT(surfaceID, ctx);
253
254 if ( stat==1 || stat==4 ) { gas_type = kArgon; }
255 else if ( stat==5 ) { gas_type = kKrypton; }
256 else if ( stat==2 || stat==3 ) { gas_type = kXenon; }
257 else if ( stat==6 ) gas_type = kEmAr;
258 else if ( stat==7 ) gas_type = kEmKr;
259 }
260 AUXDATA(xprd, char, gasType) = gas_type;
261
262 // Use the MultiTruth Collection to get a list of all true particle contributing to the DC
263 if (m_useTruthInfo){
264 if(prdmtColl){
265 std::vector<int> uniqueIDs;
266 auto range = prdmtColl->equal_range(surfaceID);
267 for (auto i = range.first; i != range.second; ++i) {
268 uniqueIDs.push_back( HepMC::uniqueID(i->second) );
269 }
270 AUXDATA(xprd, std::vector<int> , truth_barcode) = std::move(uniqueIDs); // TODO rename variable to be consistent?
271 }
272 }
273 if (m_writeSDOs) {
274 if(sdoCollection){
275 // find hit
276 auto pos = sdoCollection->find(surfaceID);
277 int sdo_word = -1000000;
278 if( pos != sdoCollection->end() ) {
279 sdo_word = pos->second.word();
280 }
281 AUXDATA(xprd, int, sdo_word) = sdo_word;
282 }
283 }
284
285 }
286 }
287 ATH_MSG_DEBUG( " recorded TRT_PrepData obejcts: size " << xaod->size() );
288
289
290
291 // Code to test that something was added to SG:
292 StatusCode sc = StatusCode::SUCCESS;
293
294 // --- end of event. Disable one-time warnings
295 m_firstEventWarnings = false;
296
297 return sc;
298}
299
301//
302// Finalize method:
303//
306{
307 return StatusCode::SUCCESS;
308}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
static Double_t sc
#define AUXDATA(OBJ, TYP, NAME)
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
This is an Identifier helper class for the TRT subdetector.
const ServiceHandle< StoreGateSvc > & detStore() const
value_type get_compact() const
Get the compact id.
Virtual base class of TRT readout elements.
virtual const Amg::Vector3D & center() const override final
Element Surface: center of a straw layer.
A PRD is mapped onto all contributing particles.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
virtual StatusCode finalize()
ServiceHandle< ITRT_StrawNeighbourSvc > m_neighbourSvc
virtual StatusCode initialize()
SG::ReadHandleKey< InDet::TRT_DriftCircleContainer > m_driftcirclecontainer
ToolHandle< ITRT_StrawStatusSummaryTool > m_TRTStrawSummaryTool
const TRT_ID * m_TRTHelper
const InDetDD::TRT_DetectorManager * m_trtman
Gaudi::Property< bool > m_writeSDOs
ToolHandle< ITRT_DriftFunctionTool > m_driftFunctionTool
Gaudi::Property< bool > m_useTruthInfo
SG::WriteHandleKey< xAOD::TrackMeasurementValidationContainer > m_xAodContainer
SG::ReadHandleKey< InDetSimDataCollection > m_SDOcontainer
ToolHandle< ITRT_CalDbTool > m_trtcaldbTool
SG::WriteHandleKey< std::vector< unsigned int > > m_xAodOffset
virtual StatusCode execute(const EventContext &ctx)
Execute method.
SG::ReadHandleKey< PRD_MultiTruthCollection > m_multiTruth
void setLocalPositionError(float localXError, float localYError, float localXYCorrelation)
Sets the local position error.
void setLocalPosition(float localX, float localY)
Sets the local position.
void setIdentifier(uint64_t identifier)
Sets the identifier.
void setGlobalPosition(float globalX, float globalY, float globalZ)
Sets the global position.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
int uniqueID(const T &p)
TrackMeasurementValidation_v1 TrackMeasurementValidation
Reference the current persistent version: