Skip to content

Commit

Permalink
Merge pull request #31665 from civanch/mag_field_param
Browse files Browse the repository at this point in the history
Added extar parameters for Geant4 tracking in field
  • Loading branch information
cmsbuild authored Oct 14, 2020
2 parents d3fe185 + d89060d commit 242ecd0
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 24 deletions.
18 changes: 12 additions & 6 deletions SimG4Core/Application/python/g4SimHits_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,22 @@
StepperParam = cms.PSet(
VacRegions = cms.vstring(),
# VacRegions = cms.vstring('DefaultRegionForTheWorld','BeamPipeVacuum','BeamPipeOutside'),
MaximumEpsilonStep = cms.untracked.double(0.01), ## in mm
EnergyThTracker = cms.double(100000), ## in GeV
RmaxTracker = cms.double(8000), ## in mm
ZmaxTracker = cms.double(11000), ## in mm
MaximumEpsilonStep = cms.untracked.double(0.01),
DeltaOneStep = cms.double(0.001), ## in mm
DeltaOneStepTracker = cms.double(1e-4),## in mm
MaximumLoopCounts = cms.untracked.double(1000.0),
DeltaChord = cms.double(0.001), ## in mm
MinStep = cms.double(0.1), ## in mm
DeltaChord = cms.double(0.001), ## in mm
DeltaChordTracker = cms.double(0.001), ## in mm
MinStep = cms.double(0.1), ## in mm
DeltaIntersectionAndOneStep = cms.untracked.double(-1.0),
DeltaIntersection = cms.double(0.0001),## in mm
DeltaIntersection = cms.double(0.0001), ## in mm
DeltaIntersectionTracker = cms.double(1e-6),## in mm
MaxStep = cms.double(150.), ## in cm
MinimumEpsilonStep = cms.untracked.double(1e-05), ## in mm
EnergyThSimple = cms.double(0.015), ## in GeV
MinimumEpsilonStep = cms.untracked.double(1e-05),
EnergyThSimple = cms.double(0.015), ## in GeV
DeltaChordSimple = cms.double(0.1), ## in mm
DeltaOneStepSimple = cms.double(0.1), ## in mm
DeltaIntersectionSimple = cms.double(0.01), ## in mm
Expand Down
2 changes: 1 addition & 1 deletion SimG4Core/Application/src/RunManagerMTWorker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ std::unique_ptr<G4SimEvent> RunManagerMTWorker::produce(const edm::Event& inpevt
if (!(m_tls && m_tls->threadInitialized)) {
edm::LogVerbatim("SimG4CoreApplication")
<< "RunManagerMTWorker::produce(): stream " << inpevt.streamID() << " thread " << getThreadIndex()
<< " initializing in the produce(..) method - there is a problem";
<< " Geant4 initialisation for this thread";
initializeG4(&runManagerMaster, es);
m_tls->threadInitialized = true;
}
Expand Down
17 changes: 13 additions & 4 deletions SimG4Core/MagneticField/interface/CMSFieldManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@ class CMSFieldManager : public G4FieldManager {
double delta,
G4PropagatorInField *);

void SetMonopoleTracking(G4bool);
void setMonopoleTracking(G4bool);

CMSFieldManager(const CMSFieldManager &) = delete;
CMSFieldManager &operator=(const CMSFieldManager &) = delete;

private:
bool isInsideVacuum(const G4Track *);
bool isInsideTracker(const G4Track *);
void setDefaultChordFinder();
void setChordFinderForTracker();
void setChordFinderForVacuum();

CMSFieldManager(const CMSFieldManager &) = delete;
CMSFieldManager &operator=(const CMSFieldManager &) = delete;

std::unique_ptr<sim::Field> theField;

G4ChordFinder *m_currChordFinder;
Expand All @@ -60,15 +62,22 @@ class CMSFieldManager : public G4FieldManager {
std::vector<const G4Region *> m_regions;

double m_dChord;
double m_dChordTracker;
double m_dOneStep;
double m_dOneStepTracker;
double m_dIntersection;
double m_dInterTracker;
double m_Rmax2;
double m_Zmax;
double m_stepMax;
double m_energyThTracker;
double m_energyThreshold;
double m_dChordSimple;
double m_dOneStepSimple;
double m_dIntersectionSimple;
double m_stepMaxSimple;

bool m_cfTracker;
bool m_cfVacuum;
};
#endif
69 changes: 58 additions & 11 deletions SimG4Core/MagneticField/src/CMSFieldManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ CMSFieldManager::CMSFieldManager()
m_chordFinderMonopole(nullptr),
m_propagator(nullptr),
m_dChord(0.001),
m_dChordTracker(0.001),
m_dOneStep(0.001),
m_dOneStepTracker(0.0001),
m_dIntersection(0.0001),
m_dInterTracker(1e-6),
m_Rmax2(1.e+6),
m_Zmax(3.e+3),
m_stepMax(1000000.),
m_energyThTracker(1.e+7),
m_energyThreshold(0.0),
m_dChordSimple(0.1),
m_dOneStepSimple(0.1),
m_dIntersectionSimple(0.01),
m_stepMaxSimple(1000.),
m_cfTracker(false),
m_cfVacuum(false) {}

CMSFieldManager::~CMSFieldManager() {
Expand Down Expand Up @@ -52,13 +59,20 @@ void CMSFieldManager::InitialiseForVolume(const edm::ParameterSet &p,

// double
m_dChord = p.getParameter<double>("DeltaChord") * CLHEP::mm;
m_dChordTracker = p.getParameter<double>("DeltaChord") * CLHEP::mm;
m_dOneStep = p.getParameter<double>("DeltaOneStep") * CLHEP::mm;
m_dOneStepTracker = p.getParameter<double>("DeltaOneStepTracker") * CLHEP::mm;
m_dIntersection = p.getParameter<double>("DeltaIntersection") * CLHEP::mm;
m_dInterTracker = p.getParameter<double>("DeltaIntersectionTracker") * CLHEP::mm;
m_stepMax = p.getParameter<double>("MaxStep") * CLHEP::cm;

m_energyThreshold = p.getParameter<double>("EnergyThSimple") * CLHEP::GeV;
m_energyThTracker = p.getParameter<double>("EnergyThTracker") * CLHEP::GeV;

double rmax = p.getParameter<double>("RmaxTracker") * CLHEP::mm;
m_Rmax2 = rmax * rmax;
m_Zmax = p.getParameter<double>("ZmaxTracker") * CLHEP::mm;

// double
m_dChordSimple = p.getParameter<double>("DeltaChordSimple") * CLHEP::mm;
m_dOneStepSimple = p.getParameter<double>("DeltaOneStepSimple") * CLHEP::mm;
m_dIntersectionSimple = p.getParameter<double>("DeltaIntersectionSimple") * CLHEP::mm;
Expand All @@ -77,7 +91,9 @@ void CMSFieldManager::InitialiseForVolume(const edm::ParameterSet &p,
<< " DeltaChord " << m_dChord << " mm\n"
<< " DeltaOneStep " << m_dOneStep << " mm\n"
<< " DeltaIntersection " << m_dIntersection << " mm\n"
<< " EnergyThreshold " << m_energyThreshold << " MeV\n"
<< " DeltaInterTracker " << m_dInterTracker << " mm\n"
<< " EnergyThresholdSimple " << m_energyThreshold / CLHEP::MeV << " MeV\n"
<< " EnergyThresholdTracker " << m_energyThTracker / CLHEP::MeV << " MeV\n"
<< " DeltaChordSimple " << m_dChordSimple << " mm\n"
<< " DeltaOneStepSimple " << m_dOneStepSimple << " mm\n"
<< " DeltaIntersectionSimple " << m_dIntersectionSimple << " mm\n"
Expand All @@ -87,7 +103,6 @@ void CMSFieldManager::InitialiseForVolume(const edm::ParameterSet &p,
m_chordFinder = cf;
m_chordFinderMonopole = cfmon;

// m_chordFinder->SetDeltaChord(dChord);
m_chordFinderMonopole->SetDeltaChord(m_dChord);

// initialisation of field manager
Expand All @@ -102,8 +117,8 @@ void CMSFieldManager::InitialiseForVolume(const edm::ParameterSet &p,
pf->SetMinimumEpsilonStep(minEpsStep);
pf->SetMaximumEpsilonStep(maxEpsStep);

// initial initialisation the default chord finder is defined
SetMonopoleTracking(false);
// initial initialisation the default chord finder
setMonopoleTracking(false);

// define regions
std::vector<std::string> rnames = p.getParameter<std::vector<std::string>>("VacRegions");
Expand All @@ -124,21 +139,26 @@ void CMSFieldManager::InitialiseForVolume(const edm::ParameterSet &p,

void CMSFieldManager::ConfigureForTrack(const G4Track *track) {
// run time parameters per track
if ((track->GetKineticEnergy() <= m_energyThreshold && track->GetParentID() > 0) || isInsideVacuum(track)) {
if (track->GetKineticEnergy() > m_energyThTracker && isInsideTracker(track)) {
if (!m_cfTracker) {
setChordFinderForTracker();
}

} else if ((track->GetKineticEnergy() <= m_energyThreshold && track->GetParentID() > 0) || isInsideVacuum(track)) {
if (!m_cfVacuum) {
setChordFinderForVacuum();
}

} else if (m_cfVacuum) {
} else if (m_cfTracker || m_cfVacuum) {
// restore defaults
setDefaultChordFinder();
}
}

void CMSFieldManager::SetMonopoleTracking(G4bool flag) {
void CMSFieldManager::setMonopoleTracking(G4bool flag) {
if (flag) {
if (m_currChordFinder != m_chordFinderMonopole) {
if (m_cfVacuum) {
if (m_cfTracker || m_cfVacuum) {
setDefaultChordFinder();
}
m_currChordFinder = m_chordFinderMonopole;
Expand All @@ -163,20 +183,47 @@ bool CMSFieldManager::isInsideVacuum(const G4Track *track) {
return false;
}

bool CMSFieldManager::isInsideTracker(const G4Track *track) {
const G4ThreeVector &pos = track->GetPosition();
const double x = pos.x();
const double y = pos.y();
return (x * x + y * y < m_Rmax2 && std::abs(pos.z()) < m_Zmax);
}

void CMSFieldManager::setDefaultChordFinder() {
m_currChordFinder = m_chordFinder;
if (m_currChordFinder != m_chordFinder) {
m_currChordFinder = m_chordFinder;
SetChordFinder(m_currChordFinder);
}
m_currChordFinder->SetDeltaChord(m_dChord);
SetChordFinder(m_currChordFinder);
SetDeltaOneStep(m_dOneStep);
SetDeltaIntersection(m_dIntersection);
m_propagator->SetLargestAcceptableStep(m_stepMax);
m_cfVacuum = m_cfTracker = false;
}

void CMSFieldManager::setChordFinderForTracker() {
if (m_currChordFinder != m_chordFinder) {
m_currChordFinder = m_chordFinder;
SetChordFinder(m_currChordFinder);
}
m_currChordFinder->SetDeltaChord(m_dChordTracker);
SetDeltaOneStep(m_dOneStepTracker);
SetDeltaIntersection(m_dInterTracker);
m_propagator->SetLargestAcceptableStep(m_stepMax);
m_cfVacuum = false;
m_cfTracker = true;
}

void CMSFieldManager::setChordFinderForVacuum() {
if (m_currChordFinder != m_chordFinder) {
m_currChordFinder = m_chordFinder;
SetChordFinder(m_currChordFinder);
}
m_currChordFinder->SetDeltaChord(m_dChordSimple);
SetDeltaOneStep(m_dOneStepSimple);
SetDeltaIntersection(m_dIntersectionSimple);
m_propagator->SetLargestAcceptableStep(m_stepMaxSimple);
m_cfVacuum = true;
m_cfTracker = false;
}
4 changes: 2 additions & 2 deletions SimG4Core/PhysicsLists/src/MonopoleTransportation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ G4double MonopoleTransportation::AlongStepGetPhysicalInteractionLength(const G4T
G4double& currentSafety,
G4GPILSelection* selection) {
// change to monopole equation
fieldMgrCMS->SetMonopoleTracking(true);
fieldMgrCMS->setMonopoleTracking(true);

G4double geometryStepLength, newSafety;
fParticleIsLooping = false;
Expand Down Expand Up @@ -515,7 +515,7 @@ G4VParticleChange* MonopoleTransportation::PostStepDoIt(const G4Track& track, co
fParticleChange.SetTouchableHandle(retCurrentTouchable);

// change to normal equation
fieldMgrCMS->SetMonopoleTracking(false);
fieldMgrCMS->setMonopoleTracking(false);

return &fParticleChange;
}
Expand Down

0 comments on commit 242ecd0

Please sign in to comment.