source: trunk/examples/advanced/xray_fluorescence/src/XrayFluoEventAction.cc @ 1345

Last change on this file since 1345 was 1337, checked in by garnier, 14 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 7.0 KB
Line 
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// 15 Jul 2003 Alfonso Mantero        "DetectorType" use integration
36// 23 Sep 2003 Alfonso Mantero        differnt geometries integration
37//
38// -------------------------------------------------------------------
39
40#include "XrayFluoEventAction.hh"
41#include "XrayFluoSensorHit.hh"
42#include "XrayFluoEventActionMessenger.hh"
43
44//#include "XrayFluoRunAction.hh"
45#include "XrayFluoDataSet.hh"
46
47#include "XrayFluoAnalysisManager.hh"
48
49#include "G4Event.hh"
50#include "G4EventManager.hh"
51#include "G4HCofThisEvent.hh"
52#include "G4VHitsCollection.hh"
53#include "G4SDManager.hh"
54#include "G4UImanager.hh"
55#include "G4ios.hh"
56#include "G4UnitsTable.hh"
57#include "Randomize.hh"
58#include <fstream>
59//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
60
61XrayFluoEventAction::XrayFluoEventAction(XrayFluoDetectorConstruction* det)
62  :drawFlag("all"),
63   HPGeCollID(0),
64   eventMessenger(0),
65   printModulo(1),
66   detectorType(0)
67{
68  eventMessenger = new XrayFluoEventActionMessenger(this);
69 
70  if (!(det->GetPhaseSpaceFlag()) ){
71    detectorType = det->GetDetectorType();
72    HPGeCollID=-1;
73  }
74 
75  //runManager = new XrayFluoRunAction();
76  G4cout << "XrayFluoEventAction created" << G4endl; 
77}
78
79//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
80
81XrayFluoEventAction::XrayFluoEventAction(XrayFluoPlaneDetectorConstruction* det)
82  :drawFlag("all"),
83   HPGeCollID(-1),
84   eventMessenger(0),
85   printModulo(1),
86   detectorType(0)
87{
88  eventMessenger = new XrayFluoEventActionMessenger(this);
89  detectorType = det->GetDetectorType();
90
91  //runManager = new XrayFluoRunAction();
92  G4cout << "XrayFluoEventAction created" << G4endl; 
93}
94
95//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
96
97XrayFluoEventAction::XrayFluoEventAction(XrayFluoMercuryDetectorConstruction* det)
98  :drawFlag("all"),
99   HPGeCollID(-1),
100   eventMessenger(0),
101   printModulo(1),
102   detectorType(0)
103{
104  eventMessenger = new XrayFluoEventActionMessenger(this);
105  detectorType = det->GetDetectorType();
106
107  //runManager = new XrayFluoRunAction();
108  G4cout << "XrayFluoEventAction created" << G4endl; 
109}
110
111//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
112
113
114
115//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
116
117XrayFluoEventAction::~XrayFluoEventAction()
118{
119   delete eventMessenger;
120   eventMessenger = 0;
121   //delete  runManager;
122   //runManager = 0;
123   G4cout << "XrayFluoEventAction deleted" << G4endl;
124}
125
126//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
127
128void XrayFluoEventAction::BeginOfEventAction(const G4Event* evt)
129{
130
131  G4int eventNumber = (evt->GetEventID())+1;
132  if ( eventNumber == 1){
133
134  G4cout << "# = 100000 events" << G4endl;
135  G4cout << "1--------+---------+---------+---------+---------5e6"<<G4endl;
136  }
137
138  if ( ((eventNumber) % 100000) == 0 )  {
139
140    if ( eventNumber % (G4int)5e6 != 0 ) G4cout << "#" << std::flush;
141    else G4cout << "#"<< G4endl;
142    //    if ( eventNumber % 5e6 == 0 ) G4cout << "#"<< G4endl;
143#ifdef G4ANALYSIS_USE
144    XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
145    analysis->PlotCurrentResults();
146#endif
147  }
148
149  if (HPGeCollID==-1)
150   
151    {
152      G4SDManager * SDman = G4SDManager::GetSDMpointer();
153      HPGeCollID = SDman->GetCollectionID("HPGeCollection");
154      //the pointer points to the ID number of the sensitive detector
155    }
156}
157 
158//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
159
160void XrayFluoEventAction::EndOfEventAction(const G4Event* evt)
161{
162 
163  if (detectorType) {
164   
165    // extracted from hits, compute the total energy deposit (and total charged
166    // track length)
167    G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
168   
169    XrayFluoSensorHitsCollection* HPGeHC = 0;
170    G4int n_hit = 0;
171    G4double totEnergyDetect=0., totEnergy=0., energyD=0.;
172   
173    if (HCE) HPGeHC = (XrayFluoSensorHitsCollection*)(HCE->GetHC(HPGeCollID));
174    if(HPGeHC)
175     
176     
177      {
178        n_hit = HPGeHC->entries();
179       
180        // if (n_hit) {G4cout << "Ecco quante hit ho nel detector "<< n_hit << G4endl;}
181       
182        for (G4int i=0;i<n_hit;i++)
183          {
184           
185            totEnergy += (*HPGeHC)[i]->GetEdepTot(); 
186           
187           
188           
189            energyD = detectorType->ResponseFunction(totEnergy);
190            // energyD = totEnergy;
191            // G4cout << "energy deposit: "<< totEnergy  << G4endl;
192#ifdef G4ANALYSIS_USE
193            XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
194            analysis->analyseEnergyDep(energyD);
195#endif     
196            totEnergyDetect += energyD;
197           
198           
199          }
200      }
201  } 
202}
203
204//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
205
206
207
208G4double XrayFluoEventAction::RandomCut(G4double energy)
209 
210{
211  G4double efficiency = 1.;
212  G4double F = 0.15;
213  G4double epsilon = 2.96 * eV;
214  G4double deltaE = 220 * eV;
215  G4double EdepDetect = 0.;
216  //const XrayFluoDataSet* dataSet = runManager->GetEfficiencySet();
217     
218  //G4double id = 0;
219 
220  //efficiency = dataSet->FindValue(energy,id);
221 
222  G4double  Random = G4UniformRand(); 
223
224    if ( Random<efficiency )
225      {
226        G4double sigma = std::sqrt(F*epsilon*energy+std::pow(deltaE/2355,2));
227
228        EdepDetect = G4RandGauss::shoot(energy, sigma );
229
230  }
231    else {EdepDetect = 0.;}
232    return   EdepDetect;
233   
234}
235
236
Note: See TracBrowser for help on using the repository browser.