1 |
// $Id: run_g4.C,v 1.0 2007/06/01 |
2 |
// |
3 |
// Macro for running G4PAM_VMC with Geant4. |
4 |
|
5 |
void PamG4Libs_granular(); |
6 |
|
7 |
#include <PamLevel2.h> |
8 |
#include <PamG4Libs.h> |
9 |
#include <PamVMCApplication.h> |
10 |
#include <G4ApplicationState.hh> |
11 |
#include <TG4ApplicationState.h> |
12 |
#include <TGeant4.h> |
13 |
#include <PrimaryInfo.h> |
14 |
|
15 |
|
16 |
void run_sim_g4(const TString& configMacro = "g4Config.C", const TString& primfile = "prim.root") { |
17 |
|
18 |
cout<<"PRIMFILE: "<<primfile<<endl; |
19 |
|
20 |
TFile rfin(primfile,"read"); |
21 |
TTree * primtree = (TTree*)rfin.Get("primaries"); |
22 |
if(!primtree) cout<<"ERROR: tree 'primaries' with primaries kinematics not found!"<<endl; |
23 |
PrimaryInfo *p = 0; |
24 |
primtree->SetBranchAddress("PRIM", &p); |
25 |
|
26 |
PamG4Libs(); |
27 |
|
28 |
|
29 |
|
30 |
// Load this example libraries |
31 |
|
32 |
TString PAM_VMC=gSystem->Getenv("PAM_VMC"); |
33 |
TString PLAT=gSystem->Getenv("PLATFORM"); |
34 |
|
35 |
// MC application |
36 |
TString outname="."; |
37 |
outname+="/"; |
38 |
outname+=primfile; |
39 |
outname.Replace(0,outname.Index("prim_",0),""); |
40 |
outname.Replace(outname.Index(".root",0),5,"_sim"); |
41 |
|
42 |
cout<<"OUTNAME="<<outname<<endl; |
43 |
|
44 |
PamVMCApplication* appl |
45 |
= new PamVMCApplication("PAMG4_VMC", "PAMELA GEANT4 VMC application", outname); |
46 |
|
47 |
|
48 |
// Initialize MC |
49 |
G4ConfMacro=PAM_VMC+"/config/"+configMacro; |
50 |
appl->InitMC(G4ConfMacro); |
51 |
|
52 |
cout<<"MACRO READED"<<endl; |
53 |
|
54 |
|
55 |
|
56 |
((TGeant4*)gMC)->SetMaxNStep(50000); |
57 |
|
58 |
Int_t nevents = primtree->GetEntries(); |
59 |
; |
60 |
//MAIN LOOP |
61 |
Double_t x,y,z,theta,phi,momentum; |
62 |
Int_t pdg; |
63 |
for(Int_t i = 0; i<nevents; i++){ |
64 |
rfin.cd(); |
65 |
primtree->GetEntry(i); |
66 |
x = p->X0; |
67 |
y = p->Y0; |
68 |
z = p->Z0; |
69 |
theta = p->Theta; |
70 |
phi = p->Phi; |
71 |
pdg = p->PDG; |
72 |
momentum = p->P0; |
73 |
|
74 |
cout<<"EVENT: "<<i<<endl; |
75 |
cout<<"PDG:"<<pdg<<endl |
76 |
<<"X0: "<<x<<" (cm)"<<endl |
77 |
<<"Y0: "<<y<<" (cm)"<<endl |
78 |
<<"Z0: "<<z<<" (cm)"<<endl |
79 |
<<"Theta:"<<theta*180./TMath::Pi()<<" (deg)"<<endl |
80 |
<<"Phi:"<<phi*180./TMath::Pi()<<" (deg)"<<endl |
81 |
<<"Momentum: "<<momentum<<" (GV)"<<endl; |
82 |
|
83 |
appl->GetPrimaryGenerator()->SetParticle(pdg); |
84 |
appl->GetPrimaryGenerator()->SetDirection(theta,phi); |
85 |
appl->GetPrimaryGenerator()->SetMomentum(momentum); |
86 |
appl->GetPrimaryGenerator()->SetPosition(x,y,z); |
87 |
|
88 |
appl->RunMC(1); |
89 |
|
90 |
} |
91 |
appl->FinishRun(); |
92 |
// delete appl; |
93 |
} |