Skip to content
Snippets Groups Projects
Geant4TrackerSD.cpp 2.47 KiB
Newer Older
//====================================================================
//  AIDA Detector description implementation for LCD
//--------------------------------------------------------------------
//
//  Author     : M.Frank
//
//====================================================================
// Framework include files
#include "DDG4/Geant4SensitiveDetector_inline.h"
#include "DDG4/Factories.h"

/*
 *   DD4hep::Simulation namespace declaration
 */
namespace DD4hep {  namespace Simulation {
  /// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  ///               Geant4GenericSD<Tracker>
  /// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  struct Tracker {};
  /// Method for generating hit(s) using the information of G4Step object.
  template <> bool Geant4GenericSD<Tracker>::buildHits(G4Step* step,G4TouchableHistory* hist) {
Markus Frank's avatar
Markus Frank committed
    StepHandler h(step);
    Position prePos    = h.prePos();
    Position postPos   = h.postPos();
Markus Frank's avatar
Markus Frank committed
    Position position  = mean_direction(prePos,postPos);
Markus Frank's avatar
Markus Frank committed
    if (hit_len > 0) {
      double new_len = mean_length(h.preMom(),h.postMom())/hit_len;
      direction *= new_len/hit_len;
Markus Frank's avatar
Markus Frank committed
    }
    G4cout << "----------- Geant4GenericSD<Tracker>::buildHits : position : " << prePos << G4endl ;
Markus Frank's avatar
Markus Frank committed
    Geant4TrackerHit* hit = 
      new Geant4TrackerHit(h.track->GetTrackID(),
			   h.track->GetDefinition()->GetPDGEncoding(),
			   step->GetTotalEnergyDeposit(),
			   h.track->GetGlobalTime());

    
    HitContribution contrib = Geant4Hit::extractContribution(step);

    // get the copy number of the parent volume -
    // we need a more generic way of finding the volume that has the right copy number assigned...
    // otherwise we couple detector construction sensitive detector !!
    G4StepPoint* preStepPoint = step->GetPreStepPoint();    
    G4TouchableHistory* theTouchable = (G4TouchableHistory*)( preStepPoint->GetTouchable() );
    // G4int copyNo = theTouchable->GetVolume()->GetCopyNo();
    G4int motherCopyNo = theTouchable->GetVolume(1)->GetCopyNo();
    hit->cellID  = motherCopyNo ;

    hit->energyDeposit =  contrib.deposit ;

Markus Frank's avatar
Markus Frank committed
    hit->position = position;
    hit->momentum = direction;
    hit->length   = hit_len;
    collection(0)->insert(hit);
    return hit != 0;
  }
Markus Frank's avatar
Markus Frank committed
  typedef Geant4GenericSD<Tracker> Geant4Tracker;
}}    // End namespace DD4hep::Simulation

Markus Frank's avatar
Markus Frank committed
DECLARE_GEANT4SENSITIVEDETECTOR(Geant4Tracker);