Geant4  10.00.p03
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 // $Id: G4PSTrackLength.cc 67992 2013-03-13 10:59:57Z gcosmo $
28 //
29 // G4PSTrackLength
30 #include "G4PSTrackLength.hh"
31 #include "G4SystemOfUnits.hh"
32 #include "G4UnitsTable.hh"
34 // (Description)
35 // This is a primitive scorer class for scoring sum of track length.
36 //
37 //
38 // Created: 2007-02-02 Tsukasa ASO, Akinori Kimura.
39 // 2010-07-22 Introduce Unit specification.
40 // 2011-09-09 Modify comment in PrintAll().
41 //
43 
45  :G4VPrimitiveScorer(name,depth),HCID(-1),weighted(false),multiplyKinE(false),
46  divideByVelocity(false)
47 {
49  SetUnit("mm");
50 }
51 
53  G4int depth)
54  :G4VPrimitiveScorer(name,depth),HCID(-1),weighted(false),multiplyKinE(false),
55  divideByVelocity(false)
56 {
58  SetUnit(unit);
59 }
60 
62 {;}
63 
65 {
66  multiplyKinE = flg;
67  // Default unit is set according to flags.
68  SetUnit("");
69 }
70 
72 {
73  divideByVelocity = flg;
74  // Default unit is set according to flags.
75  SetUnit("");
76 }
77 
79 {
80  G4double trklength = aStep->GetStepLength();
81  if ( trklength == 0. ) return FALSE;
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 }
89 
91 {
93  if(HCID < 0) {HCID = GetCollectionID(0);}
95 }
96 
98 {;}
99 
101  EvtMap->clear();
102 }
103 
105 {;}
106 
108 {
109  G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl;
110  G4cout << " PrimitiveScorer " << GetName() << G4endl;
111  G4cout << " Number of entries " << EvtMap->entries() << G4endl;
112  std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin();
113  for(; itr != EvtMap->GetMap()->end(); itr++) {
114  G4cout << " copy no.: " << itr->first ;
115  if ( multiplyKinE ){
116  if ( divideByVelocity ) G4cout << " EnergyFlux: ";
117  else G4cout << " EnergyFlow: ";
118  }else{
119  if ( divideByVelocity ) G4cout << " Time: ";
120  else G4cout << " Length: ";
121  }
122  G4cout << *(itr->second)/GetUnitValue()
123  << " ["<< GetUnit() << "]";
124  G4cout << G4endl;
125  }
126 }
127 
129 {
130  if ( multiplyKinE ){
131  if ( divideByVelocity ){
132  if ( unit == "" ) {
133  CheckAndSetUnit("MeV_second","EnergyFlux");
134  } else {
135  CheckAndSetUnit(unit,"EnergyFlux");
136  }
137  }else {
138  if ( unit == "" ) {
139  CheckAndSetUnit("MeV_mm","EnergyFlow");
140  } else {
141  CheckAndSetUnit(unit,"EnergyFlow");
142  }
143  }
144  }else {
145  if ( divideByVelocity ){
146  if ( unit == "" ) {
147  CheckAndSetUnit("second","Time");
148  } else {
149  CheckAndSetUnit(unit,"Time");
150  }
151  }else {
152  if ( unit == "") {
153  CheckAndSetUnit("mm","Length");
154  } else {
155  CheckAndSetUnit(unit,"Length");
156  }
157  }
158  }
159 }
160 
162  // EnergyFlux
163  new G4UnitDefinition("eV_second","eV_s","EnergyFlux",(eV*second));
164  new G4UnitDefinition("keV_second","keV_s","EnergyFlux",(keV*second));
165  new G4UnitDefinition("MeV_second","MeV_s","EnergyFlux",(MeV*second));
166  new G4UnitDefinition("eV_millisecond","eV_ms","EnergyFlux",(eV*ms));
167  new G4UnitDefinition("keV_millisecond","keV_ms","EnergyFlux",(keV*ms));
168  new G4UnitDefinition("MeV_millisecond","MeV_ms","EnergyFlux",(MeV*ms));
169  //EnergyFlow
170  new G4UnitDefinition("eV_millimeter","eV_mm","EnergyFlow",(eV*mm));
171  new G4UnitDefinition("keV_millimeter","keV_mm","EnergyFlow",(keV*mm));
172  new G4UnitDefinition("MeV_millimeter","MeV_mm","EnergyFlow",(MeV*mm));
173  new G4UnitDefinition("eV_centimeter","eV_cm","EnergyFlow",(eV*cm));
174  new G4UnitDefinition("keV_centimeter","keV_cm","EnergyFlow",(keV*cm));
175  new G4UnitDefinition("MeV_centimeter","MeV_cm","EnergyFlow",(MeV*cm));
176  new G4UnitDefinition("eV_meter","eV_m","EnergyFlow",(eV*m));
177  new G4UnitDefinition("keV_meter","keV_m","EnergyFlow",(keV*m));
178  new G4UnitDefinition("MeV_meter","MeV_m","EnergyFlow",(MeV*m));
179 }
180 
181 
182 
static const double cm
Definition: G4SIunits.hh:106
static const double MeV
Definition: G4SIunits.hh:193
void clear()
Definition: G4THitsMap.hh:209
G4double GetWeight() const
G4String GetName() const
G4double GetStepLength() const
G4String name
Definition: TRTMaterials.hh:40
G4THitsMap< G4double > * EvtMap
virtual void clear()
virtual void Initialize(G4HCofThisEvent *)
G4PSTrackLength(G4String name, G4int depth=0)
G4double GetVelocity() const
void CheckAndSetUnit(const G4String &unit, const G4String &category)
int G4int
Definition: G4Types.hh:78
virtual void DrawAll()
virtual void EndOfEvent(G4HCofThisEvent *)
G4StepPoint * GetPreStepPoint() const
static const double ms
Definition: G4SIunits.hh:151
G4GLOB_DLL std::ostream G4cout
G4double GetUnitValue() const
bool G4bool
Definition: G4Types.hh:79
G4int add(const G4int &key, T *&aHit) const
Definition: G4THitsMap.hh:138
#define FALSE
Definition: globals.hh:52
virtual G4int GetIndex(G4Step *)
static const double second
Definition: G4SIunits.hh:138
virtual void PrintAll()
#define TRUE
Definition: globals.hh:55
virtual ~G4PSTrackLength()
Definition: G4Step.hh:76
G4int GetCollectionID(G4int)
void AddHitsCollection(G4int HCID, G4VHitsCollection *aHC)
G4int entries() const
Definition: G4THitsMap.hh:79
static const double eV
Definition: G4SIunits.hh:194
virtual G4bool ProcessHits(G4Step *, G4TouchableHistory *)
virtual void DefineUnitAndCategory()
void MultiplyKineticEnergy(G4bool flg=true)
std::map< G4int, T * > * GetMap() const
Definition: G4THitsMap.hh:68
#define G4endl
Definition: G4ios.hh:61
G4MultiFunctionalDetector * detector
static const double m
Definition: G4SIunits.hh:110
static const double keV
Definition: G4SIunits.hh:195
virtual void SetUnit(const G4String &unit)
G4double GetKineticEnergy() const
double G4double
Definition: G4Types.hh:76
const G4String & GetUnit() const
static const double mm
Definition: G4SIunits.hh:102
void DivideByVelocity(G4bool flg=true)