1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.30 2002/10/29 14:26:49 hristov
19 Code clean-up (F.Carminati)
21 Revision 1.29 2002/10/14 14:57:32 hristov
22 Merging the VirtualMC branch to the main development branch (HEAD)
24 Revision 1.28.6.2 2002/07/24 10:08:13 alibrary
27 Revision 1.28.6.1 2002/06/10 14:43:06 hristov
30 Revision 1.28 2001/10/21 18:38:44 hristov
31 Several pointers were set to zero in the default constructors to avoid memory management problems
33 Revision 1.27 2001/07/20 09:32:18 morsch
34 Protection against uncomplete backward stepping in dumping added.
36 Revision 1.26 2001/05/30 12:18:13 morsch
37 Fastidious printf commented.
39 Revision 1.25 2001/05/23 11:59:46 morsch
40 Use RemoveAt method instead of delete to remove objects from TClonesArray.
42 Revision 1.24 2001/05/21 08:39:13 morsch
43 Use fStepBack = 1 only in debug mode.
45 Revision 1.23 2001/05/20 10:10:39 morsch
46 - Debug output at the beginning of new event and end of run.
47 - Filter out boundary loops.
49 Revision 1.22 2001/05/11 13:22:40 morsch
50 If run with debug option (from gAlice) geantinos are sent back and volume sequence forward/backward is compared.
51 Can be very verbous in some cases.
53 Revision 1.21 2000/12/15 10:33:59 morsch
54 Invert coordinates to make meaningful zylindrical plots.
56 Revision 1.20 2000/11/30 07:12:48 alibrary
57 Introducing new Rndm and QA classes
59 Revision 1.19 2000/10/26 14:13:05 morsch
60 - Change from coordinates theta, phi to general coordinates Coor1 and Coor2.
61 - Lego generator instance can be passed in constructor.
63 Revision 1.18 2000/10/02 21:28:14 fca
64 Removal of useless dependecies via forward declarations
66 Revision 1.17 2000/07/12 08:56:25 fca
67 Coding convention correction and warning removal
69 Revision 1.16 2000/05/26 08:35:03 fca
70 Move the check on z after z has been retrieved
72 Revision 1.15 2000/05/16 13:10:40 fca
73 New method IsNewTrack and fix for a problem in Father-Daughter relations
75 Revision 1.14 2000/04/27 10:38:21 fca
76 Correct termination of Lego Run and introduce Lego getter in AliRun
78 Revision 1.13 2000/04/26 10:17:31 fca
79 Changes in Lego for G4 compatibility
81 Revision 1.12 2000/04/07 11:12:33 fca
82 G4 compatibility changes
84 Revision 1.11 2000/03/22 13:42:26 fca
85 SetGenerator does not replace an existing generator, ResetGenerator does
87 Revision 1.10 2000/02/23 16:25:22 fca
88 AliVMC and AliGeant3 classes introduced
89 ReadEuclid moved from AliRun to AliModule
91 Revision 1.9 1999/12/03 10:54:01 fca
94 Revision 1.8 1999/10/01 09:54:33 fca
95 Correct logics for Lego StepManager
97 Revision 1.7 1999/09/29 09:24:29 fca
98 Introduction of the Copyright and cvs Log
102 //////////////////////////////////////////////////////////////
103 //////////////////////////////////////////////////////////////
105 // Utility class to evaluate the material budget from
106 // a given radius to the surface of an arbitrary cylinder
107 // along radial directions from the centre:
109 // - radiation length
110 // - Interaction length
113 // Geantinos are shot in the bins in the fNtheta bins in theta
114 // and fNphi bins in phi with specified rectangular limits.
115 // The statistics are accumulated per
116 // fRadMin < r < fRadMax and <0 < z < fZMax
118 // To activate this option, you can do:
119 // Root > gAlice.RunLego();
120 // or Root > .x menu.C then select menu item "RunLego"
121 // Note that when calling gAlice->RunLego, an optional list
122 // of arguments may be specified.
126 <img src="picts/alilego.gif">
130 //////////////////////////////////////////////////////////////
132 #include "TClonesArray.h"
137 #include "AliConst.h"
138 #include "AliDebugVolume.h"
140 #include "AliLegoGenerator.h"
145 //_______________________________________________________________________
164 // Default constructor
168 //_______________________________________________________________________
169 AliLego::AliLego(const AliLego &lego):
194 //_______________________________________________________________________
195 AliLego::AliLego(const char *title, Int_t ntheta, Float_t thetamin,
196 Float_t thetamax, Int_t nphi, Float_t phimin, Float_t phimax,
197 Float_t rmin, Float_t rmax, Float_t zmax):
198 TNamed("Lego Generator",title),
216 // specify the angular limits and the size of the rectangular box
218 fGener = new AliLegoGenerator(ntheta, thetamin, thetamax,
219 nphi, phimin, phimax, rmin, rmax, zmax);
220 fHistRadl = new TH2F("hradl","Radiation length map",
221 ntheta,thetamin,thetamax,nphi,phimin,phimax);
222 fHistAbso = new TH2F("habso","Interaction length map",
223 ntheta,thetamin,thetamax,nphi,phimin,phimax);
224 fHistGcm2 = new TH2F("hgcm2","g/cm2 length map",
225 ntheta,thetamin,thetamax,nphi,phimin,phimax);
227 fVolumesFwd = new TClonesArray("AliDebugVolume",1000);
228 fVolumesBwd = new TClonesArray("AliDebugVolume",1000);
229 fDebug = gAlice->GetDebug();
232 //_______________________________________________________________________
233 AliLego::AliLego(const char *title, AliLegoGenerator* generator):
234 TNamed("Lego Generator",title),
252 // specify the angular limits and the size of the rectangular box
255 Float_t c1min, c1max, c2min, c2max;
256 Int_t n1 = fGener->NCoor1();
257 Int_t n2 = fGener->NCoor2();
259 fGener->Coor1Range(c1min, c1max);
260 fGener->Coor2Range(c2min, c2max);
262 fHistRadl = new TH2F("hradl","Radiation length map",
263 n2, c2min, c2max, n1, c1min, c1max);
264 fHistAbso = new TH2F("habso","Interaction length map",
265 n2, c2min, c2max, n1, c1min, c1max);
266 fHistGcm2 = new TH2F("hgcm2","g/cm2 length map",
267 n2, c2min, c2max, n1, c1min, c1max);
271 fVolumesFwd = new TClonesArray("AliDebugVolume",1000);
272 fVolumesBwd = new TClonesArray("AliDebugVolume",1000);
273 fDebug = gAlice->GetDebug();
276 //_______________________________________________________________________
290 //_______________________________________________________________________
291 void AliLego::BeginEvent()
294 // --- Set to 0 radiation length, absorption length and g/cm2 ---
301 if (fErrorCondition) DumpVolumes();
302 fVolumesFwd->Delete();
303 fVolumesBwd->Delete();
307 if (gAlice->CurrentTrack() == 0) fStepBack = 0;
311 //_______________________________________________________________________
312 void AliLego::FinishEvent()
315 // Finish the event and update the histos
318 c1 = fGener->CurCoor1();
319 c2 = fGener->CurCoor2();
320 fHistRadl->Fill(c2,c1,fTotRadl);
321 fHistAbso->Fill(c2,c1,fTotAbso);
322 fHistGcm2->Fill(c2,c1,fTotGcm2);
325 //_______________________________________________________________________
326 void AliLego::FinishRun()
329 // Store histograms in current Root file
335 // Delete histograms from memory
336 fHistRadl->Delete(); fHistRadl=0;
337 fHistAbso->Delete(); fHistAbso=0;
338 fHistGcm2->Delete(); fHistGcm2=0;
340 if (fErrorCondition) DumpVolumes();
343 //_______________________________________________________________________
344 void AliLego::Copy(AliLego&) const
347 // Copy *this onto lego -- not implemented
349 Fatal("Copy","Not implemented!\n");
352 //_______________________________________________________________________
353 void AliLego::StepManager()
356 // called from AliRun::Stepmanager from gustep.
357 // Accumulate the 3 parameters step by step
360 Float_t a,z,dens,radl,absl;
363 static Float_t vect[3], dir[3];
367 id = gMC->CurrentVolID(copy);
368 vol = gMC->VolName(id);
369 Float_t step = gMC->TrackStep();
371 TLorentzVector pos, mom;
372 gMC->TrackPosition(pos);
373 gMC->TrackMomentum(mom);
376 if (gMC->IsTrackEntering()) status = 1;
377 if (gMC->IsTrackExiting()) status = 2;
380 // printf("\n volume %s %d", vol, status);
382 // Normal Forward stepping
385 // printf("\n steps fwd %d %s %d %f", fStepsForward, vol, fErrorCondition, step);
388 // store volume if different from previous
391 TClonesArray &lvols = *fVolumesFwd;
392 if (fStepsForward > 0) {
393 AliDebugVolume* tmp = dynamic_cast<AliDebugVolume*>((*fVolumesFwd)[fStepsForward-1]);
394 if (tmp->IsVEqual(vol, copy) && gMC->IsTrackEntering()) {
396 fVolumesFwd->RemoveAt(fStepsForward);
397 fVolumesFwd->RemoveAt(fStepsForward+1);
401 new(lvols[fStepsForward++])
402 AliDebugVolume(vol,copy,step,pos[0], pos[1], pos[2], status);
406 // Get current material properties
408 gMC->CurrentMaterial(a,z,dens,radl,absl);
412 // --- See if we have to stop now
413 if (TMath::Abs(pos[2]) > fGener->ZMax() ||
414 pos[0]*pos[0] +pos[1]*pos[1] > fGener->RadMax()*fGener->RadMax()) {
415 if (!gMC->IsNewTrack()) {
416 // Not the first step, add past contribution
422 // generate "mirror" particle flying back
424 fStepsBackward = fStepsForward;
426 Float_t pmom[3], orig[3];
427 Float_t polar[3] = {0.,0.,0.};
436 gAlice->SetTrack(1, gAlice->CurrentTrack(),
437 0, pmom, orig, polar, 0., kPNoProcess, ntr);
440 } // not a new track !
442 if (fDebug) fStepBack = 1;
445 } // outside scoring region ?
447 // --- See how long we have to go
453 t = fGener->PropagateCylinder(vect,dir,fGener->RadMax(),fGener->ZMax());
457 fTotAbso += step/absl;
458 fTotRadl += step/radl;
459 fTotGcm2 += step*dens;
465 // Geometry debugging
466 // Fly back and compare volume sequence
468 TClonesArray &lvols = *fVolumesBwd;
469 if (fStepsBackward < fStepsForward) {
470 AliDebugVolume* tmp = dynamic_cast<AliDebugVolume*>((*fVolumesBwd)[fStepsBackward]);
471 if (tmp->IsVEqual(vol, copy) && gMC->IsTrackEntering()) {
473 fVolumesBwd->RemoveAt(fStepsBackward-1);
474 fVolumesBwd->RemoveAt(fStepsBackward-2);
479 // printf("\n steps %d %s %d", fStepsBackward, vol, fErrorCondition);
480 if (fStepsBackward < 0) {
486 new(lvols[fStepsBackward]) AliDebugVolume(vol,copy,step,pos[0], pos[1], pos[2], status);
488 AliDebugVolume* tmp = dynamic_cast<AliDebugVolume*>((*fVolumesFwd)[fStepsBackward]);
489 if (! (tmp->IsVEqual(vol, copy)) && (!fErrorCondition))
491 printf("\n Problem at (x,y,z): %d %f %f %f, volumes: %s %s step: %f\n",
492 fStepsBackward, pos[0], pos[1], pos[2], tmp->GetName(), vol, step);
499 //_______________________________________________________________________
500 void AliLego::DumpVolumes()
503 // Dump volume sequence in case of error
505 printf("\n Dumping Volume Sequence:");
506 printf("\n ==============================================");
508 for (Int_t i = fStepsForward-1; i>=0; i--)
510 AliDebugVolume* tmp1 = dynamic_cast<AliDebugVolume*>((*fVolumesFwd)[i]);
511 AliDebugVolume* tmp2 = dynamic_cast<AliDebugVolume*>((*fVolumesBwd)[i]);
513 printf("\n Volume Fwd: %3d: %5s (%3d) step: %12.5e (x,y,z) (%12.5e %12.5e %12.5e) status: %9s \n"
515 tmp1->GetName(), tmp1->CopyNumber(), tmp1->Step(),
516 tmp1->X(), tmp1->Y(), tmp1->Z(), tmp1->Status());
517 if (tmp2 && i>= fStepsBackward)
518 printf("\n Volume Bwd: %3d: %5s (%3d) step: %12.5e (x,y,z) (%12.5e %12.5e %12.5e) status: %9s \n"
520 tmp2->GetName(), tmp2->CopyNumber(), tmp2->Step(),
521 tmp2->X(), tmp2->Y(), tmp2->Z(), tmp2->Status());
523 printf("\n ............................................................................\n");
525 printf("\n ==============================================\n");