Classes | Functions | Variables
demo Namespace Reference

The simplest job module possible to illustrate the essential features of a job module. More...

Classes

class  App
 
class  DemoModule
 
class  DemoSyst1
 
class  DemoSyst2
 
class  MyEventAction
 
class  MyPrimaryGeneratorAction
 
class  MyRunAction
 
class  MySteppingAction
 
class  ScoreSD
 

Functions

TCanvas * DrawUpDownRatioCanvas (const PredictionInterp *pred, osc::IOscCalc *calc, const ISyst *syst)
 
def init_root ()
 
def hini ()
 
def hshow ()
 
def posXZ (copyN)
 
def Configure ()
 
def ConstructGeom ()
 

Variables

const DemoSyst1 kDemoSyst1
 
const DemoSyst2 kDemoSyst2
 
 myDC = testem0.DetectorConstruction()
 
 myPL = testem0.PhysicsList()
 
 myPGA = testem0.PrimaryGeneratorAction(myDC)
 
 myRA = testem0.RunAction(myDC,myPGA)
 
 pg = g4.G4ParticleGun()
 
 materialList = testem0.getMaterialTable();
 
 particleList = testem0.getParticleTable()
 
list enrgyList = ["eV","keV","MeV","GeV","TeV","PeV"]
 
list cutsList = ["um", "mm" , "cm", "m", "km"]
 
 app = App()
 
 rand_engine = Ranlux64Engine()
 
 exN03geom = g4py.ExN03geom.ExN03DetectorConstruction()
 
 exN03PL = g4py.EMSTDpl.PhysicsListEMstd()
 
 heprepViewer = os.environ.get("G4HEPREPFILE_VIEWER")
 
 heprepDir = os.environ.get("G4HEPREPFILE_DIR")
 
 heprepName = os.environ.get("G4HEPREPFILE_NAME")
 
 vrmlDir = os.environ.get("G4VRML_DEST_DIR")
 
 vrmlViewer = os.environ.get("G4VRMLFILE_VIEWER")
 

Detailed Description

The simplest job module possible to illustrate the essential features of a job module.

Author
Author
gsdavies

package to illustrate how to write modules

Function Documentation

def demo.Configure ( )

Definition at line 20 of file demo.py.

References python.gControlExecute.

20 def Configure():
21  # ------------------------------------------------------------------
22  # setup for materials
23  # ------------------------------------------------------------------
24  # simple materials for Qgeom
25  g4py.NISTmaterials.Construct()
26 
27  # ------------------------------------------------------------------
28  # setup for geometry
29  # ------------------------------------------------------------------
30  #g4py.Qgeom.Construct()
31  g4py.ezgeom.Construct() # initialize
32 
33  # ------------------------------------------------------------------
34  # setup for physics list
35  # ------------------------------------------------------------------
36  g4py.EMSTDpl.Construct()
37 
38  # ------------------------------------------------------------------
39  # setup for primary generator action
40  # ------------------------------------------------------------------
41  g4py.ParticleGun.Construct()
42  gControlExecute("gun.mac")
43 
44 # ==================================================================
45 # constructing geometry
46 # ==================================================================
gControlExecute
Definition: __init__.py:164
def Configure()
Definition: demo.py:20
def demo.ConstructGeom ( )

Definition at line 47 of file demo.py.

