1 |
nikolas |
1.1 |
// $Id: PamVMCApplication.cxx,v 1.0 2007/06/01 |
2 |
|
|
// |
3 |
|
|
// Geant4 ExampleN06 adapted to Virtual Monte Carlo |
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 "PamVMCCaloSD.h" |
16 |
|
|
#include "PamVMCTrkSD.h" |
17 |
|
|
#include "PamVMCTofSD.h" |
18 |
|
|
#include "PamVMCCardSD.h" |
19 |
|
|
#include "PamVMCCasSD.h" |
20 |
|
|
#include "PamVMCCasSD.h" |
21 |
|
|
#include "PamVMCS4SD.h" |
22 |
|
|
//#include "PamVMCDetectorHit.h" |
23 |
|
|
//#include "PamVMCCalorHit.h" |
24 |
|
|
#include "PamVMCStack.h" |
25 |
|
|
#include "PamVMCDetectorConstruction.h" |
26 |
|
|
#include "PamVMCPrimaryGenerator.h" |
27 |
|
|
|
28 |
|
|
ClassImp(PamVMCApplication) |
29 |
|
|
|
30 |
|
|
PamVMCApplication::PamVMCApplication(const char *name, const char *title) |
31 |
|
|
: TVirtualMCApplication(name,title), |
32 |
|
|
fEventNo(0), |
33 |
|
|
fVerbose(0), |
34 |
|
|
fStack(0), |
35 |
|
|
fDetConstruction(0), |
36 |
|
|
fPrimaryGenerator(0), |
37 |
|
|
fRootManager("pamtest",kWrite) |
38 |
|
|
//, fdetmap(0) |
39 |
|
|
{ |
40 |
|
|
// Standard constructor |
41 |
|
|
|
42 |
|
|
// Create a user stack |
43 |
|
|
fStack = new PamVMCStack(1000); |
44 |
|
|
|
45 |
|
|
// Create detector construction |
46 |
|
|
fDetConstruction = new PamVMCDetectorConstruction(); |
47 |
|
|
|
48 |
|
|
// Create a primary generator |
49 |
|
|
fPrimaryGenerator = new PamVMCPrimaryGenerator(fStack); |
50 |
|
|
|
51 |
|
|
//fCaloSD = new PamVMCCaloSD(); |
52 |
|
|
|
53 |
|
|
// std::cout <<"!!!!!!!!APPLICATION CREATED!!!"<<std::endl; |
54 |
|
|
// Create a tracker SD |
55 |
|
|
|
56 |
|
|
//fTrackerSD = new PamVMCTrackerSD("PamVMCTracker", fDetConstruction); |
57 |
|
|
|
58 |
|
|
// Create a tof SD |
59 |
|
|
|
60 |
|
|
//fTofSD = new PamVMCTofSD("PamVMCTof", fDetConstruction); |
61 |
|
|
|
62 |
|
|
#ifdef PAMFIELD |
63 |
|
|
// Load the PAMELA magnetic field |
64 |
|
|
|
65 |
|
|
std::string pamcal=getenv("PAM_CALIB"); pamcal+="/trk-param/field_param-0/"; |
66 |
|
|
std::cout << "PAMELA env: " << pamcal << std::endl; |
67 |
|
|
pamfield.LoadField(pamcal.c_str()); |
68 |
|
|
#endif |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
|
72 |
|
|
PamVMCApplication::PamVMCApplication() |
73 |
|
|
: TVirtualMCApplication(), |
74 |
|
|
fEventNo(0), |
75 |
|
|
fVerbose(0), |
76 |
|
|
fStack(0), |
77 |
|
|
fDetConstruction(0), |
78 |
|
|
fPrimaryGenerator(0), |
79 |
|
|
fRootManager() |
80 |
|
|
{ |
81 |
|
|
// Default constructor |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
PamVMCApplication::~PamVMCApplication() |
85 |
|
|
{ |
86 |
|
|
// Destructor |
87 |
|
|
|
88 |
|
|
delete fStack; |
89 |
|
|
delete fDetConstruction; |
90 |
|
|
delete fPrimaryGenerator; |
91 |
|
|
delete gMC; |
92 |
|
|
gMC = 0; |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
// |
96 |
|
|
// public methods |
97 |
|
|
// |
98 |
|
|
|
99 |
|
|
void PamVMCApplication::InitMC(const char* setup) |
100 |
|
|
{ |
101 |
|
|
// Initialize MC. |
102 |
|
|
|
103 |
|
|
fVerbose.InitMC(); |
104 |
|
|
|
105 |
|
|
gROOT->LoadMacro(setup); |
106 |
|
|
gInterpreter->ProcessLine("Config()"); |
107 |
|
|
gMC->SetStack(fStack); |
108 |
|
|
std::cout<<"!!! BEFORE INIT GMC"<<std::endl; |
109 |
|
|
gMC->Init(); |
110 |
|
|
|
111 |
|
|
gMC->BuildPhysics(); |
112 |
|
|
|
113 |
|
|
//Creating a KEYS for SD volume names: |
114 |
|
|
|
115 |
|
|
std::cout<<"!!!Creating PamVMCCaloSD object"<<std::endl; |
116 |
|
|
fdetmap.Add(new TObjString("CAST"), new PamVMCCaloSD() ); |
117 |
|
|
fdetmap.Add(new TObjString("S11Y"), new PamVMCTofSD("S11Y") ); |
118 |
|
|
fdetmap.Add(new TObjString("S12X"), new PamVMCTofSD("S12X") ); |
119 |
|
|
fdetmap.Add(new TObjString("S21X"), new PamVMCTofSD("S21X") ); |
120 |
|
|
fdetmap.Add(new TObjString("S22Y"), new PamVMCTofSD("S22Y") ); |
121 |
|
|
fdetmap.Add(new TObjString("S31Y"), new PamVMCTofSD("S31Y") ); |
122 |
|
|
fdetmap.Add(new TObjString("S32X"), new PamVMCTofSD("S32X") ); |
123 |
|
|
fdetmap.Add(new TObjString("TSPA"), new PamVMCTrkSD() ); |
124 |
|
|
fdetmap.Add(new TObjString("C1D1"), new PamVMCCardSD("C1D1") ); |
125 |
|
|
fdetmap.Add(new TObjString("C2D1"), new PamVMCCardSD("C2D1") ); |
126 |
|
|
fdetmap.Add(new TObjString("SID1"), new PamVMCCasSD() ); |
127 |
|
|
fdetmap.Add(new TObjString("MGSC"), new PamVMCCatSD() ); |
128 |
|
|
fdetmap.Add(new TObjString("S4"), new PamVMCS4SD() ); |
129 |
|
|
fdetmap.Add(new TObjString("NDTI"), new PamVMCNDSD() ); |
130 |
|
|
std::cout<<"!!!!PamVMCCaloSD object created"<<std::endl; |
131 |
|
|
//fdetmap.Print(); |
132 |
|
|
//Registration should be after inserting all detectors in fdetmap |
133 |
|
|
Register(); |
134 |
|
|
|
135 |
|
|
} |
136 |
|
|
|
137 |
|
|
void PamVMCApplication::RunMC(Int_t nofEvents) |
138 |
|
|
{ |
139 |
|
|
// MC run. |
140 |
|
|
|
141 |
|
|
fVerbose.RunMC(nofEvents); |
142 |
|
|
|
143 |
|
|
gMC->ProcessRun(nofEvents); |
144 |
|
|
|
145 |
|
|
fVerbose.FinishRun(); |
146 |
|
|
} |
147 |
|
|
|
148 |
|
|
|
149 |
|
|
void PamVMCApplication::ConstructGeometry() |
150 |
|
|
{ |
151 |
|
|
// Construct geometry using detector contruction class |
152 |
|
|
|
153 |
|
|
fVerbose.ConstructGeometry(); |
154 |
|
|
fDetConstruction->ConstructGeometry(); |
155 |
|
|
|
156 |
|
|
} |
157 |
|
|
|
158 |
|
|
void PamVMCApplication::InitGeometry() |
159 |
|
|
{ |
160 |
|
|
// Initialize geometry |
161 |
|
|
|
162 |
|
|
fVerbose.InitGeometry(); |
163 |
|
|
//fCalorimeterSD->Initialize(); |
164 |
|
|
//fTrackerSD->Initialize(); |
165 |
|
|
//fTofSD->Initialize(); |
166 |
|
|
|
167 |
|
|
//Initialization of HitCollestions in Root file: |
168 |
|
|
std::cout<<"!!!! Before registration HitCol!!!"<<std::endl; |
169 |
|
|
|
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
|
173 |
|
|
void PamVMCApplication::GeneratePrimaries() |
174 |
|
|
{ |
175 |
|
|
// Fill the user stack (derived from TVirtualMCStack) with primary particles. |
176 |
|
|
|
177 |
|
|
///// fVerbose.GeneratePrimaries(); |
178 |
|
|
|
179 |
|
|
fPrimaryGenerator->GeneratePrimaries(); |
180 |
|
|
} |
181 |
|
|
|
182 |
|
|
void PamVMCApplication::BeginEvent() |
183 |
|
|
{ |
184 |
|
|
// User actions at beginning of event |
185 |
|
|
|
186 |
|
|
///// fVerbose.BeginEvent(); |
187 |
|
|
|
188 |
|
|
//fCalorimeterSD->BeginOfEvent(); |
189 |
|
|
fEventNo++; |
190 |
|
|
} |
191 |
|
|
|
192 |
|
|
void PamVMCApplication::BeginPrimary() |
193 |
|
|
{ |
194 |
|
|
// User actions at beginning of a primary track |
195 |
|
|
|
196 |
|
|
fVerbose.BeginPrimary(); |
197 |
|
|
} |
198 |
|
|
|
199 |
|
|
void PamVMCApplication::PreTrack() |
200 |
|
|
{ |
201 |
|
|
// User actions at beginning of each track |
202 |
|
|
|
203 |
|
|
////// fVerbose.PreTrack(); |
204 |
|
|
|
205 |
|
|
} |
206 |
|
|
|
207 |
|
|
void PamVMCApplication::Stepping() |
208 |
|
|
{ |
209 |
|
|
|
210 |
|
|
// User actions at each step |
211 |
|
|
fVerbose.Stepping(); |
212 |
|
|
///std::cout<<"!!!! STEP"<<std::endl; |
213 |
|
|
|
214 |
|
|
// if (gMC->IsTrackAlive()){ |
215 |
|
|
PamVMCDetectorSD* temp=(PamVMCDetectorSD*) fdetmap(gMC->CurrentVolName()); |
216 |
|
|
if(temp){ |
217 |
|
|
fdstatus=INSIDE; |
218 |
|
|
if(gMC->IsTrackEntering()){ fdstatus=ENTERING; } |
219 |
|
|
if(gMC->IsTrackExiting() || gMC->IsTrackOut() || gMC->IsTrackStop() ) { fdstatus=EXITING;/* fStack->Print();*/} |
220 |
|
|
temp->FillHit(fdstatus,gMC); |
221 |
|
|
} |
222 |
|
|
// } |
223 |
|
|
|
224 |
|
|
} |
225 |
|
|
|
226 |
|
|
//void PamVMCApplication::FillTempHit(){ |
227 |
|
|
// Double_t pxin,pyin,pzin,ein; |
228 |
|
|
// gMC->TrackPosition(ftemphit.fXIN,ftemphit.fYIN,ftemphit.fZIN); |
229 |
|
|
// gMC->TrackMomentum(pxin,pyin,pzin,ein); |
230 |
|
|
|
231 |
|
|
// ftemphit.fPIN=sqrt(pxin*pxin + pyin*pyin + pzin*pzin); |
232 |
|
|
// ftemphit.fPDG= gMC->TrackPid(); |
233 |
|
|
// ftemphit.fEREL= gMC->Edep(); |
234 |
|
|
// ftemphit.fPATH= gMC->TrackStep(); |
235 |
|
|
// ftemphit.fTOF= gMC->TrackTime(); |
236 |
|
|
// ftemphit.fXOUT=ftemphit.fXIN; |
237 |
|
|
// ftemphit.fYOUT=ftemphit.fYIN; |
238 |
|
|
// ftemphit.fZOUT=ftemphit.fZIN; |
239 |
|
|
//} |
240 |
|
|
|
241 |
|
|
void PamVMCApplication::PostTrack() |
242 |
|
|
{ |
243 |
|
|
// User actions after finishing of each track |
244 |
|
|
|
245 |
|
|
|
246 |
|
|
///// fVerbose.PostTrack(); |
247 |
|
|
} |
248 |
|
|
|
249 |
|
|
void PamVMCApplication::FinishPrimary() |
250 |
|
|
{ |
251 |
|
|
// User actions after finishing of a primary track |
252 |
|
|
|
253 |
|
|
fVerbose.FinishPrimary(); |
254 |
|
|
} |
255 |
|
|
|
256 |
|
|
void PamVMCApplication::FinishEvent() |
257 |
|
|
{ |
258 |
|
|
// User actions after finishing of an event |
259 |
|
|
|
260 |
|
|
//fCalorimeterSD->GetCalorHitBuff()->Shrink(); |
261 |
|
|
/////fVerbose.FinishEvent(); |
262 |
|
|
fRootManager.Fill(); |
263 |
|
|
TMapIter *n= (TMapIter *)fdetmap.MakeIterator(); |
264 |
|
|
TObject *o; while( o=(TObject *) n->Next()) { |
265 |
|
|
((PamVMCDetectorSD *)fdetmap.GetValue(o))->ClearHitColl(); |
266 |
|
|
} |
267 |
|
|
// fCalorimeterSD->PrintTotal(); |
268 |
|
|
// std::cout<<"ENDCAL EVENT"<<std::endl; |
269 |
|
|
//fCalorimeterSD->EndOfEvent(); |
270 |
|
|
//fTrackerSD->EndOfEvent(); |
271 |
|
|
//fTofSD->EndOfEvent(); |
272 |
|
|
fStack->Reset(); |
273 |
|
|
} |
274 |
|
|
|
275 |
|
|
void PamVMCApplication::FinishRun() |
276 |
|
|
{ |
277 |
|
|
|
278 |
|
|
// fRootManager.Fill(); |
279 |
|
|
fVerbose.FinishRun(); |
280 |
|
|
|
281 |
|
|
fRootManager.WriteAll(); |
282 |
|
|
} |
283 |
|
|
void PamVMCApplication::Field(const Double_t* x, Double_t* b) const |
284 |
|
|
{ |
285 |
|
|
// Uniform magnetic field |
286 |
|
|
|
287 |
|
|
#ifdef PAMFIELD |
288 |
|
|
b[0] = pamfield.GetBX((float *)x); |
289 |
|
|
b[1] = pamfield.GetBY((float *)x); |
290 |
|
|
b[2] = pamfield.GetBZ((float *)x); |
291 |
|
|
cout<<b[0]<<" "<<b[1]<<" "<<b[2]<<endl; |
292 |
|
|
#else |
293 |
|
|
if(x) { for (Int_t i=0; i<3; i++) b[i] = 0.0; } else { b[0]=b[1]=b[2]=0.0; } |
294 |
|
|
|
295 |
|
|
#endif |
296 |
|
|
} |