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 // $Id: G4PSTrackLength.cc 81087 2014-05-20 15:44:27Z gcosmo $ 27 // 28 // 28 // G4PSTrackLength 29 // G4PSTrackLength 29 #include "G4PSTrackLength.hh" 30 #include "G4PSTrackLength.hh" 30 #include "G4SystemOfUnits.hh" 31 #include "G4SystemOfUnits.hh" 31 #include "G4UnitsTable.hh" 32 #include "G4UnitsTable.hh" 32 ////////////////////////////////////////////// 33 //////////////////////////////////////////////////////////////////////////////// 33 // (Description) 34 // (Description) 34 // This is a primitive scorer class for scor 35 // This is a primitive scorer class for scoring sum of track length. 35 // << 36 // 36 // 37 // 37 // Created: 2007-02-02 Tsukasa ASO, Akinori K 38 // Created: 2007-02-02 Tsukasa ASO, Akinori Kimura. 38 // 2010-07-22 Introduce Unit specifi 39 // 2010-07-22 Introduce Unit specification. 39 // 2011-09-09 Modify comment in Prin 40 // 2011-09-09 Modify comment in PrintAll(). 40 // << 41 // 41 ////////////////////////////////////////////// 42 /////////////////////////////////////////////////////////////////////////////// 42 43 43 G4PSTrackLength::G4PSTrackLength(const G4Strin << 44 G4PSTrackLength::G4PSTrackLength(G4String name, G4int depth) 44 : G4PSTrackLength(name, "mm", depth) << 45 :G4VPrimitiveScorer(name,depth),HCID(-1),EvtMap(0),weighted(false), 45 {} << 46 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 { 47 { 56 DefineUnitAndCategory(); << 48 DefineUnitAndCategory(); 57 SetUnit(unit); << 49 SetUnit("mm"); 58 } 50 } 59 51 60 void G4PSTrackLength::MultiplyKineticEnergy(G4 << 52 G4PSTrackLength::G4PSTrackLength(G4String name, const G4String& unit, >> 53 G4int depth) >> 54 :G4VPrimitiveScorer(name,depth),HCID(-1),EvtMap(0),weighted(false), >> 55 multiplyKinE(false),divideByVelocity(false) 61 { 56 { 62 multiplyKinE = flg; << 57 DefineUnitAndCategory(); 63 // Default unit is set according to flags. << 58 SetUnit(unit); 64 SetUnit(""); << 59 } 65 } << 60 66 << 61 G4PSTrackLength::~G4PSTrackLength() 67 void G4PSTrackLength::DivideByVelocity(G4bool << 62 {;} 68 { << 63 69 divideByVelocity = flg; << 64 void G4PSTrackLength::MultiplyKineticEnergy(G4bool flg) 70 // Default unit is set according to flags. << 65 { 71 SetUnit(""); << 66 multiplyKinE = flg; 72 } << 67 // Default unit is set according to flags. 73 << 68 SetUnit(""); 74 G4bool G4PSTrackLength::ProcessHits(G4Step* aS << 69 } 75 { << 70 76 G4double trklength = aStep->GetStepLength(); << 71 void G4PSTrackLength::DivideByVelocity(G4bool flg) 77 if(trklength == 0.) << 72 { 78 return false; << 73 divideByVelocity = flg; 79 if(weighted) << 74 // Default unit is set according to flags. 80 trklength *= aStep->GetPreStepPoint()->Get << 75 SetUnit(""); 81 if(multiplyKinE) << 76 } 82 trklength *= aStep->GetPreStepPoint()->Get << 77 83 if(divideByVelocity) << 78 G4bool G4PSTrackLength::ProcessHits(G4Step* aStep,G4TouchableHistory*) 84 trklength /= aStep->GetPreStepPoint()->Get << 79 { 85 G4int index = GetIndex(aStep); << 80 G4double trklength = aStep->GetStepLength(); 86 EvtMap->add(index, trklength); << 81 if ( trklength == 0. ) return FALSE; 87 return true; << 82 if(weighted) trklength *= aStep->GetPreStepPoint()->GetWeight(); >> 83 if(multiplyKinE) trklength *= aStep->GetPreStepPoint()->GetKineticEnergy(); >> 84 if(divideByVelocity) trklength /= aStep->GetPreStepPoint()->GetVelocity(); >> 85 G4int index = GetIndex(aStep); >> 86 EvtMap->add(index,trklength); >> 87 return TRUE; 88 } 88 } 89 89 90 void G4PSTrackLength::Initialize(G4HCofThisEve 90 void G4PSTrackLength::Initialize(G4HCofThisEvent* HCE) 91 { 91 { 92 EvtMap = new G4THitsMap<G4double>(detector-> << 92 EvtMap = new G4THitsMap<G4double>(detector->GetName(),GetName()); 93 if(HCID < 0) << 93 if(HCID < 0) {HCID = GetCollectionID(0);} 94 { << 94 HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap); 95 HCID = GetCollectionID(0); << 95 } 96 } << 96 97 HCE->AddHitsCollection(HCID, (G4VHitsCollect << 97 void G4PSTrackLength::EndOfEvent(G4HCofThisEvent*) >> 98 {;} >> 99 >> 100 void G4PSTrackLength::clear(){ >> 101 EvtMap->clear(); 98 } 102 } 99 103 100 void G4PSTrackLength::clear() { EvtMap->clear( << 104 void G4PSTrackLength::DrawAll() >> 105 {;} 101 106 102 void G4PSTrackLength::PrintAll() 107 void G4PSTrackLength::PrintAll() 103 { 108 { 104 G4cout << " MultiFunctionalDet " << detecto 109 G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl; 105 G4cout << " PrimitiveScorer " << GetName() < 110 G4cout << " PrimitiveScorer " << GetName() << G4endl; 106 G4cout << " Number of entries " << EvtMap->e 111 G4cout << " Number of entries " << EvtMap->entries() << G4endl; 107 for(const auto& [copy, length] : *(EvtMap->G << 112 std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin(); 108 { << 113 for(; itr != EvtMap->GetMap()->end(); itr++) { 109 G4cout << " copy no.: " << copy; << 114 G4cout << " copy no.: " << itr->first ; 110 if(multiplyKinE) << 115 if ( multiplyKinE ){ 111 { << 116 if ( divideByVelocity ) G4cout << " EnergyFlux: "; 112 if(divideByVelocity) << 117 else G4cout << " EnergyFlow: "; 113 G4cout << " EnergyFlux: "; << 118 }else{ 114 else << 119 if ( divideByVelocity ) G4cout << " Time: "; 115 G4cout << " EnergyFlow: "; << 120 else G4cout << " Length: "; 116 } << 121 } 117 else << 122 G4cout << *(itr->second)/GetUnitValue() 118 { << 123 << " ["<< GetUnit() << "]"; 119 if(divideByVelocity) << 124 G4cout << G4endl; 120 G4cout << " Time: "; << 121 else << 122 G4cout << " Length: "; << 123 } << 124 G4cout << *(length) / GetUnitValue() << " << 125 G4cout << G4endl; << 126 } 125 } 127 } 126 } 128 127 129 void G4PSTrackLength::SetUnit(const G4String& 128 void G4PSTrackLength::SetUnit(const G4String& unit) 130 { 129 { 131 if(multiplyKinE) << 130 if ( multiplyKinE ){ 132 { << 131 if ( divideByVelocity ){ 133 if(divideByVelocity) << 132 if ( unit == "" ) { 134 { << 133 CheckAndSetUnit("MeV_second","EnergyFlux"); 135 if(unit.empty()) << 134 } else { 136 { << 135 CheckAndSetUnit(unit,"EnergyFlux"); 137 CheckAndSetUnit("MeV_second", "EnergyF << 136 } 138 } << 137 }else { 139 else << 138 if ( unit == "" ) { 140 { << 139 CheckAndSetUnit("MeV_mm","EnergyFlow"); 141 CheckAndSetUnit(unit, "EnergyFlux"); << 140 } else { 142 } << 141 CheckAndSetUnit(unit,"EnergyFlow"); 143 } << 142 } 144 else << 143 } 145 { << 144 }else { 146 if(unit.empty()) << 145 if ( divideByVelocity ){ 147 { << 146 if ( unit == "" ) { 148 CheckAndSetUnit("MeV_mm", "EnergyFlow" << 147 CheckAndSetUnit("second","Time"); 149 } << 148 } else { 150 else << 149 CheckAndSetUnit(unit,"Time"); 151 { << 150 } 152 CheckAndSetUnit(unit, "EnergyFlow"); << 151 }else { 153 } << 152 if ( unit == "") { 154 } << 153 CheckAndSetUnit("mm","Length"); 155 } << 154 } else { 156 else << 155 CheckAndSetUnit(unit,"Length"); 157 { << 156 } 158 if(divideByVelocity) << 157 } 159 { << 158 } 160 if(unit.empty()) << 159 } 161 { << 160 162 CheckAndSetUnit("second", "Time"); << 161 void G4PSTrackLength::DefineUnitAndCategory(){ 163 } << 162 // EnergyFlux 164 else << 163 new G4UnitDefinition("eV_second","eV_s","EnergyFlux",(eV*second)); 165 { << 164 new G4UnitDefinition("keV_second","keV_s","EnergyFlux",(keV*second)); 166 CheckAndSetUnit(unit, "Time"); << 165 new G4UnitDefinition("MeV_second","MeV_s","EnergyFlux",(MeV*second)); 167 } << 166 new G4UnitDefinition("eV_millisecond","eV_ms","EnergyFlux",(eV*ms)); 168 } << 167 new G4UnitDefinition("keV_millisecond","keV_ms","EnergyFlux",(keV*ms)); 169 else << 168 new G4UnitDefinition("MeV_millisecond","MeV_ms","EnergyFlux",(MeV*ms)); 170 { << 169 //EnergyFlow 171 if(unit.empty()) << 170 new G4UnitDefinition("eV_millimeter","eV_mm","EnergyFlow",(eV*mm)); 172 { << 171 new G4UnitDefinition("keV_millimeter","keV_mm","EnergyFlow",(keV*mm)); 173 CheckAndSetUnit("mm", "Length"); << 172 new G4UnitDefinition("MeV_millimeter","MeV_mm","EnergyFlow",(MeV*mm)); 174 } << 173 new G4UnitDefinition("eV_centimeter","eV_cm","EnergyFlow",(eV*cm)); 175 else << 174 new G4UnitDefinition("keV_centimeter","keV_cm","EnergyFlow",(keV*cm)); 176 { << 175 new G4UnitDefinition("MeV_centimeter","MeV_cm","EnergyFlow",(MeV*cm)); 177 CheckAndSetUnit(unit, "Length"); << 176 new G4UnitDefinition("eV_meter","eV_m","EnergyFlow",(eV*m)); 178 } << 177 new G4UnitDefinition("keV_meter","keV_m","EnergyFlow",(keV*m)); 179 } << 178 new G4UnitDefinition("MeV_meter","MeV_m","EnergyFlow",(MeV*m)); 180 } << 181 } 179 } 182 180 183 void G4PSTrackLength::DefineUnitAndCategory() << 181 184 { << 182 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 183