10 #include <dqm/analysis/modules/DQMHistAnalysisKLM.h>
13 #include <klm/dataobjects/KLMChannelIndex.h>
38 "Threshold X for masked channels: if a channel has an occupancy X times larger than the average, it will be masked.", 100);
40 "Threshold Y for hot channels: if a channel has an occupancy Y times larger than the average, it will be marked as hot (but not masked).",
43 "Threshold Z for log scale view: if a channel has an occupancy Z times larger than the average, canvas shifts to log scale.",
48 "Minimal number of processed events required to print error messages", 10000.);
50 "Minimal number for delta histogram updates", 500000.);
52 addParam(
"RefHistoFile",
m_refFileName,
"Reference histogram file name", std::string(
"KLM_DQM_REF_BEAM.root"));
73 B2FATAL(
"The threshold used for hot channels is larger than the one for masked channels."
102 for (
int j = 0; j < nHistograms; j++) {
103 str =
"strip_hits_subdetector_" +
104 std::to_string(klmSector.getSubdetector()) +
105 "_section_" + std::to_string(klmSector.getSection()) +
106 "_sector_" + std::to_string(klmSector.getSector()) +
107 "_" + std::to_string(j);
116 B2INFO(
"KLM DQMHistAnalysis: reference root file (" <<
m_refFileName <<
") FOUND, able to read ref histograms");
119 B2WARNING(
"KLM DQMHistAnalysis: reference root file (" <<
m_refFileName <<
") not found, or closed");
133 B2FATAL(
"No KLM electronics map.");
145 int hist_max_bin;
double max_position;
148 hist_max_bin = time_rpc->GetMaximumBin();
149 max_position = time_rpc->GetXaxis()->GetBinCenter(hist_max_bin);
154 if (time_scint_bklm) {
155 hist_max_bin = time_scint_bklm->GetMaximumBin();
156 max_position = time_scint_bklm->GetXaxis()->GetBinCenter(hist_max_bin);
161 if (time_scint_eklm) {
162 hist_max_bin = time_scint_eklm->GetMaximumBin();
163 max_position = time_scint_eklm->GetXaxis()->GetBinCenter(hist_max_bin);
171 B2WARNING(
"Either DAQ/Nevent is not found or Nevent = 0.");
180 if (delta !=
nullptr) {
181 auto scale = delta->Integral();
182 if (scale > 0. && histogram->Integral() > 0) scale = histogram->Integral() / delta->Integral();
186 delta->DrawNormalized(
"SAME", scale);
193 int subdetector,
int section,
int sector,
int index,
194 TH1* histogram, TH1* delta, TCanvas* canvas, TLatex& latex)
200 std::map<KLMModuleNumber, double>::iterator it;
202 int channelSubdetector, channelSection, channelSector;
203 int layer, plane, strip;
207 histogram->SetStats(
false);
211 n = histogram->GetXaxis()->GetNbins();
214 TH1* ref_histogram =
nullptr;
215 float ref_average = 0;
217 ref_histogram = (TH1*)
m_refFile->Get(histogram->GetName());
218 if (!ref_histogram) {
219 B2WARNING(
"Unable to find " << histogram->GetName() <<
"in reference file.");
223 if (ref_histogram !=
nullptr) {
224 for (i = 1; i <= n; i++) {
225 double nHitsPerModuleRef = ref_histogram->GetBinContent(i);
226 ref_average = ref_average + nHitsPerModuleRef;
230 for (i = 1; i <= n; i++) {
234 double nHitsPerModule = histogram->GetBinContent(i);
235 average = average + nHitsPerModule;
237 channelNumber, &channelSubdetector, &channelSection, &channelSector,
238 &layer, &plane, &strip);
239 if ((channelSubdetector != subdetector) ||
240 (channelSection != section) ||
241 (channelSector != sector))
242 B2FATAL(
"Inconsistent element numbers.");
244 subdetector, section, sector, layer);
248 module, nHitsPerModule));
250 it->second += nHitsPerModule;
253 unsigned int activeModuleChannels = 0;
256 if (it->second != 0) {
261 moduleNumber, &channelSubdetector, &channelSection, &channelSector, &layer);
265 channelSubdetector, channelSection, channelSector, layer, 1, 1);
268 if (electronicsChannel ==
nullptr)
269 B2FATAL(
"Incomplete KLM electronics map.");
270 str =
"No data from lane " + std::to_string(electronicsChannel->
getLane());
271 latex.DrawLatexNDC(x, y, str.c_str());
276 std::vector<KLMModuleNumber>::iterator ite =
290 if (activeModuleChannels == 0)
292 average /= activeModuleChannels;
293 ref_average /= activeModuleChannels;
294 for (i = 1; i <= n; ++i) {
298 double nHits = histogram->GetBinContent(i);
300 channelNumber, &channelSubdetector, &channelSection, &channelSector,
301 &layer, &plane, &strip);
302 std::string channelStatus =
"Normal";
304 channelStatus =
"Masked";
305 std::vector<KLMModuleNumber>::iterator ite =
311 B2DEBUG(20,
"KLM@MaskMe " << channelNumber);
313 channelStatus =
"Hot";
315 if (channelStatus !=
"Normal") {
318 if (electronicsChannel ==
nullptr)
319 B2FATAL(
"Incomplete BKLM electronics map.");
320 if (channelStatus ==
"Masked") {
321 histogram->SetBinContent(i, 0);
322 if (delta !=
nullptr)
323 delta->SetBinContent(i, 0);
325 str = channelStatus +
" channel: ";
327 str += (
"L" + std::to_string(electronicsChannel->
getLane()) +
328 " A" + std::to_string(electronicsChannel->
getAxis()) +
329 " Ch" + std::to_string(electronicsChannel->
getChannel()));
330 latex.DrawLatexNDC(x, y, str.c_str());
336 histogram->SetMinimum(1);
338 }
else if (ref_histogram !=
nullptr) {
341 histogram->SetMinimum(1);
355 if (subdetector == 1) {
364 for (
int k = 0; k < divisions; k++) {
365 xLine = (histogram->GetXaxis()->GetBinLowEdge(bin) - canvas->GetX1()) / (canvas->GetX2() - canvas->GetX1());
371 if ((section == 2) && (index == 0 || index == 1))
375 for (
int k = 0; k < divisions; k++) {
376 xLine = (histogram->GetXaxis()->GetBinLowEdge(bin) - canvas->GetX1()) / (canvas->GetX2() - canvas->GetX1());
391 histogram->SetStats(
false);
392 histogram->Draw(
"COLZ");
404 const std::string& histName)
407 if (histogram ==
nullptr) {
413 if (canvas ==
nullptr) {
422 if (delta !=
nullptr) {
431 const std::string& histName)
434 if (histogram ==
nullptr) {
439 if (canvas ==
nullptr) {
448 int channelSubdetector, channelSection, channelSector;
449 int layer, plane, strip;
452 channel, &channelSubdetector, &channelSection, &channelSector,
453 &layer, &plane, &strip);
460 histogram->Fill(sectorIndex);
463 histogram->SetStats(
false);
469 const std::string& histName, TLatex& latex)
473 if (histogram ==
nullptr) {
478 if (canvas ==
nullptr) {
482 std::string name, alarm;
483 int moduleSubdetector, moduleSection, moduleSector, moduleLayer;
484 double xAlarm = 0.15;
488 histogram->SetStats(
false);
490 if (histName.find(
"bklm") != std::string::npos) {
494 int bin = maximalLayer * sector + 1;
495 double xLine = histogram->GetXaxis()->GetBinLowEdge(bin);
496 double xText = histogram->GetXaxis()->GetBinLowEdge(bin + maximalLayer / 2);
497 double yText = gPad->GetUymin() + 0.98 * (gPad->GetUymax() - gPad->GetUymin());
499 m_PlaneLine.DrawLine(xLine, gPad->GetUymin(), xLine, gPad->GetUymax());
505 name += std::to_string(sector % 8);
511 canvas->Pad()->SetFillColor(kWhite);
515 module, &moduleSubdetector, &moduleSection, &moduleSector, &moduleLayer);
517 alarm +=
", layer " + std::to_string(moduleLayer);
518 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
522 alarm =
"Call the KLM experts immediately!";
523 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
524 canvas->Pad()->SetFillColor(kRed);
531 for (
int layerGlobal = 1; layerGlobal <= maximalLayer; ++layerGlobal) {
532 int bin = maxPlane * layerGlobal + 1;
533 double xLine = histogram->GetXaxis()->GetBinLowEdge(bin);
534 double xText = histogram->GetXaxis()->GetBinLowEdge(bin - maxPlane / 2);
535 double yText = gPad->GetUymin() + 0.98 * (gPad->GetUymax() - gPad->GetUymin());
536 if (layerGlobal < maximalLayer)
537 m_PlaneLine.DrawLine(xLine, gPad->GetUymin(), xLine, gPad->GetUymax());
540 layerGlobal, §ion, &layer);
545 name += std::to_string(layer);
551 canvas->Pad()->SetFillColor(kWhite);
555 module, &moduleSubdetector, &moduleSection, &moduleSector, &moduleLayer);
557 alarm +=
", layer " + std::to_string(moduleLayer);
558 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
562 alarm =
"Call the KLM experts immediately!";
563 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
564 canvas->Pad()->SetFillColor(kRed);
577 if (not(daqInclusion ==
nullptr)) {
578 int isKlmIncluded = daqInclusion->GetBinContent(daqInclusion->GetXaxis()->FindBin(
"Yes"));
579 if (isKlmIncluded == 0)
587 std::string str, histogramName, canvasName;
589 latex.SetTextColor(kRed);
590 latex.SetTextAlign(11);
598 for (
int j = 0; j < nHistograms; j++) {
599 str =
"strip_hits_subdetector_" +
600 std::to_string(klmSector.getSubdetector()) +
601 "_section_" + std::to_string(klmSector.getSection()) +
602 "_sector_" + std::to_string(klmSector.getSector()) +
603 "_" + std::to_string(j);
606 TH1* histogram =
findHist(histogramName);
608 auto delta =
getDelta(
"", histogramName);
610 if (histogram ==
nullptr) {
611 B2WARNING(
"KLM DQM histogram " << histogramName <<
" is not found.");
615 if (canvas ==
nullptr) {
616 B2WARNING(
"KLM DQM histogram canvas " << canvasName <<
" is not found.");
619 UpdateCanvas(canvas->GetName(), delta !=
nullptr || histogram !=
nullptr);
621 klmSector.getSubdetector(), klmSector.getSection(),
622 klmSector.getSector(), j, histogram, delta, canvas, latex);
627 gStyle->SetPalette(kLightTemperature);
634 for (
int j = 1; j <= maximalLayerNumber; ++j) {
635 str =
"spatial_2d_hits_subdetector_" + std::to_string(subdetector) +
636 "_section_" + std::to_string(section) +
637 "_layer_" + std::to_string(j);
640 TH2F* histogram =
static_cast<TH2F*
>(
findHist(histogramName));
641 if (histogram ==
nullptr) {
642 B2ERROR(
"KLM DQM histogram " << histogramName <<
" is not found.");
646 if (canvas ==
nullptr) {
647 B2ERROR(
"KLM DQM histogram canvas " << canvasName <<
" is not found.");
655 gStyle->SetPalette(kBird);
657 latex.SetTextColor(kBlue);
666 B2DEBUG(20,
"Updating EPICS PVs for DQMHistAnalysisKLM");
670 B2DEBUG(20,
"DQMHistAnalysisKLM: MaskedChannels " <<
m_MaskedChannels.size());
static constexpr int getMaximalLayerNumber()
Get maximal layer number (1-based).
static constexpr int getMaximalSectorGlobalNumber()
Get maximal sector global number.
static int getNStrips(int section, int sector, int layer, int plane)
Get number of strips.
std::string m_refFileName
Reference Histogram Root file name.
TLine m_PlaneLine
TLine for boundary in plane histograms.
double m_ProcessedEvents
Number of processed events.
void initialize() override final
Initializer.
int m_ThresholdForLog
Threshold for log scale.
double m_minEntries
Minimal number of entries for delta histogram update.
int m_MinHitsForFlagging
Minimal number of hits for flagging.
const KLMElementNumbers * m_ElementNumbers
KLM element numbers.
const EKLMElementNumbers * m_EklmElementNumbers
EKLM element numbers.
void processSpatial2DHitEndcapHistogram(uint16_t section, TH2F *histogram, TCanvas *canvas)
Process spatial 2D hits histograms for endcap.
MonitoringObject * m_monObj
Monitoring object.
void deltaDrawer(TH1 *delta, TH1 *histogram, TCanvas *canvas)
Scales and draws desired delta histogram for current canvas.
void processTimeHistogram(const std::string &histName)
Process histogram containing the hit times.
std::vector< uint16_t > m_MaskedChannels
Vector of masked channels.
void terminate() override final
This method is called at the end of the event processing.
void event() override final
This method is called for each event.
int m_ThresholdForHot
Threshold for hot channels.
std::vector< uint16_t > m_DeadBarrelModules
Vector of dead barrel modules.
std::string m_histogramDirectoryName
Name of histogram directory.
double m_MinProcessedEventsForMessagesInput
Input parameter for minimal number of processed events for error messages.
TText m_PlaneText
TText for names in plane histograms.
DBObjPtr< KLMElectronicsMap > m_ElectronicsMap
Electronics map.
DQMHistAnalysisKLMModule()
Constructor.
void endRun() override final
This method is called if the current run ends.
void processPlaneHistogram(const std::string &histName, TLatex &latex)
Process histogram containing the number of hits in plane.
int m_ThresholdForMasked
Threshold for masked channels.
const KLMSectorArrayIndex * m_SectorArrayIndex
KLM sector array index.
void beginRun() override final
Called when entering a new run.
double m_MinProcessedEventsForMessages
Minimal number of processed events for error messages.
std::vector< uint16_t > m_DeadEndcapModules
Vector of dead endcap modules.
double getProcessedEvents()
Get number of processed events.
TLine m_2DHitsLine
TLine for background region in 2d hits histograms.
const KLMChannelArrayIndex * m_ChannelArrayIndex
KLM channel array index.
bool m_IsNullRun
Run type flag for null runs.
void analyseChannelHitHistogram(int subdetector, int section, int sector, int index, TH1 *histogram, TH1 *delta, TCanvas *canvas, TLatex &latex)
Analyse channel hit histogram.
void fillMaskedChannelsHistogram(const std::string &histName)
Fill histogram containing masked channels per sector.
TFile * m_refFile
The pointer to the reference file.
The base class for the histogram analysis module.
TCanvas * findCanvas(TString cname)
Find canvas by name.
int registerEpicsPV(std::string pvname, std::string keyname="", bool update_pvs=true)
EPICS related Functions.
void addDeltaPar(const std::string &dirname, const std::string &histname, HistDelta::EDeltaType t, int p, unsigned int a=1)
Add Delta histogram parameters.
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
TH1 * getDelta(const std::string &fullname, int n=0, bool onlyIfUpdated=true)
Get Delta histogram.
void setEpicsPV(std::string keyname, double value)
Write value to a EPICS PV.
static const std::string & getRunType(void)
Get the Run Type.
static int getEventProcessed(void)
Get the number of processed events.
void UpdateCanvas(std::string name, bool updated=true)
Mark canvas as updated (or not)
static MonitoringObject * getMonitoringObject(const std::string &histname)
Get MonitoringObject with given name (new object is created if non-existing)
int updateEpicsPVs(float timeout)
Update all EPICS PV (flush to network)
static constexpr int getNStripsSector()
Get number of strips in a sector.
static constexpr int getMaximalLayerGlobalNumber()
Get maximal detector layer global number.
int getMaximalDetectorLayerNumber(int section) const
Get maximal detector layer number.
void layerNumberToElementNumbers(int layerGlobal, int *section, int *layer) const
Get element numbers by detector layer global number.
@ c_ForwardSection
Forward.
@ c_BackwardSection
Backward.
static constexpr int getMaximalSectorNumber()
Get maximal sector number.
static constexpr int getMaximalPlaneNumber()
Get maximal plane number.
@ c_IndexLevelSection
Section.
@ c_IndexLevelSector
Sector.
void setIndexLevel(enum IndexLevel indexLevel)
Set index level.
BKLM electronics channel.
int getChannel() const
Get channel.
int getAxis() const
Get axis.
int getLane() const
Get lane.
uint16_t getNumber(uint16_t index) const
Get element number.
uint16_t getIndex(uint16_t number) const
Get element index.
KLMSectorNumber sectorNumberEKLM(int section, int sector) const
Get sector number for EKLM.
KLMChannelNumber channelNumber(int subdetector, int section, int sector, int layer, int plane, int strip) const
Get channel number.
void channelNumberToElementNumbers(KLMChannelNumber channel, int *subdetector, int *section, int *sector, int *layer, int *plane, int *strip) const
Get element numbers by channel number.
unsigned int getNChannelsModule(KLMModuleNumber module) const
Get number of channels in module.
void moduleNumberToElementNumbers(KLMModuleNumber module, int *subdetector, int *section, int *sector, int *layer) const
Get element numbers by module number.
KLMModuleNumber moduleNumber(int subdetector, int section, int sector, int layer) const
Get module number.
KLMSectorNumber sectorNumberBKLM(int section, int sector) const
Get sector number for BKLM.
std::string getSectorDAQName(int subdetector, int section, int sector) const
Get DAQ name for a given sector.
void setDescription(const std::string &description)
Sets the description of the module.
void setVariable(const std::string &var, float val, float upErr=-1., float dwErr=-1)
set value to float variable (new variable is made if not yet existing)
Class to store variables with their name which were sent to the logging service.
TH2 * moduleHitMap(TH1 *hitMap, int moduleID)
Make hit map in HAPD view (12*12 channels)
REG_MODULE(arichBtest)
Register the Module.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
uint16_t KLMSectorNumber
Sector number.
uint16_t KLMChannelNumber
Channel number.
uint16_t KLMSubdetectorNumber
Subdetector number.
uint16_t KLMModuleNumber
Module number.
uint16_t KLMSectionNumber
Section number.
Abstract base class for different kinds of events.