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),HCID(-1),EvtMap(0),weighted(false), 45 {} << 45 multiplyKinE(false),divideByVelocity(false) 46 << 47 G4PSTrackLength::G4PSTrackLength(const G4Strin << 48 G4int depth) << 49 : G4VPrimitiveScorer(name, depth) << 50 , HCID(-1) << 51 , EvtMap(nullptr) << 52 , weighted(false) << 53 , multiplyKinE(false) << 54 , divideByVelocity(false) << 55 { 46 { 56 DefineUnitAndCategory(); << 47 DefineUnitAndCategory(); 57 SetUnit(unit); << 48 SetUnit("mm"); 58 } 49 } 59 50 60 void G4PSTrackLength::MultiplyKineticEnergy(G4 << 51 G4PSTrackLength::G4PSTrackLength(G4String name, const G4String& unit, >> 52 G4int depth) >> 53 :G4VPrimitiveScorer(name,depth),HCID(-1),EvtMap(0),weighted(false), >> 54 multiplyKinE(false),divideByVelocity(false) 61 { 55 { 62 multiplyKinE = flg; << 56 DefineUnitAndCategory(); 63 // Default unit is set according to flags. << 57 SetUnit(unit); 64 SetUnit(""); << 58 } 65 } << 59 66 << 60 G4PSTrackLength::~G4PSTrackLength() 67 void G4PSTrackLength::DivideByVelocity(G4bool << 61 {;} 68 { << 62 69 divideByVelocity = flg; << 63 void G4PSTrackLength::MultiplyKineticEnergy(G4bool flg) 70 // Default unit is set according to flags. << 64 { 71 SetUnit(""); << 65 multiplyKinE = flg; 72 } << 66 // Default unit is set according to flags. 73 << 67 SetUnit(""); 74 G4bool G4PSTrackLength::ProcessHits(G4Step* aS << 68 } 75 { << 69 76 G4double trklength = aStep->GetStepLength(); << 70 void G4PSTrackLength::DivideByVelocity(G4bool flg) 77 if(trklength == 0.) << 71 { 78 return false; << 72 divideByVelocity = flg; 79 if(weighted) << 73 // Default unit is set according to flags. 80 trklength *= aStep->GetPreStepPoint()->Get << 74 SetUnit(""); 81 if(multiplyKinE) << 75 } 82 trklength *= aStep->GetPreStepPoint()->Get << 76 83 if(divideByVelocity) << 77 G4bool G4PSTrackLength::ProcessHits(G4Step* aStep,G4TouchableHistory*) 84 trklength /= aStep->GetPreStepPoint()->Get << 78 { 85 G4int index = GetIndex(aStep); << 79 G4double trklength = aStep->GetStepLength(); 86 EvtMap->add(index, trklength); << 80 if ( trklength == 0. ) return FALSE; 87 return true; << 81 if(weighted) trklength *= aStep->GetPreStepPoint()->GetWeight(); >> 82 if(multiplyKinE) trklength *= aStep->GetPreStepPoint()->GetKineticEnergy(); >> 83 if(divideByVelocity) trklength /= aStep->GetPreStepPoint()->GetVelocity(); >> 84 G4int index = GetIndex(aStep); >> 85 EvtMap->add(index,trklength); >> 86 return TRUE; 88 } 87 } 89 88 90 void G4PSTrackLength::Initialize(G4HCofThisEve 89 void G4PSTrackLength::Initialize(G4HCofThisEvent* HCE) 91 { 90 { 92 EvtMap = new G4THitsMap<G4double>(detector-> << 91 EvtMap = new G4THitsMap<G4double>(detector->GetName(),GetName()); 93 if(HCID < 0) << 92 if(HCID < 0) {HCID = GetCollectionID(0);} 94 { << 93 HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap); 95 HCID = GetCollectionID(0); << 94 } 96 } << 95 97 HCE->AddHitsCollection(HCID, (G4VHitsCollect << 96 void G4PSTrackLength::EndOfEvent(G4HCofThisEvent*) >> 97 {;} >> 98 >> 99 void G4PSTrackLength::clear(){ >> 100 EvtMap->clear(); 98 } 101 } 99 102 100 void G4PSTrackLength::clear() { EvtMap->clear( << 103 void G4PSTrackLength::DrawAll() >> 104 {;} 101 105 102 void G4PSTrackLength::PrintAll() 106 void G4PSTrackLength::PrintAll() 103 { 107 { 104 G4cout << " MultiFunctionalDet " << detecto 108 G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl; 105 G4cout << " PrimitiveScorer " << GetName() < 109 G4cout << " PrimitiveScorer " << GetName() << G4endl; 106 G4cout << " Number of entries " << EvtMap->e 110 G4cout << " Number of entries " << EvtMap->entries() << G4endl; 107 for(const auto& [copy, length] : *(EvtMap->G << 111 std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin(); 108 { << 112 for(; itr != EvtMap->GetMap()->end(); itr++) { 109 G4cout << " copy no.: " << copy; << 113 G4cout << " copy no.: " << itr->first ; 110 if(multiplyKinE) << 114 if ( multiplyKinE ){ 111 { << 115 if ( divideByVelocity ) G4cout << " EnergyFlux: "; 112 if(divideByVelocity) << 116 else G4cout << " EnergyFlow: "; 113 G4cout << " EnergyFlux: "; << 117 }else{ 114 else << 118 if ( divideByVelocity ) G4cout << " Time: "; 115 G4cout << " EnergyFlow: "; << 119 else G4cout << " Length: "; 116 } << 120 } 117 else << 121 G4cout << *(itr->second)/GetUnitValue() 118 { << 122 << " ["<< GetUnit() << "]"; 119 if(divideByVelocity) << 123 G4cout << G4endl; 120 G4cout << " Time: "; << 121 else << 122 G4cout << " Length: "; << 123 } << 124 G4cout << *(length) / GetUnitValue() << " << 125 G4cout << G4endl; << 126 } 124 } 127 } 125 } 128 126 129 void G4PSTrackLength::SetUnit(const G4String& 127 void G4PSTrackLength::SetUnit(const G4String& unit) 130 { 128 { 131 if(multiplyKinE) << 129 if ( multiplyKinE ){ 132 { << 130 if ( divideByVelocity ){ 133 if(divideByVelocity) << 131 if ( unit == "" ) { 134 { << 132 CheckAndSetUnit("MeV_second","EnergyFlux"); 135 if(unit.empty()) << 133 } else { 136 { << 134 CheckAndSetUnit(unit,"EnergyFlux"); 137 CheckAndSetUnit("MeV_second", "EnergyF << 135 } 138 } << 136 }else { 139 else << 137 if ( unit == "" ) { 140 { << 138 CheckAndSetUnit("MeV_mm","EnergyFlow"); 141 CheckAndSetUnit(unit, "EnergyFlux"); << 139 } else { 142 } << 140 CheckAndSetUnit(unit,"EnergyFlow"); 143 } << 141 } 144 else << 142 } 145 { << 143 }else { 146 if(unit.empty()) << 144 if ( divideByVelocity ){ 147 { << 145 if ( unit == "" ) { 148 CheckAndSetUnit("MeV_mm", "EnergyFlow" << 146 CheckAndSetUnit("second","Time"); 149 } << 147 } else { 150 else << 148 CheckAndSetUnit(unit,"Time"); 151 { << 149 } 152 CheckAndSetUnit(unit, "EnergyFlow"); << 150 }else { 153 } << 151 if ( unit == "") { 154 } << 152 CheckAndSetUnit("mm","Length"); 155 } << 153 } else { 156 else << 154 CheckAndSetUnit(unit,"Length"); 157 { << 155 } 158 if(divideByVelocity) << 156 } 159 { << 157 } 160 if(unit.empty()) << 158 } 161 { << 159 162 CheckAndSetUnit("second", "Time"); << 160 void G4PSTrackLength::DefineUnitAndCategory(){ 163 } << 161 // EnergyFlux 164 else << 162 new G4UnitDefinition("eV_second","eV_s","EnergyFlux",(eV*second)); 165 { << 163 new G4UnitDefinition("keV_second","keV_s","EnergyFlux",(keV*second)); 166 CheckAndSetUnit(unit, "Time"); << 164 new G4UnitDefinition("MeV_second","MeV_s","EnergyFlux",(MeV*second)); 167 } << 165 new G4UnitDefinition("eV_millisecond","eV_ms","EnergyFlux",(eV*ms)); 168 } << 166 new G4UnitDefinition("keV_millisecond","keV_ms","EnergyFlux",(keV*ms)); 169 else << 167 new G4UnitDefinition("MeV_millisecond","MeV_ms","EnergyFlux",(MeV*ms)); 170 { << 168 //EnergyFlow 171 if(unit.empty()) << 169 new G4UnitDefinition("eV_millimeter","eV_mm","EnergyFlow",(eV*mm)); 172 { << 170 new G4UnitDefinition("keV_millimeter","keV_mm","EnergyFlow",(keV*mm)); 173 CheckAndSetUnit("mm", "Length"); << 171 new G4UnitDefinition("MeV_millimeter","MeV_mm","EnergyFlow",(MeV*mm)); 174 } << 172 new G4UnitDefinition("eV_centimeter","eV_cm","EnergyFlow",(eV*cm)); 175 else << 173 new G4UnitDefinition("keV_centimeter","keV_cm","EnergyFlow",(keV*cm)); 176 { << 174 new G4UnitDefinition("MeV_centimeter","MeV_cm","EnergyFlow",(MeV*cm)); 177 CheckAndSetUnit(unit, "Length"); << 175 new G4UnitDefinition("eV_meter","eV_m","EnergyFlow",(eV*m)); 178 } << 176 new G4UnitDefinition("keV_meter","keV_m","EnergyFlow",(keV*m)); 179 } << 177 new G4UnitDefinition("MeV_meter","MeV_m","EnergyFlow",(MeV*m)); 180 } << 181 } 178 } 182 179 183 void G4PSTrackLength::DefineUnitAndCategory() << 180 184 { << 181 185 // EnergyFlux << 186 new G4UnitDefinition("eV_second", "eV_s", "E << 187 new G4UnitDefinition("keV_second", "keV_s", << 188 new G4UnitDefinition("MeV_second", "MeV_s", << 189 new G4UnitDefinition("eV_millisecond", "eV_m << 190 new G4UnitDefinition("keV_millisecond", "keV << 191 new G4UnitDefinition("MeV_millisecond", "MeV << 192 // EnergyFlow << 193 new G4UnitDefinition("eV_millimeter", "eV_mm << 194 new G4UnitDefinition("keV_millimeter", "keV_ << 195 new G4UnitDefinition("MeV_millimeter", "MeV_ << 196 new G4UnitDefinition("eV_centimeter", "eV_cm << 197 new G4UnitDefinition("keV_centimeter", "keV_ << 198 new G4UnitDefinition("MeV_centimeter", "MeV_ << 199 new G4UnitDefinition("eV_meter", "eV_m", "En << 200 new G4UnitDefinition("keV_meter", "keV_m", " << 201 new G4UnitDefinition("MeV_meter", "MeV_m", " << 202 } << 203 182