ATLAS Offline Software
Loading...
Searching...
No Matches
SCTOverlay.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
7
9
12
14
15namespace Overlay
16{
17 // Specialize copyCollection() for the SCT
18 template<>
19 std::unique_ptr<SCT_RDO_Collection> copyCollection(const IdentifierHash &hashId,
20 const SCT_RDO_Collection *collection,
21 DataPool<SCT3_RawData>& dataItems)
22 {
23 auto outputCollection = std::make_unique<SCT_RDO_Collection>(hashId);
24 outputCollection->setIdentifier(collection->identify());
25
26 // Elements created here are owned by the DataPool
27 outputCollection->clear(SG::VIEW_ELEMENTS);
28 outputCollection->reserve(collection->size());
29
30 for (const SCT_RDORawData *existingDatum : *collection) {
31 auto *oldDatum = dynamic_cast<const SCT3_RawData *>(existingDatum);
32 if (not oldDatum) {
33 throw std::runtime_error("Dynamic cast to SCT3_RawData failed in SCTOverlay.cxx, Overlay::copyCollection");
34 }
35 SCT3_RawData* datumCopy = dataItems.nextElementPtr();
36 (*datumCopy) = SCT3_RawData(oldDatum->identify(), oldDatum->getWord(),
37 &oldDatum->getErrorCondensedHit());
38 outputCollection->push_back(datumCopy);
39 }
40
41 return outputCollection;
42 }
43
44 // Specialize mergeCollections() for the SCT
45 // bkg,signal and output collections
46 // are all VIEW containers.
47 template<>
49 SCT_RDO_Collection *signalCollection,
50 SCT_RDO_Collection *outputCollection,
52 DataPool<SCT3_RawData>& dataItems)
53 {
54 // We want to use the SCT_ID helper provided by SCTOverlay, thus the constraint
55 const SCTOverlay *parent = dynamic_cast<const SCTOverlay *>(algorithm);
56 if (!parent) {
57 throw std::runtime_error("mergeCollections<SCT_RDORawData>() called by a wrong parent algorithm? Must be SCTOverlay.");
58 }
59
60 if (bkgCollection->identify() != signalCollection->identify()) {
61 throw std::runtime_error("mergeCollections<SCT_RDO_Collection>(): collection Id mismatch");
62 }
63
64 outputCollection->reserve(
65 std::max(bkgCollection->size(), signalCollection->size()));
66 const Identifier idColl =
67 parent->get_sct_id()->wafer_id(signalCollection->identifyHash());
68
69 // Strip hit timing information for Next, Current, Previous and Any BCs
70 // Prepare one more strip to create the last one. The additional strip has no hits.
71 std::bitset<SCTOverlay::NumberOfStrips+1> stripInfo[SCTOverlay::NumberOfBitSets];
72 // Process background and signal in the wafer
73 for (unsigned source = SCTOverlay::BkgSource; source < SCTOverlay::NumberOfSources; source++) {
76 if (source == SCTOverlay::BkgSource) { // background
77 rdo = bkgCollection->begin();
78 rdoEnd = bkgCollection->end();
79 } else { // signal
80 rdo = signalCollection->begin();
81 rdoEnd = signalCollection->end();
82 }
83 // Loop over all RDOs in the wafer
84 for (; rdo!=rdoEnd; ++rdo) {
85 // Here we'll just go with SCT3.
86 const SCT3_RawData* rdo3 = dynamic_cast<const SCT3_RawData*>(*rdo);
87 if (!rdo3) {
88 std::ostringstream os;
89 const auto& elt = **rdo;
90 os << "mergeCollection<SCT_RDO_Collection>(): wrong datum format. Only SCT3_RawData are produced by SCT_RodDecoder and supported by overlay."
91 << "For the supplied datum typeid(datum).name() = " << typeid(elt).name();
92 throw std::runtime_error(os.str());
93 }
94 int strip = parent->get_sct_id()->strip(rdo3->identify());
95 int stripEnd = strip + rdo3->getGroupSize();
96 int timeBin = rdo3->getTimeBin();
97 for (; strip < stripEnd && strip < SCTOverlay::NumberOfStrips; strip++) {
98 // Fill timing information for each strips, loop over 3 BCs
99 for (unsigned int bc = SCTOverlay::NextBC; bc < SCTOverlay::NumberOfBCs; bc++) {
100 if (timeBin & (1 << bc)) stripInfo[bc].set(strip);
101 }
102 }
103 }
104 }
105 // Get OR for AnyBC, loop over 3 BCs
106 for (unsigned int bc = SCTOverlay::NextBC; bc < SCTOverlay::NumberOfBCs; bc++) {
107 stripInfo[SCTOverlay::AnyBC] |= stripInfo[bc];
108 }
109 // Check if we need to use Expanded mode by checking if there is at least one hit in Next BC or Previous BC
110 bool anyNextBCHits = stripInfo[SCTOverlay::NextBC].any();
111 bool anyPreivousBCHits = stripInfo[SCTOverlay::PreviousBC].any();
112 bool isExpandedMode = (anyNextBCHits or anyPreivousBCHits);
113 // No error information is recorded because this information is not filled in data and no errors are assumed in MC.
114 const int ERRORS = 0;
115 const std::vector<int> errvec{};
116 if (isExpandedMode) {
117 // Expanded mode (record strip one by one)
118 const int groupSize = 1;
119 int tbin = 0;
120 for (unsigned int strip = 0; strip < SCTOverlay::NumberOfStrips; strip++) {
121 if (stripInfo[SCTOverlay::AnyBC][strip]) {
122 tbin = 0;
123 for (unsigned int bc = SCTOverlay::NextBC; bc < SCTOverlay::NumberOfBCs; bc++) {
124 if (stripInfo[bc][strip]) {
125 tbin |= (1 << bc);
126 }
127 }
128 unsigned int SCT_Word = (groupSize | (strip << 11) | (tbin <<22) | (ERRORS << 25));
129 Identifier rdoId = parent->get_sct_id()->strip_id(idColl, strip) ;
130 // use the pool
131 SCT3_RawData* datum = dataItems.nextElementPtr();
132 (*datum) = SCT3_RawData(rdoId, SCT_Word, &errvec);
133 outputCollection->push_back(datum);
134 }
135 }
136 } else {
137 // We can record consecutive hits into one RDO if all hits have timeBin of 010.
138 unsigned int groupSize = 0;
139 const int tbin = (1 << SCTOverlay::CurrentBC);
140 for (unsigned int strip=0; strip<SCTOverlay::NumberOfStrips+1; strip++) { // Loop over one more strip to create the last one if any
141 if (stripInfo[SCTOverlay::AnyBC][strip]) {
142 groupSize++;
143 } else {
144 if (groupSize>0) {
145 unsigned int firstStrip = strip - groupSize;
146 unsigned int SCT_Word = (groupSize | (firstStrip << 11) | (tbin <<22) | (ERRORS << 25));
147 Identifier rdoId = parent->get_sct_id()->strip_id(idColl, firstStrip) ;
148 SCT3_RawData* datum = dataItems.nextElementPtr();
149 (*datum) = SCT3_RawData(rdoId, SCT_Word, &errvec);
150 outputCollection->push_back(datum);
151 groupSize = 0;
152 }
153 }
154 }
155 }
156 } // mergeCollections()
157} // namespace Overlay
158
159
160SCTOverlay::SCTOverlay(const std::string &name, ISvcLocator *pSvcLocator)
161 : IDC_OverlayBase(name, pSvcLocator)
162{
163}
164
166{
167 ATH_MSG_DEBUG("Initializing...");
168
169 // Check and initialize keys
170 ATH_CHECK( m_bkgInputKey.initialize(!m_bkgInputKey.key().empty()) );
171 ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_bkgInputKey);
172 ATH_CHECK( m_signalInputKey.initialize() );
173 ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_signalInputKey);
174 ATH_CHECK( m_outputKey.initialize() );
175 ATH_MSG_VERBOSE("Initialized WriteHandleKey: " << m_outputKey);
176
177 // Retrieve SCT ID helper
178 if (!detStore()->retrieve(m_sctId, "SCT_ID").isSuccess() || !m_sctId) {
179 ATH_MSG_FATAL("Cannot retrieve SCT ID helper");
180 return StatusCode::FAILURE;
181 }
182
183 return StatusCode::SUCCESS;
184}
185
186StatusCode SCTOverlay::execute(const EventContext& ctx) const
187{
188 ATH_MSG_DEBUG("execute() begin");
189
190 // Reading the input RDOs
191 ATH_MSG_VERBOSE("Retrieving input RDO containers");
192
193 const SCT_RDO_Container *bkgContainerPtr = nullptr;
194 if (!m_bkgInputKey.empty()) {
196 if (!bkgContainer.isValid()) {
197 ATH_MSG_ERROR("Could not get background SCT RDO container " << bkgContainer.name() << " from store " << bkgContainer.store());
198 return StatusCode::FAILURE;
199 }
200 bkgContainerPtr = bkgContainer.cptr();
201
202 ATH_MSG_DEBUG("Found background SCT RDO container " << bkgContainer.name() << " in store " << bkgContainer.store());
203 ATH_MSG_DEBUG("SCT Background = " << Overlay::debugPrint(bkgContainer.cptr(), 50));
204 }
205
207 if (!signalContainer.isValid()) {
208 ATH_MSG_ERROR("Could not get signal SCT RDO container " << signalContainer.name() << " from store " << signalContainer.store());
209 return StatusCode::FAILURE;
210 }
211 ATH_MSG_DEBUG("Found signal SCT RDO container " << signalContainer.name() << " in store " << signalContainer.store());
212 ATH_MSG_DEBUG("SCT Signal = " << Overlay::debugPrint(signalContainer.cptr(), 50));
213
214 // Creating output RDO container
216
217
218 ATH_CHECK(outputContainer.record(std::make_unique<SCT_RDO_Container>(signalContainer->size())));
219 if (!outputContainer.isValid()) {
220 ATH_MSG_ERROR("Could not record output SCT RDO container " << outputContainer.name() << " to store " << outputContainer.store());
221 return StatusCode::FAILURE;
222 }
223 ATH_MSG_DEBUG("Recorded output SCT RDO container " << outputContainer.name() << " in store " << outputContainer.store());
224
225 // The DataPool, this is what will actually own the elements
226 // we create during this algorithm. The containers are views.
227 DataPool<SCT3_RawData> dataItemsPool(ctx);
228 // It resizes but lets reserve already quite a few
229 dataItemsPool.prepareToAdd(250000);
230
231 ATH_CHECK(overlayContainer(bkgContainerPtr, signalContainer.cptr(), outputContainer.ptr(),dataItemsPool));
232 ATH_MSG_DEBUG("SCT Result = " << Overlay::debugPrint(outputContainer.ptr(), 50));
233
234 ATH_MSG_DEBUG("execute() end");
235 return StatusCode::SUCCESS;
236}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
This is an Identifier helper class for the SCT subdetector.
InDetRawDataCollection< SCT_RDORawData > SCT_RDO_Collection
InDetRawDataContainer< InDetRawDataCollection< SCT_RDORawData > > SCT_RDO_Container
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
const ServiceHandle< StoreGateSvc > & detStore() const
a typed memory pool that saves time spent allocation small object.
Definition DataPool.h:63
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
void prepareToAdd(unsigned int size)
Prepare to add cached elements.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
const_iterator begin() const noexcept
size_type size() const noexcept
IDC_OverlayBase(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode overlayContainer(const IDC_Container *bkgContainer, const IDC_Container *signalContainer, IDC_Container *outputContainer) const
This is a "hash" representation of an Identifier.
virtual Identifier identify() const override final
virtual IdentifierHash identifyHash() const override final
virtual Identifier identify() const override final
int getTimeBin() const
virtual int getGroupSize() const override final
SG::ReadHandleKey< SCT_RDO_Container > m_signalInputKey
Definition SCTOverlay.h:35
SCTOverlay(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode execute(const EventContext &ctx) const override final
const SCT_ID * m_sctId
Definition SCTOverlay.h:32
@ NumberOfBitSets
Definition SCTOverlay.h:28
@ NumberOfSources
Definition SCTOverlay.h:29
SG::ReadHandleKey< SCT_RDO_Container > m_bkgInputKey
Definition SCTOverlay.h:34
SG::WriteHandleKey< SCT_RDO_Container > m_outputKey
Definition SCTOverlay.h:36
virtual StatusCode initialize() override final
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
std::string store() const
Return the name of the store holding the object we are proxying.
const std::string & name() const
Return the StoreGate ID for the referenced object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
pointer_type ptr()
Dereference the pointer.
std::string algorithm
Definition hcg.cxx:85
Helpers for overlaying Identifiable Containers.
std::string debugPrint(const IDC_Container *container, unsigned numprint=25)
Diagnostic output of Identifiable Containers.
std::unique_ptr< HGTD_RDO_Collection > copyCollection(const IdentifierHash &hashId, const HGTD_RDO_Collection *collection)
void mergeCollections(SCT_RDO_Collection *bkgCollection, SCT_RDO_Collection *signalCollection, SCT_RDO_Collection *outputCollection, const IDC_OverlayBase *algorithm, DataPool< SCT3_RawData > &dataItems)
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts