BLCMDcosmicraybeam Class Reference

Inheritance diagram for BLCMDcosmicraybeam:

BLBeam BLCommand

List of all members.


Detailed Description

class BLCMDcosmicraybeam -- implement a cosmic-ray muon "beam"

Generates a muon beam that fills the beam box with muons distributed like cosmic rays. After the simulation is complete, an estimate of the exposure time is printed (for apparatus at sea level). The primary vertices are on the "celestial sphere", which should be outside the apparatus; all muons generated will intersect the beam box (unless scattered or absorbed or decayed beforehand), so CPU time is not wasted on tracks missing the apparatus. Define the beam box appropriately.

Note that the z axis is vertical, increasing DOWNWARD. The "nominal" beam muons propagate in the +z direction. All primary vertices will be in the z<0 half of the celestial sphere, and all muons will have a direction with positive z component; no beam muon is more than 70 degrees from heading vertically downward.

For now, this is just mu+.

Method: First, an initial vertex is selected uniformly in the beam box (beamWidth,beamHeight,beamLength), and a muon is generated with appropriate momentum and angular distribution. This track is extended to the center of the beam box, and hits counts the number of hits inside the beam box at its midplane. Then if radius>0 the track is extended backwards to where it intersects the "celestial sphere" -- the sphere with R=radius centered at the center of the beam box. If radius<=0 then the primary vertices will be on the midplane of the beam box.

Public Member Functions

 BLCMDcosmicraybeam ()
 Constructor.
G4String commandName ()
 commandName() returns "cosmicraybeam".
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
 command() implements the cosmicraybeam command.
void printBeam ()
 printBeam() will print a description.
void defineNamedArgs ()
 defineNamedArgs() defines the named arguments for this command.
int getNEvents () const
 getNEvents() returns the # events to process.
void init ()
 init() will initialize internal variables.
bool generateReferenceParticle (G4Event *event)
 generateReferenceParticle() generates the reference particle.
bool nextBeamEvent (G4Event *event)
 nextBeamEvent() generates the next beam event.
void summary ()
 summary() will print a summary.
double cosmicRayMuonMomentum ()
 cosmicRayMuonMomentum() returns a random momentum value distributed like the muons from cosmic rays. Average momentum is 3.0*GeV/c, cutoff is 120*GeV/c. Return value is in geant4 units (MeV). Data from Kremer et al, Phys. Rev. Lett., Vol 83 no 21, p4241 (1999)
double cosmicRayMuonAngle ()
 cosmicRayMuonAngle() returns a random angle distributed like the polar angle of cosmic ray muons. The return value is the polar angle from vertical (radians). It is cut off at 70 degrees. Note this is the distribution for muons of ~3 GeV/c, which is the average momentum. In fact, lower energy muons have a steeper distribution and higher ones have a flatter distribution. But this is a reasonable approximation. Particle Data Group, Review of Particle Properties, 2002. Section 23.3.1.

Private Attributes

G4double meanMomentum
G4double beamZ
G4double beamWidth
G4double beamHeight
G4double beamLength
G4ParticleGun * muonGun
G4ParticleDefinition * muon
G4double radius
G4long hits
G4double sterradians
G4double hitsPerM2PerSecPerSterrad
G4String particle
G4int evNumber


Constructor & Destructor Documentation

BLCMDcosmicraybeam::BLCMDcosmicraybeam (  ) 

Constructor.

References beamHeight, beamLength, beamWidth, beamZ, BLCMDTYPE_BEAM, evNumber, hits, hitsPerM2PerSecPerSterrad, meanMomentum, muon, muonGun, particle, radius, BLCommand::registerCommand(), BLCommand::setDescription(), BLCommand::setSynopsis(), and sterradians.

