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 c_histmd_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 c_hist_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 c_hist_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 c_hist_skimphi[ic] =
new TCanvas(Form(
"CDC/c_hist_skimphi_c%d", ic), Form(
"hist_skimphi_c%d", ic), 500, 400);
71 c_hist_crphi =
new TCanvas(
"CDC/c_hist_crphi",
"c_hist_crphi", 500, 400);
72 c_hist_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 c_hist_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 c_hist_attach_eff[0] =
new TCanvas(
"CDC/c_hist_attached_wires",
"c_hist_attached_wires", 403, 400);
103 c_hist_attach_eff[1] =
new TCanvas(
"CDC/c_hist_expected_wires",
"c_hist_expected_wires", 403, 400);
104 c_hist_attach_eff[2] =
new TCanvas(
"CDC/c_hist_attach_eff",
"c_hist_attach_eff", 403, 400);
105 c_hist_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;
267 if (!std::isfinite(y_max) || y_max <= 0 || y_max > 1e3)y_max = 1;
273 line->SetY2(y_max * 1.20);
286 double sumadcgood = 0;
287 for (
unsigned ic = 0; ic <
kNumBoards; ++ic) {
288 if (ic == 0)
continue;
290 m_hists_bADC[ic] = m_delta_adc->ProjectionY(Form(
"histmd_tdc_board%d", ic + 1), ic + 1, ic + 1,
"");
291 m_hists_bADC[ic]->SetTitle(Form(
"histmd_adc_board%d", ic));
296 if (md_adc >= minadc && md_adc <= maxadc) {
297 sumadcgood = sumadcgood + md_adc;
301 double adcfrac = cadcgood / 2.99;
306 if (cadcgood > 0)sumadcgood = sumadcgood * 1.0 / cadcgood;
308 m_hist_adc->SetTitle(Form(
"ADC Medians: Bad board count = %d (%0.01f%%)", cadcbad - 1, 100.0 - adcfrac));
324 double sumtdcgood = 0;
325 for (
unsigned ic = 0; ic <
kNumBoards; ++ic) {
326 if (ic == 0)
continue;
328 m_hists_bTDC[ic] = m_delta_tdc->ProjectionY(Form(
"histmd_tdc_board%d", ic + 1), ic + 1, ic + 1,
"");
329 m_hists_bTDC[ic]->SetTitle(Form(
"histmd_tdc_board%d", ic));
334 if (md_tdc >= mintdc && md_tdc <= maxtdc) {
336 sumtdcgood = sumtdcgood + md_tdc;
339 double tdcfrac = ctdcgood / 2.99;
343 if (ctdcgood > 0)sumtdcgood = sumtdcgood * 1.0 / ctdcgood;
345 m_hist_tdc->SetTitle(Form(
"TDC Medians: Bad board count = %d (%0.01f%%)", ctdcbad - 1, 100.0 - tdcfrac));
357 if (m_delta_skimphi) {
358 TString sip[2] = {
"OffIP",
"IP"};
359 TString sname[4] = {
"all",
"bhabha",
"hadron",
"mumutrk"};
360 for (
int j = 0; j < 2; j++) {
361 for (
int i = 0; i < 4; i++) {
363 TString hname = TString::Format(
"histphi_%s_%sevt", sip[j].Data(), sname[i].Data());
364 m_hist_skimphi[k] = m_delta_skimphi->ProjectionX(hname, k + 1, k + 1,
"");
365 m_hist_skimphi[k]->SetTitle(TString::Format(
"cdc-track #phi (%s, %s-events);#phi;entries", sip[j].Data(), sname[i].Data()));
378 if (m_delta_skimphi) {
380 bool isFew =
false, isAlarm =
false, isWarn =
false;
381 m_hist_crphi = m_delta_skimphi->ProjectionX(
"histphi_ip_hadrons", 7, 7,
"");
382 m_hist_crphi->SetTitle(
"cdc-track #phi (IP + hadrons);cdc-track #phi;norm entries");
386 if (maxnow < 10000) {
393 if (nbinref == nbinnow) {
399 for (
int iphi = 0; iphi < nbinnow; iphi++) {
403 if (icref > 0) phidiff = fabs(icnow - icref) / icref;
409 if (warnCount >= minBins) isWarn =
true;
410 if (alarmCount >= minBins) isAlarm =
true;
411 double warnFrac = 100.0 * warnCount / nbinnow;
412 double alarmFrac = 100.0 * alarmCount / nbinnow;
414 Form(
"%s [warn bins %.1f%%, alarm bins %.1f%% | crit: %.1f%% bins]",
440 if (m_delta_effphi) {
443 const int all_phibins = m_delta_effphi->GetNbinsX();
444 const int all_hitbins = m_delta_effphi->GetNbinsY();
445 const int thr_hitbin = m_delta_effphi->GetYaxis()->FindBin(20);
446 for (
int iphi = 0; iphi < all_phibins; iphi++) {
447 TH1D* temp = (TH1D*)m_delta_effphi->ProjectionY(Form(
"hhits_bin_%d", iphi + 1), iphi + 1, iphi + 1,
"");
448 Double_t num = temp->Integral(thr_hitbin, all_hitbins);
449 Double_t den = temp->Integral();
450 if (den > 0)eff = num * 100.0 / den;
456 m_hist_effphi->SetTitle(
"CDC track efficiency(cdchits>20/all); cdc-track #phi; tracking efficiency");
468 if (m_delta_hitphi) {
470 m_delta_hitphi->SetTitle(
"CDC track #phi vs cdchits; cdc-track #phi; nCDCHits");
473 m_delta_hitphi->Draw(
"COLZ");
479 double meanWireAttachProb = 0;
480 double fracWiresWithLowAttachProb = 0;
481 double fracWiresWithHighAttachProb = 0;
482 gStyle->SetNumberContours(100);
484 if (m_delta_efflay) {
488 for (
int ij = 1; ij <= m_delta_efflay->GetNbinsX(); ij++) {
489 int halfYbin = m_delta_efflay->GetNbinsY() / 2;
490 for (
int jk = 0; jk < halfYbin; jk++) {
491 if (m_delta_efflay->GetBinContent(ij, jk + 1) == 0)
continue;
492 double binEffi = m_delta_efflay->GetBinContent(ij, jk + halfYbin + 1) / m_delta_efflay->GetBinContent(ij, jk + 1);
494 meanWireAttachProb += binEffi;
498 if (nEffiValues) meanWireAttachProb /= nEffiValues;
504 latex.SetTextSize(0.025);
505 for (
int ij = 0; ij < 3; ij++) {
515 for (
int ilay = 0; ilay < 56; ilay++) {
516 int rmdr = int(abs(ilay - 2) % 6);
517 if ((rmdr == 0 && ilay > 2) || ilay == 55) {
520 el[isl]->SetLineColor(kRed);
521 el[isl]->SetLineWidth(2);
522 el[isl]->SetFillStyle(0);
523 el[isl]->Draw(
"same");
528 latex.DrawLatexNDC(0.12, 0.87, TString::Format(
"mean = %.3f%%", meanWireAttachProb * 100.0));
539 latex.DrawLatexNDC(0.15, 0.87, TString::Format(
"%06.3f%% wire : eff < %.2f",
540 fracWiresWithLowAttachProb * 100,
542 latex.DrawLatexNDC(0.15, 0.84, TString::Format(
"%06.3f%% wire : %.2f < eff < %.2f",
543 (1. - fracWiresWithHighAttachProb - fracWiresWithLowAttachProb) * 100,
545 latex.DrawLatexNDC(0.15, 0.81, TString::Format(
"%06.3f%% wire : %.2f < eff",
546 fracWiresWithHighAttachProb * 100,
549 for (
int ij = 0; ij < 4; ij++) {
555 m_monObj->setVariable(
"meanWireAttachProb", meanWireAttachProb);
556 m_monObj->setVariable(
"fracWiresWithLowAttachProb", fracWiresWithLowAttachProb);
557 m_monObj->setVariable(
"fracWiresWithHighAttachProb", fracWiresWithHighAttachProb);
559 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: end event");
565 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: end run");
572 for (
auto* line :
m_lines)
delete line;
574 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: terminate called");
583 TH1D* hist = (TH1D*)h->Clone();
584 hist->SetBinContent(1, 0.0);
586 if (hist->Integral(1, hist->GetNbinsX()) > 0) {
588 double probSums[1] = {0.5};
589 hist->GetQuantiles(1, quantiles, probSums);
590 if (std::isfinite(quantiles[0]))median = quantiles[0];
603 std::vector<double> binEdges(nSLayers + 1);
607 binEdges[0] = firstR - (secondR - firstR) / 2;
609 for (
int lay = 1; lay < nSLayers; lay++) {
612 binEdges[lay] = (prevR + currentR) / 2;
615 double lastR = cdcgeo.
senseWireR(nSLayers - 1);
616 double secondLastR = cdcgeo.
senseWireR(nSLayers - 2);
617 binEdges[nSLayers] = lastR + (lastR - secondLastR) / 2;
619 TH1F layerHist(
"layerHist",
"Layer Histogram", nSLayers, binEdges.data());
621 for (
int binx = 1; binx <= efficiency->GetNbinsX(); binx++) {
622 for (
int biny = 1; biny <= efficiency->GetNbinsY(); biny++) {
623 double bincenterx = efficiency->GetXaxis()->GetBinCenter(binx);
624 double bincentery = efficiency->GetYaxis()->GetBinCenter(biny);
625 double r = TMath::Sqrt(bincenterx * bincenterx + bincentery * bincentery);
626 double phi = TMath::ATan2(bincentery, bincenterx);
627 if (phi < 0) phi += 2 * TMath::Pi();
629 int layerBin = layerHist.FindBin(r);
630 if (layerBin < 1 || layerBin > nSLayers)
continue;
631 int layerExpected = layerBin - 1;
634 double offset = cdcgeo.
offset(layerExpected);
635 int wireExpected = phi * nWires / (2 * TMath::Pi()) - offset + 0.5;
636 if (wireExpected < 0) wireExpected += nWires;
637 if (wireExpected >= nWires) wireExpected -= nWires;
639 int expBin = hist->GetYaxis()->FindBin(layerExpected);
640 int obsBin = expBin + nSLayers;
641 expected->SetBinContent(binx, biny, hist->GetBinContent(wireExpected + 1, expBin));
642 attached->SetBinContent(binx, biny, hist->GetBinContent(wireExpected + 1, obsBin));
645 efficiency->Divide(attached, expected);
652 double maxLayerR = cdcgeo.
senseWireR(nSLayers - 1);
653 TH2Poly* hist =
new TH2Poly(name, title, -maxLayerR * 1.02, maxLayerR * 1.02, -maxLayerR * 1.02, maxLayerR * 1.02);
654 for (
int lay = 0; lay < nSLayers; lay++) {
656 double offset = cdcgeo.
offset(lay);
663 }
else if (lay == nSLayers - 1) {
670 for (
int wire = 0; wire < nWires; wire++) {
671 double phi_inner = (wire - 0.5 + offset) * 2 * TMath::Pi() / nWires;
672 double phi_outer = (wire + 0.5 + offset) * 2 * TMath::Pi() / nWires;
674 double x0 = r_inner * TMath::Cos(phi_inner);
675 double y0 = r_inner * TMath::Sin(phi_inner);
676 double x1 = r_outer * TMath::Cos(phi_inner);
677 double y1 = r_outer * TMath::Sin(phi_inner);
678 double x2 = r_outer * TMath::Cos(phi_outer);
679 double y2 = r_outer * TMath::Sin(phi_outer);
680 double x3 = r_inner * TMath::Cos(phi_outer);
681 double y3 = r_inner * TMath::Sin(phi_outer);
682 double xx[] = {x0, x1, x2, x3};
683 double yy[] = {y0, y1, y2, y3};
684 hist->AddBin(4, xx, yy);
692 attached->Reset(
"ICES");
693 expected->Reset(
"ICES");
696 for (
int lay = 0; lay < nSLayers; lay++) {
699 double offset = cdcgeo.
offset(lay);
700 int expBin = hist->GetYaxis()->FindBin(lay);
701 int obsBin = expBin + nSLayers;
703 for (
int wire = 0; wire < nWires; wire++) {
704 double phi = (wire + offset) * 2 * TMath::Pi() / nWires;
705 double fillX = layerR * TMath::Cos(phi);
706 double fillY = layerR * TMath::Sin(phi);
707 attached->Fill(fillX, fillY, hist->GetBinContent(wire + 1, obsBin));
708 expected->Fill(fillX, fillY, hist->GetBinContent(wire + 1, expBin));
711 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 * c_hist_adc
canvas for adc board median
TCanvas * c_hist_skimphi[8]
canvas for various phi distribution
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
TCanvas * c_histmd_ladc
canvas for adc layer median
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
TCanvas * c_hist_effphi
canvas for tracking efficiency
std::string m_hname_idxphi
Phi Inedx histogram names.
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
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
std::string m_histoTrackingWireEff
Wire Eff histogram names.
TFile * m_fileRefPhi
reference histogram file point
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.
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
void getHistStyle(TH1F *&htemp, std::string label, double max) const
get histogram styles
MonitoringObject * m_monObj
monitoring object
TCanvas * c_hist_crphi
canvas for control shifter phi
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
TCanvas * c_hist_tdc
canvas for tdc board median
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.
TCanvas * c_hist_hitsphi
expert canvas for hits vs phi
double m_minphibinsfrac
min phi diff fraction for alarms
TH2Poly * m_hist_attach_eff_Poly[3]
for above
TH1D * m_hist_effphi
for above
TCanvas * c_hist_attach_eff[4]
canvas for layer efficiency
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
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
float getHistMedian(TH1D *h) const
Get median of given histogram.
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.