CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
SteppingAction Class Reference

#include <SteppingAction.h>

Inheritance diagram for SteppingAction:

Public Member Functions

 SteppingAction (EventAction *ea, const edm::ParameterSet &ps)
 
void UserSteppingAction (const G4Step *aStep)
 
 ~SteppingAction ()
 

Public Attributes

SimActivityRegistry::G4StepSignal m_g4StepSignal
 

Private Member Functions

bool catchLongLived (const G4Step *aStep)
 
bool catchLowEnergyInVacuum (G4Track *theTrack, double theKenergy)
 
bool initPointer ()
 
bool isThisVolume (const G4VTouchable *touch, G4VPhysicalVolume *pv)
 
bool killLowEnergy (const G4Step *aStep)
 
void killTrack (const G4Step *aStep)
 

Private Attributes

G4VPhysicalVolume * calo
 
std::vector< double > ekinMins
 
std::vector< std::string > ekinNames
 
std::vector< std::string > ekinParticles
 
std::vector< int > ekinPDG
 
std::vector< G4LogicalVolume * > ekinVolumes
 
EventActioneventAction_
 
bool initialized
 
bool killBeamPipe
 
bool killByEnergy
 
bool killByTimeAtRegion
 
std::vector< std::string > maxTimeNames
 
std::vector< G4Region * > maxTimeRegions
 
double maxTrackTime
 
std::vector< double > maxTrackTimes
 
double theCriticalDensity
 
double theCriticalEnergyForVacuum
 
G4VPhysicalVolume * tracker
 
int verbose
 

Detailed Description

Definition at line 19 of file SteppingAction.h.

Constructor & Destructor Documentation

SteppingAction::SteppingAction ( EventAction ea,
const edm::ParameterSet ps 
)

Definition at line 14 of file SteppingAction.cc.

References ekinMins, ekinNames, ekinParticles, ekinVolumes, g, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), i, killBeamPipe, killByEnergy, killByTimeAtRegion, maxTimeNames, maxTrackTime, maxTrackTimes, theCriticalDensity, and theCriticalEnergyForVacuum.

15  : eventAction_(e), tracker(0), calo(0), initialized(false) {
16 
17  killBeamPipe = (p.getParameter<bool>("KillBeamPipe"));
18  theCriticalEnergyForVacuum = (p.getParameter<double>("CriticalEnergyForVacuum")*MeV);
19  theCriticalDensity = (p.getParameter<double>("CriticalDensity")*g/cm3);
20  maxTrackTime = (p.getParameter<double>("MaxTrackTime")*ns);
21  maxTrackTimes = (p.getParameter<std::vector<double> >("MaxTrackTimes"));
22  maxTimeNames = (p.getParameter<std::vector<std::string> >("MaxTimeNames"));
23  ekinMins = (p.getParameter<std::vector<double> >("EkinThresholds"));
24  ekinNames = (p.getParameter<std::vector<std::string> >("EkinNames"));
25  ekinParticles = (p.getParameter<std::vector<std::string> >("EkinParticles"));
26  verbose = (p.getUntrackedParameter<int>("Verbosity",0));
27 
28  edm::LogInfo("SimG4CoreApplication") << "SteppingAction:: KillBeamPipe = "
29  << killBeamPipe << " CriticalDensity = "
30  << theCriticalDensity << " g/cc;"
31  << " CriticalEnergyForVacuum = "
32  << theCriticalEnergyForVacuum << " Mev;"
33  << " MaxTrackTime = " << maxTrackTime
34  << " ns";
35 
36  for (unsigned int i=0; i<maxTrackTimes.size(); i++) {
37  maxTrackTimes[i] *= ns;
38  edm::LogInfo("SimG4CoreApplication") << "SteppingAction::MaxTrackTime for "
39  << maxTimeNames[i] << " is "
40  << maxTrackTimes[i];
41  }
42 
43  killByTimeAtRegion = false;
44  if(maxTrackTimes.size() > 0) { killByTimeAtRegion = true; }
45 
46  killByEnergy = false;
47  if(ekinVolumes.size() > 0) {
48 
49  killByEnergy = true;
50  edm::LogInfo("SimG4CoreApplication") << "SteppingAction::Kill following "
51  << ekinParticles.size()
52  << " particles in " << ekinNames.size()
53  << " volumes";
54  for (unsigned int i=0; i<ekinParticles.size(); i++) {
55  ekinMins[i] *= GeV;
56  edm::LogInfo("SimG4CoreApplication") << "SteppingAction::Particle " << i
57  << " " << ekinParticles[i]
58  << " (Threshold = " << ekinMins[i]
59  << " MeV)";
60  }
61  for (unsigned int i=0; i<ekinNames.size(); i++)
62  edm::LogInfo("SimG4CoreApplication") << "SteppingAction::Volume[" << i
63  << "] = " << ekinNames[i];
64  }
65 }
int i
Definition: DBlmapReader.cc:9
double theCriticalDensity
G4VPhysicalVolume * calo
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
std::vector< double > maxTrackTimes
std::vector< G4LogicalVolume * > ekinVolumes
double theCriticalEnergyForVacuum
EventAction * eventAction_
std::vector< double > ekinMins
std::vector< std::string > maxTimeNames
std::vector< std::string > ekinNames
G4VPhysicalVolume * tracker
std::vector< std::string > ekinParticles
SteppingAction::~SteppingAction ( )

