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/ph1bpipe/simulation/SensitiveDetector.h>
12 #include <beast/ph1bpipe/dataobjects/Ph1bpipeSimHit.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 ph1bpipe {
27 
29  Simulation::SensitiveDetectorBase("Ph1bpipeSensitiveDetector", Const::invalidDetector)
30  {
31  //Make sure all collections are registered
32  StoreArray<MCParticle> mcParticles;
33  StoreArray<Ph1bpipeSimHit> 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 int detNb = step->GetTrack()->GetVolume()->GetCopyNo();
55 
56  //Ignore everything below 1eV
57  if (depEnergy < CLHEP::eV) return false;
58 
59 
60 
61  //Get the datastore arrays
62  StoreArray<MCParticle> mcParticles;
64  RelationArray relMCSimHit(mcParticles, simHits);
65 
66  const int hitIndex = simHits.getEntries();
67  StoreArray<Ph1bpipeSimHit> Ph1bpipeHits;
68  /*Ph1bpipeSimHit* hit = Ph1bpipeHits.appendNew(
69  depEnergy,
70  detNb
71  );*/
72 
73  //Add Relation between SimHit and MCParticle with a weight of 1. Since
74  //the MCParticle index is not yet defined we use the trackID from Geant4
75  relMCSimHit.add(trackID, hitIndex, 1.0);
76 
77  return true;
78  }
79 
80  } //ph1bpipe namespace
82 } //Belle2 namespace
Belle2::RelationArray
Low-level class to create/modify relations between StoreArrays.
Definition: RelationArray.h:72
Belle2::ph1bpipe::SensitiveDetector::SensitiveDetector
SensitiveDetector()
Constructor.
Definition: SensitiveDetector.cc:36
Belle2::microtpc::SensitiveDetector::step
bool step(G4Step *step, G4TouchableHistory *) override
Step processing method.
Definition: SensitiveDetector.cc:60
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::StoreArray< MCParticle >
Belle2::StoreArray::getEntries
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:226