Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CalibParams
/// \brief Set High Gain energy calibration coefficient
/// \param cellID Absolute ID of cell
/// \param c is the calibration coefficient
void setGain(short cellID, float c) { mGainCalib[cellID - OFFSET] = c; }
void setGain(short cellID, float c) { mGainCalib.at(cellID - OFFSET) = c; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? CellID is deterministic and using at() has overhead.


/// \brief Set High Gain energy calibration coefficients for one module in the form of 2D histogram
/// \param 2D(64,56) histogram with calibration coefficients
Expand All @@ -67,7 +67,7 @@ class CalibParams
/// \brief Set High Gain to Low Gain ratio
/// \param cellID Absolute ID of cell
/// \param r is the calibration coefficient
void setHGLGRatio(short cellID, float r) { mHGLGRatio[cellID - OFFSET] = r; }
void setHGLGRatio(short cellID, float r) { mHGLGRatio.at(cellID - OFFSET) = r; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem


/// \brief Set High Gain to Low Gain ratio for one module in the form of 2D histogram
/// \param 2D(64,56) histogram with High Gain to Low Gain ratio
Expand All @@ -83,7 +83,7 @@ class CalibParams
/// \brief Set High Gain time calibration coefficient
/// \param cellID Absolute ID of cell
/// \param t is the calibration coefficient
void setHGTimeCalib(short cellID, float t) { mHGTimeCalib[cellID - OFFSET] = t; }
void setHGTimeCalib(short cellID, float t) { mHGTimeCalib.at(cellID - OFFSET) = t; }

/// \brief Set High Gain time calibration coefficients for one module in the form of 2D histogram
/// \param 2D(64,56) histogram with calibration coefficients
Expand All @@ -99,7 +99,7 @@ class CalibParams
/// \brief Set time calibration coefficient
/// \param cellID Absolute ID of cell
/// \param t is the calibration coefficient
void setLGTimeCalib(short cellID, float t) { mLGTimeCalib[cellID - OFFSET] = t; }
void setLGTimeCalib(short cellID, float t) { mLGTimeCalib.at(cellID - OFFSET) = t; }

/// \brief Set Low Gain time calibration coefficients for one module in the form of 2D histogram
/// \param 2D(64,56) histogram with calibration coefficients
Expand All @@ -108,7 +108,7 @@ class CalibParams
bool setLGTimeCalib(TH2* h, char module);

private:
static constexpr short NCHANNELS = 14337; ///< Number of channels starting from 1
static constexpr short NCHANNELS = 12544; ///< Number of channels = 14336-1792
static constexpr short OFFSET = 1793; ///< Non-existing channels 56*64*0.5+1
std::array<float, NCHANNELS> mGainCalib; ///< Container for the gain calibration coefficients
std::array<float, NCHANNELS> mHGLGRatio; ///< Container for the High Gain to Low Gain ratios
Expand Down
12 changes: 6 additions & 6 deletions DataFormats/Detectors/PHOS/include/DataFormatsPHOS/Pedestals.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Pedestals
// module numbering:
// start from module 0 (non-existing), 1 (half-module), 2 (bottom),... 4(highest)
// absId:
// start from 1 till 5*64*56. Numbering in each module starts at bottom left and first go in z direction:
// start from 1 till 5*64*56 =14336. Numbering in each module starts at bottom left and first go in z direction:
// 56 112 3584
// ... ... ...
// 1 57 ...3529
Expand All @@ -56,7 +56,7 @@ class Pedestals
/// \brief Get pedestal
/// \param cellID Absolute ID of cell
/// \return pedestal for the cell
short getHGPedestal(short cellID) const { return short(mHGPedestals.at(cellID - OFFSET)); }
short getHGPedestal(short cellID) const { return short(mHGPedestals[cellID - OFFSET]); }

/// \brief Set pedestal
/// \param cellID Absolute ID of cell
Expand All @@ -66,7 +66,7 @@ class Pedestals
/// \brief Get pedestal
/// \param cellID Absolute ID of cell
/// \return pedestal for the cell
short getLGPedestal(short cellID) const { return short(mLGPedestals.at(cellID - OFFSET)); }
short getLGPedestal(short cellID) const { return short(mLGPedestals[cellID - OFFSET]); }

/// \brief Set pedestal
/// \param cellID Absolute ID of cell
Expand All @@ -86,7 +86,7 @@ class Pedestals
/// \brief Get pedestal RMS
/// \param cellID Absolute ID of cell
/// \return pedestal RMS for the cell
float getHGRMS(short cellID) const { return float(mHGRMS.at(cellID - OFFSET)) / RMSCOMPRESS; }
float getHGRMS(short cellID) const { return float(mHGRMS[cellID - OFFSET]) / RMSCOMPRESS; }

/// \brief Set pedestal RMS
/// \param cellID Absolute ID of cell
Expand All @@ -96,15 +96,15 @@ class Pedestals
/// \brief Get pedestal
/// \param cellID Absolute ID of cell
/// \return pedestal RMS for the LG cell
float getLGRMS(short cellID) const { return float(mLGRMS.at(cellID - OFFSET)) / RMSCOMPRESS; }
float getLGRMS(short cellID) const { return float(mLGRMS[cellID - OFFSET]) / RMSCOMPRESS; }

/// \brief Set LG pedestal RMS
/// \param cellID Absolute ID of cell
/// \param c is the pedestal RMS (expected to be in range 0..5, larger values=bad channel=overflow)
void setLGRMS(short cellID, float c) { mLGRMS[cellID - OFFSET] = static_cast<unsigned char>(c * RMSCOMPRESS); }

private:
static constexpr short NCHANNELS = 14337; ///< Number of channels starting from 1
static constexpr short NCHANNELS = 12544; ///< Number of channels = 14336-1792
static constexpr short OFFSET = 1793; ///< Non-existing channels 56*64*1.5+1
static constexpr short RMSCOMPRESS = 50; ///< Conversion to store float RMS in range ~[0..5] in uchar
std::array<unsigned char, NCHANNELS> mHGPedestals; ///< Container for HG pedestals
Expand Down
36 changes: 28 additions & 8 deletions DataFormats/Detectors/PHOS/src/TriggerMap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,44 @@ using namespace o2::phos;

TriggerMap::TriggerMap(int param) : mVersion(param)
{
if (mVersion >= mParamDescr.size()) {
LOG(ERROR) << "impossible parameterization " << mVersion;
// create default object
// empty (all channels good) bad maps and
// uniform turn-on curves for DDLs
mParamDescr.emplace_back("TestDefault");
std::array<std::array<float, NMAXPAR>, NDDL> a;
for (int iDDL = 0; iDDL < NDDL; iDDL++) {
a[iDDL].fill(0);
a[iDDL][0] = 1.; //only one step
a[iDDL][1] = 4.; //threshold
a[iDDL][2] = 0.5; //width
}
mParamSets.emplace_back(a);
mCurrentSet = mParamSets[0];
mVersion = 0;
}

void TriggerMap::addTurnOnCurvesParams(std::string_view versionName, std::array<std::array<float, 10>, 14>& params)
{
mParamDescr.emplace_back(versionName);
mParamSets.emplace_back(params);
}

void TriggerMap::setTurnOnCurvesVestion(int v)
{
if (v >= mParamDescr.size()) {
LOG(ERROR) << "impossible parameterization " << v;
LOG(ERROR) << "Available are:";
for (int i = 0; i < mParamDescr.size(); i++) {
LOG(ERROR) << i << " : " << mParamDescr[i];
}
LOG(ERROR) << " keep current " << mParamDescr[mVersion];
return;
}
mVersion = v;
LOG(INFO) << "Will use parameterization " << mParamDescr[mVersion];
mCurrentSet = mParamSets[mVersion];
}

void TriggerMap::addTurnOnCurvesParams(std::string_view versionName, std::array<std::array<float, 10>, 14>& params)
{
mParamDescr.emplace_back(versionName);
mParamSets.emplace_back(params);
}

bool TriggerMap::selectTurnOnCurvesParams(std::string_view versionName)
{
mVersion = 0;
Expand Down
2 changes: 1 addition & 1 deletion Detectors/PHOS/base/include/PHOSBase/Mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Mapping
kWrongAbsId,
kWrongCaloFlag,
kNotInitialized };
static constexpr short NCHANNELS = 14337; ///< Number of channels starting from 1
static constexpr short NCHANNELS = 14336; ///< Number of channels starting from 1
static constexpr short NHWPERDDL = 2048; ///< Number of HW addressed per DDL
static constexpr short NMaxHWAddress = 3929; ///< Maximal HW address (size of array)
static constexpr short NDDL = 14; ///< Total number of DDLs
Expand Down
31 changes: 16 additions & 15 deletions Detectors/PHOS/base/src/Geometry.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ ClassImp(Geometry);
// 56 112 3584
// ... ... ...
// 1 57 ...3529
// relid[3]: (module number[0...3], iphi[1...64], iz[1...56])
// relid[3]: (module number[1...4], iphi[1...64], iz[1...56])
//
// Then TRU channels go 112 per branch, 2 branches per ddl
// Then TRU channels go from 1 to 112 per branch, 2 branches per ddl
// absId = getTotalNCells() + TRUabsId ;
// relId for TRU
// relid: [DDL id=0..13] [x in 2x2 system: 0..7] [z in 2x2 system 0..27] TODO: verify with real TRU data!!!
// relid: [DDL id=0..13] [x in 2x2 system: 1..8] [z in 2x2 system 1..28] TODO: verify with real TRU data!!!

// these initialisations are needed for a singleton
Geometry* Geometry::sGeom = nullptr;
Expand Down Expand Up @@ -71,44 +71,45 @@ bool Geometry::absToRelNumbering(short absId, char* relid)
// relid[2] = Column number inside a PHOS module (Phi coordinate)
const short nZ = 56; // nStripZ * nCellsZInStrip
const short nPhi = 64; // nStripZ * nCellsZInStrip

short phosmodulenumber = (absId - 1) / (nZ * nPhi);
absId--;
short phosmodulenumber = absId / (nZ * nPhi);

relid[0] = phosmodulenumber + 1;
absId -= phosmodulenumber * nPhi * nZ;
relid[1] = 1 + (absId - 1) / nZ;
relid[2] = absId - (relid[1] - 1) * nZ;
relid[1] = 1 + absId / nZ;
relid[2] = absId - (relid[1] - 1) * nZ + 1;

return true;
}
bool Geometry::truAbsToRelNumbering(short truId, char* relid)
{
//convert trigger cell Id to
truId--;
relid[0] = truId / 224; //2*112 channels // DDL id
truId = truId % 224;
relid[1] = truId % 8; // x index in TRU internal 2x2 coordinate system
relid[2] = truId / 8; // z index in TRU internal 2x2 coordinate system
relid[1] = 1 + truId % 8; // x index in TRU internal 2x2 coordinate system
relid[2] = 1 + truId / 8; // z index in TRU internal 2x2 coordinate system
return true;
}
short Geometry::truRelToAbsNumbering(const char* relId)
{
return relId[0] * 224 + // the offset of PHOS modules
relId[1] + // the offset along phi
relId[2] * 8; // the offset along z
return relId[0] * 224 + // the offset of PHOS modules
relId[1] - 1 + // the offset along phi
(relId[2] - 1) * 8; // the offset along z
}
bool Geometry::truRelId2RelId(const char* truRelId, char* relId)
{
relId[0] = 1 + (truRelId[0] + 2) / 4;
relId[1] = ((truRelId[0] + 2) % 4) * 16 + truRelId[1] * 2 + 1;
relId[2] = truRelId[2] * 2 + 1;
relId[1] = ((truRelId[0] + 2) % 4) * 16 + truRelId[1] * 2 - 1;
relId[2] = truRelId[2] * 2 - 1;
return true;
}
short Geometry::relPosToTruId(char mod, float x, float z, short& ddl)
{
//tranform local cluster coordinates to truId
char relid[3] = {mod, static_cast<char>(ceil(x / CELLSTEP + 32.5)), static_cast<char>(ceil(z / CELLSTEP + 28.5))};
ddl = (mod - 1) * 4 + relid[1] / 16 - 2;
char truid[3] = {static_cast<char>(ddl), static_cast<char>((relid[1] % 16) / 2), static_cast<char>(relid[2] / 2)};
char truid[3] = {static_cast<char>(ddl), static_cast<char>(1 + ((relid[1] - 1) % 16) / 2), static_cast<char>(1 + (relid[2] - 1) / 2)};
return truRelToAbsNumbering(truid);
}

Expand Down
8 changes: 4 additions & 4 deletions Detectors/PHOS/base/src/Mapping.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ Mapping::ErrorStatus Mapping::absIdTohw(short absId, short caloFlag, short& ddl,
return kNotInitialized;
}

ddl = mAbsToHW[absId][caloFlag][0];
hwAddr = mAbsToHW[absId][caloFlag][1];
ddl = mAbsToHW[absId - 1][caloFlag][0];
hwAddr = mAbsToHW[absId - 1][caloFlag][1];
return kOK;
}
//_______________________________________________________
Expand Down Expand Up @@ -205,8 +205,8 @@ Mapping::ErrorStatus Mapping::setMapping()

mAbsId[ddl][hwAddress] = absId;
mCaloFlag[ddl][hwAddress] = (CaloFlag)caloFlag;
mAbsToHW[absId][caloFlag][0] = ddl;
mAbsToHW[absId][caloFlag][1] = hwAddress;
mAbsToHW[absId - 1][caloFlag][0] = ddl;
mAbsToHW[absId - 1][caloFlag][1] = hwAddress;
}
fIn.close();
} //RCU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,18 @@ class PHOSPedestalCalibDevice : public o2::framework::Task

