Belle II Software  release-05-02-19
SensitiveDetector Class Reference

Sensitive Detector implementation of the CSI detector. More...

#include <SensitiveDetector.h>

Inheritance diagram for SensitiveDetector:
Collaboration diagram for SensitiveDetector:

Public Member Functions

 SensitiveDetector ()
 Constructor.
 
 ~SensitiveDetector ()
 Destructor.
 
int saveSimHit (const G4int cellId, const G4int trackID, const G4int pid, const G4double tof, const G4double edep, G4ThreeVector mom, G4ThreeVector pos, G4ThreeVector PosCell, G4ThreeVector VecCell)
 Save ECLSimHits of the event into datastore. More...
 

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. More...
 
static void registerMCParticleRelation (const std::string &name, RelationArray::EConsolidationAction ignoreAction=RelationArray::c_negativeWeight)
 Register an relation involving MCParticles. More...
 
static void registerMCParticleRelation (const RelationArray &relation, RelationArray::EConsolidationAction ignoreAction=RelationArray::c_negativeWeight)
 Overload to make it easer to register MCParticle relations. More...
 

Protected Member Functions

bool step (G4Step *aStep, G4TouchableHistory *) override
 Step processing method. More...
 

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. More...
 

Private Attributes

int m_hitNum
 members of SensitiveDetector

 
int m_EvnetNumber
 The current number of created hits in an event. More...
 
int m_oldEvnetNumber
 The current number of created hits in an event. More...
 
int m_trackID
 The current number of created hits in an event. More...
 
G4ThreeVector m_startPos
 track id
 
G4ThreeVector m_endPos
 Position of prestep.
 
G4ThreeVector m_WightedPos
 Position of poststep.
 
G4ThreeVector m_momentum
 Wighted step Position.
 
double m_startTime
 momentum of track
 
double m_endTime
 global time
 
double m_WightedTime
 global time
 
double m_startEnergy
 global time
 
double m_energyDeposit
 particle energy at the entrance in volume
 
double m_trackLength
 energy deposited in volume
 
int CsiHitIndex [18][80]
 length of the track in the volume
 
int iECLCell
 Hit index of StoreArray.
 
int TimeIndex
 Hit Energy of StoreArray.
 
double local_pos
 Hit Time of StoreArray.
 
double T_ave
 position alongthe vector of crystal axis

 
int firstcall
 flight time to diode sensor

 
int m_phiID
 flag of first call

 
int m_thetaID
 The current phi ID in an event. More...
 
int m_cellID
 The current theta ID in an event. More...
 
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

Sensitive Detector implementation of the CSI detector.

Definition at line 32 of file SensitiveDetector.h.

Member Function Documentation

◆ 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 98 of file SensitiveDetectorBase.h.

◆ 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 70 of file SensitiveDetectorBase.h.

◆ 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 24 of file SensitiveDetectorBase.cc.

◆ saveSimHit()

int saveSimHit ( const G4int  cellId,
const G4int  trackID,
const G4int  pid,
const G4double  tof,
const G4double  edep,
G4ThreeVector  mom,
G4ThreeVector  pos,
G4ThreeVector  PosCell,
G4ThreeVector  VecCell 
)

Save ECLSimHits of the event into datastore.

Parameters
cellIDthe channel identifier
trackIDthe track identifier
pidthe pdg code of the particle
tofthe time of flight of the particle
edepthe energy deposited in the crystal by the particle
momthe momentum of the particle
WightedPosthe weighted position.
Returns
int the number of hits saved in this event

Definition at line 165 of file SensitiveDetector.cc.

