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

Fixed static anal warnings in SIM #13440

Merged
merged 3 commits into from Feb 29, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions SimG4Core/Application/interface/CMSGDMLWriteStructure.h
Expand Up @@ -5,6 +5,7 @@
#include <xercesc/dom/DOM.hpp>

class G4LogicalVolume;
class G4VRangeToEnergyConverter;

class CMSGDMLWriteStructure : public G4GDMLWriteStructure
{
Expand All @@ -17,6 +18,10 @@ class CMSGDMLWriteStructure : public G4GDMLWriteStructure
virtual void AddExtension(xercesc::DOMElement* volumeElement,
const G4LogicalVolume* const glv);


private:

G4VRangeToEnergyConverter *converter[4];
};

#endif
6 changes: 2 additions & 4 deletions SimG4Core/Application/interface/RunManagerMT.h
Expand Up @@ -91,17 +91,15 @@ class RunManagerMT

// In order to share the physics list with the worker threads, we
// need a non-const pointer. Thread-safety is handled inside Geant4
// with TLS. Should we consider a friend declaration here in order
// to avoid misuse?
// with TLS.
PhysicsList *physicsListForWorker() const {
return m_physicsList.get();
}

// In order to share the ChordFinderSetter (for
// G4MonopoleTransportation) with the worker threads, we need a
// non-const pointer. Thread-safety is handled inside
// ChordFinderStter with TLS. Should we consider a friend
// declaration here in order to avoid misuse?
// ChordFinderStter with TLS.
sim::ChordFinderSetter *chordFinderSetterForWorker() const {
return m_chordFinderSetter.get();
}
Expand Down
16 changes: 6 additions & 10 deletions SimG4Core/Application/src/CMSGDMLWriteStructure.cc
Expand Up @@ -11,7 +11,12 @@
#include "G4SystemOfUnits.hh"

CMSGDMLWriteStructure::CMSGDMLWriteStructure()
{}
{
converter[0] = new G4RToEConvForGamma();
converter[1] = new G4RToEConvForElectron();
converter[2] = new G4RToEConvForPositron();
converter[3] = new G4RToEConvForProton();
}

CMSGDMLWriteStructure::~CMSGDMLWriteStructure()
{}
Expand All @@ -23,15 +28,6 @@ CMSGDMLWriteStructure::AddExtension(xercesc::DOMElement* volumeElement,
xercesc::DOMElement* auxiliaryElement = 0;
std::stringstream ss;
const char* cutnames[4] = {"pcutg","pcutem","pcutep","pcutp"};
static G4VRangeToEnergyConverter *converter[4];
static G4bool ifirst = true;
if(ifirst) {
converter[0] = new G4RToEConvForGamma();
converter[1] = new G4RToEConvForElectron();
converter[2] = new G4RToEConvForPositron();
converter[3] = new G4RToEConvForProton();
ifirst = false;
}

auxiliaryElement = NewElement("auxiliary");
auxiliaryElement->setAttributeNode(NewAttribute("auxtype","G4Region"));
Expand Down
1 change: 0 additions & 1 deletion SimG4Core/CustomPhysics/interface/CustomPhysicsList.h
Expand Up @@ -25,7 +25,6 @@ class CustomPhysicsList : public G4VPhysicsConstructor

static G4ThreadLocal G4Decay* fDecayProcess;
static G4ThreadLocal G4ProcessHelper* myHelper;
static G4ThreadLocal bool fInitialized;

bool fHadronicInteraction;

Expand Down
1 change: 0 additions & 1 deletion SimG4Core/CustomPhysics/interface/CustomPhysicsListSS.h
Expand Up @@ -25,7 +25,6 @@ class CustomPhysicsListSS : public G4VPhysicsConstructor

static G4ThreadLocal G4Decay* fDecayProcess;
static G4ThreadLocal G4ProcessHelper* myHelper;
static G4ThreadLocal bool fInitialized;

bool fHadronicInteraction;

Expand Down
@@ -1,19 +1,19 @@
#ifndef RHSTOPDUMP_H
#define RHSTOPDUMP_H 1
#ifndef SimG4Core_RHStopDump_H
#define SimG4Core_RHStopDump_H
//
// Dump stopping points from the Event into ASCII file
// F.Ratnikov, Apr. 8, 2010
//

#include <fstream>

#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

class RHStopDump : public edm::EDAnalyzer {
class RHStopDump : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
explicit RHStopDump(const edm::ParameterSet&);
virtual ~RHStopDump() {};
virtual void analyze(const edm::Event&, const edm::EventSetup&);
virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
private:
std::ofstream mStream;
std::string mProducer;
Expand Down
@@ -1,16 +1,17 @@
#ifndef SimG4Core_RHStopTracer_H
#define SimG4Core_RHStopTracer_H

#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "SimG4Core/Watcher/interface/SimProducer.h"
#include "SimG4Core/Notification/interface/Observer.h"


#include <boost/regex.hpp>

class BeginOfRun;
class BeginOfEvent;
class BeginOfTrack;
class EndOfTrack;
class G4Step;
class G4ParticleDefinition;

class RHStopTracer : public SimProducer,
public Observer<const BeginOfRun *>,
Expand Down Expand Up @@ -42,7 +43,9 @@ class RHStopTracer : public SimProducer,
};
bool mStopRegular;
double mTraceEnergy;
boost::regex mTraceParticleNameRegex;
std::string mTraceParticleName;
const G4ParticleDefinition* mParticle;
std::vector <StopPoint> mStopPoints;
bool matched (const std::string& fName) const;
};

