17#include "Identifier/Identifier.h"
30#include "CLHEP/Random/RandomEngine.h"
45 const std::string& name,
46 const IInterface* parent) :
47 base_class(
type, name, parent) {
81 return StatusCode::FAILURE;
98 return StatusCode::SUCCESS;
106 : m_sielement(sielement),
107 m_chargedDiodes(chargedDiodes) {
117 void SiDigitizationSurfaceChargeInserter::operator () (
const SiSurfaceCharge& scharge) {
123 m_chargedDiodes->
add(diode, scharge.
charge());
127 class MultiElementChargeInserter :
public ISiSurfaceChargesInserter {
130 const InDetDD::SCT_ModuleSideDesign * mum)
131 : m_chargedDiodesVecForInsert(chargedDiodesVec),
134 void operator () (
const SiSurfaceCharge &scharge);
137 const InDetDD::SCT_ModuleSideDesign * m_mum;
140 void MultiElementChargeInserter::operator () (
const SiSurfaceCharge &scharge) {
148 if (m_chargedDiodesVecForInsert.at(row)) {
149 SiCellId diode = m_chargedDiodesVecForInsert.at(row)->element()->cellIdOfPosition(scharge.
position());
153 m_chargedDiodesVecForInsert.at(row)->add(diode, scharge.
charge());
175 return StatusCode::SUCCESS;
187 return StatusCode::SUCCESS;
203 return StatusCode::SUCCESS;
216 return StatusCode::SUCCESS;
221 return StatusCode::FAILURE;
225 rngWrapper->
setSeed( name(), ctx );
226 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
245 return StatusCode::SUCCESS;
265 m_thpcsi = std::make_unique<TimedHitCollection<SiHit>>();
267 return StatusCode::SUCCESS;
278 rngWrapper->
setSeed( name(), ctx );
279 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
294 return StatusCode::SUCCESS;
313 ATH_MSG_DEBUG(
"Digitizing "<<chargedDiodesMap.size()<<
" Element(s)");
323 ATH_MSG_DEBUG(
"in digitize elements with hits: ec - layer - eta - phi "
328 <<
" processing hit number " << hitcount);
335 assert(idHash < processedElements->size());
336 (*processedElements)[idHash] =
true;
340 if (not chargedDiodes.
empty()) {
342 if (
sc.isSuccess()) {
344 addSDO(&chargedDiodes, simDataCollMap);
348 chargedDiodes.
clear();
359 if (elements==
nullptr) {
367 for (
unsigned int i{0}; i < processedElements->size(); i++) {
368 if (not (*processedElements)[i]) {
371 ATH_MSG_ERROR(
"SCT Detector element id hash is invalid = " << i);
376 ATH_MSG_DEBUG(
"In digitize of untouched elements: layer - phi - eta "
380 <<
"size: " << processedElements->size());
388 if (not chargedDiodes.
empty()) {
390 if (
sc.isSuccess()) {
392 addSDO(&chargedDiodes, simDataCollMap);
396 chargedDiodes.
clear();
404 if (
nullptr == thpcsi) {
410 chargedDiodesMap.clear();
422 int barrel{firstHit->getBarrelEndcap()};
424 firstHit->getLayerDisk(),
425 firstHit->getPhiModule(),
426 firstHit->getEtaModule(),
427 firstHit->getSide())};
433 if (elements==
nullptr) {
441 if (sielement ==
nullptr) {
442 ATH_MSG_DEBUG(
"Barrel=" <<
barrel <<
" layer=" << firstHit->getLayerDisk() <<
" Eta=" << firstHit->getEtaModule() <<
" Phi=" << firstHit->getPhiModule() <<
" Side=" << firstHit->getSide());
443 ATH_MSG_ERROR(
"detector manager could not find element with id = " <<
id);
454 std::map<int, const InDetDD::SCT_ModuleSideDesign *> children;
462 children.emplace(0,thisDesign);
466 for (
const std::pair <const int, const InDetDD::SCT_ModuleSideDesign *> &subDesign : children){
474 Identifier id_child{
m_detID->wafer_id(firstHit->getBarrelEndcap(), firstHit->getLayerDisk(),
475 firstHit->getPhiModule(), firstHit->getEtaModule()+subDesign.first,
476 firstHit->getSide())};
484 std::unique_ptr<SiChargedDiodeCollection> thisChargedDiode(std::make_unique<SiChargedDiodeCollection>());
485 int i_index = subDesign.first;
486 thisChargedDiode->setDetectorElement(sielement_child);
487 chargedDiodesMap.insert({i_index,std::move(thisChargedDiode)});
491 else ATH_MSG_ERROR(
"detector manager could not find element with id = "<<id_child<<
" Barrel=" << firstHit->getBarrelEndcap() <<
" layer=" <<
492 firstHit->getLayerDisk() <<
" Eta=" << firstHit->getEtaModule()+subDesign.first <<
" Phi=" << firstHit->getPhiModule()
493 <<
" Side=" <<firstHit->getSide());
502 if (std::abs(phit->meanTime()) < 10000. * CLHEP::ns) {
504 phit->getLayerDisk(),
505 phit->getPhiModule(),
506 phit->getEtaModule(),
513 if(chargedDiodesMap.size()>1) {
514 ATH_MSG_WARNING(
"More DiodesCollections("<<chargedDiodesMap.size()<<
") than expected (1). Please check your configuration!");
517 SiDigitizationSurfaceChargeInserter inserter(sielement,chargedDiodesMap[0].
get());
523 MultiElementChargeInserter inserter(chargedDiodesMap,motherDesign);
544 int processorNumber{0};
547 proc->process(*chargedDiodes, rndmEngine);
557 ATH_MSG_VERBOSE(
"StripDigitizationTool::processBunchXing() " << bunchXing);
562 return StatusCode::SUCCESS;
565 return StatusCode::SUCCESS;
572 TimedHitCollList hitCollList;
575 bSubEvents, eSubEvents).isSuccess())) and
576 hitCollList.empty()) {
578 return StatusCode::FAILURE;
584 TimedHitCollList::iterator endColl{hitCollList.end()};
585 for (TimedHitCollList::iterator iColl{hitCollList.begin()}; iColl != endColl; ++iColl) {
586 std::unique_ptr<SiHitCollection> hitCollPtr{std::make_unique<SiHitCollection>(*iColl->second)};
588 ATH_MSG_DEBUG(
"SiHitCollection found with " << hitCollPtr->size() <<
591 <<
" index: " << timeIndex.
index()
592 <<
" type: " << timeIndex.
type());
593 m_thpcsi->insert(timeIndex, hitCollPtr.get());
597 return StatusCode::SUCCESS;
621 std::ostringstream ost;
623 ost <<
"Digitized unprocessed elements: layer - phi - eta - side "
628 <<
" unprocessed hit number: " << ++
m_msgNo <<
'\n';
644 std::unique_ptr<SCT_RDO_Collection> RDOColl{
createRDO(chDiodeCollection)};
649 int barrelec{
m_detID->barrel_ec(id_coll)};
652 if ((*rdoContainer)->addCollection(RDOColl.release(), identifyHash).isFailure()) {
653 ATH_MSG_FATAL(
"SCT RDO collection could not be added to container!");
654 return StatusCode::FAILURE;
657 ATH_MSG_VERBOSE(
"Not saving SCT_RDO_Collection: " <<
m_detID->show_to_string(RDOColl->identify()) <<
" to container!");
659 return StatusCode::SUCCESS;
668 std::unique_ptr<SCT_RDO_Collection> p_rdocoll;
674 p_rdocoll = std::make_unique<SCT_RDO_Collection>(idHash_de);
675 }
catch (
const std::bad_alloc&) {
676 ATH_MSG_FATAL(
"Could not create a new SCT_RDORawDataCollection !");
678 p_rdocoll->setIdentifier(id_de);
684 for (; i_chargedDiode != i_chargedDiode_end; ++i_chargedDiode) {
685 unsigned int flagmask{
static_cast<unsigned int>((*i_chargedDiode).second.flag() & 0xFE)};
693 if (
strip > 0xffff) {
695 ATH_MSG_FATAL(
"Strip number too big for SCT1 raw data format.");
700 const unsigned int strip_rdo{
static_cast<unsigned int>((
strip & 0xFFFF) << 16)};
705 unsigned int size_rdo{
static_cast<unsigned int>(size & 0xFFFF)};
712 for (; it2 != i_chargedDiode_end; ++it2) {
714 if (cluscounter >= size) {
717 if (it2->second.flag() & 0xDE) {
718 int tmp{cluscounter};
719 while ((it2 != i_chargedDiode_end) and (cluscounter < size - 1) and (it2->second.flag() & 0xDE)) {
723 if ((it2 != collection->
end()) and !(it2->second.flag() & 0xDE)) {
728 size_rdo = tmp & 0xFFFF;
733 unsigned int StripWord{strip_rdo | size_rdo};
736 p_rdocoll->push_back(p_rdo);
744 static const std::vector<int> dummyvector;
745 for (; i_chargedDiode != i_chargedDiode_end; ++i_chargedDiode) {
746 unsigned int flagmask{
static_cast<unsigned int>((*i_chargedDiode).second.flag() & 0xFE)};
760 id_readout =
m_detID->strip_id(collection->
identify(), row2D, strip2D);
774 if (cluscounter >= size) {
775 ATH_MSG_WARNING(
"Cluster size reached while neighbouring strips still defined.");
778 if (diode->
flag() & 0xDE) {
779 int tmp{cluscounter};
780 while ((cluscounter < size - 1) and (diode->
flag() & 0xDE)) {
784 if (diode and !(diode->
flag() & 0xDE)) {
795 int stripIn11bits{
strip & 0x7ff};
796 if (stripIn11bits !=
strip) {
797 ATH_MSG_DEBUG(
"Strip number " <<
strip <<
" doesn't fit into 11 bits - will be truncated");
800 unsigned int StripWord{
static_cast<unsigned int>(groupSize | (stripIn11bits << 11) | (tbin << 22) | (ERRORS << 25))};
803 p_rdocoll->push_back(p_rdo);
823 if (!hitCollection.
isValid()) {
824 ATH_MSG_ERROR(
"Could not get SCT SiHitCollection container " << hitCollection.
name() <<
" from store " << hitCollection.
store());
825 return StatusCode::FAILURE;
829 m_thpcsi = std::make_unique<TimedHitCollection<SiHit>>(1);
831 ATH_MSG_DEBUG(
"SiHitCollection found with " << hitCollection->size() <<
" hits");
833 return StatusCode::SUCCESS;
836 TimedHitCollList hitCollList;
837 unsigned int numberOfSiHits{0};
840 return StatusCode::FAILURE;
845 m_thpcsi = std::make_unique<TimedHitCollection<SiHit>>(numberOfSiHits);
847 TimedHitCollList::iterator endColl{hitCollList.end()};
848 for (TimedHitCollList::iterator iColl{hitCollList.begin()}; iColl != endColl; ++iColl) {
862 m_thpcsi->insert(iColl->first, p_collection);
863 ATH_MSG_DEBUG(
"SiTrackerHitCollection found with " << p_collection->
size() <<
" hits");
865 return StatusCode::SUCCESS;
874 std::vector<InDetSimData::Deposit> deposits;
881 const list_t& charges{(*i_chargedDiode).second.totalCharge().chargeComposition()};
883 bool real_particle_hit{
false};
885 list_t::const_iterator EndOfChargeList{charges.end()};
886 for (list_t::const_iterator i_ListOfCharges{charges.begin()}; i_ListOfCharges != EndOfChargeList; ++i_ListOfCharges) {
891 if (not real_particle_hit) {
902 real_particle_hit =
true;
906 std::vector<InDetSimData::Deposit>::reverse_iterator theDeposit{deposits.rend()};
907 std::vector<InDetSimData::Deposit>::reverse_iterator depositsR_end{deposits.rend()};
908 std::vector<InDetSimData::Deposit>::reverse_iterator i_Deposit{deposits.rbegin()};
909 for (; i_Deposit != depositsR_end; ++i_Deposit) {
910 if ((*i_Deposit).first == trkLink) {
911 theDeposit = i_Deposit;
917 if (theDeposit != depositsR_end) {
918 (*theDeposit).second += i_ListOfCharges->charge();
920 deposits.emplace_back(trkLink, i_ListOfCharges->charge());
938 (*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.
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.
bool is_valid() const
Check if id is in a valid state.
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)
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