Skip to content

Commit

Permalink
Backport SimCore/SimG4CMS related files which can work with the new R…
Browse files Browse the repository at this point in the history
…un3 geometry
  • Loading branch information
Sunanda committed Jan 22, 2022
1 parent 2211742 commit 24f0ae9
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 86 deletions.
3 changes: 3 additions & 0 deletions Configuration/Eras/python/Modifier_run2_ECAL_2018_cff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import FWCore.ParameterSet.Config as cms

run2_ECAL_2018 = cms.Modifier()
4 changes: 4 additions & 0 deletions Configuration/Eras/python/Modifier_run3_geomOld_cff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import FWCore.ParameterSet.Config as cms

run3_geomOld = cms.Modifier()

12 changes: 12 additions & 0 deletions SimG4CMS/Forward/interface/ForwardName.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef SimG4CMSForward_ForwardName_h
#define SimG4CMSForward_ForwardName_h

#include <G4String.hh>
#include <cstdint>
#include <string>

namespace ForwardName {
std::string getName(const G4String &);
}; // namespace ForwardName

#endif
3 changes: 2 additions & 1 deletion SimG4CMS/Forward/src/BHMNumberingScheme.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "SimG4CMS/Forward/interface/BHMNumberingScheme.h"
#include "SimG4CMS/Forward/interface/ForwardName.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "CLHEP/Units/GlobalSystemOfUnits.h"
#include "globals.hh"
Expand All @@ -17,7 +18,7 @@ void BHMNumberingScheme::detectorLevel(const G4Step* aStep, int& level, int* cop
const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
for (int ii = 0; ii < level; ++ii) {
int i = level - ii - 1;
name[ii] = touch->GetVolume(i)->GetName();
name[ii] = ForwardName::getName(touch->GetVolume(i)->GetName());
copyno[ii] = touch->GetReplicaNumber(i);
}
}
Expand Down
13 changes: 7 additions & 6 deletions SimG4CMS/Forward/src/Bcm1fSD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "SimDataFormats/SimHitMaker/interface/TrackingSlaveSD.h"

