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",
170 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: initialized.");
206 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: beginRun run called");
215 for (
unsigned il = 0; il <
kNumLayers; ++il) {
217 m_hists_lADC[il] = m_delta_ladc->ProjectionY(Form(
"histmd_adc_layer%d", il + 1), il + 1, il + 1,
"");
218 m_hists_lADC[il]->SetTitle(Form(
"histmd_adc_layer%d", il));
232 line->SetY2(y_max * 1.20);
245 double sumadcgood = 0;
246 for (
unsigned ic = 0; ic <
kNumBoards; ++ic) {
247 if (ic == 0)
continue;
249 m_hists_bADC[ic] = m_delta_adc->ProjectionY(Form(
"histmd_tdc_board%d", ic + 1), ic + 1, ic + 1,
"");
250 m_hists_bADC[ic]->SetTitle(Form(
"histmd_adc_board%d", ic));
254 sumadcgood = sumadcgood + md_adc;
258 double adcfrac = cadcgood / 2.99;
263 if (cadcgood > 0)sumadcgood = sumadcgood * 1.0 / cadcgood;
265 m_hist_adc->SetTitle(Form(
"ADC Medians: Bad board count = %d (%0.01f%%)", cadcbad - 1, 100.0 - adcfrac));
279 double sumtdcgood = 0;
280 for (
unsigned ic = 0; ic <
kNumBoards; ++ic) {
281 if (ic == 0)
continue;
283 m_hists_bTDC[ic] = m_delta_tdc->ProjectionY(Form(
"histmd_tdc_board%d", ic + 1), ic + 1, ic + 1,
"");
284 m_hists_bTDC[ic]->SetTitle(Form(
"histmd_tdc_board%d", ic));
289 sumtdcgood = sumtdcgood + md_tdc;
292 double tdcfrac = ctdcgood / 2.99;
296 if (ctdcgood > 0)sumtdcgood = sumtdcgood * 1.0 / ctdcgood;
298 m_hist_tdc->SetTitle(Form(
"TDC Medians: Bad board count = %d (%0.01f%%)", ctdcbad - 1, 100.0 - tdcfrac));
308 if (m_delta_skimphi) {
309 TString sip[2] = {
"OffIP",
"IP"};
310 TString sname[4] = {
"all",
"bhabha",
"hadron",
"mumutrk"};
311 for (
int j = 0; j < 2; j++) {
312 for (
int i = 0; i < 4; i++) {
314 TString hname = TString::Format(
"histphi_%s_%sevt", sip[j].Data(), sname[i].Data());
315 m_hist_skimphi[k] = m_delta_skimphi->ProjectionX(hname, k + 1, k + 1,
"");
316 m_hist_skimphi[k]->SetTitle(TString::Format(
"cdc-track #phi (%s, %s-events);#phi;entries", sip[j].Data(), sname[i].Data()));
329 if (m_delta_skimphi) {
331 bool isFew =
false, isAlarm =
false, isWarn =
false;
332 m_hist_crphi = m_delta_skimphi->ProjectionX(
"histphi_ip_hadrons", 7, 7,
"");
333 m_hist_crphi->SetTitle(
"cdc-track #phi (IP + hadrons);cdc-track #phi;norm entries");
337 if (maxnow < 10000) {
344 if (nbinref == nbinnow) {
348 double maxphidiff = 0;
349 double maxphidiff_angle = 0;
350 for (
int iphi = 0; iphi < nbinnow; iphi++) {
353 double phidiff = fabs(icnow - icref);
356 if (phidiff > maxphidiff) {
357 maxphidiff = phidiff;
361 m_hist_crphi->SetTitle(Form(
"%s (diff = %0.03f at %0.1f)",
m_hist_crphi->GetTitle(), maxphidiff, maxphidiff_angle));
382 if (m_delta_effphi) {
385 const int all_phibins = m_delta_effphi->GetNbinsX();
386 const int all_hitbins = m_delta_effphi->GetNbinsY();
387 const int thr_hitbin = m_delta_effphi->GetYaxis()->FindBin(20);
388 for (
int iphi = 0; iphi < all_phibins; iphi++) {
389 TH1D* temp = (TH1D*)m_delta_effphi->ProjectionY(Form(
"hhits_bin_%d", iphi + 1), iphi + 1, iphi + 1,
"");
390 Double_t num = temp->Integral(thr_hitbin, all_hitbins);
391 Double_t den = temp->Integral();
392 if (den > 0)eff = num * 100.0 / den;
398 m_hist_effphi->SetTitle(
"CDC track efficiency(cdchits>20/all); cdc-track #phi; tracking efficiency");
410 if (m_delta_hitphi) {
412 m_delta_hitphi->SetTitle(
"CDC track #phi vs cdchits; cdc-track #phi; nCDCHits");
414 m_delta_hitphi->Draw(
"COLZ");
420 double meanWireAttachProb = 0;
421 double fracWiresWithLowAttachProb = 0;
422 double fracWiresWithHighAttachProb = 0;
423 gStyle->SetNumberContours(100);
425 if (m_delta_efflay) {
429 for (
int ij = 1; ij <= m_delta_efflay->GetNbinsX(); ij++) {
430 int halfYbin = m_delta_efflay->GetNbinsY() / 2;
431 for (
int jk = 0; jk < halfYbin; jk++) {
432 if (m_delta_efflay->GetBinContent(ij, jk + 1) == 0)
continue;
433 double binEffi = m_delta_efflay->GetBinContent(ij, jk + halfYbin + 1) / m_delta_efflay->GetBinContent(ij, jk + 1);
435 meanWireAttachProb += binEffi;
439 if (nEffiValues) meanWireAttachProb /= nEffiValues;
445 latex.SetTextSize(0.025);
446 for (
int ij = 0; ij < 3; ij++) {
456 for (
int ilay = 0; ilay < 56; ilay++) {
457 int rmdr = int(abs(ilay - 2) % 6);
458 if ((rmdr == 0 && ilay > 2) || ilay == 55) {
461 el[isl]->SetLineColor(kRed);
462 el[isl]->SetLineWidth(2);
463 el[isl]->SetFillStyle(0);
464 el[isl]->Draw(
"same");
469 latex.DrawLatexNDC(0.12, 0.87, TString::Format(
"mean = %.3f%%", meanWireAttachProb * 100.0));
480 latex.DrawLatexNDC(0.15, 0.87, TString::Format(
"%06.3f%% wire : eff < %.2f",
481 fracWiresWithLowAttachProb * 100,
483 latex.DrawLatexNDC(0.15, 0.84, TString::Format(
"%06.3f%% wire : %.2f < eff < %.2f",
484 (1. - fracWiresWithHighAttachProb - fracWiresWithLowAttachProb) * 100,
486 latex.DrawLatexNDC(0.15, 0.81, TString::Format(
"%06.3f%% wire : %.2f < eff",
487 fracWiresWithHighAttachProb * 100,
490 for (
int ij = 0; ij < 4; ij++) {
500 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: end event");
506 for (
auto* line :
m_lines)
delete line;
507 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: end run");
514 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: terminate called");
521 TH1D* hist = (TH1D*)h->Clone();
522 hist->SetBinContent(1, 0.0);
524 if (hist->GetMean() != 0) {
526 double quantiles[1] = {0.0};
527 double probSums[1] = {0.5};
528 hist->GetQuantiles(1, quantiles, probSums);
529 median = quantiles[0];
542 std::vector<double> binEdges(nSLayers + 1);
546 binEdges[0] = firstR - (secondR - firstR) / 2;
548 for (
int lay = 1; lay < nSLayers; lay++) {
551 binEdges[lay] = (prevR + currentR) / 2;
554 double lastR = cdcgeo.
senseWireR(nSLayers - 1);
555 double secondLastR = cdcgeo.
senseWireR(nSLayers - 2);
556 binEdges[nSLayers] = lastR + (lastR - secondLastR) / 2;
558 TH1F layerHist(
"layerHist",
"Layer Histogram", nSLayers, binEdges.data());
560 for (
int binx = 1; binx <= efficiency->GetNbinsX(); binx++) {
561 for (
int biny = 1; biny <= efficiency->GetNbinsY(); biny++) {
562 double bincenterx = efficiency->GetXaxis()->GetBinCenter(binx);
563 double bincentery = efficiency->GetYaxis()->GetBinCenter(biny);
564 double r = TMath::Sqrt(bincenterx * bincenterx + bincentery * bincentery);
565 double phi = TMath::ATan2(bincentery, bincenterx);
566 if (phi < 0) phi += 2 * TMath::Pi();
568 int layerBin = layerHist.FindBin(r);
569 if (layerBin < 1 || layerBin > nSLayers)
continue;
570 int layerExpected = layerBin - 1;
573 double offset = cdcgeo.
offset(layerExpected);
574 int wireExpected = phi * nWires / (2 * TMath::Pi()) - offset + 0.5;
575 if (wireExpected < 0) wireExpected += nWires;
576 if (wireExpected >= nWires) wireExpected -= nWires;
578 int expBin = hist->GetYaxis()->FindBin(layerExpected);
579 int obsBin = expBin + nSLayers;
580 expected->SetBinContent(binx, biny, hist->GetBinContent(wireExpected + 1, expBin));
581 attached->SetBinContent(binx, biny, hist->GetBinContent(wireExpected + 1, obsBin));
584 efficiency->Divide(attached, expected);
591 double maxLayerR = cdcgeo.
senseWireR(nSLayers - 1);
592 TH2Poly* hist =
new TH2Poly(name, title, -maxLayerR * 1.02, maxLayerR * 1.02, -maxLayerR * 1.02, maxLayerR * 1.02);
593 for (
int lay = 0; lay < nSLayers; lay++) {
595 double offset = cdcgeo.
offset(lay);
602 }
else if (lay == nSLayers - 1) {
609 for (
int wire = 0; wire < nWires; wire++) {
610 double phi_inner = (wire - 0.5 + offset) * 2 * TMath::Pi() / nWires;
611 double phi_outer = (wire + 0.5 + offset) * 2 * TMath::Pi() / nWires;
613 double x0 = r_inner * TMath::Cos(phi_inner);
614 double y0 = r_inner * TMath::Sin(phi_inner);
615 double x1 = r_outer * TMath::Cos(phi_inner);
616 double y1 = r_outer * TMath::Sin(phi_inner);
617 double x2 = r_outer * TMath::Cos(phi_outer);
618 double y2 = r_outer * TMath::Sin(phi_outer);
619 double x3 = r_inner * TMath::Cos(phi_outer);
620 double y3 = r_inner * TMath::Sin(phi_outer);
621 double xx[] = {x0, x1, x2, x3};
622 double yy[] = {y0, y1, y2, y3};
623 hist->AddBin(4, xx, yy);
631 attached->Reset(
"ICES");
632 expected->Reset(
"ICES");
635 for (
int lay = 0; lay < nSLayers; lay++) {
638 double offset = cdcgeo.
offset(lay);
639 int expBin = hist->GetYaxis()->FindBin(lay);
640 int obsBin = expBin + nSLayers;
642 for (
int wire = 0; wire < nWires; wire++) {
643 double phi = (wire + offset) * 2 * TMath::Pi() / nWires;
644 double fillX = layerR * TMath::Cos(phi);
645 double fillY = layerR * TMath::Sin(phi);
646 attached->Fill(fillX, fillY, hist->GetBinContent(wire + 1, obsBin));
647 expected->Fill(fillX, fillY, hist->GetBinContent(wire + 1, expBin));
650 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
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
double lbinEdges[kNumLayers]
vector for radius edge 56
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.