ATLAS Offline Software
RD53SimTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 #include "RD53SimTool.h"
7 
9 #include "PixelConditionsData/ChargeCalibParameters.h" //for Thresholds
12 
16 #include "CLHEP/Random/RandFlat.h"
17 #include "CLHEP/Random/RandGaussZiggurat.h"
18 #include "PixelNoiseFunctions.h"
19 #include <cmath>
20 
21 using namespace PixelDigitization;
22 
23 RD53SimTool::RD53SimTool(const std::string& type, const std::string& name, const IInterface* parent) :
25 }
26 
27 RD53SimTool::~RD53SimTool() = default;
28 
31  ATH_MSG_DEBUG("RD53SimTool::initialize()");
33  return StatusCode::SUCCESS;
34 }
35 
37  ATH_MSG_DEBUG("RD53SimTool::finalize()");
38  return StatusCode::SUCCESS;
39 }
40 
42  CLHEP::HepRandomEngine* rndmEngine) {
43  const InDetDD::PixelModuleDesign* p_design =
44  static_cast<const InDetDD::PixelModuleDesign*>(&(chargedDiodes.element())->design());
45 
47  return;
48  }
49 
50  const PixelID* pixelId = static_cast<const PixelID*>(chargedDiodes.element()->getIdHelper());
51  const IdentifierHash moduleHash = pixelId->wafer_hash(chargedDiodes.identify()); // wafer hash
52  Identifier moduleID = pixelId->wafer_id(chargedDiodes.element()->identify());
53 
54  int barrel_ec = pixelId->barrel_ec(chargedDiodes.element()->identify());
55  int layerIndex = pixelId->layer_disk(chargedDiodes.element()->identify());
56 
57  if (std::abs(barrel_ec) != m_BarrelEC) {
58  return;
59  }
60 
61  const EventContext& ctx{Gaudi::Hive::currentContext()};
63  const PixelModuleData *moduleData = *moduleDataHandle;
65  const PixelChargeCalibCondData *calibData = *calibDataHandle;
66 
67  int overflowToT = calibData->getFEI4OverflowToT();
68 
69  std::vector<Pixel1RawData*> p_rdo_small_fei4;
70  std::vector<int> row, col;
71 
72 
73  // Add cross-talk
74  crossTalk(moduleData->getCrossTalk(barrel_ec, layerIndex), chargedDiodes);
75 
76  if (m_doNoise) {
77  // Add thermal noise
78  thermalNoise(m_thermalNoise, chargedDiodes, rndmEngine);
79 
80  // Add random noise
81  randomNoise(chargedDiodes, moduleData, m_numberOfBcid, calibData, rndmEngine, m_pixelReadout.get());
82  }
83 
84  // Add random diabled pixels
85  randomDisable(chargedDiodes, moduleData, rndmEngine); // FIXME How should we handle disabling pixels in Overlay jobs?
86 
87  for (auto &[mapId,mapDiode]:chargedDiodes) {//cannot be const ref, mapDiode will be altered
88  Identifier diodeID = chargedDiodes.getId(mapId);
89  double charge = mapDiode.charge();
90  unsigned int FE = m_pixelReadout->getFE(diodeID, moduleID);
91  InDetDD::PixelDiodeType type = m_pixelReadout->getDiodeType(diodeID);
93  SiHelper::disabled(mapDiode, true, true);
94  continue;//invalid frontend
95  }
96  // Apply analogue threshold, timing simulation
97  const auto &thresholds = calibData->getThresholds(type, moduleHash, FE);
98  double threshold = PixelDigitization::randomThreshold(thresholds, rndmEngine);
99  // This noise check is unaffected by digitizationFlags.doInDetNoise in 21.0 - see PixelCellDiscriminator.cxx in that branch
100 
101  if (charge > threshold) {
102  int bunchSim = 0;
103  if (mapDiode.totalCharge().fromTrack()) {
104  bunchSim = static_cast<int>(std::floor((getG4Time(mapDiode.totalCharge()) + m_timeOffset) / m_bunchSpace));
105  //Timewalk implementation
106  if(m_doTimeWalk){
107  if(charge < (threshold + m_overDrive)){
108  const int timeWalk = 25; // Here it is assumed that the maximum value of timewalk is one bunch crossing (25ns)
109  bunchSim = static_cast<int>(std::floor((getG4Time(mapDiode.totalCharge()) + m_timeOffset + timeWalk) / m_bunchSpace));
110  }
111  }
112  } else {
113  bunchSim = CLHEP::RandFlat::shootInt(rndmEngine, m_numberOfBcid);
114  }
115 
116  if (bunchSim < 0 || bunchSim > m_numberOfBcid) {
117  SiHelper::belowThreshold(mapDiode, true, true);
118  } else {
119  SiHelper::SetBunch(mapDiode, bunchSim);
120  }
121  } else {
122  SiHelper::belowThreshold(mapDiode, true, true);
123  }
124 
125  // charge to ToT conversion
126  double tot = calibData->getToT(type, moduleHash, FE, charge);
127  double totsig = calibData->getTotRes(moduleHash, FE, tot);
128  int nToT = static_cast<int>(CLHEP::RandGaussZiggurat::shoot(rndmEngine, tot, totsig));
129  if (nToT < 1) {
130  nToT = 1;
131  }
132  // RD53 HitDiscConfig
133  if (nToT >= overflowToT) {
134  nToT = overflowToT;
135  }
136 
137  if (nToT <= moduleData->getToTThreshold(barrel_ec, layerIndex)) {
138  SiHelper::belowThreshold(mapDiode, true, true);
139  }
140 
141  // Filter events
142  if (SiHelper::isMaskOut(mapDiode)) {
143  continue;
144  }
145  if (SiHelper::isDisabled(mapDiode)) {
146  continue;
147  }
148 
149  if (!m_pixelConditionsTool->isActive(moduleHash, diodeID, ctx)) {
150  SiHelper::disabled(mapDiode, true, true);
151  continue;
152  }
153 
154  int flag = mapDiode.flag();
155  int bunch = (flag >> 8) & 0xff;
156 
157  InDetDD::SiReadoutCellId cellId = mapDiode.getReadoutCell();
158  const Identifier id_readout = chargedDiodes.element()->identifierFromCellId(cellId);
159 
160  // Front-End simulation
161  if (bunch >= 0 && bunch < m_numberOfBcid) {
162  Pixel1RawData* p_rdo = new Pixel1RawData(id_readout, nToT, bunch, 0, bunch);
163  rdoCollection.push_back(p_rdo);
164  p_rdo = nullptr;
165  }
166  }
167 }
query_example.row
row
Definition: query_example.py:24
PixelChargeCalibCondData::getToT
float getToT(InDetDD::PixelDiodeType type, unsigned int moduleHash, unsigned int FE, float Q) const
Definition: PixelChargeCalibCondData.cxx:174
SiHelper.h
PixelNoiseFunctions.h
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
SiChargedDiodeCollection::element
const InDetDD::SolidStateDetectorElementBase * element() const
Definition: SiChargedDiodeCollection.h:218
InDetDD::PixelModuleDesign
Definition: PixelModuleDesign.h:48
SiHelper::isDisabled
static bool isDisabled(SiChargedDiode &chDiode)
Definition: SiHelper.h:179
PixelID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: PixelID.h:619
PixelModuleData::getCrossTalk
double getCrossTalk(int barrel_ec, int layer) const
Definition: PixelModuleData.cxx:129
PixelChargeCalibCondData::getThresholds
PixelChargeCalib::Thresholds getThresholds(InDetDD::PixelDiodeType type, unsigned int moduleHash, unsigned int FE) const
Definition: PixelChargeCalibCondData.cxx:99
PixelModuleData
Definition: PixelModuleData.h:22
FrontEndSimTool::m_thermalNoise
double m_thermalNoise
Definition: FrontEndSimTool.h:54
InDetDD::invalidFrontEnd
constexpr uint32_t invalidFrontEnd
Definition: PixelReadoutDefinitions.h:44
InDetDD::PixelDiodeType
PixelDiodeType
Definition: PixelReadoutDefinitions.h:25
ChargeCalibParameters.h
Structs for holding charge calibration parameterisation and data.
RD53SimTool.h
PixelChargeCalibCondData::getTotRes
float getTotRes(unsigned int moduleHash, unsigned int FE, float Q) const
Definition: PixelChargeCalibCondData.cxx:163
PixelDigitization
Definition: PixelDigitizationUtilities.cxx:16
SiHelper::disabled
static void disabled(SiChargedDiode &chDiode, bool flag, bool mask=false)
Definition: SiHelper.h:93
PixelID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
For a single crystal.
Definition: PixelID.h:364
InDetDD::SolidStateDetectorElementBase::getIdHelper
const AtlasDetectorID * getIdHelper() const
Returns the id helper (inline)
PixelDigitization::getG4Time
double getG4Time(const SiTotalCharge &totalCharge)
Definition: PixelNoiseFunctions.cxx:169
PixelDigitization::randomThreshold
double randomThreshold(const PixelChargeCalib::Thresholds &t, CLHEP::HepRandomEngine *pEngine)
Definition: PixelDigitizationUtilities.cxx:105
InDetDD::PixelReadoutTechnology::RD53
@ RD53
FrontEndSimTool::initialize
virtual StatusCode initialize() override
Definition: FrontEndSimTool.cxx:13
FrontEndSimTool::m_doNoise
Gaudi::Property< bool > m_doNoise
Definition: FrontEndSimTool.h:72
SiReadoutCellId.h
RD53SimTool::m_doTimeWalk
Gaudi::Property< bool > m_doTimeWalk
Definition: RD53SimTool.h:41
PixelID::wafer_hash
IdentifierHash wafer_hash(Identifier wafer_id) const
wafer hash from id
Definition: PixelID.h:387
RD53SimTool::m_moduleDataKey
SG::ReadCondHandleKey< PixelModuleData > m_moduleDataKey
Definition: RD53SimTool.h:36
FrontEndSimTool::m_bunchSpace
static constexpr double m_bunchSpace
Definition: FrontEndSimTool.h:50
SiChargedDiodeCollection
Definition: SiChargedDiodeCollection.h:109
PixelRDO_Collection.h
FrontEndSimTool
Definition: FrontEndSimTool.h:31
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
PixelChargeCalibCondData
Definition: PixelChargeCalibCondData.h:24
RD53SimTool::RD53SimTool
RD53SimTool()
SiHelper::belowThreshold
static void belowThreshold(SiChargedDiode &chDiode, bool flag, bool mask=false)
Definition: SiHelper.h:84
FrontEndSimTool::m_numberOfBcid
int m_numberOfBcid
Definition: FrontEndSimTool.h:51
master.flag
bool flag
Definition: master.py:29
Pixel1RawData.h
InDetRawDataCollection
Definition: InDetRawDataCollection.h:31
test_pyathena.parent
parent
Definition: test_pyathena.py:15
FrontEndSimTool::m_pixelReadout
ServiceHandle< InDetDD::IPixelReadoutManager > m_pixelReadout
Definition: FrontEndSimTool.h:59
RD53SimTool::initialize
virtual StatusCode initialize()
Definition: RD53SimTool.cxx:29
Pixel1RawData
Definition: Pixel1RawData.h:23
SiHelper::SetBunch
static void SetBunch(SiChargedDiode &chDiode, int bunch, MsgStream *log=nullptr)
Definition: SiHelper.h:129
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
RD53SimTool::m_overDrive
Gaudi::Property< int > m_overDrive
Definition: RD53SimTool.h:44
FrontEndSimTool::m_BarrelEC
Gaudi::Property< int > m_BarrelEC
Definition: FrontEndSimTool.h:68
RD53SimTool::process
virtual void process(SiChargedDiodeCollection &chargedDiodes, PixelRDO_Collection &rdoCollection, CLHEP::HepRandomEngine *rndmEngine)
Definition: RD53SimTool.cxx:41
LB_AnalMapSplitter.tot
tot
Definition: LB_AnalMapSplitter.py:46
PixelID::layer_disk
int layer_disk(const Identifier &id) const
Definition: PixelID.h:626
SiHelper::isMaskOut
static bool isMaskOut(SiChargedDiode &chDiode)
Definition: SiHelper.h:171
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
threshold
Definition: chainparser.cxx:74
charge
double charge(const T &p)
Definition: AtlasPID.h:538
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
InDetDD::PixelModuleDesign::getReadoutTechnology
PixelReadoutTechnology getReadoutTechnology() const
Definition: PixelModuleDesign.h:368
query_example.col
col
Definition: query_example.py:7
PixelDigitization::crossTalk
void crossTalk(double crossTalk, SiChargedDiodeCollection &chargedDiodes)
Definition: PixelNoiseFunctions.cxx:25
RD53SimTool::~RD53SimTool
virtual ~RD53SimTool()
PixelModuleDesign.h
InDetDD::PixelDiodeType::NONE
@ NONE
FrontEndSimTool::m_timeOffset
double m_timeOffset
Definition: FrontEndSimTool.h:52
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
PixelChargeCalibCondData::getFEI4OverflowToT
constexpr int getFEI4OverflowToT() const
Definition: PixelChargeCalibCondData.h:106
RD53SimTool::finalize
virtual StatusCode finalize()
Definition: RD53SimTool.cxx:36
PixelDigitizationUtilities.h
FrontEndSimTool::m_chargeDataKey
SG::ReadCondHandleKey< PixelChargeCalibCondData > m_chargeDataKey
Definition: FrontEndSimTool.h:64
InDetDD::SiReadoutCellId
Definition: SiReadoutCellId.h:42
PixelDigitization::randomNoise
void randomNoise(SiChargedDiodeCollection &chargedDiodes, const PixelModuleData *moduleData, int nBcid, const PixelChargeCalibCondData *chargeCalibData, CLHEP::HepRandomEngine *rndmEngine, InDetDD::IPixelReadoutManager *pixelReadout)
Definition: PixelNoiseFunctions.cxx:73
PixelID
Definition: PixelID.h:67
FrontEndSimTool::m_pixelConditionsTool
ToolHandle< IInDetConditionsTool > m_pixelConditionsTool
Definition: FrontEndSimTool.h:55
PixelDigitization::randomDisable
void randomDisable(SiChargedDiodeCollection &chargedDiodes, const PixelModuleData *moduleData, CLHEP::HepRandomEngine *rndmEngine)
Definition: PixelNoiseFunctions.cxx:147
InDetDD::SolidStateDetectorElementBase::identify
virtual Identifier identify() const override final
identifier of this detector element (inline)
PixelDigitization::thermalNoise
void thermalNoise(double thermalNoise, SiChargedDiodeCollection &chargedDiodes, CLHEP::HepRandomEngine *rndmEngine)
Definition: PixelNoiseFunctions.cxx:61
SiChargedDiodeCollection.h
SiChargedDiodeCollection::identify
virtual Identifier identify() const override final
Definition: SiChargedDiodeCollection.h:230
Identifier
Definition: IdentifierFieldParser.cxx:14