Belle II Software development
SensitiveDetector Class Reference

Class for ECL Sensitive Detector. More...

#include <SensitiveDetector.h>

Inheritance diagram for SensitiveDetector:
SensitiveDetectorBase

Public Member Functions

 SensitiveDetector (G4String, G4double, G4double)
 Constructor.
 
 ~SensitiveDetector ()
 Destructor.
 
void Initialize (G4HCofThisEvent *HCTE) override
 Register ECL hits collection into G4HCofThisEvent.
 
bool step (G4Step *aStep, G4TouchableHistory *history) override
 Process each step and calculate variables defined in ECLHit.
 
void EndOfEvent (G4HCofThisEvent *eventHC) override
 Do what you want to do at the end of each event.
 

Static Public Member Functions

static const std::map< std::string, RelationArray::EConsolidationAction > & getMCParticleRelations ()
 Return a list of all registered Relations with MCParticles.
 
static void setActive (bool activeStatus)
 Enable/Disable all Sensitive Detectors.
 
static void registerMCParticleRelation (const std::string &name, RelationArray::EConsolidationAction ignoreAction=RelationArray::c_negativeWeight)
 Register an relation involving MCParticles.
 
static void registerMCParticleRelation (const RelationArray &relation, RelationArray::EConsolidationAction ignoreAction=RelationArray::c_negativeWeight)
 Overload to make it easer to register MCParticle relations.
 

Private Member Functions

double GetHadronIntensityFromDEDX (double)
 Evaluates hadron scintillation component emission function.
 
int saveSimHit (G4int, G4int, G4int, G4double, G4double, const G4ThreeVector &, const G4ThreeVector &, double)
 Create ECLSimHit and ECLHit and relations from MCParticle and put them in datastore.
 
virtual bool ProcessHits (G4Step *aStep, G4TouchableHistory *aROhist)
 Check if recording hits is enabled and if so call step() and set the correct MCParticle flag.
 

Private Attributes

TGraph * m_HadronEmissionFunction = nullptr
 Graph for hadron scintillation component emission function.
 
G4EmCalculator m_emCal
 Used to get dE/dx for pulse shape simulations.
 
StoreArray< ECLSimHitm_eclSimHits
 ECLSimHit array.
 
StoreArray< ECLHitm_eclHits
 ECLHit array.
 
StoreArray< MCParticlem_mcParticles
 MCParticle array.
 
RelationArray m_eclSimHitRel
 MCParticle to ECLSimHit relation array.
 
RelationArray m_eclHitRel
 MCParticle to ECLHit relation array.
 
int m_trackID
 current track id
 
double m_WeightedTime
 average track time weighted by energy deposition
 
double m_energyDeposit
 total energy deposited in a volume by a track
 
double m_hadronenergyDeposit
 energy deposited resulting in hadronic scint component
 
G4ThreeVector m_WeightedPos
 average track position weighted by energy deposition
 
G4ThreeVector m_momentum
 initial momentum of track before energy deposition inside sensitive volume
 
DBObjPtr< ECLHadronComponentEmissionFunctionm_ECLHadronComponentEmissionFunction
 Hadron Component Emission Function.
 
Const::EDetector m_subdetector
 Subdetector the class belongs to.
 

Static Private Attributes

static std::map< std::string, RelationArray::EConsolidationActions_mcRelations
 Static set holding all relations which have to be updated at the end of the Event.
 
static bool s_active
 Static bool which indicates wether recording of hits is enabled.
 

Detailed Description

Class for ECL Sensitive Detector.

Definition at line 38 of file SensitiveDetector.h.

Constructor & Destructor Documentation

◆ ~SensitiveDetector()

Destructor.

Definition at line 51 of file SensitiveDetector.cc.

52{
53}

Member Function Documentation

◆ EndOfEvent()

void EndOfEvent ( G4HCofThisEvent *  eventHC)
override

Do what you want to do at the end of each event.

Definition at line 145 of file SensitiveDetector.cc.

