12 #include <FairField.h>
13 #include <FairLogger.h>
61 for (Int_t
i = 0;
i < 2;
i++) {
63 for (Int_t j = 0; j < 2; j++) {
65 for (Int_t k = 0; k < 2; k++) {
107 for (Int_t
i = 0;
i < 2;
i++) {
109 for (Int_t j = 0; j < 2; j++) {
111 for (Int_t k = 0; k < 2; k++) {
120 fTitle =
"CbmFieldMap";
121 TString dir = getenv(
"VMCWORKDIR");
123 if (fileType[0] ==
'R') {
129 LOG(info) <<
"Filename is " <<
fFileName;
162 for (Int_t
i = 0;
i < 2;
i++) {
164 for (Int_t j = 0; j < 2; j++) {
166 for (Int_t k = 0; k < 2; k++) {
177 cerr <<
"-W- CbmFieldConst::CbmFieldMap: empty parameter container!"
185 TString dir = getenv(
"VMCWORKDIR");
186 fFileName = dir +
"/input/" + fName +
".root";
221 for (Int_t
i = 0;
i < 2;
i++) {
223 for (Int_t j = 0; j < 2; j++) {
225 for (Int_t k = 0; k < 2; k++) {
236 cerr <<
"-W- CbmFieldMap: no creator given!" << endl;
277 cerr <<
"-E- CbmFieldMap::Init: No proper file name defined! (" <<
fFileName
279 Fatal(
"Init",
"No proper file name");
316 Int_t nPoints = nX * nY * nZ;
317 assert(bx->GetSize() == by->GetSize());
318 assert(bz->GetSize() == bx->GetSize());
319 if (bx->GetSize() != nPoints) {
320 LOG(error) <<
"CbmFieldMap: array size " << bx->GetSize()
321 <<
" does not match number of grid points.";
324 fBx =
new TArrayF(nPoints);
325 fBy =
new TArrayF(nPoints);
326 fBz =
new TArrayF(nPoints);
328 for (Int_t ix = 0; ix <
fNx; ix++) {
329 for (Int_t iy = 0; iy <
fNy; iy++) {
330 for (Int_t iz = 0; iz <
fNz; iz++) {
332 (*fBx)[index] = (*bx)[index];
333 (*fBy)[index] = (*by)[index];
334 (*fBz)[index] = (*bz)[index];
346 LOG(info) <<
"CbmFieldMap: Initialised from " << nPoints <<
" grid points";
362 if (
IsInside(
x,
y, z, ix, iy, iz, dx, dy, dz)) {
372 fHa[1][1][1] =
fBx->At((ix + 1) *
fNy *
fNz + (iy + 1) *
fNz + (iz + 1));
393 if (
IsInside(
x,
y, z, ix, iy, iz, dx, dy, dz)) {
403 fHa[1][1][1] =
fBy->At((ix + 1) *
fNy *
fNz + (iy + 1) *
fNz + (iz + 1));
424 if (
IsInside(
x,
y, z, ix, iy, iz, dx, dy, dz)) {
434 fHa[1][1][1] =
fBz->At((ix + 1) *
fNy *
fNz + (iy + 1) *
fNz + (iz + 1));
459 Double_t zl = z -
fPosZ;
462 if (!(xl >=
fXmin && xl < fXmax && yl >=
fYmin && yl < fYmax && zl >=
fZmin
489 LOG(info) <<
"Writing field map to ASCII file " << fileName;
490 std::ofstream mapFile(fileName);
491 if (!mapFile.is_open()) {
492 LOG(error) <<
"Could not open file! ";
497 mapFile.precision(6);
498 mapFile << showpoint;
499 if (fType == 1) mapFile <<
"nosym" << endl;
500 if (fType == 2) mapFile <<
"sym2" << endl;
501 if (fType == 3) mapFile <<
"sym3" << endl;
507 Double_t factor = 10. *
fScale;
510 cout <<
"-I- CbmFieldMap: " <<
fNx *
fNy *
fNz <<
" entries to write... "
511 << setw(3) << 0 <<
" % ";
514 Int_t iDiv = TMath::Nint(nTot / 100.);
515 for (Int_t ix = 0; ix <
fNx; ix++) {
516 for (Int_t iy = 0; iy <
fNy; iy++) {
517 for (Int_t iz = 0; iz <
fNz; iz++) {
519 modul = div(index, iDiv);
520 if (modul.rem == 0) {
521 Double_t perc = TMath::Nint(100. * index / nTot);
522 cout <<
"\b\b\b\b\b\b" << setw(3) << perc <<
" % " << flush;
524 mapFile <<
fBx->At(index) / factor <<
" " <<
fBy->At(index) / factor
525 <<
" " <<
fBz->At(index) / factor << endl;
529 cout <<
" " << index + 1 <<
" written" << endl;
539 TFile* oldFile = gFile;
540 TFile* file =
new TFile(fileName,
"RECREATE");
543 if (oldFile) oldFile->cd();
559 TString type =
"Map";
560 if (fType == 2) type =
"Map sym2";
561 if (fType == 3) type =
"Map sym3";
562 cout <<
"======================================================" << endl;
565 cout <<
"---- " << fTitle <<
" : " << fName << endl;
566 cout <<
"----" << endl;
567 cout <<
"---- Field type : " << type << endl;
568 cout <<
"----" << endl;
569 cout <<
"---- Field map grid : " << endl;
570 cout <<
"---- x = " << setw(4) <<
fXmin <<
" to " << setw(4) <<
fXmax
571 <<
" cm, " <<
fNx <<
" grid points, dx = " <<
fXstep <<
" cm" << endl;
572 cout <<
"---- y = " << setw(4) <<
fYmin <<
" to " << setw(4) <<
fYmax
573 <<
" cm, " <<
fNy <<
" grid points, dy = " <<
fYstep <<
" cm" << endl;
574 cout <<
"---- z = " << setw(4) <<
fZmin <<
" to " << setw(4) <<
fZmax
575 <<
" cm, " <<
fNz <<
" grid points, dz = " <<
fZstep <<
" cm" << endl;
577 cout <<
"---- Field centre position: ( " << setw(6) <<
fPosX <<
", "
578 << setw(6) <<
fPosY <<
", " << setw(6) <<
fPosZ <<
") cm" << endl;
579 cout <<
"---- Field scaling factor: " <<
fScale << endl;
580 cout <<
"----" << endl;
581 cout <<
"---- Field at origin is ( " << setw(6) <<
fBxOrigin <<
", "
585 cout <<
"======================================================" << endl;
617 Double_t bx = 0., by = 0., bz = 0.;
620 LOG(info) <<
"CbmFieldMap: Reading field map from ASCII file " << fileName;
621 std::ifstream mapFile(fileName);
622 if (!mapFile.is_open()) {
623 LOG(error) <<
"CbmFieldMap:ReadAsciiFile: Could not open file!";
624 LOG(fatal) <<
"CbmFieldMap:ReadAsciiFile: Could not open file!";
631 if (type ==
"nosym") iType = 1;
632 if (type ==
"sym2") iType = 2;
633 if (type ==
"sym3") iType = 3;
634 if (fType != iType) {
635 cout <<
"-E- CbmFieldMap::ReadAsciiFile: Incompatible map types!" << endl;
636 cout <<
" Field map is of type " << fType
637 <<
" but map on file is of type " << iType << endl;
638 Fatal(
"ReadAsciiFile",
"Incompatible map types");
655 Double_t factor =
fScale * 10.;
658 cout <<
"-I- CbmFieldMap: " << nTot <<
" entries to read... " << setw(3) << 0
662 Int_t iDiv = TMath::Nint(nTot / 100.);
663 for (Int_t ix = 0; ix <
fNx; ix++) {
664 for (Int_t iy = 0; iy <
fNy; iy++) {
665 for (Int_t iz = 0; iz <
fNz; iz++) {
667 cerr <<
"-E- CbmFieldMap::ReadAsciiFile: "
668 <<
"I/O Error at " << ix <<
" " << iy <<
" " << iz << endl;
670 modul = div(index, iDiv);
671 if (modul.rem == 0) {
672 Double_t perc = TMath::Nint(100. * index / nTot);
673 cout <<
"\b\b\b\b\b\b" << setw(3) << perc <<
" % " << flush;
675 mapFile >> bx >> by >> bz;
676 fBx->AddAt(factor * bx, index);
677 fBy->AddAt(factor * by, index);
678 fBz->AddAt(factor * bz, index);
681 <<
"-E- CbmFieldMap::ReadAsciiFile: EOF"
682 <<
" reached at " << ix <<
" " << iy <<
" " << iz << endl;
690 cout <<
" " << index + 1 <<
" read" << endl;
701 TFile* oldFile = gFile;
704 LOG(info) <<
"CbmFieldMap: Reading field map from ROOT file " << fileName;
705 TFile* file =
new TFile(fileName,
"READ");
706 if (!(file->IsOpen())) {
707 LOG(error) <<
"CbmFieldMap:ReadRootFile: Could not open file!";
708 LOG(fatal) <<
"CbmFieldMap:ReadRootFile: Could not open file!";
713 file->GetObject(mapName, data);
715 cout <<
"-E- CbmFieldMap::ReadRootFile: data object " << fileName
716 <<
" not found in file! " << endl;
726 if (oldFile) oldFile->cd();
735 if (data->
GetType() != fType) {
736 if (!((data->
GetType() == 3) && (fType == 5)))
738 cout <<
"-E- CbmFieldMap::SetField: Incompatible map types!" << endl;
739 cout <<
" Field map is of type " << fType
740 <<
" but map on file is of type " << data->
GetType() << endl;
741 Fatal(
"SetField",
"Incompatible map types");
743 cout <<
" CbmFieldMap::SetField: Warning: You are using PosDepScaled "
744 "map (original map type = 3)"
764 fBx =
new TArrayF(*(data->
GetBx()));
765 fBy =
new TArrayF(*(data->
GetBy()));
766 fBz =
new TArrayF(*(data->
GetBz()));
769 Double_t factor =
fScale * 10.;
771 for (Int_t ix = 0; ix <
fNx; ix++) {
772 for (Int_t iy = 0; iy <
fNy; iy++) {
773 for (Int_t iz = 0; iz <
fNz; iz++) {
775 if (
fBx) (*fBx)[index] = (*fBx)[index] * factor;
776 if (
fBy) (*fBy)[index] = (*fBy)[index] * factor;
777 if (
fBz) (*fBz)[index] = (*fBz)[index] * factor;
789 fHb[0][0] =
fHa[0][0][0] + (
fHa[1][0][0] -
fHa[0][0][0]) * dx;
790 fHb[1][0] =
fHa[0][1][0] + (
fHa[1][1][0] -
fHa[0][1][0]) * dx;
791 fHb[0][1] =
fHa[0][0][1] + (
fHa[1][0][1] -
fHa[0][0][1]) * dx;
792 fHb[1][1] =
fHa[0][1][1] + (
fHa[1][1][1] -
fHa[0][1][1]) * dx;