CMS 3D CMS Logo

TreatSecondary.cc
Go to the documentation of this file.
3 
5 
6 #include "G4Step.hh"
7 #include "G4Track.hh"
8 #include "G4VProcess.hh"
9 #include "G4HCofThisEvent.hh"
10 #include "CLHEP/Units/GlobalSystemOfUnits.h"
11 #include "CLHEP/Units/GlobalPhysicalConstants.h"
12 
13 #include <cmath>
14 #include <iostream>
15 #include <iomanip>
16 
18 
19  verbosity = p.getUntrackedParameter<int>("Verbosity",0);
20  killAfter = p.getUntrackedParameter<int>("KillAfter", -1);
21  minDeltaE = p.getUntrackedParameter<double>("MinimumDeltaE", 10.0)*MeV;
22 
23  edm::LogInfo("CheckSecondary") << "Instantiate CheckSecondary with Flag"
24  << " for Killing track after "<< killAfter
25  << " hadronic interactions\nDefine inelastic"
26  << " if > 1 seondary or change in KE > "
27  << minDeltaE << " MeV\n";
28 
30 }
31 
33  if (typeEnumerator) delete typeEnumerator;
34 }
35 
36 void TreatSecondary::initTrack(const G4Track * thTk) {
37 
38  step = 0;
39  nsecL = 0;
40  nHad = 0;
41  eTrack = thTk->GetKineticEnergy()/MeV;
42  LogDebug("CheckSecondary") << "TreatSecondary::initTrack:Track: "
43  << thTk->GetTrackID() << " Type: "
44  << thTk->GetDefinition()->GetParticleName()
45  << " KE " << thTk->GetKineticEnergy()/GeV
46  << " GeV p " << thTk->GetMomentum().mag()/GeV
47  << " GeV daughter of particle "
48  << thTk->GetParentID();
49 }
50 
51 std::vector<math::XYZTLorentzVector> TreatSecondary::tracks(const G4Step*aStep,
52  std::string & name,
53  int & procid,
54  bool & hadrInt,
55  double & deltaE,
56  std::vector<int> & charges) {
57 
58  step++;
59  procid = -1;
60  name = "Unknown";
61  hadrInt = false;
62  deltaE = 0;
63  std::vector<math::XYZTLorentzVector> secondaries;
64  charges.clear();
65 
66  if (aStep != nullptr) {
67  const G4TrackVector* tkV = aStep->GetSecondary();
68  G4Track* thTk = aStep->GetTrack();
69  const G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
70  const G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
71  double eTrackNew = thTk->GetKineticEnergy()/MeV;
72  deltaE = eTrack-eTrackNew;
73  eTrack = eTrackNew;
74  if (tkV != nullptr && postStepPoint != nullptr) {
75  int nsc = (*tkV).size();
76  const G4VProcess* proc = postStepPoint->GetProcessDefinedStep();
77  if (proc != nullptr) {
78  G4ProcessType type = proc->GetProcessType();
79  procid = typeEnumerator->processIdLong(proc);
80  name = proc->GetProcessName();
81  int sec = nsc - nsecL;
82  LogDebug("CheckSecondary") << sec << " secondaries in step "
83  << thTk->GetCurrentStepNumber()
84  << " of track " << thTk->GetTrackID()
85  << " from " << name << " of type "
86  << type << " ID " << procid << " ("
87  << typeEnumerator->processG4Name(procid)
88  << ")";
89 
90  // hadronic interaction
91  if(procid >= 121 && procid <= 151) {
92  LogDebug("CheckSecondary") << "Hadronic Interaction " << nHad
93  << " of Type " << procid << " with "
94  << sec << " secondaries from process "
95  << proc->GetProcessName() << " Delta E "
96  << deltaE << " Flag " << hadrInt;
97  math::XYZTLorentzVector secondary;
98  for (int i=nsecL; i<nsc; ++i) {
99  G4Track* tk = (*tkV)[i];
100  G4ThreeVector pp = tk->GetMomentum();
101  double ee = tk->GetTotalEnergy();
102  secondary = math::XYZTLorentzVector(pp.x(),pp.y(),pp.z(),ee);
103  secondaries.push_back(secondary);
104  int charge = (int)(tk->GetDefinition()->GetPDGCharge());
105  charges.push_back(charge);
106  }
107  if (verbosity > 0) {
108  for (int i=nsecL; i<nsc; i++) {
109  G4Track* tk = (*tkV)[i];
110  LogDebug("CheckSecondary") << "Secondary: " << sec << " ID "
111  << tk->GetTrackID() << " Status "
112  << tk->GetTrackStatus() << " Particle "
113  << tk->GetDefinition()->GetParticleName()
114  << " Position " << tk->GetPosition()
115  << " KE " << tk->GetKineticEnergy()
116  << " Time " << tk->GetGlobalTime();
117  }
118  }
119  }
120  nsecL = nsc;
121  }
122  }
123  if (verbosity > 1) {
124  LogDebug("CheckSecondary") << "Track: " << thTk->GetTrackID()
125  << " Status " << thTk->GetTrackStatus()
126  << " Particle "
127  << thTk->GetDefinition()->GetParticleName()
128  << " at " << preStepPoint->GetPosition()
129  << " Step: " << step << " KE "
130  << thTk->GetKineticEnergy()/GeV << " GeV; p "
131  << thTk->GetMomentum().mag()/GeV
132  << " GeV/c; Step Length "
133  << aStep->GetStepLength()<< " Energy Deposit "
134  << aStep->GetTotalEnergyDeposit()/MeV
135  << " MeV; Interaction " << hadrInt;
136  }
137  }
138  return secondaries;
139 }
#define LogDebug(id)
type
Definition: HCALResponse.h:21
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
const double GeV
Definition: MathUtil.h:16
TrainProcessor *const proc
Definition: MVATrainer.cc:101
virtual ~TreatSecondary()
std::vector< math::XYZTLorentzVector > tracks(const G4Step *step, std::string &procName, int &procID, bool &intr, double &deltaE, std::vector< int > &charges)
G4ProcessTypeEnumerator * typeEnumerator
const double MeV
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
TreatSecondary(const edm::ParameterSet &p)
int processIdLong(const G4VProcess *p)
void initTrack(const G4Track *trk)
step