146{
147 struct hit_t { double e, t; };
148 map<int, hit_t> a;
149
150 struct thit_t { int tid, hid; };
151 vector<thit_t> tr;
152
154
155 for (const ECLSimHit& t : m_eclSimHits) {
156 double tof = t.getFlightTime();
157 if (tof >= 8000.0 || tof < -8000.0) continue;
158 int TimeIndex = (tof + 8000.0) * (1. / 100);
159 int cellId = t.getCellId() - 1;
160 int key = cellId * 160 + TimeIndex;
161 double edep = t.getEnergyDep();
162 double tsen = tof + eclp->time2sensor(cellId, t.getPosition()); // flight time to diode sensor
163
164 hit_t& h = a[key];
165
166 int trkid = t.getTrackId();
167 tr.push_back({trkid, key});
168
169 double old_edep = h.e, old_tsen = h.t;
170 double new_edep = old_edep + edep;
171
172 h.e = new_edep;
173 h.t = (old_edep * old_tsen + edep * tsen) / new_edep;
174 }
175
176 int hitNum = m_eclHits.getEntries();
177 // assert(hitNum == 0);
178 for (pair<int, hit_t> t : a) {
179 int key = t.first, cellId = key / 160;
180 for (const thit_t& s : tr)
181 if (s.hid == key) m_eclHitRel.add(s.tid, hitNum);
182 const hit_t& h = t.second;
183 m_eclHits.appendNew(cellId + 1, h.e, h.t); hitNum++;
184 }
185}
The Class for ECL Geometry Parameters.
static ECLGeometryPar * Instance()
Static method to get a reference to the ECLGeometryPar instance.
double time2sensor(int cid, const G4ThreeVector &hit_pos)
function to calculate flight time to diode sensor
StoreArray< ECLSimHit > m_eclSimHits
ECLSimHit array.
RelationArray m_eclHitRel
MCParticle to ECLHit relation array.
StoreArray< ECLHit > m_eclHits
ECLHit array.
void add(index_type from, index_type to, weight_type weight=1.0)
Add a new element to the relation.

◆ GetHadronIntensityFromDEDX()

double GetHadronIntensityFromDEDX ( double  x)
private

Evaluates hadron scintillation component emission function.

Definition at line 61 of file SensitiveDetector.cc.

62{
63 if (x < 2) return 0;
64 if (x > 232) return m_HadronEmissionFunction->Eval(232);
65 return m_HadronEmissionFunction->Eval(x);
66}
TGraph * m_HadronEmissionFunction
Graph for hadron scintillation component emission function.

◆ getMCParticleRelations()

static const std::map< std::string, RelationArray::EConsolidationAction > & getMCParticleRelations ( )
inlinestaticinherited

Return a list of all registered Relations with MCParticles.

Definition at line 42 of file SensitiveDetectorBase.h.

42{ return s_mcRelations; }
static std::map< std::string, RelationArray::EConsolidationAction > s_mcRelations
Static set holding all relations which have to be updated at the end of the Event.

◆ Initialize()

void Initialize ( G4HCofThisEvent *  HCTE)
override

Register ECL hits collection into G4HCofThisEvent.

Definition at line 55 of file SensitiveDetector.cc.

56{
57}

◆ ProcessHits()

bool ProcessHits ( G4Step *  aStep,
G4TouchableHistory *  aROhist 
)
inlineprivatevirtualinherited

Check if recording hits is enabled and if so call step() and set the correct MCParticle flag.

Called by Geant4 for each step inside the sensitive volumes attached

Definition at line 94 of file SensitiveDetectorBase.h.

95 {
96 if (!s_active) return false;
97 bool result = step(aStep, aROhist);
98 // Do not include hits from invalid detector (beast,teastbeam, etc.)
99 if (result && (m_subdetector != Const::invalidDetector)) TrackInfo::getInfo(*aStep->GetTrack()).addSeenInDetector(m_subdetector);
100 return result;
101 }
virtual bool step(G4Step *step, G4TouchableHistory *ROhist)=0
Process a Geant4 step in any of the sensitive volumes attached to this sensitive detector.
Const::EDetector m_subdetector
Subdetector the class belongs to.
static bool s_active
Static bool which indicates wether recording of hits is enabled.
static Payload getInfo(Carrier &obj)
Static function to just return UserInformation attached to the obj of type Carrier.
Definition: UserInfo.h:100

◆ registerMCParticleRelation() [1/2]

static void registerMCParticleRelation ( const RelationArray relation,
RelationArray::EConsolidationAction  ignoreAction = RelationArray::c_negativeWeight 
)
inlinestaticinherited

Overload to make it easer to register MCParticle relations.

Parameters
relationRelationArray to register
ignoreAction

Definition at line 66 of file SensitiveDetectorBase.h.

67 { registerMCParticleRelation(relation.getName(), ignoreAction); }
static void registerMCParticleRelation(const std::string &name, RelationArray::EConsolidationAction ignoreAction=RelationArray::c_negativeWeight)
Register an relation involving MCParticles.

◆ registerMCParticleRelation() [2/2]

void registerMCParticleRelation ( const std::string &  name,
RelationArray::EConsolidationAction  ignoreAction = RelationArray::c_negativeWeight 
)
staticinherited

Register an relation involving MCParticles.

All Relations which point from an MCParticle to something have to be registered with addMCParticleRelation() because the index of the MCParticles might change at the end of the event. During simulation, the TrackID should be used as index of the MCParticle

Parameters
nameName of the relation to register
ignoreAction

Definition at line 22 of file SensitiveDetectorBase.cc.