Definition at line 67 of file SteppingAction.cc.

67 {}

Member Function Documentation

bool SteppingAction::catchLongLived ( const G4Step *  aStep)
private

Definition at line 153 of file SteppingAction.cc.

References i, killByTimeAtRegion, killTrack(), maxTimeRegions, maxTrackTime, maxTrackTimes, and cond::rpcobgas::time.

Referenced by UserSteppingAction().

154 {
155  bool flag = true;
156  double time = (aStep->GetPostStepPoint()->GetGlobalTime())/nanosecond;
157  double tofM = maxTrackTime;
158 
159  if(killByTimeAtRegion) {
160  G4Region* reg =
161  aStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume()->GetRegion();
162  for (unsigned int i=0; i<maxTimeRegions.size(); i++) {
163  if (reg == maxTimeRegions[i]) {
164  tofM = maxTrackTimes[i];
165  break;
166  }
167  }
168  }
169  if (time > tofM) {
170  killTrack(aStep);
171  flag = false;
172  }
173  return flag;
174 }
int i
Definition: DBlmapReader.cc:9
std::vector< double > maxTrackTimes
void killTrack(const G4Step *aStep)
std::vector< G4Region * > maxTimeRegions
bool SteppingAction::catchLowEnergyInVacuum ( G4Track *  theTrack,
double  theKenergy 
)
private

Definition at line 116 of file SteppingAction.cc.

References g, and theCriticalDensity.

Referenced by UserSteppingAction().

117 {
118  bool alive = true;
119  if (theTrack->GetVolume()!=0) {
120  double density = theTrack->GetVolume()->GetLogicalVolume()->GetMaterial()->GetDensity();
121  if (density <= theCriticalDensity) {
122  if (verbose>1) {
123  edm::LogInfo("SimG4CoreApplication")
124  << " SteppingAction: LoopCatchSteppingAction:catchLowEnergyInVacuumHere: "
125  << " Track from " << theTrack->GetDefinition()->GetParticleName()
126  << " of kinetic energy " << theKenergy/MeV << " MeV "
127  << " killed in " << theTrack->GetVolume()->GetLogicalVolume()->GetName()
128  << " of density " << density/(g/cm3) << " g/cm3" ;
129  }
130  theTrack->SetTrackStatus(fStopAndKill);
131  alive = false;
132  }
133  if(alive) {
134  density = theTrack->GetNextVolume()->GetLogicalVolume()->GetMaterial()->GetDensity();
135  if (density <= theCriticalDensity) {
136  if (verbose>1) {
137  edm::LogInfo("SimG4CoreApplication")
138  << " SteppingAction: LoopCatchSteppingAction::catchLowEnergyInVacuumNext: "
139  << " Track from " << theTrack->GetDefinition()->GetParticleName()
140  << " of kinetic energy " << theKenergy/MeV << " MeV "
141  << " stopped in " << theTrack->GetVolume()->GetLogicalVolume()->GetName()
142  << " before going into "<< theTrack->GetNextVolume()->GetLogicalVolume()->GetName()
143  << " of density " << density/(g/cm3) << " g/cm3" ;
144  }
145  theTrack->SetTrackStatus(fStopButAlive);
146  alive = false;
147  }
148  }
149  }
150  return alive;
151 }
double theCriticalDensity
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
bool SteppingAction::initPointer ( )
private

Definition at line 206 of file SteppingAction.cc.

References calo, ekinMins, ekinNames, ekinParticles, ekinPDG, ekinVolumes, i, LogDebug, maxTimeNames, maxTimeRegions, maxTrackTimes, mergeVDriftHistosByStation::name, pileupDistInMC::num, and tracker.

Referenced by UserSteppingAction().

207 {
208  bool flag = true;
209  const G4PhysicalVolumeStore * pvs = G4PhysicalVolumeStore::GetInstance();
210  if (pvs) {
211  std::vector<G4VPhysicalVolume*>::const_iterator pvcite;
212  for (pvcite = pvs->begin(); pvcite != pvs->end(); pvcite++) {
213  if ((*pvcite)->GetName() == "Tracker") tracker = (*pvcite);
214  if ((*pvcite)->GetName() == "CALO") calo = (*pvcite);
215  if (tracker && calo) break;
216  }
217  edm::LogInfo("SimG4CoreApplication") << "Pointer for Tracker " << tracker
218  << " and for Calo " << calo;
219  if (tracker) LogDebug("SimG4CoreApplication") << "Tracker vol name "
220  << tracker->GetName();
221  if (calo) LogDebug("SimG4CoreApplication") << "Calorimeter vol name "
222  << calo->GetName();
223  } else {
224  flag = false;
225  }
226 
227  const G4LogicalVolumeStore * lvs = G4LogicalVolumeStore::GetInstance();
228  unsigned int num = ekinNames.size();
229  if (num > 0) {
230  if (lvs) {
231  std::vector<G4LogicalVolume*>::const_iterator lvcite;
232  for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
233  for (unsigned int i=0; i<num; i++) {
234  if ((*lvcite)->GetName() == (G4String)(ekinNames[i])) {
235  ekinVolumes.push_back(*lvcite);
236  break;
237  }
238  }
239  if (ekinVolumes.size() == num) break;
240  }
241  }
242  if (ekinVolumes.size() != num) flag = false;
243  for (unsigned int i=0; i<ekinVolumes.size(); i++) {
244  edm::LogInfo("SimG4CoreApplication") << ekinVolumes[i]->GetName()
245  <<" with pointer " <<ekinVolumes[i];
246  }
247  }
248 
249  G4ParticleTable * theParticleTable = G4ParticleTable::GetParticleTable();
250  G4String particleName;
251  for (unsigned int i=0; i<ekinParticles.size(); i++) {
252  int pdg = theParticleTable->FindParticle(particleName=ekinParticles[i])->GetPDGEncoding();
253  ekinPDG.push_back(pdg);
254  edm::LogInfo("SimG4CoreApplication") << "Particle " << ekinParticles[i]
255  << " with code " << ekinPDG[i]
256  << " and KE cut off " << ekinMins[i];
257  }
258  if (!flag) edm::LogInfo("SimG4CoreApplication") << "SteppingAction fails to"
259  << " initialize some the "
260  << "LV pointers correctly";
261 
262  const G4RegionStore * rs = G4RegionStore::GetInstance();
263  num = maxTimeNames.size();
264  if (num > 0) {
265  std::vector<double> tofs;
266  if (rs) {
267  std::vector<G4Region*>::const_iterator rcite;
268  for (rcite = rs->begin(); rcite != rs->end(); rcite++) {
269  for (unsigned int i=0; i<num; i++) {
270  if ((*rcite)->GetName() == (G4String)(maxTimeNames[i])) {
271  maxTimeRegions.push_back(*rcite);
272  tofs.push_back(maxTrackTimes[i]);
273  break;
274  }
275  }
276  if (tofs.size() == num) break;
277  }
278  }
279  for (unsigned int i=0; i<tofs.size(); i++) {
280  maxTrackTimes[i] = tofs[i];
281  G4String name = "Unknown";
282  if (maxTimeRegions[i]) name = maxTimeRegions[i]->GetName();
283  edm::LogInfo("SimG4CoreApplication") << name << " with pointer "
284  << maxTimeRegions[i]<<" KE cut off "
285  << maxTrackTimes[i];
286  }
287  if (tofs.size() != num)
288  edm::LogInfo("SimG4CoreApplication") << "SteppingAction fails to "
289  << "initialize some the region "
290  << "pointers correctly";
291  }
292  return true;
293 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
std::vector< int > ekinPDG
G4VPhysicalVolume * calo
std::vector< double > maxTrackTimes
std::vector< G4LogicalVolume * > ekinVolumes
std::vector< double > ekinMins
std::vector< std::string > maxTimeNames
std::vector< std::string > ekinNames
G4VPhysicalVolume * tracker
std::vector< std::string > ekinParticles
std::vector< G4Region * > maxTimeRegions
bool SteppingAction::isThisVolume ( const G4VTouchable *  touch,
G4VPhysicalVolume *  pv 
)
private

