ATLAS Offline Software
Loading...
Searching...
No Matches
TRTNoise Class Reference

Simulation of noise hits in the TRT. More...

#include <TRTNoise.h>

Inheritance diagram for TRTNoise:
Collaboration diagram for TRTNoise:

Public Member Functions

 TRTNoise (const TRTDigSettings *, const InDetDD::TRT_DetectorManager *, CLHEP::HepRandomEngine *noiseRndmEngine, CLHEP::HepRandomEngine *elecNoiseRndmEngine, CLHEP::HepRandomEngine *elecProcRndmEngine, CLHEP::HepRandomEngine *elecNoiseResetRndmEngine, TRTDigCondBase *digcond, TRTElectronicsProcessing *ep, TRTElectronicsNoise *electronicsnoise, const TRT_ID *trt_id, int UseGasMix, const ToolHandle< ITRT_StrawStatusSummaryTool > &sumTool)
 Constructor.
void appendPureNoiseToProperDigits (std::vector< TRTDigit > &digitVect, const std::set< int > &sim_hitids, CLHEP::HepRandomEngine *noiseRndmEngine)
 Append noise digits to list of digits from proper hits.
void appendCrossTalkNoiseToProperDigits (std::vector< TRTDigit > &digitVect, const std::set< Identifier > &simhitsIdentifiers, const ServiceHandle< ITRT_StrawNeighbourSvc > &m_TRTStrawNeighbourSvc, CLHEP::HepRandomEngine *noiseRndmEngine)
 ~TRTNoise ()
bool msgLvl (const MSG::Level lvl) const
 Test the output level.
MsgStream & msg () const
 The standard message stream.
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream.
void setLevel (MSG::Level lvl)
 Change the current logging level.

Static Public Member Functions

static void sortDigits (std::vector< TRTDigit > &digitVect)

Private Member Functions

void InitThresholdsAndNoiseAmplitudes_and_ProduceNoiseDigitPool (CLHEP::HepRandomEngine *noiseRndmEngine, CLHEP::HepRandomEngine *elecNoiseRndmEngine, CLHEP::HepRandomEngine *elecProcRndmEngine)
 Initialize thresholds and noise amplitudes.
void ProduceNoiseDigitPool (const std::vector< float > &lowthresholds, const std::vector< float > &noiseamps, const std::vector< int > &strawType, CLHEP::HepRandomEngine *noiseRndmEngine, CLHEP::HepRandomEngine *elecNoiseRndmEngine, CLHEP::HepRandomEngine *elecProcRndmEngine)
 Produce pool of pure noise digits (for simulation of noise in unhit straws) and store them in m_digitPool.
double simulateNoiseFrequency (unsigned int totalNumberOfTests, double electronicsNoiseAmplitude, double lowthreshold=-1.0)
Identifier getStrawIdentifier (int hitID)
void initMessaging () const
 Initialize our message level and MessageSvc.

Static Private Member Functions

static float useLookupTable (float x, const std::vector< float > &y_given_x, float min_x, float max_x)
 Return y value corresponding to input x value from LUT.
static void makeInvertedLookupTable (const std::vector< float > &y_given_x, float min_x, float max_x, std::vector< float > &x_given_y, float &min_y, float &max_y)
 Invert look-up-table: Go from tabulated y values vs.
static void evolve_LT2AmpVsNL_to_include_LTfluct (std::vector< float > &nl_given_lt2na, float min_lt2na, float max_lt2na, float relativeLTFluct, float &new_min_lt2na, float &new_max_lt2na, unsigned int number_new_bins)
 Refined noise treatment by allowing for event-by-event fluctuations in the low threshold settings.

Private Attributes

const TRTDigSettingsm_settings {}
const InDetDD::TRT_DetectorManagerm_detmgr {}
TRTDigCondBasem_pDigConditions {}
TRTElectronicsProcessingm_pElectronicsProcessing {}
TRTElectronicsNoisem_pElectronicsNoise {}
CLHEP::HepRandomEngine * m_noise_randengine {}
const TRT_IDm_id_helper
unsigned int m_digitPoolLength
 Length of noise digit pool m_digitPool.
unsigned int m_digitPoolLength_nextaccessindex
 Pointer into noise digit pool m_digitPool.
std::vector< unsigned int > m_digitPool
 Pool of noise digits for noise in unhit straws.
int m_UseGasMix {}
ToolHandle< ITRT_StrawStatusSummaryToolm_sumTool
std::string m_nm
 Message source name.
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels).
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer.
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging).

Detailed Description

Simulation of noise hits in the TRT.


For method, please see Thomas Kittelmanns thesis

Definition at line 39 of file TRTNoise.h.

Constructor & Destructor Documentation

◆ TRTNoise()

TRTNoise::TRTNoise ( const TRTDigSettings * digset,
const InDetDD::TRT_DetectorManager * detmgr,
CLHEP::HepRandomEngine * noiseRndmEngine,
CLHEP::HepRandomEngine * elecNoiseRndmEngine,
CLHEP::HepRandomEngine * elecProcRndmEngine,
CLHEP::HepRandomEngine * elecNoiseResetRndmEngine,
TRTDigCondBase * digcond,
TRTElectronicsProcessing * ep,
TRTElectronicsNoise * electronicsnoise,
const TRT_ID * trt_id,
int UseGasMix,
const ToolHandle< ITRT_StrawStatusSummaryTool > & sumTool )

Constructor.

Definition at line 37 of file TRTNoise.cxx.

