Geant4 10.7.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 "G4SystemOfUnits.hh"
#include "G4Threading.hh"
#include "G4UnitsTable.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 577 of file G4UnitsTable.cc.

578{
580 G4UnitsContainer& List = theUnitsTable[a.IndexOfCategory]->GetUnitsList();
581 G4int len = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen();
582
583 G4int ksup(-1), kinf(-1);
584 G4double umax(0.), umin(DBL_MAX);
585 G4double rsup(DBL_MAX), rinf(0.);
586
587 // for a ThreeVector, choose the best unit for the biggest value
588 G4double value =
589 std::max(std::max(std::fabs(a.Value[0]), std::fabs(a.Value[1])),
590 std::fabs(a.Value[2]));
591
592 for(std::size_t k = 0; k < List.size(); ++k)
593 {
594 G4double unit = List[k]->GetValue();
595 if(!(value != DBL_MAX))
596 {
597 if(unit > umax)
598 {
599 umax = unit;
600 ksup = k;
601 }
602 }
603 else if(value <= DBL_MIN)
604 {
605 if(unit < umin)
606 {
607 umin = unit;
608 kinf = k;
609 }
610 }
611 else
612 {
613 G4double ratio = value / unit;
614 if((ratio >= 1.) && (ratio < rsup))
615 {
616 rsup = ratio;
617 ksup = k;
618 }
619 if((ratio < 1.) && (ratio > rinf))
620 {
621 rinf = ratio;
622 kinf = k;
623 }
624 }
625 }
626
627 G4int index = ksup;
628 if(index == -1)
629 {
630 index = kinf;
631 }
632 if(index == -1)
633 {
634 index = 0;
635 }
636
637 for(G4int j = 0; j < a.nbOfVals; ++j)
638 {
639 flux << a.Value[j] / (List[index]->GetValue()) << " ";
640 }
641
642 std::ios::fmtflags oldform = flux.flags();
643
644 flux.setf(std::ios::left, std::ios::adjustfield);
645 flux << std::setw(len) << List[index]->GetSymbol();
646 flux.flags(oldform);
647
648 return flux;
649}
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
std::vector< G4UnitDefinition * > G4UnitsContainer
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:68
static G4UnitsTable & GetUnitsTable()
#define DBL_MIN
Definition: templates.hh:54
#define DBL_MAX
Definition: templates.hh:62