Belle II Software  release-05-01-25
SensitiveDetector.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter, Igal Jaegle *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <beast/srsensor/simulation/SensitiveDetector.h>
12 #include <beast/srsensor/dataobjects/SrsensorSimHit.h>
13 
14 #include <framework/datastore/StoreArray.h>
15 #include <framework/datastore/RelationArray.h>
16 
17 #include <G4Track.hh>
18 #include <G4Step.hh>
19 
20 namespace Belle2 {
26  namespace srsensor {
27 
29  Simulation::SensitiveDetectorBase("SrsensorSensitiveDetector", Const::invalidDetector)
30  {
31  //Make sure all collections are registered
32  StoreArray<MCParticle> mcParticles;
33  StoreArray<SrsensorSimHit> simHits;
34  RelationArray relMCSimHit(mcParticles, simHits);
35 
36  //Register all collections we want to modify and require those we want to use
37  mcParticles.registerInDataStore();
38  simHits.registerInDataStore();
39  relMCSimHit.registerInDataStore();
40 
41  //Register the Relation so that the TrackIDs get replaced by the actual
42  //MCParticle indices after simulating the events. This is needed as
43  //secondary particles might not be stored so everything relating to those
44  //particles will be attributed to the last saved mother particle
45  registerMCParticleRelation(relMCSimHit);
46  }
47 
48  bool SensitiveDetector::step(G4Step* step, G4TouchableHistory*)
49  {
50  //Get Track information
51  const G4Track& track = *step->GetTrack();
52  const int trackID = track.GetTrackID();
53  const double depEnergy = step->GetTotalEnergyDeposit() * CLHEP::MeV;
54  const double nielEnergy = step->GetNonIonizingEnergyDeposit() * CLHEP::MeV;
55  const G4ThreeVector G4tkPos = step->GetTrack()->GetPosition();
56  float tkPos[3];
57  tkPos[0] = G4tkPos.x() * CLHEP::cm;
58  tkPos[1] = G4tkPos.y() * CLHEP::cm;
59  tkPos[2] = G4tkPos.z() * CLHEP::cm;
60  const G4ThreeVector G4tkMom = step->GetTrack()->GetMomentum();
61  float tkMom[3];
62  tkMom[0] = G4tkMom.x() * CLHEP::MeV;
63  tkMom[1] = G4tkMom.y() * CLHEP::MeV;
64  tkMom[2] = G4tkMom.z() * CLHEP::MeV;
65  const G4ThreeVector G4tkMomDir = step->GetTrack()->GetMomentumDirection();
66  float tkMomDir[3];
67  tkMomDir[0] = G4tkMomDir.x() * CLHEP::MeV;
68  tkMomDir[1] = G4tkMomDir.y() * CLHEP::MeV;
69  tkMomDir[2] = G4tkMomDir.z() * CLHEP::MeV;
70  const int tkPDG = step->GetTrack()->GetDefinition()->GetPDGEncoding();
71  const double tkKEnergy = step->GetTrack()->GetKineticEnergy();
72  const int detNb = step->GetTrack()->GetVolume()->GetCopyNo();
73  const double GlTime = step->GetPreStepPoint()->GetGlobalTime();
74  //Ignore everything below 1eV
75  if (depEnergy < CLHEP::eV) return false;
76 
77  //Get the datastore arrays
78  StoreArray<MCParticle> mcParticles;
80  RelationArray relMCSimHit(mcParticles, simHits);
81 
82  StoreArray<SrsensorSimHit> SrsensorHits;
83  SrsensorSimHit* hit = SrsensorHits.appendNew(
84  depEnergy,
85  nielEnergy,
86  tkPDG,
87  tkKEnergy,
88  detNb,
89  GlTime,
90  tkPos,
91  tkMom,
92  tkMomDir
93  );
94 
95  //Add Relation between SimHit and MCParticle with a weight of 1. Since
96  //the MCParticle index is not yet defined we use the trackID from Geant4
97  relMCSimHit.add(trackID, hit->getArrayIndex(), 1.0);
98 
99  return true;
100  }
101 
102  } //srsensor namespace
104 } //Belle2 namespace
Belle2::StoreArray::appendNew
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:256
Belle2::RelationArray
Low-level class to create/modify relations between StoreArrays.
Definition: RelationArray.h:72
Belle2::Simulation::SensitiveDetectorBase::registerMCParticleRelation
static void registerMCParticleRelation(const std::string &name, RelationArray::EConsolidationAction ignoreAction=RelationArray::c_negativeWeight)
Register an relation involving MCParticles.
Definition: SensitiveDetectorBase.cc:24
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::qcsmonitor::SensitiveDetector::step
bool step(G4Step *step, G4TouchableHistory *) override
Step processing method.
Definition: SensitiveDetector.cc:87
Belle2::StoreArray< MCParticle >
Belle2::srsensor::SensitiveDetector::SensitiveDetector
SensitiveDetector()
Constructor.
Definition: SensitiveDetector.cc:36
Belle2::SrsensorSimHit
ClassSrsensorSimHit - Geant4 simulated hit for the Srsensor detector.
Definition: SrsensorSimHit.h:40