Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-02 02:23:11

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   inline bool isThisVolume(const G4VTouchable* touch, const G4VPhysicalVolume* pv) const;
0047 
0048   bool isLowEnergy(const G4LogicalVolume*, const G4Track*) const;
0049   void PrintKilledTrack(const G4Track*, const TrackStatus&) const;
0050 
0051   EventAction* eventAction_;
0052   const G4VPhysicalVolume *tracker, *calo;
0053   const CMSSteppingVerbose* steppingVerbose;
0054   double theCriticalEnergyForVacuum;
0055   double theCriticalDensity;
0056   double maxTrackTime;
0057   double maxTrackTimeForward;
0058   double maxZCentralCMS;
0059 
0060   unsigned int numberTimes;
0061   unsigned int numberEkins;
0062   unsigned int numberPart;
0063   unsigned int ndeadRegions;
0064   unsigned int nWarnings;
0065   G4int maxNumberOfSteps;
0066 
0067   bool initialized;
0068   bool killBeamPipe;
0069   bool hasWatcher;
0070 
0071   std::vector<double> maxTrackTimes, ekinMins;
0072   std::vector<std::string> maxTimeNames, ekinNames, ekinParticles;
0073   std::vector<std::string> deadRegionNames;
0074   std::vector<const G4Region*> maxTimeRegions;
0075   std::vector<const G4Region*> deadRegions;
0076   std::vector<G4LogicalVolume*> ekinVolumes;
0077   std::vector<int> ekinPDG;
0078 };
0079 
0080 inline bool SteppingAction::isInsideDeadRegion(const G4Region* reg) const {
0081   bool res = false;
0082   for (auto& region : deadRegions) {
0083     if (reg == region) {
0084       res = true;
0085       break;
0086     }
0087   }
0088   return res;
0089 }
0090 
0091 inline bool SteppingAction::isOutOfTimeWindow(const G4Region* reg, const double& time) const {
0092   double tofM = maxTrackTime;
0093   for (unsigned int i = 0; i < numberTimes; ++i) {
0094     if (reg == maxTimeRegions[i]) {
0095       tofM = maxTrackTimes[i];
0096       break;
0097     }
0098   }
0099   return (time > tofM);
0100 }
0101 
0102 inline bool SteppingAction::isThisVolume(const G4VTouchable* touch, const G4VPhysicalVolume* pv) const {
0103   int level = (touch->GetHistoryDepth()) + 1;
0104   return (level >= 3) ? (touch->GetVolume(level - 3) == pv) : false;
0105 }
0106 
0107 #endif