Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run3-sim98 Make use of ESGetToken in some of the classes in SimG4Core/HelpfulWatchers #36289

Merged
merged 2 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions SimG4Core/HelpfulWatchers/interface/MonopoleSteppingAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "SimG4Core/Notification/interface/Observer.h"
#include "SimG4Core/Watcher/interface/SimWatcher.h"
#include "MagneticField/Engine/interface/MagneticField.h"
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"

#include "G4Step.hh"
#include <vector>

class BeginOfJob;
class BeginOfRun;
class BeginOfTrack;

class MonopoleSteppingAction : public SimWatcher,
public Observer<const BeginOfJob *>,
public Observer<const BeginOfRun *>,
public Observer<const BeginOfTrack *>,
public Observer<const G4Step *> {
public:
MonopoleSteppingAction(edm::ParameterSet const &p);
~MonopoleSteppingAction() override;
void update(const BeginOfJob *) override;
void registerConsumes(edm::ConsumesCollector) override;
void beginRun(edm::EventSetup const &) override;
void update(const BeginOfRun *) override;
void update(const BeginOfTrack *) override;
void update(const G4Step *) override;

private:
edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> tok_bFieldH_;
bool mode, actOnTrack;
std::vector<int> pdgCode;
double eStart, pxStart, pyStart, pzStart;
Expand Down
34 changes: 16 additions & 18 deletions SimG4Core/HelpfulWatchers/src/MonopoleSteppingAction.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "SimG4Core/HelpfulWatchers/interface/MonopoleSteppingAction.h"

#include "SimG4Core/Notification/interface/BeginOfJob.h"
#include "SimG4Core/Notification/interface/BeginOfRun.h"
#include "SimG4Core/Notification/interface/BeginOfTrack.h"
#include "SimG4Core/Physics/interface/Monopole.h"
Expand All @@ -9,9 +8,6 @@
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "MagneticField/Engine/interface/MagneticField.h"
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"

#include "G4Event.hh"
#include "G4ParticleTable.hh"
#include "G4Run.hh"
Expand All @@ -22,21 +18,23 @@

MonopoleSteppingAction::MonopoleSteppingAction(edm::ParameterSet const &p) : actOnTrack(false), bZ(0) {
mode = p.getUntrackedParameter<bool>("ChangeFromFirstStep", true);
edm::LogInfo("SimG4CoreWatcher") << "MonopoleSeppingAction set mode for"
<< " start at first step to " << mode;
edm::LogVerbatim("SimG4CoreWatcher") << "MonopoleSeppingAction set mode for"
<< " start at first step to " << mode;
}

MonopoleSteppingAction::~MonopoleSteppingAction() {}

void MonopoleSteppingAction::update(const BeginOfJob *job) {
const edm::EventSetup *iSetup = (*job)();
edm::ESHandle<MagneticField> bFieldH;
iSetup->get<IdealMagneticFieldRecord>().get(bFieldH);
const MagneticField *bField = bFieldH.product();
void MonopoleSteppingAction::registerConsumes(edm::ConsumesCollector cc) {
tok_bFieldH_ = cc.esConsumes<MagneticField, IdealMagneticFieldRecord, edm::Transition::BeginRun>();
edm::LogVerbatim("SimG4CoreWatcher") << "MonopoleSteppingAction::Initialize ESGetToken for MagneticField";
}

void MonopoleSteppingAction::beginRun(edm::EventSetup const &es) {
const MagneticField *bField = &es.getData(tok_bFieldH_);
const GlobalPoint p(0, 0, 0);
bZ = (bField->inTesla(p)).z();
edm::LogInfo("SimG4CoreWatcher") << "Magnetic Field (X): " << (bField->inTesla(p)).x()
<< " Y: " << (bField->inTesla(p)).y() << " Z: " << bZ;
edm::LogVerbatim("SimG4CoreWatcher") << "Magnetic Field (X): " << (bField->inTesla(p)).x()
<< " Y: " << (bField->inTesla(p)).y() << " Z: " << bZ;
}

void MonopoleSteppingAction::update(const BeginOfRun *) {
Expand All @@ -50,16 +48,16 @@ void MonopoleSteppingAction::update(const BeginOfRun *) {
pdgCode.push_back(particle->GetPDGEncoding());
}
}
edm::LogInfo("SimG4CoreWatcher") << "MonopoleSeppingAction Finds " << pdgCode.size() << " candidates";
edm::LogVerbatim("SimG4CoreWatcher") << "MonopoleSeppingAction Finds " << pdgCode.size() << " candidates";
for (unsigned int ii = 0; ii < pdgCode.size(); ++ii) {
edm::LogInfo("SimG4CoreWatcher") << "PDG Code[" << ii << "] = " << pdgCode[ii];
edm::LogVerbatim("SimG4CoreWatcher") << "PDG Code[" << ii << "] = " << pdgCode[ii];
}
cMevToJ = CLHEP::e_SI / CLHEP::eV;
cMeVToKgMByS = CLHEP::e_SI * CLHEP::meter / (CLHEP::eV * CLHEP::c_light * CLHEP::second);
cInMByS = CLHEP::c_light * CLHEP::second / CLHEP::meter;
edm::LogInfo("SimG4CoreWatcher") << "MonopoleSeppingAction Constants:"
<< " MevToJoules = " << cMevToJ << ", MevToKgm/s = " << cMeVToKgMByS
<< ", c in m/s = " << cInMByS << ", mag. charge = " << magCharge;
edm::LogVerbatim("SimG4CoreWatcher") << "MonopoleSeppingAction Constants:"
<< " MevToJoules = " << cMevToJ << ", MevToKgm/s = " << cMeVToKgMByS
<< ", c in m/s = " << cInMByS << ", mag. charge = " << magCharge;
}

void MonopoleSteppingAction::update(const BeginOfTrack *trk) {
Expand Down