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 **************************************************************************/
21 /////////////////////////////////////////////////////////////////////////////
23 // Contain parametrizations to generate atmospheric muons, and also
24 // to generate single muons and muon bundles at surface level.
28 <img src="picts/AliGenCRTClass.gif">
31 <font size=+2 color=red>
32 <p>The responsible person for this module is
33 <a href="mailto:Enrique.Gamez.Flores@cern.ch">Enrique Gamez</a>.
39 /////////////////////////////////////////////////////////////////////////////
46 #include "AliMCProcess.h"
48 #include "AliGenCRT.h"
52 //_____________________________________________________________________________
53 AliGenCRT::AliGenCRT() : AliGenerator(-1)
67 // Set the origin above the vertex, on the surface.
87 fUnfoldedMomentumDist = 0;
92 //_____________________________________________________________________________
93 AliGenCRT::AliGenCRT(Int_t npart)
100 fTitle = "Cosmic Muons generator";
102 // Generate Muon- by default
111 // Set the origin above the vertex, on the surface.
113 fOrigin[1] = AliCRTConstants::fgDepth; // At the surface by default.
116 fZenithMin = 0.; // Generate veritcals by default.
122 fPResolution = 1.; // 1 GeV by default.
123 fPRange = 0.; // 0 GeV by default.
131 fUnfoldedMomentumDist = 0;
136 //_____________________________________________________________________________
137 AliGenCRT::AliGenCRT(const AliGenCRT& gen) : AliGenerator()
145 //_____________________________________________________________________________
146 AliGenCRT& AliGenCRT::operator= (const AliGenCRT& gen)
155 //_____________________________________________________________________________
156 AliGenCRT::~AliGenCRT()
161 if ( fAp ) delete fAp;
162 if ( fMomentumDist ) delete fMomentumDist;
163 if ( fUnfoldedMomentumDist ) delete fUnfoldedMomentumDist;
164 if ( fZenithDist ) delete fZenithDist;
165 if ( fPDist ) delete fPDist;
168 //_____________________________________________________________________________
169 void AliGenCRT::Generate()
172 // Generate on one trigger
175 Float_t polar[3]= {0,0,0}; // Polarization parameters
181 Float_t zenith, azimuth;
186 // Check if you need to use a distribution function for the momentum
187 if ( fMomentumDist ) {
188 pmom = - this->GetMomentum(); // Always downwards.
195 zenith = this->GetZenithAngle(pmom); // In degrees
197 // Take the azimuth random.
199 azimuth = (fAzimuthMin + (fAzimuthMax-fAzimuthMin)*random[0]); // In degrees
201 origin[0] = AliCRTConstants::fgDepth*TMath::Tan(zenith*kDegrad)*
202 TMath::Sin(azimuth*kDegrad);
203 origin[1] = AliCRTConstants::fgDepth;
204 origin[2] = AliCRTConstants::fgDepth*TMath::Tan(zenith*kDegrad)*
205 TMath::Cos(azimuth*kDegrad);
207 if ( fVertexSmear == kPerEvent ) {
211 // Don't smear the vertical position.
212 origin[j] = AliCRTConstants::fgDepth;
214 origin[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
215 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
221 if ( fCRMode == kSingleMuons ) {
224 // Generate kinematics a la AliGenBox
227 for(i=0;i<fNpart;i++) {
230 if(TestBit(kMomentumRange)) {
231 pmom = -( fPMin + random[1]*(fPMax - fPMin) ); // always downwards.
232 pt=pmom*TMath::Sin(zenith*kDegrad);
235 pt= -(fPtMin+random[1]*(fPtMax-fPtMin)); // always downwards.
236 pmom=pt/TMath::Sin(zenith*kDegrad);
239 p[0] = pt*TMath::Sin(azimuth*kDegrad);
240 p[1] = pmom*TMath::Cos(zenith*kDegrad);
241 p[2] = pt*TMath::Cos(azimuth*kDegrad);
243 if(fVertexSmear==kPerTrack) {
247 origin[j] = AliCRTConstants::fgDepth;
249 origin[j]=fOrigin[j]+fOsigma[j]*
250 TMath::Cos(2*random[2*j]*TMath::Pi())*
251 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
258 // End of generation a la AliGenBox
260 } else if ( fCRMode == kMuonBundle ) {
263 // Generate kinematics a la AliGenScan
279 for (Int_t ix=0; ix<fNx; ix++) {
280 for (Int_t iz=0; iz<fNz; iz++){
282 origin[0]+=ix*dx+2*(random[0]-0.5)*fOsigma[0];
283 origin[2]+=iz*dz+2*(random[1]-0.5)*fOsigma[2];
285 pmom = -(fPMin + random[3] *(fPMax - fPMax) ); // Always downward.
286 p[0] = TMath::Sin(zenith*kDegrad)*TMath::Sin(azimuth*kDegrad)*pmom;
287 p[1] = TMath::Cos(zenith*kDegrad)*pmom;
288 p[2] = TMath::Sin(zenith*kDegrad)*TMath::Cos(azimuth*kDegrad)*pmom;
293 // End of generation a la AliGenScan
295 } else if ( fCRMode == kMuonFlux ) {
297 // Always generate the things downwards.
298 p[0] = TMath::Sin(zenith*kDegrad)*TMath::Sin(azimuth*kDegrad)*pmom;
299 p[1] = TMath::Cos(zenith*kDegrad)*pmom;
300 p[2] = TMath::Sin(zenith*kDegrad)*TMath::Cos(azimuth*kDegrad)*pmom;
303 Error("Generate", "Generation Mode unknown!\n");
306 // Put the track on the stack.
307 SetTrack(fTrackIt,-1,fIpart,p,origin,polar,0,kPPrimary,nt);
312 //_____________________________________________________________________________
313 void AliGenCRT::Init()
316 // Initialize some internal methods.
319 // Determine some specific data members.
320 fPRange = TMath::Abs(fPMax-fPMin);
322 if ( fCRMode == kSingleMuons ) {
323 fCRModeName = new TString("Single Muons");
324 // Initialisation, check consistency of selected ranges
325 if(TestBit(kPtRange)&&TestBit(kMomentumRange))
326 Fatal("Init","You should not set the momentum range and the pt range!");
328 if((!TestBit(kPtRange))&&(!TestBit(kMomentumRange)))
329 Fatal("Init","You should set either the momentum or the pt range!");
331 } else if ( fCRMode == kMuonBundle ) {
332 fCRModeName = new TString("Muon Bundles");
334 } else if ( fCRMode == kMuonFlux ) {
335 fCRModeName = new TString("Muon Fluxes");
336 // Initialize the ditribution functions.
337 this->InitMomentumGeneration();
338 this->InitZenithalAngleGeneration();
341 Fatal("Generate", "Generation Mode unknown!\n");
347 //____________________________________________________________________________
348 void AliGenCRT::SetGridRange(Int_t nx,Float_t xwidth, Int_t nz, Float_t zwidth)
352 // This data shuold be used for Muon bundles generation.
359 // Print a message about the use, if the Mode has not been set, or
360 // it has to a different Mode.
361 if ( fCRMode != kMuonBundle ) {
362 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");
367 //____________________________________________________________________________
368 void AliGenCRT::InitApWeightFactors()
371 // This factors will be to correct the zenithal angle distribution
372 // acording the momentum
375 // Fill the array for the flux zenith angle dependence.
376 // at the index 0 of fAp[] will be the "factor" if we have a muon
378 Float_t a[6] = {-1.61, -1.50, -1.28, -0.94, -0.61, -0.22};
379 Float_t p[6] = { 0., 10., 30., 100., 300., 1000.};
381 // Get the information from the momentum
382 Int_t pEnd = TMath::Abs(TMath::Nint(fPMax/fPResolution)) + 1;
383 // Initialize the Array of floats to hold the a(p) factors.
384 fAp = new TArrayF(pEnd);
388 for (Int_t i = 0; i < pEnd; i++ ) {
389 Float_t currentP = ((Float_t)i)*fPResolution;
390 if ( currentP < p[1] ) index = 0;
391 else if ( currentP >= p[1] && currentP < p[2] ) index = 1;
392 else if ( currentP >= p[2] && currentP < p[3] ) index = 2;
393 else if ( currentP >= p[3] && currentP < p[4] ) index = 3;
394 else if ( currentP >= p[4] ) index = 4;
396 Float_t ap = (currentP -p[index])*(a[index+1] - a[index])/
397 (p[index+1] - p[index]) + a[index];
403 //___________________________________________________________________________
404 void AliGenCRT::InitMomentumGeneration()
407 // Initialize a funtion to generate the momentum randomly
408 // acording this function.
411 // Check if we nned to initialize the function
412 if ( fPMin != fPMax ) {
414 // Check also if the function have been defined yet.
415 if ( !fMomentumDist ) {
417 // If not, use this function
418 const char* y = "log10(x)";
420 const char* h1Coef = "[0]*( %s*%s*%s/2 - (5*%s*%s/2) + 3*%s )";
421 const char* h2Coef = "[1]*( (-2*%s*%s*%s/3) + (3*%s*%s) - 10*%s/3 + 1 )";
422 const char* h3Coef = "[2]*( %s*%s*%s/6 - %s*%s/2 + %s/3 )";
423 const char* s2Coef = "[3]*( %s*%s*%s/3 - 2*%s*%s + 11*%s/3 - 2 )";
425 const char* h = "%s + %s + %s + %s";
426 const char* flux = "pow(10., %s)";
427 const char* normalizedFlux = "0.86*x*x*x*pow(10., %s)";
428 const char* paramNames[4] = {"H1", "H2", "H3", "S1"};
438 sprintf(buffer1, h1Coef, y, y, y, y, y, y);
439 sprintf(buffer2, h2Coef, y, y, y, y, y, y);
440 sprintf(buffer3, h3Coef, y, y, y, y, y, y);
441 sprintf(buffer4, s2Coef, y, y, y, y, y, y);
443 sprintf(buffer5, h, buffer1, buffer2, buffer3, buffer4);
445 sprintf(buffer6, flux, buffer5);
447 fMomentumDist = new TF1("fMomentumDist", buffer6, fPMin, fPMax);
448 sprintf(buffer7, normalizedFlux, buffer5);
449 fUnfoldedMomentumDist = new TF1("fUnfoldedMomentumDist", buffer7, fPMin, fPMax);
450 for (Int_t i = 0; i < 4; i++ ) {
451 fMomentumDist->SetParName(i, paramNames[i]);
452 fUnfoldedMomentumDist->SetParName(i, paramNames[i]);
455 fMomentumDist->SetParameter(0, 0.133);
456 fMomentumDist->SetParameter(1, -2.521);
457 fMomentumDist->SetParameter(2, -5.78);
458 fMomentumDist->SetParameter(3, -2.11);
460 fUnfoldedMomentumDist->SetParameter(0, 0.133);
461 fUnfoldedMomentumDist->SetParameter(1, -2.521);
462 fUnfoldedMomentumDist->SetParameter(2, -5.78);
463 fUnfoldedMomentumDist->SetParameter(3, -2.11);
471 //____________________________________________________________________________
472 void AliGenCRT::InitZenithalAngleGeneration()
475 // Initalize a distribution function for the zenith angle.
476 // This angle will be obtained randomly acording this function.
477 // The generated angles will been in degrees.
479 // Check if we need to create the function.
480 if ( fZenithMin != fZenithMax ) {
482 // Check also if another function have been defined.
483 if ( !fZenithDist ) {
485 // initialize the momentum dependent coefficients, a(p)
486 InitApWeightFactors();
488 // Define the standard function.
489 char* zenithalDisributionFunction = "1 + [0]*(1 - cos(x*3.14159265358979312/180))";
491 Int_t pEnd = TMath::Abs(TMath::Nint(fPMax/fPResolution)) + 1;
492 fPDist = new TClonesArray("TF1", pEnd);
493 TClonesArray &angle = *fPDist;
494 for ( Int_t i = 0; i < pEnd; i++ ) {
495 // Fill the distribution
496 TF1* zenith = new(angle[i]) TF1("zenith",zenithalDisributionFunction, fZenithMin, fZenithMax);
498 // Fix the momentum dependent coefficients
499 zenith->SetParName(0, "a(p)");
500 zenith->SetParameter(0, fAp->At(i));
510 //____________________________________________________________________________
511 const Float_t AliGenCRT::GetZenithAngle(Float_t mom)
515 // Check if you need to generate a constant zenith angle.
516 if ( !fZenithDist ) {
517 // Check if you have defined an array of momentum functions
519 Int_t pIndex = TMath::Abs(TMath::Nint(mom));
520 TF1* zenithAngle = (TF1*)fPDist->UncheckedAt(pIndex);
521 zenith = zenithAngle->GetRandom();
525 if ( fCRMode != kMuonFlux ) {
526 // If you aren't generating muons obeying any ditribution
527 // only generate a flat zenith angle, acording the input settings
530 zenith = fZenithMin + (fZenithMax - fZenithMin)*random[0];
533 // Even if you are generating muons acording some distribution,
534 // but you don't want to ...
541 zenith = fZenithDist->GetRandom();
548 //____________________________________________________________________________