Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // 27 // 27 // 28 // G4PSTrackLength 28 // G4PSTrackLength 29 #include "G4PSTrackLength.hh" 29 #include "G4PSTrackLength.hh" 30 #include "G4SystemOfUnits.hh" 30 #include "G4SystemOfUnits.hh" 31 #include "G4UnitsTable.hh" 31 #include "G4UnitsTable.hh" 32 ////////////////////////////////////////////// 32 //////////////////////////////////////////////////////////////////////////////// 33 // (Description) 33 // (Description) 34 // This is a primitive scorer class for scor 34 // This is a primitive scorer class for scoring sum of track length. 35 // 35 // 36 // 36 // 37 // Created: 2007-02-02 Tsukasa ASO, Akinori K 37 // Created: 2007-02-02 Tsukasa ASO, Akinori Kimura. 38 // 2010-07-22 Introduce Unit specifi 38 // 2010-07-22 Introduce Unit specification. 39 // 2011-09-09 Modify comment in Prin 39 // 2011-09-09 Modify comment in PrintAll(). 40 // 40 // 41 ////////////////////////////////////////////// 41 /////////////////////////////////////////////////////////////////////////////// 42 42 43 G4PSTrackLength::G4PSTrackLength(const G4Strin << 43 G4PSTrackLength::G4PSTrackLength(G4String name, G4int depth) 44 : G4PSTrackLength(name, "mm", depth) << 44 : G4VPrimitiveScorer(name, depth) 45 {} << 45 , HCID(-1) >> 46 , EvtMap(0) >> 47 , weighted(false) >> 48 , multiplyKinE(false) >> 49 , divideByVelocity(false) >> 50 { >> 51 DefineUnitAndCategory(); >> 52 SetUnit("mm"); >> 53 } 46 54 47 G4PSTrackLength::G4PSTrackLength(const G4Strin << 55 G4PSTrackLength::G4PSTrackLength(G4String name, const G4String& unit, 48 G4int depth) 56 G4int depth) 49 : G4VPrimitiveScorer(name, depth) 57 : G4VPrimitiveScorer(name, depth) 50 , HCID(-1) 58 , HCID(-1) 51 , EvtMap(nullptr) << 59 , EvtMap(0) 52 , weighted(false) 60 , weighted(false) 53 , multiplyKinE(false) 61 , multiplyKinE(false) 54 , divideByVelocity(false) 62 , divideByVelocity(false) 55 { 63 { 56 DefineUnitAndCategory(); 64 DefineUnitAndCategory(); 57 SetUnit(unit); 65 SetUnit(unit); 58 } 66 } 59 67 >> 68 G4PSTrackLength::~G4PSTrackLength() { ; } >> 69 60 void G4PSTrackLength::MultiplyKineticEnergy(G4 70 void G4PSTrackLength::MultiplyKineticEnergy(G4bool flg) 61 { 71 { 62 multiplyKinE = flg; 72 multiplyKinE = flg; 63 // Default unit is set according to flags. 73 // Default unit is set according to flags. 64 SetUnit(""); 74 SetUnit(""); 65 } 75 } 66 76 67 void G4PSTrackLength::DivideByVelocity(G4bool 77 void G4PSTrackLength::DivideByVelocity(G4bool flg) 68 { 78 { 69 divideByVelocity = flg; 79 divideByVelocity = flg; 70 // Default unit is set according to flags. 80 // Default unit is set according to flags. 71 SetUnit(""); 81 SetUnit(""); 72 } 82 } 73 83 74 G4bool G4PSTrackLength::ProcessHits(G4Step* aS 84 G4bool G4PSTrackLength::ProcessHits(G4Step* aStep, G4TouchableHistory*) 75 { 85 { 76 G4double trklength = aStep->GetStepLength(); 86 G4double trklength = aStep->GetStepLength(); 77 if(trklength == 0.) 87 if(trklength == 0.) 78 return false; << 88 return FALSE; 79 if(weighted) 89 if(weighted) 80 trklength *= aStep->GetPreStepPoint()->Get 90 trklength *= aStep->GetPreStepPoint()->GetWeight(); 81 if(multiplyKinE) 91 if(multiplyKinE) 82 trklength *= aStep->GetPreStepPoint()->Get 92 trklength *= aStep->GetPreStepPoint()->GetKineticEnergy(); 83 if(divideByVelocity) 93 if(divideByVelocity) 84 trklength /= aStep->GetPreStepPoint()->Get 94 trklength /= aStep->GetPreStepPoint()->GetVelocity(); 85 G4int index = GetIndex(aStep); 95 G4int index = GetIndex(aStep); 86 EvtMap->add(index, trklength); 96 EvtMap->add(index, trklength); 87 return true; << 97 return TRUE; 88 } 98 } 89 99 90 void G4PSTrackLength::Initialize(G4HCofThisEve 100 void G4PSTrackLength::Initialize(G4HCofThisEvent* HCE) 91 { 101 { 92 EvtMap = new G4THitsMap<G4double>(detector-> 102 EvtMap = new G4THitsMap<G4double>(detector->GetName(), GetName()); 93 if(HCID < 0) 103 if(HCID < 0) 94 { 104 { 95 HCID = GetCollectionID(0); 105 HCID = GetCollectionID(0); 96 } 106 } 97 HCE->AddHitsCollection(HCID, (G4VHitsCollect 107 HCE->AddHitsCollection(HCID, (G4VHitsCollection*) EvtMap); 98 } 108 } 99 109 >> 110 void G4PSTrackLength::EndOfEvent(G4HCofThisEvent*) { ; } >> 111 100 void G4PSTrackLength::clear() { EvtMap->clear( 112 void G4PSTrackLength::clear() { EvtMap->clear(); } 101 113 >> 114 void G4PSTrackLength::DrawAll() { ; } >> 115 102 void G4PSTrackLength::PrintAll() 116 void G4PSTrackLength::PrintAll() 103 { 117 { 104 G4cout << " MultiFunctionalDet " << detecto 118 G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl; 105 G4cout << " PrimitiveScorer " << GetName() < 119 G4cout << " PrimitiveScorer " << GetName() << G4endl; 106 G4cout << " Number of entries " << EvtMap->e 120 G4cout << " Number of entries " << EvtMap->entries() << G4endl; 107 for(const auto& [copy, length] : *(EvtMap->G << 121 std::map<G4int, G4double*>::iterator itr = EvtMap->GetMap()->begin(); >> 122 for(; itr != EvtMap->GetMap()->end(); itr++) 108 { 123 { 109 G4cout << " copy no.: " << copy; << 124 G4cout << " copy no.: " << itr->first; 110 if(multiplyKinE) 125 if(multiplyKinE) 111 { 126 { 112 if(divideByVelocity) 127 if(divideByVelocity) 113 G4cout << " EnergyFlux: "; 128 G4cout << " EnergyFlux: "; 114 else 129 else 115 G4cout << " EnergyFlow: "; 130 G4cout << " EnergyFlow: "; 116 } 131 } 117 else 132 else 118 { 133 { 119 if(divideByVelocity) 134 if(divideByVelocity) 120 G4cout << " Time: "; 135 G4cout << " Time: "; 121 else 136 else 122 G4cout << " Length: "; 137 G4cout << " Length: "; 123 } 138 } 124 G4cout << *(length) / GetUnitValue() << " << 139 G4cout << *(itr->second) / GetUnitValue() << " [" << GetUnit() << "]"; 125 G4cout << G4endl; 140 G4cout << G4endl; 126 } 141 } 127 } 142 } 128 143 129 void G4PSTrackLength::SetUnit(const G4String& 144 void G4PSTrackLength::SetUnit(const G4String& unit) 130 { 145 { 131 if(multiplyKinE) 146 if(multiplyKinE) 132 { 147 { 133 if(divideByVelocity) 148 if(divideByVelocity) 134 { 149 { 135 if(unit.empty()) << 150 if(unit == "") 136 { 151 { 137 CheckAndSetUnit("MeV_second", "EnergyF 152 CheckAndSetUnit("MeV_second", "EnergyFlux"); 138 } 153 } 139 else 154 else 140 { 155 { 141 CheckAndSetUnit(unit, "EnergyFlux"); 156 CheckAndSetUnit(unit, "EnergyFlux"); 142 } 157 } 143 } 158 } 144 else 159 else 145 { 160 { 146 if(unit.empty()) << 161 if(unit == "") 147 { 162 { 148 CheckAndSetUnit("MeV_mm", "EnergyFlow" 163 CheckAndSetUnit("MeV_mm", "EnergyFlow"); 149 } 164 } 150 else 165 else 151 { 166 { 152 CheckAndSetUnit(unit, "EnergyFlow"); 167 CheckAndSetUnit(unit, "EnergyFlow"); 153 } 168 } 154 } 169 } 155 } 170 } 156 else 171 else 157 { 172 { 158 if(divideByVelocity) 173 if(divideByVelocity) 159 { 174 { 160 if(unit.empty()) << 175 if(unit == "") 161 { 176 { 162 CheckAndSetUnit("second", "Time"); 177 CheckAndSetUnit("second", "Time"); 163 } 178 } 164 else 179 else 165 { 180 { 166 CheckAndSetUnit(unit, "Time"); 181 CheckAndSetUnit(unit, "Time"); 167 } 182 } 168 } 183 } 169 else 184 else 170 { 185 { 171 if(unit.empty()) << 186 if(unit == "") 172 { 187 { 173 CheckAndSetUnit("mm", "Length"); 188 CheckAndSetUnit("mm", "Length"); 174 } 189 } 175 else 190 else 176 { 191 { 177 CheckAndSetUnit(unit, "Length"); 192 CheckAndSetUnit(unit, "Length"); 178 } 193 } 179 } 194 } 180 } 195 } 181 } 196 } 182 197 183 void G4PSTrackLength::DefineUnitAndCategory() 198 void G4PSTrackLength::DefineUnitAndCategory() 184 { 199 { 185 // EnergyFlux 200 // EnergyFlux 186 new G4UnitDefinition("eV_second", "eV_s", "E 201 new G4UnitDefinition("eV_second", "eV_s", "EnergyFlux", (eV * second)); 187 new G4UnitDefinition("keV_second", "keV_s", 202 new G4UnitDefinition("keV_second", "keV_s", "EnergyFlux", (keV * second)); 188 new G4UnitDefinition("MeV_second", "MeV_s", 203 new G4UnitDefinition("MeV_second", "MeV_s", "EnergyFlux", (MeV * second)); 189 new G4UnitDefinition("eV_millisecond", "eV_m 204 new G4UnitDefinition("eV_millisecond", "eV_ms", "EnergyFlux", (eV * ms)); 190 new G4UnitDefinition("keV_millisecond", "keV 205 new G4UnitDefinition("keV_millisecond", "keV_ms", "EnergyFlux", (keV * ms)); 191 new G4UnitDefinition("MeV_millisecond", "MeV 206 new G4UnitDefinition("MeV_millisecond", "MeV_ms", "EnergyFlux", (MeV * ms)); 192 // EnergyFlow 207 // EnergyFlow 193 new G4UnitDefinition("eV_millimeter", "eV_mm 208 new G4UnitDefinition("eV_millimeter", "eV_mm", "EnergyFlow", (eV * mm)); 194 new G4UnitDefinition("keV_millimeter", "keV_ 209 new G4UnitDefinition("keV_millimeter", "keV_mm", "EnergyFlow", (keV * mm)); 195 new G4UnitDefinition("MeV_millimeter", "MeV_ 210 new G4UnitDefinition("MeV_millimeter", "MeV_mm", "EnergyFlow", (MeV * mm)); 196 new G4UnitDefinition("eV_centimeter", "eV_cm 211 new G4UnitDefinition("eV_centimeter", "eV_cm", "EnergyFlow", (eV * cm)); 197 new G4UnitDefinition("keV_centimeter", "keV_ 212 new G4UnitDefinition("keV_centimeter", "keV_cm", "EnergyFlow", (keV * cm)); 198 new G4UnitDefinition("MeV_centimeter", "MeV_ 213 new G4UnitDefinition("MeV_centimeter", "MeV_cm", "EnergyFlow", (MeV * cm)); 199 new G4UnitDefinition("eV_meter", "eV_m", "En 214 new G4UnitDefinition("eV_meter", "eV_m", "EnergyFlow", (eV * m)); 200 new G4UnitDefinition("keV_meter", "keV_m", " 215 new G4UnitDefinition("keV_meter", "keV_m", "EnergyFlow", (keV * m)); 201 new G4UnitDefinition("MeV_meter", "MeV_m", " 216 new G4UnitDefinition("MeV_meter", "MeV_m", "EnergyFlow", (MeV * m)); 202 } 217 } 203 218