17 #include "Identifier/Identifier.h"
30 #include "CLHEP/Random/RandomEngine.h"
45 const std::string&
name,
46 const IInterface*
parent) :
81 return StatusCode::FAILURE;
98 return StatusCode::SUCCESS;
106 : m_sielement(sielement),
107 m_chargedDiodes(chargedDiodes) {
117 void SiDigitizationSurfaceChargeInserter::operator () (
const SiSurfaceCharge& scharge) {
121 if (diode.isValid()) {
123 m_chargedDiodes->add(diode, scharge.
charge());
131 : m_chargedDiodesVecForInsert(chargedDiodesVec),
140 void MultiElementChargeInserter::operator () (
const SiSurfaceCharge &scharge) {
145 auto [
strip,
row] = m_mum->getStripRow(motherDiode);
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;
226 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
245 return StatusCode::SUCCESS;
265 m_thpcsi = std::make_unique<TimedHitCollection<SiHit>>();
267 return StatusCode::SUCCESS;
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]) {
370 if (not idHash.is_valid()) {
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;
466 for (
const std::pair <const int, const InDetDD::SCT_ModuleSideDesign *> &subDesign :
children){
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;
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;
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)};
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;
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 !");
684 for (; i_chargedDiode != i_chargedDiode_end; ++i_chargedDiode) {
685 unsigned int flagmask{
static_cast<unsigned int>((*i_chargedDiode).second.flag() & 0xFE)};
692 int strip{roCell.strip()};
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};
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)};
752 int strip{roCell.strip()};
754 int row2D{sctDesign.
row(strip)};
759 int strip2D{sctDesign.strip(strip)};
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)) {
781 diode = diode->nextInCluster();
784 if (diode and !(diode->flag() & 0xDE)) {
791 diode = diode->nextInCluster();
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))};
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;
840 return StatusCode::FAILURE;
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());
927 int strip{roCell.strip()};
930 int row2D{sctDesign.
row(strip)};
935 int strip2D{sctDesign.strip(strip)};
938 (*simDataCollMap)->try_emplace(id_readout, std::move(deposits), (*i_chargedDiode).second.flag());