00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "BDSGlobalConstants.hh"
00019 #include "BDSDebug.hh"
00020
00021 #include "BDSQuadrupole.hh"
00022 #include "G4Box.hh"
00023 #include "G4Tubs.hh"
00024 #include "G4Trd.hh"
00025 #include "G4VisAttributes.hh"
00026 #include "G4LogicalVolume.hh"
00027 #include "G4VPhysicalVolume.hh"
00028 #include "G4UserLimits.hh"
00029 #include "G4TransportationManager.hh"
00030 #include "G4HelixMixedStepper.hh"
00031 #include "G4HelixImplicitEuler.hh"
00032 #include "G4SimpleRunge.hh"
00033 #include "G4CashKarpRKF45.hh"
00034
00035 #include <map>
00036
00037
00038
00039
00040 typedef std::map<G4String,int> LogVolCountMap;
00041 extern LogVolCountMap* LogVolCount;
00042
00043 typedef std::map<G4String,G4LogicalVolume*> LogVolMap;
00044 extern LogVolMap* LogVol;
00045
00046 extern G4RotationMatrix* RotY90;
00047
00048
00049 BDSQuadrupole::BDSQuadrupole(G4String aName, G4double aLength,
00050 G4double bpRad, G4double FeRad,
00051 G4double bGrad, G4double tilt, G4double outR,
00052 std::list<G4double> blmLocZ, std::list<G4double> blmLocTheta,
00053 G4String aTunnelMaterial, G4String aMaterial, G4String spec):
00054 BDSMultipole(aName, aLength, bpRad, FeRad, SetVisAttributes(), blmLocZ, blmLocTheta, aTunnelMaterial, aMaterial),
00055 itsBGrad(bGrad),
00056 itsStepper(NULL),itsMagField(NULL),itsEqRhs(NULL)
00057 {
00058 #ifdef DEBUG
00059 G4cout<< __METHOD_NAME__ << "spec=" << spec << G4endl;
00060 #endif
00061
00062 G4String qtype = getParameterValueString(spec, "type");
00063 #ifdef DEBUG
00064 G4cout<< __METHOD_NAME__ << "qtype="<<qtype<<G4endl;
00065 #endif
00066
00067 SetOuterRadius(outR);
00068 itsTilt=tilt;
00069 itsType="quad";
00070
00071 if (!(*LogVolCount)[itsName])
00072 {
00073
00074
00075
00076 #ifdef DEBUG
00077 G4cout<<"Building marker volume "<<G4endl;
00078 #endif
00079 BuildDefaultMarkerLogicalVolume();
00080
00081
00082
00083
00084 if(BDSGlobalConstants::Instance()->GetBuildTunnel()){
00085 BuildTunnel();
00086 }
00087
00088
00089
00090
00091 #ifdef DEBUG
00092 G4cout<<"Building beam pipe field and stepper "<<G4endl;
00093 #endif
00094 BuildBPFieldAndStepper();
00095 #ifdef DEBUG
00096 G4cout<<"Building beam pipe field manager "<<G4endl;
00097 #endif
00098 BuildBPFieldMgr(itsStepper,itsMagField);
00099 #ifdef DEBUG
00100 G4cout<<"Building beam pipe "<<G4endl;
00101 #endif
00102 BuildBeampipe();
00103
00104
00105
00106
00107
00108 if(qtype=="standard")
00109 BuildOuterLogicalVolume();
00110 else if(qtype=="cylinder")
00111 BuildDefaultOuterLogicalVolume(itsLength);
00112
00113 else
00114 BuildDefaultOuterLogicalVolume(itsLength);
00115
00116
00117 if(BDSGlobalConstants::Instance()->GetIncludeIronMagFields())
00118 {
00119 G4double polePos[4];
00120 G4double Bfield[3];
00121
00122
00123 polePos[0]=-BDSGlobalConstants::Instance()->GetMagnetPoleRadius()*sin(pi/4);
00124 polePos[1]=BDSGlobalConstants::Instance()->GetMagnetPoleRadius()*cos(pi/4);
00125 polePos[2]=0.;
00126 polePos[3]=-999.;
00127
00128 itsMagField->GetFieldValue(polePos,Bfield);
00129 G4double BFldIron=
00130 sqrt(Bfield[0]*Bfield[0]+Bfield[1]*Bfield[1])*
00131 BDSGlobalConstants::Instance()->GetMagnetPoleSize()/
00132 (BDSGlobalConstants::Instance()->GetComponentBoxSize()/2-
00133 BDSGlobalConstants::Instance()->GetMagnetPoleRadius());
00134
00135
00136 BFldIron/=2.;
00137
00138 BuildOuterFieldManager(4, BFldIron,pi/4);
00139 }
00140
00141 BuildBLMs();
00142
00143
00144
00145 if(BDSGlobalConstants::Instance()->GetSensitiveBeamPipe()){
00146 G4cout << "BDSQuadrupole.cc:> setting sensitive beam pipe" << G4endl;
00147 SetMultipleSensitiveVolumes(itsBeampipeLogicalVolume);
00148 }
00149 if(BDSGlobalConstants::Instance()->GetSensitiveComponents()){
00150 G4cout << "BDSQuadrupole.cc:> setting sensitive outer volume" << G4endl;
00151 SetMultipleSensitiveVolumes(itsOuterLogicalVolume);
00152 }
00153
00154
00155
00156 itsVisAttributes=SetVisAttributes();
00157 itsVisAttributes->SetForceSolid(true);
00158 itsOuterLogicalVolume->SetVisAttributes(itsVisAttributes);
00159
00160
00161
00162
00163 (*LogVolCount)[itsName]=1;
00164 (*LogVol)[itsName]=itsMarkerLogicalVolume;
00165 }
00166 else
00167 {
00168 (*LogVolCount)[itsName]++;
00169 if(BDSGlobalConstants::Instance()->GetSynchRadOn()&& BDSGlobalConstants::Instance()->GetSynchRescale())
00170 {
00171
00172
00173
00174 itsName+=BDSGlobalConstants::Instance()->StringFromInt((*LogVolCount)[itsName]);
00175
00176
00177
00178
00179 BuildDefaultMarkerLogicalVolume();
00180
00181
00182
00183
00184 BuildBPFieldAndStepper();
00185 BuildBPFieldMgr(itsStepper,itsMagField);
00186 BuildBeampipe();
00187
00188
00189
00190
00191
00192 if(qtype=="standard")
00193 BuildOuterLogicalVolume();
00194 else if(qtype=="cylinder")
00195 BuildDefaultOuterLogicalVolume(itsLength);
00196
00197 else
00198 BuildDefaultOuterLogicalVolume(itsLength);
00199
00200 if(BDSGlobalConstants::Instance()->GetIncludeIronMagFields())
00201 {
00202 G4double polePos[4];
00203 G4double Bfield[3];
00204
00205
00206 polePos[0]=-BDSGlobalConstants::Instance()->GetMagnetPoleRadius()*sin(pi/4);
00207 polePos[1]=BDSGlobalConstants::Instance()->GetMagnetPoleRadius()*cos(pi/4);
00208 polePos[2]=0.;
00209 polePos[3]=-999.;
00210
00211 itsMagField->GetFieldValue(polePos,Bfield);
00212 G4double BFldIron=
00213 sqrt(Bfield[0]*Bfield[0]+Bfield[1]*Bfield[1])*
00214 BDSGlobalConstants::Instance()->GetMagnetPoleSize()/
00215 (BDSGlobalConstants::Instance()->GetComponentBoxSize()/2-
00216 BDSGlobalConstants::Instance()->GetMagnetPoleRadius());
00217
00218
00219 BFldIron/=2.;
00220
00221 BuildOuterFieldManager(4, BFldIron,pi/4);
00222 }
00223
00224
00225
00226
00227
00228 if(BDSGlobalConstants::Instance()->GetSensitiveBeamPipe()){
00229 G4cout << "BDSQuadrupole.cc:> setting sensitive beampipe 2" << G4endl;
00230 SetMultipleSensitiveVolumes(itsBeampipeLogicalVolume);
00231 }
00232 if(BDSGlobalConstants::Instance()->GetSensitiveComponents()){
00233 G4cout << "BDSQuadrupole.cc:> setting sensitive outer volume 2" << G4endl;
00234 SetMultipleSensitiveVolumes(itsOuterLogicalVolume);
00235 }
00236
00237
00238
00239
00240 itsVisAttributes=SetVisAttributes();
00241 itsVisAttributes->SetForceSolid(true);
00242 itsOuterLogicalVolume->SetVisAttributes(itsVisAttributes);
00243
00244
00245
00246
00247 (*LogVol)[itsName]=itsMarkerLogicalVolume;
00248 }
00249 else
00250 {
00251
00252
00253
00254 itsMarkerLogicalVolume=(*LogVol)[itsName];
00255 }
00256 }
00257 }
00258
00259 void BDSQuadrupole::SynchRescale(G4double factor)
00260 {
00261 itsStepper->SetBGrad(factor*itsBGrad);
00262 itsMagField->SetBGrad(factor*itsBGrad);
00263 #ifdef DEBUG
00264 G4cout << "Quad " << itsName << " has been scaled" << G4endl;
00265 #endif
00266 }
00267
00268 G4VisAttributes* BDSQuadrupole::SetVisAttributes()
00269 {
00270 itsVisAttributes=new G4VisAttributes(G4Colour(1,0,0));
00271 return itsVisAttributes;
00272 }
00273
00274 void BDSQuadrupole::BuildBPFieldAndStepper()
00275 {
00276
00277 itsMagField=new BDSQuadMagField(1*itsBGrad);
00278 itsEqRhs=new G4Mag_UsualEqRhs(itsMagField);
00279
00280 itsStepper=new BDSQuadStepper(itsEqRhs);
00281 itsStepper->SetBGrad(itsBGrad);
00282 }
00283
00284 void BDSQuadrupole::BuildOuterLogicalVolume()
00285 {
00286 G4double outerRadius = itsOuterR;
00287 if(itsOuterR==0) outerRadius = BDSGlobalConstants::Instance()->GetComponentBoxSize()/2;
00288
00289 outerRadius = outerRadius/sqrt(2.0);
00290
00291 itsOuterLogicalVolume=
00292 new G4LogicalVolume(new G4Tubs(itsName+"_outer_solid",
00293 itsInnerIronRadius,
00294 outerRadius * sqrt(2.0),
00295 itsLength/2,
00296 0,twopi*radian),
00297 BDSMaterials::Instance()->GetMaterial(BDSGlobalConstants::Instance()->GetVacuumMaterial()),
00298 itsName+"_outer");
00299
00300
00301 G4LogicalVolume* lQuadrant =
00302 new G4LogicalVolume(new G4Tubs(itsName+"_outer_solid",
00303 itsInnerIronRadius,
00304 outerRadius * sqrt(2.0),
00305 itsLength/2,
00306 0,pi/ 2 *radian),
00307 BDSMaterials::Instance()->GetMaterial(BDSGlobalConstants::Instance()->GetVacuumMaterial()),
00308 itsName+"_outer");
00309
00310
00311 G4double poleR = itsBpRadius;
00312 G4double phiStart = -pi / 4;
00313 G4double dPhi = pi / 2;
00314
00315 G4LogicalVolume* lPole =
00316 new G4LogicalVolume(new G4Tubs(itsName+"_pole",
00317 0,
00318 poleR,
00319 itsLength/2,
00320 phiStart,
00321 dPhi),
00322 BDSMaterials::Instance()->GetMaterial("Iron"),
00323 itsName+"pole_outer");
00324
00325 G4RotationMatrix* rotPole = new G4RotationMatrix;
00326
00327 rotPole->rotateZ(3.*pi / 4.);
00328
00329 G4double xPole = (poleR + itsBpRadius) / sqrt(2.0);
00330 G4double yPole = (poleR + itsBpRadius) / sqrt(2.0);
00331
00332
00333 G4VPhysicalVolume* itsPhysiQPole1;
00334 itsPhysiQPole1 = new G4PVPlacement(
00335 rotPole,
00336 G4ThreeVector(xPole,yPole,0),
00337 lPole,
00338 itsName+"_solid",
00339 lQuadrant,
00340 false,
00341 0, BDSGlobalConstants::Instance()->GetCheckOverlaps());
00342
00343
00344
00345 G4VisAttributes* VisAtt =
00346 new G4VisAttributes(G4Colour(1., 0., 0.));
00347 VisAtt->SetForceSolid(true);
00348 lPole->SetVisAttributes(VisAtt);
00349
00350
00351
00352 G4double rYoke = outerRadius - poleR - itsBpRadius + poleR * cos(dPhi / 2);
00353
00354 if(rYoke > 0 )
00355 {
00356
00357
00358 G4double rYoke1 = outerRadius;
00359 G4double rYoke2 = itsBpRadius;
00360
00361 G4LogicalVolume* lYoke1 =
00362 new G4LogicalVolume(new G4Trd(itsName+"_yoke1",
00363 rYoke1 / 2,
00364 rYoke2 / 2,
00365 itsLength/2,
00366 itsLength/2,
00367 rYoke/2),
00368 BDSMaterials::Instance()->GetMaterial("Iron"),
00369 itsName+"yoke_outer1");
00370
00371 G4RotationMatrix* rotYoke = new G4RotationMatrix;
00372
00373 rotYoke->rotateX( - pi / 2.);
00374 rotYoke->rotateY( pi / 4.);
00375
00376 G4double xYoke = (poleR - poleR * cos(dPhi / 2) + itsBpRadius + rYoke/2) / sqrt(2.0);
00377 G4double yYoke = (poleR - poleR * cos(dPhi / 2) + itsBpRadius + rYoke/2) / sqrt(2.0);
00378
00379
00380 G4VPhysicalVolume* itsPhysiQYoke1;
00381 itsPhysiQYoke1 = new G4PVPlacement(
00382 rotYoke,
00383 G4ThreeVector(xYoke,yYoke,0),
00384 lYoke1,
00385 itsName+"_yoke_solid",
00386 lQuadrant,
00387 false,
00388 0, BDSGlobalConstants::Instance()->GetCheckOverlaps());
00389 SetMultiplePhysicalVolumes(itsPhysiQYoke1);
00390
00391
00392 G4VisAttributes* VisAtt1 =
00393 new G4VisAttributes(G4Colour(1., 0., 0.4));
00394 VisAtt1->SetForceSolid(true);
00395 lYoke1->SetVisAttributes(VisAtt1);
00396 }
00397 else
00398 {
00399 G4cerr<<"Not enough place for yoke..."<<G4endl;
00400 }
00401
00402
00403
00404
00405
00406 G4VPhysicalVolume* itsPhysiQuadrant1;
00407 itsPhysiQuadrant1 = new G4PVPlacement(
00408 (G4RotationMatrix*)0,
00409 (G4ThreeVector)0,
00410 lQuadrant,
00411 itsName+"_solid",
00412 itsOuterLogicalVolume,
00413 false,
00414 0, BDSGlobalConstants::Instance()->GetCheckOverlaps());
00415
00416
00417 G4RotationMatrix* rotQ2= new G4RotationMatrix;
00418 rotQ2->rotateZ( pi / 2.);
00419
00420 G4VPhysicalVolume* itsPhysiQuadrant2;
00421 itsPhysiQuadrant2 = new G4PVPlacement(
00422 rotQ2,
00423 (G4ThreeVector)0,
00424 lQuadrant,
00425 itsName+"_solid",
00426 itsOuterLogicalVolume,
00427 false,
00428 0, BDSGlobalConstants::Instance()->GetCheckOverlaps());
00429
00430 G4RotationMatrix* rotQ3= new G4RotationMatrix;
00431 rotQ3->rotateZ( pi );
00432
00433 G4VPhysicalVolume* itsPhysiQuadrant3;
00434 itsPhysiQuadrant3 = new G4PVPlacement(
00435 rotQ3,
00436 (G4ThreeVector)0,
00437 lQuadrant,
00438 itsName+"_solid",
00439 itsOuterLogicalVolume,
00440 false,
00441 0, BDSGlobalConstants::Instance()->GetCheckOverlaps());
00442
00443
00444 G4RotationMatrix* rotQ4= new G4RotationMatrix;
00445 rotQ4->rotateZ( 3. * pi / 2.);
00446
00447 G4VPhysicalVolume* itsPhysiQuadrant4;
00448 itsPhysiQuadrant4 = new G4PVPlacement(
00449 rotQ4,
00450 (G4ThreeVector)0,
00451 lQuadrant,
00452 itsName+"_solid",
00453 itsOuterLogicalVolume,
00454 false,
00455 0, BDSGlobalConstants::Instance()->GetCheckOverlaps());
00456
00457
00458
00459
00460
00461
00462 itsPhysiComp =
00463 new G4PVPlacement(
00464 (G4RotationMatrix*)0,
00465 (G4ThreeVector)0,
00466 itsOuterLogicalVolume,
00467 itsName+"_outer_phys",
00468 itsMarkerLogicalVolume,
00469 false,
00470 0, BDSGlobalConstants::Instance()->GetCheckOverlaps());
00471
00472 SetMultiplePhysicalVolumes(itsPhysiQPole1);
00473 SetMultiplePhysicalVolumes(itsPhysiQuadrant1);
00474 SetMultiplePhysicalVolumes(itsPhysiQuadrant2);
00475 SetMultiplePhysicalVolumes(itsPhysiQuadrant3);
00476 SetMultiplePhysicalVolumes(itsPhysiQuadrant4);
00477 SetMultiplePhysicalVolumes(itsPhysiComp);
00478 #ifndef NOUSERLIMITS
00479 itsOuterUserLimits =
00480 new G4UserLimits("quadrupole cut",itsLength,DBL_MAX,BDSGlobalConstants::Instance()->GetMaxTime(),
00481 BDSGlobalConstants::Instance()->GetThresholdCutCharged());
00482 itsOuterLogicalVolume->SetUserLimits(itsOuterUserLimits);
00483 #endif
00484 }
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702 BDSQuadrupole::~BDSQuadrupole()
00703 {
00704 delete itsVisAttributes;
00705 delete itsMagField;
00706 delete itsEqRhs;
00707 delete itsStepper;
00708 }