[1199] | 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 | // $Id: XrayFluoEventAction.cc |
---|
| 28 | // GEANT4 tag $Name: xray_fluo-V03-02-00 |
---|
| 29 | // |
---|
| 30 | // Author: Elena Guardincerri (Elena.Guardincerri@ge.infn.it) |
---|
| 31 | // |
---|
| 32 | // History: |
---|
| 33 | // ----------- |
---|
| 34 | // 28 Nov 2001 Elena Guardincerri Created |
---|
| 35 | // |
---|
| 36 | // ------------------------------------------------------------------- |
---|
| 37 | |
---|
| 38 | #include "XrayFluoEventAction.hh" |
---|
| 39 | #include "XrayFluoSensorHit.hh" |
---|
| 40 | #include "XrayFluoEventActionMessenger.hh" |
---|
| 41 | #include "XrayFluoRunAction.hh" |
---|
| 42 | #include "XrayFluoDataSet.hh" |
---|
| 43 | #ifdef G4ANALYSIS_USE |
---|
| 44 | #include "XrayFluoAnalysisManager.hh" |
---|
| 45 | #endif |
---|
| 46 | |
---|
| 47 | #include "G4Event.hh" |
---|
| 48 | #include "G4EventManager.hh" |
---|
| 49 | #include "G4HCofThisEvent.hh" |
---|
| 50 | #include "G4VHitsCollection.hh" |
---|
| 51 | #include "G4TrajectoryContainer.hh" |
---|
| 52 | #include "G4Trajectory.hh" |
---|
| 53 | #include "G4VVisManager.hh" |
---|
| 54 | #include "G4SDManager.hh" |
---|
| 55 | #include "G4UImanager.hh" |
---|
| 56 | #include "G4ios.hh" |
---|
| 57 | #include "G4UnitsTable.hh" |
---|
| 58 | #include "Randomize.hh" |
---|
| 59 | |
---|
| 60 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 61 | |
---|
| 62 | XrayFluoEventAction::XrayFluoEventAction() |
---|
| 63 | :drawFlag("all"), |
---|
| 64 | HPGeCollID(-1), |
---|
| 65 | eventMessenger(0), |
---|
| 66 | printModulo(1) |
---|
| 67 | |
---|
| 68 | { |
---|
| 69 | eventMessenger = new XrayFluoEventActionMessenger(this); |
---|
| 70 | runManager = new XrayFluoRunAction(); |
---|
| 71 | |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | XrayFluoEventAction::~XrayFluoEventAction() |
---|
| 78 | { |
---|
| 79 | delete eventMessenger; |
---|
| 80 | eventMessenger = 0; |
---|
| 81 | delete runManager; |
---|
| 82 | runManager = 0; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 86 | |
---|
| 87 | void XrayFluoEventAction::BeginOfEventAction(const G4Event* evt) |
---|
| 88 | { |
---|
| 89 | |
---|
| 90 | if (HPGeCollID==-1) |
---|
| 91 | { |
---|
| 92 | G4SDManager * SDman = G4SDManager::GetSDMpointer(); |
---|
| 93 | HPGeCollID = SDman->GetCollectionID("HPGeCollection"); |
---|
| 94 | //the pointer points to the ID number of the sensitive detector |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 99 | |
---|
| 100 | void XrayFluoEventAction::EndOfEventAction(const G4Event* evt) |
---|
| 101 | { |
---|
| 102 | // extracted from hits, compute the total energy deposit (and total charged |
---|
| 103 | // track length) |
---|
| 104 | G4HCofThisEvent* HCE = evt->GetHCofThisEvent(); |
---|
| 105 | |
---|
| 106 | XrayFluoSensorHitsCollection* HPGeHC = 0; |
---|
| 107 | G4int n_hit = 0; |
---|
| 108 | G4double totEnergyDetect=0., totEnergy=0, energyD=0.; |
---|
| 109 | |
---|
| 110 | if (HCE) HPGeHC = (XrayFluoSensorHitsCollection*)(HCE->GetHC(HPGeCollID)); |
---|
| 111 | if(HPGeHC) |
---|
| 112 | { |
---|
| 113 | n_hit = HPGeHC->entries(); |
---|
| 114 | for (G4int i=0;i<n_hit;i++) |
---|
| 115 | { |
---|
| 116 | totEnergy += (*HPGeHC)[i]->GetEdepTot(); |
---|
| 117 | |
---|
| 118 | energyD = ResponseFunction(totEnergy); |
---|
| 119 | #ifdef G4ANALYSIS_USE |
---|
| 120 | XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance(); |
---|
| 121 | analysis->analyseEnergyDep(energyD); |
---|
| 122 | #endif |
---|
| 123 | totEnergyDetect += energyD; |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | // extract the trajectories and draw them |
---|
| 130 | |
---|
| 131 | if (G4VVisManager::GetConcreteInstance()) |
---|
| 132 | { |
---|
| 133 | |
---|
| 134 | G4TrajectoryContainer * trajectoryContainer = evt->GetTrajectoryContainer(); |
---|
| 135 | G4int n_trajectories = 0; |
---|
| 136 | if (trajectoryContainer) n_trajectories = trajectoryContainer->size(); |
---|
| 137 | |
---|
| 138 | for (G4int i=0; i<n_trajectories; i++) |
---|
| 139 | { G4Trajectory* trj = (G4Trajectory*)((*(evt->GetTrajectoryContainer()))[i]); |
---|
| 140 | if (drawFlag == "all") trj->DrawTrajectory(50); |
---|
| 141 | else if ((drawFlag == "charged")&&(trj->GetCharge() != 0.)) |
---|
| 142 | trj->DrawTrajectory(50); |
---|
| 143 | else if ((drawFlag == "neutral")&&(trj->GetCharge() == 0.)) |
---|
| 144 | trj->DrawTrajectory(50); |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | G4double XrayFluoEventAction::RandomCut(G4double energy) |
---|
| 154 | |
---|
| 155 | { |
---|
| 156 | G4double efficiency = 1.; |
---|
| 157 | G4double F = 0.15; |
---|
| 158 | G4double epsilon = 2.96 * eV; |
---|
| 159 | G4double deltaE = 220 * eV; |
---|
| 160 | G4double EdepDetect = 0.; |
---|
| 161 | //const XrayFluoDataSet* dataSet = runManager->GetEfficiencySet(); |
---|
| 162 | |
---|
| 163 | //G4double id = 0; |
---|
| 164 | |
---|
| 165 | //efficiency = dataSet->FindValue(energy,id); |
---|
| 166 | |
---|
| 167 | G4double Random = G4UniformRand(); |
---|
| 168 | |
---|
| 169 | if ( Random<efficiency ) |
---|
| 170 | { |
---|
| 171 | G4double sigma = std::sqrt(F*epsilon*energy+std::pow(deltaE/2355,2)); |
---|
| 172 | |
---|
| 173 | EdepDetect = G4RandGauss::shoot(energy, sigma ); |
---|
| 174 | |
---|
| 175 | } |
---|
| 176 | else {EdepDetect = 0.;} |
---|
| 177 | return EdepDetect; |
---|
| 178 | |
---|
| 179 | }; |
---|
| 180 | G4double XrayFluoEventAction::ResponseFunction(G4double energy) |
---|
| 181 | { |
---|
| 182 | G4double eMin = 1* keV; |
---|
| 183 | G4double eMax = 10*keV; |
---|
| 184 | G4double value = 0.; |
---|
| 185 | G4double efficiency = 1.; |
---|
| 186 | |
---|
| 187 | const XrayFluoDataSet* dataSet = runManager->GetEfficiencySet(); |
---|
| 188 | G4double id = 0; |
---|
| 189 | |
---|
| 190 | G4double random = G4UniformRand(); |
---|
| 191 | |
---|
| 192 | if (energy>=eMin && energy <=eMax) |
---|
| 193 | { |
---|
| 194 | G4double infEnergy = (G4int)(energy/keV)* keV; |
---|
| 195 | |
---|
| 196 | G4double supEnergy = ((G4int)(energy/keV) + 1)*keV; |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | |
---|
| 200 | G4double infData = runManager->GetInfData(energy, random); |
---|
| 201 | |
---|
| 202 | G4double supData = runManager->GetSupData(energy,random); |
---|
| 203 | |
---|
| 204 | value = (std::log10(infData)*std::log10(supEnergy/energy) + |
---|
| 205 | std::log10(supData)*std::log10(energy/infEnergy)) / |
---|
| 206 | std::log10(supEnergy/infEnergy); |
---|
| 207 | value = std::pow(10,value); |
---|
| 208 | } |
---|
| 209 | else if (energy<eMin) |
---|
| 210 | { |
---|
| 211 | G4double infEnergy = eMin; |
---|
| 212 | G4double supEnergy = eMin/keV +1*keV; |
---|
| 213 | |
---|
| 214 | G4double infData = runManager->GetInfData(eMin, random); |
---|
| 215 | G4double supData = runManager->GetSupData(eMin,random); |
---|
| 216 | value = (std::log10(infData)*std::log10(supEnergy/eMin) + |
---|
| 217 | std::log10(supData)*std::log10(eMin/infEnergy)) / |
---|
| 218 | std::log10(supEnergy/infEnergy); |
---|
| 219 | value = std::pow(10,value); |
---|
| 220 | value = value-eMin+ energy; |
---|
| 221 | |
---|
| 222 | |
---|
| 223 | } |
---|
| 224 | else if (energy>eMax) |
---|
| 225 | { |
---|
| 226 | G4double infEnergy = eMax/keV - 1. *keV; |
---|
| 227 | G4double supEnergy = eMax; |
---|
| 228 | |
---|
| 229 | G4double infData = runManager->GetInfData(eMax, random); |
---|
| 230 | G4double supData = runManager->GetSupData(eMax,random); |
---|
| 231 | value = (std::log10(infData)*std::log10(supEnergy/eMax) + |
---|
| 232 | std::log10(supData)*std::log10(eMax/infEnergy)) / |
---|
| 233 | std::log10(supEnergy/infEnergy); |
---|
| 234 | value = std::pow(10,value); |
---|
| 235 | value = value+energy- eMax; |
---|
| 236 | } |
---|
| 237 | G4double RandomNum = G4UniformRand(); |
---|
| 238 | |
---|
| 239 | efficiency = dataSet->FindValue(value,id); |
---|
| 240 | if ( RandomNum>efficiency ) |
---|
| 241 | { |
---|
| 242 | value = 0.; |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | return value; |
---|
| 246 | |
---|
| 247 | } |
---|