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 <beast/ph1sustr/simulation/SensitiveDetector.h>
10#include <beast/ph1sustr/dataobjects/Ph1sustrSimHit.h>
11
12#include <framework/datastore/StoreArray.h>
13#include <framework/datastore/RelationArray.h>
14
15#include <G4Track.hh>
16#include <G4Step.hh>
17
18namespace Belle2 {
24 namespace ph1sustr {
25
27 Simulation::SensitiveDetectorBase("Ph1sustrSensitiveDetector", Const::invalidDetector)
28 {
29 //Make sure all collections are registered
30 StoreArray<MCParticle> mcParticles;
32 RelationArray relMCSimHit(mcParticles, simHits);
33
34 //Register all collections we want to modify and require those we want to use
35 mcParticles.registerInDataStore();
36 simHits.registerInDataStore();
37 relMCSimHit.registerInDataStore();
38
39 //Register the Relation so that the TrackIDs get replaced by the actual
40 //MCParticle indices after simulating the events. This is needed as
41 //secondary particles might not be stored so everything relating to those
42 //particles will be attributed to the last saved mother particle
43 registerMCParticleRelation(relMCSimHit);
44 }
45
46 bool SensitiveDetector::step(G4Step* step, G4TouchableHistory*)
47 {
48 //Get Track information
49 const G4Track& track = *step->GetTrack();
50 const int trackID = track.GetTrackID();
51 const double depEnergy = step->GetTotalEnergyDeposit() * CLHEP::MeV;
52 //const int detNb = step->GetTrack()->GetVolume()->GetCopyNo();
53
54 //Ignore everything below 1eV
55 if (depEnergy < CLHEP::eV) return false;
56
57
58
59 //Get the datastore arrays
60 StoreArray<MCParticle> mcParticles;
62 RelationArray relMCSimHit(mcParticles, simHits);
63
64 const int hitIndex = simHits.getEntries();
65 StoreArray<Ph1sustrSimHit> Ph1sustrHits;
66 /*Ph1sustrSimHit* hit = Ph1sustrHits.appendNew(
67 depEnergy,
68 detNb
69 );*/
70
71 //Add Relation between SimHit and MCParticle with a weight of 1. Since
72 //the MCParticle index is not yet defined we use the trackID from Geant4
73 relMCSimHit.add(trackID, hitIndex, 1.0);
74
75 return true;
76 }
77
78 } //ph1sustr namespace
80} //Belle2 namespace
This class provides a set of constants for the framework.
Definition: Const.h:34
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.
static void registerMCParticleRelation(const std::string &name, RelationArray::EConsolidationAction ignoreAction=RelationArray::c_negativeWeight)
Register an relation involving MCParticles.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
bool step(G4Step *step, G4TouchableHistory *) override
Step processing method.
Abstract base class for different kinds of events.