CMS 3D CMS Logo

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