00124                                        : BLBeam()
00125 {
00126         registerCommand(BLCMDTYPE_BEAM);
00127         setSynopsis("Define a Cosmic-Ray muon 'beam'.");
00128         setDescription("The muon beam is nominally headed in the +Z direction,\n"
00129                 "implying that +Z is physically DOWN.\n"
00130                 "The beam intersects a box defined by beamWidth, beamHeight,\n"
00131                 "and beamLength, centered at X=Y=0 and beamZ. For each\n"
00132                 "event a point is selected randomly within this box, angles\n"
00133                 "theta and phi and the muon momentum are generated according\n"
00134                 "to a fit to their sea-level distributions, the track is\n"
00135                 "extended backwards to the 'celestial sphere', and that is\n"
00136                 "the initial beam position for the event. The muon flux\n"
00137                 "through the rectangle at Z=beamZ is used to display an\n"
00138                 "estimate of the sea-level exposure time for the run.");
00139 
00140         meanMomentum = 3.0*GeV;
00141         beamZ = 0.0;
00142         beamWidth = 0.0;
00143         beamHeight = 0.0;
00144         beamLength = 0.0;
00145         muonGun = 0;
00146         muon = 0;
00147         radius = 0.0;
00148         hits = 0;
00149         sterradians = 0.0;
00150         hitsPerM2PerSecPerSterrad = 0.0;
00151         particle = "mu+";
00152         evNumber = 0;
00153 }


Member Function Documentation

G4String BLCMDcosmicraybeam::commandName (  )  [inline, virtual]

commandName() returns "cosmicraybeam".

Implements BLCommand.

00077 { return "cosmicraybeam"; }

int BLCMDcosmicraybeam::command ( BLArgumentVector argv,
BLArgumentMap namedArgs 
) [virtual]

command() implements the cosmicraybeam command.

Implements BLCommand.

References BLManager::getObject(), BLGroup::getWorld(), BLCommand::handleNamedArgs(), printBeam(), BLCommand::printError(), radius, BLManager::registerBeam(), BLGroup::setMinHeight(), BLGroup::setMinLength(), and BLGroup::setMinWidth().

00156 {
00157         if(argv.size() != 0) {
00158                 printError("Invalid cosmicraybeam command");
00159                 return -1;
00160         }
00161 
00162         handleNamedArgs(namedArgs);
00163 
00164         // ensure our muons are within the world.
00165         BLGroup::getWorld()->setMinWidth(radius*2.0);
00166         BLGroup::getWorld()->setMinHeight(radius*2.0);
00167         BLGroup::getWorld()->setMinLength(radius*2.0);
00168 
00169         BLManager::getObject()->registerBeam(this);
00170 
00171         printBeam();
00172 
00173         printf("********************************************************\n"
00174                "*                                                      *\n"
00175                "*  NOTE: This command needs to be completely re-done.  *\n"
00176                "*                                                      *\n"
00177                "********************************************************\n");
00178 
00179         return 0;
00180 }

void BLCMDcosmicraybeam::printBeam (  ) 

printBeam() will print a description.

References beamHeight, beamLength, beamWidth, beamZ, BLBeam::nEvents, particle, and radius.

Referenced by command().

00193 {
00194         printf("cosmicraybeam mu+ particle=%s ",particle.c_str());
00195         printf("nEvents=%d ",nEvents);
00196         printf("beamZ=%.1f ",beamZ);
00197         printf("radius=%.3f ",radius);
00198         printf("\n\t\t");
00199         printf("beamHeight=%.1f ",beamHeight);
00200         printf("beamWidth=%.1f ",beamWidth);
00201         printf("beamLength=%.3f ",beamLength);
00202         printf("\n");
00203 }

void BLCMDcosmicraybeam::defineNamedArgs (  )  [virtual]

defineNamedArgs() defines the named arguments for this command.

Reimplemented from BLCommand.

References BLCommand::argDouble(), BLCommand::argInt(), beamHeight, beamLength, beamWidth, beamZ, BLBeam::nEvents, and radius.

