src/BDSGlobalConstants.cc

00001 
00006 #include "BDSGlobalConstants.hh"
00007 #include "parser/gmad.h"
00008 //#include "../parser/getEnv.h"
00009 #include "BDSDebug.hh"
00010 #include "G4UniformMagField.hh"
00011 #include "G4ParticleTypes.hh"
00012 #include "G4ParticleTable.hh"
00013 #include "G4ParticleDefinition.hh"
00014 #include <cstdlib>
00015 
00016 #include <assert.h>
00017 #include <string>
00018 #include <stack>
00019 #include <cmath>
00020 
00021 BDSGlobalConstants* BDSGlobalConstants::_instance = 0;
00022 
00023 BDSGlobalConstants* BDSGlobalConstants::Instance(){
00024   if(_instance==0) {
00025     _instance = new BDSGlobalConstants(options);
00026   }
00027   return _instance;
00028 }
00029 
00030 BDSGlobalConstants::BDSGlobalConstants(struct Options& opt):
00031   log(NULL), itsBeamParticleDefinition(NULL)
00032 {
00033   PI = 4.0 * atan(1.0);
00034   // defaults:
00035   if(opt.physicsList == "") 
00036     itsPhysListName = "standard";
00037   else
00038     itsPhysListName = opt.physicsList;
00039   if(opt.pipeMaterial == "") 
00040     itsPipeMaterial = "StainlessSteel";
00041   else
00042     itsPipeMaterial = opt.pipeMaterial;
00043   if(opt.vacMaterial == "") 
00044     itsVacMaterial = "Vacuum";
00045   else
00046     itsVacMaterial = opt.vacMaterial;
00047 
00048  if(opt.tunnelMaterial == "") 
00049     itsTunnelMaterialName = "concrete";
00050   else
00051     itsTunnelMaterialName = opt.tunnelMaterial;
00052  if(opt.tunnelCavityMaterial == "") 
00053     itsTunnelCavityMaterialName = "Air";
00054   else
00055     itsTunnelCavityMaterialName = opt.tunnelCavityMaterial;
00056  if(opt.soilMaterial == "") 
00057     itsSoilMaterialName = "soil";
00058   else
00059     itsSoilMaterialName = opt.soilMaterial;
00060 
00061  itsSampleDistRandomly = true;
00062  itsGeometryBias = opt.geometryBias;
00063 
00064  itsShowTunnel=opt.showTunnel;
00065  itsSensitiveComponents=opt.sensitiveBeamlineComponents;
00066  itsSensitiveBeamPipe=opt.sensitiveBeamPipe;
00067  itsSensitiveBLMs=opt.sensitiveBLMs;
00068  itsDefaultRangeCut=opt.defaultRangeCut;
00069  itsElossHistoBinWidth=opt.elossHistoBinWidth; //Longitudinal and transverse energy loss histogram bin widths
00070  itsElossHistoTransBinWidth=opt.elossHistoTransBinWidth;
00071   itsFFact=opt.ffact;
00072   itsParticleName=G4String(opt.particleName);
00073   itsBeamTotalEnergy = opt.beamEnergy * GeV;
00074   itsVacuumPressure = opt.vacuumPressure*bar;
00075   itsPlanckScatterFe = opt.planckScatterFe;
00076   //Fraction of events with leading particle biasing.
00077   itsBeampipeRadius = opt.beampipeRadius * m;
00078   if(itsBeampipeRadius == 0){
00079     G4cerr << __METHOD_NAME__ << "Error: option \"beampipeRadius\" must be greater than 0" <<  G4endl;
00080     exit(1);
00081   }
00082   itsBeampipeThickness = opt.beampipeThickness * m;
00083   itsComponentBoxSize = opt.componentBoxSize *m;
00084   if (itsComponentBoxSize < (itsBeampipeThickness + itsBeampipeRadius)){
00085     G4cerr << __METHOD_NAME__ << "Error: option \"boxSize\" must be greater than the sum of \"beampipeRadius\" and \"beamPipeThickness\" " << G4endl;
00086     exit(1);
00087   }
00088   itsBuildTunnel = opt.buildTunnel;
00089   itsBuildTunnelFloor = opt.buildTunnelFloor;  
00090   itsTunnelRadius = opt.tunnelRadius * m;
00091   if (itsTunnelRadius < itsComponentBoxSize/2){
00092     G4cerr << __METHOD_NAME__ << "> Error: option \"tunnelRadius\" must be grater than \"boxSize\"/2 " << G4endl;
00093     exit(1);
00094   }
00095   itsTunnelThickness = opt.tunnelThickness * m; //Tunnel geometry options read from file
00096   itsTunnelSoilThickness = opt.tunnelSoilThickness * m;
00097   itsTunnelFloorOffset = opt.tunnelFloorOffset * m;
00098   itsTunnelOffsetX = opt.tunnelOffsetX * m;
00099   itsTunnelOffsetY = opt.tunnelOffsetY * m;
00100   //Beam loss monitor (BLM) geometry
00101   itsBlmRad = opt.blmRad * m;
00102   itsBlmLength = opt.blmLength *m;
00103   //Sampler geometry - default diameter is the tunnel diameter
00104   if(opt.samplerDiameter==0){
00105     itsSamplerDiameter=2*itsTunnelRadius;
00106   } else {
00107     itsSamplerDiameter = opt.samplerDiameter * m;
00108   }
00109   itsSamplerLength = 1E-8 * m;
00110   itsThresholdCutCharged = opt.thresholdCutCharged * GeV;
00111   itsThresholdCutPhotons = opt.thresholdCutPhotons * GeV;
00112   itsProdCutPhotons = opt.prodCutPhotons * m;
00113   itsProdCutPhotonsP = opt.prodCutPhotonsP * m;
00114   itsProdCutElectrons = opt.prodCutElectrons * m;
00115   itsProdCutElectronsP = opt.prodCutElectronsP * m;
00116   itsProdCutPositrons = opt.prodCutPositrons * m;
00117   itsProdCutPositronsP = opt.prodCutPositronsP * m;
00118   itsDeltaChord = opt.deltaChord * m;
00119   itsChordStepMinimum = opt.chordStepMinimum * m;
00120   itsDeltaIntersection= opt.deltaIntersection * m;
00121   itsMinimumEpsilonStep = opt.minimumEpsilonStep;
00122   itsMaximumEpsilonStep = opt.maximumEpsilonStep;
00123   itsMaxTime = opt.maximumTrackingTime * s;
00124   
00125   itsDeltaOneStep = opt.deltaOneStep * m;
00126   doTwiss = opt.doTwiss;
00127   itsDoPlanckScattering = opt.doPlanckScattering;
00128   itsCheckOverlaps = opt.checkOverlaps;
00129   itsTurnOnCerenkov = opt.turnOnCerenkov;
00130   itsSynchRadOn = opt.synchRadOn;
00131   G4cout << "BDSGlobalConstants::Instance() synchRadOn = " << itsSynchRadOn << G4endl;
00132   itsDecayOn = opt.decayOn;
00133   itsSynchRescale = opt.synchRescale; // rescale due to synchrotron
00134   itsSynchTrackPhotons= opt.synchTrackPhotons;
00135   G4cout << __METHOD_NAME__ << "synchTrackphotons = " << itsSynchTrackPhotons << G4endl;
00136   itsSynchLowX = opt.synchLowX;
00137   itsSynchLowGamE = opt.synchLowGamE * GeV;  // lowest gamma energy
00138   itsSynchPhotonMultiplicity = opt.synchPhotonMultiplicity;
00139   itsSynchMeanFreeFactor = opt.synchMeanFreeFactor;
00140   //Synchrotron primary generator
00141   itsSynchPrimaryGen = false; //XXX check what this is 19/4/11
00142   itsLengthSafety = opt.lengthSafety;
00143   itsNumberToGenerate = opt.numberToGenerate;
00144   itsNumberOfEventsPerNtuple = opt.numberOfEventsPerNtuple;
00145   itsEventNumberOffset = opt.eventNumberOffset;
00146   itsRandomSeed = opt.randomSeed;
00147   itsGammaToMuFe= opt.gammaToMuFe;
00148   itsAnnihiToMuFe= opt.annihiToMuFe;
00149   itsEeToHadronsFe=opt.eeToHadronsFe;
00150   itsUseEMLPB=opt.useEMLPB;
00151   itsUseHadLPB=opt.useHadLPB;
00152   itsDecayOn=opt.decayOn;
00153   SetLPBFraction(opt.LPBFraction);
00154   itsStoreMuonTrajectories = opt.storeMuonTrajectories;
00155   itsTrajCutGTZ = opt.trajCutGTZ;
00156   itsTrajCutLTR = opt.trajCutLTR;
00157   itsStoreNeutronTrajectories = opt.storeNeutronTrajectories;
00158   itsStoreTrajectory = opt.storeTrajectory;
00159   //G4cout<<"STOREA TRAJ = "<< itsStoreTrajectory<<G4endl;
00160   stopTracks = opt.stopTracks; 
00161   // defaults - parameters of the laserwire process
00162   itsLaserwireWavelength = 0.532 * micrometer;
00163   itsLaserwireDir = G4ThreeVector(1,0,0);
00164   itsLaserwireTrackPhotons = 1;
00165   itsLaserwireTrackElectrons = 1;
00166   isWaitingForDump = false;
00167   isDumping = false;
00168   isReading = false;
00169   isReadFromStack = false;
00170   itsFifo = opt.fifo;
00171   G4cout << __METHOD_NAME__ << "itsFifo = " << itsFifo << G4endl;
00172   G4cout << __METHOD_NAME__ << "GetFifo() = " << GetFifo() << G4endl;
00173   itsRefVolume = opt.refvolume;
00174   itsRefCopyNo = opt.refcopyno;
00175   isReference = 0;
00176   itsIncludeIronMagFields = opt.includeIronMagFields;
00177   zeroMagField = new G4UniformMagField(G4ThreeVector());
00178   itsZeroFieldManager=new G4FieldManager();
00179   itsZeroFieldManager->SetDetectorField(zeroMagField);
00180   itsZeroFieldManager->CreateChordFinder(zeroMagField);
00181    
00182 }
00183 
00184 // a robust compiler-invariant method to convert from integer to G4String
00185 G4String BDSGlobalConstants::StringFromInt(G4int N) 
00186 {
00187   if (N==0) return "0";
00188   G4int nLocal=N, nDigit=0, nMax=1;
00189   do { nDigit++;
00190       nMax*=10;} while(N > nMax-1);
00191   nMax/=10;
00192   G4String Cnum;
00193   do {Cnum+=StringFromDigit(nLocal/nMax);
00194       nLocal-= nLocal/nMax * nMax;
00195       nMax/=10;}   while(nMax>1);
00196   if(nMax!=0)Cnum+=StringFromDigit(nLocal/nMax);
00197   return Cnum;
00198 }
00199 
00200 // a robust compiler-invariant method to convert from digit to G4String
00201 G4String BDSGlobalConstants::StringFromDigit(G4int N) 
00202 {
00203   if(N<0 || N>9)
00204     G4Exception("Invalid Digit in BDSGlobalConstants::StringFromDigit", "-1", FatalException, "");
00205   G4String Cnum;
00206   if(N==0)Cnum="0";
00207   else if(N==1)Cnum="1";
00208   else if(N==2)Cnum="2";
00209   else if(N==3)Cnum="3";
00210   else if(N==4)Cnum="4";
00211   else if(N==5)Cnum="5";
00212   else if(N==6)Cnum="6";
00213   else if(N==7)Cnum="7";
00214   else if(N==8)Cnum="8";
00215   else if(N==9)Cnum="9"; 
00216   return Cnum;
00217 }
00218 
00219 BDSGlobalConstants::~BDSGlobalConstants()
00220 {  
00221   delete itsZeroFieldManager;
00222   delete zeroMagField;
00223 }

Generated on 27 Aug 2013 for BDSIM by  doxygen 1.4.7