ATLAS Offline Software
Loading...
Searching...
No Matches
LUTChargeCalibParser.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
6#include "Identifier/Identifier.h"
12
13namespace{
14 constexpr size_t FEStringSize{20};
15} // namespace
16
19
20namespace PixelChargeCalib{
21
23 LUTChargeCalibParser::parseImpl(unsigned int moduleHash, const nlohmann::json & data, int inputSource){
24 IdentifierHash wafer_hash = IdentifierHash(moduleHash);
25 const InDetDD::SiDetectorElement *element = m_elements->getDetectorElement(wafer_hash);
26 const auto & [numFE, technology] = numChipsAndTechnology(element);
27 bool isLUTEnabled = (inputSource == 1);
28 bool isChargeCalibrationFromJson = (inputSource == 2);
29 //
30 ChargeCalibrationBundle b(numFE,isLUTEnabled,isChargeCalibrationFromJson);
31 //
32 for (unsigned int j{}; j < numFE; j++) {
33 //Retrieve calibArrays in different formats for Run4 (based on ITKPixV2 chip settings) and Run3
34 const auto &calibArray = (isLUTEnabled || isChargeCalibrationFromJson) ? data.at(0) : data.at(j);
35 if (!calibArray.empty()) {
36 // new charge calibration for RUN-3
37 if ((technology == InDetDD::PixelReadoutTechnology::FEI4 && !(element->isDBM())) || ((b.useLUT || b.useTXT) && technology == InDetDD::PixelReadoutTechnology::RD53)) {
38 if (calibArray.size() != FEStringSize) {
39 std::cout<<"Parameter size is not consistent(" << FEStringSize << ") " << calibArray.size() << " at (i,j)=(" << moduleHash << "," << j << ")\n";
40 b.isValid = false;
41 return b;
42 }
43 auto getInt = getFunc<int>(calibArray);
44 auto getFloat = getFunc<float>(calibArray);
45 auto &charges = b.tot2Charges.emplace_back(PixelChargeCalibCondData::IBLCalibration());
46 for (size_t k{}; k < PixelChargeCalibCondData::IBLCalibrationSize; k++) {
47 charges[k] = getFloat(k + 4ul);
48 }
50 b.threshold.emplace_back(getInt(0), 0.f, getInt(1), 0.f);
51 b.thresholdLong.emplace_back(getInt(2), 0.f, getInt(3), 0.f);
52 b.thresholdGanged.emplace_back(getInt(2), 0.f, getInt(3), 0.f);
53 b.params.emplace_back(0.f, 0.f, 0.f, LegacyFitParameters::defaultOverflow);
54 b.paramsGanged.emplace_back(0.f, 0.f, 0.f, LegacyFitParameters::defaultOverflow);
55 b.totRes.emplace_back(0.f, 0.f);
56 } else { //normal CalibrationStrategy used by ITk
57 if (calibArray.size() != FEStringSize) {
58 std::cout<<"Parameter size is not consistent(" << FEStringSize << ") " << calibArray.size() << " at (i,j)=(" << moduleHash << "," << j << ")\n";
59 b.isValid = false;
60 return b;
61 }
62 auto getInt = getFunc<int>(calibArray);
63 auto getFloat = getFunc<float>(calibArray);
64 b.threshold.emplace_back(getInt(0), getInt(1), getInt(2), getInt(3));
65 b.thresholdLong.emplace_back(getInt(4), getInt(5), getInt(6), getInt(7));
66 b.thresholdGanged.emplace_back(getInt(8), getInt(9), getInt(10), getInt(11));
67 //note: for ITk, setting the first parameter to the constructor (A) less than totlimit
68 //will result in pathological behaviour for the 'Q' method on LegacyFitParameters
69 const auto totLimit = (technology == InDetDD::PixelReadoutTechnology::RD53) ? 14: LegacyFitParameters::defaultOverflow;
70 b.params.emplace_back(getFloat(12), getFloat(13), getFloat(14), totLimit);
71 b.paramsGanged.emplace_back(getFloat(15), getFloat(16), getFloat(17), totLimit);
72 b.totRes.emplace_back(getFloat(18), getFloat(19));
73
74 // Linear extrapolation above large charge
75 if (m_configData->getPIXLinearExtrapolation()) {
77 const auto & [barrel_ec, layer] = getBecAndLayer(m_pixelID, wafer_hash);
78 // search for ToT when charge exceeds threshold
79 if (!(element->isDBM())) {
80 //charge threshold beyond which linear fit will be used
81 const int totIdxStart = m_configData->getToTThreshold(barrel_ec,layer);
82 const int totIdxEnd = m_configData->getFEI3Latency(barrel_ec,layer);
83 // Normal pixels
84 int totlimit = b.idxAtChargeLimit(m_chargeLimit, InDetDD::PixelDiodeType::NORMAL, totIdxStart, totIdxEnd);
85 b.insertLinearParams( InDetDD::PixelDiodeType::NORMAL, totlimit);
86 // Ganged pixels
87 totlimit = b.idxAtChargeLimit(m_chargeLimit, InDetDD::PixelDiodeType::GANGED, totIdxStart, totIdxEnd);
88 b.insertLinearParams( InDetDD::PixelDiodeType::GANGED, totlimit);
89 } else { // DBM
90 b.lin.emplace_back(0.f, 0.f);
91 b.linGanged.emplace_back(0.f, 0.f);
92 }
93 } else {
95 b.lin.emplace_back(0.f, 0.f);
96 b.linGanged.emplace_back(0.f, 0.f);
97 }
98 }
99 } else {
100 std::cout<<"Array size is zero in " << calibArray << " at (i,j)=(" << moduleHash << "," << j << ")\n";
101 b.isValid = false;
102 return b;
103 }
104 }
105 return b;
106 }
107}
Struct for holding vectors of charge calibration constants, with utility methods.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Parses a database run4 Look-Up-Table format string to a ChargeCalibrationBundle.
Store pixel constant parameters in PixelModuleData.
This is a "hash" representation of an Identifier.
Class to hold geometrical description of a silicon detector element.
static constexpr size_t IBLCalibrationSize
std::array< float, IBLCalibrationSize > IBLCalibration
std::function< T(size_t)> getFunc(const std::vector< std::string > &data)
Return function converting a string to number type T at index i of data vector.
static constexpr float m_chargeLimit
If the calculated charge exceeds this limit, a linear extrapolation is used at this point.
const InDetDD::SiDetectorElementCollection * m_elements
virtual ChargeCalibrationBundle parseImpl(unsigned int moduleHash, const nlohmann::json &data, int inputSource) override final
std::pair< size_t, InDetDD::PixelReadoutTechnology > numChipsAndTechnology(const InDetDD::SiDetectorElement *element)
std::pair< int, int > getBecAndLayer(const PixelID *pPixelId, IdentifierHash hash)
bundles of parameters used together in the PixelChargeCalibCondAlg