Skip to content
Snippets Groups Projects
Commit 8ac3a284 authored by Elmar Ritsch's avatar Elmar Ritsch Committed by Graeme Stewart
Browse files

Merge changes from MCTruth-00-02-00->MCTruth-00-02-00-03 into trunk....

Merge changes from MCTruth-00-02-00->MCTruth-00-02-00-03 into trunk. ATLASSIM-2701 : Add pointer to primary (generator) MC truth particle to VTrackInformation. Critical for fix of incorret calibration hits assignment. ATLASSIM-2456 + Introduce more appropriate naming for pointer to base ISFParticle in various TrackInformation classes. (MCTruth-00-04-00)

	* Merge changes from MCTruth-00-02-00->MCTruth-00-02-00-03 into trunk.
	ATLASSIM-2701 :
		* Add pointer to primary (generator) MC truth particle to
		VTrackInformation. Critical for fix of incorret calibration hits
		assignment. ATLASSIM-2456
		* Introduce more appropriate naming for pointer to base ISFParticle
		in various TrackInformation classes.
	* tagging MCTruth-00-04-00

2015-09-15  John Chapman  <John.Chapman@cern.ch>
	* Removed MCTruth/CosmicTRSD.h, src/CosmicTRSD.cxx,
	MCTruth/TrackRecorderSD.h, src/TrackRecorderSD.cxx - Merged into
	TrackWriteFastSim/TrackWriteFastSD. ATLASSIM-2144. Requires
	TrackWriteFastSim-00-03-00 or later.
	* Removed MCTruth/TruthStrategy.h, src/TruthStrategy.cxx,
	MCTruth/TruthStrategyManager.h, src/TruthStrategyManager.cxx,
	MCTruth/MCTruthSteppingAction.h, src/MCTruthSteppingAction.cxx,
	MCTruth/AtlasTrajectory.h, src/AtlasTrajectory.cxx,
	src/components, python - moved to MCTruthBase. Requires
	MCTruthBase-00-01-01 onwards. ATLASSIM-2144
