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 /////////////////////////////////////////////////////////////////////////////
20 // Contain parametrizations to generate atmospheric muons, and also
21 // to generate single muons and muon bundles at surface level.
25 <img src="picts/AliGenCRTClass.gif">
28 <font size=+2 color=red>
29 <p>The responsible person for this module is
30 <a href="mailto:Enrique.Gamez.Flores@cern.ch">Enrique Gamez</a>.
36 /////////////////////////////////////////////////////////////////////////////
38 #include "AliGenCRT.h"
40 #include <TMCProcess.h>
42 #include <TClonesArray.h>
50 //_____________________________________________________________________________
51 AliGenCRT::AliGenCRT()
54 fCRMode(kSingleMuons),
69 fUnfoldedMomentumDist(0),
78 //_____________________________________________________________________________
79 AliGenCRT::AliGenCRT(Int_t npart)
80 : AliGenerator(npart),
82 fCRMode(kSingleMuons),
97 fUnfoldedMomentumDist(0),
105 fTitle = "Cosmic Muons generator";
107 // Set the origin above the vertex, on the surface.
109 fOrigin[1] = AliCRTConstants::Instance()->Depth(); // At the surface by default.
113 //_____________________________________________________________________________
114 AliGenCRT::AliGenCRT(const AliGenCRT& gen)
123 //_____________________________________________________________________________
124 AliGenCRT& AliGenCRT::operator=(const AliGenCRT& gen)
127 // Asingment operator
133 //_____________________________________________________________________________
134 AliGenCRT::~AliGenCRT()
139 if ( fPDist ) {fPDist->Delete(); delete fPDist; fPDist = 0;}
140 if ( fUnfoldedMomentumDist ) delete fUnfoldedMomentumDist;
141 if ( fMomentumDist ) delete fMomentumDist;
142 if ( fAp ) delete fAp;
143 if ( fCRModeName ) delete fCRModeName;
146 //_____________________________________________________________________________
147 void AliGenCRT::Generate()
150 // Generate on one trigger
151 // Call the respective method inside the loop for the number
152 // of tracks per trigger.
154 for (Int_t i = 0; i < fNpart; i++ ) {
156 if ( fCRMode == kMuonBundle ) {
157 this->GenerateOneMuonBundle();
159 } else if ( fCRMode == kSingleMuons ) {
160 this->GenerateOneSingleMuon(kTRUE);
163 // Generate only single muons but following the parametrizations
164 // for atmospheric muons.
165 this->GenerateOneSingleMuon();
172 //_____________________________________________________________________________
173 void AliGenCRT::Init()
176 // Initialize some internal methods.
179 // Determine some specific data members.
180 fPRange = TMath::Abs(fPMax-fPMin);
182 if ( fCRMode == kSingleMuons ) {
183 fCRModeName = new TString("Single Muons");
184 // Initialisation, check consistency of selected ranges
185 if(TestBit(kPtRange)&&TestBit(kMomentumRange))
186 Fatal("Init","You should not set the momentum range and the pt range!");
188 if((!TestBit(kPtRange))&&(!TestBit(kMomentumRange)))
189 Fatal("Init","You should set either the momentum or the pt range!");
191 } else if ( fCRMode == kMuonBundle ) {
192 fCRModeName = new TString("Muon Bundles");
194 } else if ( fCRMode == kMuonFlux ) {
195 fCRModeName = new TString("Muon Fluxes");
196 // Initialize the ditribution functions.
197 this->InitMomentumGeneration();
198 this->InitZenithalAngleGeneration();
201 Fatal("Generate", "Generation Mode unknown!\n");
207 //____________________________________________________________________________
208 void AliGenCRT::GenerateOneSingleMuon(Bool_t withFlatMomentum)
211 // Generate One Single Muon
212 // This method will generate only one muon.
213 // The momentum will be randomly flat distributed if
214 // the paremeter "withFlatMomentum" is set to kTRUE,
215 // otherwise the momentum will generate acordingly the parametrization
217 // and adpted from Bruno Alessandro's implementation with the
218 // CERNLIB to AliRoot.
219 // The "withFlatMomentum" parameter also will be used to generate
220 // the muons with a flat Zenithal angle distribution.
221 // Do the smearing here, so that means per track.
223 Float_t polar[3]= {0,0,0}; // Polarization parameters
230 // Take the azimuth random.
232 Float_t azimuth = fAzimuthMin + (fAzimuthMax-fAzimuthMin)*random[0];
233 Float_t zenith = fZenithMin + (fZenithMax - fZenithMin)*random[1];
235 if ( withFlatMomentum ) {
237 if(TestBit(kMomentumRange)) {
238 pmom = -( fPMin + random[0]*(fPMax - fPMin) ); // always downwards.
239 pt = pmom*TMath::Sin(zenith*kDegrad);
241 pt = -( fPtMin + random[1]*(fPtMax - fPtMin)); // always downwards.
242 pmom = pt/TMath::Sin(zenith*kDegrad);
246 if ( fMomentumDist ) {
247 pmom = -this->GetMomentum(); // Always downwards.
251 zenith = this->GetZenithAngle(pmom); // In degrees
252 pt = pmom*TMath::Sin(zenith*kDegrad);
255 p[0] = pt*TMath::Sin(azimuth*kDegrad);
256 p[1] = pmom*TMath::Cos(zenith*kDegrad);
257 p[2] = pt*TMath::Cos(azimuth*kDegrad);
259 // Finaly the origin, with the smearing
261 origin[0] = AliCRTConstants::Instance()->Depth()*TMath::Tan(zenith*kDegrad)*
262 TMath::Sin(azimuth*kDegrad);
263 // + fOsigma[0]* TMath::Cos(2*random[0]*TMath::Pi())*TMath::Sqrt(-2*TMath::Log(random[1]));
265 origin[1] = AliCRTConstants::Instance()->Depth();
267 origin[2] = AliCRTConstants::Instance()->Depth()*TMath::Tan(zenith*kDegrad)*
268 TMath::Cos(azimuth*kDegrad);
269 // + fOsigma[2]* TMath::Cos(2*random[2]*TMath::Pi())*TMath::Sqrt(-2*TMath::Log(random[3]));;
271 // Put the track on the stack.
272 PushTrack(fTrackIt,-1,fIpart,p,origin,polar,0,kPPrimary,nt);
276 //____________________________________________________________________________
277 void AliGenCRT::GenerateOneMuonBundle()
280 // Generate One Muon Bundle method
281 // This method will generate a bunch of muons following the
282 // procedure of the AliGenScan class.
283 // These muons will be generated with flat momentum.
285 Float_t polar[3]= {0,0,0}; // Polarization parameters
293 //Float_t zenith = fZenithMin + (fZenithMax - fZenithMin)*random[1];
294 //Float_t azimuth = fAzimuthMin + (fAzimuthMax-fAzimuthMin)*random[2];
296 Float_t azimuth = 30;
298 // Generate the kinematics a la AliGenScan (Andreas Morchs)
314 //origin[0] = AliCRTConstants::fgDepth*TMath::Tan(zenith*kDegrad)*
316 //TMath::Sin(azimuth*kDegrad);
317 //origin[1] = AliCRTConstants::fgDepth;
319 //origin[2] = AliCRTConstants::fgDepth*TMath::Tan(zenith*kDegrad)*
321 //TMath::Cos(azimuth*kDegrad);
323 for (Int_t ix = 0; ix < fNx; ix++ ) {
324 for (Int_t iz = 0; iz < fNz; iz++ ) {
326 origin[0]+=ix*dx+2*(random[1]-0.5)*fOsigma[0];
327 origin[2]+=iz*dz+2*(random[2]-0.5)*fOsigma[2];
328 if ( random[4] < 0.5 ) {
329 origin[0] = -1*origin[0];
331 if ( random[5] < 0.5 ) {
332 origin[2] = -1*origin[2];
335 pmom = -(fPMin + random[3] *(fPMax - fPMax) ); // Always downwards
336 p[0] = TMath::Sin(zenith*kDegrad)*TMath::Sin(azimuth*kDegrad)*pmom;
337 p[1] = TMath::Cos(zenith*kDegrad)*pmom;
338 p[2] = TMath::Sin(zenith*kDegrad)*TMath::Cos(azimuth*kDegrad)*pmom;
340 PushTrack(fTrackIt, -1, fIpart, p, origin, polar, 0, kPPrimary, nt);
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 this->InitApWeightFactors();
488 // Define the standard function.
489 const 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) const
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);
522 Float_t tmpzenith = TMath::Cos(zenithAngle->GetRandom()*kDegrad);
524 zenith = kRaddeg*TMath::ACos(1 - (tmpzenith - 1)/fAp->At(pIndex));
528 if ( fCRMode != kMuonFlux ) {
529 // If you aren't generating muons obeying any ditribution
530 // only generate a flat zenith angle, acording the input settings
533 zenith = fZenithMin + (fZenithMax - fZenithMin)*random[0];
536 // Even if you are generating muons acording some distribution,
537 // but you don't want to ...
544 zenith = fZenithDist->GetRandom();
550 //_____________________________________________________________________________
551 const Float_t AliGenCRT::GetMomentum() const
556 return fMomentumDist->GetRandom();