Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-22 22:49:22

0001 #include "SimG4CMS/Forward/interface/MtdSD.h"
0002 
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 
0006 #include "Geometry/MTDCommonData/interface/BTLNumberingScheme.h"
0007 #include "Geometry/MTDCommonData/interface/ETLNumberingScheme.h"
0008 #include "DataFormats/ForwardDetId/interface/MTDDetId.h"
0009 
0010 #include "G4Track.hh"
0011 #include "G4Step.hh"
0012 #include "G4StepPoint.hh"
0013 
0014 #include <iostream>
0015 
0016 //#define EDM_ML_DEBUG
0017 //-------------------------------------------------------------------
0018 MtdSD::MtdSD(const std::string& name,
0019              const SensitiveDetectorCatalog& clg,
0020              edm::ParameterSet const& p,
0021              const SimTrackManager* manager)
0022     : TimingSD(name, clg, manager), numberingScheme(nullptr) {
0023   //Parameters
0024   edm::ParameterSet m_p = p.getParameter<edm::ParameterSet>("MtdSD");
0025   int verbn = m_p.getUntrackedParameter<int>("Verbosity");
0026 
0027   SetVerboseLevel(verbn);
0028 
0029   MTDNumberingScheme* scheme = nullptr;
0030   if (name == "FastTimerHitsBarrel") {
0031     scheme = dynamic_cast<MTDNumberingScheme*>(new BTLNumberingScheme());
0032     isBTL = true;
0033   } else if (name == "FastTimerHitsEndcap") {
0034     scheme = dynamic_cast<MTDNumberingScheme*>(new ETLNumberingScheme());
0035     isETL = true;
0036   } else {
0037     scheme = nullptr;
0038     edm::LogWarning("MtdSim") << "MtdSD: ReadoutName not supported";
0039   }
0040   if (scheme)
0041     setNumberingScheme(scheme);
0042 
0043   double newTimeFactor = 1. / m_p.getParameter<double>("TimeSliceUnit");
0044   edm::LogVerbatim("MtdSim") << "New time factor = " << newTimeFactor;
0045   setTimeFactor(newTimeFactor);
0046 
0047   edm::LogVerbatim("MtdSim") << "MtdSD: Instantiation completed for " << name;
0048 }
0049 
0050 MtdSD::~MtdSD() {}
0051 
0052 uint32_t MtdSD::setDetUnitId(const G4Step* aStep) {
0053   if (numberingScheme == nullptr) {
0054     return MTDDetId();
0055   } else {
0056     getBaseNumber(aStep);
0057 #ifdef EDM_ML_DEBUG
0058     edm::LogVerbatim("MtdSim") << "DetId = " << numberingScheme->getUnitID(theBaseNumber);
0059 #endif
0060     return numberingScheme->getUnitID(theBaseNumber);
0061   }
0062 }
0063 
0064 void MtdSD::setNumberingScheme(MTDNumberingScheme* scheme) {
0065   if (scheme != nullptr) {
0066     edm::LogVerbatim("MtdSim") << "MtdSD: updates numbering scheme for " << GetName();
0067     if (numberingScheme)
0068       delete numberingScheme;
0069     numberingScheme = scheme;
0070   }
0071 }
0072 
0073 void MtdSD::getBaseNumber(const G4Step* aStep) {
0074   theBaseNumber.reset();
0075   const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0076   int theSize = touch->GetHistoryDepth() + 1;
0077   if (theBaseNumber.getCapacity() < theSize)
0078     theBaseNumber.setSize(theSize);
0079   //Get name and copy numbers
0080   if (theSize > 1) {
0081 #ifdef EDM_ML_DEBUG
0082     edm::LogVerbatim("MtdSim") << "Building MTD basenumber:";
0083 #endif
0084     for (int ii = 0; ii < theSize; ii++) {
0085       theBaseNumber.addLevel(touch->GetVolume(ii)->GetName(), touch->GetReplicaNumber(ii));
0086 #ifdef EDM_ML_DEBUG
0087       edm::LogVerbatim("MtdSim") << "MtdSD::getBaseNumber(): Adding level " << ii << ": "
0088                                  << touch->GetVolume(ii)->GetName() << "[" << touch->GetReplicaNumber(ii) << "]";
0089 #endif
0090     }
0091   }
0092 }