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