ATLAS Offline Software
GenericMuonSensitiveDetector.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "MCTruth/TrackHelper.h"
7 
8 #include "G4Track.hh"
9 
10 #include <string>
11 
13 
14 // construction/destruction
15 GenericMuonSensitiveDetector::GenericMuonSensitiveDetector(const std::string& name, const std::string& hitCollectionName)
16  : G4VSensitiveDetector( name )
17  , m_GenericMuonHitCollection( hitCollectionName )
18 {
19  G4cout << " creating a GenericMuonSensitiveDetector: "<<name << G4endl;
20 }
21 
22 // Implemenation of memebr functions
24 {
25  if (!m_GenericMuonHitCollection.isValid()) m_GenericMuonHitCollection = std::make_unique<GenericMuonSimHitCollection>();
26 }
27 
28 G4bool GenericMuonSensitiveDetector::ProcessHits(G4Step* aStep,G4TouchableHistory* /*ROHist*/)
29 {
30  G4cout << "Hit in a sensitive layer!!!!! " << G4endl;
31  G4Track* currentTrack = aStep->GetTrack();
32  const G4AffineTransform trans = currentTrack->GetTouchable()->GetHistory()->GetTopTransform(); // from global to local
33  G4StepPoint* postStep=aStep->GetPostStepPoint();
34  G4StepPoint* preStep=aStep->GetPreStepPoint();
35  const G4Step* post_Step=aStep->GetTrack()->GetStep();
36 
37  Amg::Vector3D position = Amg::Hep3VectorToEigen( postStep->GetPosition() );
38  Amg::Vector3D preposition = Amg::Hep3VectorToEigen( preStep->GetPosition() );
39 
40  Amg::Vector3D local_position = Amg::Hep3VectorToEigen( trans.TransformPoint( postStep->GetPosition() ) ) ;
41  Amg::Vector3D local_preposition = Amg::Hep3VectorToEigen( trans.TransformPoint( preStep->GetPosition() ) );
42 
43  int pdgCode=currentTrack->GetDefinition()->GetPDGEncoding();
44 
45  float globalTime=postStep->GetGlobalTime();
46  float globalpreTime=preStep->GetGlobalTime();
47  float eKin=postStep->GetKineticEnergy();
48 
49  Amg::Vector3D direction = Amg::Hep3VectorToEigen( postStep->GetMomentumDirection() );
50  float depositEnergy=post_Step->GetTotalEnergyDeposit();
51  float StepLength=post_Step->GetStepLength();
52 
53  TrackHelper trHelp(aStep->GetTrack());
54 
55  //G4cout << aHit->print() << G4endl;
56  m_GenericMuonHitCollection->Emplace( 0 /* HitID id generic*/,globalTime,globalpreTime,position,local_position,preposition,local_preposition,pdgCode,eKin,direction,depositEnergy,StepLength,trHelp.GenerateParticleLink());
57 
58  return true;
59 }
60 
TrackHelper.h
Amg::Hep3VectorToEigen
Amg::Vector3D Hep3VectorToEigen(const CLHEP::Hep3Vector &CLHEPvector)
Converts a CLHEP-based CLHEP::Hep3Vector into an Eigen-based Amg::Vector3D.
Definition: CLHEPtoEigenConverter.h:137
TrackHelper
Definition: TrackHelper.h:14
GenericMuonSensitiveDetector::GenericMuonSensitiveDetector
GenericMuonSensitiveDetector(const std::string &name, const std::string &hitCollectionName)
construction/destruction
Definition: GenericMuonSensitiveDetector.cxx:15
CLHEPtoEigenConverter.h
GenericMuonSensitiveDetector::Initialize
void Initialize(G4HCofThisEvent *HCE) override final
member functions
Definition: GenericMuonSensitiveDetector.cxx:23
GenericMuonSensitiveDetector.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
GenericMuonSensitiveDetector::m_GenericMuonHitCollection
SG::WriteHandle< GenericMuonSimHitCollection > m_GenericMuonHitCollection
Definition: GenericMuonSensitiveDetector.h:27
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
TrackHelper::GenerateParticleLink
HepMcParticleLink GenerateParticleLink()
Generates a creates new HepMcParticleLink object on the stack based on GetUniqueID(),...
Definition: TrackHelper.h:35
GenericMuonSensitiveDetector::ProcessHits
G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist) override final
Definition: GenericMuonSensitiveDetector.cxx:28
Trk::StepLength
@ StepLength
Definition: MaterialAssociationType.h:17