28 fPosX(0), fPosY(0), fPosZ(0),
29 fXmin(0), fXmax(0), fXstep(0),
30 fYmin(0), fYmax(0), fYstep(0),
31 fZmin(0), fZmax(0), fZstep(0),
33 fBx(NULL), fBy(NULL), fBz(NULL)
45 fFileName(TString(
"")),
48 fPosX(0), fPosY(0), fPosZ(0),
49 fXmin(0), fXmax(0), fXstep(0),
50 fYmin(0), fYmax(0), fYstep(0),
51 fZmin(0), fZmax(0), fZstep(0),
53 fBx(NULL), fBy(NULL), fBz(NULL)
56 TString dir = getenv(
"VMCWORKDIR");
58 if ( fileType[0] ==
'R' )
fFileName +=
".root";
69 fFileName(TString(
"")),
72 fPosX(0), fPosY(0), fPosZ(0),
73 fXmin(0), fXmax(0), fXstep(0),
74 fYmin(0), fYmax(0), fYstep(0),
75 fZmin(0), fZmax(0), fZstep(0),
77 fBx(NULL), fBy(NULL), fBz(NULL)
86 TString
Name=GetName();
92 TString dir = getenv(
"VMCWORKDIR");
93 fFileName = dir +
"/input/" + Name +
".root";
119 Fatal(
"Init",
"No proper file name");
136 if (
IsInside(x, y, z, ix, iy, iz, dx, dy, dz) ) {
169 if (
IsInside(x, y, z, ix, iy, iz, dx, dy, dz) ) {
202 if (
IsInside(x, y, z, ix, iy, iz, dx, dy, dz) ) {
227 Int_t& ix, Int_t& iy, Int_t& iz,
228 Double_t&
dx, Double_t&
dy, Double_t&
dz) {
231 Double_t xl = x -
fPosX;
232 Double_t yl = y -
fPosY;
233 Double_t zl = z -
fPosZ;
244 ix = Int_t( xl /
fXstep );
245 iy = Int_t( yl /
fYstep );
246 iz = Int_t( zl /
fZstep );
250 dx = xl /
fXstep - Double_t(ix);
251 dy = yl /
fYstep - Double_t(iy);
252 dz = zl /
fZstep - Double_t(iz);
266 ofstream mapFile(fileName);
267 if ( ! mapFile.is_open() ) {
273 mapFile.precision(4);
274 mapFile << showpoint;
275 if ( fType == 1 ) mapFile <<
"nosym" << endl;
276 if ( fType == 2 ) mapFile <<
"Solenoid" << endl;
277 if ( fType == 3 ) mapFile <<
"Dipole" << endl;
278 if ( fType == 4 ) mapFile <<
"Trans" << endl;
279 if (
funit == 10.0 ) mapFile <<
"T" << endl;
280 if (
funit == 0.001 ) mapFile <<
"G" << endl;
281 if (
funit == 1.0 ) mapFile <<
"kG" << endl;
291 cout <<
"-I- PndFieldMap: " <<
fNx*
fNy*fNz <<
" entries to write... "
292 << setw(3) << 0 <<
" % ";
295 Int_t iDiv = TMath::Nint(nTot/100.);
296 for(Int_t ix=0; ix<
fNx; ix++) {
297 for(Int_t iy=0; iy<
fNy; iy++) {
298 for(Int_t iz=0; iz<
fNz; iz++) {
299 index =ix*fNy*fNz + iy*fNz + iz;
302 modul = div(index,iDiv);
303 if ( modul.rem == 0 ) {
304 Double_t perc = TMath::Nint(100.*index/nTot);
305 cout <<
"\b\b\b\b\b\b" << setw(3) << perc <<
" % " << flush;
308 mapFile <<
fBx->At(index)/factor <<
" " <<
fBy->At(index)/factor
309 <<
" " <<
fBz->At(index)/factor << endl;
313 cout <<
" " << index+1 <<
" written" << endl;
323 const char* mapName) {
326 TFile* oldFile = gFile;
327 TFile*
file =
new TFile(fileName,
"RECREATE");
330 if(oldFile) oldFile->cd();
349 TString type =
"Map";
350 if ( fType == 2 ) type =
"Soleniod Map ";
351 if ( fType == 3 ) type =
"Dipole Map ";
352 if ( fType == 4 ) type =
"Trans Map ";
353 cout <<
"======================================================" << endl;
356 cout <<
"---- " << fTitle <<
" : " << fName << endl;
357 cout <<
"----" << endl;
358 cout <<
"---- Field type : " << type << endl;
359 cout <<
"----" << endl;
360 cout <<
"---- Field map grid : " << endl;
361 cout <<
"---- x = " << setw(4) <<
fXmin <<
" to " << setw(4) <<
fXmax
362 <<
" cm, " <<
fNx <<
" grid points, dx = " <<
fXstep <<
" cm" << endl;
363 cout <<
"---- y = " << setw(4) <<
fYmin <<
" to " << setw(4) <<
fYmax
364 <<
" cm, " <<
fNy <<
" grid points, dy = " <<
fYstep <<
" cm" << endl;
365 cout <<
"---- z = " << setw(4) <<
fZmin <<
" to " << setw(4) <<
fZmax
366 <<
" cm, " <<
fNz <<
" grid points, dz = " <<
fZstep <<
" cm" << endl;
368 cout <<
"---- Field centre position: ( " << setw(6) <<
fPosX <<
", "
369 << setw(6) <<
fPosY <<
", " << setw(6) <<
fPosZ <<
") cm" << endl;
370 cout <<
"---- Field scaling factor: " <<
fScale << endl;
371 Double_t bx =
GetBx(0.,0.,0.);
372 Double_t by =
GetBy(0.,0.,0.);
373 Double_t bz =
GetBz(0.,0.,0.);
374 cout <<
"----" << endl;
375 cout <<
"---- Field at origin is ( " << setw(6) << bx <<
", " << setw(6)
376 << by <<
", " << setw(6) << bz <<
") kG" << endl;
377 cout <<
"======================================================" << endl;
403 Double_t bx=0., by=0., bz=0.;
406 cout <<
"-I- PndFieldMap: Reading field map from ASCII file "
408 ifstream mapFile(fileName);
409 if ( ! mapFile.is_open() ) {
410 cerr <<
"-E- PndFieldMap:ReadAsciiFile: Could not open file! " << endl;
411 Fatal(
"ReadAsciiFile",
"Could not open file");
419 if ( type ==
"nosym" ) iType = 1;
420 if ( type ==
"Solenoid") iType = 2;
421 if ( type ==
"Dipole" ) iType = 3;
422 if ( type ==
"Trans" ) iType = 4;
423 if ( fType != iType ) {
424 cout <<
"-E- PndFieldMap::ReadAsciiFile: Incompatible map types!"
426 cout <<
" Field map is of type " << fType
427 <<
" but map on file is of type " << iType << endl;
428 Fatal(
"ReadAsciiFile",
"Incompatible map types");
433 if ( unit ==
"G" )
funit = 0.001;
434 else if ( unit ==
"T" )
funit = 10.0;
435 else if ( unit ==
"kG" )
funit=1.0;
437 cout <<
"-E- FieldMap::ReadAsciiFile: No units!"
439 Fatal(
"ReadAsciiFile",
"No units defined");
453 fBx =
new TArrayF(fNx * fNy * fNz);
454 fBy =
new TArrayF(fNx * fNy * fNz);
455 fBz =
new TArrayF(fNx * fNy * fNz);
460 Int_t nTot = fNx * fNy *
fNz;
461 cout <<
"-I- PndFieldMap: " << nTot <<
" entries to read... "
462 << setw(3) << 0 <<
" % ";
465 Int_t iDiv = TMath::Nint(nTot/100.);
466 for (Int_t ix=0; ix<
fNx; ix++) {
467 for (Int_t iy = 0; iy<
fNy; iy++) {
468 for (Int_t iz = 0; iz<
fNz; iz++) {
469 if (! mapFile.good()) cerr <<
"-E- PndFieldMap::ReadAsciiFile: "
470 <<
"I/O Error at " << ix <<
" "
471 << iy <<
" " << iz << endl;
472 index = ix*fNy*fNz + iy*fNz + iz;
475 modul = div(index,iDiv);
476 if ( modul.rem == 0 ) {
477 Double_t perc = TMath::Nint(100.*index/nTot);
478 cout <<
"\b\b\b\b\b\b" << setw(3) << perc <<
" % " << flush;
482 mapFile >> bx >> by >> bz ;
484 fBx->AddAt(factor*bx, index);
485 fBy->AddAt(factor*by, index);
486 fBz->AddAt(factor*bz, index);
487 if ( mapFile.eof() ) {
488 cerr << endl <<
"-E- PndFieldMap::ReadAsciiFile: EOF"
489 <<
" reached at " << ix <<
" " << iy <<
" " << iz << endl;
497 cout <<
" " << index+1 <<
" read" << endl;
508 const char* mapName) {
511 TFile* oldFile = gFile;
515 TFile*
file =
new TFile(fileName,
"READ");
516 if (file->IsZombie()) {
518 Fatal(
"ReadRootFile",
"Cannot read from file");
523 file->GetObject(mapName, data);
536 if ( oldFile ) oldFile->cd();
547 if ( data->
GetType() != fType ) {
549 Fatal(
"SetField",
"Incompatible map types");
568 fBx =
new TArrayF(*(data->
GetBx()));
569 fBy =
new TArrayF(*(data->
GetBy()));
570 fBz =
new TArrayF(*(data->
GetBz()));
575 for (Int_t ix=0; ix<
fNx; ix++) {
576 for (Int_t iy=0; iy<
fNy; iy++) {
577 for (Int_t iz=0; iz<
fNz; iz++) {
578 index = ix*fNy*fNz + iy*fNz + iz;
579 if (
fBx ) (*fBx)[index] = (*fBx)[index] * factor;
580 if (
fBy ) (*fBy)[index] = (*fBy)[index] * factor;
581 if (
fBz ) (*fBz)[index] = (*fBz)[index] * factor;
595 fHb[0][0] =
fHa[0][0][0] + (
fHa[1][0][0]-
fHa[0][0][0] ) * dx;
596 fHb[1][0] =
fHa[0][1][0] + (
fHa[1][1][0]-
fHa[0][1][0] ) * dx;
597 fHb[0][1] =
fHa[0][0][1] + (
fHa[1][0][1]-
fHa[0][0][1] ) * dx;
598 fHb[1][1] =
fHa[0][1][1] + (
fHa[1][1][1]-
fHa[0][1][1] ) * dx;
601 fHc[0] = fHb[0][0] + ( fHb[1][0] - fHb[0][0] ) * dy;
602 fHc[1] = fHb[0][1] + ( fHb[1][1] - fHb[0][1] ) * dy;
605 return fHc[0] + ( fHc[1] - fHc[0] ) * dz;