ATLAS Offline Software
Loading...
Searching...
No Matches
xAODTrackParticleRetriever.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "CLHEP/Units/SystemOfUnits.h"
7
9
10namespace JiveXML {
11
18 xAODTrackParticleRetriever::xAODTrackParticleRetriever(const std::string& type,const std::string& name,const IInterface* parent):
19 AthAlgTool(type,name,parent){}
20
21
23 ATH_CHECK(m_keys.initialize());
24 return StatusCode::SUCCESS;
25 }
26
31 StatusCode xAODTrackParticleRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
32
33 ATH_MSG_DEBUG("In retrieve()");
34
35
36 // Loop through the keys and retrieve the corresponding data
37 for (const auto& key : m_keys) {
39 if (cont.isValid()) {
40 DataMap data = getData(&(*cont));
41 if (FormatTool->AddToEvent(dataTypeName(), key.key() + "_xAOD", &data).isFailure()) {
42 ATH_MSG_WARNING("Failed to add collection " << key.key());
43 } else {
44 ATH_MSG_DEBUG(" (" << key.key() << ") retrieved");
45 }
46 } else {
47 ATH_MSG_WARNING("Collection " << key.key() << " not found in SG");
48 }
49 }
50
51 return StatusCode::SUCCESS;
52 }
53
54
60
61 ATH_MSG_DEBUG("in getData()");
62
64
65 DataVect d0; d0.reserve(TrackParticleCont->size());
66 DataVect z0; z0.reserve(TrackParticleCont->size());
67 DataVect pt; pt.reserve(TrackParticleCont->size());
68 DataVect phi0; phi0.reserve(TrackParticleCont->size());
69 DataVect cotTheta; cotTheta.reserve(TrackParticleCont->size());
70 DataVect label; label.reserve(TrackParticleCont->size());
71 DataVect nBLayerHits; nBLayerHits.reserve(TrackParticleCont->size());
72 DataVect nPixHits; nPixHits.reserve(TrackParticleCont->size());
73 DataVect nSCTHits; nSCTHits.reserve(TrackParticleCont->size());
74 DataVect nTRTHits; nTRTHits.reserve(TrackParticleCont->size());
75
76 xAOD::TrackParticleContainer::const_iterator TrackParticleItr = TrackParticleCont->begin();
77 xAOD::TrackParticleContainer::const_iterator TrackParticleItrE = TrackParticleCont->end();
78
79 int counter = 0;
80 float charge = 0.;
81 float myQOverP = 0.;
82 double countHits = 0.;
83 std::string labelStr = "unknownHits";
84
85 for (; TrackParticleItr != TrackParticleItrE; ++TrackParticleItr) {
86
87 ATH_MSG_VERBOSE(" TrackParticle #" << counter++ << " : d0 = " << (*TrackParticleItr)->d0() << ", z0 = "
88 << (*TrackParticleItr)->z0() << ", pt[GeV] = " << (*TrackParticleItr)->pt()*(1./CLHEP::GeV)
89 << ", phi = " << (*TrackParticleItr)->phi()
90 << ", qOverP = " << (*TrackParticleItr)->qOverP()
91 << ", abs(qOverP) = " << fabs((*TrackParticleItr)->qOverP()));
92
93 // Event/xAOD/xAODTrackingCnv/trunk/src/TrackParticleCnvAlg.cxx#L190 Info from Nick Styles
94
95 uint8_t numberOfBLayerHits=0;
96 uint8_t numberOfBLayerHits_tmp=0;
97 if ( (*TrackParticleItr)->summaryValue(numberOfBLayerHits_tmp,xAOD::numberOfBLayerHits) ){
98 numberOfBLayerHits += numberOfBLayerHits_tmp;
99 }
100 uint8_t numberOfPixelHits = 0;
101 uint8_t numberOfPixelHits_tmp = 0;
102 if ( (*TrackParticleItr)->summaryValue(numberOfPixelHits_tmp,xAOD::numberOfPixelHits)){
103 numberOfPixelHits += numberOfPixelHits_tmp;
104 }
105 uint8_t numberOfTRTHits = 0;
106 uint8_t numberOfTRTHits_tmp = 0;
107 if ( (*TrackParticleItr)->summaryValue(numberOfTRTHits_tmp,xAOD::numberOfTRTHits)){
108 numberOfTRTHits += numberOfTRTHits_tmp;
109 }
110 uint8_t numberOfSCTHits = 0;
111 uint8_t numberOfSCTHits_tmp = 0;
112 if ( (*TrackParticleItr)->summaryValue(numberOfSCTHits_tmp,xAOD::numberOfSCTHits)){
113 numberOfSCTHits += numberOfSCTHits_tmp;
114 }
115 labelStr = "_PixelHits"+DataType( (double)numberOfPixelHits ).toString()
116 + "_SCTHits"+DataType( (double)numberOfSCTHits ).toString()
117 + "_BLayerHits"+DataType( (double)numberOfBLayerHits ).toString()
118 + "_TRTHits"+DataType( (double)numberOfTRTHits ).toString() ;
119
120 countHits = (double)numberOfBLayerHits + (double)numberOfPixelHits
121 + (double)numberOfSCTHits + (double)numberOfTRTHits;
122
123 ATH_MSG_VERBOSE(" TrackParticle #" << counter
124 << " BLayer hits: " << (double)numberOfBLayerHits
125 << ", Pixel hits: " << (double)numberOfPixelHits
126 << ", SCT hits: " << (double)numberOfSCTHits
127 << ", TRT hits: " << (double)numberOfTRTHits
128 << ", Total hits: " << countHits
129 << "; Label: " << labelStr);
130
131 nBLayerHits.emplace_back( DataType( (double)numberOfBLayerHits ));
132 nPixHits.emplace_back( DataType( (double)numberOfPixelHits ));
133 nSCTHits.emplace_back( DataType( (double)numberOfSCTHits ));
134 nTRTHits.emplace_back( DataType( (double)numberOfTRTHits ));
135
136 label.emplace_back( DataType( labelStr ).toString() );
137 d0.emplace_back(DataType((*TrackParticleItr)->d0()/CLHEP::cm));
138 z0.emplace_back(DataType((*TrackParticleItr)->z0()/CLHEP::cm));
139 phi0.emplace_back(DataType((*TrackParticleItr)->phi()));
140
141 // pt is always positive, get charge from qOverP
142 myQOverP = (*TrackParticleItr)->qOverP() ;
143 if (fabs(myQOverP) != myQOverP){
144 charge = -1.;
145 }else{
146 charge = +1.;
147 }
148 pt.emplace_back(DataType(( charge*(*TrackParticleItr)->pt() )/CLHEP::GeV));
149
150 if ( (*TrackParticleItr)->theta() == 0.) {
151 cotTheta.emplace_back(DataType(9999.));
152 } else {
153 cotTheta.emplace_back(DataType(1./tan((*TrackParticleItr)->theta())));
154 }
155 } // end TrackParticleIterator
156
157 // four-vectors
158 DataMap["d0"] = d0;
159 DataMap["z0"] = z0;
160 DataMap["pt"] = pt;
161 DataMap["phi0"] = phi0;
162 DataMap["cotTheta"] = cotTheta;
163 DataMap["label"] = label;
164 DataMap["nBLayerHits"] = nBLayerHits;
165 DataMap["nPixHits"] = nPixHits;
166 DataMap["nSCTHits"] = nSCTHits;
167 DataMap["nTRTHits"] = nTRTHits;
168
169 ATH_MSG_DEBUG(dataTypeName() << " retrieved with " << d0.size() << " entries");
170
171 //All collections retrieved okay
172 return DataMap;
173
174 }
175
176
177} // JiveXML namespace
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
double charge(const T &p)
Definition AtlasPID.h:997
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
DataModel_detail::const_iterator< DataVector > 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.
size_type size() const noexcept
Returns the number of elements in the collection.
SG::ReadHandleKeyArray< xAOD::TrackParticleContainer > m_keys
const DataMap getData(const xAOD::TrackParticleContainer *)
Puts the variables into a DataMap.
virtual std::string dataTypeName() const
Return the name of the data type that is generated by this retriever.
xAODTrackParticleRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
For each TrackParticle collections retrieve basic parameters.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::string label(const std::string &format, int i)
Definition label.h:19
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
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
@ numberOfTRTHits
number of TRT hits [unit8_t].
@ numberOfBLayerHits
these are the hits in the first pixel layer, i.e.
@ numberOfSCTHits
number of hits in SCT [unit8_t].
@ numberOfPixelHits
these are the pixel hits, including the b-layer [unit8_t].