ATLAS Offline Software
ITkPixChargeCalibAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "ITkPixChargeCalibAlg.h"
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 
27 using namespace PixelChargeCalib; //containing LegacyFitParameters etc
28 using InDetDD::enum2uint;
29 
30 namespace{
31  //default values of ITk thresholds, hard coded for now
32  Thresholds
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(){
45  static const LegacyFitParameters legacyFit{14.0f, -1000.f, 8000.f};
46  return legacyFit;
47  }
48 
50  defaultResolutions(){
51  static const Resolutions r{0.4, 0.02};
52  return r;
53  }
54 
55  EventIDRange
56  infiniteEventRange(){
57  const EventIDBase start{EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, 0, 0, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
58  const EventIDBase stop {EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
59  return EventIDRange{start, stop};
60  }
61 }
62 
63 
64 ITkPixChargeCalibAlg::ITkPixChargeCalibAlg(const std::string& name, ISvcLocator* pSvcLocator):
65  ::AthReentrantAlgorithm(name, pSvcLocator){
66 
67 }
68 
70  ATH_CHECK(detStore()->retrieve(m_pixelID,"PixelID"));
73  return StatusCode::SUCCESS;
74 }
75 
76 StatusCode ITkPixChargeCalibAlg::execute(const EventContext& ctx) const {
77 
79  if (writeHandle.isValid()) {
80  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.");
81  return StatusCode::SUCCESS;
82  }
83 
85  const InDetDD::SiDetectorElementCollection* elements(*pixelDetEleHandle);
86  if (not pixelDetEleHandle.isValid() or elements==nullptr) {
87  ATH_MSG_FATAL(m_pixelDetEleCollKey.fullKey() << " is not available.");
88  return StatusCode::FAILURE;
89  }
92 
93  // Construct the output Cond Object and fill it in
94  auto pChargeCalibData = std::make_unique<PixelChargeCalibCondData>(m_pixelID->wafer_hash_max());
95  //
96  for (unsigned int moduleHash{}; moduleHash < m_pixelID->wafer_hash_max(); moduleHash++) {
97  IdentifierHash wafer_hash = IdentifierHash(moduleHash);
98  const auto & [barrel_ec, layer] = getBecAndLayer(m_pixelID, wafer_hash);
99  const InDetDD::SiDetectorElement *element = elements->getDetectorElement(wafer_hash);
100  const auto & [numFE, technology] = numChipsAndTechnology(element);
101  const std::vector<Thresholds> allDefaultThresholds(numFE, defaultThresholds(barrel_ec, layer));
102  //
103  const std::vector<LegacyFitParameters> allDefaultFitParams(numFE, defaultLegacyParameters());
104  //
105  const std::vector<LinearFitParameters> allDefaultLinearParams(numFE, LinearFitParameters{0.0f, 0.0f});
106  //
107  for (InDetDD::PixelDiodeType type : diodeTypes) {
108  pChargeCalibData -> setThresholds(type, moduleHash, allDefaultThresholds);
109  pChargeCalibData -> setLegacyFitParameters(type, moduleHash, allDefaultFitParams);
110  pChargeCalibData -> setLinearFitParameters(type, moduleHash, allDefaultLinearParams);
111  }
112  pChargeCalibData -> setTotResolutions(moduleHash, std::vector<Resolutions>(numFE, defaultResolutions()));
113  }
114 
115  const auto & rangeW = infiniteEventRange();
116  if (writeHandle.record(rangeW, std::move(pChargeCalibData)).isFailure()) {
117  ATH_MSG_FATAL("Could not record PixelChargeCalibCondData " << writeHandle.key() << " with EventRange " << rangeW << " into Conditions Store");
118  return StatusCode::FAILURE;
119  }
120  ATH_MSG_INFO("recorded new CDO " << writeHandle.key() << " with range " << rangeW << " into Conditions Store");
121 
122  return StatusCode::SUCCESS;
123 }
124 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
beamspotman.r
def r
Definition: beamspotman.py:676
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PixelChargeCalib::Resolutions
Definition: ChargeCalibParameters.h:90
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
PixelChargeCalib::getBecAndLayer
std::pair< int, int > getBecAndLayer(const PixelID *pPixelId, IdentifierHash hash)
Definition: PixelChargeCalibUtils.cxx:13
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
InDetDD::enum2uint
constexpr std::size_t enum2uint(T n, const std::string &callingFunctionName="")
Convert an enum class to size_t for use as an array index.
Definition: PixelReadoutDefinitions.h:48
InDetDD::PixelDiodeType
PixelDiodeType
Definition: PixelReadoutDefinitions.h:25
ChargeCalibParameters.h
Structs for holding charge calibration parameterisation and data.
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
PixelChargeCalib::numChipsAndTechnology
std::pair< size_t, InDetDD::PixelReadoutTechnology > numChipsAndTechnology(const InDetDD::SiDetectorElement *element)
Definition: PixelChargeCalibUtils.cxx:19
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition: WriteCondHandle.h:157
InDetDD::PixelDiodeType::GANGED
@ GANGED
PixelChargeCalib::LegacyFitParameters
Definition: ChargeCalibParameters.h:18
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
InDetDD::PixelDiodeType::N_DIODETYPES
@ N_DIODETYPES
SG::WriteCondHandle::fullKey
const DataObjID & fullKey() const
Definition: WriteCondHandle.h:41
InDetDD::PixelDiodeType::LONG
@ LONG
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ITkPixChargeCalibAlg::initialize
virtual StatusCode initialize() override final
Definition: ITkPixChargeCalibAlg.cxx:69
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
ChargeCalibrationBundle.h
Struct for holding vectors of charge calibration constants, with utility methods.
InDetDD::PixelDiodeType::LARGE
@ LARGE
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
PixelChargeCalibUtils.h
PixelChargeCalib::LinearFitParameters
Definition: ChargeCalibParameters.h:49
lumiFormat.array
array
Definition: lumiFormat.py:91
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SG::WriteCondHandle::key
const std::string & key() const
Definition: WriteCondHandle.h:40
IdentifierHash.h
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
PixelID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: PixelID.cxx:831
ITkPixChargeCalibAlg.h
SiDetectorElement.h
PixelReadoutDefinitions.h
PixelModuleDesign.h
Thresholds
Definition: LArCalorimeter/LArCalibDataQuality/python/Thresholds.py:1
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
SG::WriteCondHandle::isValid
bool isValid() const
Definition: WriteCondHandle.h:248
PixelChargeCalib
Definition: IChargeCalibrationParser.h:30
InDetDD::PixelDiodeType::NORMAL
@ NORMAL
ITkPixChargeCalibAlg::m_writeKey
SG::WriteCondHandleKey< PixelChargeCalibCondData > m_writeKey
Definition: ITkPixChargeCalibAlg.h:40
IChargeCalibrationParser.h
Interface to parsers which accept a string or json object and return a ChargeCalibrationBundle.
ITkPixChargeCalibAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: ITkPixChargeCalibAlg.cxx:76
ITkPixChargeCalibAlg::ITkPixChargeCalibAlg
ITkPixChargeCalibAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ITkPixChargeCalibAlg.cxx:64
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
InDetDD::SiDetectorElementCollection::getDetectorElement
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
Definition: SiDetectorElementCollection.cxx:15
ITkPixChargeCalibAlg::m_pixelID
const PixelID * m_pixelID
Definition: ITkPixChargeCalibAlg.h:34
ITkPixChargeCalibAlg::m_pixelDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
Definition: ITkPixChargeCalibAlg.h:37