EDepSimSegmentSD.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////
2 // $Id: EDepSim::SegmentSD.cc,v 1.6 2008/09/03 17:33:42 mcgrew Exp $
3 //
4 
5 #include <G4HCofThisEvent.hh>
6 #include <G4Step.hh>
7 #include <G4StepPoint.hh>
8 #include <G4VProcess.hh>
9 #include <G4TouchableHistory.hh>
10 #include <G4SDManager.hh>
11 #include <G4UnitsTable.hh>
12 
13 #include <G4SystemOfUnits.hh>
14 #include <G4PhysicalConstants.hh>
15 
16 #include <EDepSimLog.hh>
17 
18 #include "EDepSimSegmentSD.hh"
19 #include "EDepSimHitSegment.hh"
20 
22  :G4VSensitiveDetector(name),
23  fHits(NULL), fHCID(-1),
24  fMaximumHitSagitta(1*CLHEP::mm), fMaximumHitLength(3*CLHEP::mm),
25  fLastHit(0) {
26  // In an unbelievably poor interface, the G4VSensitiveDetector class
27  // exposes the protected field "std::vector<G4String> collectionName" to
28  // the user and expects any derived classes to explicitly fill it with the
29  // names of the hit collection filled. The values in collectionName
30  // should be accessed through
31  // "G4VSensitiveDetector::GetCollectionName(i)".
32  collectionName.insert("SegmentHits");
33 }
34 
36 
37 void EDepSim::SegmentSD::Initialize(G4HCofThisEvent* HCE) {
39  GetCollectionName(0));
40 
41  if (fHCID<0) {
42  G4String hcName = GetName() + "/" + GetCollectionName(0);
43  fHCID = G4SDManager::GetSDMpointer()->GetCollectionID(hcName);
44  EDepSimLog("Initialize SD for "
45  << GetName() << "/" << GetCollectionName(0)
46  << " w/ sagitta " << G4BestUnit(fMaximumHitSagitta,"Length")
47  << " & " << G4BestUnit(fMaximumHitLength,"Length"));
48  }
49  HCE->AddHitsCollection(fHCID, fHits);
50 }
51 
52 G4bool EDepSim::SegmentSD::ProcessHits(G4Step* theStep,
53  G4TouchableHistory*) {
54  // Get the hit information.
55  G4double energyDeposit = theStep->GetTotalEnergyDeposit();
56  if (energyDeposit <= 0.) return true;
57 
58  EDepSimTrace("Process hit with " << energyDeposit
59  << " in " << theStep->GetTrack()->GetVolume()->GetName());
60 
61 
62  EDepSim::HitSegment* currentHit = NULL;
63 
64  // Check to see if the last hit in the vector of hits needs to be
65  // expanded.
66  if (0<=fLastHit && fLastHit < (int) fHits->entries()) {
67  EDepSim::HitSegment *tmpHit = (*fHits)[fLastHit];
68  if (tmpHit->SameHit(theStep)) {
69  currentHit = tmpHit;
70  }
71  }
72 
73  // If a hit wasn't found, create one.
74  if (!currentHit) {
75  currentHit = new EDepSim::HitSegment(fMaximumHitSagitta,
77  fLastHit = fHits->entries();
78  fHits->insert(currentHit);
79  }
80 
81  currentHit->AddStep(theStep);
82 
83  return true;
84 }
85 
86 void EDepSim::SegmentSD::EndOfEvent(G4HCofThisEvent*) { }
static QCString name
Definition: declinfo.cpp:673
#define EDepSimLog(outStream)
Definition: EDepSimLog.hh:717
int fLastHit
The last hit that was found.
void EndOfEvent(G4HCofThisEvent *)
G4bool ProcessHits(G4Step *, G4TouchableHistory *)
int fHCID
The hit collection id of fHits.
SegmentSD(G4String name)
virtual bool SameHit(G4Step *theStep)
EDepSim::HitSegment::HitSegmentCollection * fHits
#define EDepSimTrace(outStream)
Definition: EDepSimLog.hh:653
void Initialize(G4HCofThisEvent *)
static constexpr double mm
Definition: Units.h:65
G4THitsCollection< EDepSim::HitSegment > HitSegmentCollection
double fMaximumHitLength
The maximum allowed length;.
double fMaximumHitSagitta
The maximum allowed sagitta;.