...
(Long ChangeLog diff - truncated)
parent 2d2f7c51
No related merge requests found
Showing
with 55 additions and 782 deletions
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef AtlasTrajectory_H
#define AtlasTrajectory_H
#include "G4Trajectory.hh"
#include "G4TrackingManager.hh"
#include "SimHelpers/SecondaryTracksHelper.h"
class AtlasTrajectory: public G4Trajectory {
public:
AtlasTrajectory();
AtlasTrajectory(const G4Track* aTrack);
~AtlasTrajectory() {}
void AppendStep(const G4Step* aStep);
#if G4VERSION_NUMBER >= 1010
void DrawTrajectory() const override { DrawTrajectory(0); }
#endif
void DrawTrajectory(G4int) const;
private:
const G4TrackingManager *theTrackManager;
SecondaryTracksHelper theSecondaryTrackHelper;
};
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef CavernBGKiller_H
#define CavernBGKiller_H
#include "TrackRecord/TrackRecordCollection.h"
#include "SimHelpers/AthenaHitsCollectionHelper.h"
#include "FadsSensitiveDetector/FadsSensitiveDetector.h"
class G4Step;
class G4TouchableHistory;
class G4HCofThisEvent;
// Generic SD for recording track hits in any part of the detector
class CavernBGKiller : public FADS::FadsSensitiveDetector
{
public:
CavernBGKiller(std::string name);
~CavernBGKiller();
/** member functions */
void Initialize(G4HCofThisEvent* );
G4bool ProcessHits(G4Step* , G4TouchableHistory* );
void EndOfEvent(G4HCofThisEvent* );
private:
TrackRecordCollection *trackRecordCollection;
AthenaHitsCollectionHelper theHelper;
};
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef CosmicTRSD_H
#define CosmicTRSD_H
#include "TrackRecord/TrackRecordCollection.h"
#include "SimHelpers/AthenaHitsCollectionHelper.h"
#include "FadsSensitiveDetector/FadsSensitiveDetector.h"
class G4HCofThisEvent;
class G4Step;
class G4TouchableHistory;
// Generic SD for recording track hits in any part of the detector
class CosmicTRSD : public FADS::FadsSensitiveDetector
{
public:
CosmicTRSD(std::string name);
~CosmicTRSD();
/** member functions */
void Initialize(G4HCofThisEvent* );
G4bool ProcessHits(G4Step* , G4TouchableHistory* );
void EndOfEvent(G4HCofThisEvent* );
private:
TrackRecordCollection *trackRecordCollection;
AthenaHitsCollectionHelper theHelper;
};
#endif
......@@ -9,50 +9,43 @@
#include "G4ThreeVector.hh"
#include "G4VUserEventInformation.hh"
namespace ISF {
class ISFParticle;
}
class EventInformation: public G4VUserEventInformation {
public:
EventInformation(): G4VUserEventInformation(),nrOfPrimaryParticles(0),
EventInformation(): G4VUserEventInformation(),nrOfPrimaryParticles(0),
nrOfPrimaryVertices(0),secondaryParticleBarCode(200000),
secondaryVertexBarCode(-200000),theEvent(0),
currentPrimary(0),currentlyTraced(0),currentISFPrimary(0) {}
HepMC::GenEvent* GetHepMCEvent() ;
void SetHepMCEvent(HepMC::GenEvent*);
int GetNrOfPrimaryParticles() const;
void SetNrOfPrimaryParticles(int nr);
int GetNrOfPrimaryVertices() const;
void SetNrOfPrimaryVertices(int nr);
void SetVertexPosition(const G4ThreeVector);
const G4ThreeVector GetVertexPosition() const;
void Print() const {}
void SetCurrentPrimary(HepMC::GenParticle *p) {currentPrimary=p;}
void SetCurrentISFPrimary(const ISF::ISFParticle *p) {currentISFPrimary=p;}
void SetCurrentlyTraced(HepMC::GenParticle *p) {currentlyTraced=p;}
HepMC::GenParticle *GetCurrentPrimary() const {return currentPrimary;}
const ISF::ISFParticle* GetCurrentISFPrimary() const { return currentISFPrimary; }
HepMC::GenParticle *GetCurrentlyTraced() const {return currentlyTraced;}
int SecondaryParticleBarCode() {secondaryParticleBarCode++;
return secondaryParticleBarCode;}
int SecondaryVertexBarCode() {secondaryVertexBarCode--;
return secondaryVertexBarCode;}
currentPrimary(0),currentlyTraced(0) {}
HepMC::GenEvent* GetHepMCEvent() ;
void SetHepMCEvent(HepMC::GenEvent*);
int GetNrOfPrimaryParticles() const;
void SetNrOfPrimaryParticles(int nr);
int GetNrOfPrimaryVertices() const;
void SetNrOfPrimaryVertices(int nr);
void SetVertexPosition(const G4ThreeVector);
const G4ThreeVector GetVertexPosition() const;
void Print() const {}
void SetCurrentPrimary(HepMC::GenParticle *p) {currentPrimary=p;}
void SetCurrentlyTraced(HepMC::GenParticle *p) {currentlyTraced=p;}
HepMC::GenParticle *GetCurrentPrimary() const {return currentPrimary;}
HepMC::GenParticle *GetCurrentlyTraced() const {return currentlyTraced;}
int SecondaryParticleBarCode() {secondaryParticleBarCode++;
return secondaryParticleBarCode;}
int SecondaryVertexBarCode() {secondaryVertexBarCode--;
return secondaryVertexBarCode;}
private:
G4ThreeVector vertexPosition;
int nrOfPrimaryParticles;
int nrOfPrimaryVertices;
int secondaryParticleBarCode;
int secondaryVertexBarCode;
HepMC::GenEvent *theEvent;
HepMC::GenParticle *currentPrimary;
HepMC::GenParticle *currentlyTraced;
const ISF::ISFParticle *currentISFPrimary;
G4ThreeVector vertexPosition;
int nrOfPrimaryParticles;
int nrOfPrimaryVertices;
int secondaryParticleBarCode;
int secondaryVertexBarCode;
HepMC::GenEvent *theEvent;
HepMC::GenParticle *currentPrimary;
HepMC::GenParticle *currentlyTraced;
};
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef MCTruthSteppingAction_H
#define MCTruthSteppingAction_H
#include "G4UserSteppingAction.hh"
#include <map>
#include <string>
class SensitiveDetectorEntry;
class G4VSensitiveDetector;
typedef std::map<std::string, int, std::less<std::string> > volMap;
typedef std::map<std::string,G4VSensitiveDetector*, std::less<std::string> > sdMap;
typedef volMap::const_iterator volMapIterator;
class MCTruthSteppingAction : public G4UserSteppingAction
{
friend class TruthStrategyManager;
public:
void UserSteppingAction(const G4Step* aStep);
private:
volMap vm;
sdMap sdm;
void AddRecordingEnvelope(std::string,int,std::string sdName="");
void ListRecordingEnvelopes();
MCTruthSteppingAction();
MCTruthSteppingAction(const MCTruthSteppingAction&);
SensitiveDetectorEntry *sde;
};
#endif
File mode changed from 100755 to 100644
......@@ -13,15 +13,15 @@ namespace ISF {
class TrackBarcodeInfo: public VTrackInformation {
public:
TrackBarcodeInfo(int bc, const ISF::ISFParticle* isp=0);
TrackBarcodeInfo(int bc, const ISF::ISFParticle* baseIsp=0);
int GetParticleBarcode() const;
const ISF::ISFParticle *GetISFParticle() const;
void SetISFParticle(const ISF::ISFParticle*);
const ISF::ISFParticle *GetBaseISFParticle() const;
void SetBaseISFParticle(const ISF::ISFParticle*);
void SetReturnedToISF(bool returned);
bool GetReturnedToISF() const;
private:
const ISF::ISFParticle *theISFParticle;
const ISF::ISFParticle *theBaseISFParticle;
int barcode;
bool returnedToISF;
};
......
File mode changed from 100755 to 100644
......@@ -14,12 +14,12 @@ namespace ISF {
class TrackInformation: public VTrackInformation {
public:
TrackInformation();
TrackInformation(const HepMC::GenParticle*,const ISF::ISFParticle* isp=0);
TrackInformation(const HepMC::GenParticle*,const ISF::ISFParticle* baseIsp=0);
const HepMC::GenParticle *GetHepMCParticle() const;
const ISF::ISFParticle *GetISFParticle() const;
const ISF::ISFParticle *GetBaseISFParticle() const;
int GetParticleBarcode() const;
void SetParticle(const HepMC::GenParticle*);
void SetISFParticle(const ISF::ISFParticle*);
void SetBaseISFParticle(const ISF::ISFParticle*);
void SetReturnedToISF(bool returned) {returnedToISF=returned;};
bool GetReturnedToISF() const {return returnedToISF;};
void SetRegenerationNr(int i) {regenerationNr=i;};
......@@ -27,7 +27,7 @@ public:
private:
int regenerationNr;
const HepMC::GenParticle *theParticle;
const ISF::ISFParticle *theISFParticle;
const ISF::ISFParticle *theBaseISFParticle;
bool returnedToISF;
};
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TrackRecorderSD_H
#define TrackRecorderSD_H
#include "TrackRecord/TrackRecordCollection.h"
#include "SimHelpers/AthenaHitsCollectionHelper.h"
#include "FadsSensitiveDetector/FadsSensitiveDetector.h"
class G4HCofThisEvent;
class G4Step;
class G4TouchableHistory;
// Generic SD for recording track hits in any part of the detector
class TrackRecorderSD : public FADS::FadsSensitiveDetector
{
public:
TrackRecorderSD(std::string name);
~TrackRecorderSD();
/** member functions */
void Initialize(G4HCofThisEvent* );
G4bool ProcessHits(G4Step* , G4TouchableHistory* );
void EndOfEvent(G4HCofThisEvent* );
TrackRecordCollection::const_iterator HitsBegin(){return trackRecordCollection->begin();};
TrackRecordCollection::const_iterator HitsEnd(){return trackRecordCollection->end();};
private:
TrackRecordCollection *trackRecordCollection;
AthenaHitsCollectionHelper theHelper;
};
#endif
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TruthStrategy_H
#define TruthStrategy_H
#include "MCTruth/TruthStrategyManager.h"
#include "GaudiKernel/MsgStream.h" // So that all who inherit have full access
#include <string>
#include <map>
class G4Step;
class G4LogicalVolume;
class TruthStrategy {
public:
TruthStrategy(const std::string);
virtual ~TruthStrategy() { if (m_log) delete m_log; }
std::string StrategyName() {return strategyName;}
//std::string VolumeName() {return volumeName;}
//int VolumeLevel() {return volumeLevel;}
virtual bool IsApplicable(const G4Step*);
virtual bool AnalyzeVertex(const G4Step*) = 0;
bool Activate(const std::string, int);
void Disactivate() {MCActiveArea.clear();activated=false;}
bool IsActivated() {return activated;}
protected:
TruthStrategyManager *theTruthManager;
MsgStream * m_log;
MsgStream log();
private:
std::string strategyName;
std::map<std::string,int> MCActiveArea;//key=volumeName, val=volumeLevel
typedef std::map<std::string,int>::value_type valType;
bool activated;
bool m_init;
void checkVolumeDepth( G4LogicalVolume * lv , int d=0 );
};
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TruthStrategyManager_H
#define TruthStrategyManager_H
#include <string>
#include <map>
#include <vector>
#include "HepMC/GenEvent.h"
#include "GaudiKernel/MsgStream.h"
class TruthStrategy;
class G4Step;
class G4Track;
class G4StepPoint;
class EventInformation;
class MCTruthSteppingAction;
typedef std::map<std::string,TruthStrategy*, std::less<std::string> > strategyMap;
class TruthStrategyManager {
public:
static TruthStrategyManager* GetStrategyManager();
bool IsApplicable() {return !isEmpty;}
bool AnalyzeVertex(const G4Step*);
void RegisterStrategy(TruthStrategy *);
TruthStrategy * GetStrategy(std::string);
void ListStrategies(); // Non-const as logger may need to be grabbed
void SetNrOfSecondaries(int i) {nSecondaries=i;}
int GetNrOfSecondaries() {return nSecondaries;}
void SetSecondarySavingLevel(int i) {secondarySavingLevel=i;}
int GetSecondarySavingLevel() const {return secondarySavingLevel;}
void EnableRecordingEnvelopes();
void AddRecordingEnvelope(std::string,int,std::string sdName="");
void ListRecordingEnvelopes();
void SetTruthParameter(const std::string, double);
double GetTruthParameter(const std::string);
void PrintParameterList(); // Non-const as logger may need to be grabbed
EventInformation* GetEventInformation() const;
std::vector<G4Track*> GetSecondaries();
// here a couple of helper functions
HepMC::GenVertex* StepPoint2Vertex(G4StepPoint*) const;
HepMC::GenParticle* Track2Particle(G4Track*) const;
void SaveSecondaryVertex(G4Track*, G4StepPoint*, std::vector<G4Track*>) const;
private:
TruthStrategyManager();
TruthStrategyManager(const TruthStrategyManager&) : m_log(0) {}
~TruthStrategyManager() { if (m_log) delete m_log; }
static TruthStrategyManager *thePointer;
strategyMap theStrategies;
bool isEmpty;
int secondarySavingLevel;
// cache the nr. of secondaries produced in an interaction here, on
// request, to avoid too many tours in the G4 meanders...
int nSecondaries;
std::vector<G4Track*> theSecondaries;
// here go the parameters needed by all various strategies
std::map< std::string, double, std::less<std::string> > truthParams;
MCTruthSteppingAction *theSteppingAction;
MsgStream * m_log;
MsgStream log();
};
#endif
......@@ -20,18 +20,21 @@ namespace ISF {
class VTrackInformation: public G4VUserTrackInformation {
public:
VTrackInformation(TrackClassification tc=Primary);
const HepMC::GenParticle *GetPrimaryHepMCParticle() const;
void SetPrimaryHepMCParticle(const HepMC::GenParticle*);
virtual const HepMC::GenParticle *GetHepMCParticle() const;
virtual const ISF::ISFParticle *GetISFParticle() const;
virtual const ISF::ISFParticle *GetBaseISFParticle() const;
virtual bool GetReturnedToISF() const;
virtual int GetParticleBarcode() const =0;
virtual int GetParticleBarcode() const =0;
virtual void SetParticle(const HepMC::GenParticle*);
virtual void SetISFParticle(const ISF::ISFParticle*);
virtual void SetBaseISFParticle(const ISF::ISFParticle*);
virtual void SetReturnedToISF(bool) ;
virtual void Print() const {}
void SetClassification(TrackClassification tc) {classify=tc;}
TrackClassification GetClassification() {return classify;}
private:
TrackClassification classify;
const HepMC::GenParticle *thePrimaryParticle;
};
#endif
package MCTruth
version MCTruth-00-00-01
public
use AtlasPolicy AtlasPolicy-*
author ADA <dellacqu@mail.cern.ch>
branches src cmt
use AtlasPolicy AtlasPolicy-*
use AtlasHepMC AtlasHepMC-* External
use CLIDSvc CLIDSvc-* Control
use Geant4 Geant4-* External
use GaudiInterface GaudiInterface-* External
use FadsSensitiveDetector FadsSensitiveDetector-* Simulation/G4Sim/FADS
use TrackRecord TrackRecord-* Simulation/G4Sim
use SimHelpers SimHelpers-* Simulation/G4Sim
use AtlasHepMC AtlasHepMC-* External
use CLIDSvc CLIDSvc-* Control
use Geant4 Geant4-* External
private
use FadsActions FadsActions-* Simulation/G4Sim/FADS
use SimHelpers SimHelpers-* Simulation/G4Sim
end_private
include_dirs "$(MCTruth_root)"
......@@ -26,3 +16,7 @@ include_dirs "$(MCTruth_root)"
library MCTruth ../src/*.cxx
apply_pattern installed_library
#private
# use this to enable debugging for this package
#macro cppdebugflags '$(cppdebugflags_s)'
#macro_remove componentshr_linkopts "-Wl,-s"
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "MCTruth/AtlasTrajectory.h"
#include "MCTruth/TruthController.h"
#include "MCTruth/TruthStrategyManager.h"
#include "MCTruth/TrackHelper.h"
#include "SimHelpers/TrackVisualizationHelper.h"
#include "SimHelpers/SecondaryTracksHelper.h"
#include "G4TrackVector.hh"
#include "G4VVisManager.hh"
#include "G4Polyline.hh"
#include "G4Polymarker.hh"
#include "G4VisAttributes.hh"
#include "G4Colour.hh"
#include <iostream>
#include "FadsActions/FadsTrackingAction.h"
AtlasTrajectory::AtlasTrajectory() :G4Trajectory()
{
theTrackManager=FADS::FadsTrackingAction::GetTrackingAction()->
GetTrackingManager();
theSecondaryTrackHelper.SetTrackingManager(theTrackManager);
}
AtlasTrajectory::AtlasTrajectory(const G4Track* aTrack): G4Trajectory(aTrack)
{
theTrackManager=FADS::FadsTrackingAction::GetTrackingAction()->
GetTrackingManager();
theSecondaryTrackHelper.SetTrackingManager(theTrackManager);
}
void AtlasTrajectory::AppendStep(const G4Step* aStep)
{
int nsecs=theSecondaryTrackHelper.NrOfNewSecondaries();
if (nsecs)
{
// OK, there was an interation. look at the track, if it
// is not a secondary (i.e. we have a connected tree) we
// apply the MC truth machinery...
TrackHelper tHelper(aStep->GetTrack());
if (!tHelper.IsSecondary())
{
TruthStrategyManager *sManager=TruthStrategyManager::
GetStrategyManager();
if (sManager->IsApplicable())
{
sManager->SetNrOfSecondaries(nsecs);
sManager->AnalyzeVertex(aStep);
}
}
}
G4Trajectory::AppendStep(aStep);
}
#if G4VERSION_NUMBER < 1010
void AtlasTrajectory::DrawTrajectory(G4int i_mode=0) const
#else
void AtlasTrajectory::DrawTrajectory(G4int i_mode) const
#endif
{
// If i_mode>=0, draws a trajectory as a polyline (blue for
// positive, red for negative, green for neutral) and, if i_mode!=0,
// adds markers - yellow circles for step points and magenta squares
// for auxiliary points, if any - whose screen size in pixels is
// given by abs(i_mode)/1000. E.g: i_mode = 5000 gives easily
// visible markers.
G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
if (!pVVisManager) return;
const G4double markerSize = abs(i_mode)/1000;
G4bool lineRequired (i_mode >= 0);
G4bool markersRequired (markerSize > 0.);
G4Polyline trajectoryLine;
G4Polymarker stepPoints;
G4Polymarker auxiliaryPoints;
for (G4int i = 0; i < GetPointEntries() ; i++)
{
G4VTrajectoryPoint* aTrajectoryPoint = GetPoint(i);
const std::vector<G4ThreeVector>* auxiliaries
= aTrajectoryPoint->GetAuxiliaryPoints();
if (auxiliaries)
{
for (size_t iAux = 0; iAux < auxiliaries->size(); ++iAux)
{
const G4ThreeVector pos((*auxiliaries)[iAux]);
if (lineRequired)
{
trajectoryLine.push_back(pos);
}
if (markersRequired)
{
auxiliaryPoints.push_back(pos);
}
}
}
const G4ThreeVector pos(aTrajectoryPoint->GetPosition());
if (lineRequired)
{
trajectoryLine.push_back(pos);
}
if (markersRequired)
{
stepPoints.push_back(pos);
}
}
if (lineRequired)
{
int visScheme=TruthController::GetTruthController()->
GetVisualizationHelper()->TrackVisualizationScheme();
G4Colour colour;
const G4double charge = GetCharge();
if (visScheme==1)
{
// Geant3-like color code - neutrals are dashed
const G4String pname=GetParticleName();
if (pname=="e+" || pname=="e-") colour = G4Colour(1.,1.,0.);
else if (pname=="mu+" || pname=="mu-") colour = G4Colour(0.,1.,0.);
else if (pname=="gamma") colour = G4Colour(0.,0.,1.);
else if (pname=="neutron") colour = G4Colour(0.,0.,0.);
else if (charge) colour = G4Colour(1.,0.,0.);
}
else if (visScheme==2)
{
if(charge>0.) colour = G4Colour(0.,0.,1.); // Blue = positive.
else if(charge<0.) colour = G4Colour(1.,0.,0.); // Red = negative.
else colour = G4Colour(0.,1.,0.); // Green = neutral.
}
else if (visScheme==3)
{
const G4String pname=GetParticleName();
if (pname=="e+" || pname=="e-") colour = G4Colour(1.,1.,0.);
else if (pname=="mu+" || pname=="mu-") colour = G4Colour(0.,0.,1.);
else if (pname=="gamma") colour = G4Colour(60./256.,79./256.,113./256.);
else if (pname=="neutron") colour = G4Colour(1.,1.,1.);
else if (pname=="pi-"|| pname=="pi+") colour=G4Colour(250/256.,128/256.,114/256.);
else colour = G4Colour(176/256.,48/256.,96/256.);
}
G4VisAttributes trajectoryLineAttribs(colour);
if(visScheme==1 && charge==0)
{
G4VisAttributes::LineStyle style=G4VisAttributes::dotted;
trajectoryLineAttribs.SetLineStyle(style);
}
trajectoryLine.SetVisAttributes(&trajectoryLineAttribs);
pVVisManager->Draw(trajectoryLine);
}
if (markersRequired)
{
auxiliaryPoints.SetMarkerType(G4Polymarker::squares);
auxiliaryPoints.SetScreenSize(markerSize);
auxiliaryPoints.SetFillStyle(G4VMarker::filled);
G4VisAttributes auxiliaryPointsAttribs(G4Colour(0.,1.,1.)); // Magenta
auxiliaryPoints.SetVisAttributes(&auxiliaryPointsAttribs);
pVVisManager->Draw(auxiliaryPoints);
stepPoints.SetMarkerType(G4Polymarker::circles);
stepPoints.SetScreenSize(markerSize);
stepPoints.SetFillStyle(G4VMarker::filled);
G4VisAttributes stepPointsAttribs(G4Colour(1.,1.,0.)); // Yellow.
stepPoints.SetVisAttributes(&stepPointsAttribs);
pVVisManager->Draw(stepPoints);
}
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "MCTruth/CavernBGKiller.h"
#include "FadsSensitiveDetector/SensitiveDetectorEntryT.h"
#include "G4VSolid.hh"
#include "MCTruth/TrackHelper.h"
#include "G4Neutron.hh"
static FADS::SensitiveDetectorEntryT<CavernBGKiller> ttrksd("CavernBGKiller");
CavernBGKiller::CavernBGKiller(std::string name)
: FADS::FadsSensitiveDetector(name)
, trackRecordCollection(0)
{;}
CavernBGKiller::~CavernBGKiller()
{;}
void CavernBGKiller::Initialize(G4HCofThisEvent*)
{
trackRecordCollection = new TrackRecordCollection("CavernBG");
}
G4bool CavernBGKiller::ProcessHits(G4Step* aStep,G4TouchableHistory* )
{
// Only score neutrons
if (aStep->GetTrack()->GetDefinition()!=G4Neutron::Neutron() ) return false;
G4StepPoint *preStep=aStep->GetPreStepPoint();
G4StepPoint *postStep=aStep->GetPostStepPoint();
G4VPhysicalVolume *preVol=preStep?preStep->GetPhysicalVolume():0;
G4VPhysicalVolume *postVol=postStep?postStep->GetPhysicalVolume():0;
// Only if we're changing volumes
if (preVol == postVol) return false;
int volume=0;
// Dirty trick because G4 string comparisons were buggy...
static const G4String volNames[15] =
{ "MA::MA" , "MB::MB" , "MC::MC" ,
"ME1::ME1" , "ME2::ME2" , "FI1::FI1" , "FI2::FI2" ,
"FE1::FE1" , "FE2::FE2" , "FM1::FM1" , "FM2::FM2" ,
"FO1::FO1" , "FO2::FO2" , "CS1::CS1" , "CS2::CS2" };
if (postVol &&
postVol->GetName().length()==6 ){
if (postVol->GetName()==volNames[0] ) volume=110;
else if(postVol->GetName()==volNames[1] ) volume=120;
else if(postVol->GetName()==volNames[2] ) volume=130;
} else if (postVol &&
postVol->GetName().length()==8 ){
if (postVol->GetName()==volNames[3] ) volume=141;
else if(postVol->GetName()==volNames[4] ) volume=142;
else if(postVol->GetName()==volNames[5] ) volume=211;
else if(postVol->GetName()==volNames[6] ) volume=212;
else if(postVol->GetName()==volNames[7] ) volume=221;
else if(postVol->GetName()==volNames[8] ) volume=222;
else if(postVol->GetName()==volNames[9] ) volume=231;
else if(postVol->GetName()==volNames[10]) volume=232;
else if(postVol->GetName()==volNames[11]) volume=241;
else if(postVol->GetName()==volNames[12]) volume=242;
else if(postVol->GetName()==volNames[13]) volume=301;
else if(postVol->GetName()==volNames[14]) volume=302;
}
if (volume == 0) return false; // Require entering an interesting volume
int pdgcode = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
G4ThreeVector pos=postStep->GetPosition();
G4ThreeVector mom=postStep->GetMomentum();
double ener=postStep->GetTotalEnergy();
double time=postStep->GetGlobalTime();
TrackHelper trHelp(aStep->GetTrack());
int barcode = trHelp.GetBarcode();
//create the TimedTrackRecord
trackRecordCollection->Emplace(pdgcode,ener,mom,pos,time,barcode,preVol->GetName());
aStep->GetTrack()->SetTrackStatus(fStopAndKill); // Remove the neutron
return true;
}
void CavernBGKiller::EndOfEvent(G4HCofThisEvent* )
{
theHelper.ExportCollection<TrackRecordCollection>(trackRecordCollection);
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "MCTruth/CosmicTRSD.h"
#include "FadsSensitiveDetector/SensitiveDetectorEntryT.h"
#include "G4VSolid.hh"
#include "MCTruth/TrackHelper.h"
#include "TrackRecord/TrackRecordCollection.h"
#include "SimHelpers/AthenaHitsCollectionHelper.h"
static FADS::SensitiveDetectorEntryT<CosmicTRSD> ttrksd("CosmicTRSD");
CosmicTRSD::CosmicTRSD(std::string name): FADS::FadsSensitiveDetector(name),trackRecordCollection(0)
{
}
CosmicTRSD::~CosmicTRSD()
{
}
void CosmicTRSD::Initialize(G4HCofThisEvent*)
{
trackRecordCollection = new TrackRecordCollection(GetName());
}
G4bool CosmicTRSD::ProcessHits(G4Step* aStep,G4TouchableHistory* )
{
G4StepPoint *preStep=aStep->GetPreStepPoint();
G4StepPoint *postStep=aStep->GetPostStepPoint();
G4VPhysicalVolume *preVol=preStep->GetPhysicalVolume();
G4VPhysicalVolume *postVol=postStep->GetPhysicalVolume();
G4TouchableHistory* touchHist = (G4TouchableHistory*)preStep->GetTouchable();
if (preVol==postVol) return false;
int pdgcode = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
std::string pname = aStep->GetTrack()->GetDefinition()->GetParticleName();
G4ThreeVector pos=postStep->GetPosition();
G4ThreeVector mom=postStep->GetMomentum();
// need to get the local position
const G4AffineTransform trans = aStep->GetTrack()->GetTouchable()->GetHistory()->GetTopTransform(); // trans from global to local
G4ThreeVector localPos=trans.TransformPoint(pos);
G4ThreeVector localMom=mom;
trans.ApplyAxisTransform(localMom); // rotate momentum as needed
G4VSolid* shape= touchHist->GetSolid();
G4ThreeVector normal=shape->SurfaceNormal(localPos);
// check if particle is entering. if it is extiting don't record it.
if(normal.dot(localPos)>=0.) return false;
//double ener=aStep->GetTrack()->GetKineticEnergy();
double ener=postStep->GetTotalEnergy();
double time=postStep->GetGlobalTime();
//create the TimedTrackRecord
if(pname=="geantino") pdgcode=999;
TrackHelper trHelp(aStep->GetTrack());
int barcode = trHelp.GetBarcode();
trackRecordCollection->Emplace(pdgcode,ener,localMom,localPos,time,barcode,preVol->GetName());
return true;
}
void CosmicTRSD::EndOfEvent(G4HCofThisEvent* )
{
theHelper.ExportCollection<TrackRecordCollection>(trackRecordCollection);
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "MCTruth/MCTruthSteppingAction.h"
#include "MCTruth/TrackHelper.h"
#include "MCTruth/TrackRecorderSD.h"
#include "FadsActions/FadsSteppingAction.h"
#include "FadsSensitiveDetector/SensitiveDetectorCatalog.h"
#include "FadsSensitiveDetector/SensitiveDetectorEntry.h"
#include "FadsSensitiveDetector/SensitiveDetectorEntryT.h"
#include <iostream>
#include "G4Step.hh"
#include "G4StepPoint.hh"
#include "G4TouchableHistory.hh"
#include "G4SDManager.hh"
#include <map>
using namespace FADS;
MCTruthSteppingAction::MCTruthSteppingAction():G4UserSteppingAction(),sde(0)
{
FADS::FadsSteppingAction::GetSteppingAction()->SetMCTSteppingAction(this);
}
MCTruthSteppingAction::MCTruthSteppingAction(const MCTruthSteppingAction&):G4UserSteppingAction(),sde(0)
{
}
void MCTruthSteppingAction::AddRecordingEnvelope(std::string name, int lev,
std::string sdName)
{
if (sdName.empty()) sdName=name;
vm[name]=lev;
FADS::SensitiveDetectorEntryT<TrackRecorderSD> ii(sdName);
ii.Construct(sdName);
G4SDManager *SDM=G4SDManager::GetSDMpointer();
G4VSensitiveDetector *sd=SDM->FindSensitiveDetector(sdName);
sdm[name]=sd;
}
void MCTruthSteppingAction::ListRecordingEnvelopes()
{
volMapIterator it;
for (it=vm.begin();it!=vm.end();it++)
std::cout << " Recording Envelope -> "<<(*it).second<<std::endl;
}
void MCTruthSteppingAction::UserSteppingAction(const G4Step* aStep)
{
if (vm.size() == 0) return;
TrackHelper tHelp(aStep->GetTrack());
if (tHelp.IsSecondary()) return;
G4StepPoint *preStep=aStep->GetPreStepPoint();
G4StepPoint *postStep=aStep->GetPostStepPoint();
G4VPhysicalVolume *preVol=preStep->GetPhysicalVolume();
G4VPhysicalVolume *postVol=postStep->GetPhysicalVolume();
if (preVol==postVol) return;
G4TouchableHistory *preTHist=(G4TouchableHistory *)preStep->GetTouchable();
G4TouchableHistory *postTHist=(G4TouchableHistory *)postStep->GetTouchable();
int nLev1=preTHist->GetHistoryDepth();
int nLev2=postTHist->GetHistoryDepth();
std::string vname1;
volMapIterator it;
for (it=vm.begin();it!=vm.end();it++)
{
int il=(*it).second;
if (il<=(nLev1+1))
{
vname1=preTHist->GetVolume(nLev1-il+1)->GetName();
if (vname1!=(*it).first) continue;
if (il<=(nLev2+1))
{
if (vname1==postTHist->GetVolume(nLev2-il+1)->GetName()) continue;
}
G4Step *vStep=const_cast<G4Step *>(aStep);
sdm[vname1]->Hit(vStep);
break;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment