| [1199] | 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 7 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 9 | // * include a list of copyright holders. *
|
|---|
| 10 | // * *
|
|---|
| 11 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 12 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 13 | // * work make any representation or warranty, express or implied, *
|
|---|
| 14 | // * regarding this software system or assume any liability for its *
|
|---|
| 15 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 16 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 17 | // * *
|
|---|
| 18 | // * This code implementation is the result of the scientific and *
|
|---|
| 19 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 20 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 21 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 22 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 23 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 24 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | //
|
|---|
| 27 | // $Id: G4UnitsTableTest.cc,v 1.8 2006/06/29 19:04:51 gunter Exp $
|
|---|
| 28 | //
|
|---|
| 29 | // ----------------------------------------------------------------------
|
|---|
| 30 | #include "G4ios.hh"
|
|---|
| 31 | #include "globals.hh"
|
|---|
| 32 | #include "G4ThreeVector.hh"
|
|---|
| 33 | #include "G4UnitsTable.hh"
|
|---|
| 34 |
|
|---|
| 35 | #include <iomanip>
|
|---|
| 36 |
|
|---|
| 37 | int main()
|
|---|
| 38 | {
|
|---|
| 39 | //
|
|---|
| 40 | // test the UnitsTable classes
|
|---|
| 41 | //
|
|---|
| 42 | // Build the Table of units
|
|---|
| 43 | //
|
|---|
| 44 | G4UnitDefinition::BuildUnitsTable();
|
|---|
| 45 | G4UnitDefinition::PrintUnitsTable();
|
|---|
| 46 |
|
|---|
| 47 | // Get internal value of an unit
|
|---|
| 48 | //
|
|---|
| 49 | G4cout << "\n \t G4UnitDefinition::GetValueOf('Unit') \n";
|
|---|
| 50 |
|
|---|
| 51 | G4cout << " meter = " << G4UnitDefinition::GetValueOf("meter") << G4endl;
|
|---|
| 52 | G4cout << " cm = " << G4UnitDefinition::GetValueOf("cm") << G4endl;
|
|---|
| 53 | G4cout << " joule = " << G4UnitDefinition::GetValueOf("J") << G4endl;
|
|---|
| 54 |
|
|---|
| 55 | // Get category of an unit
|
|---|
| 56 | //
|
|---|
| 57 | G4cout << "\n \t G4UnitDefinition::GetCategory('Unit') \n";
|
|---|
| 58 |
|
|---|
| 59 | G4cout << " meter is " << G4UnitDefinition::GetCategory("m") << G4endl;
|
|---|
| 60 | G4cout << " g is " << G4UnitDefinition::GetCategory("gram") << G4endl;
|
|---|
| 61 | G4cout << " joule is " << G4UnitDefinition::GetCategory("J") << G4endl;
|
|---|
| 62 | G4cout << " ns is " << G4UnitDefinition::GetCategory("ns") << G4endl;
|
|---|
| 63 |
|
|---|
| 64 | // Automatic conversion on output of a physical quantity
|
|---|
| 65 | //
|
|---|
| 66 | G4cout << "\n \t G4BestUnit \n";
|
|---|
| 67 | G4cout.precision(3);
|
|---|
| 68 |
|
|---|
| 69 | G4cout << " a = " << std::setw(4) << G4BestUnit (0.5*GeV ,"Energy") << G4endl;
|
|---|
| 70 | G4cout << " b = " << std::setw(4) << G4BestUnit (0.15*MeV,"Energy") << G4endl;
|
|---|
| 71 | G4cout << " c = " << std::setw(4) << G4BestUnit (4000*MeV,"Energy") << G4endl;
|
|---|
| 72 |
|
|---|
| 73 | G4double x = -1000.*cm;
|
|---|
| 74 | G4BestUnit d(x,"Length"); G4cout << " x = " << d << G4endl;
|
|---|
| 75 | G4BestUnit e(2e40*m,"Length"); G4cout << " e = " << e << G4endl;
|
|---|
| 76 | G4BestUnit f(DBL_MAX ,"Energy"); G4cout << " f = " << f << G4endl;
|
|---|
| 77 | G4BestUnit h(0.,"Magnetic flux density"); G4cout << " h = " << h << G4endl;
|
|---|
| 78 |
|
|---|
| 79 | G4ThreeVector point(2*mm, 3*cm, 1*m);
|
|---|
| 80 | G4ThreeVector momen(3*MeV, 2*keV, 0.);
|
|---|
| 81 | G4cout << std::setw(6) << G4BestUnit (point, "Length") << G4endl;
|
|---|
| 82 | G4cout << std::setw(6) << G4BestUnit (momen, "Energy") << G4endl;
|
|---|
| 83 |
|
|---|
| 84 | // Define new units
|
|---|
| 85 | //
|
|---|
| 86 | new G4UnitDefinition("kg/m3","kg/m3","Volumic Mass",kg/m3);
|
|---|
| 87 | new G4UnitDefinition("g/cm3","g/cm3","Volumic Mass",g/cm3);
|
|---|
| 88 |
|
|---|
| 89 | G4double rho = 14.*mg/mm3;
|
|---|
| 90 | G4cout << " rho = " << G4BestUnit (rho,"Volumic Mass") << G4endl;
|
|---|
| 91 |
|
|---|
| 92 | new G4UnitDefinition("g/cm2","g/cm2","Depth",g/cm2);
|
|---|
| 93 |
|
|---|
| 94 | //
|
|---|
| 95 | // G4UnitDefinition::PrintUnitsTable();
|
|---|
| 96 |
|
|---|
| 97 | return 0;
|
|---|
| 98 | }
|
|---|