private:
bool mUseCCDB = false;
bool mForceUpdate = false; /// Update CCDB even if difference to current is large
bool mUpdateCCDB = true; /// set is close to current and can update it
static constexpr short kMinorChange = 10; /// ignore if number of channels changed smaller than...
long mRunStartTime = 0; /// start time of the run (sec)
std::string mCCDBPath{"http://ccdb-test.cern.ch:8080"}; /// CCDB path to retrieve current CCDB objects for comparison
std::unique_ptr<Pedestals> mPedestals; //! Final calibration object
std::unique_ptr<Pedestals> mOldPed; //! Pedestals currently stored in CCDB for comparisoin
std::unique_ptr<TH2F> mMeanHG; //! Mean values in High Gain channels
std::unique_ptr<TH2F> mMeanLG; //! RMS of values in High Gain channels
std::unique_ptr<TH2F> mRMSHG; //! Mean values in Low Gain channels
std::unique_ptr<TH2F> mRMSLG; //! RMS of values in Low Gain channels
std::array<short, o2::phos::Mapping::NCHANNELS> mPedHGDiff; //! Pedestal variation wrt previous map
std::array<short, o2::phos::Mapping::NCHANNELS> mPedLGDiff; //! Pedestal variation wrt previous map
bool mForceUpdate = false; /// Update CCDB even if difference to current is large
bool mUpdateCCDB = true; /// set is close to current and can update it
static constexpr short kMinorChange = 10; /// ignore if number of channels changed smaller than...
long mRunStartTime = 0; /// start time of the run (sec)
std::string mCCDBPath{"http://ccdb-test.cern.ch:8080"}; /// CCDB path to retrieve current CCDB objects for comparison
std::unique_ptr<Pedestals> mPedestals; //! Final calibration object
std::unique_ptr<Pedestals> mOldPed; //! Pedestals currently stored in CCDB for comparisoin
std::unique_ptr<TH2F> mMeanHG; //! Mean values in High Gain channels
std::unique_ptr<TH2F> mMeanLG; //! RMS of values in High Gain channels
std::unique_ptr<TH2F> mRMSHG; //! Mean values in Low Gain channels
std::unique_ptr<TH2F> mRMSLG; //! RMS of values in Low Gain channels
std::array<short, 2 * o2::phos::Mapping::NCHANNELS + 1> mPedDiff; //! Pedestal variation wrt previous map
};

