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.2 2002/10/14 14:55:34 hristov
19 Merging the VirtualMC branch to the main development branch (HEAD)
21 Revision 1.1.2.1 2002/10/10 14:40:31 hristov
22 Updating VirtualMC to v3-09-02
24 Revision 1.1 2002/10/07 11:25:28 gamez
25 First version, generation of cosmic muons on the surface
30 /////////////////////////////////////////////////////////////////////////////
32 // Contain parametrizations to generate atmospheric muons, and also
33 // to generate single muons and muon bundles at surface level.
37 <img src="picts/AliGenCRTClass.gif">
40 <font size=+2 color=red>
41 <p>The responsible person for this module is
42 <a href="mailto:Enrique.Gamez.Flores@cern.ch">Enrique Gamez</a>.
48 /////////////////////////////////////////////////////////////////////////////
50 #include <Riostream.h>
55 #include "AliMCProcess.h"
57 #include "AliGenCRT.h"
61 //_____________________________________________________________________________
62 AliGenCRT::AliGenCRT() : AliGenerator(-1)
76 // Set the origin above the vertex, on the surface.
96 fUnfoldedMomentumDist = 0;
101 //_____________________________________________________________________________
102 AliGenCRT::AliGenCRT(Int_t npart)
103 : AliGenerator(npart)
109 fTitle = "Cosmic Muons generator";
111 // Generate Muon- by default
120 // Set the origin above the vertex, on the surface.
122 fOrigin[1] = AliCRTConstants::fgDepth; // At the surface by default.
125 fZenithMin = 0.; // Generate veritcals by default.
131 fPResolution = 1.; // 1 GeV by default.
132 fPRange = 0.; // 0 GeV by default.
140 fUnfoldedMomentumDist = 0;
145 //_____________________________________________________________________________
146 AliGenCRT::AliGenCRT(const AliGenCRT& gen) : AliGenerator()
154 //_____________________________________________________________________________
155 AliGenCRT& AliGenCRT::operator= (const AliGenCRT& gen)
164 //_____________________________________________________________________________
165 AliGenCRT::~AliGenCRT()
170 if ( fAp ) delete fAp;
171 if ( fMomentumDist ) delete fMomentumDist;
172 if ( fUnfoldedMomentumDist ) delete fUnfoldedMomentumDist;
173 if ( fZenithDist ) delete fZenithDist;
174 if ( fPDist ) delete fPDist;
177 //_____________________________________________________________________________
178 void AliGenCRT::Generate()
181 // Generate on one trigger
184 Float_t polar[3]= {0,0,0}; // Polarization parameters
190 Float_t zenith, azimuth;
195 // Check if you need to use a distribution function for the momentum
196 if ( fMomentumDist ) {
197 pmom = - this->GetMomentum(); // Always downwards.
204 zenith = this->GetZenithAngle(pmom); // In degrees
206 // Take the azimuth random.
208 azimuth = (fAzimuthMin + (fAzimuthMax-fAzimuthMin)*random[0]); // In degrees
210 origin[0] = AliCRTConstants::fgDepth*TMath::Tan(zenith*kDegrad)*
211 TMath::Sin(azimuth*kDegrad);
212 origin[1] = AliCRTConstants::fgDepth;
213 origin[2] = AliCRTConstants::fgDepth*TMath::Tan(zenith*kDegrad)*
214 TMath::Cos(azimuth*kDegrad);
216 if ( fVertexSmear == kPerEvent ) {
220 // Don't smear the vertical position.
221 origin[j] = AliCRTConstants::fgDepth;
223 origin[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
224 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
230 if ( fCRMode == kSingleMuons ) {
233 // Generate kinematics a la AliGenBox
236 for(i=0;i<fNpart;i++) {
239 if(TestBit(kMomentumRange)) {
240 pmom = -( fPMin + random[1]*(fPMax - fPMin) ); // always downwards.
241 pt=pmom*TMath::Sin(zenith*kDegrad);
244 pt= -(fPtMin+random[1]*(fPtMax-fPtMin)); // always downwards.
245 pmom=pt/TMath::Sin(zenith*kDegrad);
248 p[0] = pt*TMath::Sin(azimuth*kDegrad);
249 p[1] = pmom*TMath::Cos(zenith*kDegrad);
250 p[2] = pt*TMath::Cos(azimuth*kDegrad);
252 if(fVertexSmear==kPerTrack) {
256 origin[j] = AliCRTConstants::fgDepth;
258 origin[j]=fOrigin[j]+fOsigma[j]*
259 TMath::Cos(2*random[2*j]*TMath::Pi())*
260 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
267 // End of generation a la AliGenBox
269 } else if ( fCRMode == kMuonBundle ) {
272 // Generate kinematics a la AliGenScan
288 for (Int_t ix=0; ix<fNx; ix++) {
289 for (Int_t iz=0; iz<fNz; iz++){
291 origin[0]+=ix*dx+2*(random[0]-0.5)*fOsigma[0];
292 origin[2]+=iz*dz+2*(random[1]-0.5)*fOsigma[2];
294 pmom = -(fPMin + random[3] *(fPMax - fPMax) ); // Always downward.
295 p[0] = TMath::Sin(zenith*kDegrad)*TMath::Sin(azimuth*kDegrad)*pmom;
296 p[1] = TMath::Cos(zenith*kDegrad)*pmom;
297 p[2] = TMath::Sin(zenith*kDegrad)*TMath::Cos(azimuth*kDegrad)*pmom;
302 // End of generation a la AliGenScan
304 } else if ( fCRMode == kMuonFlux ) {
306 // Always generate the things downwards.
307 p[0] = TMath::Sin(zenith*kDegrad)*TMath::Sin(azimuth*kDegrad)*pmom;
308 p[1] = TMath::Cos(zenith*kDegrad)*pmom;
309 p[2] = TMath::Sin(zenith*kDegrad)*TMath::Cos(azimuth*kDegrad)*pmom;
312 Error("Generate", "Generation Mode unknown!\n");
315 // Put the track on the stack.
316 SetTrack(fTrackIt,-1,fIpart,p,origin,polar,0,kPPrimary,nt);
321 //_____________________________________________________________________________
322 void AliGenCRT::Init()
325 // Initialize some internal methods.
328 // Determine some specific data members.
329 fPRange = TMath::Abs(fPMax-fPMin);
331 if ( fCRMode == kSingleMuons ) {
332 fCRModeName = new TString("Single Muons");
333 // Initialisation, check consistency of selected ranges
334 if(TestBit(kPtRange)&&TestBit(kMomentumRange))
335 Fatal("Init","You should not set the momentum range and the pt range!");
337 if((!TestBit(kPtRange))&&(!TestBit(kMomentumRange)))
338 Fatal("Init","You should set either the momentum or the pt range!");
340 } else if ( fCRMode == kMuonBundle ) {
341 fCRModeName = new TString("Muon Bundles");
343 } else if ( fCRMode == kMuonFlux ) {
344 fCRModeName = new TString("Muon Fluxes");
345 // Initialize the ditribution functions.
346 this->InitMomentumGeneration();
347 this->InitZenithalAngleGeneration();
350 Fatal("Generate", "Generation Mode unknown!\n");
356 //____________________________________________________________________________
357 void AliGenCRT::SetGridRange(Int_t nx,Float_t xwidth, Int_t nz, Float_t zwidth)
361 // This data shuold be used for Muon bundles generation.
368 // Print a message about the use, if the Mode has not been set, or
369 // it has to a different Mode.
370 if ( fCRMode != kMuonBundle ) {
371 Warning("SetRange","You have been specified a grid to generate muon bundles, but seems that you haven't choose this generation mode, or you have already select a different one");
376 //____________________________________________________________________________
377 void AliGenCRT::InitApWeightFactors()
380 // This factors will be to correct the zenithal angle distribution
381 // acording the momentum
384 // Fill the array for the flux zenith angle dependence.
385 // at the index 0 of fAp[] will be the "factor" if we have a muon
387 Float_t a[6] = {-1.61, -1.50, -1.28, -0.94, -0.61, -0.22};
388 Float_t p[6] = { 0., 10., 30., 100., 300., 1000.};
390 // Get the information from the momentum
391 Int_t pEnd = TMath::Abs(TMath::Nint(fPMax/fPResolution)) + 1;
392 // Initialize the Array of floats to hold the a(p) factors.
393 fAp = new TArrayF(pEnd);
397 for (Int_t i = 0; i < pEnd; i++ ) {
398 Float_t currentP = ((Float_t)i)*fPResolution;
399 if ( currentP < p[1] ) index = 0;
400 else if ( currentP >= p[1] && currentP < p[2] ) index = 1;
401 else if ( currentP >= p[2] && currentP < p[3] ) index = 2;
402 else if ( currentP >= p[3] && currentP < p[4] ) index = 3;
403 else if ( currentP >= p[4] ) index = 4;
405 Float_t ap = (currentP -p[index])*(a[index+1] - a[index])/
406 (p[index+1] - p[index]) + a[index];
412 //___________________________________________________________________________
413 void AliGenCRT::InitMomentumGeneration()
416 // Initialize a funtion to generate the momentum randomly
417 // acording this function.
420 // Check if we nned to initialize the function
421 if ( fPMin != fPMax ) {
423 // Check also if the function have been defined yet.
424 if ( !fMomentumDist ) {
426 // If not, use this function
427 const char* y = "log10(x)";
429 const char* h1Coef = "[0]*( %s*%s*%s/2 - (5*%s*%s/2) + 3*%s )";
430 const char* h2Coef = "[1]*( (-2*%s*%s*%s/3) + (3*%s*%s) - 10*%s/3 + 1 )";
431 const char* h3Coef = "[2]*( %s*%s*%s/6 - %s*%s/2 + %s/3 )";
432 const char* s2Coef = "[3]*( %s*%s*%s/3 - 2*%s*%s + 11*%s/3 - 2 )";
434 const char* h = "%s + %s + %s + %s";
435 const char* flux = "pow(10., %s)";
436 const char* normalizedFlux = "0.86*x*x*x*pow(10., %s)";
437 const char* paramNames[4] = {"H1", "H2", "H3", "S1"};
447 sprintf(buffer1, h1Coef, y, y, y, y, y, y);
448 sprintf(buffer2, h2Coef, y, y, y, y, y, y);
449 sprintf(buffer3, h3Coef, y, y, y, y, y, y);
450 sprintf(buffer4, s2Coef, y, y, y, y, y, y);
452 sprintf(buffer5, h, buffer1, buffer2, buffer3, buffer4);
454 sprintf(buffer6, flux, buffer5);
456 fMomentumDist = new TF1("fMomentumDist", buffer6, fPMin, fPMax);
457 sprintf(buffer7, normalizedFlux, buffer5);
458 fUnfoldedMomentumDist = new TF1("fUnfoldedMomentumDist", buffer7, fPMin, fPMax);
459 for (Int_t i = 0; i < 4; i++ ) {
460 fMomentumDist->SetParName(i, paramNames[i]);
461 fUnfoldedMomentumDist->SetParName(i, paramNames[i]);
464 fMomentumDist->SetParameter(0, 0.133);
465 fMomentumDist->SetParameter(1, -2.521);
466 fMomentumDist->SetParameter(2, -5.78);
467 fMomentumDist->SetParameter(3, -2.11);
469 fUnfoldedMomentumDist->SetParameter(0, 0.133);
470 fUnfoldedMomentumDist->SetParameter(1, -2.521);
471 fUnfoldedMomentumDist->SetParameter(2, -5.78);
472 fUnfoldedMomentumDist->SetParameter(3, -2.11);
480 //____________________________________________________________________________
481 void AliGenCRT::InitZenithalAngleGeneration()
484 // Initalize a distribution function for the zenith angle.
485 // This angle will be obtained randomly acording this function.
486 // The generated angles will been in degrees.
488 // Check if we need to create the function.
489 if ( fZenithMin != fZenithMax ) {
491 // Check also if another function have been defined.
492 if ( !fZenithDist ) {
494 // initialize the momentum dependent coefficients, a(p)
495 InitApWeightFactors();
497 // Define the standard function.
498 char* zenithalDisributionFunction = "1 + [0]*(1 - cos(x*3.14159265358979312/180))";
500 Int_t pEnd = TMath::Abs(TMath::Nint(fPMax/fPResolution)) + 1;
501 fPDist = new TClonesArray("TF1", pEnd);
502 TClonesArray &angle = *fPDist;
503 for ( Int_t i = 0; i < pEnd; i++ ) {
504 // Fill the distribution
505 TF1* zenith = new(angle[i]) TF1("zenith",zenithalDisributionFunction, fZenithMin, fZenithMax);
507 // Fix the momentum dependent coefficients
508 zenith->SetParName(0, "a(p)");
509 zenith->SetParameter(0, fAp->At(i));
519 //____________________________________________________________________________
520 const Float_t AliGenCRT::GetZenithAngle(Float_t mom)
524 // Check if you need to generate a constant zenith angle.
525 if ( !fZenithDist ) {
526 // Check if you have defined an array of momentum functions
528 Int_t pIndex = TMath::Abs(TMath::Nint(mom));
529 TF1* zenithAngle = (TF1*)fPDist->UncheckedAt(pIndex);
530 zenith = zenithAngle->GetRandom();
534 if ( fCRMode != kMuonFlux ) {
535 // If you aren't generating muons obeying any ditribution
536 // only generate a flat zenith angle, acording the input settings
539 zenith = fZenithMin + (fZenithMax - fZenithMin)*random[0];
542 // Even if you are generating muons acording some distribution,
543 // but you don't want to ...
550 zenith = fZenithDist->GetRandom();
557 //____________________________________________________________________________