1 |
// $Id: PamVMCApplication.cxx,v 1.0 2007/06/01 |
// $Id: PamVMCApplication.cxx,v 1.0 2007/06/01 |
2 |
// |
// |
3 |
// Geant4 ExampleN06 adapted to Virtual Monte Carlo |
// Geant4 PAMELA VMC |
4 |
#include <cstdlib> |
#include <cstdlib> |
5 |
#include <string> |
#include <string> |
6 |
|
#include <iostream> |
7 |
#include <TROOT.h> |
#include <TROOT.h> |
8 |
#include <TInterpreter.h> |
#include <TInterpreter.h> |
9 |
#include <TVirtualMC.h> |
#include <TVirtualMC.h> |
10 |
#include <Riostream.h> |
#include <Riostream.h> |
11 |
#include <TGeoManager.h> |
#include <TGeoManager.h> |
12 |
#include <TVirtualGeoTrack.h> |
#include <TVirtualGeoTrack.h> |
13 |
|
#include <TLorentzVector.h> |
14 |
#include "PamVMCApplication.h" |
#include "PamVMCApplication.h" |
15 |
#include "PamVMCStack.h" |
#include "PamVMCStack.h" |
|
#include "PamVMCDetectorConstruction.h" |
|
16 |
#include "PamVMCPrimaryGenerator.h" |
#include "PamVMCPrimaryGenerator.h" |
17 |
|
|
18 |
|
#include "PamVMCFieldMgr.h" |
19 |
|
|
20 |
|
#include "PamVMCSDMgr.h" |
21 |
|
|
22 |
|
#include "PamVMCVolCrossMgr.h" |
23 |
|
|
24 |
|
#include "PamVMCDetPamela.h" |
25 |
|
|
26 |
|
//#include "TFluka.h" |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
ClassImp(PamVMCApplication) |
ClassImp(PamVMCApplication) |
31 |
|
|
32 |
PamVMCApplication::PamVMCApplication(const char *name, const char *title) |
PamVMCApplication::PamVMCApplication(const char *name, const char *title) |
33 |
: TVirtualMCApplication(name,title), |
: TVirtualMCApplication(name,title), |
34 |
fEventNo(0), |
fEventNo(0), |
35 |
fVerbose(0), |
fVerbose(2), |
36 |
fStack(0), |
fStack(0), |
37 |
fDetConstruction(0), |
fdetector(0), |
38 |
fPrimaryGenerator(0) |
fPrimaryGenerator(0), |
39 |
|
fRootManager("pamtest",kWrite) |
40 |
{ |
{ |
41 |
// Standard constructor |
// Standard constructor |
42 |
|
|
43 |
// Create a user stack |
// Create a user stack |
44 |
fStack = new PamVMCStack(10000); |
fStack = new PamVMCStack(1000); |
45 |
|
|
|
// Create detector construction |
|
|
fDetConstruction = new PamVMCDetectorConstruction(); |
|
46 |
|
|
47 |
// Create a primary generator |
// Create a primary generator |
48 |
fPrimaryGenerator = new PamVMCPrimaryGenerator(fStack); |
fPrimaryGenerator = new PamVMCPrimaryGenerator(fStack); |
|
#ifdef PAMFIELD |
|
|
// Load the PAMELA magnetic field |
|
49 |
|
|
50 |
std::string pamcal=getenv("PAM_CALIB"); pamcal+="/trk-param/field_param-0/"; |
|
51 |
std::cout << "PAMELA env: " << pamcal << std::endl; |
fdetector = new PamVMCDetPamela(); |
52 |
pamfield.LoadField(pamcal.c_str()); |
|
53 |
#endif |
PamVMCFieldMgr::Instance()->LoadField(); |
54 |
} |
} |
55 |
|
|
56 |
|
|
59 |
fEventNo(0), |
fEventNo(0), |
60 |
fVerbose(0), |
fVerbose(0), |
61 |
fStack(0), |
fStack(0), |
62 |
fDetConstruction(0), |
fdetector(0), |
63 |
fPrimaryGenerator(0) |
fPrimaryGenerator(0), |
64 |
|
fRootManager() |
65 |
{ |
{ |
66 |
// Default constructor |
// Default constructor |
67 |
} |
} |
69 |
PamVMCApplication::~PamVMCApplication() |
PamVMCApplication::~PamVMCApplication() |
70 |
{ |
{ |
71 |
// Destructor |
// Destructor |
72 |
|
|
73 |
delete fStack; |
delete fStack; |
74 |
delete fDetConstruction; |
delete fdetector; |
75 |
delete fPrimaryGenerator; |
delete fPrimaryGenerator; |
76 |
delete gMC; |
delete gMC; |
77 |
gMC = 0; |
gMC = 0; |
78 |
} |
} |
79 |
|
|
|
// |
|
|
// public methods |
|
|
// |
|
80 |
|
|
81 |
void PamVMCApplication::InitMC(const char* setup) |
void PamVMCApplication::InitMC(const char* setup) |
82 |
{ |
{ |
84 |
|
|
85 |
fVerbose.InitMC(); |
fVerbose.InitMC(); |
86 |
|
|
87 |
gROOT->LoadMacro(setup); |
gROOT->LoadMacro(setup); |
88 |
gInterpreter->ProcessLine("Config()"); |
gInterpreter->ProcessLine("Config()"); |
89 |
gMC->SetStack(fStack); |
gMC->SetStack(fStack); |
90 |
gMC->Init(); |
std::cout<<"!!! BEFORE INIT GMC"<<std::endl; |
91 |
gMC->BuildPhysics(); |
|
92 |
|
gMC->Init(); |
93 |
|
cout<<"INIT MC"<<endl; |
94 |
|
gMC->BuildPhysics(); |
95 |
|
cout<<"PHYSICS BUILDED"<<endl; |
96 |
|
|
97 |
|
|
98 |
|
fdetector->InitMC(); |
99 |
|
|
100 |
|
// fdetector->Print(); |
101 |
|
|
102 |
|
PamVMCSDMgr::Instance()->Register(); |
103 |
|
|
104 |
|
PamVMCDigMgr::Instance()->LoadCalib(); |
105 |
|
PamVMCRawMgr::Instance()->WriteToFile(); |
106 |
|
|
107 |
|
fPrimaryGenerator->Register(); |
108 |
|
|
109 |
|
std::cout<<"LIST OF ACTIVE SD'S:"<<std::endl; |
110 |
|
|
111 |
|
PamVMCSDMgr::Instance()->Print(); |
112 |
} |
} |
113 |
|
|
114 |
void PamVMCApplication::RunMC(Int_t nofEvents) |
void PamVMCApplication::RunMC(Int_t nofEvents) |
115 |
{ |
{ |
116 |
// MC run. |
// MC run. |
117 |
|
|
118 |
fVerbose.RunMC(nofEvents); |
fVerbose.RunMC(nofEvents); |
119 |
|
|
120 |
gMC->ProcessRun(nofEvents); |
gMC->ProcessRun(nofEvents); |
121 |
|
|
122 |
//// fVerbose.FinishRun(); |
fVerbose.FinishRun(); |
123 |
|
} |
124 |
|
|
125 |
|
void PamVMCApplication::AddIons(){ |
126 |
|
|
127 |
|
fVerbose.AddIons(); |
128 |
|
gMC->DefineIon("He4",2,4,1,0.); |
129 |
|
gMC->DefineIon("Boron",5,10,1,0.); |
130 |
|
gMC->DefineIon("Carbon",6,12,1,0.); |
131 |
} |
} |
132 |
|
|
133 |
|
|
134 |
void PamVMCApplication::ConstructGeometry() |
void PamVMCApplication::ConstructGeometry() |
135 |
{ |
{ |
136 |
// Construct geometry using detector contruction class |
// Construct geometry using detector contruction class |
137 |
|
|
138 |
fVerbose.ConstructGeometry(); |
fVerbose.ConstructGeometry(); |
139 |
fDetConstruction->ConstructGeometry(); |
new TGeoManager("PAM_GEOM","PAMELA GEOMETRY"); |
140 |
|
fdetector->ConstructGeometry(); |
141 |
|
//TGeoManager::Import("/home/pamela/PamCAL210508/gp2tgeo.root"); |
142 |
|
gGeoManager->CloseGeometry(); |
143 |
|
gMC->SetRootGeometry(); |
144 |
|
|
145 |
|
cout<<"!!CONSTRUCT GEOMETRY!!"<<endl; |
146 |
|
fdetector->ConstructCuts(); |
147 |
|
|
148 |
} |
} |
149 |
|
|
150 |
void PamVMCApplication::InitGeometry() |
void PamVMCApplication::InitGeometry() |
151 |
{ |
{ |
152 |
// Initialize geometry |
// Initialize geometry |
153 |
|
|
154 |
fVerbose.InitGeometry(); |
cout<<"!!SETUP CUTS"<<endl; |
155 |
|
//fdetector->InitGeometry(); |
156 |
|
|
157 |
|
fVerbose.InitGeometry(); |
158 |
} |
} |
159 |
|
|
160 |
|
|
161 |
void PamVMCApplication::GeneratePrimaries() |
void PamVMCApplication::GeneratePrimaries() |
162 |
{ |
{ |
163 |
// Fill the user stack (derived from TVirtualMCStack) with primary particles. |
// Fill the user stack (derived from TVirtualMCStack) with primary particles. |
164 |
|
|
165 |
///// fVerbose.GeneratePrimaries(); |
fPrimaryGenerator->GeneratePrimary(); |
|
|
|
|
fPrimaryGenerator->GeneratePrimaries(); |
|
166 |
} |
} |
167 |
|
|
168 |
void PamVMCApplication::BeginEvent() |
void PamVMCApplication::BeginEvent() |
169 |
{ |
{ |
170 |
// User actions at beginning of event |
// User actions at beginning of event |
171 |
|
PamVMCSDMgr::Instance()->PreEvent(); |
|
///// fVerbose.BeginEvent(); |
|
|
|
|
172 |
fEventNo++; |
fEventNo++; |
173 |
} |
} |
174 |
|
|
175 |
void PamVMCApplication::BeginPrimary() |
void PamVMCApplication::BeginPrimary() |
176 |
{ |
{ |
177 |
// User actions at beginning of a primary track |
// User actions at beginning of a primary track |
178 |
|
|
179 |
//// fVerbose.BeginPrimary(); |
fVerbose.BeginPrimary(); |
180 |
} |
} |
181 |
|
|
182 |
void PamVMCApplication::PreTrack() |
void PamVMCApplication::PreTrack() |
183 |
{ |
{ |
184 |
// User actions at beginning of each track |
// User actions at beginning of each track |
185 |
|
|
|
////// fVerbose.PreTrack(); |
|
|
|
|
186 |
} |
} |
187 |
|
|
188 |
void PamVMCApplication::Stepping() |
void PamVMCApplication::Stepping() |
189 |
{ |
{ |
190 |
|
if (fStack->GetCurrentTrack()->IsPrimary()){ |
191 |
|
PamVMCVolCross* tmp=(PamVMCVolCross*)PamVMCVolCrossMgr::Instance()->GetSD(gMC->CurrentVolName()); |
192 |
|
if (tmp){ |
193 |
|
tmp->CrossVol(); |
194 |
|
} |
195 |
|
} |
196 |
// User actions at each step |
// User actions at each step |
197 |
|
fVerbose.Stepping(); |
198 |
////// fVerbose.Stepping(); |
PamVMCDetectorSD* temp=(PamVMCDetectorSD*) PamVMCSDMgr::Instance()->GetSD(gMC->CurrentVolName()); |
199 |
|
if(temp){ |
200 |
|
fdstatus=INSIDE; |
201 |
|
if(gMC->IsTrackEntering()){ fdstatus=ENTERING; } |
202 |
|
if(gMC->IsTrackExiting() || gMC->IsTrackOut() || gMC->IsTrackStop() ) { fdstatus=EXITING;} |
203 |
|
temp->FillHit(fdstatus,gMC); |
204 |
|
} |
205 |
|
|
206 |
} |
} |
207 |
|
|
208 |
void PamVMCApplication::PostTrack() |
void PamVMCApplication::PostTrack() |
209 |
{ |
{ |
210 |
// User actions after finishing of each track |
// User actions after finishing of each track |
211 |
|
|
|
|
|
|
///// fVerbose.PostTrack(); |
|
212 |
} |
} |
213 |
|
|
214 |
void PamVMCApplication::FinishPrimary() |
void PamVMCApplication::FinishPrimary() |
215 |
{ |
{ |
216 |
// User actions after finishing of a primary track |
// User actions after finishing of a primary track |
217 |
|
fPrimaryGenerator->SetGood(PamVMCVolCrossMgr::Instance()->IsTrackGood()); |
218 |
///// fVerbose.FinishPrimary(); |
PamVMCVolCrossMgr::Instance()->Reset(); |
219 |
|
fVerbose.FinishPrimary(); |
220 |
} |
} |
221 |
|
|
222 |
void PamVMCApplication::FinishEvent() |
void PamVMCApplication::FinishEvent() |
223 |
{ |
{ |
224 |
// User actions after finishing of an event |
// User actions after finishing of an event |
225 |
|
|
226 |
|
|
227 |
|
|
228 |
/////fVerbose.FinishEvent(); |
PamVMCSDMgr::Instance()->Digitize(); |
229 |
|
//EventNo needs for trigger, particle PDG needs for TOF.. |
230 |
|
PamVMCDigMgr::Instance()->Digitize(fEventNo,fPrimaryGenerator->GetParticle()); |
231 |
|
|
232 |
|
PamVMCSDMgr::Instance()->Compress(); |
233 |
|
|
234 |
fStack->Reset(); |
PamVMCRawMgr::Instance()->WriteEvent(); |
235 |
|
|
236 |
|
fRootManager.Fill(); |
237 |
|
|
238 |
|
fPrimaryGenerator->ClearPrimCol(); |
239 |
|
|
240 |
|
PamVMCSDMgr::Instance()->Clear(); |
241 |
|
|
242 |
|
fStack->Reset(); |
243 |
|
|
244 |
} |
} |
245 |
|
|
246 |
void PamVMCApplication::Field(const Double_t* x, Double_t* b) const |
void PamVMCApplication::FinishRun() |
247 |
{ |
{ |
248 |
// Uniform magnetic field |
fVerbose.FinishRun(); |
249 |
|
|
250 |
|
fRootManager.WriteAll(); |
251 |
|
|
252 |
|
PamVMCDigMgr::Instance()->FinishRun(); //write RunTrailer to buffer |
253 |
|
|
254 |
#ifdef PAMFIELD |
PamVMCRawMgr::Instance()->FinishRun(); //write RunTrailer to file and close; |
255 |
b[0] = pamfield.GetBX((float *)x); |
|
256 |
b[1] = pamfield.GetBY((float *)x); |
PamVMCDigMgr::Instance()->PrintCollections(); |
257 |
b[2] = pamfield.GetBZ((float *)x); |
|
258 |
#else |
} |
259 |
for (Int_t i=0; i<3; i++) b[i] = 0.0; |
|
260 |
#endif |
void PamVMCApplication::Field(const Double_t* x, Double_t* b) const |
261 |
|
{ |
262 |
|
PamVMCFieldMgr::Instance()->Field(x,b); |
263 |
} |
} |