source: trunk/source/geometry/solids/test/SurfaceVisTest/src/RunAction.cc@ 1316

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

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

File size: 6.1 KB
RevLine 
[1316]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//
28
29#include "RunAction.hh"
30#include "RunMessenger.hh"
31
32#include "G4Run.hh"
33#include "G4UImanager.hh"
34#include "G4VVisManager.hh"
35#include "G4VisAttributes.hh"
36#include "G4Circle.hh"
37#include "G4VSolid.hh"
38#include "globals.hh"
39#include <vector>
40#include "G4LogicalVolumeStore.hh"
41#include "G4LogicalVolume.hh"
42
43#include "G4ios.hh"
44#include <iomanip>
45
46#include "Randomize.hh"
47
48//////////////////////////////////////////////////////////////////////////////
49
50RunAction::RunAction()
51 : saveRndm(0)
52{
53 runMessenger = new RunMessenger(this);
54 saveNum=1000;
55}
56
57////////////////////////////////////////////////////////////////////////////
58
59RunAction::~RunAction()
60{
61 delete runMessenger;
62}
63
64/////////////////////////////////////////////////////////////////////////////
65
66void RunAction::BeginOfRunAction(const G4Run* aRun)
67{
68 G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
69
70 // save Rndm status
71 if (saveRndm > 0)
72 {
73 CLHEP::HepRandom::showEngineStatus();
74 CLHEP::HepRandom::saveEngineStatus("beginOfRun.rndm");
75 }
76 G4int check=CheckPoints(saveNum);
77 if(check==0){G4cout<<"Check Point On Surface Ok! for "<<saveNum<<" points"<<G4endl;}
78 else{G4cout<<"Check Point On Surface has "<<check<<" inconsistencies"<<G4endl;};
79 DrawPoints(saveNum);
80
81
82
83}
84
85/////////////////////////////////////////////////////////////////////////////
86
87void RunAction::EndOfRunAction(const G4Run*)
88{
89 if (G4VVisManager::GetConcreteInstance())
90 {
91 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
92 }
93 // DrawPoints(saveNum);
94 // save Rndm status
95
96 if (saveRndm == 1)
97 {
98 CLHEP::HepRandom::showEngineStatus();
99 CLHEP::HepRandom::saveEngineStatus("endOfRun.rndm");
100 }
101}
102
103//
104//
105////////////////////////////////////////////////////////////////////////
106/////////////////////////////////////////////////////////////////////////////
107
108void RunAction::DrawPoints(G4int num)
109{
110 //LogicalVolumeStore search for Solid
111 G4LogicalVolumeStore *theLVStore = G4LogicalVolumeStore::GetInstance();
112 G4VSolid *solid;
113 G4ThreeVector point;
114 solid=theLVStore->GetVolume("aVolume_L",false)->GetSolid();
115
116 if(solid){
117 //Loop for Points on the Surface
118 G4int N=num;
119 for (G4int j=0; j<N;j++){
120 //Visualisation
121 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
122 if(pVVisManager){
123 point=solid->GetPointOnSurface();
124 G4Circle circle(point); // Instantiate a circle with its 3D
125 // position. The argument "position"
126 // is defined as G4Point3D instance
127 circle.SetScreenDiameter (2.0); // Should be circle.SetScreenDiameter
128 // (1.0 * pixels) - to be implemented
129 circle.SetFillStyle (G4Circle::filled); // Make it a filled circle
130 G4Colour colour(1.,0.,0.); // Define red color
131 G4VisAttributes attribs(colour); // Define a red visualization attribute
132 circle.SetVisAttributes(attribs); //
133 // make a 3D data for visualization
134 pVVisManager->Draw(circle);
135 }
136 }
137 }else{//no corresponding solid found
138 G4cout<<"RunAction::DrawPoints Sorry, No solid is found "<<G4endl;
139
140 }
141}
142// Check if the Randomly Choosen Points are On the Surface
143// return number of points not on the surface
144G4int RunAction::CheckPoints(G4int num)
145{
146 //LogicalVolumeStore search for Solid
147 G4LogicalVolumeStore *theLVStore = G4LogicalVolumeStore::GetInstance();
148 G4VSolid *solid;
149 G4ThreeVector point;
150 EInside surface;
151 solid=theLVStore->GetVolume("aVolume_L",false)->GetSolid();
152 G4int count=0;
153 if(solid){
154 //Loop for Points on the Surface
155 G4int N=num;
156 for (G4int j=0; j<N;j++){
157
158 point=solid->GetPointOnSurface();
159 surface=solid->Inside(point);
160 if(surface != kSurface)count++;
161 }
162 }else{//no corresponding solid found
163 G4cout<<"RunAction::DrawPoints Sorry, No solid is found "<<G4endl;
164 return count;
165 }
166
167 return count;
168}
169//
170//
171////////////////////////////////////////////////////////////////////////
172 void RunAction:: SetNumberOfSurfacePoints(G4int val)
173{saveNum=val;
174
175}
176//
177//
178////////////////////////////////////////////////////////////////////////
179/////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.