11 #include <reconstruction/calibration/CDCDedx2DCellAlgorithm.h>
13 #include <reconstruction/dbobjects/CDCDedx2DCell.h>
38 feaLE(-TMath::Pi() / 2),
39 feaUE(+TMath::Pi() / 2),
48 setDescription(
"A calibration algorithm for the CDC dE/dx two dimensional correction");
59 auto ttree = getObjectPtr<TTree>(
"tree");
62 std::vector<double>* dedxhit = 0, *doca = 0, *enta = 0;
63 std::vector<int>* layer = 0;
65 ttree->SetBranchAddress(
"dedxhit", &dedxhit);
66 ttree->SetBranchAddress(
"layer", &layer);
67 ttree->SetBranchAddress(
"docaRS", &doca);
68 ttree->SetBranchAddress(
"entaRS", &enta);
74 std::vector<int> globalbinsEnta, globalbinsDoca;
75 for (
int ibin = 0; ibin <
fnEntaBinG; ibin++)globalbinsEnta.push_back(ibin);
76 for (
int ibin = 0; ibin <
fnDocaBinG; ibin++)globalbinsDoca.push_back(ibin);
89 std::vector<std::vector<TH1F*>> hILdEdxhitInEntaDocaBin(
fnEntaBinL, std::vector<TH1F*>(
fnDocaBinL, 0));
90 std::vector<std::vector<TH1F*>> hOLdEdxhitInEntaDocaBin(
fnEntaBinL, std::vector<TH1F*>(
fnDocaBinL, 0));
91 Double_t ifeaLE = 0, ifeaUE = 0, ifdocaLE = 0, ifdocaUE = 0;
99 ifeaUE = ifeaLE +
feaBS;
102 for (
int idoca = 0; idoca <
fnDocaBinL; idoca++) {
107 hILdEdxhitInEntaDocaBin[iea][idoca] =
new TH1F(Form(
"hILdEdxhitInEntaBin%dDocaBin%d", iea, idoca),
"bla-bla", 500, 0., 5.);
108 hILdEdxhitInEntaDocaBin[iea][idoca]->SetTitle(Form(
"IL: EntA = (%0.03f to %0.03f) and Doca = (%0.03f to %0.03f)", ifeaLE,
109 ifeaUE, ifdocaLE, ifdocaUE));
110 hILdEdxhitInEntaDocaBin[iea][idoca]->GetXaxis()->SetTitle(
"dedxhits in Inner Layer");
111 hILdEdxhitInEntaDocaBin[iea][idoca]->GetYaxis()->SetTitle(
"Entries");
113 hOLdEdxhitInEntaDocaBin[iea][idoca] =
new TH1F(Form(
"hOLdEdxhitInEntaBin%dDocaBin%d", iea, idoca),
"bla-bla", 500, 0., 5.);
114 hOLdEdxhitInEntaDocaBin[iea][idoca]->SetTitle(Form(
"OL: EntA = (%0.03f to %0.03f) and Doca = (%0.03f to %0.03f)", ifeaLE,
115 ifeaUE, ifdocaLE, ifdocaUE));
116 hOLdEdxhitInEntaDocaBin[iea][idoca]->GetXaxis()->SetTitle(
"dedxhits in Outer Layer");
117 hOLdEdxhitInEntaDocaBin[iea][idoca]->GetYaxis()->SetTitle(
"Entries");
124 hILDocaEntaG->GetXaxis()->SetTitle(
"Doca");
125 hILDocaEntaG->GetYaxis()->SetTitle(
"Entrance angle (#theta)");
128 hOLDocaEntaG->GetXaxis()->SetTitle(
"Doca");
129 hOLDocaEntaG->GetYaxis()->SetTitle(
"Entrance angle (#theta)");
135 hILDocaEntaL->GetXaxis()->SetTitle(
"Doca");
136 hILDocaEntaL->GetYaxis()->SetTitle(
"Entrance angle (#theta)");
140 hOLDocaEntaL->GetXaxis()->SetTitle(
"Doca");
141 hOLDocaEntaL->GetYaxis()->SetTitle(
"Entrance angle (#theta)");
143 TH1D* hILdEdx_all =
new TH1D(
"hILdEdx_all",
"", 500, 0., 5.);
144 TH1D* hOLdEdx_all =
new TH1D(
"hOLdEdx_all",
"", 500, 0., 5.);
147 Int_t ibinEA = 0, ibinDOCA = 0;
148 for (
int i = 0; i < ttree->GetEntries(); ++i) {
152 for (
unsigned int j = 0; j < dedxhit->size(); ++j) {
154 if (dedxhit->at(j) == 0)
continue;
156 Double_t ieaHit = enta->at(j);
157 if (ieaHit < -TMath::Pi() / 2.0) ieaHit += TMath::Pi() / 2.0;
158 else if (ieaHit > TMath::Pi() / 2.0) ieaHit -= TMath::Pi() / 2.0;
159 if (abs(ieaHit) > TMath::Pi() / 2.0)
continue;
161 Double_t idocaHit = doca->at(j);
162 if (abs(idocaHit) > 1.50)
continue;
175 if (layer->at(j) < 8) {
176 hILDocaEntaG->Fill(idocaHit, ieaHit);
177 if (
IsLocalBin)hILDocaEntaL->Fill(idocaHit, ieaHit);
178 hILdEdx_all->Fill(dedxhit->at(j));
179 hILdEdxhitInEntaDocaBin[ibinEA][ibinDOCA]->Fill(dedxhit->at(j));
181 hOLDocaEntaG->Fill(idocaHit, ieaHit);
182 if (
IsLocalBin)hOLDocaEntaL->Fill(idocaHit, ieaHit);
183 hOLdEdx_all->Fill(dedxhit->at(j));
184 hOLdEdxhitInEntaDocaBin[ibinEA][ibinDOCA]->Fill(dedxhit->at(j));
191 TCanvas* ctmpde =
new TCanvas(
"DocavsEnta",
"Doca vs Enta distributions", 800, 400);
193 ctmpde->SetCanvasSize(800, 800);
194 ctmpde->Divide(2, 2);
195 ctmpde->cd(1); hILDocaEntaG->Draw(
"colz");
196 ctmpde->cd(2); hOLDocaEntaG->Draw(
"colz");
197 ctmpde->cd(3); hILDocaEntaL->Draw(
"colz");
198 ctmpde->cd(4); hOLDocaEntaL->Draw(
"colz");
200 ctmpde->Divide(2, 1);
201 ctmpde->cd(1); hILDocaEntaG->Draw(
"colz");
202 ctmpde->cd(2); hOLDocaEntaG->Draw(
"colz");
204 ctmpde->SaveAs(Form(
"DocavsEnta_%s.pdf",
fSetPrefix.data()));
205 ctmpde->SaveAs(Form(
"DocavsEnta_%s.root",
fSetPrefix.data()));
207 TCanvas* ctem =
new TCanvas(
"Layerhisto",
"Inner and Outer Histo", 600, 600);
208 hOLdEdx_all->Draw(
"histo");
209 hILdEdx_all->SetMarkerColor(kRed);
210 hILdEdx_all->Draw(
"same histo");
211 ctem->SaveAs(Form(
"Layerhistodedxhit_TwoDCorr_%s.pdf",
fSetPrefix.data()));
216 double InsumPer5 = 0.0, InsumPer75 = 0.0;
217 double OutsumPer5 = 0.0, OutsumPer75 = 0.0;
218 double InLayInt = hILdEdx_all->Integral();
219 double OutLayInt = hOLdEdx_all->Integral();
221 Int_t lBinInLayer = 1, hBinInLayer = 1;
222 Int_t lBinOutLayer = 1, hBinOutLayer = 1;
224 for (
int ibin = 1; ibin <= hILdEdx_all->GetNbinsX(); ibin++) {
226 if (InsumPer5 <= 0.05 * InLayInt) {
227 InsumPer5 += hILdEdx_all->GetBinContent(ibin);
231 if (InsumPer75 <= 0.75 * InLayInt) {
232 InsumPer75 += hILdEdx_all->GetBinContent(ibin);
236 if (OutsumPer5 <= 0.05 * OutLayInt) {
237 OutsumPer5 += hOLdEdx_all->GetBinContent(ibin);
241 if (OutsumPer75 <= 0.75 * OutLayInt) {
242 OutsumPer75 += hOLdEdx_all->GetBinContent(ibin);
248 TCanvas* ctmp =
new TCanvas(
"tmp",
"tmp", 1200, 1200);
250 std::stringstream psname; psname << Form(
"dedx_2dcell_%s.pdf[",
fSetPrefix.data());
251 TLine* tl =
new TLine();
252 tl->SetLineColor(kRed);
254 TBox* tb =
new TBox();
257 ctmp->Print(psname.str().c_str());
258 psname.str(
""); psname << Form(
"dedx_2dcell_%s.pdf",
fSetPrefix.data());
261 gStyle->SetOptStat(
"nemriou");
263 std::vector<TH2F> twodcors;
269 std::ofstream file2DILout;
271 for (
int iIOLayer = 0; iIOLayer <= 1; iIOLayer++) {
273 file2DILout.open(Form(
"f2D_Constants_Local_Layer%d_%s.txt", iIOLayer,
fSetPrefix.data()));
275 int startfrom = 1, endat = 1;
277 startfrom = lBinInLayer; endat = hBinInLayer;
279 startfrom = lBinOutLayer; endat = hBinOutLayer;
285 Int_t ieaprime = iea;
288 for (
int idoca = 1; idoca <=
fnDocaBinL; idoca++) {
291 htemp = (TH1D*)hILdEdxhitInEntaDocaBin[ieaprime - 1][idoca - 1]->Clone(Form(
"hL%d_Ea%d_Doca%d", iIOLayer, iea, idoca));
292 else if (iIOLayer == 1)
293 htemp = (TH1D*)hOLdEdxhitInEntaDocaBin[ieaprime - 1][idoca - 1]->Clone(Form(
"hL%d_Ea%d_Doca%d", iIOLayer, iea, idoca));
296 double truncMean = 1.0;
297 if (htemp->GetEntries() < 400) truncMean = 1.0;
299 double binweights = 0.0;
301 for (
int ibin = startfrom; ibin <= endat; ibin++) {
303 if (htemp->GetBinContent(ibin) > 0) {
304 binweights += (htemp->GetBinContent(ibin) * htemp->GetBinCenter(ibin));
305 sumofbc += htemp->GetBinContent(ibin);
308 if (sumofbc > 0)truncMean = (double)(binweights / sumofbc);
309 else truncMean = 1.0;
312 if (truncMean <= 0)truncMean = 1.0;
313 tempTwoD.SetBinContent(idoca, iea, truncMean);
316 ctmp->cd(((idoca - 1) % 16) + 1);
317 htemp->SetTitle(Form(
"%s, mean = %0.4f", htemp->GetTitle(), truncMean));
318 htemp->SetFillColorAlpha(kGreen, 0.30);
319 if (truncMean >= 1.02 || truncMean <= 0.98)htemp->SetFillColor(kYellow);
320 if (truncMean >= 1.05 || truncMean <= 0.95)htemp->SetFillColor(kOrange);
321 if (truncMean >= 1.10 || truncMean <= 0.90)htemp->SetFillColor(kRed);
323 tl->SetLineColor(kRed);
324 tl->SetX1(truncMean); tl->SetX2(truncMean);
325 tl->SetY1(0); tl->SetY2(htemp->GetMaximum());
326 tl->DrawClone(
"same");
328 tb->SetLineColor(kPink);
330 tb->SetFillColorAlpha(kPink, 0.15);
331 tb->SetX1(htemp->GetBinLowEdge(startfrom));
333 tb->SetX2(htemp->GetBinLowEdge(endat));
334 tb->SetY2(htemp->GetMaximum());
335 tb->DrawClone(
"same");
336 if (idoca % 16 == 0)ctmp->Print(psname.str().c_str());
339 file2DILout << iea <<
", \t" << idoca <<
", \t" << truncMean <<
"\n";
345 ibinEA = 0, ibinDOCA = 0;
349 for (
int idoca = 0; idoca <
fnDocaBinG; idoca++) {
351 twodcor.SetBinContent(idoca + 1, iea + 1, tempTwoD.GetBinContent(ibinDOCA + 1, ibinEA + 1));
355 if (iIOLayer == 0)twodcor.SetTitle(
"InnerLayer: dE/dx in bins of DOCA/Enta");
356 else if (iIOLayer == 1)twodcor.SetTitle(
"OuterLayer: dE/dx in bins of DOCA/Enta");
357 twodcors.push_back(twodcor);
364 psname.str(
""); psname << Form(
"dedx_2dcell_%s.pdf]",
fSetPrefix.data());
365 ctmp->Print(psname.str().c_str());
368 TCanvas* cconst =
new TCanvas(
"FinalConstantHistoMap",
"Inner and Outer Histo", 800, 400);
369 cconst->Divide(2, 1);
370 cconst->cd(1); twodcors.at(0).Draw(
"colz");
371 cconst->cd(2); twodcors.at(1).Draw(
"colz");
372 cconst->SaveAs(Form(
"Final2DConstantMap_wGlobalBin_%s.pdf",
fSetPrefix.data()));
373 cconst->SaveAs(Form(
"Final2DConstantMap_wGlobalBin_%s.root",
fSetPrefix.data()));
377 B2INFO(
"dE/dx calibration done for 2D correction");