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

Contents of /PamVMC/src/PamVMCApplication.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Fri Jun 12 18:39:29 2009 UTC (15 years, 8 months ago) by pam-rm2
Branch: MAIN
CVS Tags: v1r0
Changes since 1.3: +59 -31 lines
- Introduced user-defined names of output files and random seeds number.
Users can do it use options of PamVMCApplication constructor:
PamVMCApplication(const char* name,  const char *title, const char*
filename="pamtest", Int_t seed=0).
The Random object that I use is TRandom3 object which has astronomical
large period (in case of default initialization 0). All random generators
in the code use this object by calling of gRandom singleton which keeps
it.

- Corrected TOF digitization routine. No problems with TDC hits due to
hadronic interactions anymore.

- Some small changes was done to compile code under Root 5.23. +
geant4_vmc v. 2.6 without any warnings

- Some classes of PamG4RunConfiguartion was changed for geant4_vmc v.
2.6.Some obsolete classes was deleted as soon as developers implemented
regions.

- Navigation was changed from "geomRootToGeant4" to "geomRoot", because on
VMC web page written that as soon as Geant4 has no option ONLY/MANY
translation of overlapped geometry to Geant4 through VGM could be wrong.
I'd like to stay with Root navigation:
http://root.cern.ch/root/vmc/Geant4VMC.html. This should be default
option.

- New Tracker digitization routine written by Sergio was implemented

- PamVMC again became compatible with geant4_vmc v.2.5 and ROOT 5.20.
 The problem was that ROOT developers introduced in TVirtualMC class a new
method SetMagField and new base class:TVirtualMagField from which
user-defined classes shoukd be derived

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
52 fdetector = new PamVMCDetPamela();
53
54 PamVMCFieldMgr::Instance()->LoadField();
55
56 TString fname=filename; fname+=".pam";
57
58 PamVMCRawMgr::Instance()-> CreateOutFile(fname.Data());
59 }
60
61
62 PamVMCApplication::~PamVMCApplication()
63 {
64 // Destructor
65 delete frandom;
66 delete fStack;
67 delete fdetector;
68 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 gROOT->LoadMacro(setup);
81 gInterpreter->ProcessLine("Config()");
82 gMC->SetStack(fStack);
83 gMC->SetRandom(frandom);
84
85 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
92 #if ROOT_VERSION_CODE >= 333572
93 gMC->SetMagField(PamVMCFieldMgr::Instance());
94 cout<<"Magnetic field setted"<<endl;
95 #endif
96
97 fdetector->InitMC();
98
99 // fdetector->Print();
100
101 PamVMCSDMgr::Instance()->Register();
102
103 PamVMCDigMgr::Instance()->Initialize(gMC->GetRandom());
104
105 PamVMCRawMgr::Instance()->WriteToFile();
106
107 fPrimaryGenerator->SetRandom(gMC->GetRandom());
108 fPrimaryGenerator->Register();
109
110 std::cout<<"LIST OF ACTIVE SD'S:"<<std::endl;
111
112 PamVMCSDMgr::Instance()->Print();
113 }
114
115 void PamVMCApplication::RunMC(Int_t nofEvents)
116 {
117 // MC run.
118
119 fVerbose.RunMC(nofEvents);
120
121 gMC->ProcessRun(nofEvents);
122
123 fVerbose.FinishRun();
124 }
125
126 void PamVMCApplication::AddIons(){
127
128 fVerbose.AddIons();
129 //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 }
144
145
146 void PamVMCApplication::ConstructGeometry()
147 {
148 // Construct geometry using detector contruction class
149
150 fVerbose.ConstructGeometry();
151 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 }
161
162 void PamVMCApplication::InitGeometry()
163 {
164 // Initialize geometry
165
166 cout<<"!!SETUP CUTS"<<endl;
167 //fdetector->InitGeometry();
168
169 fVerbose.InitGeometry();
170 }
171
172
173 void PamVMCApplication::GeneratePrimaries()
174 {
175 // Fill the user stack (derived from TVirtualMCStack) with primary particles.
176
177 fPrimaryGenerator->GeneratePrimary();
178 }
179
180 void PamVMCApplication::BeginEvent()
181 {
182 // User actions at beginning of event
183 PamVMCSDMgr::Instance()->PreEvent();
184 fEventNo++;
185 }
186
187 void PamVMCApplication::BeginPrimary()
188 {
189 // User actions at beginning of a primary track
190 fPrimaryGenerator->SetGood(kTRUE);
191 fVerbose.BeginPrimary();
192 }
193
194 void PamVMCApplication::PreTrack()
195 {
196 // User actions at beginning of each track
197
198 }
199
200
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 void PamVMCApplication::Stepping()
217 {
218 if (fStack->GetCurrentTrack()->IsPrimary()){
219 if(!IsInsideCavity()) fPrimaryGenerator->SetGood(kFALSE);
220 }
221
222 // User actions at each step
223 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 temp->FillHit(fdstatus,gMC,fStack->GetCurrentTrack()->IsPrimary());
230 }
231
232 }
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 //fPrimaryGenerator->SetGood(PamVMCVolCrossMgr::Instance()->IsTrackGood());
244 //PamVMCVolCrossMgr::Instance()->Reset();
245 fVerbose.FinishPrimary();
246 }
247
248 void PamVMCApplication::FinishEvent()
249 {
250 // User actions after finishing of an event
251
252
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
260 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
276 fRootManager.WriteAll();
277
278 PamVMCDigMgr::Instance()->FinishRun(); //write RunTrailer to buffer
279
280 PamVMCRawMgr::Instance()->FinishRun(); //write RunTrailer to file and close;
281
282 PamVMCDigMgr::Instance()->PrintCollections();
283
284 }
285
286 #if ROOT_VERSION_CODE < 333572
287 void PamVMCApplication::Field(const Double_t* x, Double_t* b) const
288 {
289 PamVMCFieldMgr::Instance()->Field(x,b);
290 }
291 #endif

  ViewVC Help
Powered by ViewVC 1.1.23