ATLAS Offline Software
Loading...
Searching...
No Matches
SpacePointCopier.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4#include <algorithm>
8#include "SpacePointCopier.h"
11
12SpacePointCopier::SpacePointCopier(const std::string& name, ISvcLocator* pSvcLocator) :
13 AthReentrantAlgorithm(name, pSvcLocator)
14{
15}
16
20
22{
23 ATH_CHECK( m_pixelSPKey.initialize() );
24 ATH_CHECK( m_SCTSPKey.initialize() );
25 ATH_CHECK( m_tracksKey.initialize() );
26 ATH_CHECK( m_outputKey.initialize() );
27 return StatusCode::SUCCESS;
28}
29
31{
32 return StatusCode::SUCCESS;
33}
34
35StatusCode SpacePointCopier::execute(const EventContext& context) const
36{
37 auto pixelSPContainer = SG::makeHandle(m_pixelSPKey, context);
38 auto SCTSPContainer = SG::makeHandle(m_SCTSPKey, context);
39
40 auto output = std::make_unique<xAOD::BaseContainer>();
41 auto outputAux = std::make_unique<xAOD::AuxContainerBase>();
42 output->setStore(outputAux.get());
43
44 size_t pixSize = 0;
45 for ( auto coll: *pixelSPContainer ) {
46 pixSize += coll->size();
47 }
48 size_t SCTSize = 0;
49 for ( auto coll: *SCTSPContainer ) {
50 SCTSize += coll->size();
51 }
52 // avoid recording for large events (for them the output collection will be empty)
53 auto goodNumberOfSpacePoints = [this, SCTSize, pixSize](){
54 return pixSize <= m_maxPixSP
55 or SCTSize <= m_maxSCTSP
56 or pixSize + SCTSize <= m_maxTotalSP;
57 };
58
59 auto goodNumberOfTracks = [this, &context]() {
60 auto tracksHandle = SG::makeHandle(m_tracksKey, context);
61 return tracksHandle->size() <= m_maxTracks;
62 };
63
64 if ( goodNumberOfSpacePoints() and goodNumberOfTracks() ) {
65 ATH_MSG_DEBUG("Converting " << pixSize + SCTSize << " SPs");
66 static const SG::Accessor< float > x ("x");
67 static const SG::Accessor< float > y ("y");
68 static const SG::Accessor< float > z ("z");
69 static const SG::Accessor< float > tot ("tot");
70 static const SG::Accessor< short > csize ("csize");
71 static const SG::Accessor< unsigned int > module1 ("module1");
72 static const SG::Accessor< unsigned int > module2 ("module2");
73
74 const PixelID *pixelID = nullptr;
75 const SCT_ID *stripID = nullptr;
76
77 ATH_CHECK(detStore()->retrieve(pixelID, "PixelID"));
78 ATH_CHECK(detStore()->retrieve(stripID, "SCT_ID"));
79
80
81 for ( auto coll: *pixelSPContainer ) {
82 for ( auto sp: *coll ) {
83 auto *item = new SG::AuxElement();
84 output->push_back( item );
85 x(*item) = float(sp->globalPosition().x());
86 y(*item) = float(sp->globalPosition().y());
87 z(*item) = float(sp->globalPosition().z());
88 const InDet::PixelCluster* cluster = static_cast<const InDet::PixelCluster *>(sp->clusterList().first);
89 tot(*item) = float(cluster->totalToT());
90 csize(*item) = short(cluster->totList().size());
91 auto[hashId1, hashId2] = sp->elementIdList();
92 module1(*item) = hashId1;
93 module2(*item) = hashId2;
94
95 }
96 }
97
98
99 for ( auto coll: *SCTSPContainer ) {
100 for ( auto sp: *coll ) {
101 auto *item = new SG::AuxElement();
102 output->push_back( item );
103 x(*item) = float(sp->globalPosition().x());
104 y(*item) = float(sp->globalPosition().y());
105 z(*item) = float(sp->globalPosition().z());
106 tot(*item) = 0;
107 csize(*item) = 0;
108
109 auto[hashId1, hashId2] = sp->elementIdList();
110 module1(*item) = hashId1;
111 module2(*item) = hashId2;
112 }
113 }
114 for ( size_t i = 0; i < std::min(10ul, output->size()); ++i ) {
115 static const SG::ConstAccessor<float> xAcc ("x");
116 static const SG::ConstAccessor<float> yAcc ("y");
117 static const SG::ConstAccessor<float> zAcc ("z");
118 ATH_MSG_DEBUG("Saves SP x y z: " << xAcc(*output->at(i))
119 << " " << yAcc(*output->at(i))
120 << " " << zAcc(*output->at(i)) );
121 }
122 ATH_MSG_DEBUG("... and more ...");
123 }
124
125 auto outputHandle = SG::makeHandle(m_outputKey, context);
126 ATH_CHECK( outputHandle.record(std::move(output), std::move(outputAux)));
127
128 return StatusCode::SUCCESS;
129}
130
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
Helper class to provide constant type-safe access to aux data.
Helper class to provide type-safe access to aux data.
static Double_t sp
This is an Identifier helper class for the Pixel subdetector.
This is an Identifier helper class for the SCT subdetector.
#define y
#define x
#define z
const ServiceHandle< StoreGateSvc > & detStore() const
An algorithm that can be simultaneously executed in multiple threads.
This is an Identifier helper class for the Pixel subdetector.
Definition PixelID.h:67
This is an Identifier helper class for the SCT subdetector.
Definition SCT_ID.h:68
Base class for elements of a container that can have aux data.
Definition AuxElement.h:483
Helper class to provide constant type-safe access to aux data.
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_tracksKey
virtual StatusCode execute(const EventContext &context) const override
SpacePointCopier(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< size_t > m_maxTracks
SG::WriteHandleKey< xAOD::BaseContainer > m_outputKey
Gaudi::Property< size_t > m_maxPixSP
Gaudi::Property< size_t > m_maxTotalSP
virtual ~SpacePointCopier() override
virtual StatusCode finalize() override
SG::ReadHandleKey< SpacePointContainer > m_pixelSPKey
Gaudi::Property< size_t > m_maxSCTSP
SG::ReadHandleKey< SpacePointContainer > m_SCTSPKey
virtual StatusCode initialize() override
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())