Skip to content

Commit

Permalink
Addition of HV issues algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
comrademarvin authored and pillot committed Jul 9, 2024
1 parent becff59 commit 35b3277
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 19 deletions.
39 changes: 24 additions & 15 deletions Detectors/MUON/MCH/Status/include/MCHStatus/HVStatusCreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@ class HVStatusCreator
using DPVAL = dcs::DataPointValue;
using DPMAP = std::unordered_map<DPID, std::vector<DPVAL>>;

/// @brief internal structure to define a time range
struct TimeRange {
uint64_t begin = 0; ///< beginning of time range
uint64_t end = 0; ///< end of time range

TimeRange(uint64_t begin, uint64_t end) : begin(begin), end(end){}; // default constructor

/**
* @brief check if the time range contains the given time stamp
* @param timestamp time stamp of interest
* @return true if the time stamp is in the time range
*/
bool contains(uint64_t timestamp) const { return timestamp >= begin && timestamp < end; }
};

using BADHVMAP = std::unordered_map<std::string, std::vector<TimeRange>>;

/**
* getter for the internal map of bad HV channels
*/
BADHVMAP getHVIssuesList();

/**
* Find all HV issues and their time ranges
* @param dpMap DCS HV data points from CCDB
Expand Down Expand Up @@ -80,24 +102,11 @@ class HVStatusCreator
}

private:
/// @brief internal structure to define a time range
struct TimeRange {
uint64_t begin = 0; ///< beginning of time range
uint64_t end = 0; ///< end of time range

/**
* @brief check if the time range contains the given time stamp
* @param timestamp time stamp of interest
* @return true if the time stamp is in the time range
*/
bool contains(uint64_t timestamp) const { return timestamp >= begin && timestamp < end; }
};

/// map of bad HV channels with the time ranges concerned
std::unordered_map<std::string, std::vector<TimeRange>> mBadHVTimeRanges{};
BADHVMAP mBadHVTimeRanges{};
std::set<std::string> mCurrentBadHVs{}; ///< current list of bad HV channels
};

} // namespace o2::mch

#endif // O2_MCH_HV_STATUS_CREATOR_H_
#endif // O2_MCH_HV_STATUS_CREATOR_H_
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ namespace o2::mch
*/
struct StatusMapCreatorParam : public o2::conf::ConfigurableParamHelper<StatusMapCreatorParam> {

bool useBadChannels = true; ///< reject bad channels (obtained during pedestal calibration runs)
bool useRejectList = true; ///< use extra rejection list (relative to other bad channels sources)
bool useHV = false; ///< reject channels connected to bad HV sectors
bool useBadChannels = true; ///< reject bad channels (obtained during pedestal calibration runs)
bool useRejectList = true; ///< use extra rejection list (relative to other bad channels sources)
bool useHV = false; ///< reject channels connected to bad HV sectors
double hvLimits[10] = {1550., 1550., 1600., 1600., 1600., 1600., 1600., 1600., 1600., 1600.}; ///< chambers HV thresholds for detecting issues
uint64_t minDuration = 10 * 1000; ///< minimum duration of HV issues in ms

bool isActive() const { return useBadChannels || useRejectList || useHV; }

Expand Down
98 changes: 97 additions & 1 deletion Detectors/MUON/MCH/Status/src/HVStatusCreator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,110 @@
// or submit itself to any jurisdiction.

#include <algorithm>
#include <map>

#include "MCHStatus/HVStatusCreator.h"

#include "MCHConditions/DetectionElement.h"
#include "MCHGlobalMapping/Mapper.h"
#include "MCHStatus/StatusMap.h"
#include "MCHStatus/StatusMapCreatorParam.h"

using DPMAP2 = std::map<std::string, std::map<uint64_t, double>>;

// converts DCS data point value to double HV value
double dpConverter(o2::dcs::DataPointValue v)
{
union Converter {
uint64_t raw_data;
double value;
} converter;
converter.raw_data = v.payload_pt1;
return converter.value;
};

// decode the DCS DPMAP to be processed for HV issues
DPMAP2 decodeDPMAP(const o2::mch::HVStatusCreator::DPMAP& dpMap)
{
DPMAP2 dpsMapPerAlias;

for (const auto& [dpId, dpsHV] : dpMap) {
std::string alias = dpId.get_alias();

if (alias.find("vMon") != std::string::npos) {
auto& dps2 = dpsMapPerAlias[alias];

// copy first point to the beginning of time
auto firstPoint = dpsHV.front();
dps2.emplace(0, dpConverter(firstPoint));

for (const auto& value : dpsHV) {
double valueConverted = dpConverter(value);
dps2.emplace(value.get_epoch_time(), valueConverted);
}

// copy last point to the end of time
auto lastPoint = dpsHV.back();
dps2.emplace(std::numeric_limits<uint64_t>::max(), dpConverter(lastPoint));
}
}

return dpsMapPerAlias;
}

namespace o2::mch
{

void HVStatusCreator::findBadHVs(const DPMAP& dpMap)
{
// clear current list of issues
mBadHVTimeRanges.clear();

// decode the DCS DPMAP
DPMAP2 dpsMapPerAlias = decodeDPMAP(dpMap);

// Find list of HV issues per alias
for (const auto& [alias, dpsHV] : dpsMapPerAlias) {
int chamber = o2::mch::dcs::toInt(o2::mch::dcs::aliasToChamber(alias));
auto chamberThreshold = StatusMapCreatorParam::Instance().hvLimits[chamber];
auto minDuration = StatusMapCreatorParam::Instance().minDuration;

std::vector<TimeRange> hvIssuesList;

uint64_t tStart, tStop = 0;
bool ongoingIssue = false;

for (const auto& [timestamp, valueHV] : dpsHV) {
if (valueHV < chamberThreshold) { // check whether HV point is below set threshold for chamber
if (!ongoingIssue) {
tStart = timestamp;
tStop = tStart;
ongoingIssue = true;
} else {
tStop = timestamp;
}
} else {
if (ongoingIssue) {
tStop = timestamp;
if ((tStop - tStart) > minDuration) { // exclude issues less than set minimum duration parameter
TimeRange newIssue(tStart, tStop);
hvIssuesList.push_back(newIssue);
}
ongoingIssue = false;
}
}
}
// ongoing issue at the end of the object
if (ongoingIssue && ((tStop - tStart) > minDuration)) {
TimeRange newIssue(tStart, tStop);
hvIssuesList.push_back(newIssue);
}

// add issues for the alias if non-empty
if (!hvIssuesList.empty()) {
mBadHVTimeRanges.emplace(alias, hvIssuesList);
}
}
}

bool HVStatusCreator::findCurrentBadHVs(uint64_t timestamp)
Expand Down Expand Up @@ -60,4 +151,9 @@ void HVStatusCreator::updateStatusMap(StatusMap& statusMap)
}
}

} // namespace o2::mch
HVStatusCreator::BADHVMAP HVStatusCreator::getHVIssuesList()
{
return mBadHVTimeRanges;
}

} // namespace o2::mch

0 comments on commit 35b3277

Please sign in to comment.