44 #include "HepPDT/defs.h"
45 #include "HepPDT/TableBuilder.hh"
46 #include "HepPDT/ParticleDataTable.hh"
49 #include "G4GeometryManager.hh"
50 #include "G4StateManager.hh"
51 #include "G4ApplicationState.hh"
52 #include "G4RunManagerKernel.hh"
53 #include "G4UImanager.hh"
55 #include "G4EventManager.hh"
58 #include "G4TransportationManager.hh"
59 #include "G4ParticleTable.hh"
61 #include "G4FieldManager.hh"
63 #include "G4GDMLParser.hh"
64 #include "G4SystemOfUnits.hh"
78 std::vector<std::shared_ptr<SimWatcher> >& oWatchers,
79 std::vector<std::shared_ptr<SimProducer> >& oProds
84 vector<ParameterSet> watchers;
86 watchers = iP.
getParameter<vector<ParameterSet> >(
"Watchers");
90 for(vector<ParameterSet>::iterator itWatcher = watchers.begin();
91 itWatcher != watchers.end();
93 std::auto_ptr<SimWatcherMakerBase> maker(
100 std::shared_ptr<SimWatcher> watcherTemp;
101 std::shared_ptr<SimProducer> producerTemp;
102 maker->make(*itWatcher,iReg,watcherTemp,producerTemp);
103 oWatchers.push_back(watcherTemp);
105 oProds.push_back(producerTemp);
112 : m_generator(0), m_nonBeam(p.getParameter<bool>(
"NonBeamEvent")),
113 m_primaryTransformer(0),
114 m_managerInitialized(
false),
117 m_pUseMagneticField(p.getParameter<bool>(
"UseMagneticField")),
118 m_currentRun(0), m_currentEvent(0), m_simEvent(0),
119 m_PhysicsTablesDir(p.getParameter<std::
string>(
"PhysicsTablesDirectory")),
120 m_StorePhysicsTables(p.getParameter<bool>(
"StorePhysicsTables")),
121 m_RestorePhysicsTables(p.getParameter<bool>(
"RestorePhysicsTables")),
122 m_EvtMgrVerbosity(p.getUntrackedParameter<int>(
"G4EventManagerVerbosity",0)),
123 m_pField(p.getParameter<edm::
ParameterSet>(
"MagneticField")),
124 m_pGenerator(p.getParameter<edm::
ParameterSet>(
"Generator")),
125 m_pPhysics(p.getParameter<edm::
ParameterSet>(
"Physics")),
126 m_pRunAction(p.getParameter<edm::
ParameterSet>(
"RunAction")),
127 m_pEventAction(p.getParameter<edm::
ParameterSet>(
"EventAction")),
128 m_pStackingAction(p.getParameter<edm::
ParameterSet>(
"StackingAction")),
129 m_pTrackingAction(p.getParameter<edm::
ParameterSet>(
"TrackingAction")),
130 m_pSteppingAction(p.getParameter<edm::
ParameterSet>(
"SteppingAction")),
131 m_G4Commands(p.getParameter<std::vector<std::
string> >(
"G4Commands")),
132 m_p(p), m_fieldBuilder(0), m_chordFinderSetter(
nullptr),
133 m_theLHCTlinkTag(p.getParameter<edm::
InputTag>(
"theLHCTlinkTag"))
137 m_kernel = G4RunManagerKernel::GetRunManagerKernel();
145 if(
"" != m_FieldFile) { m_FieldFile +=
".txt"; }
167 G4StateManager::GetStateManager()->SetNewState(G4State_Quit);
168 G4GeometryManager::GetInstance()->OpenGeometry();
178 <<
"[SimG4Core RunManager]\n"
179 <<
"The Geometry configuration is changed during the job execution\n"
180 <<
"this is not allowed, the geometry must stay unchanged\n";
186 <<
"[SimG4Core RunManager]\n"
187 <<
"The MagneticField configuration is changed during the job execution\n"
188 <<
"this is not allowed, the MagneticField must stay unchanged\n";
217 G4TransportationManager * tM =
218 G4TransportationManager::GetTransportationManager();
220 tM->GetPropagatorInField(),
233 std::pair< std::vector<SensitiveTkDetector*>,
234 std::vector<SensitiveCaloDetector*> > sensDets =
242 <<
" RunManager: Sensitive Detector "
243 <<
"building finished; found "
245 <<
" Tk type Producers, and "
247 <<
" Calo type producers ";
255 std::auto_ptr<PhysicsListMakerBase>
258 if (physicsMaker.get()==0) {
259 throw SimG4Exception(
"Unable to find the Physics list requested");
283 throw SimG4Exception(
"G4RunManagerKernel initialization failed!");
288 std::ostringstream
dir;
289 dir << tableDir <<
'\0';
292 G4UImanager::GetUIpointer()->ApplyCommand(cmd);
303 edm::LogInfo(
"SimG4CoreApplication") <<
"RunManager:: Requests UI: "
305 G4UImanager::GetUIpointer()->ApplyCommand(
m_G4Commands[it]);
319 G4StateManager::GetStateManager()->SetNewState(G4State_Quit);
338 <<
" RunManager::produce event " << inpevt.
id().
event()
339 <<
" with no G4PrimaryVertices \n Aborting Run" ;
347 <<
" RunManager: saved : Event " << inpevt.
id().
event()
360 G4Event * evt =
new G4Event(inpevt.
id().
event());
389 m_kernel->GetEventManager()->GetTrackingManager()->GetTrack();
390 t->SetTrackStatus(fStopAndKill) ;
411 m_kernel->GetEventManager()->GetStackManager()->clear() ;
412 m_kernel->GetEventManager()->GetTrackingManager()->EventAborted() ;
414 G4StateManager* stateManager = G4StateManager::GetStateManager();
415 stateManager->SetNewState(G4State_GeomClosed);
425 G4EventManager * eventManager =
m_kernel->GetEventManager();
432 eventManager->SetUserAction(userEventAction);
437 eventManager->SetUserAction(userTrackingAction);
442 eventManager->SetUserAction(userSteppingAction);
444 eventManager->SetUserAction(
new StackingAction(userTrackingAction,
449 <<
"No generator; initialized "
450 <<
"only RunAction!";
458 G4StateManager::GetStateManager()->SetNewState(G4State_GeomClosed);
540 <<
" RunManager WARNING : "
541 <<
"error opening file <" <<
m_FieldFile <<
"> for magnetic field";
543 double rmax = 9000*mm;
544 double zmax = 16000*mm;
549 int nr = (int)(rmax/dr);
550 int nz = 2*(int)(zmax/dz);
557 double cosf =
cos(phi);
558 double sinf =
sin(phi);
560 double point[4] = {0.0,0.0,0.0,0.0};
561 double bfield[3] = {0.0,0.0,0.0};
563 fout << std::setprecision(6);
564 for(
int i=0;
i<=nr; ++
i) {
566 for(
int j=0;
j<=nz; ++
j) {
570 field->GetFieldValue(point, bfield);
571 fout <<
"R(mm)= " << r/mm <<
" phi(deg)= " << phi/degree
572 <<
" Z(mm)= " << z/mm <<
" Bz(tesla)= " << bfield[2]/tesla
573 <<
" Br(tesla)= " << (bfield[0]*cosf + bfield[1]*sinf)/tesla
574 <<
" Bphi(tesla)= " << (bfield[0]*sinf - bfield[1]*cosf)/tesla
T getParameter(std::string const &) const
EventNumber_t event() const
edm::ParameterSet m_pGenerator
T getUntrackedParameter(std::string const &, T const &) const
std::auto_ptr< SimTrackManager > m_trackManager
virtual const math::XYZTLorentzVector * genVertex() const
SimTrackManager * GetSimTrackManager()
edm::ESWatcher< IdealMagneticFieldRecord > idealMagRcdWatcher_
const G4VPhysicalVolume * GetWorldVolume() const
virtual const double eventWeight() const
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
void abortRun(bool softAbort=false)
G4StepSignal g4StepSignal_
SimActivityRegistry m_registry
virtual const HepMC::GenEvent * genEvent() const
SimActivityRegistry::G4StepSignal m_g4StepSignal
HepPDT::ParticleDataTable ParticleDataTable
std::vector< std::shared_ptr< SimProducer > > m_producers
void HepMC2G4(const HepMC::GenEvent *g, G4Event *e)
EndOfEventSignal endOfEventSignal_
Sin< T >::type sin(const T &t)
void initializeUserActions()
SimActivityRegistry::EndOfRunSignal m_endOfRunSignal
BeginOfRunSignal beginOfRunSignal_
SimActivityRegistry::EndOfEventSignal m_endOfEventSignal
static void createWatchers(const edm::ParameterSet &iP, SimActivityRegistry &iReg, std::vector< std::shared_ptr< SimWatcher > > &oWatchers, std::vector< std::shared_ptr< SimProducer > > &oProds)
edm::ESWatcher< IdealGeometryRecord > idealGeomRcdWatcher_
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
std::vector< SensitiveCaloDetector * > m_sensCaloDets
std::vector< SensitiveTkDetector * > m_sensTkDets
BeginOfJobSignal beginOfJobSignal_
U second(std::pair< T, U > const &p)
std::auto_ptr< PhysicsList > m_physicsList
void build(G4FieldManager *fM=nullptr, G4PropagatorInField *fP=nullptr, ChordFinderSetter *setter=nullptr)
SimRunInterface * m_runInterface
Cos< T >::type cos(const T &t)
bool m_RestorePhysicsTables
void hepEvent(const HepMC::GenEvent *r)
std::vector< std::shared_ptr< SimWatcher > > m_watchers
void setGenEvent(const HepMC::GenEvent *inpevt)
BeginOfEventSignal beginOfEventSignal_
SimActivityRegistry::EndOfTrackSignal m_endOfTrackSignal
void EndOfRunAction(const G4Run *aRun)
void resetGenParticleId(edm::Event &inpevt)
EndOfRunSignal endOfRunSignal_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
edm::ParameterSet m_pStackingAction
unsigned int nTracks() const
void connect(Observer< const T * > *iObs)
does not take ownership of memory
edm::ParameterSet m_pEventAction
unsigned int nVertices() const
edm::ParameterSet m_pField
edm::ParameterSet m_pPhysics
edm::ParameterSet m_pSteppingAction
T const * product() const
virtual void PostUserTrackingAction(const G4Track *aTrack)
unsigned int nGenParts() const
RunAction * m_userRunAction
void BeginOfRunAction(const G4Run *aRun)
DDDWorldSignal dddWorldSignal_
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 ®) const
void nonBeamEvent2G4(const HepMC::GenEvent *g, G4Event *e)
bool check(const edm::EventSetup &iSetup)
G4Event * generateEvent(edm::Event &inpevt)
void DumpMagneticField(const G4Field *) const
SimActivityRegistry::BeginOfRunSignal m_beginOfRunSignal
sim::ChordFinderSetter * m_chordFinderSetter
void Connect(RunAction *)
PrimaryTransformer * m_primaryTransformer
sim::FieldBuilder * m_fieldBuilder
std::string m_PhysicsTablesDir
bool m_StorePhysicsTables
void connect(SimActivityRegistry &iOther)
forwards our signals to slots connected to iOther
volatile std::atomic< bool > shutdown_flag false
EndOfTrackSignal endOfTrackSignal_
edm::ParameterSet m_pRunAction
RunManager(edm::ParameterSet const &p)
edm::ParameterSet m_pTrackingAction
void collisionPoint(const math::XYZTLorentzVectorD &v)
std::vector< std::string > m_G4Commands
SimActivityRegistry::BeginOfEventSignal m_beginOfEventSignal
bool m_managerInitialized
void initG4(const edm::EventSetup &es)
T get(const Candidate &c)
edm::InputTag m_theLHCTlinkTag
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
BeginOfTrackSignal beginOfTrackSignal_
G4RunManagerKernel * m_kernel
void produce(edm::Event &inpevt, const edm::EventSetup &es)
SimActivityRegistry::BeginOfTrackSignal m_beginOfTrackSignal