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 (storagePath ==
"")
100 mapName =
"$VMCWORKDIR/input/" + mapName;
102 mapName =
"$GEOMPATH/" + mapName;
104 gSystem->ExpandPathName(mapName);
115 if (mapFilePath.
Contains(
"extrap")) {
116 LOG(info) <<
"Extrapolated magnetic field map is used";
119 LOG(info) <<
"Basic magnetic field map is used";
129 TString strFileName(asciiFileName);
130 gSystem->ExpandPathName(strFileName);
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;
140 mapFile.precision(6);
141 mapFile << showpoint;
143 mapFile <<
"nosym" << endl;
145 mapFile <<
"sym2" << endl;
147 mapFile <<
"sym3" << endl;
156 LOG(info) <<
"BmnFieldMap: " <<
fNx *
fNy *
fNz <<
" entries to write... " << setw(3) << 0 <<
" % ";
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++) {
164 modul = div(index, iDiv);
165 if (modul.rem == 0) {
167 cout <<
"\b\b\b\b\b\b" << setw(3) << perc <<
" % " << flush;
169 mapFile <<
fBx->At(index) / factor <<
" " <<
fBy->At(index) / factor <<
" " <<
fBz->At(index) / factor
174 cout <<
" " << index + 1 <<
" written" << endl;
182 TString strFileName(rootFileName);
183 gSystem->ExpandPathName(strFileName);
208 cout <<
"======================================================" << endl;
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;
223 cout <<
"---- Target position: ( " << setw(6) <<
fPosX <<
", " << setw(6) <<
fPosY <<
", " << setw(6) <<
fPosZ
225 cout <<
"---- Field scaling factor: " <<
fScale << endl;
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;
262 TString strFileName(asciiFileName);
263 gSystem->ExpandPathName(strFileName);
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!";
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");
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++) {
313 cerr <<
"-E- BmnFieldMap::ReadAsciiFile: "
314 <<
"I/O Error at " << ix <<
" " << iy <<
" " << iz << endl;
316 modul = div(index, iDiv);
321 mapFile >> bx >> by >> bz;
322 fBx->AddAt(factor * bx, index);
323 fBy->AddAt(factor * by, index);
324 fBz->AddAt(factor * bz, index);
327 <<
"-E- BmnFieldMap::ReadAsciiFile: EOF"
328 <<
" reached at " << ix <<
" " << iy <<
" " << iz << endl;
336 cout <<
" " << index + 1 <<
" read" << endl;
352 TString strFileName(rootFileName);
353 gSystem->ExpandPathName(strFileName);
355 LOG(info) <<
"BmnFieldMap: Reading field map from ROOT file " << strFileName.
Data();
357 if ((file ==
nullptr) || (!file->
IsOpen()))
358 LOG(fatal) <<
"BmnFieldMap:ReadRootFileNewFormat: Could not open the file with a field map";
407 TString strFileName(rootFileName);
408 gSystem->ExpandPathName(strFileName);
410 LOG(info) <<
"BmnFieldMap: Reading field map from ROOT file " << strFileName.
Data();
413 if ((file ==
nullptr) || (!file->
IsOpen()))
414 LOG(fatal) <<
"BmnFieldMap:ReadRootFileNewFormatExtrap: Could not open the file with a field map";
419 LOG(fatal) <<
"BmnFieldMap:ReadRootFileNewFormatExtrap: Tree 'Field_map' not found";
429 LOG(info) <<
"BmnFieldMap: Reading grid info from Field_map_info tree";
432 Double_t X1I, X2I, Y1I, Y2I, Z1I, Z2I;
461 LOG(info) <<
" Grid: Nx = " <<
fNx <<
", Ny = " <<
fNy <<
", Nz = " <<
fNz;
470 LOG(warning) <<
"BmnFieldMap: Field_map_info tree not found, using hardcoded grid";
495 if (nEntries != nTot) {
496 LOG(warning) <<
"BmnFieldMap:ReadRootFileNewFormatExtrap: number of entries (" << nEntries <<
") != Nx*Ny*Nz ("
501 for (
Int_t i = 0;
i < nEntries &&
i < nTot; ++
i) {
525 vector<Double_t>* read_Field = NULL;
527 TString strFileName(rootFileName);
528 gSystem->ExpandPathName(strFileName);
530 LOG(info) <<
"BmnFieldMap: Reading field map from ROOT file " << strFileName.
Data();
532 if ((file ==
nullptr) || (!file->
IsOpen()))
533 LOG(fatal) <<
"BmnFieldMap:ReadRootFile: Could not open the file with a field map";
546 if (*type ==
"nosym")
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";
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);
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);
610 if (data->
GetType() != fType) {
611 if (!((data->
GetType() == 3) && (fType == 5)))
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";
617 LOG(info) <<
" BmnFieldMap::SetField: Warning: You are using PosDepScaled map (original map type = 3)";
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++) {
650 (*fBx)[index] = (*fBx)[index] * factor;
652 (*fBy)[index] = (*fBy)[index] * factor;
654 (*fBz)[index] = (*fBz)[index] * factor;
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;
void Fatal(const char *location, const char *msgfmt,...)
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)
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.
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.
Double_t fHb[2][2]
Field at corners of a grid cell.
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.
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.
void SetPosition(Double_t x, Double_t y, Double_t z)
Set the position of the field centre.
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.
Double_t fHc[2]
Interpolated field (2-dim).
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)
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)