WCSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WCSimTrackingAction.cc
Go to the documentation of this file.
1 #include "WCSimTrackingAction.hh"
2 #include "WCSimTrajectory.hh"
3 #include "G4ParticleTypes.hh"
4 #include "G4TrackingManager.hh"
5 #include "G4Track.hh"
6 #include "G4ios.hh"
7 #include "G4VProcess.hh"
9 
10 #include "G4PhysicalConstants.hh"
11 #include "G4SystemOfUnits.hh"
12 
14 {
15  ProcessList.insert("Decay") ;
16  //ProcessList.insert("MuonMinusCaptureAtRest") ;
17 // ProcessList.insert("conv");
18  ParticleList.insert(111); // pi0
19  ParticleList.insert(211); // pion+
20  ParticleList.insert(-211);
21  ParticleList.insert(321);
22  ParticleList.insert(-321); // kaon-
23  ParticleList.insert(311); // kaon0
24  ParticleList.insert(-311); // kaon0 bar
25 
26  ParticleList.insert(11);
27  ParticleList.insert(-11);
28  ParticleList.insert(12);
29  ParticleList.insert(-12);
30  // don't put gammas there or there'll be too many
31 
32 
33  // Max time for radioactive decay:
34  fMaxTime = 1. * second;
35  fTime_birth = 0.;
36 }
37 
39 
40 void WCSimTrackingAction::PreUserTrackingAction(const G4Track* aTrack)
41 {
42  G4double percentageOfCherenkovPhotonsToDraw = 0.0;
43 
44  if ( aTrack->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition()
45  || G4UniformRand() < percentageOfCherenkovPhotonsToDraw )
46  {
47  WCSimTrajectory* thisTrajectory = new WCSimTrajectory(aTrack);
48  fpTrackingManager->SetTrajectory(thisTrajectory);
49  fpTrackingManager->SetStoreTrajectory(true);
50  }
51  else
52  fpTrackingManager->SetStoreTrajectory(false);
53 
54  G4ParticleDefinition* particle = aTrack->GetDefinition();
55  G4String name = particle->GetParticleName();
56  G4double fCharge = particle->GetPDGCharge();
57 
58  G4Track* tr = (G4Track*) aTrack;
59  if ( aTrack->GetTrackID() == 1 ) {
60  // Re-initialize time
61  fTime_birth = 0;
62  // Ask G4 to kill the track when all secondary are done (will exclude other decays)
63  if ( fCharge > 2. )
64  tr->SetTrackStatus(fStopButAlive);
65  }
66 
67  if ( aTrack->GetTrackID() == 2 ) {
68  // First track of the decay save time
69  fTime_birth = aTrack->GetGlobalTime();
70  }
71 }
72 
74 {
75  // added by M Fechner
76  const G4VProcess* creatorProcess = aTrack->GetCreatorProcess();
77  // if ( creatorProcess )
78  // G4cout << "process name " << creatorProcess->GetProcessName() << G4endl;
79 
80 
81  WCSimTrackInformation* anInfo;
82  if (aTrack->GetUserInformation())
83  anInfo = (WCSimTrackInformation*)(aTrack->GetUserInformation());
84  else anInfo = new WCSimTrackInformation();
85 
86  // is it a primary ?
87  // is the process in the set ?
88  // is the particle in the set ?
89  // is it a gamma
90  // due to lazy evaluation of the 'or' in C++ the order is important
91  if( aTrack->GetParentID()==0 ||
92  ((creatorProcess!=0) && ProcessList.count(creatorProcess->GetProcessName()) ) ||
93  (ParticleList.count(aTrack->GetDefinition()->GetPDGEncoding()) )
94  || (aTrack->GetDefinition()->GetPDGEncoding()==22 && aTrack->GetTotalEnergy() > 50.0*MeV)
95  )
96  {
97  // if so the track is worth saving
98  anInfo->WillBeSaved(true);
99 
100  // G4cout << "track # " << aTrack->GetTrackID() << " is worth saving\n";
101  // G4cout << "It is a " <<aTrack->GetDefinition()->GetParticleName() << G4endl;
102  }
103  else
104  anInfo->WillBeSaved(false);
105 
106  if (aTrack->GetDefinition()->GetPDGEncoding()==111)
107  pi0List.insert(aTrack->GetTrackID()); // list of all pi0-s
108 
109  if (aTrack->GetParentID()==0 || // primary particle
110  (aTrack->GetDefinition()->GetPDGEncoding()==22 && // primary gamma from
111  pi0List.count(aTrack->GetParentID()))) // a pi0
112  anInfo->SetPrimaryParentID(aTrack->GetTrackID());
113 
114  G4Track* theTrack = (G4Track*)aTrack;
115  theTrack->SetUserInformation(anInfo);
116 
117  // pass primary parent ID to children
118  G4TrackVector* secondaries = fpTrackingManager->GimmeSecondaries();
119  if(secondaries)
120  {
121  size_t nSeco = secondaries->size();
122  if(nSeco>0)
123  {
124  for(size_t i=0;i<nSeco;i++)
125  {
126  WCSimTrackInformation* infoSec = new WCSimTrackInformation(anInfo);
127  infoSec->WillBeSaved(false); // ADDED BY MFECHNER, temporary, 30/8/06
128  (*secondaries)[i]->SetUserInformation(infoSec);
129  }
130  }
131  }
132 
133  if ( aTrack->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition() )
134  // if (aTrack->GetDefinition()->GetPDGCharge() == 0)
135  {
136  WCSimTrajectory *currentTrajectory =
137  (WCSimTrajectory*)fpTrackingManager->GimmeTrajectory();
138 
139  G4ThreeVector currentPosition = aTrack->GetPosition();
140  G4VPhysicalVolume* currentVolume = aTrack->GetVolume();
141 
142  currentTrajectory->SetStoppingPoint(currentPosition);
143  currentTrajectory->SetStoppingVolume(currentVolume);
144 
145  if (anInfo->isSaved())
146  currentTrajectory->SetSaveFlag(true);// mark it for WCSimEventAction ;
147  else currentTrajectory->SetSaveFlag(false);// mark it for WCSimEventAction ;
148  }
149 
150 }
151 
152 
153 
154 
155 
dictionary particle
Definition: MakeKin.py:97
void PreUserTrackingAction(const G4Track *aTrack)
std::set< G4int > pi0List
void SetStoppingVolume(G4VPhysicalVolume *currentVolume)
std::set< G4int > ParticleList
void WillBeSaved(G4bool choice)
void SetStoppingPoint(G4ThreeVector &currentPosition)
void SetSaveFlag(G4bool value)
void PostUserTrackingAction(const G4Track *)
std::set< G4String > ProcessList