ATLAS Offline Software
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"
10 #include "AthContainers/Accessor.h"
11 
12 SpacePointCopier::SpacePointCopier(const std::string& name, ISvcLocator* pSvcLocator) :
13  AthReentrantAlgorithm(name, pSvcLocator)
14 {
15 }
16 
18 {
19 }
20 
22 {
26  ATH_CHECK( m_outputKey.initialize() );
27  return StatusCode::SUCCESS;
28 }
29 
31 {
32  return StatusCode::SUCCESS;
33 }
34 
35 StatusCode 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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
xAOD::short
short
Definition: Vertex_v1.cxx:165
SG::Accessor< float >
SpacePointCopier::m_tracksKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_tracksKey
Definition: SpacePointCopier.h:31
PixelCluster.h
SG::AuxElement
Base class for elements of a container that can have aux data.
Definition: AuxElement.h:446
SG::ConstAccessor< float >
SpacePointCopier::SpacePointCopier
SpacePointCopier(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SpacePointCopier.cxx:12
SpacePointCopier::m_maxTotalSP
Gaudi::Property< size_t > m_maxTotalSP
Definition: SpacePointCopier.h:36
x
#define x
InDet::PixelCluster::totList
const std::vector< int > & totList() const
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/PixelCluster.h:201
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
SpacePointCopier::initialize
virtual StatusCode initialize() override
Definition: SpacePointCopier.cxx:21
SpacePointCopier::m_maxSCTSP
Gaudi::Property< size_t > m_maxSCTSP
Definition: SpacePointCopier.h:35
lumiFormat.i
int i
Definition: lumiFormat.py:92
z
#define z
SpacePointCopier::m_maxPixSP
Gaudi::Property< size_t > m_maxPixSP
Definition: SpacePointCopier.h:34
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
InDet::PixelCluster::totalToT
int totalToT() const
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/PixelCluster.h:205
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
LB_AnalMapSplitter.tot
tot
Definition: LB_AnalMapSplitter.py:46
SpacePointCopier::m_pixelSPKey
SG::ReadHandleKey< SpacePointContainer > m_pixelSPKey
Definition: SpacePointCopier.h:29
min
#define min(a, b)
Definition: cfImp.cxx:40
merge.output
output
Definition: merge.py:17
SpacePointCopier.h
SpacePointCopier::m_maxTracks
Gaudi::Property< size_t > m_maxTracks
Definition: SpacePointCopier.h:37
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
Accessor.h
Helper class to provide type-safe access to aux data.
item
Definition: ItemListSvc.h:43
SpacePointCopier::m_outputKey
SG::WriteHandleKey< xAOD::BaseContainer > m_outputKey
Definition: SpacePointCopier.h:32
InDet::PixelCluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/PixelCluster.h:49
SpacePointCopier::finalize
virtual StatusCode finalize() override
Definition: SpacePointCopier.cxx:30
y
#define y
SCT_ID
Definition: SCT_ID.h:68
SpacePointCopier::~SpacePointCopier
virtual ~SpacePointCopier() override
Definition: SpacePointCopier.cxx:17
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
SpacePointCopier::m_SCTSPKey
SG::ReadHandleKey< SpacePointContainer > m_SCTSPKey
Definition: SpacePointCopier.h:30
PixelID
Definition: PixelID.h:67
readCCLHist.float
float
Definition: readCCLHist.py:83
SpacePointCopier::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: SpacePointCopier.cxx:35