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)
 
   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");
 
   57   fFileName = dir + 
"/input/fieldmaps/" + mapName;
 
   58   if ( fileType[0] == 
'R' ) 
fFileName += 
".root";
 
   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)
 
   81     LOG(ERROR) << 
"PndConstField::PndConstField: empty parameter container!"  ;
 
   92     TString dir = getenv(
"VMCWORKDIR");
 
   93     fFileName = dir + 
"/input/fieldmaps/" + Name + 
".root";
 
  102     fFileName(L.fFileName),
 
  105     fPosX(L.fPosX), fPosY(L.fPosY), fPosZ(L.fPosZ),
 
  106     fXmin(L.fXmin), fXmax(L.fXmax), fXstep(L.fXstep),
 
  107     fYmin(L.fYmin), fYmax(L.fYmax), fYstep(L.fYstep),
 
  108     fZmin(L.fZmin), fZmax(L.fZmax), fZstep(L.fZstep),
 
  109     fNx(L.fNx),fNy(L.fNy),fNz(L.fNz),
 
  110     fBx(L.fBx), fBy(L.fBy), fBz(L.fBz)
 
  113   for (Int_t ii=0; ii<2; ii++)
 
  116       for (Int_t 
jj=0; 
jj<2; 
jj++)
 
  119             for (Int_t kk=0; kk<2; kk++)
 
  148     LOG(ERROR) << 
