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