Definition at line 295 of file SteppingAction.cc.

References cuy::ii, and testEve_cfg::level.

Referenced by UserSteppingAction().

297 {
298 
299  int level = ((touch->GetHistoryDepth())+1);
300  if (level > 0 && level >= 3) {
301  unsigned int ii = (unsigned int)(level - 3);
302  return (touch->GetVolume(ii) == pv);
303  }
304  return false;
305 }
int ii
Definition: cuy.py:588
tuple level
Definition: testEve_cfg.py:34
bool SteppingAction::killLowEnergy ( const G4Step *  aStep)
private

Definition at line 176 of file SteppingAction.cc.

References ekinMins, ekinPDG, ekinVolumes, i, killTrack(), and convertSQLiteXML::ok.

Referenced by UserSteppingAction().

177 {
178  bool ok = true;
179  bool flag = false;
180  G4LogicalVolume* lv = aStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume();
181  for (unsigned int i=0; i<ekinVolumes.size(); i++) {
182  if (lv == ekinVolumes[i]) {
183  flag = true;
184  break;
185  }
186  }
187  if (flag) {
188  G4Track * track = aStep->GetTrack();
189  double ekin = track->GetKineticEnergy();
190  double ekinM = 0;
191  int pCode = track->GetDefinition()->GetPDGEncoding();
192  for (unsigned int i=0; i<ekinPDG.size(); i++) {
193  if (pCode == ekinPDG[i]) {
194  ekinM = ekinMins[i];
195  break;
196  }
197  }
198  if (ekin < ekinM) {
199  killTrack(aStep);
200  ok = false;
201  }
202  }
203  return ok;
204 }
int i
Definition: DBlmapReader.cc:9
std::vector< int > ekinPDG
std::vector< G4LogicalVolume * > ekinVolumes
void killTrack(const G4Step *aStep)
std::vector< double > ekinMins
void SteppingAction::killTrack ( const G4Step *  aStep)
private