48  print "* Constructing geometry..."
49  # reset world material
50  global absorber
51  air= G4Material.GetMaterial("G4_AIR", 1)
52  galactic = G4Material.GetMaterial("G4_Galactic", 1)
53  absorber = {} # material's dictionary to be used by a radiobutton
54  aluminum = G4Material.GetMaterial("G4_Al", 1)
55  iron = G4Material.GetMaterial("G4_Fe", 1)
56  silver = G4Material.GetMaterial("G4_Ag", 1)
57  gold = G4Material.GetMaterial("G4_Au", 1)
58  lead = G4Material.GetMaterial("G4_Pb", 1)
59  water = G4Material.GetMaterial("G4_WATER", 1)
60  absorber = {"air":air, "aluminum":aluminum, "iron":iron, "lead":lead, "water":water, "gold":gold}
61  g4py.ezgeom.SetWorldMaterial(galactic)
62  g4py.ezgeom.ResizeWorld(120.*cm, 120.*cm, 100.*cm)
63  # water phantom
64  global water_phantom, water_phantom_pv
65 
66  water_phantom= G4EzVolume("WaterPhantom")
67  water_phantom.CreateBoxVolume(water, 110.*cm, 110.*cm, 10.*cm)
68 
69  water_phantom_pv = water_phantom.PlaceIt(G4ThreeVector(0.,0.,0.*cm))
70 
71 # ==================================================================
72 # main
73 # ==================================================================
74 # ------------------------------------------------------------------
75 # randum number
76 # ------------------------------------------------------------------
def ConstructGeom()
Definition: demo.py:47
TCanvas* demo::DrawUpDownRatioCanvas ( const PredictionInterp pred,
osc::IOscCalc calc,
const ISyst syst 
)

Definition at line 142 of file demoSysts.C.

References make_syst_table_plots::c, MECModelEnuComparisons::leg, pot, ana::PredictionInterp::PredictSyst(), ana::IPrediction::PredictUnoscillated(), ana::SystShifts::SetShift(), ana::SplitCanvas(), top, and ana::Ratio::ToTH1().

Referenced by demoSysts().

145  {
146  SystShifts shifts;
147 
148  // get the spectra from the predictions
149  auto spec_nom = pred->PredictUnoscillated();
150  shifts.SetShift(syst, 1.0);
151  auto spec_shift_up = pred->PredictSyst(calc, shifts);
152  Ratio rat_shift_up(spec_shift_up, spec_nom);
153  shifts.SetShift(syst, -1.0);
154  auto spec_shift_down = pred->PredictSyst(calc, shifts);
155  Ratio rat_shift_down(spec_shift_down, spec_nom);
156 
157  double pot = spec_nom.POT();
158 
159  // prep the drawing area
160  auto c = new TCanvas; // just leak this in the demo.
161  TPad * top;
162  TPad * bottom;
163  SplitCanvas(0.3, top, bottom);
164  auto leg = new TLegend(0.6, 0.6, 0.9, 0.9); // also leaked
165  leg->SetBorderSize(0);
166  leg->SetFillStyle(0);
167 
168  // compare the event rate spectra in the top panel
169  top->cd();
170  auto hup = spec_shift_up.ToTH1(pot, kRed, kDashed);
171  hup->GetXaxis()->SetTitleSize(0); // since it will also be drawn on the bottom panel
172  hup->GetXaxis()->SetLabelSize(0);
173  hup->Draw("hist");
174  auto hnom = spec_nom.ToTH1(pot);
175  hnom->Draw("hist same");
176  auto hdown = spec_shift_down.ToTH1(pot, kBlue, kDashed);
177  hdown->Draw("hist same");
178  leg->AddEntry(hnom, "Nominal", "l");
179  leg->AddEntry(hup, "+1#sigma shift");
180  leg->AddEntry(hdown, "-1#sigma shift");
181  leg->Draw();
182 
183  // compare the ratios to nominal in the bottom
184  bottom->cd();
185  auto hbottom = rat_shift_up.ToTH1(kRed);
186  hbottom->GetYaxis()->SetRangeUser(0.45, 1.55);
187  hbottom->Draw("hist");
188  rat_shift_down.ToTH1(kBlue)->Draw("hist same");
189 
190  return c;
191  }
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
Spectrum PredictSyst(osc::IOscCalc *calc, const SystShifts &shift) const override
virtual Spectrum PredictUnoscillated() const
Definition: IPrediction.cxx:69
void SplitCanvas(double ysplit, TPad *&p1, TPad *&p2)
Split the current pad into two vertically stacked pieces, suitable for ratio plots and so on...
Definition: Plots.cxx:1372
#define pot
Represent the ratio between two spectra.
Definition: Ratio.h:8
void SetShift(const ISyst *syst, double shift, bool force=false)
Definition: SystShifts.cxx:70
TGeoVolume * top
Definition: make_fe_box.C:9
def demo.hini ( )

