25#include "Identifier/Identifier.h"
40#include "GaudiKernel/EventContext.h"
41#include "GaudiKernel/ThreadLocalContext.h"
48#include "CLHEP/Random/RandomEngine.h"
49#include "CLHEP/Random/RandGaussZiggurat.h"
54 const std::string& name,
55 const IInterface* parent)
59 m_settings->addPropertiesForOverrideableParameters(
static_cast<AlgTool*
>(
this));
91 m_settings->printFlagsForOverrideableParameters(
"TRTDigSettings Overrideables : ");
112 return StatusCode::FAILURE;
150 const double intervalBetweenCrossings(
m_settings->timeInterval() / 3.);
157 ATH_MSG_ERROR (
"storeSDO is out of range:"<<
m_settings->storeSDO()<<
"allowed values are: 0,1,2. Setting storeSDO = 2 " );
167 return StatusCode::SUCCESS;
177 return StatusCode::SUCCESS;
185 m_seen.emplace_back(std::distance(bSubEvents,eSubEvents), bunchXing);
195 TimedHitCollList hitCollList;
198 bSubEvents, eSubEvents).isSuccess()) &&
199 hitCollList.empty()) {
201 return StatusCode::FAILURE;
203 ATH_MSG_VERBOSE(hitCollList.size() <<
" TRTUncompressedHitCollection with key " <<
207 TimedHitCollList::iterator iColl(hitCollList.begin());
208 TimedHitCollList::iterator endColl(hitCollList.end());
210 for( ; iColl != endColl; ++iColl){
213 ATH_MSG_DEBUG(
"TRTUncompressedHitCollection found with " << hitCollPtr->
size() <<
216 <<
" index: " << timeIndex.
index()
217 <<
" type: " << timeIndex.
type());
218 m_thpctrt->insert(timeIndex, hitCollPtr);
222 return StatusCode::SUCCESS;
265 noiseThreshRndmEngine,
266 noiseElecResetRndmEngine,
294 pTRTsimdrifttimetool,
306 return StatusCode::SUCCESS;
312 std::set<int>& sim_hitids, std::set<Identifier>& simhitsIdentifiers,
313 CLHEP::HepRandomEngine *rndmEngine,
314 CLHEP::HepRandomEngine *strawRndmEngine,
315 CLHEP::HepRandomEngine *elecProcRndmEngine,
316 CLHEP::HepRandomEngine *elecNoiseRndmEngine,
317 CLHEP::HepRandomEngine *paiRndmEngine) {
331 if (fieldCondObj ==
nullptr) {
333 return StatusCode::FAILURE;
340 if(!trtDetElements) {
342 return StatusCode::FAILURE;
347 ATH_CHECK(simDataMap.
record(std::make_unique<InDetSimDataCollection>() ));
350 if (not simDataMap.
isValid()) {
352 return StatusCode::FAILURE;
363 std::vector<InDetSimData::Deposit> depositVector(100);
369 int hitID((*i)->GetHitID());
376 sim_hitids.insert(hitID);
379 if ( hitID & 0xc0000000 ) {
380 ATH_MSG_ERROR (
"Hit ID not Valid (" << MSG::hex << hitID <<
")" << MSG::dec );
389 if ( !identifierOK ) {
390 ATH_MSG_ERROR (
"Ignoring simhits with suspicious identifier (1)" );
395 simhitsIdentifiers.insert(idStraw);
399 depositVector.clear();
400 depositVector.reserve(std::distance(i,e));
404 (*hit_iter)->GetEnergyDeposit() );
408 ATH_MSG_VERBOSE (
"Deposit: trackID " << deposit.first <<
" energyDeposit " << deposit.second );
409 depositVector.emplace_back(std::move(deposit));
413 const double bunchCrossingTime(
hitTime(theHit) -
static_cast<double>(theHit->GetGlobalTime()));
416 if ( !depositVector.empty() &&
419 simDataMap->try_emplace(idStraw, std::move(depositVector));
436 bool emulateArFlag =
m_sumTool->getStatusHT(idStraw, ctx) == 6;
437 bool emulateKrFlag =
m_sumTool->getStatusHT(idStraw, ctx) == 7;
438 const int statusHT =
m_sumTool->getStatusHT(idStraw, ctx);
465 return StatusCode::SUCCESS;
473 CLHEP::HepRandomEngine *elecNoiseRndmEngine =
getRandomEngine(
"TRT_ElectronicsNoise", ctx);
474 CLHEP::HepRandomEngine *noiseRndmEngine =
getRandomEngine(
"TRT_NoiseDigitPool", ctx);
475 CLHEP::HepRandomEngine *strawRndmEngine =
getRandomEngine(
"TRT_ProcessStraw", ctx);
476 CLHEP::HepRandomEngine *elecProcRndmEngine =
getRandomEngine(
"TRT_ThresholdFluctuations", ctx);
477 CLHEP::HepRandomEngine *paiRndmEngine =
getRandomEngine(
"TRT_PAI", ctx);
482 return StatusCode::FAILURE;
488 ATH_MSG_DEBUG (
"TRTDigitizationTool::processAllSubEvents()" );
496 return StatusCode::FAILURE;
509 if (!hitCollection.
isValid()) {
510 ATH_MSG_ERROR(
"Could not get TRTUncompressedHitCollection container " << hitCollection.
name() <<
" from store " << hitCollection.
store());
511 return StatusCode::FAILURE;
519 ATH_MSG_DEBUG(
"TRTUncompressedHitCollection found with " << hitCollection->size() <<
" hits");
522 TimedHitCollList hitCollList;
523 unsigned int numberOfSimHits(0);
524 if ( !(
m_mergeSvc->retrieveSubEvtsData(
m_dataObjectName, hitCollList, numberOfSimHits).isSuccess()) && hitCollList.empty() ) {
526 return StatusCode::FAILURE;
532 thpctrt.
reserve(numberOfSimHits);
535 TimedHitCollList::iterator iColl(hitCollList.begin());
536 TimedHitCollList::iterator endColl(hitCollList.end() );
539 while ( iColl != endColl ) {
545 thpctrt.
insert(iColl->first, p_collection);
546 ATH_MSG_DEBUG (
"TRTUncompressedHitCollection found with " << p_collection->
size() <<
" hits" );
552 std::set<int> sim_hitids;
553 std::set<Identifier> simhitsIdentifiers;
556 ATH_CHECK(this->
processStraws(ctx, thpctrt, sim_hitids, simhitsIdentifiers, rndmEngine, strawRndmEngine, elecProcRndmEngine, elecNoiseRndmEngine,paiRndmEngine));
562 const int numberOfDigitsBeforeNoise(
m_vDigits.size());
582 return StatusCode::FAILURE;
588 return StatusCode::SUCCESS;
592 const EventContext& ctx)
const
595 std::string rngName = name()+streamName;
596 rngWrapper->
setSeed( rngName, ctx );
602 const EventContext& ctx)
const
605 rngWrapper->
setSeed( streamName, ctx.slot(), randomSeedOffset, ctx.eventID().run_number() );
614 ATH_MSG_DEBUG(
"mergeEvent: there are " << ii->first <<
" events in bunch xing " << ii->second );
620 CLHEP::HepRandomEngine *elecNoiseRndmEngine =
getRandomEngine(
"TRT_ElectronicsNoise", ctx);
621 CLHEP::HepRandomEngine *noiseRndmEngine =
getRandomEngine(
"TRT_NoiseDigitPool", ctx);
622 CLHEP::HepRandomEngine *strawRndmEngine =
getRandomEngine(
"TRT_ProcessStraw", ctx);
623 CLHEP::HepRandomEngine *elecProcRndmEngine =
getRandomEngine(
"TRT_ThresholdFluctuations", ctx);
624 CLHEP::HepRandomEngine *paiRndmEngine =
getRandomEngine(
"TRT_PAI", ctx);
629 return StatusCode::FAILURE;
642 return StatusCode::FAILURE;
648 std::set<int> sim_hitids;
649 std::set<Identifier> simhitsIdentifiers;
653 ATH_CHECK(this->
processStraws(ctx, *
m_thpctrt, sim_hitids, simhitsIdentifiers, rndmEngine, strawRndmEngine, elecProcRndmEngine, elecNoiseRndmEngine,paiRndmEngine));
662 const unsigned int numberOfDigitsBeforeNoise(
m_vDigits.size());
682 return StatusCode::FAILURE;
688 return StatusCode::SUCCESS;
695 std::vector<TRTDigit>::const_iterator TRTDigitIter(
m_vDigits.begin());
696 std::vector<TRTDigit>::const_iterator endOfTRTDigits(
m_vDigits.end());
705 while (TRTDigitIter != endOfTRTDigits) {
706 ATH_MSG_DEBUG (
"Digit ID " << TRTDigitIter->GetStrawID() <<
" Digit " << TRTDigitIter->GetDigit() );
709 bool identifierOK(
false);
710 idStraw =
getIdentifier(TRTDigitIter->GetStrawID(), IdHash, layer_id, identifierOK);
712 ATH_MSG_ERROR (
"Ignoring simhits with suspicious identifier (2)" );
725 if (IdHash != IdHashOld) {
727 ATH_MSG_DEBUG (
"New TRT RDO Collection created with IdHash " <<
static_cast<int>(IdHash) );
734 return StatusCode::FAILURE;
745 ATH_MSG_FATAL (
"Failed to create the TRT_RDO_Collection before trying to add an RDO to it! IdHash = " <<
static_cast<int>(IdHash) );
747 return StatusCode::FAILURE;
753 return StatusCode::SUCCESS;
761 bool & statusok )
const
767 const int mask(0x0000001F);
768 const int word_shift(5);
769 int trtID, ringID, moduleID, layerID, strawID;
770 int wheelID, planeID, sectorID;
775 if ( !(hitID & 0x00200000) ) {
776 strawID = hitID & mask;
777 hitID >>= word_shift;
778 layerID = hitID & mask;
779 hitID >>= word_shift;
780 moduleID = hitID & mask;
781 hitID >>= word_shift;
782 ringID = hitID & mask;
783 trtID = hitID >> word_shift;
785 barrelElement =
m_manager->getBarrelElement(trtID, ringID, moduleID, layerID);
786 if ( barrelElement ) {
788 IdLayer = barrelElement->
identify();
789 IdStraw =
m_trt_id->straw_id(IdLayer, strawID);
791 ATH_MSG_ERROR (
"Could not find detector element for barrel identifier with "
792 <<
"(ipos,iring,imod,ilayer,istraw) = ("
793 << trtID <<
", " << ringID <<
", " << moduleID <<
", "
794 << layerID <<
", " << strawID <<
")" );
798 strawID = hitID & mask;
799 hitID >>= word_shift;
800 planeID = hitID & mask;
801 hitID >>= word_shift;
802 sectorID = hitID & mask;
803 hitID >>= word_shift;
804 wheelID = hitID & mask;
805 trtID = hitID >> word_shift;
808 if (trtID == 3) { trtID = 0; }
811 endcapElement =
m_manager->getEndcapElement(trtID, wheelID, planeID, sectorID);
813 if ( endcapElement ) {
815 IdLayer = endcapElement->
identify();
816 IdStraw =
m_trt_id->straw_id(IdLayer, strawID);
818 ATH_MSG_ERROR (
"Could not find detector element for endcap identifier with "
819 <<
"(ipos,iwheel,isector,iplane,istraw) = ("
820 << trtID <<
", " << wheelID <<
", " << sectorID <<
", "
821 << planeID <<
", " << strawID <<
")" );
822 ATH_MSG_ERROR (
"If this happens very rarely, don't be alarmed (it is a Geant4 'feature')" );
823 ATH_MSG_ERROR (
"If it happens a lot, you probably have misconfigured geometry in the sim. job." );
836 m_settings->print(
"TRTDigSettings Settings : ");
841 return StatusCode::SUCCESS;
849 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