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.22 2001/05/11 13:22:40 morsch
19 If run with debug option (from gAlice) geantinos are sent back and volume sequence forward/backward is compared.
20 Can be very verbous in some cases.
22 Revision 1.21 2000/12/15 10:33:59 morsch
23 Invert coordinates to make meaningful zylindrical plots.
25 Revision 1.20 2000/11/30 07:12:48 alibrary
26 Introducing new Rndm and QA classes
28 Revision 1.19 2000/10/26 14:13:05 morsch
29 - Change from coordinates theta, phi to general coordinates Coor1 and Coor2.
30 - Lego generator instance can be passed in constructor.
32 Revision 1.18 2000/10/02 21:28:14 fca
33 Removal of useless dependecies via forward declarations
35 Revision 1.17 2000/07/12 08:56:25 fca
36 Coding convention correction and warning removal
38 Revision 1.16 2000/05/26 08:35:03 fca
39 Move the check on z after z has been retrieved
41 Revision 1.15 2000/05/16 13:10:40 fca
42 New method IsNewTrack and fix for a problem in Father-Daughter relations
44 Revision 1.14 2000/04/27 10:38:21 fca
45 Correct termination of Lego Run and introduce Lego getter in AliRun
47 Revision 1.13 2000/04/26 10:17:31 fca
48 Changes in Lego for G4 compatibility
50 Revision 1.12 2000/04/07 11:12:33 fca
51 G4 compatibility changes
53 Revision 1.11 2000/03/22 13:42:26 fca
54 SetGenerator does not replace an existing generator, ResetGenerator does
56 Revision 1.10 2000/02/23 16:25:22 fca
57 AliVMC and AliGeant3 classes introduced
58 ReadEuclid moved from AliRun to AliModule
60 Revision 1.9 1999/12/03 10:54:01 fca
63 Revision 1.8 1999/10/01 09:54:33 fca
64 Correct logics for Lego StepManager
66 Revision 1.7 1999/09/29 09:24:29 fca
67 Introduction of the Copyright and cvs Log
71 //////////////////////////////////////////////////////////////
72 //////////////////////////////////////////////////////////////
74 // Utility class to evaluate the material budget from
75 // a given radius to the surface of an arbitrary cylinder
76 // along radial directions from the centre:
79 // - Interaction length
82 // Geantinos are shot in the bins in the fNtheta bins in theta
83 // and fNphi bins in phi with specified rectangular limits.
84 // The statistics are accumulated per
85 // fRadMin < r < fRadMax and <0 < z < fZMax
87 // To activate this option, you can do:
88 // Root > gAlice.RunLego();
89 // or Root > .x menu.C then select menu item "RunLego"
90 // Note that when calling gAlice->RunLego, an optional list
91 // of arguments may be specified.
95 <img src="picts/alilego.gif">
99 //////////////////////////////////////////////////////////////
105 #include "AliDebugVolume.h"
107 #include "AliLegoGenerator.h"
108 #include "AliConst.h"
111 #include "../TGeant3/TGeant3.h"
113 #include "TClonesArray.h"
118 //___________________________________________
122 // Default constructor
130 //___________________________________________
131 AliLego::AliLego(const char *title, Int_t ntheta, Float_t thetamin,
132 Float_t thetamax, Int_t nphi, Float_t phimin, Float_t phimax,
133 Float_t rmin, Float_t rmax, Float_t zmax)
134 : TNamed("Lego Generator",title)
137 // specify the angular limits and the size of the rectangular box
139 fGener = new AliLegoGenerator(ntheta, thetamin, thetamax,
140 nphi, phimin, phimax, rmin, rmax, zmax);
144 fHistRadl = new TH2F("hradl","Radiation length map",
145 ntheta,thetamin,thetamax,nphi,phimin,phimax);
146 fHistAbso = new TH2F("habso","Interaction length map",
147 ntheta,thetamin,thetamax,nphi,phimin,phimax);
148 fHistGcm2 = new TH2F("hgcm2","g/cm2 length map",
149 ntheta,thetamin,thetamax,nphi,phimin,phimax);
155 fVolumesFwd = new TClonesArray("AliDebugVolume",1000);
156 fVolumesBwd = new TClonesArray("AliDebugVolume",1000);
157 fDebug = gAlice->GetDebug();
161 AliLego::AliLego(const char *title, AliLegoGenerator* generator)
162 : TNamed("Lego Generator",title)
165 // specify the angular limits and the size of the rectangular box
168 Float_t c1min, c1max, c2min, c2max;
169 Int_t n1 = fGener->NCoor1();
170 Int_t n2 = fGener->NCoor2();
172 fGener->Coor1Range(c1min, c1max);
173 fGener->Coor2Range(c2min, c2max);
175 fHistRadl = new TH2F("hradl","Radiation length map",
176 n2, c2min, c2max, n1, c1min, c1max);
177 fHistAbso = new TH2F("habso","Interaction length map",
178 n2, c2min, c2max, n1, c1min, c1max);
179 fHistGcm2 = new TH2F("hgcm2","g/cm2 length map",
180 n2, c2min, c2max, n1, c1min, c1max);
187 fVolumesFwd = new TClonesArray("AliDebugVolume",1000);
188 fVolumesBwd = new TClonesArray("AliDebugVolume",1000);
189 fDebug = gAlice->GetDebug();
193 //___________________________________________
203 if (fVolumesFwd) delete fVolumesFwd;
204 if (fVolumesBwd) delete fVolumesBwd;
207 //___________________________________________
208 void AliLego::BeginEvent()
211 // --- Set to 0 radiation length, absorption length and g/cm2 ---
216 // printf("\n Begin Event %d", fErrorCondition);
219 if (fErrorCondition) DumpVolumes();
220 fVolumesFwd->Delete();
221 fVolumesBwd->Delete();
225 if (gAlice->CurrentTrack() == 0) fStepBack = 0;
229 //___________________________________________
230 void AliLego::FinishEvent()
233 // Finish the event and update the histos
236 c1 = fGener->CurCoor1();
237 c2 = fGener->CurCoor2();
238 fHistRadl->Fill(c2,c1,fTotRadl);
239 fHistAbso->Fill(c2,c1,fTotAbso);
240 fHistGcm2->Fill(c2,c1,fTotGcm2);
243 //___________________________________________
244 void AliLego::FinishRun()
247 // Store histograms in current Root file
253 // Delete histograms from memory
254 fHistRadl->Delete(); fHistRadl=0;
255 fHistAbso->Delete(); fHistAbso=0;
256 fHistGcm2->Delete(); fHistGcm2=0;
258 if (fErrorCondition) DumpVolumes();
261 //___________________________________________
262 void AliLego::Copy(AliLego &lego) const
265 // Copy *this onto lego -- not implemented
267 Fatal("Copy","Not implemented!\n");
270 //___________________________________________
271 void AliLego::StepManager() {
272 // called from AliRun::Stepmanager from gustep.
273 // Accumulate the 3 parameters step by step
276 Float_t a,z,dens,radl,absl;
279 static Float_t vect[3], dir[3];
283 id = gMC->CurrentVolID(copy);
284 vol = gMC->VolName(id);
285 Float_t step = gMC->TrackStep();
287 TLorentzVector pos, mom;
288 gMC->TrackPosition(pos);
289 gMC->TrackMomentum(mom);
292 if (gMC->IsTrackEntering()) status = 1;
293 if (gMC->IsTrackExiting()) status = 2;
299 // printf("\n volume %s %d", vol, status);
301 // Normal Forward stepping
304 // printf("\n steps fwd %d %s %d %f", fStepsForward, vol, fErrorCondition, step);
307 // store volume if different from previous
310 TClonesArray &lvols = *fVolumesFwd;
311 if (fStepsForward > 0) {
312 AliDebugVolume* tmp = (AliDebugVolume*) (*fVolumesFwd)[fStepsForward-1];
313 if (tmp->IsEqual(vol, copy) && gMC->IsTrackEntering()) {
314 step += ((AliDebugVolume*) lvols[fStepsForward])->Step();
316 delete ((AliDebugVolume*) lvols[fStepsForward]);
317 delete ((AliDebugVolume*) lvols[fStepsForward+1]);
321 new(lvols[fStepsForward++])
322 AliDebugVolume(vol,copy,step,pos[0], pos[1], pos[2], status);
326 // Get current material properties
328 gMC->CurrentMaterial(a,z,dens,radl,absl);
332 // --- See if we have to stop now
333 if (TMath::Abs(pos[2]) > fGener->ZMax() ||
334 pos[0]*pos[0] +pos[1]*pos[1] > fGener->RadMax()*fGener->RadMax()) {
335 if (!gMC->IsNewTrack()) {
336 // Not the first step, add past contribution
343 // generate "mirror" particle flying back
345 fStepsBackward = fStepsForward;
347 Float_t pmom[3], orig[3];
348 Float_t polar[3] = {0.,0.,0.};
357 gAlice->SetTrack(1, gAlice->CurrentTrack(),
358 0, pmom, orig, polar, 0., kPNoProcess, ntr);
361 } // not a new track !
366 } // outside scoring region ?
368 // --- See how long we have to go
374 t = fGener->PropagateCylinder(vect,dir,fGener->RadMax(),fGener->ZMax());
377 fTotAbso += step/absl;
378 fTotRadl += step/radl;
379 fTotGcm2 += step*dens;
386 // Geometry debugging
387 // Fly back and compare volume sequence
389 TClonesArray &lvols = *fVolumesBwd;
390 if (fStepsBackward < fStepsForward) {
391 AliDebugVolume* tmp = (AliDebugVolume*) (*fVolumesBwd)[fStepsBackward];
392 if (tmp->IsEqual(vol, copy) && gMC->IsTrackEntering()) {
394 delete ((AliDebugVolume*) lvols[fStepsBackward-1]);
395 delete ((AliDebugVolume*) lvols[fStepsBackward-2]);
396 step += ((AliDebugVolume*) lvols[fStepsBackward])->Step();
401 // printf("\n steps %d %s %d", fStepsBackward, vol, fErrorCondition);
402 if (fStepsBackward < 0) {
408 new(lvols[fStepsBackward]) AliDebugVolume(vol,copy,step,pos[0], pos[1], pos[2], status);
410 AliDebugVolume* tmp = (AliDebugVolume*) (*fVolumesFwd)[fStepsBackward];
411 if (! (tmp->IsEqual(vol, copy)) && (!fErrorCondition))
413 printf("\n Problem at (x,y,z): %d %f %f %f, volumes: %s %s step: %f\n",
414 fStepsBackward, pos[0], pos[1], pos[2], tmp->GetName(), vol, step);
421 void AliLego::DumpVolumes()
424 // Dump volume sequence in case of error
426 printf("\n Dumping Volume Sequence:");
427 printf("\n ==============================================");
429 for (Int_t i = fStepsForward-1; i>=0; i--)
431 AliDebugVolume* tmp1 = (AliDebugVolume*) (*fVolumesFwd)[i];
432 AliDebugVolume* tmp2 = (AliDebugVolume*) (*fVolumesBwd)[i];
433 printf("\n Volume Fwd: %3d: %5s (%3d) step: %12.5e (x,y,z) (%12.5e %12.5e %12.5e) status: %9s\n"
435 tmp1->GetName(), tmp1->CopyNumber(), tmp1->Step(),
436 tmp1->X(), tmp1->Y(), tmp1->Z(), tmp1->Status());
438 printf("\n Volume Bwd: %3d: %5s (%3d) step: %12.5e (x,y,z) (%12.5e %12.5e %12.5e) status: %9s\n"
440 tmp2->GetName(), tmp2->CopyNumber(), tmp2->Step(),
441 tmp2->X(), tmp2->Y(), tmp2->Z(), tmp2->Status());
443 printf("\n ............................................................................\n");
445 printf("\n ==============================================\n");