/scratch0/jsnuveri/BDSIM/BDSIMgit/bdsim/src/BDSGlobalConstants.cc

00001 
00007 #include <cstdlib>
00008 
00009 #include "BDSGlobalConstants.hh"
00010 
00011 #include "parser/options.h"
00012 
00013 #include "BDSBeamPipeType.hh"
00014 #include "BDSDebug.hh"
00015 
00016 #include "G4Colour.hh"
00017 #include "G4FieldManager.hh"
00018 #include "G4UniformMagField.hh"
00019 #include "G4ThreeVector.hh"
00020 #include "G4UserLimits.hh"
00021 #include "G4VisAttributes.hh"
00022 
00023 extern Options options;
00024 
00025 BDSGlobalConstants* BDSGlobalConstants::_instance = 0;
00026 
00027 BDSGlobalConstants* BDSGlobalConstants::Instance(){
00028   if(_instance==0) {
00029     _instance = new BDSGlobalConstants(options);
00030   }
00031   return _instance;
00032 }
00033 
00034 BDSGlobalConstants::BDSGlobalConstants(struct Options& opt):
00035   itsBeamParticleDefinition(NULL),itsBeamMomentum(0.0),itsBeamKineticEnergy(0.0),itsParticleMomentum(0.0),itsParticleKineticEnergy(0.0),itsSMax(0.0)
00036 {
00037   itsPhysListName       = opt.physicsList;
00038   itsBeamPipeMaterial   = opt.beampipeMaterial;
00039   itsApertureType       = BDS::DetermineBeamPipeType(opt.apertureType);
00040   itsVacuumMaterial     = opt.vacMaterial;
00041   itsEmptyMaterial      = "G4_Galactic"; // space vacuum
00042 
00043   itsSampleDistRandomly = true;
00044   itsGeometryBias = opt.geometryBias;
00045   
00046   itsSensitiveComponents=opt.sensitiveBeamlineComponents;
00047   itsSensitiveBeamPipe=opt.sensitiveBeamPipe;
00048   itsSensitiveBLMs=opt.sensitiveBLMs;
00049   itsDefaultRangeCut=opt.defaultRangeCut;
00050   itsElossHistoBinWidth=opt.elossHistoBinWidth; //Longitudinal and transverse energy loss histogram bin widths
00051   itsElossHistoTransBinWidth=opt.elossHistoTransBinWidth;
00052   itsFFact=opt.ffact;
00053   itsParticleName=G4String(opt.particleName);
00054   itsBeamTotalEnergy = opt.beamEnergy * CLHEP::GeV;
00055   if (itsBeamTotalEnergy == 0) {
00056     G4cerr << __METHOD_NAME__ << "Error: option \"beamenergy\" is not defined or must be greater than 0" <<  G4endl;
00057     exit(1);
00058   }
00059   itsParticleTotalEnergy = opt.E0 * CLHEP::GeV; 
00060   if (itsParticleTotalEnergy == 0) {
00061     itsParticleTotalEnergy = itsBeamTotalEnergy;
00062   }
00063 
00064   itsPlanckScatterFe = opt.planckScatterFe;
00065   //Fraction of events with leading particle biasing.
00066 
00067   //beampipe
00068   itsBeamPipeRadius = opt.beampipeRadius * CLHEP::m;
00069   itsAper1 = opt.aper1*CLHEP::m;
00070   itsAper2 = opt.aper2*CLHEP::m;
00071   itsAper3 = opt.aper3*CLHEP::m;
00072   itsAper4 = opt.aper4*CLHEP::m;
00073   // note beampipetype already done before these checks! at top of this function
00074   BDS::CheckApertureInfo(itsApertureType,itsBeamPipeRadius,itsAper1,itsAper2,itsAper3,itsAper4);
00075   
00076   itsBeamPipeThickness = opt.beampipeThickness * CLHEP::m;
00077 
00078   //magnet geometry
00079   itsOuterDiameter = opt.outerDiameter * CLHEP::m;
00080   if (itsOuterDiameter < 2*(itsBeamPipeThickness + itsBeamPipeRadius)){
00081     G4cerr << __METHOD_NAME__ << "Error: option \"outerDiameter\" must be greater than 2x (\"beampipeRadius\" + \"beamPipeThickness\") " << G4endl;
00082     exit(1);
00083   }
00084   itsMagnetGeometryType = BDS::DetermineMagnetGeometryType(opt.magnetGeometryType);
00085   itsOuterMaterialName  = opt.outerMaterialName;
00086   
00087   //Beam loss monitor (BLM) geometry
00088   itsBlmRad = opt.blmRad * CLHEP::m;
00089   itsBlmLength = opt.blmLength * CLHEP::m;
00090   itsSamplerDiameter = opt.samplerDiameter * CLHEP::m;
00091   itsSamplerLength = 4E-8 * CLHEP::m;
00092   itsThresholdCutCharged = opt.thresholdCutCharged * CLHEP::GeV;
00093   itsThresholdCutPhotons = opt.thresholdCutPhotons * CLHEP::GeV;
00094   itsProdCutPhotons = opt.prodCutPhotons * CLHEP::m;
00095   itsProdCutPhotonsP = opt.prodCutPhotonsP * CLHEP::m;
00096   itsProdCutPhotonsA = opt.prodCutPhotonsA * CLHEP::m;
00097   itsProdCutElectrons = opt.prodCutElectrons * CLHEP::m;
00098   itsProdCutElectronsP = opt.prodCutElectronsP * CLHEP::m;
00099   itsProdCutElectronsA = opt.prodCutElectronsA * CLHEP::m;
00100   itsProdCutPositrons = opt.prodCutPositrons * CLHEP::m;
00101   itsProdCutPositronsP = opt.prodCutPositronsP * CLHEP::m;
00102   itsProdCutPositronsA = opt.prodCutPositronsA * CLHEP::m;
00103   itsDeltaChord = opt.deltaChord * CLHEP::m;
00104   itsChordStepMinimum = opt.chordStepMinimum * CLHEP::m;
00105   itsDeltaIntersection= opt.deltaIntersection * CLHEP::m;
00106   itsMinimumEpsilonStep = opt.minimumEpsilonStep;
00107   itsMaximumEpsilonStep = opt.maximumEpsilonStep;
00108   itsMaxTime = opt.maximumTrackingTime * CLHEP::s;
00109   
00110   itsDeltaOneStep = opt.deltaOneStep * CLHEP::m;
00111   itsDoPlanckScattering = opt.doPlanckScattering;
00112   itsCheckOverlaps = opt.checkOverlaps;
00113   itsTurnOnCerenkov = opt.turnOnCerenkov;
00114   itsTurnOnOpticalAbsorption = opt.turnOnOpticalAbsorption;
00115   itsTurnOnRayleighScattering = opt.turnOnRayleighScattering;
00116   itsTurnOnMieScattering = opt.turnOnMieScattering;
00117   itsTurnOnOpticalSurface = opt.turnOnOpticalSurface;
00118   itsTurnOnBirksSaturation = opt.turnOnBirksSaturation;
00119   itsScintYieldFactor=opt.scintYieldFactor;
00120   itsSynchRadOn = opt.synchRadOn;
00121   G4cout << "BDSGlobalConstants::Instance() synchRadOn = " << itsSynchRadOn << G4endl;
00122   itsDecayOn = opt.decayOn;
00123   itsSynchTrackPhotons= opt.synchTrackPhotons;
00124   G4cout << __METHOD_NAME__ << "synchTrackphotons = " << itsSynchTrackPhotons << G4endl;
00125   itsSynchLowX = opt.synchLowX;
00126   itsSynchLowGamE = opt.synchLowGamE * CLHEP::GeV;  // lowest gamma energy
00127   itsSynchPhotonMultiplicity = opt.synchPhotonMultiplicity;
00128   itsSynchMeanFreeFactor = opt.synchMeanFreeFactor;
00129   itsLengthSafety = opt.lengthSafety;
00130   itsNumberToGenerate = opt.numberToGenerate;
00131   itsNumberOfEventsPerNtuple = opt.numberOfEventsPerNtuple;
00132   itsEventNumberOffset = opt.eventNumberOffset;
00133   itsRandomSeed = opt.randomSeed;
00134   itsGammaToMuFe= opt.gammaToMuFe;
00135   itsAnnihiToMuFe= opt.annihiToMuFe;
00136   itsEeToHadronsFe=opt.eeToHadronsFe;
00137   itsUseEMLPB=opt.useEMLPB;
00138   itsUseHadLPB=opt.useHadLPB;
00139   itsDecayOn=opt.decayOn;
00140   SetLPBFraction(opt.LPBFraction);
00141   itsStoreMuonTrajectories = opt.storeMuonTrajectories;
00142   itsTrajCutGTZ = opt.trajCutGTZ;
00143   itsTrajCutLTR = opt.trajCutLTR;
00144   itsStoreNeutronTrajectories = opt.storeNeutronTrajectories;
00145   itsStoreTrajectory = opt.storeTrajectory;
00146   //G4cout<<"STOREA TRAJ = "<< itsStoreTrajectory<<G4endl;
00147   stopTracks = opt.stopTracks; 
00148   // defaults - parameters of the laserwire process
00149   itsLaserwireWavelength = 0.532 * CLHEP::micrometer;
00150   itsLaserwireDir = G4ThreeVector(1,0,0);
00151   itsLaserwireTrackPhotons = 1;
00152   itsLaserwireTrackElectrons = 1;
00153   isWaitingForDump = false;
00154   isDumping = false;
00155   isReading = false;
00156   isReadFromStack = false;
00157   itsFifo = opt.fifo;
00158 #ifdef BDSDEBUG
00159   G4cout << __METHOD_NAME__ << "itsFifo = " << itsFifo << G4endl;
00160   G4cout << __METHOD_NAME__ << "GetFifo() = " << GetFifo() << G4endl;
00161 #endif
00162   itsIncludeIronMagFields = opt.includeIronMagFields;
00163   zeroMagField = new G4UniformMagField(G4ThreeVector());
00164   itsZeroFieldManager=new G4FieldManager();
00165   itsZeroFieldManager->SetDetectorField(zeroMagField);
00166   itsZeroFieldManager->CreateChordFinder(zeroMagField);
00167   itsTurnsTaken = 1; //counting from 1
00168   if(opt.nturns < 1)
00169     itsTurnsToTake = 1;
00170   else
00171     itsTurnsToTake = opt.nturns;
00172   teleporterdelta     = G4ThreeVector(0.,0.,0.);
00173   teleporterlength    = 0.0;
00174 
00175   InitRotationMatrices();
00176   
00177   // options that are never used (no set method):
00178   itsLWCalWidth       = 0.0;
00179   itsLWCalOffset      = 0.0;
00180   itsMagnetPoleRadius = 0.0;
00181   itsMagnetPoleSize   = 0.0;
00182 
00183   // initialise the default vis attributes and user limits that
00184   // can be copied by various bits of geometry
00185   InitVisAttributes();
00186   InitDefaultUserLimits();
00187 }
00188 
00189 void BDSGlobalConstants::InitVisAttributes()
00190 {
00191   //for vacuum volumes
00192   invisibleVisAttr = new G4VisAttributes(G4Colour::Black());
00193   invisibleVisAttr->SetVisibility(false);
00194   invisibleVisAttr->SetForceLineSegmentsPerCircle(50);
00195 
00196   //for normally invisible volumes like marker / container volumes in debug mode
00197   visibleDebugVisAttr = new G4VisAttributes(); //green
00198   visibleDebugVisAttr->SetColour(0,0.6,0,0.1);
00199   visibleDebugVisAttr->SetVisibility(true);
00200   visibleDebugVisAttr->SetForceLineSegmentsPerCircle(50);
00201 }
00202 
00203 void BDSGlobalConstants::InitDefaultUserLimits()
00204 {
00205   //these must be copied and not attached directly
00206   defaultUserLimits = new G4UserLimits("default_cuts");
00207   defaultUserLimits->SetUserMinEkine( GetThresholdCutCharged() );
00208   //user must set step length manually
00209 }
00210 
00211 void BDSGlobalConstants::InitRotationMatrices(){
00212   _RotY90       = new G4RotationMatrix();
00213   _RotYM90      = new G4RotationMatrix();
00214   _RotX90       = new G4RotationMatrix();
00215   _RotXM90      = new G4RotationMatrix();
00216   _RotYM90X90   = new G4RotationMatrix();
00217   _RotYM90XM90  = new G4RotationMatrix();
00218   G4double pi_ov_2 = asin(1.);
00219   _RotY90->rotateY(pi_ov_2);
00220   _RotYM90->rotateY(-pi_ov_2);
00221   _RotX90->rotateX(pi_ov_2);
00222   _RotXM90->rotateX(-pi_ov_2);
00223   _RotYM90X90->rotateY(-pi_ov_2);
00224   _RotYM90X90->rotateX( pi_ov_2);
00225   _RotYM90XM90->rotateY(-pi_ov_2);
00226   _RotYM90XM90->rotateX(-pi_ov_2);
00227 }
00228 
00229 //Methods to get the rotation matrices
00230 G4RotationMatrix* BDSGlobalConstants::RotY90() const{
00231   return _RotY90;
00232 }
00233 
00234 G4RotationMatrix* BDSGlobalConstants::RotYM90() const{
00235   return _RotYM90;
00236 }
00237 
00238 G4RotationMatrix* BDSGlobalConstants::RotX90() const{
00239   return _RotX90;
00240 }
00241 
00242 G4RotationMatrix* BDSGlobalConstants::RotXM90() const{
00243   return _RotXM90;
00244 }
00245 
00246 G4RotationMatrix* BDSGlobalConstants::RotYM90X90() const{
00247   return _RotYM90X90;
00248 }
00249 
00250 G4RotationMatrix* BDSGlobalConstants::RotYM90XM90() const{
00251   return _RotYM90XM90;
00252 }
00253 
00254 // a robust compiler-invariant method to convert from integer to G4String
00255 G4String BDSGlobalConstants::StringFromInt(G4int N)const
00256 {
00257   if (N==0) return "0";
00258   G4int nLocal=N, nDigit=0, nMax=1;
00259   do { nDigit++;
00260       nMax*=10;} while(N > nMax-1);
00261   nMax/=10;
00262   G4String Cnum;
00263   do {Cnum+=StringFromDigit(nLocal/nMax);
00264       nLocal-= nLocal/nMax * nMax;
00265       nMax/=10;}   while(nMax>1);
00266   if(nMax!=0)Cnum+=StringFromDigit(nLocal/nMax);
00267   return Cnum;
00268 }
00269 
00270 // a robust compiler-invariant method to convert from digit to G4String
00271 G4String BDSGlobalConstants::StringFromDigit(G4int N)const 
00272 {
00273   if(N<0 || N>9)
00274     G4Exception("Invalid Digit in BDSGlobalConstants::StringFromDigit", "-1", FatalException, "");
00275   G4String Cnum;
00276   if(N==0)Cnum="0";
00277   else if(N==1)Cnum="1";
00278   else if(N==2)Cnum="2";
00279   else if(N==3)Cnum="3";
00280   else if(N==4)Cnum="4";
00281   else if(N==5)Cnum="5";
00282   else if(N==6)Cnum="6";
00283   else if(N==7)Cnum="7";
00284   else if(N==8)Cnum="8";
00285   else if(N==9)Cnum="9"; 
00286   return Cnum;
00287 }
00288 
00289 BDSGlobalConstants::~BDSGlobalConstants()
00290 {  
00291   delete itsZeroFieldManager;
00292   delete zeroMagField;
00293   delete defaultUserLimits;
00294   _instance = 0;
00295 }

Generated on 28 Jun 2015 for BDSIM by  doxygen 1.4.7