9#include <dqm/analysis/modules/DQMHistAnalysisCDCEpics.h>
10#include <cdc/geometry/CDCGeometryPar.h>
26 addParam(
"RefFilePhi",
m_fname_refphi,
"Reference histogram file name", std::string(
"CDCDQM_PhiRef.root"));
40 for (
int i = 0; i < 300; i++) {
47 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: Constructor done.");
54 m_canv_md_ladc =
new TCanvas(
"CDC/c_histmd_ladc",
"c_histmd_ladc", 500, 400);
55 m_histmd_ladc =
new TH1F(
"CDC/histmd_ladc",
"m_histmd_ladc", 56, 0, 56);
56 m_histmd_ladc->SetTitle(
"ADC Medians vs Layers (SL-lines); CDC Layer index; ADC medians");
58 m_canv_adc =
new TCanvas(
"CDC/c_hist_adc",
"c_hist_adc", 500, 400);
59 m_hist_adc =
new TH1F(
"CDC/hist_adc",
"m_hist_adc", 300, 0, 300);
60 m_hist_adc->SetTitle(
"ADC Medians; CDC board index; ADC medians");
62 m_canv_tdc =
new TCanvas(
"CDC/c_hist_tdc",
"c_hist_tdc", 500, 400);
63 m_hist_tdc =
new TH1F(
"CDC/hist_tdc",
"m_hist_tdc", 300, 0, 300);
64 m_hist_tdc->SetTitle(
"TDC Medians; CDC board index; TDC medians");
67 for (
int ic = 0; ic < 8; ic++) {
68 m_canv_skimphi[ic] =
new TCanvas(Form(
"CDC/c_hist_skimphi_c%d", ic), Form(
"hist_skimphi_c%d", ic), 500, 400);
71 m_canv_crphi =
new TCanvas(
"CDC/c_hist_crphi",
"c_hist_crphi", 500, 400);
72 m_canv_hitsphi =
new TCanvas(
"CDC/c_hist_hitsphi",
"c_hist_hitsphi", 500, 400);
78 B2INFO(
"DQMHistAnalysisCDCEpics: reference (" <<
m_fname_refphi <<
") found OK");
81 else B2INFO(
"\t ..and (cdcdqm_phiref) also exist");
89 auto* line =
new TLine(bin, 0, bin, 1.0);
90 line->SetLineStyle(2);
91 if (bin >= 8 && bin < 14)line->SetLineColor(kRed);
92 else if (bin >= 20 && bin < 26)line->SetLineColor(kGreen);
93 else if (bin >= 32 && bin < 38)line->SetLineColor(kRed);
94 else if (bin >= 44 && bin < 50)line->SetLineColor(kGreen);
95 else line->SetLineColor(kGray);
99 m_canv_effphi =
new TCanvas(
"CDC/c_hist_effphi",
"c_hist_effphi", 500, 400);
100 m_hist_effphi =
new TH1D(
"CDC/hist_effphi",
"m_hist_effphi", 180, -180.0, 180.0);
102 m_canv_attach_eff[0] =
new TCanvas(
"CDC/c_hist_attached_wires",
"c_hist_attached_wires", 403, 400);
103 m_canv_attach_eff[1] =
new TCanvas(
"CDC/c_hist_expected_wires",
"c_hist_expected_wires", 403, 400);
104 m_canv_attach_eff[2] =
new TCanvas(
"CDC/c_hist_attach_eff",
"c_hist_attach_eff", 403, 400);
105 m_canv_attach_eff[3] =
new TCanvas(
"CDC/c_hist_attach_eff_1d",
"c_hist_attach_eff_1d", 403, 400);
108 "hist_attachedWires (backplate view);X [cm];Y [cm]; Track / bin");
112 m_hist_attach_eff_Poly[1]->SetNameTitle(
"CDC/hist_expectedWires",
"hist_expectedWires (backplate view);X [cm];Y [cm]; Track / bin");
115 m_hist_attach_eff_Poly[2]->SetNameTitle(
"CDC/hist_wireAttachEff",
"hist_wireAttachEff (backplate view);X [cm];Y [cm]; Efficiency");
120 double maxLayerR = cdcgeo.
senseWireR(nSLayers - 1);
121 m_hist_attach_eff[0] =
new TH2F(
"CDC/hist_attachedWires",
"hist_attachedWires (backplate view);X [cm];Y [cm]; Track / bin",
122 nSLayers * 6, -maxLayerR * 1.02, maxLayerR * 1.02,
123 nSLayers * 6, -maxLayerR * 1.02, maxLayerR * 1.02);
126 m_hist_attach_eff[1]->SetNameTitle(
"CDC/hist_expectedWires",
"hist_expectedWires (backplate view);X [cm];Y [cm]; Track / bin");
128 m_hist_attach_eff[2]->SetNameTitle(
"CDC/hist_wireAttachEff",
"hist_wireAttachEff (backplate view);X [cm];Y [cm]; Efficiency");
130 m_hist_wire_attach_eff_1d =
new TH1F(
"CDC/hist_wire_attach_eff_1d",
"hist_wire_attach_eff_1d;Wire Efficiency;Wire / bin",
200 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: initialized.");
246 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: beginRun run called");
255 for (
unsigned il = 0; il <
kNumLayers; ++il) {
257 m_hists_lADC[il] = m_delta_ladc->ProjectionY(Form(
"histmd_adc_layer%d", il + 1), il + 1, il + 1,
"");
258 m_hists_lADC[il]->SetTitle(Form(
"histmd_adc_layer%d", il));
260 if (!std::isfinite(md_ladc) || md_ladc < 0) md_ladc = 0;
269 if (std::isfinite(val) && val > y_max) y_max = val;
271 if (y_max <= 0) y_max = 1;
291 double sumadcgood = 0;
292 for (
unsigned ic = 0; ic <
kNumBoards; ++ic) {
293 if (ic == 0)
continue;
295 m_hists_bADC[ic] = m_delta_adc->ProjectionY(Form(
"histmd_tdc_board%d", ic + 1), ic + 1, ic + 1,
"");
296 m_hists_bADC[ic]->SetTitle(Form(
"histmd_adc_board%d", ic));
301 if (md_adc >= minadc && md_adc <= maxadc) {
302 sumadcgood = sumadcgood + md_adc;
306 double adcfrac = cadcgood / 2.99;
311 if (cadcgood > 0)sumadcgood = sumadcgood * 1.0 / cadcgood;
313 m_hist_adc->SetTitle(Form(
"ADC Medians: Bad board count = %d (%0.01f%%)", cadcbad - 1, 100.0 - adcfrac));
329 double sumtdcgood = 0;
330 for (
unsigned ic = 0; ic <
kNumBoards; ++ic) {
331 if (ic == 0)
continue;
333 m_hists_bTDC[ic] = m_delta_tdc->ProjectionY(Form(
"histmd_tdc_board%d", ic + 1), ic + 1, ic + 1,
"");
334 m_hists_bTDC[ic]->SetTitle(Form(
"histmd_tdc_board%d", ic));
339 if (md_tdc >= mintdc && md_tdc <= maxtdc) {
341 sumtdcgood = sumtdcgood + md_tdc;
344 double tdcfrac = ctdcgood / 2.99;
348 if (ctdcgood > 0)sumtdcgood = sumtdcgood * 1.0 / ctdcgood;
350 m_hist_tdc->SetTitle(Form(
"TDC Medians: Bad board count = %d (%0.01f%%)", ctdcbad - 1, 100.0 - tdcfrac));
362 if (m_delta_skimphi) {
363 TString sip[2] = {
"OffIP",
"IP"};
364 TString sname[4] = {
"all",
"bhabha",
"hadron",
"mumutrk"};
365 for (
int j = 0; j < 2; j++) {
366 for (
int i = 0; i < 4; i++) {
368 TString hname = TString::Format(
"histphi_%s_%sevt", sip[j].Data(), sname[i].Data());
369 m_hist_skimphi[k] = m_delta_skimphi->ProjectionX(hname, k + 1, k + 1,
"");
370 m_hist_skimphi[k]->SetTitle(TString::Format(
"cdc-track #phi (%s, %s-events);#phi;entries", sip[j].Data(), sname[i].Data()));
383 if (m_delta_skimphi) {
385 bool isFew =
false, isAlarm =
false, isWarn =
false;
386 m_hist_crphi = m_delta_skimphi->ProjectionX(
"histphi_ip_hadrons", 7, 7,
"");
388 m_hist_crphi->SetTitle(
"cdc-track #phi (IP + hadrons);cdc-track #phi;norm entries");
391 if (maxnow < 10000) {
398 if (nbinref == nbinnow) {
404 for (
int iphi = 0; iphi < nbinnow; iphi++) {
408 if (icref > 0) phidiff = fabs(icnow - icref) / icref;
414 if (warnCount >= minBins) isWarn =
true;
415 if (alarmCount >= minBins) isAlarm =
true;
416 double warnFrac = 100.0 * warnCount / nbinnow;
417 double alarmFrac = 100.0 * alarmCount / nbinnow;
419 Form(
"%s [warn bins %.1f%%, alarm bins %.1f%% | crit: %.1f%% bins]",
445 if (m_delta_effphi) {
448 const int all_phibins = m_delta_effphi->GetNbinsX();
449 const int all_hitbins = m_delta_effphi->GetNbinsY();
450 const int thr_hitbin = m_delta_effphi->GetYaxis()->FindBin(20);
451 for (
int iphi = 0; iphi < all_phibins; iphi++) {
452 TH1D* temp =
static_cast<TH1D*
>(m_delta_effphi->ProjectionY(Form(
"hhits_bin_%d", iphi + 1), iphi + 1, iphi + 1,
""));
453 Double_t num = temp->Integral(thr_hitbin, all_hitbins);
454 Double_t den = temp->Integral();
455 if (den > 0)eff = num * 100.0 / den;
461 m_hist_effphi->SetTitle(
"CDC track efficiency(cdchits>20/all); cdc-track #phi; tracking efficiency");
473 if (m_delta_hitphi) {
475 m_delta_hitphi->SetTitle(
"CDC track #phi vs cdchits; cdc-track #phi; nCDCHits");
478 m_delta_hitphi->Draw(
"COLZ");
484 double meanWireAttachProb = 0;
485 double fracWiresWithLowAttachProb = 0;
486 double fracWiresWithHighAttachProb = 0;
487 gStyle->SetNumberContours(100);
489 if (m_delta_efflay) {
493 for (
int ij = 1; ij <= m_delta_efflay->GetNbinsX(); ij++) {
494 int halfYbin = m_delta_efflay->GetNbinsY() / 2;
495 for (
int jk = 0; jk < halfYbin; jk++) {
496 if (m_delta_efflay->GetBinContent(ij, jk + 1) == 0)
continue;
497 double binEffi = m_delta_efflay->GetBinContent(ij, jk + halfYbin + 1) / m_delta_efflay->GetBinContent(ij, jk + 1);
499 meanWireAttachProb += binEffi;
503 if (nEffiValues) meanWireAttachProb /= nEffiValues;
509 latex.SetTextSize(0.025);
510 for (
int ij = 0; ij < 3; ij++) {
520 for (
int ilay = 0; ilay < 56; ilay++) {
521 int rmdr = int(abs(ilay - 2) % 6);
522 if ((rmdr == 0 && ilay > 2) || ilay == 55) {
525 el[isl]->SetLineColor(kRed);
526 el[isl]->SetLineWidth(2);
527 el[isl]->SetFillStyle(0);
528 el[isl]->Draw(
"same");
533 latex.DrawLatexNDC(0.12, 0.87, TString::Format(
"mean = %.3f%%", meanWireAttachProb * 100.0));
544 latex.DrawLatexNDC(0.15, 0.87, TString::Format(
"%06.3f%% wire : eff < %.2f",
545 fracWiresWithLowAttachProb * 100,
547 latex.DrawLatexNDC(0.15, 0.84, TString::Format(
"%06.3f%% wire : %.2f < eff < %.2f",
548 (1. - fracWiresWithHighAttachProb - fracWiresWithLowAttachProb) * 100,
550 latex.DrawLatexNDC(0.15, 0.81, TString::Format(
"%06.3f%% wire : %.2f < eff",
551 fracWiresWithHighAttachProb * 100,
554 for (
int ij = 0; ij < 4; ij++) {
560 m_monObj->setVariable(
"meanWireAttachProb", meanWireAttachProb);
561 m_monObj->setVariable(
"fracWiresWithLowAttachProb", fracWiresWithLowAttachProb);
562 m_monObj->setVariable(
"fracWiresWithHighAttachProb", fracWiresWithHighAttachProb);
564 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: end event");
570 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: end run");
577 for (
auto* line :
m_lines)
delete line;
579 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: terminate called");
588 TH1* hist =
static_cast<TH1*
>(h->Clone());
589 hist->SetBinContent(1, 0.0);
591 if (hist->Integral(1, hist->GetNbinsX()) > 0) {
593 double probSums[1] = {0.5};
594 hist->GetQuantiles(1, quantiles, probSums);
595 if (std::isfinite(quantiles[0]))median = quantiles[0];
608 std::vector<double> binEdges(nSLayers + 1);
612 binEdges[0] = firstR - (secondR - firstR) / 2;
614 for (
int lay = 1; lay < nSLayers; lay++) {
617 binEdges[lay] = (prevR + currentR) / 2;
620 double lastR = cdcgeo.
senseWireR(nSLayers - 1);
621 double secondLastR = cdcgeo.
senseWireR(nSLayers - 2);
622 binEdges[nSLayers] = lastR + (lastR - secondLastR) / 2;
624 TH1F layerHist(
"layerHist",
"Layer Histogram", nSLayers, binEdges.data());
626 for (
int binx = 1; binx <= efficiency->GetNbinsX(); binx++) {
627 for (
int biny = 1; biny <= efficiency->GetNbinsY(); biny++) {
628 double bincenterx = efficiency->GetXaxis()->GetBinCenter(binx);
629 double bincentery = efficiency->GetYaxis()->GetBinCenter(biny);
630 double r = TMath::Sqrt(bincenterx * bincenterx + bincentery * bincentery);
631 double phi = TMath::ATan2(bincentery, bincenterx);
632 if (phi < 0) phi += 2 * TMath::Pi();
634 int layerBin = layerHist.FindBin(r);
635 if (layerBin < 1 || layerBin > nSLayers)
continue;
636 int layerExpected = layerBin - 1;
639 double offset = cdcgeo.
offset(layerExpected);
640 int wireExpected = phi * nWires / (2 * TMath::Pi()) - offset + 0.5;
641 if (wireExpected < 0) wireExpected += nWires;
642 if (wireExpected >= nWires) wireExpected -= nWires;
644 int expBin = hist->GetYaxis()->FindBin(layerExpected);
645 int obsBin = expBin + nSLayers;
646 expected->SetBinContent(binx, biny, hist->GetBinContent(wireExpected + 1, expBin));
647 attached->SetBinContent(binx, biny, hist->GetBinContent(wireExpected + 1, obsBin));
650 efficiency->Divide(attached, expected);
657 double maxLayerR = cdcgeo.
senseWireR(nSLayers - 1);
658 TH2Poly* hist =
new TH2Poly(name, title, -maxLayerR * 1.02, maxLayerR * 1.02, -maxLayerR * 1.02, maxLayerR * 1.02);
659 for (
int lay = 0; lay < nSLayers; lay++) {
661 double offset = cdcgeo.
offset(lay);
668 }
else if (lay == nSLayers - 1) {
675 for (
int wire = 0; wire < nWires; wire++) {
676 double phi_inner = (wire - 0.5 + offset) * 2 * TMath::Pi() / nWires;
677 double phi_outer = (wire + 0.5 + offset) * 2 * TMath::Pi() / nWires;
679 double x0 = r_inner * TMath::Cos(phi_inner);
680 double y0 = r_inner * TMath::Sin(phi_inner);
681 double x1 = r_outer * TMath::Cos(phi_inner);
682 double y1 = r_outer * TMath::Sin(phi_inner);
683 double x2 = r_outer * TMath::Cos(phi_outer);
684 double y2 = r_outer * TMath::Sin(phi_outer);
685 double x3 = r_inner * TMath::Cos(phi_outer);
686 double y3 = r_inner * TMath::Sin(phi_outer);
687 double xx[] = {x0, x1, x2, x3};
688 double yy[] = {y0, y1, y2, y3};
689 hist->AddBin(4, xx, yy);
697 attached->Reset(
"ICES");
698 expected->Reset(
"ICES");
701 for (
int lay = 0; lay < nSLayers; lay++) {
704 double offset = cdcgeo.
offset(lay);
705 int expBin = hist->GetYaxis()->FindBin(lay);
706 int obsBin = expBin + nSLayers;
708 for (
int wire = 0; wire < nWires; wire++) {
709 double phi = (wire + offset) * 2 * TMath::Pi() / nWires;
710 double fillX = layerR * TMath::Cos(phi);
711 double fillY = layerR * TMath::Sin(phi);
712 attached->Fill(fillX, fillY, hist->GetBinContent(wire + 1, obsBin));
713 expected->Fill(fillX, fillY, hist->GetBinContent(wire + 1, expBin));
716 efficiency->Divide(attached, expected);
The Class for CDC Geometry Parameters.
double offset(int layerID) const
Return wire offset in phi direction at endplate.
unsigned nWiresInLayer(int layerId) const
Returns wire numbers in a layer.
ushort getNumberOfSenseLayers() const
Get the number of sense layers.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
double senseWireR(int layerId) const
Returns radius of sense wire in each layer.
TCanvas * m_canv_effphi
canvas for tracking efficiency
TLine * m_line_ltdc_sl28
line for lower TDC window for SL2-8
double m_maxtdc_sl28
max tdc median threshold accepted for SL2-8
void initialize() override final
Initialize the Module.
TH1F * m_hist_wire_attach_eff_1d
for above
TH1D * m_hist_crphi
for above
double m_secondEffBoundary
The second boundary of the efficiency range.
TH1D * m_hist_skimphi[8]
for above
int m_minevt
min events for single intra-run point
std::string m_hname_idxphi
Phi Inedx histogram names.
static void fillEffiTH2Poly(TH2F *hist, TH2Poly *attached, TH2Poly *expected, TH2Poly *efficiency)
Populate the efficiency histograms.
TH1D * m_hists_bADC[kNumBoards]
ADC histograms with track associated hits for each board (0-299)
double m_mintdc_sl01
min tdc median threshold accepted for SL0-1
static TH2Poly * createEffiTH2Poly(const TString &name, const TString &title)
Convenient function to create a TH2Poly based on CDC geometry.
double m_maxadc_sl28
max adc median threshold accepted for SL2-8
std::string m_hname_hitsphi
Phi Hits histogram names.
double m_phiwarn
5% warn thershold for phi differences
TLine * m_line_ladc_sl01
line for lower ADC window for SL0-1
std::string m_name_dir
histogram dir
static float getHistMedian(TH1 *h)
Get median of given histogram.
static void getHistStyle(TH1F *&htemp, const std::string &label, double max)
get histogram styles
std::string m_histoTrackingWireEff
Wire Eff histogram names.
TFile * m_fileRefPhi
reference histogram file point
TCanvas * m_canv_md_ladc
canvas for adc layer median
double m_mintdc_sl28
min tdc median threshold accepted for SL2-8
double m_phialarm
15% alarm thershold for phi differences
TLine * m_line_ltdc_sl01
line for lower TDC window for SL0-1
std::string m_hname_effphi
Phi Eff histogram names.
TCanvas * m_canv_tdc
canvas for tdc board median
double m_maxadc_sl01
max adc median threshold accepted for SL0-1
TH1F * m_hist_adc
for above
TLine * m_line_hadc_sl01
line for higher ADC window for SL0-1
TH2F * m_histref_phiindex
for above
TH1F * m_hist_tdc
for above
double m_lbinEdges[kNumLayers+1]
vector for radius edge 56
MonitoringObject * m_monObj
monitoring object
double m_minadc_sl28
min adc median threshold accepted for SL2-8
TLine * m_line_htdc_sl01
line for higher TDC window for SL0-1
std::string m_fname_refphi
reference file of phi histogram
void terminate() override final
Termination action.
std::string m_name_pvpfx
Prefix of PVs.
void event() override final
intra-run actions (EPICC PVs).
std::vector< TLine * > m_lines
number of CDC layer lines
std::string m_hname_ladc
Layer ADC histogram names.
TH1D * m_hists_lADC[kNumLayers]
ADC histograms with track associated hits for each board (0-299)
bool m_doTH2PolyTrackingWireEff
If true, creates TH2Poly instead of TH2F for TrackingWireEff Histos.
double m_minphibinsfrac
min phi diff fraction for alarms
TH2Poly * m_hist_attach_eff_Poly[3]
for above
TH1D * m_hist_effphi
for above
double m_firstEffBoundary
The first boundary of the efficiency range.
double m_maxtdc_sl01
max tdc median threshold accepted for SL0-1
std::string m_name_refdir
reference histogram dir
void endRun() override final
End-of-run action.
TH1D * m_hist_refphi
for above
TCanvas * m_canv_hitsphi
expert canvas for hits vs phi
void beginRun() override final
Called when entering a new run.
TLine * m_line_htdc_sl28
line for higher TDC window for SL2-8
TH1D * m_hists_bTDC[kNumBoards]
TDC histograms with track associated hits for each board (0-299)
double m_minadc_sl01
min adc median threshold accepted for SL0-1
TLine * m_line_hadc_sl28
line for higher ADC window for SL2-8
TCanvas * m_canv_crphi
canvas for control shifter phi
TCanvas * m_canv_skimphi[8]
canvas for various phi distribution
TCanvas * m_canv_adc
canvas for adc board median
TCanvas * m_canv_attach_eff[4]
canvas for layer efficiency
TH2F * m_hist_attach_eff[3]
for above
TH1F * m_histmd_ladc
for above
DQMHistAnalysisCDCEpicsModule()
Constructor.
TLine * m_line_ladc_sl28
line for lower ADC window for SL2-8
std::string m_hname_btdc
Board TDC histogram names.
std::string m_hname_badc
Board ADC histogram names.
void fillEffiTH2(TH2F *hist, TH2F *attached, TH2F *expected, TH2F *efficiency)
Populate the efficiency histograms.
static bool hasDeltaPar(const std::string &dirname, const std::string &histname)
Check if Delta histogram parameters exist for histogram.
int registerEpicsPV(const std::string &pvname, const std::string &keyname="")
EPICS related Functions.
static MonitoringObject * getMonitoringObject(const std::string &name)
Get MonitoringObject with given name (new object is created if non-existing)
static void addDeltaPar(const std::string &dirname, const std::string &histname, HistDelta::EDeltaType t, int p, unsigned int a=1)
Add Delta histogram parameters.
static void colorizeCanvas(TCanvas *canvas, EStatus status)
Helper function for Canvas colorization.
static void UpdateCanvas(const std::string &name, bool updated=true)
Mark canvas as updated (or not)
TH1 * getDelta(const std::string &fullname, int n=0, bool onlyIfUpdated=true)
Get Delta histogram.
DQMHistAnalysisModule()
Constructor / Destructor.
@ c_StatusTooFew
Not enough entries/event to judge.
@ c_StatusError
Analysis result: Severe issue found.
@ c_StatusWarning
Analysis result: Warning, there may be minor issues.
@ c_StatusGood
Analysis result: Good.
bool requestLimitsFromEpicsPVs(chid id, double &lowerAlarm, double &lowerWarn, double &upperWarn, double &upperAlarm)
Get Alarm Limits from EPICS PV.
void setEpicsPV(const std::string &keyname, double value)
Write value to a EPICS PV.
constexpr unsigned kNumLayers
const CDC numbers for layers, boards and super layers
constexpr unsigned kNumBoards
Total number of CDC Boards.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.