Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4BestUnit Class Reference

#include <G4UnitsTable.hh>

Public Member Functions

 G4BestUnit (G4double internalValue, const G4String &category)
 
 G4BestUnit (const G4ThreeVector &internalValue, const G4String &category)
 
 ~G4BestUnit ()
 
G4doubleGetValue ()
 
const G4StringGetCategory () const
 
size_t GetIndexOfCategory () const
 
 operator G4String () const
 

Friends

std::ostream & operator<< (std::ostream &, G4BestUnit VU)
 

Detailed Description

Definition at line 148 of file G4UnitsTable.hh.

Constructor & Destructor Documentation

◆ G4BestUnit() [1/2]

G4BestUnit::G4BestUnit ( G4double  internalValue,
const G4String category 
)

Definition at line 416 of file G4UnitsTable.cc.

417 : nbOfVals(1)
418{
419 // find the category
421 size_t nbCat = theUnitsTable.size();
422 size_t i = 0;
423 while ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) { i++; }
424 if (i == nbCat)
425 {
426 G4cout << " G4BestUnit: the category " << category
427 << " does not exist !!" << G4endl;
428 G4Exception("G4BestUnit::G4BestUnit()", "InvalidCall",
429 FatalException, "Missing unit category !") ;
430 }
431 //
432 Value[0] = value;
433 Value[1] = 0.;
434 Value[2] = 0.;
435 IndexOfCategory = i;
436}
@ FatalException
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:60
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
static G4UnitsTable & GetUnitsTable()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41

◆ G4BestUnit() [2/2]

G4BestUnit::G4BestUnit ( const G4ThreeVector internalValue,
const G4String category 
)

Definition at line 440 of file G4UnitsTable.cc.

441 : nbOfVals(3)
442{
443 // find the category
445 size_t nbCat = theUnitsTable.size();
446 size_t i = 0;
447 while ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) { i++; }
448 if (i == nbCat)
449 {
450 G4cerr << " G4BestUnit: the category " << category
451 << " does not exist." << G4endl;
452 G4Exception("G4BestUnit::G4BestUnit()", "InvalidCall",
453 FatalException, "Missing unit category !") ;
454 }
455 //
456 Value[0] = value.x();
457 Value[1] = value.y();
458 Value[2] = value.z();
459 IndexOfCategory = i;
460}
G4DLLIMPORT std::ostream G4cerr

◆ ~G4BestUnit()

G4BestUnit::~G4BestUnit ( )

Definition at line 463 of file G4UnitsTable.cc.

464{}

Member Function Documentation

◆ GetCategory()

const G4String & G4BestUnit::GetCategory ( ) const
inline

◆ GetIndexOfCategory()

size_t G4BestUnit::GetIndexOfCategory ( ) const
inline

◆ GetValue()

G4double * G4BestUnit::GetValue ( )
inline

◆ operator G4String()

G4BestUnit::operator G4String ( ) const

Definition at line 468 of file G4UnitsTable.cc.

469{
470 std::ostringstream oss;
471 oss << *this;
472 return oss.str();
473}

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  flux,
G4BestUnit  VU 
)
friend

Definition at line 477 of file G4UnitsTable.cc.

478{
480 G4UnitsContainer& List = theUnitsTable[a.IndexOfCategory]
481 ->GetUnitsList();
482 G4int len = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen();
483
484 G4int ksup(-1), kinf(-1);
485 G4double umax(0.), umin(DBL_MAX);
486 G4double rsup(DBL_MAX), rinf(0.);
487
488 //for a ThreeVector, choose the best unit for the biggest value
489 G4double value = std::max(std::max(std::fabs(a.Value[0]),
490 std::fabs(a.Value[1])),
491 std::fabs(a.Value[2]));
492
493 for (size_t k=0; k<List.size(); k++)
494 {
495 G4double unit = List[k]->GetValue();
496 if (!(value!=DBL_MAX))
497 {if(unit>umax) {umax=unit; ksup=k;}}
498 else if (value<=DBL_MIN)
499 {if(unit<umin) {umin=unit; kinf=k;}}
500 else
501 {
502 G4double ratio = value/unit;
503 if ((ratio>=1.)&&(ratio<rsup)) {rsup=ratio; ksup=k;}
504 if ((ratio< 1.)&&(ratio>rinf)) {rinf=ratio; kinf=k;}
505 }
506 }
507
508 G4int index=ksup;
509 if(index==-1) { index=kinf; }
510 if(index==-1) { index=0; }
511
512 for (G4int j=0; j<a.nbOfVals; j++)
513 { flux << a.Value[j]/(List[index]->GetValue()) << " "; }
514
515 std::ios::fmtflags oldform = flux.flags();
516
517 flux.setf(std::ios::left,std::ios::adjustfield);
518 flux << std::setw(len) << List[index]->GetSymbol();
519 flux.flags(oldform);
520
521 return flux;
522}
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
std::vector< G4UnitDefinition * > G4UnitsContainer
#define DBL_MIN
Definition: templates.hh:75
#define DBL_MAX
Definition: templates.hh:83

The documentation for this class was generated from the following files: