00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __BDSACCELERATORCOMPONENT_H
00024 #define __BDSACCELERATORCOMPONENT_H
00025
00026 #include <cstring>
00027 #include "G4LogicalVolume.hh"
00028 #include "G4VisAttributes.hh"
00029 #include "G4LogicalVolume.hh"
00030 #include "globals.hh"
00031 #include "BDSBeamPipe.hh"
00032 #include "BDSEnergyCounterSD.hh"
00033
00034 #include "G4MagneticField.hh"
00035 #include "G4Mag_EqRhs.hh"
00036 #include "G4MagIntegratorStepper.hh"
00037 #include "G4FieldManager.hh"
00038 #include "G4UserLimits.hh"
00039
00040 #include <vector>
00041
00042
00043
00044 class BDSAcceleratorComponent
00045 {
00046 public:
00047
00048 virtual ~BDSAcceleratorComponent ();
00049
00050
00051 const G4String GetName () const;
00052 void SetName(G4String aName);
00053
00054
00055 const G4String GetType () const;
00056 void SetType(G4String aType);
00057
00058
00059
00060
00061
00062
00063
00064 const G4double GetAngle () const;
00065
00066
00067 void SetLength(G4double aLength);
00068 virtual const G4double GetLength () const;
00069 virtual const G4double GetZLength () const;
00070 virtual const G4double GetArcLength () const;
00071
00072 const G4double GetPhi () const;
00073 void SetPhi (G4double val);
00074
00075 const G4double GetTheta () const;
00076 void SetTheta(G4double val);
00077
00078 const G4double GetPsi () const;
00079 void SetPsi(G4double val);
00080
00081 const G4double GetXOffset() const;
00082 const G4double GetYOffset() const;
00083 const G4double GetZOffset() const;
00084
00085 G4double GetAperX();
00086 G4double GetAperY();
00087
00088 G4double GetK1();
00089 G4double GetK2();
00090 G4double GetK3();
00091
00092
00093 void SetK1(G4double K1);
00094 void SetK2(G4double K2);
00095 void SetK3(G4double K3);
00096
00097 G4RotationMatrix* GetRotation();
00098 G4ThreeVector GetPosition();
00099 void SetPosition(G4ThreeVector);
00100
00101 const G4double GetTilt() const;
00102
00103
00104
00105
00106
00107
00108 G4LogicalVolume* GetMarkerLogicalVolume() const;
00109
00110 BDSEnergyCounterSD* GetBDSEnergyCounter() const;
00111
00112 void SetBDSEnergyCounter( BDSEnergyCounterSD* anBDSEnergyCounter);
00113
00114 G4int GetCopyNumber() const;
00115
00116 G4double GetSPos() const;
00117
00118 void SetSPos(G4double spos);
00119
00120 void SetCopyNumber(G4int nCopy);
00121
00122 void SetBDSEnergyCounterID(G4int anID);
00123
00124 G4int GetBDSEnergyCounterID();
00125
00126 void SetSensitiveVolume(G4LogicalVolume* aLogVol);
00127
00128 G4LogicalVolume* GetSensitiveVolume();
00129
00130 void SetMultipleSensitiveVolumes(G4LogicalVolume* aLogVol);
00131
00132 std::vector<G4LogicalVolume*> GetMultipleSensitiveVolumes();
00133
00134 void SetInnerMostLogicalVolume(G4LogicalVolume* aLogVol);
00135
00136 G4LogicalVolume* GetInnerMostLogicalVolume() const;
00137
00138 G4UserLimits* GetInnerBPUserLimits();
00139
00140 G4double GetZLower();
00141 G4double GetZUpper();
00142 void SetZLower(G4double aZLower);
00143 void SetZUpper(G4double aZUpper);
00144 void AddSynchEnergyLoss(G4double SynchEnergyLoss);
00145 G4double GetSynchEnergyLoss();
00146
00147 BDSAcceleratorComponent();
00148 void BuildOuterFieldManager();
00149
00150
00151 virtual void PrepareField(G4VPhysicalVolume *referenceVolume);
00152 virtual void SynchRescale(G4double factor);
00153
00154
00155 virtual void AlignComponent(G4ThreeVector& TargetPos,
00156 G4RotationMatrix *TargetRot,
00157 G4RotationMatrix& globalRotation,
00158 G4ThreeVector& rtot,
00159 G4ThreeVector& rlast,
00160 G4ThreeVector& localX,
00161 G4ThreeVector& localY,
00162 G4ThreeVector& localZ);
00163
00164
00165
00166
00167 G4double getParameterValue(G4String spec, G4String name) const;
00168 G4String getParameterValueString(G4String spec, G4String name) const;
00169
00170
00171 BDSAcceleratorComponent (
00172 G4String& aName,
00173 G4double aLength,
00174 G4double aBpRadius,
00175 G4double aXAper,
00176 G4double aYAper,
00177 G4VisAttributes* aVisAtt,
00178 G4String aMaterial = "",
00179 G4double phi=0.,
00180
00181 G4double XOffset=0.,
00182 G4double YOffset=0.,
00183 G4double ZOffset=0.);
00184
00185
00186 G4VisAttributes* GetVisAttributes()const;
00187 G4LogicalVolume* itsOuterLogicalVolume;
00188 G4LogicalVolume* itsMarkerLogicalVolume;
00189
00190 protected:
00191 G4String itsName;
00192 G4String itsType;
00193 G4double itsLength;
00194 G4double itsBpRadius;
00195 G4double itsXAper;
00196 G4double itsYAper;
00197 G4double itsAngle;
00198 G4double itsTilt;
00199 G4String itsMaterial;
00200
00201 G4double itsMagScaleFactor;
00202 G4double itsPhi;
00203 G4double itsTheta;
00204 G4double itsPsi;
00205 G4double itsK1, itsK2, itsK3;
00206 G4RotationMatrix* itsRotation;
00207 G4ThreeVector itsPosition;
00208 BDSBeamPipe* itsBeamPipe;
00209 G4MagneticField* itsOuterMagField;
00210 G4Mag_EqRhs* itsOuterEqRhs;
00211 G4MagIntegratorStepper* itsOuterStepper;
00212 G4ChordFinder* itsOuterChordFinder;
00213 G4FieldManager* itsOuterFieldMgr;
00214 G4VisAttributes* itsVisAttributes;
00215 G4UserLimits* itsOuterUserLimits;
00216 G4UserLimits* itsMarkerUserLimits;
00217 G4UserLimits* itsInnerBeampipeUserLimits;
00218 G4LogicalVolume* itsInnerMostLogicalVolume;
00219
00220 G4double itsXOffset;
00221 G4double itsYOffset;
00222 G4double itsZOffset;
00223
00224 private:
00225 G4double itsSPos;
00226 G4int itsCopyNumber;
00227 BDSEnergyCounterSD* itsBDSEnergyCounter;
00228 G4int itsCollectionID;
00229 G4LogicalVolume* itsSensitiveVolume;
00230 std::vector<G4LogicalVolume*> itsMultipleSensitiveVolumes;
00231 G4double itsZLower;
00232 G4double itsZUpper;
00233 G4double itsSynchEnergyLoss;
00234
00235 };
00236
00237
00238
00239 inline BDSAcceleratorComponent::
00240 BDSAcceleratorComponent (
00241 G4String& aName,G4double aLength,
00242 G4double aBpRadius,G4double aXAper,G4double aYAper,
00243 G4VisAttributes* aVisAtt,G4String aMaterial,G4double angle,
00244 G4double XOffset, G4double YOffset,G4double ZOffset):
00245 itsName(aName),itsLength(aLength),itsBpRadius(aBpRadius),
00246 itsXAper(aXAper),itsYAper(aYAper),itsAngle(angle),
00247 itsMaterial(aMaterial),itsVisAttributes(aVisAtt),
00248 itsXOffset(XOffset),itsYOffset(YOffset), itsZOffset(ZOffset)
00249 {
00250 itsSensitiveVolume=NULL;
00251 itsInnerBeampipeUserLimits =new G4UserLimits();
00252 itsPhi = 0;
00253 itsTheta = 0;
00254 itsPsi = 0;
00255 itsTilt = 0;
00256 itsMagScaleFactor = 1;
00257 }
00258
00259 inline const G4double BDSAcceleratorComponent::GetLength () const
00260 {return itsLength;}
00261
00262 inline const G4double BDSAcceleratorComponent::GetArcLength () const
00263 {return itsLength;}
00264
00265 inline const G4double BDSAcceleratorComponent::GetZLength () const
00266 {return itsLength;}
00267
00268 inline const G4double BDSAcceleratorComponent::GetAngle () const
00269 {return itsAngle;}
00270
00271 inline const G4double BDSAcceleratorComponent::GetPhi () const
00272 {return itsPhi;}
00273
00274 inline void BDSAcceleratorComponent::SetPhi (G4double val)
00275 {itsPhi = val;}
00276
00277 inline const G4double BDSAcceleratorComponent::GetTheta () const
00278 {return itsTheta;}
00279
00280 inline void BDSAcceleratorComponent::SetTheta (G4double val)
00281 {itsTheta = val;}
00282
00283 inline const G4double BDSAcceleratorComponent::GetPsi () const
00284 {return itsPsi;}
00285
00286 inline void BDSAcceleratorComponent::SetPsi (G4double val)
00287 {itsPsi = val;}
00288
00289 inline G4double BDSAcceleratorComponent::GetAperX()
00290 {
00291 if(itsXAper==0)
00292 return itsBpRadius;
00293 else return itsXAper;
00294 }
00295
00296 inline G4double BDSAcceleratorComponent::GetAperY()
00297 {
00298 if(itsYAper==0)
00299 return itsBpRadius;
00300 else return itsYAper;
00301 }
00302
00303 inline G4double BDSAcceleratorComponent::GetK1()
00304 { return itsK1; }
00305
00306 inline G4double BDSAcceleratorComponent::GetK2()
00307 { return itsK2; }
00308
00309 inline G4double BDSAcceleratorComponent::GetK3()
00310 { return itsK3; }
00311
00312 inline void BDSAcceleratorComponent::SetK1(G4double K1)
00313 { itsK1 = K1; }
00314
00315 inline void BDSAcceleratorComponent::SetK2(G4double K2)
00316 { itsK2 = K2; }
00317
00318 inline void BDSAcceleratorComponent::SetK3(G4double K3)
00319 { itsK3 = K3; }
00320
00321 inline G4RotationMatrix* BDSAcceleratorComponent::GetRotation()
00322 { return itsRotation;}
00323
00324 inline G4ThreeVector BDSAcceleratorComponent::GetPosition()
00325 { return itsPosition;}
00326
00327 inline void BDSAcceleratorComponent::SetPosition(G4ThreeVector pos)
00328 { itsPosition = pos;}
00329
00330 inline const G4String BDSAcceleratorComponent::GetName () const
00331 {return itsName;}
00332
00333 inline void BDSAcceleratorComponent::SetName (G4String aName)
00334 {itsName=aName;}
00335
00336 inline const G4String BDSAcceleratorComponent::GetType () const
00337 {return itsType;}
00338
00339 inline void BDSAcceleratorComponent::SetType (G4String aType)
00340 {itsType=aType;}
00341
00342 inline G4LogicalVolume* BDSAcceleratorComponent::GetMarkerLogicalVolume() const
00343 {return itsMarkerLogicalVolume;}
00344
00345 inline G4LogicalVolume* BDSAcceleratorComponent::GetInnerMostLogicalVolume() const
00346 {return itsInnerMostLogicalVolume;}
00347
00348 inline void BDSAcceleratorComponent::
00349 SetInnerMostLogicalVolume(G4LogicalVolume* aLogVol)
00350 {itsInnerMostLogicalVolume = aLogVol;}
00351
00352 inline G4VisAttributes* BDSAcceleratorComponent::GetVisAttributes() const
00353 {return itsVisAttributes;}
00354
00355 inline BDSEnergyCounterSD* BDSAcceleratorComponent::GetBDSEnergyCounter() const
00356 {return itsBDSEnergyCounter;}
00357
00358 inline G4int BDSAcceleratorComponent::GetCopyNumber() const
00359 {return itsCopyNumber;}
00360
00361 inline G4double BDSAcceleratorComponent::GetSPos() const
00362 {return itsSPos;}
00363
00364 inline void BDSAcceleratorComponent::SetCopyNumber(G4int nCopy)
00365 {itsCopyNumber=nCopy;}
00366
00367 inline void BDSAcceleratorComponent::SetSPos(G4double spos)
00368 {itsSPos=spos;}
00369
00370 inline void
00371 BDSAcceleratorComponent::SetBDSEnergyCounter(BDSEnergyCounterSD* anBDSEnergyCounter)
00372 {itsBDSEnergyCounter=anBDSEnergyCounter;}
00373
00374 inline void BDSAcceleratorComponent::SetBDSEnergyCounterID(G4int anID)
00375 {itsCollectionID=anID;}
00376
00377 inline G4int BDSAcceleratorComponent::GetBDSEnergyCounterID()
00378 {return itsCollectionID;}
00379
00380 inline
00381 void BDSAcceleratorComponent::SetSensitiveVolume(G4LogicalVolume* aLogVol)
00382 {itsSensitiveVolume=aLogVol;}
00383
00384 inline G4LogicalVolume* BDSAcceleratorComponent::GetSensitiveVolume()
00385 {return itsSensitiveVolume;}
00386
00387 inline void BDSAcceleratorComponent::SetMultipleSensitiveVolumes(G4LogicalVolume* aLogVol)
00388 { itsMultipleSensitiveVolumes.push_back(aLogVol);}
00389
00390 inline std::vector<G4LogicalVolume*> BDSAcceleratorComponent::GetMultipleSensitiveVolumes()
00391 {return itsMultipleSensitiveVolumes;}
00392
00393 inline G4double BDSAcceleratorComponent::GetZLower()
00394 {return itsZLower;}
00395
00396 inline G4double BDSAcceleratorComponent::GetZUpper()
00397 {return itsZUpper;}
00398
00399 inline void BDSAcceleratorComponent::SetZLower(G4double aZLower)
00400 {itsZLower=aZLower;}
00401
00402 inline void BDSAcceleratorComponent::SetZUpper(G4double aZUpper)
00403 {itsZUpper=aZUpper;}
00404
00405 inline void
00406 BDSAcceleratorComponent::AddSynchEnergyLoss(G4double SynchEnergyLoss)
00407 {itsSynchEnergyLoss+=SynchEnergyLoss;}
00408
00409 inline G4double BDSAcceleratorComponent::GetSynchEnergyLoss()
00410 {return itsSynchEnergyLoss;}
00411
00412 inline G4UserLimits* BDSAcceleratorComponent::GetInnerBPUserLimits()
00413 {return itsInnerBeampipeUserLimits;}
00414
00415 inline const G4double BDSAcceleratorComponent::GetXOffset() const
00416 {return itsXOffset;}
00417
00418 inline const G4double BDSAcceleratorComponent::GetYOffset() const
00419 {return itsYOffset;}
00420
00421 inline const G4double BDSAcceleratorComponent::GetZOffset() const
00422 {return itsZOffset;}
00423
00424 inline const G4double BDSAcceleratorComponent::GetTilt() const
00425 {return itsTilt;}
00426
00427
00428 inline G4double BDSAcceleratorComponent::getParameterValue(G4String spec, G4String name) const
00429 {
00430 G4double value = 0;
00431
00432 std::string delimiters = "&";
00433 std::string param = name + "=";
00434
00435 int pos = spec.find(param);
00436 if( pos >= 0 )
00437 {
00438
00439 int pos2 = spec.find("&",pos);
00440 int pos3 = spec.length();
00441 int tend = pos2 < 0 ? pos3 : pos2;
00442 int llen = tend - pos - param.length();
00443
00444 std::string val = spec.substr(pos + param.length(), llen);
00445
00446 value = atof(val.c_str());
00447
00448 }
00449
00450 return value;
00451
00452 }
00453
00454 inline G4String BDSAcceleratorComponent::getParameterValueString(G4String spec, G4String name) const
00455 {
00456 G4String value = "";
00457
00458 std::string delimiters = "&";
00459 std::string param = name + "=";
00460
00461 int pos = spec.find(param);
00462 if( pos >= 0 )
00463 {
00464
00465 int pos2 = spec.find("&",pos);
00466 int pos3 = spec.length();
00467 int tend = pos2 < 0 ? pos3 : pos2;
00468 int llen = tend - pos - param.length();
00469
00470 value = spec.substr(pos + param.length(), llen);
00471 }
00472
00473 return value;
00474
00475 }
00476
00477 #endif