"-E- PndFieldMap::Init: No proper file name defined!  "<<
fFileName.Data()  ;
 
  149     Fatal(
"Init", 
"No proper file name");
 
  166   if ( 
IsInside(x, y, z, ix, iy, iz, dx, dy, dz) ) {
 
  199   if ( 
IsInside(x, y, z, ix, iy, iz, dx, dy, dz) ) {
 
  232   if ( 
IsInside(x, y, z, ix, iy, iz, dx, dy, dz) ) {
 
  257                              Int_t& ix, Int_t& iy, Int_t& iz,
 
  274   ix = Int_t( xl / 
fXstep );
 
  275   iy = Int_t( yl / 
fYstep );
 
  276   iz = Int_t( zl / 
fZstep );
 
  295   LOG(INFO) <<
"PndFieldMap: Writing field map to ASCII file " <<fileName  ;
 
  296   ofstream mapFile(fileName);
 
  297   if ( ! mapFile.is_open() ) {
 
  298     LOG(ERROR) << 
"PndFieldMap:ReadAsciiFile: Could not open file! "  ;
 
  303   mapFile.precision(4);
 
  304   mapFile << showpoint;
 
  305   if ( fType == 1 ) mapFile << 
"nosym" << endl;
 
  306   if ( fType == 2 ) mapFile << 
"Solenoid" << endl;
 
  307   if ( fType == 3 ) mapFile << 
"Dipole" << endl;
 
  308   if ( fType == 4 ) mapFile << 
"Trans" << endl;
 
  309   if ( 
funit == 10.0  ) mapFile << 
"T" << endl;
 
  310   if ( 
funit == 0.001 ) mapFile << 
"G" << endl;
 
  311   if ( 
funit == 1.0   ) mapFile << 
"kG" << endl;
 
  321   cout << 
"-I- PndFieldMap: " << 
fNx*
fNy*fNz << 
" entries to write... " 
  322        << setw(3) << 0 << 
" % ";
 
  326   for(Int_t ix=0; ix<
fNx; ix++) {
 
  327     for(Int_t iy=0; iy<
fNy; iy++) {
 
  328       for(Int_t iz=0; iz<
fNz; iz++) {
 
  329         index =ix*fNy*fNz + iy*fNz + iz;
 
  332             modul = div(index,iDiv);
 
  333             if ( modul.rem == 0 ) {
 
  335               cout << 
"\b\b\b\b\b\b" << setw(3) << perc << 
" % " << flush;
 
  338         mapFile << 
fBx->At(index)/factor << 
" " << 
fBy->At(index)/factor
 
  339                 << 
" " << 
fBz->At(index)/factor << endl;
 
  343   cout << 
"   " << index+1 << 
" written" << endl;
 
  353                                 const char* mapName) {
 
  356   TFile* oldFile = gFile;
 
  357   TFile* 
file = 
new TFile(fileName, 
"RECREATE");
 
  360   if(oldFile) oldFile->cd();
 
  380   if ( fType == 2 ) type = 
"Soleniod Map ";
 
  381   if ( fType == 3 ) type = 
"Dipole Map ";
 
  382   if ( fType == 4 ) type = 
"Trans Map ";
 
  383   cout << 
"======================================================" << endl;
 
  386   cout << 
"----  " << fTitle << 
" : " << fName << endl;
 
  387   cout << 
"----" << endl;
 
  388   cout << 
"----  Field type     : " << type << endl;
 
  389   cout << 
"----" << endl;
 
  390   cout << 
"----  Field map grid : " << endl;
 
  391   cout << 
"----  x = " << setw(4) << 
fXmin << 
" to " << setw(4) << 
fXmax 
  392        << 
" cm, " << 
fNx << 
" grid points, dx = " << 
fXstep << 
" cm" << endl;
 
  393   cout << 
"----  y = " << setw(4) << 
fYmin << 
" to " << setw(4) << 
fYmax 
  394        << 
" cm, " << 
fNy << 
" grid points, dy = " << 
fYstep << 
" cm" << endl;
 
  395   cout << 
"----  z = " << setw(4) << 
fZmin << 
" to " << setw(4) << 
fZmax 
  396        << 
" cm, " << 
fNz << 
" grid points, dz = " << 
fZstep << 
" cm" << endl;
 
  398   cout << 
"----  Field centre position: ( " << setw(6) << 
fPosX << 
", " 
  399        << setw(6) << 
fPosY << 
", " << setw(6) << 
fPosZ << 
") cm" << endl;
 
  400   cout << 
"----  Field scaling factor: " << 
fScale << endl;
 
  404   cout << 
"----" << endl;
 
  405   cout << 
"----  Field at origin is ( " << setw(6) << bx << 
", " << setw(6)
 
  406        << by << 
", " << setw(6) << bz << 
") kG" << endl;
 
  407  cout << 
"======================================================" << endl;
 
  435   cout << 
"-I- PndFieldMap: Reading field map from ASCII file " 
  437   ifstream mapFile(fileName);
 
  438   if ( ! mapFile.is_open() ) {
 
  439     cerr << 
"-E- PndFieldMap:ReadAsciiFile: Could not open file! " << endl;
 
  440     Fatal(
"ReadAsciiFile",
"Could not open file");
 
  448   if ( type == 
"nosym" ) iType = 1;
 
  449   if ( type == 
"Solenoid") iType = 2;
 
  450   if ( type == 
"Dipole"  ) iType = 3;
 
  451   if ( type == 
"Trans"  ) iType = 4;
 
  452   if ( fType != iType ) {
 
  453     cout << 
"-E- PndFieldMap::ReadAsciiFile: Incompatible map types!" 
  455     cout << 
"    Field map is of type " << fType
 
  456          << 
" but map on file is of type " << iType << endl;
 
  457     Fatal(
"ReadAsciiFile",
"Incompatible map types");
 
  462   if ( unit == 
"G" ) 
funit = 0.001;
 
  463   else if ( unit == 
"T"  ) 
funit = 10.0;
 
  464   else if ( unit == 
"kG"  ) 
funit=1.0;
 
  466     cout << 
"-E- FieldMap::ReadAsciiFile: No units!" 
  468         Fatal(
"ReadAsciiFile",
"No units defined");
 
  482   fBx = 
new TArrayF(fNx * fNy * fNz);
 
  483   fBy = 
new TArrayF(fNx * fNy * fNz);
 
  484   fBz = 
new TArrayF(fNx * fNy * fNz);
 
  489   Int_t nTot = fNx * fNy * 
fNz;
 
  490   cout << 
"-I- PndFieldMap: " << nTot << 
" entries to read... " 
  491        << setw(3) << 0 << 
" % ";
 
  495   for (Int_t ix=0; ix<
fNx; ix++) {
 
  496     for (Int_t iy = 0; iy<
fNy; iy++) {
 
  497       for (Int_t iz = 0; iz<
fNz; iz++) {
 
  498         if (! mapFile.good()) cerr << 
"-E- PndFieldMap::ReadAsciiFile: " 
  499                                    << 
"I/O Error at " << ix << 
" " 
  500                                    << iy << 
" " << iz << endl;
 
  501         index = ix*fNy*fNz + iy*fNz + iz;
 
  504             modul = div(index,iDiv);
 
  505             if ( modul.rem == 0 ) {
 
  507               cout << 
"\b\b\b\b\b\b" << setw(3) << perc << 
" % " << flush;
 
  511         mapFile >>  bx >> by >> bz ;
 
  513         fBx->AddAt(factor*bx, index);
 
  514         fBy->AddAt(factor*by, index);
 
  515         fBz->AddAt(factor*bz, index);
 
  516         if ( mapFile.eof() ) {
 
  517           cerr << endl << 
"-E- PndFieldMap::ReadAsciiFile: EOF" 
  518                << 
" reached at " << ix << 
" " << iy << 
" " << iz << endl;
 
  526   cout << 
"   " << index+1 << 
" read" << endl;
 
  537                                const char* mapName) {
 
  540   TFile* oldFile = gFile;
 
  543   LOG(INFO) <<
"PndFieldMap: Reading field map from ROOT file  "<<fileName  ;
 
  544   TFile* 
file = 
new TFile(fileName, 
"READ");
 
  545   if (file->IsZombie()) {
 
  546     LOG(ERROR) << 
"-E- PndFieldMap::ReadRootfile: Cannot read from file! "  ;
 
  547     Fatal(
"ReadRootFile",
"Cannot read from file");
 
  552   file->GetObject(mapName, data);
 
  554      LOG(ERROR)<<
"PndFieldMap::ReadRootFile: data object %s not found in file! "<< fileName  ;
 
  565   if ( oldFile ) oldFile->cd();
 
  576   if ( data->
GetType() != fType ) {
 
  577     LOG(ERROR)<<
"PndFieldMap::SetField: Incompatible map types Field map is of type "<<fType<<
" \n but map on file is of type "<<data->
GetType()  ;
 
  578     Fatal(
"SetField",
"Incompatible map types");
 
  597   fBx = 
new TArrayF(*(data->
GetBx()));
 
  598   fBy = 
new TArrayF(*(data->
GetBy()));
 
  599   fBz = 
new TArrayF(*(data->
GetBz()));
 
  604   for (Int_t ix=0; ix<
fNx; ix++) {
 
  605     for (Int_t iy=0; iy<
fNy; iy++) {
 
  606       for (Int_t iz=0; iz<
fNz; iz++) {
 
  607         index = ix*fNy*fNz + iy*fNz + iz;
 
  608         if ( 
fBx ) (*fBx)[index] = (*fBx)[index] * factor;
 
  609         if ( 
fBy ) (*fBy)[index] = (*fBy)[index] * factor;
 
  610         if ( 
fBz ) (*fBz)[index] = (*fBz)[index] * factor;
 
  624   fHb[0][0] = 
fHa[0][0][0] + ( 
fHa[1][0][0]-
fHa[0][0][0] ) * dx;
 
  625   fHb[1][0] = 
fHa[0][1][0] + ( 
fHa[1][1][0]-
fHa[0][1][0] ) * dx;
 
  626   fHb[0][1] = 
fHa[0][0][1] + ( 
fHa[1][0][1]-
fHa[0][0][1] ) * dx;
 
  627   fHb[1][1] = 
fHa[0][1][1] + ( 
fHa[1][1][1]-
fHa[0][1][1] ) * dx;
 
  630   fHc[0] = fHb[0][0] + ( fHb[1][0] - fHb[0][0] ) * dy;
 
  631   fHc[1] = fHb[0][1] + ( fHb[1][1] - fHb[0][1] ) * dy;
 
  634   return fHc[0] + ( fHc[1] - fHc[0] ) * dz;
 
cout<< "-----------------------------------------------> Quarter VOLUME<<endl;name="QuarterShape";QuarterShape=newTGeoArb8(name,dz,vertQuar);name="Quarter4Vol";TStringmedium="air";QuarterVol=newTGeoVolumeAssembly(name);name="SubunitShape";SubunitShape=newTGeoArb8(name,dz,vertSub);TStringmedium="air";name="SubunitVol";name1="SubunitVol1";name2="SubunitVol2";name3="SubunitVol3";name4="SubunitVol4";name5="SubunitVol5";name6="SubunitVol6";name7="SubunitVol7";name8="SubunitVol8";name9="SubunitVol9";SubunitVol=newTGeoVolumeAssembly(name);SubunitVol1=newTGeoVolumeAssembly(name1);SubunitVol2=newTGeoVolumeAssembly(name2);SubunitVol3=newTGeoVolumeAssembly(name3);SubunitVol4=newTGeoVolumeAssembly(name4);SubunitVol5=newTGeoVolumeAssembly(name5);SubunitVol6=newTGeoVolumeAssembly(name6);SubunitVol7=newTGeoVolumeAssembly(name7);SubunitVol8=newTGeoVolumeAssembly(name8);SubunitVol9=newTGeoVolumeAssembly(name9);name="BoxShape";BoxShape=newTGeoArb8(name,dz,vertBox);TStringmedium="air";name="BoxVol";BoxVol=newTGeoVolumeAssembly(name);name1="BoxVol1";name2="BoxVol2";name3="BoxVol3";name4="BoxVol4";BoxVol1=newTGeoVolumeAssembly(name1);BoxVol2=newTGeoVolumeAssembly(name2);BoxVol3=newTGeoVolumeAssembly(name3);BoxVol4=newTGeoVolumeAssembly(name4);for(Int_tb=0;b<kNumOfBoxes;b++){cout<<""<<endl;cout<<"---------------->BOXnumber:"<<b<<endl;if(b==0){trBox=newTGeoTranslation(tr+kSpaceInSub+kAlveoleThickness+0.5*kSpaceInBox,tr+kSpaceInSub+kAlveoleThickness+0.5*kSpaceInBox,0.);rotBox=newTGeoRotation();rotBox.RotateX(0.465518);rotBox.RotateY(-0.465518);}if(b==1){trBox=newTGeoTranslation(-tr-kSpaceInSub-kAlveoleThickness-0.5*kSpaceInBox,-tr-kSpaceInSub-kAlveoleThickness-0.5*kSpaceInBox,0.);rotBox=newTGeoRotation();rotBox.RotateX(-0.465518);rotBox.RotateY(0.465518);}if(b==2){trBox=newTGeoTranslation(tr+kSpaceInSub+kAlveoleThickness+0.5*kSpaceInBox,-tr-kSpaceInSub-kAlveoleThickness-0.5*kSpaceInBox,0.);rotBox=newTGeoRotation();rotBox.RotateX(-0.465518);rotBox.RotateY(-0.465518);}if(b==3){trBox=newTGeoTranslation(-tr-kSpaceInSub-kAlveoleThickness-0.5*kSpaceInBox,tr+kSpaceInSub+kAlveoleThickness+0.5*kSpaceInBox,0.);rotBox=newTGeoRotation();rotBox.RotateX(0.465518);rotBox.RotateY(0.465518);}TGeoCombiTrans*trrotBox=newTGeoCombiTrans(trBox,rotBox);name="BoxVol";name+=b;trrotBox->SetName(name);trrotBox->RegisterYourself();SubunitVol->AddNode(BoxVol,b,trrotBox);if(b==1){name+=b;trrotBox->SetName(name);trrotBox->RegisterYourself();SubunitVol1->AddNode(BoxVol,b,trrotBox);}if(b==2){name+=b;trrotBox->SetName(name);trrotBox->RegisterYourself();SubunitVol2->AddNode(BoxVol1,b,trrotBox);}if(b==0){name+=b;trrotBox-> SetName(name)
void WriteAsciiFile(const char *fileName)
void MapName(TString &name)
Double_t GetPositionZ() const 
Double_t fHb[2][2]
Field at corners of a grid cell. 
void WriteRootFile(const char *fileName, const char *mapName)
virtual Bool_t IsInside(Double_t x, Double_t y, Double_t z, Int_t &ix, Int_t &iy, Int_t &iz, Double_t &dx, Double_t &dy, Double_t &dz)
Double_t fHc[2]
Interpolated field (2-dim) 
Double_t GetPositionY() const 
void SetPosition(Double_t x, Double_t y, Double_t z)
Double_t Interpolate(Double_t dx, Double_t dy, Double_t dz)
PndMultiFieldPar * fieldPar
void SetField(const PndFieldMapData *data)
Double_t GetPositionX() const 
Double_t GetScale() const 
void ReadAsciiFile(const char *fileName)
void ReadRootFile(const char *fileName, const char *mapName)