00001
00002
00003
00004 static const char* MyStackingAction_cc =
00005 "@(#) $Id: MyStackingAction.cc 80 2007-12-09 10:01:09Z comet $";
00006
00007 #include "MyStackingAction.hh"
00008 #include "MyStackingActionMessenger.hh"
00009 #include "McTruthSvc.hh"
00010
00011 #include "G4UserStackingAction.hh"
00012 #include "G4ParticleDefinition.hh"
00013 #include "G4ParticleTable.hh"
00014 #include "G4Track.hh"
00015 #include "G4ios.hh"
00016 #include "G4VProcess.hh"
00017
00018 MyStackingAction::MyStackingAction()
00019 : fTrackIDMap(NULL), fEleCut(0), fPosCut(0), fGamCut(0) {
00020 fStackingActionMessenger = new MyStackingActionMessenger(this);
00021 m_white_list.clear();
00022 m_black_list.clear();
00023 m_no_sec=false;
00024 m_no_MC=false;
00025 m_no_PC=false;
00026 }
00027
00028
00029 MyStackingAction::~MyStackingAction() {
00030 delete fTrackIDMap;
00031 }
00032
00033
00034 G4ClassificationOfNewTrack
00035 MyStackingAction::ClassifyNewTrack(const G4Track* aTrack) {
00036 G4ParticleDefinition* aPart = aTrack->GetDefinition();
00037 G4int aPDGEncoding = aPart->GetPDGEncoding();
00038 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
00039
00040
00041
00042
00043 G4int aTrackID = aTrack->GetTrackID();
00044 G4int aParentTrackID = aTrack->GetParentID();
00045 if ( (fTrackIDMap->find(aTrackID)) == fTrackIDMap->end() ) {
00046 fTrackIDMap->insert( TTrackIDMapValue(aTrackID, aParentTrackID));
00047 }
00048
00049
00050
00051
00052 G4ClassificationOfNewTrack aClassification = fWaiting;
00053
00054 if ( aPDGEncoding ==
00055 particleTable->FindParticle("e-")->GetPDGEncoding() ) {
00056 if ( aTrack->GetTotalEnergy() >= fEleCut ) {
00057 aClassification = fUrgent;
00058 }
00059 else {
00060 aClassification = fKill;
00061 }
00062
00063 } else if ( aPDGEncoding ==
00064 particleTable->FindParticle("e+")->GetPDGEncoding() ) {
00065 if ( aTrack->GetTotalEnergy() >= fPosCut ) {
00066 aClassification = fUrgent;
00067 }
00068 else {
00069 aClassification = fKill;
00070 }
00071 } else if ( aPDGEncoding ==
00072 particleTable->FindParticle("gamma")->GetPDGEncoding() ) {
00073 if ( aTrack->GetTotalEnergy() >= fGamCut ) {
00074 aClassification = fUrgent;
00075 }
00076 else {
00077 aClassification = fKill;
00078 }
00079
00080 }
00081
00082 if (m_no_MC||m_no_PC||m_no_sec){
00083 G4String processName;
00084 const G4VProcess* process = aTrack->GetCreatorProcess();
00085 if (process) {
00086 processName = process->GetProcessName();
00087 }
00088 else{
00089 processName = "NULL";
00090 }
00091 if (processName=="muMinusCaptureAtRest"&&m_no_MC){
00092 aClassification = fKill;
00093 McTruthSvc::GetMcTruthSvc()->SetValuePre(aTrack);
00094 }
00095 if (processName=="hBertiniCaptureAtRest"&&m_no_PC){
00096 aClassification = fKill;
00097 McTruthSvc::GetMcTruthSvc()->SetValuePre(aTrack);
00098 }
00099 if (processName!="NULL"&&m_no_sec){
00100 aClassification = fKill;
00101 McTruthSvc::GetMcTruthSvc()->SetValuePre(aTrack);
00102 }
00103 }
00104
00105 if (aTrackID!=1){
00106 bool foundit=false;
00107 if (m_white_list.size()!=0){
00108 foundit=false;
00109 for (int i = 0; i< m_white_list.size(); i++){
00110 if (aPDGEncoding==m_white_list[i]){
00111 foundit=true;
00112 break;
00113 }
00114 }
00115 if (!foundit){
00116 aClassification = fKill;
00117 }
00118 }
00119 foundit=false;
00120 for (int i = 0; i< m_black_list.size(); i++){
00121 if (aPDGEncoding==m_black_list[i]){
00122 foundit=true;
00123 break;
00124 }
00125 }
00126 if (foundit){
00127 aClassification = fKill;
00128 }
00129 }
00130
00131 return aClassification;
00132 }
00133
00134
00135 void MyStackingAction::NewStage()
00136 {;}
00137
00138 void MyStackingAction::PrepareNewEvent() {
00139 delete fTrackIDMap;
00140 fTrackIDMap = new TTrackIDMap;
00141 }
00142
00143
00144 G4int MyStackingAction::GetDepthFromParent(G4int aTrackID, G4int aParentID) {
00145 G4int trackID = aTrackID;
00146 G4int depth = 0;
00147 G4bool found = false;
00148
00149 if ( aParentID <= 0 || aTrackID <= 0 ) {
00150 return -1;
00151 }
00152 else if ( aTrackID == aParentID ) {
00153 return 0;
00154 }
00155 else {
00156 depth = 1;
00157 while ( trackID != 0 ) {
00158
00159
00160
00161 if ( (*(fTrackIDMap->find(trackID))).second == aParentID ) {
00162 found = true;
00163 break;
00164 }
00165 trackID = (*(fTrackIDMap->find(trackID))).second;
00166 ++depth;
00167 }
00168 if ( found ) {
00169 return depth;
00170 }
00171 else {
00172 return -1;
00173 }
00174 }
00175
00176 return found;
00177 }