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 #include "G4PSTrackLength.hh"
00031 #include "G4SystemOfUnits.hh"
00032 #include "G4UnitsTable.hh"
00034
00035
00036
00037
00038
00039
00040
00041
00043
00044 G4PSTrackLength::G4PSTrackLength(G4String name, G4int depth)
00045 :G4VPrimitiveScorer(name,depth),HCID(-1),weighted(false),multiplyKinE(false),
00046 divideByVelocity(false)
00047 {
00048 DefineUnitAndCategory();
00049 SetUnit("mm");
00050 }
00051
00052 G4PSTrackLength::G4PSTrackLength(G4String name, const G4String& unit,
00053 G4int depth)
00054 :G4VPrimitiveScorer(name,depth),HCID(-1),weighted(false),multiplyKinE(false),
00055 divideByVelocity(false)
00056 {
00057 DefineUnitAndCategory();
00058 SetUnit(unit);
00059 }
00060
00061 G4PSTrackLength::~G4PSTrackLength()
00062 {;}
00063
00064 void G4PSTrackLength::MultiplyKineticEnergy(G4bool flg)
00065 {
00066 multiplyKinE = flg;
00067
00068 SetUnit("");
00069 }
00070
00071 void G4PSTrackLength::DivideByVelocity(G4bool flg)
00072 {
00073 divideByVelocity = flg;
00074
00075 SetUnit("");
00076 }
00077
00078 G4bool G4PSTrackLength::ProcessHits(G4Step* aStep,G4TouchableHistory*)
00079 {
00080 G4double trklength = aStep->GetStepLength();
00081 if ( trklength == 0. ) return FALSE;
00082 if(weighted) trklength *= aStep->GetPreStepPoint()->GetWeight();
00083 if(multiplyKinE) trklength *= aStep->GetPreStepPoint()->GetKineticEnergy();
00084 if(divideByVelocity) trklength /= aStep->GetPreStepPoint()->GetVelocity();
00085 G4int index = GetIndex(aStep);
00086 EvtMap->add(index,trklength);
00087 return TRUE;
00088 }
00089
00090 void G4PSTrackLength::Initialize(G4HCofThisEvent* HCE)
00091 {
00092 EvtMap = new G4THitsMap<G4double>(detector->GetName(),GetName());
00093 if(HCID < 0) {HCID = GetCollectionID(0);}
00094 HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap);
00095 }
00096
00097 void G4PSTrackLength::EndOfEvent(G4HCofThisEvent*)
00098 {;}
00099
00100 void G4PSTrackLength::clear(){
00101 EvtMap->clear();
00102 }
00103
00104 void G4PSTrackLength::DrawAll()
00105 {;}
00106
00107 void G4PSTrackLength::PrintAll()
00108 {
00109 G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl;
00110 G4cout << " PrimitiveScorer " << GetName() << G4endl;
00111 G4cout << " Number of entries " << EvtMap->entries() << G4endl;
00112 std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin();
00113 for(; itr != EvtMap->GetMap()->end(); itr++) {
00114 G4cout << " copy no.: " << itr->first ;
00115 if ( multiplyKinE ){
00116 if ( divideByVelocity ) G4cout << " EnergyFlux: ";
00117 else G4cout << " EnergyFlow: ";
00118 }else{
00119 if ( divideByVelocity ) G4cout << " Time: ";
00120 else G4cout << " Length: ";
00121 }
00122 G4cout << *(itr->second)/GetUnitValue()
00123 << " ["<< GetUnit() << "]";
00124 G4cout << G4endl;
00125 }
00126 }
00127
00128 void G4PSTrackLength::SetUnit(const G4String& unit)
00129 {
00130 if ( multiplyKinE ){
00131 if ( divideByVelocity ){
00132 if ( unit == "" ) {
00133 CheckAndSetUnit("MeV_second","EnergyFlux");
00134 } else {
00135 CheckAndSetUnit(unit,"EnergyFlux");
00136 }
00137 }else {
00138 if ( unit == "" ) {
00139 CheckAndSetUnit("MeV_mm","EnergyFlow");
00140 } else {
00141 CheckAndSetUnit(unit,"EnergyFlow");
00142 }
00143 }
00144 }else {
00145 if ( divideByVelocity ){
00146 if ( unit == "" ) {
00147 CheckAndSetUnit("second","Time");
00148 } else {
00149 CheckAndSetUnit(unit,"Time");
00150 }
00151 }else {
00152 if ( unit == "") {
00153 CheckAndSetUnit("mm","Length");
00154 } else {
00155 CheckAndSetUnit(unit,"Length");
00156 }
00157 }
00158 }
00159 }
00160
00161 void G4PSTrackLength::DefineUnitAndCategory(){
00162
00163 new G4UnitDefinition("eV_second","eV_s","EnergyFlux",(eV*second));
00164 new G4UnitDefinition("keV_second","keV_s","EnergyFlux",(keV*second));
00165 new G4UnitDefinition("MeV_second","MeV_s","EnergyFlux",(MeV*second));
00166 new G4UnitDefinition("eV_millisecond","eV_ms","EnergyFlux",(eV*ms));
00167 new G4UnitDefinition("keV_millisecond","keV_ms","EnergyFlux",(keV*ms));
00168 new G4UnitDefinition("MeV_millisecond","MeV_ms","EnergyFlux",(MeV*ms));
00169
00170 new G4UnitDefinition("eV_millimeter","eV_mm","EnergyFlow",(eV*mm));
00171 new G4UnitDefinition("keV_millimeter","keV_mm","EnergyFlow",(keV*mm));
00172 new G4UnitDefinition("MeV_millimeter","MeV_mm","EnergyFlow",(MeV*mm));
00173 new G4UnitDefinition("eV_centimeter","eV_cm","EnergyFlow",(eV*cm));
00174 new G4UnitDefinition("keV_centimeter","keV_cm","EnergyFlow",(keV*cm));
00175 new G4UnitDefinition("MeV_centimeter","MeV_cm","EnergyFlow",(MeV*cm));
00176 new G4UnitDefinition("eV_meter","eV_m","EnergyFlow",(eV*m));
00177 new G4UnitDefinition("keV_meter","keV_m","EnergyFlow",(keV*m));
00178 new G4UnitDefinition("MeV_meter","MeV_m","EnergyFlow",(MeV*m));
00179 }
00180
00181
00182