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