00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "G4WeightWindowStore.hh"
00038 #include "G4VPhysicalVolume.hh"
00039 #include "G4LogicalVolume.hh"
00040 #include "G4GeometryCellStepStream.hh"
00041
00042
00043 G4WeightWindowStore::
00044 G4WeightWindowStore(const G4VPhysicalVolume &worldvolume) :
00045 fWorldVolume(worldvolume),
00046 fGeneralUpperEnergyBounds(),
00047 fCellToUpEnBoundLoWePairsMap(),
00048 fCurrentIterator(fCellToUpEnBoundLoWePairsMap.end())
00049 {}
00050
00051 G4WeightWindowStore::~G4WeightWindowStore()
00052 {}
00053
00054
00055 G4double G4WeightWindowStore::GetLowerWeight(const G4GeometryCell &gCell,
00056 G4double partEnergy) const
00057 {
00058 SetInternalIterator(gCell);
00059 G4GeometryCellWeight::const_iterator gCellIterator = fCurrentIterator;
00060 if (gCellIterator == fCellToUpEnBoundLoWePairsMap.end()) {
00061 Error("GetLowerWitgh() - Cell does not exist!");
00062 return 0.;
00063 }
00064 G4UpperEnergyToLowerWeightMap upEnLoWeiPairs =
00065 fCurrentIterator->second;
00066 G4double lowerWeight = -1;
00067 G4bool found = false;
00068 for (G4UpperEnergyToLowerWeightMap::iterator it =
00069 upEnLoWeiPairs.begin(); it != upEnLoWeiPairs.end(); it++) {
00070 if (partEnergy < it->first) {
00071 lowerWeight = it->second;
00072 found = true;
00073 break;
00074 }
00075 }
00076 if (!found) {
00077 std::ostringstream err_mess;
00078 err_mess << "GetLowerWitgh() - Couldn't find lower weight bound." << G4endl
00079 << "Energy: " << partEnergy << ".";
00080 Error(err_mess.str());
00081 }
00082 return lowerWeight;
00083
00084
00085 }
00086
00087 void G4WeightWindowStore::
00088 SetInternalIterator(const G4GeometryCell &gCell) const
00089 {
00090 fCurrentIterator = fCellToUpEnBoundLoWePairsMap.find(gCell);
00091 }
00092
00093 G4bool G4WeightWindowStore::
00094 IsInWorld(const G4VPhysicalVolume &aVolume) const
00095 {
00096 G4bool isIn(true);
00097 if (!(aVolume == fWorldVolume)) {
00098 isIn = fWorldVolume.GetLogicalVolume()->IsAncestor(&aVolume);
00099 }
00100 return isIn;
00101 }
00102
00103
00104 G4bool G4WeightWindowStore::IsKnown(const G4GeometryCell &gCell) const
00105 {
00106 G4bool inWorldKnown(IsInWorld(gCell.GetPhysicalVolume()));
00107
00108 if ( inWorldKnown ) {
00109 SetInternalIterator(gCell);
00110 inWorldKnown = (fCurrentIterator!=fCellToUpEnBoundLoWePairsMap.end());
00111 }
00112 return inWorldKnown;
00113 }
00114
00115
00116 const G4VPhysicalVolume &G4WeightWindowStore::GetWorldVolume() const
00117 {
00118 return fWorldVolume;
00119 }
00120
00121
00122 void G4WeightWindowStore::
00123 AddLowerWeights(const G4GeometryCell & gCell,
00124 const std::vector<G4double> &lowerWeights)
00125 {
00126 if (fGeneralUpperEnergyBounds.empty()) {
00127 Error("AddLowerWeights() - No general upper energy limits set!");
00128 }
00129 if (IsKnown(gCell)) {
00130 Error("AddLowerWeights() - Cell already in the store.");
00131 }
00132 if (lowerWeights.size() != fGeneralUpperEnergyBounds.size()) {
00133 std::ostringstream err_mess;
00134 err_mess << "AddLowerWeights() - Mismatch between "
00135 << "number of lower weights (" << lowerWeights.size()
00136 << ") and energy bounds (" << fGeneralUpperEnergyBounds.size()
00137 << ")!";
00138 Error(err_mess.str());
00139 }
00140 G4UpperEnergyToLowerWeightMap map;
00141 G4int i = 0;
00142 for (std::set<G4double, std::less<G4double> >::iterator it =
00143 fGeneralUpperEnergyBounds.begin();
00144 it != fGeneralUpperEnergyBounds.end();
00145 it++) {
00146 map[*it] = lowerWeights[i];
00147 i++;
00148 }
00149 fCellToUpEnBoundLoWePairsMap[gCell] = map;
00150 }
00151
00152
00153 void G4WeightWindowStore::
00154 AddUpperEboundLowerWeightPairs(const G4GeometryCell &gCell,
00155 const G4UpperEnergyToLowerWeightMap& enWeMap)
00156 {
00157 if (IsKnown(gCell)) {
00158 Error("AddUpperEboundLowerWeightPairs() - Cell already in the store.");
00159 }
00160 if (IsKnown(gCell)) {
00161 Error("AddUpperEboundLowerWeightPairs() - Cell already in the store.");
00162 }
00163 fCellToUpEnBoundLoWePairsMap[gCell] = enWeMap;
00164
00165 }
00166
00167
00168 void G4WeightWindowStore::
00169 SetGeneralUpperEnergyBounds(const std::set<G4double,
00170 std::less<G4double> > &enBounds)
00171 {
00172 if (!fGeneralUpperEnergyBounds.empty()) {
00173 Error("SetGeneralUpperEnergyBounds() - Energy bounds already set.");
00174 }
00175 fGeneralUpperEnergyBounds = enBounds;
00176 }
00177
00178
00179 void G4WeightWindowStore::Error(const G4String &msg) const
00180 {
00181 G4Exception("G4WeightWindowStore::Error()",
00182 "GeomBias0002", FatalException, msg);
00183 }