source: trunk/source/digits_hits/scorer/src/G4PSPassageTrackLength.cc @ 1340

Last change on this file since 1340 was 1340, checked in by garnier, 14 years ago

update ti head

File size: 5.2 KB
Line 
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: G4PSPassageTrackLength.cc,v 1.2 2010/07/22 07:23:45 taso Exp $
28// GEANT4 tag $Name:  $
29//
30// G4PSPassageTrackLength
31#include "G4PSPassageTrackLength.hh"
32#include "G4StepStatus.hh"
33#include "G4Track.hh"
34#include "G4UnitsTable.hh"
35
36////////////////////////////////////////////////////////////////////////////////
37// (Description)
38//   This is a primitive scorer class for scoring only track length.
39//   The tracks which passed a geometry is taken into account.
40//
41//
42// Created: 2005-11-14  Tsukasa ASO, Akinori Kimura.
43// 2010-07-22   Introduce Unit specification.
44//
45///////////////////////////////////////////////////////////////////////////////
46
47G4PSPassageTrackLength::G4PSPassageTrackLength(G4String name, G4int depth)
48  :G4VPrimitiveScorer(name,depth),HCID(-1),fCurrentTrkID(-1),fTrackLength(0.),
49   weighted(false)
50{
51    SetUnit("mm");
52}
53
54G4PSPassageTrackLength::G4PSPassageTrackLength(G4String name, 
55                                               const G4String& unit, 
56                                               G4int depth)
57  :G4VPrimitiveScorer(name,depth),HCID(-1),fCurrentTrkID(-1),fTrackLength(0.),
58   weighted(false)
59{
60    SetUnit(unit);
61}
62
63
64G4PSPassageTrackLength::~G4PSPassageTrackLength()
65{;}
66
67G4bool G4PSPassageTrackLength::ProcessHits(G4Step* aStep,G4TouchableHistory*)
68{
69
70  if ( IsPassed(aStep) ) {
71    G4int index = GetIndex(aStep);
72    EvtMap->add(index,fTrackLength);
73  }
74
75  return TRUE;
76}
77
78G4bool G4PSPassageTrackLength::IsPassed(G4Step* aStep){
79  G4bool Passed = FALSE;
80
81  G4bool IsEnter = aStep->GetPreStepPoint()->GetStepStatus() == fGeomBoundary;
82  G4bool IsExit  = aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary;
83
84  G4int  trkid  = aStep->GetTrack()->GetTrackID();
85  G4double trklength  = aStep->GetStepLength();
86  if(weighted) trklength *= aStep->GetPreStepPoint()->GetWeight();
87
88  if ( IsEnter &&IsExit ){         // Passed at one step
89    fTrackLength = trklength;      // Track length is absolutely given.
90    Passed = TRUE;                 
91  }else if ( IsEnter ){            // Enter a new geometry
92    fCurrentTrkID = trkid;         // Resetting the current track.
93    fTrackLength  = trklength;     
94  }else if ( IsExit ){             // Exit a current geometry
95    if ( fCurrentTrkID == trkid ) {
96      fTrackLength  += trklength;  // Adding the track length to current one,
97      Passed = TRUE;               // if the track is same as entered.
98    }
99  }else{                           // Inside geometry
100    if ( fCurrentTrkID == trkid ){ // Adding the track length to current one ,
101      fTrackLength  += trklength;  // if the track is same as entered.
102    }
103  }
104
105  return Passed;
106}
107
108void G4PSPassageTrackLength::Initialize(G4HCofThisEvent* HCE)
109{
110  fCurrentTrkID = -1;
111
112  EvtMap = new G4THitsMap<G4double>(detector->GetName(),GetName());
113  if ( HCID < 0 ) HCID = GetCollectionID(0);
114  HCE->AddHitsCollection(HCID,EvtMap);
115}
116
117void G4PSPassageTrackLength::EndOfEvent(G4HCofThisEvent*)
118{;}
119
120void G4PSPassageTrackLength::clear(){
121  EvtMap->clear();
122}
123
124void G4PSPassageTrackLength::DrawAll()
125{;}
126
127void G4PSPassageTrackLength::PrintAll()
128{
129  G4cout << " MultiFunctionalDet  " << detector->GetName() << G4endl;
130  G4cout << " PrimitiveSenstivity " << GetName() << G4endl;
131  G4cout << " Number of entries " << EvtMap->entries() << G4endl;
132  std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin();
133  for(; itr != EvtMap->GetMap()->end(); itr++) {
134    G4cout << "  copy no.: " << itr->first
135           << "  track length : " 
136           << *(itr->second)/GetUnitValue()
137           << " [" << GetUnit()<< "]"
138           << G4endl;
139  }
140}
141
142void G4PSPassageTrackLength::SetUnit(const G4String& unit)
143{
144    CheckAndSetUnit(unit,"Length");
145}
Note: See TracBrowser for help on using the repository browser.