ATLAS Offline Software
RD53SimTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 #include "RD53SimTool.h"
7 #include "PixelNoiseFunctions.h"
9 #include "PixelConditionsData/ChargeCalibParameters.h" //for Thresholds
12 
16 #include "CLHEP/Random/RandFlat.h"
17 #include "PixelNoiseFunctions.h"
18 #include <cmath>
19 
20 using namespace PixelDigitization;
21 
22 RD53SimTool::RD53SimTool(const std::string& type, const std::string& name, const IInterface* parent) :
24 }
25 
26 RD53SimTool::~RD53SimTool() = default;
27 
30  ATH_MSG_DEBUG("RD53SimTool::initialize()");
31  return StatusCode::SUCCESS;
32 }
33 
35  ATH_MSG_DEBUG("RD53SimTool::finalize()");
36  return StatusCode::SUCCESS;
37 }
38 
40  CLHEP::HepRandomEngine* rndmEngine) const {
41  const PixelID* pixelId = static_cast<const PixelID*>(chargedDiodes.element()->getIdHelper());
42  const IdentifierHash moduleHash = pixelId->wafer_hash(chargedDiodes.identify()); // wafer hash
43  Identifier moduleID = pixelId->wafer_id(chargedDiodes.element()->identify());
44 
45  int barrel_ec = pixelId->barrel_ec(chargedDiodes.element()->identify());
46  if (std::abs(barrel_ec) != m_BarrelEC) {
47  return;
48  }
49 
50  const EventContext& ctx{Gaudi::Hive::currentContext()};
52  const PixelChargeCalibCondData *calibData = *calibDataHandle;
53 
54  int overflowToT = 14; //for RD53 (aka ITkPixV2) chip, not FEI4
55 
56  // Add cross-talk
57  auto xtalk = m_chipSim.crossTalk();
58  crossTalk(xtalk, chargedDiodes);
59 
60  if (m_doNoise) {
61  // Add thermal noise
62  thermalNoise(m_thermalNoise, chargedDiodes, rndmEngine);
63  // Add random noise
64  randomNoise(chargedDiodes, m_chipSim, m_numberOfBcid, calibData, rndmEngine, m_pixelReadout.get());
65  }
66 
67  // Add random diabled pixels
68  randomDisable(chargedDiodes, m_chipSim, rndmEngine); // FIXME How should we handle disabling pixels in Overlay jobs?
69 
70  for (auto &[mapId,mapDiode]:chargedDiodes) {//cannot be const ref, mapDiode will be altered
71  Identifier diodeID = chargedDiodes.getId(mapId);
72  double charge = mapDiode.charge();
73  unsigned int FE = m_pixelReadout->getFE(diodeID, moduleID);
74  InDetDD::PixelDiodeType type = m_pixelReadout->getDiodeType(diodeID);
76  SiHelper::disabled(mapDiode, true, true);
77  continue;//invalid frontend
78  }
79  // Apply analogue threshold, timing simulation
80  const auto &thresholds = calibData->getThresholds(type, moduleHash, FE);
81  double threshold = PixelDigitization::randomThreshold(thresholds, rndmEngine);
82 
83  if (charge > threshold) {
84  int bunchSim = 0;
85  if (mapDiode.totalCharge().fromTrack()) {
86  bunchSim = static_cast<int>(std::floor((getG4Time(mapDiode.totalCharge()) + m_timeOffset) / m_bunchSpace));
87  //Timewalk implementation
88  if(m_doTimeWalk){
89  if(charge < (threshold + m_overDrive)){
90  const int timeWalk = 25; // Here it is assumed that the maximum value of timewalk is one bunch crossing (25ns)
91  bunchSim = static_cast<int>(std::floor((getG4Time(mapDiode.totalCharge()) + m_timeOffset + timeWalk) / m_bunchSpace));
92  }
93  }
94  } else {
95  bunchSim = CLHEP::RandFlat::shootInt(rndmEngine, m_numberOfBcid);
96  }
97 
98  if (bunchSim < 0 || bunchSim > m_numberOfBcid) {
99  SiHelper::belowThreshold(mapDiode, true, true);
100  } else {
101  SiHelper::SetBunch(mapDiode, bunchSim);
102  }
103  } else {
104  SiHelper::belowThreshold(mapDiode, true, true);
105  }
106 
107  // charge to ToT conversion
108  double tot = calibData->getToT(type, moduleHash, FE, charge);
109  double totsig = calibData->getTotRes(moduleHash, FE, tot);
110  int nToT = generateToT(rndmEngine, tot,totsig, std::make_pair(0,overflowToT));
111  auto thresh = m_chipSim.totThreshold();
112 
113  if (nToT <= thresh) {
114  SiHelper::belowThreshold(mapDiode, true, true);
115  }
116 
117  // Filter events
118  if (SiHelper::isMaskOut(mapDiode)) {
119  continue;
120  }
121  if (SiHelper::isDisabled(mapDiode)) {
122  continue;
123  }
124 
125  if (!m_pixelConditionsTool->isActive(moduleHash, diodeID, ctx)) {
126  SiHelper::disabled(mapDiode, true, true);
127  continue;
128  }
129 
130  int flag = mapDiode.flag();
131  int bunch = (flag >> 8) & 0xff;
132 
133  InDetDD::SiReadoutCellId cellId = mapDiode.getReadoutCell();
134  const Identifier id_readout = chargedDiodes.element()->identifierFromCellId(cellId);
135 
136  // Front-End simulation
137  if (bunch >= 0 && bunch < m_numberOfBcid) {
138  Pixel1RawData* p_rdo = new Pixel1RawData(id_readout, nToT, bunch, 0, bunch);
139  rdoCollection.push_back(p_rdo);
140  p_rdo = nullptr;
141  }
142  }
143 }
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
ITkPixSimulationParameters::crossTalk
double crossTalk() const
Definition: ITkPixSimulationParameters.h: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
SiHelper::isDisabled
static bool isDisabled(SiChargedDiode &chDiode)
Definition: SiHelper.h:179
physval_make_web_display.thresh
thresh
Definition: physval_make_web_display.py:35
PixelID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: PixelID.h:615
PixelChargeCalibCondData::getThresholds
PixelChargeCalib::Thresholds getThresholds(InDetDD::PixelDiodeType type, unsigned int moduleHash, unsigned int FE) const
Definition: PixelChargeCalibCondData.cxx:99
FrontEndSimTool::m_thermalNoise
double m_thermalNoise
Definition: FrontEndSimTool.h:54
InDetDD::invalidFrontEnd
constexpr uint32_t invalidFrontEnd
Definition: PixelReadoutDefinitions.h:47
InDetDD::PixelDiodeType
PixelDiodeType
Definition: PixelReadoutDefinitions.h:28
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
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
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:360
InDetDD::SolidStateDetectorElementBase::getIdHelper
const AtlasDetectorID * getIdHelper() const
Returns the id helper (inline)
PixelDigitization::getG4Time
double getG4Time(const SiTotalCharge &totalCharge)
Definition: PixelNoiseFunctions.cxx:206
PixelDigitization::randomThreshold
double randomThreshold(const PixelChargeCalib::Thresholds &t, CLHEP::HepRandomEngine *pEngine)
Definition: PixelDigitizationUtilities.cxx:105
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:40
PixelID::wafer_hash
IdentifierHash wafer_hash(Identifier wafer_id) const
wafer hash from id
Definition: PixelID.h:383
FrontEndSimTool::m_bunchSpace
static constexpr double m_bunchSpace
Definition: FrontEndSimTool.h:50
SiChargedDiodeCollection
Definition: SiChargedDiodeCollection.h:109
PixelDigitization::generateToT
int generateToT(CLHEP::HepRandomEngine *rndmEngine, double mean, double sd, const std::pair< int, int > &range)
Definition: PixelNoiseFunctions.cxx:192
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:28
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::process
virtual void process(SiChargedDiodeCollection &chargedDiodes, PixelRDO_Collection &rdoCollection, CLHEP::HepRandomEngine *rndmEngine) const
Definition: RD53SimTool.cxx:39
RD53SimTool::m_overDrive
Gaudi::Property< int > m_overDrive
Definition: RD53SimTool.h:43
FrontEndSimTool::m_BarrelEC
Gaudi::Property< int > m_BarrelEC
Definition: FrontEndSimTool.h:68
SiHelper::isMaskOut
static bool isMaskOut(SiChargedDiode &chDiode)
Definition: SiHelper.h:171
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
threshold
Definition: chainparser.cxx:74
charge
double charge(const T &p)
Definition: AtlasPID.h:986
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
ITkPixSimulationParameters::totThreshold
int totThreshold() const
Definition: ITkPixSimulationParameters.h:23
PixelDigitization::crossTalk
void crossTalk(double crossTalk, SiChargedDiodeCollection &chargedDiodes)
Definition: PixelNoiseFunctions.cxx:28
RD53SimTool::~RD53SimTool
virtual ~RD53SimTool()
InDetDD::PixelDiodeType::NONE
@ NONE
FrontEndSimTool::m_timeOffset
double m_timeOffset
Definition: FrontEndSimTool.h:52
RD53SimTool::finalize
virtual StatusCode finalize()
Definition: RD53SimTool.cxx:34
PixelDigitizationUtilities.h
RD53SimTool::m_chipSim
ITkPixSimulationParameters m_chipSim
Definition: RD53SimTool.h:37
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:76
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:164
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:64
SiChargedDiodeCollection.h
SiChargedDiodeCollection::identify
virtual Identifier identify() const override final
Definition: SiChargedDiodeCollection.h:230
Identifier
Definition: IdentifierFieldParser.cxx:14