00183 {
00184         argInt(nEvents,"nEvents","Number of events to process");
00185         argDouble(beamZ,"beamZ","Beam location in Z (mm)",mm);
00186         argDouble(radius,"radius","Radius of celestial sphere (mm)",mm);
00187         argDouble(beamHeight,"beamHeight","Rectangular Beam height (mm)",mm);
00188         argDouble(beamWidth,"beamWidth","Rectangular Beam width (mm)",mm);
00189         argDouble(beamLength,"beamLength","Rectangular Beam length (mm)",mm);
00190 }

int BLCMDcosmicraybeam::getNEvents (  )  const [inline, virtual]

getNEvents() returns the # events to process.

Reimplemented from BLBeam.

References BLBeam::nEvents.

00089 { return nEvents; }

void BLCMDcosmicraybeam::init (  )  [virtual]

init() will initialize internal variables.

Implements BLBeam.

References evNumber, muon, muonGun, and particle.

Referenced by cosmicRayMuonAngle(), and cosmicRayMuonMomentum().

00206 {
00207         if(muon != 0) return;
00208 
00209         muon = G4ParticleTable::GetParticleTable()->FindParticle(particle);
00210         muonGun = new G4ParticleGun(1);
00211         muonGun->SetParticleDefinition(muon);
00212         evNumber = 0;
00213 }

bool BLCMDcosmicraybeam::generateReferenceParticle ( G4Event *  event  )  [virtual]

generateReferenceParticle() generates the reference particle.

Implements BLBeam.

00216 {
00217         return false;
00218 }

bool BLCMDcosmicraybeam::nextBeamEvent ( G4Event *  event  )  [virtual]

nextBeamEvent() generates the next beam event.

Implements BLBeam.

References beamHeight, beamLength, beamWidth, beamZ, cosmicRayMuonAngle(), cosmicRayMuonMomentum(), evNumber, hits, muon, muonGun, BLBeam::nEvents, radius, BLBeam::setRandomSeedToGenerate(), and BLBeam::setRandomSeedToTrack().

00221 {
00222         if(++evNumber > nEvents) return false;
00223 
00224         setRandomSeedToGenerate(evNumber);
00225 
00226         G4double mass = muon->GetPDGMass();
00227         G4ThreeVector position;
00228         G4ThreeVector direction;
00229         G4double time = 0.0;
00230         G4double momentum = 0.0;
00231 
00232         // work in local coordinates (relative to the beam box)
00233         G4double x = beamWidth*G4UniformRand() - beamWidth/2.0;
00234         G4double y = beamHeight*G4UniformRand() - beamHeight/2.0;
00235         G4double z = beamLength*G4UniformRand() - beamLength/2.0;
00236         momentum = cosmicRayMuonMomentum();
00237         double theta = cosmicRayMuonAngle();
00238         double phi = 2.0*pi*G4UniformRand();
00239         direction[0] = momentum*sin(theta)*cos(phi);
00240         direction[1] = momentum*sin(theta)*sin(phi);
00241         direction[2] = momentum*cos(theta);
00242 
00243         // propagate to z=0 (center of the beam box)
00244         x -= direction[0]/direction[2]*z;
00245         y -= direction[1]/direction[2]*z;
00246         z = 0.0;
00247 
00248         // count midplane hits in the beam box (for normalization in summary())
00249         if(fabs(x) < beamWidth/2.0 && fabs(y) < beamHeight/2.0)
00250                 ++hits;
00251 
00252         // project backwards (negative z) onto the celestial sphere
00253         if(radius > 0.0) {
00254                 G4double xp = direction[0]/direction[2];
00255                 G4double yp = direction[1]/direction[2];
00256                 G4double a = 1.0 + xp*xp + yp*yp;
00257                 G4double b = 2.0 * (x*xp + y*yp);
00258                 G4double c = x*x + y*y - radius*radius;
00259                 z = (-b - sqrt(b*b-4.0*a*c)) / (2.0 * a);
00260                 position[0] = x + xp*z;
00261                 position[1] = y + yp*z;
00262                 position[2] = z + beamZ;
00263         } else {
00264                 position[0] = x;
00265                 position[1] = y;
00266                 position[2] = beamZ;
00267         }
00268 
00269         G4double ke = sqrt(momentum*momentum + mass*mass) - mass;
00270         muonGun->SetParticleTime(time);
00271         muonGun->SetParticlePosition(position);
00272         muonGun->SetParticleEnergy(ke);
00273         muonGun->SetParticleMomentumDirection(direction);
00274         muonGun->GeneratePrimaryVertex(event);
00275 
00276         setRandomSeedToTrack(evNumber);
00277         return true;
00278 }

