Belle II Software release-09-00-04
CDCDedx1DCellAlgorithm.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <cdc/calibration/CDCdEdx/CDCDedx1DCellAlgorithm.h>
10#include <cmath>
11
12using namespace Belle2;
13
14//-----------------------------------------------------------------
15// Implementation
16//-----------------------------------------------------------------
18 CalibrationAlgorithm("CDCDedxElectronCollector"),
19 m_eaMin(-TMath::Pi() / 2),
20 m_eaMax(+TMath::Pi() / 2),
21 m_eaB(316),
22 m_dedxMin(0.0),
23 m_dedxMax(5.0),
24 m_dedxBin(250),
25 m_ptMax(8.0),
26 m_cosMax(1.0),
27 m_truncMin(0.05),
28 m_truncMax(0.75),
29 m_binSplit(3),
30 m_chargeType(0),
31 m_adjustFac(1.00),
32 isFixTrunc(false),
33 isVarBins(true),
34 isRotSymm(false),
35 isMakePlots(true),
36 isPrintLog(false),
37 isMerge(true),
38 m_suffix("")
39{
40 // Set module properties
41 setDescription("A calibration algorithm for the CDC dE/dx entrance angle cleanup correction");
42}
43
44//-----------------------------------------------------------------
45// Run the calibration
46//-----------------------------------------------------------------
48{
49
51
52 if (!m_DBOneDCell.isValid())
53 B2FATAL("There is no valid previous payload for CDCDedx1DCell");
54
55 //reading radiative electron collector TREE
56 auto ttree = getObjectPtr<TTree>("tree");
57 if (!ttree) return c_NotEnoughData;
58
59 std::vector<double>* dedxhit = 0, *enta = 0;
60 std::vector<int>* layer = 0;
61 double pt = 0, costh = 0;
62
63 ttree->SetBranchAddress("dedxhit", &dedxhit);
64 ttree->SetBranchAddress("entaRS", &enta);
65 ttree->SetBranchAddress("layer", &layer);
66 ttree->SetBranchAddress("pt", &pt);
67 ttree->SetBranchAddress("costh", &costh);
68
69 //repair nbins if they are not divisible accordingly
72
73 //Settings of variables bins
75
76 if (isPrintLog) {
77 B2INFO("inner layers bins: " << m_eaBinLocal[0]);
78 B2INFO("outer layers bins: " << m_eaBinLocal[1]);
79 }
80
81 // dedxhit vector to store dE/dx values for each enta bin
82 std::vector<TH1D*> hdedxhit[2];
83 TH1D* hdedxlay[2];
84 TH1D* hentalay[2];
85
86 TH2D* hptcosth = new TH2D("hptcosth", "pt vs costh dist;pt;costh", 1000, -8.0, 8.0, 1000, -1.0, 1.0);
87
88 defineHisto(hdedxhit, hdedxlay, hentalay);
89
90 //Star filling histogram defined above
91 for (int i = 0; i < ttree->GetEntries(); ++i) {
92
93 ttree->GetEvent(i);
94
95 if (std::abs(costh) > m_cosMax) continue;
96
97 // remove wide angle bhabha tracks
98 // double mom = pt/sqrt(1-costh*costh);
99 // if(abs(pt)<2.4 && abs(mom)>3.6)continue;
100
101 if (std::abs(pt) > m_ptMax) continue;
102
103 //change to random 10%
104 int rand = gRandom->Integer(100);
105 if (rand < 10) hptcosth->Fill(pt, costh);
106
107 for (unsigned int j = 0; j < dedxhit->size(); ++j) {
108
109 if (dedxhit->at(j) == 0) continue;
110
111 double entaval = enta->at(j);
112 //Mapped bin corresponds to entaval
113 int ibin = std::floor((entaval - m_eaMin) / m_eaBW);
114 if (ibin < 0 || ibin > m_eaBin) continue;
115
116 int mL = -1;
117 if (layer->at(j) < 8)mL = 0;
118 else mL = 1;
119
120 hdedxlay[mL]->Fill(dedxhit->at(j));
121 if (rand < 10) hentalay[mL]->Fill(entaval);
122
123 int jbinea = ibin;
124 if (isVarBins) jbinea = m_binIndex[mL].at(ibin);
125 hdedxhit[mL][jbinea]->Fill(dedxhit->at(j));
126 }
127 }
128
129 for (int il = 0; il < 2; il++) {
130
131 int minlay = 0, maxlay = 0;
132
133 if (isFixTrunc) {
134 getTruncatedBins(hdedxlay[il], minlay, maxlay);
135 hdedxlay[il]->SetTitle(Form("%s;%d;%d", hdedxlay[il]->GetTitle(), minlay, maxlay));
136 }
137
138 std::vector<double>tempconst;
139 tempconst.reserve(m_eaBinLocal[il]);
140
141 for (int iea = 0; iea < m_eaBinLocal[il]; iea++) {
142
143 int jea = iea;
144
145 // rotation symmtery for 1<->3 and 4<->2 but only symmetric bin
146 if (!isVarBins && isRotSymm) jea = rotationalBin(m_eaBinLocal[il], jea);
147
148 TH1D* htemp = (TH1D*)hdedxhit[il][jea]->Clone(Form("h_%s_b%d_c", m_label[il].data(), jea));
149
150 int minbin = 1, maxbin = 1;
151 if (isFixTrunc) {
152 minbin = minlay;
153 maxbin = maxlay;
154 } else {
155 //extract truncation window per bin
156 getTruncatedBins(htemp, minbin, maxbin);
157 }
158
159 double dedxmean;
160 dedxmean = getTruncationMean(htemp, minbin, maxbin);
161 tempconst.push_back(dedxmean);
162
163 hdedxhit[il][iea]->SetTitle(Form("%s, #mu_{truc} = %0.5f;%d;%d", hdedxhit[il][iea]->GetTitle(), dedxmean, minbin, maxbin));
164 }
165
166 //Expending constants
167 std::vector<double>layerconst;
168 layerconst.reserve(m_eaBin);
169
170 for (int iea = 0; iea < m_eaBin; iea++) {
171 int jea = iea;
172 if (isVarBins) jea = m_binIndex[il].at(iea);
173 layerconst.push_back(tempconst.at(jea));
174 }
175
176 // plot the rel constants var/sym bins
177 if (isMakePlots) plotRelConst(tempconst, layerconst, il);
178 m_onedcors.push_back(layerconst);
179
180 layerconst.clear();
181 tempconst.clear();
182 }
183
184 //Saving final constants
186
187 if (isMakePlots) {
188
189 //1. dE/dx dist. for entrance angle bins
190 plotdedxHist(hdedxhit);
191
192 //3. Inner and Outer layer dE/dx distributions
193 plotLayerDist(hdedxlay);
194
195 //4. entrance angle distribution sym/var bins
196 plotQaPars(hentalay, hptcosth);
197
198 //6. draw the final constants
200
201 //7. plot statistics related plots here
203 }
204
205 for (int il = 0; il < 2; il++) {
206 delete hentalay[il];
207 delete hdedxlay[il];
208 for (int iea = 0; iea < m_eaBinLocal[il]; iea++)
209 delete hdedxhit[il][iea];
210 }
211
212 delete hptcosth;
213 m_eaBinLocal.clear();
214 for (int il = 0; il < 2; il++) {
215 m_binValue[il].clear();
216 m_binIndex[il].clear();
217 }
218 return c_OK;
219}
220
221//--------------------------------------------------
223{
224
225 int cruns = 0;
226 for (auto expRun : getRunList()) {
227 if (cruns == 0) B2INFO("CDCDedxBadWires: start exp " << expRun.first << " and run " << expRun.second << "");
228 cruns++;
229 }
230
231 const auto erStart = getRunList()[0];
232 int estart = erStart.first;
233 int rstart = erStart.second;
234
235 const auto erEnd = getRunList()[cruns - 1];
236 int eend = erEnd.first;
237 int rend = erEnd.second;
238
239 updateDBObjPtrs(1, rstart, estart);
240
241 m_runExp = Form("Range (%d:%d,%d:%d)", estart, rstart, eend, rend);
242 if (m_suffix.length() > 0) m_suffix = Form("%s_e%d_r%dr%d", m_suffix.data(), estart, rstart, rend);
243 else m_suffix = Form("e%d_r%dr%d", estart, rstart, rend);
244}
245
246//--------------------------------------------------
248{
249
250 std::map<int, std::vector<double>> bounds;
251 std::map<int, std::vector<int>> steps;
252
253 const std::array<int, 2> nDev{8, 4};
254 bounds[0] = {0, 108, 123, 133, 158, 183, 193, 208, 316}; //il boundries
255 steps[0] = {9, 3, 2, 1, 1, 2, 3, 9}; //il steps
256 bounds[1] = {0, 38, 158, 278, 316}; //OL boundries
257 steps[1] = {2, 1, 1, 2}; //OL steps
258
259 for (int il = 0; il < 2; il++) {
260
261 for (int ibin = 0; ibin <= nDev[il]; ibin++) bounds[il][ibin] = bounds[il][ibin] * m_binSplit;
262
263 int ieaprime = -1, temp = -99, ibin = 0;
264
265 double pastbin = m_eaMin;
266 m_binValue[il].push_back(pastbin);
267
268 for (int iea = 0; iea < m_eaBin; iea++) {
269
270 if (isVarBins) {
271 if (iea % int(bounds[il][ibin + 1]) == 0 && iea > 0) ibin++;
272 int diff = iea - int(bounds[il][ibin]);
273 if (diff % steps[il][ibin] == 0) ieaprime++;
274 } else ieaprime = iea;
275
276 m_binIndex[il].push_back(ieaprime);
277
278 if (ieaprime != temp) {
279 double binwidth = m_eaBW;
280 if (isVarBins) binwidth = m_eaBW * steps[il][ibin];
281 double binvalue = pastbin + binwidth;
282 pastbin = binvalue;
283 if (std::abs(binvalue) < 1e-5)binvalue = 0;
284 m_binValue[il].push_back(binvalue);
285 }
286 temp = ieaprime;
287 }
288 m_eaBinLocal.push_back(int(m_binValue[il].size()) - 1) ;
289 }
290 if (isMakePlots) plotMergeFactor(bounds, nDev, steps);
291}
292
293//--------------------------------------------------
294void CDCDedx1DCellAlgorithm::defineHisto(std::vector<TH1D*> hdedxhit[2], TH1D* hdedxlay[2], TH1D* hentalay[2])
295{
296 for (int il = 0; il < 2; il++) {
297
298 std::string title = Form("dedxhit dist (%s): %s ; dedxhit;entries", m_label[il].data(), m_runExp.data());
299 hdedxlay[il] = new TH1D(Form("hdedxlay%s", m_label[il].data()), "", m_dedxBin, m_dedxMin, m_dedxMax);
300 hdedxlay[il]->SetTitle(Form("%s", title.data()));
301
302 Double_t* nvarBins;
303 nvarBins = &m_binValue[il][0];
304
305 if (isVarBins) title = Form("entaRS dist (variable bins): %s: (%s); entaRS (#alpha);entries", m_label[il].data(), m_runExp.data());
306 else title = Form("entaRS dist (sym. bins): %s: (%s); entaRS (#alpha);entries", m_label[il].data(), m_runExp.data());
307
308 hentalay[il] = new TH1D(Form("hentalay%s", m_label[il].data()), "", m_eaBinLocal[il], nvarBins);
309 hentalay[il]->SetTitle(Form("%s", title.data()));
310
311 for (int iea = 0; iea < m_eaBinLocal[il]; iea++) {
312
313 double min = m_binValue[il].at(iea);
314 double max = m_binValue[il].at(iea + 1);
315 double width = max - min;
316
317 if (isPrintLog) B2INFO("bin: " << iea << " ], min:" << min << " , max: " << max << " , width: " << width);
318
319 title = Form("%s: entaRS = (%0.03f to %0.03f)", m_label[il].data(), min, max);
320 hdedxhit[il].push_back(new TH1D(Form("hdedxhit_%s_bin%d", m_label[il].data(), iea), "", m_dedxBin, m_dedxMin, m_dedxMax));
321 hdedxhit[il][iea]->SetTitle(Form("%s", title.data()));
322 }
323 }
324}
325
326//--------------------------------------------------
327void CDCDedx1DCellAlgorithm::getTruncatedBins(TH1D* hist, int& binlow, int& binhigh)
328{
329
330 //calculating truncation average
331 double sum = hist->Integral();
332 if (sum <= 0 || hist->GetNbinsX() <= 0) {
333 binlow = 1; binhigh = 1;
334 return ;
335 }
336
337 binlow = 1.0; binhigh = 1.0;
338 double sumPer5 = 0.0, sumPer75 = 0.0;
339 for (int ibin = 1; ibin <= hist->GetNbinsX(); ibin++) {
340 double bcdedx = hist->GetBinContent(ibin);
341 if (sumPer5 <= m_truncMin * sum) {
342 sumPer5 += bcdedx;
343 binlow = ibin;
344 }
345 if (sumPer75 <= m_truncMax * sum) {
346 sumPer75 += bcdedx;
347 binhigh = ibin;
348 }
349 }
350 return;
351}
352
353//--------------------------
354double CDCDedx1DCellAlgorithm::getTruncationMean(TH1D* hist, int binlow, int binhigh)
355{
356
357 //calculating truncation average
358 if (hist->Integral() < 100) return 1.0;
359
360 if (binlow <= 0 || binhigh > hist->GetNbinsX())return 1.0;
361
362 double binweights = 0., sumofbc = 0.;
363 for (int ibin = binlow; ibin <= binhigh; ibin++) {
364 double bcdedx = hist->GetBinContent(ibin);
365 if (bcdedx > 0) {
366 binweights += (bcdedx * hist->GetBinCenter(ibin));
367 sumofbc += bcdedx;
368 }
369 }
370 if (sumofbc > 0) return binweights / sumofbc;
371 else return 1.0;
372}
373
374//--------------------------------------------------
376{
377
378 B2INFO("dE/dx one cell calibration: Generating payloads");
379
380 for (unsigned int il = 0; il < 2; il++) {
381
382 if (isMerge) {
383 unsigned int nbins = m_DBOneDCell->getNBins(il);
384
385 if (int(nbins) != m_eaBin)
386 B2ERROR("merging failed because of unmatch bins (old " << m_eaBin << " new " << nbins << ")");
387
388 for (unsigned int iea = 0; iea < nbins; iea++) {
389 double prev = m_DBOneDCell->getMean(8 * il + 1, iea);
390 m_onedcors[il][iea] *= prev;
391 }
392 }
393
394 double binsize = TMath::Pi() / m_onedcors[il].size();
395
396 auto computeAverages = [&](double angLow, double angHigh, const std::string & label) {
397 unsigned int binLow = std::floor((angLow + TMath::Pi() / 2.0) / binsize);
398 unsigned int binHigh = std::floor((angHigh + TMath::Pi() / 2.0) / binsize);
399 double sum_new = 0.0, sum_prev = 0.0;
400 int count = 0;
401
402 for (unsigned int iea = binLow; iea < binHigh; ++iea) {
403 sum_new += m_onedcors[il][iea];
404 sum_prev += m_DBOneDCell->getMean(8 * il + 1, iea);
405 ++count;
406 }
407
408 double avg_new = (count > 0) ? sum_new / count : 1.0;
409 double avg_prev = (count > 0) ? sum_prev / count : 1.0;
410 return std::make_pair(avg_new, avg_prev);
411 };
412
413 double negLow = -0.75, negHigh = -0.25;
414 double posLow = 0.25, posHigh = 0.75;
415
416 if (il == 0) {
417 negLow = -0.5; negHigh = -0.2;
418 posLow = 0.2; posHigh = 0.5;
419 }
420
421 auto [avgNewNeg, avgPrevNeg] = computeAverages(negLow, negHigh, "Negative");
422 auto [avgNewPos, avgPrevPos] = computeAverages(posLow, posHigh, "Positive");
423
424 double avgNew = (avgNewNeg + avgNewPos) / 2.0;
425 double avgPrev = (avgPrevNeg + avgPrevPos) / 2.0;
426 double scaleFactor = avgPrev / avgNew;
427
428 for (unsigned int iea = 0; iea < m_eaBin; iea++) {
429 m_onedcors[il][iea] *= scaleFactor;
430 }
431
432 if (m_chargeType > 0)
433 for (int ie = 0; ie < m_eaBin / 2; ie++) m_onedcors[il][ie] *= m_adjustFac;
434 if (m_chargeType < 0)
435 for (int ie = m_eaBin / 2; ie < m_eaBin; ie++) m_onedcors[il][ie] *= m_adjustFac;
436
437 }
438 //Saving constants
439 B2INFO("dE/dx Calibration done for CDCDedx1DCell");
440 CDCDedx1DCell* gain = new CDCDedx1DCell(0, m_onedcors);
441 saveCalibration(gain, "CDCDedx1DCell");
442}
443
444//--------------------------------------------------
445void CDCDedx1DCellAlgorithm::plotMergeFactor(std::map<int, std::vector<double>> bounds, const std::array<int, 2> nDev,
446 std::map<int, std::vector<int>> steps)
447{
448
449 TCanvas cmfactor("cmfactor", "Merging factors", 800, 400);
450 cmfactor.Divide(2, 1);
451
452 for (int il = 0; il < 2; il++) {
453 Double_t* nvarBins;
454 nvarBins = &bounds[il][0];
455
456 TH1I* hist = new TH1I(Form("hist_%s", m_label[il].data()), "", nDev[il], nvarBins);
457 hist->SetTitle(Form("Merging factor for %s bins;binindex;merge-factors", m_label[il].data()));
458
459 for (int ibin = 0; ibin < nDev[il]; ibin++) hist->SetBinContent(ibin + 1, steps[il][ibin]);
460
461 cmfactor.cd(il + 1);
462 hist->SetFillColor(kYellow);
463 hist->Draw("hist");
464 delete hist;
465 }
466
467 cmfactor.SaveAs(Form("cdcdedx_1dcell_mergefactor%s.pdf", m_suffix.data()));
468 cmfactor.SaveAs(Form("cdcdedx_1dcell_mergefactor%s.root", m_suffix.data()));
469}
470
471//--------------------------------------------------
472void CDCDedx1DCellAlgorithm::plotdedxHist(std::vector<TH1D*> hdedxhit[2])
473{
474
475 TCanvas ctmp("tmp", "tmp", 1200, 1200);
476 ctmp.Divide(4, 4);
477 std::stringstream psname;
478
479 psname << Form("cdcdedx_1dcell_dedxhit%s.pdf[", m_suffix.data());
480 ctmp.Print(psname.str().c_str());
481 psname.str("");
482 psname << Form("cdcdedx_1dcell_dedxhit%s.pdf", m_suffix.data());
483
484 for (int il = 0; il < 2; il++) {
485
486 for (int jea = 0; jea < m_eaBinLocal[il]; jea++) {
487
488 int minbin = std::stoi(hdedxhit[il][jea]->GetXaxis()->GetTitle());
489 int maxbin = std::stoi(hdedxhit[il][jea]->GetYaxis()->GetTitle());
490
491 ctmp.cd(jea % 16 + 1);
492 hdedxhit[il][jea]->SetFillColor(4 + il);
493
494 hdedxhit[il][jea]->SetTitle(Form("%s;dedxhit;entries", hdedxhit[il][jea]->GetTitle()));
495 hdedxhit[il][jea]->DrawClone("hist");
496 TH1D* htempC = (TH1D*)hdedxhit[il][jea]->Clone(Form("%sc2", hdedxhit[il][jea]->GetName()));
497 htempC->GetXaxis()->SetRange(minbin, maxbin);
498 htempC->SetFillColor(kGray);
499 htempC->DrawClone("same hist");
500
501 if (jea % 16 == 15 || (jea == m_eaBinLocal[il] - 1)) {
502 ctmp.Print(psname.str().c_str());
503 gPad->Clear("D");
504 ctmp.Clear("D");
505 }
506 delete htempC;
507 }
508 }
509 psname.str("");
510 psname << Form("cdcdedx_1dcell_dedxhit%s.pdf]", m_suffix.data());
511 ctmp.Print(psname.str().c_str());
512}
513
514//--------------------------------------------------
516{
517
518 TCanvas cdedxlayer("layerdedxhit", "Inner and Outer Layer dedxhit dist", 900, 400);
519 cdedxlayer.Divide(2, 1);
520
521 for (int il = 0; il < 2; il++) {
522 int minlay = 0, maxlay = 0;
523 if (isFixTrunc) {
524 minlay = std::stoi(hdedxlay[il]->GetXaxis()->GetTitle());
525 maxlay = std::stoi(hdedxlay[il]->GetYaxis()->GetTitle());
526 double lowedge = hdedxlay[il]->GetXaxis()->GetBinLowEdge(minlay);
527 double upedge = hdedxlay[il]->GetXaxis()->GetBinUpEdge(maxlay);
528 hdedxlay[il]->SetTitle(Form("%s, trunc #rightarrow: %0.02f - %0.02f;dedxhit;entries", hdedxlay[il]->GetTitle(), lowedge, upedge));
529 }
530
531 cdedxlayer.cd(il + 1);
532 hdedxlay[il]->SetFillColor(kYellow);
533 hdedxlay[il]->Draw("histo");
534
535 if (isFixTrunc) {
536 TH1D* hdedxlayC = (TH1D*)hdedxlay[il]->Clone(Form("hdedxlayC%d", il));
537 hdedxlayC->GetXaxis()->SetRange(minlay, maxlay);
538 hdedxlayC->SetFillColor(kAzure + 1);
539 hdedxlayC->Draw("same histo");
540 }
541 }
542
543 cdedxlayer.SaveAs(Form("cdcdedx_1dcell_dedxlay%s.pdf", m_suffix.data()));
544 cdedxlayer.SaveAs(Form("cdcdedx_1dcell_dedxlay%s.root", m_suffix.data()));
545}
546
547//--------------------------------------------------
548void CDCDedx1DCellAlgorithm::plotQaPars(TH1D* hentalay[2], TH2D* hptcosth)
549{
550
551 TCanvas ceadist("ceadist", "Enta distributions", 800, 400);
552 ceadist.Divide(2, 1);
553
554 for (int il = 0; il < 2; il++) {
555
556 ceadist.cd(il + 1);
557 gPad->SetLogy();
558 hentalay[il]->SetFillColor(kYellow);
559 hentalay[il]->Draw("hist");
560 }
561
562 TCanvas cptcos("cptcos", "pt vs costh dist.", 400, 400);
563 cptcos.cd();
564 hptcosth->Draw("colz");
565
566 cptcos.SaveAs(Form("cdcdedx_ptcosth_%s.pdf", m_suffix.data()));
567 ceadist.SaveAs(Form("cdcdedx_1dcell_enta%s.pdf", m_suffix.data()));
568 ceadist.SaveAs(Form("cdcdedx_1dcell_enta%s.root", m_suffix.data()));
569}
570
571//--------------------------------------------------
572void CDCDedx1DCellAlgorithm::plotRelConst(std::vector<double>tempconst, std::vector<double>layerconst, int il)
573{
574
575 TH1D* hconst, *hconstvar;
576
577 Double_t* nvarBins;
578 nvarBins = &m_binValue[il][0];
579
580 hconst = new TH1D(Form("hconst%s", m_label[il].data()), "", m_eaBin, m_eaMin, m_eaMax);
581 std::string title = Form("calibration const dist: %s: (%s); entaRS (#alpha); entries", m_label[il].data(), m_runExp.data());
582 hconst->SetTitle(Form("%s", title.data()));
583
584 hconstvar = new TH1D(Form("hconstvar%s", m_label[il].data()), "", m_eaBinLocal[il], nvarBins);
585 title = Form("calibration const dist (var bins): %s: (%s); entaRS (#alpha);entries", m_label[il].data(), m_runExp.data());
586 hconstvar->SetTitle(Form("%s", title.data()));
587
588 if (isVarBins) {
589 for (int iea = 0; iea < m_eaBinLocal[il]; iea++)
590 hconstvar->SetBinContent(iea + 1, tempconst.at(iea));
591 }
592
593 for (int jea = 0; jea < m_eaBin; jea++) hconst->SetBinContent(jea + 1, layerconst.at(jea));
594
595 gStyle->SetOptStat("ne");
596 TCanvas cconst("cconst", "Calirbation Constants", 800, 400);
597 if (isVarBins) {
598 cconst.Divide(2, 1);
599 cconst.SetWindowSize(1000, 800);
600 }
601
602 cconst.cd(1);
603 hconst->SetFillColor(kYellow);
604 hconst->Draw("histo");
605 if (isVarBins) {
606 cconst.cd(2);
607 hconstvar->SetFillColor(kBlue);
608 hconstvar->Draw("hist");
609 }
610 cconst.SaveAs(Form("cdcdedx_1dcell_relconst%s_%s.pdf", m_label[il].data(), m_suffix.data()));
611 cconst.SaveAs(Form("cdcdedx_1dcell_relconst%s_%s.root", m_label[il].data(), m_suffix.data()));
612
613 delete hconst;
614 delete hconstvar;
615}
616
617//--------------------------------------------------
619{
620
621 //Draw New/Old final constants
622 TH1D* hnewconst[2], *holdconst[2];
623 double min[2], max[2];
624
625 for (unsigned int il = 0; il < 2; il++) {
626 unsigned int nbins = m_DBOneDCell->getNBins(il);
627
628 std::string title = Form("final calibration const dist (%s): %s; entaRS (#alpha); entries", m_label[il].data(), m_runExp.data());
629 hnewconst[il] = new TH1D(Form("hnewconst_%s", m_label[il].data()), "", m_eaBin, m_eaMin, m_eaMax);
630 hnewconst[il]->SetTitle(Form("%s", title.data()));
631
632 title = Form("old calibration const dist (%s): %s; entaRS (#alpha); entries", m_label[il].data(), m_runExp.data());
633 holdconst[il] = new TH1D(Form("holdconst_%s", m_label[il].data()), "", m_eaBin, m_eaMin, m_eaMax);
634 holdconst[il]->SetTitle(Form("%s", title.data()));
635
636 for (unsigned int iea = 0; iea < nbins; iea++) {
637 double prev = m_DBOneDCell->getMean(8 * il + 1, iea);
638 holdconst[il]->SetBinContent(iea + 1, prev);
639 hnewconst[il]->SetBinContent(iea + 1, m_onedcors[il][iea]);
640 }
641 min[il] = hnewconst[il]->GetMinimum();
642 max[il] = hnewconst[il]->GetMaximum();
643 }
644
645 //Ploting final constants
646 if (max[1] < max[0])max[1] = max[0];
647 if (min[1] > min[0])min[1] = min[0];
648
649 gStyle->SetOptStat("ne");
650 TCanvas cfconst("cfconst", "Final calirbation constants", 800, 400);
651 cfconst.Divide(2, 1);
652
653 for (int il = 0; il < 2; il++) {
654 cfconst.cd(il + 1);
655 hnewconst[il]->GetYaxis()->SetRangeUser(min[1] * 0.95, max[1] * 1.05);
656 hnewconst[il]->SetLineColor(kBlack);
657 hnewconst[il]->Draw("histo");
658 holdconst[il]->SetLineColor(kRed);
659 holdconst[il]->Draw("histo same");
660
661 auto legend = new TLegend(0.4, 0.75, 0.56, 0.85);
662 legend->AddEntry(holdconst[il], "Old", "lep");
663 legend->AddEntry(hnewconst[il], "New", "lep");
664 legend->Draw();
665 }
666
667 cfconst.SaveAs(Form("cdcdedx_1dcell_fconsts%s.pdf", m_suffix.data()));
668 cfconst.SaveAs(Form("cdcdedx_1dcell_fconsts%s.root", m_suffix.data()));
669
670 for (int il = 0; il < 2; il++) {
671 delete hnewconst[il];
672 delete holdconst[il];
673 }
674}
675
676//------------------------------------
678{
679
680 TCanvas cstats("cstats", "cstats", 1000, 500);
681 cstats.SetBatch(kTRUE);
682 cstats.Divide(2, 1);
683
684 cstats.cd(1);
685 auto hestats = getObjectPtr<TH1I>("hestats");
686 if (hestats) {
687 hestats->SetName(Form("hestats_%s", m_suffix.data()));
688 hestats->SetStats(0);
689 hestats->DrawCopy("");
690 }
691
692 cstats.cd(2);
693 auto htstats = getObjectPtr<TH1I>("htstats");
694 if (htstats) {
695 hestats->SetName(Form("htstats_%s", m_suffix.data()));
696 htstats->DrawCopy("");
697 hestats->SetStats(0);
698 }
699 cstats.Print(Form("cdcdedx_1dcell_stats_%s.pdf", m_suffix.data()));
700}
CDCDedx1DCellAlgorithm()
Constructor: Sets the description, the properties and the parameters of the algorithm.
std::string m_label[2]
add inner/outer layer label
double m_eaMax
upper edge of entrance angle
void plotMergeFactor(std::map< int, std::vector< double > > bounds, const std::array< int, 2 > nDev, std::map< int, std::vector< int > > steps)
function to plot merging factor
double m_truncMax
upper threshold on truncation
int m_binSplit
multiply nbins by this factor in full range
std::array< std::vector< int >, 2 > m_binIndex
symm/Var bin numbers
double m_truncMin
lower threshold on truncation
double m_adjustFac
factor with that one what to adjust baseline
void getTruncatedBins(TH1D *hist, int &binlow, int &binhigh)
function to get bins of truncation from histogram
void CreateBinMapping()
class function to create vectors for bin mapping (Var->symm)
double m_chargeType
charge type for baseline adj
void getExpRunInfo()
function to get extract calibration run/exp
DBObjPtr< CDCDedx1DCell > m_DBOneDCell
One cell correction DB object.
double m_cosMax
a limit on cos theta
bool isPrintLog
print more debug information
std::array< std::vector< double >, 2 > m_binValue
enta Var bin values
std::string m_suffix
add suffix to all plot name
int m_eaB
reset # of bins for entrance angle for each experiment
double getTruncationMean(TH1D *hist, int binlow, int binhigh)
function to get truncated mean
double m_ptMax
a limit on transverse momentum
void plotConstants()
function to draw the old/new final constants
bool isFixTrunc
true = fix window for all out/inner layers
bool isVarBins
true: if variable bin size is requested
void plotdedxHist(std::vector< TH1D * > hdedxhit[2])
function to draw the dE/dx histogram in enta bins
void defineHisto(std::vector< TH1D * > hdedxhit[2], TH1D *hdedxlay[2], TH1D *hentalay[2])
function to define histograms
double m_eaBW
binwdith of entrance angle bin
bool isRotSymm
if rotation symmetry requested
std::string m_runExp
add suffix to all plot name
void plotEventStats()
function to draw the stats plots
int rotationalBin(int nbin, int ibin)
class function to set rotation symmetry
virtual EResult calibrate() override
1D cell algorithm
void plotQaPars(TH1D *hentalay[2], TH2D *hptcosth)
function to draw pt vs costh and entrance angle distribution for Inner/Outer layer
double m_dedxMax
upper edge of dedxhit
void createPayload()
function to generate final constants
bool isMakePlots
produce plots for status
void plotRelConst(std::vector< double >tempconst, std::vector< double >layerconst, int il)
function to draw symm/Var layer constant
std::vector< std::vector< double > > m_onedcors
final vectors of calibration
bool isMerge
print more debug information
double m_dedxMin
lower edge of dedxhit
void plotLayerDist(TH1D *hdedxL[2])
function to draw dedx dist.
double m_eaMin
lower edge of entrance angle
dE/dx wire gain calibration constants
Definition: CDCDedx1DCell.h:26
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)
const std::vector< Calibration::ExpRun > & getRunList() const
Get the list of runs for which calibration is called.
EResult
The result of calibration.
@ c_OK
Finished successfuly =0 in Python.
@ c_NotEnoughData
Needs more data =2 in Python.
Abstract base class for different kinds of events.