[831] | 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: G4WeightWindowStore.cc,v 1.5 2006/06/29 18:18:05 gunter Exp $ |
---|
[1058] | 28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $ |
---|
[831] | 29 | // |
---|
| 30 | // ---------------------------------------------------------------------- |
---|
| 31 | // GEANT 4 class source file |
---|
| 32 | // |
---|
| 33 | // G4WeightWindowStore |
---|
| 34 | // |
---|
| 35 | // ---------------------------------------------------------------------- |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | #include "G4WeightWindowStore.hh" |
---|
| 39 | #include "G4VPhysicalVolume.hh" |
---|
| 40 | #include "G4LogicalVolume.hh" |
---|
| 41 | #include "G4GeometryCellStepStream.hh" |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | G4WeightWindowStore:: |
---|
| 45 | G4WeightWindowStore(const G4VPhysicalVolume &worldvolume) : |
---|
| 46 | fWorldVolume(worldvolume), |
---|
| 47 | fGeneralUpperEnergyBounds(), |
---|
| 48 | fCellToUpEnBoundLoWePairsMap(), |
---|
| 49 | fCurrentIterator(fCellToUpEnBoundLoWePairsMap.end()) |
---|
| 50 | {} |
---|
| 51 | |
---|
| 52 | G4WeightWindowStore::~G4WeightWindowStore() |
---|
| 53 | {} |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | G4double G4WeightWindowStore::GetLowerWeitgh(const G4GeometryCell &gCell, |
---|
| 57 | G4double partEnergy) const |
---|
| 58 | { |
---|
| 59 | SetInternalIterator(gCell); |
---|
| 60 | if (fCurrentIterator == fCellToUpEnBoundLoWePairsMap.end()) { |
---|
| 61 | Error("GetLowerWitgh: Cell does not exist"); |
---|
| 62 | } |
---|
| 63 | G4UpperEnergyToLowerWeightMap upEnLoWeiPairs = |
---|
| 64 | fCurrentIterator->second; |
---|
| 65 | G4double lowerWeight = -1; |
---|
| 66 | G4bool found = false; |
---|
| 67 | for (G4UpperEnergyToLowerWeightMap::iterator it = |
---|
| 68 | upEnLoWeiPairs.begin(); it != upEnLoWeiPairs.end(); it++) { |
---|
| 69 | if (partEnergy < it->first) { |
---|
| 70 | lowerWeight = it->second; |
---|
| 71 | found = true; |
---|
| 72 | break; |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | if (!found) { |
---|
| 76 | G4cout << "energy: " << partEnergy << G4endl; |
---|
| 77 | Error("GetLowerWitgh: couldn't find lower weight bound"); |
---|
| 78 | } |
---|
| 79 | return lowerWeight; |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | void G4WeightWindowStore:: |
---|
| 85 | SetInternalIterator(const G4GeometryCell &gCell) const |
---|
| 86 | { |
---|
| 87 | fCurrentIterator = fCellToUpEnBoundLoWePairsMap.find(gCell); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | G4bool G4WeightWindowStore:: |
---|
| 91 | IsInWorld(const G4VPhysicalVolume &aVolume) const |
---|
| 92 | { |
---|
| 93 | G4bool isIn(true); |
---|
| 94 | if (!(aVolume == fWorldVolume)) { |
---|
| 95 | isIn = fWorldVolume.GetLogicalVolume()->IsAncestor(&aVolume); |
---|
| 96 | } |
---|
| 97 | return isIn; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | G4bool G4WeightWindowStore::IsKnown(const G4GeometryCell &gCell) const |
---|
| 102 | { |
---|
| 103 | G4bool inWorldKnown(IsInWorld(gCell.GetPhysicalVolume())); |
---|
| 104 | |
---|
| 105 | if ( inWorldKnown ) { |
---|
| 106 | SetInternalIterator(gCell); |
---|
| 107 | inWorldKnown = (fCurrentIterator!=fCellToUpEnBoundLoWePairsMap.end()); |
---|
| 108 | } |
---|
| 109 | return inWorldKnown; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | const G4VPhysicalVolume &G4WeightWindowStore::GetWorldVolume() const |
---|
| 114 | { |
---|
| 115 | return fWorldVolume; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | void G4WeightWindowStore:: |
---|
| 120 | AddLowerWeights(const G4GeometryCell & gCell, |
---|
| 121 | const std::vector<G4double> &lowerWeights) |
---|
| 122 | { |
---|
| 123 | if (fGeneralUpperEnergyBounds.empty()) { |
---|
| 124 | Error("AddLowerWeights: no general upper energy limits set"); |
---|
| 125 | } |
---|
| 126 | if (IsKnown(gCell)) { |
---|
| 127 | Error("AddLowerWeights: the cell is already in the store"); |
---|
| 128 | } |
---|
| 129 | if (lowerWeights.size() != fGeneralUpperEnergyBounds.size()) { |
---|
| 130 | Error("missmatch between number of lower weights and energy bounds"); |
---|
| 131 | } |
---|
| 132 | G4UpperEnergyToLowerWeightMap m; |
---|
| 133 | G4int i = 0; |
---|
| 134 | for (std::set<G4double, std::less<G4double> >::iterator it = |
---|
| 135 | fGeneralUpperEnergyBounds.begin(); |
---|
| 136 | it != fGeneralUpperEnergyBounds.end(); |
---|
| 137 | it++) { |
---|
| 138 | m[*it] = lowerWeights[i]; |
---|
| 139 | i++; |
---|
| 140 | } |
---|
| 141 | fCellToUpEnBoundLoWePairsMap[gCell] = m; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | void G4WeightWindowStore:: |
---|
| 146 | AddUpperEboundLowerWeightPairs(const G4GeometryCell &gCell, |
---|
| 147 | const G4UpperEnergyToLowerWeightMap& enWeMap) |
---|
| 148 | { |
---|
| 149 | if (IsKnown(gCell)) { |
---|
| 150 | Error("AddUpperEboundLowerWeightPairs: the cell is already in the store"); |
---|
| 151 | } |
---|
| 152 | if (IsKnown(gCell)) { |
---|
| 153 | Error("AddUpperEboundLowerWeightPairs: the cell is already in the store"); |
---|
| 154 | } |
---|
| 155 | fCellToUpEnBoundLoWePairsMap[gCell] = enWeMap; |
---|
| 156 | |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | void G4WeightWindowStore:: |
---|
| 161 | SetGeneralUpperEnergyBounds(const std::set<G4double, |
---|
| 162 | std::less<G4double> > &enBounds) |
---|
| 163 | { |
---|
| 164 | if (!fGeneralUpperEnergyBounds.empty()) { |
---|
| 165 | Error("SetGeneralUpperEnergyBounds: energy bounds already set"); |
---|
| 166 | } |
---|
| 167 | fGeneralUpperEnergyBounds = enBounds; |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | void G4WeightWindowStore::Error(const G4String &m) const |
---|
| 172 | { |
---|
| 173 | G4cerr << "ERROR - G4WeightWindowStore: " << m << G4endl; |
---|
| 174 | G4Exception("G4WeightWindowStore::Error()", |
---|
| 175 | "FatalException", FatalException, m); |
---|
| 176 | } |
---|