[286] | 1 | #include "ELYSE/TrackingAction.hh" |
---|
| 2 | |
---|
| 3 | //Geant4 |
---|
| 4 | #include "G4ParticleTable.hh" |
---|
| 5 | #include "G4ParticleTypes.hh" |
---|
| 6 | #include "G4TrackingManager.hh" |
---|
| 7 | #include "G4Track.hh" |
---|
| 8 | #include "G4ios.hh" |
---|
| 9 | #include "G4VProcess.hh" |
---|
| 10 | |
---|
| 11 | //ELYSE |
---|
| 12 | #include "ELYSE/Trajectory.hh" |
---|
| 13 | #include "ELYSE/TrackInformation.hh" |
---|
| 14 | #include "ELYSE/TrackingActionMessenger.hh" |
---|
| 15 | |
---|
| 16 | ELYSE::TrackingAction::TrackingAction() { |
---|
| 17 | ProcessList.insert("eIoni") ; |
---|
| 18 | |
---|
| 19 | G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); |
---|
| 20 | ParticleList.insert(particleTable->FindParticle("e-")->GetPDGEncoding()); |
---|
| 21 | ParticleList.insert(particleTable->FindParticle("e+")->GetPDGEncoding()); |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | // don't put gammas there or there'll be too many |
---|
| 25 | |
---|
| 26 | messenger = new TrackingActionMessenger(this); |
---|
| 27 | |
---|
| 28 | }//Ctor |
---|
| 29 | |
---|
| 30 | //-------------------------------------------------------------------------------------------------- |
---|
| 31 | |
---|
| 32 | ELYSE::TrackingAction::~TrackingAction(){ |
---|
| 33 | //JEC 24/1/06 |
---|
| 34 | delete messenger; |
---|
| 35 | messenger = 0; |
---|
| 36 | }//Dtor |
---|
| 37 | |
---|
| 38 | //--------------------------------------------------------------------------------------------------- |
---|
| 39 | |
---|
| 40 | void ELYSE::TrackingAction::PreUserTrackingAction(const G4Track* aTrack) { |
---|
| 41 | |
---|
| 42 | G4ParticleDefinition* particleType = aTrack->GetDefinition(); |
---|
| 43 | G4String particleName = particleType->GetParticleName(); |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | fpTrackingManager->SetStoreTrajectory(false); //Track default: no custom or G4Trajectories |
---|
| 47 | |
---|
| 48 | //-----------optical photon: store trajectory objects |
---|
| 49 | |
---|
[294] | 50 | // G4cout << "(JEC) PreUserTrackingAction (" << particleName |
---|
| 51 | // << ") and DrawOptical = " << drawOpticalPhoton |
---|
| 52 | // << G4endl; |
---|
[286] | 53 | |
---|
| 54 | if(!drawOpticalPhoton && (particleName == "opticalphoton") )return; |
---|
| 55 | |
---|
| 56 | if(drawOpticalPhoton && (particleName == "opticalphoton") ){ |
---|
| 57 | |
---|
[294] | 58 | // G4cout << "(JEC) PreUserTrackingAction: Optical--ParentID : " << aTrack->GetParentID() |
---|
| 59 | // << G4endl; |
---|
[286] | 60 | |
---|
| 61 | |
---|
| 62 | Trajectory* aTrajectory = new Trajectory(aTrack); |
---|
| 63 | fpTrackingManager->SetTrajectory(aTrajectory); |
---|
| 64 | fpTrackingManager->SetStoreTrajectory(true); //(JEC) 14/12/05 keep it and delete it a posteriori |
---|
| 65 | // only if it has not produced a hit |
---|
| 66 | |
---|
| 67 | TrackInformation* aInfo = new TrackInformation(aTrack); |
---|
| 68 | fpTrackingManager->SetUserTrackInformation(aInfo); |
---|
| 69 | |
---|
| 70 | return; |
---|
| 71 | |
---|
| 72 | }//eo optical photon |
---|
| 73 | |
---|
| 74 | //-----------other particle: store trajectory objects |
---|
| 75 | |
---|
| 76 | // A priori some tracks are worth to be saved |
---|
| 77 | // is it a primary ? |
---|
| 78 | // is the process in the set ? |
---|
| 79 | // is the particle in the set ? |
---|
| 80 | // is it a gamma with enough energy |
---|
| 81 | // due to lazy evaluation of the 'or' in C++ the order is important |
---|
| 82 | |
---|
| 83 | const G4VProcess* creatorProcess = aTrack->GetCreatorProcess(); |
---|
| 84 | G4double thresholdTobeSaved = 0.*keV; //JEC FIXME put in the messenger |
---|
| 85 | |
---|
[294] | 86 | // G4cout << "(JEC) PreUserTrackingAction (" << particleName |
---|
| 87 | // << " ParentID " << aTrack->GetParentID(); |
---|
| 88 | // if (creatorProcess!=0) G4cout << ") and Process Name " << creatorProcess->GetProcessName(); |
---|
| 89 | // G4cout << G4endl; |
---|
[286] | 90 | |
---|
| 91 | |
---|
| 92 | //JEC 20/2/06 debug: keep all particle for the moment |
---|
| 93 | // if( ( aTrack->GetParentID() == 0 ) || |
---|
| 94 | // ( (creatorProcess!=0) && ProcessList.count(creatorProcess->GetProcessName()) ) || |
---|
| 95 | // ( ParticleList.count(particleType->GetPDGEncoding()) ) || |
---|
| 96 | // ( (particleType->GetPDGEncoding() == 22) && (aTrack->GetTotalEnergy() > thresholdTobeSaved) ) ) { |
---|
| 97 | |
---|
| 98 | //G4cout <<"Pre Tracking::particle = " << particleName |
---|
| 99 | // << " " << aTrack << G4endl; |
---|
| 100 | |
---|
| 101 | Trajectory* aTrajectory = new Trajectory(aTrack); |
---|
| 102 | fpTrackingManager->SetTrajectory(aTrajectory); |
---|
| 103 | fpTrackingManager->SetStoreTrajectory(true); |
---|
| 104 | return; |
---|
| 105 | |
---|
| 106 | // }//eo particles |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | }//PreUserTrackingAction |
---|
| 111 | |
---|
| 112 | //--------------------------------------------------------------------------------------------------- |
---|
| 113 | |
---|
| 114 | void ELYSE::TrackingAction::PostUserTrackingAction(const G4Track* aTrack) { |
---|
| 115 | |
---|
| 116 | //-----------Check StoreTrajectory for particle : true or false? |
---|
| 117 | |
---|
| 118 | G4bool storetrajectory = fpTrackingManager->GetStoreTrajectory(); |
---|
| 119 | if(!storetrajectory)return; |
---|
| 120 | |
---|
| 121 | G4ParticleDefinition* particleType = aTrack->GetDefinition(); |
---|
| 122 | G4String particleName = particleType->GetParticleName(); |
---|
| 123 | |
---|
| 124 | //-----------opticalphoton |
---|
| 125 | //---------------do not store it if it is not detected by the Tyvek |
---|
| 126 | |
---|
| 127 | if ( particleName == "opticalphoton" ) { |
---|
| 128 | |
---|
| 129 | TrackInformation* aInfo = (TrackInformation*)(aTrack->GetUserInformation()); |
---|
| 130 | |
---|
| 131 | //G4cout <<"PostTracking::opticalphoton = " |
---|
| 132 | // << particleName << " " << aTrack << " " << aInfo << G4endl; |
---|
| 133 | |
---|
| 134 | //------------- produced or not a hit: if not remove and return |
---|
| 135 | |
---|
| 136 | if ( !(aInfo->GetTrackStatus() & hitProduced) ) { |
---|
| 137 | //JEC temporary fpTrackingManager->SetStoreTrajectory(false); |
---|
| 138 | return; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | }//eo optical photon |
---|
| 142 | |
---|
| 143 | //-----------Get the trajectory from TrackingManager |
---|
| 144 | //---------------and fill in |
---|
| 145 | |
---|
| 146 | //G4cout <<"PostTracking::particles = " |
---|
| 147 | // << particleName << " " << aTrack << G4endl; |
---|
| 148 | |
---|
| 149 | Trajectory *currentTrajectory = (Trajectory*)fpTrackingManager->GimmeTrajectory(); |
---|
| 150 | |
---|
| 151 | G4ThreeVector currentPosition = aTrack->GetPosition(); |
---|
| 152 | G4VPhysicalVolume* currentVolume = aTrack->GetVolume(); |
---|
| 153 | |
---|
| 154 | currentTrajectory->SetStoppingPoint(currentPosition); |
---|
| 155 | currentTrajectory->SetStoppingVolume(currentVolume); |
---|
| 156 | currentTrajectory->SetSaveFlag(true); //For saving into Tuple (see EventAction) |
---|
| 157 | |
---|
| 158 | //JEC to be fixed the above flag should not be needed now |
---|
| 159 | |
---|
| 160 | }//PostUserTrackingAction |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | |
---|