Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-07-14 22:56:12

0001 #ifndef SimG4Core_SteppingAction_H
0002 #define SimG4Core_SteppingAction_H
0003 
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "SimG4Core/Notification/interface/SimActivityRegistry.h"
0006 
0007 #include "G4LogicalVolume.hh"
0008 #include "G4Region.hh"
0009 #include "G4UserSteppingAction.hh"
0010 #include "G4VPhysicalVolume.hh"
0011 #include "G4VTouchable.hh"
0012 #include "G4Track.hh"
0013 
0014 #include <string>
0015 #include <vector>
0016 
0017 class EventAction;
0018 class CMSSteppingVerbose;
0019 
0020 enum TrackStatus {
0021   sAlive = 0,
0022   sKilledByProcess = 1,
0023   sDeadRegion = 2,
0024   sOutOfTime = 3,
0025   sLowEnergy = 4,
0026   sLowEnergyInVacuum = 5,
0027   sEnergyDepNaN = 6,
0028   sVeryForward = 7,
0029   sNumberOfSteps = 8
0030 };
0031 
0032 class SteppingAction : public G4UserSteppingAction {
0033 public:
0034   explicit SteppingAction(EventAction* ea, const edm::ParameterSet& ps, const CMSSteppingVerbose*, bool hasW);
0035   ~SteppingAction() override;
0036 
0037   void UserSteppingAction(const G4Step* aStep) final;
0038 
0039   SimActivityRegistry::G4StepSignal m_g4StepSignal;
0040 
0041 private:
0042   bool initPointer();
0043 
0044   inline bool isInsideDeadRegion(const G4Region* reg) const;
0045   inline bool isOutOfTimeWindow(const G4Region* reg, const double& time) const;
0046 
0047   bool isLowEnergy(const G4LogicalVolume*, const G4Track*) const;
0048   void PrintKilledTrack(const G4Track*, const TrackStatus&) const;
0049 
0050   EventAction* eventAction_;
0051   const G4VPhysicalVolume *tracker, *calo;
0052   const CMSSteppingVerbose* steppingVerbose;
0053   double theCriticalEnergyForVacuum;
0054   double theCriticalDensity;
0055   double maxTrackTime;
0056   double maxTrackTimeForward;
0057   double maxZCentralCMS;
0058 
0059   unsigned int numberTimes;
0060   unsigned int numberEkins;
0061   unsigned int numberPart;
0062   unsigned int ndeadRegions;
0063   unsigned int nWarnings;
0064   G4int maxNumberOfSteps;
0065 
0066   bool initialized;
0067   bool killBeamPipe;
0068   bool hasWatcher;
0069 
0070   std::vector<double> maxTrackTimes, ekinMins;
0071   std::vector<std::string> maxTimeNames, ekinNames, ekinParticles;
0072   std::vector<std::string> deadRegionNames;
0073   std::vector<const G4Region*> maxTimeRegions;
0074   std::vector<const G4Region*> deadRegions;
0075   std::vector<G4LogicalVolume*> ekinVolumes;
0076   std::vector<int> ekinPDG;
0077 };
0078 
0079 inline bool SteppingAction::isInsideDeadRegion(const G4Region* reg) const {
0080   bool res = false;
0081   for (auto& region : deadRegions) {
0082     if (reg == region) {
0083       res = true;
0084       break;
0085     }
0086   }
0087   return res;
0088 }
0089 
0090 inline bool SteppingAction::isOutOfTimeWindow(const G4Region* reg, const double& time) const {
0091   double tofM = maxTrackTime;
0092   for (unsigned int i = 0; i < numberTimes; ++i) {
0093     if (reg == maxTimeRegions[i]) {
0094       tofM = maxTrackTimes[i];
0095       break;
0096     }
0097   }
0098   return (time > tofM);
0099 }
0100 
0101 #endif