ATLAS Offline Software
Loading...
Searching...
No Matches
ITkPixChargeCalibAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
10#include "PixelConditionsData/ChargeCalibParameters.h" //LegacyFitParameters, LinearFitParameters, Thresholds, Resolutions
13
15#include "GaudiKernel/EventIDRange.h"
16//
17#include <memory>
18#include <sstream>
19#include <iostream>
20#include <fstream>
21#include <iomanip>
22
23
26
27using namespace PixelChargeCalib; //containing LegacyFitParameters etc
29
30namespace{
31 //default values of ITk thresholds, hard coded for now
33 defaultThresholds(int bec, int layer){
34 static const Thresholds t{600, 24, 75, 1000}; //value, sigma, noise, inTimeThresh
35 static const Thresholds ec0{600, 24, 75, 1500};
36 static const Thresholds b0{900, 36, 110, 1000}; //different for first layer of barrel
37 if (layer == 0){
38 return bec==0 ? b0 : ec0;
39 }
40 return t;
41 }
42
44 defaultLegacyParameters(int bec, int layer){
45 // the first parameter should match the threshold
46 static const LegacyFitParameters t{14.0f, -600.f, 4500.f, 14.0f};
47 static const LegacyFitParameters ec0{14.0f, -600.f, 4500.f, 14.0f};
48 static const LegacyFitParameters b0{14.0f, -900.f, 4000.f, 14.0f}; //different for first layer of barrel
49 if (layer == 0){
50 return bec==0 ? b0 : ec0;
51 }
52 return t;
53 }
54
56 defaultResolutions(){
57 static const Resolutions r{0.4, 0.02};
58 return r;
59 }
60
61 EventIDRange
62 infiniteEventRange(){
63 const EventIDBase start{EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, 0, 0, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
64 const EventIDBase stop {EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
65 return EventIDRange{start, stop};
66 }
67}
68
69
70ITkPixChargeCalibAlg::ITkPixChargeCalibAlg(const std::string& name, ISvcLocator* pSvcLocator):
71 ::AthReentrantAlgorithm(name, pSvcLocator){
72
73}
74
76 ATH_CHECK(detStore()->retrieve(m_pixelID,"PixelID"));
77 ATH_CHECK(m_pixelDetEleCollKey.initialize());
78 ATH_CHECK(m_writeKey.initialize());
79 return StatusCode::SUCCESS;
80}
81
82StatusCode ITkPixChargeCalibAlg::execute(const EventContext& ctx) const {
83
85 if (writeHandle.isValid()) {
86 ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid.. In theory this should not be called, but may happen if multiple concurrent events are being processed out of order.");
87 return StatusCode::SUCCESS;
88 }
89
91 const InDetDD::SiDetectorElementCollection* elements(*pixelDetEleHandle);
92 if (not pixelDetEleHandle.isValid() or elements==nullptr) {
93 ATH_MSG_FATAL(m_pixelDetEleCollKey.fullKey() << " is not available.");
94 return StatusCode::FAILURE;
95 }
96 static constexpr std::array<InDetDD::PixelDiodeType, enum2uint(InDetDD::PixelDiodeType::N_DIODETYPES)> diodeTypes
98
99 // Construct the output Cond Object and fill it in
100 auto pChargeCalibData = std::make_unique<PixelChargeCalibCondData>(m_pixelID->wafer_hash_max());
101 //
102 for (unsigned int moduleHash{}; moduleHash < m_pixelID->wafer_hash_max(); moduleHash++) {
103 IdentifierHash wafer_hash = IdentifierHash(moduleHash);
104 const auto & [barrel_ec, layer] = getBecAndLayer(m_pixelID, wafer_hash);
105 const InDetDD::SiDetectorElement *element = elements->getDetectorElement(wafer_hash);
106 const auto & [numFE, technology] = numChipsAndTechnology(element);
107 const std::vector<Thresholds> allDefaultThresholds(numFE, defaultThresholds(barrel_ec, layer));
108 //
109 const std::vector<LegacyFitParameters> allDefaultFitParams(numFE, defaultLegacyParameters(barrel_ec, layer));
110 //
111 const std::vector<LinearFitParameters> allDefaultLinearParams(numFE, LinearFitParameters{0.0f, 0.0f});
112 //
113 for (InDetDD::PixelDiodeType type : diodeTypes) {
114 pChargeCalibData -> setThresholds(type, moduleHash, allDefaultThresholds);
115 pChargeCalibData -> setLegacyFitParameters(type, moduleHash, allDefaultFitParams);
116 pChargeCalibData -> setLinearFitParameters(type, moduleHash, allDefaultLinearParams);
117 }
118 pChargeCalibData -> setTotResolutions(moduleHash, std::vector<Resolutions>(numFE, defaultResolutions()));
119 }
120
121 const auto & rangeW = infiniteEventRange();
122 if (writeHandle.record(rangeW, std::move(pChargeCalibData)).isFailure()) {
123 ATH_MSG_FATAL("Could not record PixelChargeCalibCondData " << writeHandle.key() << " with EventRange " << rangeW << " into Conditions Store");
124 return StatusCode::FAILURE;
125 }
126 ATH_MSG_INFO("recorded new CDO " << writeHandle.key() << " with range " << rangeW << " into Conditions Store");
127
128 return StatusCode::SUCCESS;
129}
130
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Structs for holding charge calibration parameterisation and data.
Struct for holding vectors of charge calibration constants, with utility methods.
Interface to parsers which accept a string or json object and return a ChargeCalibrationBundle.
constexpr std::size_t enum2uint(T n, std::string_view callingFunctionName="")
Convert an enum class to size_t for use as an array index.
const ServiceHandle< StoreGateSvc > & detStore() const
An algorithm that can be simultaneously executed in multiple threads.
SG::WriteCondHandleKey< PixelChargeCalibCondData > m_writeKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
virtual StatusCode initialize() override final
virtual StatusCode execute(const EventContext &ctx) const override final
ITkPixChargeCalibAlg(const std::string &name, ISvcLocator *pSvcLocator)
This is a "hash" representation of an Identifier.
Class to hold the SiDetectorElement objects to be put in the detector store.
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
Class to hold geometrical description of a silicon detector element.
const std::string & key() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
int r
Definition globals.cxx:22
constexpr std::size_t enum2uint(T n, std::string_view callingFunctionName="")
Convert an enum class to size_t for use as an array index.
std::pair< size_t, InDetDD::PixelReadoutTechnology > numChipsAndTechnology(const InDetDD::SiDetectorElement *element)
std::pair< int, int > getBecAndLayer(const PixelID *pPixelId, IdentifierHash hash)