ROOT  6.06/09
Reference Guide
TMCVerbose.cxx
Go to the documentation of this file.
1 // @(#)root/vmc:$Id$
2 // Author: Ivana Hrivnacova, 27/03/2002
3 
4 /*************************************************************************
5  * Copyright (C) 2006, Rene Brun and Fons Rademakers. *
6  * Copyright (C) 2002, ALICE Experiment at CERN. *
7  * All rights reserved. *
8  * *
9  * For the licensing terms see $ROOTSYS/LICENSE. *
10  * For the list of contributors see $ROOTSYS/README/CREDITS. *
11  *************************************************************************/
12 
13 #include "Riostream.h"
14 #include "TVirtualMC.h"
15 #include "TVirtualMCStack.h"
16 #include "TDatabasePDG.h"
17 #include "TParticlePDG.h"
18 #include "TArrayI.h"
19 
20 #include "TMCVerbose.h"
21 
22 //______________________________________________________________________________
23 //
24 // Class for printing detailed info from MC application.
25 // Defined levels:
26 // 0 no output
27 // 1 info up to event level
28 // 2 info up to tracking level
29 // 3 detailed info for each step
30 //______________________________________________________________________________
31 
32 
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// Standard constructor
37 /// ---
38 
40  : TObject(),
41  fLevel(level),
42  fStepNumber(0)
43 {
44 }
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Default constructor
48 /// ---
49 
51  : TObject(),
52  fLevel(0),
53  fStepNumber(0)
54 {
55 }
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// Destructor
59 /// ---
60 
62 {
63 }
64 
65 //
66 // private methods
67 //
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 /// Prints banner for track information
71 /// ---
72 
74 {
75  std::cout << std::endl;
76  for (Int_t i=0; i<10; i++) std::cout << "**********";
77  std::cout << std::endl;
78 }
79 
80 ////////////////////////////////////////////////////////////////////////////////
81 /// Prints track information
82 /// ---
83 
85 {
86  // Particle
87  //
88  std::cout << " Particle = ";
89  TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle(gMC->TrackPid());
90  if (particle)
91  std::cout << particle->GetName() << " ";
92  else
93  std::cout << "unknown" << " ";
94 
95  // Track ID
96  //
97  std::cout << " Track ID = " << gMC->GetStack()->GetCurrentTrackNumber() << " ";
98 
99  // Parent ID
100  //
101  std::cout << " Parent ID = " << gMC->GetStack()->GetCurrentParentTrackNumber();
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Prints the header for stepping information
106 /// ---
107 
109 {
110  std::cout << "Step# "
111  << "X(cm) "
112  << "Y(cm) "
113  << "Z(cm) "
114  << "KinE(MeV) "
115  << "dE(MeV) "
116  << "Step(cm) "
117  << "TrackL(cm) "
118  << "Volume "
119  << "Process "
120  << std::endl;
121 }
122 
123 //
124 // public methods
125 //
126 
127 ////////////////////////////////////////////////////////////////////////////////
128 /// Initialize MC info.
129 /// ---
130 
132 {
133  if (fLevel>0)
134  std::cout << "--- Init MC " << std::endl;
135 }
136 
137 ////////////////////////////////////////////////////////////////////////////////
138 /// MC run info.
139 /// ---
140 
141 void TMCVerbose::RunMC(Int_t nofEvents)
142 {
143  if (fLevel>0)
144  std::cout << "--- Run MC for " << nofEvents << " events" << std::endl;
145 }
146 
147 ////////////////////////////////////////////////////////////////////////////////
148 /// Finish MC run info.
149 /// ---
150 
152 {
153  if (fLevel>0)
154  std::cout << "--- Finish Run MC " << std::endl;
155 }
156 
157 ////////////////////////////////////////////////////////////////////////////////
158 /// Construct geometry info
159 /// ---
160 
162 {
163  if (fLevel>0)
164  std::cout << "--- Construct geometry " << std::endl;
165 }
166 
167 ////////////////////////////////////////////////////////////////////////////////
168 /// Construct geometry for optical physics info
169 /// ---
170 
172 {
173  if (fLevel>0)
174  std::cout << "--- Construct geometry for optical processes" << std::endl;
175 }
176 
177 ////////////////////////////////////////////////////////////////////////////////
178 /// Initialize geometry info
179 /// ---
180 
182 {
183  if (fLevel>0)
184  std::cout << "--- Init geometry " << std::endl;
185 }
186 
187 ////////////////////////////////////////////////////////////////////////////////
188 /// Add particles info
189 /// ---
190 
192 {
193  if (fLevel>0)
194  std::cout << "--- Add particles " << std::endl;
195 }
196 
197 ////////////////////////////////////////////////////////////////////////////////
198 /// Add ions info
199 /// ---
200 
202 {
203  if (fLevel>0)
204  std::cout << "--- Add ions " << std::endl;
205 }
206 
207 ////////////////////////////////////////////////////////////////////////////////
208 /// Generate primaries info
209 /// ---
210 
212 {
213  if (fLevel>0)
214  std::cout << "--- Generate primaries " << std::endl;
215 }
216 
217 ////////////////////////////////////////////////////////////////////////////////
218 /// Begin event info
219 /// ---
220 
222 {
223  if (fLevel>0)
224  std::cout << "--- Begin event " << std::endl;
225 }
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 /// Begin of a primary track info
229 /// ---
230 
232 {
233  if (fLevel>1)
234  std::cout << "--- Begin primary " << std::endl;
235 }
236 
237 ////////////////////////////////////////////////////////////////////////////////
238 /// Begin of each track info
239 /// ---
240 
242 {
243  if (fLevel>2) {
244  PrintBanner();
245  PrintTrackInfo();
246  PrintBanner();
247  PrintStepHeader();
248 
249  fStepNumber = 0;
250 
251  return;
252  }
253 
254  if (fLevel>1)
255  std::cout << "--- Pre track " << std::endl;
256 }
257 
258 ////////////////////////////////////////////////////////////////////////////////
259 /// Stepping info
260 /// ---
261 
263 {
264  if (fLevel>2) {
265 
266 #if __GNUC__ >= 3
267  std::cout << std::fixed;
268 #endif
269 
270  // Step number
271  //
272  std::cout << "#" << std::setw(4) << fStepNumber++ << " ";
273 
274  // Position
275  //
276  Double_t x, y, z;
277  gMC->TrackPosition(x, y, z);
278  std::cout << std::setw(8) << std::setprecision(3) << x << " "
279  << std::setw(8) << std::setprecision(3) << y << " "
280  << std::setw(8) << std::setprecision(3) << z << " ";
281 
282  // Kinetic energy
283  //
284  Double_t px, py, pz, etot;
285  gMC->TrackMomentum(px, py, pz, etot);
286  Double_t ekin = etot - gMC->TrackMass();
287  std::cout << std::setw(9) << std::setprecision(4) << ekin*1e03 << " ";
288 
289  // Energy deposit
290  //
291  std::cout << std::setw(9) << std::setprecision(4) << gMC->Edep()*1e03 << " ";
292 
293  // Step length
294  //
295  std::cout << std::setw(8) << std::setprecision(3) << gMC->TrackStep() << " ";
296 
297  // Track length
298  //
299  std::cout << std::setw(8) << std::setprecision(3) << gMC->TrackLength() << " ";
300 
301  // Volume
302  //
303  if (gMC->CurrentVolName() != 0)
304  std::cout << std::setw(4) << gMC->CurrentVolName() << " ";
305  else
306  std::cout << std::setw(4) << "None" << " ";
307 
308  // Process
309  //
310  TArrayI processes;
311  Int_t nofProcesses = gMC->StepProcesses(processes);
312  if (nofProcesses > 0)
313  std::cout << TMCProcessName[processes[nofProcesses-1]];
314 
315  std::cout << std::endl;
316  }
317 }
318 
319 ////////////////////////////////////////////////////////////////////////////////
320 /// Finish of each track info
321 /// ---
322 
324 {
325  if (fLevel==2)
326  std::cout << "--- Post track " << std::endl;
327 }
328 
329 ////////////////////////////////////////////////////////////////////////////////
330 /// Finish of a primary track info
331 /// ---
332 
334 {
335  if (fLevel==2)
336  std::cout << "--- Finish primary " << std::endl;
337 }
338 
339 ////////////////////////////////////////////////////////////////////////////////
340 /// Finish of an event info
341 /// ---
342 
344 {
345  if (fLevel>0)
346  std::cout << "--- Finish event " << std::endl;
347 }
348 
virtual void RunMC(Int_t nofEvents)
MC run info.
Definition: TMCVerbose.cxx:141
virtual void ConstructOpGeometry()
Construct geometry for optical physics info
Definition: TMCVerbose.cxx:171
virtual void FinishPrimary()
Finish of a primary track info
Definition: TMCVerbose.cxx:333
virtual void GeneratePrimaries()
Generate primaries info
Definition: TMCVerbose.cxx:211
TParticlePDG * GetParticle(Int_t pdgCode) const
Get a pointer to the particle object according to the MC code number.
void PrintStepHeader() const
Prints the header for stepping information
Definition: TMCVerbose.cxx:108
static const char *const TMCProcessName[kMaxMCProcess]
Definition: TMCProcess.h:89
virtual void Stepping()
Stepping info
Definition: TMCVerbose.cxx:262
virtual void BeginPrimary()
Begin of a primary track info
Definition: TMCVerbose.cxx:231
int Int_t
Definition: RtypesCore.h:41
void PrintBanner() const
Prints banner for track information
Definition: TMCVerbose.cxx:73
Array of integers (32 bits per element).
Definition: TArrayI.h:29
virtual void InitGeometry()
Initialize geometry info
Definition: TMCVerbose.cxx:181
virtual void ConstructGeometry()
Construct geometry info
Definition: TMCVerbose.cxx:161
Double_t x[n]
Definition: legend1.C:17
static TDatabasePDG * Instance()
static function
Int_t fLevel
Definition: TMCVerbose.h:66
virtual void BeginEvent()
Begin event info
Definition: TMCVerbose.cxx:221
TMCVerbose()
Default constructor
Definition: TMCVerbose.cxx:50
ClassImp(TMCVerbose) TMCVerbose
Standard constructor
Definition: TMCVerbose.cxx:33
virtual void PreTrack()
Begin of each track info
Definition: TMCVerbose.cxx:241
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
void PrintTrackInfo() const
Prints track information
Definition: TMCVerbose.cxx:84
virtual void FinishEvent()
Finish of an event info
Definition: TMCVerbose.cxx:343
double Double_t
Definition: RtypesCore.h:55
Double_t y[n]
Definition: legend1.C:17
#define gMC
Definition: TVirtualMC.h:880
virtual void AddParticles()
Add particles info
Definition: TMCVerbose.cxx:191
Mother of all ROOT objects.
Definition: TObject.h:58
virtual void PostTrack()
Finish of each track info
Definition: TMCVerbose.cxx:323
virtual ~TMCVerbose()
Destructor
Definition: TMCVerbose.cxx:61
virtual void FinishRun()
Finish MC run info.
Definition: TMCVerbose.cxx:151
virtual void AddIons()
Add ions info
Definition: TMCVerbose.cxx:201
virtual void InitMC()
Initialize MC info.
Definition: TMCVerbose.cxx:131
Int_t fStepNumber
Definition: TMCVerbose.h:67