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, UInt_t seed) |
33 |
: TVirtualMCApplication(name,title), |
34 |
fEventNo(0), |
35 |
fVerbose(2), |
36 |
fStack(0), |
37 |
fdetector(0), |
38 |
//fPrimaryGenerator(0,seed), |
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, seed); |
48 |
|
49 |
fdetector = new PamVMCDetPamela(); |
50 |
|
51 |
PamVMCFieldMgr::Instance()->LoadField(); |
52 |
|
53 |
} |
54 |
|
55 |
|
56 |
|
57 |
PamVMCApplication::PamVMCApplication() |
58 |
: TVirtualMCApplication(), |
59 |
fEventNo(0), |
60 |
fVerbose(0), |
61 |
fStack(0), |
62 |
fdetector(0), |
63 |
fPrimaryGenerator(0), |
64 |
fRootManager() |
65 |
{ |
66 |
// Default constructor |
67 |
} |
68 |
|
69 |
|
70 |
PamVMCApplication::~PamVMCApplication() |
71 |
{ |
72 |
// Destructor |
73 |
|
74 |
delete fStack; |
75 |
delete fdetector; |
76 |
delete fPrimaryGenerator; |
77 |
delete gMC; |
78 |
gMC = 0; |
79 |
} |
80 |
|
81 |
|
82 |
void PamVMCApplication::InitMC(const char* setup, const char *filename, UInt_t seed ) |
83 |
{ |
84 |
// Initialize MC. |
85 |
|
86 |
fVerbose.InitMC(); |
87 |
|
88 |
gROOT->LoadMacro(setup); |
89 |
gInterpreter->ProcessLine("Config()"); |
90 |
gMC->SetStack(fStack); |
91 |
std::cout<<"!!! BEFORE INIT GMC"<<std::endl; |
92 |
|
93 |
gMC->Init(); |
94 |
cout<<"INIT MC"<<endl; |
95 |
gMC->BuildPhysics(); |
96 |
cout<<"PHYSICS BUILDED"<<endl; |
97 |
|
98 |
PamVMCRawMgr::Instance(filename); |
99 |
|
100 |
// Initialize seed for random generation // Cecilia |
101 |
PamVMCDigMgr::Instance(seed); |
102 |
|
103 |
fdetector->InitMC(); |
104 |
// fdetector->Print(); |
105 |
|
106 |
PamVMCSDMgr::Instance()->Register(); |
107 |
|
108 |
PamVMCDigMgr::Instance()->LoadCalib(); |
109 |
PamVMCRawMgr::Instance(filename)->WriteToFile(); |
110 |
|
111 |
fPrimaryGenerator->Register(); |
112 |
|
113 |
std::cout<<"LIST OF ACTIVE SD'S:"<<std::endl; |
114 |
PamVMCSDMgr::Instance()->Print(); |
115 |
} |
116 |
|
117 |
|
118 |
void PamVMCApplication::RunMC(Int_t nofEvents) |
119 |
{ |
120 |
// MC run. |
121 |
|
122 |
fVerbose.RunMC(nofEvents); |
123 |
|
124 |
gMC->ProcessRun(nofEvents); |
125 |
|
126 |
fVerbose.FinishRun(); |
127 |
} |
128 |
|
129 |
void PamVMCApplication::AddIons(){ |
130 |
|
131 |
fVerbose.AddIons(); |
132 |
gMC->DefineIon("He4",2,4,1,0.); |
133 |
gMC->DefineIon("Boron",5,10,1,0.); |
134 |
gMC->DefineIon("Carbon",6,12,1,0.); |
135 |
} |
136 |
|
137 |
|
138 |
void PamVMCApplication::ConstructGeometry() |
139 |
{ |
140 |
// Construct geometry using detector contruction class |
141 |
|
142 |
fVerbose.ConstructGeometry(); |
143 |
new TGeoManager("PAM_GEOM","PAMELA GEOMETRY"); |
144 |
fdetector->ConstructGeometry(); |
145 |
//TGeoManager::Import("/home/pamela/PamCAL210508/gp2tgeo.root"); |
146 |
gGeoManager->CloseGeometry(); |
147 |
gMC->SetRootGeometry(); |
148 |
|
149 |
cout<<"!!CONSTRUCT GEOMETRY!!"<<endl; |
150 |
fdetector->ConstructCuts(); |
151 |
|
152 |
} |
153 |
|
154 |
void PamVMCApplication::InitGeometry() |
155 |
{ |
156 |
// Initialize geometry |
157 |
|
158 |
cout<<"!!SETUP CUTS"<<endl; |
159 |
//fdetector->InitGeometry(); |
160 |
|
161 |
fVerbose.InitGeometry(); |
162 |
} |
163 |
|
164 |
|
165 |
void PamVMCApplication::GeneratePrimaries() |
166 |
{ |
167 |
// Fill the user stack (derived from TVirtualMCStack) with primary particles. |
168 |
|
169 |
fPrimaryGenerator->GeneratePrimary(); |
170 |
//fPrimaryGenerator->Print(); |
171 |
} |
172 |
|
173 |
void PamVMCApplication::BeginEvent() |
174 |
{ |
175 |
// User actions at beginning of event |
176 |
PamVMCSDMgr::Instance()->PreEvent(); |
177 |
fEventNo++; |
178 |
} |
179 |
|
180 |
void PamVMCApplication::BeginPrimary() |
181 |
{ |
182 |
// User actions at beginning of a primary track |
183 |
|
184 |
fVerbose.BeginPrimary(); |
185 |
} |
186 |
|
187 |
void PamVMCApplication::PreTrack() |
188 |
{ |
189 |
// User actions at beginning of each track |
190 |
|
191 |
} |
192 |
|
193 |
void PamVMCApplication::Stepping() |
194 |
{ |
195 |
if (fStack->GetCurrentTrack()->IsPrimary()){ |
196 |
PamVMCVolCross* tmp=(PamVMCVolCross*)PamVMCVolCrossMgr::Instance()->GetSD(gMC->CurrentVolName()); |
197 |
if (tmp){ |
198 |
tmp->CrossVol(); |
199 |
} |
200 |
} |
201 |
// User actions at each step |
202 |
fVerbose.Stepping(); |
203 |
PamVMCDetectorSD* temp=(PamVMCDetectorSD*) PamVMCSDMgr::Instance()->GetSD(gMC->CurrentVolName()); |
204 |
if(temp){ |
205 |
fdstatus=INSIDE; |
206 |
if(gMC->IsTrackEntering()){ fdstatus=ENTERING; } |
207 |
if(gMC->IsTrackExiting() || gMC->IsTrackOut() || gMC->IsTrackStop() ) { fdstatus=EXITING;} |
208 |
temp->FillHit(fdstatus,gMC); |
209 |
} |
210 |
|
211 |
} |
212 |
|
213 |
void PamVMCApplication::PostTrack() |
214 |
{ |
215 |
// User actions after finishing of each track |
216 |
|
217 |
} |
218 |
|
219 |
void PamVMCApplication::FinishPrimary() |
220 |
{ |
221 |
// User actions after finishing of a primary track |
222 |
fPrimaryGenerator->SetGood(PamVMCVolCrossMgr::Instance()->IsTrackGood()); |
223 |
PamVMCVolCrossMgr::Instance()->Reset(); |
224 |
fVerbose.FinishPrimary(); |
225 |
} |
226 |
|
227 |
void PamVMCApplication::FinishEvent() |
228 |
{ |
229 |
// User actions after finishing of an event |
230 |
|
231 |
|
232 |
|
233 |
PamVMCSDMgr::Instance()->Digitize(); |
234 |
//EventNo needs for trigger, particle PDG needs for TOF.. |
235 |
PamVMCDigMgr::Instance()->Digitize(fEventNo,fPrimaryGenerator->GetParticle()); |
236 |
|
237 |
PamVMCSDMgr::Instance()->Compress(); |
238 |
|
239 |
PamVMCRawMgr::Instance()->WriteEvent(); |
240 |
|
241 |
fRootManager.Fill(); |
242 |
|
243 |
fPrimaryGenerator->ClearPrimCol(); |
244 |
|
245 |
PamVMCSDMgr::Instance()->Clear(); |
246 |
|
247 |
fStack->Reset(); |
248 |
|
249 |
//getchar(); |
250 |
|
251 |
} |
252 |
|
253 |
void PamVMCApplication::FinishRun() |
254 |
{ |
255 |
fVerbose.FinishRun(); |
256 |
|
257 |
fRootManager.WriteAll(); |
258 |
|
259 |
PamVMCDigMgr::Instance()->FinishRun(); //write RunTrailer to buffer |
260 |
|
261 |
PamVMCRawMgr::Instance()->FinishRun(); //write RunTrailer to file and close; |
262 |
|
263 |
PamVMCDigMgr::Instance()->PrintCollections(); |
264 |
|
265 |
} |
266 |
|
267 |
void PamVMCApplication::Field(const Double_t* x, Double_t* b) const |
268 |
{ |
269 |
PamVMCFieldMgr::Instance()->Field(x,b); |
270 |
} |