HGCal Test Beam  03a93d6239a951948e06fb3ef8dae4cbdebfad30
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SteppingAction.cc
Go to the documentation of this file.
1 #include "HGCal/TBStandaloneSimulator/interface/SteppingAction.hh"
2 #include "HGCal/TBStandaloneSimulator/interface/DetectorConstruction.hh"
3 #include "HGCal/TBStandaloneSimulator/interface/EventAction.hh"
4 #include "HGCal/TBStandaloneSimulator/interface/HGCSSGenParticle.hh"
5 #include "G4Step.hh"
6 #include "G4RunManager.hh"
7 
8 //
9 SteppingAction::SteppingAction()
10 {
11  eventAction_ = (EventAction*)G4RunManager::GetRunManager()->
12  GetUserEventAction();
13  eventAction_->Add( ((DetectorConstruction*)G4RunManager::GetRunManager()->
14  GetUserDetectorConstruction())->getStructure() );
15  saturationEngine = new G4EmSaturation();
16  // A hack to avoid compiler warning
17  int hack = CLHEP::HepRandomGenActive;
18  timeLimit_ = hack;
19  timeLimit_ = 100;//ns
20 }
21 
22 //
23 SteppingAction::~SteppingAction()
24 { }
25 
26 //
27 void SteppingAction::UserSteppingAction(const G4Step* aStep)
28 {
29  // get PreStepPoint
30  const G4StepPoint *thePreStepPoint = aStep->GetPreStepPoint();
31  const G4StepPoint *thePostStepPoint = aStep->GetPostStepPoint();
32  // get TouchableHandle
33  const G4Track* lTrack = aStep->GetTrack();
34  G4int trackID = lTrack->GetTrackID();
35  G4int parentID = lTrack->GetParentID();
36 
37  G4VPhysicalVolume* volume = thePreStepPoint->GetPhysicalVolume();
38  std::string thePrePVname("null");
39  if(volume == 0) {
40  } else {
41  thePrePVname = volume->GetName();
42  }
43  G4VPhysicalVolume* postvolume = thePostStepPoint->GetPhysicalVolume();
44  std::string thePostPVname("null");
45  if(postvolume == 0) {
46  } else {
47  thePostPVname = postvolume->GetName();
48  }
49 
50  G4double edep = aStep->GetTotalEnergyDeposit();
51 
52  //correct with Birk's law for scintillator material
53  if (volume->GetName().find("Scint") != volume->GetName().npos) {
54  G4double attEdep
55  = saturationEngine->
56  VisibleEnergyDeposition(lTrack->GetDefinition(),
57  lTrack->GetMaterialCutsCouple(),
58  aStep->GetStepLength(), edep, 0.);
59  edep = attEdep;
60  }
61 
62  G4double stepl = 0.;
63  if (lTrack->GetDefinition()->GetPDGCharge() != 0.)
64  stepl = aStep->GetStepLength();
65 
66  G4int pdgId = lTrack->GetDefinition()->GetPDGEncoding();
67  G4double globalTime = lTrack->GetGlobalTime();
68 
69  // store track segment
70  const G4ThreeVector& position = thePreStepPoint->GetPosition();
71  const G4ThreeVector& postposition = thePostStepPoint->GetPosition();
72  const G4ThreeVector& p = lTrack->GetMomentum();
73  eventAction_->Store(trackID, pdgId, globalTime, p, position, postposition);
74 
75  HGCSSGenParticle genPart;
76  if (globalTime < timeLimit_ &&
77  thePrePVname == "Wphys"
78  && eventAction_->isFirstVolume(thePostPVname)) {
79  const G4ThreeVector& postposition = thePostStepPoint->GetPosition();
80  const G4ThreeVector& p = lTrack->GetMomentum();
81  G4ParticleDefinition* pd = lTrack->GetDefinition();
82  genPart.setPosition(postposition[0],
83  postposition[1],
84  postposition[2]);
85  genPart.setMomentum(p[0], p[1], p[2]);
86  genPart.mass(pd->GetPDGMass());
87  genPart.time(globalTime);
88  genPart.pdgid(pdgId);
89  genPart.charge(pd->GetPDGCharge());
90  genPart.trackID(trackID);
91  }
92 
93  eventAction_->Detect(edep,
94  stepl,
95  globalTime,
96  pdgId,
97  volume,
98  position,
99  trackID,
100  parentID,
101  genPart);
102 }