void BLCMDcosmicraybeam::summary (  )  [virtual]

summary() will print a summary.

Reimplemented from BLBeam.

References beamHeight, beamWidth, hits, hitsPerM2PerSecPerSterrad, and sterradians.

00281 {
00282         G4double area = beamWidth*beamHeight/meter2;
00283         G4double hitsPerSec = hitsPerM2PerSecPerSterrad * area * sterradians;
00284         printf("CosmicRayBeam: %ld hits in midplane, area %.3f meter^2  "
00285                 " %.3f sterradians\n",
00286                 hits,area,sterradians);
00287         if(hitsPerSec > 0.0)
00288                 printf("               %.1f hits/sec, estimated exposure"
00289                         " %.1f sec\n",hitsPerSec,hits/hitsPerSec);
00290 }

double BLCMDcosmicraybeam::cosmicRayMuonMomentum (  ) 

cosmicRayMuonMomentum() returns a random momentum value distributed like the muons from cosmic rays. Average momentum is 3.0*GeV/c, cutoff is 120*GeV/c. Return value is in geant4 units (MeV). Data from Kremer et al, Phys. Rev. Lett., Vol 83 no 21, p4241 (1999)

References BLAssert, hitsPerM2PerSecPerSterrad, and init().

Referenced by nextBeamEvent().

00293 {
00294         // Data from Kremer et al, Phys. Rev. Lett., Vol 83 no 21, p4241 (1999).
00295         // values are lower bin edge, bin average, mu+ rate, mu- rate
00296         // (laid out this silly way so verification with the paper is easy)
00297         // NOTE: units are GeV/c, and counts/(GeV/c m^2 sr s)
00298         static double vals[] = {
00299                 0.0,    0.0,    0.0,    0.0,
00300                 0.2,    0.25,   14.0,   11.0,
00301                 0.3,    0.35,   16.8,   13.6,
00302                 0.4,    0.47,   17.2,   14.4,
00303                 0.55,   0.62,   16.6,   13.5,
00304                 0.70,   0.78,   15.6,   13.3,
00305                 0.85,   0.92,   14.8,   12.1,
00306                 1.0,    1.1,    13.0,   11.0,
00307                 1.2,    1.3,    12.0,   10.1,
00308                 1.4,    1.5,    10.2,   8.7,
00309                 1.6,    1.84,   9.1,    7.3,
00310                 2.1,    2.49,   6.6,    5.2,
00311                 2.94,   3.49,   4.12,   3.38,
00312                 4.12,   4.78,   2.53,   1.98,
00313                 5.5,    6.21,   1.61,   1.25,
00314                 7.0,    8.37,   0.90,   0.69,
00315                 10.0,   12.42,  0.389,  0.309,
00316                 15.5,   18.85,  0.138,  0.108,
00317                 23.0,   26.68,  0.063,  0.046,
00318                 31.1,   36.69,  0.028,  0.019,
00319                 43.6,   51.47,  0.0099, 0.0071,
00320                 61.1,   72.08,  0.0036, 0.0030,
00321                 85.6,   100.96, 0.0014, 0.0012,
00322                 120.0,  120.0,  0.0,    0.0}; // cutoff at 120 GeV/c
00323         const int nvals = sizeof(vals)/sizeof(vals[0]);
00324         const int nbins = nvals/4 - 1;
00325         const int npdf=256;
00326         static double pdf[npdf];
00327         static double pmax = vals[4*nbins];
00328         static bool init=true;
00329 
00330         if(init) {
00331                 // RandGeneral needs equal-sized bins for pdf[]
00332                 // it returns a value in the range [0,1)
00333                 hitsPerM2PerSecPerSterrad = 0.0;
00334                 for(int i=0,ibin=0; i<npdf; ++i) {
00335                         double p = (i+0.5)*pmax/npdf;
00336                         while(p >= vals[4*ibin+5]) ++ibin;
00337                         BLAssert(ibin <= nbins);
00338                         double f = (p - vals[4*ibin+1]) /
00339                                                 (vals[4*ibin+5]-vals[4*ibin+1]);
00340                         BLAssert(0.0 <= f && f <= 1.0);
00341                         pdf[i] = (1.0-f)*(vals[4*ibin+2]+vals[4*ibin+3]) +
00342                                         f*(vals[4*ibin+6]+vals[4*ibin+7]);
00343                         hitsPerM2PerSecPerSterrad += pdf[i] * pmax/npdf;
00344                 }
00345                 init = false;
00346         }
00347 
00348         CLHEP::RandGeneral generator(pdf,npdf); // BUG in RandGeneral - cannot use new
00349         return generator.shoot() * pmax * GeV;
00350 }

