9#include <dqm/analysis/modules/DQMHistAnalysisCDCEpics.h>
10#include <cdc/geometry/CDCGeometryPar.h>
33 addParam(
"RefFilePhi",
m_refNamePhi,
"Reference histogram file name", std::string(
"CDCDQM_PhiRef.root"));
34 addParam(
"RefDirectory",
m_refDir,
"Reference histogram dir", std::string(
"ref/CDC/default"));
40 for (
int i = 0; i < 300; i++) {
44 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: Constructor done.");
54 c_hist_adc =
new TCanvas(
"CDC/c_hist_adc",
"c_hist_adc", 500, 400);
55 m_hist_adc =
new TH1F(
"CDC/hist_adc",
"m_hist_adc", 300, 0, 300);
56 m_hist_adc->SetTitle(
"ADC Medians; CDC board index; ADC medians");
58 c_hist_tdc =
new TCanvas(
"CDC/c_hist_tdc",
"c_hist_tdc", 500, 400);
59 m_hist_tdc =
new TH1F(
"CDC/hist_tdc",
"m_hist_tdc", 300, 0, 300);
60 m_hist_tdc->SetTitle(
"TDC Medians; CDC board index; TDC medians");
63 for (
int ic = 0; ic < 8; ic++) {
64 c_hist_skimphi[ic] =
new TCanvas(Form(
"CDC/c_hist_skimphi_c%d", ic), Form(
"hist_skimphi_c%d", ic), 500, 400);
67 c_hist_crphi =
new TCanvas(
"CDC/c_hist_crphi",
"c_hist_crphi", 500, 400);
68 c_hist_hitsphi =
new TCanvas(
"CDC/c_hist_hitsphi",
"c_hist_hitsphi", 500, 400);
74 B2INFO(
"DQMHistAnalysisCDCEpics: reference (" <<
m_refNamePhi <<
") found OK");
77 else B2INFO(
"\t ..and (cdcdqm_phiref) also exist");
81 c_hist_effphi =
new TCanvas(
"CDC/c_hist_effphi",
"c_hist_effphi", 500, 400);
82 m_hist_effphi =
new TH1D(
"CDC/hist_effphi",
"m_hist_effphi", 360, -180.0, 180.0);
84 c_hist_attach_eff[0] =
new TCanvas(
"CDC/c_hist_attached_wires",
"c_hist_attached_wires", 403, 400);
85 c_hist_attach_eff[1] =
new TCanvas(
"CDC/c_hist_expected_wires",
"c_hist_expected_wires", 403, 400);
86 c_hist_attach_eff[2] =
new TCanvas(
"CDC/c_hist_attach_eff",
"c_hist_attach_eff", 403, 400);
87 c_hist_attach_eff[3] =
new TCanvas(
"CDC/c_hist_attach_eff_1d",
"c_hist_attach_eff_1d", 403, 400);
90 "hist_attachedWires (backplate view);X [cm];Y [cm]; Track / bin");
94 m_hist_attach_eff_Poly[1]->SetNameTitle(
"CDC/hist_expectedWires",
"hist_expectedWires (backplate view);X [cm];Y [cm]; Track / bin");
97 m_hist_attach_eff_Poly[2]->SetNameTitle(
"CDC/hist_wireAttachEff",
"hist_wireAttachEff (backplate view);X [cm];Y [cm]; Efficiency");
102 double maxLayerR = cdcgeo.
senseWireR(nSLayers - 1);
103 m_hist_attach_eff[0] =
new TH2F(
"CDC/hist_attachedWires",
"hist_attachedWires (backplate view);X [cm];Y [cm]; Track / bin",
104 nSLayers * 6, -maxLayerR * 1.02, maxLayerR * 1.02,
105 nSLayers * 6, -maxLayerR * 1.02, maxLayerR * 1.02);
108 m_hist_attach_eff[1]->SetNameTitle(
"CDC/hist_expectedWires",
"hist_expectedWires (backplate view);X [cm];Y [cm]; Track / bin");
110 m_hist_attach_eff[2]->SetNameTitle(
"CDC/hist_wireAttachEff",
"hist_wireAttachEff (backplate view);X [cm];Y [cm]; Efficiency");
112 m_hist_wire_attach_eff_1d =
new TH1F(
"CDC/hist_wire_attach_eff_1d",
"hist_wire_attach_eff_1d;Wire Efficiency;Wire / bin",
144 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: initialized.");
180 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: beginRun run called");
191 double sumadcgood = 0;
192 for (
int ic = 0; ic < 300; ++ic) {
193 if (ic == 0)
continue;
195 m_hADCs[ic] = m_delta_adc->ProjectionY(Form(
"hADC%d", ic + 1), ic + 1, ic + 1,
"");
196 m_hADCs[ic]->SetTitle(Form(
"hADC%d", ic));
200 sumadcgood = sumadcgood + md_adc;
204 double adcfrac = cadcgood / 2.99;
209 if (cadcgood > 0)sumadcgood = sumadcgood * 1.0 / cadcgood;
211 m_hist_adc->SetTitle(Form(
"ADC Medians: Bad board count = %d (%0.01f%%)", cadcbad - 1, 100.0 - adcfrac));
224 double sumtdcgood = 0;
225 for (
int ic = 0; ic < 300; ++ic) {
226 if (ic == 0)
continue;
228 m_hTDCs[ic] = m_delta_tdc->ProjectionY(Form(
"hTDC%d", ic + 1), ic + 1, ic + 1,
"");
229 m_hTDCs[ic]->SetTitle(Form(
"hTDC%d", ic));
234 sumtdcgood = sumtdcgood + md_tdc;
238 double tdcfrac = ctdcgood / 2.99;
242 if (ctdcgood > 0)sumtdcgood = sumtdcgood * 1.0 / ctdcgood;
244 m_hist_tdc->SetTitle(Form(
"TDC Medians: Bad board count = %d (%0.01f%%)", ctdcbad - 1, 100.0 - tdcfrac));
254 if (m_delta_skimphi) {
255 TString sip[2] = {
"OffIP",
"IP"};
256 TString sname[4] = {
"all",
"bhabha",
"hadron",
"mumutrk"};
257 for (
int j = 0; j < 2; j++) {
258 for (
int i = 0; i < 4; i++) {
260 TString hname = TString::Format(
"histphi_%s_%sevt", sip[j].Data(), sname[i].Data());
261 m_hist_skimphi[k] = m_delta_skimphi->ProjectionX(hname, k + 1, k + 1,
"");
262 m_hist_skimphi[k]->SetTitle(TString::Format(
"cdc-track #phi (%s, %s-events);#phi;entries", sip[j].Data(), sname[i].Data()));
275 if (m_delta_skimphi) {
277 bool isFew =
false, isAlarm =
false, isWarn =
false;
278 m_hist_crphi = m_delta_skimphi->ProjectionX(
"histphi_ip_hadrons", 7, 7,
"");
279 m_hist_crphi->SetTitle(
"cdc-track #phi (IP + hadrons);cdc-track #phi;norm entries");
283 if (maxnow < 10000) isFew =
true;
289 if (nbinref == nbinnow) {
292 double maxphidiff = 0;
293 double maxphidiff_angle = 0;
294 for (
int iphi = 0; iphi < nbinnow; iphi++) {
297 double phidiff = fabs(icnow - icref);
300 if (phidiff > maxphidiff) {
301 maxphidiff = phidiff;
305 m_hist_crphi->SetTitle(Form(
"%s (diff = %0.03f at %0.1f)",
m_hist_crphi->GetTitle(), maxphidiff, maxphidiff_angle));
325 if (m_delta_effphi) {
328 const int all_phibins = m_delta_effphi->GetNbinsX();
329 const int all_hitbins = m_delta_effphi->GetNbinsY();
330 const int thr_hitbin = m_delta_effphi->GetYaxis()->FindBin(20);
331 for (
int iphi = 0; iphi < all_phibins; iphi++) {
332 TH1D* temp = (TH1D*)m_delta_effphi->ProjectionY(Form(
"hhits_bin_%d", iphi + 1), iphi + 1, iphi + 1,
"");
333 Double_t num = temp->Integral(thr_hitbin, all_hitbins);
334 Double_t den = temp->Integral();
335 if (den > 0)eff = num * 100.0 / den;
340 m_hist_effphi->SetTitle(
"CDC track efficiency(cdchits>20/all); cdc-track #phi; tracking efficiency");
352 if (m_delta_hitphi) {
354 m_delta_hitphi->SetTitle(
"CDC track #phi vs cdchits; cdc-track #phi; nCDCHits");
356 m_delta_hitphi->Draw(
"COLZ");
362 double meanWireAttachProb = 0;
363 double fracWiresWithLowAttachProb = 0;
364 double fracWiresWithHighAttachProb = 0;
365 gStyle->SetNumberContours(100);
367 if (m_delta_efflay) {
371 for (
int ij = 1; ij <= m_delta_efflay->GetNbinsX(); ij++) {
372 int halfYbin = m_delta_efflay->GetNbinsY() / 2;
373 for (
int jk = 0; jk < halfYbin; jk++) {
374 if (m_delta_efflay->GetBinContent(ij, jk + 1) == 0)
continue;
375 double binEffi = m_delta_efflay->GetBinContent(ij, jk + halfYbin + 1) / m_delta_efflay->GetBinContent(ij, jk + 1);
377 meanWireAttachProb += binEffi;
381 if (nEffiValues) meanWireAttachProb /= nEffiValues;
387 latex.SetTextSize(0.025);
388 for (
int ij = 0; ij < 3; ij++) {
398 latex.DrawLatexNDC(0.12, 0.87, TString::Format(
"mean = %.3f%%", meanWireAttachProb * 100.0));
409 latex.DrawLatexNDC(0.15, 0.87, TString::Format(
"%06.3f%% wire : eff < %.2f",
410 fracWiresWithLowAttachProb * 100,
412 latex.DrawLatexNDC(0.15, 0.84, TString::Format(
"%06.3f%% wire : %.2f < eff < %.2f",
413 (1. - fracWiresWithHighAttachProb - fracWiresWithLowAttachProb) * 100,
415 latex.DrawLatexNDC(0.15, 0.81, TString::Format(
"%06.3f%% wire : %.2f < eff",
416 fracWiresWithHighAttachProb * 100,
419 for (
int ij = 0; ij < 4; ij++) {
429 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: end event");
435 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: end run");
441 TH1D* hist = (TH1D*)h->Clone();
442 hist->SetBinContent(1, 0.0);
444 if (hist->GetMean() != 0) {
446 double quantiles[1] = {0.0};
447 double probSums[1] = {0.5};
448 hist->GetQuantiles(1, quantiles, probSums);
449 median = quantiles[0];
458 B2DEBUG(20,
"DQMHistAnalysisCDCEpics: terminate called");
467 std::vector<double> binEdges(nSLayers + 1);
471 binEdges[0] = firstR - (secondR - firstR) / 2;
472 for (
int lay = 1; lay < nSLayers; lay++) {
475 binEdges[lay] = (prevR + currentR) / 2;
477 double lastR = cdcgeo.
senseWireR(nSLayers - 1);
478 double secondLastR = cdcgeo.
senseWireR(nSLayers - 2);
479 binEdges[nSLayers] = lastR + (lastR - secondLastR) / 2;
481 TH1F layerHist(
"layerHist",
"Layer Histogram", nSLayers, binEdges.data());
483 for (
int binx = 1; binx <= efficiency->GetNbinsX(); binx++) {
484 for (
int biny = 1; biny <= efficiency->GetNbinsY(); biny++) {
485 double bincenterx = efficiency->GetXaxis()->GetBinCenter(binx);
486 double bincentery = efficiency->GetYaxis()->GetBinCenter(biny);
487 double r = TMath::Sqrt(bincenterx * bincenterx + bincentery * bincentery);
488 double phi = TMath::ATan2(bincentery, bincenterx);
489 if (phi < 0) phi += 2 * TMath::Pi();
491 int layerBin = layerHist.FindBin(r);
492 if (layerBin < 1 || layerBin > nSLayers)
continue;
493 int layerExpected = layerBin - 1;
496 double offset = cdcgeo.
offset(layerExpected);
497 int wireExpected = phi * nWires / (2 * TMath::Pi()) - offset + 0.5;
498 if (wireExpected < 0) wireExpected += nWires;
499 if (wireExpected >= nWires) wireExpected -= nWires;
501 int expBin = hist->GetYaxis()->FindBin(layerExpected);
502 int obsBin = expBin + nSLayers;
503 expected->SetBinContent(binx, biny, hist->GetBinContent(wireExpected + 1, expBin));
504 attached->SetBinContent(binx, biny, hist->GetBinContent(wireExpected + 1, obsBin));
507 efficiency->Divide(attached, expected);
514 double maxLayerR = cdcgeo.
senseWireR(nSLayers - 1);
515 TH2Poly* hist =
new TH2Poly(name, title, -maxLayerR * 1.02, maxLayerR * 1.02, -maxLayerR * 1.02, maxLayerR * 1.02);
516 for (
int lay = 0; lay < nSLayers; lay++) {
518 double offset = cdcgeo.
offset(lay);
525 }
else if (lay == nSLayers - 1) {
532 for (
int wire = 0; wire < nWires; wire++) {
533 double phi_inner = (wire - 0.5 + offset) * 2 * TMath::Pi() / nWires;
534 double phi_outer = (wire + 0.5 + offset) * 2 * TMath::Pi() / nWires;
536 double x0 = r_inner * TMath::Cos(phi_inner);
537 double y0 = r_inner * TMath::Sin(phi_inner);
538 double x1 = r_outer * TMath::Cos(phi_inner);
539 double y1 = r_outer * TMath::Sin(phi_inner);
540 double x2 = r_outer * TMath::Cos(phi_outer);
541 double y2 = r_outer * TMath::Sin(phi_outer);
542 double x3 = r_inner * TMath::Cos(phi_outer);
543 double y3 = r_inner * TMath::Sin(phi_outer);
544 double xx[] = {x0, x1, x2, x3};
545 double yy[] = {y0, y1, y2, y3};
546 hist->AddBin(4, xx, yy);
554 attached->Reset(
"ICES");
555 expected->Reset(
"ICES");
558 for (
int lay = 0; lay < nSLayers; lay++) {
561 double offset = cdcgeo.
offset(lay);
562 int expBin = hist->GetYaxis()->FindBin(lay);
563 int obsBin = expBin + nSLayers;
565 for (
int wire = 0; wire < nWires; wire++) {
566 double phi = (wire + offset) * 2 * TMath::Pi() / nWires;
567 double fillX = layerR * TMath::Cos(phi);
568 double fillY = layerR * TMath::Sin(phi);
569 attached->Fill(fillX, fillY, hist->GetBinContent(wire + 1, obsBin));
570 expected->Fill(fillX, fillY, hist->GetBinContent(wire + 1, expBin));
573 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
std::string m_refDir
reference histogram dir of CDC DQMs
void initialize() override final
Initialize the Module.
double m_minadc
min adc median thershold accepted
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
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_histoADC
ADC histogram names of CDC DQMs.
std::string m_histoDir
histogram dir of CDC DQMs
void fillEffiTH2Poly(TH2F *hist, TH2Poly *attached, TH2Poly *expected, TH2Poly *efficiency)
Populate the efficiency histograms.
TH2Poly * createEffiTH2Poly(const TString &name, const TString &title)
Convenient function to create a TH2Poly based on CDC geometry.
std::string m_histoTDC
TDC histogram names of CDC DQMs.
~DQMHistAnalysisCDCEpicsModule()
Destructor.
double m_phiwarn
warn thershold for phi differences
std::string m_refNamePhi
reference histogram of phi
std::string m_histoTrackingWireEff
Wire Eff histogram names of CDC DQMs.
TFile * m_fileRefPhi
reference histogram file point
TLine * m_line_htdc
line for higher TDC window
double m_phialarm
alram thershold for phi differences
double m_maxadc
max adc median thershold accepted
TH1F * m_hist_adc
for above
TH1D * m_hTDCs[300]
TDC histograms with track associated hits for each board (0-299)
TH2F * m_histref_phiindex
for above
std::string m_pvPrefix
Prefix of PVs.
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
void terminate() override final
Termination action.
void event() override final
intra-run actions (EPICC PVs).
std::string m_histoPhiEff
Phi Eff histogram names of CDC DQMs.
TCanvas * c_hist_tdc
canvas for tdc board median
TH1D * m_hADCs[300]
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_histoHitsPhi
Phi Hits histogram names of CDC DQMs.
void endRun() override final
End-of-run action.
TH1D * m_hist_refphi
for above
std::string m_histoPhiIndex
Phi Inedx histogram names of CDC DQMs.
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.
float getHistMedian(TH1D *h) const
Get median of given histogram.
TH2F * m_hist_attach_eff[3]
for above
DQMHistAnalysisCDCEpicsModule()
Constructor.
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)
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.