46 for (
Int_t j = 0; j < 2; j++) {
48 for (
Int_t k = 0; k < 2; k++) {
71 LOG(error) <<
"BmnFieldMap::BmnFieldMap: empty parameter container";
99 if (localDbPath !=
"") {
100 gSystem->ExpandPathName(localDbPath);
105 localDbPath =
gSystem->GetDirName(localDbPath.
Data());
106 mapName = localDbPath +
"/storage/" + mapName;
108 localDbPath =
gSystem->Getenv(
"GEOMPATH");
109 if (localDbPath ==
"")
110 mapName =
"$VMCWORKDIR/input/" + mapName;
112 mapName =
"$GEOMPATH/" + mapName;
115 gSystem->ExpandPathName(mapName);
126 if (mapFilePath.
Contains(
"extrap")) {
127 LOG(info) <<
"Extrapolated magnetic field map is used";
130 LOG(info) <<
"Basic magnetic field map is used";
140 TString strFileName(asciiFileName);
141 gSystem->ExpandPathName(strFileName);
143 LOG(info) <<
"BmnFieldMap: Writing field map to ASCII file " << strFileName.
Data() << endl;
144 ofstream mapFile(strFileName.
Data());
145 if (!mapFile.is_open()) {
146 LOG(error) <<
"BmnFieldMap:ReadAsciiFile: Could not open file" << endl;
151 mapFile.precision(6);
152 mapFile << showpoint;
154 mapFile <<
"nosym" << endl;
156 mapFile <<
"sym2" << endl;
158 mapFile <<
"sym3" << endl;
167 LOG(info) <<
"BmnFieldMap: " <<
fNx *
fNy *
fNz <<
" entries to write... " << setw(3) << 0 <<
" % ";
171 for (
Int_t ix = 0; ix <
fNx; ix++) {
172 for (
Int_t iy = 0; iy <
fNy; iy++) {
173 for (
Int_t iz = 0; iz <
fNz; iz++) {
175 modul = div(index, iDiv);
176 if (modul.rem == 0) {
178 cout <<
"\b\b\b\b\b\b" << setw(3) << perc <<
" % " << flush;
180 mapFile <<
fBx->At(index) / factor <<
" " <<
fBy->At(index) / factor <<
" " <<
fBz->At(index) / factor
185 cout <<
" " << index + 1 <<
" written" << endl;
193 TString strFileName(rootFileName);
194 gSystem->ExpandPathName(strFileName);
219 cout <<
"======================================================" << endl;
222 cout <<
"---- " << fTitle <<
" : " << fName << endl;
223 cout <<
"----" << endl;
224 cout <<
"---- Field type : " << type << endl;
225 cout <<
"----" << endl;
226 cout <<
"---- Field map grid : " << endl;
227 cout <<
"---- x = " << setw(4) <<
fXmin <<
" to " << setw(4) <<
fXmax <<
" cm, " <<
fNx
228 <<
" grid points, dx = " <<
fXstep <<
" cm" << endl;
229 cout <<
"---- y = " << setw(4) <<
fYmin <<
" to " << setw(4) <<
fYmax <<
" cm, " <<
fNy
230 <<
" grid points, dy = " <<
fYstep <<
" cm" << endl;
231 cout <<
"---- z = " << setw(4) <<
fZmin <<
" to " << setw(4) <<
fZmax <<
" cm, " <<
fNz
232 <<
" grid points, dz = " <<
fZstep <<
" cm" << endl;
234 cout <<
"---- Target position: ( " << setw(6) <<
fPosX <<
", " << setw(6) <<
fPosY <<
", " << setw(6) <<
fPosZ
236 cout <<
"---- Field scaling factor: " <<
fScale << endl;
238 cout <<
"---- Field is off ----" << endl;
239 cout <<
"----" << endl;
240 cout <<
"---- Field at Target Position ( " << setw(6) <<
fPosBx <<
", " << setw(6) <<
fPosBy <<
", " << setw(6)
241 <<
fPosBz <<
") kG" << endl;
242 cout <<
"======================================================" << endl;
273 TString strFileName(asciiFileName);
274 gSystem->ExpandPathName(strFileName);
276 LOG(info) <<
"BmnFieldMap: Reading field map from ASCII file " << strFileName.
Data();
277 ifstream mapFile(strFileName.
Data());
278 if (!mapFile.is_open()) {
279 LOG(error) <<
"BmnFieldMap:ReadAsciiFile: Could not open file!";
280 LOG(fatal) <<
"BmnFieldMap:ReadAsciiFile: Could not open file!";
293 if (fType != iType) {
294 cout <<
"-E- BmnFieldMap::ReadAsciiFile: Incompatible map types!" << endl;
295 cout <<
" Field map is of type " << fType <<
" but map on file is of type " << iType << endl;
296 Fatal(
"ReadAsciiFile",
"Incompatible map types");
320 for (
Int_t ix = 0; ix <
fNx; ix++) {
321 for (
Int_t iy = 0; iy <
fNy; iy++) {
322 for (
Int_t iz = 0; iz <
fNz; iz++) {
324 cerr <<
"-E- BmnFieldMap::ReadAsciiFile: "
325 <<
"I/O Error at " << ix <<
" " << iy <<
" " << iz << endl;
327 modul = div(index, iDiv);
332 mapFile >> bx >> by >> bz;
333 fBx->AddAt(factor * bx, index);
334 fBy->AddAt(factor * by, index);
335 fBz->AddAt(factor * bz, index);
338 <<
"-E- BmnFieldMap::ReadAsciiFile: EOF"
339 <<
" reached at " << ix <<
" " << iy <<
" " << iz << endl;
347 cout <<
" " << index + 1 <<
" read" << endl;
363 TString strFileName(rootFileName);
364 gSystem->ExpandPathName(strFileName);
366 LOG(info) <<
"BmnFieldMap: Reading field map from ROOT file " << strFileName.
Data();
368 if ((file ==
nullptr) || (!file->
IsOpen()))
369 LOG(fatal) <<
"BmnFieldMap:ReadRootFileNewFormat: Could not open the file with a field map";
418 TString strFileName(rootFileName);
419 gSystem->ExpandPathName(strFileName);
421 LOG(info) <<
"BmnFieldMap: Reading field map from ROOT file " << strFileName.
Data();
423 if ((file ==
nullptr) || (!file->
IsOpen()))
424 LOG(fatal) <<
"BmnFieldMap:ReadRootFileNewFormatExtrap: Could not open the file with a field map";
475 vector<Double_t>* read_Field = NULL;
477 TString strFileName(rootFileName);
478 gSystem->ExpandPathName(strFileName);
480 LOG(info) <<
"BmnFieldMap: Reading field map from ROOT file " << strFileName.
Data();
482 if ((file ==
nullptr) || (!file->
IsOpen()))
483 LOG(fatal) <<
"BmnFieldMap:ReadRootFile: Could not open the file with a field map";
496 if (*type ==
"nosym")
502 if (fType != iType) {
503 LOG(error) <<
"BmnFieldMap::ReadRootFile: Incompatible map types!";
504 LOG(info) <<
" Field map is of type " << fType <<
" but map on file is of type " << iType;
505 LOG(fatal) <<
"ReadRootFile: Incompatible map types";
533 for (
Int_t ix = 0; ix <
fNx; ix++) {
534 for (
Int_t iy = 0; iy <
fNy; iy++) {
535 for (
Int_t iz = 0; iz <
fNz; iz++) {
536 modul = div(index, iDiv);
542 vector<Double_t>
v = (*read_Field);
543 fBx->AddAt(factor *
v[0], index);
544 fBy->AddAt(factor *
v[1], index);
545 fBz->AddAt(factor *
v[2], index);
560 if (data->
GetType() != fType) {
561 if (!((data->
GetType() == 3) && (fType == 5)))
563 LOG(error) <<
"BmnFieldMap::SetField: Incompatible map types!";
564 LOG(info) <<
" Field map is of type " << fType <<
" but map on file is of type " << data->
GetType();
565 LOG(fatal) <<
"SetField: Incompatible map types";
567 LOG(info) <<
" BmnFieldMap::SetField: Warning: You are using PosDepScaled map (original map type = 3)";
595 for (
Int_t ix = 0; ix <
fNx; ix++) {
596 for (
Int_t iy = 0; iy <
fNy; iy++) {
597 for (
Int_t iz = 0; iz <
fNz; iz++) {
600 (*fBx)[index] = (*fBx)[index] * factor;
602 (*fBy)[index] = (*fBy)[index] * factor;
604 (*fBz)[index] = (*fBz)[index] * factor;
613 fHb[0][0] =
fHa[0][0][0] + (
fHa[1][0][0] -
fHa[0][0][0]) * dx;
614 fHb[1][0] =
fHa[0][1][0] + (
fHa[1][1][0] -
fHa[0][1][0]) * dx;
615 fHb[0][1] =
fHa[0][0][1] + (
fHa[1][0][1] -
fHa[0][0][1]) * dx;
616 fHb[1][1] =
fHa[0][1][1] + (
fHa[1][1][1] -
fHa[0][1][1]) * dx;
void Fatal(const char *location, const char *msgfmt,...)
Bool_t R_ISDIR(Int_t mode)
R__EXTERN TSystem * gSystem
Int_t GetType() const
Accessors to field parameters in local coordinate system.
TArrayF * GetBx() const
Accessors to the field value arrays.
void ReadRootFileNewFormat(const char *rootFileName)
Double_t fHa[2][2][2]
Variables for temporary storage Used in the very frequently called method GetFieldValue.
void SetField(const BmnFieldMapData *data)
Set field parameters and data.
Bool_t fIsOff
Whether magnetic field is off.
TArrayF * GetBx() const
Accessors to the field value arrays.
Int_t fNx
Number of grid points.
void ReadRootFileNewFormatExtrap(const char *rootFileName)
void ReadRootFile(const char *rootFileName)
Read field map from a ROOT file.
static TString GetMapFilePath(TString mapName)
Get the expanded path to the field map file in the current installation.
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.
Double_t fHc[2]
Interpolated field (2-dim).
void Reset()
Reset the field parameters and data.
void SetPosition(Double_t x, Double_t y, Double_t z)
Set the position of the field centre.
Double_t fHb[2][2]
Field at corners of a grid cell.
void WriteRootFile(const char *rootFileName, const char *mapFileName)
Write field map data to a ROOT file.
Bool_t fDebugInfo
Interpolated field (1-dim).
Double_t fXmin
Field limits in local coordinate system.
TArrayF * fBx
Arrays with the field values.
void ReadAsciiFile(const char *asciiFileName)
Reset the field parameters and data.
void WriteAsciiFile(const char *asciiFileName)
Write the field map to an ASCII file.
virtual void Print(Option_t *) const
Screen output.
Double_t GetPositionZ() const
Bool_t IsFieldOff() const
Int_t GetType() const
Accessors.
Double_t GetScale() const
Double_t GetPositionY() const
Double_t GetPositionX() const
void MapName(TString &name)
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)
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)