double BLCMDcosmicraybeam::cosmicRayMuonAngle (  ) 

cosmicRayMuonAngle() returns a random angle distributed like the polar angle of cosmic ray muons. The return value is the polar angle from vertical (radians). It is cut off at 70 degrees. Note this is the distribution for muons of ~3 GeV/c, which is the average momentum. In fact, lower energy muons have a steeper distribution and higher ones have a flatter distribution. But this is a reasonable approximation. Particle Data Group, Review of Particle Properties, 2002. Section 23.3.1.

References init(), and sterradians.

Referenced by nextBeamEvent().

00353 {
00354         const int npdf=128;
00355         static double pdf[npdf];
00356         const double thetamax = 70.0*deg;
00357         static bool init = true;
00358 
00359         if(init) {
00360                 // RandGeneral needs equal-sized bins for pdf[]
00361                 // it returns a value in the range [0,1)
00362                 sterradians = 0.0;
00363                 G4double dtheta = thetamax / npdf;
00364                 for(int i=0; i<npdf; ++i) {
00365                         // Particle Data Group, Review of Particle Properties,
00366                         // 2002. Section 23.3.1.
00367                         double c = cos(dtheta*i);
00368                         pdf[i] = c*c;
00369                         sterradians += 2.0*pi*c*c*sin(dtheta*i)*dtheta;
00370                 }
00371                 init = false;
00372         }
00373 
00374         CLHEP::RandGeneral generator(pdf,npdf); // BUG in RandGeneral - cannot use new
00375         return generator.shoot() * thetamax;
00376 }


Member Data Documentation

Referenced by BLCMDcosmicraybeam().

G4double BLCMDcosmicraybeam::beamZ [private]

G4double BLCMDcosmicraybeam::beamWidth [private]

G4double BLCMDcosmicraybeam::beamHeight [private]

G4double BLCMDcosmicraybeam::beamLength [private]

G4ParticleGun* BLCMDcosmicraybeam::muonGun [private]

G4ParticleDefinition* BLCMDcosmicraybeam::muon [private]

G4double BLCMDcosmicraybeam::radius [private]

G4long BLCMDcosmicraybeam::hits [private]

G4double BLCMDcosmicraybeam::sterradians [private]

G4String BLCMDcosmicraybeam::particle [private]

Referenced by BLCMDcosmicraybeam(), init(), and printBeam().


The documentation for this class was generated from the following file:
g4beamline