Belle II Software development
SensitiveDetector.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <ir/simulation/SensitiveDetector.h>
10#include <ir/dataobjects/IRSimHit.h>
11
12#include <framework/logging/Logger.h>
13#include <framework/datastore/StoreArray.h>
14#include <framework/datastore/RelationArray.h>
15#include <framework/gearbox/Unit.h>
16
17#include <Math/Vector3D.h>
18
19// Geant4
20#include <G4Types.hh>
21#include <G4ThreeVector.hh>
22#include <G4Track.hh>
23#include <G4VPhysicalVolume.hh>
24#include <G4Step.hh>
25#include <G4UserLimits.hh>
26
27#include <string>
28
29using namespace std;
30
31namespace Belle2 {
36 namespace ir {
37
39 Simulation::SensitiveDetectorBase("IR ", Const::IR)
40 {
41 StoreArray<MCParticle> mcParticles;
42 StoreArray<IRSimHit> irSimHits;
43 RelationArray irSimHitRel(mcParticles, irSimHits);
44 registerMCParticleRelation(irSimHitRel);
45 }
46
47 G4bool SensitiveDetector::step(G4Step* step, G4TouchableHistory*)
48 {
49 const G4Track& track = *step->GetTrack();
50 const G4int trackID = track.GetTrackID();
51 const G4int partPDGCode = track.GetDefinition()->GetPDGEncoding();
52
53 const G4VPhysicalVolume& g4Volume = *track.GetVolume();
54 string Volname = g4Volume.GetName();
55
56 const G4double depEnergy = step->GetTotalEnergyDeposit() * Unit::MeV;
57
58 const G4StepPoint& preStep = *step->GetPreStepPoint();
59 const G4StepPoint& postStep = *step->GetPostStepPoint();
60 const G4ThreeVector& preStepPos = preStep.GetPosition();
61 const G4ThreeVector& postStepPos = postStep.GetPosition();
62 const G4ThreeVector momIn(preStep.GetMomentum());
63 const G4ThreeVector momOut(postStep.GetMomentum());
64 const G4ThreeVector preStepPosLocal = preStep.GetTouchableHandle()->GetHistory()->GetTopTransform().TransformPoint(preStepPos);
65 const G4ThreeVector postStepPosLocal = postStep.GetTouchableHandle()->GetHistory()->GetTopTransform().TransformPoint(postStepPos);
66 const G4ThreeVector momInLocal = preStep.GetTouchableHandle()->GetHistory()->GetTopTransform().TransformAxis(momIn);
67 const G4ThreeVector momOutLocal = preStep.GetTouchableHandle()->GetHistory()->GetTopTransform().TransformAxis(momOut);
68 ROOT::Math::XYZVector posInVec(preStepPosLocal.x() * Unit::mm, preStepPosLocal.y() * Unit::mm, preStepPosLocal.z() * Unit::mm);
69 ROOT::Math::XYZVector posOutVec(postStepPosLocal.x() * Unit::mm, postStepPosLocal.y() * Unit::mm, postStepPosLocal.z() * Unit::mm);
70 ROOT::Math::XYZVector momInVec(momInLocal.x() * Unit::MeV, momInLocal.y() * Unit::MeV, momInLocal.z() * Unit::MeV);
71 ROOT::Math::XYZVector momOutVec(momOutLocal.x() * Unit::MeV, momOutLocal.y() * Unit::MeV, momOutLocal.z() * Unit::MeV);
72
73 // B2INFO("Step in volume: " << g4Volume.GetName())
74 // check that user limits are set properly
75 G4UserLimits* userLimits = g4Volume.GetLogicalVolume()->GetUserLimits();
76 if (userLimits) {
77 B2DEBUG(100, "Volume " << g4Volume.GetName() << ": max. allowed step set to " << userLimits->GetMaxAllowedStep(track));
78 }
79
80 StoreArray<IRSimHit> irSimHits;
81 IRSimHit* simHit = irSimHits.appendNew(posInVec, momInVec, posOutVec, momOutVec, partPDGCode, depEnergy, Volname);
82
83 // add relation to MCParticles
84 StoreArray<MCParticle> mcParticles;
85 RelationArray irSimHitRel(mcParticles, irSimHits);
86 irSimHitRel.add(trackID, simHit->getArrayIndex());
87
88 return true;
89 }
90
91 }
93}
This class provides a set of constants for the framework.
Definition: Const.h:34
Class for saving raw hit data of the IR.
Definition: IRSimHit.h:22
Low-level class to create/modify relations between StoreArrays.
Definition: RelationArray.h:62
void add(index_type from, index_type to, weight_type weight=1.0)
Add a new element to the relation.
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
static void registerMCParticleRelation(const std::string &name, RelationArray::EConsolidationAction ignoreAction=RelationArray::c_negativeWeight)
Register an relation involving MCParticles.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
static const double mm
[millimeters]
Definition: Unit.h:70
static const double MeV
[megaelectronvolt]
Definition: Unit.h:114
bool step(G4Step *aStep, G4TouchableHistory *) override
Process each step and calculate variables defined in IRSimHit.
Abstract base class for different kinds of events.
STL namespace.