Definition at line 307 of file SteppingAction.cc.

References GetVolume(), GetRecoTauVFromDQM_MC_cff::kk, and LogDebug.

Referenced by catchLongLived(), and killLowEnergy().

308 {
309 
310  aStep->GetTrack()->SetTrackStatus(fStopAndKill);
311  G4TrackVector tv = *(aStep->GetSecondary());
312  for (unsigned int kk=0; kk<tv.size(); kk++) {
313  if (tv[kk]->GetVolume() == aStep->GetPreStepPoint()->GetPhysicalVolume())
314  tv[kk]->SetTrackStatus(fStopAndKill);
315  }
316  LogDebug("SimG4CoreApplication")
317  << "SteppingAction: Kills track "
318  << aStep->GetTrack()->GetTrackID() << " ("
319  << aStep->GetTrack()->GetDefinition()->GetParticleName()
320  << ") at " << aStep->GetPostStepPoint()->GetGlobalTime()/nanosecond << " ns in "
321  << aStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume()->GetName()
322  << " from region "
323  << aStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume()->GetRegion()->GetName();
324 }
#define LogDebug(id)
static const G4LogicalVolume * GetVolume(const std::string &name)
void SteppingAction::UserSteppingAction ( const G4Step *  aStep)

Definition at line 69 of file SteppingAction.cc.

References EventAction::addTkCaloStateInfo(), calo, catchLongLived(), catchLowEnergyInVacuum(), eventAction_, initialized, initPointer(), isThisVolume(), killBeamPipe, killByEnergy, killLowEnergy(), m_g4StepSignal, convertSQLiteXML::ok, AlCaHLTBitMon_ParallelJobs::p, theCriticalEnergyForVacuum, tracker, x, detailsBasic3DVector::y, and detailsBasic3DVector::z.

70 {
71  if (!initialized) { initialized = initPointer(); }
72  m_g4StepSignal(aStep);
73 
74  G4Track * theTrack = aStep->GetTrack();
75  bool ok = (theTrack->GetTrackStatus() == fAlive);
76  G4double kinEnergy = theTrack->GetKineticEnergy();
77 
78  if (ok && killBeamPipe && kinEnergy < theCriticalEnergyForVacuum
79  && theTrack->GetDefinition()->GetPDGCharge() != 0.0 && kinEnergy > 0.0) {
80  ok = catchLowEnergyInVacuum(theTrack, kinEnergy);
81 
82  //ok = catchLowEnergyInVacuumHere(theTrack);
83  //if(ok) { ok = catchLowEnergyInVacuumNext(aStep); }
84  }
85 
86  if(ok && aStep->GetPostStepPoint()->GetPhysicalVolume() != 0) {
87 
88  ok = catchLongLived(aStep);
89 
90  if(ok && killByEnergy) { ok = killLowEnergy(aStep); }
91 
92  if(ok) {
93 
94  G4StepPoint* preStep = aStep->GetPreStepPoint();
95  if(isThisVolume(preStep->GetTouchable(),tracker) &&
96  isThisVolume(aStep->GetPostStepPoint()->GetTouchable(),calo)) {
97 
98  math::XYZVectorD pos((preStep->GetPosition()).x(),
99  (preStep->GetPosition()).y(),
100  (preStep->GetPosition()).z());
101 
102  math::XYZTLorentzVectorD mom((preStep->GetMomentum()).x(),
103  (preStep->GetMomentum()).y(),
104  (preStep->GetMomentum()).z(),
105  preStep->GetTotalEnergy());
106 
107  uint32_t id = aStep->GetTrack()->GetTrackID();
108 
109  std::pair<math::XYZVectorD,math::XYZTLorentzVectorD> p(pos,mom);
111  }
112  }
113  }
114 }
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
SimActivityRegistry::G4StepSignal m_g4StepSignal
bool catchLongLived(const G4Step *aStep)
G4VPhysicalVolume * calo
bool isThisVolume(const G4VTouchable *touch, G4VPhysicalVolume *pv)
float float float z
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > XYZVectorD
spatial vector with cartesian internal representation
Definition: Vector3D.h:8
bool catchLowEnergyInVacuum(G4Track *theTrack, double theKenergy)
double theCriticalEnergyForVacuum
EventAction * eventAction_
bool killLowEnergy(const G4Step *aStep)
void addTkCaloStateInfo(uint32_t t, const std::pair< math::XYZVectorD, math::XYZTLorentzVectorD > &p)
Definition: EventAction.cc:75
G4VPhysicalVolume * tracker
Definition: DDAxes.h:10

