Geant4 11.1.1
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, const G4BestUnit &a)
 

Function Documentation

◆ operator<<()

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

Definition at line 588 of file G4UnitsTable.cc.

589{
591 G4UnitsContainer& List = theUnitsTable[a.IndexOfCategory]->GetUnitsList();
592 G4int len = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen();
593
594 G4long ksup(-1), kinf(-1);
595 G4double umax(0.), umin(DBL_MAX);
596 G4double rsup(DBL_MAX), rinf(0.);
597
598 // for a ThreeVector, choose the best unit for the biggest value
599 G4double value =
600 std::max(std::max(std::fabs(a.Value[0]), std::fabs(a.Value[1])),
601 std::fabs(a.Value[2]));
602
603 //special treatement for Energy.
604 if ((a.Category == "Energy") && (value == 0.)) {
605 for (G4int j = 0; j < a.nbOfVals; ++j) {
606 flux << a.Value[j] << " ";
607 }
608 std::ios::fmtflags oldform = flux.flags();
609 flux.setf(std::ios::left, std::ios::adjustfield);
610 flux << std::setw(len) << "eV";
611 flux.flags(oldform);
612 return flux;
613 }
614
615 //here, value != 0.
616 for(std::size_t k = 0; k < List.size(); ++k)
617 {
618 G4double unit = List[k]->GetValue();
619 if(!(value != DBL_MAX))
620 {
621 if(unit > umax)
622 {
623 umax = unit;
624 ksup = k;
625 }
626 }
627 else if(value <= DBL_MIN)
628 {
629 if(unit < umin)
630 {
631 umin = unit;
632 kinf = k;
633 }
634 }
635 else
636 {
637 G4double ratio = value / unit;
638 if((ratio >= 1.) && (ratio < rsup))
639 {
640 rsup = ratio;
641 ksup = k;
642 }
643 if((ratio < 1.) && (ratio > rinf))
644 {
645 rinf = ratio;
646 kinf = k;
647 }
648 }
649 }
650
651 G4long index = ksup;
652 if(index == -1)
653 {
654 index = kinf;
655 }
656 if(index == -1)
657 {
658 index = 0;
659 }
660
661 for(G4int j = 0; j < a.nbOfVals; ++j)
662 {
663 flux << a.Value[j] / (List[index]->GetValue()) << " ";
664 }
665
666 std::ios::fmtflags oldform = flux.flags();
667
668 flux.setf(std::ios::left, std::ios::adjustfield);
669 flux << std::setw(len) << List[index]->GetSymbol();
670 flux.flags(oldform);
671
672 return flux;
673}
double G4double
Definition: G4Types.hh:83
long G4long
Definition: G4Types.hh:87
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