ATLAS Offline Software
Loading...
Searching...
No Matches
TRTRetriever.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "TRTRetriever.h"
6#include "JiveXML/DataType.h"
7
12
13// ReadHandle
15
16namespace JiveXML {
17
24 TRTRetriever::TRTRetriever(const std::string& type,const std::string& name,const IInterface* parent):
25 AthAlgTool(type,name,parent)
26 {
27 //Declare the interface
28 declareInterface<IDataRetriever>(this);
29
30 //And properties
31 declareProperty("TRTTruthMap" , m_TRTTruthMapKey = "PRD_MultiTruthTRT");
32 }
33
35 ATH_CHECK( m_geo.retrieve() );
36 ATH_CHECK( m_TRTDriftCircleCollKey.initialize() );
37 m_useTRTTruthMap = !m_TRTTruthMapKey.key().empty();
39 return StatusCode::SUCCESS;
40 }
41
42 StatusCode TRTRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
43 //be verbose
44 ATH_MSG_DEBUG( "Retrieving " << dataTypeName() );
45
46 //First try to retrieve the DriftCircleContainer
48 if ( !DriftCircleContainer.isValid() ) {
49 ATH_MSG_DEBUG( "Unable to retrieve TRT_DriftCircleContainer with name " << m_TRTDriftCircleCollKey.key() );
50 return StatusCode::RECOVERABLE;
51 }
52
53 //Also try to obtain the truth container
55 if ( m_useTRTTruthMap ) {
56 TRTMultiTruthMap = SG::makeHandle(m_TRTTruthMapKey);
57 if ( !TRTMultiTruthMap.isValid() ){
58 //Only warn if this container is not available
59 ATH_MSG_DEBUG( "Unable to retrieve PRD_MultiTruthCollection with name " << m_TRTTruthMapKey.key() );
60 }
61 }
62
63 //Get total size of all all drift circles in all collections
64 unsigned long NDriftCircleTotal = 0;
65 //Loop over collections in container
66 for (const auto DriftCircleColl : *DriftCircleContainer)
67 NDriftCircleTotal += DriftCircleColl->size();
68
69 //be verbose
70 ATH_MSG_VERBOSE( "Reserving space for " << NDriftCircleTotal << " entries" );
71
72 //Rerserve space in the map
73 DataVect rhoz; rhoz.reserve(NDriftCircleTotal);
74 DataVect phi; phi.reserve(NDriftCircleTotal);
75 DataVect driftR; driftR.reserve(NDriftCircleTotal);
76 DataVect threshold; threshold.reserve(NDriftCircleTotal);
77 DataVect ident; ident.reserve(NDriftCircleTotal);
78 DataVect sub; sub.reserve(NDriftCircleTotal);
79 DataVect noise; noise.reserve(NDriftCircleTotal);
80 DataVect timeOverThreshold; timeOverThreshold.reserve(NDriftCircleTotal);
81 DataVect bitPattern; bitPattern.reserve(NDriftCircleTotal);
82 DataVect numBarcodes; numBarcodes.reserve(NDriftCircleTotal);
83 DataVect barcodes; barcodes.reserve(NDriftCircleTotal); //< on average less than one, so this should be enough
84
85 //Now loop over container to retrieve the data
86 for (const auto DriftCircleColl : *DriftCircleContainer) {
87
89 for (const auto driftcircle : *DriftCircleColl){
90
91 //Get the drift cirlce itself and its unique identifier
92
93 //In verbose mode, print out drift circle information
94 ATH_MSG_VERBOSE( "Retrieving information from " << (*driftcircle) );
95
96 Identifier id = driftcircle->identify();
97
98 //Check if it is valid
99 if (! id.is_valid()) {
100 ATH_MSG_DEBUG( "Ignoring TRT_DriftCircle with invalid identifier " << id );
101 continue;
102 }
103
104 //Store the identifier
105 ident.push_back(DataType(id.get_compact()));
106
111 const InDetDD::TRT_BaseElement* element = m_geo->TRTGeoManager()->getElement(m_geo->TRTIDHelper()->layer_id(id));
112
113 //get global coord of straw
114 Amg::Vector3D global = element->strawTransform(m_geo->TRTIDHelper()->straw(id))*Amg::Vector3D(0.,0.,0.);
115
116 //store the phi value
117 phi.push_back(DataType( (global.phi()<0) ? global.phi() + 2*M_PI : global.phi()));
118
119 //store rho for barrel and z for endcap
121 rhoz.push_back(DataType(global.perp()*CLHEP::mm/CLHEP::cm));
122 else if (element->type()==InDetDD::TRT_BaseElement::ENDCAP)
123 rhoz.push_back(DataType(global.z()*CLHEP::mm/CLHEP::cm));
124 else
125 ATH_MSG_VERBOSE( "Unknown TRT base element of type " << element->type() );
126
127 //Store local position parameters
128 driftR.push_back(DataType((driftcircle->localPosition())[Trk::driftRadius]*CLHEP::mm/CLHEP::cm));
129
130 //Get subdetector number
131 switch ( m_geo->TRTIDHelper()->barrel_ec(id) ) {
132 case -2 : sub.push_back(DataType( 0 )); break;
133 case -1 : sub.push_back(DataType( 1 )); break;
134 case 1 : sub.push_back(DataType( 2 )); break;
135 case 2 : sub.push_back(DataType( 3 )); break;
136 default : sub.push_back(DataType(-1 ));
137 }
138
139 //Store threshold related parameters
140 threshold.push_back(DataType(driftcircle->highLevel()));
141 timeOverThreshold.push_back(DataType(driftcircle->timeOverThreshold()));
142 noise.push_back(DataType(driftcircle->isNoise()));
143 bitPattern.push_back(DataType(driftcircle->getWord()));
144
148 if ( !m_useTRTTruthMap || !TRTMultiTruthMap.isValid() ) continue;
149
150 //Count number of barcodes we get
151 int NBarcodes = 0;
152 //Loop over associated truth tracks with same id
153 using iter = PRD_MultiTruthCollection::const_iterator;
154 std::pair<iter,iter> equalIDRange = TRTMultiTruthMap->equal_range(id);
155 for ( iter TRTMultiTruthMapItr = equalIDRange.first; TRTMultiTruthMapItr != equalIDRange.second; ++TRTMultiTruthMapItr){
156 NBarcodes++;
157 barcodes.push_back(DataType(TRTMultiTruthMapItr->second.barcode()));
158 }
159 numBarcodes.push_back(DataType(NBarcodes));
160 } //loop over collection
161 }//loop over container
162
163 //Add everything to our data map
164 DataMap dataMap;
165 dataMap["rhoz"]=rhoz;
166 dataMap["phi"]=phi;
167 dataMap["driftR"]=driftR;
168 dataMap["threshold"]=threshold;
169 dataMap["id"]=ident;
170 dataMap["sub"]=sub;
171 dataMap["noise"]=noise;
172 dataMap["timeOverThreshold"]=timeOverThreshold;
173 dataMap["bitPattern"]=bitPattern;
174
175 //Only write truth association tags if we processed truth
176 if ( numBarcodes.size() > 0 ){
177 //Add barcodes counter
178 dataMap["numBarcodes"]=numBarcodes;
179 // Compute the "multiple" for barcodes and put the vector in the map.
180 std::string bctag = "barcodes multiple=\""+DataType(barcodes.size()/double(numBarcodes.size())).toString()+"\"";
181 dataMap[bctag]=barcodes;
182 }
183
184 //be verbose
185 ATH_MSG_DEBUG( dataTypeName() << ": " << rhoz.size() );
186
187 //forward data to formating tool and return
188 return FormatTool->AddToEvent(dataTypeName(), "", &dataMap);
189 }
190}
191
#define M_PI
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
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:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Virtual base class of TRT readout elements.
virtual TRT_BaseElement::Type type() const =0
Type information: returns BARREL or ENDCAP.
const Amg::Transform3D & strawTransform(unsigned int straw) const
Straw transform - fast access in array, in Tracking frame: Amg.
bool m_useTRTTruthMap
The StoreGate key for the TRT MultiTruthMap with the track associations.
virtual StatusCode initialize()
initialize only geo model tool
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
SG::ReadHandleKey< InDet::TRT_DriftCircleContainer > m_TRTDriftCircleCollKey
The StoreGate key for the TRT Cluster collection to retrieve.
virtual std::string dataTypeName() const
Return the name of the data type.
const ToolHandle< IInDetGeoModelTool > m_geo
A tool handle to the geo model tool.
SG::ReadHandleKey< PRD_MultiTruthCollection > m_TRTTruthMapKey
TRTRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
double timeOverThreshold(unsigned int m_word)
Eigen::Matrix< double, 3, 1 > Vector3D
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
std::map< std::string, DataVect > DataMap
Definition DataType.h:59
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition DataType.h:58
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
@ driftRadius
trt, straws
Definition ParamDefs.h:53