Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-13 01:44:05

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/GlobalSystemOfUnits.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 = m_TrackerSD.getParameter<double>("EnergyThresholdForPersistencyInGeV") * GeV;  //default must be 0.5 (?)
0039   energyHistoryCut =
0040       m_TrackerSD.getParameter<double>("EnergyThresholdForHistoryInGeV") * GeV;  //default must be 0.05 (?)
0041 
0042   setCuts(energyCut, energyHistoryCut);
0043 }
0044 
0045 Bcm1fSD::~Bcm1fSD() {}
0046 
0047 uint32_t Bcm1fSD::setDetUnitId(const G4Step* aStep) {
0048   uint32_t detId = 0;
0049 
0050   //Find number of levels
0051   const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0052   int level = (touch) ? ((touch->GetHistoryDepth()) + 1) : 0;
0053 
0054   //Get name and copy numbers
0055   if (level > 1) {
0056     std::string sensorName = ForwardName::getName(touch->GetVolume(0)->GetName());
0057     std::string diamondName = ForwardName::getName(touch->GetVolume(1)->GetName());
0058     std::string detectorName = ForwardName::getName(touch->GetVolume(2)->GetName());
0059     std::string volumeName = ForwardName::getName(touch->GetVolume(3)->GetName());
0060 
0061     if (sensorName != "BCM1FSensor") {
0062       edm::LogWarning("ForwardSim") << "Bcm1fSD::setDetUnitId -w- Sensor name " << sensorName << " not BCM1FSensor ";
0063     }
0064     if (detectorName != "BCM1F") {
0065       edm::LogWarning("ForwardSim") << " Bcm1fSD::setDetUnitId -w- Detector name " << detectorName << " not BCM1F ";
0066     }
0067     int sensorNo = touch->GetReplicaNumber(0);
0068     int diamondNo = touch->GetReplicaNumber(1);
0069     int volumeNo = touch->GetReplicaNumber(3);
0070 
0071     // Detector ID definition
0072     // detId = XYYZ
0073     // X  = volume,  1: +Z, 2: -Z
0074     // YY = diamond, 01-12, 12: phi = 90 deg, numbering clockwise when looking from the IP
0075     // Z  = sensor,  1 or 2, clockwise when looking from the IP
0076 
0077     detId = 1000 * volumeNo + 10 * diamondNo + sensorNo;
0078   }
0079   return detId;
0080 }
0081 
0082 bool Bcm1fSD::checkHit(const G4Step*, BscG4Hit* hit) {
0083   // 50 micron are allowed between the exit
0084   // point of the current hit and the entry point of the new hit
0085   static const float tolerance2 = (float)(0.0025 * CLHEP::mm * CLHEP::mm);
0086   return ((hit->getExitLocalP() - getLocalEntryPoint()).mag2() < tolerance2);
0087 }