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

Annotation of /PamVMC/src/PamVMCApplication.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide 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 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     PamVMCApplication::PamVMCApplication(const char *name, const char *title)
33     : 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     fRootManager("pamtest",kWrite)
40 nikolas 1.1 {
41     // Standard constructor
42    
43     // Create a user stack
44 nikolas 1.2 fStack = new PamVMCStack(1000);
45 nikolas 1.1
46    
47     // Create a primary generator
48     fPrimaryGenerator = new PamVMCPrimaryGenerator(fStack);
49    
50 nikolas 1.2
51     fdetector = new PamVMCDetPamela();
52    
53     PamVMCFieldMgr::Instance()->LoadField();
54 nikolas 1.1 }
55    
56    
57     PamVMCApplication::PamVMCApplication()
58     : TVirtualMCApplication(),
59     fEventNo(0),
60     fVerbose(0),
61     fStack(0),
62 nikolas 1.2 fdetector(0),
63     fPrimaryGenerator(0),
64     fRootManager()
65 nikolas 1.1 {
66     // Default constructor
67     }
68    
69     PamVMCApplication::~PamVMCApplication()
70     {
71     // Destructor
72 nikolas 1.2
73 nikolas 1.1 delete fStack;
74 nikolas 1.2 delete fdetector;
75 nikolas 1.1 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 nikolas 1.3 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 nikolas 1.1 }
113    
114     void PamVMCApplication::RunMC(Int_t nofEvents)
115     {
116 nikolas 1.2 // MC run.
117 nikolas 1.1
118     fVerbose.RunMC(nofEvents);
119    
120     gMC->ProcessRun(nofEvents);
121    
122 nikolas 1.2 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 nikolas 1.1 }
132    
133 nikolas 1.2
134 nikolas 1.1 void PamVMCApplication::ConstructGeometry()
135     {
136 nikolas 1.2 // Construct geometry using detector contruction class
137 nikolas 1.1
138     fVerbose.ConstructGeometry();
139 nikolas 1.2 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 nikolas 1.1 }
149    
150     void PamVMCApplication::InitGeometry()
151     {
152 nikolas 1.2 // Initialize geometry
153 nikolas 1.1
154 nikolas 1.2 cout<<"!!SETUP CUTS"<<endl;
155     //fdetector->InitGeometry();
156    
157     fVerbose.InitGeometry();
158 nikolas 1.1 }
159    
160    
161     void PamVMCApplication::GeneratePrimaries()
162     {
163 nikolas 1.2 // Fill the user stack (derived from TVirtualMCStack) with primary particles.
164 nikolas 1.1
165 nikolas 1.2 fPrimaryGenerator->GeneratePrimary();
166 nikolas 1.1 }
167    
168     void PamVMCApplication::BeginEvent()
169     {
170     // User actions at beginning of event
171 nikolas 1.2 PamVMCSDMgr::Instance()->PreEvent();
172 nikolas 1.1 fEventNo++;
173 nikolas 1.2 }
174 nikolas 1.1
175     void PamVMCApplication::BeginPrimary()
176     {
177     // User actions at beginning of a primary track
178    
179 nikolas 1.2 fVerbose.BeginPrimary();
180 nikolas 1.1 }
181    
182     void PamVMCApplication::PreTrack()
183     {
184     // User actions at beginning of each track
185 nikolas 1.2
186 nikolas 1.1 }
187    
188     void PamVMCApplication::Stepping()
189     {
190 nikolas 1.2 if (fStack->GetCurrentTrack()->IsPrimary()){
191     PamVMCVolCross* tmp=(PamVMCVolCross*)PamVMCVolCrossMgr::Instance()->GetSD(gMC->CurrentVolName());
192     if (tmp){
193     tmp->CrossVol();
194     }
195     }
196 nikolas 1.1 // User actions at each step
197 nikolas 1.2 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 nikolas 1.1 }
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 nikolas 1.2 fPrimaryGenerator->SetGood(PamVMCVolCrossMgr::Instance()->IsTrackGood());
218     PamVMCVolCrossMgr::Instance()->Reset();
219     fVerbose.FinishPrimary();
220 nikolas 1.1 }
221    
222     void PamVMCApplication::FinishEvent()
223     {
224     // User actions after finishing of an event
225    
226 nikolas 1.2
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 nikolas 1.1
234 nikolas 1.2 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 nikolas 1.1
250 nikolas 1.2 fRootManager.WriteAll();
251    
252     PamVMCDigMgr::Instance()->FinishRun(); //write RunTrailer to buffer
253    
254     PamVMCRawMgr::Instance()->FinishRun(); //write RunTrailer to file and close;
255 nikolas 1.1
256 nikolas 1.2 PamVMCDigMgr::Instance()->PrintCollections();
257 nikolas 1.1
258 nikolas 1.2 }
259 nikolas 1.1
260     void PamVMCApplication::Field(const Double_t* x, Double_t* b) const
261     {
262 nikolas 1.2 PamVMCFieldMgr::Instance()->Field(x,b);
263 nikolas 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.23