50: AthMessaging("TRTNoise"),
51 m_settings(digset),
52 m_detmgr(detmgr),
53 m_pDigConditions(digcond),
55 m_pElectronicsNoise(electronicsnoise),
56 m_id_helper(trt_id),
59 m_UseGasMix(UseGasMix),
60 m_sumTool(sumTool)
61{
62 InitThresholdsAndNoiseAmplitudes_and_ProduceNoiseDigitPool(noiseRndmEngine,elecNoiseRndmEngine,elecProcRndmEngine);
63 if ( m_settings->noiseInSimhits() ) m_pElectronicsNoise->reinitElectronicsNoise( 1000, elecNoiseResetRndmEngine );
64}
AthMessaging()
Default constructor:
const TRT_ID * m_id_helper
Definition TRTNoise.h:139
unsigned int m_digitPoolLength
Length of noise digit pool m_digitPool.
Definition TRTNoise.h:141
ToolHandle< ITRT_StrawStatusSummaryTool > m_sumTool
Definition TRTNoise.h:210
void InitThresholdsAndNoiseAmplitudes_and_ProduceNoiseDigitPool(CLHEP::HepRandomEngine *noiseRndmEngine, CLHEP::HepRandomEngine *elecNoiseRndmEngine, CLHEP::HepRandomEngine *elecProcRndmEngine)
Initialize thresholds and noise amplitudes.
Definition TRTNoise.cxx:70
TRTElectronicsProcessing * m_pElectronicsProcessing
Definition TRTNoise.h:89
const InDetDD::TRT_DetectorManager * m_detmgr
Definition TRTNoise.h:86
TRTElectronicsNoise * m_pElectronicsNoise
Definition TRTNoise.h:90
int m_UseGasMix
Definition TRTNoise.h:209
const TRTDigSettings * m_settings
Definition TRTNoise.h:85
unsigned int m_digitPoolLength_nextaccessindex
Pointer into noise digit pool m_digitPool.
Definition TRTNoise.h:143
TRTDigCondBase * m_pDigConditions
Definition TRTNoise.h:88

◆ ~TRTNoise()

TRTNoise::~TRTNoise ( )
default

Member Function Documentation

◆ appendCrossTalkNoiseToProperDigits()

void TRTNoise::appendCrossTalkNoiseToProperDigits ( std::vector< TRTDigit > & digitVect,
const std::set< Identifier > & simhitsIdentifiers,
const ServiceHandle< ITRT_StrawNeighbourSvc > & m_TRTStrawNeighbourSvc,
CLHEP::HepRandomEngine * noiseRndmEngine )

Definition at line 357 of file TRTNoise.cxx.

