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 //////////////////////////////////////////////////////////////
19 //////////////////////////////////////////////////////////////
21 // Utility class to evaluate the material budget from
22 // a given radius to the surface of an arbitrary cylinder
23 // along radial directions from the centre:
26 // - Interaction length
29 // Geantinos are shot in the bins in the fNtheta bins in theta
30 // and fNphi bins in phi with specified rectangular limits.
31 // The statistics are accumulated per
32 // fRadMin < r < fRadMax and <0 < z < fZMax
34 // To activate this option, you can do:
35 // Root > gAlice.RunLego();
36 // or Root > .x menu.C then select menu item "RunLego"
37 // Note that when calling gAlice->RunLego, an optional list
38 // of arguments may be specified.
42 <img src="picts/alilego.gif">
46 //////////////////////////////////////////////////////////////
48 #include "TClonesArray.h"
52 #include "TVirtualMC.h"
55 #include "AliDebugVolume.h"
57 #include "AliLegoGenerator.h"
63 //_______________________________________________________________________
86 // Default constructor
90 //_______________________________________________________________________
91 AliLego::AliLego(const AliLego &lego):
120 //_______________________________________________________________________
121 AliLego::AliLego(const char *title, Int_t ntheta, Float_t thetamin,
122 Float_t thetamax, Int_t nphi, Float_t phimin, Float_t phimax,
123 Float_t rmin, Float_t rmax, Float_t zmax):
124 TNamed("Lego Generator",title),
146 // specify the angular limits and the size of the rectangular box
148 fGener = new AliLegoGenerator(ntheta, thetamin, thetamax,
149 nphi, phimin, phimax, rmin, rmax, zmax);
150 fHistRadl = new TH2F("hradl","Radiation length map",
151 ntheta,thetamin,thetamax,nphi,phimin,phimax);
152 fHistAbso = new TH2F("habso","Interaction length map",
153 ntheta,thetamin,thetamax,nphi,phimin,phimax);
154 fHistGcm2 = new TH2F("hgcm2","g/cm2 length map",
155 ntheta,thetamin,thetamax,nphi,phimin,phimax);
156 fRZR = new TH2F("rzR","Radiation length @ (r,z)",
157 zmax,-zmax,zmax,(rmax-rmin),rmin,rmax);
158 fRZR->SetXTitle("#it{z} [cm]");
159 fRZR->SetYTitle("#it{r} [cm]");
160 fRZA = static_cast<TH2F*>(fRZR->Clone("rzA"));
161 fRZA->SetTitle("Interaction length @ (r,z)");
162 fRZG = static_cast<TH2F*>(fRZR->Clone("rzG"));
163 fRZG->SetTitle("g/cm^{2} @ (r,z)");
166 fVolumesFwd = new TClonesArray("AliDebugVolume",1000);
167 fVolumesBwd = new TClonesArray("AliDebugVolume",1000);
168 fDebug = AliDebugLevel();
171 //_______________________________________________________________________
172 AliLego::AliLego(const char *title, AliLegoGenerator* generator):
173 TNamed("Lego Generator",title),
195 // specify the angular limits and the size of the rectangular box
198 Float_t c1min, c1max, c2min, c2max;
199 Int_t n1 = fGener->NCoor1();
200 Int_t n2 = fGener->NCoor2();
202 fGener->Coor1Range(c1min, c1max);
203 fGener->Coor2Range(c2min, c2max);
205 fHistRadl = new TH2F("hradl","Radiation length map",
206 n2, c2min, c2max, n1, c1min, c1max);
207 fHistAbso = new TH2F("habso","Interaction length map",
208 n2, c2min, c2max, n1, c1min, c1max);
209 fHistGcm2 = new TH2F("hgcm2","g/cm2 length map",
210 n2, c2min, c2max, n1, c1min, c1max);
211 Double_t rmax = generator->RadMax();
213 Double_t zmax = generator->ZMax();
214 fRZR = new TH2F("rzR","Radiation length @ (r,z)",
215 2*zmax,-zmax,zmax,(rmax-rmin),rmin,rmax);
216 fRZR->SetXTitle("#it{z} [cm]");
217 fRZR->SetYTitle("#it{r} [cm]");
218 fRZA = static_cast<TH2F*>(fRZR->Clone("rzA"));
219 fRZA->SetTitle("Interaction length @ (r,z)");
220 fRZG = static_cast<TH2F*>(fRZR->Clone("rzG"));
221 fRZG->SetTitle("g/cm^{2} @ (r,z)");
225 fVolumesFwd = new TClonesArray("AliDebugVolume",1000);
226 fVolumesBwd = new TClonesArray("AliDebugVolume",1000);
227 fDebug = AliDebugLevel();
230 //_______________________________________________________________________
244 //_______________________________________________________________________
245 void AliLego::BeginEvent()
248 // --- Set to 0 radiation length, absorption length and g/cm2 ---
256 if (fErrorCondition) ToAliDebug(1, DumpVolumes());
257 fVolumesFwd->Delete();
258 fVolumesBwd->Delete();
262 if (gAlice->GetMCApp()->GetCurrentTrackNumber() == 0) fStepBack = 0;
266 //_______________________________________________________________________
267 void AliLego::FinishEvent()
270 // Finish the event and update the histos
273 c1 = fGener->CurCoor1();
274 c2 = fGener->CurCoor2();
275 fHistRadl->Fill(c2,c1,fTotRadl);
276 fHistAbso->Fill(c2,c1,fTotAbso);
277 fHistGcm2->Fill(c2,c1,fTotGcm2);
280 //_______________________________________________________________________
281 void AliLego::FinishRun()
284 // Store histograms in current Root file
293 // Delete histograms from memory
294 fHistRadl->Delete(); fHistRadl=0;
295 fHistAbso->Delete(); fHistAbso=0;
296 fHistGcm2->Delete(); fHistGcm2=0;
298 if (fErrorCondition) ToAliError(DumpVolumes());
301 //_______________________________________________________________________
302 void AliLego::Copy(TObject&) const
305 // Copy *this onto lego -- not implemented
307 AliFatal("Not implemented!");
310 //_______________________________________________________________________
311 void AliLego::StepManager()
314 // called from AliRun::Stepmanager from gustep.
315 // Accumulate the 3 parameters step by step
318 Float_t a,z,dens,radl,absl;
321 static Float_t vect[3], dir[3];
325 id = TVirtualMC::GetMC()->CurrentVolID(copy);
326 vol = TVirtualMC::GetMC()->VolName(id);
327 Float_t step = TVirtualMC::GetMC()->TrackStep();
329 TLorentzVector pos, mom;
330 TVirtualMC::GetMC()->TrackPosition(pos);
331 TVirtualMC::GetMC()->TrackMomentum(mom);
334 if (TVirtualMC::GetMC()->IsTrackEntering()) status = 1;
335 if (TVirtualMC::GetMC()->IsTrackExiting()) status = 2;
338 // printf("\n volume %s %d", vol, status);
340 // Normal Forward stepping
343 // printf("\n steps fwd %d %s %d %f", fStepsForward, vol, fErrorCondition, step);
346 // store volume if different from previous
349 TClonesArray &lvols = *fVolumesFwd;
350 if (fStepsForward > 0) {
351 AliDebugVolume* tmp = dynamic_cast<AliDebugVolume*>((*fVolumesFwd)[fStepsForward-1]);
352 if (tmp && tmp->IsVEqual(vol, copy) && TVirtualMC::GetMC()->IsTrackEntering()) {
354 fVolumesFwd->RemoveAt(fStepsForward);
355 fVolumesFwd->RemoveAt(fStepsForward+1);
359 new(lvols[fStepsForward++])
360 AliDebugVolume(vol,copy,step,pos[0], pos[1], pos[2], status);
364 // Get current material properties
366 TVirtualMC::GetMC()->CurrentMaterial(a,z,dens,radl,absl);
367 Double_t r = TMath::Sqrt(pos[0]*pos[0] +pos[1]*pos[1]);
368 fRZR->Fill(pos[2], r, step/radl);
369 fRZA->Fill(pos[2], r ,step/absl);
370 fRZG->Fill(pos[2], r, step*dens);
375 // --- See if we have to stop now
376 if (TMath::Abs(pos[2]) > TMath::Abs(fGener->ZMax()) ||
377 r > fGener->RadMax()) {
378 if (!TVirtualMC::GetMC()->IsNewTrack()) {
379 // Not the first step, add past contribution
381 if (absl) fTotAbso += t/absl;
382 if (radl) fTotRadl += t/radl;
386 // printf("We will stop now %5d %13.3f !\n", fStopped, t);
387 // printf("%13.3f %13.3f %13.3f %13.3f %13.3f %13.3f %13.3f %s %13.3f\n",
388 // pos[2], TMath::Sqrt(pos[0] * pos[0] + pos[1] * pos[1]), step, a, z, radl, absl, TVirtualMC::GetMC()->CurrentVolName(), fTotRadl);
391 // generate "mirror" particle flying back
393 fStepsBackward = fStepsForward;
395 Float_t pmom[3], orig[3];
396 Float_t polar[3] = {0.,0.,0.};
405 gAlice->GetMCApp()->PushTrack(1, gAlice->GetMCApp()->GetCurrentTrackNumber(),
406 0, pmom, orig, polar, 0., kPNoProcess, ntr);
409 } // not a new track !
411 if (fDebug) fStepBack = 1;
413 TVirtualMC::GetMC()->StopTrack();
415 } // outside scoring region ?
417 // --- See how long we have to go
423 t = fGener->PropagateCylinder(vect,dir,fGener->RadMax(),fGener->ZMax());
427 if (absl) fTotAbso += step/absl;
428 if (radl) fTotRadl += step/radl;
429 fTotGcm2 += step*dens;
430 // printf("%13.3f %13.3f %13.3f %13.3f %13.3f %13.3f %13.3f %s %13.3f\n",
431 // pos[2], TMath::Sqrt(pos[0] * pos[0] + pos[1] * pos[1]), step, a, z, radl, absl, TVirtualMC::GetMC()->CurrentVolName(), fTotRadl);
437 // Geometry debugging
438 // Fly back and compare volume sequence
440 TClonesArray &lvols = *fVolumesBwd;
441 if (fStepsBackward < fStepsForward) {
442 AliDebugVolume* tmp = dynamic_cast<AliDebugVolume*>((*fVolumesBwd)[fStepsBackward]);
443 if (tmp && tmp->IsVEqual(vol, copy) && TVirtualMC::GetMC()->IsTrackEntering()) {
445 fVolumesBwd->RemoveAt(fStepsBackward-1);
446 fVolumesBwd->RemoveAt(fStepsBackward-2);
451 // printf("\n steps %d %s %d", fStepsBackward, vol, fErrorCondition);
452 if (fStepsBackward < 0) {
453 TVirtualMC::GetMC()->StopTrack();
458 new(lvols[fStepsBackward]) AliDebugVolume(vol,copy,step,pos[0], pos[1], pos[2], status);
460 AliDebugVolume* tmp = dynamic_cast<AliDebugVolume*>((*fVolumesFwd)[fStepsBackward]);
461 if (tmp && !(tmp->IsVEqual(vol, copy)) && (!fErrorCondition))
463 AliWarning(Form("Problem at (x,y,z): %d %f %f %f, volumes: %s %s step: %f\n",
464 fStepsBackward, pos[0], pos[1], pos[2], tmp->GetName(), vol, step));
471 //_______________________________________________________________________
472 void AliLego::DumpVolumes()
475 // Dump volume sequence in case of error
477 printf("\n Dumping Volume Sequence:");
478 printf("\n ==============================================");
480 for (Int_t i = fStepsForward-1; i>=0; i--)
482 AliDebugVolume* tmp1 = dynamic_cast<AliDebugVolume*>((*fVolumesFwd)[i]);
483 AliDebugVolume* tmp2 = dynamic_cast<AliDebugVolume*>((*fVolumesBwd)[i]);
485 printf("\n Volume Fwd: %3d: %5s (%3d) step: %12.5e (x,y,z) (%12.5e %12.5e %12.5e) status: %9s \n"
487 tmp1->GetName(), tmp1->CopyNumber(), tmp1->Step(),
488 tmp1->X(), tmp1->Y(), tmp1->Z(), tmp1->Status());
489 if (tmp2 && i>= fStepsBackward)
490 printf("\n Volume Bwd: %3d: %5s (%3d) step: %12.5e (x,y,z) (%12.5e %12.5e %12.5e) status: %9s \n"
492 tmp2->GetName(), tmp2->CopyNumber(), tmp2->Step(),
493 tmp2->X(), tmp2->Y(), tmp2->Z(), tmp2->Status());
495 printf("\n ............................................................................\n");
497 printf("\n ==============================================\n");