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

Last change on this file since 830 was 807, checked in by garnier, 16 years ago

update

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