/[PAMELA software]/PamVMC/src/PamVMCApplication.cxx
ViewVC logotype

Contents of /PamVMC/src/PamVMCApplication.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Thu Feb 19 18:43:14 2009 UTC (15 years, 9 months ago) by nikolas
Branch: MAIN
Changes since 1.2: +25 -25 lines
Almost done ....

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)
33 : TVirtualMCApplication(name,title),
34 fEventNo(0),
35 fVerbose(2),
36 fStack(0),
37 fdetector(0),
38 fPrimaryGenerator(0),
39 fRootManager("pamtest",kWrite)
40 {
41 // Standard constructor
42
43 // Create a user stack
44 fStack = new PamVMCStack(1000);
45
46
47 // Create a primary generator
48 fPrimaryGenerator = new PamVMCPrimaryGenerator(fStack);
49
50
51 fdetector = new PamVMCDetPamela();
52
53 PamVMCFieldMgr::Instance()->LoadField();
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 PamVMCApplication::~PamVMCApplication()
70 {
71 // Destructor
72
73 delete fStack;
74 delete fdetector;
75 delete fPrimaryGenerator;
76 delete gMC;
77 gMC = 0;
78 }
79
80
81 void PamVMCApplication::InitMC(const char* setup)
82 {
83 // Initialize MC.
84
85 fVerbose.InitMC();
86
87 gROOT->LoadMacro(setup);
88 gInterpreter->ProcessLine("Config()");
89 gMC->SetStack(fStack);
90 std::cout<<"!!! BEFORE INIT GMC"<<std::endl;
91
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)
115 {
116 // MC run.
117
118 fVerbose.RunMC(nofEvents);
119
120 gMC->ProcessRun(nofEvents);
121
122 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()
135 {
136 // Construct geometry using detector contruction class
137
138 fVerbose.ConstructGeometry();
139 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()
151 {
152 // Initialize geometry
153
154 cout<<"!!SETUP CUTS"<<endl;
155 //fdetector->InitGeometry();
156
157 fVerbose.InitGeometry();
158 }
159
160
161 void PamVMCApplication::GeneratePrimaries()
162 {
163 // Fill the user stack (derived from TVirtualMCStack) with primary particles.
164
165 fPrimaryGenerator->GeneratePrimary();
166 }
167
168 void PamVMCApplication::BeginEvent()
169 {
170 // User actions at beginning of event
171 PamVMCSDMgr::Instance()->PreEvent();
172 fEventNo++;
173 }
174
175 void PamVMCApplication::BeginPrimary()
176 {
177 // User actions at beginning of a primary track
178
179 fVerbose.BeginPrimary();
180 }
181
182 void PamVMCApplication::PreTrack()
183 {
184 // User actions at beginning of each track
185
186 }
187
188 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
197 fVerbose.Stepping();
198 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()
209 {
210 // User actions after finishing of each track
211
212 }
213
214 void PamVMCApplication::FinishPrimary()
215 {
216 // User actions after finishing of a primary track
217 fPrimaryGenerator->SetGood(PamVMCVolCrossMgr::Instance()->IsTrackGood());
218 PamVMCVolCrossMgr::Instance()->Reset();
219 fVerbose.FinishPrimary();
220 }
221
222 void PamVMCApplication::FinishEvent()
223 {
224 // User actions after finishing of an event
225
226
227
228 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 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::FinishRun()
247 {
248 fVerbose.FinishRun();
249
250 fRootManager.WriteAll();
251
252 PamVMCDigMgr::Instance()->FinishRun(); //write RunTrailer to buffer
253
254 PamVMCRawMgr::Instance()->FinishRun(); //write RunTrailer to file and close;
255
256 PamVMCDigMgr::Instance()->PrintCollections();
257
258 }
259
260 void PamVMCApplication::Field(const Double_t* x, Double_t* b) const
261 {
262 PamVMCFieldMgr::Instance()->Field(x,b);
263 }

  ViewVC Help
Powered by ViewVC 1.1.23