Belle II Software development
AWESOMESensitiveDetector.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/* Own header. */
10#include <online_book/awesome/simulation/AWESOMESensitiveDetector.h>
11
12/* Basf2 headers. */
13#include <framework/gearbox/Unit.h>
14
15/* Geant4 headers. */
16#include <G4StepPoint.hh>
17#include <G4Track.hh>
18
19/* CLHEP headers. */
20#include <CLHEP/Units/SystemOfUnits.h>
21#include <CLHEP/Vector/ThreeVector.h>
22
23using namespace Belle2;
24using namespace Belle2::AWESOME;
25
27 Simulation::SensitiveDetectorBase{"AwesomeSensitiveDetector", Const::EDetector::TEST}
28{
29 /* MCParticles must be optional, not required. */
30 m_MCParticles.isOptional();
31 /* Register the simulted hits and all the necessary relations in the datastore. */
32 m_SimHits.registerInDataStore();
33 m_MCParticles.registerRelationTo(m_SimHits);
34 /*
35 * Register the Relation so that the Geant4 TrackIDs get replaced by the actual
36 * MCParticle indices after simulating the events. This is needed as
37 * secondary particles might not be stored so everything relating to those
38 * particles will be attributed to the last saved mother particle.
39 */
41}
42
43bool AWESOMESensitiveDetector::step(G4Step* step, G4TouchableHistory*)
44{
45 /* Get some basic information from Geant4. */
46 const G4Track& track = *step->GetTrack();
47 const int trackID = track.GetTrackID();
48 const double energyDep = step->GetTotalEnergyDeposit() * Unit::MeV;
49 G4StepPoint* preStep = step->GetPreStepPoint();
50 G4StepPoint* postStep = step->GetPostStepPoint();
51 /* Ignore everything below 1 eV. */
52 if (energyDep < Unit::eV)
53 return false;
54 /*
55 * Compute other useful quantities to be stored.
56 * We must be sure that the quantities are stored using the proper Belle2 units:
57 * positions in cm, time in ns, etc.
58 */
59 const CLHEP::Hep3Vector position = 0.5 * (preStep->GetPosition() + postStep->GetPosition()) / CLHEP::cm; // Now in cm
60 const double time = 0.5 * (preStep->GetGlobalTime() + postStep->GetGlobalTime()); // Already in ns
61 /* Store the simulated hit. */
62 AWESOMESimHit* simHit = m_SimHits.appendNew();
63 simHit->setEnergyDep(energyDep);
64 simHit->setPosition(ROOT::Math::XYZVector(position));
65 simHit->setTime(time);
66 /*
67 * Add a relation between the current MCParticle and the simulated hit.
68 * Since the MCParticle index is not yet defined we use the trackID from Geant4.
69 */
70 m_MCParticlesToSimHits.add(trackID, simHit->getArrayIndex());
71 return true;
72}
A Geant4 simulated hit for the AWESOME detector.
void setEnergyDep(float energyDep)
Set the deposited energy.
void setPosition(ROOT::Math::XYZVector position)
Set the vector for position.
void setTime(float time)
Set the time.
StoreArray< AWESOMESimHit > m_SimHits
AWESOME simulated hits.
RelationArray m_MCParticlesToSimHits
Relation array between MCParticles and AWESOMESimHits.
StoreArray< MCParticle > m_MCParticles
MC particles.
bool step(G4Step *step, G4TouchableHistory *) override
Step processing method.
This class provides a set of constants for the framework.
Definition Const.h:34
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.
SensitiveDetectorBase(const std::string &name, Const::EDetector subdetector)
Create a new Sensitive detecor with a given name and belonging to a given subdetector.
static const double eV
[electronvolt]
Definition Unit.h:112
static const double MeV
[megaelectronvolt]
Definition Unit.h:114
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
Abstract base class for different kinds of events.