CMS 3D CMS Logo

GeometryProducer.cc
Go to the documentation of this file.
2 
4 
9 
19 
22 
24 
27 
28 #include "G4RunManagerKernel.hh"
29 #include "G4TransportationManager.hh"
30 
31 #include <iostream>
32 #include <memory>
33 
34 static void createWatchers(const edm::ParameterSet &iP,
35  SimActivityRegistry &iReg,
36  std::vector<std::shared_ptr<SimWatcher>> &oWatchers,
37  std::vector<std::shared_ptr<SimProducer>> &oProds) {
38  using namespace std;
39  using namespace edm;
40  std::vector<ParameterSet> watchers;
41  try {
42  watchers = iP.getParameter<vector<ParameterSet>>("Watchers");
43  } catch (edm::Exception const &) {
44  }
45 
46  for (std::vector<ParameterSet>::iterator itWatcher = watchers.begin(); itWatcher != watchers.end(); ++itWatcher) {
47  std::unique_ptr<SimWatcherMakerBase> maker(
48  SimWatcherFactory::get()->create(itWatcher->getParameter<std::string>("type")));
49  if (maker.get() == nullptr) {
50  throw cms::Exception("SimG4CoreGeometryProducer", " 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)
58  oProds.push_back(producerTemp);
59  }
60 }
61 
63  : m_kernel(nullptr),
64  m_pField(p.getParameter<edm::ParameterSet>("MagneticField")),
65  m_attach(nullptr),
66  m_p(p),
67  m_pDD(nullptr),
68  m_pDD4hep(nullptr),
69  m_firstRun(true),
70  m_pUseMagneticField(p.getParameter<bool>("UseMagneticField")),
71  m_pUseSensitiveDetectors(p.getParameter<bool>("UseSensitiveDetectors")),
72  m_pGeoFromDD4hep(false) {
73  // Look for an outside SimActivityRegistry
74  // this is used by the visualization code
76  if (otherRegistry)
77  m_registry.connect(*otherRegistry);
79  produces<int>();
80 }
81 
83  delete m_attach;
84  delete m_kernel;
85 }
86 
88  if (m_pUseMagneticField) {
89  // setup the magnetic field
91  es.get<IdealMagneticFieldRecord>().get(pMF);
92  const GlobalPoint g(0., 0., 0.);
93  edm::LogInfo("GeometryProducer") << "B-field(T) at (0,0,0)(cm): " << pMF->inTesla(g);
94 
95  sim::FieldBuilder fieldBuilder(pMF.product(), m_pField);
96  CMSFieldManager *fieldManager = new CMSFieldManager();
97  G4TransportationManager *tM = G4TransportationManager::GetTransportationManager();
98  tM->SetFieldManager(fieldManager);
99  fieldBuilder.build(fieldManager, tM->GetPropagatorInField());
100  edm::LogInfo("GeometryProducer") << "Magentic field is built";
101  }
102 }
103 
105  // mag field cannot be change in new lumi section - this is commented out
106  // updateMagneticField( es );
107 }
108 
110 
112 
114  if (!m_firstRun)
115  return;
116  m_firstRun = false;
117 
118  edm::LogVerbatim("GeometryProducer") << "Producing G4 Geom";
119 
120  m_kernel = G4RunManagerKernel::GetRunManagerKernel();
121  if (m_kernel == nullptr)
122  m_kernel = new G4RunManagerKernel();
123  edm::LogVerbatim("GeometryProducer") << " GeometryProducer initializing ";
124  // DDDWorld: get the DDCV from the ES and use it to build the World
125  if (m_pGeoFromDD4hep) {
127  es.get<IdealGeometryRecord>().get(pDD);
128  m_pDD4hep = pDD.product();
129  } else {
131  es.get<IdealGeometryRecord>().get(pDD);
132  m_pDD = pDD.product();
133  }
134 
136  const DDDWorld *dddworld = new DDDWorld(m_pDD, m_pDD4hep, catalog, 1, false, false);
137  G4VPhysicalVolume *world = dddworld->GetWorldVolume();
138  if (nullptr != world)
139  edm::LogVerbatim("GeometryProducer") << " World Volume: " << world->GetName();
140  m_kernel->DefineWorldVolume(world, true);
141 
142  m_registry.dddWorldSignal_(dddworld);
143 
144  edm::LogVerbatim("GeometryProducer") << " Magnetic field initialisation";
146 
148  edm::LogInfo("GeometryProducer") << " instantiating sensitive detectors ";
149  // instantiate and attach the sensitive detectors
150  m_trackManager = std::make_unique<SimTrackManager>();
151  if (m_attach == nullptr)
152  m_attach = new AttachSD;
153  {
154  std::pair<std::vector<SensitiveTkDetector *>, std::vector<SensitiveCaloDetector *>> sensDets =
156 
157  m_sensTkDets.swap(sensDets.first);
158  m_sensCaloDets.swap(sensDets.second);
159  }
160 
161  edm::LogInfo("GeometryProducer") << " Sensitive Detector building finished; found " << m_sensTkDets.size()
162  << " Tk type Producers, and " << m_sensCaloDets.size() << " Calo type producers ";
163  }
164 
165  for (Producers::iterator itProd = m_producers.begin(); itProd != m_producers.end(); ++itProd) {
166  (*itProd)->produce(e, es);
167  }
168 }
169 
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:104
MagneticField::inTesla
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
GeometryProducer::m_pDD4hep
const cms::DDCompactView * m_pDD4hep
Definition: GeometryProducer.h:66
electrons_cff.bool
bool
Definition: electrons_cff.py:393
GeometryProducer::m_p
edm::ParameterSet m_p
Definition: GeometryProducer.h:63
ESTransientHandle.h
GeometryProducer::m_pUseSensitiveDetectors
bool m_pUseSensitiveDetectors
Definition: GeometryProducer.h:70
funct::false
false
Definition: Factorize.h:29
GeometryProducer::m_sensCaloDets
std::vector< SensitiveCaloDetector * > m_sensCaloDets
Definition: GeometryProducer.h:62
edm::ESTransientHandle::product
T const * product() const
Definition: ESTransientHandle.h:51
GeometryProducer::m_pGeoFromDD4hep
bool m_pGeoFromDD4hep
Definition: GeometryProducer.h:71
GeometryProducer.h
getEcalConditions_orcoffint2r_cff.catalog
catalog
Definition: getEcalConditions_orcoffint2r_cff.py:40
ESHandle.h
DDDWorld
Definition: DDDWorld.h:14
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::Run
Definition: Run.h:45
CMSFieldManager.h
GeometryProducer::m_registry
SimActivityRegistry m_registry
Definition: GeometryProducer.h:55
edm
HLT enums.
Definition: AlignableModifier.h:19
SimProducer.h
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
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:113
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
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:80
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:60
SensitiveDetectorCatalog
Definition: SensitiveDetectorCatalog.h:10
DDCompactView.h
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:111
GeometryProducer::updateMagneticField
void updateMagneticField(edm::EventSetup const &es)
Definition: GeometryProducer.cc:87
funct::true
true
Definition: Factorize.h:173
edm::ParameterSet
Definition: ParameterSet.h:47
DDDWorld::GetWorldVolume
G4VPhysicalVolume * GetWorldVolume() const
Definition: DDDWorld.h:24
SimWatcherFactory.h
Field.h
SensitiveDetectorCatalog.h
GeometryProducer::GeometryProducer
GeometryProducer(edm::ParameterSet const &p)
Definition: GeometryProducer.cc:62
edm::Service
Definition: Service.h:30
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
IdealGeometryRecord.h
GeometryProducer::m_kernel
G4RunManagerKernel * m_kernel
Definition: GeometryProducer.h:53
MagneticField.h
edm::EventSetup
Definition: EventSetup.h:57
GeometryProducer::m_sensTkDets
std::vector< SensitiveTkDetector * > m_sensTkDets
Definition: GeometryProducer.h:61
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:34
get
#define get
GeometryProducer::m_pDD
const DDCompactView * m_pDD
Definition: GeometryProducer.h:65
edm::ESTransientHandle
Definition: ESTransientHandle.h:41
GeometryProducer::m_producers
std::vector< std::shared_ptr< SimProducer > > m_producers
Definition: GeometryProducer.h:57
GeometryProducer::m_firstRun
bool m_firstRun
Definition: GeometryProducer.h:68
GeometryProducer::beginRun
void beginRun(const edm::Run &r, const edm::EventSetup &c) override
Definition: GeometryProducer.cc:109
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
SimActivityRegistry
Definition: SimActivityRegistry.h:43
PluginManager.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
SimTrackManager.h
Exception
Definition: hltDiff.cc:246
SimActivityRegistry::connect
void connect(Observer< const BeginOfJob * > *iObject)
Definition: SimActivityRegistry.h:51
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
AttachSD
Definition: AttachSD.h:17
GeometryProducer::m_watchers
std::vector< std::shared_ptr< SimWatcher > > m_watchers
Definition: GeometryProducer.h:56
GeometryProducer
Definition: GeometryProducer.h:35
GeometryProducer::m_trackManager
std::unique_ptr< SimTrackManager > m_trackManager
Definition: GeometryProducer.h:59
edm::Event
Definition: Event.h:73
GeometryProducer::m_pUseMagneticField
bool m_pUseMagneticField
Definition: GeometryProducer.h:69
IdealGeometryRecord
Definition: IdealGeometryRecord.h:25
GeometryProducer::~GeometryProducer
~GeometryProducer() override
Definition: GeometryProducer.cc:82
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:54