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 void createWatchers(const edm::ParameterSet &iP,
33  SimActivityRegistry &iReg,
34  std::vector<std::shared_ptr<SimWatcher>> &oWatchers,
35  std::vector<std::shared_ptr<SimProducer>> &oProds) {
36  using namespace std;
37  using namespace edm;
38  std::vector<ParameterSet> watchers;
39  try {
40  watchers = iP.getParameter<vector<ParameterSet>>("Watchers");
41  } catch (edm::Exception const &) {
42  }
43 
44  for (std::vector<ParameterSet>::iterator itWatcher = watchers.begin(); itWatcher != watchers.end(); ++itWatcher) {
45  std::unique_ptr<SimWatcherMakerBase> maker(
46  SimWatcherFactory::get()->create(itWatcher->getParameter<std::string>("type")));
47  if (maker.get() == nullptr) {
48  throw cms::Exception("SimG4CoreGeometryProducer", " createWatchers: Unable to find the requested Watcher");
49  }
50 
51  std::shared_ptr<SimWatcher> watcherTemp;
52  std::shared_ptr<SimProducer> producerTemp;
53  maker->make(*itWatcher, iReg, watcherTemp, producerTemp);
54  oWatchers.push_back(watcherTemp);
55  if (producerTemp)
56  oProds.push_back(producerTemp);
57  }
58 }
59 
61  : m_kernel(nullptr),
62  m_pField(p.getParameter<edm::ParameterSet>("MagneticField")),
63  m_attach(nullptr),
64  m_p(p),
65  m_pDD(nullptr),
66  m_firstRun(true),
67  m_pUseMagneticField(p.getParameter<bool>("UseMagneticField")),
68  m_pUseSensitiveDetectors(p.getParameter<bool>("UseSensitiveDetectors")) {
69  // Look for an outside SimActivityRegistry
70  // this is used by the visualization code
72  if (otherRegistry)
73  m_registry.connect(*otherRegistry);
75  produces<int>();
76 }
77 
79  delete m_attach;
80  delete m_kernel;
81 }
82 
84  if (m_pUseMagneticField) {
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  // mag field cannot be change in new lumi section - this is commented out
102  // updateMagneticField( es );
103 }
104 
106 
108 
110  if (!m_firstRun)
111  return;
112  m_firstRun = false;
113 
114  edm::LogVerbatim("GeometryProducer") << "Producing G4 Geom";
115 
116  m_kernel = G4RunManagerKernel::GetRunManagerKernel();
117  if (m_kernel == nullptr)
118  m_kernel = new G4RunManagerKernel();
119  edm::LogVerbatim("GeometryProducer") << " GeometryProducer initializing ";
120  // DDDWorld: get the DDCV from the ES and use it to build the World
121 
123  es.get<IdealGeometryRecord>().get(pDD);
124  m_pDD = pDD.product();
125 
128 
129  const DDDWorld *dddworld = new DDDWorld(&(*pDD), map, catalog, false);
130  G4VPhysicalVolume *world = dddworld->GetWorldVolumeForWorker();
131 
132  if (nullptr != world)
133  edm::LogVerbatim("GeometryProducer") << " World Volume: " << world->GetName();
134  m_kernel->DefineWorldVolume(world, true);
135 
136  m_registry.dddWorldSignal_(dddworld);
137 
138  edm::LogVerbatim("GeometryProducer") << " Magnetic field initialisation";
140 
142  edm::LogInfo("GeometryProducer") << " instantiating sensitive detectors ";
143  // instantiate and attach the sensitive detectors
144  m_trackManager = std::unique_ptr<SimTrackManager>(new SimTrackManager);
145  if (m_attach == nullptr)
146  m_attach = new AttachSD;
147  {
148  std::pair<std::vector<SensitiveTkDetector *>, std::vector<SensitiveCaloDetector *>> sensDets =
149  m_attach->create((*m_pDD), catalog, m_p, m_trackManager.get(), m_registry);
150 
151  m_sensTkDets.swap(sensDets.first);
152  m_sensCaloDets.swap(sensDets.second);
153  }
154 
155  edm::LogInfo("GeometryProducer") << " Sensitive Detector building finished; found " << m_sensTkDets.size()
156  << " Tk type Producers, and " << m_sensCaloDets.size() << " Calo type producers ";
157  }
158 
159  for (Producers::iterator itProd = m_producers.begin(); itProd != m_producers.end(); ++itProd) {
160  (*itProd)->produce(e, es);
161  }
162 }
163 
std::vector< SensitiveTkDetector * > m_sensTkDets
T getParameter(std::string const &) const
GeometryProducer(edm::ParameterSet const &p)
void endRun(const edm::Run &r, const edm::EventSetup &c) override
def create(alignables, pedeDump, additionalData, outputFile, config)
const DDCompactView * m_pDD
void connect(Observer< const BeginOfJob * > *iObject)
edm::ParameterSet m_pField
#define nullptr
~GeometryProducer() override
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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< std::shared_ptr< SimWatcher > > m_watchers
std::vector< SensitiveCaloDetector * > m_sensCaloDets
G4RunManagerKernel * m_kernel
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::pair< std::vector< SensitiveTkDetector * >, std::vector< SensitiveCaloDetector * > > create(const DDCompactView &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *, SimActivityRegistry &reg) const
Definition: AttachSD.cc:17
DDDWorldSignal dddWorldSignal_
G4VPhysicalVolume * GetWorldVolumeForWorker() const
Definition: DDDWorld.h:22
T const * product() const
std::unique_ptr< SimTrackManager > m_trackManager
void beginLuminosityBlock(edm::LuminosityBlock &, edm::EventSetup const &)
HLT enums.
T get() const
Definition: EventSetup.h:71
static void createWatchers(const edm::ParameterSet &iP, SimActivityRegistry &iReg, std::vector< std::shared_ptr< SimWatcher >> &oWatchers, std::vector< std::shared_ptr< SimProducer >> &oProds)
edm::ParameterSet m_p
T const * product() const
Definition: ESHandle.h:86
T get(const Candidate &c)
Definition: component.h:55
Definition: Run.h:45