Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4UnitsTable.cc File Reference
#include <iomanip>
#include <sstream>
#include "G4UnitsTable.hh"
#include "G4SystemOfUnits.hh"

Go to the source code of this file.

Functions

std::ostream & operator<< (std::ostream &flux, G4BestUnit a)
 

Function Documentation

◆ operator<<()

std::ostream & operator<< ( std::ostream &  flux,
G4BestUnit  a 
)

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< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:60
std::vector< G4UnitDefinition * > G4UnitsContainer
static G4UnitsTable & GetUnitsTable()
#define DBL_MIN
Definition: templates.hh:75
#define DBL_MAX
Definition: templates.hh:83