Definition at line 35 of file demo.py.

Referenced by posXZ().

35 def hini():
36 # ------------------------------------------------------------------
37  global gPad1
38  gPad1= ROOT.TPad("2D", "2D", 0.02, 0.5, 0.98, 1.)
39  gPad1.Draw()
40  gPad1.cd()
41 
42  ROOT.gStyle.SetPalette(1);
43 
44  global hist_dose2d
45  hist_dose2d= ROOT.TH2D("2D Dose", "Dose Distribution",
46  200, 0., 400.,
47  81, -81., 81.)
48  hist_dose2d.SetXTitle("Z (mm)")
49  hist_dose2d.SetYTitle("X (mm)")
50  hist_dose2d.SetStats(0)
51  hist_dose2d.Draw("colz")
52 
53  gCanvas.cd()
54  global gPad2
55  gPad2= ROOT.TPad("Z", "Z", 0.02, 0., 0.98, 0.5)
56  gPad2.Draw()
57  gPad2.cd()
58 
59  global hist_dosez
60  hist_dosez= ROOT.TH1D("Z Dose", "Depth Dose", 200, 0., 400.)
61  hist_dosez.SetXTitle("(mm)")
62  hist_dosez.SetYTitle("Accumulated Dose (MeV)")
63  hist_dosez.Draw()
64 
65 # ------------------------------------------------------------------
def hini()
Definition: demo.py:35
def demo.hshow ( )

Definition at line 66 of file demo.py.

66 def hshow():
67 # ------------------------------------------------------------------
68  gPad1.cd()
69  hist_dose2d.Draw("colz")
70  gPad2.cd()
71  hist_dosez.Draw()
72 
73 
74 # ==================================================================
75 # Geant4 PART #
76 # ==================================================================
77 
78 # ==================================================================
79 # user actions in python
80 # ==================================================================
def hshow()
Definition: demo.py:66
def demo.init_root ( )

Definition at line 18 of file demo.py.

Referenced by posXZ().

18 def init_root():
19 # ------------------------------------------------------------------
20  ROOT.gROOT.Reset()
21 
22  # plot style
23  ROOT.gStyle.SetTextFont(42)
24  ROOT.gStyle.SetTitleFont(42, "X")
25  ROOT.gStyle.SetLabelFont(42, "X")
26  ROOT.gStyle.SetTitleFont(42, "Y")
27  ROOT.gStyle.SetLabelFont(42, "Y")
28 
29  global gCanvas
30  gCanvas= ROOT.TCanvas("water_phantom_plots",
31  "Water Phantom Demo Plots",
32  620, 30, 800, 800)
33 
34 # ------------------------------------------------------------------
def init_root()
Definition: demo.py:18
def demo.posXZ (   copyN)

Definition at line 140 of file demo.py.

References python.gApplyUICommand, hini(), and init_root().

Referenced by demo.ScoreSD.ProcessHits().

