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>
51 //_____________________________________________________________________________
52 AliGenCRT::AliGenCRT()
55 fCRMode(kSingleMuons),
70 fUnfoldedMomentumDist(0),
79 //_____________________________________________________________________________
80 AliGenCRT::AliGenCRT(Int_t npart)
81 : AliGenerator(npart),
83 fCRMode(kSingleMuons),
98 fUnfoldedMomentumDist(0),
106 fTitle = "Cosmic Muons generator";
108 // Set the origin above the vertex, on the surface.
110 fOrigin[1] = AliCRTConstants::Instance()->Depth(); // At the surface by default.
114 //_____________________________________________________________________________
115 AliGenCRT::AliGenCRT(const AliGenCRT& gen)
124 //_____________________________________________________________________________
125 AliGenCRT& AliGenCRT::operator=(const AliGenCRT& gen)
128 // Asingment operator
134 //_____________________________________________________________________________
135 AliGenCRT::~AliGenCRT()
140 if ( fPDist ) {fPDist->Delete(); delete fPDist; fPDist = 0;}
141 if ( fUnfoldedMomentumDist ) delete fUnfoldedMomentumDist;
142 if ( fMomentumDist ) delete fMomentumDist;
143 if ( fAp ) delete fAp;
144 if ( fCRModeName ) delete fCRModeName;
147 //_____________________________________________________________________________
148 void AliGenCRT::Generate()
151 // Generate on one trigger
152 // Call the respective method inside the loop for the number
153 // of tracks per trigger.
155 for (Int_t i = 0; i < fNpart; i++ ) {
157 if ( fCRMode == kMuonBundle ) {
158 this->GenerateOneMuonBundle();
160 } else if ( fCRMode == kSingleMuons ) {
161 this->GenerateOneSingleMuon(kTRUE);
164 // Generate only single muons following the parametrizations
165 // for atmospheric muons.
166 this->GenerateOneSingleMuon();
173 //_____________________________________________________________________________
174 void AliGenCRT::Init()
177 // Initialize some internal methods.
180 // Determine some specific data members.
181 fPRange = TMath::Abs(fPMax-fPMin);
183 if ( fCRMode == kSingleMuons ) {
184 fCRModeName = new TString("Single Muons");
185 // Initialisation, check consistency of selected ranges
186 if(TestBit(kPtRange)&&TestBit(kMomentumRange))
187 Fatal("Init","You should not set the momentum range and the pt range!");
189 if((!TestBit(kPtRange))&&(!TestBit(kMomentumRange)))
190 Fatal("Init","You should set either the momentum or the pt range!");
192 } else if ( fCRMode == kMuonBundle ) {
193 fCRModeName = new TString("Muon Bundles");
195 } else if ( fCRMode == kMuonFlux ) {
196 fCRModeName = new TString("Muon Fluxes");
197 // Initialize the ditribution functions.
198 this->InitMomentumGeneration();
199 this->InitZenithalAngleGeneration();
202 Fatal("Generate", "Generation Mode unknown!\n");
208 //____________________________________________________________________________
209 void AliGenCRT::GenerateOneSingleMuon(Bool_t withFlatMomentum)
212 // Generate One Single Muon
213 // This method will generate only one muon.
214 // The momentum will be randomly flat distributed if
215 // the paremeter "withFlatMomentum" is set to kTRUE,
216 // otherwise the momentum will generate acordingly the parametrization
218 // and adpted from Bruno Alessandro's implementation with the
219 // CERNLIB to AliRoot.
220 // The "withFlatMomentum" parameter also will be used to generate
221 // the muons with a flat Zenithal angle distribution.
222 // Do the smearing here, so that means per track.
224 Float_t polar[3]= {0,0,0}; // Polarization parameters
231 // Take the azimuth random.
233 Float_t azimuth = fAzimuthMin + (fAzimuthMax-fAzimuthMin)*random[0];
234 Float_t zenith = fZenithMin + (fZenithMax - fZenithMin)*random[1];
236 if ( withFlatMomentum ) {
238 if(TestBit(kMomentumRange)) {
239 pmom = -( fPMin + random[0]*(fPMax - fPMin) ); // always downwards.
240 pt = pmom*TMath::Sin(zenith*kDegrad);
242 pt = -( fPtMin + random[1]*(fPtMax - fPtMin)); // always downwards.
243 pmom = pt/TMath::Sin(zenith*kDegrad);
247 if ( fMomentumDist ) {
248 pmom = -this->GetMomentum(); // Always downwards.
252 zenith = this->GetZenithAngle(pmom); // In degrees
253 pt = pmom*TMath::Sin(zenith*kDegrad);
256 p[0] = pt*TMath::Sin(azimuth*kDegrad);
257 p[1] = pmom*TMath::Cos(zenith*kDegrad);
258 p[2] = pt*TMath::Cos(azimuth*kDegrad);
260 // Finaly the origin, with the smearing
262 origin[0] = AliCRTConstants::Instance()->Depth()*TMath::Tan(zenith*kDegrad)*
263 TMath::Sin(azimuth*kDegrad);
264 + fOsigma[0]* TMath::Cos(2*random[0]*TMath::Pi())*TMath::Sqrt(-2*TMath::Log(random[1]));
266 origin[1] = AliCRTConstants::Instance()->Depth();
268 origin[2] = AliCRTConstants::Instance()->Depth()*TMath::Tan(zenith*kDegrad)*
269 TMath::Cos(azimuth*kDegrad);
270 + fOsigma[2]* TMath::Cos(2*random[2]*TMath::Pi())*TMath::Sqrt(-2*TMath::Log(random[3]));;
272 // Put the track on the stack.
273 PushTrack(fTrackIt,-1,fIpart,p,origin,polar,0,kPPrimary,nt);
277 //____________________________________________________________________________
278 void AliGenCRT::GenerateOneMuonBundle()
281 // Generate One Muon Bundle method
282 // This method will generate a bunch of muons following the
283 // procedure of the AliGenScan class.
284 // These muons will be generated with flat momentum.
286 Float_t polar[3]= {0,0,0}; // Polarization parameters
294 Float_t zenith = fZenithMin + (fZenithMax - fZenithMin)*random[1];
295 Float_t azimuth = fAzimuthMin + (fAzimuthMax-fAzimuthMin)*random[2];
296 //Float_t zenith = 10;
297 //Float_t azimuth = 30;
299 // Generate the kinematics a la AliGenScan (Andreas Morchs)
315 origin[0] = AliCRTConstants::Instance()->Depth()*TMath::Tan(zenith*kDegrad)*
316 TMath::Sin(azimuth*kDegrad);
318 origin[1] = AliCRTConstants::Instance()->Depth();
320 origin[2] = AliCRTConstants::Instance()->Depth()*TMath::Tan(zenith*kDegrad)*
321 TMath::Cos(azimuth*kDegrad);
324 for (Int_t ix = 0; ix < fNx; ix++ ) {
325 for (Int_t iz = 0; iz < fNz; iz++ ) {
327 origin[0]+=ix*dx+2*(random[1]-0.5)*fOsigma[0];
328 origin[2]+=iz*dz+2*(random[2]-0.5)*fOsigma[2];
329 if ( random[4] < 0.5 ) {
330 origin[0] = -1*origin[0];
332 if ( random[5] < 0.5 ) {
333 origin[2] = -1*origin[2];
336 pmom = -(fPMin + random[3] *(fPMax - fPMax) ); // Always downwards
337 p[0] = TMath::Sin(zenith*kDegrad)*TMath::Sin(azimuth*kDegrad)*pmom;
338 p[1] = TMath::Cos(zenith*kDegrad)*pmom;
339 p[2] = TMath::Sin(zenith*kDegrad)*TMath::Cos(azimuth*kDegrad)*pmom;
341 PushTrack(fTrackIt, -1, fIpart, p, origin, polar, 0, kPPrimary, nt);
348 //____________________________________________________________________________
349 void AliGenCRT::SetGridRange(Int_t nx,Float_t xwidth, Int_t nz, Float_t zwidth)
353 // This data shuold be used for Muon bundles generation.
360 // Print a message about the use, if the Mode has not been set, or
361 // it has to a different Mode.
362 if ( fCRMode != kMuonBundle ) {
363 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");
368 //____________________________________________________________________________
369 void AliGenCRT::InitApWeightFactors()
372 // This factors will be to correct the zenithal angle distribution
373 // acording the momentum
376 // Fill the array for the flux zenith angle dependence.
377 // at the index 0 of fAp[] will be the "factor" if we have a muon
379 Float_t a[6] = {-1.61, -1.50, -1.28, -0.94, -0.61, -0.22};
380 Float_t p[6] = { 0., 10., 30., 100., 300., 1000.};
382 // Get the information from the momentum
383 Int_t pEnd = TMath::Abs(TMath::Nint(fPMax/fPResolution)) + 1;
384 // Initialize the Array of floats to hold the a(p) factors.
385 fAp = new TArrayF(pEnd);
389 for (Int_t i = 0; i < pEnd; i++ ) {
390 Float_t currentP = ((Float_t)i)*fPResolution;
391 if ( currentP < p[1] ) index = 0;
392 else if ( currentP >= p[1] && currentP < p[2] ) index = 1;
393 else if ( currentP >= p[2] && currentP < p[3] ) index = 2;
394 else if ( currentP >= p[3] && currentP < p[4] ) index = 3;
395 else if ( currentP >= p[4] ) index = 4;
397 Float_t ap = (currentP -p[index])*(a[index+1] - a[index])/
398 (p[index+1] - p[index]) + a[index];
404 //___________________________________________________________________________
405 void AliGenCRT::InitMomentumGeneration()
408 // Initialize a funtion to generate the momentum randomly
409 // acording this function.
412 // Check if we nned to initialize the function
413 if ( fPMin != fPMax ) {
415 // Check also if the function have been defined yet.
416 if ( !fMomentumDist ) {
418 // If not, use this function
419 const char* y = "log10(x)";
421 const char* h1Coef = "[0]*( %s*%s*%s/2 - (5*%s*%s/2) + 3*%s )";
422 const char* h2Coef = "[1]*( (-2*%s*%s*%s/3) + (3*%s*%s) - 10*%s/3 + 1 )";
423 const char* h3Coef = "[2]*( %s*%s*%s/6 - %s*%s/2 + %s/3 )";
424 const char* s2Coef = "[3]*( %s*%s*%s/3 - 2*%s*%s + 11*%s/3 - 2 )";
426 const char* h = "%s + %s + %s + %s";
427 const char* flux = "pow(10., %s)";
428 const char* normalizedFlux = "0.86*x*x*x*pow(10., %s)";
429 const char* paramNames[4] = {"H1", "H2", "H3", "S1"};
439 sprintf(buffer1, h1Coef, y, y, y, y, y, y);
440 sprintf(buffer2, h2Coef, y, y, y, y, y, y);
441 sprintf(buffer3, h3Coef, y, y, y, y, y, y);
442 sprintf(buffer4, s2Coef, y, y, y, y, y, y);
444 sprintf(buffer5, h, buffer1, buffer2, buffer3, buffer4);
446 sprintf(buffer6, flux, buffer5);
448 fMomentumDist = new TF1("fMomentumDist", buffer6, fPMin, fPMax);
449 sprintf(buffer7, normalizedFlux, buffer5);
450 fUnfoldedMomentumDist = new TF1("fUnfoldedMomentumDist", buffer7, fPMin, fPMax);
451 for (Int_t i = 0; i < 4; i++ ) {
452 fMomentumDist->SetParName(i, paramNames[i]);
453 fUnfoldedMomentumDist->SetParName(i, paramNames[i]);
456 fMomentumDist->SetParameter(0, 0.133);
457 fMomentumDist->SetParameter(1, -2.521);
458 fMomentumDist->SetParameter(2, -5.78);
459 fMomentumDist->SetParameter(3, -2.11);
461 fUnfoldedMomentumDist->SetParameter(0, 0.133);
462 fUnfoldedMomentumDist->SetParameter(1, -2.521);
463 fUnfoldedMomentumDist->SetParameter(2, -5.78);
464 fUnfoldedMomentumDist->SetParameter(3, -2.11);
472 //____________________________________________________________________________
473 void AliGenCRT::InitZenithalAngleGeneration()
476 // Initalize a distribution function for the zenith angle.
477 // This angle will be obtained randomly acording this function.
478 // The generated angles will been in degrees.
480 // Check if we need to create the function.
481 if ( fZenithMin != fZenithMax ) {
483 // Check also if another function have been defined.
484 if ( !fZenithDist ) {
486 // initialize the momentum dependent coefficients, a(p)
487 this->InitApWeightFactors();
489 Int_t pEnd = TMath::Abs(TMath::Nint(fPMax/fPResolution)) + 1;
492 fPDist = new TClonesArray("TH1F", pEnd);
493 TClonesArray &mom = *fPDist;
496 for ( Int_t i = 0; i < pEnd; i++ ) {
497 // Fill the distribution
498 sprintf(name, "zenith%d", i+1);
499 sprintf(title, "Zenith distribution, p=%f", fPMin+(Float_t)i);
500 zenith = new(mom[i]) TH1F(name, title, TMath::Abs(TMath::Nint(fZenithMax-fZenithMin)), TMath::Cos(fZenithMax*TMath::Pi()/180), TMath::Cos(fZenithMin*TMath::Pi()/180));
502 // Make a loop for the angle and fill the histogram for the weight
505 for (Int_t j = 0; j < steps; j++ ) {
506 value = TMath::Cos(fZenithMin*TMath::Pi()/180) + (Float_t)j * ( TMath::Cos(fZenithMax*TMath::Pi()/180) - TMath::Cos(fZenithMin*TMath::Pi()/180))/1000;
507 weight = 1 + fAp->At(i)*(1 - value);
508 zenith->Fill(value, weight);
519 //____________________________________________________________________________
520 const Float_t AliGenCRT::GetZenithAngle(Float_t mom) const
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 TH1F* cosZenithAngle = (TH1F*)fPDist->UncheckedAt(pIndex);
530 Float_t tmpzenith = TMath::ACos(cosZenithAngle->GetRandom());
532 zenith = kRaddeg*tmpzenith;
536 if ( fCRMode != kMuonFlux ) {
537 // If you aren't generating muons obeying any ditribution
538 // only generate a flat zenith angle, acording the input settings
541 zenith = fZenithMin + (fZenithMax - fZenithMin)*random[0];
544 // Even if you are generating muons acording some distribution,
545 // but you don't want to ...
552 zenith = fZenithDist->GetRandom();
558 //_____________________________________________________________________________
559 const Float_t AliGenCRT::GetMomentum() const
564 return fMomentumDist->GetRandom();