BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
TestField.C
Go to the documentation of this file.
1
2
4{
5
6 TString fileNew = "FieldMap_1900.root";
7 TString fileOld = "field_sp41v5_ascii_Extrap.root";
8 BmnFieldMap* fieldNew = new BmnNewFieldMap(fileNew.Data());
9 BmnFieldMap* fieldOld = new BmnNewFieldMap(fileOld.Data());
10 fieldNew->SetFormat(1);
11 fieldOld->SetFormat(0);
12 fieldNew->SetScale(900.0 / 1600.0);
13 fieldOld->SetScale(1.0);
14 fieldNew->Init();
15 fieldOld->Init();
16
17 const Float_t xMin = -155.0;
18 const Float_t xMax = +144.0;
19 const Int_t nXbins = 100;
20 Float_t xStep = (xMax - xMin) / nXbins;
21 const Float_t yMin = -37.0;
22 const Float_t yMax = +54.0;
23 const Int_t nYbins = 100;
24 Float_t yStep = (yMax - yMin) / nYbins;
25 const Float_t zMin = -162.0;
26 const Float_t zMax = +439.0;
27 const Int_t nZbins = 100;
28 Float_t zStep = (zMax - zMin) / nZbins;
29
30 TFile* f = new TFile("field_QA.root", "RECREATE");
31
32 TH1F* hBx_Z_center_old =
33 new TH1F("hBx_Z_center_old", "Z profile of Bx in center; Z, cm; By, kGs", nZbins, zMin, zMax);
34 TH1F* hBx_Z_center_new =
35 new TH1F("hBx_Z_center_new", "Z profile of Bx in center; Z, cm; By, kGs", nZbins, zMin, zMax);
36 TH1F* hBy_Z_center_old =
37 new TH1F("hBy_Z_center_old", "Z profile of By in center; Z, cm; By, kGs", nZbins, zMin, zMax);
38 TH1F* hBy_Z_center_new =
39 new TH1F("hBy_Z_center_new", "Z profile of By in center; Z, cm; By, kGs", nZbins, zMin, zMax);
40 TH1F* hBz_Z_center_old =
41 new TH1F("hBz_Z_center_old", "Z profile of Bz in center; Z, cm; By, kGs", nZbins, zMin, zMax);
42 TH1F* hBz_Z_center_new =
43 new TH1F("hBz_Z_center_new", "Z profile of Bz in center; Z, cm; By, kGs", nZbins, zMin, zMax);
44
45 for (Int_t k = 0; k < nZbins; ++k) {
46 Float_t z = zMin + k * zStep;
47 hBx_Z_center_new->SetBinContent(k, fieldNew->GetBx(0, 0, z));
48 hBx_Z_center_old->SetBinContent(k, fieldOld->GetBx(0, 0, z));
49 hBy_Z_center_new->SetBinContent(k, fieldNew->GetBy(0, 0, z));
50 hBy_Z_center_old->SetBinContent(k, fieldOld->GetBy(0, 0, z));
51 hBz_Z_center_new->SetBinContent(k, fieldNew->GetBz(0, 0, z));
52 hBz_Z_center_old->SetBinContent(k, fieldOld->GetBz(0, 0, z));
53 }
54
55 hBx_Z_center_new->Write();
56 hBx_Z_center_old->Write();
57 hBy_Z_center_new->Write();
58 hBy_Z_center_old->Write();
59 hBz_Z_center_new->Write();
60 hBz_Z_center_old->Write();
61
62 TH1F* hBx_Y_center_old =
63 new TH1F("hBx_Y_center_old", "Y profile of Bx in center; Y, cm; Bx, kGs", nYbins, yMin, yMax);
64 TH1F* hBx_Y_center_new =
65 new TH1F("hBx_Y_center_new", "Y profile of Bx in center; Y, cm; Bx, kGs", nYbins, yMin, yMax);
66 TH1F* hBy_Y_center_old =
67 new TH1F("hBy_Y_center_old", "Y profile of By in center; Y, cm; By, kGs", nYbins, yMin, yMax);
68 TH1F* hBy_Y_center_new =
69 new TH1F("hBy_Y_center_new", "Y profile of By in center; Y, cm; By, kGs", nYbins, yMin, yMax);
70 TH1F* hBz_Y_center_old =
71 new TH1F("hBz_Y_center_old", "Y profile of Bz in center; Y, cm; Bz, kGs", nYbins, yMin, yMax);
72 TH1F* hBz_Y_center_new =
73 new TH1F("hBz_Y_center_new", "Y profile of Bz in center; Y, cm; Bz, kGs", nYbins, yMin, yMax);
74
75 for (Int_t k = 0; k < nYbins; ++k) {
76 Float_t y = yMin + k * yStep;
77 hBx_Y_center_new->SetBinContent(k, fieldNew->GetBx(0, y, 0));
78 hBx_Y_center_old->SetBinContent(k, fieldOld->GetBx(0, y, 0));
79 hBy_Y_center_new->SetBinContent(k, fieldNew->GetBy(0, y, 0));
80 hBy_Y_center_old->SetBinContent(k, fieldOld->GetBy(0, y, 0));
81 hBz_Y_center_new->SetBinContent(k, fieldNew->GetBz(0, y, 0));
82 hBz_Y_center_old->SetBinContent(k, fieldOld->GetBz(0, y, 0));
83 }
84
85 hBx_Y_center_new->Write();
86 hBx_Y_center_old->Write();
87 hBy_Y_center_new->Write();
88 hBy_Y_center_old->Write();
89 hBz_Y_center_new->Write();
90 hBz_Y_center_old->Write();
91
92 TH1F* hBx_X_center_old =
93 new TH1F("hBx_X_center_old", "X profile of Bx in center; X, cm; Bx, kGs", nXbins, xMin, xMax);
94 TH1F* hBx_X_center_new =
95 new TH1F("hBx_X_center_new", "X profile of Bx in center; X, cm; Bx, kGs", nXbins, xMin, xMax);
96 TH1F* hBy_X_center_old =
97 new TH1F("hBy_X_center_old", "X profile of By in center; X, cm; By, kGs", nXbins, xMin, xMax);
98 TH1F* hBy_X_center_new =
99 new TH1F("hBy_X_center_new", "X profile of By in center; X, cm; By, kGs", nXbins, xMin, xMax);
100 TH1F* hBz_X_center_old =
101 new TH1F("hBz_X_center_old", "X profile of Bz in center; X, cm; Bz, kGs", nXbins, xMin, xMax);
102 TH1F* hBz_X_center_new =
103 new TH1F("hBz_X_center_new", "X profile of Bz in center; X, cm; Bz, kGs", nXbins, xMin, xMax);
104
105 for (Int_t k = 0; k < nXbins; ++k) {
106 Float_t x = xMin + k * xStep;
107 hBx_X_center_new->SetBinContent(k, fieldNew->GetBx(x, 0, 0));
108 hBx_X_center_old->SetBinContent(k, fieldOld->GetBx(x, 0, 0));
109 hBy_X_center_new->SetBinContent(k, fieldNew->GetBy(x, 0, 0));
110 hBy_X_center_old->SetBinContent(k, fieldOld->GetBy(x, 0, 0));
111 hBz_X_center_new->SetBinContent(k, fieldNew->GetBz(x, 0, 0));
112 hBz_X_center_old->SetBinContent(k, fieldOld->GetBz(x, 0, 0));
113 }
114
115 hBx_X_center_new->Write();
116 hBx_X_center_old->Write();
117 hBy_X_center_new->Write();
118 hBy_X_center_old->Write();
119 hBz_X_center_new->Write();
120 hBz_X_center_old->Write();
121
122 const Int_t nXslices = 10;
123 const Int_t nYslices = 10;
124 const Int_t nZslices = 10;
125 const Int_t nComp = 3;
126 TString comp[nComp] = {"x", "y", "z"};
127 TH2F* hB_XZ_new[nComp][nYslices];
128 TH2F* hB_XZ_old[nComp][nYslices];
129 TH2F* hB_XZ_dif[nComp][nYslices];
130 TH2F* hB_YZ_new[nComp][nXslices];
131 TH2F* hB_YZ_old[nComp][nXslices];
132 TH2F* hB_YZ_dif[nComp][nXslices];
133 TH2F* hB_XY_new[nComp][nZslices];
134 TH2F* hB_XY_old[nComp][nZslices];
135 TH2F* hB_XY_dif[nComp][nZslices];
136
137 const Int_t nPlanes = 3;
138 TString planes[nPlanes] = {"XZ", "YZ", "XY"};
139 TCanvas* cB[nComp][nPlanes];
140
141 for (Int_t iC = 0; iC < nComp; ++iC) {
142 for (Int_t iPlane = 0; iPlane < nPlanes; ++iPlane) {
143 cB[iC][iPlane] = new TCanvas(Form("cB%s_%s", comp[iC].Data(), planes[iPlane].Data()),
144 Form("cB%s_%s", comp[iC].Data(), planes[iPlane].Data()), 300, 1000);
145 cB[iC][iPlane]->Divide(3, 10);
146 }
147 for (Int_t i = 0; i < nYslices; ++i) {
148 hB_XZ_new[iC][i] = new TH2F(Form("hB%s_XZ_new_%d", comp[iC].Data(), i),
149 Form("B%s new, XZ profile, Y slice %d; Z, cm; X, cm", comp[iC].Data(), i),
150 nZbins, zMin, zMax, nXbins, xMin, xMax);
151 hB_XZ_old[iC][i] = new TH2F(Form("hB%s_XZ_old_%d", comp[iC].Data(), i),
152 Form("B%s old, XZ profile, Y slice %d; Z, cm; X, cm", comp[iC].Data(), i),
153 nZbins, zMin, zMax, nXbins, xMin, xMax);
154 hB_XZ_dif[iC][i] = new TH2F(Form("hB%s_XZ_dif_%d", comp[iC].Data(), i),
155 Form("B%s dif, XZ profile, Y slice %d; Z, cm; X, cm", comp[iC].Data(), i),
156 nZbins, zMin, zMax, nXbins, xMin, xMax);
157 Float_t y = yMin + i * (yMax - yMin) / nYslices;
158 for (Int_t j = 0; j < nXbins; ++j) {
159 Float_t x = xMin + j * xStep;
160 for (Int_t k = 0; k < nZbins; ++k) {
161 Float_t z = zMin + k * zStep;
162 Float_t bNew = (iC == 0) ? fieldNew->GetBx(x, y, z)
163 : (iC == 1) ? fieldNew->GetBy(x, y, z)
164 : (iC == 2) ? fieldNew->GetBz(x, y, z)
165 : 0.0;
166 Float_t bOld = (iC == 0) ? fieldOld->GetBx(x, y, z)
167 : (iC == 1) ? fieldOld->GetBy(x, y, z)
168 : (iC == 2) ? fieldOld->GetBz(x, y, z)
169 : 0.0;
170 hB_XZ_new[iC][i]->SetBinContent(k, j, bNew);
171 hB_XZ_old[iC][i]->SetBinContent(k, j, bOld);
172 hB_XZ_dif[iC][i]->SetBinContent(k, j, bNew - bOld);
173 }
174 }
175 hB_XZ_new[iC][i]->Write();
176 hB_XZ_old[iC][i]->Write();
177 hB_XZ_dif[iC][i]->Write();
178 cB[iC][0]->cd(3 * i + 1);
179 hB_XZ_new[iC][i]->Draw("colz");
180 cB[iC][0]->cd(3 * i + 2);
181 hB_XZ_old[iC][i]->Draw("colz");
182 cB[iC][0]->cd(3 * i + 3);
183 hB_XZ_dif[iC][i]->Draw("colz");
184 }
185 for (Int_t i = 0; i < nXslices; ++i) {
186 hB_YZ_new[iC][i] = new TH2F(Form("hB%s_YZ_new_%d", comp[iC].Data(), i),
187 Form("B%s new, YZ profile, X slice %d; Z, cm; Y, cm", comp[iC].Data(), i),
188 nZbins, zMin, zMax, nYbins, yMin, yMax);
189 hB_YZ_old[iC][i] = new TH2F(Form("hB%s_YZ_old_%d", comp[iC].Data(), i),
190 Form("B%s old, YZ profile, X slice %d; Z, cm; Y, cm", comp[iC].Data(), i),
191 nZbins, zMin, zMax, nYbins, yMin, yMax);
192 hB_YZ_dif[iC][i] = new TH2F(Form("hB%s_YZ_dif_%d", comp[iC].Data(), i),
193 Form("B%s dif, YZ profile, X slice %d; Z, cm; Y, cm", comp[iC].Data(), i),
194 nZbins, zMin, zMax, nYbins, yMin, yMax);
195 Float_t x = xMin + i * (xMax - xMin) / nXslices;
196 for (Int_t j = 0; j < nYbins; ++j) {
197 Float_t y = yMin + j * yStep;
198 for (Int_t k = 0; k < nZbins; ++k) {
199 Float_t z = zMin + k * zStep;
200 Float_t bNew = (iC == 0) ? fieldNew->GetBx(x, y, z)
201 : (iC == 1) ? fieldNew->GetBy(x, y, z)
202 : (iC == 2) ? fieldNew->GetBz(x, y, z)
203 : 0.0;
204 Float_t bOld = (iC == 0) ? fieldOld->GetBx(x, y, z)
205 : (iC == 1) ? fieldOld->GetBy(x, y, z)
206 : (iC == 2) ? fieldOld->GetBz(x, y, z)
207 : 0.0;
208 hB_YZ_new[iC][i]->SetBinContent(k, j, bNew);
209 hB_YZ_old[iC][i]->SetBinContent(k, j, bOld);
210 hB_YZ_dif[iC][i]->SetBinContent(k, j, bNew - bOld);
211 }
212 }
213 hB_YZ_new[iC][i]->Write();
214 hB_YZ_old[iC][i]->Write();
215 hB_YZ_dif[iC][i]->Write();
216 cB[iC][1]->cd(3 * i + 1);
217 hB_YZ_new[iC][i]->Draw("colz");
218 cB[iC][1]->cd(3 * i + 2);
219 hB_YZ_old[iC][i]->Draw("colz");
220 cB[iC][1]->cd(3 * i + 3);
221 hB_YZ_dif[iC][i]->Draw("colz");
222 }
223 for (Int_t i = 0; i < nZslices; ++i) {
224 hB_XY_new[iC][i] = new TH2F(Form("hB%s_XY_new_%d", comp[iC].Data(), i),
225 Form("B%s new, XY profile, Z slice %d; Y, cm; X, cm", comp[iC].Data(), i),
226 nYbins, yMin, yMax, nXbins, xMin, xMax);
227 hB_XY_old[iC][i] = new TH2F(Form("hB%s_XY_old_%d", comp[iC].Data(), i),
228 Form("B%s old, XY profile, Z slice %d; Y, cm; X, cm", comp[iC].Data(), i),
229 nYbins, yMin, yMax, nXbins, xMin, xMax);
230 hB_XY_dif[iC][i] = new TH2F(Form("hB%s_XY_dif_%d", comp[iC].Data(), i),
231 Form("B%s dif, XY profile, Z slice %d; Y, cm; X, cm", comp[iC].Data(), i),
232 nYbins, yMin, yMax, nXbins, xMin, xMax);
233 Float_t z = zMin + i * (zMax - zMin) / nZslices;
234 for (Int_t j = 0; j < nXbins; ++j) {
235 Float_t x = xMin + j * xStep;
236 for (Int_t k = 0; k < nYbins; ++k) {
237 Float_t y = yMin + k * yStep;
238 Float_t bNew = (iC == 0) ? fieldNew->GetBx(x, y, z)
239 : (iC == 1) ? fieldNew->GetBy(x, y, z)
240 : (iC == 2) ? fieldNew->GetBz(x, y, z)
241 : 0.0;
242 Float_t bOld = (iC == 0) ? fieldOld->GetBx(x, y, z)
243 : (iC == 1) ? fieldOld->GetBy(x, y, z)
244 : (iC == 2) ? fieldOld->GetBz(x, y, z)
245 : 0.0;
246 hB_XY_new[iC][i]->SetBinContent(k, j, bNew);
247 hB_XY_old[iC][i]->SetBinContent(k, j, bOld);
248 hB_XY_dif[iC][i]->SetBinContent(k, j, bNew - bOld);
249 }
250 }
251 hB_XY_new[iC][i]->Write();
252 hB_XY_old[iC][i]->Write();
253 hB_XY_dif[iC][i]->Write();
254 cB[iC][2]->cd(3 * i + 1);
255 hB_XY_new[iC][i]->Draw("colz");
256 cB[iC][2]->cd(3 * i + 2);
257 hB_XY_old[iC][i]->Draw("colz");
258 cB[iC][2]->cd(3 * i + 3);
259 hB_XY_dif[iC][i]->Draw("colz");
260 }
261 for (Int_t iPlane = 0; iPlane < nPlanes; ++iPlane) {
262 cB[iC][iPlane]->SaveAs(Form("cB%s_%s.pdf", comp[iC].Data(), planes[iPlane].Data()));
263 }
264 }
265
266 f->Close();
267}
int i
Definition P4_F32vec4.h:22
int Int_t
float Float_t
char * Form(const char *fmt,...)
virtual Double_t GetBz(Double_t x, Double_t y, Double_t z)=0
virtual Double_t GetBy(Double_t x, Double_t y, Double_t z)=0
void SetScale(Double_t factor)
Set a global field scaling factor.
Definition BmnFieldMap.h:55
virtual Double_t GetBx(Double_t x, Double_t y, Double_t z)=0
virtual void Init()
Field Map does not have any symmetries w.r.t coordinate axises.
TVirtualPad * cd(Int_t subpadnumber=0) override
void Draw(Option_t *option="") override
virtual void SetBinContent(Int_t bin, Double_t content)
void SetBinContent(Int_t bin, Double_t content) override
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
void SaveAs(const char *filename="", Option_t *option="") const override
const char * Data() const
void TestField()
Definition TestField.C:3