CMS 3D CMS Logo

CMSFieldManager.cc
Go to the documentation of this file.
4 
5 #include "G4ChordFinder.hh"
6 #include "G4Track.hh"
7 #include "G4Region.hh"
8 #include "G4RegionStore.hh"
9 #include "G4PropagatorInField.hh"
10 #include "G4MagIntegratorStepper.hh"
11 #include "CLHEP/Units/GlobalSystemOfUnits.h"
12 
14  : G4FieldManager(), m_currChordFinder(nullptr), m_chordFinder(nullptr),
15  m_chordFinderMonopole(nullptr), m_propagator(nullptr), m_dChord(0.001),
16  m_dOneStep(0.001), m_dIntersection(0.0001), m_stepMax(1000000.),
17  m_energyThreshold(0.0), m_dChordSimple(0.1), m_dOneStepSimple(0.1),
18  m_dIntersectionSimple(0.01), m_stepMaxSimple(1000.), m_cfVacuum(false)
19 {}
20 
22 {
25 }
26 
28  G4ChordFinder* cf, G4ChordFinder* cfmon,
29  const std::string& vol, const std::string& type,
30  const std::string& stepper,
31  double delta,
32  G4PropagatorInField* pf)
33 {
34  double minstep = p.getParameter<double>("MinStep")*CLHEP::mm;
35  double minEpsStep =
36  p.getUntrackedParameter<double>("MinimumEpsilonStep",0.00001)*CLHEP::mm;
37  double maxEpsStep =
38  p.getUntrackedParameter<double>("MaximumEpsilonStep",0.01)*CLHEP::mm;
39  int maxLC = (int)p.getUntrackedParameter<double>("MaximumLoopCounts",1000.);
40 
41  //double
42  m_dChord = p.getParameter<double>("DeltaChord")*CLHEP::mm;
43  m_dOneStep = p.getParameter<double>("DeltaOneStep")*CLHEP::mm;
44  m_dIntersection = p.getParameter<double>("DeltaIntersection")*CLHEP::mm;
45  m_stepMax = p.getParameter<double>("MaxStep")*CLHEP::cm;
46 
47  m_energyThreshold = p.getParameter<double>("EnergyThSimple")*CLHEP::GeV;
48 
49  //double
50  m_dChordSimple = p.getParameter<double>("DeltaChordSimple")*CLHEP::mm;
51  m_dOneStepSimple = p.getParameter<double>("DeltaOneStepSimple")*CLHEP::mm;
52  m_dIntersectionSimple = p.getParameter<double>("DeltaIntersectionSimple")*CLHEP::mm;
53  m_stepMaxSimple = p.getParameter<double>("MaxStepSimple")*CLHEP::cm;
54 
55  edm::LogVerbatim("SimG4CoreApplication")
56  << " New CMSFieldManager: LogicalVolume: <" << vol << ">\n"
57  << " Stepper: <" << stepper << ">\n"
58  << " Field type <" << type<< ">\n"
59  << " Field const delta " << delta << " mm\n"
60  << " MaximumLoopCounts " << maxLC<< "\n"
61  << " MinimumEpsilonStep " << minEpsStep<< "\n"
62  << " MaximumEpsilonStep " << maxEpsStep<< "\n"
63  << " MinStep " << minstep<< " mm\n"
64  << " MaxStep " << m_stepMax/CLHEP::cm<< " cm\n"
65  << " DeltaChord " << m_dChord<< " mm\n"
66  << " DeltaOneStep " << m_dOneStep<< " mm\n"
67  << " DeltaIntersection " << m_dIntersection<< " mm\n"
68  << " EnergyThreshold " << m_energyThreshold<< " MeV\n"
69  << " DeltaChordSimple " << m_dChordSimple<< " mm\n"
70  << " DeltaOneStepSimple " << m_dOneStepSimple<< " mm\n"
71  << " DeltaIntersectionSimple " << m_dIntersectionSimple<< " mm\n"
72  << " MaxStepInVacuum " << m_stepMaxSimple/CLHEP::cm<< " cm";
73 
74  // initialisation of chord finders
75  m_chordFinder = cf;
76  m_chordFinderMonopole = cfmon;
77 
78  // m_chordFinder->SetDeltaChord(dChord);
79  m_chordFinderMonopole->SetDeltaChord(m_dChord);
80 
81  // initialisation of field manager
82  theField.reset(field);
83  SetDetectorField(field);
84  SetMinimumEpsilonStep(minEpsStep);
85  SetMaximumEpsilonStep(maxEpsStep);
86 
87  // propagater in field
88  m_propagator = pf;
89  pf->SetMaxLoopCount(maxLC);
90  pf->SetMinimumEpsilonStep(minEpsStep);
91  pf->SetMaximumEpsilonStep(maxEpsStep);
92 
93  // initial initialisation the default chord finder is defined
94  SetMonopoleTracking(false);
95 
96  // define regions
97  std::vector<std::string> rnames = p.getParameter<std::vector<std::string> >("VacRegions");
98  if(!rnames.empty()) {
99  std::stringstream ss;
100  std::vector<G4Region*> *rs = G4RegionStore::GetInstance();
101  for (auto & regnam : rnames) {
102  for (auto & reg : *rs) {
103  if(regnam == reg->GetName()) {
104  m_regions.push_back(reg);
105  ss << " " << regnam;
106  }
107  }
108  }
109  edm::LogVerbatim("SimG4CoreApplication") << "Simple field integration in G4Regions:\n"
110  << ss.str() << "\n";
111  }
112 }
113 
115 {
116  // run time parameters per track
117  if((track->GetKineticEnergy() <= m_energyThreshold && track->GetParentID() > 0)
118  || isInsideVacuum(track)) {
120 
121  } else if(m_cfVacuum) {
122  // restore defaults
124  }
125 }
126 
128 {
129  if(flag) {
133  SetChordFinder(m_currChordFinder);
134  }
135  } else {
137  }
138  SetFieldChangesEnergy(flag);
139  m_currChordFinder->ResetStepEstimate();
140 }
141 
143 {
144  if(!m_regions.empty()) {
145  const G4Region* reg = track->GetVolume()->GetLogicalVolume()->GetRegion();
146  for (auto & areg : m_regions) {
147  if(reg == areg) { return true; }
148  }
149  }
150  return false;
151 }
152 
154 {
156  m_currChordFinder->SetDeltaChord(m_dChord);
157  SetChordFinder(m_currChordFinder);
158  SetDeltaOneStep(m_dOneStep);
159  SetDeltaIntersection(m_dIntersection);
160  m_propagator->SetLargestAcceptableStep(m_stepMax);
161  m_cfVacuum = false;
162 }
163 
165 {
166  m_currChordFinder->SetDeltaChord(m_dChordSimple);
167  SetDeltaOneStep(m_dOneStepSimple);
168  SetDeltaIntersection(m_dIntersectionSimple);
169  m_propagator->SetLargestAcceptableStep(m_stepMaxSimple);
170  m_cfVacuum = true;
171 }
G4ChordFinder * m_chordFinder
dbl * delta
Definition: mlp_gen.cc:36
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
double m_dIntersectionSimple
T getUntrackedParameter(std::string const &, T const &) const
void setDefaultChordFinder()
const double GeV
Definition: MathUtil.h:16
double m_energyThreshold
#define nullptr
~CMSFieldManager() override
G4PropagatorInField * m_propagator
G4ChordFinder * m_currChordFinder
void ConfigureForTrack(const G4Track *) override
bool isInsideVacuum(const G4Track *)
G4ChordFinder * m_chordFinderMonopole
std::vector< const G4Region * > m_regions
void setChordFinderForVacuum()
std::unique_ptr< sim::Field > theField
void InitialiseForVolume(const edm::ParameterSet &, sim::Field *, G4ChordFinder *cfDefault, G4ChordFinder *cfMonopole, const std::string &vol, const std::string &fieldType, const std::string &stepperName, double delta, G4PropagatorInField *)
void SetMonopoleTracking(G4bool)