17#include "Identifier/Identifier.h"
30#include "CLHEP/Random/RandomEngine.h"
40 const std::string& name,
41 const IInterface* parent) :
42 base_class(
type, name, parent) {
76 return StatusCode::FAILURE;
93 return StatusCode::SUCCESS;
97 class SiDigitizationSurfaceChargeInserter
103 : m_sielement(sielement),
104 m_chargedDiodes(chargedDiodes) {
107 void operator () (
const SiSurfaceCharge& scharge);
109 const InDetDD::SiDetectorElement* m_sielement;
110 SiChargedDiodeCollection* m_chargedDiodes;
114 void SiDigitizationSurfaceChargeInserter::operator ()
117 SiCellId diode{m_sielement->cellIdOfPosition(scharge.position())};
121 m_chargedDiodes->add(diode, scharge.charge());
139 return StatusCode::SUCCESS;
151 return StatusCode::SUCCESS;
167 return StatusCode::SUCCESS;
180 return StatusCode::SUCCESS;
185 return StatusCode::FAILURE;
189 rngWrapper->
setSeed( name(), ctx );
190 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
209 return StatusCode::SUCCESS;
229 m_thpcsi = std::make_unique<TimedHitCollection<SiHit>>();
231 return StatusCode::SUCCESS;
242 rngWrapper->
setSeed( name(), ctx );
243 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
258 return StatusCode::SUCCESS;
280 ATH_MSG_DEBUG(
"in digitize elements with hits: ec - layer - eta - phi "
285 <<
" processing hit number " << hitcount);
292 assert(idHash < processedElements->size());
293 (*processedElements)[idHash] =
true;
297 if (not chargedDiodes.
empty()) {
299 if (
sc.isSuccess()) {
301 addSDO(&chargedDiodes, simDataCollMap);
305 chargedDiodes.
clear();
315 if (elements==
nullptr) {
323 for (
unsigned int i{0}; i < processedElements->size(); i++) {
324 if (not (*processedElements)[i]) {
327 ATH_MSG_ERROR(
"SCT Detector element id hash is invalid = " << i);
332 ATH_MSG_DEBUG(
"In digitize of untouched elements: layer - phi - eta "
336 <<
"size: " << processedElements->size());
344 if (not chargedDiodes.
empty()) {
346 if (
sc.isSuccess()) {
348 addSDO(&chargedDiodes, simDataCollMap);
352 chargedDiodes.
clear();
360 if (
nullptr == thpcsi) {
376 int barrel{firstHit->getBarrelEndcap()};
378 firstHit->getLayerDisk(),
379 firstHit->getPhiModule(),
380 firstHit->getEtaModule(),
381 firstHit->getSide())};
387 if (elements==
nullptr) {
395 if (sielement ==
nullptr) {
396 ATH_MSG_DEBUG(
"Barrel=" <<
barrel <<
" layer=" << firstHit->getLayerDisk() <<
" Eta=" << firstHit->getEtaModule() <<
" Phi=" << firstHit->getPhiModule() <<
" Side=" << firstHit->getSide());
397 ATH_MSG_ERROR(
"detector manager could not find element with id = " <<
id);
408 if (std::abs(phit->meanTime()) < 10000. * CLHEP::ns) {
410 phit->getLayerDisk(),
411 phit->getPhiModule(),
412 phit->getEtaModule(),
415 SiDigitizationSurfaceChargeInserter inserter(sielement, chargedDiodes);
430 int processorNumber{0};
433 proc->process(*chargedDiodes, rndmEngine);
443 ATH_MSG_VERBOSE(
"SCT_DigitizationTool::processBunchXing() " << bunchXing);
448 return StatusCode::SUCCESS;
451 return StatusCode::SUCCESS;
458 TimedHitCollList hitCollList;
461 bSubEvents, eSubEvents).isSuccess())) and
462 hitCollList.empty()) {
464 return StatusCode::FAILURE;
470 const TimedHitCollList::iterator endColl{hitCollList.end()};
471 for (TimedHitCollList::iterator iColl{hitCollList.begin()}; iColl != endColl; ++iColl) {
472 std::unique_ptr<SiHitCollection> hitCollPtr{std::make_unique<SiHitCollection>(*iColl->second)};
474 ATH_MSG_DEBUG(
"SiHitCollection found with " << hitCollPtr->size() <<
477 <<
" index: " << timeIndex.
index()
478 <<
" type: " << timeIndex.
type());
479 m_thpcsi->insert(timeIndex, hitCollPtr.get());
483 return StatusCode::SUCCESS;
507 std::ostringstream ost;
509 ost <<
"Digitized unprocessed elements: layer - phi - eta - side "
514 <<
" unprocessed hit number: " << ++
m_msgNo <<
'\n';
530 std::unique_ptr<SCT_RDO_Collection> RDOColl{
createRDO(chDiodeCollection)};
535 int barrelec{
m_detID->barrel_ec(id_coll)};
538 if ((*rdoContainer)->addCollection(RDOColl.release(), identifyHash).isFailure()) {
539 ATH_MSG_FATAL(
"SCT RDO collection could not be added to container!");
540 return StatusCode::FAILURE;
543 ATH_MSG_VERBOSE(
"Not saving SCT_RDO_Collection: " <<
m_detID->show_to_string(RDOColl->identify()) <<
" to container!");
545 return StatusCode::SUCCESS;
554 std::unique_ptr<SCT_RDO_Collection> p_rdocoll;
560 p_rdocoll = std::make_unique<SCT_RDO_Collection>(idHash_de);
561 }
catch (
const std::bad_alloc&) {
562 ATH_MSG_FATAL(
"Could not create a new SCT_RDORawDataCollection !");
564 p_rdocoll->setIdentifier(id_de);
570 for (; i_chargedDiode != i_chargedDiode_end; ++i_chargedDiode) {
571 unsigned int flagmask{
static_cast<unsigned int>((*i_chargedDiode).second.flag() & 0xFE)};
579 if (
strip > 0xffff) {
581 ATH_MSG_FATAL(
"Strip number too big for SCT1 raw data format.");
586 const unsigned int strip_rdo{
static_cast<unsigned int>((
strip & 0xFFFF) << 16)};
591 unsigned int size_rdo{
static_cast<unsigned int>(size & 0xFFFF)};
598 for (; it2 != i_chargedDiode_end; ++it2) {
600 if (cluscounter >= size) {
603 if (it2->second.flag() & 0xDE) {
604 int tmp{cluscounter};
605 while ((it2 != i_chargedDiode_end) and (cluscounter < size - 1) and (it2->second.flag() & 0xDE)) {
609 if ((it2 != collection->
end()) and !(it2->second.flag() & 0xDE)) {
614 size_rdo = tmp & 0xFFFF;
619 unsigned int SCT_Word{strip_rdo | size_rdo};
622 p_rdocoll->push_back(p_rdo);
630 static const std::vector<int> dummyvector;
631 for (; i_chargedDiode != i_chargedDiode_end; ++i_chargedDiode) {
632 unsigned int flagmask{
static_cast<unsigned int>((*i_chargedDiode).second.flag() & 0xFE)};
646 id_readout =
m_detID->strip_id(collection->
identify(), row2D, strip2D);
660 if (cluscounter >= size) {
661 ATH_MSG_WARNING(
"Cluster size reached while neighbouring strips still defined.");
664 if (diode->
flag() & 0xDE) {
665 int tmp{cluscounter};
666 while ((cluscounter < size - 1) and (diode->
flag() & 0xDE)) {
670 if (diode and !(diode->
flag() & 0xDE)) {
681 int stripIn11bits{
strip & 0x7ff};
682 if (stripIn11bits !=
strip) {
683 ATH_MSG_DEBUG(
"Strip number " <<
strip <<
" doesn't fit into 11 bits - will be truncated");
686 unsigned int SCT_Word{
static_cast<unsigned int>(groupSize | (stripIn11bits << 11) | (tbin << 22) | (ERRORS << 25))};
689 p_rdocoll->push_back(p_rdo);
709 if (!hitCollection.
isValid()) {
710 ATH_MSG_ERROR(
"Could not get SCT SiHitCollection container " << hitCollection.
name() <<
" from store " << hitCollection.
store());
711 return StatusCode::FAILURE;
715 m_thpcsi = std::make_unique<TimedHitCollection<SiHit>>(1);
717 ATH_MSG_DEBUG(
"SiHitCollection found with " << hitCollection->size() <<
" hits");
719 return StatusCode::SUCCESS;
722 TimedHitCollList hitCollList;
723 unsigned int numberOfSiHits{0};
726 return StatusCode::FAILURE;
731 m_thpcsi = std::make_unique<TimedHitCollection<SiHit>>(numberOfSiHits);
733 TimedHitCollList::iterator endColl{hitCollList.end()};
734 for (TimedHitCollList::iterator iColl{hitCollList.begin()}; iColl != endColl; ++iColl) {
748 m_thpcsi->insert(iColl->first, p_collection);
749 ATH_MSG_DEBUG(
"SiTrackerHitCollection found with " << p_collection->
size() <<
" hits");
751 return StatusCode::SUCCESS;
759 std::vector<InDetSimData::Deposit> deposits;
761 const auto collectionid = collection->
identify();
763 static_assert(std::is_nothrow_move_constructible<InDetSimData::Deposit>::value);
770 const list_t& charges{(*i_chargedDiode).second.totalCharge().chargeComposition()};
772 bool real_particle_hit{
false};
774 const list_t::const_iterator EndOfChargeList{charges.end()};
775 for (list_t::const_iterator i_ListOfCharges{charges.begin()}; i_ListOfCharges != EndOfChargeList; ++i_ListOfCharges) {
780 if (!real_particle_hit) {
791 real_particle_hit =
true;
795 std::vector<InDetSimData::Deposit>::reverse_iterator theDeposit{deposits.rend()};
796 std::vector<InDetSimData::Deposit>::reverse_iterator depositsR_end{deposits.rend()};
797 std::vector<InDetSimData::Deposit>::reverse_iterator i_Deposit{deposits.rbegin()};
798 for (; i_Deposit != depositsR_end; ++i_Deposit) {
799 if ((*i_Deposit).first == trkLink) {
800 theDeposit = i_Deposit;
806 if (theDeposit != depositsR_end) {
807 (*theDeposit).second += i_ListOfCharges->charge();
809 deposits.emplace_back(trkLink, i_ListOfCharges->charge());
817 const int row2D{sctDesign.
row(
strip)};
819 (*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.
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.
bool is_valid() const
Check if id is in a valid state.
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)
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