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