360 {
361
362 //id helper:
363 const TRTHitIdHelper* hitid_helper = TRTHitIdHelper::GetHelper();
364
365 std::vector<Identifier> IdsFromChip;
366 std::vector<Identifier> CrossTalkIds;
367 std::vector<Identifier> CrossTalkIdsOtherEnd;
368 std::set<Identifier>::const_iterator simhitsIdentifiers_end = simhitsIdentifiers.end();
369 std::set<Identifier>::const_iterator simhitsIdentifiers_begin = simhitsIdentifiers.begin();
370 std::set<Identifier>::iterator simhitsIdentifiersIter;
371
372 for (simhitsIdentifiersIter=simhitsIdentifiers_begin; simhitsIdentifiersIter!=simhitsIdentifiers_end; ++simhitsIdentifiersIter) {
373
374 TRTStrawNeighbourSvc->getStrawsFromChip(*simhitsIdentifiersIter,IdsFromChip);
375 CrossTalkIds.assign(IdsFromChip.begin(),IdsFromChip.end());
376
377 //for barrel only - treated exactly equally as id's on the right end
378 if (!(abs(m_id_helper->barrel_ec(IdsFromChip[0]))==1)) { continue; }
379
380 Identifier otherEndID = m_id_helper->straw_id((-1)*m_id_helper->barrel_ec(*simhitsIdentifiersIter),
381 m_id_helper->phi_module(*simhitsIdentifiersIter),
382 m_id_helper->layer_or_wheel(*simhitsIdentifiersIter),
383 m_id_helper->straw_layer(*simhitsIdentifiersIter),
384 m_id_helper->straw(*simhitsIdentifiersIter));
385 if (otherEndID.get_compact()) { CrossTalkIdsOtherEnd.push_back(otherEndID); }
386
387 for (auto & CrossTalkId : CrossTalkIds) {
388
389 if ( simhitsIdentifiers.find(CrossTalkId) == simhitsIdentifiers_end ) {
390 if (m_pDigConditions->crossTalkNoise(noiseRndmEngine)==1 ) {
391 const int ndigit(m_digitPool[CLHEP::RandFlat::shootInt(noiseRndmEngine,
393 int barrel_endcap, isneg;
394 switch ( m_id_helper->barrel_ec(CrossTalkId) ) {
395 case -1: barrel_endcap = 0; isneg = 0; break;
396 case 1: barrel_endcap = 0; isneg = 1; break;
397 default:
398 ATH_MSG_WARNING("TRTDigitization::TRTNoise - identifier problems - skipping detector element!!");
399 continue;
400 }
401 const int ringwheel(m_id_helper->layer_or_wheel(CrossTalkId));
402 const int phisector(m_id_helper->phi_module(CrossTalkId));
403 const int layer (m_id_helper->straw_layer(CrossTalkId));
404 const int straw (m_id_helper->straw(CrossTalkId));
405
406 //built hit id
407 int hitid = hitid_helper->buildHitId( barrel_endcap, isneg, ringwheel, phisector,layer, straw);
408 //add to digit vector
409 digitVect.emplace_back(hitid,ndigit);
410 }
411 }
412 }
413
414 for (auto & i : CrossTalkIdsOtherEnd) {
415 if ( simhitsIdentifiers.find(i) == simhitsIdentifiers_end ) {
416 if (m_pDigConditions->crossTalkNoiseOtherEnd(noiseRndmEngine)==1 ) {
417
418 const int ndigit(m_digitPool[CLHEP::RandFlat::shootInt(noiseRndmEngine,m_digitPoolLength)]);
419
420 int barrel_endcap, isneg;
421 switch ( m_id_helper->barrel_ec(i) ) {
422 case -1: barrel_endcap = 0; isneg = 0; break;
423 case 1: barrel_endcap = 0; isneg = 1; break;
424 default:
425 ATH_MSG_WARNING("TRTDigitization::TRTNoise - identifier problems - skipping detector element!!");
426 continue;
427 }
428
429 const int ringwheel(m_id_helper->layer_or_wheel(i));
430 const int phisector(m_id_helper->phi_module(i));
431 const int layer (m_id_helper->straw_layer(i));
432 const int straw (m_id_helper->straw(i));
433
434 //built hit id
435 int hitid = hitid_helper->buildHitId( barrel_endcap, isneg, ringwheel, phisector,layer, straw);
436 //add to digit vector
437 digitVect.emplace_back(hitid,ndigit);
438 }
439 }
440 }
441
442 IdsFromChip.resize(0);
443 CrossTalkIdsOtherEnd.resize(0);
444 CrossTalkIds.resize(0);
445 }
446}
#define ATH_MSG_WARNING(x)
value_type get_compact() const
Get the compact id.
static const TRTHitIdHelper * GetHelper()
int buildHitId(const int, const int, const int, const int, const int, const int) const
std::vector< unsigned int > m_digitPool
Pool of noise digits for noise in unhit straws.
Definition TRTNoise.h:145
@ layer
Definition HitInfo.h:79
@ straw
Definition HitInfo.h:82

◆ appendPureNoiseToProperDigits()

void TRTNoise::appendPureNoiseToProperDigits ( std::vector< TRTDigit > & digitVect,
const std::set< int > & sim_hitids,
CLHEP::HepRandomEngine * noiseRndmEngine )

Append noise digits to list of digits from proper hits.


We are here dealing with unhit straws and noise digits are added from a pool of cached digits (m_digitPool).

Parameters
digitVectvector of digits this event. At input, contains digits from hits. At output, noise digits have been added.
sim_hitidslist of IDs of hit straws. This to make sure we do not add noise digit to already hit straw.

Definition at line 334 of file TRTNoise.cxx.

336{
337
338 const std::set<int>::const_iterator sim_hitids_end(sim_hitids.end());
339
340 m_pDigConditions->resetGetNextNoisyStraw();
341 int hitid;
342 float noiselevel;
343
344 while (m_pDigConditions->getNextNoisyStraw(noiseRndmEngine,hitid,noiselevel) ) {
345 //returned noiselevel not used for anything right now (fixme?).
346 // If this strawID does not have a sim_hit, add a pure noise digit
347 if ( sim_hitids.find(hitid) == sim_hitids_end ) {
348 const int ndigit(m_digitPool[CLHEP::RandFlat::shootInt(noiseRndmEngine,m_digitPoolLength)]);
349 digitVect.emplace_back(hitid,ndigit);
350 }
351 };
352
353 digitVect.pop_back(); }

◆ evolve_LT2AmpVsNL_to_include_LTfluct()

void TRTNoise::evolve_LT2AmpVsNL_to_include_LTfluct ( std::vector< float > & nl_given_lt2na,
float min_lt2na,
float max_lt2na,
float relativeLTFluct,
float & new_min_lt2na,
float & new_max_lt2na,
unsigned int number_new_bins )
staticprivate

Refined noise treatment by allowing for event-by-event fluctuations in the low threshold settings.

This is done by smearing of a LUT giving noise fractions as function of LT/NA values (see TK thesis).

What this method effectively does, is to smear the x-axis in a LUT with a Gaussian with a given relative width.

Parameters
nl_given_lt2naThe (inverted) LUT of noise level vs. LT/NA values (input and output)
min_lt2nalower LT/NA value (input)
max_lt2nahigher LT/NA value (input)
relativeLTfluctrelative event-by-event fluctuations in low threshold level (input)
new_min_lt2nalower LT/NA value after smearing (output)
new_max_lt2nahigher LT/NA value after smearing (output)
number_new_binsLUT is expanded to this number of bins (input)

Definition at line 540 of file TRTNoise.cxx.

547{
548 //RelativeLTfluct should be less than 0.2.
549
550 // unsigned int n = nl_given_lt2na.size();
551 std::vector<float> new_nl_given_lt2na(number_new_bins);
552 constexpr double reciprocalSqrt2Pi = M_2_SQRTPI * 0.5 * M_SQRT1_2;//cmath definitions
553 new_min_lt2na = min_lt2na;
554 new_max_lt2na = relativeLTFluct < 0.4 ? max_lt2na/(1.0-2.0*relativeLTFluct) : 5*max_lt2na;
555
556 for (unsigned int i = 0; i<number_new_bins;++i) {
557 const float new_lt2naval(new_min_lt2na + (new_max_lt2na-new_min_lt2na)*static_cast<float>(i)/(number_new_bins-1));
558 float sigma = new_lt2naval*relativeLTFluct;
559 if ( sigma <= 0 ) {
560 if (sigma<0) { sigma *= -1.0; }
561 else { sigma = 1.0e-8; }
562 }
563 const float lowerintrange(new_lt2naval - 5.0*sigma);
564 float upperintrange(new_lt2naval + 5.0*sigma);
565 if (upperintrange>max_lt2na) {
566 upperintrange = max_lt2na; //Since the NL is zero above anyway
567 }
568 const double du((upperintrange-lowerintrange)/100.0);
569 double sum(0.);
570 const double minusoneover2sigmasq(- 1.0 / (2.0*sigma*sigma));
571
572 for (double u(lowerintrange); u < upperintrange; u += du) {
573 sum += useLookupTable(u,nl_given_lt2na,min_lt2na,max_lt2na) *
574 exp(minusoneover2sigmasq * (u-new_lt2naval) * (u-new_lt2naval));
575 }
576 sum *= du*reciprocalSqrt2Pi /sigma;
577 new_nl_given_lt2na[i] = sum;
578 };
579
580 nl_given_lt2na.resize(number_new_bins);
581 copy(new_nl_given_lt2na.begin(),
582 new_nl_given_lt2na.end(),
583 nl_given_lt2na.begin());
584}
static float useLookupTable(float x, const std::vector< float > &y_given_x, float min_x, float max_x)
Return y value corresponding to input x value from LUT.
Definition TRTNoise.cxx:454
@ u
Enums for curvilinear frames.
Definition ParamDefs.h:77
bool copy
Definition calibdata.py:26

◆ getStrawIdentifier()

Identifier TRTNoise::getStrawIdentifier ( int hitID)
private

Definition at line 586 of file TRTNoise.cxx.

587{
588 Identifier IdStraw;
589 Identifier IdLayer;
590
591 const int mask(0x0000001F);
592 const int word_shift(5);
593 int trtID, ringID, moduleID, layerID, strawID;
594 int wheelID, planeID, sectorID;
595
596 const InDetDD::TRT_BarrelElement *barrelElement;
597 const InDetDD::TRT_EndcapElement *endcapElement;
598
599 if ( !(hitID & 0x00200000) ) { // barrel
600 strawID = hitID & mask;
601 hitID >>= word_shift;
602 layerID = hitID & mask;
603 hitID >>= word_shift;
604 moduleID = hitID & mask;
605 hitID >>= word_shift;
606 ringID = hitID & mask;
607 trtID = hitID >> word_shift;
608
609 barrelElement = m_detmgr->getBarrelElement(trtID, ringID, moduleID, layerID);
610 if ( barrelElement ) {
611 IdLayer = barrelElement->identify();
612 IdStraw = m_id_helper->straw_id(IdLayer, strawID);
613 } else {
614 ATH_MSG_ERROR("Could not find detector element for barrel identifier with "
615 << "(ipos,iring,imod,ilayer,istraw) = ("
616 << trtID << ", " << ringID << ", " << moduleID << ", "
617 << layerID << ", " << strawID << ")");
618 }
619 } else { // endcap
620 strawID = hitID & mask;
621 hitID >>= word_shift;
622 planeID = hitID & mask;
623 hitID >>= word_shift;
624 sectorID = hitID & mask;
625 hitID >>= word_shift;
626 wheelID = hitID & mask;
627 trtID = hitID >> word_shift;
628
629 // change trtID (which is 2/3 for endcaps) to use 0/1 in getEndcapElement
630 if (trtID == 3) { trtID = 0; }
631 else { trtID = 1; }
632
633 endcapElement = m_detmgr->getEndcapElement(trtID, wheelID, planeID, sectorID);
634
635 if ( endcapElement ) {
636 IdLayer = endcapElement->identify();
637 IdStraw = m_id_helper->straw_id(IdLayer, strawID);
638 } else {
639 ATH_MSG_ERROR("Could not find detector element for endcap identifier with "
640 << "(ipos,iwheel,isector,iplane,istraw) = ("
641 << trtID << ", " << wheelID << ", " << sectorID << ", "
642 << planeID << ", " << strawID << ")");
643 ATH_MSG_ERROR("If this happens very rarely, don't be alarmed "
644 "(it is a Geant4 'feature')");
645 ATH_MSG_ERROR("If it happens a lot, you probably have misconfigured geometry "
646 "in the sim. job.");
647 }
648
649 }
650
651 return IdStraw;
652}
#define ATH_MSG_ERROR(x)
virtual Identifier identify() const override final
identifier of this detector element:

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40{
42 // If user did not set an explicit level, set a default
43 if (m_lvl == MSG::NIL) {
44 m_lvl = m_imsg ?
45 static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
46 MSG::INFO;
47 }
48}
std::string m_nm
Message source name.
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
std::atomic< MSG::Level > m_lvl
Current logging level.
IMessageSvc * getMessageSvc(bool quiet=false)

◆ InitThresholdsAndNoiseAmplitudes_and_ProduceNoiseDigitPool()

void TRTNoise::InitThresholdsAndNoiseAmplitudes_and_ProduceNoiseDigitPool ( CLHEP::HepRandomEngine * noiseRndmEngine,
CLHEP::HepRandomEngine * elecNoiseRndmEngine,
CLHEP::HepRandomEngine * elecProcRndmEngine )
private

Initialize thresholds and noise amplitudes.


This is the main initialization method for the noise treatment.
Strategy:

  • First we create a lookup table so that we can, based on the noiselevel_i (i=straw_id), calculate for each straw: (LT/NA)_i (NA=Noise Amplitude).
  • We also know for each straw their relative noise amplitude, r_i.
  • C.f. Thomas Kittelmanns thesis, one finds that the lowthreshold and noise amplitude for each straw is given by the formulas:
    LT_i = (LT/NA)_i * r_i * k and NA_i = r_i * k, with k = < LT_i > / <(LT/NA)_i * r_i>

Steps:

  1. Create lookup table for mapping: noiselevel to LT/NA
  2. Find constant: k=< LT_i > / <(LT/NA)_i * r_i>
  3. Calculate and set actual values of LT_i and NA_i for each straw.
  4. Call method ProduceNoiseDigitPool to produce pool of pure noise digits

Loop through all non-dead straws (there are no dead straws since 2009!):

Definition at line 70 of file TRTNoise.cxx.

72 {
73
75 //Strategy: //
76 // //
77 //First we create a lookup table so that we can, based on the //
78 //noiselevel_i (i=straw_id), calculate for each straw: (LT/NA)_i //
79 //(NA=Noise Amplitude). //
80 // //
81 //We also know for each straw their relative noise amplitude, r_i. //
82 // //
83 //C.f. the noise note, one finds that the lowthreshold and noise //
84 //amplitude for each straw is given by the formulas: //
85 // //
86 // LT_i = (LT/NA)_i * r_i * k and NA_i = r_i * k //
87 // //
88 // with k = <LT_i>/<(LT/NA)_i * r_i> //
89 // //
90 // So now we first figure out the value of k, and afterwards we go //
91 // through the straws and set LT_i and NA_i. //
93
94
96 // Step 1 - create lookup table for mapping: noiselevel -> LT/NA //
98 // According to Anatoli, the noise shaping function is not very different for Argon and Xenon(and Krypton).
99 std::vector<float> maxLTOverNoiseAmp;
100 m_pElectronicsNoise->getSamplesOfMaxLTOverNoiseAmp(maxLTOverNoiseAmp,10000,elecNoiseRndmEngine);
101
102 std::stable_sort( maxLTOverNoiseAmp.begin(), maxLTOverNoiseAmp.end() );
103 reverse( maxLTOverNoiseAmp.begin(), maxLTOverNoiseAmp.end() );
104
105 // If we have LT event-event fluctuations, we need to include that effect in the curve
106
107 double relfluct = m_settings->relativeLowThresholdFluctuation();
108
109 if ( relfluct > 0. ) {
110 std::vector<float> nl_given_LT2Amp;
111 float min_lt2amp, max_lt2amp;
112 makeInvertedLookupTable( maxLTOverNoiseAmp, 0., 1.,
113 nl_given_LT2Amp, min_lt2amp, max_lt2amp);
114 float new_min_lt2amp, new_max_lt2amp;
116 min_lt2amp, max_lt2amp,
117 relfluct,
118 new_min_lt2amp, new_max_lt2amp,
119 static_cast<unsigned int>(0.1*nl_given_LT2Amp.size()));
120 float min_nl,max_nl; //Sanity check could be that ~0 and ~1 are returned.
121 makeInvertedLookupTable( nl_given_LT2Amp,new_min_lt2amp, new_max_lt2amp, maxLTOverNoiseAmp,min_nl,max_nl);
122 }
123
125 // Step 2 - figure out constant, k = <LT_i> / <(LT/NA)_i * r_i> //
127
128 //Figure out <(LT/NA)_i * r_i>:
129
130 unsigned long nstrawsBa_Xe(0), nstrawsEC_Xe(0);
131 unsigned long nstrawsBa_Kr(0), nstrawsEC_Kr(0);
132 unsigned long nstrawsBa_Ar(0), nstrawsEC_Ar(0);
133 double sumBa_Xe(0.), sumEC_Xe(0.);
134 double sumBa_Kr(0.), sumEC_Kr(0.);
135 double sumBa_Ar(0.), sumEC_Ar(0.);
136 int hitid(0);
137 float noiselevel(0.), noiseamp(0.);
138
139 m_pDigConditions->resetGetNextStraw();
140
142 while ( m_pDigConditions->getNextStraw(hitid, noiselevel, noiseamp) ) {
143
144 const bool isBarrel(!(hitid & 0x00200000));
145 const int statusHT = m_sumTool->getStatusHT(getStrawIdentifier(hitid), Gaudi::Hive::currentContext());
146 const int strawGasType = TRTDigiHelper::StrawGasType(statusHT,m_UseGasMix, &msg());
147 float lt = useLookupTable(noiselevel, maxLTOverNoiseAmp, 0., 1.) * noiseamp;
148
149 if (strawGasType==0) {
150 if ( isBarrel ) { ++nstrawsBa_Xe; sumBa_Xe += lt; }
151 else { ++nstrawsEC_Xe; sumEC_Xe += lt; }
152 }
153 else if (strawGasType==1) {
154 if ( isBarrel ) { ++nstrawsBa_Kr; sumBa_Kr += lt; }
155 else { ++nstrawsEC_Kr; sumEC_Kr += lt; }
156 }
157 else if (strawGasType==2) {
158 if ( isBarrel ) { ++nstrawsBa_Ar; sumBa_Ar += lt; }
159 else { ++nstrawsEC_Ar; sumEC_Ar += lt; }
160 }
161
162 }; // end "Loop through all non-dead straws"
163
164 //This gives us k right away:
165 double kBa_Xe(0.), kEC_Xe(0.);
166 double kBa_Kr(0.), kEC_Kr(0.);
167 double kBa_Ar(0.), kEC_Ar(0.);
168 if (sumBa_Xe !=0.) kBa_Xe = m_settings->lowThresholdBar(0) * (nstrawsBa_Xe/sumBa_Xe);
169 if (sumBa_Kr !=0.) kBa_Kr = m_settings->lowThresholdBar(1) * (nstrawsBa_Kr/sumBa_Kr);
170 if (sumBa_Ar !=0.) kBa_Ar = m_settings->lowThresholdBar(2) * (nstrawsBa_Ar/sumBa_Ar);
171 if (sumEC_Xe !=0.) kEC_Xe = m_settings->lowThresholdEC(0) * (nstrawsEC_Xe/sumEC_Xe);
172 if (sumEC_Kr !=0.) kEC_Kr = m_settings->lowThresholdEC(1) * (nstrawsEC_Kr/sumEC_Kr);
173 if (sumEC_Ar !=0.) kEC_Ar = m_settings->lowThresholdEC(2) * (nstrawsEC_Ar/sumEC_Ar);
174
176 // Step 3 - Calculate and set actual LT_i and NA_i //
178
179 std::vector<float> actual_LTs, actual_noiseamps;
180 std::vector<int> strawTypes;
181 if ( m_settings->noiseInUnhitStraws() ) {
182 int nstraws = m_pDigConditions->totalNumberOfActiveStraws();
183 actual_LTs.reserve(nstraws);
184 actual_noiseamps.reserve(nstraws);
185 };
186
187 float actualLT, actualNA;
188
189 m_pDigConditions->resetGetNextStraw();
190
191 double sumLT_Ar(0.), sumLTsq_Ar(0.), sumNA_Ar(0.), sumNAsq_Ar(0.);
192 double sumLT_Xe(0.), sumLTsq_Xe(0.), sumNA_Xe(0.), sumNAsq_Xe(0.);
193 double sumLT_Kr(0.), sumLTsq_Kr(0.), sumNA_Kr(0.), sumNAsq_Kr(0.);
194
195 while ( m_pDigConditions->getNextStraw( hitid, noiselevel, noiseamp) ) {
196
197 const int statusHT = m_sumTool->getStatusHT(getStrawIdentifier(hitid), Gaudi::Hive::currentContext());
198 const int strawGasType = TRTDigiHelper::StrawGasType(statusHT,m_UseGasMix, &msg());
199
200 const bool isBarrel(!(hitid & 0x00200000));
201 if (strawGasType==0) { actualNA = noiseamp*( isBarrel ? kBa_Xe : kEC_Xe ); }
202 else if (strawGasType==1) { actualNA = noiseamp*( isBarrel ? kBa_Kr : kEC_Kr ); }
203 else if (strawGasType==2) { actualNA = noiseamp*( isBarrel ? kBa_Ar : kEC_Ar ); }
204 else { actualNA = 0.0; } // should never happen
205
206 actualLT = useLookupTable(noiselevel, maxLTOverNoiseAmp, 0., 1.)*actualNA;
207
208 if (strawGasType==0) {
209 sumNA_Xe += actualNA; sumNAsq_Xe += actualNA*actualNA;
210 sumLT_Xe += actualLT; sumLTsq_Xe += actualLT*actualLT;
211 }
212 else if (strawGasType==1) {
213 sumNA_Kr += actualNA; sumNAsq_Kr += actualNA*actualNA;
214 sumLT_Kr += actualLT; sumLTsq_Kr += actualLT*actualLT;
215 }
216 else if (strawGasType==2) {
217 sumNA_Ar += actualNA; sumNAsq_Ar += actualNA*actualNA;
218 sumLT_Ar += actualLT; sumLTsq_Ar += actualLT*actualLT;
219 }
220
221 m_pDigConditions->setRefinedStrawParameters( hitid, actualLT, actualNA );
222
223 if ( m_settings->noiseInUnhitStraws() ) {
224 actual_LTs.push_back(actualLT);
225 actual_noiseamps.push_back(actualNA);
226 strawTypes.push_back(strawGasType);
227 }
228
229 };
230
231
232 if (msgLvl(MSG::INFO)) {
233
234 unsigned long nstraws_Kr = nstrawsBa_Kr + nstrawsEC_Kr;
235 unsigned long nstraws_Xe = nstrawsBa_Xe + nstrawsEC_Xe;
236 unsigned long nstraws_Ar = nstrawsBa_Ar + nstrawsEC_Ar;
237
238 if (nstraws_Xe) {
239 ATH_MSG_INFO("Xe Average LT is " << sumLT_Xe/nstraws_Xe/CLHEP::eV << " eV, with an RMS of "
240 << sqrt((sumLTsq_Xe/nstraws_Xe)-(sumLT_Xe/nstraws_Xe)*(sumLT_Xe/nstraws_Xe))/CLHEP::eV << " eV");
241 ATH_MSG_INFO("Xe Average NA is " << sumNA_Xe/nstraws_Xe/CLHEP::eV << " eV, with an RMS of "
242 << sqrt((sumNAsq_Xe/nstraws_Xe)-(sumNA_Xe/nstraws_Xe)*(sumNA_Xe/nstraws_Xe))/CLHEP::eV << " eV");
243 }
244 if (nstraws_Kr) {
245 ATH_MSG_INFO("Kr Average LT is " << sumLT_Kr/nstraws_Kr/CLHEP::eV << " eV, with an RMS of "
246 << sqrt((sumLTsq_Kr/nstraws_Kr)-(sumLT_Kr/nstraws_Kr)*(sumLT_Kr/nstraws_Kr))/CLHEP::eV << " eV");
247 ATH_MSG_INFO("Kr Average NA is " << sumNA_Kr/nstraws_Kr/CLHEP::eV << " eV, with an RMS of "
248 << sqrt((sumNAsq_Kr/nstraws_Kr)-(sumNA_Kr/nstraws_Kr)*(sumNA_Kr/nstraws_Kr))/CLHEP::eV << " eV");
249 }
250 if (nstraws_Ar) {
251 ATH_MSG_INFO("Ar Average LT is " << sumLT_Ar/nstraws_Ar/CLHEP::eV << " eV, with an RMS of "
252 << sqrt((sumLTsq_Ar/nstraws_Ar)-(sumLT_Ar/nstraws_Ar)*(sumLT_Ar/nstraws_Ar))/CLHEP::eV << " eV");
253 ATH_MSG_INFO("Ar Average NA is " << sumNA_Ar/nstraws_Ar/CLHEP::eV << " eV, with an RMS of "
254 << sqrt((sumNAsq_Ar/nstraws_Ar)-(sumNA_Ar/nstraws_Ar)*(sumNA_Ar/nstraws_Ar))/CLHEP::eV << " eV");
255 }
256
257 }
258
260 // Step 4 - Produce pool of pure noise digits //
262 if ( m_settings->noiseInUnhitStraws() ) {
263 ProduceNoiseDigitPool( actual_LTs, actual_noiseamps, strawTypes, noiseRndmEngine, elecNoiseRndmEngine, elecProcRndmEngine );
264 }
265
266 }
#define ATH_MSG_INFO(x)
MsgStream & msg() const
The standard message stream.
bool msgLvl(const MSG::Level lvl) const
Test the output level.
void ProduceNoiseDigitPool(const std::vector< float > &lowthresholds, const std::vector< float > &noiseamps, const std::vector< int > &strawType, CLHEP::HepRandomEngine *noiseRndmEngine, CLHEP::HepRandomEngine *elecNoiseRndmEngine, CLHEP::HepRandomEngine *elecProcRndmEngine)
Produce pool of pure noise digits (for simulation of noise in unhit straws) and store them in m_digit...
Definition TRTNoise.cxx:269
static void evolve_LT2AmpVsNL_to_include_LTfluct(std::vector< float > &nl_given_lt2na, float min_lt2na, float max_lt2na, float relativeLTFluct, float &new_min_lt2na, float &new_max_lt2na, unsigned int number_new_bins)
Refined noise treatment by allowing for event-by-event fluctuations in the low threshold settings.
Definition TRTNoise.cxx:540
static void makeInvertedLookupTable(const std::vector< float > &y_given_x, float min_x, float max_x, std::vector< float > &x_given_y, float &min_y, float &max_y)
Invert look-up-table: Go from tabulated y values vs.
Definition TRTNoise.cxx:486
Identifier getStrawIdentifier(int hitID)
Definition TRTNoise.cxx:586
int StrawGasType(int statusHT, int useGasMix, MsgStream *log)
void stable_sort(DataModel_detail::iterator< DVL > beg, DataModel_detail::iterator< DVL > end)
Specialization of stable_sort for DataVector/List.

◆ makeInvertedLookupTable()

void TRTNoise::makeInvertedLookupTable ( const std::vector< float > & y_given_x,
float min_x,
float max_x,
std::vector< float > & x_given_y,
float & min_y,
float & max_y )
staticprivate

Invert look-up-table: Go from tabulated y values vs.

equidistantly spaced x values to tabulated x values vs. equidistantly spaced y values.

Parameters
y_given_xy given x (input)
min_xlower x value (input)
max_xhigher x value (input)
x_given_yx given y (output)
min_ylower y value (output)
max_yhigher y value (output)

Definition at line 486 of file TRTNoise.cxx.

491 {
492
493 //Only works well when y_given_x.size() is large.
494 //
495 //Also assumes that y_given_x is homogeneous.
496
497 //Figure out if rising or falling, and y limits:
498 bool rising;
499
500 if ( y_given_x.front() < y_given_x.back() ) {
501 //NB: All use-cases have so far been on rising=false lookuptables
502 rising = true;
503 min_y = y_given_x.front();
504 max_y = y_given_x.back();
505 } else {
506 rising = false;
507 min_y = y_given_x.back();
508 max_y = y_given_x.front();
509 };
510
511 const unsigned int n(y_given_x.size());
512 if ( x_given_y.size() != n ) {
513 x_given_y.resize(n);
514 }
515
516 //Fill new array:
517 const float step_y((max_y-min_y)/(n-1));
518 const float step_x((max_x-min_x)/(n-1));
519
520 unsigned int searchindex = rising ? 0 : n-1;
521 float yval;
522 x_given_y.front() = rising ? min_x : max_x;
523 for (unsigned int i = 1; i < n-1; ++i) {
524 yval = min_y + i*step_y;
525 if (rising) {
526 // increase index in old array until we come to the index
527 // with a appropriate yval
528 while ( y_given_x[searchindex] < yval ) { ++searchindex; };
529 x_given_y[i] = min_x + searchindex*step_x;
530 } else {
531 while ( y_given_x[searchindex]<yval ) { --searchindex; };
532 x_given_y[i] = min_x + searchindex*step_x;
533 }
534 };
535 x_given_y.back() = rising ? max_x : min_x;
536
537}

◆ msg() [1/2]

MsgStream & AthMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 167 of file AthMessaging.h.

168{
169 MsgStream* ms = m_msg_tls.get();
170 if (!ms) {
171 if (!m_initialized.test_and_set()) initMessaging();
172 ms = new MsgStream(m_imsg,m_nm);
173 m_msg_tls.reset( ms );
174 }
175
176 ms->setLevel (m_lvl);
177 return *ms;
178}
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels).
void initMessaging() const
Initialize our message level and MessageSvc.

◆ msg() [2/2]

MsgStream & AthMessaging::msg ( const MSG::Level lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 182 of file AthMessaging.h.

183{ return msg() << lvl; }

◆ msgLvl()

bool AthMessaging::msgLvl ( const MSG::Level lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicating if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 151 of file AthMessaging.h.

152{
153 // If user did not set explicit message level we have to initialize
154 // the messaging and retrieve the default via the MessageSvc.
155 if (m_lvl==MSG::NIL && !m_initialized.test_and_set()) initMessaging();
156
157 if (m_lvl <= lvl) {
158 msg() << lvl;
159 return true;
160 } else {
161 return false;
162 }
163}

◆ ProduceNoiseDigitPool()

void TRTNoise::ProduceNoiseDigitPool ( const std::vector< float > & lowthresholds,
const std::vector< float > & noiseamps,
const std::vector< int > & strawType,
CLHEP::HepRandomEngine * noiseRndmEngine,
CLHEP::HepRandomEngine * elecNoiseRndmEngine,
CLHEP::HepRandomEngine * elecProcRndmEngine )
private

Produce pool of pure noise digits (for simulation of noise in unhit straws) and store them in m_digitPool.


The procedure uses TRTElectronicsProcessing::ProcessDeposits(), but with no input deposits. This way, we get the noise contribution only. The noise signals are thus originating from the cached vectors TRTElectronicsNoise::m_cachedFastNoiseAfterSignalShaping[] and TRTElectronicsNoise::m_cachedSlowNoiseAfterSignalShaping[]

Parameters
lowthresholdslow threshold settings, all straws
noiseampnoise amplitudes, all straws

Definition at line 269 of file TRTNoise.cxx.

274 {
275
276 unsigned int nstraw = lowthresholds.size();
277 unsigned int istraw;
278
280
281 std::vector<TRTElectronicsProcessing::Deposit> deposits;
282 int dummyhitid(0);
283 TRTDigit digit;
284 unsigned int nokdigits(0);
285 unsigned int ntries(0);
286
287 while ( nokdigits < m_digitPoolLength ) {
288
289 // Once and a while, create new vectors of shaped electronics noise.
290 // These are used as inputs to TRTElectronicsProcessing::ProcessDeposits
291 // to create noise digits
292 if ( ntries%400==0 ) {
293 m_pElectronicsNoise->reinitElectronicsNoise(200, elecNoiseRndmEngine);
294 }
295 // Initialize stuff (is that necessary)?
296 digit = TRTDigit();
297 deposits.clear();
298
299 // Choose straw to simulate
300 istraw = CLHEP::RandFlat::shootInt(noiseRndmEngine, nstraw );
301
302 // Process deposits this straw. Since there are no deposits, only noise will contrinute
303 m_pElectronicsProcessing->ProcessDeposits( deposits,
304 dummyhitid,
305 digit,
306 lowthresholds.at(istraw),
307 noiseamps.at(istraw),
308 strawType.at(istraw),
309 elecProcRndmEngine,
310 elecNoiseRndmEngine
311 );
312
313 // If this process produced a digit, store in pool
314 if ( digit.GetDigit() ) {
315 m_digitPool[nokdigits++] = digit.GetDigit();
316 }
317 ntries++;
318 };
319
320 if (msgLvl(MSG::VERBOSE)) {
321 if(0==ntries) {
322 ATH_MSG_FATAL("ntries==0 this should not be possible!");
323 throw std::exception();
324 }
325 ATH_MSG_VERBOSE("Produced noise digit pool of size " << m_digitPool.size()
326 << " (efficiency was " << static_cast<double>(m_digitPool.size())/ntries << ")");
327 }
328
330
331}
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29{
30 m_lvl = lvl;
31}

◆ simulateNoiseFrequency()

double TRTNoise::simulateNoiseFrequency ( unsigned int totalNumberOfTests,
double electronicsNoiseAmplitude,
double lowthreshold = -1.0 )
private

◆ sortDigits()

void TRTNoise::sortDigits ( std::vector< TRTDigit > & digitVect)
static

Definition at line 448 of file TRTNoise.cxx.

449{
450 std::stable_sort(digitVect.begin(), digitVect.end(), TRTDigitSorterObject);
451}
struct TRTDigitSorter TRTDigitSorterObject

◆ useLookupTable()

float TRTNoise::useLookupTable ( float x,
const std::vector< float > & y_given_x,
float min_x,
float max_x )
staticprivate

Return y value corresponding to input x value from LUT.

Returns
y: Output y value
Parameters
xInput x value
y_given_xLook-up-table: gives y values for uniformly distributed x values
min_xlowest tabulated x value
max_xhighest tabulated x value

Definition at line 454 of file TRTNoise.cxx.

457 {
458
459 double bin_withfrac;
460 unsigned int lower_index;
461 double fraction_into_bin;
462
463 // Assumes that y_given_x is homogeneous (and not entirely flat)
464
465 // Low x-value, return first y-value
466 if ( x < min_x ) {
467 return y_given_x.front();
468 }
469
470 // Which bin?
471 bin_withfrac = (x-min_x)*(y_given_x.size()-1)/(max_x-min_x);
472 lower_index = static_cast<unsigned int>(bin_withfrac);
473
474 // High x-value, return last y-value
475 if ( lower_index >= y_given_x.size()-1 ) {
476 return y_given_x.back();
477 }
478
479 // Normal case: return weighted sum of two neighbouring bin values
480 fraction_into_bin = bin_withfrac - lower_index;
481 return (1.-fraction_into_bin) * y_given_x[lower_index] + fraction_into_bin * y_given_x[lower_index+1];
482
483}
#define x

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging).

Definition at line 141 of file AthMessaging.h.

◆ m_detmgr

const InDetDD::TRT_DetectorManager* TRTNoise::m_detmgr {}
private

Definition at line 86 of file TRTNoise.h.

86{};

◆ m_digitPool

std::vector<unsigned int> TRTNoise::m_digitPool
private

Pool of noise digits for noise in unhit straws.

Definition at line 145 of file TRTNoise.h.

◆ m_digitPoolLength

unsigned int TRTNoise::m_digitPoolLength
private

Length of noise digit pool m_digitPool.

Definition at line 141 of file TRTNoise.h.

◆ m_digitPoolLength_nextaccessindex

unsigned int TRTNoise::m_digitPoolLength_nextaccessindex
private

Pointer into noise digit pool m_digitPool.

Definition at line 143 of file TRTNoise.h.

◆ m_id_helper

const TRT_ID* TRTNoise::m_id_helper
private

Definition at line 139 of file TRTNoise.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

138{ MSG::NIL };

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels).

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_noise_randengine

CLHEP::HepRandomEngine* TRTNoise::m_noise_randengine {}
private

Definition at line 91 of file TRTNoise.h.

91{};

◆ m_pDigConditions

TRTDigCondBase* TRTNoise::m_pDigConditions {}
private

Definition at line 88 of file TRTNoise.h.

88{};

◆ m_pElectronicsNoise

TRTElectronicsNoise* TRTNoise::m_pElectronicsNoise {}
private

Definition at line 90 of file TRTNoise.h.

90{};

◆ m_pElectronicsProcessing

TRTElectronicsProcessing* TRTNoise::m_pElectronicsProcessing {}
private

Definition at line 89 of file TRTNoise.h.

89{};

◆ m_settings

const TRTDigSettings* TRTNoise::m_settings {}
private

Definition at line 85 of file TRTNoise.h.

85{};

◆ m_sumTool

ToolHandle<ITRT_StrawStatusSummaryTool> TRTNoise::m_sumTool
private

Definition at line 210 of file TRTNoise.h.

◆ m_UseGasMix

int TRTNoise::m_UseGasMix {}
private

Definition at line 209 of file TRTNoise.h.

209{};

The documentation for this class was generated from the following files: