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 "G4PSTrackCounter.hh"
00031 #include "G4UnitsTable.hh"
00032
00034
00035
00036
00037
00038
00039
00041
00042 G4PSTrackCounter::G4PSTrackCounter(G4String name, G4int direction, G4int depth)
00043 :G4VPrimitiveScorer(name,depth),HCID(-1),fDirection(direction),weighted(false)
00044 {
00045 SetUnit("");
00046 }
00047
00048 G4PSTrackCounter::~G4PSTrackCounter()
00049 {;}
00050
00051 G4bool G4PSTrackCounter::ProcessHits(G4Step* aStep,G4TouchableHistory*)
00052 {
00053
00054 G4StepPoint* preStep = aStep->GetPreStepPoint();
00055 G4StepPoint* posStep = aStep->GetPostStepPoint();
00056 G4bool IsEnter = preStep->GetStepStatus()==fGeomBoundary;
00057 G4bool IsExit = posStep->GetStepStatus()==fGeomBoundary;
00058
00059
00060 G4int index = GetIndex(aStep);
00061
00062
00063
00064
00065
00066
00067
00068
00069 G4bool flag = FALSE;
00070
00071 if ( IsEnter && fDirection == fCurrent_In ) flag = TRUE;
00072 else if ( IsExit && fDirection == fCurrent_Out ) flag = TRUE;
00073 else if ( (IsExit||IsEnter) && fDirection == fCurrent_InOut ) flag = TRUE;
00074
00075 if ( flag ){
00076
00077 G4double val = 1.0;
00078 if(weighted) val *= aStep->GetPreStepPoint()->GetWeight();
00079 EvtMap->add(index,val);
00080 }
00081
00082 return TRUE;
00083 }
00084
00085 void G4PSTrackCounter::Initialize(G4HCofThisEvent* HCE)
00086 {
00087 EvtMap = new G4THitsMap<G4double>(detector->GetName(),GetName());
00088 if(HCID < 0) {HCID = GetCollectionID(0);}
00089 HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap);
00090
00091 }
00092
00093 void G4PSTrackCounter::EndOfEvent(G4HCofThisEvent*)
00094 {;}
00095
00096 void G4PSTrackCounter::clear(){
00097 EvtMap->clear();
00098 }
00099
00100 void G4PSTrackCounter::DrawAll()
00101 {;}
00102
00103 void G4PSTrackCounter::PrintAll()
00104 {
00105 G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl;
00106 G4cout << " PrimitiveScorer " << GetName() << G4endl;
00107 G4cout << " Number of entries " << EvtMap->entries() << G4endl;
00108 std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin();
00109 for(; itr != EvtMap->GetMap()->end(); itr++) {
00110 G4cout << " copy no.: " << itr->first
00111 << " track count: " << *(itr->second)
00112 << " [tracks] "
00113 << G4endl;
00114 }
00115 }
00116
00117 void G4PSTrackCounter::SetUnit(const G4String& unit)
00118 {
00119 if (unit == "" ){
00120 unitName = unit;
00121 unitValue = 1.0;
00122 }else{
00123 G4String msg = "Invalid unit ["+unit+"] (Current unit is [" +GetUnit()+"] ) for " + GetName();
00124 G4Exception("G4PSTrackCounter::SetUnit","DetPS0018",JustWarning,msg);
00125 }
00126
00127 }
00128