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 <Riostream.h>
40 #include <TMCProcess.h>
45 #include "AliGenCRT.h"
50 //_____________________________________________________________________________
51 AliGenCRT::AliGenCRT() : AliGenerator(-1)
65 // Set the origin above the vertex, on the surface.
85 fUnfoldedMomentumDist = 0;
90 //_____________________________________________________________________________
91 AliGenCRT::AliGenCRT(Int_t npart)
98 fTitle = "Cosmic Muons generator";
100 // Generate Muon- by default
109 // Set the origin above the vertex, on the surface.
111 fOrigin[1] = AliCRTConstants::fgDepth; // At the surface by default.
114 fZenithMin = 0.; // Generate veritcals by default.
120 fPResolution = 1.; // 1 GeV by default.
121 fPRange = 0.; // 0 GeV by default.
129 fUnfoldedMomentumDist = 0;
134 //_____________________________________________________________________________
135 AliGenCRT::AliGenCRT(const AliGenCRT& gen) : AliGenerator()
143 //_____________________________________________________________________________
144 AliGenCRT& AliGenCRT::operator= (const AliGenCRT& gen)
153 //_____________________________________________________________________________
154 AliGenCRT::~AliGenCRT()
159 if ( fAp ) delete fAp;
160 if ( fMomentumDist ) delete fMomentumDist;
161 if ( fUnfoldedMomentumDist ) delete fUnfoldedMomentumDist;
162 if ( fZenithDist ) delete fZenithDist;
163 if ( fPDist ) delete fPDist;
166 //_____________________________________________________________________________
167 void AliGenCRT::Generate()
170 // Generate on one trigger
173 Float_t polar[3]= {0,0,0}; // Polarization parameters
179 Float_t zenith, azimuth;
184 // Check if you need to use a distribution function for the momentum
185 if ( fMomentumDist ) {
186 pmom = - this->GetMomentum(); // Always downwards.
193 zenith = this->GetZenithAngle(pmom); // In degrees
195 // Take the azimuth random.
197 azimuth = (fAzimuthMin + (fAzimuthMax-fAzimuthMin)*random[0]); // In degrees
199 origin[0] = AliCRTConstants::fgDepth*TMath::Tan(zenith*kDegrad)*
200 TMath::Sin(azimuth*kDegrad);
201 origin[1] = AliCRTConstants::fgDepth;
202 origin[2] = AliCRTConstants::fgDepth*TMath::Tan(zenith*kDegrad)*
203 TMath::Cos(azimuth*kDegrad);
205 if ( fVertexSmear == kPerEvent ) {
209 // Don't smear the vertical position.
210 origin[j] = AliCRTConstants::fgDepth;
212 origin[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
213 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
219 if ( fCRMode == kSingleMuons ) {
222 // Generate kinematics a la AliGenBox
225 for(i=0;i<fNpart;i++) {
228 if(TestBit(kMomentumRange)) {
229 pmom = -( fPMin + random[1]*(fPMax - fPMin) ); // always downwards.
230 pt=pmom*TMath::Sin(zenith*kDegrad);
233 pt= -(fPtMin+random[1]*(fPtMax-fPtMin)); // always downwards.
234 pmom=pt/TMath::Sin(zenith*kDegrad);
237 p[0] = pt*TMath::Sin(azimuth*kDegrad);
238 p[1] = pmom*TMath::Cos(zenith*kDegrad);
239 p[2] = pt*TMath::Cos(azimuth*kDegrad);
241 if(fVertexSmear==kPerTrack) {
245 origin[j] = AliCRTConstants::fgDepth;
247 origin[j]=fOrigin[j]+fOsigma[j]*
248 TMath::Cos(2*random[2*j]*TMath::Pi())*
249 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
256 // End of generation a la AliGenBox
258 } else if ( fCRMode == kMuonBundle ) {
261 // Generate kinematics a la AliGenScan
277 for (Int_t ix=0; ix<fNx; ix++) {
278 for (Int_t iz=0; iz<fNz; iz++){
280 origin[0]+=ix*dx+2*(random[0]-0.5)*fOsigma[0];
281 origin[2]+=iz*dz+2*(random[1]-0.5)*fOsigma[2];
283 pmom = -(fPMin + random[3] *(fPMax - fPMax) ); // Always downward.
284 p[0] = TMath::Sin(zenith*kDegrad)*TMath::Sin(azimuth*kDegrad)*pmom;
285 p[1] = TMath::Cos(zenith*kDegrad)*pmom;
286 p[2] = TMath::Sin(zenith*kDegrad)*TMath::Cos(azimuth*kDegrad)*pmom;
291 // End of generation a la AliGenScan
293 } else if ( fCRMode == kMuonFlux ) {
295 // Always generate the things downwards.
296 p[0] = TMath::Sin(zenith*kDegrad)*TMath::Sin(azimuth*kDegrad)*pmom;
297 p[1] = TMath::Cos(zenith*kDegrad)*pmom;
298 p[2] = TMath::Sin(zenith*kDegrad)*TMath::Cos(azimuth*kDegrad)*pmom;
301 Error("Generate", "Generation Mode unknown!\n");
304 // Put the track on the stack.
305 PushTrack(fTrackIt,-1,fIpart,p,origin,polar,0,kPPrimary,nt);
310 //_____________________________________________________________________________
311 void AliGenCRT::Init()
314 // Initialize some internal methods.
317 // Determine some specific data members.
318 fPRange = TMath::Abs(fPMax-fPMin);
320 if ( fCRMode == kSingleMuons ) {
321 fCRModeName = new TString("Single Muons");
322 // Initialisation, check consistency of selected ranges
323 if(TestBit(kPtRange)&&TestBit(kMomentumRange))
324 Fatal("Init","You should not set the momentum range and the pt range!");
326 if((!TestBit(kPtRange))&&(!TestBit(kMomentumRange)))
327 Fatal("Init","You should set either the momentum or the pt range!");
329 } else if ( fCRMode == kMuonBundle ) {
330 fCRModeName = new TString("Muon Bundles");
332 } else if ( fCRMode == kMuonFlux ) {
333 fCRModeName = new TString("Muon Fluxes");
334 // Initialize the ditribution functions.
335 this->InitMomentumGeneration();
336 this->InitZenithalAngleGeneration();
339 Fatal("Generate", "Generation Mode unknown!\n");
345 //____________________________________________________________________________
346 void AliGenCRT::SetGridRange(Int_t nx,Float_t xwidth, Int_t nz, Float_t zwidth)
350 // This data shuold be used for Muon bundles generation.
357 // Print a message about the use, if the Mode has not been set, or
358 // it has to a different Mode.
359 if ( fCRMode != kMuonBundle ) {
360 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");
365 //____________________________________________________________________________
366 void AliGenCRT::InitApWeightFactors()
369 // This factors will be to correct the zenithal angle distribution
370 // acording the momentum
373 // Fill the array for the flux zenith angle dependence.
374 // at the index 0 of fAp[] will be the "factor" if we have a muon
376 Float_t a[6] = {-1.61, -1.50, -1.28, -0.94, -0.61, -0.22};
377 Float_t p[6] = { 0., 10., 30., 100., 300., 1000.};
379 // Get the information from the momentum
380 Int_t pEnd = TMath::Abs(TMath::Nint(fPMax/fPResolution)) + 1;
381 // Initialize the Array of floats to hold the a(p) factors.
382 fAp = new TArrayF(pEnd);
386 for (Int_t i = 0; i < pEnd; i++ ) {
387 Float_t currentP = ((Float_t)i)*fPResolution;
388 if ( currentP < p[1] ) index = 0;
389 else if ( currentP >= p[1] && currentP < p[2] ) index = 1;
390 else if ( currentP >= p[2] && currentP < p[3] ) index = 2;
391 else if ( currentP >= p[3] && currentP < p[4] ) index = 3;
392 else if ( currentP >= p[4] ) index = 4;
394 Float_t ap = (currentP -p[index])*(a[index+1] - a[index])/
395 (p[index+1] - p[index]) + a[index];
401 //___________________________________________________________________________
402 void AliGenCRT::InitMomentumGeneration()
405 // Initialize a funtion to generate the momentum randomly
406 // acording this function.
409 // Check if we nned to initialize the function
410 if ( fPMin != fPMax ) {
412 // Check also if the function have been defined yet.
413 if ( !fMomentumDist ) {
415 // If not, use this function
416 const char* y = "log10(x)";
418 const char* h1Coef = "[0]*( %s*%s*%s/2 - (5*%s*%s/2) + 3*%s )";
419 const char* h2Coef = "[1]*( (-2*%s*%s*%s/3) + (3*%s*%s) - 10*%s/3 + 1 )";
420 const char* h3Coef = "[2]*( %s*%s*%s/6 - %s*%s/2 + %s/3 )";
421 const char* s2Coef = "[3]*( %s*%s*%s/3 - 2*%s*%s + 11*%s/3 - 2 )";
423 const char* h = "%s + %s + %s + %s";
424 const char* flux = "pow(10., %s)";
425 const char* normalizedFlux = "0.86*x*x*x*pow(10., %s)";
426 const char* paramNames[4] = {"H1", "H2", "H3", "S1"};
436 sprintf(buffer1, h1Coef, y, y, y, y, y, y);
437 sprintf(buffer2, h2Coef, y, y, y, y, y, y);
438 sprintf(buffer3, h3Coef, y, y, y, y, y, y);
439 sprintf(buffer4, s2Coef, y, y, y, y, y, y);
441 sprintf(buffer5, h, buffer1, buffer2, buffer3, buffer4);
443 sprintf(buffer6, flux, buffer5);
445 fMomentumDist = new TF1("fMomentumDist", buffer6, fPMin, fPMax);
446 sprintf(buffer7, normalizedFlux, buffer5);
447 fUnfoldedMomentumDist = new TF1("fUnfoldedMomentumDist", buffer7, fPMin, fPMax);
448 for (Int_t i = 0; i < 4; i++ ) {
449 fMomentumDist->SetParName(i, paramNames[i]);
450 fUnfoldedMomentumDist->SetParName(i, paramNames[i]);
453 fMomentumDist->SetParameter(0, 0.133);
454 fMomentumDist->SetParameter(1, -2.521);
455 fMomentumDist->SetParameter(2, -5.78);
456 fMomentumDist->SetParameter(3, -2.11);
458 fUnfoldedMomentumDist->SetParameter(0, 0.133);
459 fUnfoldedMomentumDist->SetParameter(1, -2.521);
460 fUnfoldedMomentumDist->SetParameter(2, -5.78);
461 fUnfoldedMomentumDist->SetParameter(3, -2.11);
469 //____________________________________________________________________________
470 void AliGenCRT::InitZenithalAngleGeneration()
473 // Initalize a distribution function for the zenith angle.
474 // This angle will be obtained randomly acording this function.
475 // The generated angles will been in degrees.
477 // Check if we need to create the function.
478 if ( fZenithMin != fZenithMax ) {
480 // Check also if another function have been defined.
481 if ( !fZenithDist ) {
483 // initialize the momentum dependent coefficients, a(p)
484 InitApWeightFactors();
486 // Define the standard function.
487 char* zenithalDisributionFunction = "1 + [0]*(1 - cos(x*3.14159265358979312/180))";
489 Int_t pEnd = TMath::Abs(TMath::Nint(fPMax/fPResolution)) + 1;
490 fPDist = new TClonesArray("TF1", pEnd);
491 TClonesArray &angle = *fPDist;
492 for ( Int_t i = 0; i < pEnd; i++ ) {
493 // Fill the distribution
494 TF1* zenith = new(angle[i]) TF1("zenith",zenithalDisributionFunction, fZenithMin, fZenithMax);
496 // Fix the momentum dependent coefficients
497 zenith->SetParName(0, "a(p)");
498 zenith->SetParameter(0, fAp->At(i));
508 //____________________________________________________________________________
509 const Float_t AliGenCRT::GetZenithAngle(Float_t mom)
513 // Check if you need to generate a constant zenith angle.
514 if ( !fZenithDist ) {
515 // Check if you have defined an array of momentum functions
517 Int_t pIndex = TMath::Abs(TMath::Nint(mom));
518 TF1* zenithAngle = (TF1*)fPDist->UncheckedAt(pIndex);
519 zenith = zenithAngle->GetRandom();
523 if ( fCRMode != kMuonFlux ) {
524 // If you aren't generating muons obeying any ditribution
525 // only generate a flat zenith angle, acording the input settings
528 zenith = fZenithMin + (fZenithMax - fZenithMin)*random[0];
531 // Even if you are generating muons acording some distribution,
532 // but you don't want to ...
539 zenith = fZenithDist->GetRandom();
546 //____________________________________________________________________________