67 for (Int_t i = 0; i < 2; i++) {
69 for (Int_t j = 0; j < 2; j++) {
71 for (Int_t k = 0; k < 2; k++) {
114 for (Int_t i = 0; i < 2; i++) {
116 for (Int_t j = 0; j < 2; j++) {
118 for (Int_t k = 0; k < 2; k++) {
127 fTitle =
"CbmFieldMap";
128 TString dir = getenv(
"VMCWORKDIR");
130 if (fileType[0] ==
'R') {
fFileName +=
".root"; }
135 LOG(info) <<
"Filename is " <<
fFileName;
169 for (Int_t i = 0; i < 2; i++) {
171 for (Int_t j = 0; j < 2; j++) {
173 for (Int_t k = 0; k < 2; k++) {
183 if (!fieldPar) { cerr <<
"-W- CbmFieldConst::CbmFieldMap: empty parameter container!" << endl; }
190 TString dir = getenv(
"VMCWORKDIR");
191 fFileName = dir +
"/input/" + fName +
".root";
227 for (Int_t i = 0; i < 2; i++) {
229 for (Int_t j = 0; j < 2; j++) {
231 for (Int_t k = 0; k < 2; k++) {
241 if (!creator) { cerr <<
"-W- CbmFieldMap: no creator given!" << endl; }
283 cerr <<
"-E- CbmFieldMap::Init: No proper file name defined! (" <<
fFileName <<
")" << endl;
284 Fatal(
"Init",
"No proper file name");
298void CbmFieldMap::Init(Int_t nX, Double_t xMin, Double_t xMax, Int_t nY, Double_t yMin, Double_t yMax, Int_t nZ,
299 Double_t zMin, Double_t zMax, TArrayF* bx, TArrayF* by, TArrayF* bz)
312 Int_t nPoints = nX * nY * nZ;
313 assert(bx->GetSize() == by->GetSize());
314 assert(bz->GetSize() == bx->GetSize());
315 if (bx->GetSize() != nPoints) {
316 LOG(error) <<
"CbmFieldMap: array size " << bx->GetSize() <<
" does not match number of grid points.";
319 fBx =
new TArrayF(nPoints);
320 fBy =
new TArrayF(nPoints);
321 fBz =
new TArrayF(nPoints);
323 for (Int_t ix = 0; ix <
fNx; ix++) {
324 for (Int_t iy = 0; iy <
fNy; iy++) {
325 for (Int_t iz = 0; iz <
fNz; iz++) {
327 (*fBx)[index] = (*bx)[index];
328 (*fBy)[index] = (*by)[index];
329 (*fBz)[index] = (*bz)[index];
341 LOG(info) <<
"CbmFieldMap: Initialised from " << nPoints <<
" grid points";
358 if (
IsInside(
x,
y, z, ix, iy, iz, dx, dy, dz)) {
368 fHa[1][1][1] =
fBx->At((ix + 1) *
fNy *
fNz + (iy + 1) *
fNz + (iz + 1));
390 if (
IsInside(
x,
y, z, ix, iy, iz, dx, dy, dz)) {
400 fHa[1][1][1] =
fBy->At((ix + 1) *
fNy *
fNz + (iy + 1) *
fNz + (iz + 1));
422 if (
IsInside(
x,
y, z, ix, iy, iz, dx, dy, dz)) {
432 fHa[1][1][1] =
fBz->At((ix + 1) *
fNy *
fNz + (iy + 1) *
fNz + (iz + 1));
445 Double_t& dy, Double_t& dz)
451 Double_t zl = z -
fPosZ;
481 LOG(info) <<
"Writing field map to ASCII file " << fileName;
482 std::ofstream mapFile(fileName);
483 if (!mapFile.is_open()) {
484 LOG(error) <<
"Could not open file! ";
489 mapFile.precision(6);
490 mapFile << showpoint;
491 if (fType == 1) mapFile <<
"nosym" << endl;
492 if (fType == 2) mapFile <<
"sym2" << endl;
493 if (fType == 3) mapFile <<
"sym3" << endl;
499 Double_t factor = 10. *
fScale;
502 cout <<
"-I- CbmFieldMap: " <<
fNx *
fNy *
fNz <<
" entries to write... " << setw(3) << 0 <<
" % ";
505 Int_t iDiv = TMath::Nint(nTot / 100.);
506 for (Int_t ix = 0; ix <
fNx; ix++) {
507 for (Int_t iy = 0; iy <
fNy; iy++) {
508 for (Int_t iz = 0; iz <
fNz; iz++) {
510 modul = div(index, iDiv);
511 if (modul.rem == 0) {
512 Double_t perc = TMath::Nint(100. * index / nTot);
513 cout <<
"\b\b\b\b\b\b" << setw(3) << perc <<
" % " << flush;
515 mapFile <<
fBx->At(index) / factor <<
" " <<
fBy->At(index) / factor <<
" " <<
fBz->At(index) / factor << endl;
519 cout <<
" " << index + 1 <<
" written" << endl;
532 TFile* oldFile = gFile;
533 TDirectory* oldDir = gDirectory;
535 TFile* file =
new TFile(fileName,
"RECREATE");
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 <<
" cm, " <<
fNx
571 <<
" grid points, dx = " <<
fXstep <<
" cm" << endl;
572 cout <<
"---- y = " << setw(4) <<
fYmin <<
" to " << setw(4) <<
fYmax <<
" cm, " <<
fNy
573 <<
" grid points, dy = " <<
fYstep <<
" cm" << endl;
574 cout <<
"---- z = " << setw(4) <<
fZmin <<
" to " << setw(4) <<
fZmax <<
" cm, " <<
fNz
575 <<
" grid points, dz = " <<
fZstep <<
" cm" << endl;
577 cout <<
"---- Field centre position: ( " << setw(6) <<
fPosX <<
", " << setw(6) <<
fPosY <<
", " << setw(6) <<
fPosZ
579 cout <<
"---- Field scaling factor: " <<
fScale << endl;
580 cout <<
"----" << endl;
581 cout <<
"---- Field at origin is ( " << setw(6) <<
fBxOrigin <<
", " << setw(6) <<
fByOrigin <<
", " << setw(6)
584 cout <<
"======================================================" << endl;
618 Double_t bx = 0., by = 0., bz = 0.;
621 LOG(info) <<
"CbmFieldMap: Reading field map from ASCII file " << fileName;
622 std::ifstream mapFile(fileName);
623 if (!mapFile.is_open()) {
624 LOG(error) <<
"CbmFieldMap:ReadAsciiFile: Could not open file!";
625 LOG(fatal) <<
"CbmFieldMap:ReadAsciiFile: Could not open file!";
632 if (type ==
"nosym") iType = 1;
633 if (type ==
"sym2") iType = 2;
634 if (type ==
"sym3") iType = 3;
635 if (fType != iType) {
636 cout <<
"-E- CbmFieldMap::ReadAsciiFile: Incompatible map types!" << endl;
637 cout <<
" Field map is of type " << fType <<
" 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 <<
" % ";
661 Int_t iDiv = TMath::Nint(nTot / 100.);
662 for (Int_t ix = 0; ix <
fNx; ix++) {
663 for (Int_t iy = 0; iy <
fNy; iy++) {
664 for (Int_t iz = 0; iz <
fNz; iz++) {
666 cerr <<
"-E- CbmFieldMap::ReadAsciiFile: "
667 <<
"I/O Error at " << ix <<
" " << iy <<
" " << iz << endl;
669 modul = div(index, iDiv);
670 if (modul.rem == 0) {
671 Double_t perc = TMath::Nint(100. * index / nTot);
672 cout <<
"\b\b\b\b\b\b" << setw(3) << perc <<
" % " << flush;
674 mapFile >> bx >> by >> bz;
675 fBx->AddAt(factor * bx, index);
676 fBy->AddAt(factor * by, index);
677 fBz->AddAt(factor * bz, index);
680 <<
"-E- CbmFieldMap::ReadAsciiFile: EOF"
681 <<
" reached at " << ix <<
" " << iy <<
" " << iz << endl;
689 cout <<
" " << index + 1 <<
" read" << endl;
700 TFile* oldFile = gFile;
701 TDirectory* oldDir = gDirectory;
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 <<
" not found in file! " << endl;
738 if (data->
GetType() != fType) {
739 if (!((data->
GetType() == 3) && (fType == 5)))
741 cout <<
"-E- CbmFieldMap::SetField: Incompatible map types!" << endl;
742 cout <<
" Field map is of type " << fType <<
" but map on file is of type " << data->
GetType() << endl;
743 Fatal(
"SetField",
"Incompatible map types");
746 cout <<
" CbmFieldMap::SetField: Warning: You are using PosDepScaled "
747 "map (original map type = 3)"
767 fBx =
new TArrayF(*(data->
GetBx()));
768 fBy =
new TArrayF(*(data->
GetBy()));
769 fBz =
new TArrayF(*(data->
GetBz()));
772 Double_t factor =
fScale * 10.;
774 for (Int_t ix = 0; ix <
fNx; ix++) {
775 for (Int_t iy = 0; iy <
fNy; iy++) {
776 for (Int_t iz = 0; iz <
fNz; iz++) {
778 if (
fBx) (*fBx)[index] = (*fBx)[index] * factor;
779 if (
fBy) (*fBy)[index] = (*fBy)[index] * factor;
780 if (
fBz) (*fBz)[index] = (*fBz)[index] * factor;
793 fHb[0][0] =
fHa[0][0][0] + (
fHa[1][0][0] -
fHa[0][0][0]) * dx;
794 fHb[1][0] =
fHa[0][1][0] + (
fHa[1][1][0] -
fHa[0][1][0]) * dx;
795 fHb[0][1] =
fHa[0][0][1] + (
fHa[1][0][1] -
fHa[0][0][1]) * dx;
796 fHb[1][1] =
fHa[0][1][1] + (
fHa[1][1][1] -
fHa[0][1][1]) * dx;
ClassImp(CbmConverterManager)
TString GetMapName() const
Double_t fBxOrigin
Interpolated field (1-dim)
virtual void SetPosition(Double_t x, Double_t y, Double_t z)
void WriteRootFile(const char *fileName, const char *mapName)
void ReadAsciiFile(const char *fileName)
virtual void Print(Option_t *="") const
Double_t fHb[2][2]
Field at corners of a grid cell.
virtual Bool_t IsInside(Double_t x, Double_t y, Double_t z, Int_t &ix, Int_t &iy, Int_t &iz, Double_t &dx, Double_t &dy, Double_t &dz)
void SetField(const CbmFieldMapData *data)
Double_t Interpolate(Double_t dx, Double_t dy, Double_t dz)
Double_t fHc[2]
Interpolated field (2-dim)
void ReadRootFile(const char *fileName, const char *mapName)
void WriteAsciiFile(const char *fileName)
Double_t fBzOrigin
y-component of the field at the origin
Double_t fByOrigin
x-component of the field at the origin
Double_t GetPositionZ() const
void MapName(TString &name)
Double_t GetPositionY() const
Double_t GetScale() const
Double_t GetPositionX() const