9#include <dqm/analysis/modules/DQMHistAnalysisCDCDedx.h>
22 B2DEBUG(20,
"DQMHistAnalysisCDCDedx: Constructor done.");
23 setDescription(
"Module to draw and compute values related to dEdx for CDC. ");
26 addParam(
"mmode",
mmode,
"default monitoring mode is basic", std::string(
"basic"));
34 gStyle->SetOptStat(0);
37 B2DEBUG(20,
"DQMHistAnalysisCDCDedx: initialized.");
40 c_ir_dedx =
new TCanvas(
"CDCDedx/c_ir_dedx",
"", 1400, 500);
43 c_pr_dedx =
new TCanvas(
"CDCDedx/c_CDCdedxMean",
"", 800, 800);
45 f_gaus =
new TF1(
"f_gaus",
"gaus", 0.0, 2.5);
46 f_gaus->SetLineColor(kRed);
49 l_line->SetLineColor(kRed);
64 B2DEBUG(20,
"DQMHistAnalysisCDCDedx: beginRun called.");
72 B2DEBUG(20,
"DQMHistAnalysisCDCDedx: event called.");
78 if (
mmode !=
"basic") {
102 if (
mmode !=
"basic") {
117 if (
mmode !=
"basic") {
126 B2DEBUG(20,
"DQMHistAnalysisCDCDedx : endRun called");
133 B2DEBUG(20,
"DQMHistAnalysisCDCDedx : terminate called");
144 TH1D* h_Meta = (TH1D*)
findHist(
"CDCDedx/hMeta");
146 if (h_Meta !=
nullptr) {
147 m_nallevt = int(h_Meta->GetBinContent(1));
149 m_nhadevt = int(h_Meta->GetBinContent(3));
151 std::string m_title = h_Meta->GetTitle();
153 first = m_title.find(
"Exp:");
154 last = m_title.find(
", Run:");
157 first = m_title.find(
", Run:");
158 last = m_title.find(
", RG:");
161 first = m_title.find(
", RG:");
162 last = m_title.find(
")");
163 std::string runGain = m_title.substr(
first + 5,
last -
first - 5);
165 m_exp = std::stoi(expN.c_str());
166 m_run = std::stoi(runN.c_str());
167 m_dbrg = std::stof(runGain.c_str());
179 TH1* h_dEdx =
findHist(
"CDCDedx/hdEdx");
180 if (h_dEdx !=
nullptr) {
182 double m_meanerr = 0.0;
183 double m_sigmaerr = 0.0;
190 TH1D* h_dEdxClone = (TH1D*)h_dEdx->Clone(
"hdEdx_clone");
191 if (h_dEdxClone !=
nullptr) {
192 if (h_dEdxClone->Integral() > 250) {
195 m_mean = h_dEdxClone->GetFunction(
"f_gaus")->GetParameter(1);
196 m_sigma = h_dEdxClone->GetFunction(
"f_gaus")->GetParameter(2);
197 m_meanerr = h_dEdxClone->GetFunction(
"f_gaus")->GetParError(1);
198 m_sigmaerr = h_dEdxClone->GetFunction(
"f_gaus")->GetParError(2);
202 h_dEdxClone->SetTitle(
"CDC-dEdx");
203 h_dEdxClone->DrawCopy(
"");
213 TF1* f_gausC = (TF1*)
f_gaus->Clone(
"f_gausC");
214 f_gausC->SetLineColor(kRed);
215 f_gausC->DrawClone(
"same");
217 TPaveText* pinfo0 =
new TPaveText(0.12, 0.72, 0.37, 0.89,
"NBNDC");
219 pinfo0->AddText(Form(
"Fit Status: %s",
m_status.data()));
220 pinfo0->AddText(Form(
"Fit #mu^{dE/dx}: %0.3f ",
m_mean));
221 pinfo0->AddText(Form(
"Fit #sigma^{dE/dx}: %0.3f ",
m_sigma));
222 pinfo0->SetTextColor(kRed);
223 pinfo0->Draw(
"same");
225 TPaveText* pinfo1 =
new TPaveText(0.60, 0.69, 0.85, 0.89,
"NBNDC");
227 pinfo1->AddText(Form(
"-- Expert info"));
228 pinfo1->AddText(Form(
"-------------"));
230 pinfo1->AddText(Form(
"Prev Gain: %0.03f",
m_dbrg));
231 pinfo1->Draw(
"same");
243 if (
mmode !=
"basic") {
247 TH2D* hdEdxIRScat = (TH2D*)
findHist(
"CDCDedx/hdEdxvsEvt");
248 if (hdEdxIRScat !=
nullptr) {
252 if (hdEdxIRScat->GetEntries() > 0) {
253 hdEdxIRScat->GetXaxis()->SetRange(hdEdxIRScat->FindFirstBinAbove(0, 1), hdEdxIRScat->FindLastBinAbove(0, 1));
257 hdEdxIRScat->Draw(
"");
258 TPaveText* pinfo =
new TPaveText(0.609, 0.710, 0.942, 0.911,
"NBNDC");
260 pinfo->AddText(
"CDC-dE/dx Intra-run");
267 TH2D* hdEdxIRScatC = (TH2D*)
findHist(
"CDCDedx/hdEdxvsEvt");
269 if (hdEdxIRScatC !=
nullptr) {
274 int fbin = hdEdxIRScatC->FindFirstBinAbove(0, 1);
275 int lbin = hdEdxIRScatC->FindLastBinAbove(0, 1);
276 int nbin = lbin - fbin + 1;
278 if (nbin <= 0) nbin = 1;
280 TH1F* hdEdxIRMean =
new TH1F(
"hdEdxIRMean",
"", nbin, 0.5, nbin + 0.5);
281 hdEdxIRMean->SetTitle(
"CDC-dE/dx gain(#mu): intra-run variation;Events(M);dE/dx (#mu_{fit})");
283 TH1F* hdEdxIRSigma =
new TH1F(
"hdEdxIRSigma",
"", nbin, 0.5, nbin + 0.5);
284 hdEdxIRSigma->SetTitle(
"CDC-dE/dx reso.(#sigma): intra-run variation;Events(M);dE/dx (#sigma_{fit})");
286 setHistPars(hdEdxIRScatC, hdEdxIRMean, hdEdxIRSigma, nbin);
304 TH2D* hdEdxVsP = (TH2D*)
findHist(
"CDCDedx/hdEdxVsP");
305 if (hdEdxVsP !=
nullptr) {
313 hdEdxVsP->SetTitle(
"CDC-dEdx band plot");
314 hdEdxVsP->SetMinimum(0.10);
315 hdEdxVsP->Draw(
"col");
317 TPaveText* pinfo0 =
new TPaveText(0.60, 0.77, 0.85, 0.89,
"NBNDC");
319 pinfo0->AddText(Form(
"IP tracks (hadron)"));
320 pinfo0->AddText(Form(
"Exp/Run: %d/%d",
m_exp,
m_run));
322 pinfo0->AddText(Form(
"Events: %0.02fM",
double(
m_nhadevt / 1e6)));
324 pinfo0->AddText(Form(
"Events: %0.02fK",
double(
m_nhadevt / 1e3)));
326 pinfo0->AddText(Form(
"Events: %d",
m_nhadevt));
327 pinfo0->DrawClone(
"same");
337 TH2D* hdEdxvsPhi = (TH2D*)
findHist(
"CDCDedx/hdEdxvsPhi");
338 if (hdEdxvsPhi !=
nullptr) {
343 hdEdxvsPhi->SetTitle(
"CDC-dEdx vs Phi");
344 hdEdxvsPhi->Draw(
"col");
348 TPaveText* pinfo0 =
new TPaveText(0.60, 0.77, 0.85, 0.89,
"NBNDC");
351 pinfo0->DrawClone(
"same");
355 TH2D* hdEdxvsCosth = (TH2D*)
findHist(
"CDCDedx/hdEdxvsCosth");
356 if (hdEdxvsCosth !=
nullptr) {
361 hdEdxvsCosth->SetTitle(
"CDC-dEdx vs Costh");
362 hdEdxvsCosth->Draw(
"col");
366 TPaveText* pinfo1 =
new TPaveText(0.60, 0.77, 0.85, 0.89,
"NBNDC");
369 pinfo1->DrawClone(
"same");
378 TH2D* hinjtimeHer = (TH2D*)
findHist(
"CDCDedx/hinjtimeHer");
379 TH2D* hinjtimeLer = (TH2D*)
findHist(
"CDCDedx/hinjtimeLer");
381 if (hinjtimeHer !=
nullptr && hinjtimeLer !=
nullptr) {
387 hinjtimeHer->SetTitle(
"Time since last injection (HER)");
388 hinjtimeHer->Draw(
"box");
391 hinjtimeLer->SetFillColor(kRed);
392 hinjtimeLer->Draw(
"same box");
396 TLegend* lego =
new TLegend(0.50, 0.77, 0.60, 0.89);
397 lego->AddEntry(hinjtimeHer,
"HER",
"f");
398 lego->AddEntry(hinjtimeLer,
"LER",
"f");
401 TPaveText* pinfo0 =
new TPaveText(0.60, 0.77, 0.85, 0.89,
"NBNDC");
404 pinfo0->DrawClone(
"same");
413 TH2D* hdEdxITHer = (TH2D*)
findHist(
"CDCDedx/hinjtimeHer");
414 TH2D* hdEdxITLer = (TH2D*)
findHist(
"CDCDedx/hinjtimeLer");
416 if (hdEdxITHer !=
nullptr && hdEdxITLer !=
nullptr) {
420 int fbin = hdEdxITHer->FindFirstBinAbove(0, 1);
421 int lbin = hdEdxITHer->FindLastBinAbove(0, 1);
422 int nbin = (lbin - fbin + 1) / 2;
423 if (nbin <= 0)nbin = 1;
425 TH1F* hinjectmean[2];
426 TH1F* hinjectsigma[2];
428 for (
int i = 0; i < 2; i++) {
429 hinjectmean[i] =
new TH1F(Form(
"hinjectmean%d", i),
"", nbin, 0.5, nbin + 0.5);
430 hinjectmean[i]->SetTitle(
"CDC-dE/dx gain(#mu);Injection time (ms);dE/dx (#mu_{fit})");
431 hinjectsigma[i] =
new TH1F(Form(
"hinjectsigma%d", i),
"", nbin, 0.5, nbin + 0.5);
432 hinjectsigma[i]->SetTitle(
"CDC-dE/dx reso.(#sigma);Injection time (ms);dE/dx (#sigma_{fit})");
435 setHistPars(hdEdxITHer, hinjectmean[0], hinjectsigma[0], nbin);
436 setHistPars(hdEdxITLer, hinjectmean[1], hinjectsigma[1], nbin);
444 hinjectmean[1]->SetMarkerColor(kBlue);
445 hinjectmean[1]->SetMarkerStyle(20);
446 hinjectmean[1]->SetMarkerSize(1.10);
447 hinjectmean[1]->Draw(
"same");
449 TLegend* lego =
new TLegend(0.45, 0.77, 0.60, 0.89);
450 lego->AddEntry(hinjectmean[0],
"HER",
"p");
451 lego->AddEntry(hinjectmean[1],
"LER",
"p");
459 hinjectsigma[1]->SetMarkerColor(kBlue);
460 hinjectsigma[1]->SetMarkerStyle(20);
461 hinjectsigma[1]->SetMarkerSize(1.10);
462 hinjectsigma[1]->Draw(
"same");
464 TLegend* lego1 =
new TLegend(0.45, 0.77, 0.60, 0.89);
465 lego1->AddEntry(hinjectsigma[0],
"HER",
"p");
466 lego1->AddEntry(hinjectsigma[1],
"LER",
"p");
476 TH2D* hWires = (TH2D*)
findHist(
"CDCDedx/hWires");
477 TH2D* hWireStatus = (TH2D*)
findHist(
"CDCDedx/hWireStatus");
478 if (hWires !=
nullptr && hWireStatus !=
nullptr) {
482 hWires->SetMarkerColor(kGray);
485 std::string s_ndead = hWireStatus->GetTitle();
486 int m_ndead = atof(s_ndead.c_str());
490 hWireStatus->SetMarkerColor(kRed);
491 hWireStatus->SetMarkerStyle(7);
492 hWireStatus->Draw(
"same");
494 TPaveText* pinfo0 =
new TPaveText(0.117, 0.832, 0.148, 0.976,
"NBNDC");
496 pinfo0->AddText(Form(
"CDC Wire Status"));
497 pinfo0->AddText(Form(
"Exp/Run: %d/%d",
m_exp,
m_run));
498 pinfo0->AddText(Form(
"Dead: %d (%0.02f%%)", m_ndead, (100.0 * m_ndead / c_nSenseWires)));
500 pinfo0->AddText(Form(
"Events: %0.02fM",
double(
m_nallevt / 1e6)));
502 pinfo0->AddText(Form(
"Events: %0.02fK",
double(
m_nallevt / 1e3)));
504 pinfo0->AddText(Form(
"Events: %d",
m_nallevt));
505 pinfo0->Draw(
"same");
513 int fbin = hdEdx->FindFirstBinAbove(0, 1);
515 for (
int ibin = 0; ibin < nbin; ibin++) {
516 int localbin = ibin + fbin;
517 TH1D* hdEdxIRInd = (TH1D*)hdEdx->ProjectionY(Form(
"htemp_%d", localbin), localbin, localbin);
519 double mean = 0.0, meanerr = 0.0;
520 double sigma = 0.0, sigmaerr = 0.0;
525 mean = hdEdxIRInd->GetFunction(
"f_gaus")->GetParameter(1);
526 meanerr = hdEdxIRInd->GetFunction(
"f_gaus")->GetParError(1);
527 sigma = hdEdxIRInd->GetFunction(
"f_gaus")->GetParameter(2);
528 sigmaerr = hdEdxIRInd->GetFunction(
"f_gaus")->GetParError(2);
531 hmean->SetBinContent(ibin + 1, mean);
532 hmean->SetBinError(ibin + 1, meanerr);
533 hsigma->SetBinContent(ibin + 1, sigma);
534 hsigma->SetBinError(ibin + 1, sigmaerr);
542 std::string hname = hist->GetName();
544 hist->SetMarkerColor(kRed);
545 hist->SetMarkerStyle(20);
546 hist->SetMarkerSize(1.10);
547 hist->GetYaxis()->SetRangeUser(pars - fac, pars + fac);
550 l_line->DrawLine(0.5, pars, hist->GetXaxis()->GetBinUpEdge(nbin), pars);
552 TPaveText* pinfo0 =
new TPaveText(0.609, 0.680, 0.942, 0.911,
"NBNDC");
554 if (hname ==
"hdEdxIRMean" || hname ==
"hdEdxIRSigma") pinfo0->AddText(
"Intra-run variation");
556 pinfo0->AddText(Form(
"Avg %s: %0.3f", var.data(), pars));
557 pinfo0->Draw(
"same");
564 pt->AddText(
"CDC dE/dx (e^{+}e^{-})");
565 pt->AddText(Form(
"Exp/Run: %d/%d",
m_exp,
m_run));
567 pt->AddText(Form(
"Events: %0.02fM",
double(
m_nbhabhaevt / 1e6)));
569 pt->AddText(Form(
"Events: %0.02fK",
double(
m_nbhabhaevt / 1e3)));
578 if (temphist !=
nullptr) {
579 temphist->GetXaxis()->SetRange(temphist->FindFirstBinAbove(0, 1), temphist->FindLastBinAbove(0, 1));
580 int fs = temphist->Fit(
f_gaus,
"QR");
584 double mean = temphist->GetFunction(
"f_gaus")->GetParameter(1);
585 double width = temphist->GetFunction(
"f_gaus")->GetParameter(2);
586 temphist->GetXaxis()->SetRangeUser(mean - 5.0 * width, mean + 5.0 * width);
587 fs = temphist->Fit(
f_gaus,
"QR",
"", mean - 3.0 * width, mean + 3.0 * width);
588 if (fs != 0)status =
"Failed";
590 temphist->GetXaxis()->SetRangeUser(mean - 5.0 * width, mean + 5.0 * width);
602 const Int_t NRGBs = 6;
603 const Int_t NCont = 255;
604 Double_t stops[NRGBs] = { 0.00, 0.00, 0.34, 0.61, 0.84, 1.00 };
605 Double_t red[NRGBs] = { 0.00, 0.00, 0.00, 0.87, 1.00, 0.51 };
606 Double_t green[NRGBs] = { 0.00, 0.00, 0.81, 1.00, 0.20, 0.00 };
607 Double_t blue[NRGBs] = { 0.00, 0.51, 1.00, 0.12, 0.00, 0.00 };
608 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
609 gStyle->SetNumberContours(NCont);
618 obj->SetFillColor(0);
619 obj->SetFillStyle(0);
621 obj->SetLineColor(TColor::GetColor(
"#000000"));
622 obj->SetLineWidth(0);
623 obj->SetTextAlign(12);
625 obj->SetTextColor(kGray + 3);
626 obj->SetTextFont(82);
627 obj->SetTextSize(0.03157895);
628 obj->SetTextAlign(12);
638 obj->SetFillColor(kYellow);
640 obj->SetTitleOffset(1.15,
"x");
641 obj->SetTitleSize(.040,
"x");
642 obj->SetTitleOffset(1.15,
"y");
643 obj->SetTitleSize(.040,
"y");
645 obj->SetLabelOffset(0.015,
"x");
646 obj->SetLabelSize(.040,
"x");
647 obj->SetLabelOffset(0.015,
"y");
648 obj->SetLabelSize(.040,
"y");
650 obj->SetTickLength(0.03,
"x");
651 obj->SetTickLength(0.02,
"y");
659 if (l != 0)gPad->SetLeftMargin(l);
660 if (r != 0)gPad->SetRightMargin(r);
661 if (t != 0)gPad->SetTopMargin(t);
662 if (b != 0)gPad->SetBottomMargin(b);
DQMHistAnalysisCDCDedxModule()
constructor
void drawDedxInjTime()
function to draw the dEdx vs injection time
void drawDedxCosPhi()
function to draw dEdx vs costh and phi
void initialize() override final
init function for default values
unsigned first
substring start value
void drawBandPlot()
function to dedx bands P
TLine * l_line
line for dedx mean
void drawWireStatus()
function to draw ADC-based dead wire status of CDC
void drawHistPars(TH1F *hist, int nbin, double pars, double fac, std::string var)
function to draw the histograms
int m_nhadevt
hadron events
unsigned last
substring last value
void setHistStyle(TH1 *obj)
function to set the style of histogram
std::string m_status
fit status
MonitoringObject * m_monObj
MonitoringObject for mirabelle.
void terminate() override final
terminating at the end of last run
void drawDedxInjTimeBin()
function to draw the mean/reso of dedx vs injection time
void event() override final
event by event function
TCanvas * c_ir_dedx
intra-run dedx status
void setHistPars(TH2D *hist, TH1F *hmean, TH1F *hsigma, int nbin)
function to set the mean and sigma histograms
void endRun() override final
end of each run
TCanvas * c_pr_dedx
dedx dist+fit
void setPadStyle(double l, double r, double t, double b)
function to reset pad margins
void getMetadata()
function to get metadata from histogram
void setBEvtInfo(TPaveText *pt)
function to set the bhabha event info
double m_dbrg
previous run gain
void beginRun() override final
begin each run
int m_nbhabhaevt
bhabha events
void drawDedxPR()
function to draw dEdx+Fit
void fitHistogram(TH1D *&temphist, std::string &status)
function to fit gaussian dist.
void drawDedxIR()
function to draw dEdx+Fit for run variation
void setTextStyle(TPaveText *&obj)
function to add text style
std::string mmode
monitoring mode all/basic
void setPlotStyle()
function to add plot style
The base class for the histogram analysis module.
static MonitoringObject * getMonitoringObject(const std::string &name)
Get MonitoringObject with given name (new object is created if non-existing)
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
void setDescription(const std::string &description)
Sets the description of the module.
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 addCanvas(TCanvas *canv)
Add Canvas to monitoring object.
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.