#endif
2 changes: 1 addition & 1 deletion SimG4Core/CustomPhysics/plugins/RHStopDump.cc
@@ -1,4 +1,4 @@
#include "RHStopDump.h"
#include "SimG4Core/CustomPhysics/interface/RHStopDump.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
Expand Down
77 changes: 40 additions & 37 deletions SimG4Core/CustomPhysics/plugins/RHStopTracer.cc
@@ -1,4 +1,4 @@
#include "RHStopTracer.h"
#include "SimG4Core/CustomPhysics/interface/RHStopTracer.h"

#include "SimG4Core/Notification/interface/BeginOfRun.h"
#include "SimG4Core/Notification/interface/BeginOfEvent.h"
Expand All @@ -14,12 +14,14 @@
#include "G4Run.hh"
#include "G4Event.hh"
#include "G4SystemOfUnits.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"

RHStopTracer::RHStopTracer(edm::ParameterSet const & p) {
edm::ParameterSet parameters = p.getParameter<edm::ParameterSet>("RHStopTracer");
mStopRegular = parameters.getUntrackedParameter<bool>("stopRegularParticles", false);
mTraceEnergy = 1000 * parameters.getUntrackedParameter<double>("traceEnergy", 1.e20); // GeV->KeV
mTraceParticleNameRegex = parameters.getParameter<std::string>("traceParticle");
mTraceEnergy = parameters.getUntrackedParameter<double>("traceEnergy", 1.e20);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@civanch - what are the units of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidlange6 , G4 default unit is MeV, because this parameter of the class is used only to compare with G4 value, no conversion is needed. To clarify value a LogInfo printout is added, so user will see what is the value/unit of this energy.

mTraceParticleName = parameters.getParameter<std::string>("traceParticle");
produces< std::vector<std::string> >("StoppedParticlesName");
produces< std::vector<float> >("StoppedParticlesX");
produces< std::vector<float> >("StoppedParticlesY");
Expand All @@ -29,53 +31,58 @@ RHStopTracer::RHStopTracer(edm::ParameterSet const & p) {
produces< std::vector<float> >("StoppedParticlesMass");
produces< std::vector<float> >("StoppedParticlesCharge");

LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::RHStopTracer->"
<< mTraceParticleNameRegex << '/' << mTraceEnergy;
mParticle = G4ParticleTable::GetParticleTable()->FindParticle(mTraceParticleName);

edm::LogInfo("SimG4CoreCustomPhysics")
<< "RHStopTracer::RHStopTracer " << mTraceParticleName
<< " Eth(GeV)= " << mTraceEnergy;
mTraceEnergy *= CLHEP::GeV;
}

RHStopTracer::~RHStopTracer() {
}

void RHStopTracer::update (const BeginOfRun * fRun) {
LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::update-> begin of the run " << (*fRun)()->GetRunID();
LogDebug("SimG4CoreCustomPhysics")
<< "RHStopTracer::update-> begin of the run " << (*fRun)()->GetRunID();
}

void RHStopTracer::update (const BeginOfEvent * fEvent) {
LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::update-> begin of the event " << (*fEvent)()->GetEventID();
LogDebug("SimG4CoreCustomPhysics")
<< "RHStopTracer::update-> begin of the event " << (*fEvent)()->GetEventID();
}

void RHStopTracer::update (const BeginOfTrack * fTrack) {
const G4Track* track = (*fTrack)();
if ((track->GetMomentum().mag()> mTraceEnergy) || matched (track->GetDefinition()->GetParticleName())) {
LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::update-> new track: ID/Name/pdgId/mass/charge/Parent: "
<< track->GetTrackID() << '/' << track->GetDefinition()->GetParticleName() << '/'
<< track->GetDefinition()->GetPDGEncoding() << '/'
<< track->GetDefinition()->GetPDGMass()/GeV <<" GeV/" << track->GetDefinition()->GetPDGCharge() << '/'
<< track->GetParentID()
<< " position X/Y/Z: " << track->GetPosition().x() << '/'
<< track->GetPosition().y() << '/' << track->GetPosition().z()
<< " R/phi: " << track->GetPosition().perp() << '/' << track->GetPosition().phi()
<< " px/py/pz/p=" << track->GetMomentum().x() << '/'
<< track->GetMomentum().y() << '/' << track->GetMomentum().z() << '/'<< track->GetMomentum().mag();
}
if (mStopRegular && !matched (track->GetDefinition()->GetParticleName())) { // kill regular particles
const G4ParticleDefinition* part = track->GetDefinition();
if(part && part == mParticle && track->GetKineticEnergy() > mTraceEnergy) {
LogDebug("SimG4CoreCustomPhysics")
<< "RHStopTracer::update-> new track: ID/Name/pdgId/mass/charge/Parent: "
<< track->GetTrackID() << '/' << part->GetParticleName() << '/'
<< part->GetPDGEncoding() << '/'
<< part->GetPDGMass()/GeV <<" GeV/" << part->GetPDGCharge() << '/'
<< track->GetParentID()
<< " Position: " << track->GetPosition() << ' '
<< " R/phi: " << track->GetPosition().perp() << '/' << track->GetPosition().phi()
<< " 4vec " << track->GetMomentum();
} else if (mStopRegular) { // kill regular particles
const_cast<G4Track*>(track)->SetTrackStatus(fStopAndKill);
}
}

void RHStopTracer::update (const EndOfTrack * fTrack) {
const G4Track* track = (*fTrack)();
if ((track->GetMomentum().mag()> mTraceEnergy) || matched (track->GetDefinition()->GetParticleName())) {
LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::update-> stop track: ID/Name/pdgId/mass/charge/Parent: "
<< track->GetTrackID() << '/' << track->GetDefinition()->GetParticleName() << '/'
<< track->GetDefinition()->GetPDGEncoding() << '/'
<< track->GetDefinition()->GetPDGMass()/GeV <<" GeV/" << track->GetDefinition()->GetPDGCharge() << '/'
<< track->GetParentID()
<< " position X/Y/Z: " << track->GetPosition().x() << '/'
<< track->GetPosition().y() << '/' << track->GetPosition().z()
<< " R/phi: " << track->GetPosition().perp() << '/' << track->GetPosition().phi()
<< " px/py/pz/p=" << track->GetMomentum().x() << '/'
<< track->GetMomentum().y() << '/' << track->GetMomentum().z() << '/'<< track->GetMomentum().mag();
const G4ParticleDefinition* part = track->GetDefinition();
if(part && part == mParticle && track->GetKineticEnergy() > mTraceEnergy) {
LogDebug("SimG4CoreCustomPhysics") <<
"RHStopTracer::update-> stop track: ID/Name/pdgId/mass/charge/Parent: "
<< track->GetTrackID() << '/' << part->GetParticleName() << '/'
<< part->GetPDGEncoding() << '/'
<< part->GetPDGMass()/GeV <<" GeV/" << part->GetPDGCharge() << '/'
<< track->GetParentID()
<< " Position: " << track->GetPosition() << ' '
<< " R/phi: " << track->GetPosition().perp() << '/' << track->GetPosition().phi()
<< " 4vec " << track->GetMomentum();
if (track->GetMomentum().mag () < 0.001) {
mStopPoints.push_back (StopPoint (track->GetDefinition()->GetParticleName(),
track->GetPosition().x(),
Expand All @@ -89,11 +96,7 @@ void RHStopTracer::update (const EndOfTrack * fTrack) {
}
}

bool RHStopTracer::matched (const std::string& fName) const {
return boost::regex_match (fName, mTraceParticleNameRegex);
}

void RHStopTracer::produce(edm::Event& fEvent, const edm::EventSetup&) {
void RHStopTracer::produce(edm::Event& fEvent, const edm::EventSetup&) {
LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::produce->";

std::auto_ptr<std::vector<std::string> > names (new std::vector<std::string>);
Expand Down Expand Up @@ -125,4 +128,4 @@ bool RHStopTracer::matched (const std::string& fName) const {
fEvent.put (masses, "StoppedParticlesMass");
fEvent.put (charges, "StoppedParticlesCharge");
mStopPoints.clear ();
}
}
5 changes: 2 additions & 3 deletions SimG4Core/CustomPhysics/plugins/module.cc
Expand Up @@ -5,9 +5,8 @@
#include "SimG4Core/Physics/interface/PhysicsListFactory.h"
#include "SimG4Core/CustomPhysics/interface/CustomPhysics.h"

#include "RHStopDump.h"
#include "RHStopTracer.h"

#include "SimG4Core/CustomPhysics/interface/RHStopDump.h"
#include "SimG4Core/CustomPhysics/interface/RHStopTracer.h"

DEFINE_PHYSICSLIST(CustomPhysics);
DEFINE_FWK_MODULE(RHStopDump) ;
Expand Down
21 changes: 10 additions & 11 deletions SimG4Core/CustomPhysics/src/CustomPhysicsList.cc
Expand Up @@ -18,9 +18,8 @@

using namespace CLHEP;

G4ThreadLocal G4Decay* CustomPhysicsList::fDecayProcess = 0;
G4ThreadLocal G4ProcessHelper* CustomPhysicsList::myHelper = 0;
G4ThreadLocal bool CustomPhysicsList::fInitialized = false;
G4ThreadLocal G4Decay* CustomPhysicsList::fDecayProcess = nullptr;
G4ThreadLocal G4ProcessHelper* CustomPhysicsList::myHelper = nullptr;

CustomPhysicsList::CustomPhysicsList(std::string name, const edm::ParameterSet & p)
: G4VPhysicsConstructor(name)
Expand All @@ -45,19 +44,19 @@ void CustomPhysicsList::ConstructParticle(){

void CustomPhysicsList::ConstructProcess() {

//if(fInitialized) { return; }
//fInitialized = true;

edm::LogInfo("SimG4CoreCustomPhysics")
<<"CustomPhysicsList: adding CustomPhysics processes "
<< "for the list of particles";

fDecayProcess = new G4Decay();

G4PhysicsListHelper* ph = G4PhysicsListHelper::GetPhysicsListHelper();

aParticleIterator->reset();
G4ParticleDefinition* particle;

while((*aParticleIterator)()) {
G4ParticleDefinition* particle = aParticleIterator->value();
particle = aParticleIterator->value();
if(CustomParticleFactory::isCustomParticle(particle)) {
CustomParticle* cp = dynamic_cast<CustomParticle*>(particle);
G4ProcessManager* pmanager = particle->GetProcessManager();
Expand All @@ -67,11 +66,11 @@ void CustomPhysicsList::ConstructProcess() {
<< " Mass= " << particle->GetPDGMass()/GeV <<" GeV.";
if(cp && pmanager) {
if(particle->GetPDGCharge() != 0.0) {
pmanager->AddProcess(new G4hMultipleScattering,-1, 1, 1);
pmanager->AddProcess(new G4hIonisation, -1, 2, 2);
ph->RegisterProcess(new G4hMultipleScattering, particle);
ph->RegisterProcess(new G4hIonisation, particle);
}
if(fDecayProcess->IsApplicable(*particle)) {
pmanager->AddProcess(new G4Decay, 0, -1, 3);
ph->RegisterProcess(fDecayProcess, particle);
}
if(cp->GetCloud() && fHadronicInteraction &&
CustomPDGParser::s_isRHadron(particle->GetPDGEncoding())) {
Expand All @@ -80,7 +79,7 @@ void CustomPhysicsList::ConstructProcess() {
<<" CloudMass= " <<cp->GetCloud()->GetPDGMass()/GeV
<<" GeV; SpectatorMass= " << cp->GetSpectator()->GetPDGMass()/GeV<<" GeV.";

if(!myHelper) myHelper = new G4ProcessHelper(myConfig);
if(!myHelper) { myHelper = new G4ProcessHelper(myConfig); }
pmanager->AddDiscreteProcess(new FullModelHadronicProcess(myHelper));
}
}
Expand Down