#include "lem4TabulatedField2D.hh" //#include "lem4EventAction.hh" // cks: just to get the event nr. if needed. #include "lem4Parameters.hh" lem4TabulatedField2D* lem4TabulatedField2D::pointerToTabulatedField2D=NULL; lem4TabulatedField2D* lem4TabulatedField2D::GetInstance() { return pointerToTabulatedField2D; } lem4TabulatedField2D::lem4TabulatedField2D( const char* filename, double fieldValue, double lenUnit, double fieldNormalisation ) :ffieldValue(fieldValue),invertX(false),invertZ(false) { pointerToTabulatedField2D=this; G4cout << "pointerToTabulatedField2D="< " "Reading the field grid from " << filename << " ... " << G4endl; positionOffset[0]=0; positionOffset[1]=0; positionOffset[2]=0; positionOffset[3]=0; std::ifstream file( filename ); // Open the file for reading. // Ignore first blank line char buffer[256]; // file.getline(buffer,256); // Read table dimensions int nDummy; file >> nx >> nDummy >> nz; // Note dodgy order G4cout << " [ Number of values x,z: " << nx << " " << nz << " ] " << G4endl; // Set up storage space for table xField.resize( nx ); zField.resize( nx ); int ix, iz; for (ix=0; ix> xval >> yval >> zval >> bx >> bz >> permeability; if ( ix==0 && iz==0 ) { minx = xval * lenUnit; minz = zval * lenUnit; } //xField[ix][iy][iz] = bx * fieldUnit * fieldValue; //zField[ix][iy][iz] = bz * fieldUnit * fieldValue; // xField[ix][iy][iz] = bx * fieldValue; // zField[ix][iy][iz] = bz * fieldValue; xField[ix][iz] = bx*fieldNormalisation; zField[ix][iz] = bz*fieldNormalisation; } } file.close(); maxx = xval * lenUnit; maxz = zval * lenUnit; G4cout << "\n ---> ... done reading " << G4endl; // G4cout << " Read values of field from file " << filename << G4endl; G4cout << " ---> assumed the order: x, y, z, Bx, Bz " << "\n ---> Min values x,y,z: " << minx/cm << " " << minz/cm << " cm " << "\n ---> Max values x,y,z: " << maxx/cm << " " << maxz/cm << " cm " << G4endl; // Should really check that the limits are not the wrong way around. if (maxx < minx) {std::swap(maxx,minx); invertX = true;} if (maxz < minz) {std::swap(maxz,minz); invertZ = true;} G4cout << "\nAfter reordering if neccesary" << "\n ---> Min values x,y,z: " << minx/cm << " " << minz/cm << " cm " << " \n ---> Max values x,y,z: " << maxx/cm << " " << maxz/cm << " cm "; dx = maxx - minx; dz = maxz - minz; G4cout << "\n ---> Dif values x,z (range): " << dx/cm << " " << dz/cm << " cm in z " << "\n-----------------------------------------------------------" << G4endl; } void lem4TabulatedField2D::GetFieldValue(const double point[4], double *Bfield ) const { // G4cout<<"Tabulated: Field requested at point ("<GetLatestEventNr(); // G4int evNrKriz=6795; //457; //14250 // if (evNr==evNrKriz) { // std::cout<<"evNr="<0) ? 1.:-1.; //if (evNr==evNrKriz) std::cout<<"x ="<(xdindex); int zindex = static_cast(zdindex); //cks The following check is necessary - even though xindex and zindex should never be out of range, // it may happen (due to some rounding error ?). It is better to leave the check here. if ((xindex<0)||(xindex>(nx-2))) { std::cout<<"SERIOUS PROBLEM: xindex out of range! xindex="< // // G4String processName = G4EventManager::GetEventManager()-> // GetTrackingManager()->GetTrack()->GetStep()-> // GetPostStepPoint()->GetProcessDefinedStep()-> // GetProcessName(); // The following seems to be OK: // if (lem4Parameters::field_DecayWithSpin) { // lem4Parameters::field_DecayWithSpin=false; // // } // else { // Muon is not decaying, use a fast method of interpolation. // Interpolate between the neighbouring points double Bfield_R = xField[xindex ][zindex ] * (1-xlocal) * (1-zlocal) + xField[xindex ][zindex+1] * (1-xlocal) * zlocal + xField[xindex+1][zindex ] * xlocal * (1-zlocal) + xField[xindex+1][zindex+1] * xlocal * zlocal ; Bfield[0] = (x>0) ? Bfield_R * (pppoint[0]/x) : 0.; Bfield[1] = (x>0) ? Bfield_R * (pppoint[1]/x) : 0.; Bfield[2] = zField[xindex ][zindex ] * (1-xlocal) * (1-zlocal) + zField[xindex ][zindex+1] * (1-xlocal) * zlocal + zField[xindex+1][zindex ] * xlocal * (1-zlocal) + zField[xindex+1][zindex+1] * xlocal * zlocal ; Bfield[0] = Bfield[0] * ffieldValue * z_sign; Bfield[1] = Bfield[1] * ffieldValue * z_sign; Bfield[2] = Bfield[2] * ffieldValue; // } } // Set some small field if field is almost zero (to avoid internal problems of Geant). if (sqrt(Bfield[0]*Bfield[0]+Bfield[1]*Bfield[1]+Bfield[2]*Bfield[2])<0.00001*tesla) { // if (evNr>evNrKriz) std::cout<<"bol som tuna"<-0.1*mm)&&(point[2]<0.1*mm)) { // printf ("for point= %f %f %f B= %10.10f %10.10f %10.10f \n", // point[0],point[1],point[2],Bfield[0]/tesla,Bfield[1]/tesla,Bfield[2]/tesla); // } // if (evNr>evNrKriz) std::cout<<"this is the end"<