BmnRoot 26.10.0-233-gb9bbe585
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnFieldMap.cxx
Go to the documentation of this file.
1// ---------------------------------------------------------------------------------
2// ----- BmnFieldMap header file -------------
3// ----- Created 03/02/2015 by P. Batyuk -------------
4// ---------------------------------------------------------------------------------
5
6#include "BmnFieldMap.h"
7
8#include "BmnFieldPoint.h"
9#include "TFile.h"
10#include "TMath.h"
11#include "TSystem.h"
12#include "TTree.h"
13
14#include <iomanip>
15#include <iostream>
16using namespace std;
17
19 : FairField()
20 , fScale(1.)
21 , fPosX(0.)
22 , fPosY(0.)
23 , fPosZ(0.)
24 , fXmin(0.)
25 , fXmax(0.)
26 , fXstep(0.)
27 , fYmin(0.)
28 , fYmax(0.)
29 , fYstep(0.)
30 , fZmin(0.)
31 , fZmax(0.)
32 , fZstep(0.)
33 , fNx(0)
34 , fNy(0)
35 , fNz(0)
36 , fBx(nullptr)
37 , fBy(nullptr)
38 , fBz(nullptr)
40 , fIsOff(kFALSE)
41{
42 // Initilization of arrays is to my knowledge not
43 // possible in member initalization lists
44 for (Int_t i = 0; i < 2; i++) {
45 fHc[i] = 0;
46 for (Int_t j = 0; j < 2; j++) {
47 fHb[i][j] = 0;
48 for (Int_t k = 0; k < 2; k++) {
49 fHa[i][j][k] = 0;
50 }
51 }
52 }
53
54 // fName stores file name or path (using $VMCWORKDIR var) with magnetic field map
55 fName = "";
56 // fType: 1- nosym magnetic field, 2 - sym2, 3 - sym3
57 fType = 1;
58}
59
60BmnFieldMap::BmnFieldMap(const char* mapFileName)
61 : BmnFieldMap()
62{
63 fName = mapFileName;
64 fType = 1;
65}
66
68 : BmnFieldMap()
69{
70 if (!fieldPar)
71 LOG(error) << "BmnFieldMap::BmnFieldMap: empty parameter container";
72 else {
73 fPosX = fieldPar->GetPositionX();
74 fPosY = fieldPar->GetPositionY();
75 fPosZ = fieldPar->GetPositionZ();
76 fScale = fieldPar->GetScale();
77 fIsOff = fieldPar->IsFieldOff();
78 fieldPar->MapName(fName);
79 fType = fieldPar->GetType();
80 }
81}
82
84{
85 if (fBx)
86 delete fBx;
87 if (fBy)
88 delete fBy;
89 if (fBz)
90 delete fBz;
91}
92
93// get the expanded path to the field map file: a file name without a folder is searched in $GEOMPATH (the storage
94// of the Local Geometry Database), otherwise in $VMCWORKDIR/input
96{
97 if (!mapName.Contains("/")) {
98 TString storagePath = gSystem->Getenv("GEOMPATH");
99 if (storagePath == "")
100 mapName = "$VMCWORKDIR/input/" + mapName;
101 else
102 mapName = "$GEOMPATH/" + mapName;
103 }
104 gSystem->ExpandPathName(mapName);
105
106 return mapName;
107}
108
110{
111 // fName is not changed here: it is written to the output files (DST run header, field parameters),
112 // so it must not contain the path specific to the installation, where the files were produced
113 TString mapFilePath = GetMapFilePath(fName);
114
115 if (mapFilePath.Contains("extrap")) {
116 LOG(info) << "Extrapolated magnetic field map is used";
117 ReadRootFileNewFormatExtrap(mapFilePath);
118 } else {
119 LOG(info) << "Basic magnetic field map is used";
120 ReadRootFileNewFormat(mapFilePath);
121 }
125}
126
127void BmnFieldMap::WriteAsciiFile(const char* asciiFileName)
128{
129 TString strFileName(asciiFileName);
130 gSystem->ExpandPathName(strFileName);
131 // Open file
132 LOG(info) << "BmnFieldMap: Writing field map to ASCII file " << strFileName.Data() << endl;
133 ofstream mapFile(strFileName.Data());
134 if (!mapFile.is_open()) {
135 LOG(error) << "BmnFieldMap:ReadAsciiFile: Could not open file" << endl;
136 return;
137 }
138
139 // Write field map grid parameters
140 mapFile.precision(6);
141 mapFile << showpoint;
142 if (fType == 1)
143 mapFile << "nosym" << endl;
144 if (fType == 2)
145 mapFile << "sym2" << endl;
146 if (fType == 3)
147 mapFile << "sym3" << endl;
148 mapFile << fXmin << " " << fXmax << " " << fNx << endl;
149 mapFile << fYmin << " " << fYmax << " " << fNy << endl;
150 mapFile << fZmin << " " << fZmax << " " << fNz << endl;
151
152 // Write field values
153 Double_t factor = 10. * fScale; // Takes out scaling and converts kG->T
154 cout << right;
155 Int_t nTot = fNx * fNy * fNz;
156 LOG(info) << "BmnFieldMap: " << fNx * fNy * fNz << " entries to write... " << setw(3) << 0 << " % ";
157 Int_t index = 0;
158 div_t modul;
159 Int_t iDiv = TMath::Nint(nTot / 100.);
160 for (Int_t ix = 0; ix < fNx; ix++) {
161 for (Int_t iy = 0; iy < fNy; iy++) {
162 for (Int_t iz = 0; iz < fNz; iz++) {
163 index = ix * fNy * fNz + iy * fNz + iz;
164 modul = div(index, iDiv);
165 if (modul.rem == 0) {
166 Double_t perc = TMath::Nint(100. * index / nTot);
167 cout << "\b\b\b\b\b\b" << setw(3) << perc << " % " << flush;
168 }
169 mapFile << fBx->At(index) / factor << " " << fBy->At(index) / factor << " " << fBz->At(index) / factor
170 << endl;
171 }
172 }
173 }
174 cout << " " << index + 1 << " written" << endl;
175 mapFile.close();
176}
177
178void BmnFieldMap::WriteRootFile(const char* rootFileName, const char* mapFileName)
179{
180 BmnFieldMapData* data = new BmnFieldMapData(mapFileName, *this);
181 TFile* oldFile = gFile;
182 TString strFileName(rootFileName);
183 gSystem->ExpandPathName(strFileName);
184 TFile* file = TFile::Open(strFileName, "RECREATE");
185 data->Write();
186 delete file;
187 if (oldFile)
188 oldFile->cd();
189}
190
192{
193 fPosX = x;
194 fPosY = y;
195 fPosZ = z;
199}
200
202{
203 TString type = "Map";
204 if (fType == 2)
205 type = "Map sym2";
206 if (fType == 3)
207 type = "Map sym3";
208 cout << "======================================================" << endl;
209 cout.precision(4);
210 cout << showpoint;
211 cout << "---- " << fTitle << " : " << fName << endl;
212 cout << "----" << endl;
213 cout << "---- Field type : " << type << endl;
214 cout << "----" << endl;
215 cout << "---- Field map grid : " << endl;
216 cout << "---- x = " << setw(4) << fXmin << " to " << setw(4) << fXmax << " cm, " << fNx
217 << " grid points, dx = " << fXstep << " cm" << endl;
218 cout << "---- y = " << setw(4) << fYmin << " to " << setw(4) << fYmax << " cm, " << fNy
219 << " grid points, dy = " << fYstep << " cm" << endl;
220 cout << "---- z = " << setw(4) << fZmin << " to " << setw(4) << fZmax << " cm, " << fNz
221 << " grid points, dz = " << fZstep << " cm" << endl;
222 cout << endl;
223 cout << "---- Target position: ( " << setw(6) << fPosX << ", " << setw(6) << fPosY << ", " << setw(6) << fPosZ
224 << ") cm" << endl;
225 cout << "---- Field scaling factor: " << fScale << endl;
226 if (fIsOff)
227 cout << "---- Field is off ----" << endl;
228 cout << "----" << endl;
229 cout << "---- Field at Target Position ( " << setw(6) << fPosBx << ", " << setw(6) << fPosBy << ", " << setw(6)
230 << fPosBz << ") kG" << endl;
231 cout << "======================================================" << endl;
232}
233
235{
236 fPosX = fPosY = fPosZ = 0.;
237 fPosBx = fPosBy = fPosBz = 0.;
238 fXmin = fYmin = fZmin = 0.;
239 fXmax = fYmax = fZmax = 0.;
240 fXstep = fYstep = fZstep = 0.;
241 fNx = fNy = fNz = 0;
242 fScale = 1.;
243 fIsOff = kFALSE;
244 if (fBx) {
245 delete fBx;
246 fBx = NULL;
247 }
248 if (fBy) {
249 delete fBy;
250 fBy = NULL;
251 }
252 if (fBz) {
253 delete fBz;
254 fBz = NULL;
255 }
256}
257
258void BmnFieldMap::ReadAsciiFile(const char* asciiFileName)
259{
260 Double_t bx = 0., by = 0., bz = 0.;
261
262 TString strFileName(asciiFileName);
263 gSystem->ExpandPathName(strFileName);
264 // Open file
265 LOG(info) << "BmnFieldMap: Reading field map from ASCII file " << strFileName.Data();
266 ifstream mapFile(strFileName.Data());
267 if (!mapFile.is_open()) {
268 LOG(error) << "BmnFieldMap:ReadAsciiFile: Could not open file!";
269 LOG(fatal) << "BmnFieldMap:ReadAsciiFile: Could not open file!";
270 }
271
272 // Read map type
273 TString type;
274 mapFile >> type;
275 Int_t iType = 0;
276 if (type == "nosym")
277 iType = 1;
278 if (type == "sym2")
279 iType = 2;
280 if (type == "sym3")
281 iType = 3;
282 if (fType != iType) {
283 cout << "-E- BmnFieldMap::ReadAsciiFile: Incompatible map types!" << endl;
284 cout << " Field map is of type " << fType << " but map on file is of type " << iType << endl;
285 Fatal("ReadAsciiFile", "Incompatible map types");
286 }
287
288 // Read grid parameters
289 mapFile >> fXmin >> fXmax >> fNx;
290 mapFile >> fYmin >> fYmax >> fNy;
291 mapFile >> fZmin >> fZmax >> fNz;
292 fXstep = (fXmax - fXmin) / Double_t(fNx - 1);
293 fYstep = (fYmax - fYmin) / Double_t(fNy - 1);
294 fZstep = (fZmax - fZmin) / Double_t(fNz - 1);
295
296 // Create field arrays
297 fBx = new TArrayF(fNx * fNy * fNz);
298 fBy = new TArrayF(fNx * fNy * fNz);
299 fBz = new TArrayF(fNx * fNy * fNz);
300
301 // Read the field values
302 Double_t factor = fScale * 10.; // Factor 10 for T -> kG
303 cout << right;
304 Int_t nTot = fNx * fNy * fNz;
305 // cout << "-I- BmnFieldMap: " << nTot << " entries to read... " << setw(3) << 0 << " % ";
306 Int_t index = 0;
307 div_t modul;
308 Int_t iDiv = TMath::Nint(nTot / 100.);
309 for (Int_t ix = 0; ix < fNx; ix++) {
310 for (Int_t iy = 0; iy < fNy; iy++) {
311 for (Int_t iz = 0; iz < fNz; iz++) {
312 if (!mapFile.good())
313 cerr << "-E- BmnFieldMap::ReadAsciiFile: "
314 << "I/O Error at " << ix << " " << iy << " " << iz << endl;
315 index = ix * fNy * fNz + iy * fNz + iz;
316 modul = div(index, iDiv);
317 // if (modul.rem == 0) {
318 // Double_t perc = TMath::Nint(100. * index / nTot);
319 // cout << "\b\b\b\b\b\b" << setw(3) << perc << " % " << flush;
320 //}
321 mapFile >> bx >> by >> bz;
322 fBx->AddAt(factor * bx, index);
323 fBy->AddAt(factor * by, index);
324 fBz->AddAt(factor * bz, index);
325 if (mapFile.eof()) {
326 cerr << endl
327 << "-E- BmnFieldMap::ReadAsciiFile: EOF"
328 << " reached at " << ix << " " << iy << " " << iz << endl;
329 mapFile.close();
330 break;
331 }
332 }
333 }
334 }
335
336 cout << " " << index + 1 << " read" << endl;
337
338 fXmin += fPosX;
339 fXmax += fPosX;
340
341 fYmin += fPosY;
342 fYmax += fPosY;
343
344 fZmin += fPosZ;
345 fZmax += fPosZ;
346
347 mapFile.close();
348}
349
350void BmnFieldMap::ReadRootFileNewFormat(const char* rootFileName)
351{
352 TString strFileName(rootFileName);
353 gSystem->ExpandPathName(strFileName);
354 // Open root file
355 LOG(info) << "BmnFieldMap: Reading field map from ROOT file " << strFileName.Data();
356 TFile* file = TFile::Open(strFileName, "READ");
357 if ((file == nullptr) || (!file->IsOpen()))
358 LOG(fatal) << "BmnFieldMap:ReadRootFileNewFormat: Could not open the file with a field map";
359
360 BmnFieldPoint point;
361 TTree* tree = (TTree*)file->Get("Field_map");
362 tree->SetBranchAddress("field_points", &point);
363
364 fNx = 126;
365 fXmin = -155.78;
366 fXmax = 144.82;
367 fXstep = (fXmax - fXmin) / (fNx - 1);
368
369 fNy = 47;
370 fYmin = -37.67;
371 fYmax = 54.33;
372 fYstep = (fYmax - fYmin) / (fNy - 1);
373
374 fNz = 241;
375 fZmin = -162.16;
376 fZmax = 439.04;
377 fZstep = (fZmax - fZmin) / (fNz - 1);
378
379 Int_t nTot = fNx * fNy * fNz;
380 fBx = new TArrayF(nTot);
381 fBy = new TArrayF(nTot);
382 fBz = new TArrayF(nTot);
383
384 Int_t index = 0;
385
386 for (Int_t i = 0; i < tree->GetEntries(); i++) {
387 tree->GetEntry(i);
388 // В дереве, сформированном из CSV файлов, данные записаны в одном порядке, а BmnFieldMap они хранятся в другом.
389 // Поэтому сначала из общего сквозного индекса получаем отдельные индексы по каждому измерению.
390 // При этом индекс по x инвертируем, так как направление оси в Bmn и в рамке с замерами поля противоположные.
391 Int_t iz = i % fNz;
392 Int_t ix = fNx - ((i / fNz) % fNx) - 1;
393 Int_t iy = ((i / fNz) / fNx) % fNy;
394 // После этого формируем итоговый сквозной индекс для карты поля в формате BmnFieldMap
395 index = ix * fNy * fNz + iy * fNz + iz;
396 // И пишем по этому индексу компоненты, предварительно скалируя их.
397 fBx->AddAt(fScale * point.GetBx(), index);
398 fBy->AddAt(fScale * point.GetBy(), index);
399 fBz->AddAt(fScale * point.GetBz(), index);
400 }
401
402 delete file;
403}
404
405void BmnFieldMap::ReadRootFileNewFormatExtrap(const char* rootFileName)
406{
407 TString strFileName(rootFileName);
408 gSystem->ExpandPathName(strFileName);
409
410 LOG(info) << "BmnFieldMap: Reading field map from ROOT file " << strFileName.Data();
411
412 TFile* file = TFile::Open(strFileName, "READ");
413 if ((file == nullptr) || (!file->IsOpen()))
414 LOG(fatal) << "BmnFieldMap:ReadRootFileNewFormatExtrap: Could not open the file with a field map";
415
416 BmnFieldPoint point;
417 TTree* tree = (TTree*)file->Get("Field_map");
418 if (!tree)
419 LOG(fatal) << "BmnFieldMap:ReadRootFileNewFormatExtrap: Tree 'Field_map' not found";
420
421 tree->SetBranchAddress("field_points", &point);
422
423 // ============================================================
424 // Попытка прочитать метаданные сетки из дерева Field_map_info
425 // ============================================================
426 TTree* treeInfo = (TTree*)file->Get("Field_map_info");
427
428 if (treeInfo) {
429 LOG(info) << "BmnFieldMap: Reading grid info from Field_map_info tree";
430
431 Int_t NxI, NyI, NzI;
432 Double_t X1I, X2I, Y1I, Y2I, Z1I, Z2I;
433
434 treeInfo->SetBranchAddress("Nx", &NxI);
435 treeInfo->SetBranchAddress("Ny", &NyI);
436 treeInfo->SetBranchAddress("Nz", &NzI);
437 treeInfo->SetBranchAddress("Xmin", &X1I);
438 treeInfo->SetBranchAddress("Xmax", &X2I);
439 treeInfo->SetBranchAddress("Ymin", &Y1I);
440 treeInfo->SetBranchAddress("Ymax", &Y2I);
441 treeInfo->SetBranchAddress("Zmin", &Z1I);
442 treeInfo->SetBranchAddress("Zmax", &Z2I);
443
444 treeInfo->GetEntry(0);
445
446 fNx = NxI;
447 fNy = NyI;
448 fNz = NzI;
449
450 fXmin = X1I;
451 fXmax = X2I;
452 fYmin = Y1I;
453 fYmax = Y2I;
454 fZmin = Z1I;
455 fZmax = Z2I;
456
457 fXstep = (fXmax - fXmin) / Double_t(fNx - 1);
458 fYstep = (fYmax - fYmin) / Double_t(fNy - 1);
459 fZstep = (fZmax - fZmin) / Double_t(fNz - 1);
460
461 LOG(info) << " Grid: Nx = " << fNx << ", Ny = " << fNy << ", Nz = " << fNz;
462 LOG(info) << " X [" << fXmin << ", " << fXmax << "], step = " << fXstep;
463 LOG(info) << " Y [" << fYmin << ", " << fYmax << "], step = " << fYstep;
464 LOG(info) << " Z [" << fZmin << ", " << fZmax << "], step = " << fZstep;
465 } else {
466 // ============================================================
467 // Fallback: старые жёстко зашитые константы
468 // (для совместимости с уже существующими файлами без метаданных)
469 // ============================================================
470 LOG(warning) << "BmnFieldMap: Field_map_info tree not found, using hardcoded grid";
471
472 fNx = 206;
473 fXmin = -251.972;
474 fXmax = 241.012;
475 fXstep = (fXmax - fXmin) / (fNx - 1);
476
477 fNy = 87;
478 fYmin = -77.67;
479 fYmax = 94.33;
480 fYstep = (fYmax - fYmin) / (fNy - 1);
481
482 fNz = 341;
483 fZmin = -287.41;
484 fZmax = 564.29;
485 fZstep = (fZmax - fZmin) / (fNz - 1);
486 }
487
488 Int_t nTot = fNx * fNy * fNz;
489 fBx = new TArrayF(nTot);
490 fBy = new TArrayF(nTot);
491 fBz = new TArrayF(nTot);
492
493 Int_t nEntries = tree->GetEntries();
494
495 if (nEntries != nTot) {
496 LOG(warning) << "BmnFieldMap:ReadRootFileNewFormatExtrap: number of entries (" << nEntries << ") != Nx*Ny*Nz ("
497 << nTot << ")";
498 }
499
500 Int_t index = 0;
501 for (Int_t i = 0; i < nEntries && i < nTot; ++i) {
502 tree->GetEntry(i);
503
504 // В дереве данные записаны в порядке (iy внешний, ix средний, iz внутренний),
505 // при этом ix инвертирован для соответствия формату BmnFieldMap.
506 Int_t iz = i % fNz;
507 Int_t ix = fNx - ((i / fNz) % fNx) - 1;
508 Int_t iy = ((i / fNz) / fNx) % fNy;
509
510 index = ix * fNy * fNz + iy * fNz + iz;
511
512 fBx->AddAt(fScale * point.GetBx(), index);
513 fBy->AddAt(fScale * point.GetBy(), index);
514 fBz->AddAt(fScale * point.GetBz(), index);
515 }
516
517 file->Close();
518 delete file;
519}
520
521void BmnFieldMap::ReadRootFile(const char* rootFileName)
522{
523 TString* type = 0;
524 coordinate_info_t X, Y, Z;
525 vector<Double_t>* read_Field = NULL;
526
527 TString strFileName(rootFileName);
528 gSystem->ExpandPathName(strFileName);
529 // Open root file
530 LOG(info) << "BmnFieldMap: Reading field map from ROOT file " << strFileName.Data();
531 TFile* file = TFile::Open(strFileName, "READ");
532 if ((file == nullptr) || (!file->IsOpen()))
533 LOG(fatal) << "BmnFieldMap:ReadRootFile: Could not open the file with a field map";
534
535 TTree* tree = (TTree*)file->Get("Main_info");
536 TTree* t = (TTree*)file->Get("Field_map");
537 tree->SetBranchAddress("Field_type", &type);
538 tree->SetBranchAddress("Main_info_X", &X);
539 tree->SetBranchAddress("Main_info_Y", &Y);
540 tree->SetBranchAddress("Main_info_Z", &Z);
541 t->SetBranchAddress("field_map", &read_Field);
542
543 tree->GetEntry(0);
544 Int_t iType = 0;
545
546 if (*type == "nosym")
547 iType = 1;
548 if (*type == "sym2")
549 iType = 2;
550 if (*type == "sym3")
551 iType = 3;
552 if (fType != iType) {
553 LOG(error) << "BmnFieldMap::ReadRootFile: Incompatible map types!";
554 LOG(info) << " Field map is of type " << fType << " but map on file is of type " << iType;
555 LOG(fatal) << "ReadRootFile: Incompatible map types";
556 }
557
558 fNx = X.N;
559 fXmin = X.min + fPosX;
560 fXmax = X.max + fPosX;
561 fXstep = X.step;
562
563 fNy = Y.N;
564 fYmin = Y.min + fPosY;
565 fYmax = Y.max + fPosY;
566 fYstep = Y.step;
567
568 fNz = Z.N;
569 fZmin = Z.min + fPosZ;
570 fZmax = Z.max + fPosZ;
571 fZstep = Z.step;
572
573 fBx = new TArrayF(fNx * fNy * fNz);
574 fBy = new TArrayF(fNx * fNy * fNz);
575 fBz = new TArrayF(fNx * fNy * fNz);
576
577 Double_t factor = fScale;
578 Int_t nTot = fNx * fNy * fNz;
579 Int_t index = 0;
580 div_t modul;
581 Int_t iDiv = TMath::Nint(nTot / 100.);
582
583 for (Int_t ix = 0; ix < fNx; ix++) {
584 for (Int_t iy = 0; iy < fNy; iy++) {
585 for (Int_t iz = 0; iz < fNz; iz++) {
586 modul = div(index, iDiv);
587 // if (modul.rem == 0) {
588 // Double_t perc = TMath::Nint(100. * index / nTot);
589 // }
590 index = ix * fNy * fNz + iy * fNz + iz;
591 t->GetEntry(index);
592 vector<Double_t> v = (*read_Field);
593 fBx->AddAt(factor * v[0], index);
594 fBy->AddAt(factor * v[1], index);
595 fBz->AddAt(factor * v[2], index);
596 }
597 }
598 }
599
600 t->Delete();
601 tree->Delete();
602 delete type;
603 delete read_Field;
604 delete file;
605}
606
608{
609 // Check compatibility
610 if (data->GetType() != fType) {
611 if (!((data->GetType() == 3) && (fType == 5))) // E.Litvinenko
612 {
613 LOG(error) << "BmnFieldMap::SetField: Incompatible map types!";
614 LOG(info) << " Field map is of type " << fType << " but map on file is of type " << data->GetType();
615 LOG(fatal) << "SetField: Incompatible map types";
616 } else
617 LOG(info) << " BmnFieldMap::SetField: Warning: You are using PosDepScaled map (original map type = 3)";
618 }
619
620 fXmin = data->GetXmin();
621 fYmin = data->GetYmin();
622 fZmin = data->GetZmin();
623 fXmax = data->GetXmax();
624 fYmax = data->GetYmax();
625 fZmax = data->GetZmax();
626 fNx = data->GetNx();
627 fNy = data->GetNy();
628 fNz = data->GetNz();
629 fXstep = (fXmax - fXmin) / Double_t(fNx - 1);
630 fYstep = (fYmax - fYmin) / Double_t(fNy - 1);
631 fZstep = (fZmax - fZmin) / Double_t(fNz - 1);
632 if (fBx)
633 delete fBx;
634 if (fBy)
635 delete fBy;
636 if (fBz)
637 delete fBz;
638 fBx = new TArrayF(*(data->GetBx()));
639 fBy = new TArrayF(*(data->GetBy()));
640 fBz = new TArrayF(*(data->GetBz()));
641
642 // Scale and convert from T to kG
643 Double_t factor = fScale * 10.;
644 Int_t index = 0;
645 for (Int_t ix = 0; ix < fNx; ix++) {
646 for (Int_t iy = 0; iy < fNy; iy++) {
647 for (Int_t iz = 0; iz < fNz; iz++) {
648 index = ix * fNy * fNz + iy * fNz + iz;
649 if (fBx)
650 (*fBx)[index] = (*fBx)[index] * factor;
651 if (fBy)
652 (*fBy)[index] = (*fBy)[index] * factor;
653 if (fBz)
654 (*fBz)[index] = (*fBz)[index] * factor;
655 }
656 }
657 }
658}
659
661{
662 // Interpolate in x coordinate
663 fHb[0][0] = fHa[0][0][0] + (fHa[1][0][0] - fHa[0][0][0]) * dx;
664 fHb[1][0] = fHa[0][1][0] + (fHa[1][1][0] - fHa[0][1][0]) * dx;
665 fHb[0][1] = fHa[0][0][1] + (fHa[1][0][1] - fHa[0][0][1]) * dx;
666 fHb[1][1] = fHa[0][1][1] + (fHa[1][1][1] - fHa[0][1][1]) * dx;
667
668 // Interpolate in y coordinate
669 fHc[0] = fHb[0][0] + (fHb[1][0] - fHb[0][0]) * dy;
670 fHc[1] = fHb[0][1] + (fHb[1][1] - fHb[0][1]) * dy;
671
672 // Interpolate in z coordinate
673 return fHc[0] + (fHc[1] - fHc[0]) * dz;
674}
__m128 v
Definition P4_F32vec4.h:1
int i
Definition P4_F32vec4.h:22
int Int_t
constexpr Bool_t kFALSE
double Double_t
const char Option_t
void Fatal(const char *location, const char *msgfmt,...)
#define gFile
R__EXTERN TSystem * gSystem
TArrayF * GetBy() const
Double_t GetYmax() const
Double_t GetZmin() const
Double_t GetXmin() const
TArrayF * GetBz() const
Int_t GetNz() const
Int_t GetType() const
Accessors to field parameters in local coordinate system.
Double_t GetXmax() const
Int_t GetNy() const
TArrayF * GetBx() const
Accessors to the field value arrays.
Int_t GetNx() const
Double_t GetYmin() const
Double_t GetZmax() const
void ReadRootFileNewFormat(const char *rootFileName)
TArrayF * fBy
TArrayF * fBx
Arrays with the field values.
void SetField(const BmnFieldMapData *data)
Set field parameters and data.
Bool_t fIsOff
Whether magnetic field is off.
Double_t fPosZ
Double_t fPosBx
TArrayF * GetBx() const
Accessors to the field value arrays.
Definition BmnFieldMap.h:96
Int_t fNx
Number of grid points.
void ReadRootFileNewFormatExtrap(const char *rootFileName)
void ReadRootFile(const char *rootFileName)
Read field map from a ROOT file.
Double_t fHb[2][2]
Field at corners of a grid cell.
Double_t fPosY
static TString GetMapFilePath(TString mapName)
Get the expanded path to the field map file in the current installation.
TArrayF * GetBy() const
Definition BmnFieldMap.h:97
Double_t Interpolate(Double_t dx, Double_t dy, Double_t dz)
Get field values by interpolation of the grid.
Double_t fScale
Global scaling factor (w.r.t.
Double_t fPosX
Field centre position in global coordinates.
void Reset()
Reset the field parameters and data.
Double_t fHa[2][2][2]
Variables for temporary storage Used in the very frequently called method GetFieldValue.
virtual ~BmnFieldMap()
void SetPosition(Double_t x, Double_t y, Double_t z)
Set the position of the field centre.
Double_t fZmin
TArrayF * GetBz() const
Definition BmnFieldMap.h:98
Double_t fYmax
TArrayF * fBz
void WriteRootFile(const char *rootFileName, const char *mapFileName)
Write field map data to a ROOT file.
virtual void Init()
Bool_t fDebugInfo
Interpolated field (1-dim).
Double_t fPosBy
Double_t fXstep
Double_t fZstep
Double_t fPosBz
Double_t fXmin
Field limits in local coordinate system.
Double_t fHc[2]
Interpolated field (2-dim).
void ReadAsciiFile(const char *asciiFileName)
Reset the field parameters and data.
Double_t fZmax
Double_t fYmin
Double_t fYstep
void WriteAsciiFile(const char *asciiFileName)
Write the field map to an ASCII file.
Double_t fXmax
virtual void Print(Option_t *) const
Screen output.
Double_t GetPositionZ() const
Definition BmnFieldPar.h:61
Bool_t IsFieldOff() const
Definition BmnFieldPar.h:63
Int_t GetType() const
Accessors.
Definition BmnFieldPar.h:48
Double_t GetScale() const
Definition BmnFieldPar.h:62
Double_t GetPositionY() const
Definition BmnFieldPar.h:60
Double_t GetPositionX() const
Definition BmnFieldPar.h:59
void MapName(TString &name)
Definition BmnFieldPar.h:58
Double_t GetBy()
Double_t GetBz()
Double_t GetBx()
Bool_t cd() override
T * Get(const char *namecycle)
virtual Bool_t IsOpen() const
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
void Close(Option_t *option="") override
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
const char * Data() const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
void Delete(Option_t *option="") override
virtual Long64_t GetEntries() const
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
Int_t Nint(T x)