Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // 27 /// \file XrayTESdetSteppingAction.cc 28 /// \brief Implementation of the SteppingAction class 29 // 30 // Authors: P.Dondero (paolo.dondero@cern.ch), R.Stanzani (ronny.stanzani@cern.ch) 31 // 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 34 35 36 #include "XrayTESdetSteppingAction.hh" 37 #include "G4AnalysisManager.hh" 38 39 #include "G4SteppingManager.hh" 40 #include "G4RunManager.hh" 41 #include "G4SystemOfUnits.hh" 42 #include "G4PhysicalConstants.hh" 43 44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 45 46 G4String clean_name (const G4String& vol_name) 47 { 48 G4String cleaned_name = ""; 49 50 // Search if the vol_name contains one of the following part 51 if (((std::string)vol_name).find("Bipxl") != std::string::npos) 52 cleaned_name = "Bipxl"; 53 if (((std::string)vol_name).find("membrane") != std::string::npos) 54 cleaned_name = "membrane"; 55 if (((std::string)vol_name).find("gridpiece") != std::string::npos) 56 cleaned_name = "gridpiece"; 57 if (((std::string)vol_name).find("trapezoid") != std::string::npos) 58 cleaned_name = "Mesh"; 59 if (cleaned_name == "") cleaned_name = vol_name; 60 return cleaned_name; 61 } 62 63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 64 65 void XrayTESdetSteppingAction::UserSteppingAction(const G4Step* step) 66 { 67 // Define quantities to use in the 68 G4RunManager *rm = G4RunManager::GetRunManager(); 69 auto analysisManager = G4AnalysisManager::Instance(); 70 71 G4int eventID = rm->GetCurrentEvent()->GetEventID(); 72 G4Track* track = step->GetTrack(); 73 G4StepPoint* pre_step_point = step->GetPreStepPoint(); 74 G4int parentID = track->GetParentID(); 75 G4int trackID = track->GetTrackID(); 76 const G4String& vol_name = track->GetVolume()->GetName(); 77 G4String mother_name = ""; 78 G4double init_kinetic_energy = 0; 79 G4double kinetic_energy = track->GetKineticEnergy(); 80 G4double pre_kinetic_energy = pre_step_point->GetKineticEnergy(); 81 const G4String& particle_name = track->GetParticleDefinition()->GetParticleName(); 82 const G4VProcess* pre_step_proc = pre_step_point->GetProcessDefinedStep(); 83 const G4VProcess* post_step_proc = pre_step_point->GetProcessDefinedStep(); 84 85 bool proceed = false; 86 G4String pre_step_name_s = "Undefined"; 87 G4String post_step_name_s = "Undefined"; 88 G4String creator_process_name = "Undefined"; 89 G4String init_creator_process = "Undefined"; 90 const G4String& pre_step_name = pre_step_name_s; 91 const G4String& post_step_name = post_step_name_s; 92 93 if (track->GetCreatorProcess() != nullptr) 94 { 95 creator_process_name = track->GetCreatorProcess()->GetProcessName(); 96 } 97 98 if (pre_step_proc != nullptr) 99 { 100 pre_step_name_s = pre_step_proc->GetProcessName(); 101 } 102 103 if (post_step_proc != nullptr) 104 { 105 post_step_name_s = post_step_proc->GetProcessName(); 106 } 107 108 // Saves the first energy of the secondaries 109 if (eventID != fPrev_eventID) 110 { 111 fInit_energy.clear(); 112 fCreator_proc.clear(); 113 } 114 115 G4int current_step_number = -1; 116 current_step_number = track->GetCurrentStepNumber(); 117 if (current_step_number != -1) 118 { 119 if (current_step_number == 1 && parentID == 0) 120 { 121 proceed = true; 122 fInit_energy.insert(std::pair<G4int, G4double>(trackID, pre_kinetic_energy)); 123 fCreator_proc.insert(std::pair<G4int, G4String>(trackID, creator_process_name)); 124 pre_step_name_s = "InitStep"; 125 } 126 } 127 128 // Fill the map for the secondaries 129 if (trackID > 1) 130 { 131 // First value for each trackIDs; this serves to keep it untile the eventID changes. 132 if (fInit_energy.count((int)trackID) == 0) 133 { 134 fInit_energy.insert(std::pair<G4int, G4double>(trackID, pre_kinetic_energy)); 135 fCreator_proc.insert(std::pair<G4int, G4String>(trackID, creator_process_name)); 136 } 137 } 138 139 // Exclude the world volume, which has no mother volume 140 if (((std::string)vol_name).find("expHall") == std::string::npos) 141 { 142 if (track->GetVolume() != nullptr) 143 { 144 if (track->GetVolume()->GetMotherLogical() != nullptr) 145 { 146 mother_name = track->GetVolume()->GetMotherLogical()->GetName(); 147 } 148 } 149 if (((std::string)mother_name).find("Detector_log") != std::string::npos || ((std::string)mother_name).find("element_log") != std::string::npos) 150 { 151 proceed = true; 152 } 153 } 154 155 init_kinetic_energy = fInit_energy[(int)trackID]; 156 init_creator_process = fCreator_proc[trackID]; 157 158 G4String cleaned_name = ""; 159 cleaned_name = clean_name(vol_name); 160 161 // Saves on tuple 162 if (proceed) 163 { 164 G4double x = pre_step_point->GetPosition().x(); 165 G4double y = pre_step_point->GetPosition().y(); 166 G4double z = pre_step_point->GetPosition().z(); 167 G4ThreeVector direction = pre_step_point->GetMomentum(); 168 G4double theta = direction.theta(); 169 G4double phi = direction.phi(); 170 G4int pixel_number = track->GetVolume()->GetCopyNo(); 171 G4int def_replica_number = -999; // default value, to be discarded during the analysis 172 G4int step_number = track->GetCurrentStepNumber(); 173 G4double step_energy_dep = step->GetTotalEnergyDeposit(); 174 175 // Fill tuple 176 analysisManager->FillNtupleIColumn(0, eventID); 177 analysisManager->FillNtupleSColumn(1, cleaned_name); 178 analysisManager->FillNtupleIColumn(2, trackID); 179 analysisManager->FillNtupleDColumn(3, x); 180 analysisManager->FillNtupleDColumn(4, y); 181 analysisManager->FillNtupleDColumn(5, z); 182 analysisManager->FillNtupleDColumn(6, theta); 183 analysisManager->FillNtupleDColumn(7, phi); 184 analysisManager->FillNtupleIColumn(8, parentID); 185 if (((std::string)vol_name).find("Bipxl") != std::string::npos) 186 { 187 analysisManager->FillNtupleIColumn(9, pixel_number); 188 } 189 else 190 { 191 analysisManager->FillNtupleIColumn(9, def_replica_number); 192 } 193 analysisManager->FillNtupleDColumn(10, step_energy_dep); 194 analysisManager->FillNtupleIColumn(11, step_number); 195 analysisManager->FillNtupleDColumn(12, init_kinetic_energy); 196 analysisManager->FillNtupleDColumn(13, kinetic_energy); 197 analysisManager->FillNtupleSColumn(14, particle_name); 198 analysisManager->FillNtupleSColumn(15, pre_step_name); 199 analysisManager->FillNtupleSColumn(16, post_step_name); 200 analysisManager->FillNtupleSColumn(17, init_creator_process); 201 analysisManager->AddNtupleRow(0); 202 } 203 fPrev_eventID = eventID; 204 fPrev_trackID = trackID; 205 } 206 207 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 208