#include "SimG4Core/Notification/interface/TrackInformation.h"
#include "SimG4CMS/Forward/interface/ForwardName.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
Expand Down Expand Up @@ -52,16 +53,16 @@ uint32_t Bcm1fSD::setDetUnitId(const G4Step* aStep) {

//Get name and copy numbers
if (level > 1) {
G4String sensorName = touch->GetVolume(0)->GetName();
G4String diamondName = touch->GetVolume(1)->GetName();
G4String detectorName = touch->GetVolume(2)->GetName();
G4String volumeName = touch->GetVolume(3)->GetName();
std::string sensorName = ForwardName::getName(touch->GetVolume(0)->GetName());
std::string diamondName = ForwardName::getName(touch->GetVolume(1)->GetName());
std::string detectorName = ForwardName::getName(touch->GetVolume(2)->GetName());
std::string volumeName = ForwardName::getName(touch->GetVolume(3)->GetName());

if (sensorName != "BCM1FSensor") {
edm::LogWarning("ForwardSim") << "Bcm1fSD::setDetUnitId -w- Sensor name not BCM1FSensor ";
edm::LogWarning("ForwardSim") << "Bcm1fSD::setDetUnitId -w- Sensor name " << sensorName << " not BCM1FSensor ";
}
if (detectorName != "BCM1F") {
edm::LogWarning("ForwardSim") << " Bcm1fSD::setDetUnitId -w- Detector name not BCM1F ";
edm::LogWarning("ForwardSim") << " Bcm1fSD::setDetUnitId -w- Detector name " << detectorName << " not BCM1F ";
}
int sensorNo = touch->GetReplicaNumber(0);
int diamondNo = touch->GetReplicaNumber(1);
Expand Down
5 changes: 3 additions & 2 deletions SimG4CMS/Forward/src/BscNumberingScheme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
// Modifications:
///////////////////////////////////////////////////////////////////////////////
#include "SimG4CMS/Forward/interface/BscNumberingScheme.h"
#include "SimG4CMS/Forward/interface/ForwardName.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
//
#include "CLHEP/Units/GlobalSystemOfUnits.h"
#include "globals.hh"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

BscNumberingScheme::BscNumberingScheme() { LogDebug("BscSim") << " Creating BscNumberingScheme"; }

Expand All @@ -24,7 +25,7 @@ void BscNumberingScheme::detectorLevel(const G4Step* aStep, int& level, int* cop
const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
for (int ii = 0; ii < level; ++ii) {
int i = level - ii - 1;
name[ii] = touch->GetVolume(i)->GetName();
name[ii] = ForwardName::getName(touch->GetVolume(i)->GetName());
copyno[ii] = touch->GetReplicaNumber(i);
}
}
Expand Down
13 changes: 13 additions & 0 deletions SimG4CMS/Forward/src/ForwardName.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "SimG4CMS/Forward/interface/ForwardName.h"

std::string ForwardName::getName(const G4String& namx) {
std::string name = static_cast<std::string>(namx);
if (name.find(':') == std::string::npos) {
return name;
} else {
std::size_t first = name.find(':') + 1;
std::size_t last = name.rfind('_');
std::size_t length = (last != std::string::npos) ? (last - first) : (name.size() - first);
return name.substr(first, length);
}
}
7 changes: 4 additions & 3 deletions SimG4CMS/Forward/src/PltSD.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "SimG4CMS/Forward/interface/PltSD.h"
#include "SimG4CMS/Forward/interface/ForwardName.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
Expand Down Expand Up @@ -46,9 +47,9 @@ uint32_t PltSD::setDetUnitId(const G4Step* aStep) {
//Get name and copy numbers
if (level > 1) {
//some debugging with the names
G4String sensorName = touch->GetVolume(2)->GetName();
G4String telName = touch->GetVolume(3)->GetName();
G4String volumeName = touch->GetVolume(4)->GetName();
std::string sensorName = ForwardName::getName(touch->GetVolume(2)->GetName());
std::string telName = ForwardName::getName(touch->GetVolume(3)->GetName());
std::string volumeName = ForwardName::getName(touch->GetVolume(4)->GetName());
if (sensorName != "PLTSensorPlane")
edm::LogVerbatim("PltSD") << " PltSD::setDetUnitId -w- Sensor name not PLTSensorPlane ";
if (telName != "Telescope")
Expand Down
12 changes: 8 additions & 4 deletions SimG4CMS/Forward/src/TotemT1Organization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// user include files
#include "SimG4CMS/Forward/interface/TotemT1Organization.h"
#include "SimG4CMS/Forward/interface/TotemNumberMerger.h"
#include "SimG4CMS/Forward/interface/ForwardName.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "G4VPhysicalVolume.hh"
Expand Down Expand Up @@ -58,10 +59,13 @@ uint32_t TotemT1Organization ::getUnitID(const G4Step* aStep) {
<< ", physVol->GetCopyNo()=" << physVol->GetCopyNo();
#endif

if (physVol->GetName() == "TotemT1" && physVol->GetCopyNo() == 1)
_currentDetectorPosition = 1;
if (physVol->GetName() == "TotemT1" && physVol->GetCopyNo() == 2)
_currentDetectorPosition = 2;
std::string dName = ForwardName::getName(physVol->GetName());
if (dName == "TotemT1") {
if (physVol->GetCopyNo() == 1)
_currentDetectorPosition = 1;
else if (physVol->GetCopyNo() == 2)
_currentDetectorPosition = 2;
}
}

touch = aStep->GetPreStepPoint()->GetTouchable();
Expand Down
46 changes: 24 additions & 22 deletions SimG4CMS/Forward/src/TotemT2OrganizationGem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// user include files
#include "SimG4CMS/Forward/interface/TotemT2OrganizationGem.h"
#include "SimG4CMS/Forward/interface/TotemNumberMerger.h"
#include "SimG4CMS/Forward/interface/ForwardName.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "G4VPhysicalVolume.hh"
Expand Down Expand Up @@ -46,49 +47,50 @@ uint32_t TotemT2OrganizationGem ::getUnitID(const G4Step* aStep) const {

physVol = touch->GetVolume(0);

if (physVol->GetName() == "TotemT2gem")
std::string dName = ForwardName::getName(physVol->GetName());
if (dName == "TotemT2gem")
UNITA = 10 + physVol->GetCopyNo();
if (physVol->GetName() == "TotemT2gem_supporto")
else if (dName == "TotemT2gem_supporto")
UNITA = 20 + physVol->GetCopyNo();
if (physVol->GetName() == "TotemT2gem_detector7r")
else if (dName == "TotemT2gem_detector7r")
UNITA = 100 + physVol->GetCopyNo() + (touch->GetVolume(2)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_HC7r")
else if (dName == "TotemT2gem_HC7r")
UNITA = 200 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_drift7r")
else if (dName == "TotemT2gem_drift7r")
UNITA = 300 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_driftspace7r")
else if (dName == "TotemT2gem_driftspace7r")
UNITA = 400 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_GEMa7r")
else if (dName == "TotemT2gem_GEMa7r")
UNITA = 500 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_GEMb7r")
else if (dName == "TotemT2gem_GEMb7r")
UNITA = 600 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_GEMc7r")
else if (dName == "TotemT2gem_GEMc7r")
UNITA = 700 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_GAS7r")
else if (dName == "TotemT2gem_GAS7r")
UNITA = 800 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_GEMa17r")
else if (dName == "TotemT2gem_GEMa17r")
UNITA = 900 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_GEMb17r")
else if (dName == "TotemT2gem_GEMb17r")
UNITA = 1000 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_GEMc17r")
else if (dName == "TotemT2gem_GEMc17r")
UNITA = 1100 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_GAS17r")
else if (dName == "TotemT2gem_GAS17r")
UNITA = 1200 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_GEMa27r")
else if (dName == "TotemT2gem_GEMa27r")
UNITA = 1300 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_GEMb27r")
else if (dName == "TotemT2gem_GEMb27r")
UNITA = 1400 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_GEMc27r")
else if (dName == "TotemT2gem_GEMc27r")
UNITA = 1500 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_GAS27r")
else if (dName == "TotemT2gem_GAS27r")
UNITA = 1600 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_strips7r")
else if (dName == "TotemT2gem_strips7r")
UNITA = 1700 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_isol7r")
else if (dName == "TotemT2gem_isol7r")
UNITA = 1800 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_pads7r")
else if (dName == "TotemT2gem_pads7r")
UNITA = 1900 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;
if (physVol->GetName() == "TotemT2gem_HC17r")
else if (dName == "TotemT2gem_HC17r")
UNITA = 2000 + touch->GetVolume(1)->GetCopyNo() + (touch->GetVolume(3)->GetCopyNo()) * 1000;

return UNITA;
Expand Down
3 changes: 2 additions & 1 deletion SimG4CMS/Forward/src/ZdcNumberingScheme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Modifications:
///////////////////////////////////////////////////////////////////////////////
#include "SimG4CMS/Forward/interface/ZdcNumberingScheme.h"
#include "SimG4CMS/Forward/interface/ForwardName.h"
#include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "CLHEP/Units/GlobalSystemOfUnits.h"
Expand Down Expand Up @@ -167,7 +168,7 @@ void ZdcNumberingScheme::detectorLevel(const G4Step* aStep, int& level, int* cop
const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
for (int ii = 0; ii < level; ii++) {
int i = level - ii - 1;
name[ii] = touch->GetVolume(i)->GetName();
name[ii] = ForwardName::getName(touch->GetVolume(i)->GetName());
copyno[ii] = touch->GetReplicaNumber(i);
}
}
Expand Down
5 changes: 3 additions & 2 deletions SimG4CMS/Forward/src/ZdcSD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <memory>

#include "SimG4CMS/Forward/interface/ZdcSD.h"
#include "SimG4CMS/Forward/interface/ForwardName.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"
Expand Down Expand Up @@ -122,7 +123,7 @@ double ZdcSD::getEnergyDeposit(const G4Step* aStep) {
// preStepPoint information
G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
const G4String& nameVolume = currentPV->GetName();
std::string nameVolume = ForwardName::getName(currentPV->GetName());

const G4ThreeVector& hitPoint = preStepPoint->GetPosition();
const G4ThreeVector& hit_mom = preStepPoint->GetMomentumDirection();
Expand Down Expand Up @@ -155,7 +156,7 @@ double ZdcSD::getEnergyDeposit(const G4Step* aStep) {
// postStepPoint information
G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
G4VPhysicalVolume* postPV = postStepPoint->GetPhysicalVolume();
const G4String& postnameVolume = postPV->GetName();
std::string postnameVolume = ForwardName::getName(postPV->GetName());
edm::LogVerbatim("ForwardSim") << "ZdcSD:: getEnergyDeposit: \n"
<< " preStepPoint: " << nameVolume << "," << stepL << "," << stepE << "," << beta
<< "," << charge << "\n"
Expand Down
18 changes: 11 additions & 7 deletions SimG4CMS/Muon/interface/MuonSensitiveDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "SimG4Core/SensitiveDetector/interface/SensitiveTkDetector.h"
#include "DataFormats/GeometryVector/interface/LocalPoint.h"
#include "CondFormats/GeometryObjects/interface/MuonOffsetMap.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "Geometry/MuonNumbering/interface/MuonGeometryConstants.h"

#include <string>
Expand All @@ -41,10 +42,7 @@ class MuonSensitiveDetector : public SensitiveTkDetector, public Observer<const
const MuonOffsetMap*,
const MuonGeometryConstants&,
const SensitiveDetectorCatalog&,
double ePersistentCutGeV,
bool allMuonsPersistent,
bool aPrintHits,
bool dd4hep,
edm::ParameterSet const& p,
const SimTrackManager*);
~MuonSensitiveDetector() override;
G4bool ProcessHits(G4Step*, G4TouchableHistory*) override;
Expand All @@ -61,6 +59,7 @@ class MuonSensitiveDetector : public SensitiveTkDetector, public Observer<const

private:
inline Local3DPoint cmsUnits(const Local3DPoint& v) { return Local3DPoint(v.x() * 0.1, v.y() * 0.1, v.z() * 0.1); }
bool acceptHit(uint32_t id);

MuonSlaveSD* slaveMuon;
MuonSimHitNumberingScheme* numbering;
Expand All @@ -87,12 +86,17 @@ class MuonSensitiveDetector : public SensitiveTkDetector, public Observer<const
uint32_t newDetUnitId;
int theTrackID;

bool printHits;
bool printHits_;
SimHitPrinter* thePrinter;

//--- SimTracks cuts
float ePersistentCutGeV;
bool allMuonsPersistent;
float ePersistentCutGeV_;
bool allMuonsPersistent_;

// For choice of demo chambers
bool haveDemo_;
bool demoGEM_;
bool demoRPC_;

G4ProcessTypeEnumerator* theG4ProcessTypeEnumerator;

Expand Down
11 changes: 2 additions & 9 deletions SimG4CMS/Muon/plugins/MuonSensitiveDetectorBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@ class MuonSensitiveDetectorBuilder : public SensitiveDetectorMakerBase {
: offmap_{nullptr},
mdc_{nullptr},
offsetToken_{cc.esConsumes<edm::Transition::BeginRun>()},
geomConstantsToken_{cc.esConsumes<edm::Transition::BeginRun>()} {
edm::ParameterSet muonSD = p.getParameter<edm::ParameterSet>("MuonSD");
ePersistentCutGeV_ = muonSD.getParameter<double>("EnergyThresholdForPersistency") / CLHEP::GeV; //Default 1. GeV
allMuonsPersistent_ = muonSD.getParameter<bool>("AllMuonsPersistent");
printHits_ = muonSD.getParameter<bool>("PrintHits");
dd4hep_ = p.getParameter<bool>("g4GeometryDD4hepSource");
}
geomConstantsToken_{cc.esConsumes<edm::Transition::BeginRun>()} {}

void beginRun(const edm::EventSetup& es) final {
edm::ESHandle<MuonOffsetMap> mom = es.getHandle(offsetToken_);
Expand All @@ -55,8 +49,7 @@ class MuonSensitiveDetectorBuilder : public SensitiveDetectorMakerBase {
const edm::ParameterSet& p,
const SimTrackManager* man,
SimActivityRegistry& reg) const final {
auto sd = std::make_unique<MuonSensitiveDetector>(
iname, offmap_, *mdc_, clg, ePersistentCutGeV_, allMuonsPersistent_, printHits_, dd4hep_, man);
auto sd = std::make_unique<MuonSensitiveDetector>(iname, offmap_, *mdc_, clg, p, man);
SimActivityRegistryEnroller::enroll(reg, sd.get());
return sd;
}
Expand Down
Loading

0 comments on commit 24f0ae9

Please sign in to comment.