source: trunk/examples/extended/eventgenerator/exgps/src/exGPSEventAction.cc @ 1230

Last change on this file since 1230 was 1230, checked in by garnier, 15 years ago

update to geant4.9.3

File size: 5.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#include "exGPSEventAction.hh"
28
29#ifdef G4ANALYSIS_USE
30#include "exGPSAnalysisManager.hh"
31#endif
32
33#include "exGPSEventActionMessenger.hh"
34
35#include "G4Event.hh"
36#include "G4EventManager.hh"
37#include "G4TrajectoryContainer.hh"
38#include "G4Trajectory.hh"
39#include "G4VVisManager.hh"
40#include "G4ios.hh"
41#include "G4UnitsTable.hh"
42#include "G4ThreeVector.hh"
43
44//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
45exGPSEventAction::exGPSEventAction()
46:drawFlag("all"), printModulo(1000), eventMessenger(NULL) 
47{
48  eventMessenger = new exGPSEventActionMessenger(this);
49}
50
51//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
52
53exGPSEventAction::~exGPSEventAction()
54{
55  delete eventMessenger;
56}
57
58//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
59
60void exGPSEventAction::BeginOfEventAction(const G4Event* evt)
61{
62 
63  G4int evtNb = evt->GetEventID();
64  if (evtNb%printModulo == 0)
65    { 
66      G4cout << "\n---> Begin of event: " << evtNb << G4endl;
67      //  HepRandom::showEngineStatus();
68    }
69   
70}
71
72//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
73
74void exGPSEventAction::EndOfEventAction(const G4Event* evt)
75{
76  //  G4int evtNb = evt->GetEventID();
77
78#ifdef G4ANALYSIS_USE
79  G4int nVertex = evt->GetNumberOfPrimaryVertex();
80  for ( G4int j = 0; j < nVertex; j++) { 
81    G4int nPart =  evt->GetPrimaryVertex(j)->GetNumberOfParticle(); 
82    for ( G4int i = 0; i < nPart; i++) {
83      G4ThreeVector position=evt->GetPrimaryVertex(j)->GetPosition();
84      G4ThreeVector direction=evt->GetPrimaryVertex(j)->GetPrimary(i)->GetMomentum();
85      G4double P=direction.mag();
86      G4double E=evt->GetPrimaryVertex(j)->GetPrimary(i)->GetMass();
87      G4double E0=evt->GetPrimaryVertex(j)->GetPrimary(i)->GetG4code()->GetPDGMass();
88      E=std::sqrt(P*P+E0*E0);   
89      E -= E0;
90//      G4String pname = evt->GetPrimaryVertex(j)->GetPrimary(i)->GetG4code()->GetParticleName();
91      G4double pid = G4double(evt->GetPrimaryVertex(j)->GetPrimary(i)->GetPDGcode());
92      //
93      direction=direction*(1./direction.mag());               
94      direction = -direction;  // reverse the direction
95      G4double x,y,z,w;
96      G4double Phi=direction.phi();
97      if (Phi <0) Phi=Phi+twopi;
98      G4double Theta=direction.theta();
99      x=position.x();
100      y=position.y();
101      z=position.z();
102      w = evt->GetPrimaryVertex(j)->GetPrimary(i)->GetWeight();
103//      exGPSAnalysisManager::getInstance()->Fill(pname,E,x,y,z,Theta,Phi,w);
104     exGPSAnalysisManager::getInstance()->Fill(pid,E,x,y,z,Theta,Phi,w);
105    }
106  }   
107#endif
108
109#ifdef G4VIS_USE
110  // extract the trajectories and draw them
111  if (G4VVisManager::GetConcreteInstance())
112    {
113     G4TrajectoryContainer * trajectoryContainer = evt->GetTrajectoryContainer();
114     G4int n_trajectories = 0;
115     if (trajectoryContainer) n_trajectories = trajectoryContainer->entries();
116     
117     for (G4int i=0; i<n_trajectories; i++) 
118       { G4Trajectory* trj = (G4Trajectory*)((*(evt->GetTrajectoryContainer()))[i]);
119       if (drawFlag == "all") trj->DrawTrajectory(0);
120       else if ((drawFlag == "charged")&&(trj->GetCharge() != 0.))
121         trj->DrawTrajectory(0);
122       else if ((drawFlag == "neutral")&&(trj->GetCharge() == 0.))
123         trj->DrawTrajectory(0);                                   
124       }
125   }             
126#endif
127}
128
129//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
130
131
132
133
134
135
Note: See TracBrowser for help on using the repository browser.