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