1 |
// $Id: PamVMCApplication.cxx,v 1.0 2007/06/01 |
2 |
// |
3 |
// Geant4 PAMELA VMC |
4 |
#include <cstdlib> |
5 |
#include <string> |
6 |
#include <iostream> |
7 |
#include <TROOT.h> |
8 |
#include <TInterpreter.h> |
9 |
#include <TVirtualMC.h> |
10 |
#include <Riostream.h> |
11 |
#include <TGeoManager.h> |
12 |
#include <TVirtualGeoTrack.h> |
13 |
#include <TLorentzVector.h> |
14 |
#include "PamVMCApplication.h" |
15 |
#include "PamVMCStack.h" |
16 |
#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) |
31 |
|
32 |
PamVMCApplication::PamVMCApplication(const char *name, const char *title, const char* filename, Int_t seed) |
33 |
: TVirtualMCApplication(name,title), |
34 |
fEventNo(0), |
35 |
fVerbose(2), |
36 |
fStack(0), |
37 |
fdetector(0), |
38 |
fPrimaryGenerator(0), |
39 |
fRootManager(filename,kWrite) |
40 |
{ |
41 |
// Standard constructor |
42 |
|
43 |
// Create a user stack |
44 |
fStack = new PamVMCStack(1000); |
45 |
|
46 |
// Create a primary generator |
47 |
fPrimaryGenerator = new PamVMCPrimaryGenerator(fStack); |
48 |
|
49 |
//Create random object |
50 |
frandom = new TRandom3(seed); |
51 |
std::cout<<"!!! THE SEED of this MONTE CARLO is: "<<frandom->GetSeed()<<std::endl; |
52 |
|
53 |
fdetector = new PamVMCDetPamela(); |
54 |
|
55 |
PamVMCFieldMgr::Instance()->LoadField(); |
56 |
|
57 |
TString fname=filename; fname+=".pam"; |
58 |
|
59 |
PamVMCRawMgr::Instance()-> CreateOutFile(fname.Data()); |
60 |
} |
61 |
|
62 |
|
63 |
PamVMCApplication::~PamVMCApplication() |
64 |
{ |
65 |
// Destructor |
66 |
delete frandom; |
67 |
delete fStack; |
68 |
delete fdetector; |
69 |
delete fPrimaryGenerator; |
70 |
delete gMC; |
71 |
gMC = 0; |
72 |
} |
73 |
|
74 |
|
75 |
void PamVMCApplication::InitMC(const char* setup) |
76 |
{ |
77 |
// Initialize MC. |
78 |
|
79 |
fVerbose.InitMC(); |
80 |
|
81 |
gROOT->LoadMacro(setup); |
82 |
gInterpreter->ProcessLine("Config()"); |
83 |
gMC->SetStack(fStack); |
84 |
gMC->SetRandom(frandom); |
85 |
|
86 |
std::cout<<"!!! BEFORE INIT GMC"<<std::endl; |
87 |
|
88 |
gMC->Init(); |
89 |
cout<<"INIT MC"<<endl; |
90 |
gMC->BuildPhysics(); |
91 |
cout<<"PHYSICS BUILDED"<<endl; |
92 |
|
93 |
#if ROOT_VERSION_CODE >= 333572 |
94 |
gMC->SetMagField(PamVMCFieldMgr::Instance()); |
95 |
cout<<"Magnetic field setted"<<endl; |
96 |
#endif |
97 |
|
98 |
fdetector->InitMC(); |
99 |
|
100 |
// fdetector->Print(); |
101 |
|
102 |
PamVMCSDMgr::Instance()->Register(); |
103 |
|
104 |
PamVMCDigMgr::Instance()->Initialize(gMC->GetRandom()); |
105 |
|
106 |
PamVMCRawMgr::Instance()->WriteToFile(); |
107 |
|
108 |
fPrimaryGenerator->SetRandom(gMC->GetRandom()); |
109 |
fPrimaryGenerator->Register(); |
110 |
|
111 |
std::cout<<"LIST OF ACTIVE SD'S:"<<std::endl; |
112 |
|
113 |
PamVMCSDMgr::Instance()->Print(); |
114 |
} |
115 |
|
116 |
void PamVMCApplication::RunMC(Int_t nofEvents) |
117 |
{ |
118 |
// MC run. |
119 |
|
120 |
fVerbose.RunMC(nofEvents); |
121 |
|
122 |
gMC->ProcessRun(nofEvents); |
123 |
|
124 |
fVerbose.FinishRun(); |
125 |
} |
126 |
|
127 |
void PamVMCApplication::AddIons(){ |
128 |
|
129 |
fVerbose.AddIons(); |
130 |
//Arguments are: |
131 |
//name |
132 |
//Z (atomic number) |
133 |
//A (atomic mass) |
134 |
//Q (charge eplus) |
135 |
//exitation exitation energy [GeV] 0. if in ground state |
136 |
//mass [GeV], if not specified, calculated approx |
137 |
|
138 |
gMC->DefineIon("He3",2,3,2,0.,2.808); |
139 |
gMC->DefineIon("He4",2,4,2,0.,3.727); |
140 |
|
141 |
//gMC->DefineIon("He7",2,7,2,0.); |
142 |
//gMC->DefineIon("Boron",5,10,5,0.); |
143 |
//gMC->DefineIon("Carbon",6,12,6,0.); |
144 |
} |
145 |
|
146 |
|
147 |
void PamVMCApplication::ConstructGeometry() |
148 |
{ |
149 |
// Construct geometry using detector contruction class |
150 |
|
151 |
fVerbose.ConstructGeometry(); |
152 |
new TGeoManager("PAM_GEOM","PAMELA GEOMETRY"); |
153 |
fdetector->ConstructGeometry(); |
154 |
//TGeoManager::Import("/home/pamela/PamCAL210508/gp2tgeo.root"); |
155 |
gGeoManager->CloseGeometry(); |
156 |
gMC->SetRootGeometry(); |
157 |
|
158 |
cout<<"!!CONSTRUCT GEOMETRY!!"<<endl; |
159 |
fdetector->ConstructCuts(); |
160 |
|
161 |
} |
162 |
|
163 |
void PamVMCApplication::InitGeometry() |
164 |
{ |
165 |
// Initialize geometry |
166 |
|
167 |
cout<<"!!SETUP CUTS"<<endl; |
168 |
//fdetector->InitGeometry(); |
169 |
|
170 |
fVerbose.InitGeometry(); |
171 |
} |
172 |
|
173 |
|
174 |
void PamVMCApplication::GeneratePrimaries() |
175 |
{ |
176 |
// Fill the user stack (derived from TVirtualMCStack) with primary particles. |
177 |
|
178 |
fPrimaryGenerator->GeneratePrimary(); |
179 |
} |
180 |
|
181 |
void PamVMCApplication::BeginEvent() |
182 |
{ |
183 |
// User actions at beginning of event |
184 |
PamVMCSDMgr::Instance()->PreEvent(); |
185 |
fEventNo++; |
186 |
} |
187 |
|
188 |
void PamVMCApplication::BeginPrimary() |
189 |
{ |
190 |
// User actions at beginning of a primary track |
191 |
fPrimaryGenerator->SetGood(kTRUE); |
192 |
fVerbose.BeginPrimary(); |
193 |
} |
194 |
|
195 |
void PamVMCApplication::PreTrack() |
196 |
{ |
197 |
// User actions at beginning of each track |
198 |
|
199 |
} |
200 |
|
201 |
|
202 |
#define CAVITY_X 8.07 |
203 |
#define CAVITY_Y 6.57 |
204 |
#define ZCAVITY_MIN 27.399 |
205 |
#define ZCAVITY_MAX 71.059 |
206 |
|
207 |
|
208 |
Bool_t PamVMCApplication::IsInsideCavity(){ |
209 |
Double_t x,y,z; |
210 |
gMC->TrackPosition(x,y,z); |
211 |
if( (z<ZCAVITY_MIN) || (z>ZCAVITY_MAX)) return kTRUE; |
212 |
if( (TMath::Abs(x) > CAVITY_X) || (TMath::Abs(y) > CAVITY_Y)) return kFALSE; |
213 |
return kTRUE; |
214 |
} |
215 |
|
216 |
|
217 |
void PamVMCApplication::Stepping() |
218 |
{ |
219 |
if (fStack->GetCurrentTrack()->IsPrimary()){ |
220 |
if(!IsInsideCavity()) fPrimaryGenerator->SetGood(kFALSE); |
221 |
} |
222 |
|
223 |
// User actions at each step |
224 |
fVerbose.Stepping(); |
225 |
PamVMCDetectorSD* temp=(PamVMCDetectorSD*) PamVMCSDMgr::Instance()->GetSD(gMC->CurrentVolName()); |
226 |
if(temp){ |
227 |
fdstatus=INSIDE; |
228 |
if(gMC->IsTrackEntering()){ fdstatus=ENTERING; } |
229 |
if(gMC->IsTrackExiting() || gMC->IsTrackOut() || gMC->IsTrackStop() ) { fdstatus=EXITING;} |
230 |
temp->FillHit(fdstatus,gMC,fStack->GetCurrentTrack()->IsPrimary()); |
231 |
} |
232 |
|
233 |
} |
234 |
|
235 |
void PamVMCApplication::PostTrack() |
236 |
{ |
237 |
// User actions after finishing of each track |
238 |
|
239 |
} |
240 |
|
241 |
void PamVMCApplication::FinishPrimary() |
242 |
{ |
243 |
// User actions after finishing of a primary track |
244 |
//fPrimaryGenerator->SetGood(PamVMCVolCrossMgr::Instance()->IsTrackGood()); |
245 |
//PamVMCVolCrossMgr::Instance()->Reset(); |
246 |
fVerbose.FinishPrimary(); |
247 |
} |
248 |
|
249 |
void PamVMCApplication::FinishEvent() |
250 |
{ |
251 |
// User actions after finishing of an event |
252 |
|
253 |
|
254 |
|
255 |
PamVMCSDMgr::Instance()->Digitize(); |
256 |
//EventNo needs for trigger, particle PDG needs for TOF.. |
257 |
PamVMCDigMgr::Instance()->Digitize(fEventNo,fPrimaryGenerator->GetParticle()); |
258 |
|
259 |
PamVMCSDMgr::Instance()->Compress(); |
260 |
|
261 |
PamVMCRawMgr::Instance()->WriteEvent(); |
262 |
|
263 |
fRootManager.Fill(); |
264 |
|
265 |
fPrimaryGenerator->ClearPrimCol(); |
266 |
|
267 |
PamVMCSDMgr::Instance()->Clear(); |
268 |
|
269 |
fStack->Reset(); |
270 |
|
271 |
} |
272 |
|
273 |
void PamVMCApplication::FinishRun() |
274 |
{ |
275 |
fVerbose.FinishRun(); |
276 |
|
277 |
fRootManager.WriteAll(); |
278 |
|
279 |
PamVMCDigMgr::Instance()->FinishRun(); //write RunTrailer to buffer |
280 |
|
281 |
PamVMCRawMgr::Instance()->FinishRun(); //write RunTrailer to file and close; |
282 |
|
283 |
PamVMCDigMgr::Instance()->PrintCollections(); |
284 |
|
285 |
} |
286 |
|
287 |
#if ROOT_VERSION_CODE < 333572 |
288 |
void PamVMCApplication::Field(const Double_t* x, Double_t* b) const |
289 |
{ |
290 |
PamVMCFieldMgr::Instance()->Field(x,b); |
291 |
} |
292 |
#endif |