166  {
167 
168  //Get the datastore arrays
169  StoreArray<MCParticle> mcParticles;
170  StoreArray<CsiSimHit> simHits;
171 
172  RelationArray simHitRel(mcParticles, simHits);
173 
174  // convert Hep3Vectors to TVector3
175  TVector3 momentum(mom.getX() , mom.getY() , mom.getZ());
176  TVector3 position(pos.getX() , pos.getY() , pos.getZ());
177 
178  //Append
179  simHits.appendNew(cellId, trackID, pid, tof / CLHEP::ns, edep / CLHEP::GeV,
180  momentum * (1.0 / CLHEP::GeV), position * (1.0 / CLHEP::cm));
181 
182  int simhitNumber = simHits.getEntries() - 1;
183  simHitRel.add(trackID, simhitNumber);
184  B2DEBUG(150, "Saving CsiSimHit Number: " << simhitNumber);
185 
186  // Store CsiHit: total energy deposited per hit, with average time.
187 
188  // Old names:
189  /*
190  StoreArray<CsiHit> eclHitArray;
191  RelationArray eclHitRel(mcParticles, eclHitArray);
192  */
193 
194  // New names:
195 
196  StoreArray<CsiHit> csiHits;
197 
198  RelationArray csiHitRel(mcParticles, csiHits);
199 
200 
201  StoreObjPtr<EventMetaData> eventMetaDataPtr;
202  int m_currentEvnetNumber = eventMetaDataPtr->getEvent();
203 
204 
205  if (firstcall == 0 || m_currentEvnetNumber != m_oldEvnetNumber) {
206  m_oldEvnetNumber = m_currentEvnetNumber;
207  for (int iCSICell = 0; iCSICell < 18; iCSICell++) {
208  for (int TimeInd = 0; TimeInd < 80; TimeInd++) {
209  CsiHitIndex[iCSICell][TimeInd] = -1;
210  }
211  }
212  firstcall++;
213  }
214 
215 
216  if (m_currentEvnetNumber == m_oldEvnetNumber) {
217  if ((tof / CLHEP::ns) < 8000) {
218  TimeIndex = (int)((tof / CLHEP::ns) / 100);
219 
220  // local_pos is the distance between the hit and the PIN-diode end of the crystal.
221  local_pos = (15. - (pos - PosCell) * VecCell);
222 
223  // From the ECL package T_ave = 6.05 + 0.0749 * local_pos - 0.00112 * local_pos * local_pos + (tof / CLHEP::ns) ;
224 
225  //For CsI: we remove the offset (I hypothetize it if from photo-sensor delay)
226  // we remove the acceleration of the light
227  // we correct the velocity term using n_CsI=1.80
228  T_ave = 0.0600 * local_pos + (tof / CLHEP::ns) ;
229 
230 
231  double E_cell = (edep / CLHEP::GeV);
232  if (CsiHitIndex[cellId][TimeIndex] == -1) {
233  //m_hitNum = csiHits->GetLast() + 1;
234  //new(csiHits->AddrAt(m_hitNum)) CSIHit();
235  csiHits.appendNew();
236  m_hitNum = csiHits.getEntries() - 1;
237  CsiHitIndex[cellId][TimeIndex] = m_hitNum;
238  csiHits[m_hitNum]->setCellId(cellId);
239  csiHits[m_hitNum]->setEnergyDep(E_cell);
240  csiHits[m_hitNum]->setTimeAve(T_ave);
241  csiHits[m_hitNum]->setTimeVar(0);
242  csiHitRel.add(trackID, m_hitNum);
243 
244  } else {
245  m_hitNum = CsiHitIndex[cellId][TimeIndex];
246  double old_edep = csiHits[m_hitNum]->getEnergyDep();
247  double old_TimeAve = csiHits[m_hitNum]->getTimeAve();
248  double old_TimeVar = csiHits[m_hitNum]->getTimeVar();
249 
250  //double new_edep = E_cell + old_edep;
251  //double new_TimeAve = (old_edep * old_TimeAve + E_cell * T_ave) / new_edep;
252 
253  double temp = E_cell + old_edep;
254  double delta = T_ave - old_TimeAve;
255  double R = delta * E_cell / temp;
256  double new_TimeAve = old_TimeAve + R;
257  double new_TimeVar = old_TimeVar + old_edep * delta * R;
258  double new_edep = temp;
259 
260  //Algo from Wiki:
261  /*
262  for x, weight in dataWeightPairs: # Alternatively "for x, weight in zip(data, weights):"
263  temp = weight + sumweight
264  delta = x - mean
265  R = delta * weight / temp
266  mean = mean + R
267  M2 = M2 + sumweight * delta * R # Alternatively, "M2 = M2 + weight * delta * (x−mean)"
268  sumweight = temp
269 
270  variance_n = M2/sumweight
271  */
272 
273  csiHits[m_hitNum]->setEnergyDep(new_edep);
274  csiHits[m_hitNum]->setTimeAve(new_TimeAve);
275  csiHits[m_hitNum]->setTimeVar(new_TimeVar);
276  csiHitRel.add(trackID, m_hitNum);
277 
278  }
279  }
280  } else { B2ERROR("m_currentEvnetNumber ERROR: m_oldEvnetNumber==m_oldEvnetNumber"); }
281 
282  return (simhitNumber);
283  }//saveSimHit
284  } //csi namespace
286 } //Belle2 namespace

◆ 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 54 of file SensitiveDetectorBase.h.

◆ step()

bool step ( G4Step *  aStep,
G4TouchableHistory *   
)
overrideprotectedvirtual

Step processing method.

Parameters
stepthe G4Step with the current step information
Returns
true if a Hit has been created, false if the hit was ignored

Implements SensitiveDetectorBase.

Definition at line 97 of file SensitiveDetector.cc.

Member Data Documentation

◆ m_cellID

int m_cellID
private

The current theta ID in an event.

Used to fill the DataStore ECL array

Definition at line 101 of file SensitiveDetector.h.

◆ m_EvnetNumber

int m_EvnetNumber
private

The current number of created hits in an event.

Used to fill the DataStore ECLHit.

Definition at line 77 of file SensitiveDetector.h.

◆ m_oldEvnetNumber

int m_oldEvnetNumber
private

The current number of created hits in an event.

Used to fill the DataStore ECL EB array.

Definition at line 78 of file SensitiveDetector.h.

◆ m_thetaID

int m_thetaID
private

The current phi ID in an event.

Used to fill the DataStore ECL array

Definition at line 100 of file SensitiveDetector.h.

◆ m_trackID

int m_trackID
private

The current number of created hits in an event.

Used to fill the DataStore

Definition at line 79 of file SensitiveDetector.h.


The documentation for this class was generated from the following files:
Belle2::csi::SensitiveDetector::firstcall
int firstcall
flight time to diode sensor
Definition: SensitiveDetector.h:98
Belle2::csi::SensitiveDetector::m_oldEvnetNumber
int m_oldEvnetNumber
The current number of created hits in an event.
Definition: SensitiveDetector.h:78
Belle2::csi::SensitiveDetector::T_ave
double T_ave
position alongthe vector of crystal axis
Definition: SensitiveDetector.h:97
Belle2::csi::SensitiveDetector::local_pos
double local_pos
Hit Time of StoreArray.
Definition: SensitiveDetector.h:96
Belle2::csi::SensitiveDetector::TimeIndex
int TimeIndex
Hit Energy of StoreArray.
Definition: SensitiveDetector.h:93
Belle2::csi::SensitiveDetector::m_hitNum
int m_hitNum
members of SensitiveDetector
Definition: SensitiveDetector.h:76
Belle2::csi::SensitiveDetector::CsiHitIndex
int CsiHitIndex[18][80]
length of the track in the volume
Definition: SensitiveDetector.h:91