43 #include "HepPDT/defs.h"
44 #include "HepPDT/TableBuilder.hh"
45 #include "HepPDT/ParticleDataTable.hh"
48 #include "G4GeometryManager.hh"
49 #include "G4StateManager.hh"
50 #include "G4ApplicationState.hh"
51 #include "G4RunManagerKernel.hh"
52 #include "G4UImanager.hh"
54 #include "G4EventManager.hh"
57 #include "G4TransportationManager.hh"
58 #include "G4ParticleTable.hh"
60 #include "G4FieldManager.hh"
62 #include "G4GDMLParser.hh"
63 #include "G4SystemOfUnits.hh"
77 std::vector<boost::shared_ptr<SimWatcher> >& oWatchers,
78 std::vector<boost::shared_ptr<SimProducer> >& oProds
83 vector<ParameterSet> watchers;
85 watchers = iP.
getParameter<vector<ParameterSet> >(
"Watchers");
89 for(vector<ParameterSet>::iterator itWatcher = watchers.begin();
90 itWatcher != watchers.end();
92 std::auto_ptr<SimWatcherMakerBase> maker(
99 boost::shared_ptr<SimWatcher> watcherTemp;
100 boost::shared_ptr<SimProducer> producerTemp;
101 maker->make(*itWatcher,iReg,watcherTemp,producerTemp);
102 oWatchers.push_back(watcherTemp);
104 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),
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 RunManagerMT]\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 RunManagerMT]\n"
187 <<
"The MagneticField configuration is changed during the job execution\n"
188 <<
"this is not allowed, the MagneticField must stay unchanged\n";
216 G4TransportationManager * tM =
217 G4TransportationManager::GetTransportationManager();
219 tM->GetPropagatorInField());
231 std::pair< std::vector<SensitiveTkDetector*>,
232 std::vector<SensitiveCaloDetector*> > sensDets =
240 <<
" RunManagerMT: Sensitive Detector "
241 <<
"building finished; found "
243 <<
" Tk type Producers, and "
245 <<
" Calo type producers ";
253 std::auto_ptr<PhysicsListMakerBase>
256 if (physicsMaker.get()==0) {
257 throw SimG4Exception(
"Unable to find the Physics list requested");
281 throw SimG4Exception(
"G4RunManagerKernel initialization failed!");
286 std::ostringstream
dir;
287 dir << tableDir <<
'\0';
290 G4UImanager::GetUIpointer()->ApplyCommand(cmd);
301 edm::LogInfo(
"SimG4CoreApplication") <<
"RunManagerMT:: Requests UI: "
303 G4UImanager::GetUIpointer()->ApplyCommand(
m_G4Commands[it]);
318 G4StateManager::GetStateManager()->SetNewState(G4State_Quit);
337 <<
" RunManagerMT::produce event " << inpevt.
id().
event()
338 <<
" with no G4PrimaryVertices \n Aborting Run" ;
346 <<
" RunManagerMT: saved : Event " << inpevt.
id().
event()
359 G4Event * evt =
new G4Event(inpevt.
id().
event());
388 m_kernel->GetEventManager()->GetTrackingManager()->GetTrack();
389 t->SetTrackStatus(fStopAndKill) ;
410 m_kernel->GetEventManager()->GetStackManager()->clear() ;
411 m_kernel->GetEventManager()->GetTrackingManager()->EventAborted() ;
413 G4StateManager* stateManager = G4StateManager::GetStateManager();
414 stateManager->SetNewState(G4State_GeomClosed);
424 G4EventManager * eventManager =
m_kernel->GetEventManager();
431 eventManager->SetUserAction(userEventAction);
436 eventManager->SetUserAction(userTrackingAction);
441 eventManager->SetUserAction(userSteppingAction);
447 <<
"No generator; initialized "
448 <<
"only RunAction!";
456 G4StateManager::GetStateManager()->SetNewState(G4State_GeomClosed);
538 <<
" RunManagerMT WARNING : "
539 <<
"error opening file <" <<
m_FieldFile <<
"> for magnetic field";
541 double rmax = 9000*mm;
542 double zmax = 16000*mm;
547 int nr = (int)(rmax/dr);
548 int nz = 2*(int)(zmax/dz);
555 double cosf =
cos(phi);
556 double sinf =
sin(phi);
558 double point[4] = {0.0,0.0,0.0,0.0};
559 double bfield[3] = {0.0,0.0,0.0};
561 fout << std::setprecision(6);
562 for(
int i=0;
i<=nr; ++
i) {
564 for(
int j=0;
j<=nz; ++
j) {
568 field->GetFieldValue(point, bfield);
569 fout <<
"R(mm)= " << r/mm <<
" phi(deg)= " << phi/degree
570 <<
" Z(mm)= " << z/mm <<
" Bz(tesla)= " << bfield[2]/tesla
571 <<
" Br(tesla)= " << (bfield[0]*cosf + bfield[1]*sinf)/tesla
572 <<
" Bphi(tesla)= " << (bfield[0]*sinf - bfield[1]*cosf)/tesla
void Connect(RunAction *)
bool m_managerInitialized
T getParameter(std::string const &) const
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
edm::ParameterSet m_pStackingAction
SimTrackManager * GetSimTrackManager()
std::pair< std::vector< SensitiveTkDetector * >, std::vector< SensitiveCaloDetector * > > create(const DDDWorld &w, const DDCompactView &cpv, SensitiveDetectorCatalog &clg, edm::ParameterSet const &p, const SimTrackManager *m, SimActivityRegistry ®) const
virtual const math::XYZTLorentzVector * genVertex() const
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.
edm::ParameterSet m_pRunAction
G4StepSignal g4StepSignal_
edm::ESWatcher< IdealMagneticFieldRecord > idealMagRcdWatcher_
virtual const HepMC::GenEvent * genEvent() const
void initG4(const edm::EventSetup &es)
SimActivityRegistry::G4StepSignal m_g4StepSignal
std::vector< SensitiveCaloDetector * > m_sensCaloDets
edm::ParameterSet m_pGenerator
HepPDT::ParticleDataTable ParticleDataTable
void HepMC2G4(const HepMC::GenEvent *g, G4Event *e)
EndOfEventSignal endOfEventSignal_
std::auto_ptr< SimTrackManager > m_trackManager
Sin< T >::type sin(const T &t)
void abortRun(bool softAbort=false)
PrimaryTransformer * m_primaryTransformer
SimActivityRegistry::EndOfRunSignal m_endOfRunSignal
ExceptionHandler * m_CustomExceptionHandler
sim::FieldBuilder * m_fieldBuilder
void build(G4FieldManager *fM=0, G4PropagatorInField *fP=0)
BeginOfRunSignal beginOfRunSignal_
std::vector< std::string > m_G4Commands
SimActivityRegistry::EndOfEventSignal m_endOfEventSignal
void initializeUserActions()
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
RunManagerMT(edm::ParameterSet const &p)
BeginOfJobSignal beginOfJobSignal_
U second(std::pair< T, U > const &p)
std::vector< SensitiveTkDetector * > m_sensTkDets
static void createWatchers(const edm::ParameterSet &iP, SimActivityRegistry &iReg, std::vector< boost::shared_ptr< SimWatcher > > &oWatchers, std::vector< boost::shared_ptr< SimProducer > > &oProds)
edm::ParameterSet m_pTrackingAction
G4RunManagerKernel * m_kernel
std::vector< boost::shared_ptr< SimProducer > > m_producers
Cos< T >::type cos(const T &t)
void hepEvent(const HepMC::GenEvent *r)
edm::InputTag m_theLHCTlinkTag
void setGenEvent(const HepMC::GenEvent *inpevt)
BeginOfEventSignal beginOfEventSignal_
SimActivityRegistry::EndOfTrackSignal m_endOfTrackSignal
void EndOfRunAction(const G4Run *aRun)
EndOfRunSignal endOfRunSignal_
edm::ParameterSet m_pSteppingAction
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
unsigned int nTracks() const
std::vector< boost::shared_ptr< SimWatcher > > m_watchers
void DumpMagneticField(const G4Field *) const
void connect(Observer< const T * > *iObs)
does not take ownership of memory
unsigned int nVertices() const
bool m_StorePhysicsTables
std::auto_ptr< PhysicsList > m_physicsList
edm::ParameterSet m_pField
virtual void PostUserTrackingAction(const G4Track *aTrack)
unsigned int nGenParts() const
edm::ParameterSet m_pPhysics
void BeginOfRunAction(const G4Run *aRun)
DDDWorldSignal dddWorldSignal_
bool m_RestorePhysicsTables
T const * product() const
void nonBeamEvent2G4(const HepMC::GenEvent *g, G4Event *e)
edm::ParameterSet m_pEventAction
bool check(const edm::EventSetup &iSetup)
SimActivityRegistry::BeginOfRunSignal m_beginOfRunSignal
G4Event * generateEvent(edm::Event &inpevt)
std::string m_PhysicsTablesDir
void connect(SimActivityRegistry &iOther)
forwards our signals to slots connected to iOther
edm::ESWatcher< IdealGeometryRecord > idealGeomRcdWatcher_
volatile std::atomic< bool > shutdown_flag false
EndOfTrackSignal endOfTrackSignal_
RunAction * m_userRunAction
void produce(edm::Event &inpevt, const edm::EventSetup &es)
void resetGenParticleId(edm::Event &inpevt)
void collisionPoint(const math::XYZTLorentzVectorD &v)
SimActivityRegistry::BeginOfEventSignal m_beginOfEventSignal
T get(const Candidate &c)
*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
SimRunInterface * m_runInterface
BeginOfTrackSignal beginOfTrackSignal_
SimActivityRegistry m_registry
SimActivityRegistry::BeginOfTrackSignal m_beginOfTrackSignal