Member Data Documentation

G4VPhysicalVolume * SteppingAction::calo
private

Definition at line 40 of file SteppingAction.h.

Referenced by initPointer(), and UserSteppingAction().

std::vector<double> SteppingAction::ekinMins
private

Definition at line 44 of file SteppingAction.h.

Referenced by initPointer(), killLowEnergy(), and SteppingAction().

std::vector<std::string> SteppingAction::ekinNames
private

Definition at line 45 of file SteppingAction.h.

Referenced by initPointer(), and SteppingAction().

std::vector<std::string> SteppingAction::ekinParticles
private

Definition at line 45 of file SteppingAction.h.

Referenced by initPointer(), and SteppingAction().

std::vector<int> SteppingAction::ekinPDG
private

Definition at line 48 of file SteppingAction.h.

Referenced by initPointer(), and killLowEnergy().

std::vector<G4LogicalVolume*> SteppingAction::ekinVolumes
private

Definition at line 47 of file SteppingAction.h.

Referenced by initPointer(), killLowEnergy(), and SteppingAction().

EventAction* SteppingAction::eventAction_
private

Definition at line 39 of file SteppingAction.h.

Referenced by UserSteppingAction().

bool SteppingAction::initialized
private

Definition at line 51 of file SteppingAction.h.

Referenced by UserSteppingAction().

bool SteppingAction::killBeamPipe
private

Definition at line 52 of file SteppingAction.h.

Referenced by SteppingAction(), and UserSteppingAction().

bool SteppingAction::killByEnergy
private

Definition at line 54 of file SteppingAction.h.

Referenced by SteppingAction(), and UserSteppingAction().

bool SteppingAction::killByTimeAtRegion
private

Definition at line 53 of file SteppingAction.h.

Referenced by catchLongLived(), and SteppingAction().

SimActivityRegistry::G4StepSignal SteppingAction::m_g4StepSignal
std::vector<std::string> SteppingAction::maxTimeNames
private

Definition at line 45 of file SteppingAction.h.

Referenced by initPointer(), and SteppingAction().

std::vector<G4Region*> SteppingAction::maxTimeRegions
private

Definition at line 46 of file SteppingAction.h.

Referenced by catchLongLived(), and initPointer().

double SteppingAction::maxTrackTime
private

Definition at line 43 of file SteppingAction.h.

Referenced by catchLongLived(), and SteppingAction().

std::vector<double> SteppingAction::maxTrackTimes
private

Definition at line 44 of file SteppingAction.h.

Referenced by catchLongLived(), initPointer(), and SteppingAction().

double SteppingAction::theCriticalDensity
private

Definition at line 42 of file SteppingAction.h.

Referenced by catchLowEnergyInVacuum(), and SteppingAction().

double SteppingAction::theCriticalEnergyForVacuum
private

Definition at line 41 of file SteppingAction.h.

Referenced by SteppingAction(), and UserSteppingAction().

G4VPhysicalVolume* SteppingAction::tracker
private

Definition at line 40 of file SteppingAction.h.

Referenced by initPointer(), and UserSteppingAction().

int SteppingAction::verbose
private

Definition at line 49 of file SteppingAction.h.