140 def posXZ(copyN):
141  dd= 2.*mm
142  nx= 81
143 
144  iz= copyN/nx
145  ix= copyN-iz*nx-nx/2
146 
147  x0= ix*dd
148  z0= (iz+0.5)*dd
149  return (x0,z0)
150 
151 
152 # ==================================================================
153 # main
154 # ==================================================================
155 # init ROOT...
156 init_root()
157 hini()
158 
159 # configure application
160 #app= demo_wp.MyApplication()
161 #app.Configure()
162 
163 myMaterials= demo_wp.MyMaterials()
164 myMaterials.Construct()
165 
166 myDC= demo_wp.MyDetectorConstruction()
167 gRunManager.SetUserInitialization(myDC)
168 
169 myPL= FTFP_BERT()
170 gRunManager.SetUserInitialization(myPL)
171 
172 # set user actions...
174 gRunManager.SetUserAction(myPGA)
175 
176 myRA= MyRunAction()
177 gRunManager.SetUserAction(myRA)
178 
179 myEA= MyEventAction()
180 gRunManager.SetUserAction(myEA)
181 
182 #mySA= MySteppingAction()
183 #gRunManager.SetUserAction(mySA)
184 
185 # set particle gun
186 #pg= myPGA.particleGun
187 #pg.SetParticleByName("proton")
188 #pg.SetParticleEnergy(230.*MeV)
189 #pg.SetParticleMomentumDirection(G4ThreeVector(0., 0., 1.))
190 #pg.SetParticlePosition(G4ThreeVector(0.,0.,-50.)*cm)
191 
192 # medical beam
193 beam= g4py.MedicalBeam.Construct()
194 beam.particle= "proton"
195 beam.kineticE= 230.*MeV
196 #beam.particle= "gamma"
197 #beam.kineticE= 1.77*MeV
198 beam.sourcePosition= G4ThreeVector(0.,0.,-100.*cm)
199 beam.SSD= 100.*cm
200 beam.fieldXY= [5.*cm, 5.*cm]
201 
202 # initialize
203 gRunManager.Initialize()
204 
205 # set SD (A SD should be set after geometry construction)
206 scoreSD= ScoreSD()
207 myDC.SetSDtoScoreVoxel(scoreSD)
208 
209 # visualization
210 gApplyUICommand("/control/execute vis.mac")
211 
212 # beamOn
213 gRunManager.BeamOn(100)
214 
215 #ROOT.gSystem.Run()
216 
217 
def posXZ(copyN)
Definition: demo.py:140
def init_root()
Definition: demo.py:18
def hini()
Definition: demo.py:35
gApplyUICommand
Definition: __init__.py:165

Variable Documentation

list demo.cutsList = ["um", "mm" , "cm", "m", "km"]

Definition at line 45 of file demo.py.

list demo.enrgyList = ["eV","keV","MeV","GeV","TeV","PeV"]

Definition at line 43 of file demo.py.

demo.exN03geom = g4py.ExN03geom.ExN03DetectorConstruction()

Definition at line 41 of file demo.py.

demo.exN03PL = g4py.EMSTDpl.PhysicsListEMstd()

Definition at line 56 of file demo.py.

demo.heprepDir = os.environ.get("G4HEPREPFILE_DIR")

Definition at line 121 of file demo.py.

demo.heprepName = os.environ.get("G4HEPREPFILE_NAME")

Definition at line 122 of file demo.py.

demo.heprepViewer = os.environ.get("G4HEPREPFILE_VIEWER")

Definition at line 120 of file demo.py.

const DemoSyst1 demo::kDemoSyst1

Definition at line 87 of file demoSysts.C.

Referenced by demoSysts().

const DemoSyst2 demo::kDemoSyst2

Definition at line 138 of file demoSysts.C.

Referenced by demoSysts().

demo.materialList = testem0.getMaterialTable();

Definition at line 39 of file demo.py.

demo.myDC = testem0.DetectorConstruction()

Definition at line 18 of file demo.py.

demo.myPGA = testem0.PrimaryGeneratorAction(myDC)

Definition at line 25 of file demo.py.

demo.myPL = testem0.PhysicsList()

Definition at line 21 of file demo.py.

demo.myRA = testem0.RunAction(myDC,myPGA)

Definition at line 28 of file demo.py.

demo.pg = g4.G4ParticleGun()

Definition at line 37 of file demo.py.

demo.rand_engine = Ranlux64Engine()

Definition at line 78 of file demo.py.

demo.vrmlDir = os.environ.get("G4VRML_DEST_DIR")

Definition at line 128 of file demo.py.

demo.vrmlViewer = os.environ.get("G4VRMLFILE_VIEWER")

Definition at line 129 of file demo.py.