44 for (Int_t
i = 0;
i < 2;
i++) {
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";
95 if (!fName.Contains(
"/")) {
96 TString localDbPath = gSystem->Getenv(
"DBL_FILE_PATH");
97 if (localDbPath ==
"")
98 fName =
"$VMCWORKDIR/input/" + fName;
100 fName =
"$DBL_FILE_PATH/storage/" + fName;
103 if (fName.Contains(
"extrap")) {
104 LOG(info) <<
"Extrapolated magnetic field map is used";
105 gSystem->ExpandPathName(fName);
108 LOG(info) <<
"Basic magnetic field map is used";
109 gSystem->ExpandPathName(fName);
119 TString strFileName(asciiFileName);
120 gSystem->ExpandPathName(strFileName);
122 LOG(info) <<
"BmnFieldMap: Writing field map to ASCII file " << strFileName.Data() << endl;
123 ofstream mapFile(strFileName.Data());
124 if (!mapFile.is_open()) {
125 LOG(error) <<
"BmnFieldMap:ReadAsciiFile: Could not open file" << endl;
130 mapFile.precision(6);
131 mapFile << showpoint;
133 mapFile <<
"nosym" << endl;
135 mapFile <<
"sym2" << endl;
137 mapFile <<
"sym3" << endl;
143 Double_t factor = 10. *
fScale;
146 LOG(info) <<
"BmnFieldMap: " <<
fNx *
fNy *
fNz <<
" entries to write... " << setw(3) << 0 <<
" % ";
149 Int_t iDiv = TMath::Nint(nTot / 100.);
150 for (Int_t ix = 0; ix <
fNx; ix++) {
151 for (Int_t iy = 0; iy <
fNy; iy++) {
152 for (Int_t iz = 0; iz <
fNz; iz++) {
154 modul = div(index, iDiv);
155 if (modul.rem == 0) {
156 Double_t perc = TMath::Nint(100. * index / nTot);
157 cout <<
"\b\b\b\b\b\b" << setw(3) << perc <<
" % " << flush;
159 mapFile <<
fBx->At(index) / factor <<
" " <<
fBy->At(index) / factor <<
" " <<
fBz->At(index) / factor
164 cout <<
" " << index + 1 <<
" written" << endl;
171 TFile* oldFile = gFile;
172 TString strFileName(rootFileName);
173 gSystem->ExpandPathName(strFileName);
174 TFile* file = TFile::Open(strFileName,
"RECREATE");
193 TString type =
"Map";
198 cout <<
"======================================================" << endl;
201 cout <<
"---- " << fTitle <<
" : " << fName << endl;
202 cout <<
"----" << endl;
203 cout <<
"---- Field type : " << type << endl;
204 cout <<
"----" << endl;
205 cout <<
"---- Field map grid : " << endl;
206 cout <<
"---- x = " << setw(4) <<
fXmin <<
" to " << setw(4) <<
fXmax <<
" cm, " <<
fNx
207 <<
" grid points, dx = " <<
fXstep <<
" cm" << endl;
208 cout <<
"---- y = " << setw(4) <<
fYmin <<
" to " << setw(4) <<
fYmax <<
" cm, " <<
fNy
209 <<
" grid points, dy = " <<
fYstep <<
" cm" << endl;
210 cout <<
"---- z = " << setw(4) <<
fZmin <<
" to " << setw(4) <<
fZmax <<
" cm, " <<
fNz
211 <<
" grid points, dz = " <<
fZstep <<
" cm" << endl;
213 cout <<
"---- Target position: ( " << setw(6) <<
fPosX <<
", " << setw(6) <<
fPosY <<
", " << setw(6) <<
fPosZ
215 cout <<
"---- Field scaling factor: " <<
fScale << endl;
217 cout <<
"---- Field is off ----" << endl;
218 cout <<
"----" << endl;
219 cout <<
"---- Field at Target Position ( " << setw(6) <<
fPosBx <<
", " << setw(6) <<
fPosBy <<
", " << setw(6)
220 <<
fPosBz <<
") kG" << endl;
221 cout <<
"======================================================" << endl;
250 Double_t bx = 0., by = 0., bz = 0.;
252 TString strFileName(asciiFileName);
253 gSystem->ExpandPathName(strFileName);
255 LOG(info) <<
"BmnFieldMap: Reading field map from ASCII file " << strFileName.Data();
256 ifstream mapFile(strFileName.Data());
257 if (!mapFile.is_open()) {
258 LOG(error) <<
"BmnFieldMap:ReadAsciiFile: Could not open file!";
259 LOG(fatal) <<
"BmnFieldMap:ReadAsciiFile: Could not open file!";
272 if (fType != iType) {
273 cout <<
"-E- BmnFieldMap::ReadAsciiFile: Incompatible map types!" << endl;
274 cout <<
" Field map is of type " << fType <<
" but map on file is of type " << iType << endl;
275 Fatal(
"ReadAsciiFile",
"Incompatible map types");
292 Double_t factor =
fScale * 10.;
298 Int_t iDiv = TMath::Nint(nTot / 100.);
299 for (Int_t ix = 0; ix <
fNx; ix++) {
300 for (Int_t iy = 0; iy <
fNy; iy++) {
301 for (Int_t iz = 0; iz <
fNz; iz++) {
303 cerr <<
"-E- BmnFieldMap::ReadAsciiFile: "
304 <<
"I/O Error at " << ix <<
" " << iy <<
" " << iz << endl;
306 modul = div(index, iDiv);
311 mapFile >> bx >> by >> bz;
312 fBx->AddAt(factor * bx, index);
313 fBy->AddAt(factor * by, index);
314 fBz->AddAt(factor * bz, index);
317 <<
"-E- BmnFieldMap::ReadAsciiFile: EOF"
318 <<
" reached at " << ix <<
" " << iy <<
" " << iz << endl;
326 cout <<
" " << index + 1 <<
" read" << endl;
342 TString strFileName(rootFileName);
343 gSystem->ExpandPathName(strFileName);
345 LOG(info) <<
"BmnFieldMap: Reading field map from ROOT file " << strFileName.Data();
346 TFile* file = TFile::Open(strFileName,
"READ");
347 if ((file ==
nullptr) || (!file->IsOpen()))
348 LOG(fatal) <<
"BmnFieldMap:ReadRootFileNewFormat: Could not open the file with a field map";
351 TTree* tree = (TTree*)file->Get(
"Field_map");
352 tree->SetBranchAddress(
"field_points", &point);
370 fBx =
new TArrayF(nTot);
371 fBy =
new TArrayF(nTot);
372 fBz =
new TArrayF(nTot);
376 for (Int_t
i = 0;
i < tree->GetEntries();
i++) {
397 TString strFileName(rootFileName);
398 gSystem->ExpandPathName(strFileName);
400 LOG(info) <<
"BmnFieldMap: Reading field map from ROOT file " << strFileName.Data();
401 TFile* file = TFile::Open(strFileName,
"READ");
402 if ((file ==
nullptr) || (!file->IsOpen()))
403 LOG(fatal) <<
"BmnFieldMap:ReadRootFileNewFormatExtrap: Could not open the file with a field map";
406 TTree* tree = (TTree*)file->Get(
"Field_map");
407 tree->SetBranchAddress(
"field_points", &point);
425 fBx =
new TArrayF(nTot);
426 fBy =
new TArrayF(nTot);
427 fBz =
new TArrayF(nTot);
431 for (Int_t
i = 0;
i < tree->GetEntries();
i++) {
454 vector<Double_t>* read_Field = NULL;
456 TString strFileName(rootFileName);
457 gSystem->ExpandPathName(strFileName);
459 LOG(info) <<
"BmnFieldMap: Reading field map from ROOT file " << strFileName.Data();
460 TFile* file = TFile::Open(strFileName,
"READ");
461 if ((file ==
nullptr) || (!file->IsOpen()))
462 LOG(fatal) <<
"BmnFieldMap:ReadRootFile: Could not open the file with a field map";
464 TTree* tree = (TTree*)file->Get(
"Main_info");
465 TTree* t = (TTree*)file->Get(
"Field_map");
466 tree->SetBranchAddress(
"Field_type", &type);
467 tree->SetBranchAddress(
"Main_info_X", &X);
468 tree->SetBranchAddress(
"Main_info_Y", &Y);
469 tree->SetBranchAddress(
"Main_info_Z", &Z);
470 t->SetBranchAddress(
"field_map", &read_Field);
475 if (*type ==
"nosym")
481 if (fType != iType) {
482 LOG(error) <<
"BmnFieldMap::ReadRootFile: Incompatible map types!";
483 LOG(info) <<
" Field map is of type " << fType <<
" but map on file is of type " << iType;
484 LOG(fatal) <<
"ReadRootFile: Incompatible map types";
510 Int_t iDiv = TMath::Nint(nTot / 100.);
512 for (Int_t ix = 0; ix <
fNx; ix++) {
513 for (Int_t iy = 0; iy <
fNy; iy++) {
514 for (Int_t iz = 0; iz <
fNz; iz++) {
515 modul = div(index, iDiv);
521 vector<Double_t>
v = (*read_Field);
522 fBx->AddAt(factor *
v[0], index);
523 fBy->AddAt(factor *
v[1], index);
524 fBz->AddAt(factor *
v[2], index);
539 if (data->
GetType() != fType) {
540 if (!((data->
GetType() == 3) && (fType == 5)))
542 LOG(error) <<
"BmnFieldMap::SetField: Incompatible map types!";
543 LOG(info) <<
" Field map is of type " << fType <<
" but map on file is of type " << data->
GetType();
544 LOG(fatal) <<
"SetField: Incompatible map types";
546 LOG(info) <<
" BmnFieldMap::SetField: Warning: You are using PosDepScaled map (original map type = 3)";
567 fBx =
new TArrayF(*(data->
GetBx()));
568 fBy =
new TArrayF(*(data->
GetBy()));
569 fBz =
new TArrayF(*(data->
GetBz()));
572 Double_t factor =
fScale * 10.;
574 for (Int_t ix = 0; ix <
fNx; ix++) {
575 for (Int_t iy = 0; iy <
fNy; iy++) {
576 for (Int_t iz = 0; iz <
fNz; iz++) {
579 (*fBx)[index] = (*fBx)[index] * factor;
581 (*fBy)[index] = (*fBy)[index] * factor;
583 (*fBz)[index] = (*fBz)[index] * factor;
592 fHb[0][0] =
fHa[0][0][0] + (
fHa[1][0][0] -
fHa[0][0][0]) * dx;
593 fHb[1][0] =
fHa[0][1][0] + (
fHa[1][1][0] -
fHa[0][1][0]) * dx;
594 fHb[0][1] =
fHa[0][0][1] + (
fHa[1][0][1] -
fHa[0][0][1]) * dx;
595 fHb[1][1] =
fHa[0][1][1] + (
fHa[1][1][1] -
fHa[0][1][1]) * dx;
void ReadRootFileNewFormat(const char *rootFileName)
void SetField(const BmnFieldMapData *data)
void ReadRootFileNewFormatExtrap(const char *rootFileName)
void ReadRootFile(const char *rootFileName)
Double_t Interpolate(Double_t dx, Double_t dy, Double_t dz)
Double_t fHc[2]
Interpolated field (2-dim)
void SetPosition(Double_t x, Double_t y, Double_t z)
Double_t fHb[2][2]
Field at corners of a grid cell.
void WriteRootFile(const char *rootFileName, const char *mapFileName)
void ReadAsciiFile(const char *asciiFileName)
void WriteAsciiFile(const char *asciiFileName)
virtual void Print(Option_t *) const
Double_t GetPositionZ() const
Bool_t IsFieldOff() const
Double_t GetScale() const
Double_t GetPositionY() const
Double_t GetPositionX() const
void MapName(TString &name)