Belle II Software  release-05-01-25
EKLMSensitiveDetector.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Timofey Uglov, Kirill Chilikin *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 /* Own header. */
12 #include <klm/eklm/simulation/EKLMSensitiveDetector.h>
13 
14 /* KLM headers. */
15 #include <klm/dbobjects/eklm/EKLMSimulationParameters.h>
16 
17 /* Belle 2 headers. */
18 #include <framework/database/DBObjPtr.h>
19 #include <framework/gearbox/Unit.h>
20 #include <framework/logging/Logger.h>
21 
22 /* Geant4 headers. */
23 #include <G4Step.hh>
24 
25 /* CLHEP headers. */
26 #include <CLHEP/Geometry/Point3D.h>
27 
28 using namespace Belle2;
29 
31  Simulation::SensitiveDetectorBase(name, Const::KLM),
32  m_ElementNumbers(&(EKLMElementNumbers::Instance()))
33 {
35  if (!simPar.isValid())
36  B2FATAL("EKLM simulation parameters are not available.");
37  m_ThresholdHitTime = simPar->getHitTimeThreshold();
38  StoreArray<MCParticle> particles;
39  m_SimHits.registerInDataStore();
40  particles.registerRelationTo(m_SimHits);
41  RelationArray particleToSimHits(particles, m_SimHits);
42  registerMCParticleRelation(particleToSimHits);
43 }
44 
46 {
47 }
48 
49 bool EKLM::EKLMSensitiveDetector::step(G4Step* aStep, G4TouchableHistory*)
50 {
51  const int stripLevel = 1;
52  int section, layer, sector, plane, strip, stripGlobal;
53  HepGeom::Point3D<double> gpos, lpos;
54  G4TouchableHandle hist = aStep->GetPreStepPoint()->GetTouchableHandle();
55  section = hist->GetVolume(stripLevel + 6)->GetCopyNo();
56  layer = hist->GetVolume(stripLevel + 5)->GetCopyNo();
57  sector = hist->GetVolume(stripLevel + 4)->GetCopyNo();
58  plane = hist->GetVolume(stripLevel + 3)->GetCopyNo();
59  strip = hist->GetVolume(stripLevel)->GetCopyNo();
60  stripGlobal = m_ElementNumbers->stripNumber(
61  section, layer, sector, plane, strip);
62  const G4double eDep = aStep->GetTotalEnergyDeposit();
63  /* Do not record hits without deposited energy. */
64  if (eDep <= 0)
65  return false;
66  const G4Track& track = * aStep->GetTrack();
67  const G4double hitTime = track.GetGlobalTime();
68  /* No time cut for background studies. */
69  if (hitTime > m_ThresholdHitTime) {
70  B2INFO("EKLMSensitiveDetector: "
71  " ALL HITS WITH TIME > hitTimeThreshold ARE DROPPED!!");
72  return false;
73  }
74  /* Hit position. */
75  gpos = 0.5 * (aStep->GetPostStepPoint()->GetPosition() +
76  aStep->GetPreStepPoint()->GetPosition());
77  lpos = hist->GetHistory()->GetTopTransform().TransformPoint(gpos);
78  /* Create step hit and store in to DataStore */
79  EKLMSimHit* hit = m_SimHits.appendNew();
80  CLHEP::Hep3Vector trackMomentum = track.GetMomentum();
81  hit->setMomentum(TLorentzVector(trackMomentum.x(), trackMomentum.y(),
82  trackMomentum.z(), track.GetTotalEnergy()));
83  hit->setTrackID(track.GetTrackID());
84  hit->setParentTrackID(track.GetParentID());
85  hit->setLocalPosition(lpos.x() / CLHEP::mm * Unit::mm,
86  lpos.y() / CLHEP::mm * Unit::mm,
87  lpos.z() / CLHEP::mm * Unit::mm);
88  hit->setPosition(gpos.x() / CLHEP::mm * Unit::mm,
89  gpos.y() / CLHEP::mm * Unit::mm,
90  gpos.z() / CLHEP::mm * Unit::mm);
91  hit->setEnergyDeposit(eDep);
92  hit->setPDG(track.GetDefinition()->GetPDGEncoding());
93  hit->setTime(hitTime);
94  hit->setStrip(strip);
95  hit->setPlane(plane);
96  hit->setSector(sector);
97  hit->setLayer(layer);
98  hit->setSection(section);
99  hit->setVolumeID(stripGlobal);
100  /* Relation. */
101  StoreArray<MCParticle> particles;
102  RelationArray particleToSimHits(particles, m_SimHits);
103  particleToSimHits.add(track.GetTrackID(), m_SimHits.getEntries() - 1);
104  return true;
105 }
106 
Belle2::RelationArray
Low-level class to create/modify relations between StoreArrays.
Definition: RelationArray.h:72
Belle2::EKLMElementNumbers
EKLM element numbers.
Definition: EKLMElementNumbers.h:34
Belle2::EKLM::EKLMSensitiveDetector::~EKLMSensitiveDetector
~EKLMSensitiveDetector()
Destructor.
Definition: EKLMSensitiveDetector.cc:45
Belle2::EKLM::EKLMSensitiveDetector::step
bool step(G4Step *aStep, G4TouchableHistory *history) override
Process each step and calculate variables for EKLMSimHit store EKLMSimHit.
Definition: EKLMSensitiveDetector.cc:49
Belle2::EKLM::EKLMSensitiveDetector::EKLMSensitiveDetector
EKLMSensitiveDetector(G4String name)
Constructor.
Definition: EKLMSensitiveDetector.cc:30
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::DBObjPtr
Class for accessing objects in the database.
Definition: DBObjPtr.h:31
Belle2::EKLMSimHit
Class EKLMSimHit stores information on particular Geant step; using information from TrackID and Pare...
Definition: EKLMSimHit.h:41
Belle2::EKLM::EKLMSensitiveDetector::m_SimHits
StoreArray< EKLMSimHit > m_SimHits
Simulation hits.
Definition: EKLMSensitiveDetector.h:70
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::RelationArray::add
void add(index_type from, index_type to, weight_type weight=1.0)
Add a new element to the relation.
Definition: RelationArray.h:291
Belle2::DBAccessorBase::isValid
bool isValid() const
Check whether a valid object was obtained from the database.
Definition: DBAccessorBase.h:75
Belle2::Unit::mm
static const double mm
[millimeters]
Definition: Unit.h:80
HepGeom::Point3D< double >
Belle2::StoreArray< MCParticle >
Belle2::Const
This class provides a set of constants for the framework.
Definition: Const.h:36
Belle2::EKLM::EKLMSensitiveDetector::m_ThresholdHitTime
G4double m_ThresholdHitTime
All hits with time large than m_ThresholdHitTime will be dropped.
Definition: EKLMSensitiveDetector.h:76