// ------------------------------------------------------------------------- // ----- FairConstField source file ----- // ----- Created 30/01/07 by M. Al/Turany ----- // ------------------------------------------------------------------------- #include "FairConstField.h" #include "FairConstPar.h" // for FairConstPar #include "FairRun.h" // for FairRun #include "FairRuntimeDb.h" // for FairRuntimeDb #include "Riosfwd.h" // for ostream #include "TString.h" // for operator<<, TString #include // for operator<<, setw #include // for operator<<, basic_ostream, etc using namespace std; // ----- Default constructor ------------------------------------------- FairConstField::FairConstField() : fXmin(0), fXmax(0), fYmin(0), fYmax(0), fZmin(0), fZmax(0), fBx(0), fBy(0), fBz(0) { fType = 0; } // ------------------------------------------------------------------------- // ----- Standard constructor ------------------------------------------ FairConstField::FairConstField(const char* name, Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax, Double_t zMin, Double_t zMax, Double_t bX, Double_t bY, Double_t bZ) : FairField(name), fXmin(xMin), fXmax(xMax), fYmin(yMin), fYmax(yMax), fZmin(zMin), fZmax(zMax), fBx(bX), fBy(bY), fBz(bZ) { fType = 0; } // ------------------------------------------------------------------------- // -------- Constructor from PndFieldPar ------------------------------- FairConstField::FairConstField(FairConstPar* fieldPar) : FairField(), fXmin(0), fXmax(0), fYmin(0), fYmax(0), fZmin(0), fZmax(0), fBx(0), fBy(0), fBz(0) { if ( ! fieldPar ) { cerr << "-W- FairConstField::FairConstField: empty parameter container!"<< endl; fType= -1; } else { fXmin = fieldPar->GetXmin(); fXmax = fieldPar->GetXmax(); fYmin = fieldPar->GetYmin(); fYmax = fieldPar->GetYmax(); fZmin = fieldPar->GetZmin(); fZmax = fieldPar->GetZmax(); fBx = fieldPar->GetBx(); fBy = fieldPar->GetBy(); fBz = fieldPar->GetBz(); fType = fieldPar->GetType(); } } // ------------------------------------------------------------------------- // ----- Destructor ---------------------------------------------------- FairConstField::~FairConstField() { } // ------------------------------------------------------------------------- // ----- Set field region ---------------------------------------------- void FairConstField::SetFieldRegion(Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax, Double_t zMin, Double_t zMax) { fXmin = xMin; fXmax = xMax; fYmin = yMin; fYmax = yMax; fZmin = zMin; fZmax = zMax; } // ------------------------------------------------------------------------- // ----- Set field values ---------------------------------------------- void FairConstField::SetField(Double_t bX, Double_t bY, Double_t bZ) { fBx = bX; fBy = bY; fBz = bZ; } // ------------------------------------------------------------------------- // ----- Get x component of field -------------------------------------- Double_t FairConstField::GetBx(Double_t x, Double_t y, Double_t z) { if ( x < fXmin || x > fXmax || y < fYmin || y > fYmax || z < fZmin || z > fZmax ) { return 0.; } return fBx; } // ------------------------------------------------------------------------- // ----- Get y component of field -------------------------------------- Double_t FairConstField::GetBy(Double_t x, Double_t y, Double_t z) { if ( x < fXmin || x > fXmax || y < fYmin || y > fYmax || z < fZmin || z > fZmax ) { return 0.; } return fBy; } // ------------------------------------------------------------------------- // ----- Get z component of field -------------------------------------- Double_t FairConstField::GetBz(Double_t x, Double_t y, Double_t z) { if ( x < fXmin || x > fXmax || y < fYmin || y > fYmax || z < fZmin || z > fZmax ) { return 0.; } return fBz; } // ------------------------------------------------------------------------- // ----- Screen output ------------------------------------------------- void FairConstField::Print() { cout << "======================================================" << endl; cout << "---- " << fTitle << " : " << fName << endl; cout << "----" << endl; cout << "---- Field type : constant" << endl; cout << "----" << endl; cout << "---- Field regions : " << endl; cout << "---- x = " << setw(4) << fXmin << " to " << setw(4) << fXmax << " cm" << endl; cout << "---- y = " << setw(4) << fYmin << " to " << setw(4) << fYmax << " cm" << endl; cout << "---- z = " << setw(4) << fZmin << " to " << setw(4) << fZmax << " cm" << endl; cout.precision(4); cout << "---- B = ( " << fBx << ", " << fBy << ", " << fBz << " ) kG" << endl; cout << "======================================================" << endl; } // ------------------------------------------------------------------------- // --------- Fill the parameters -------------------------------------------- void FairConstField::FillParContainer() { TString MapName=GetName(); // cout << "FairConstField::FillParContainer() " << endl; FairRun* fRun=FairRun::Instance(); FairRuntimeDb* rtdb=fRun->GetRuntimeDb(); Bool_t kParameterMerged=kTRUE; FairConstPar* Par = (FairConstPar*) rtdb->getContainer("FairConstPar"); Par->SetParameters(this); Par->setInputVersion(fRun->GetRunId(),1); Par->setChanged(); } ClassImp(FairConstField)