]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliLego.cxx
More exact rounding function, but also much slower.
[u/mrichter/AliRoot.git] / STEER / AliLego.cxx
CommitLineData
4c039060 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/*
17$Log$
2685bf00 18Revision 1.27 2001/07/20 09:32:18 morsch
19Protection against uncomplete backward stepping in dumping added.
20
899fde02 21Revision 1.26 2001/05/30 12:18:13 morsch
22Fastidious printf commented.
23
09a536f9 24Revision 1.25 2001/05/23 11:59:46 morsch
25Use RemoveAt method instead of delete to remove objects from TClonesArray.
26
5f3dc1c9 27Revision 1.24 2001/05/21 08:39:13 morsch
28Use fStepBack = 1 only in debug mode.
29
19237f5f 30Revision 1.23 2001/05/20 10:10:39 morsch
31- Debug output at the beginning of new event and end of run.
32- Filter out boundary loops.
33
a74d2699 34Revision 1.22 2001/05/11 13:22:40 morsch
35If run with debug option (from gAlice) geantinos are sent back and volume sequence forward/backward is compared.
36Can be very verbous in some cases.
37
7eb618fa 38Revision 1.21 2000/12/15 10:33:59 morsch
39Invert coordinates to make meaningful zylindrical plots.
40
10bd7535 41Revision 1.20 2000/11/30 07:12:48 alibrary
42Introducing new Rndm and QA classes
43
65fb704d 44Revision 1.19 2000/10/26 14:13:05 morsch
45- Change from coordinates theta, phi to general coordinates Coor1 and Coor2.
46- Lego generator instance can be passed in constructor.
47
0b27b8c7 48Revision 1.18 2000/10/02 21:28:14 fca
49Removal of useless dependecies via forward declarations
50
94de3818 51Revision 1.17 2000/07/12 08:56:25 fca
52Coding convention correction and warning removal
53
8918e700 54Revision 1.16 2000/05/26 08:35:03 fca
55Move the check on z after z has been retrieved
56
119a6af6 57Revision 1.15 2000/05/16 13:10:40 fca
58New method IsNewTrack and fix for a problem in Father-Daughter relations
59
a01a8b12 60Revision 1.14 2000/04/27 10:38:21 fca
61Correct termination of Lego Run and introduce Lego getter in AliRun
62
838edcaf 63Revision 1.13 2000/04/26 10:17:31 fca
64Changes in Lego for G4 compatibility
65
dffd31ef 66Revision 1.12 2000/04/07 11:12:33 fca
67G4 compatibility changes
68
875c717b 69Revision 1.11 2000/03/22 13:42:26 fca
70SetGenerator does not replace an existing generator, ResetGenerator does
71
ee1dd322 72Revision 1.10 2000/02/23 16:25:22 fca
73AliVMC and AliGeant3 classes introduced
74ReadEuclid moved from AliRun to AliModule
75
b13db077 76Revision 1.9 1999/12/03 10:54:01 fca
77Fix lego summary
78
00719c1b 79Revision 1.8 1999/10/01 09:54:33 fca
80Correct logics for Lego StepManager
81
f059c84a 82Revision 1.7 1999/09/29 09:24:29 fca
83Introduction of the Copyright and cvs Log
84
4c039060 85*/
86
fe4da5cc 87//////////////////////////////////////////////////////////////
88//////////////////////////////////////////////////////////////
89//
90// Utility class to evaluate the material budget from
91// a given radius to the surface of an arbitrary cylinder
92// along radial directions from the centre:
93//
94// - radiation length
95// - Interaction length
96// - g/cm2
97//
98// Geantinos are shot in the bins in the fNtheta bins in theta
99// and fNphi bins in phi with specified rectangular limits.
100// The statistics are accumulated per
101// fRadMin < r < fRadMax and <0 < z < fZMax
102//
103// To activate this option, you can do:
104// Root > gAlice.RunLego();
105// or Root > .x menu.C then select menu item "RunLego"
106// Note that when calling gAlice->RunLego, an optional list
107// of arguments may be specified.
108//
109//Begin_Html
110/*
1439f98e 111<img src="picts/alilego.gif">
fe4da5cc 112*/
113//End_Html
114//
115//////////////////////////////////////////////////////////////
116
117#include "TMath.h"
94de3818 118
1578254f 119#include "AliLego.h"
a74d2699 120
7eb618fa 121#include "AliDebugVolume.h"
122#include "AliRun.h"
8918e700 123#include "AliLegoGenerator.h"
fe4da5cc 124#include "AliConst.h"
875c717b 125#include "AliMC.h"
94de3818 126#include "TH2.h"
a74d2699 127#include "../TGeant3/TGeant3.h"
7eb618fa 128#include "TString.h"
129#include "TClonesArray.h"
130
fe4da5cc 131ClassImp(AliLego)
132
133
134//___________________________________________
135AliLego::AliLego()
136{
8918e700 137 //
138 // Default constructor
139 //
2685bf00 140 fGener = 0;
8918e700 141 fHistRadl = 0;
142 fHistAbso = 0;
143 fHistGcm2 = 0;
144 fHistReta = 0;
2685bf00 145 fVolumesFwd = 0;
146 fVolumesBwd = 0;
fe4da5cc 147}
148
149//___________________________________________
0b27b8c7 150AliLego::AliLego(const char *title, Int_t ntheta, Float_t thetamin,
151 Float_t thetamax, Int_t nphi, Float_t phimin, Float_t phimax,
b13db077 152 Float_t rmin, Float_t rmax, Float_t zmax)
153 : TNamed("Lego Generator",title)
fe4da5cc 154{
8918e700 155 //
156 // specify the angular limits and the size of the rectangular box
157 //
0b27b8c7 158 fGener = new AliLegoGenerator(ntheta, thetamin, thetamax,
b13db077 159 nphi, phimin, phimax, rmin, rmax, zmax);
160
b13db077 161
0b27b8c7 162
b13db077 163 fHistRadl = new TH2F("hradl","Radiation length map",
0b27b8c7 164 ntheta,thetamin,thetamax,nphi,phimin,phimax);
b13db077 165 fHistAbso = new TH2F("habso","Interaction length map",
0b27b8c7 166 ntheta,thetamin,thetamax,nphi,phimin,phimax);
b13db077 167 fHistGcm2 = new TH2F("hgcm2","g/cm2 length map",
0b27b8c7 168 ntheta,thetamin,thetamax,nphi,phimin,phimax);
7eb618fa 169//
19237f5f 170 fStepBack = 0;
171 fStepsBackward = 0;
172 fStepsForward = 0;
173 fStepBack = 0;
7eb618fa 174 fVolumesFwd = new TClonesArray("AliDebugVolume",1000);
175 fVolumesBwd = new TClonesArray("AliDebugVolume",1000);
19237f5f 176 fDebug = gAlice->GetDebug();
177 fErrorCondition = 0;
0b27b8c7 178}
179
180AliLego::AliLego(const char *title, AliLegoGenerator* generator)
181 : TNamed("Lego Generator",title)
182{
183 //
184 // specify the angular limits and the size of the rectangular box
185 //
186 fGener = generator;
187 Float_t c1min, c1max, c2min, c2max;
188 Int_t n1 = fGener->NCoor1();
189 Int_t n2 = fGener->NCoor2();
190
191 fGener->Coor1Range(c1min, c1max);
192 fGener->Coor2Range(c2min, c2max);
b13db077 193
0b27b8c7 194 fHistRadl = new TH2F("hradl","Radiation length map",
10bd7535 195 n2, c2min, c2max, n1, c1min, c1max);
0b27b8c7 196 fHistAbso = new TH2F("habso","Interaction length map",
10bd7535 197 n2, c2min, c2max, n1, c1min, c1max);
0b27b8c7 198 fHistGcm2 = new TH2F("hgcm2","g/cm2 length map",
10bd7535 199 n2, c2min, c2max, n1, c1min, c1max);
7eb618fa 200//
201//
202 fStepBack = 0;
203 fStepsBackward = 0;
204 fStepsForward = 0;
205 fStepBack = 0;
206 fVolumesFwd = new TClonesArray("AliDebugVolume",1000);
207 fVolumesBwd = new TClonesArray("AliDebugVolume",1000);
19237f5f 208 fDebug = gAlice->GetDebug();
a74d2699 209 fErrorCondition =0;
fe4da5cc 210}
211
212//___________________________________________
213AliLego::~AliLego()
214{
8918e700 215 //
216 // Destructor
217 //
218 delete fHistRadl;
219 delete fHistAbso;
220 delete fHistGcm2;
8918e700 221 delete fGener;
7eb618fa 222 if (fVolumesFwd) delete fVolumesFwd;
223 if (fVolumesBwd) delete fVolumesBwd;
fe4da5cc 224}
225
b13db077 226//___________________________________________
dffd31ef 227void AliLego::BeginEvent()
b13db077 228{
8918e700 229 //
230 // --- Set to 0 radiation length, absorption length and g/cm2 ---
231 //
dffd31ef 232 fTotRadl = 0;
233 fTotAbso = 0;
234 fTotGcm2 = 0;
19237f5f 235
a74d2699 236 if (fDebug) {
237 if (fErrorCondition) DumpVolumes();
238 fVolumesFwd->Delete();
239 fVolumesBwd->Delete();
240 fStepsForward = 0;
241 fStepsBackward = 0;
242 fErrorCondition = 0;
243 if (gAlice->CurrentTrack() == 0) fStepBack = 0;
244 }
dffd31ef 245}
246
247//___________________________________________
248void AliLego::FinishEvent()
249{
8918e700 250 //
251 // Finish the event and update the histos
252 //
0b27b8c7 253 Double_t c1, c2;
254 c1 = fGener->CurCoor1();
255 c2 = fGener->CurCoor2();
10bd7535 256 fHistRadl->Fill(c2,c1,fTotRadl);
257 fHistAbso->Fill(c2,c1,fTotAbso);
258 fHistGcm2->Fill(c2,c1,fTotGcm2);
b13db077 259}
260
dffd31ef 261//___________________________________________
262void AliLego::FinishRun()
263{
8918e700 264 //
265 // Store histograms in current Root file
266 //
dffd31ef 267 fHistRadl->Write();
268 fHistAbso->Write();
269 fHistGcm2->Write();
dffd31ef 270
271 // Delete histograms from memory
272 fHistRadl->Delete(); fHistRadl=0;
273 fHistAbso->Delete(); fHistAbso=0;
274 fHistGcm2->Delete(); fHistGcm2=0;
a74d2699 275 //
276 if (fErrorCondition) DumpVolumes();
dffd31ef 277}
278
8918e700 279//___________________________________________
280void AliLego::Copy(AliLego &lego) const
281{
282 //
283 // Copy *this onto lego -- not implemented
284 //
285 Fatal("Copy","Not implemented!\n");
286}
dffd31ef 287
b13db077 288//___________________________________________
7eb618fa 289void AliLego::StepManager() {
b13db077 290// called from AliRun::Stepmanager from gustep.
291// Accumulate the 3 parameters step by step
a74d2699 292
7eb618fa 293 static Float_t t;
294 Float_t a,z,dens,radl,absl;
295 Int_t i, id, copy;
296 const char* vol;
297 static Float_t vect[3], dir[3];
a01a8b12 298
7eb618fa 299 TString tmp1, tmp2;
300 copy = 1;
301 id = gMC->CurrentVolID(copy);
302 vol = gMC->VolName(id);
303 Float_t step = gMC->TrackStep();
7eb618fa 304
305 TLorentzVector pos, mom;
b13db077 306 gMC->TrackPosition(pos);
307 gMC->TrackMomentum(mom);
7eb618fa 308
309 Int_t status = 0;
310 if (gMC->IsTrackEntering()) status = 1;
a74d2699 311 if (gMC->IsTrackExiting()) status = 2;
0b27b8c7 312
a74d2699 313
314
315
7eb618fa 316 if (! fStepBack) {
09a536f9 317// printf("\n volume %s %d", vol, status);
7eb618fa 318//
319// Normal Forward stepping
320//
321 if (fDebug) {
a74d2699 322// printf("\n steps fwd %d %s %d %f", fStepsForward, vol, fErrorCondition, step);
323
7eb618fa 324//
325// store volume if different from previous
326//
327
a74d2699 328 TClonesArray &lvols = *fVolumesFwd;
7eb618fa 329 if (fStepsForward > 0) {
330 AliDebugVolume* tmp = (AliDebugVolume*) (*fVolumesFwd)[fStepsForward-1];
a74d2699 331 if (tmp->IsEqual(vol, copy) && gMC->IsTrackEntering()) {
a74d2699 332 fStepsForward -= 2;
5f3dc1c9 333 fVolumesFwd->RemoveAt(fStepsForward);
334 fVolumesFwd->RemoveAt(fStepsForward+1);
a74d2699 335 }
7eb618fa 336 }
a74d2699 337
338 new(lvols[fStepsForward++])
339 AliDebugVolume(vol,copy,step,pos[0], pos[1], pos[2], status);
340
7eb618fa 341 } // Debug
342//
343// Get current material properties
b13db077 344
7eb618fa 345 gMC->CurrentMaterial(a,z,dens,radl,absl);
346
347 if (z < 1) return;
348
349// --- See if we have to stop now
350 if (TMath::Abs(pos[2]) > fGener->ZMax() ||
351 pos[0]*pos[0] +pos[1]*pos[1] > fGener->RadMax()*fGener->RadMax()) {
352 if (!gMC->IsNewTrack()) {
353 // Not the first step, add past contribution
354 fTotAbso += t/absl;
355 fTotRadl += t/radl;
356 fTotGcm2 += t*dens;
7eb618fa 357 if (fDebug) {
358//
359// generate "mirror" particle flying back
360//
361 fStepsBackward = fStepsForward;
362
363 Float_t pmom[3], orig[3];
364 Float_t polar[3] = {0.,0.,0.};
365 Int_t ntr;
366 pmom[0] = -dir[0];
367 pmom[1] = -dir[1];
368 pmom[2] = -dir[2];
369 orig[0] = vect[0];
370 orig[1] = vect[1];
371 orig[2] = vect[2];
372
373 gAlice->SetTrack(1, gAlice->CurrentTrack(),
374 0, pmom, orig, polar, 0., kPNoProcess, ntr);
375 } // debug
376
377 } // not a new track !
378
19237f5f 379 if (fDebug) fStepBack = 1;
7eb618fa 380 gMC->StopTrack();
381 return;
382 } // outside scoring region ?
383
b13db077 384// --- See how long we have to go
7eb618fa 385 for(i=0;i<3;++i) {
386 vect[i]=pos[i];
387 dir[i]=mom[i];
388 }
389
390 t = fGener->PropagateCylinder(vect,dir,fGener->RadMax(),fGener->ZMax());
391
392 if(step) {
19237f5f 393
7eb618fa 394 fTotAbso += step/absl;
395 fTotRadl += step/radl;
396 fTotGcm2 += step*dens;
397 }
398
399
400 } else {
401 if (fDebug) {
402//
403// Geometry debugging
404// Fly back and compare volume sequence
405//
a74d2699 406 TClonesArray &lvols = *fVolumesBwd;
7eb618fa 407 if (fStepsBackward < fStepsForward) {
408 AliDebugVolume* tmp = (AliDebugVolume*) (*fVolumesBwd)[fStepsBackward];
a74d2699 409 if (tmp->IsEqual(vol, copy) && gMC->IsTrackEntering()) {
410 fStepsBackward += 2;
5f3dc1c9 411 fVolumesBwd->RemoveAt(fStepsBackward-1);
412 fVolumesBwd->RemoveAt(fStepsBackward-2);
7eb618fa 413 }
414 }
a74d2699 415
7eb618fa 416 fStepsBackward--;
a74d2699 417// printf("\n steps %d %s %d", fStepsBackward, vol, fErrorCondition);
7eb618fa 418 if (fStepsBackward < 0) {
419 gMC->StopTrack();
a74d2699 420 fStepBack = 0;
7eb618fa 421 return;
422 }
423
7eb618fa 424 new(lvols[fStepsBackward]) AliDebugVolume(vol,copy,step,pos[0], pos[1], pos[2], status);
425
426 AliDebugVolume* tmp = (AliDebugVolume*) (*fVolumesFwd)[fStepsBackward];
427 if (! (tmp->IsEqual(vol, copy)) && (!fErrorCondition))
428 {
429 printf("\n Problem at (x,y,z): %d %f %f %f, volumes: %s %s step: %f\n",
430 fStepsBackward, pos[0], pos[1], pos[2], tmp->GetName(), vol, step);
431 fErrorCondition = 1;
432 }
433 } // Debug
434 } // bwd/fwd
b13db077 435}
436
a74d2699 437void AliLego::DumpVolumes()
438{
439//
440// Dump volume sequence in case of error
441//
442 printf("\n Dumping Volume Sequence:");
443 printf("\n ==============================================");
444
445 for (Int_t i = fStepsForward-1; i>=0; i--)
446 {
447 AliDebugVolume* tmp1 = (AliDebugVolume*) (*fVolumesFwd)[i];
448 AliDebugVolume* tmp2 = (AliDebugVolume*) (*fVolumesBwd)[i];
899fde02 449 if (tmp1)
450 printf("\n Volume Fwd: %3d: %5s (%3d) step: %12.5e (x,y,z) (%12.5e %12.5e %12.5e) status: %9s \n"
a74d2699 451 , i,
452 tmp1->GetName(), tmp1->CopyNumber(), tmp1->Step(),
453 tmp1->X(), tmp1->Y(), tmp1->Z(), tmp1->Status());
899fde02 454 if (tmp2 && i>= fStepsBackward)
455 printf("\n Volume Bwd: %3d: %5s (%3d) step: %12.5e (x,y,z) (%12.5e %12.5e %12.5e) status: %9s \n"
a74d2699 456 , i,
457 tmp2->GetName(), tmp2->CopyNumber(), tmp2->Step(),
458 tmp2->X(), tmp2->Y(), tmp2->Z(), tmp2->Status());
459
460 printf("\n ............................................................................\n");
461 }
462 printf("\n ==============================================\n");
463}
0b27b8c7 464
465
466
467
7eb618fa 468
469
470