23 {
24 std::pair<std::map<std::string, RelationArray::EConsolidationAction>::iterator, bool> insert = s_mcRelations.insert(std::make_pair(
25 name, ignoreAction));
26 //If the relation already exists and the ignoreAction is different we do have a problem
27 if (!insert.second && insert.first->second != ignoreAction) {
28 B2FATAL("MCParticle Relation " << name << " already registered with different ignore action.");
29 }
30 }

◆ saveSimHit()

int saveSimHit ( G4int  cellId,
G4int  trackID,
G4int  pid,
G4double  tof,
G4double  edep,
const G4ThreeVector &  mom,
const G4ThreeVector &  pos,
double  Hadronedep 
)
private

Create ECLSimHit and ECLHit and relations from MCParticle and put them in datastore.

Definition at line 187 of file SensitiveDetector.cc.

189{
190 int simhitNumber = m_eclSimHits.getEntries();
191 m_eclSimHitRel.add(trackID, simhitNumber);
192 tof *= 1 / CLHEP::ns;
193 edep *= 1 / CLHEP::GeV;
194 m_eclSimHits.appendNew(cellId + 1, trackID, pid, tof, edep, mom * (1 / CLHEP::GeV), pos * (1 / CLHEP::cm), Hadronedep);
195 return simhitNumber;
196}
RelationArray m_eclSimHitRel
MCParticle to ECLSimHit relation array.

◆ setActive()

static void setActive ( bool  activeStatus)
inlinestaticinherited

Enable/Disable all Sensitive Detectors.

By default, all sensitive detectors won't create hits to make it possible to use the Geant4 Navigator for non-simulation purposes. Only during simulation the sensitive detectors will be enabled to record hits

Parameters
activeStatusbool to indicate wether hits should be recorded

Definition at line 50 of file SensitiveDetectorBase.h.

50{ s_active = activeStatus; }

◆ step()

bool step ( G4Step *  aStep,
G4TouchableHistory *  history 
)
overridevirtual

Process each step and calculate variables defined in ECLHit.

Implements SensitiveDetectorBase.

Definition at line 84 of file SensitiveDetector.cc.

85{
86 //
87 double preKineticEnergy = aStep->GetPreStepPoint()->GetKineticEnergy();
88 double postKineticEnergy = aStep->GetPostStepPoint()->GetKineticEnergy();
89 double avgKineticEnergy = 0.5 * (preKineticEnergy + postKineticEnergy);
90 const G4ParticleDefinition* StepParticleDefinition = aStep->GetTrack()->GetParticleDefinition();
91 G4Material* StepMaterial = aStep->GetTrack()->GetMaterial();
92 const double CsIDensity = 4.51; //gcm^-3
93 double ELE_DEDX = m_emCal.ComputeDEDX(avgKineticEnergy, StepParticleDefinition, "eIoni",
94 StepMaterial) / CLHEP::MeV * CLHEP::cm / (CsIDensity);
95 double MU_DEDX = m_emCal.ComputeDEDX(avgKineticEnergy, StepParticleDefinition, "muIoni",
96 StepMaterial) / CLHEP::MeV * CLHEP::cm / (CsIDensity);
97 double HAD_DEDX = m_emCal.ComputeDEDX(avgKineticEnergy, StepParticleDefinition, "hIoni",
98 StepMaterial) / CLHEP::MeV * CLHEP::cm / (CsIDensity);
99 double ION_DEDX = m_emCal.ComputeDEDX(avgKineticEnergy, StepParticleDefinition, "ionIoni",
100 StepMaterial) / CLHEP::MeV * CLHEP::cm / (CsIDensity);
101 G4double DEDX_val = ELE_DEDX + MU_DEDX + HAD_DEDX + ION_DEDX; //Ionization dE/dx for any particle type
102
103 G4double edep = aStep->GetTotalEnergyDeposit();
104 double LightOutputCorrection = GetCsITlScintillationEfficiency(DEDX_val);
105 edep *= LightOutputCorrection;
106 const G4StepPoint& s0 = *aStep->GetPreStepPoint();
107 const G4StepPoint& s1 = *aStep->GetPostStepPoint();
108 const G4Track& track = *aStep->GetTrack();
109
110 if (m_trackID != track.GetTrackID()) { //TrackID changed, store track information
111 m_trackID = track.GetTrackID();
112 m_momentum = s0.GetMomentum(); // Get momentum
113 //Reset track parameters
114 m_energyDeposit = 0;
115 m_WeightedTime = 0;
116 m_WeightedPos.set(0, 0, 0);
118 }
119 //Update energy deposit
120 G4double hedep = 0.5 * edep; // half of energy deposition -- for averaging purpose
121 m_energyDeposit += edep;
122 m_WeightedTime += (s0.GetGlobalTime() + s1.GetGlobalTime()) * hedep;
123 m_WeightedPos += (s0.GetPosition() + s1.GetPosition()) * hedep;
124 //
125 //Calculate hadronic scintillation component intensity from dEdx
126 m_hadronenergyDeposit += (edep / CLHEP::GeV) * GetHadronIntensityFromDEDX(DEDX_val);
127 //
128 //Save Hit if track leaves volume or is killed
129 if (track.GetNextVolume() != track.GetVolume() || track.GetTrackStatus() >= fStopAndKill) {
130 if (m_energyDeposit > 0.0) {
132 G4int cellID = eclp->TouchableToCellID(s0.GetTouchable());
133 G4double dTotalEnergy = 1 / m_energyDeposit;
134 m_WeightedTime *= dTotalEnergy;
135 m_WeightedPos *= dTotalEnergy;
136 int pdgCode = track.GetDefinition()->GetPDGEncoding();
138 }
139 //Reset TrackID
140 m_trackID = 0;
141 }
142 return true;
143}
int TouchableToCellID(const G4VTouchable *)
The same as above but without sanity checks.
double m_energyDeposit
total energy deposited in a volume by a track
double GetHadronIntensityFromDEDX(double)
Evaluates hadron scintillation component emission function.
double m_hadronenergyDeposit
energy deposited resulting in hadronic scint component
G4ThreeVector m_momentum
initial momentum of track before energy deposition inside sensitive volume
G4EmCalculator m_emCal
Used to get dE/dx for pulse shape simulations.
double m_WeightedTime
average track time weighted by energy deposition
int saveSimHit(G4int, G4int, G4int, G4double, G4double, const G4ThreeVector &, const G4ThreeVector &, double)
Create ECLSimHit and ECLHit and relations from MCParticle and put them in datastore.
G4ThreeVector m_WeightedPos
average track position weighted by energy deposition

