17#include "Identifier/Identifier.h"
30#include "CLHEP/Random/RandomEngine.h"
46 const std::string& name,
47 const IInterface* parent) :
48 base_class(
type, name, parent) {
82 return StatusCode::FAILURE;
99 return StatusCode::SUCCESS;
107 : m_sielement(sielement),
108 m_chargedDiodes(chargedDiodes) {
118 void SiDigitizationSurfaceChargeInserter::operator () (
const SiSurfaceCharge& scharge) {
124 m_chargedDiodes->
add(diode, scharge.
charge());
128 class MultiElementChargeInserter :
public ISiSurfaceChargesInserter {
131 const InDetDD::SCT_ModuleSideDesign * mum)
132 : m_chargedDiodesVecForInsert(chargedDiodesVec),
138 const InDetDD::SCT_ModuleSideDesign * m_mum;
141 void MultiElementChargeInserter::operator () (
const SiSurfaceCharge &scharge) {
149 if (m_chargedDiodesVecForInsert.at(row)) {
150 SiCellId diode = m_chargedDiodesVecForInsert.at(row)->element()->cellIdOfPosition(scharge.
position());
154 m_chargedDiodesVecForInsert.at(row)->add(diode, scharge.
charge());
176 return StatusCode::SUCCESS;
188 return StatusCode::SUCCESS;
204 return StatusCode::SUCCESS;
217 return StatusCode::SUCCESS;
222 return StatusCode::FAILURE;
226 rngWrapper->
setSeed( name(), ctx );
227 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
246 return StatusCode::SUCCESS;
266 m_thpcsi = std::make_unique<TimedHitCollection<SiHit>>();
268 return StatusCode::SUCCESS;
279 rngWrapper->
setSeed( name(), ctx );
280 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
295 return StatusCode::SUCCESS;
314 ATH_MSG_DEBUG(
"Digitizing "<<chargedDiodesMap.size()<<
" Element(s)");
324 ATH_MSG_DEBUG(
"in digitize elements with hits: ec - layer - eta - phi "
329 <<
" processing hit number " << hitcount);
336 assert(idHash < processedElements->
size());
337 (*processedElements)[idHash] =
true;
341 if (not chargedDiodes.
empty()) {
343 if (
sc.isSuccess()) {
345 addSDO(&chargedDiodes, simDataCollMap);
349 chargedDiodes.
clear();
360 if (elements==
nullptr) {
368 for (
unsigned int i{0}; i < processedElements->size(); i++) {
369 if (not (*processedElements)[i]) {
372 ATH_MSG_ERROR(
"SCT Detector element id hash is invalid = " << i);
377 ATH_MSG_DEBUG(
"In digitize of untouched elements: layer - phi - eta "
381 <<
"size: " << processedElements->size());
389 if (not chargedDiodes.
empty()) {
391 if (
sc.isSuccess()) {
393 addSDO(&chargedDiodes, simDataCollMap);
397 chargedDiodes.
clear();
405 if (
nullptr == thpcsi) {
411 chargedDiodesMap.clear();
423 int barrel{firstHit->getBarrelEndcap()};
425 firstHit->getLayerDisk(),
426 firstHit->getPhiModule(),
427 firstHit->getEtaModule(),
428 firstHit->getSide())};
434 if (elements==
nullptr) {
442 if (sielement ==
nullptr) {
443 ATH_MSG_DEBUG(
"Barrel=" <<
barrel <<
" layer=" << firstHit->getLayerDisk() <<
" Eta=" << firstHit->getEtaModule() <<
" Phi=" << firstHit->getPhiModule() <<
" Side=" << firstHit->getSide());
444 ATH_MSG_ERROR(
"detector manager could not find element with id = " <<
id);
455 std::map<int, const InDetDD::SCT_ModuleSideDesign *> children;
463 children.emplace(0,thisDesign);
467 for (
const std::pair <const int, const InDetDD::SCT_ModuleSideDesign *> &subDesign : children){
475 Identifier id_child{
m_detID->wafer_id(firstHit->getBarrelEndcap(), firstHit->getLayerDisk(),
476 firstHit->getPhiModule(), firstHit->getEtaModule()+subDesign.first,
477 firstHit->getSide())};
485 std::unique_ptr<SiChargedDiodeCollection> thisChargedDiode(std::make_unique<SiChargedDiodeCollection>());
486 int i_index = subDesign.first;
487 thisChargedDiode->setDetectorElement(sielement_child);
488 chargedDiodesMap.insert({i_index,std::move(thisChargedDiode)});
492 else ATH_MSG_ERROR(
"detector manager could not find element with id = "<<id_child<<
" Barrel=" << firstHit->getBarrelEndcap() <<
" layer=" <<
493 firstHit->getLayerDisk() <<
" Eta=" << firstHit->getEtaModule()+subDesign.first <<
" Phi=" << firstHit->getPhiModule()
494 <<
" Side=" <<firstHit->getSide());
503 if (std::abs(phit->meanTime()) < 10000. * CLHEP::ns) {
505 phit->getLayerDisk(),
506 phit->getPhiModule(),
507 phit->getEtaModule(),
514 if(chargedDiodesMap.size()>1) {
515 ATH_MSG_WARNING(
"More DiodesCollections("<<chargedDiodesMap.size()<<
") than expected (1). Please check your configuration!");
518 SiDigitizationSurfaceChargeInserter inserter(sielement,chargedDiodesMap[0].
get());
524 MultiElementChargeInserter inserter(chargedDiodesMap,motherDesign);
545 int processorNumber{0};
548 proc->process(*chargedDiodes, rndmEngine);
558 ATH_MSG_VERBOSE(
"StripDigitizationTool::processBunchXing() " << bunchXing);
563 return StatusCode::SUCCESS;
566 return StatusCode::SUCCESS;
573 TimedHitCollList hitCollList;
576 bSubEvents, eSubEvents).isSuccess())) and
577 hitCollList.empty()) {
579 return StatusCode::FAILURE;
585 TimedHitCollList::iterator endColl{hitCollList.end()};
586 for (TimedHitCollList::iterator iColl{hitCollList.begin()}; iColl != endColl; ++iColl) {
587 std::unique_ptr<SiHitCollection> hitCollPtr{std::make_unique<SiHitCollection>(*iColl->second)};
589 ATH_MSG_DEBUG(
"SiHitCollection found with " << hitCollPtr->size() <<
592 <<
" index: " << timeIndex.
index()
593 <<
" type: " << timeIndex.
type());
594 m_thpcsi->insert(timeIndex, hitCollPtr.get());
598 return StatusCode::SUCCESS;
622 std::ostringstream ost;
624 ost <<
"Digitized unprocessed elements: layer - phi - eta - side "
629 <<
" unprocessed hit number: " << ++
m_msgNo <<
'\n';
645 std::unique_ptr<SCT_RDO_Collection> RDOColl{
createRDO(chDiodeCollection)};
650 int barrelec{
m_detID->barrel_ec(id_coll)};
653 if ((*rdoContainer)->addCollection(RDOColl.release(), identifyHash).isFailure()) {
654 ATH_MSG_FATAL(
"SCT RDO collection could not be added to container!");
655 return StatusCode::FAILURE;
658 ATH_MSG_VERBOSE(
"Not saving SCT_RDO_Collection: " <<
m_detID->show_to_string(RDOColl->identify()) <<
" to container!");
660 return StatusCode::SUCCESS;
669 std::unique_ptr<SCT_RDO_Collection> p_rdocoll;
675 p_rdocoll = std::make_unique<SCT_RDO_Collection>(idHash_de);
676 }
catch (
const std::bad_alloc&) {
677 ATH_MSG_FATAL(
"Could not create a new SCT_RDORawDataCollection !");
679 p_rdocoll->setIdentifier(id_de);
685 for (; i_chargedDiode != i_chargedDiode_end; ++i_chargedDiode) {
686 unsigned int flagmask{
static_cast<unsigned int>((*i_chargedDiode).second.flag() & 0xFE)};
694 if (
strip > 0xffff) {
696 ATH_MSG_FATAL(
"Strip number too big for SCT1 raw data format.");
701 const unsigned int strip_rdo{
static_cast<unsigned int>((
strip & 0xFFFF) << 16)};
706 unsigned int size_rdo{
static_cast<unsigned int>(
size & 0xFFFF)};
713 for (; it2 != i_chargedDiode_end; ++it2) {
715 if (cluscounter >=
size) {
718 if (it2->second.flag() & 0xDE) {
719 int tmp{cluscounter};
720 while ((it2 != i_chargedDiode_end) and (cluscounter <
size - 1) and (it2->second.flag() & 0xDE)) {
724 if ((it2 != collection->
end()) and !(it2->second.flag() & 0xDE)) {
729 size_rdo = tmp & 0xFFFF;
734 unsigned int StripWord{strip_rdo | size_rdo};
737 p_rdocoll->push_back(p_rdo);
745 static const std::vector<int> dummyvector;
746 for (; i_chargedDiode != i_chargedDiode_end; ++i_chargedDiode) {
747 unsigned int flagmask{
static_cast<unsigned int>((*i_chargedDiode).second.flag() & 0xFE)};
761 id_readout =
m_detID->strip_id(collection->
identify(), row2D, strip2D);
775 if (cluscounter >=
size) {
776 ATH_MSG_WARNING(
"Cluster size reached while neighbouring strips still defined.");
779 if (diode->
flag() & 0xDE) {
780 int tmp{cluscounter};
781 while ((cluscounter <
size - 1) and (diode->
flag() & 0xDE)) {
785 if (diode and !(diode->
flag() & 0xDE)) {
796 int stripIn11bits{
strip & 0x7ff};
797 if (stripIn11bits !=
strip) {
798 ATH_MSG_DEBUG(
"Strip number " <<
strip <<
" doesn't fit into 11 bits - will be truncated");
801 unsigned int StripWord{
static_cast<unsigned int>(groupSize | (stripIn11bits << 11) | (tbin << 22) | (ERRORS << 25))};
804 p_rdocoll->push_back(p_rdo);
824 if (!hitCollection.
isValid()) {
825 ATH_MSG_ERROR(
"Could not get SCT SiHitCollection container " << hitCollection.
name() <<
" from store " << hitCollection.
store());
826 return StatusCode::FAILURE;
830 m_thpcsi = std::make_unique<TimedHitCollection<SiHit>>(1);
832 ATH_MSG_DEBUG(
"SiHitCollection found with " << hitCollection->size() <<
" hits");
834 return StatusCode::SUCCESS;
837 TimedHitCollList hitCollList;
838 unsigned int numberOfSiHits{0};
841 return StatusCode::FAILURE;
846 m_thpcsi = std::make_unique<TimedHitCollection<SiHit>>(numberOfSiHits);
848 TimedHitCollList::iterator endColl{hitCollList.end()};
849 for (TimedHitCollList::iterator iColl{hitCollList.begin()}; iColl != endColl; ++iColl) {
863 m_thpcsi->insert(iColl->first, p_collection);
864 ATH_MSG_DEBUG(
"SiTrackerHitCollection found with " << p_collection->
size() <<
" hits");
866 return StatusCode::SUCCESS;
875 std::vector<InDetSimData::Deposit> deposits;
882 const list_t& charges{(*i_chargedDiode).second.totalCharge().chargeComposition()};
884 bool real_particle_hit{
false};
886 list_t::const_iterator EndOfChargeList{charges.end()};
887 for (list_t::const_iterator i_ListOfCharges{charges.begin()}; i_ListOfCharges != EndOfChargeList; ++i_ListOfCharges) {
892 if (not real_particle_hit) {
903 real_particle_hit =
true;
907 const auto theDeposit = std::ranges::find_if(
908 deposits.rbegin(), deposits.rend(),
910 return deposit.first == trkLink;
914 if (theDeposit != deposits.rend()) {
915 theDeposit->second += i_ListOfCharges->charge();
917 deposits.emplace_back(trkLink, i_ListOfCharges->charge());
935 (*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.
a link optimized in size for a GenParticle in a McEventCollection
std::string msg(const InDetDD::SiDetectorElement *element)
DigitizeNonHitElementsDebugPrinter(const SCT_ID *detID)
This is a "hash" representation of an Identifier.
constexpr bool is_valid() const
virtual SiCellId cellIdOfPosition(const SiLocalPosition &localPos) const =0
position -> id
Base class for the SCT module side design, extended by the Forward and Barrel module design.
virtual std::pair< int, int > getStripRow(SiCellId id) const
Get the strip and row number of the cell.
virtual int strip(int stripId1Dim) const
const std::map< int, const SCT_ModuleSideDesign * > & getChildren() const
const SCT_ModuleSideDesign * getMother() 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.
virtual const SiDetectorDesign & design() const override final
access to the local description (inline):
Identifier for the strip or pixel readout cell.
SiCellId cellIdOfPosition(const Amg::Vector2D &localPos) const
As in previous method but returns SiCellId.
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()
void add(const InDetDD::SiCellId &diode, const T &charge)
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)
const SiCharge & charge() const
const InDetDD::SiLocalPosition & position() const
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.
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
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.
row
Appending html table to final .html summary file.
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