test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FieldBuilder.cc
Go to the documentation of this file.
3 
6 
10 #include "SimG4Core/MagneticField/interface/G4MonopoleEquation.hh"
12 
13 #include "G4Mag_UsualEqRhs.hh"
14 #include "G4ClassicalRK4.hh"
15 #include "G4PropagatorInField.hh"
16 #include "G4FieldManager.hh"
17 #include "G4TransportationManager.hh"
18 #include "G4ChordFinder.hh"
19 #include "G4UniformMagField.hh"
20 
22 
23 #include "G4LogicalVolumeStore.hh"
24 
25 using namespace sim;
26 
28  const edm::ParameterSet & p)
29  : theField(new Field(f, p.getParameter<double>("delta"))),
30  theFieldEquation(new G4Mag_UsualEqRhs(theField.get())),
31  theTopVolume(nullptr),
32  fieldValue(0.), minStep(0.), dChord(0.), dOneStep(0.),
33  dIntersection(0.), dIntersectionAndOneStep(0.),
34  maxLoopCount(0), minEpsilonStep(0.), maxEpsilonStep(0.),
35  thePSet(p)
36 {
37  delta = p.getParameter<double>("delta");
38  theField->fieldEquation(theFieldEquation);
39 }
40 
41 void FieldBuilder::build( G4FieldManager* fM, G4PropagatorInField* fP, ChordFinderSetter *setter)
42 {
43  edm::ParameterSet thePSetForGMFM =
44  thePSet.getParameter<edm::ParameterSet>("ConfGlobalMFM");
45 
46  std::string volName = thePSetForGMFM.getParameter< std::string >("Volume");
47 
48  edm::ParameterSet volPSet =
49  thePSetForGMFM.getParameter< edm::ParameterSet >( volName );
50 
51  configureForVolume( volName, volPSet, fM, fP, setter );
52 
53  if ( thePSet.getParameter<bool>("UseLocalMagFieldManager") ) {
54 
55  edm::LogInfo("SimG4CoreApplication")
56  << " FieldBuilder: Local magnetic field is used";
57 
58  edm::ParameterSet defpset ;
59  edm::ParameterSet thePSetForLMFM =
60  thePSet.getUntrackedParameter<edm::ParameterSet>("ConfLocalMFM", defpset);
61  //
62  // Patology !!! LocalFM requested but configuration not given !
63  // In principal, need to throw an exception
64  //
65  if ( thePSetForLMFM == defpset ) {
66  edm::LogError("SimG4CoreApplication")
67  << " FieldBuilder::build: Patology! Local Mag.Field Manager requested but config not given!";
68  return ;
69  }
70 
71  std::vector<std::string> ListOfVolumes =
72  thePSetForLMFM.getParameter< std::vector<std::string> >("ListOfVolumes");
73 
74  // creating Local Mag.Field Manager
75  for (unsigned int i = 0; i < ListOfVolumes.size(); ++ i ) {
76  volPSet = thePSetForLMFM.getParameter< edm::ParameterSet >(ListOfVolumes[i]);
77  G4FieldManager* fAltM = new G4FieldManager() ;
78  configureForVolume( ListOfVolumes[i], volPSet, fAltM, nullptr, setter ) ;
79 
80  LocalFieldManager* fLM = new LocalFieldManager( theField.get(), fM, fAltM ) ;
81  fLM->SetVerbosity(thePSet.getUntrackedParameter<bool>("Verbosity",false));
82  theTopVolume->SetFieldManager( fLM, true ) ;
83  }
84  } else {
85  edm::LogInfo("SimG4CoreApplication")
86  << " FieldBuilder::build: Global magnetic field is used";
87  }
88 }
89 
91  edm::ParameterSet& volPSet,
92  G4FieldManager * fM,
93  G4PropagatorInField * fP,
94  ChordFinderSetter *setter)
95 {
96  G4LogicalVolumeStore* theStore = G4LogicalVolumeStore::GetInstance();
97  for (unsigned int i=0; i<(*theStore).size(); ++i ) {
98  std::string curVolName = ((*theStore)[i])->GetName();
99  if ( curVolName == volName ) {
100  theTopVolume = (*theStore)[i] ;
101  }
102  }
103 
104  fieldType = volPSet.getParameter<std::string>("Type") ;
105  stepper = volPSet.getParameter<std::string>("Stepper") ;
106  edm::ParameterSet stpPSet =
107  volPSet.getParameter<edm::ParameterSet>("StepperParam") ;
108  minStep = stpPSet.getParameter<double>("MinStep") ;
109  dChord = stpPSet.getParameter<double>("DeltaChord") ;
110  dOneStep = stpPSet.getParameter<double>("DeltaOneStep") ;
111  dIntersection = stpPSet.getParameter<double>("DeltaIntersection") ;
113  stpPSet.getUntrackedParameter<double>("DeltaIntersectionAndOneStep",-1.);
114  maxLoopCount =
115  stpPSet.getUntrackedParameter<double>("MaximumLoopCounts",1000);
116  minEpsilonStep =
117  stpPSet.getUntrackedParameter<double>("MinimumEpsilonStep",0.00001);
118  maxEpsilonStep =
119  stpPSet.getUntrackedParameter<double>("MaximumEpsilonStep",0.01);
120 
121  if (fM!=nullptr) configureFieldManager(fM, setter);
122  if (fP!=nullptr) configurePropagatorInField(fP);
123 
124  edm::LogInfo("SimG4CoreApplication")
125  << " FieldBuilder: Selected stepper: <" << stepper
126  << "> const field delta(mm)= " << delta;
127 }
128 
129 G4LogicalVolume * FieldBuilder::fieldTopVolume() { return theTopVolume; }
130 
131 void FieldBuilder::configureFieldManager(G4FieldManager * fM, ChordFinderSetter *setter) {
132 
133  if (fM!=nullptr) {
134  fM->SetDetectorField(theField.get());
135  FieldStepper * theStepper =
136  new FieldStepper(theField->fieldEquation(), delta);
137  theStepper->select(stepper);
138  G4ChordFinder * CF = new G4ChordFinder(theField.get(),minStep,theStepper);
139  CF->SetDeltaChord(dChord);
140  fM->SetChordFinder(CF);
141  fM->SetDeltaOneStep(dOneStep);
142  fM->SetDeltaIntersection(dIntersection);
143  if (dIntersectionAndOneStep != -1.)
144  fM->SetAccuraciesWithDeltaOneStep(dIntersectionAndOneStep);
145  }
146  if(setter && !setter->isMonopoleSet()) {
147  G4MonopoleEquation* fMonopoleEquation =
148  new G4MonopoleEquation(theField.get());
149  G4MagIntegratorStepper* theStepper =
150  new G4ClassicalRK4(fMonopoleEquation,8);
151  G4ChordFinder *chordFinderMonopole =
152  new G4ChordFinder(theField.get(),minStep,theStepper);
153  chordFinderMonopole->SetDeltaChord(dChord);
154  setter->setMonopole(chordFinderMonopole);
155  }
156 }
157 
158 void FieldBuilder::configurePropagatorInField(G4PropagatorInField * fP) {
159  if(fP!=0) {
160  fP->SetMaxLoopCount(int(maxLoopCount));
161  fP->SetMinimumEpsilonStep(minEpsilonStep);
162  fP->SetMaximumEpsilonStep(maxEpsilonStep);
163  fP->SetVerboseLevel(0);
164  }
165 }
166 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::string fieldType
Definition: FieldBuilder.h:53
void configureForVolume(const std::string &volName, edm::ParameterSet &volPSet, G4FieldManager *fM=nullptr, G4PropagatorInField *fP=nullptr, ChordFinderSetter *setter=nullptr)
Definition: FieldBuilder.cc:90
#define nullptr
Definition: sim.h:19
void configureFieldManager(G4FieldManager *fM, ChordFinderSetter *setter)
void build(G4FieldManager *fM=nullptr, G4PropagatorInField *fP=nullptr, ChordFinderSetter *setter=nullptr)
Definition: FieldBuilder.cc:41
G4LogicalVolume * theTopVolume
Definition: FieldBuilder.h:50
void SetVerbosity(bool flag)
double f[11][100]
double dIntersectionAndOneStep
Definition: FieldBuilder.h:60
FieldBuilder(const MagneticField *, const edm::ParameterSet &)
Definition: FieldBuilder.cc:27
G4MagIntegratorStepper * select(const std::string &s)
Definition: FieldStepper.cc:34
std::auto_ptr< Field > theField
Definition: FieldBuilder.h:48
return(e1-e2)*(e1-e2)+dp *dp
void setMonopole(G4ChordFinder *cfm)
G4LogicalVolume * fieldTopVolume()
G4Mag_UsualEqRhs * theFieldEquation
Definition: FieldBuilder.h:49
edm::ParameterSet thePSet
Definition: FieldBuilder.h:65
std::string stepper
Definition: FieldBuilder.h:55
void configurePropagatorInField(G4PropagatorInField *fP)
T get(const Candidate &c)
Definition: component.h:55