Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 81087 2014-05-20 15:44:27Z 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),EvtMap(0),weighted(false),
46  multiplyKinE(false),divideByVelocity(false)
47 {
49  SetUnit("mm");
50 }
51 
53  G4int depth)
54  :G4VPrimitiveScorer(name,depth),HCID(-1),EvtMap(0),weighted(false),
55  multiplyKinE(false),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 {
92  EvtMap = new G4THitsMap<G4double>(detector->GetName(),GetName());
93  if(HCID < 0) {HCID = GetCollectionID(0);}
94  HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap);
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 
const XML_Char * name
Definition: expat.h:151
void clear()
Definition: G4THitsMap.hh:267
G4double GetWeight() const
static constexpr double mm
Definition: G4SIunits.hh:115
G4String GetName() const
G4double GetStepLength() const
virtual void clear()
virtual void Initialize(G4HCofThisEvent *)
G4PSTrackLength(G4String name, G4int depth=0)
static constexpr double second
Definition: G4SIunits.hh:157
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
G4GLOB_DLL std::ostream G4cout
static constexpr double m
Definition: G4SIunits.hh:129
G4double GetUnitValue() const
bool G4bool
Definition: G4Types.hh:79
static constexpr double cm
Definition: G4SIunits.hh:119
#define FALSE
Definition: globals.hh:52
virtual G4int GetIndex(G4Step *)
static constexpr double eV
Definition: G4SIunits.hh:215
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:200
G4int add(const G4int &key, T *&aHit) const
Definition: G4THitsMap.hh:106
virtual G4bool ProcessHits(G4Step *, G4TouchableHistory *)
virtual void DefineUnitAndCategory()
void MultiplyKineticEnergy(G4bool flg=true)
std::map< G4int, T * > * GetMap() const
Definition: G4THitsMap.hh:99
#define G4endl
Definition: G4ios.hh:61
static constexpr double MeV
Definition: G4SIunits.hh:214
G4MultiFunctionalDetector * detector
virtual void SetUnit(const G4String &unit)
G4double GetKineticEnergy() const
double G4double
Definition: G4Types.hh:76
static constexpr double ms
Definition: G4SIunits.hh:170
const G4String & GetUnit() const
static constexpr double keV
Definition: G4SIunits.hh:216
void DivideByVelocity(G4bool flg=true)