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

Last change on this file since 1202 was 1012, checked in by garnier, 15 years ago

update

File size: 4.7 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.1 2007/07/11 01:31:03 asaim Exp $
28// GEANT4 tag $Name: geant4-09-02-ref-02 $
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//
44///////////////////////////////////////////////////////////////////////////////
45
46G4PSPassageTrackLength::G4PSPassageTrackLength(G4String name, G4int depth)
47  :G4VPrimitiveScorer(name,depth),HCID(-1),fCurrentTrkID(-1),fTrackLength(0.),
48   weighted(false)
49{;}
50
51G4PSPassageTrackLength::~G4PSPassageTrackLength()
52{;}
53
54G4bool G4PSPassageTrackLength::ProcessHits(G4Step* aStep,G4TouchableHistory*)
55{
56
57  if ( IsPassed(aStep) ) {
58    G4int index = GetIndex(aStep);
59    EvtMap->add(index,fTrackLength);
60  }
61
62  return TRUE;
63}
64
65G4bool G4PSPassageTrackLength::IsPassed(G4Step* aStep){
66  G4bool Passed = FALSE;
67
68  G4bool IsEnter = aStep->GetPreStepPoint()->GetStepStatus() == fGeomBoundary;
69  G4bool IsExit  = aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary;
70
71  G4int  trkid  = aStep->GetTrack()->GetTrackID();
72  G4double trklength  = aStep->GetStepLength();
73  if(weighted) trklength *= aStep->GetPreStepPoint()->GetWeight();
74
75  if ( IsEnter &&IsExit ){         // Passed at one step
76    fTrackLength = trklength;      // Track length is absolutely given.
77    Passed = TRUE;                 
78  }else if ( IsEnter ){            // Enter a new geometry
79    fCurrentTrkID = trkid;         // Resetting the current track.
80    fTrackLength  = trklength;     
81  }else if ( IsExit ){             // Exit a current geometry
82    if ( fCurrentTrkID == trkid ) {
83      fTrackLength  += trklength;  // Adding the track length to current one,
84      Passed = TRUE;               // if the track is same as entered.
85    }
86  }else{                           // Inside geometry
87    if ( fCurrentTrkID == trkid ){ // Adding the track length to current one ,
88      fTrackLength  += trklength;  // if the track is same as entered.
89    }
90  }
91
92  return Passed;
93}
94
95void G4PSPassageTrackLength::Initialize(G4HCofThisEvent* HCE)
96{
97  fCurrentTrkID = -1;
98
99  EvtMap = new G4THitsMap<G4double>(detector->GetName(),GetName());
100  if ( HCID < 0 ) HCID = GetCollectionID(0);
101  HCE->AddHitsCollection(HCID,EvtMap);
102}
103
104void G4PSPassageTrackLength::EndOfEvent(G4HCofThisEvent*)
105{;}
106
107void G4PSPassageTrackLength::clear(){
108  EvtMap->clear();
109}
110
111void G4PSPassageTrackLength::DrawAll()
112{;}
113
114void G4PSPassageTrackLength::PrintAll()
115{
116  G4cout << " MultiFunctionalDet  " << detector->GetName() << G4endl;
117  G4cout << " PrimitiveSenstivity " << GetName() << G4endl;
118  G4cout << " Number of entries " << EvtMap->entries() << G4endl;
119  std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin();
120  for(; itr != EvtMap->GetMap()->end(); itr++) {
121    G4cout << "  copy no.: " << itr->first
122           << "  track length : " << G4BestUnit(*(itr->second),"Length") 
123           << G4endl;
124  }
125}
126
Note: See TracBrowser for help on using the repository browser.