Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "SimG4CMS/Forward/interface/PltSD.h"
0002 #include "SimG4CMS/Forward/interface/ForwardName.h"
0003 
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 #include "G4Step.hh"
0008 #include "G4StepPoint.hh"
0009 #include "G4Track.hh"
0010 #include "G4ThreeVector.hh"
0011 
0012 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0013 #include "CLHEP/Units/GlobalPhysicalConstants.h"
0014 
0015 #include <iostream>
0016 
0017 //#define EDM_ML_DEBUG
0018 
0019 PltSD::PltSD(const std::string& name,
0020              const SensitiveDetectorCatalog& clg,
0021              edm::ParameterSet const& p,
0022              const SimTrackManager* manager)
0023     : TimingSD(name, clg, manager) {
0024   edm::ParameterSet m_TrackerSD = p.getParameter<edm::ParameterSet>("PltSD");
0025   energyCut =
0026       m_TrackerSD.getParameter<double>("EnergyThresholdForPersistencyInGeV") * CLHEP::GeV;  //default must be 0.5
0027   energyHistoryCut =
0028       m_TrackerSD.getParameter<double>("EnergyThresholdForHistoryInGeV") * CLHEP::GeV;  //default must be 0.05
0029 
0030   setCuts(energyCut, energyHistoryCut);
0031 }
0032 
0033 PltSD::~PltSD() {}
0034 
0035 uint32_t PltSD::setDetUnitId(const G4Step* aStep) {
0036   unsigned int detId = 0;
0037 
0038 #ifdef EDM_ML_DEBUG
0039   edm::LogVerbatim("PltSD") << " DetID = " << detId;
0040 #endif
0041   //Find number of levels
0042   const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0043   int level = 0;
0044   if (touch)
0045     level = ((touch->GetHistoryDepth()) + 1);
0046 
0047   //Get name and copy numbers
0048   if (level > 1) {
0049     //some debugging with the names
0050     std::string sensorName = ForwardName::getName(touch->GetVolume(2)->GetName());
0051     std::string telName = ForwardName::getName(touch->GetVolume(3)->GetName());
0052     std::string volumeName = ForwardName::getName(touch->GetVolume(4)->GetName());
0053     if (sensorName != "PLTSensorPlane")
0054       edm::LogVerbatim("PltSD") << " PltSD::setDetUnitId -w- Sensor name not PLTSensorPlane ";
0055     if (telName != "Telescope")
0056       edm::LogVerbatim("PltSD") << " PltSD::setDetUnitId -w- Telescope name not Telescope ";
0057     if (volumeName != "PLT")
0058       edm::LogVerbatim("PltSD") << " PltSD::setDetUnitId -w- Volume name not PLT ";
0059 
0060     //Get the information about which telescope, plane, row/column was hit
0061     int columnNum = touch->GetReplicaNumber(0);
0062     int rowNum = touch->GetReplicaNumber(1);
0063     int sensorNum = touch->GetReplicaNumber(2);
0064     int telNum = touch->GetReplicaNumber(3);
0065     //temp stores the PLTBCM volume the hit occured in (i.e. was the hit on the + or -z side?)
0066     int temp = touch->GetReplicaNumber(5);
0067     //convert to the PLT hit id standard
0068     int pltNum;
0069     if (temp == 2)
0070       pltNum = 0;
0071     else
0072       pltNum = 1;
0073 
0074     //correct the telescope numbers on the -z side to have the same naming convention in phi as the +z side
0075     if (pltNum == 0) {
0076       if (telNum == 0) {
0077         telNum = 7;
0078       } else if (telNum == 1) {
0079         telNum = 6;
0080       } else if (telNum == 2) {
0081         telNum = 5;
0082       } else if (telNum == 3) {
0083         telNum = 4;
0084       } else if (telNum == 4) {
0085         telNum = 3;
0086       } else if (telNum == 5) {
0087         telNum = 2;
0088       } else if (telNum == 6) {
0089         telNum = 1;
0090       } else if (telNum == 7) {
0091         telNum = 0;
0092       }
0093     }
0094     //the PLT is divided into sets of telescopes on the + and -x sides
0095     int halfCarriageNum = -1;
0096 
0097     //If the telescope is on the -x side of the carriage, halfCarriageNum=0.  If on the +x side, it is = 1.
0098     if (telNum == 0 || telNum == 1 || telNum == 2 || telNum == 3)
0099       halfCarriageNum = 0;
0100     else
0101       halfCarriageNum = 1;
0102     //correct the telescope numbers of the +x half-carriage to range from 0 to 3
0103     if (halfCarriageNum == 1) {
0104       if (telNum == 4) {
0105         telNum = 0;
0106       } else if (telNum == 5) {
0107         telNum = 1;
0108       } else if (telNum == 6) {
0109         telNum = 2;
0110       } else if (telNum == 7) {
0111         telNum = 3;
0112       }
0113     }
0114     //Define unique detId for each pixel.  See https://twiki.cern.ch/twiki/bin/viewauth/CMS/PLTSimulationGuide for more information
0115     detId =
0116         10000000 * pltNum + 1000000 * halfCarriageNum + 100000 * telNum + 10000 * sensorNum + 100 * rowNum + columnNum;
0117 #ifdef EDM_ML_DEBUG
0118     edm::LogVerbatim("PltSD") << "Hit Recorded at "
0119                               << "plt:" << pltNum << " hc:" << halfCarriageNum << " tel:" << telNum
0120                               << " plane:" << sensorNum;
0121 #endif
0122   }
0123   return detId;
0124 }
0125 
0126 bool PltSD::checkHit(const G4Step*, BscG4Hit* hit) {
0127   // 50 micron are allowed between the exit
0128   // point of the current hit and the entry point of the new hit
0129   static const float tolerance2 = (float)(0.0025 * CLHEP::mm * CLHEP::mm);
0130   return ((hit->getExitLocalP() - getLocalEntryPoint()).mag2() < tolerance2);
0131 }