6#include "CLHEP/Random/RandomEngine.h"
7#include "CLHEP/Random/RandFlat.h"
27 bool operator()(TRT_RDORawData *digit1, TRT_RDORawData *digit2) {
45 (*datumCopy) =
TRT_LoLumRawData(existingDatum->identify(), existingDatum->getWord());
52std::unique_ptr<TRT_RDO_Collection> copyCollectionAndSort(
88 return StatusCode::FAILURE;
97 return StatusCode::SUCCESS;
110 ATH_MSG_ERROR(
"Could not get background TRT RDO container " << bkgContainer.
name() <<
" from store " << bkgContainer.
store());
111 return StatusCode::FAILURE;
113 bkgContainerPtr = bkgContainer.
cptr();
115 ATH_MSG_DEBUG(
"Found background TRT RDO container " << bkgContainer.
name() <<
" in store " << bkgContainer.
store());
120 if (!signalContainer.
isValid()) {
121 ATH_MSG_ERROR(
"Could not get signal TRT RDO container " << signalContainer.
name() <<
" from store " << signalContainer.
store());
122 return StatusCode::FAILURE;
124 ATH_MSG_DEBUG(
"Found signal TRT RDO container " << signalContainer.
name() <<
" in store " << signalContainer.
store());
128 if (!signalSDOContainer.
isValid()) {
129 ATH_MSG_ERROR(
"Could not get signal TRT SDO map container " << signalSDOContainer.
name() <<
" from store " << signalSDOContainer.
store());
130 return StatusCode::FAILURE;
132 ATH_MSG_DEBUG(
"Found signal TRT SDO map container " << signalSDOContainer.
name() <<
" in store " << signalSDOContainer.
store());
142 ATH_CHECK(outputContainer.
record(std::make_unique<TRT_RDO_Container>(signalContainer->size())));
143 if (!outputContainer.
isValid()) {
144 ATH_MSG_ERROR(
"Could not record output TRT RDO container " << outputContainer.
name() <<
" to store " << outputContainer.
store());
145 return StatusCode::FAILURE;
147 ATH_MSG_DEBUG(
"Recorded output TRT RDO container " << outputContainer.
name() <<
" in store " << outputContainer.
store());
150 outputContainer.
ptr(), signalSDOContainer.
cptr(),
156 return StatusCode::SUCCESS;
174 std::unique_ptr<TRT_RDO_Collection> signalCollection = copyCollection(hashId, ptr, dataItemsPool);
176 if (outputContainer->
addCollection(signalCollection.get(), hashId).isFailure()) {
177 ATH_MSG_ERROR(
"Adding signal Collection with hashId " << hashId <<
" failed");
178 return StatusCode::FAILURE;
180 (void)signalCollection.release();
184 return StatusCode::SUCCESS;
189 rngWrapper->
setSeed( name(), ctx );
190 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
202 std::vector < std::pair<IdentifierHash, bool> > overlapMap;
205 overlapMap.emplace_back(hashId,
false);
210 auto search = std::lower_bound( overlapMap.begin(), overlapMap.end(), hashId,
211 [](
const std::pair<IdentifierHash, bool> &lhs,
IdentifierHash rhs) ->
bool { return lhs.first < rhs; } );
212 if (
search == overlapMap.end() ||
search->first != hashId) {
214 std::unique_ptr<TRT_RDO_Collection> bkgCollection{};
217 bkgCollection = copyCollectionAndSort(hashId, bkgContainer->
indexFindPtr(hashId),dataItemsPool);
219 bkgCollection = copyCollection(hashId, bkgContainer->
indexFindPtr(hashId),dataItemsPool);
222 if (outputContainer->
addCollection(bkgCollection.get(), hashId).isFailure()) {
223 ATH_MSG_ERROR(
"Adding background Collection with hashId " << hashId <<
" failed");
224 return StatusCode::FAILURE;
226 (void)bkgCollection.release();
236 for (
const auto &[hashId, overlap] : overlapMap) {
238 std::unique_ptr<TRT_RDO_Collection> signalCollection =
239 copyCollection(hashId, signalContainer->
indexFindPtr(hashId),dataItemsPool);
243 auto outputCollection = std::make_unique<TRT_RDO_Collection>(hashId);
244 outputCollection->setIdentifier(signalCollection->identify());
250 std::unique_ptr<TRT_RDO_Collection> bkgCollection{};
252 bkgCollection = copyCollectionAndSort(hashId, bkgContainer->
indexFindPtr(hashId),dataItemsPool);
254 bkgCollection = copyCollection(hashId, bkgContainer->
indexFindPtr(hashId),dataItemsPool);
258 int det =
m_trtId->barrel_ec(signalCollection->identify());
260 signalCollection.get(),
261 outputCollection.get(),
267 if (outputContainer->
addCollection(outputCollection.get(), hashId).isFailure()) {
268 ATH_MSG_ERROR(
"Adding overlaid Collection with hashId " << hashId <<
" failed");
269 return StatusCode::FAILURE;
271 outputCollection.release();
274 if (outputContainer->
addCollection(signalCollection.get(), hashId).isFailure()) {
275 ATH_MSG_ERROR(
"Adding signal Collection with hashId " << hashId <<
" failed");
276 return StatusCode::FAILURE;
278 (void)signalCollection.release();
283 return StatusCode::SUCCESS;
294 CLHEP::HepRandomEngine *rndmEngine)
const
297 throw std::runtime_error(
"mergeCollections(): collection Id mismatch");
303 outputCollection->reserve(
304 std::max(bkgCollection->
size(), signalCollection->
size()));
316 while ((ibkg < bkgCollection->size()) || (isig < signalCollection->size())) {
320 if (isig == signalCollection->
size()) {
323 }
else if (ibkg == bkgCollection->
size()) {
325 signalCollection->
swapElement(isig++,
nullptr, tmp);
330 signalCollection->
swapElement(isig++,
nullptr, tmp);
337 bkgCollection->
swapElement(ibkg++,
nullptr, tmpBkg);
338 signalCollection->
swapElement(isig++,
nullptr, tmp);
343 if (sigRdo && bkgRdo) {
345 sigRdo->
merge(*bkgRdo);
348 if (!(sigRdo->
getWord() & 0x04020100)) {
352 InDetSimDataCollection::const_iterator sdoIter = signalSDOCollection->find(rdoId);
353 if (sdoIter != signalSDOCollection->end()) {
354 const std::vector<InDetSimData::Deposit> &deposits = sdoIter->second.getdeposits();
358 if (std::abs(particleLink->pdg_id()) == 11) {
367 bool isXenonStraw =
false;
368 if (strawStatusHT !=
nullptr) {
375 int det =
m_trtId->barrel_ec(rdoId);
376 float HTOccupancyCorrection = 0.;
391 unsigned int newWord = 0;
392 if (HTOccupancyCorrection != 0. && occupancy * HTOccupancyCorrection > CLHEP::RandFlat::shoot(rndmEngine, 0, 1)) {
393 newWord += 1 << (26-9);
397 sigRdo->
merge(newRdo);
405 outputCollection->push_back(tmp);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
bool isElectron(const T &p)
#define CHECK(...)
Evaluate an expression and check for errors.
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
This is an Identifier helper class for the TRT subdetector.
InDetRawDataCollection< TRT_RDORawData > TRT_RDO_Collection
InDetRawDataContainer< InDetRawDataCollection< TRT_RDORawData > > TRT_RDO_Container
A wrapper class for event-slot-local random engines.
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
const ServiceHandle< StoreGateSvc > & detStore() const
An algorithm that can be simultaneously executed in multiple threads.
a typed memory pool that saves time spent allocation small object.
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.
typename DataVectorBase< TRT_RDORawData >::Base::size_type size_type
const RawDataT * at(size_type n) const
void swapElement(size_type index, value_type newElem, reference oldElem)
size_type size() const noexcept
a link optimized in size for a GenParticle in a McEventCollection
bool isValid() const
Validity check.
virtual size_t numberOfCollections() const override final
return number of collections
const std::vector< EventContainers::hashPair< T > > & GetAllHashPtrPair() const
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,...
virtual StatusCode addCollection(const T *coll, IdentifierHash hashId) override final
insert collection into container with id hash if IDC should not take ownership of collection,...
This is a "hash" representation of an Identifier.
virtual Identifier identify() const override final
void merge(const InDetRawData &other)
virtual Identifier identify() const override final
unsigned int getWord() const
std::pair< HepMcParticleLink, float > Deposit
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.
unsigned int findStatus(const IdentifierHash &hashID) const
Gaudi::Property< double > m_HTOccupancyCorrectionB_noE
virtual StatusCode initialize() override final
virtual StatusCode execute(const EventContext &ctx) const override final
Gaudi::Property< double > m_HTOccupancyCorrectionEC_noE
Gaudi::Property< double > m_HTOccupancyCorrectionB_Ar_noE
Gaudi::Property< double > m_HTOccupancyCorrectionB_Ar
SG::WriteHandleKey< TRT_RDO_Container > m_outputKey
Gaudi::Property< double > m_HTOccupancyCorrectionEC_Ar
Gaudi::Property< double > m_HTOccupancyCorrectionEC
Gaudi::Property< bool > m_sortBkgInput
StatusCode overlayContainer(const EventContext &ctx, const TRT_RDO_Container *bkgContainer, const TRT_RDO_Container *signalContainer, TRT_RDO_Container *outputContainer, const InDetSimDataCollection *signalSDOCollection, DataPool< TRT_LoLumRawData > &dataItemsPool) const
void mergeCollections(TRT_RDO_Collection *bkgCollection, TRT_RDO_Collection *signalCollection, TRT_RDO_Collection *outputCollection, double occupancy, const InDetSimDataCollection *signalSDOCollection, const TRTCond::StrawStatusData *strawStatusHT, CLHEP::HepRandomEngine *rndmEngine) const
Here we take 2 view containers with elements owned by the DataPool we modify some of them and push th...
SG::ReadHandleKey< TRT_RDO_Container > m_bkgInputKey
ToolHandle< InDet::ITRT_LocalOccupancy > m_TRT_LocalOccupancyTool
ServiceHandle< IAthRNGSvc > m_rndmSvc
SG::ReadHandleKey< InDetSimDataCollection > m_signalInputSDOKey
Gaudi::Property< double > m_HTOccupancyCorrectionB
Gaudi::Property< double > m_HTOccupancyCorrectionEC_Ar_noE
TRTOverlay(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< TRT_RDO_Container > m_signalInputKey
SG::ReadCondHandleKey< TRTCond::StrawStatusData > m_strawStatusHTKey
void search(TDirectory *td, const std::string &s, std::string cwd, node *n)
recursive directory search for TH1 and TH2 and TProfiles
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)
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
void stable_sort(DataModel_detail::iterator< DVL > beg, DataModel_detail::iterator< DVL > end)
Specialization of stable_sort for DataVector/List.