Member Data Documentation

◆ m_ECLHadronComponentEmissionFunction

DBObjPtr<ECLHadronComponentEmissionFunction> m_ECLHadronComponentEmissionFunction
private

Hadron Component Emission Function.

Definition at line 76 of file SensitiveDetector.h.

◆ m_eclHitRel

RelationArray m_eclHitRel
private

MCParticle to ECLHit relation array.

Definition at line 69 of file SensitiveDetector.h.

◆ m_eclHits

StoreArray<ECLHit> m_eclHits
private

ECLHit array.

Definition at line 66 of file SensitiveDetector.h.

◆ m_eclSimHitRel

RelationArray m_eclSimHitRel
private

MCParticle to ECLSimHit relation array.

Definition at line 68 of file SensitiveDetector.h.

◆ m_eclSimHits

StoreArray<ECLSimHit> m_eclSimHits
private

ECLSimHit array.

Definition at line 65 of file SensitiveDetector.h.

◆ m_emCal

G4EmCalculator m_emCal
private

Used to get dE/dx for pulse shape simulations.

Definition at line 63 of file SensitiveDetector.h.

◆ m_energyDeposit

double m_energyDeposit
private

total energy deposited in a volume by a track

Definition at line 72 of file SensitiveDetector.h.

◆ m_HadronEmissionFunction

TGraph* m_HadronEmissionFunction = nullptr
private

Graph for hadron scintillation component emission function.

Definition at line 56 of file SensitiveDetector.h.

◆ m_hadronenergyDeposit

double m_hadronenergyDeposit
private

energy deposited resulting in hadronic scint component

Definition at line 73 of file SensitiveDetector.h.

◆ m_mcParticles

StoreArray<MCParticle> m_mcParticles
private

MCParticle array.

Definition at line 67 of file SensitiveDetector.h.

◆ m_momentum

G4ThreeVector m_momentum
private

initial momentum of track before energy deposition inside sensitive volume

Definition at line 75 of file SensitiveDetector.h.

◆ m_subdetector

Const::EDetector m_subdetector
privateinherited

Subdetector the class belongs to.

Definition at line 91 of file SensitiveDetectorBase.h.

◆ m_trackID

int m_trackID
private

current track id

Definition at line 70 of file SensitiveDetector.h.

◆ m_WeightedPos

G4ThreeVector m_WeightedPos
private

average track position weighted by energy deposition

Definition at line 74 of file SensitiveDetector.h.

◆ m_WeightedTime

double m_WeightedTime
private

average track time weighted by energy deposition

Definition at line 71 of file SensitiveDetector.h.

◆ s_active

bool s_active
staticprivateinherited

Static bool which indicates wether recording of hits is enabled.

Definition at line 89 of file SensitiveDetectorBase.h.

◆ s_mcRelations

map< string, RelationArray::EConsolidationAction > s_mcRelations
staticprivateinherited

Static set holding all relations which have to be updated at the end of the Event.

Definition at line 87 of file SensitiveDetectorBase.h.


The documentation for this class was generated from the following files: