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