BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSSDThinThing.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2022.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#include "BDSDebug.hh"
20#include "BDSGlobalConstants.hh"
21#include "BDSSDThinThing.hh"
22#include "BDSTrajectoryOptions.hh"
23#include "BDSTrajectoryPoint.hh"
24#include "BDSUtilities.hh"
25
26#include "G4String.hh"
27#include "G4SDManager.hh"
28#include "G4Step.hh"
29#include "G4StepPoint.hh"
30#include "G4ThreeVector.hh"
31#include "G4Track.hh"
32#include "G4Types.hh"
33#include "G4VHit.hh"
34
35#include <vector>
36
37BDSSDThinThing::BDSSDThinThing(const G4String& name,
38 const BDS::TrajectoryOptions& trajectoryOptionsIn):
39 BDSSensitiveDetector("thinthing/" + name),
40 thinThingCollection(nullptr),
41 itsCollectionName(name),
42 itsHCID(-1),
43 storeTrajectoryLocal(trajectoryOptionsIn.storeLocal),
44 storeTrajectoryLinks(trajectoryOptionsIn.storeLinks),
45 storeTrajectoryIon(trajectoryOptionsIn.storeIon)
46{
47 collectionName.insert(name);
48}
49
50BDSSDThinThing::~BDSSDThinThing()
51{;}
52
53void BDSSDThinThing::Initialize(G4HCofThisEvent* HCE)
54{
55 // Create ThinThing hits collection
57
58 // Record id for use in EventAction to save time - slow string lookup by collection name
59 if (itsHCID < 0)
60 {itsHCID = G4SDManager::GetSDMpointer()->GetCollectionID(thinThingCollection);}
61 HCE->AddHitsCollection(itsHCID, thinThingCollection);
62
63#ifdef BDSDEBUG
64 G4cout << __METHOD_NAME__ << "Hits Collection ID: " << itsHCID << G4endl;
65#endif
66}
67
68G4bool BDSSDThinThing::ProcessHits(G4Step* step, G4TouchableHistory* rOHist)
69{
70 std::vector<G4VHit*> hits;
71 return ProcessHitsOrdered(step, rOHist, hits);
72}
73
75 G4TouchableHistory* /*rOHist*/,
76 const std::vector<G4VHit*>& /*hits*/)
77{
78 // primary filter applied outside this
79
80 // if scattering point
81 G4bool condition1 = BDSTrajectoryPoint::IsScatteringPoint(step);
82 // if finite delta p
83 G4bool condition2 = BDS::IsFinite(step->GetPostStepPoint()->GetMomentumDirection() - step->GetPreStepPoint()->GetMomentumDirection());
84 // if detla E
85 G4bool condition3 = BDS::IsFinite(step->GetTotalEnergyDeposit());
86
87 if (condition1 || condition2 || condition3)
88 {
89 G4Track* track = step->GetTrack();
90 G4int turnsTaken = BDSGlobalConstants::Instance()->TurnsTaken();
91 BDSHitThinThing* hit = new BDSHitThinThing(track->GetParticleDefinition()->GetPDGEncoding(),
92 track->GetTrackID(),
93 track->GetParentID(),
94 turnsTaken,
95 new BDSTrajectoryPoint(step,
96 storeTrajectoryLocal,
97 storeTrajectoryLinks,
98 storeTrajectoryIon));
99 thinThingCollection->insert(hit);
100 return true;
101 }
102 else
103 {return false;}
104}
105
106G4VHit* BDSSDThinThing::last() const
107{
108 auto hitsVector = thinThingCollection->GetVector();
109 if (hitsVector->empty())
110 {return nullptr;}
111 else
112 {
113 BDSHitThinThing* lastHit = hitsVector->back();
114 return static_cast<G4VHit*>(lastHit);
115 }
116}
static BDSGlobalConstants * Instance()
Access method.
A hit if a particle lost energy in a thin object.
virtual G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *rOHist) override
virtual G4bool ProcessHitsOrdered(G4Step *step, G4TouchableHistory *rOHist, const std::vector< G4VHit * > &hits) override
BDSHitsCollectionThinThing * thinThingCollection
The hits collection for this sensitive detector class that's owned by each instance.
G4String itsCollectionName
The name of the hits collection that's created and registered.
virtual G4VHit * last() const override
Return the last collimator hit.
virtual void Initialize(G4HCofThisEvent *HCE) override
BDSSDThinThing(const G4String &name, const BDS::TrajectoryOptions &trajectoryOptionsIn)
Include unique name for each instance.
Virtual class to define interface for ordered multi-sensitive detector.
A Point in a trajectory with extra information.
G4bool IsScatteringPoint() const
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())