Skip to content
Snippets Groups Projects
Commit a104f4f0 authored by Shaun Roe's avatar Shaun Roe Committed by Walter Lampl
Browse files

23.0-refactor-PixelConditionsData

23.0-refactor-PixelConditionsData
parent 4cc5e683
No related branches found
No related tags found
2 merge requests!64264Daily merge of 23.0 into main,!6418523.0-refactor-PixelConditionsData
/*
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
*/
/**
* @file PixelChargeCalibParameters.h
* @author Shaun Roe
* @date June, 2023
* @brief Structs for holding charge calibration parameterisation and data
*/
namespace PixelChargeCalib{
struct LegacyFitParameters{
float A = 0.f;
float E = 0.f;
float C = 0.f;
///Return Time-over-threshold given charge Q
float ToT(float Q) const{
if ((C + Q) != 0.0) {
return A * (E + Q) / (C + Q);
}
return 0.f;
}
//return Charge, given time-over-Threshold
float Q(float tot) const{
if (std::fabs(A) != 0.0 && std::fabs(tot / A - 1.0) != 0.0) {
return (C * tot / A - E) / (1.0 - tot / A);
}
return 0.f;
}
};
struct LinearFitParameters{
float F = 0.f;
float G = 0.f;
float ToT(float Q) const{
if (F != 0.0f){
return (Q - G) / F;
}
return 0.f;
}
float Q(float tot) const {
return F * tot + G;
}
};
struct Thresholds{
int value = 0;
int sigma = 0;
int noise = 0;
int inTimeValue = 0;
};
struct Resolutions{
float res1 = 0.f;
float res2 = 0.f;
float total(float Q) const {
return res1 + res2 * Q;
}
};
}
......@@ -11,11 +11,17 @@
#include <map>
#include <vector>
#include <array>
namespace PixelChargeCalib{
class LegacyFitParameters;
class LinearFitParameters;
class Thresholds;
class Resolutions;
}
class PixelChargeCalibCondData
{
public:
PixelChargeCalibCondData();
PixelChargeCalibCondData() = default;
PixelChargeCalibCondData(std::size_t max_module_hash);
static constexpr size_t IBLCalibrationSize{16};
......@@ -31,28 +37,51 @@ class PixelChargeCalibCondData
};
// Normal pixel
void
setThresholds(InDetDD::PixelDiodeType type, unsigned int moduleHash, const std::vector<PixelChargeCalib::Thresholds> & thresholds);
//
void setAnalogThreshold(InDetDD::PixelDiodeType type, unsigned int moduleHash, std::vector<int> &&value);
void setAnalogThresholdSigma(InDetDD::PixelDiodeType type, unsigned int moduleHash, std::vector<int> &&value);
void setAnalogThresholdNoise(InDetDD::PixelDiodeType type, unsigned int moduleHash, std::vector<int> &&value);
void setInTimeThreshold(InDetDD::PixelDiodeType type, unsigned int moduleHash, std::vector<int> &&value);
//
//
void setLegacyFitParameters(InDetDD::PixelDiodeType type, unsigned int moduleHash, const std::vector<PixelChargeCalib::LegacyFitParameters> &parameters);
//
void setQ2TotA(InDetDD::PixelDiodeType type, unsigned int moduleHash, std::vector<float> &&value);
void setQ2TotE(InDetDD::PixelDiodeType type, unsigned int moduleHash, std::vector<float> &&value);
void setQ2TotC(InDetDD::PixelDiodeType type, unsigned int moduleHash, std::vector<float> &&value);
//
//
void setLinearFitParameters(InDetDD::PixelDiodeType type, unsigned int moduleHash, const std::vector<PixelChargeCalib::LinearFitParameters> &parameters);
//
void setQ2TotF(InDetDD::PixelDiodeType type, unsigned int moduleHash, std::vector<float> &&value);
void setQ2TotG(InDetDD::PixelDiodeType type, unsigned int moduleHash, std::vector<float> &&value);
//
//
void setTotResolutions(unsigned int moduleHash, const std::vector<PixelChargeCalib::Resolutions> &value);
//
void setTotRes1(unsigned int moduleHash, std::vector<float> &&value);
void setTotRes2(unsigned int moduleHash, std::vector<float> &&value);
//
//
PixelChargeCalib::Thresholds getThresholds(InDetDD::PixelDiodeType type, unsigned int moduleHash, unsigned int FE) const;
//
int getAnalogThreshold(InDetDD::PixelDiodeType type, unsigned int moduleHash, unsigned int FE) const;
int getAnalogThresholdSigma(InDetDD::PixelDiodeType type, unsigned int moduleHash, unsigned int FE) const;
int getAnalogThresholdNoise(InDetDD::PixelDiodeType type, unsigned int moduleHash, unsigned int FE) const;
int getInTimeThreshold(InDetDD::PixelDiodeType type, unsigned int moduleHash, unsigned int FE) const;
//
//
PixelChargeCalib::LegacyFitParameters getLegacyFitParameters(InDetDD::PixelDiodeType type, unsigned int moduleHash, unsigned int FE) const;
//
float getQ2TotA(InDetDD::PixelDiodeType type, unsigned int moduleHash, unsigned int FE) const;
float getQ2TotE(InDetDD::PixelDiodeType type, unsigned int moduleHash, unsigned int FE) const;
float getQ2TotC(InDetDD::PixelDiodeType type, unsigned int moduleHash, unsigned int FE) const;
//
//
PixelChargeCalib::LinearFitParameters getLinearFitParameters(InDetDD::PixelDiodeType type, unsigned int moduleHash, unsigned int FE) const;
//
float getQ2TotF(InDetDD::PixelDiodeType type, unsigned int moduleHash, unsigned int FE) const;
float getQ2TotG(InDetDD::PixelDiodeType type, unsigned int moduleHash, unsigned int FE) const;
......@@ -72,8 +101,7 @@ class PixelChargeCalibCondData
private:
std::size_t m_maxModuleHash = 0;
constexpr static std::size_t s_NPixelDiods = 4;
static unsigned short diodeIndex(InDetDD::PixelDiodeType type) { return static_cast<unsigned int>(type); }
constexpr static std::size_t s_NPixelDiodes = enum2uint(InDetDD::PixelDiodeType::N_DIODETYPES);
template <typename T>
static void resize(std::size_t idx, std::size_t max_size, T &container) { if (idx >= container.size()) { container.resize(max_size); } }
......@@ -85,14 +113,14 @@ class PixelChargeCalibCondData
template <typename T, typename T_Value>
static void setValue(std::size_t max_size, T &container, InDetDD::PixelDiodeType type, unsigned int moduleHash, T_Value &&value) {
resize( moduleHash,max_size, container.at(diodeIndex(type)));
container.at(diodeIndex(type)).at(moduleHash) = std::move(value);
resize( moduleHash,max_size, container.at(enum2uint(type)));
container.at(enum2uint(type)).at(moduleHash) = std::move(value);
}
using chipThreshold = std::vector<std::vector<int>>;
using chipCharge = std::vector<std::vector<float>>;
using chipThresholdMap = std::array<chipThreshold, s_NPixelDiods>;
using chipChargeMap = std::array<chipCharge, s_NPixelDiods>;
using chipThresholdMap = std::array<chipThreshold, s_NPixelDiodes>;
using chipChargeMap = std::array<chipCharge, s_NPixelDiodes>;
chipThresholdMap m_analogThreshold;
chipThresholdMap m_analogThresholdSigma;
......
......@@ -18,6 +18,7 @@
#include <boost/test/unit_test.hpp>
//
#include "PixelConditionsData/PixelChargeCalibCondData.h"
#include "PixelConditionsData/ChargeCalibParameters.h"
#include <vector>
#include <stdexcept>
#include <algorithm>
......@@ -33,18 +34,34 @@ BOOST_AUTO_TEST_SUITE(PixelChargeCalibCondDataTest)
}
BOOST_AUTO_TEST_CASE( SetAndGet ){
std::vector<int> dummy(6,10);
std::vector<int> thresholds{0,20,40, 100, 4, 30};//normally 16 values, 1 for each chip
size_t maxModuleHash(100); //normally given by the maximum hash
InDetDD::PixelDiodeType type = InDetDD::PixelDiodeType::NORMAL;
unsigned int moduleHash=10;
unsigned int hashTooBig=200;
PixelChargeCalibCondData calib(maxModuleHash);
//arguments to set and get I will use:
unsigned int moduleHash=10;
unsigned int frontEndIdx=1;
unsigned int frontEndIdxTooBig=15;
InDetDD::PixelDiodeType type = InDetDD::PixelDiodeType::NORMAL;
//
//
PixelChargeCalib::Thresholds oneValue{0,3,6,9};// thresh, noise, sigma, intime
std::vector<PixelChargeCalib::Thresholds> allThresholds(5, oneValue);
BOOST_CHECK_NO_THROW(calib.setThresholds(type,moduleHash, allThresholds));
BOOST_CHECK_THROW(calib.setThresholds(type,hashTooBig, allThresholds), std::out_of_range);
//use old methods to get values
BOOST_CHECK(calib.getAnalogThreshold(type, moduleHash, frontEndIdx) == 0);
BOOST_CHECK(calib.getAnalogThresholdSigma(type, moduleHash, frontEndIdx) == 3);
//return struct in new method
BOOST_CHECK(calib.getThresholds(type, moduleHash, frontEndIdx).sigma == 3);
BOOST_CHECK(calib.getThresholds(type, moduleHash, frontEndIdx).noise == 6);
BOOST_CHECK_THROW(calib.getThresholds(type,hashTooBig,frontEndIdx), std::out_of_range);
BOOST_CHECK_THROW(calib.getThresholds(type,moduleHash,frontEndIdxTooBig), std::out_of_range);
//
std::vector<int> dummy(6,10);
std::vector<int> thresholds{0,20,40, 100, 4, 30};//normally 16 values, 1 for each chip
BOOST_CHECK_NO_THROW(calib.setAnalogThreshold(type,moduleHash, std::move(thresholds)));
unsigned int hashTooBig=200;
BOOST_CHECK_THROW(calib.setAnalogThreshold(type,hashTooBig, std::move(dummy)), std::out_of_range);
//
unsigned int frontEndIdx=1;
unsigned int frontEndIdxTooBig=15;
BOOST_CHECK(calib.getAnalogThreshold(type, moduleHash, frontEndIdx) == 20);
BOOST_CHECK_THROW(calib.getAnalogThreshold(type, hashTooBig, frontEndIdx), std::out_of_range);
BOOST_CHECK_THROW(calib.getAnalogThreshold(type, moduleHash, frontEndIdxTooBig), std::out_of_range);
......@@ -64,6 +81,31 @@ BOOST_AUTO_TEST_SUITE(PixelChargeCalibCondDataTest)
BOOST_CHECK_NO_THROW(calib.setInTimeThreshold(type,moduleHash, std::move(inTime)));
BOOST_CHECK(calib.getInTimeThreshold(type, moduleHash, frontEndIdx) == 4);
//
PixelChargeCalib::LegacyFitParameters oneFit{100.f, 300.f, 600.f};
std::vector< PixelChargeCalib::LegacyFitParameters > allParameters(4, oneFit);
BOOST_CHECK_NO_THROW(calib.setLegacyFitParameters(type,moduleHash, allParameters));
BOOST_CHECK_THROW(calib.setLegacyFitParameters(type,hashTooBig, allParameters), std::out_of_range);
BOOST_TEST(calib.getQ2TotA(type, moduleHash, frontEndIdx) == 100.f);
BOOST_TEST(calib.getLegacyFitParameters(type, moduleHash, frontEndIdx).C == 600.f);
BOOST_CHECK_THROW(calib.getLegacyFitParameters(type,hashTooBig,frontEndIdx), std::out_of_range);
BOOST_CHECK_THROW(calib.getLegacyFitParameters(type,moduleHash,frontEndIdxTooBig), std::out_of_range);
//
PixelChargeCalib::LinearFitParameters linFit{110.f, 120.f};
std::vector< PixelChargeCalib::LinearFitParameters > linParameters(4, linFit);
BOOST_CHECK_NO_THROW(calib.setLinearFitParameters(type,moduleHash, linParameters));
BOOST_CHECK_THROW(calib.setLinearFitParameters(type,hashTooBig, linParameters), std::out_of_range);
BOOST_TEST(calib.getQ2TotF(type, moduleHash, frontEndIdx) == 110.f);
BOOST_TEST(calib.getLinearFitParameters(type, moduleHash, frontEndIdx).G == 120.f);
BOOST_CHECK_THROW(calib.getLinearFitParameters(type,hashTooBig,frontEndIdx), std::out_of_range);
BOOST_CHECK_THROW(calib.getLinearFitParameters(type,moduleHash,frontEndIdxTooBig), std::out_of_range);
//
float Q=5.f;
PixelChargeCalib::Resolutions oneResolution{20.f,30.f};
std::vector< PixelChargeCalib::Resolutions > resolutions(4, oneResolution);
BOOST_CHECK_NO_THROW(calib.setTotResolutions(moduleHash, resolutions));
BOOST_CHECK_THROW(calib.setTotResolutions(hashTooBig, resolutions), std::out_of_range);
BOOST_TEST(calib.getTotRes(moduleHash, frontEndIdx, Q) == (20.f + 5.f*30.f));
//
std::vector<float> A(6);
std::iota(A.begin(), A.end(), 0.);
BOOST_CHECK_NO_THROW(calib.setQ2TotA(type, moduleHash, std::move(A)));
......@@ -97,7 +139,7 @@ BOOST_AUTO_TEST_SUITE(PixelChargeCalibCondDataTest)
std::iota(res2.begin(), res2.end(), 5.);
BOOST_CHECK_NO_THROW(calib.setTotRes2(moduleHash, std::move(res2)));
//
float Q=5.f;
float expectedResult = 6.f*Q + 6.f;
BOOST_TEST(calib.getTotRes(moduleHash, frontEndIdx, Q) == expectedResult);
//round trip calculation
......
# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
# Declare the package name:
atlas_subdir( PixelReadoutDefinitions )
find_package( Boost COMPONENTS unit_test_framework)
# Component(s) in the package:
atlas_add_library( PixelReadoutDefinitionsLib
PixelReadoutDefinitions/*.h
INTERFACE
PUBLIC_HEADERS PixelReadoutDefinitions )
atlas_add_test( PixelReadoutDefinitions_test
SOURCES test/PixelReadoutDefinitions_test.cxx
INCLUDE_DIRS ${Boost_INCLUDE_DIRS}
LINK_LIBRARIES ${Boost_LIBRARIES} PixelReadoutDefinitionsLib
POST_EXEC_SCRIPT "nopost.sh" )
/*
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
*/
#ifndef PIXELREADOUTDEFINITIONS_H
#define PIXELREADOUTDEFINITIONS_H
#include <cstddef> //for size_t
namespace InDetDD
{
namespace InDetDD{
enum class PixelModuleType
{
DBM,
IBL_PLANAR,
IBL_3D,
PIX_BARREL,
PIX_ENDCAP,
NONE
};
enum class PixelModuleType{
DBM,
IBL_PLANAR,
IBL_3D,
PIX_BARREL,
PIX_ENDCAP,
NONE
};
enum class PixelDiodeType
{
NORMAL,
LONG,
GANGED,
LARGE
};
enum class PixelDiodeType{
NORMAL,
LONG,
GANGED,
LARGE,
N_DIODETYPES
};
enum class PixelReadoutTechnology
{
FEI3,
FEI4,
RD53
};
enum class PixelReadoutTechnology{
FEI3,
FEI4,
RD53,
N_TECHNOLOGIES
};
///Convert an enum class to size_t for use as an array index
template <typename T>
constexpr std::size_t
enum2uint(T n){
return static_cast<size_t>(n);
}
}
......
/*
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
*/
/**
* @file PixelReadoutDefinitions/test/PixelReadoutDefinitions_test.cxx
* @author Shaun Roe
* @date July, 2023
* @brief Some tests for PixelReadoutDefinitions enum2uint
*/
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE TEST_PIXELREADOUTDEFINITIONS
#include <boost/test/unit_test.hpp>
//
#include "PixelReadoutDefinitions/PixelReadoutDefinitions.h"
using namespace InDetDD;
BOOST_AUTO_TEST_SUITE(PixelReadoutDefinitionsTest)
BOOST_AUTO_TEST_CASE(enum2uint_test){
BOOST_TEST(enum2uint(PixelModuleType::IBL_PLANAR) == 1);
BOOST_TEST(enum2uint(PixelDiodeType::LONG) == 1);
BOOST_TEST(enum2uint(PixelReadoutTechnology::FEI4) == 1);
}
BOOST_AUTO_TEST_SUITE_END()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment