test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GeometryProducer.cc
Go to the documentation of this file.
2 
4 
8 
18 
21 
23 
25 
26 #include "G4RunManagerKernel.hh"
27 #include "G4TransportationManager.hh"
28 
29 #include <iostream>
30 
31 static
33  std::vector<std::shared_ptr<SimWatcher> >& oWatchers,
34  std::vector<std::shared_ptr<SimProducer> >& oProds)
35 {
36  using namespace std;
37  using namespace edm;
38  std::vector<ParameterSet> watchers;
39  try { watchers = iP.getParameter<vector<ParameterSet> >("Watchers"); }
40  catch(edm::Exception) {}
41 
42  for(std::vector<ParameterSet>::iterator itWatcher = watchers.begin();
43  itWatcher != watchers.end(); ++itWatcher)
44  {
45  std::auto_ptr<SimWatcherMakerBase>
46  maker(SimWatcherFactory::get()->create(itWatcher->getParameter<std::string> ("type")));
47  if(maker.get()==0) { throw SimG4Exception("Unable to find the requested Watcher"); }
48 
49  std::shared_ptr<SimWatcher> watcherTemp;
50  std::shared_ptr<SimProducer> producerTemp;
51  maker->make(*itWatcher,iReg,watcherTemp,producerTemp);
52  oWatchers.push_back(watcherTemp);
53  if(producerTemp) oProds.push_back(producerTemp);
54  }
55 }
56 
58  m_kernel(nullptr),
59  m_pUseMagneticField(p.getParameter<bool>("UseMagneticField")),
60  m_pField(p.getParameter<edm::ParameterSet>("MagneticField")),
61  m_pUseSensitiveDetectors(p.getParameter<bool>("UseSensitiveDetectors")),
62  m_attach(nullptr), m_p(p), m_firstRun ( true )
63 {
64  //Look for an outside SimActivityRegistry
65  //this is used by the visualization code
67  if (otherRegistry) m_registry.connect(*otherRegistry);
69  produces<int>();
70 }
71 
73 {
74  delete m_attach;
75  delete m_kernel;
76 }
77 
80  {
81  // setup the magnetic field
83  es.get<IdealMagneticFieldRecord>().get(pMF);
84  const GlobalPoint g(0.,0.,0.);
85  edm::LogInfo("GeometryProducer") << "B-field(T) at (0,0,0)(cm): " << pMF->inTesla(g);
86 
87  m_fieldBuilder = std::auto_ptr<sim::FieldBuilder>(new sim::FieldBuilder(&(*pMF), m_pField));
88 
89  G4TransportationManager * tM = G4TransportationManager::GetTransportationManager();
90  // update field here ...
91  m_fieldBuilder->build( tM->GetFieldManager(),tM->GetPropagatorInField());
92 
93  edm::LogInfo("GeometryProducer") << "Magentic field updated";
94  }
95 
96 }
97 
99  // mag field can change in new lumi section
100  updateMagneticField( es );
101 }
102 
104 {}
105 
107 {}
108 
110 {
111  if ( !m_firstRun ) return;
112  m_firstRun = false;
113 
114  edm::LogInfo("GeometryProducer") << "Producing G4 Geom";
115 
116  m_kernel = G4RunManagerKernel::GetRunManagerKernel();
117  if (m_kernel==0) 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 
128  updateMagneticField( es );
129 
131  {
132  edm::LogInfo("GeometryProducer") << " instantiating sensitive detectors ";
133  // instantiate and attach the sensitive detectors
134  m_trackManager = std::auto_ptr<SimTrackManager>(new SimTrackManager);
135  if (m_attach==0) m_attach = new AttachSD;
136  {
137  std::pair< std::vector<SensitiveTkDetector*>,
138  std::vector<SensitiveCaloDetector*> >
139  sensDets = m_attach->create(*world,(*pDD),catalog_,m_p,m_trackManager.get(),m_registry);
140 
141  m_sensTkDets.swap(sensDets.first);
142  m_sensCaloDets.swap(sensDets.second);
143  }
144 
145  edm::LogInfo("GeometryProducer") << " Sensitive Detector building finished; found "
146  << m_sensTkDets.size()
147  << " Tk type Producers, and " << m_sensCaloDets.size()
148  << " Calo type producers ";
149  }
150 
151  for(Producers::iterator itProd = m_producers.begin();itProd != m_producers.end();
152  ++itProd) {
153  (*itProd)->produce(e,es);
154  }
155 }
156 
T getParameter(std::string const &) const
Map map_
GeometryProducer(edm::ParameterSet const &p)
virtual void endRun(const edm::Run &r, const edm::EventSetup &c) override
void connect(Observer< const BeginOfJob * > *iObject)
edm::ParameterSet m_pField
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual ~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
virtual 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
virtual void produce(edm::Event &e, const edm::EventSetup &c) override
void updateMagneticField(edm::EventSetup const &es)
std::vector< SensitiveTkDetector * > m_sensTkDets
DDDWorldSignal dddWorldSignal_
const T & get() const
Definition: EventSetup.h:56
std::auto_ptr< sim::FieldBuilder > m_fieldBuilder
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 &)
edm::ParameterSet m_p
T get(const Candidate &c)
Definition: component.h:55
std::vector< SensitiveCaloDetector * > m_sensCaloDets
Definition: Run.h:43