10#include <klm/calibration/KLMChannelStatusAlgorithm.h>
13#include <framework/logging/Logger.h>
28 m_HitMapChannel = results.m_HitMapChannel;
29 m_HitMapModule = results.m_HitMapModule;
30 m_HitMapSector = results.m_HitMapSector;
31 m_HitMapModuleNoHot = results.m_HitMapModuleNoHot;
32 m_HitMapSectorNoHot = results.m_HitMapSectorNoHot;
33 m_ModuleActiveChannelMap = results.m_ModuleActiveChannelMap;
34 m_TotalHitNumber = results.m_TotalHitNumber;
35 m_HitNumberBKLM = results.m_HitNumberBKLM;
36 m_HitNumberEKLM = results.m_HitNumberEKLM;
37 m_HitNumberBKLMNoHot = results.m_HitNumberBKLMNoHot;
38 m_HitNumberEKLMNoHot = results.m_HitNumberEKLMNoHot;
43 if (m_ModuleStatus !=
nullptr)
44 delete m_ModuleStatus;
45 if (m_ChannelStatus !=
nullptr)
46 delete m_ChannelStatus;
62 unsigned int hits, moduleHits, maxHits;
68 std::shared_ptr<TTree> calibrationData;
69 calibrationData = getObjectPtr<TTree>(
"calibration_data");
70 calibrationData->SetBranchAddress(
"channel", &channel);
71 calibrationData->SetBranchAddress(
"hits", &hits);
72 int n = calibrationData->GetEntries();
77 for (
int i = 0; i < n; ++i) {
78 calibrationData->GetEntry(i);
99 channel = klmChannel.getKLMChannelNumber();
113 channel = klmChannel.getKLMChannelNumber();
114 module = klmChannel.getKLMModuleNumber();
115 sector = klmChannel.getKLMSectorNumber();
127 module = klmModule.getKLMModuleNumber();
133 if (moduleHits == 0) {
134 for (; klmChannel != klmNextModule; ++klmChannel) {
141 unsigned int activeChannels = 0;
142 for (; klmChannel != klmNextModule; ++klmChannel) {
151 klmChannel = klmModule;
154 for (; klmChannel != klmNextModule; ++klmChannel) {
160 if (hits > maxHits) {
161 klmChannelMaxHits = klmChannel;
168 moduleHits, activeChannels))
170 moduleHits -= maxHits;
182 channel = klmChannel.getKLMChannelNumber();
185 module = klmChannel.getKLMModuleNumber();
186 sector = klmChannel.getKLMSectorNumber();
198 int activeSectorsBKLM = 0;
199 int activeSectorsEKLM = 0;
201 sector = klmSector.getKLMSectorNumber();
210 double averageHitsActiveSector = 0;
211 if (activeSectorsBKLM > 0) {
216 bklmSector != klmSectors.
endBKLM(); ++bklmSector) {
217 sector = bklmSector.getKLMSectorNumber();
220 if (activeSectorsEKLM > 0) {
225 eklmSector != klmSectors.
endEKLM(); ++eklmSector) {
226 sector = eklmSector.getKLMSectorNumber();
235 bool notEnoughData =
false;
237 module = klmModule.getKLMModuleNumber();
245 unsigned int activeChannels = 0;
246 for (; klmChannel != klmNextModule; ++klmChannel) {
254 double averageHits = double(moduleHits) / activeChannels;
256 if (!notEnoughData) {
257 B2INFO(
"KLM module " << klmModule.getKLMModuleNumber() <<
258 " (subdetector " << klmModule.getSubdetector() <<
259 ", section " << klmModule.getSection() <<
260 ", sector " << klmModule.getSector() <<
261 ", layer " << klmModule.getLayer() <<
262 "): " << moduleHits <<
" hits, average: " << averageHits <<
".");
264 notEnoughData =
true;
267 klmChannel = klmModule;
269 for (; klmChannel != klmNextModule; ++klmChannel)
284 double r = log(hits / averageHitsActiveSector) / log(10.);
286 B2WARNING(
"Number of hits in sector " << sector <<
" (" << hits <<
287 ") strongly deviates from the average (" <<
288 averageHitsActiveSector <<
289 "), the 10-based logarithm of the ratio is " << r <<
".");
309 if (activeChannels == 1) {
316 double r = hits / (double(moduleHits - hits) / (activeChannels - 1));
Base class for calibration algorithms.
void saveCalibration(TClonesArray *data, const std::string &name)
Store DBArray payload with given name with default IOV.
EResult
The result of calibration.
@ c_OK
Finished successfully =0 in Python.
@ c_NotEnoughData
Needs more data =2 in Python.
void clearCalibrationData()
Clear calibration data.
KLMChannelIndex & endEKLM()
Last channel for EKLM.
KLMChannelIndex beginBKLM()
First channel for BKLM.
@ c_IndexLevelSector
Sector.
@ c_IndexLevelLayer
Layer.
@ c_IndexLevelStrip
Strip.
KLMChannelNumber getKLMChannelNumber() const
Get KLM channel number.
void setIndexLevel(enum IndexLevel indexLevel)
Set index level.
KLMChannelIndex & endBKLM()
Last channel for BKLM.
KLMChannelIndex beginEKLM()
First channel for EKLM.
void setChannelData(KLMChannelNumber channel, const T data)
Set channel data.
const T getChannelData(KLMChannelNumber channel) const
Get channel data.
void setDataAllChannels(const T data)
Set data for all channels.
unsigned int m_HitNumberEKLM
Number of hits in EKLM.
KLMChannelStatus * m_ChannelStatus
Channel status.
KLMChannelMapValue< unsigned int > m_HitMapModuleNoHot
Module hit map (no hit channels).
unsigned int m_TotalHitNumber
Total hit number.
KLMChannelMapValue< unsigned int > m_HitMapSectorNoHot
Sector hit map (no hot channels).
KLMChannelMapValue< unsigned int > m_HitMapChannel
Channel hit map.
KLMChannelMapValue< unsigned int > m_ModuleActiveChannelMap
Module active-channel map (number of active channels in module).
unsigned int m_HitNumberBKLM
Number of hits in BKLM.
KLMChannelMapValue< unsigned int > m_HitMapModule
Module hit map.
KLMChannelMapValue< unsigned int > m_HitMapSector
Sector hit map.
unsigned int m_HitNumberBKLMNoHot
Number of hits in BKLM (no hot channels).
unsigned int m_HitNumberEKLMNoHot
Number of hits in EKLM (no hot channels).
KLMChannelStatus * m_ModuleStatus
Module status.
~KLMChannelStatusAlgorithm()
Destructor.
bool markHotChannel(KLMChannelNumber channel, unsigned int moduleHits, int activeChannels)
Mark hot channel.
double m_MinimalAverageHitNumber
Minimal average number of hits per channel required for calibration.
bool m_ForcedCalibration
Whether the calibration is forced (calibrate even for insufficient average number of hits).
const KLMElementNumbers * m_ElementNumbers
Element numbers.
unsigned int m_MinimalModuleHitNumber
Minimal module hit number for module-based calibration.
void calibrateChannel(KLMChannelNumber channel)
Calibrate channel.
double m_MinimalHitNumberRatioHotChannel
Minimal ratio of number of hits in this channel and average over other channels in this module to mar...
unsigned int m_MinimalHitNumberHotChannel
Minimal number of hits to mark to mark the channel as hot.
Results m_Results
Calibration results.
void calibrateSector(KLMSectorNumber sector, double averageHitsActiveSector)
Caliobrate sector.
void calibrateModule(KLMModuleNumber module)
Calibrate module.
KLMChannelStatusAlgorithm()
Constructor.
double m_MaximalLogSectorHitsRatio
Maximal absolute value of the logarithm (base 10) of the ratio of the number of hits in this sector a...
CalibrationAlgorithm::EResult calibrate() override
Calibration.
unsigned int m_MinimalHitNumberSingleHotChannel
Minimal number of hits in a single channel to mark it as hot.
void setChannelStatus(KLMChannelNumber channel, enum ChannelStatus status)
Set channel status.
enum ChannelStatus getChannelStatus(KLMChannelNumber channel) const
Get channel status.
void setStatusAllChannels(enum ChannelStatus status)
Set status for all channels.
@ c_Hot
Hot channel (large background).
@ c_Undetermined
Undetermined (used during calibration).
@ c_Normal
Normally operating channel.
@ c_Dead
Dead channel (no signal).
bool isBKLMChannel(KLMChannelNumber channel) const
Determine whether a given channel is in BKLM.
uint16_t KLMSectorNumber
Sector number.
uint16_t KLMChannelNumber
Channel number.
uint16_t KLMModuleNumber
Module number.
Abstract base class for different kinds of events.