CMS 3D CMS Logo

GeometryProducer.cc
Go to the documentation of this file.
2 
4 
9 
19 
22 
24 
26 
27 #include "G4RunManagerKernel.hh"
28 #include "G4TransportationManager.hh"
29 
30 #include <iostream>
31 
32 static
34  std::vector<std::shared_ptr<SimWatcher> >& oWatchers,
35  std::vector<std::shared_ptr<SimProducer> >& oProds)
36 {
37  using namespace std;
38  using namespace edm;
39  std::vector<ParameterSet> watchers;
40  try { watchers = iP.getParameter<vector<ParameterSet> >("Watchers"); }
41  catch(edm::Exception) {}
42 
43  for(std::vector<ParameterSet>::iterator itWatcher = watchers.begin();
44  itWatcher != watchers.end(); ++itWatcher)
45  {
46  std::unique_ptr<SimWatcherMakerBase>
47  maker(SimWatcherFactory::get()->create(itWatcher->getParameter<std::string> ("type")));
48  if(maker.get()==nullptr) {
49  throw cms::Exception("SimG4CoreGeometryProducer",
50  " createWatchers: Unable to find the requested Watcher");
51  }
52 
53  std::shared_ptr<SimWatcher> watcherTemp;
54  std::shared_ptr<SimProducer> producerTemp;
55  maker->make(*itWatcher,iReg,watcherTemp,producerTemp);
56  oWatchers.push_back(watcherTemp);
57  if(producerTemp) oProds.push_back(producerTemp);
58  }
59 }
60 
62  m_kernel(nullptr),
63  m_pUseMagneticField(p.getParameter<bool>("UseMagneticField")),
64  m_pField(p.getParameter<edm::ParameterSet>("MagneticField")),
65  m_pUseSensitiveDetectors(p.getParameter<bool>("UseSensitiveDetectors")),
66  m_attach(nullptr), m_p(p), m_firstRun ( true )
67 {
68  //Look for an outside SimActivityRegistry
69  //this is used by the visualization code
71  if (otherRegistry) m_registry.connect(*otherRegistry);
73  produces<int>();
74 }
75 
77 {
78  delete m_attach;
79  delete m_kernel;
80 }
81 
84  {
85  // setup the magnetic field
87  es.get<IdealMagneticFieldRecord>().get(pMF);
88  const GlobalPoint g(0.,0.,0.);
89  edm::LogInfo("GeometryProducer") << "B-field(T) at (0,0,0)(cm): " << pMF->inTesla(g);
90 
91  sim::FieldBuilder fieldBuilder(pMF.product(), m_pField);
92  CMSFieldManager* fieldManager = new CMSFieldManager();
93  G4TransportationManager * tM = G4TransportationManager::GetTransportationManager();
94  tM->SetFieldManager(fieldManager);
95  fieldBuilder.build( fieldManager, tM->GetPropagatorInField());
96  edm::LogInfo("GeometryProducer") << "Magentic field is built";
97  }
98 }
99 
101 {
102  // mag field cannot be change in new lumi section - this is commented out
103  // updateMagneticField( es );
104 }
105 
107 {}
108 
110 {}
111 
113 {
114  if ( !m_firstRun ) return;
115  m_firstRun = false;
116 
117  edm::LogInfo("GeometryProducer") << "Producing G4 Geom";
118 
119  m_kernel = G4RunManagerKernel::GetRunManagerKernel();
120  if (m_kernel==nullptr) m_kernel = new G4RunManagerKernel();
121  edm::LogInfo("GeometryProducer") << " GeometryProducer initializing ";
122  // DDDWorld: get the DDCV from the ES and use it to build the World
124  es.get<IdealGeometryRecord>().get(pDD);
125 
127  SensitiveDetectorCatalog catalog_;
128  const DDDWorld * world = new DDDWorld(&(*pDD), map_, catalog_, false);
130 
131  updateMagneticField( es );
132 
134  {
135  edm::LogInfo("GeometryProducer") << " instantiating sensitive detectors ";
136  // instantiate and attach the sensitive detectors
137  m_trackManager = std::auto_ptr<SimTrackManager>(new SimTrackManager);
138  if (m_attach==nullptr) m_attach = new AttachSD;
139  {
140  std::pair< std::vector<SensitiveTkDetector*>,
141  std::vector<SensitiveCaloDetector*> >
142  sensDets = m_attach->create(*world,(*pDD),catalog_,m_p,m_trackManager.get(),m_registry);
143 
144  m_sensTkDets.swap(sensDets.first);
145  m_sensCaloDets.swap(sensDets.second);
146  }
147 
148  edm::LogInfo("GeometryProducer") << " Sensitive Detector building finished; found "
149  << m_sensTkDets.size()
150  << " Tk type Producers, and " << m_sensCaloDets.size()
151  << " Calo type producers ";
152  }
153 
154  for(Producers::iterator itProd = m_producers.begin();itProd != m_producers.end();
155  ++itProd) {
156  (*itProd)->produce(e,es);
157  }
158 }
159 
T getParameter(std::string const &) const
Map map_
GeometryProducer(edm::ParameterSet const &p)
void endRun(const edm::Run &r, const edm::EventSetup &c) override
def create(alignables, pedeDump, additionalData, outputFile, config)
void connect(Observer< const BeginOfJob * > *iObject)
edm::ParameterSet m_pField
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
~GeometryProducer() override
std::auto_ptr< SimTrackManager > m_trackManager
#define nullptr
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
void beginRun(const edm::Run &r, const edm::EventSetup &c) override
std::vector< std::shared_ptr< SimWatcher > > m_watchers
G4RunManagerKernel * m_kernel
static void createWatchers(const edm::ParameterSet &iP, SimActivityRegistry &iReg, std::vector< std::shared_ptr< SimWatcher > > &oWatchers, std::vector< std::shared_ptr< SimProducer > > &oProds)
std::vector< std::shared_ptr< SimProducer > > m_producers
SimActivityRegistry m_registry
void produce(edm::Event &e, const edm::EventSetup &c) override
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
void updateMagneticField(edm::EventSetup const &es)
std::vector< SensitiveTkDetector * > m_sensTkDets
DDDWorldSignal dddWorldSignal_
const T & get() const
Definition: EventSetup.h:55
std::pair< std::vector< SensitiveTkDetector * >, std::vector< SensitiveCaloDetector * > > create(const DDDWorld &w, const DDCompactView &cpv, const SensitiveDetectorCatalog &clg, edm::ParameterSet const &p, const SimTrackManager *m, SimActivityRegistry &reg) const
Definition: AttachSD.cc:23
void beginLuminosityBlock(edm::LuminosityBlock &, edm::EventSetup const &)
HLT enums.
edm::ParameterSet m_p
T const * product() const
Definition: ESHandle.h:86
T get(const Candidate &c)
Definition: component.h:55
std::vector< SensitiveCaloDetector * > m_sensCaloDets
Definition: Run.h:43