17#include "Identifier/Identifier.h"
30#include "CLHEP/Random/RandomEngine.h"
41 const std::string& name,
42 const IInterface* parent) :
43 base_class(
type, name, parent) {
77 return StatusCode::FAILURE;
94 return StatusCode::SUCCESS;
98 class SiDigitizationSurfaceChargeInserter
104 : m_sielement(sielement),
105 m_chargedDiodes(chargedDiodes) {
110 const InDetDD::SiDetectorElement* m_sielement;
111 SiChargedDiodeCollection* m_chargedDiodes;
115 void SiDigitizationSurfaceChargeInserter::operator ()
118 SiCellId diode{m_sielement->cellIdOfPosition(scharge.position())};
122 m_chargedDiodes->add(diode, scharge.charge());
140 return StatusCode::SUCCESS;
152 return StatusCode::SUCCESS;
168 return StatusCode::SUCCESS;
181 return StatusCode::SUCCESS;
186 return StatusCode::FAILURE;
190 rngWrapper->
setSeed( name(), ctx );
191 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
210 return StatusCode::SUCCESS;
230 m_thpcsi = std::make_unique<TimedHitCollection<SiHit>>();
232 return StatusCode::SUCCESS;
243 rngWrapper->
setSeed( name(), ctx );
244 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
259 return StatusCode::SUCCESS;
281 ATH_MSG_DEBUG(
"in digitize elements with hits: ec - layer - eta - phi "
286 <<
" processing hit number " << hitcount);
293 assert(idHash < processedElements->
size());
294 (*processedElements)[idHash] =
true;
298 if (not chargedDiodes.
empty()) {
300 if (
sc.isSuccess()) {
302 addSDO(&chargedDiodes, simDataCollMap);
306 chargedDiodes.
clear();
316 if (elements==
nullptr) {
324 for (
unsigned int i{0}; i < processedElements->size(); i++) {
325 if (not (*processedElements)[i]) {
328 ATH_MSG_ERROR(
"SCT Detector element id hash is invalid = " << i);
333 ATH_MSG_DEBUG(
"In digitize of untouched elements: layer - phi - eta "
337 <<
"size: " << processedElements->size());
345 if (not chargedDiodes.
empty()) {
347 if (
sc.isSuccess()) {
349 addSDO(&chargedDiodes, simDataCollMap);
353 chargedDiodes.
clear();
361 if (
nullptr == thpcsi) {
377 int barrel{firstHit->getBarrelEndcap()};
379 firstHit->getLayerDisk(),
380 firstHit->getPhiModule(),
381 firstHit->getEtaModule(),
382 firstHit->getSide())};
388 if (elements==
nullptr) {
396 if (sielement ==
nullptr) {
397 ATH_MSG_DEBUG(
"Barrel=" <<
barrel <<
" layer=" << firstHit->getLayerDisk() <<
" Eta=" << firstHit->getEtaModule() <<
" Phi=" << firstHit->getPhiModule() <<
" Side=" << firstHit->getSide());
398 ATH_MSG_ERROR(
"detector manager could not find element with id = " <<
id);
409 if (std::abs(phit->meanTime()) < 10000. * CLHEP::ns) {
411 phit->getLayerDisk(),
412 phit->getPhiModule(),
413 phit->getEtaModule(),
416 SiDigitizationSurfaceChargeInserter inserter(sielement, chargedDiodes);
431 int processorNumber{0};
434 proc->process(*chargedDiodes, rndmEngine);
444 ATH_MSG_VERBOSE(
"SCT_DigitizationTool::processBunchXing() " << bunchXing);
449 return StatusCode::SUCCESS;
452 return StatusCode::SUCCESS;
459 TimedHitCollList hitCollList;
462 bSubEvents, eSubEvents).isSuccess())) and
463 hitCollList.empty()) {
465 return StatusCode::FAILURE;
471 const TimedHitCollList::iterator endColl{hitCollList.end()};
472 for (TimedHitCollList::iterator iColl{hitCollList.begin()}; iColl != endColl; ++iColl) {
473 std::unique_ptr<SiHitCollection> hitCollPtr{std::make_unique<SiHitCollection>(*iColl->second)};
475 ATH_MSG_DEBUG(
"SiHitCollection found with " << hitCollPtr->size() <<
478 <<
" index: " << timeIndex.
index()
479 <<
" type: " << timeIndex.
type());
480 m_thpcsi->insert(timeIndex, hitCollPtr.get());
484 return StatusCode::SUCCESS;
508 std::ostringstream ost;
510 ost <<
"Digitized unprocessed elements: layer - phi - eta - side "
515 <<
" unprocessed hit number: " << ++
m_msgNo <<
'\n';
531 std::unique_ptr<SCT_RDO_Collection> RDOColl{
createRDO(chDiodeCollection)};
536 int barrelec{
m_detID->barrel_ec(id_coll)};
539 if ((*rdoContainer)->addCollection(RDOColl.release(), identifyHash).isFailure()) {
540 ATH_MSG_FATAL(
"SCT RDO collection could not be added to container!");
541 return StatusCode::FAILURE;
544 ATH_MSG_VERBOSE(
"Not saving SCT_RDO_Collection: " <<
m_detID->show_to_string(RDOColl->identify()) <<
" to container!");
546 return StatusCode::SUCCESS;
555 std::unique_ptr<SCT_RDO_Collection> p_rdocoll;
561 p_rdocoll = std::make_unique<SCT_RDO_Collection>(idHash_de);
562 }
catch (
const std::bad_alloc&) {
563 ATH_MSG_FATAL(
"Could not create a new SCT_RDORawDataCollection !");
565 p_rdocoll->setIdentifier(id_de);
571 for (; i_chargedDiode != i_chargedDiode_end; ++i_chargedDiode) {
572 unsigned int flagmask{
static_cast<unsigned int>((*i_chargedDiode).second.flag() & 0xFE)};
580 if (
strip > 0xffff) {
582 ATH_MSG_FATAL(
"Strip number too big for SCT1 raw data format.");
587 const unsigned int strip_rdo{
static_cast<unsigned int>((
strip & 0xFFFF) << 16)};
592 unsigned int size_rdo{
static_cast<unsigned int>(
size & 0xFFFF)};
599 for (; it2 != i_chargedDiode_end; ++it2) {
601 if (cluscounter >=
size) {
604 if (it2->second.flag() & 0xDE) {
605 int tmp{cluscounter};
606 while ((it2 != i_chargedDiode_end) and (cluscounter <
size - 1) and (it2->second.flag() & 0xDE)) {
610 if ((it2 != collection->
end()) and !(it2->second.flag() & 0xDE)) {
615 size_rdo = tmp & 0xFFFF;
620 unsigned int SCT_Word{strip_rdo | size_rdo};
623 p_rdocoll->push_back(p_rdo);
631 static const std::vector<int> dummyvector;
632 for (; i_chargedDiode != i_chargedDiode_end; ++i_chargedDiode) {
633 unsigned int flagmask{
static_cast<unsigned int>((*i_chargedDiode).second.flag() & 0xFE)};
647 id_readout =
m_detID->strip_id(collection->
identify(), row2D, strip2D);
661 if (cluscounter >=
size) {
662 ATH_MSG_WARNING(
"Cluster size reached while neighbouring strips still defined.");
665 if (diode->
flag() & 0xDE) {
666 int tmp{cluscounter};
667 while ((cluscounter <
size - 1) and (diode->
flag() & 0xDE)) {
671 if (diode and !(diode->
flag() & 0xDE)) {
682 int stripIn11bits{
strip & 0x7ff};
683 if (stripIn11bits !=
strip) {
684 ATH_MSG_DEBUG(
"Strip number " <<
strip <<
" doesn't fit into 11 bits - will be truncated");
687 unsigned int SCT_Word{
static_cast<unsigned int>(groupSize | (stripIn11bits << 11) | (tbin << 22) | (ERRORS << 25))};
690 p_rdocoll->push_back(p_rdo);
710 if (!hitCollection.
isValid()) {
711 ATH_MSG_ERROR(
"Could not get SCT SiHitCollection container " << hitCollection.
name() <<
" from store " << hitCollection.
store());
712 return StatusCode::FAILURE;
716 m_thpcsi = std::make_unique<TimedHitCollection<SiHit>>(1);
718 ATH_MSG_DEBUG(
"SiHitCollection found with " << hitCollection->size() <<
" hits");
720 return StatusCode::SUCCESS;
723 TimedHitCollList hitCollList;
724 unsigned int numberOfSiHits{0};
727 return StatusCode::FAILURE;
732 m_thpcsi = std::make_unique<TimedHitCollection<SiHit>>(numberOfSiHits);
734 TimedHitCollList::iterator endColl{hitCollList.end()};
735 for (TimedHitCollList::iterator iColl{hitCollList.begin()}; iColl != endColl; ++iColl) {
749 m_thpcsi->insert(iColl->first, p_collection);
750 ATH_MSG_DEBUG(
"SiTrackerHitCollection found with " << p_collection->
size() <<
" hits");
752 return StatusCode::SUCCESS;
760 std::vector<InDetSimData::Deposit> deposits;
762 const auto collectionid = collection->
identify();
764 static_assert(std::is_nothrow_move_constructible<InDetSimData::Deposit>::value);
771 const list_t& charges{(*i_chargedDiode).second.totalCharge().chargeComposition()};
773 bool real_particle_hit{
false};
775 const list_t::const_iterator EndOfChargeList{charges.end()};
776 for (list_t::const_iterator i_ListOfCharges{charges.begin()}; i_ListOfCharges != EndOfChargeList; ++i_ListOfCharges) {
781 if (!real_particle_hit) {
792 real_particle_hit =
true;
796 auto theDeposit = std::ranges::find_if(deposits|std::views::reverse,
801 if (theDeposit != deposits.rend()) {
802 (*theDeposit).second += i_ListOfCharges->charge();
804 deposits.emplace_back(trkLink, i_ListOfCharges->charge());
812 const int row2D{sctDesign.
row(
strip)};
814 (*simDataCollMap)->try_emplace(id_readout, std::move(deposits),(*i_chargedDiode).second.flag());
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
This is an Identifier helper class for the SCT subdetector.
SiChargedDiodeMap::iterator SiChargedDiodeIterator
AtlasHitsVector< SiHit > SiHitCollection
Handle class for reading from StoreGate.
size_t size() const
Number of registered mappings.
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.
std::string msg(const InDetDD::SiDetectorElement *element)
DigitizeNonHitElementsDebugPrinter(const SCT_ID *detID)
a link optimized in size for a GenParticle in a McEventCollection
This is a "hash" representation of an Identifier.
constexpr bool is_valid() const
Base class for the SCT module side design, extended by the Forward and Barrel module design.
virtual int strip(int stripId1Dim) const
virtual int row(int stripId1Dim) const
Identifier for the strip or pixel cell.
int strip() const
Get strip number. Equivalent to phiIndex().
bool isValid() const
Test if its in a valid state.
Class to hold the SiDetectorElement objects to be put in the detector store.
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
Class to hold geometrical description of a silicon detector element.
Identifier for the strip or pixel readout cell.
virtual Identifier identify() const override final
identifier of this detector element (inline)
std::pair< HepMcParticleLink, float > Deposit
This is an Identifier helper class for the SCT subdetector.
const_pointer_type retrieve()
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.
virtual Identifier identify() const override final
void setDetectorElement(const InDetDD::SolidStateDetectorElementBase *SiElement)
SiChargedDiodeIterator begin()
const InDetDD::DetectorDesign & design() const
virtual IdentifierHash identifyHash() const override final
SiChargedDiodeIterator end()
SiChargedDiode * nextInCluster()
static void ClusterUsed(SiChargedDiode &chDiode, bool flag)
static void SetStripNum(SiChargedDiode &chDiode, int nstrip, MsgStream *log=nullptr)
static int GetStripNum(SiChargedDiode &chDiode)
static int GetTimeBin(SiChargedDiode &chDiode)
std::vector< SiCharge > list_t
bool nextDetectorElement(const_iterator &b, const_iterator &e)
sets an iterator range with the hits of current detector element returns a bool when done
TimedVector::const_iterator const_iterator
a smart pointer to a hit that also provides access to the extended timing info of the host event.
bool no_truth_link(const T &p)
Method to establish if a if the object is linked to something which was never saved to the HepMC Trut...
bool ignoreTruthLink(const T &p, bool vetoPileUp)
Helper function for SDO creation in PileUpTools.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
std::list< value_t > type
type of the collection of timed data object
a struct encapsulating the identifier of a pile-up event
index_type index() const
the index of the component event in PileUpEventInfo
PileUpType type() const
the pileup type - minbias, cavern, beam halo, signal?
time_type time() const
bunch xing time in ns