frequency=0.0 is accepted and yields a pillbox with a constant Ez = maxGradient (useful to verify units are correct).
Public Member Functions | |
PillboxField (G4String &_name, BLCoordinateTransform &_global2local, BLCMDpillbox *_pillbox, G4VPhysicalVolume *_timingPV) | |
constructor. _zmin/max are global coordinates. | |
G4String | getName () |
getName() returns the name of this placement. | |
void | addFieldValue (const G4double point[4], G4double field[6]) const |
addFieldValue() adds the field for this pillbox into field[]. point[] is in global coordinates. | |
void | UserSteppingAction (const G4Step *step) |
doStep() handles a step of the tune particle. | |
Private Attributes | |
G4String | name |
BLCMDpillbox * | pillbox |
G4VPhysicalVolume * | timingPV |
BLCoordinateTransform | global2local |
G4RotationMatrix * | rotation |
G4double | timeOffset |
G4Track | saveTrack |
G4int | timeCount |
G4bool | validSaveTrack |
G4bool | settingTiming |
BLFieldMap * | fieldMap |
Friends | |
class | BLCMDpillbox |
PillboxField::PillboxField | ( | G4String & | _name, | |
BLCoordinateTransform & | _global2local, | |||
BLCMDpillbox * | _pillbox, | |||
G4VPhysicalVolume * | _timingPV | |||
) |
constructor. _zmin/max are global coordinates.
References BLCMDpillbox::fieldMap, fieldMap, BLCMDpillbox::frequency, BLCoordinateTransform::getGlobal(), BLCoordinateTransform::getRotation(), global2local, BLCMDpillbox::innerLength, BLCMDpillbox::innerRadius, BLCoordinateTransform::isRotated(), name, pillbox, rotation, BLElementField::setGlobalPoint(), settingTiming, timeCount, BLCMDpillbox::timeOffset, timeOffset, timingPV, validSaveTrack, and BLCMDpillbox::wallThick.
00570 : 00571 BLElementField(), BLManager::SteppingAction() 00572 { 00573 name = _name; 00574 pillbox = _pillbox; 00575 timingPV = _timingPV; 00576 global2local = _global2local; 00577 rotation = 0; 00578 timeOffset = pillbox->timeOffset; 00579 timeCount = 0; 00580 validSaveTrack = false; 00581 settingTiming = false; 00582 fieldMap = pillbox->fieldMap; 00583 00584 if(global2local.isRotated()) { 00585 rotation = new G4RotationMatrix(global2local.getRotation()); 00586 rotation->invert(); 00587 } 00588 00589 if(pillbox->frequency == 0.0) { 00590 timeOffset = 0.0; 00591 settingTiming = false; 00592 } 00593 00594 // set global bounding box 00595 G4double local[4], global[4]; 00596 local[3] = 0.0; 00597 G4double dz = pillbox->innerLength/2.0 + pillbox->wallThick; 00598 for(int i=0; i<2; ++i) { 00599 local[0] = (i==0 ? -1.0 : 1.0) * pillbox->innerRadius; 00600 for(int j=0; j<2; ++j) { 00601 local[1] = (j==0 ? -1.0 : 1.0) * pillbox->innerRadius; 00602 for(int k=0; k<2; ++k) { 00603 local[2] = (k==0 ? -1.0 : 1.0) * dz; 00604 global2local.getGlobal(local,global); 00605 setGlobalPoint(global); 00606 } 00607 } 00608 } 00609 }
G4String PillboxField::getName | ( | ) | [inline] |
getName() returns the name of this placement.
References name.
Referenced by UserSteppingAction().
00076 { return name; }
void PillboxField::addFieldValue | ( | const G4double | point[4], | |
G4double | field[6] | |||
) | const [virtual] |
addFieldValue() adds the field for this pillbox into field[]. point[] is in global coordinates.
Implements BLElementField.
References B, E, BLCMDpillbox::E2Bfactor, fieldMap, BLCMDpillbox::frequency, BLFieldMap::getFieldValue(), BLCoordinateTransform::getLocal(), global2local, BLCMDpillbox::innerLength, BLCMDpillbox::innerRadius, BLCMDpillbox::maxGradient, BLCMDpillbox::omega, pillbox, BLCMDpillbox::rFactor, rotation, BLCMDpillbox::skinDepth, timeOffset, and BLCMDpillbox::wallThick.
00612 { 00613 G4double local[4]; 00614 global2local.getLocal(local,point); 00615 00616 if(fieldMap) { 00617 G4double myField[6]; 00618 fieldMap->getFieldValue(local,myField,pillbox->maxGradient, 00619 pillbox->maxGradient); 00620 // frequency == 0.0 means a d.c. electric field 00621 G4double timeE=1.0, timeB=0.0; 00622 if(pillbox->frequency != 0) { 00623 double tArg = pillbox->omega * (point[3] - timeOffset); 00624 timeE = cos(tArg); 00625 timeB = sin(tArg); 00626 } 00627 if(rotation) { 00628 G4ThreeVector B(myField[0],myField[1],myField[2]); 00629 G4ThreeVector E(myField[3],myField[4],myField[5]); 00630 B = *rotation * B; 00631 E = *rotation * E; 00632 field[0] += B[0] * timeB; 00633 field[1] += B[1] * timeB; 00634 field[2] += B[2] * timeB; 00635 field[3] += E[0] * timeE; 00636 field[4] += E[1] * timeE; 00637 field[5] += E[2] * timeE; 00638 } else { 00639 field[0] += myField[0] * timeB; 00640 field[1] += myField[1] * timeB; 00641 field[2] += myField[2] * timeB; 00642 field[3] += myField[3] * timeE; 00643 field[4] += myField[4] * timeE; 00644 field[5] += myField[5] * timeE; 00645 } 00646 return; 00647 } 00648 00649 G4double x = local[0]; 00650 G4double y = local[1]; 00651 G4double z = local[2]; 00652 G4double r = sqrt(x*x + y*y); 00653 G4double dz = pillbox->innerLength/2.0 + pillbox->wallThick; 00654 if(z < -dz || z > dz || r > pillbox->innerRadius) return; 00655 00656 // frequency == 0.0 means a d.c. electric field 00657 if(pillbox->frequency == 0.0) { 00658 // zmin and zmax include the walls, so re-test z position 00659 if(z >= -pillbox->innerLength/2.0 && 00660 z <= pillbox->innerLength/2.0) 00661 field[5] += pillbox->maxGradient; 00662 return; 00663 } 00664 00665 // compute normal RF pillbox field 00666 double arg = pillbox->rFactor*r; 00667 if(fabs(arg) < 1.0e-20) arg = 0.0; 00668 double j0 = gsl_sf_bessel_J0(arg); 00669 double j1 = gsl_sf_bessel_J1(arg); 00670 double tArg = pillbox->omega * (point[3] - timeOffset); 00671 double ez = pillbox->maxGradient * j0 * cos(tArg); 00672 double bphi = -pillbox->maxGradient*pillbox->E2Bfactor*j1*sin(tArg); 00673 // handle skin depth if in wall or window 00674 double f = 1.0; 00675 if(z > pillbox->innerLength/2.0) 00676 f=exp(-(z-pillbox->innerLength/2.0)/pillbox->skinDepth); 00677 else if(z < -pillbox->innerLength/2.0) 00678 f=exp(-(-z-pillbox->innerLength/2.0)/pillbox->skinDepth); 00679 double phi = atan2(point[1],point[0]); 00680 if(rotation) { 00681 G4ThreeVector B(-bphi*sin(phi)*f, bphi*cos(phi)*f, 0.0); 00682 G4ThreeVector E(0.0, 0.0, ez*f); 00683 B = *rotation * B; 00684 E = *rotation * E; 00685 field[0] += B[0]; 00686 field[1] += B[1]; 00687 field[2] += B[2]; 00688 field[3] += E[0]; 00689 field[4] += E[1]; 00690 field[5] += E[2]; 00691 } else { 00692 field[0] += -bphi * sin(phi) * f; 00693 field[1] += bphi * cos(phi) * f; 00694 field[5] += ez * f; 00695 } 00696 }
void PillboxField::UserSteppingAction | ( | const G4Step * | step | ) | [virtual] |
doStep() handles a step of the tune particle.
Implements BLManager::SteppingAction.
References BLCMDpillbox::frequency, getName(), BLManager::getObject(), BLManager::getSteppingManager(), BLCMDpillbox::innerLength, ITERATION_LIMIT, BLCMDpillbox::maxGradient, BLCMDpillbox::omega, BLCMDpillbox::phaseAcc, pillbox, saveTrack, settingTiming, timeCount, BLCMDpillbox::timeIncrement, timeOffset, timingPV, BLCMDpillbox::timingTolerance, and validSaveTrack.
00700 { 00701 // do nothing if d.c. or no field 00702 if(pillbox->frequency <= 0.0 || pillbox->maxGradient == 0.0) return; 00703 00704 G4Track *track = step->GetTrack(); 00705 G4StepPoint *prePoint = step->GetPreStepPoint(); 00706 if(!prePoint) return; 00707 G4VPhysicalVolume *prePV = prePoint->GetPhysicalVolume(); 00708 G4StepPoint *postPoint = step->GetPostStepPoint(); 00709 if(!postPoint) return; 00710 G4VPhysicalVolume *postPV = postPoint->GetPhysicalVolume(); 00711 G4SteppingManager *steppingMgr = 00712 BLManager::getObject()->getSteppingManager(); 00713 00714 if(prePV == postPV) return; // neither entering nor leaving 00715 00716 if(postPV == timingPV) { // entering timingPV 00717 // save track for setting timeOffset (and tuning if this is first) 00718 saveTrack.CopyTrackInfo(*step->GetTrack()); 00719 saveTrack.SetUserInformation(0); 00720 validSaveTrack = true; 00721 // estimate timingOffset by neglecting acceleration 00722 if(!settingTiming) { 00723 settingTiming = true; 00724 double v = saveTrack.GetVelocity(); 00725 double dist = pillbox->innerLength/2.0; 00726 double arrival = saveTrack.GetGlobalTime() + dist/v; 00727 // pi/2 because E is a cos() and we want phaseAcc=0 00728 // to be the rising zero-crossing 00729 timeOffset = arrival - 00730 (pillbox->phaseAcc-pi/2.0)/pillbox->omega; 00731 } 00732 } else if(prePV == timingPV) { // leaving timingPV 00733 if(++timeCount > ITERATION_LIMIT) 00734 G4Exception("pillbox","Iteration Limit",FatalException,""); 00735 // check timing offset 00736 double t = track->GetGlobalTime(); 00737 double phase = pillbox->omega * (t-timeOffset) + pi/2.0; 00738 double dt = (phase-pillbox->phaseAcc)/pillbox->omega; 00739 timeOffset = timeOffset + dt; 00740 if(fabs(dt) <= pillbox->timingTolerance) { 00741 // Success! 00742 printf("pillbox %s: Time OK timeOffset=%.4f ns, incremented to " 00743 "%.4f ns\n",getName().c_str(),timeOffset, 00744 timeOffset+pillbox->timeIncrement); 00745 timeOffset += pillbox->timeIncrement; 00746 settingTiming = false; 00747 return; 00748 } 00749 // restore saved data (i.e. jump back to when the track 00750 // enteered TimingVol) 00751 if(!validSaveTrack) 00752 G4Exception("pillbox","Invalid Step",FatalException,""); 00753 steppingMgr->GetSecondary()->push_back(new G4Track(saveTrack)); 00754 track->SetTrackStatus(fStopAndKill); 00755 } 00756 }
friend class BLCMDpillbox [friend] |
G4String PillboxField::name [private] |
Referenced by getName(), and PillboxField().
BLCMDpillbox* PillboxField::pillbox [private] |
Referenced by addFieldValue(), BLCMDpillbox::construct(), PillboxField(), and UserSteppingAction().
G4VPhysicalVolume* PillboxField::timingPV [private] |
Referenced by BLCMDpillbox::construct(), PillboxField(), and UserSteppingAction().
Referenced by addFieldValue(), BLCMDpillbox::construct(), and PillboxField().
G4RotationMatrix* PillboxField::rotation [private] |
Referenced by addFieldValue(), and PillboxField().
G4double PillboxField::timeOffset [private] |
Referenced by addFieldValue(), PillboxField(), and UserSteppingAction().
G4Track PillboxField::saveTrack [private] |
Referenced by UserSteppingAction().
G4int PillboxField::timeCount [private] |
Referenced by PillboxField(), and UserSteppingAction().
G4bool PillboxField::validSaveTrack [private] |
Referenced by PillboxField(), and UserSteppingAction().
G4bool PillboxField::settingTiming [private] |
Referenced by PillboxField(), and UserSteppingAction().
BLFieldMap* PillboxField::fieldMap [private] |
Referenced by addFieldValue(), and PillboxField().