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,v 1.2 2010-07-22 07:23:45 taso Exp $ >> 28 // GEANT4 tag $Name: not supported by cvs2svn $ 27 // 29 // 28 // G4PSTrackLength 30 // G4PSTrackLength 29 #include "G4PSTrackLength.hh" 31 #include "G4PSTrackLength.hh" 30 #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 // 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),weighted(false),multiplyKinE(false), 45 {} << 45 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),weighted(false),multiplyKinE(false), >> 54 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); << 96 } << 97 HCE->AddHitsCollection(HCID, (G4VHitsCollect << 98 } 94 } 99 95 100 void G4PSTrackLength::clear() { EvtMap->clear( << 96 void G4PSTrackLength::EndOfEvent(G4HCofThisEvent*) >> 97 {;} >> 98 >> 99 void G4PSTrackLength::clear(){ >> 100 EvtMap->clear(); >> 101 } >> 102 >> 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 << " value "; 110 if(multiplyKinE) << 114 G4cout << *(itr->second)/GetUnitValue() 111 { << 115 << " ["<< GetUnit() << "]"; 112 if(divideByVelocity) << 116 G4cout << G4endl; 113 G4cout << " EnergyFlux: "; << 114 else << 115 G4cout << " EnergyFlow: "; << 116 } << 117 else << 118 { << 119 if(divideByVelocity) << 120 G4cout << " Time: "; << 121 else << 122 G4cout << " Length: "; << 123 } << 124 G4cout << *(length) / GetUnitValue() << " << 125 G4cout << G4endl; << 126 } 117 } 127 } 118 } 128 119 129 void G4PSTrackLength::SetUnit(const G4String& 120 void G4PSTrackLength::SetUnit(const G4String& unit) 130 { 121 { 131 if(multiplyKinE) << 122 if ( multiplyKinE ){ 132 { << 123 if ( divideByVelocity ){ 133 if(divideByVelocity) << 124 if ( unit == "" ) { 134 { << 125 CheckAndSetUnit("MeV_second","EnergyFlux"); 135 if(unit.empty()) << 126 } else { 136 { << 127 CheckAndSetUnit(unit,"EnergyFlux"); 137 CheckAndSetUnit("MeV_second", "EnergyF << 128 } 138 } << 129 }else { 139 else << 130 if ( unit == "" ) { 140 { << 131 CheckAndSetUnit("MeV_mm","EnergyFlow"); 141 CheckAndSetUnit(unit, "EnergyFlux"); << 132 } else { 142 } << 133 CheckAndSetUnit(unit,"EnergyFlow"); 143 } << 134 } 144 else << 135 } 145 { << 136 }else { 146 if(unit.empty()) << 137 if ( divideByVelocity ){ 147 { << 138 if ( unit == "" ) { 148 CheckAndSetUnit("MeV_mm", "EnergyFlow" << 139 CheckAndSetUnit("second","Time"); 149 } << 140 } else { 150 else << 141 CheckAndSetUnit(unit,"Time"); 151 { << 142 } 152 CheckAndSetUnit(unit, "EnergyFlow"); << 143 }else { 153 } << 144 if ( unit == "") { 154 } << 145 CheckAndSetUnit("mm","Length"); 155 } << 146 } else { 156 else << 147 CheckAndSetUnit(unit,"Length"); 157 { << 148 } 158 if(divideByVelocity) << 149 } 159 { << 150 } 160 if(unit.empty()) << 151 } 161 { << 152 162 CheckAndSetUnit("second", "Time"); << 153 void G4PSTrackLength::DefineUnitAndCategory(){ 163 } << 154 // EnergyFlux 164 else << 155 new G4UnitDefinition("eV_second","eV_s","EnergyFlux",(eV*second)); 165 { << 156 new G4UnitDefinition("keV_second","keV_s","EnergyFlux",(keV*second)); 166 CheckAndSetUnit(unit, "Time"); << 157 new G4UnitDefinition("MeV_second","MeV_s","EnergyFlux",(MeV*second)); 167 } << 158 new G4UnitDefinition("eV_millisecond","eV_ms","EnergyFlux",(eV*ms)); 168 } << 159 new G4UnitDefinition("keV_millisecond","keV_ms","EnergyFlux",(keV*ms)); 169 else << 160 new G4UnitDefinition("MeV_millisecond","MeV_ms","EnergyFlux",(MeV*ms)); 170 { << 161 //EnergyFlow 171 if(unit.empty()) << 162 new G4UnitDefinition("eV_millimeter","eV_mm","EnergyFlow",(eV*mm)); 172 { << 163 new G4UnitDefinition("keV_millimeter","keV_mm","EnergyFlow",(keV*mm)); 173 CheckAndSetUnit("mm", "Length"); << 164 new G4UnitDefinition("MeV_millimeter","MeV_mm","EnergyFlow",(MeV*mm)); 174 } << 165 new G4UnitDefinition("eV_centimeter","eV_cm","EnergyFlow",(eV*cm)); 175 else << 166 new G4UnitDefinition("keV_centimeter","keV_cm","EnergyFlow",(keV*cm)); 176 { << 167 new G4UnitDefinition("MeV_centimeter","MeV_cm","EnergyFlow",(MeV*cm)); 177 CheckAndSetUnit(unit, "Length"); << 168 new G4UnitDefinition("eV_meter","eV_m","EnergyFlow",(eV*m)); 178 } << 169 new G4UnitDefinition("keV_meter","keV_m","EnergyFlow",(keV*m)); 179 } << 170 new G4UnitDefinition("MeV_meter","MeV_m","EnergyFlow",(MeV*m)); 180 } << 181 } 171 } 182 172 183 void G4PSTrackLength::DefineUnitAndCategory() << 173 184 { << 174 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 175