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