9 #include <reconstruction/calibration/CDCDedxBadWireAlgorithm.h>
20 c_nwireCDC(c_nSenseWires),
46 B2FATAL(
"There is no valid payload for BadWire and/or Wirgain");
49 auto ttree = getObjectPtr<TTree>(
"tree");
52 vector<int>* wire = 0;
53 ttree->SetBranchAddress(
"wire", &wire);
55 vector<double>* hitvar = 0;
56 if (
m_isADC) ttree->SetBranchAddress(
"adccorr", &hitvar);
57 else ttree->SetBranchAddress(
"dedxhit", &hitvar);
63 hvarall.SetTitle(Form(
"dist %s; %s; %s",
m_suffix.data(),
m_varName.data(),
"entries"));
65 map<int, vector<double>> vhitvar;
67 for (
int i = 0; i < ttree->GetEntries(); ++i) {
69 for (
unsigned int ih = 0; ih < wire->size(); ++ih) {
70 double ivalue = hitvar->at(ih);
71 vhitvar[wire->at(ih)].push_back(ivalue);
90 map<int, vector<double>> qapars;
91 vector<double> vdefectwires, vbadwires, vdeadwires;
93 for (
unsigned int jw = 0; jw <
c_nwireCDC; ++jw) {
94 int ncount = 0, tcount = 0;
96 for (
unsigned int jh = 0; jh < vhitvar[jw].size(); ++jh) {
97 double jvalue = vhitvar[jw][jh];
104 bool badwire =
false;
106 qapars[0].push_back(0);
107 qapars[1].push_back(0);
108 qapars[2].push_back(0);
111 nmean = nmean / ncount;
115 for (
unsigned int kh = 0; kh < vhitvar[jw].size(); ++kh) {
116 double kvalue = vhitvar[jw][kh];
117 if (kvalue <
m_varMax) nrms += pow(kvalue - nmean, 2);
120 nrms =
sqrt(nrms / ncount);
123 double badfrac = 0.0;
124 if (tcount > 0) badfrac = (1.0 * tcount) / (tcount + ncount);
127 qapars[0].push_back(nmean);
128 qapars[1].push_back(nrms);
129 qapars[2].push_back(badfrac);
133 vdefectwires.push_back(0.0);
134 if (ncount == 0) vdeadwires.push_back(jw);
135 else vbadwires.push_back(jw);
136 }
else vdefectwires.push_back(1.0);
155 B2INFO(
"dE/dx Badwire Calibration done: " << vdefectwires.size() <<
" wires");
170 if (cruns == 0) B2INFO(
"CDCDedxBadWires: start exp " << expRun.first <<
" and run " << expRun.second <<
"");
175 int estart = erStart.first;
176 int rstart = erStart.second;
179 int rend = erEnd.second;
184 else m_suffix = Form(
"e%d_r%dr%d", estart, rstart, rend);
190 map<
int, vector<double>>& vhitvar)
193 TList* bdlist =
new TList();
194 bdlist->SetName(
"badwires");
196 TList* goodlist =
new TList();
197 goodlist->SetName(
"goodwires");
199 TList* hflist =
new TList();
200 hflist->SetName(
"highfracwires");
202 for (
unsigned int jw = 0; jw <
c_nwireCDC; ++jw) {
207 hvarhf->SetTitle(Form(
"%s, wire = %d; %s; entries",
m_suffix.data(), jw,
m_varName.data()));
209 int ncount = 0, tcount = 0;
211 for (
unsigned int jh = 0; jh < vhitvar[jw].size(); ++jh) {
212 double jvalue = vhitvar[jw][jh];
218 if (jvalue <
m_varMax * 10.) hvarhf->Fill(jvalue / 10.);
222 double badfrac = 0.0;
223 if (tcount > 0) badfrac = (1.0 * tcount) / (tcount + ncount);
224 hvar->SetTitle(Form(
"%s, wire = %d; %s; %0.01f",
m_suffix.data(), jw,
m_varName.data(), badfrac * 100));
227 if (count(inwires.begin(), inwires.end(), jw)) isbad =
true;
231 hvar->SetLineWidth(2);
232 hvar->SetLineColor(kRed);
239 if (hvar->Integral() > 100) goodlist->Add(hvar);
255 string listname = list->GetName();
256 string sfx = Form(
"%s_%s", listname.data(),
m_suffix.data());
258 TCanvas ctmp(Form(
"cdcdedx_%s", sfx.data()),
"", 1200, 1200);
260 ctmp.SetBatch(kTRUE);
263 psname << Form(
"cdcdedx_bdcal_%s.pdf[", sfx.data());
264 ctmp.Print(psname.str().c_str());
266 psname << Form(
"cdcdedx_bdcal_%s.pdf", sfx.data());
268 for (
int ih = 0; ih < list->GetSize(); ih++) {
270 TH1D* hist = (TH1D*)list->At(ih);
272 double frac = stod(hist->GetYaxis()->GetTitle());
274 TPaveText* pinfo =
new TPaveText(0.40, 0.63, 0.89, 0.89,
"NBNDC");
277 pinfo->AddText(Form(
"N: %0.00f", hist->Integral()));
278 pinfo->AddText(Form(
"hf: %0.00f%%(%0.00f%%)", frac,
m_fracThres * 100));
281 ctmp.cd(ih % 16 + 1);
282 hist->GetYaxis()->SetTitle(
"entries");
283 hist->SetFillColor(color);
288 if (listname ==
"badwires") {
289 TH1D* histhf = (TH1D*)hflist->At(ih);
290 if (hist->GetMaximum() < histhf->GetMaximum()) hist->SetMaximum(histhf->GetMaximum() * 1.05);
291 histhf->SetFillColor(kGray);
293 histhf->Draw(
"same");
296 if (((ih + 1) % 16 == 0) || ih == (list->GetSize() - 1)) {
297 ctmp.Print(psname.str().c_str());
303 psname << Form(
"cdcdedx_bdcal_%s.pdf]", sfx.data());
304 ctmp.Print(psname.str().c_str());
311 TCanvas cmap(Form(
"cmap_%s",
m_suffix.data()),
"", 800, 800);
312 cmap.SetTitle(
"CDC dE/dx bad wire status");
316 hxyAll->SetTitle(Form(
"wire status map (%s)",
m_suffix.data()));
324 hxyBad->Draw(
"same");
331 hxyDead->Draw(
"same");
334 int ndefect = nbad + ndead;
335 auto leg =
new TLegend(0.68, 0.80, 0.90, 0.92);
336 leg->SetBorderSize(0);
337 leg->SetLineWidth(3);
338 leg->SetHeader(Form(
"total defective: %d (~%0.02f%%)", ndefect, 100.*(ndefect) /
c_nwireCDC));
339 leg->AddEntry(hxyBad, Form(
"bad #rightarrow %d", nbad),
"p");
340 leg->AddEntry(hxyDead, Form(
"dead #rightarrow %d", ndead),
"p");
343 gStyle->SetLegendTextSize(0.025);
344 TPaveText* pt =
new TPaveText(-0.30, -1.47, -0.31, -1.30,
"br");
347 TText* text = pt->AddText(
"CDC-wire map: counter-clockwise and start from +x");
348 text->SetTextColor(kGray + 1);
351 cmap.SaveAs(Form(
"cdcdedx_bdcal_wiremap_%s.pdf",
m_suffix.data()));
362 B2INFO(
"Creating CDCGeometryPar object");
365 TH2F* temp =
new TH2F(Form(
"temp_%s_%s",
m_suffix.data(), suffix.data()),
"", 2400, -1.2, 1.2, 2400, -1.2, 1.2);
369 for (
unsigned int ilay = 0; ilay < c_maxNSenseLayers; ++ilay) {
370 for (
unsigned int iwire = 0; iwire < cdcgeo.
nWiresInLayer(ilay); ++iwire) {
372 double phi = 2.*TMath::Pi() * (float(iwire) / float(cdcgeo.
nWiresInLayer(ilay)));
373 double radius = cdcgeo.
senseWireR(ilay) / 100.;
374 double x = radius * cos(phi);
375 double y = radius * sin(phi);
376 if (suffix ==
"all") {
380 if (count(inwires.begin(), inwires.end(), jwire)) {
394 string qaname[3] = {
"mean",
"rms",
"high_fraction"};
399 for (
int iqa = 0; iqa < 3; iqa++) {
401 TH1D histqa(Form(
"%s_%s", qaname[iqa].data(),
m_suffix.data()),
"",
c_nwireCDC, -0.5, 14335.5);
403 for (
unsigned int jw = 0; jw <
c_nwireCDC; jw++) {
404 if (iqa == 2) histqa.SetBinContent(jw + 1, qapars[iqa][jw] * 100);
405 else histqa.SetBinContent(jw + 1, qapars[iqa][jw]);
408 TCanvas c_pars(Form(
"c_pars_%d", iqa),
"", 800, 600);
412 histqa.SetTitle(Form(
"%s vs wires (%s); wire ; %s", qaname[iqa].data(),
m_suffix.data(), qaname[iqa].data()));
416 TLine* lmin =
new TLine(-0.5, linemin[iqa], 14335.5, linemin[iqa]);
417 lmin->SetLineColor(kRed);
419 TLine* lmax =
new TLine(-0.5, linemax[iqa], 14335.5, linemax[iqa]);
420 lmax->SetLineColor(kRed);
423 c_pars.Print(Form(
"cdcdedx_bdcal_%s_%s.root", qaname[iqa].data(),
m_suffix.data()));
424 c_pars.Print(Form(
"cdcdedx_bdcal_%s_%s.pdf", qaname[iqa].data(),
m_suffix.data()));
435 TCanvas cstats(
"cstats",
"cstats", 1000, 500);
436 cstats.SetBatch(kTRUE);
440 auto hestats = getObjectPtr<TH1I>(
"hestats");
442 hestats->SetName(Form(
"htstats_%s",
m_suffix.data()));
443 hestats->SetStats(0);
444 hestats->DrawCopy(
"");
448 auto htstats = getObjectPtr<TH1I>(
"htstats");
450 htstats->SetName(Form(
"htstats_%s",
m_suffix.data()));
451 htstats->SetStats(0);
452 htstats->DrawCopy(
"");
455 cstats.Print(Form(
"cdcdedx_bdcal_qastats_%s.pdf",
m_suffix.data()));
void setHistCosmetics(TH2F *hist, Color_t color)
function to change histogram styles
void plotBadWireMap(const std::vector< double > &vbadwires, const std::vector< double > &vdeadwires)
function to plot wire status map (all, bad and dead)
double m_varMax
max range for input variable
double m_rmsThres
rms Threshold accepted for good wire
void plotWireDist(const std::vector< double > &inwires, std::map< int, std::vector< double >> &vhitvar)
function to draw per wire plots
double m_varMin
min range for input variable
std::string m_varName
std::string to set var name (adc or dedx)
void getExpRunInfo()
function to get extract calibration run/exp
unsigned int c_nwireCDC
number of wires in CDC
double m_arms
average rms of dedx for all wires
bool m_isMakePlots
produce plots for status
DBObjPtr< CDCDedxBadWires > m_DBBadWires
Badwire DB object.
std::string m_suffix
suffix std::string for naming plots
void setTextCosmetics(TPaveText *pt, double size)
function to change text styles
CDCDedxBadWireAlgorithm()
Constructor: Sets the description, the properties and the parameters of the algorithm.
DBObjPtr< CDCGeometry > m_cdcGeo
Geometry of CDC.
void plotQaPars(std::map< int, std::vector< double >> &qapars)
function to plot the QA (decision) parameters
double m_meanThres
mean Threshold accepted for good wire
DBObjPtr< CDCDedxWireGain > m_DBWireGains
Wiregain DB object.
double m_fracThres
high-frac Threshold accepted for good wire
int m_varBins
number of bins for input variable
void printCanvas(TList *list, TList *hflist, Color_t color)
function to print canvas
void plotEventStats()
function to draw the stats
virtual EResult calibrate() override
cdcdedx badwire algorithm
double m_amean
average mean of dedx for all wires
bool m_isADC
Use adc if(true) else dedx for calibration.
TH2F * getHistoPattern(const std::vector< double > &inwires, const std::string &suffix, int &total)
function to get wire map with input file (all, bad and dead)
dE/dx wire gain calibration constants
The Class for CDC Geometry Parameters.
unsigned nWiresInLayer(int layerId) const
Returns wire numbers in a layer.
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.
Base class for calibration algorithms.
void saveCalibration(TClonesArray *data, const std::string &name)
Store DBArray payload with given name with default IOV.
void updateDBObjPtrs(const unsigned int event, const int run, const int experiment)
Updates any DBObjPtrs by calling update(event) for DBStore.
void setDescription(const std::string &description)
Set algorithm description (in constructor)
EResult
The result of calibration.
@ c_OK
Finished successfuly =0 in Python.
@ c_NotEnoughData
Needs more data =2 in Python.
const std::vector< Calibration::ExpRun > & getRunList() const
Get the list of runs for which calibration is called.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.