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_pUseMagneticField(p.getParameter<bool>("UseMagneticField")),
63  m_pField(p.getParameter<edm::ParameterSet>("MagneticField")),
64  m_pUseSensitiveDetectors(p.getParameter<bool>("UseSensitiveDetectors")),
65  m_attach(nullptr),
66  m_p(p),
67  m_firstRun(true) {
68  // Look for an outside SimActivityRegistry
69  // this is used by the visualization code
71  if (otherRegistry)
72  m_registry.connect(*otherRegistry);
74  produces<int>();
75 }
76 
78  delete m_attach;
79  delete m_kernel;
80 }
81 
83  if (m_pUseMagneticField) {
84  // setup the magnetic field
86  es.get<IdealMagneticFieldRecord>().get(pMF);
87  const GlobalPoint g(0., 0., 0.);
88  edm::LogInfo("GeometryProducer") << "B-field(T) at (0,0,0)(cm): " << pMF->inTesla(g);
89 
90  sim::FieldBuilder fieldBuilder(pMF.product(), m_pField);
91  CMSFieldManager *fieldManager = new CMSFieldManager();
92  G4TransportationManager *tM = G4TransportationManager::GetTransportationManager();
93  tM->SetFieldManager(fieldManager);
94  fieldBuilder.build(fieldManager, tM->GetPropagatorInField());
95  edm::LogInfo("GeometryProducer") << "Magentic field is built";
96  }
97 }
98 
100  // mag field cannot be change in new lumi section - this is commented out
101  // updateMagneticField( es );
102 }
103 
105 
107 
109  if (!m_firstRun)
110  return;
111  m_firstRun = false;
112 
113  edm::LogInfo("GeometryProducer") << "Producing G4 Geom";
114 
115  m_kernel = G4RunManagerKernel::GetRunManagerKernel();
116  if (m_kernel == nullptr)
117  m_kernel = new G4RunManagerKernel();
118  edm::LogInfo("GeometryProducer") << " GeometryProducer initializing ";
119  // DDDWorld: get the DDCV from the ES and use it to build the World
121  es.get<IdealGeometryRecord>().get(pDD);
122 
124  SensitiveDetectorCatalog catalog_;
125  const DDDWorld *world = new DDDWorld(&(*pDD), map_, catalog_, false);
127 
129 
131  edm::LogInfo("GeometryProducer") << " instantiating sensitive detectors ";
132  // instantiate and attach the sensitive detectors
133  m_trackManager = std::unique_ptr<SimTrackManager>(new SimTrackManager);
134  if (m_attach == nullptr)
135  m_attach = new AttachSD;
136  {
137  std::pair<std::vector<SensitiveTkDetector *>, std::vector<SensitiveCaloDetector *>> sensDets =
138  m_attach->create(es, catalog_, m_p, m_trackManager.get(), m_registry);
139 
140  m_sensTkDets.swap(sensDets.first);
141  m_sensCaloDets.swap(sensDets.second);
142  }
143 
144  edm::LogInfo("GeometryProducer") << " Sensitive Detector building finished; found " << m_sensTkDets.size()
145  << " Tk type Producers, and " << m_sensCaloDets.size() << " Calo type producers ";
146  }
147 
148  for (Producers::iterator itProd = m_producers.begin(); itProd != m_producers.end(); ++itProd) {
149  (*itProd)->produce(e, es);
150  }
151 }
152 
FieldBuilder.h
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
GeometryProducer::beginLuminosityBlock
void beginLuminosityBlock(edm::LuminosityBlock &, edm::EventSetup const &)
Definition: GeometryProducer.cc:99
SimTrackManager
Definition: SimTrackManager.h:35
MagneticField::inTesla
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
electrons_cff.bool
bool
Definition: electrons_cff.py:372
GeometryProducer::m_p
edm::ParameterSet m_p
Definition: GeometryProducer.h:60
ESTransientHandle.h
GeometryProducer::m_pUseSensitiveDetectors
bool m_pUseSensitiveDetectors
Definition: GeometryProducer.h:51
GeometryProducer::m_sensCaloDets
std::vector< SensitiveCaloDetector * > m_sensCaloDets
Definition: GeometryProducer.h:59
GeometryProducer.h
ESHandle.h
DDDWorld
Definition: DDDWorld.h:14
DDMapper< G4LogicalVolume *, DDLogicalPart >
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::Run
Definition: Run.h:45
CMSFieldManager.h
GeometryProducer::m_registry
SimActivityRegistry m_registry
Definition: GeometryProducer.h:52
edm
HLT enums.
Definition: AlignableModifier.h:19
SimProducer.h
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
edm::LogInfo
Definition: MessageLogger.h:254
CMSFieldManager
Definition: CMSFieldManager.h:24
SimActivityRegistry::dddWorldSignal_
DDDWorldSignal dddWorldSignal_
Definition: SimActivityRegistry.h:54
G4LogicalVolumeToDDLogicalPartMap.h
AttachSD::create
std::pair< std::vector< SensitiveTkDetector * >, std::vector< SensitiveCaloDetector * > > create(const edm::EventSetup &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *, SimActivityRegistry &reg) const
Definition: AttachSD.cc:15
GeometryProducer::produce
void produce(edm::Event &e, const edm::EventSetup &c) override
Definition: GeometryProducer.cc:108
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
DDCompactView.h
DDDWorld.h
edm::Exception
Definition: EDMException.h:77
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
IdealMagneticFieldRecord.h
edm::ESHandle< MagneticField >
GeometryProducer::m_attach
AttachSD * m_attach
Definition: GeometryProducer.h:57
SensitiveDetectorCatalog
Definition: SensitiveDetectorCatalog.h:10
Point3DBase< float, GlobalTag >
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
GeometryProducer::endRun
void endRun(const edm::Run &r, const edm::EventSetup &c) override
Definition: GeometryProducer.cc:106
GeometryProducer::updateMagneticField
void updateMagneticField(edm::EventSetup const &es)
Definition: GeometryProducer.cc:82
funct::true
true
Definition: Factorize.h:173
edm::ParameterSet
Definition: ParameterSet.h:36
SimWatcherFactory.h
Field.h
SensitiveDetectorCatalog.h
GeometryProducer::GeometryProducer
GeometryProducer(edm::ParameterSet const &p)
Definition: GeometryProducer.cc:60
edm::Service
Definition: Service.h:30
IdealGeometryRecord.h
GeometryProducer::m_kernel
G4RunManagerKernel * m_kernel
Definition: GeometryProducer.h:48
MagneticField.h
edm::EventSetup
Definition: EventSetup.h:57
GeometryProducer::m_sensTkDets
std::vector< SensitiveTkDetector * > m_sensTkDets
Definition: GeometryProducer.h:58
createWatchers
static void createWatchers(const edm::ParameterSet &iP, SimActivityRegistry &iReg, std::vector< std::shared_ptr< SimWatcher >> &oWatchers, std::vector< std::shared_ptr< SimProducer >> &oProds)
Definition: GeometryProducer.cc:32
get
#define get
edm::ESTransientHandle
Definition: ESTransientHandle.h:41
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
GeometryProducer::m_producers
std::vector< std::shared_ptr< SimProducer > > m_producers
Definition: GeometryProducer.h:54
GeometryProducer::m_firstRun
bool m_firstRun
Definition: GeometryProducer.h:61
GeometryProducer::beginRun
void beginRun(const edm::Run &r, const edm::EventSetup &c) override
Definition: GeometryProducer.cc:104
std
Definition: JetResolutionObject.h:76
SimActivityRegistry
Definition: SimActivityRegistry.h:43
PluginManager.h
SimTrackManager.h
Exception
Definition: hltDiff.cc:246
SimActivityRegistry::connect
void connect(Observer< const BeginOfJob * > *iObject)
Definition: SimActivityRegistry.h:51
Exception.h
AttachSD
Definition: AttachSD.h:17
GeometryProducer::m_watchers
std::vector< std::shared_ptr< SimWatcher > > m_watchers
Definition: GeometryProducer.h:53
GeometryProducer
Definition: GeometryProducer.h:30
GeometryProducer::m_trackManager
std::unique_ptr< SimTrackManager > m_trackManager
Definition: GeometryProducer.h:56
edm::Event
Definition: Event.h:73
GeometryProducer::m_pUseMagneticField
bool m_pUseMagneticField
Definition: GeometryProducer.h:49
IdealGeometryRecord
Definition: IdealGeometryRecord.h:27
GeometryProducer::~GeometryProducer
~GeometryProducer() override
Definition: GeometryProducer.cc:77
g
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
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
sim::FieldBuilder
Definition: FieldBuilder.h:15
GeometryProducer::m_pField
edm::ParameterSet m_pField
Definition: GeometryProducer.h:50