File indexing completed on 2024-05-10 02:21:18
0001 #include "SimG4CMS/Forward/interface/Bcm1fSD.h"
0002
0003 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0004 #include "DataFormats/GeometryVector/interface/LocalVector.h"
0005
0006 #include "SimG4Core/Notification/interface/TrackInformation.h"
0007 #include "SimG4Core/Notification/interface/G4TrackToParticleID.h"
0008 #include "SimG4Core/Physics/interface/G4ProcessTypeEnumerator.h"
0009
0010 #include "SimDataFormats/TrackingHit/interface/UpdatablePSimHit.h"
0011 #include "SimDataFormats/SimHitMaker/interface/TrackingSlaveSD.h"
0012
0013 #include "SimG4Core/Notification/interface/TrackInformation.h"
0014 #include "SimG4CMS/Forward/interface/ForwardName.h"
0015
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018
0019 #include "G4Track.hh"
0020 #include "G4SDManager.hh"
0021 #include "G4VProcess.hh"
0022 #include "G4EventManager.hh"
0023 #include "G4Event.hh"
0024 #include "G4VProcess.hh"
0025
0026 #include <string>
0027 #include <vector>
0028 #include <iostream>
0029
0030 #include <CLHEP/Units/SystemOfUnits.h>
0031
0032 Bcm1fSD::Bcm1fSD(const std::string& name,
0033 const SensitiveDetectorCatalog& clg,
0034 edm::ParameterSet const& p,
0035 const SimTrackManager* manager)
0036 : TimingSD(name, clg, manager) {
0037 edm::ParameterSet m_TrackerSD = p.getParameter<edm::ParameterSet>("Bcm1fSD");
0038 energyCut =
0039 m_TrackerSD.getParameter<double>("EnergyThresholdForPersistencyInGeV") * CLHEP::GeV;
0040 energyHistoryCut =
0041 m_TrackerSD.getParameter<double>("EnergyThresholdForHistoryInGeV") * CLHEP::GeV;
0042
0043 setCuts(energyCut, energyHistoryCut);
0044 }
0045
0046 Bcm1fSD::~Bcm1fSD() {}
0047
0048 uint32_t Bcm1fSD::setDetUnitId(const G4Step* aStep) {
0049 uint32_t detId = 0;
0050
0051
0052 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0053 int level = (touch) ? ((touch->GetHistoryDepth()) + 1) : 0;
0054
0055
0056 if (level > 1) {
0057 std::string sensorName = ForwardName::getName(touch->GetVolume(0)->GetName());
0058 std::string diamondName = ForwardName::getName(touch->GetVolume(1)->GetName());
0059 std::string detectorName = ForwardName::getName(touch->GetVolume(2)->GetName());
0060 std::string volumeName = ForwardName::getName(touch->GetVolume(3)->GetName());
0061
0062 if (sensorName != "BCM1FSensor") {
0063 edm::LogWarning("ForwardSim") << "Bcm1fSD::setDetUnitId -w- Sensor name " << sensorName << " not BCM1FSensor ";
0064 }
0065 if (detectorName != "BCM1F") {
0066 edm::LogWarning("ForwardSim") << " Bcm1fSD::setDetUnitId -w- Detector name " << detectorName << " not BCM1F ";
0067 }
0068 int sensorNo = touch->GetReplicaNumber(0);
0069 int diamondNo = touch->GetReplicaNumber(1);
0070 int volumeNo = touch->GetReplicaNumber(3);
0071
0072
0073
0074
0075
0076
0077
0078 detId = 1000 * volumeNo + 10 * diamondNo + sensorNo;
0079 }
0080 return detId;
0081 }
0082
0083 bool Bcm1fSD::checkHit(const G4Step*, BscG4Hit* hit) {
0084
0085
0086 static const float tolerance2 = (float)(0.0025 * CLHEP::mm * CLHEP::mm);
0087 return ((hit->getExitLocalP() - getLocalEntryPoint()).mag2() < tolerance2);
0088 }