ATLAS Offline Software
Loading...
Searching...
No Matches
TRTRetriever.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "TRTRetriever.h"
7#include "JiveXML/DataType.h"
8
13
14// ReadHandle
16
17namespace JiveXML {
18
25 TRTRetriever::TRTRetriever(const std::string& type,const std::string& name,const IInterface* parent):
26 AthAlgTool(type,name,parent)
27 {
28 //Declare the interface
29 declareInterface<IDataRetriever>(this);
30
31 //And properties
32 declareProperty("TRTTruthMap" , m_TRTTruthMapKey = "PRD_MultiTruthTRT");
33 }
34
36 ATH_CHECK( m_geo.retrieve() );
37 ATH_CHECK( m_TRTDriftCircleCollKey.initialize() );
38 m_useTRTTruthMap = !m_TRTTruthMapKey.key().empty();
40 return StatusCode::SUCCESS;
41 }
42
43 StatusCode TRTRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
44 //be verbose
45 ATH_MSG_DEBUG( "Retrieving " << dataTypeName() );
46
47 //First try to retrieve the DriftCircleContainer
49 if ( !DriftCircleContainer.isValid() ) {
50 ATH_MSG_DEBUG( "Unable to retrieve TRT_DriftCircleContainer with name " << m_TRTDriftCircleCollKey.key() );
51 return StatusCode::RECOVERABLE;
52 }
53
54 //Also try to obtain the truth container
56 if ( m_useTRTTruthMap ) {
57 TRTMultiTruthMap = SG::makeHandle(m_TRTTruthMapKey);
58 if ( !TRTMultiTruthMap.isValid() ){
59 //Only warn if this container is not available
60 ATH_MSG_DEBUG( "Unable to retrieve PRD_MultiTruthCollection with name " << m_TRTTruthMapKey.key() );
61 }
62 }
63
64 //Get total size of all all drift circles in all collections
65 unsigned long NDriftCircleTotal = 0;
66 //Loop over collections in container
67 for (const auto DriftCircleColl : *DriftCircleContainer)
68 NDriftCircleTotal += DriftCircleColl->size();
69
70 //be verbose
71 ATH_MSG_VERBOSE( "Reserving space for " << NDriftCircleTotal << " entries" );
72
73 //Rerserve space in the map
74 DataVect rhoz; rhoz.reserve(NDriftCircleTotal);
75 DataVect phi; phi.reserve(NDriftCircleTotal);
76 DataVect driftR; driftR.reserve(NDriftCircleTotal);
77 DataVect threshold; threshold.reserve(NDriftCircleTotal);
78 DataVect ident; ident.reserve(NDriftCircleTotal);
79 DataVect sub; sub.reserve(NDriftCircleTotal);
80 DataVect noise; noise.reserve(NDriftCircleTotal);
81 DataVect timeOverThreshold; timeOverThreshold.reserve(NDriftCircleTotal);
82 DataVect bitPattern; bitPattern.reserve(NDriftCircleTotal);
83 DataVect numBarcodes; numBarcodes.reserve(NDriftCircleTotal);
84 DataVect barcodes; barcodes.reserve(NDriftCircleTotal); //< on average less than one, so this should be enough
85
86 //Now loop over container to retrieve the data
87 for (const auto DriftCircleColl : *DriftCircleContainer) {
88
90 for (const auto driftcircle : *DriftCircleColl){
91
92 //Get the drift cirlce itself and its unique identifier
93
94 //In verbose mode, print out drift circle information
95 ATH_MSG_VERBOSE( "Retrieving information from " << (*driftcircle) );
96
97 Identifier id = driftcircle->identify();
98
99 //Check if it is valid
100 if (! id.is_valid()) {
101 ATH_MSG_DEBUG( "Ignoring TRT_DriftCircle with invalid identifier " << id );
102 continue;
103 }
104
105 //Store the identifier
106 ident.push_back(DataType(id.get_compact()));
107
112 const InDetDD::TRT_BaseElement* element = m_geo->TRTGeoManager()->getElement(m_geo->TRTIDHelper()->layer_id(id));
113
114 //get global coord of straw
115 Amg::Vector3D global = element->strawTransform(m_geo->TRTIDHelper()->straw(id))*Amg::Vector3D(0.,0.,0.);
116
117 //store the phi value
118 phi.push_back(DataType( (global.phi()<0) ? global.phi() + 2*M_PI : global.phi()));
119
120 //store rho for barrel and z for endcap
122 rhoz.push_back(DataType(global.perp()*CLHEP::mm/CLHEP::cm));
123 else if (element->type()==InDetDD::TRT_BaseElement::ENDCAP)
124 rhoz.push_back(DataType(global.z()*CLHEP::mm/CLHEP::cm));
125 else
126 ATH_MSG_VERBOSE( "Unknown TRT base element of type " << element->type() );
127
128 //Store local position parameters
129 driftR.push_back(DataType((driftcircle->localPosition())[Trk::driftRadius]*CLHEP::mm/CLHEP::cm));
130
131 //Get subdetector number
132 switch ( m_geo->TRTIDHelper()->barrel_ec(id) ) {
133 case -2 : sub.push_back(DataType( 0 )); break;
134 case -1 : sub.push_back(DataType( 1 )); break;
135 case 1 : sub.push_back(DataType( 2 )); break;
136 case 2 : sub.push_back(DataType( 3 )); break;
137 default : sub.push_back(DataType(-1 ));
138 }
139
140 //Store threshold related parameters
141 threshold.push_back(DataType(driftcircle->highLevel()));
142 timeOverThreshold.push_back(DataType(driftcircle->timeOverThreshold()));
143 noise.push_back(DataType(driftcircle->isNoise()));
144 bitPattern.push_back(DataType(driftcircle->getWord()));
145
149 if ( !m_useTRTTruthMap || !TRTMultiTruthMap.isValid() ) continue;
150
151 //Count number of barcodes we get
152 int NBarcodes = 0;
153 //Loop over associated truth tracks with same id
154 using iter = PRD_MultiTruthCollection::const_iterator;
155 std::pair<iter,iter> equalIDRange = TRTMultiTruthMap->equal_range(id);
156 for ( iter TRTMultiTruthMapItr = equalIDRange.first; TRTMultiTruthMapItr != equalIDRange.second; ++TRTMultiTruthMapItr){
157 NBarcodes++;
158 barcodes.push_back(DataType(TRTMultiTruthMapItr->second.barcode()));
159 }
160 numBarcodes.push_back(DataType(NBarcodes));
161 } //loop over collection
162 }//loop over container
163
164 //Add everything to our data map
165 DataMap dataMap;
166 dataMap["rhoz"]=rhoz;
167 dataMap["phi"]=phi;
168 dataMap["driftR"]=driftR;
169 dataMap["threshold"]=threshold;
170 dataMap["id"]=ident;
171 dataMap["sub"]=sub;
172 dataMap["noise"]=noise;
173 dataMap["timeOverThreshold"]=timeOverThreshold;
174 dataMap["bitPattern"]=bitPattern;
175
176 //Only write truth association tags if we processed truth
177 if ( numBarcodes.size() > 0 ){
178 //Add barcodes counter
179 dataMap["numBarcodes"]=numBarcodes;
180 // Compute the "multiple" for barcodes and put the vector in the map.
181 std::string bctag = "barcodes multiple=\""+DataType(barcodes.size()/double(numBarcodes.size())).toString()+"\"";
182 dataMap[bctag]=barcodes;
183 }
184
185 //be verbose
186 ATH_MSG_DEBUG( dataTypeName() << ": " << rhoz.size() );
187
188 //forward data to formating tool and return
189 return FormatTool->AddToEvent(dataTypeName(), "", &dataMap);
190 }
191}
192
#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
defines an "iterator" over instances of a given type in StoreGateSvc
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