Skip to content

Commit

Permalink
cleanup user actions amd MC truth
Browse files Browse the repository at this point in the history
  • Loading branch information
civanch committed Jul 28, 2014
1 parent d01d39c commit ebcbd10
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 42 deletions.
4 changes: 3 additions & 1 deletion SimG4Core/Application/interface/StackingAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
#include <vector>

class NewTrackAction;
class TrackingAction;

class StackingAction : public G4UserStackingAction {

public:
StackingAction(const edm::ParameterSet & ps);
StackingAction(const TrackingAction*, const edm::ParameterSet & ps);
virtual ~StackingAction();

virtual G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track * aTrack);
Expand Down Expand Up @@ -65,6 +66,7 @@ class StackingAction : public G4UserStackingAction {
std::vector<const G4Region*> lowdensRegions;
std::vector<const G4Region*> deadRegions;

const TrackingAction* trackAction;
NewTrackAction* newTA;

// Russian roulette regions
Expand Down
2 changes: 2 additions & 0 deletions SimG4Core/Application/interface/TrackingAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TrackingAction : public G4UserTrackingAction
virtual void PostUserTrackingAction(const G4Track * aTrack);

TrackWithHistory * currentTrackWithHistory() { return currentTrack_; }
const G4Track * geant4Track() const { return g4Track_; }
G4TrackingManager * getTrackManager();

SimActivityRegistry::BeginOfTrackSignal m_beginOfTrackSignal;
Expand All @@ -30,6 +31,7 @@ class TrackingAction : public G4UserTrackingAction
private:
EventAction * eventAction_;
TrackWithHistory * currentTrack_;
const G4Track * g4Track_;
G4VSolid * worldSolid;
bool detailedTiming;
bool checkTrack;
Expand Down
2 changes: 1 addition & 1 deletion SimG4Core/Application/src/ActionInitialization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void ActionInitialization::Build() const
SetUserAction(stepAction);
interface->Connect(stepAction);

SetUserAction(new StackingAction(m_pStackingAction));
SetUserAction(new StackingAction(trackAction, m_pStackingAction));
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
3 changes: 2 additions & 1 deletion SimG4Core/Application/src/RunManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ void RunManager::initializeUserActions()
Connect(userSteppingAction);
eventManager->SetUserAction(userSteppingAction);

eventManager->SetUserAction(new StackingAction(m_pStackingAction));
eventManager->SetUserAction(new StackingAction(userTrackingAction,
m_pStackingAction));

} else {
edm::LogWarning("SimG4CoreApplication") << " RunManager: WARNING : "
Expand Down
3 changes: 2 additions & 1 deletion SimG4Core/Application/src/RunManagerMTWorker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ void RunManagerMTWorker::initializeUserActions() {
Connect(userSteppingAction);
eventManager->SetUserAction(userSteppingAction);

eventManager->SetUserAction(new StackingAction(m_pStackingAction));
eventManager->SetUserAction(new StackingAction(userTrackingAction,
m_pStackingAction));

}

Expand Down
7 changes: 4 additions & 3 deletions SimG4Core/Application/src/StackingAction.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "SimG4Core/Application/interface/StackingAction.h"
#include "SimG4Core/Notification/interface/CurrentG4Track.h"
#include "SimG4Core/Application/interface/TrackingAction.h"
#include "SimG4Core/Notification/interface/NewTrackAction.h"
#include "SimG4Core/Notification/interface/TrackInformation.h"
#include "SimG4Core/Notification/interface/TrackInformationExtractor.h"
Expand All @@ -17,7 +17,8 @@

//#define DebugLog

StackingAction::StackingAction(const edm::ParameterSet & p)
StackingAction::StackingAction(const TrackingAction* trka, const edm::ParameterSet & p)
: trackAction(trka)
{
trackNeutrino = p.getParameter<bool>("TrackNeutrino");
killHeavy = p.getParameter<bool>("KillHeavy");
Expand Down Expand Up @@ -292,7 +293,7 @@ G4ClassificationOfNewTrack StackingAction::ClassifyNewTrack(const G4Track * aTra

// Russian roulette && MC truth
if(classification != fKill) {
const G4Track * mother = CurrentG4Track::track();
const G4Track * mother = trackAction->geant4Track();
int flag = 0;
if(savePDandCinAll) {
flag = isItPrimaryDecayProductOrConversion(aTrack, *mother);
Expand Down
5 changes: 2 additions & 3 deletions SimG4Core/Application/src/TrackingAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//using namespace std;

TrackingAction::TrackingAction(EventAction * e, const edm::ParameterSet & p)
: eventAction_(e),currentTrack_(0),
: eventAction_(e),currentTrack_(0),g4Track_(0),
detailedTiming(p.getUntrackedParameter<bool>("DetailedTiming",false)),
checkTrack(p.getUntrackedParameter<bool>("CheckTrack",false)),
trackMgrVerbose(p.getUntrackedParameter<int>("G4TrackManagerVerbosity",0))
Expand All @@ -33,7 +33,7 @@ TrackingAction::~TrackingAction() {}

void TrackingAction::PreUserTrackingAction(const G4Track * aTrack)
{
CurrentG4Track::setTrack(aTrack);
g4Track_ = aTrack;

if (currentTrack_ != 0) {
throw SimG4Exception("TrackingAction: currentTrack is a mess...");
Expand Down Expand Up @@ -77,7 +77,6 @@ void TrackingAction::PreUserTrackingAction(const G4Track * aTrack)

void TrackingAction::PostUserTrackingAction(const G4Track * aTrack)
{
CurrentG4Track::postTracking(aTrack);
if (eventAction_->trackContainer() != 0) {

TrackInformationExtractor extractor;
Expand Down
14 changes: 2 additions & 12 deletions SimG4Core/Notification/interface/CurrentG4Track.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#ifndef SimG4Core_CurrentG4Track_H
#define SimG4Core_CurrentG4Track_H

#include "SimG4Core/Notification/interface/SimG4Exception.h"

#include "G4Track.hh"

class TrackingAction;

/** This class is NOT intended for general use.
* It provides immediate access to the currently tracked G4Track
* for places that can't access this information easily,
Expand All @@ -18,16 +14,10 @@ class TrackingAction;
class CurrentG4Track
{
public:
static int id() { check(); return m_track->GetTrackID(); }
static const G4Track * track() { check(); return m_track; }
static const G4Track * track();
static void setTrack(const G4Track *);
private:
static thread_local const G4Track * m_track;
static thread_local bool m_tracking;
static void setTrack(const G4Track *);
static void postTracking(const G4Track *);
static void check()
{ if (m_track == 0) throw SimG4Exception("CurrentG4Track requested but not set"); }
friend class TrackingAction;
};

#endif
14 changes: 3 additions & 11 deletions SimG4Core/Notification/src/CurrentG4Track.cc
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
#include "SimG4Core/Notification/interface/CurrentG4Track.h"

thread_local const G4Track * CurrentG4Track::m_track = 0;
thread_local bool CurrentG4Track::m_tracking = false;

void CurrentG4Track::setTrack(const G4Track * t)
{
if (m_tracking)
throw SimG4Exception("CurrentG4Track: new track set while previous is being tracked");
m_track = t;
m_tracking = true;
m_track = t;
}

void CurrentG4Track::postTracking(const G4Track * t)
const G4Track * CurrentG4Track::track()
{
if (t != m_track)
throw SimG4Exception("CurrentG4Track: tracking finishes for a different track");
if (!m_tracking)
throw SimG4Exception("CurrentG4Track: tracking finishes without having started");
m_tracking = false;
return m_track;
}

12 changes: 5 additions & 7 deletions SimG4Core/Notification/src/G4TrackToParticleID.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
int G4TrackToParticleID::particleID(const G4Track * g4trk)
{
int particleID_ = g4trk->GetDefinition()->GetPDGEncoding();
#ifdef DebugLog
if ( particleID_ > 1000000000 ) {
LogDebug("SimG4CoreNotification") << "G4TrackToParticleID ion code = " << particleID_ ;
if (0 == particleID_) {
edm::LogWarning("SimG4CoreNotification")
<< "G4TrackToParticleID: unknown code for track Id = " << g4trk->GetTrackID();
particleID_ = -99;
}
#endif
if (particleID_ != 0) return particleID_;
edm::LogWarning("SimG4CoreNotification") << "G4TrackToParticleID: unknown code for track Id = " << g4trk->GetTrackID();
return -99;
return particleID_;
}
5 changes: 3 additions & 2 deletions SimG4Core/Physics/src/G4ProcessTypeEnumerator.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "SimG4Core/Physics/interface/G4ProcessTypeEnumerator.h"

static const int nprocesses = 47;
static const std::string g4processes[nprocesses] = {
static const int nprocesses = 48;
static const std::string g4processes[nprocesses] = { "Primary",
"Transportation", "CoupleTrans", "CoulombScat", "Ionisation", "Brems",
"PairProdCharged", "Annih", "AnnihToMuMu", "AnnihToHad", "NuclearStopp",
"Msc", "Rayleigh", "PhotoElectric", "Compton", "Conv",
Expand All @@ -13,6 +13,7 @@ static const std::string g4processes[nprocesses] = {
"DecayPiWSpin", "DecayRadio", "DecayUnKnown", "DecayExt", "StepLimiter",
"UsrSpecCuts", "NeutronKiller"};
static const int g4subtype[nprocesses] = {
0, // Primary generator
91, // Transportation
92, // CoupleTrans
1, // CoulombScat
Expand Down

0 comments on commit ebcbd10

Please sign in to comment.