Belle II Software development
SensitiveAero.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 <arich/simulation/SensitiveAero.h>
10#include <arich/dataobjects/ARICHAeroHit.h>
11
12#include <G4Step.hh>
13#include <G4Track.hh>
14
15#include <framework/datastore/StoreArray.h>
16#include <framework/datastore/RelationArray.h>
17#include <framework/gearbox/Unit.h>
18
19#include <Math/Vector3D.h>
20
21using namespace std;
22
23namespace Belle2 {
28 namespace arich {
29
31 Simulation::SensitiveDetectorBase("ARICH", Const::ARICH)
32 {
33
34 // registration of store arrays and relations
35
36 StoreArray<MCParticle> mcParticles;
38 aeroHits.registerInDataStore();
39 mcParticles.registerRelationTo(aeroHits);
40
41 // additional registration of MCParticle relation (required for correct relations)
42
43 RelationArray relation(mcParticles, aeroHits);
45
46 }
47
48 bool SensitiveAero::step(G4Step* aStep, G4TouchableHistory*)
49 {
50 // Get track parameters
51
52 G4Track* aTrack = aStep->GetTrack();
53
54 G4StepPoint* PostPosition = aStep->GetPostStepPoint();
55 G4ThreeVector worldPosition = PostPosition->GetPosition();
56 G4ParticleDefinition* particle = aTrack->GetDefinition();
57 G4double PDGCharge = particle->GetPDGCharge();
58 G4ThreeVector momentum = PostPosition->GetMomentum();
59
60 // Save only tracks of charged particles
61 if (PDGCharge == 0) return (true);
62
63 // Track parameters are saved at the entrance in aerogel
64
65 if ((PostPosition->GetStepStatus() == fGeomBoundary) && (momentum.z() > 0.0)) {
66
67 /* B2INFO ("SensAero: " << aTrack->GetDefinition()->GetParticleName()
68 << " " << aTrack->GetTrackID()
69 << " " << aTrack->GetParentID()
70 << " " << G4BestUnit(worldPosition,"Length")
71 << " " << G4BestUnit(aTrack->GetMomentum(), "Energy")
72 << " " << G4BestUnit(aTrack->GetGlobalTime(), "Time")
73 << " Edep is " << G4BestUnit(aStep->GetTotalEnergyDeposit(),"Energy"));
74 */
75
76 int trackID = aTrack->GetTrackID();
77 int PDGEncoding = particle->GetPDGEncoding();
78
79 ROOT::Math::XYZVector TPosition(worldPosition.x() * Unit::mm, worldPosition.y() * Unit::mm, worldPosition.z() * Unit::mm);
80 ROOT::Math::XYZVector TMomentum(momentum.x() * Unit::MeV, momentum.y() * Unit::MeV, momentum.z() * Unit::MeV);
81
82 // write the hit in datastore"
84 ARICHAeroHit* aeroHit = aeroHits.appendNew(PDGEncoding, TPosition, TMomentum);
85
86 // Create relation to MCParticle
87 StoreArray<MCParticle> mcParticles;
88 RelationArray rel(mcParticles, aeroHits);
89 rel.add(trackID, aeroHit->getArrayIndex());
90
91 }
92
93 return true;
94
95 }
96
97 } // end of namespace arich
99} // end of namespace Belle2
Datastore class that holds information on track parameters at the entrance in aerogel.
Definition: ARICHAeroHit.h:27
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
@ c_deleteElement
Delete the whole relation element if the original element got re-attributed.
Definition: RelationArray.h:81
void add(index_type from, index_type to, weight_type weight=1.0)
Add a new element to the relation.
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.
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
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
Definition: StoreArray.h:140
static const double mm
[millimeters]
Definition: Unit.h:70
static const double MeV
[megaelectronvolt]
Definition: Unit.h:114
bool step(G4Step *aStep, G4TouchableHistory *) override
Process each step and calculate variables defined in PXDSimHit.
Abstract base class for different kinds of events.
STL namespace.