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;
149 const double intervalBetweenCrossings(
m_settings->timeInterval() / 3.);
156 ATH_MSG_ERROR (
"storeSDO is out of range:"<<
m_settings->storeSDO()<<
"allowed values are: 0,1,2. Setting storeSDO = 2 " );
166 return StatusCode::SUCCESS;
176 return StatusCode::SUCCESS;
184 m_seen.emplace_back(std::distance(bSubEvents,eSubEvents), bunchXing);
194 TimedHitCollList hitCollList;
197 bSubEvents, eSubEvents).isSuccess()) &&
198 hitCollList.empty()) {
200 return StatusCode::FAILURE;
202 ATH_MSG_VERBOSE(hitCollList.size() <<
" TRTUncompressedHitCollection with key " <<
206 TimedHitCollList::iterator iColl(hitCollList.begin());
207 TimedHitCollList::iterator endColl(hitCollList.end());
209 for( ; iColl != endColl; ++iColl){
212 ATH_MSG_DEBUG(
"TRTUncompressedHitCollection found with " << hitCollPtr->
size() <<
215 <<
" index: " << timeIndex.
index()
216 <<
" type: " << timeIndex.
type());
217 m_thpctrt->insert(timeIndex, hitCollPtr);
221 return StatusCode::SUCCESS;
264 noiseThreshRndmEngine,
265 noiseElecResetRndmEngine,
293 pTRTsimdrifttimetool,
305 return StatusCode::SUCCESS;
311 std::set<int>& sim_hitids, std::set<Identifier>& simhitsIdentifiers,
312 CLHEP::HepRandomEngine *rndmEngine,
313 CLHEP::HepRandomEngine *strawRndmEngine,
314 CLHEP::HepRandomEngine *elecProcRndmEngine,
315 CLHEP::HepRandomEngine *elecNoiseRndmEngine,
316 CLHEP::HepRandomEngine *paiRndmEngine) {
330 if (fieldCondObj ==
nullptr) {
332 return StatusCode::FAILURE;
339 if(!trtDetElements) {
341 return StatusCode::FAILURE;
346 ATH_CHECK(simDataMap.
record(std::make_unique<InDetSimDataCollection>() ));
349 if (not simDataMap.
isValid()) {
351 return StatusCode::FAILURE;
362 std::vector<InDetSimData::Deposit> depositVector(100);
368 int hitID((*i)->GetHitID());
375 sim_hitids.insert(hitID);
378 if ( hitID & 0xc0000000 ) {
379 ATH_MSG_ERROR (
"Hit ID not Valid (" << MSG::hex << hitID <<
")" << MSG::dec );
388 if ( !identifierOK ) {
389 ATH_MSG_ERROR (
"Ignoring simhits with suspicious identifier (1)" );
394 simhitsIdentifiers.insert(idStraw);
398 depositVector.clear();
399 depositVector.reserve(std::distance(i,e));
403 (*hit_iter)->GetEnergyDeposit() );
407 ATH_MSG_VERBOSE (
"Deposit: trackID " << deposit.first <<
" energyDeposit " << deposit.second );
408 depositVector.emplace_back(std::move(deposit));
412 const double bunchCrossingTime(
hitTime(theHit) -
static_cast<double>(theHit->GetGlobalTime()));
415 if ( !depositVector.empty() &&
418 simDataMap->try_emplace(idStraw, std::move(depositVector));
435 bool emulateArFlag =
m_sumTool->getStatusHT(idStraw, ctx) == 6;
436 bool emulateKrFlag =
m_sumTool->getStatusHT(idStraw, ctx) == 7;
437 const int statusHT =
m_sumTool->getStatusHT(idStraw, ctx);
464 return StatusCode::SUCCESS;
472 CLHEP::HepRandomEngine *elecNoiseRndmEngine =
getRandomEngine(
"TRT_ElectronicsNoise", ctx);
473 CLHEP::HepRandomEngine *noiseRndmEngine =
getRandomEngine(
"TRT_NoiseDigitPool", ctx);
474 CLHEP::HepRandomEngine *strawRndmEngine =
getRandomEngine(
"TRT_ProcessStraw", ctx);
475 CLHEP::HepRandomEngine *elecProcRndmEngine =
getRandomEngine(
"TRT_ThresholdFluctuations", ctx);
476 CLHEP::HepRandomEngine *paiRndmEngine =
getRandomEngine(
"TRT_PAI", ctx);
481 return StatusCode::FAILURE;
487 ATH_MSG_DEBUG (
"TRTDigitizationTool::processAllSubEvents()" );
495 return StatusCode::FAILURE;
508 if (!hitCollection.
isValid()) {
509 ATH_MSG_ERROR(
"Could not get TRTUncompressedHitCollection container " << hitCollection.
name() <<
" from store " << hitCollection.
store());
510 return StatusCode::FAILURE;
518 ATH_MSG_DEBUG(
"TRTUncompressedHitCollection found with " << hitCollection->size() <<
" hits");
521 TimedHitCollList hitCollList;
522 unsigned int numberOfSimHits(0);
523 if ( !(
m_mergeSvc->retrieveSubEvtsData(
m_dataObjectName, hitCollList, numberOfSimHits).isSuccess()) && hitCollList.empty() ) {
525 return StatusCode::FAILURE;
531 thpctrt.
reserve(numberOfSimHits);
534 TimedHitCollList::iterator iColl(hitCollList.begin());
535 TimedHitCollList::iterator endColl(hitCollList.end() );
538 while ( iColl != endColl ) {
544 thpctrt.
insert(iColl->first, p_collection);
545 ATH_MSG_DEBUG (
"TRTUncompressedHitCollection found with " << p_collection->
size() <<
" hits" );
551 std::set<int> sim_hitids;
552 std::set<Identifier> simhitsIdentifiers;
555 ATH_CHECK(this->
processStraws(ctx, thpctrt, sim_hitids, simhitsIdentifiers, rndmEngine, strawRndmEngine, elecProcRndmEngine, elecNoiseRndmEngine,paiRndmEngine));
561 const int numberOfDigitsBeforeNoise(
m_vDigits.size());
581 return StatusCode::FAILURE;
587 return StatusCode::SUCCESS;
591 const EventContext& ctx)
const
594 std::string rngName = name()+streamName;
595 rngWrapper->
setSeed( rngName, ctx );
601 const EventContext& ctx)
const
604 rngWrapper->
setSeed( streamName, ctx.slot(), randomSeedOffset, ctx.eventID().run_number() );
613 ATH_MSG_DEBUG(
"mergeEvent: there are " << ii->first <<
" events in bunch xing " << ii->second );
619 CLHEP::HepRandomEngine *elecNoiseRndmEngine =
getRandomEngine(
"TRT_ElectronicsNoise", ctx);
620 CLHEP::HepRandomEngine *noiseRndmEngine =
getRandomEngine(
"TRT_NoiseDigitPool", ctx);
621 CLHEP::HepRandomEngine *strawRndmEngine =
getRandomEngine(
"TRT_ProcessStraw", ctx);
622 CLHEP::HepRandomEngine *elecProcRndmEngine =
getRandomEngine(
"TRT_ThresholdFluctuations", ctx);
623 CLHEP::HepRandomEngine *paiRndmEngine =
getRandomEngine(
"TRT_PAI", ctx);
628 return StatusCode::FAILURE;
641 return StatusCode::FAILURE;
647 std::set<int> sim_hitids;
648 std::set<Identifier> simhitsIdentifiers;
652 ATH_CHECK(this->
processStraws(ctx, *
m_thpctrt, sim_hitids, simhitsIdentifiers, rndmEngine, strawRndmEngine, elecProcRndmEngine, elecNoiseRndmEngine,paiRndmEngine));
661 const unsigned int numberOfDigitsBeforeNoise(
m_vDigits.size());
681 return StatusCode::FAILURE;
687 return StatusCode::SUCCESS;
694 std::vector<TRTDigit>::const_iterator TRTDigitIter(
m_vDigits.begin());
695 std::vector<TRTDigit>::const_iterator endOfTRTDigits(
m_vDigits.end());
704 while (TRTDigitIter != endOfTRTDigits) {
705 ATH_MSG_DEBUG (
"Digit ID " << TRTDigitIter->GetStrawID() <<
" Digit " << TRTDigitIter->GetDigit() );
708 bool identifierOK(
false);
709 idStraw =
getIdentifier(TRTDigitIter->GetStrawID(), IdHash, layer_id, identifierOK);
711 ATH_MSG_ERROR (
"Ignoring simhits with suspicious identifier (2)" );
724 if (IdHash != IdHashOld) {
726 ATH_MSG_DEBUG (
"New TRT RDO Collection created with IdHash " <<
static_cast<int>(IdHash) );
733 return StatusCode::FAILURE;
744 ATH_MSG_FATAL (
"Failed to create the TRT_RDO_Collection before trying to add an RDO to it! IdHash = " <<
static_cast<int>(IdHash) );
746 return StatusCode::FAILURE;
752 return StatusCode::SUCCESS;
760 bool & statusok )
const
766 const int mask(0x0000001F);
767 const int word_shift(5);
768 int trtID, ringID, moduleID, layerID, strawID;
769 int wheelID, planeID, sectorID;
774 if ( !(hitID & 0x00200000) ) {
775 strawID = hitID & mask;
776 hitID >>= word_shift;
777 layerID = hitID & mask;
778 hitID >>= word_shift;
779 moduleID = hitID & mask;
780 hitID >>= word_shift;
781 ringID = hitID & mask;
782 trtID = hitID >> word_shift;
784 barrelElement =
m_manager->getBarrelElement(trtID, ringID, moduleID, layerID);
785 if ( barrelElement ) {
787 IdLayer = barrelElement->
identify();
788 IdStraw =
m_trt_id->straw_id(IdLayer, strawID);
790 ATH_MSG_ERROR (
"Could not find detector element for barrel identifier with "
791 <<
"(ipos,iring,imod,ilayer,istraw) = ("
792 << trtID <<
", " << ringID <<
", " << moduleID <<
", "
793 << layerID <<
", " << strawID <<
")" );
797 strawID = hitID & mask;
798 hitID >>= word_shift;
799 planeID = hitID & mask;
800 hitID >>= word_shift;
801 sectorID = hitID & mask;
802 hitID >>= word_shift;
803 wheelID = hitID & mask;
804 trtID = hitID >> word_shift;
807 if (trtID == 3) { trtID = 0; }
810 endcapElement =
m_manager->getEndcapElement(trtID, wheelID, planeID, sectorID);
812 if ( endcapElement ) {
814 IdLayer = endcapElement->
identify();
815 IdStraw =
m_trt_id->straw_id(IdLayer, strawID);
817 ATH_MSG_ERROR (
"Could not find detector element for endcap identifier with "
818 <<
"(ipos,iwheel,isector,iplane,istraw) = ("
819 << trtID <<
", " << wheelID <<
", " << sectorID <<
", "
820 << planeID <<
", " << strawID <<
")" );
821 ATH_MSG_ERROR (
"If this happens very rarely, don't be alarmed (it is a Geant4 'feature')" );
822 ATH_MSG_ERROR (
"If it happens a lot, you probably have misconfigured geometry in the sim. job." );
835 m_settings->print(
"TRTDigSettings Settings : ");
840 return StatusCode::SUCCESS;
848 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