ATLAS Offline Software
PixelClusterization.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
12 // Silicon trackers includes
16 
17 #include "Identifier/Identifier.h"
21 
22 
25 
26 #include "StoreGate/WriteHandle.h"
27 
28 
29 namespace InDet{
30  using namespace InDet;
31  // Constructor with parameters:
32  PixelClusterization::PixelClusterization(const std::string &name, ISvcLocator *pSvcLocator) :
33  AthReentrantAlgorithm(name, pSvcLocator),
34  m_clusteringTool("InDet::MergedPixelsTool", this), //made private
35  m_gangedAmbiguitiesFinder("InDet::PixelGangedAmbiguitiesFinder", this), //made private
36  m_rdoContainerKey(""),
37  m_roiCollectionKey(""),
38  m_roiSeeded(false),
39  m_idHelper(nullptr),
40  m_clusterContainerKey(""),
41  m_clusterContainerLinkKey(""),
42  m_ambiguitiesMapKey(""),
43  m_clusterContainercacheKey("") {
44  // Get parameter values from jobOptions file
45  declareProperty("DataObjectName", m_rdoContainerKey = std::string("PixelRDOs"));
46  declareProperty("clusteringTool", m_clusteringTool);
47  declareProperty("gangedAmbiguitiesFinder", m_gangedAmbiguitiesFinder);
48  declareProperty("ClustersName",
49  m_clusterContainerKey = std::string("PixelClusters"),
50  "Pixel cluster container");
51  declareProperty("ClustersLinkName_",
52  m_clusterContainerLinkKey = std::string("PixelClusters"),
53  "Pixel cluster container link name (don't set this)");
54  declareProperty("AmbiguitiesMap",
55  m_ambiguitiesMapKey = std::string("PixelClusterAmbiguitiesMap"),
56  "Ambiguity Map container");
57  declareProperty("RoIs", m_roiCollectionKey = std::string(""), "RoIs to read in");
58  declareProperty("isRoI_Seeded", m_roiSeeded = false, "Use RoI");
59  declareProperty("ClusterContainerCacheKey", m_clusterContainercacheKey, "Optional External Pixel cluster Cache");
60  }
61 
62  //-----------------------------------------------------------------------------
63  // Initialize method:
65  // get the InDet::MergedPixelsTool
66  ATH_CHECK(m_clusteringTool.retrieve());
67  // get the InDet::PixelGangedAmbiguitiesFinder
69  // Get the Pixel helper
70  ATH_CHECK(detStore()->retrieve(m_idHelper,"PixelID"));
71  ATH_CHECK( m_rdoContainerKey.initialize() );
72  if (m_roiSeeded) {
74  ATH_CHECK(m_regionSelector.retrieve());
75  }else{
76  m_regionSelector.disable();
78  }
79 
81 
86 
87  if ( !m_monTool.empty() ) {
88  ATH_CHECK(m_monTool.retrieve() );
89  }
90 
91  return StatusCode::SUCCESS;
92  }
93 
94  //----------------------------------------------------------------------------
95  // Execute method:
96  StatusCode PixelClusterization::execute(const EventContext& ctx) const {
97  //Monitoring Tool Configuration
98  auto mnt_timer_Total = Monitored::Timer<std::chrono::milliseconds>("TIME_Total");
99 
100 
101 
103  if(m_clusterContainercacheKey.key().empty()){
104  ATH_CHECK( clusterContainer.record (std::make_unique<PixelClusterContainer>(m_idHelper->wafer_hash_max(), EventContainers::Mode::OfflineFast)) );
105  }else{
107  ATH_CHECK(clusterContainercache.isValid());
108  ATH_CHECK( clusterContainer.record (std::make_unique<PixelClusterContainer>(clusterContainercache.ptr() )));
109  }
110 
111  ATH_CHECK(clusterContainer.isValid());
112  ATH_MSG_DEBUG( "Container '" << clusterContainer->name() << "' initialised" );
113 
114  ATH_CHECK( clusterContainer.symLink (m_clusterContainerLinkKey) );
115  ATH_MSG_DEBUG( "Pixel clusters '" << clusterContainer.name() << "' symlinked in StoreGate");
116 
117  ATH_MSG_DEBUG( "Creating the ganged ambiguities map");
119  ambiguitiesMap = std::make_unique<PixelGangedClusterAmbiguities>();
120 
122 
123  ATH_CHECK(rdoContainer.isValid());
124 
125  ATH_MSG_DEBUG( "Data object " << rdoContainer.name() << " found" );
126 
127  std::unique_ptr<DataPool<PixelCluster>> dataItemsPool = nullptr;
128  const bool hasExternalCache = rdoContainer->hasExternalCache();
129  if (!hasExternalCache) {
130  dataItemsPool = std::make_unique<DataPool<PixelCluster>>(ctx);
131  dataItemsPool->reserve(20000); // Some large default size
132  }else if (m_useDataPoolWithCache){
133  dataItemsPool = std::make_unique<DataPool<PixelCluster>>(ctx);
134  //Default size for now 1024 let it expand on its own
135  }
136 
137 
138  if (!m_roiSeeded) {//Full-scan mode
139  PixelRDO_Container::const_iterator rdoCollections = rdoContainer->begin();
140  PixelRDO_Container::const_iterator rdoCollectionsEnd = rdoContainer->end();
141 
142  for(; rdoCollections!=rdoCollectionsEnd; ++rdoCollections){
143  const COLLECTION* RDO_Collection(*rdoCollections);
144  if (!RDO_Collection || RDO_Collection->empty()) continue;
145  PixelClusterContainer::IDC_WriteHandle lock = clusterContainer->getWriteHandle(rdoCollections.hashId());
146  if( lock.OnlineAndPresentInAnotherView() ) continue;
147 
148  // Use one of the specific clustering AlgTools to make clusters
149  std::unique_ptr<PixelClusterCollection> clusterCollection(
150  m_clusteringTool->clusterize(*RDO_Collection, *m_idHelper,
151  dataItemsPool.get(), ctx));
152 
153  if (clusterCollection && !clusterCollection->empty()){
154 
155  m_gangedAmbiguitiesFinder->execute(clusterCollection.get(),*ambiguitiesMap);
156  ATH_CHECK(lock.addOrDelete( std::move(clusterCollection) ));
157  }else{
158  ATH_MSG_DEBUG("No PixelClusterCollection to write");
159  }
160  }
161  }
162  else {//enter RoI-seeded mode
164  ATH_CHECK(roiCollection.isValid());
165 
166  TrigRoiDescriptorCollection::const_iterator roi = roiCollection->begin();
167  TrigRoiDescriptorCollection::const_iterator roiE = roiCollection->end();
168 
169  std::vector<IdentifierHash> listOfPixIds;
170  for (; roi!=roiE; ++roi) {
171 
172  listOfPixIds.clear();//Prevents needless memory reallocations
173  m_regionSelector->HashIDList( **roi, listOfPixIds);
174  ATH_MSG_VERBOSE(**roi);
175  ATH_MSG_VERBOSE( "REGTEST: Pixel : Roi contains "
176  << listOfPixIds.size() << " det. Elements" );
177  for (auto & listOfPixId : listOfPixIds) {
178  const InDetRawDataCollection<PixelRDORawData>* RDO_Collection (rdoContainer->indexFindPtr(listOfPixId));
179 
180  if (!RDO_Collection) continue;
181  PixelClusterContainer::IDC_WriteHandle lock = clusterContainer->getWriteHandle(listOfPixId);
182  if( lock.OnlineAndPresentInAnotherView() ) continue;
183 
184  // Use one of the specific clustering AlgTools to make clusters
185  std::unique_ptr<PixelClusterCollection> clusterCollection(
186  m_clusteringTool->clusterize(*RDO_Collection, *m_idHelper,
187  dataItemsPool.get(), ctx));
188  if (clusterCollection && !clusterCollection->empty()) {
189  ATH_MSG_VERBOSE( "REGTEST: Pixel : clusterCollection contains "
190  << clusterCollection->size() << " clusters" );
191  m_gangedAmbiguitiesFinder->execute(clusterCollection.get(),*ambiguitiesMap);
192  ATH_CHECK(lock.addOrDelete( std::move(clusterCollection) ));
193 
194  } else {
195  ATH_MSG_DEBUG("No PixelClusterCollection to write");
196  }
197  }
198  }
199  }
200  ATH_CHECK(clusterContainer.setConst());
201  ATH_MSG_DEBUG("clusterContainer->numberOfCollections() " << clusterContainer->numberOfCollections());
202  ATH_CHECK(ambiguitiesMap.isValid());
203  ATH_MSG_DEBUG( "PixelClusterAmbiguitiesMap recorded in StoreGate");
204  auto monTime = Monitored::Group(m_monTool, mnt_timer_Total);
205  return StatusCode::SUCCESS;
206  }
207 
208 }// namespace closure
209 
210 
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...
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
InDet::PixelClusterization::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: PixelClusterization.cxx:96
InDet::PixelClusterization::m_roiCollectionKey
SG::ReadHandleKey< TrigRoiDescriptorCollection > m_roiCollectionKey
Definition: PixelClusterization.h:83
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
InDet::PixelClusterization::m_idHelper
const PixelID * m_idHelper
Definition: PixelClusterization.h:87
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
InDet
DUMMY Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
SG::WriteHandle::symLink
StatusCode symLink(const WriteHandleKey< U > &key)
Make an explicit link.
InDet::PixelClusterization::m_roiSeeded
bool m_roiSeeded
Definition: PixelClusterization.h:86
SG::UpdateHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
InDet::PixelClusterization::m_clusterContainercacheKey
SG::UpdateHandleKey< InDet::PixelClusterContainerCache > m_clusterContainercacheKey
Definition: PixelClusterization.h:91
InDet::PixelClusterization::m_regionSelector
ToolHandle< IRegSelTool > m_regionSelector
region selector tool
Definition: PixelClusterization.h:84
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
InDet::PixelClusterization::m_gangedAmbiguitiesFinder
ToolHandle< PixelGangedAmbiguitiesFinder > m_gangedAmbiguitiesFinder
class to find out which clusters shares ganged pixels
Definition: PixelClusterization.h:81
SG::VarHandleBase::setConst
StatusCode setConst()
Set the 'const' bit for the bound proxy in the store.
Definition: StoreGate/src/VarHandleBase.cxx:599
IPixelClusteringTool.h
SG::UpdateHandle::ptr
pointer_type ptr()
Dereference the pointer.
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
InDet::PixelClusterization::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: PixelClusterization.h:85
IdentifiableContainerMT::hasExternalCache
virtual bool hasExternalCache() const override final
Definition: IdentifiableContainerMT.h:155
AtlasDetectorID.h
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
WriteHandle.h
Handle class for recording to StoreGate.
PixelRDORawData.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
InDetRawDataCollection
Definition: InDetRawDataCollection.h:31
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IdentifiableContainerMT::end
const_iterator end() const
return const_iterator for end of container
Definition: IdentifiableContainerMT.h:242
PixelGangedAmbiguitiesFinder.h
IdentifiableContainerMT::const_iterator
Definition: IdentifiableContainerMT.h:82
IdentifiableContainerMT::begin
const_iterator begin() const
return const_iterator for first entry
Definition: IdentifiableContainerMT.h:236
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
InDet::PixelClusterization::m_rdoContainerKey
SG::ReadHandleKey< PixelRDO_Container > m_rdoContainerKey
Definition: PixelClusterization.h:82
PixelClusterCollection.h
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
IdentifiableContainerMT::const_iterator::hashId
IdentifierHash hashId() const
hashId of the pointed-to element
Definition: IdentifiableContainerMT.h:130
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
InDet::PixelClusterization::m_ambiguitiesMapKey
SG::WriteHandleKey< PixelGangedClusterAmbiguities > m_ambiguitiesMapKey
Definition: PixelClusterization.h:90
SG::UpdateHandle
Definition: UpdateHandle.h:94
PixelID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: PixelID.cxx:912
EventContainers::Mode::OfflineFast
@ OfflineFast
InDet::PixelClusterization::m_clusteringTool
ToolHandle< IPixelClusteringTool > m_clusteringTool
Definition: PixelClusterization.h:79
PixelRDO_Container.h
InDet::PixelClusterization::initialize
virtual StatusCode initialize() override
Definition: PixelClusterization.cxx:64
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
IdentifiableContainerMT::indexFindPtr
virtual const T * indexFindPtr(IdentifierHash hashId) const override final
return pointer on the found entry or null if out of range using hashed index - fast version,...
Definition: IdentifiableContainerMT.h:292
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
InDet::PixelClusterization::m_clusterContainerKey
SG::WriteHandleKey< PixelClusterContainer > m_clusterContainerKey
Definition: PixelClusterization.h:88
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
InDet::PixelClusterization::m_clusterContainerLinkKey
SG::WriteHandleKey< SiClusterContainer > m_clusterContainerLinkKey
Definition: PixelClusterization.h:89
PixelClusterization.h
InDet::PixelClusterization::m_useDataPoolWithCache
Gaudi::Property< bool > m_useDataPoolWithCache
Definition: PixelClusterization.h:92
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
InDet::PixelClusterization::PixelClusterization
PixelClusterization()=delete