25#include "Identifier/Identifier.h"
40#include "GaudiKernel/EventContext.h"
47#include "CLHEP/Random/RandomEngine.h"
48#include "CLHEP/Random/RandGaussZiggurat.h"
53 const std::string& name,
54 const IInterface* parent)
58 m_settings->addPropertiesForOverrideableParameters(
static_cast<AlgTool*
>(
this));
90 m_settings->printFlagsForOverrideableParameters(
"TRTDigSettings Overrideables : ");
111 return StatusCode::FAILURE;
145 const double intervalBetweenCrossings(
m_settings->timeInterval() / 3.);
152 ATH_MSG_ERROR (
"storeSDO is out of range:"<<
m_settings->storeSDO()<<
"allowed values are: 0,1,2. Setting storeSDO = 2 " );
162 return StatusCode::SUCCESS;
172 return StatusCode::SUCCESS;
180 m_seen.emplace_back(std::distance(bSubEvents,eSubEvents), bunchXing);
190 TimedHitCollList hitCollList;
193 bSubEvents, eSubEvents).isSuccess()) &&
194 hitCollList.empty()) {
196 return StatusCode::FAILURE;
198 ATH_MSG_VERBOSE(hitCollList.size() <<
" TRTUncompressedHitCollection with key " <<
202 TimedHitCollList::iterator iColl(hitCollList.begin());
203 TimedHitCollList::iterator endColl(hitCollList.end());
205 for( ; iColl != endColl; ++iColl){
208 ATH_MSG_DEBUG(
"TRTUncompressedHitCollection found with " << hitCollPtr->
size() <<
211 <<
" index: " << timeIndex.
index()
212 <<
" type: " << timeIndex.
type());
213 m_thpctrt->insert(timeIndex, hitCollPtr);
217 return StatusCode::SUCCESS;
260 noiseThreshRndmEngine,
261 noiseElecResetRndmEngine,
289 pTRTsimdrifttimetool,
300 return StatusCode::SUCCESS;
306 std::set<int>& sim_hitids, std::set<Identifier>& simhitsIdentifiers,
307 CLHEP::HepRandomEngine *rndmEngine,
308 CLHEP::HepRandomEngine *strawRndmEngine,
309 CLHEP::HepRandomEngine *elecProcRndmEngine,
310 CLHEP::HepRandomEngine *elecNoiseRndmEngine,
311 CLHEP::HepRandomEngine *paiRndmEngine) {
325 if (fieldCondObj ==
nullptr) {
327 return StatusCode::FAILURE;
334 if(!trtDetElements) {
336 return StatusCode::FAILURE;
341 ATH_CHECK(simDataMap.
record(std::make_unique<InDetSimDataCollection>() ));
344 if (not simDataMap.
isValid()) {
346 return StatusCode::FAILURE;
357 std::vector<InDetSimData::Deposit> depositVector(100);
363 int hitID((*i)->GetHitID());
370 sim_hitids.insert(hitID);
373 if ( hitID & 0xc0000000 ) {
374 ATH_MSG_ERROR (
"Hit ID not Valid (" << MSG::hex << hitID <<
")" << MSG::dec );
383 if ( !identifierOK ) {
384 ATH_MSG_ERROR (
"Ignoring simhits with suspicious identifier (1)" );
389 simhitsIdentifiers.insert(idStraw);
393 depositVector.clear();
394 depositVector.reserve(std::distance(i,e));
398 (*hit_iter)->GetEnergyDeposit() );
402 ATH_MSG_VERBOSE (
"Deposit: trackID " << deposit.first <<
" energyDeposit " << deposit.second );
403 depositVector.emplace_back(std::move(deposit));
407 const double bunchCrossingTime(
hitTime(theHit) -
static_cast<double>(theHit->GetGlobalTime()));
410 if ( !depositVector.empty() &&
413 simDataMap->try_emplace(idStraw, std::move(depositVector));
430 bool emulateArFlag =
m_sumTool->getStatusHT(idStraw, ctx) == 6;
431 bool emulateKrFlag =
m_sumTool->getStatusHT(idStraw, ctx) == 7;
432 const int statusHT =
m_sumTool->getStatusHT(idStraw, ctx);
459 return StatusCode::SUCCESS;
467 CLHEP::HepRandomEngine *elecNoiseRndmEngine =
getRandomEngine(
"TRT_ElectronicsNoise", ctx);
468 CLHEP::HepRandomEngine *noiseRndmEngine =
getRandomEngine(
"TRT_NoiseDigitPool", ctx);
469 CLHEP::HepRandomEngine *strawRndmEngine =
getRandomEngine(
"TRT_ProcessStraw", ctx);
470 CLHEP::HepRandomEngine *elecProcRndmEngine =
getRandomEngine(
"TRT_ThresholdFluctuations", ctx);
471 CLHEP::HepRandomEngine *paiRndmEngine =
getRandomEngine(
"TRT_PAI", ctx);
476 return StatusCode::FAILURE;
482 ATH_MSG_DEBUG (
"TRTDigitizationTool::processAllSubEvents()" );
490 return StatusCode::FAILURE;
503 if (!hitCollection.
isValid()) {
504 ATH_MSG_ERROR(
"Could not get TRTUncompressedHitCollection container " << hitCollection.
name() <<
" from store " << hitCollection.
store());
505 return StatusCode::FAILURE;
513 ATH_MSG_DEBUG(
"TRTUncompressedHitCollection found with " << hitCollection->size() <<
" hits");
516 TimedHitCollList hitCollList;
517 unsigned int numberOfSimHits(0);
518 if ( !(
m_mergeSvc->retrieveSubEvtsData(
m_dataObjectName, hitCollList, numberOfSimHits).isSuccess()) && hitCollList.empty() ) {
520 return StatusCode::FAILURE;
526 thpctrt.
reserve(numberOfSimHits);
529 TimedHitCollList::iterator iColl(hitCollList.begin());
530 TimedHitCollList::iterator endColl(hitCollList.end() );
533 while ( iColl != endColl ) {
539 thpctrt.
insert(iColl->first, p_collection);
540 ATH_MSG_DEBUG (
"TRTUncompressedHitCollection found with " << p_collection->
size() <<
" hits" );
546 std::set<int> sim_hitids;
547 std::set<Identifier> simhitsIdentifiers;
550 ATH_CHECK(this->
processStraws(ctx, thpctrt, sim_hitids, simhitsIdentifiers, rndmEngine, strawRndmEngine, elecProcRndmEngine, elecNoiseRndmEngine,paiRndmEngine));
556 const int numberOfDigitsBeforeNoise(
m_vDigits.size());
576 return StatusCode::FAILURE;
582 return StatusCode::SUCCESS;
586 const EventContext& ctx)
const
589 std::string rngName = name()+streamName;
590 rngWrapper->
setSeed( rngName, ctx );
596 const EventContext& ctx)
const
599 rngWrapper->
setSeed( streamName, ctx.slot(), randomSeedOffset, ctx.eventID().run_number() );
608 ATH_MSG_DEBUG(
"mergeEvent: there are " << ii->first <<
" events in bunch xing " << ii->second );
614 CLHEP::HepRandomEngine *elecNoiseRndmEngine =
getRandomEngine(
"TRT_ElectronicsNoise", ctx);
615 CLHEP::HepRandomEngine *noiseRndmEngine =
getRandomEngine(
"TRT_NoiseDigitPool", ctx);
616 CLHEP::HepRandomEngine *strawRndmEngine =
getRandomEngine(
"TRT_ProcessStraw", ctx);
617 CLHEP::HepRandomEngine *elecProcRndmEngine =
getRandomEngine(
"TRT_ThresholdFluctuations", ctx);
618 CLHEP::HepRandomEngine *paiRndmEngine =
getRandomEngine(
"TRT_PAI", ctx);
623 return StatusCode::FAILURE;
636 return StatusCode::FAILURE;
642 std::set<int> sim_hitids;
643 std::set<Identifier> simhitsIdentifiers;
647 ATH_CHECK(this->
processStraws(ctx, *
m_thpctrt, sim_hitids, simhitsIdentifiers, rndmEngine, strawRndmEngine, elecProcRndmEngine, elecNoiseRndmEngine,paiRndmEngine));
656 const unsigned int numberOfDigitsBeforeNoise(
m_vDigits.size());
676 return StatusCode::FAILURE;
682 return StatusCode::SUCCESS;
689 std::vector<TRTDigit>::const_iterator TRTDigitIter(
m_vDigits.begin());
690 std::vector<TRTDigit>::const_iterator endOfTRTDigits(
m_vDigits.end());
699 while (TRTDigitIter != endOfTRTDigits) {
700 ATH_MSG_DEBUG (
"Digit ID " << TRTDigitIter->GetStrawID() <<
" Digit " << TRTDigitIter->GetDigit() );
703 bool identifierOK(
false);
704 idStraw =
getIdentifier(TRTDigitIter->GetStrawID(), IdHash, layer_id, identifierOK);
706 ATH_MSG_ERROR (
"Ignoring simhits with suspicious identifier (2)" );
719 if (IdHash != IdHashOld) {
721 ATH_MSG_DEBUG (
"New TRT RDO Collection created with IdHash " <<
static_cast<int>(IdHash) );
728 return StatusCode::FAILURE;
739 ATH_MSG_FATAL (
"Failed to create the TRT_RDO_Collection before trying to add an RDO to it! IdHash = " <<
static_cast<int>(IdHash) );
741 return StatusCode::FAILURE;
747 return StatusCode::SUCCESS;
755 bool & statusok )
const
761 const int mask(0x0000001F);
762 const int word_shift(5);
763 int trtID, ringID, moduleID, layerID, strawID;
764 int wheelID, planeID, sectorID;
769 if ( !(hitID & 0x00200000) ) {
770 strawID = hitID & mask;
771 hitID >>= word_shift;
772 layerID = hitID & mask;
773 hitID >>= word_shift;
774 moduleID = hitID & mask;
775 hitID >>= word_shift;
776 ringID = hitID & mask;
777 trtID = hitID >> word_shift;
779 barrelElement =
m_manager->getBarrelElement(trtID, ringID, moduleID, layerID);
780 if ( barrelElement ) {
782 IdLayer = barrelElement->
identify();
783 IdStraw =
m_trt_id->straw_id(IdLayer, strawID);
785 ATH_MSG_ERROR (
"Could not find detector element for barrel identifier with "
786 <<
"(ipos,iring,imod,ilayer,istraw) = ("
787 << trtID <<
", " << ringID <<
", " << moduleID <<
", "
788 << layerID <<
", " << strawID <<
")" );
792 strawID = hitID & mask;
793 hitID >>= word_shift;
794 planeID = hitID & mask;
795 hitID >>= word_shift;
796 sectorID = hitID & mask;
797 hitID >>= word_shift;
798 wheelID = hitID & mask;
799 trtID = hitID >> word_shift;
802 if (trtID == 3) { trtID = 0; }
805 endcapElement =
m_manager->getEndcapElement(trtID, wheelID, planeID, sectorID);
807 if ( endcapElement ) {
809 IdLayer = endcapElement->
identify();
810 IdStraw =
m_trt_id->straw_id(IdLayer, strawID);
812 ATH_MSG_ERROR (
"Could not find detector element for endcap identifier with "
813 <<
"(ipos,iwheel,isector,iplane,istraw) = ("
814 << trtID <<
", " << wheelID <<
", " << sectorID <<
", "
815 << planeID <<
", " << strawID <<
")" );
816 ATH_MSG_ERROR (
"If this happens very rarely, don't be alarmed (it is a Geant4 'feature')" );
817 ATH_MSG_ERROR (
"If it happens a lot, you probably have misconfigured geometry in the sim. job." );
830 m_settings->print(
"TRTDigSettings Settings : ");
835 return StatusCode::SUCCESS;
843 return CLHEP::RandGaussZiggurat::shoot(rndmEngine, 5.48, 8.91);
float hitTime(const AFP_SIDSimHit &hit)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
AtlasHitsVector< TRTUncompressedHit > TRTUncompressedHitCollection
This is an Identifier helper class for the TRT subdetector.
InDetRawDataCollection< TRT_RDORawData > TRT_RDO_Collection
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.
void getInitializedCache(MagField::AtlasFieldCache &cache) const
get B field cache for evaluation as a function of 2-d or 3-d position.
value_type push_back(value_type pElem)
static HepMcParticleLink getRedirectedLink(const HepMcParticleLink &particleLink, uint32_t eventIndex, const EventContext &ctx)
Return a HepMcParticleLink pointing at the same particle, but in a different GenEvent.
This is a "hash" representation of an Identifier.
Extended TRT_BaseElement to describe a TRT readout element, this is a planar layer with n ( order of ...
virtual IdentifierHash identifyHash() const override final
identifier hash
virtual Identifier identify() const override final
identifier of this detector element:
Class to hold different TRT detector elements structures.
Extended class of a TRT_BaseElement to describe a readout elment in the endcap.
virtual IdentifierHash identifyHash() const override final
void setIdentifier(Identifier id)
std::pair< HepMcParticleLink, float > Deposit
Local cache for magnetic field (based on MagFieldServices/AtlasFieldSvcTLS.h).
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.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
"Fake" straw map until "real" map is known.
Class containing parameters and settings used by TRT digitization.
unsigned GetDigit() const
Get digit.
Simulate TRT Electronics Noise For description of metod, see Thomas Kittelmanns PhD thesis chapters ...
Simulation of noise hits in the TRT.
static void sortDigits(std::vector< TRTDigit > &digitVect)
TRT Digitization: Processing of a TRT Straws.
void reserve(unsigned int numberOfHits)
reserve a timed vector numberOfHits in size.
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
void insert(const PileUpTimeEventIndex &timeEventIndex, const AtlasHitsVector< HIT > *inputCollection)
a smart pointer to a hit that also provides access to the extended timing info of the host event.
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())
int StrawGasType(int statusHT, int useGasMix, MsgStream *log)
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