o2::framework::DataProcessorSpec getPedestalCalibSpec(bool useCCDB, bool forceUpdate, std::string path);
Expand Down
26 changes: 10 additions & 16 deletions Detectors/PHOS/calib/src/PHOSHGLGRatioCalibDevice.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ void PHOSHGLGRatioCalibDevice::init(o2::framework::InitContext& ic)
{

//Create histograms for mean and RMS
short n = o2::phos::Mapping::NCHANNELS;
mhRatio.reset(new TH2F("HGLGRatio", "HGLGRatio", n, 0.5, n + 0.5, 100, 10., 20.));
short n = o2::phos::Mapping::NCHANNELS - 1792;
mhRatio.reset(new TH2F("HGLGRatio", "HGLGRatio", n, 1792.5, n + 1792.5, 100, 10., 20.));
mCalibParams.reset(new CalibParams());
}

Expand Down Expand Up @@ -115,7 +115,7 @@ void PHOSHGLGRatioCalibDevice::calculateRatios()
}
tmp->Fit(fitFunc, "QL0", "", 0., 20.);
float a = fitFunc->GetParameter(1);
mCalibParams->setHGLGRatio(i - 1, a); //absId starts from 0
mCalibParams->setHGLGRatio(i, a); //absId starts from 0
tmp->Delete();
}
}
Expand Down Expand Up @@ -174,7 +174,7 @@ void PHOSHGLGRatioCalibDevice::sendOutput(DataAllocator& output)
{

// extract CCDB infos and calibration objects, convert it to TMemFile and send them to the output
if (mUseCCDB && (mUpdateCCDB || mForceUpdate)) {
if (mUpdateCCDB || mForceUpdate) {
// prepare all info to be sent to CCDB
auto flName = o2::ccdb::CcdbApi::generateFileName("CalibParams");
std::map<std::string, std::string> md;
Expand All @@ -193,27 +193,21 @@ void PHOSHGLGRatioCalibDevice::sendOutput(DataAllocator& output)
}
//Anyway send change to QC
LOG(INFO) << "[PHOSHGLGRatioCalibDevice - sendOutput] Sending QC ";
if (mUseCCDB) { //can get previous calibration
output.snapshot(o2::framework::Output{"PHS", "HGLGRATIODIFF", 0, o2::framework::Lifetime::Timeframe}, mRatioDiff);
}
output.snapshot(o2::framework::Output{"PHS", "CALIBDIFF", 0, o2::framework::Lifetime::Timeframe}, mRatioDiff);
}

DataProcessorSpec o2::phos::getHGLGRatioCalibSpec(bool useCCDB, bool forceUpdate, std::string path)
{

std::vector<InputSpec> inputs;
inputs.emplace_back("cells", o2::header::gDataOriginPHS, "CELLS", 0, o2::framework::Lifetime::Timeframe);
inputs.emplace_back("cellTriggerRecords", o2::header::gDataOriginPHS, "CELLTRIGREC", 0, o2::framework::Lifetime::Timeframe);
inputs.emplace_back("cells", ConcreteDataTypeMatcher{o2::header::gDataOriginPHS, "CELLS"}, o2::framework::Lifetime::Timeframe);
inputs.emplace_back("cellTriggerRecords", ConcreteDataTypeMatcher{o2::header::gDataOriginPHS, "CELLTRIGREC"}, o2::framework::Lifetime::Timeframe);

using clbUtils = o2::calibration::Utils;
std::vector<OutputSpec> outputs;
if (useCCDB) {
outputs.emplace_back(
ConcreteDataTypeMatcher{clbUtils::gDataOriginCDBPayload, "PHOS_HGLGratio"});
outputs.emplace_back(
ConcreteDataTypeMatcher{clbUtils::gDataOriginCDBWrapper, "PHOS_HGLGratio"});
outputs.emplace_back("PHS", "HGLGRATIODIFF", 0, o2::framework::Lifetime::Timeframe);
}
outputs.emplace_back(o2::header::gDataOriginPHS, "CALIBDIFF", 0, o2::framework::Lifetime::Timeframe);
outputs.emplace_back(ConcreteDataTypeMatcher{clbUtils::gDataOriginCDBPayload, "PHOS_HGLGratio"});
outputs.emplace_back(ConcreteDataTypeMatcher{clbUtils::gDataOriginCDBWrapper, "PHOS_HGLGratio"});
return o2::framework::DataProcessorSpec{"HGLGRatioCalibSpec",
inputs,
outputs,
Expand Down
Loading