9#include <dqm/analysis/modules/DQMHistAnalysisCDCEpics.h>
10#include <cdc/geometry/CDCGeometryPar.h>
28 addParam(
"RefFilePhi",
m_fname_refphi,
"Reference histogram file name", std::string(
"CDCDQM_PhiRef.root"));
41 for (
int i = 0; i < 300; i++) {
48 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: Constructor done.");
59 c_histmd_ladc =
new TCanvas(
"CDC/c_histmd_ladc",
"c_histmd_ladc", 500, 400);
60 m_histmd_ladc =
new TH1F(
"CDC/histmd_ladc",
"m_histmd_ladc", 56, 0, 56);
61 m_histmd_ladc->SetTitle(
"ADC Medians vs Layers (SL-lines); CDC Layer index; ADC medians");
63 c_hist_adc =
new TCanvas(
"CDC/c_hist_adc",
"c_hist_adc", 500, 400);
64 m_hist_adc =
new TH1F(
"CDC/hist_adc",
"m_hist_adc", 300, 0, 300);
65 m_hist_adc->SetTitle(
"ADC Medians; CDC board index; ADC medians");
67 c_hist_tdc =
new TCanvas(
"CDC/c_hist_tdc",
"c_hist_tdc", 500, 400);
68 m_hist_tdc =
new TH1F(
"CDC/hist_tdc",
"m_hist_tdc", 300, 0, 300);
69 m_hist_tdc->SetTitle(
"TDC Medians; CDC board index; TDC medians");
72 for (
int ic = 0; ic < 8; ic++) {
73 c_hist_skimphi[ic] =
new TCanvas(Form(
"CDC/c_hist_skimphi_c%d", ic), Form(
"hist_skimphi_c%d", ic), 500, 400);
76 c_hist_crphi =
new TCanvas(
"CDC/c_hist_crphi",
"c_hist_crphi", 500, 400);
77 c_hist_hitsphi =
new TCanvas(
"CDC/c_hist_hitsphi",
"c_hist_hitsphi", 500, 400);
83 B2INFO(
"DQMHistAnalysisCDCEpics: reference (" <<
m_fname_refphi <<
") found OK");
86 else B2INFO(
"\t ..and (cdcdqm_phiref) also exist");
94 auto* line =
new TLine(bin, 0, bin, 1.0);
95 line->SetLineStyle(2);
96 if (bin >= 8 && bin < 14)line->SetLineColor(kRed);
97 else if (bin >= 20 && bin < 26)line->SetLineColor(kGreen);
98 else if (bin >= 32 && bin < 38)line->SetLineColor(kRed);
99 else if (bin >= 44 && bin < 50)line->SetLineColor(kGreen);
100 else line->SetLineColor(kGray);
104 c_hist_effphi =
new TCanvas(
"CDC/c_hist_effphi",
"c_hist_effphi", 500, 400);
105 m_hist_effphi =
new TH1D(
"CDC/hist_effphi",
"m_hist_effphi", 360, -180.0, 180.0);
107 c_hist_attach_eff[0] =
new TCanvas(
"CDC/c_hist_attached_wires",
"c_hist_attached_wires", 403, 400);
108 c_hist_attach_eff[1] =
new TCanvas(
"CDC/c_hist_expected_wires",
"c_hist_expected_wires", 403, 400);
109 c_hist_attach_eff[2] =
new TCanvas(
"CDC/c_hist_attach_eff",
"c_hist_attach_eff", 403, 400);
110 c_hist_attach_eff[3] =
new TCanvas(
"CDC/c_hist_attach_eff_1d",
"c_hist_attach_eff_1d", 403, 400);
113 "hist_attachedWires (backplate view);X [cm];Y [cm]; Track / bin");
117 m_hist_attach_eff_Poly[1]->SetNameTitle(
"CDC/hist_expectedWires",
"hist_expectedWires (backplate view);X [cm];Y [cm]; Track / bin");
120 m_hist_attach_eff_Poly[2]->SetNameTitle(
"CDC/hist_wireAttachEff",
"hist_wireAttachEff (backplate view);X [cm];Y [cm]; Efficiency");
125 double maxLayerR = cdcgeo.
senseWireR(nSLayers - 1);
126 m_hist_attach_eff[0] =
new TH2F(
"CDC/hist_attachedWires",
"hist_attachedWires (backplate view);X [cm];Y [cm]; Track / bin",
127 nSLayers * 6, -maxLayerR * 1.02, maxLayerR * 1.02,
128 nSLayers * 6, -maxLayerR * 1.02, maxLayerR * 1.02);
131 m_hist_attach_eff[1]->SetNameTitle(
"CDC/hist_expectedWires",
"hist_expectedWires (backplate view);X [cm];Y [cm]; Track / bin");
133 m_hist_attach_eff[2]->SetNameTitle(
"CDC/hist_wireAttachEff",
"hist_wireAttachEff (backplate view);X [cm];Y [cm]; Efficiency");
135 m_hist_wire_attach_eff_1d =
new TH1F(
"CDC/hist_wire_attach_eff_1d",
"hist_wire_attach_eff_1d;Wire Efficiency;Wire / bin",
187 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: initialized.");
216 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: beginRun run called");
225 for (
unsigned il = 0; il <
kNumLayers; ++il) {
227 m_hists_lADC[il] = m_delta_ladc->ProjectionY(Form(
"histmd_adc_layer%d", il + 1), il + 1, il + 1,
"");
228 m_hists_lADC[il]->SetTitle(Form(
"histmd_adc_layer%d", il));
242 line->SetY2(y_max * 1.20);
255 double sumadcgood = 0;
256 for (
unsigned ic = 0; ic <
kNumBoards; ++ic) {
257 if (ic == 0)
continue;
259 m_hists_bADC[ic] = m_delta_adc->ProjectionY(Form(
"histmd_tdc_board%d", ic + 1), ic + 1, ic + 1,
"");
260 m_hists_bADC[ic]->SetTitle(Form(
"histmd_adc_board%d", ic));
264 sumadcgood = sumadcgood + md_adc;
268 double adcfrac = cadcgood / 2.99;
273 if (cadcgood > 0)sumadcgood = sumadcgood * 1.0 / cadcgood;
275 m_hist_adc->SetTitle(Form(
"ADC Medians: Bad board count = %d (%0.01f%%)", cadcbad - 1, 100.0 - adcfrac));
289 double sumtdcgood = 0;
290 for (
unsigned ic = 0; ic <
kNumBoards; ++ic) {
291 if (ic == 0)
continue;
293 m_hists_bTDC[ic] = m_delta_tdc->ProjectionY(Form(
"histmd_tdc_board%d", ic + 1), ic + 1, ic + 1,
"");
294 m_hists_bTDC[ic]->SetTitle(Form(
"histmd_tdc_board%d", ic));
299 sumtdcgood = sumtdcgood + md_tdc;
302 double tdcfrac = ctdcgood / 2.99;
306 if (ctdcgood > 0)sumtdcgood = sumtdcgood * 1.0 / ctdcgood;
308 m_hist_tdc->SetTitle(Form(
"TDC Medians: Bad board count = %d (%0.01f%%)", ctdcbad - 1, 100.0 - tdcfrac));
318 if (m_delta_skimphi) {
319 TString sip[2] = {
"OffIP",
"IP"};
320 TString sname[4] = {
"all",
"bhabha",
"hadron",
"mumutrk"};
321 for (
int j = 0; j < 2; j++) {
322 for (
int i = 0; i < 4; i++) {
324 TString hname = TString::Format(
"histphi_%s_%sevt", sip[j].Data(), sname[i].Data());
325 m_hist_skimphi[k] = m_delta_skimphi->ProjectionX(hname, k + 1, k + 1,
"");
326 m_hist_skimphi[k]->SetTitle(TString::Format(
"cdc-track #phi (%s, %s-events);#phi;entries", sip[j].Data(), sname[i].Data()));
339 if (m_delta_skimphi) {
341 bool isFew =
false, isAlarm =
false, isWarn =
false;
342 m_hist_crphi = m_delta_skimphi->ProjectionX(
"histphi_ip_hadrons", 7, 7,
"");
343 m_hist_crphi->SetTitle(
"cdc-track #phi (IP + hadrons);cdc-track #phi;norm entries");
347 if (maxnow < 10000) {
354 if (nbinref == nbinnow) {
358 double maxphidiff = 0;
359 double maxphidiff_angle = 0;
360 for (
int iphi = 0; iphi < nbinnow; iphi++) {
363 double phidiff = fabs(icnow - icref);
366 if (phidiff > maxphidiff) {
367 maxphidiff = phidiff;
371 m_hist_crphi->SetTitle(Form(
"%s (diff = %0.03f at %0.1f)",
m_hist_crphi->GetTitle(), maxphidiff, maxphidiff_angle));
392 if (m_delta_effphi) {
395 const int all_phibins = m_delta_effphi->GetNbinsX();
396 const int all_hitbins = m_delta_effphi->GetNbinsY();
397 const int thr_hitbin = m_delta_effphi->GetYaxis()->FindBin(20);
398 for (
int iphi = 0; iphi < all_phibins; iphi++) {
399 TH1D* temp = (TH1D*)m_delta_effphi->ProjectionY(Form(
"hhits_bin_%d", iphi + 1), iphi + 1, iphi + 1,
"");
400 Double_t num = temp->Integral(thr_hitbin, all_hitbins);
401 Double_t den = temp->Integral();
402 if (den > 0)eff = num * 100.0 / den;
408 m_hist_effphi->SetTitle(
"CDC track efficiency(cdchits>20/all); cdc-track #phi; tracking efficiency");
420 if (m_delta_hitphi) {
422 m_delta_hitphi->SetTitle(
"CDC track #phi vs cdchits; cdc-track #phi; nCDCHits");
424 m_delta_hitphi->Draw(
"COLZ");
430 double meanWireAttachProb = 0;
431 double fracWiresWithLowAttachProb = 0;
432 double fracWiresWithHighAttachProb = 0;
433 gStyle->SetNumberContours(100);
435 if (m_delta_efflay) {
439 for (
int ij = 1; ij <= m_delta_efflay->GetNbinsX(); ij++) {
440 int halfYbin = m_delta_efflay->GetNbinsY() / 2;
441 for (
int jk = 0; jk < halfYbin; jk++) {
442 if (m_delta_efflay->GetBinContent(ij, jk + 1) == 0)
continue;
443 double binEffi = m_delta_efflay->GetBinContent(ij, jk + halfYbin + 1) / m_delta_efflay->GetBinContent(ij, jk + 1);
445 meanWireAttachProb += binEffi;
449 if (nEffiValues) meanWireAttachProb /= nEffiValues;
455 latex.SetTextSize(0.025);
456 for (
int ij = 0; ij < 3; ij++) {
466 for (
int ilay = 0; ilay < 56; ilay++) {
467 int rmdr = int(abs(ilay - 2) % 6);
468 if ((rmdr == 0 && ilay > 2) || ilay == 55) {
471 el[isl]->SetLineColor(kRed);
472 el[isl]->SetLineWidth(2);
473 el[isl]->SetFillStyle(0);
474 el[isl]->Draw(
"same");
479 latex.DrawLatexNDC(0.12, 0.87, TString::Format(
"mean = %.3f%%", meanWireAttachProb * 100.0));
490 latex.DrawLatexNDC(0.15, 0.87, TString::Format(
"%06.3f%% wire : eff < %.2f",
491 fracWiresWithLowAttachProb * 100,
493 latex.DrawLatexNDC(0.15, 0.84, TString::Format(
"%06.3f%% wire : %.2f < eff < %.2f",
494 (1. - fracWiresWithHighAttachProb - fracWiresWithLowAttachProb) * 100,
496 latex.DrawLatexNDC(0.15, 0.81, TString::Format(
"%06.3f%% wire : %.2f < eff",
497 fracWiresWithHighAttachProb * 100,
500 for (
int ij = 0; ij < 4; ij++) {
510 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: end event");
516 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: end run");
523 for (
auto* line :
m_lines)
delete line;
525 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: terminate called");
532 TH1D* hist = (TH1D*)h->Clone();
533 hist->SetBinContent(1, 0.0);
535 if (hist->GetMean() != 0) {
537 double quantiles[1] = {0.0};
538 double probSums[1] = {0.5};
539 hist->GetQuantiles(1, quantiles, probSums);
540 median = quantiles[0];
553 std::vector<double> binEdges(nSLayers + 1);
557 binEdges[0] = firstR - (secondR - firstR) / 2;
559 for (
int lay = 1; lay < nSLayers; lay++) {
562 binEdges[lay] = (prevR + currentR) / 2;
565 double lastR = cdcgeo.
senseWireR(nSLayers - 1);
566 double secondLastR = cdcgeo.
senseWireR(nSLayers - 2);
567 binEdges[nSLayers] = lastR + (lastR - secondLastR) / 2;
569 TH1F layerHist(
"layerHist",
"Layer Histogram", nSLayers, binEdges.data());
571 for (
int binx = 1; binx <= efficiency->GetNbinsX(); binx++) {
572 for (
int biny = 1; biny <= efficiency->GetNbinsY(); biny++) {
573 double bincenterx = efficiency->GetXaxis()->GetBinCenter(binx);
574 double bincentery = efficiency->GetYaxis()->GetBinCenter(biny);
575 double r = TMath::Sqrt(bincenterx * bincenterx + bincentery * bincentery);
576 double phi = TMath::ATan2(bincentery, bincenterx);
577 if (phi < 0) phi += 2 * TMath::Pi();
579 int layerBin = layerHist.FindBin(r);
580 if (layerBin < 1 || layerBin > nSLayers)
continue;
581 int layerExpected = layerBin - 1;
584 double offset = cdcgeo.
offset(layerExpected);
585 int wireExpected = phi * nWires / (2 * TMath::Pi()) - offset + 0.5;
586 if (wireExpected < 0) wireExpected += nWires;
587 if (wireExpected >= nWires) wireExpected -= nWires;
589 int expBin = hist->GetYaxis()->FindBin(layerExpected);
590 int obsBin = expBin + nSLayers;
591 expected->SetBinContent(binx, biny, hist->GetBinContent(wireExpected + 1, expBin));
592 attached->SetBinContent(binx, biny, hist->GetBinContent(wireExpected + 1, obsBin));
595 efficiency->Divide(attached, expected);
602 double maxLayerR = cdcgeo.
senseWireR(nSLayers - 1);
603 TH2Poly* hist =
new TH2Poly(name, title, -maxLayerR * 1.02, maxLayerR * 1.02, -maxLayerR * 1.02, maxLayerR * 1.02);
604 for (
int lay = 0; lay < nSLayers; lay++) {
606 double offset = cdcgeo.
offset(lay);
613 }
else if (lay == nSLayers - 1) {
620 for (
int wire = 0; wire < nWires; wire++) {
621 double phi_inner = (wire - 0.5 + offset) * 2 * TMath::Pi() / nWires;
622 double phi_outer = (wire + 0.5 + offset) * 2 * TMath::Pi() / nWires;
624 double x0 = r_inner * TMath::Cos(phi_inner);
625 double y0 = r_inner * TMath::Sin(phi_inner);
626 double x1 = r_outer * TMath::Cos(phi_inner);
627 double y1 = r_outer * TMath::Sin(phi_inner);
628 double x2 = r_outer * TMath::Cos(phi_outer);
629 double y2 = r_outer * TMath::Sin(phi_outer);
630 double x3 = r_inner * TMath::Cos(phi_outer);
631 double y3 = r_inner * TMath::Sin(phi_outer);
632 double xx[] = {x0, x1, x2, x3};
633 double yy[] = {y0, y1, y2, y3};
634 hist->AddBin(4, xx, yy);
642 attached->Reset(
"ICES");
643 expected->Reset(
"ICES");
646 for (
int lay = 0; lay < nSLayers; lay++) {
649 double offset = cdcgeo.
offset(lay);
650 int expBin = hist->GetYaxis()->FindBin(lay);
651 int obsBin = expBin + nSLayers;
653 for (
int wire = 0; wire < nWires; wire++) {
654 double phi = (wire + offset) * 2 * TMath::Pi() / nWires;
655 double fillX = layerR * TMath::Cos(phi);
656 double fillY = layerR * TMath::Sin(phi);
657 attached->Fill(fillX, fillY, hist->GetBinContent(wire + 1, obsBin));
658 expected->Fill(fillX, fillY, hist->GetBinContent(wire + 1, expBin));
661 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
void initialize() override final
Initialize the Module.
double m_minadc
min adc median thershold accepted
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
TLine * m_line_hadc
line for higher ADC window
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)
TH2Poly * createEffiTH2Poly(const TString &name, const TString &title)
Convenient function to create a TH2Poly based on CDC geometry.
~DQMHistAnalysisCDCEpicsModule()
Destructor.
std::string m_hname_hitsphi
Phi Hits histogram names.
double m_phiwarn
warn thershold for phi differences
std::string m_name_dir
histogram dir
std::string m_histoTrackingWireEff
Wire Eff histogram names.
TFile * m_fileRefPhi
reference histogram file point
TLine * m_line_htdc
line for higher TDC window
double m_phialarm
alarm thershold for phi differences
double m_maxadc
max adc median thershold accepted
std::string m_hname_effphi
Phi Eff histogram names.
TH1F * m_hist_adc
for above
TH2F * m_histref_phiindex
for above
double m_maxtdc
max tdc median thershold accepted
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
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
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.
std::string m_name_refdir
reference histogram dir
void endRun() override final
End-of-run action.
TH1D * m_hist_refphi
for above
TLine * m_line_ltdc
line for lower TDC window
TLine * m_line_ladc
line for lower ADC window
void beginRun() override final
Called when entering a new run.
TH1D * m_hists_bTDC[kNumBoards]
TDC histograms with track associated hits for each board (0-299)
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.
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.
double m_mintdc
min tdc median thershold accepted
The base class for the histogram analysis module.
bool hasDeltaPar(const std::string &dirname, const std::string &histname)
Check if Delta histogram parameters exist for histogram.
static MonitoringObject * getMonitoringObject(const std::string &name)
Get MonitoringObject with given name (new object is created if non-existing)
void addDeltaPar(const std::string &dirname, const std::string &histname, HistDelta::EDeltaType t, int p, unsigned int a=1)
Add Delta histogram parameters.
void colorizeCanvas(TCanvas *canvas, EStatus status)
Helper function for Canvas colorization.
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.
@ 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.
int registerEpicsPV(std::string pvname, std::string keyname="")
EPICS related Functions.
void UpdateCanvas(std::string name, bool updated=true)
Mark canvas as updated (or not)
bool requestLimitsFromEpicsPVs(chid id, double &lowerAlarm, double &lowerWarn, double &upperWarn, double &upperAlarm)
Get Alarm Limits from EPICS PV.
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)
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.