104 fTitle =
"CbmFieldMap";
105 TString dir = getenv(
"VMCWORKDIR");
107 if (fileType[0] ==
'R') {
114 LOG(info) <<
"Filename is " <<
fFileName;
152 cerr <<
"-W- CbmFieldConst::CbmFieldMap: empty parameter container!" << endl;
160 TString dir = getenv(
"VMCWORKDIR");
161 fFileName = dir +
"/input/" + fName +
".root";
201 cerr <<
"-W- CbmFieldMap: no creator given!" << endl;
245 cerr <<
"-E- CbmFieldMap::Init: No proper file name defined! (" <<
fFileName <<
")" << endl;
246 Fatal(
"Init",
"No proper file name");
261 Double_t zMin, Double_t zMax, TArrayF* bx, TArrayF* by, TArrayF* bz)
274 Int_t nPoints = nX * nY * nZ;
275 assert(bx->GetSize() == by->GetSize());
276 assert(bz->GetSize() == bx->GetSize());
277 if (bx->GetSize() != nPoints) {
278 LOG(error) <<
"CbmFieldMap: array size " << bx->GetSize() <<
" does not match number of grid points.";
281 fBx =
new TArrayF(nPoints);
282 fBy =
new TArrayF(nPoints);
283 fBz =
new TArrayF(nPoints);
285 for (
Int_t ix = 0; ix <
fNx; ix++) {
286 for (
Int_t iy = 0; iy <
fNy; iy++) {
287 for (
Int_t iz = 0; iz <
fNz; iz++) {
289 (*fBx)[index] = (*bx)[index];
290 (*fBy)[index] = (*by)[index];
291 (*fBz)[index] = (*bz)[index];
303 LOG(info) <<
"CbmFieldMap: Initialised from " << nPoints <<
" grid points";
327 auto cell =
Global2Grid(point[0], point[1], point[2]);
341 LOG(info) <<
"Writing field map to ASCII file " << fileName;
342 std::ofstream mapFile(fileName);
343 if (!mapFile.is_open()) {
344 LOG(error) <<
"Could not open file! ";
349 mapFile.precision(6);
350 mapFile << showpoint;
351 if (fType == 1) mapFile <<
"nosym" << endl;
352 if (fType == 2) mapFile <<
"sym2" << endl;
353 if (fType == 3) mapFile <<
"sym3" << endl;
359 Double_t factor = 10. *
fScale;
362 cout <<
"-I- CbmFieldMap: " <<
fNx *
fNy *
fNz <<
" entries to write... " << setw(3) << 0 <<
" % ";
365 Int_t iDiv = TMath::Nint(nTot / 100.);
366 for (
Int_t ix = 0; ix <
fNx; ix++) {
367 for (
Int_t iy = 0; iy <
fNy; iy++) {
368 for (
Int_t iz = 0; iz <
fNz; iz++) {
370 modul = div(index, iDiv);
371 if (modul.rem == 0) {
372 Double_t perc = TMath::Nint(100. * index / nTot);
373 cout <<
"\b\b\b\b\b\b" << setw(3) << perc <<
" % " << flush;
375 mapFile <<
fBx->At(index) / factor <<
" " <<
fBy->At(index) / factor <<
" " <<
fBz->At(index) / factor << endl;
379 cout <<
" " << index + 1 <<
" written" << endl;
392 TFile* oldFile = gFile;
393 TDirectory* oldDir = gDirectory;
395 TFile* file =
new TFile(fileName,
"RECREATE");
419 TString type =
"Map";
420 if (fType == 2) type =
"Map sym2";
421 if (fType == 3) type =
"Map sym3";
422 cout <<
"======================================================" << endl;
425 cout <<
"---- " << fTitle <<
" : " << fName << endl;
426 cout <<
"----" << endl;
427 cout <<
"---- Field type : " << type << endl;
428 cout <<
"----" << endl;
429 cout <<
"---- Field map grid : " << endl;
430 cout <<
"---- x = " << setw(4) <<
fXmin <<
" to " << setw(4) <<
fXmax <<
" cm, " <<
fNx
431 <<
" grid points, dx = " <<
fXstep <<
" cm" << endl;
432 cout <<
"---- y = " << setw(4) <<
fYmin <<
" to " << setw(4) <<
fYmax <<
" cm, " <<
fNy
433 <<
" grid points, dy = " <<
fYstep <<
" cm" << endl;
434 cout <<
"---- z = " << setw(4) <<
fZmin <<
" to " << setw(4) <<
fZmax <<
" cm, " <<
fNz
435 <<
" grid points, dz = " <<
fZstep <<
" cm" << endl;
437 cout <<
"---- Field centre position: ( " << setw(6) <<
fPosX <<
", " << setw(6) <<
fPosY <<
", " << setw(6) <<
fPosZ
439 cout <<
"---- Field scaling factor: " <<
fScale << endl;
440 cout <<
"----" << endl;
441 cout <<
"---- Field at origin is ( " << setw(6) <<
fBxOrigin <<
", " << setw(6) <<
fByOrigin <<
", " << setw(6)
444 cout <<
"======================================================" << endl;
478 Double_t bx = 0., by = 0., bz = 0.;
481 LOG(info) <<
"CbmFieldMap: Reading field map from ASCII file " << fileName;
482 std::ifstream mapFile(fileName);
483 if (!mapFile.is_open()) {
484 LOG(error) <<
"CbmFieldMap:ReadAsciiFile: Could not open file!";
485 LOG(fatal) <<
"CbmFieldMap:ReadAsciiFile: Could not open file!";
492 if (type ==
"nosym") iType = 1;
493 if (type ==
"sym2") iType = 2;
494 if (type ==
"sym3") iType = 3;
495 if (fType != iType) {
496 cout <<
"-E- CbmFieldMap::ReadAsciiFile: Incompatible map types!" << endl;
497 cout <<
" Field map is of type " << fType <<
" but map on file is of type " << iType << endl;
498 Fatal(
"ReadAsciiFile",
"Incompatible map types");
515 Double_t factor =
fScale * 10.;
518 cout <<
"-I- CbmFieldMap: " << nTot <<
" entries to read... " << setw(3) << 0 <<
" % ";
521 Int_t iDiv = TMath::Nint(nTot / 100.);
522 for (
Int_t ix = 0; ix <
fNx; ix++) {
523 for (
Int_t iy = 0; iy <
fNy; iy++) {
524 for (
Int_t iz = 0; iz <
fNz; iz++) {
526 cerr <<
"-E- CbmFieldMap::ReadAsciiFile: "
527 <<
"I/O Error at " << ix <<
" " << iy <<
" " << iz << endl;
529 modul = div(index, iDiv);
530 if (modul.rem == 0) {
531 Double_t perc = TMath::Nint(100. * index / nTot);
532 cout <<
"\b\b\b\b\b\b" << setw(3) << perc <<
" % " << flush;
534 mapFile >> bx >> by >> bz;
535 fBx->AddAt(factor * bx, index);
536 fBy->AddAt(factor * by, index);
537 fBz->AddAt(factor * bz, index);
540 <<
"-E- CbmFieldMap::ReadAsciiFile: EOF"
541 <<
" reached at " << ix <<
" " << iy <<
" " << iz << endl;
549 cout <<
" " << index + 1 <<
" read" << endl;
560 TFile* oldFile = gFile;
561 TDirectory* oldDir = gDirectory;
564 LOG(info) <<
"CbmFieldMap: Reading field map from ROOT file " << fileName;
565 TFile* file =
new TFile(fileName,
"READ");
566 if (!(file->IsOpen())) {
567 LOG(error) <<
"CbmFieldMap:ReadRootFile: Could not open file!";
568 LOG(fatal) <<
"CbmFieldMap:ReadRootFile: Could not open file!";
573 file->GetObject(mapName, data);
575 cout <<
"-E- CbmFieldMap::ReadRootFile: data object " << fileName <<
" not found in file! " << endl;
598 if (data->
GetType() != fType) {
599 if (!((data->
GetType() == 3) && (fType == 5)))
601 cout <<
"-E- CbmFieldMap::SetField: Incompatible map types!" << endl;
602 cout <<
" Field map is of type " << fType <<
" but map on file is of type " << data->
GetType() << endl;
603 Fatal(
"SetField",
"Incompatible map types");
606 cout <<
" CbmFieldMap::SetField: Warning: You are using PosDepScaled "
607 "map (original map type = 3)"
627 fBx =
new TArrayF(*(data->
GetBx()));
628 fBy =
new TArrayF(*(data->
GetBy()));
629 fBz =
new TArrayF(*(data->
GetBz()));
632 Double_t factor =
fScale * 10.;
634 for (
Int_t ix = 0; ix <
fNx; ix++) {
635 for (
Int_t iy = 0; iy <
fNy; iy++) {
636 for (
Int_t iz = 0; iz <
fNz; iz++) {
638 if (
fBx) (*fBx)[index] = (*fBx)[index] * factor;
639 if (
fBy) (*fBy)[index] = (*fBy)[index] * factor;
640 if (
fBz) (*fBz)[index] = (*fBz)[index] * factor;
TString GetMapName() const
virtual void SetPosition(Double_t x, Double_t y, Double_t z)
virtual void GetFieldValue(const Double_t point[3], Double_t *bField) override
void WriteRootFile(const char *fileName, const char *mapName)
void ReadAsciiFile(const char *fileName)
void SetField(const CbmFieldMapData *data)
virtual void Print(Option_t *="") const override
GridCoordinates Global2Grid(Double_t x, Double_t y, Double_t z) const
Get grid cell coordinates for a point in global coordinates.
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 Interpolate(const TArrayF *B, const GridCoordinates &point) const
Get field values by interpolation of the grid.
virtual void Init() override
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