Belle II Software development
SensitiveDiode Class Reference

Class for ECL Sensitive Detector. More...

#include <SensitiveDetector.h>

Inheritance diagram for SensitiveDiode:
SensitiveDetectorBase

Classes

struct  hit_t
 simple hit structure More...
 

Public Member Functions

 SensitiveDiode (const G4String &)
 Constructor.
 
 ~SensitiveDiode ()
 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

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

ECLGeometryParm_eclp
 pointer to ECLGeometryPar
 
int m_trackID
 current track id
 
double m_tsum
 average track time weighted by energy deposition
 
double m_esum
 total energy deposited in a volume by a track
 
std::vector< hit_tm_hits
 array of hits
 
std::vector< int > m_cells
 array of hitted crystals
 
StoreArray< ECLHitm_eclHits
 ECLHit array.
 
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 80 of file SensitiveDetector.h.

Constructor & Destructor Documentation

◆ SensitiveDiode()

SensitiveDiode ( const G4String &  name)
explicit

Constructor.

Definition at line 198 of file SensitiveDetector.cc.

198 :
199 Simulation::SensitiveDetectorBase(name, Const::ECL)
200{
201 m_eclHits.registerInDataStore("ECLDiodeHits");
203 m_trackID = -1;
204 m_tsum = 0;
205 m_esum = 0;
206}
static ECLGeometryPar * Instance()
Static method to get a reference to the ECLGeometryPar instance.
int m_trackID
current track id
double m_tsum
average track time weighted by energy deposition
double m_esum
total energy deposited in a volume by a track
ECLGeometryPar * m_eclp
pointer to ECLGeometryPar
StoreArray< ECLHit > m_eclHits
ECLHit array.

◆ ~SensitiveDiode()

Destructor.

Definition at line 208 of file SensitiveDetector.cc.

209{
210}

Member Function Documentation

◆ EndOfEvent()

void EndOfEvent ( G4HCofThisEvent *  eventHC)
override

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

Definition at line 274 of file SensitiveDetector.cc.

275{
276 struct dep_t {double e, t;};
277 vector<dep_t> v;
278 for (int cellId : m_cells) {
279 v.clear();
280 for (const hit_t& h : m_hits) {
281 if (cellId == h.cellId) v.push_back({h.e, h.t});
282 }
283
284 double esum = 0, tsum = 0;
285 for (const dep_t& t : v) {
286 esum += t.e;
287 tsum += t.t * t.e;
288 }
289 tsum /= esum;
290
291 tsum *= 1 / CLHEP::ns;
292 esum *= 1 / CLHEP::GeV;
293 m_eclHits.appendNew(cellId + 1, esum, tsum);
294
295
296 // cout<<"DD: "<<cellId<<" "<<esum<<" "<<tsum<<" +- "<<sqrt(tsum2)<<endl;
297
298 // sort(v.begin(),v.end(),[](const dep_t &a, const dep_t &b){return a.t<b.t;});
299 // cout<<"DD: "<<cellId<<" ";
300 // for(const dep_t &t: v)cout<<t.e<<" MeV "<<t.t<<" nsec, ";
301 // cout<<"\n";
302
303 }
304}
std::vector< hit_t > m_hits
array of hits
std::vector< int > m_cells
array of hitted crystals

◆ 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 212 of file SensitiveDetector.cc.

213{
214 m_hits.clear();
215 m_cells.clear();
216}

◆ 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 }

◆ 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 221 of file SensitiveDetector.cc.

222{
223 const G4StepPoint& s0 = *aStep->GetPreStepPoint();
224 const G4StepPoint& s1 = *aStep->GetPostStepPoint();
225 const G4Track& track = *aStep->GetTrack();
226
227 if (m_trackID != track.GetTrackID()) { //TrackID changed, store track informations
228 m_trackID = track.GetTrackID();
229 //Reset track parameters
230 m_esum = 0;
231 m_tsum = 0;
232 }
233 //Update energy deposit
234 G4double edep = aStep->GetTotalEnergyDeposit();
235 m_esum += edep;
236 m_tsum += (s0.GetGlobalTime() + s1.GetGlobalTime()) * edep;
237 //Save Hit if track leaves volume or is killed
238 if (track.GetNextVolume() != track.GetVolume() ||
239 track.GetTrackStatus() >= fStopAndKill) {
240 if (m_esum > 0.0) {
241 int cellID = m_eclp->TouchableDiodeToCellID(s0.GetTouchable());
242 m_tsum /= 2 * m_esum; // average
243 m_hits.push_back({cellID, m_esum, m_tsum});
244 auto it = find(m_cells.begin(), m_cells.end(), cellID);
245 if (it == m_cells.end())m_cells.push_back(cellID);
246#if 0
247 const G4ThreeVector& p = s0.GetPosition();
248 G4ThreeVector cp = 10 * m_eclp->getCrystalPos(cellID);
249 G4ThreeVector cv = m_eclp->getCrystalVec(cellID);
250 double dz = (p - cp) * cv;
251 double rho = ((p - cp) - dz * cv).perp();
252 cout << "diff " << cellID << " " << dz << " " << rho << endl;
253 if (abs(dz - 150) > 1) {
254 const G4VTouchable* touch = s0.GetTouchable();
255 const G4NavigationHistory* h = touch->GetHistory();
256 int hd = h->GetDepth();
257 int i1 = h->GetReplicaNo(hd - 1); // index of each volume is set at physical volume creation
258 int i2 = h->GetReplicaNo(hd - 2); // go up in volume hierarchy
259 const G4String& vname = touch->GetVolume()->GetName();
260 cout << vname << " " << hd << " " << i1 << " " << i2 << endl;
261 for (int i = 0; i <= hd; i++) {
262 G4VPhysicalVolume* v = h->GetVolume(i);
263 cout << v->GetName() << endl;
264 }
265 }
266#endif
267 }
268 //Reset TrackID
269 m_trackID = 0;
270 }
271 return true;
272}
G4ThreeVector getCrystalVec(int cid)
The direction of crystal.
G4ThreeVector getCrystalPos(int cid)
The Position of crystal.
int TouchableDiodeToCellID(const G4VTouchable *)
Mapping from G4VTouchable copyNumbers to Crystal CellID.

Member Data Documentation

◆ m_cells

std::vector<int> m_cells
private

array of hitted crystals

Definition at line 111 of file SensitiveDetector.h.

◆ m_eclHits

StoreArray<ECLHit> m_eclHits
private

ECLHit array.

Definition at line 112 of file SensitiveDetector.h.

◆ m_eclp

ECLGeometryPar* m_eclp
private

pointer to ECLGeometryPar

Definition at line 99 of file SensitiveDetector.h.

◆ m_esum

double m_esum
private

total energy deposited in a volume by a track

Definition at line 108 of file SensitiveDetector.h.

◆ m_hits

std::vector<hit_t> m_hits
private

array of hits

Definition at line 110 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 106 of file SensitiveDetector.h.

◆ m_tsum

double m_tsum
private

average track time weighted by energy deposition

Definition at line 107 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: