RFdeviceField Class Reference

Inheritance diagram for RFdeviceField:

BLElementField BLManager::SteppingAction

List of all members.


Detailed Description

RFdeviceField represents one placement of an rfdevice.

frequency=0.0 is accepted and yields an rfdevice with a constant Ez = maxGradient (useful to verify units are correct).

Public Member Functions

 RFdeviceField (G4String &_name, BLCoordinateTransform &_global2local, BLCMDrfdevice *_rfdevice, 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 rfdevice into field[]. point[] is in global coordinates.
void UserSteppingAction (const G4Step *step)
 doStep() handles a step of the timing particle.
void show1step (AutoTimingState state, const char *pre, G4double wrkval, const char *suf)
 show1step() prints handy messages about autoTiming
void reset ()
 reset() resets various internal used by autoTime to initial settings

Private Attributes

G4String name
BLCMDrfdevicerfdevice
G4VPhysicalVolume * timingPV
BLCoordinateTransform global2local
G4RotationMatrix * rotation
G4Track saveTrack
G4int timeCount
G4bool validSaveTrack
BLFieldMapfieldMap
AutoTimingMethod automethod
AutoTimingState stateOfPlacement
G4double maxGradient
G4double timeOffset
G4int redo
char pbname [256]
int timeCount000
G4bool revisited_timingZero
double timingZero
double timingPhase
double timingZeroStep
double timingPhaseStep
double timingGrad
double timingGradStep
AutoTimingChange previous
int cycle
double ampl
double drift
AutoTimingSnapshot entrance
AutoTimingSnapshot exit
AutoTimingSnapshot base
AutoTimingSnapshot estimate

Friends

class BLCMDrfdevice


Constructor & Destructor Documentation

RFdeviceField::RFdeviceField ( G4String &  _name,
BLCoordinateTransform _global2local,
BLCMDrfdevice _rfdevice,
G4VPhysicalVolume *  _timingPV 
)

constructor. _zmin/max are global coordinates.

References ampl, ATWORKING_UNKNOWN, cycle, drift, BLCMDrfdevice::fieldMap, fieldMap, BLCoordinateTransform::getGlobal(), getName(), BLCoordinateTransform::getRotation(), global2local, BLCMDrfdevice::innerLength, BLCMDrfdevice::innerRadius, BLCoordinateTransform::isRotated(), maxGradient, name, pbname, redo, revisited_timingZero, rfdevice, rotation, BLElementField::setGlobalPoint(), stateOfPlacement, timeCount, timeCount000, timeOffset, timingGrad, timingGradStep, timingPhase, timingPhaseStep, timingPV, timingZero, timingZeroStep, BLCommand::undefined(), validSaveTrack, and BLCMDrfdevice::wallThick.

01394                                                       :
01395                         BLElementField(), BLManager::SteppingAction()
01396 {
01397         name = _name;
01398         stateOfPlacement= ATWORKING_UNKNOWN;
01399         maxGradient= BLCommand::undefined();
01400         timeOffset= BLCommand::undefined();
01401         redo= 0;
01402 
01403         rfdevice = _rfdevice;
01404         timingPV = _timingPV;
01405         global2local = _global2local;
01406         rotation = 0;
01407 
01408         //use rfdevicefield #s if available, then rfdevice #s, then safe values
01409 
01410         timeCount = 0;
01411         validSaveTrack = false;
01412         fieldMap = rfdevice->fieldMap;
01413 
01414         if(global2local.isRotated()) {
01415                 rotation = new G4RotationMatrix(global2local.getRotation());
01416                 rotation->invert();
01417         }
01418 
01419         // set global bounding box
01420         G4double local[4], global[4];
01421         local[3] = 0.0;
01422         G4double dz = rfdevice->innerLength/2.0 + rfdevice->wallThick;
01423         for(int i=0; i<2; ++i) {
01424                 local[0] = (i==0 ? -1.0 : 1.0) * rfdevice->innerRadius;
01425                 for(int j=0; j<2; ++j) {
01426                         local[1] = (j==0 ? -1.0 : 1.0) * rfdevice->innerRadius;
01427                         for(int k=0; k<2; ++k) {
01428                                 local[2] = (k==0 ? -1.0 : 1.0) * dz;
01429                                 global2local.getGlobal(local,global);
01430                                 setGlobalPoint(global);
01431                         }
01432                 }
01433         }
01434 
01435         sprintf(pbname,"%s",getName().c_str());
01436         int timeCount000= 0;         
01437         G4bool revisited_timingZero= false;   
01438         double timingZero= 0;           
01439         double timingPhase= 0;           
01440         double timingZeroStep= 0;         
01441         double timingPhaseStep= 0;   
01442         double timingGrad= 0;       
01443         double timingGradStep=0;      
01444         int cycle= 0;              
01445         double ampl= 0;               
01446         double drift= 0;                 
01447 }


Member Function Documentation

G4String RFdeviceField::getName (  )  [inline]

getName() returns the name of this placement.

References name.

Referenced by RFdeviceField(), and UserSteppingAction().

00482 { return name; }

void RFdeviceField::addFieldValue ( const G4double  point[4],
G4double  field[6] 
) const [virtual]

addFieldValue() adds the field for this rfdevice into field[]. point[] is in global coordinates.

Implements BLElementField.

References B, E, BLCMDrfdevice::E2Bfactor, fieldMap, BLCMDrfdevice::frequency, BLFieldMap::getFieldValueNoTimeNoScale(), BLCoordinateTransform::getLocal(), global2local, BLCMDrfdevice::innerLength, BLCMDrfdevice::innerRadius, BLCommand::isUndefined(), BLCMDrfdevice::maxGradient, maxGradient, BLCMDrfdevice::omega, BLCMDrfdevice::rFactor, rfdevice, rotation, BLCMDrfdevice::skinDepth, BLCMDrfdevice::timeOffset, timeOffset, TINY_NONZERO_GRADIENT, and BLCMDrfdevice::wallThick.

01474 {
01475         G4double local[4];
01476         global2local.getLocal(local,point);
01477 
01478         //use locked rfdevicefield values if available, 
01479         //then working rfdevice value, then a safe value
01480 
01481         G4double tOff = !BLCommand::isUndefined(timeOffset)? timeOffset : 
01482           !BLCommand::isUndefined(rfdevice->timeOffset) ? rfdevice->timeOffset : 0;
01483 
01484         G4double Vo = !BLCommand::isUndefined(maxGradient)? maxGradient :
01485           !BLCommand::isUndefined(rfdevice->maxGradient) ? rfdevice->maxGradient : TINY_NONZERO_GRADIENT;
01486 
01487         if(fieldMap) {
01488                 G4double myField[6];
01489 
01490                 //KBB-8mar11: this getFieldValue applies time & gradient!
01491                 //
01492                 //              fieldMap->getFieldValue(local,myField,rfdevice->maxGradient,
01493                 //                              rfdevice->maxGradient);
01494 
01495                 fieldMap->getFieldValueNoTimeNoScale(local,myField);  //KBB-8mar11: w/o time, scale applied
01496 
01497                 // frequency == 0.0 means a d.c. electric field
01498                 G4double timeE=1.0, timeB=0.0;
01499                 if(rfdevice->frequency != 0) {
01500                   double tArg = rfdevice->omega * (point[3] - tOff);
01501                   timeE = cos(tArg);
01502                   timeB = -sin(tArg);  //KBB 6/17/2011
01503                 }
01504 
01505                 timeE *= Vo/(megavolt/meter);
01506                 timeB *= Vo/(megavolt/meter);
01507 
01508                 if(rotation) {
01509                         G4ThreeVector B(myField[0],myField[1],myField[2]);
01510                         G4ThreeVector E(myField[3],myField[4],myField[5]);
01511                         B = *rotation * B;
01512                         E = *rotation * E;
01513                         field[0] += B[0] * timeB;
01514                         field[1] += B[1] * timeB;
01515                         field[2] += B[2] * timeB;
01516                         field[3] += E[0] * timeE;
01517                         field[4] += E[1] * timeE;
01518                         field[5] += E[2] * timeE;
01519                 } else {
01520                         field[0] += myField[0] * timeB;
01521                         field[1] += myField[1] * timeB;
01522                         field[2] += myField[2] * timeB;
01523                         field[3] += myField[3] * timeE;
01524                         field[4] += myField[4] * timeE;
01525                         field[5] += myField[5] * timeE;
01526                 }
01527                 return;
01528         }
01529 
01530         G4double x = local[0];
01531         G4double y = local[1];
01532         G4double z = local[2];
01533         G4double r = sqrt(x*x + y*y);
01534         G4double dz = rfdevice->innerLength/2.0 + rfdevice->wallThick;
01535         if(z < -dz || z > dz || r > rfdevice->innerRadius) return;
01536 
01537         // frequency == 0.0 means a d.c. electric field
01538         if(rfdevice->frequency == 0.0) {
01539                 // zmin and zmax include the walls, so re-test z position
01540                 if(z >= -rfdevice->innerLength/2.0 && 
01541                    z <=  rfdevice->innerLength/2.0) {
01542                         if(rotation) {
01543                                 G4ThreeVector E(0.0, 0.0, Vo);
01544                                 E = *rotation * E;
01545                                 field[3] += E[0];
01546                                 field[4] += E[1];
01547                                 field[5] += E[2];
01548                         } else {
01549                                 field[5] += Vo;
01550                         }
01551                 }
01552                 return;
01553         }
01554 
01555         // compute normal RF rfdevice field
01556         double arg = rfdevice->rFactor*r;
01557         if(fabs(arg) < 1.0e-20) arg = 0.0;
01558         double j0 = gsl_sf_bessel_J0(arg);
01559         double j1 = gsl_sf_bessel_J1(arg);
01560         double tArg = rfdevice->omega * (point[3] - tOff);
01561         double ez = Vo * j0 * cos(tArg);
01562         double bphi = -Vo * rfdevice->E2Bfactor * j1 * sin(tArg);
01563         // handle skin depth if in wall or window
01564         double f = 1.0;
01565         if(z > rfdevice->innerLength/2.0)
01566                 f=exp(-(z-rfdevice->innerLength/2.0)/rfdevice->skinDepth);
01567         else if(z < -rfdevice->innerLength/2.0)
01568                 f=exp(-(-z-rfdevice->innerLength/2.0)/rfdevice->skinDepth);
01569         //@ double phi = atan2(point[1],point[0]);
01570         //@ TJR 3/29/2011 - this surel should be local, not point
01571         double phi = atan2(local[1],local[0]);
01572         if(rotation) {
01573                 G4ThreeVector B(-bphi*sin(phi)*f, bphi*cos(phi)*f, 0.0);
01574                 G4ThreeVector E(0.0, 0.0, ez*f);
01575                 B = *rotation * B;
01576                 E = *rotation * E;
01577                 field[0] += B[0];
01578                 field[1] += B[1];
01579                 field[2] += B[2];
01580                 field[3] += E[0];
01581                 field[4] += E[1];
01582                 field[5] += E[2];
01583         } else {
01584                 field[0] += -bphi * sin(phi) * f;
01585                 field[1] += bphi * cos(phi) * f;
01586                 field[5] += ez * f;
01587         }
01588 }

void RFdeviceField::UserSteppingAction ( const G4Step *  step  )  [virtual]

doStep() handles a step of the timing particle.

Implements BLManager::SteppingAction.

References ampl, BLCMDrfdevice::argChanged(), ATFIX_DE, ATFIX_DT, ATFIX_GRADIENT, ATFIX_OFFSET, ATFIX_OFFSETINCR, ATFIX_P, ATFIX_PHASE, ATFIX_XDEFL, ATFIX_YDEFL, ATWORKING_BASE, ATWORKING_BYPASS, ATWORKING_DONE, ATWORKING_ESTIMATE, ATWORKING_FINAL, ATWORKING_FINETUNE, ATWORKING_INFLUX, ATWORKING_OFFSET, ATWORKING_RESET, ATWORKING_UNKNOWN, AUTOADJUST_GRADIENT, AUTOADJUST_OUTPUT, AUTOADJUST_PHASE, AUTOADJUST_UNKNOWN, AUTOADJUST_UNNEEDED, automethod2text(), automethod2timingphase(), autotiming2method(), AUTOTIMING_ATZ, AUTOTIMING_MAXDXP, AUTOTIMING_MAXDYP, AUTOTIMING_MAXENERGY, AUTOTIMING_MAXTIME, AUTOTIMING_MINDXP, AUTOTIMING_MINDYP, AUTOTIMING_MINENERGY, AUTOTIMING_MINTIME, AUTOTIMING_NODXP, AUTOTIMING_NODYP, AUTOTIMING_NOENERGY, AUTOTIMING_NOMTIME, BLCMDrfdevice::autoTimingFailureLimit, BLCMDrfdevice::autoTimingFixDE, BLCMDrfdevice::autoTimingFixDT, BLCMDrfdevice::autoTimingFixP, BLCMDrfdevice::autoTimingFixXdeflection, BLCMDrfdevice::autoTimingFixYdeflection, autoTimingIn2Out(), BLCMDrfdevice::autoTimingMethod, base, cycle, AutoTimingChange::dE, drift, AutoTimingChange::dT, entrance, ESSENTIALLY_UNCHANGED, estimate, AutoTimingSnapshot::estTransit, exit, fieldMap, BLCMDrfdevice::frequency, BLFieldMap::getFieldValue(), BLGlobalField::GetFieldValue(), getName(), BLGlobalField::getObject(), BLManager::getObject(), BLManager::getSteppingManager(), BLCommand::isUndefined(), ITERATION_LIMIT, lastFound_maxGradient, BLCMDrfdevice::LtimingVolume, AutoTimingSnapshot::m, BLCMDrfdevice::maxGradient, maxGradient, BLCMDrfdevice::omega, pbname, BLCMDrfdevice::phaseAcc, AutoTimingChange::Pout, previous, AutoTimingSnapshot::Ptot, AutoTimingSnapshot::q, redo, reset(), revisited_timingZero, rfdevice, rotation, saveTrack, show1step(), BLCMDrfdevice::state, state2desc(), stateOfPlacement, step2snapshot(), AutoTimingSnapshot::t, timeCount, timeCount000, BLCMDrfdevice::timeIncrement, BLCMDrfdevice::timeOffset, timeOffset, timingGrad, timingGradStep, timingPhase, timingPhaseStep, timingPV, BLCMDrfdevice::timingTolerance, timingZero, timingZeroStep, TrackOfInterest, BLCommand::undefined(), validSaveTrack, BLCMDrfdevice::verbose, BLCMDrfdevice::what2adjust, BLCMDrfdevice::whatFixed, whatFixedOk(), AutoTimingSnapshot::within, AutoTimingSnapshot::x, AutoTimingChange::Xdefl, AutoTimingSnapshot::y, AutoTimingChange::Ydefl, and AutoTimingSnapshot::z.

01707 {
01708   /*
01709     The traditional pillbox autophasing only worked for a 
01710     single cell cavity; here it's
01711     been generallized to any RF structure (via an specified RF map)
01712     and supports determining the timeOffset in a number of ways.
01713 
01714     In general, it won't matter much which method you specify to
01715     determine timeOffset - the AtZ is sets the arrival time for
01716     a local Z location (usually the center z=0), but isn't appropriate
01717     for all cases.  Usually people adjust the phase for maximum 
01718     energy gain and call that "on crest", 90degRF in the G4beamline
01719     notation.
01720     
01721     KBB March-April 2011
01722   */
01723   static int stepcall=0;
01724 
01725   TrackOfInterest= false;
01726 
01727   if(rfdevice->verbose>4)
01728     {
01729       printf("\nRFdeviceField::UserSteppingAction %s call#%d timeCount=%d %d=%s->rfdevice->state=%d=%s ", 
01730              getName().c_str(), stepcall, timeCount, stateOfPlacement, state2desc(stateOfPlacement),
01731              rfdevice->state, state2desc(rfdevice->state));
01732 
01733       printf("whatFixed=%d what2adjust=%d ",rfdevice->whatFixed,rfdevice->what2adjust);
01734 
01735       printf("frequency=%gGHz maxGradient=%gMV/m timeOffset=%gns\n",
01736              rfdevice->frequency*ns, maxGradient/(megavolt/meter), timeOffset/ns);
01737 
01738       fflush(stdout);
01739     }
01740 
01741   /* 
01742      need to find out position w.r.t. rfdevice in case "tune" is in use 
01743      to update TrackOfInterest - otherwise could wait and do this later 
01744   */
01745 
01746   G4Track *track = step->GetTrack();
01747   G4StepPoint *prePoint = step->GetPreStepPoint();
01748   if(!prePoint) return;
01749   G4VPhysicalVolume *prePV = prePoint->GetPhysicalVolume();
01750   G4StepPoint *postPoint = step->GetPostStepPoint();
01751   if(!postPoint) return;
01752   G4VPhysicalVolume *postPV = postPoint->GetPhysicalVolume();
01753   G4SteppingManager *steppingMgr = BLManager::getObject()->getSteppingManager();
01754 
01755   enum WhereROI { ROI_OUTSIDE, ROI_ENTERING, ROI_INSIDE, ROI_EXITING };
01756   WhereROI whereROI;  
01757   
01758   if(prePV == timingPV && postPV == timingPV)
01759     whereROI= ROI_INSIDE;
01760   else if(prePV != timingPV && postPV == timingPV)
01761     whereROI= ROI_ENTERING;
01762   else if(prePV == timingPV && postPV != timingPV)
01763     whereROI= ROI_EXITING;
01764   else
01765     whereROI= ROI_OUTSIDE;
01766 
01767   G4bool Interesting=  prePV==timingPV || postPV==timingPV;
01768 
01769   // DC field specified
01770   if(rfdevice->frequency<=0)  
01771     {
01772       stateOfPlacement= rfdevice->state= ATWORKING_DONE;
01773       timeOffset= rfdevice->timeOffset= 0;
01774       maxGradient= rfdevice->maxGradient;
01775       TrackOfInterest= Interesting;
01776       return;
01777     }
01778  
01779   // zero field specified
01780   if(rfdevice->whatFixed & ATFIX_GRADIENT && rfdevice->maxGradient==0)  
01781     {
01782       stateOfPlacement= rfdevice->state= ATWORKING_DONE;
01783       maxGradient= rfdevice->maxGradient;
01784       timeOffset= rfdevice->timeOffset= 0;
01785       TrackOfInterest= Interesting;
01786       return;
01787     }
01788 
01789   // everything needed specified in advance
01790   if(rfdevice->what2adjust==AUTOADJUST_UNNEEDED)
01791     {
01792       stateOfPlacement= rfdevice->state= ATWORKING_DONE;
01793       maxGradient= rfdevice->maxGradient;
01794       timeOffset= rfdevice->timeOffset;
01795       if(rfdevice->whatFixed & ATFIX_OFFSETINCR)  timeOffset+= rfdevice->timeIncrement;
01796       TrackOfInterest= Interesting;
01797       return;
01798     }
01799 
01800   ++stepcall;
01801   
01802   //"tune" 2nd pass requires a re-autoTiming from beginning
01803   //(can improve efficiency later by comparing to previous entrance snapshot-KBB)
01804   if(whereROI==ROI_ENTERING)  //restart when reentering timingVolume - w/o "tune" only once
01805     {
01806       rfdevice->state= ATWORKING_RESET;
01807     }
01808 
01809   if(stateOfPlacement==ATWORKING_UNKNOWN || 
01810       rfdevice->state==ATWORKING_UNKNOWN || rfdevice->state==ATWORKING_RESET)  //clean start
01811     {
01812       if(stateOfPlacement==ATWORKING_DONE) ++redo;
01813       rfdevice->state= ATWORKING_RESET;  //force to initial state
01814       rfdevice->argChanged();
01815       rfdevice->state= ATWORKING_UNKNOWN;
01816       this->reset();
01817    }
01818 
01819   //no more work to do - rfdevice may be in use elsewhere
01820   if(stateOfPlacement==ATWORKING_DONE && !BLCommand::isUndefined(maxGradient) && !BLCommand::isUndefined(timeOffset)) 
01821     return;
01822 
01823   stateOfPlacement= ATWORKING_INFLUX;
01824 
01825   if(!timingPV)  G4Exception("rfdevice","Missing timing volume",FatalException,"");
01826   
01827   AutoTimingMethod method= autotiming2method(rfdevice->autoTimingMethod);
01828   
01829   if(prePV == postPV) return;     // neither entering nor leaving, do nothing
01830 
01831   if(rfdevice->verbose>2)
01832     {
01833       printf("\nRFdeviceField::UserSteppingAction %s call#%d redo#%d:timeCount=%d ", 
01834              getName().c_str(), stepcall, redo, timeCount);
01835 
01836       printf("stateOfPlacement=%d=%s->rfdevice->state=%d=%s ", 
01837              stateOfPlacement,state2desc(stateOfPlacement),
01838              rfdevice->state,state2desc(rfdevice->state));
01839 
01840       printf("what2adjust=%d ",rfdevice->what2adjust);
01841 
01842       printf("frequency=%gGHz pf.maxGradient=%g p.maxGradient=%gMV/m pf.timeOffset=%g p.timeOffset=%gns\n",
01843              rfdevice->frequency*ns, maxGradient/(megavolt/meter), rfdevice->maxGradient/(megavolt/meter), 
01844              timeOffset/ns, rfdevice->timeOffset/ns);
01845 
01846       fflush(stdout);
01847     }
01848 
01849   //KBB-mar11 complete rethink of adjusting RF 
01850  
01851   const G4bool RevisitTimingAfterGradientAdjust= true;  //once correct gradient found, 
01852                                                         //refind timing zero using that gradient
01853 
01854   const G4bool TurnTransportationThresholdDownward= false;  //Geant4 thresholds of ~100-250MeV usually OK
01855                                                             //but in some rare case where particle is
01856                                                             //supposed to be trapped may be too high -
01857                                                             //does no harm to turn it on, except may prevent
01858                                                             //inhibit detection of trapped particles
01859   G4bool firstVisit=false,AnotherPass=false;
01860   G4int verbose= rfdevice->verbose;
01861   static G4bool negativeParticle=false;                
01862     
01863   AutoTimingChange chng;                  //change over timing volume
01864 
01865   double RFperiod= 1./rfdevice->frequency; //1 RFperiod in native time units
01866   double degRF= RFperiod/360.;            //1 degRF in native time units
01867 
01868   double dt=0,phi=0;
01869 
01870   if(rfdevice->state==ATWORKING_UNKNOWN)  //initialize all static info
01871     {
01872       if(verbose)
01873         {
01874           printf("RFdeviceField::UserSteppingAction - %s - initialize ",pbname);
01875           fflush(stdout);
01876         
01877           printf("whatFixed=0x%X what2adjust=0x%X\n",rfdevice->whatFixed,rfdevice->what2adjust);
01878         }
01879 
01880       if(rfdevice->what2adjust==AUTOADJUST_UNKNOWN)  //abort
01881         G4Exception("RFdeviceField::UserSteppingAction","what2adjust==AUTOADJUST_UNKNOWN",FatalException,"");
01882 
01883       if(!whatFixedOk(pbname, rfdevice->whatFixed))
01884         G4Exception("RFdeviceField::UserSteppingAction","whatFixed not OK",FatalException,"");  //abort
01885 
01886       stepcall= 0;
01887       cycle= 1;
01888       timingZero=0; 
01889       timingPhase= BLCommand::undefined();
01890       timingZeroStep=0; 
01891       chng.dE= chng.Pout= chng.dT= chng.Xdefl= chng.Ydefl= 0;
01892       previous= chng;
01893       entrance.within= exit.within= false;
01894             
01895       firstVisit= true;
01896 
01897       if(rfdevice->state & ATFIX_OFFSET)
01898         {
01899           timingZero= rfdevice->timeOffset;
01900           rfdevice->state= ATWORKING_BYPASS;     //timeOffset known already; satisfy other conditions
01901         }
01902       else
01903         {
01904           rfdevice->state= ATWORKING_OFFSET;     //start working on determining timeOffset
01905           timingZero= rfdevice->timeOffset= 0;   //initial value
01906         }
01907     }
01908   else
01909     {
01910       firstVisit= false;
01911     }
01912   
01913   if(verbose)  // show progress for now
01914     {
01915       const G4ThreeVector& tmp_xyz= postPoint->GetPosition();
01916       G4double xyzt[4];
01917       xyzt[0]= tmp_xyz.getX();
01918       xyzt[1]= tmp_xyz.getY();
01919       xyzt[2]= tmp_xyz.getZ();
01920       xyzt[3]= postPoint->GetGlobalTime();
01921       
01922       const G4ThreeVector& tmp_mom= postPoint->GetMomentum();
01923       G4double Pxyz[3];
01924       Pxyz[0]= tmp_mom.getX();
01925       Pxyz[1]= tmp_mom.getY();
01926       Pxyz[2]= tmp_mom.getZ();
01927       
01928       G4double herefield[6];
01929       BLGlobalField::getObject()->GetFieldValue(xyzt,herefield);
01930       if(this->fieldMap)
01931         this->fieldMap->getFieldValue(xyzt,herefield);
01932       
01933       if(firstVisit)  //only print once 
01934         {
01935           if(verbose>1)
01936             {
01937               printf("kbb:ROI:status(name) #x y z Px Py Pz t - - - - - Bx By Bz Ex Ey Ez count KE step\n");
01938               
01939               printf("kbb:method=%d=%s\n", method, automethod2text(method));
01940 
01941               fflush(stdout);
01942             }
01943         }
01944       
01945       if(verbose>1)
01946         {
01947           printf("kbb:ROI:%s(%s) ", 
01948                  whereROI==ROI_INSIDE ? "inside" : 
01949                  whereROI==ROI_ENTERING ? "entering" :
01950                  whereROI==ROI_EXITING ? "EXITing" : "outside", pbname);
01951           
01952           printf("%g %g %g ",xyzt[0]/mm,xyzt[1]/mm,xyzt[2]/mm);
01953           
01954           printf("%g %g %g ",Pxyz[0]/MeV,Pxyz[1]/MeV,Pxyz[2]/MeV);
01955           
01956           printf("%g 0 0 0 0 0 ",xyzt[3]/ns);
01957           
01958           printf("%g %g %g ",herefield[0]/tesla,herefield[1]/tesla,herefield[2]/tesla);
01959           
01960           printf("%g %g %g ",herefield[3]/(megavolt/meter),
01961                  herefield[4]/(megavolt/meter),herefield[5]/(megavolt/meter));
01962           
01963           int g= stepcall;
01964           printf("timeCount=%d %g stepcall=%d ",timeCount,track->GetKineticEnergy()/MeV,g);
01965           
01966           printf("%d=%s\n",rfdevice->state, state2desc(rfdevice->state));
01967           
01968           fflush(stdout);
01969         }
01970     }
01971   
01972   // Region-Of-Interest //
01973 
01974   switch(whereROI) 
01975     {
01976     case ROI_INSIDE:               //entirely inside - keep going
01977     case ROI_OUTSIDE:              //entirely outside - keep going
01978       return;
01979 
01980     case ROI_ENTERING:             //entering into timing volume - only once/rfdevice
01981       {
01982         G4RotationMatrix *rot= rotation;
01983 
01984         entrance= step2snapshot(step, rfdevice->timeOffset, rfdevice->LtimingVolume, rot, true);
01985         
01986         drift= entrance.estTransit;  //drift time
01987         
01988         timingPhase= automethod2timingphase(method, entrance.q);
01989         
01990         negativeParticle= entrance.q<0; 
01991 
01992         if(verbose>1 && firstVisit) 
01993           {
01994             printf("kbb------ %s ------- %s ",
01995                    pbname, automethod2text(method));
01996             
01997             printf("Gradient=%.3f MV/m",rfdevice->maxGradient/(megavolt/meter));
01998             if(rfdevice->whatFixed&ATFIX_PHASE)
01999               printf(", phaseAcc=%.1f degRF ",rfdevice->phaseAcc/deg);
02000 
02001             printf(", timingPhase=%gdeg ",timingPhase/deg);
02002 
02003             printf("\n");
02004             fflush(stdout);
02005           } 
02006 
02007         //In some rare future case a nearly trapped particle may be part of the plan...
02008         //but not in any of the current concepts.  This is primarially just FYI:
02009         if(firstVisit && TurnTransportationThresholdDownward)
02010           {
02011             // sometimes the track gets stuck after the rfdevice -
02012             // it is unclear why - so tweak Process->Transportation settings
02013 
02014             G4ProcessManager *procMgr = saveTrack.GetDefinition()->GetProcessManager();
02015 
02016             G4ProcessVector *procList= procMgr->GetProcessList();
02017             
02018             for(int i=0; i<procList->size(); ++i) //look through whole list
02019               {
02020                 if(verbose>1)
02021                   printf("kbb::process#%d %s\n", i, (*procList)[i]->GetProcessName().data());
02022                 
02023                 if((*procList)[i]->GetProcessName()=="Transportation")
02024                   {
02025                     G4Transportation *trans= (G4Transportation *) (*procList)[i];
02026                     
02027                     G4double init_trans_ThresholdWarningEnergy= trans->GetThresholdWarningEnergy();
02028                     G4double init_trans_ThresholdImportantEnergy= trans->GetThresholdImportantEnergy();
02029                     G4int init_trans_ThresholdTrials= trans->GetThresholdTrials();
02030                     
02031                     // avoid Tune being killed for getting stuck or looping near boundry
02032                     
02033                     trans->SetThresholdWarningEnergy(0.1*keV);  //typically 100MeV
02034                     trans->SetThresholdImportantEnergy(0.250*keV);       //typically 250MeV
02035                     trans->SetThresholdTrials(3050);            //typically 10
02036                     
02037                     if(verbose>1)
02038                       {
02039                         printf("kbb::trans->ThresholdWarningEnergy=%g=>%gMeV ", 
02040                                init_trans_ThresholdWarningEnergy/MeV,trans->GetThresholdWarningEnergy()/MeV);
02041                         
02042                         printf("ThresholdImportantEnergy=%g=>%gMeV ", 
02043                                init_trans_ThresholdImportantEnergy/MeV,trans->GetThresholdImportantEnergy()/MeV);
02044                         
02045                         printf("GetThresholdTrials=%d=>%d\n", 
02046                                init_trans_ThresholdTrials,trans->GetThresholdTrials());
02047                       }
02048                   }
02049                 
02050                 fflush(stdout);
02051               }
02052           }
02053             
02054         // save track for setting up timeOffset, etc.
02055         // will return to this track later
02056 
02057         saveTrack.CopyTrackInfo(*step->GetTrack());
02058         saveTrack.SetUserInformation(0);
02059         validSaveTrack = true;
02060         
02061         if(verbose>1)  // show progress for now
02062           {
02063             printf("kbb-enter:%d timeOffset=%g\n",timeCount,rfdevice->timeOffset/ns);
02064             fflush(stdout);
02065           } 
02066         
02067         if(firstVisit)
02068           {
02069             if(rfdevice->state==ATWORKING_OFFSET)          // first visit to this rfdevice
02070               {
02071                 timingZero= rfdevice->timeOffset= 0;            // convenient settings
02072                 timingZeroStep= 0*degRF;              // 0 degRF
02073               }
02074             else
02075               {
02076                 timingZero= rfdevice->timeOffset;
02077               }
02078             
02079             if(rfdevice->what2adjust==AUTOADJUST_GRADIENT)  //estimate a reasonable starting value
02080               {
02081                 double DISCARD=ESSENTIALLY_UNCHANGED;
02082                 double q= entrance.q;
02083                 double c= c_light;
02084                 double L= rfdevice->LtimingVolume;
02085                 double to= entrance.estTransit;
02086                 double m= entrance.m;
02087                 double Po= entrance.Ptot;
02088                 double Eo= sqrt(Po*Po+m*m);
02089                 double w= !BLCommand::isUndefined(rfdevice->phaseAcc)? rfdevice->phaseAcc : pi/2;
02090                 double dt= rfdevice->whatFixed & ATFIX_DT ? rfdevice->autoTimingFixDT - to : 0;
02091                 double dE= rfdevice->whatFixed & ATFIX_DE ? rfdevice->autoTimingFixDE : 0;
02092                 double Pf= rfdevice->whatFixed & ATFIX_P ? rfdevice->autoTimingFixP : Po;
02093                 double xdf= rfdevice->whatFixed & ATFIX_XDEFL ? rfdevice->autoTimingFixXdeflection : 0;
02094                 double ydf= rfdevice->whatFixed & ATFIX_YDEFL ? rfdevice->autoTimingFixYdeflection : 0;
02095                 
02096                 //avoid divide-by-zero issues; let it work on crest
02097                 double sin_w= fabs(sin(w)) > DISCARD ? sin(w) : 1;
02098                 double aw= fabs(ampl*sin(w)) > DISCARD ? ampl*sin(w) : 1;
02099                 
02100                 if(rfdevice->whatFixed & ATFIX_P)  //estimate dE from fixP & Po
02101                   {
02102                     dE= sqrt(Pf*Pf+m*m) - Eo;
02103                   }
02104                 
02105                 //simplest possible model as a starting point
02106                 
02107                 if(rfdevice->whatFixed & (ATFIX_P | ATFIX_DE)) 
02108                   {
02109                     double wavelength= 2*pi*c_light/rfdevice->omega;
02110 
02111                     if(2*L<wavelength)
02112                       timingGrad= dE*pi/(q*wavelength*sin(pi*L/wavelength)*sin_w);  //single cell?
02113                     else
02114                       timingGrad= dE*pi/(q*2*L*sin_w);      //multicell?
02115                   }
02116                 else if(rfdevice->whatFixed & ATFIX_DT)        //total transit time
02117                   { 
02118                     timingGrad= (m/sqrt(1-1/pow(c*dt/L+Eo/Po,2.))-Eo)/(q*L*sin_w);
02119                   }
02120                 else if(rfdevice->whatFixed & ATFIX_XDEFL)     //deflection angle in radians
02121                   {
02122                     timingGrad= (xdf/radian)*(Po/MeV)/q/(to/ns) * 
02123                       0.3*megavolt/meter/sin_w;
02124                   }
02125                 else if(rfdevice->whatFixed & ATFIX_YDEFL)
02126                   {
02127                     timingGrad= (ydf/radian)*(Po/MeV)/q/(to/ns) *
02128                       0.3*megavolt/meter/sin_w;
02129                   }
02130                 else if(lastFound_maxGradient!=0)
02131                   {
02132                     timingGrad= lastFound_maxGradient;
02133                   }
02134                 else
02135                   {
02136                     timingGrad= 1*megavolt/meter;     //no idea - ought to never happen
02137                   }
02138                 
02139                 rfdevice->maxGradient= timingGrad;
02140                 
02141                 if(verbose>1)
02142                   {
02143                     printf("kbb:ROI:(%s) guess at working Gradient=%.3f MV/m\n", 
02144                            pbname, rfdevice->maxGradient/(megavolt/meter));
02145                   }
02146               }
02147           }         
02148 
02149         return;                    //keep going on toward exit
02150       }
02151         
02152     case ROI_EXITING:
02153       break;                       //stop & process
02154     }
02155   
02156   // ROI_EXITING
02157 
02158   ++timeCount;
02159 
02160   exit= step2snapshot(step, rfdevice->timeOffset, rfdevice->LtimingVolume, rotation, true);
02161   chng= autoTimingIn2Out(entrance, exit);
02162   
02163   if(timeCount > ITERATION_LIMIT)
02164     G4Exception("rfdevice","Iteration Limit",FatalException,"");  //abort
02165   
02166   AnotherPass= true;
02167   
02168   switch(rfdevice->state)
02169     {
02170     case ATWORKING_OFFSET:
02171       {
02172         //determine basic timeOffset; RF ~ sin(w*(t-timeOffset))
02173         
02174         if(exit.within!=true)
02175           G4Exception("rfdevice","Exit w/o Enter",FatalException,"");  //abort
02176         
02177         /*********************************************************************************
02178                KBB: Assume that dE, dT, Xdeflection, Ydeflection approximately follow a sine-like curve - 
02179                from 2 points 90 degrees apart in phase, estimate time offset for a maximum
02180                f(wto)= K sin(w(t-to)+phi) = K sin(phi)
02181                f(wto+RFperiod/4)= K sin(w(t-to)+phi+TT/2)=  K cos(w(t-to)+phi)= K cos(phi)
02182                f(wto)/f(wto+RFperiod/4) = tan(phi) 
02183                f(t=to) => sin(w(t-to)+phi)= 0 -> w(t-to)-phi=0 -> t-to=phi/w
02184         *********************************************************************************/
02185         
02186         if(timeCount<=1 || timeCount000+1==timeCount)  /*KBB always get 1st of 2 points to start */
02187           {
02188             //timeOffset and timingZero were 0 
02189             
02190             show1step(rfdevice->state,"(1of3)timingzero=",timingZero/ns,"ns");
02191             
02192             rfdevice->timeOffset= timingZero + pi/2/rfdevice->omega;  // was 0 -> now shift +90degRF
02193             
02194             if(verbose>1)
02195               printf("kbb.1: was timeZero=timeOffset=0 => 90degRF\n");
02196 
02197             rfdevice->state= ATWORKING_OFFSET; 
02198           }
02199         else if(timeCount==2 || timeCount000+2==timeCount) /*KBB always from 2nd point, estimate overall phase */
02200           {
02201             show1step(rfdevice->state,"(2of3)timingzero=",timingZero/ns,"ns");
02202             
02203             //timeOffset was 90degRF from first
02204             
02205             if(method==AUTOTIMING_ATZ)      //KBB: based on TJR's original method of arrival time
02206               {                               //at a local Z (timingVolume exit); usually middle of cell
02207                                               // time of arrival   
02208                 double t = track->GetGlobalTime();                  //time now (usually at the center)
02209                                 
02210                 double dt= t - timingZero - timingPhase/rfdevice->omega; 
02211                 
02212                 while(dt>+RFperiod/2)  dt-= RFperiod;
02213 
02214                 while(dt<-RFperiod/2)  dt+= RFperiod;
02215 
02216                 timingZero+= dt;
02217                 
02218                 phi= atan2(previous.dE, chng.dE);      //kinetic energy change (for subsequent adjustments)
02219 
02220                 if(verbose>1)
02221                   printf("kbb.2: dt=%gns timingZero->%gns\n",dt/ns,timingZero/ns);
02222               }
02223             else if(method==AUTOTIMING_MAXENERGY || method==AUTOTIMING_NOENERGY || method==AUTOTIMING_MINENERGY)
02224               {
02225                 phi= atan2(previous.dE, chng.dE);      //kinetic energy change  
02226                 ampl= sqrt(previous.dE*previous.dE + chng.dE*chng.dE);
02227               }
02228             else if(method==AUTOTIMING_MINTIME || method==AUTOTIMING_NOMTIME || method==AUTOTIMING_MAXTIME)
02229               {
02230                 phi= atan2(previous.dT-drift, chng.dT-drift);        //(transit.time-drift) change
02231                 ampl= sqrt((previous.dT-drift)*(previous.dT-drift) + (chng.dT-drift)*(chng.dT-drift));
02232               }
02233             else if(method==AUTOTIMING_MAXDXP || method==AUTOTIMING_NODXP || method==AUTOTIMING_MINDXP)
02234               {
02235                 phi= atan2(previous.Xdefl, chng.Xdefl);        //X deflection
02236                 ampl= sqrt(previous.Xdefl*previous.Xdefl + chng.Xdefl*chng.Xdefl);
02237               }
02238             else if(method==AUTOTIMING_MAXDYP || method==AUTOTIMING_NODYP || method==AUTOTIMING_MINDYP)
02239               {
02240                 phi= atan2(previous.Ydefl, chng.Ydefl);        //Y deflection
02241                 ampl= sqrt(previous.Ydefl*previous.Ydefl + chng.Ydefl*chng.Ydefl);
02242               }
02243             else
02244               {
02245                 phi= BLCommand::undefined();  //unknown method
02246                 ampl= BLCommand::undefined();
02247               }
02248 
02249             if(rfdevice->whatFixed & (ATFIX_DE | ATFIX_P) || method==AUTOTIMING_ATZ)
02250               {
02251                 ampl= sqrt(previous.dE*previous.dE + chng.dE*chng.dE);
02252               }
02253             else if(rfdevice->whatFixed & ATFIX_DT )
02254               {
02255                 ampl= sqrt((previous.dT-drift)*(previous.dT-drift) + (chng.dT-drift)*(chng.dT-drift));
02256               }
02257             else if(rfdevice->whatFixed & ATFIX_XDEFL)
02258               {
02259                 ampl= sqrt(previous.Xdefl*previous.Xdefl + chng.Xdefl*chng.Xdefl);
02260               }
02261             else if(rfdevice->whatFixed & ATFIX_YDEFL)
02262               {
02263                 ampl= sqrt(previous.Ydefl*previous.Ydefl + chng.Ydefl*chng.Ydefl);
02264               }
02265             
02266             if(verbose>1)
02267               {
02268                 printf("kbb.2: pass1-2 amplitude=");
02269                 !BLCommand::isUndefined(ampl) ? printf("%g",ampl) : printf("undefined()");
02270                 printf(" delta-phi-zero=");
02271                 !BLCommand::isUndefined(phi) ? printf("%gdegRF",phi/deg) : printf("undefined()");
02272                 printf(" timingZero=%gns rfdevice->timeOffset=%gns",timingZero/ns,rfdevice->timeOffset/ns);
02273                 printf("\n");
02274               }
02275 
02276             if(method!=AUTOTIMING_ATZ && !BLCommand::isUndefined(phi))  //phi of the sine-like signal, not necc. overall phase
02277               {
02278                 //redefine timingZero to new value
02279                 timingZero= phi/rfdevice->omega;   //zero crossing time w.r.t. previous 1st pass timeOffset=0
02280 
02281                 if(negativeParticle)
02282                   timingZero+= pi/rfdevice->omega;  //negative particle shifted by 180deg
02283 
02284                 rfdevice->timeOffset= timingZero - timingPhase/rfdevice->omega;
02285 
02286                 if(verbose>1)
02287                   {
02288                     printf("kbb.2a: pass1-2 amplitude=");
02289                     !BLCommand::isUndefined(ampl) ? printf("%g",ampl) : printf("undefined()");
02290                     printf(" delta-phi-zero=");
02291                     !BLCommand::isUndefined(phi) ? printf("%gdegRF",phi/deg) : printf("undefined()");
02292                     printf(" timingZero=%gns rfdevice->timeOffset=%gns",timingZero/ns,rfdevice->timeOffset/ns);
02293                     printf("\n");
02294                   }
02295               }
02296 
02297             rfdevice->state= ATWORKING_OFFSET; 
02298           }
02299         else    //all other passes...
02300           {
02301             if(method==AUTOTIMING_ATZ)      //KBB: based on TJR's original method of arrival time
02302               {                               //at a local Z (timingVolume exit); usually middle of cell
02303                                               // time of arrival   
02304                 double t = track->GetGlobalTime();                  //time now (usually at the center)
02305                 
02306                 show1step(rfdevice->state,"timingzero=",timingZero/ns,"ns");
02307                 
02308                 double dt= t - (timingZero - timingPhase/rfdevice->omega); 
02309                 
02310                 while(dt>+RFperiod/2)  dt-= RFperiod;
02311 
02312                 while(dt<-RFperiod/2)  dt+= RFperiod;
02313 
02314                 timingZero+= dt;
02315                 
02316                 AnotherPass= fabs(dt) > rfdevice->timingTolerance;              
02317                 
02318                 if(verbose>1)
02319                   printf("kbb.%d: dt=%gns timingZero->%gns Another=%s\n",
02320                          timeCount,dt/ns,timingZero/ns,AnotherPass?"Y":"N");
02321 
02322               }
02323             else if(timeCount==3 || timeCount000+3==timeCount) //ought to have timingZero to be pretty close
02324               {
02325                 //ought to be parked on right point
02326                 
02327                 timingZeroStep= 10*degRF;     //overshoot a bit
02328                 timingZero-= timingZeroStep;  //displace so begin working back toward estimated point
02329                 
02330                 show1step(rfdevice->state,"(3of3)timingZero=",timingZero/ns,"ns");
02331                   
02332                 rfdevice->timeOffset= timingZero - timingPhase/rfdevice->omega;
02333                   
02334                 if(verbose>1)
02335                   printf("kbb.3 timingZeroStep=%gdegRF timingZero=%gns\n",
02336                          timingZeroStep/degRF,timingZero/ns);
02337 
02338                 AnotherPass= true;
02339               }
02340             else   //KBB - simple search about the method
02341               {
02342                 G4bool same=true;  //try#3,4 ought to be close
02343 
02344                 switch(method)
02345                   {
02346                   case AUTOTIMING_MAXENERGY:
02347                     same= chng.dE > previous.dE;
02348                     break;
02349                   case AUTOTIMING_NOENERGY:
02350                     same= fabs(chng.dE) < fabs(previous.dE);
02351                     break;
02352                   case AUTOTIMING_MINENERGY:
02353                     same= chng.dE < previous.dE;
02354                     break;
02355                   case AUTOTIMING_MAXTIME:
02356                     same= chng.dT > previous.dT;
02357                     break;
02358                   case AUTOTIMING_NOMTIME:
02359                     same= fabs(chng.dT) < fabs(previous.dT);
02360                     break;
02361                   case AUTOTIMING_MINTIME:
02362                     same= chng.dT < previous.dT;
02363                     break;
02364                   case AUTOTIMING_NODXP:
02365                     same= fabs(chng.Xdefl) < fabs(previous.Xdefl);
02366                     break;
02367                   case AUTOTIMING_MAXDXP:
02368                     same= chng.Xdefl > previous.Xdefl;
02369                     break;
02370                   case AUTOTIMING_MINDXP:
02371                     same= chng.Xdefl < previous.Xdefl;
02372                     break;
02373                   case AUTOTIMING_NODYP:
02374                     same= fabs(chng.Ydefl) < fabs(previous.Ydefl);
02375                     break;
02376                   case AUTOTIMING_MAXDYP:
02377                     same= chng.Ydefl > previous.Ydefl;
02378                     break;
02379                   case AUTOTIMING_MINDYP:
02380                     same= chng.Ydefl < previous.Ydefl;
02381                     break;
02382                   default:
02383                     break;
02384                   }
02385                 
02386                 show1step(rfdevice->state,"timingzero=",timingZero/ns,"ns");
02387 
02388                 AnotherPass= fabs(timingZeroStep) > rfdevice->timingTolerance;          
02389                 
02390                 if(AnotherPass)
02391                   {
02392                     if(!same)  timingZeroStep/= -1.5;     //backup and reverse direction, 2/3 step size
02393                     timingZero+= timingZeroStep;
02394                   }
02395 
02396                 if(verbose>1)
02397                   printf("kbb.%d timingZeroStep=%gns Another=%s negativeParticle=%s\n",
02398                          timeCount,timingZeroStep/ns,AnotherPass?"y":"n",
02399                          negativeParticle?"Y":"N");
02400               }
02401 
02402             if(AnotherPass)
02403               {
02404                 rfdevice->timeOffset= timingZero - timingPhase/rfdevice->omega;  //adjustment point
02405                 rfdevice->state= ATWORKING_OFFSET; //continue on
02406               }
02407             else
02408               {
02409                 /* 
02410                    the definition of 0degRF is the zero crossing on the rising slope,
02411                    independent of the sign of the particle 
02412                 */
02413 
02414                 //bracket -RFperiod/2<timingZero<+RFperiod/2
02415                 while(timingZero>RFperiod/2) timingZero-= RFperiod;
02416                 while(timingZero<-RFperiod/2) timingZero+= RFperiod;
02417 
02418                 rfdevice->timeOffset= timingZero; 
02419 
02420                 rfdevice->state= ATWORKING_BASE;  //set next pass at 0degRF
02421               }
02422           }
02423 
02424         break;
02425       }
02426 
02427     case ATWORKING_BYPASS:   //base timeOffset set explicitly
02428       {
02429         show1step(rfdevice->state,"timingzero=",timingZero/ns,"ns");
02430 
02431         timingZero= rfdevice->timeOffset;  //time explicitly fixed
02432         timingPhase= 0;
02433 
02434         if(rfdevice->what2adjust==AUTOADJUST_GRADIENT)
02435           {
02436             rfdevice->state= ATWORKING_BASE;
02437           }
02438         else  //nothing left to adjust
02439           {
02440             rfdevice->state= ATWORKING_FINAL;
02441 
02442             if(rfdevice->whatFixed & ATFIX_OFFSETINCR)  
02443               rfdevice->timeOffset= rfdevice->timeOffset+= rfdevice->timeIncrement;
02444           }
02445 
02446         break;
02447       }
02448 
02449     case ATWORKING_BASE:  //ought to be final 0degRF baseline
02450       {
02451         /* 
02452            Because 0degRF is DEFINED to be when voltage is at zero crosing and
02453            rising with a postive slope, for both positive and negative reference
02454            particles, the BASE ought to show a zero crossing with a rising slope. KBB
02455         */
02456 
02457         show1step(rfdevice->state,"timingZero=",timingZero/ns,"ns");
02458 
02459         base= step2snapshot(step, rfdevice->timeOffset, rfdevice->LtimingVolume, rotation, true);
02460         
02461         AutoTimingChange diba= autoTimingIn2Out(entrance, base);
02462         
02463         //set approximate value to satisfy conditions
02464         
02465         switch(rfdevice->what2adjust)
02466           {
02467           case AUTOADJUST_OUTPUT:   //fixed gradient and phase
02468             {
02469               timingPhase= rfdevice->phaseAcc;
02470               rfdevice->timeOffset= timingZero - rfdevice->phaseAcc/rfdevice->omega;
02471 
02472               if(verbose>1)
02473                 printf("kbb.%d BASE - adjust output phaseAcc=%gdegRF\n",timeCount,rfdevice->phaseAcc/deg);
02474 
02475               rfdevice->state= ATWORKING_FINAL;  //done adjusting
02476 
02477               if(rfdevice->whatFixed & ATFIX_OFFSETINCR)  
02478                 rfdevice->timeOffset+= rfdevice->timeIncrement;
02479 
02480               break;
02481             }
02482             
02483           case AUTOADJUST_PHASE:    //fixed gradient and output
02484             {
02485               double signal=0;
02486               
02487               if(BLCommand::isUndefined(ampl))
02488                 {
02489                   signal= 0;  //just start from base
02490                 }
02491               else if(rfdevice->whatFixed & ATFIX_P)  //estimate P swing from dE swing
02492                 {
02493                   double Eo= sqrt(base.Ptot*base.Ptot+entrance.m*entrance.m);
02494                   ampl= sqrt((Eo+ampl)*(Eo+ampl)-entrance.m*entrance.m) - base.Ptot;
02495                   signal= (rfdevice->autoTimingFixP - base.Ptot)/ampl;
02496                 }
02497               else if(rfdevice->whatFixed & ATFIX_DE)  //base.DE ~ 0
02498                 {
02499                   signal= (rfdevice->autoTimingFixDE - diba.dE)/ampl;
02500                 }
02501               else if(rfdevice->whatFixed & ATFIX_DT)  //total transit times
02502                 {
02503                   signal= (rfdevice->autoTimingFixDT - diba.dT)/ampl;
02504                 }
02505               else if(rfdevice->whatFixed & ATFIX_XDEFL)  //base.Xdefl ~ 0
02506                 {
02507                   signal= (rfdevice->autoTimingFixXdeflection - diba.Xdefl)/ampl;
02508                 }
02509               else if(rfdevice->whatFixed & ATFIX_YDEFL)  //base.Ydefl ~ 0
02510                 {
02511                   signal= (rfdevice->autoTimingFixYdeflection - diba.Ydefl)/ampl;
02512                 }
02513               
02514               if(signal>1.)
02515                 signal= 1.;
02516               else if(signal<-1.)
02517                 signal= -1.;
02518 
02519               timingPhase= asin(signal);
02520 
02521               if(negativeParticle)  timingPhase+= pi;
02522 
02523               if(verbose>1)
02524                 printf("kbb.%d BASE - ampl=%g signal=%g timingPhase=%gdegRF\n",
02525                        timeCount,ampl,signal,timingPhase/deg);
02526               
02527               rfdevice->timeOffset= timingZero - timingPhase/rfdevice->omega;
02528               
02529               rfdevice->state= ATWORKING_ESTIMATE;  //best guess at phase
02530               break;
02531             }
02532             
02533           case AUTOADJUST_GRADIENT:    //fixed phase and output
02534             {
02535               //currently at phase 0, so no energy gain... reuse estimate
02536 
02537               timingPhase= rfdevice->phaseAcc;
02538 
02539               if(rfdevice->whatFixed & ATFIX_PHASE)
02540                 {
02541                   rfdevice->timeOffset= timingZero - rfdevice->phaseAcc/rfdevice->omega;  //fixed phase & timing
02542                   timingPhase= rfdevice->phaseAcc;
02543                 }
02544               else if(rfdevice->whatFixed & ATFIX_OFFSET)
02545                 {
02546                   timingZero= rfdevice->timeOffset;
02547                   timingPhase= 0;
02548                 }
02549               else   //ought to have phaseAcc or timeOffset set
02550                 {
02551                   rfdevice->timeOffset= timingZero;
02552                   timingPhase= 0;
02553                 }
02554 
02555               timingGrad= rfdevice->maxGradient;
02556               rfdevice->state= ATWORKING_ESTIMATE;  //best guess at gradient
02557 
02558               if(verbose>1)
02559                 {
02560                   printf("kbb:ROI:(%s) estimated maxGradient=%.6f MV/m\n", 
02561                          pbname, rfdevice->maxGradient/(megavolt/meter));
02562                 }
02563 
02564               break;
02565             }
02566 
02567           case AUTOADJUST_UNKNOWN:
02568           case AUTOADJUST_UNNEEDED:
02569             break;
02570           }
02571         
02572         break;
02573       }
02574       
02575     case ATWORKING_ESTIMATE:     //extrapolated
02576       {
02577         estimate= step2snapshot(step, rfdevice->timeOffset, rfdevice->LtimingVolume, rotation, true);
02578         
02579         AutoTimingChange dies= autoTimingIn2Out(entrance, estimate);
02580         
02581         switch(rfdevice->what2adjust)
02582           {
02583           case AUTOADJUST_PHASE:    //fixed gradient and output
02584             {
02585               show1step(rfdevice->state,"timingZero=",timingZero/ns,"ns");
02586               timingPhaseStep= 5*deg;         //back off a little
02587               timingPhase-= timingPhaseStep;  //displace so begin working back toward estimated point   
02588               rfdevice->timeOffset= timingZero - timingPhase/rfdevice->omega;
02589               rfdevice->state= ATWORKING_FINETUNE;
02590               rfdevice->phaseAcc= timingPhase; //FYI only - determined by timeOffset
02591 
02592               if(verbose>1)
02593                 {
02594                   printf("kbb.%d estimate (shift 10deg) timingPhaseStep=%gdegRF timingPhase=%gdegRF\n", 
02595                          timeCount, timingPhaseStep/deg, timingPhase/deg);
02596                 }
02597 
02598               break;
02599             }
02600             
02601           case AUTOADJUST_GRADIENT:    //fixed phase and output
02602             {
02603               show1step(rfdevice->state,"timingGrad=",timingGrad/(megavolt/meter),"MV/m");
02604               timingGradStep= timingGrad/3;  
02605               timingGrad-= timingGradStep;  //displace so begin working back toward estimated point
02606               rfdevice->maxGradient= timingGrad;
02607               rfdevice->state= ATWORKING_FINETUNE;
02608 
02609               if(verbose>1)
02610                 {
02611                   printf("kbb.%d estimate (shift 1/3) timingGradStep=%gMV/m timingGrad=%gMV/m\n",
02612                          timeCount, timingGradStep/(megavolt/meter), timingGrad/(megavolt/meter));
02613                 }
02614 
02615               break;
02616             }
02617 
02618           case AUTOADJUST_UNKNOWN:  //ought to have been handled already
02619           case AUTOADJUST_UNNEEDED:
02620           case AUTOADJUST_OUTPUT:   //ought to have been handled already
02621             {
02622               show1step(rfdevice->state,"timeOffset=",rfdevice->timeOffset/ns,"ns");
02623 
02624               rfdevice->state= ATWORKING_FINAL;  //done adjusting
02625 
02626               if(rfdevice->whatFixed & ATFIX_OFFSETINCR)  
02627                 rfdevice->timeOffset+= rfdevice->timeIncrement;
02628 
02629               if(verbose>1)
02630                 {
02631                   printf("kbb.%d estimate? what2adjust=0x%X\n", timeCount, rfdevice->what2adjust);
02632                 }
02633 
02634               break;
02635             }         
02636           }
02637 
02638         break;
02639       }
02640       
02641     case ATWORKING_FINETUNE:  //fine tune
02642       {
02643         //offset has been determined; working on adjustments from there
02644         //start parked at predicted phase
02645         
02646         G4double doup=0,dout=0;  //diffence between previous,current goal and result
02647         
02648         if(rfdevice->whatFixed & ATFIX_P)
02649           {
02650             dout= chng.Pout - rfdevice->autoTimingFixP;
02651             doup= previous.Pout - rfdevice->autoTimingFixP;
02652             show1step(rfdevice->state,"Pout=",chng.Pout/MeV,"MeV/c");
02653           }
02654         else if(rfdevice->whatFixed & ATFIX_DE)
02655           {
02656             dout= chng.dE - rfdevice->autoTimingFixDE;
02657             doup= previous.dE - rfdevice->autoTimingFixDE;
02658             show1step(rfdevice->state,"dE=",chng.dE/MeV,"MeV");
02659           }
02660         else if(rfdevice->whatFixed & ATFIX_DT)
02661           {
02662             dout= chng.dT - rfdevice->autoTimingFixDT;
02663             doup= previous.dT - rfdevice->autoTimingFixDT;
02664             show1step(rfdevice->state,"dT=",chng.dT/ns,"ns");
02665           }
02666         else if(rfdevice->whatFixed & ATFIX_XDEFL)
02667           {
02668             dout= chng.Xdefl - rfdevice->autoTimingFixXdeflection;
02669             doup= previous.Xdefl - rfdevice->autoTimingFixXdeflection;
02670             show1step(rfdevice->state,"dX=",chng.Xdefl/deg,"deg");
02671           }
02672         else if(rfdevice->whatFixed & ATFIX_YDEFL)
02673           {
02674             dout= chng.Ydefl - rfdevice->autoTimingFixYdeflection;
02675             doup= previous.Ydefl - rfdevice->autoTimingFixYdeflection;
02676             show1step(rfdevice->state,"dY=",chng.Ydefl/deg,"deg");
02677           }
02678         else
02679           {
02680             show1step(rfdevice->state,"dE=",chng.dE/MeV,"MeV");
02681           }
02682 
02683         G4double same= fabs(dout) < fabs(doup);    //KBB - simple search 
02684         
02685         switch(rfdevice->what2adjust)
02686           {
02687           case AUTOADJUST_PHASE:    //fix gradient & output
02688             {
02689               AnotherPass= fabs(timingPhaseStep/rfdevice->omega) > rfdevice->timingTolerance ||
02690                 fabs(dout) > rfdevice->autoTimingFailureLimit;
02691               
02692               if(AnotherPass)
02693                 {
02694                   if(!same)  timingPhaseStep/= -1.5;  //backup and reverse direction, reduce step size
02695                   timingPhase+= timingPhaseStep;
02696                   rfdevice->timeOffset= timingZero - timingPhase/rfdevice->omega;
02697 
02698                   if(verbose>1)
02699                     {
02700                       printf("kbb.%d FINETUNE timingPhaseStep=%gdeg timingPhase=%.9fdeg Another=Y\n", 
02701                              timeCount, timingPhaseStep/deg, timingPhase/deg);
02702                     }
02703                 }
02704               else
02705                 {
02706                   if(verbose>1)
02707                     {
02708                       printf("kbb.%d FINETUNE timingPhase=%.9fdeg Another=N\n", 
02709                              timeCount,timingPhase/deg);
02710                     }
02711 
02712                   rfdevice->state= ATWORKING_FINAL;  //done adjusting
02713 
02714                   if(rfdevice->whatFixed & ATFIX_OFFSETINCR)  
02715                     rfdevice->timeOffset= rfdevice->timeOffset+= rfdevice->timeIncrement;
02716                 }
02717               
02718               break;
02719             }
02720             
02721           case AUTOADJUST_GRADIENT:
02722             {
02723               AnotherPass= fabs(dout) > rfdevice->autoTimingFailureLimit;
02724               
02725               if(AnotherPass)
02726                 {
02727                   if(!same)  timingGradStep/= -1.5;     //backup and reverse direction, decrease step size
02728                   timingGrad+= timingGradStep;
02729                   rfdevice->maxGradient= timingGrad;
02730 
02731                   if(verbose>1)
02732                     {
02733                       printf("kbb.%d FINETUNE timingGradStep=%gMV/m timingGrad=%.9fMV/m Another=Y\n", 
02734                              timeCount, timingGradStep/(megavolt/meter), timingGrad/(megavolt/m));
02735                     }
02736                 }
02737               else
02738                 {
02739                   if(!RevisitTimingAfterGradientAdjust || revisited_timingZero)
02740                     {
02741                       if(verbose>1)
02742                         {
02743                           printf("kbb.%d FINETUNE timingGrad=%.9fMV/m Another=N Revisit=N\n", 
02744                                  timeCount, timingGrad/(megavolt/m));
02745                         }
02746 
02747                       lastFound_maxGradient= rfdevice->maxGradient= timingGrad;
02748 
02749                       rfdevice->state= ATWORKING_FINAL;  //done adjusting
02750 
02751                       if(rfdevice->whatFixed & ATFIX_OFFSETINCR)  
02752                         rfdevice->timeOffset+= rfdevice->timeIncrement;
02753                     }
02754                   else  //start all over deterimining timeZero, but using current gradient
02755                     {         
02756                       rfdevice->state= ATWORKING_OFFSET;
02757                       rfdevice->timeOffset= timingZero= 0;
02758                       timingPhase= automethod2timingphase(method, entrance.q);  //reset
02759                       revisited_timingZero= true;
02760                       timeCount000= timeCount;  //last of 1st of 2 passes
02761 
02762                       if(verbose>1)
02763                         {
02764                           printf("kbb.%d:STARTOVER:(%s) start over using maxGradient=%.6f MV/m\n", 
02765                                  timeCount, pbname, rfdevice->maxGradient/(megavolt/meter));
02766                         }
02767                     }
02768                 }
02769 
02770               break;
02771             }
02772           case AUTOADJUST_UNKNOWN:  //ought to have been done already
02773           case AUTOADJUST_UNNEEDED:
02774           case AUTOADJUST_OUTPUT:   //ought to have been done already
02775             {
02776               if(verbose>1)
02777                 {
02778                   printf("kbb.%d FINETUNE - don't know what?\n", timeCount);
02779                 }
02780 
02781               rfdevice->state= ATWORKING_FINAL;  //done adjusting
02782 
02783               if(rfdevice->whatFixed & ATFIX_OFFSETINCR)  
02784                 rfdevice->timeOffset+= rfdevice->timeIncrement;
02785 
02786               break;
02787             }
02788           }
02789 
02790         break;
02791       }
02792       
02793     case ATWORKING_FINAL:   //found solution, but need to do one more pass to update all
02794       {
02795         G4bool ok=true;
02796         if(BLCommand::isUndefined(rfdevice->autoTimingFailureLimit))
02797           {
02798             ok= true;
02799           }
02800         else if(rfdevice->whatFixed & ATFIX_P)
02801           {
02802             ok= fabs(rfdevice->autoTimingFixP-chng.Pout)/MeV <  rfdevice->autoTimingFailureLimit;
02803             show1step(rfdevice->state,"Pout=",chng.Pout/MeV,"MeV/c");
02804           }
02805         else if(rfdevice->whatFixed & ATFIX_DE)
02806           {
02807             ok= fabs(rfdevice->autoTimingFixDE-chng.dE)/MeV <  rfdevice->autoTimingFailureLimit;
02808             show1step(rfdevice->state,"dE=",chng.dE/MeV,"MeV");
02809           }
02810         else if(rfdevice->whatFixed & ATFIX_DT)
02811           {
02812             ok= fabs(rfdevice->autoTimingFixDT-chng.dT)/ns <  rfdevice->autoTimingFailureLimit;
02813             show1step(rfdevice->state,"dT=",chng.dT/ns,"ns");
02814           }
02815         else if(rfdevice->whatFixed & ATFIX_XDEFL)
02816           {
02817             ok= fabs(rfdevice->autoTimingFixXdeflection-chng.Xdefl)/deg <  rfdevice->autoTimingFailureLimit;
02818             show1step(rfdevice->state,"dX=",chng.Xdefl,"deg");
02819           }
02820         else if(rfdevice->whatFixed & ATFIX_YDEFL)
02821           {
02822             ok= fabs(rfdevice->autoTimingFixYdeflection-chng.Ydefl)/deg <  rfdevice->autoTimingFailureLimit;
02823             show1step(rfdevice->state,"dY=",chng.Ydefl,"deg");
02824           }
02825         else
02826           {
02827             show1step(rfdevice->state,"dE=",chng.dE/MeV,"MeV");
02828           }     
02829         
02830         printf("rfdevice::autoTiming:%d",redo);
02831 
02832         printf("[%s,%.1fdeg]ok=%s %s ",
02833                automethod2text(method), automethod2timingphase(method,entrance.q)/deg,
02834                ok? "Yes":"No", pbname);
02835         
02836         printf("timeOffset=%.9fns", rfdevice->timeOffset/ns);
02837 
02838         if(rfdevice->whatFixed & ATFIX_OFFSETINCR)
02839           printf("{timeIncrement=%.9fns}",rfdevice->timeIncrement/ns);
02840         
02841         printf(",maxGradient=%gMV/m,phaseAcc=%gdegRF -> ",
02842                rfdevice->maxGradient/(megavolt/meter),rfdevice->phaseAcc/deg);
02843         
02844         printf("%gMeV/c,%gMeV,%gns,%gXdeg,%gYdeg ",
02845                chng.Pout/MeV,chng.dE/MeV,chng.dT/ns,chng.Xdefl/deg,chng.Ydefl/deg);
02846         
02847         printf("timingZero=%.6fns,exit@%gmm,%gmm,%gmm,%gns\n",
02848                timingZero/ns,exit.x/mm,exit.y/mm,exit.z/mm,exit.t/ns);
02849 
02850         if(!ok)
02851             G4Exception("rfdevice","Final fixed value out of limits",FatalException,"");  //abort
02852 
02853         TrackOfInterest= true;
02854 
02855         if(verbose>1)
02856           {
02857             printf("kbb.%d FINAL - all done\n", timeCount);
02858             fflush(stdout);
02859           }
02860 
02861         /* lock final values into rfdevicefield, as copies of rfdevicefield reuse rfdevice... */
02862         maxGradient= rfdevice->maxGradient;
02863         timeOffset= rfdevice->timeOffset;
02864         stateOfPlacement= rfdevice->state= ATWORKING_DONE;
02865         break;
02866       }
02867 
02868     case ATWORKING_DONE:  
02869       {
02870         maxGradient= rfdevice->maxGradient;
02871         timeOffset= rfdevice->timeOffset;
02872         stateOfPlacement= rfdevice->state= ATWORKING_DONE;
02873         return; /* continue onward */
02874       } 
02875       
02876     case ATWORKING_UNKNOWN:  //never ought to happen
02877     case ATWORKING_INFLUX:
02878     case ATWORKING_RESET:
02879     default:
02880       {
02881         if(verbose>1)
02882           {
02883             printf("kbb.%d FINAL - ought not to be here\n", timeCount);
02884           }
02885       }
02886 
02887       return;
02888     }
02889 
02890     previous= chng;
02891  
02892     // restore saved data (i.e. jump back to when the track 
02893     // first entered TimingVol)
02894 
02895     if(!validSaveTrack)
02896       G4Exception("rfdevice","Invalid Step",FatalException,"");
02897  
02898     track->SetTrackStatus(fStopAndKill);  //kill off current track
02899 
02900     steppingMgr->GetfSecondary()->push_back(new G4Track(saveTrack));  //KBB* g4bl 2.06-2.08 change
02901  
02902     if(verbose>0)  fflush(stdout);
02903 
02904     return;
02905 }

void RFdeviceField::show1step ( AutoTimingState  state,
const char *  pre,
G4double  wrkval,
const char *  suf 
)

show1step() prints handy messages about autoTiming

References ATFIX_DE, ATFIX_DT, ATFIX_GRADIENT, ATFIX_OFFSET, ATFIX_OFFSETINCR, ATFIX_OUTPUT, ATFIX_P, ATFIX_PHASE, ATFIX_XDEFL, ATFIX_YDEFL, ATWORKING_BASE, ATWORKING_DONE, ATWORKING_ESTIMATE, ATWORKING_FINAL, ATWORKING_FINETUNE, ATWORKING_UNKNOWN, AUTOADJUST_GRADIENT, AUTOADJUST_OUTPUT, AUTOADJUST_PHASE, AUTOADJUST_UNKNOWN, automethod2text(), autotiming2method(), BLCMDrfdevice::autoTimingFixDE, BLCMDrfdevice::autoTimingFixDT, BLCMDrfdevice::autoTimingFixP, BLCMDrfdevice::autoTimingFixXdeflection, BLCMDrfdevice::autoTimingFixYdeflection, BLCMDrfdevice::autoTimingMethod, autotimingstate2text(), BLCMDrfdevice::autoTimingZlocal, global_2TraceCounter, BLCommand::isUndefined(), BLCMDrfdevice::maxGradient, pbname, BLCMDrfdevice::phaseAcc, rfdevice, stateOfPlacement, timeCount, BLCMDrfdevice::timeIncrement, BLCMDrfdevice::timeOffset, timingPhase, BLCMDrfdevice::verbose, BLCMDrfdevice::what2adjust, and BLCMDrfdevice::whatFixed.

Referenced by UserSteppingAction().

01607 {
01608   //show info on current autoTiming step
01609 
01610   if(!rfdevice->verbose)  return;
01611 
01612   int g= global_2TraceCounter;  //problems printing I*8
01613 
01614   printf("kbb_{%s}_%d:-2.%d:%s->%s ",pbname,timeCount,g,
01615          autotimingstate2text(stateOfPlacement),autotimingstate2text(state));
01616 
01617   //alltrace numbers UserSteppingActions as Event#-2.1,-2.1000,-2.1001,...
01618   if(global_2TraceCounter<1000)
01619     global_2TraceCounter= 1000;
01620   else
01621     ++global_2TraceCounter; 
01622 
01623   G4int fx= rfdevice->whatFixed & ~ATFIX_OUTPUT;
01624 
01625   if(state==ATWORKING_UNKNOWN && fx!=0)
01626     {
01627       printf("fixed:");
01628       if(fx & ATFIX_OFFSET)  printf("%gnS",rfdevice->timeOffset/ns);
01629       fx&= ~ATFIX_OFFSET;
01630 
01631       if(fx & ATFIX_OFFSETINCR)
01632         printf("timeIncrement=%gnS",rfdevice->timeIncrement/ns);
01633 
01634       fx&= ~ATFIX_OFFSETINCR;
01635 
01636       if(fx!=0)  printf(",");
01637       if(fx & ATFIX_GRADIENT)  printf("%gMV/m",rfdevice->maxGradient/(megavolt/meter));
01638       fx&= ~ATFIX_GRADIENT;
01639       if(fx!=0)  printf(",");
01640       if(fx & ATFIX_PHASE)  printf("%gdegRF",rfdevice->phaseAcc/deg);
01641       fx&= ~ATFIX_PHASE;
01642       if(fx!=0)  printf(",");
01643       if(fx & ATFIX_DE)  printf("%gMeV",rfdevice->autoTimingFixDE/MeV);
01644       fx&= ~ATFIX_DE;
01645       if(fx!=0)  printf(",");
01646       if(fx & ATFIX_P)  printf("%gMeV/c",rfdevice->autoTimingFixP/MeV);
01647       fx&= ~ATFIX_P;
01648       if(fx!=0)  printf(",");
01649       if(fx & ATFIX_DT)  printf("%gns",rfdevice->autoTimingFixDT/ns);
01650       fx&= ~ATFIX_DT;
01651       if(fx!=0)  printf(",");
01652       if(fx & ATFIX_XDEFL)  printf("%gdegX",rfdevice->autoTimingFixXdeflection/deg);
01653       fx&= ~ATFIX_XDEFL;
01654       if(fx!=0)  printf(",");
01655       if(fx & ATFIX_YDEFL)  printf("%gdegY",rfdevice->autoTimingFixYdeflection/deg);
01656       fx&= ~ATFIX_YDEFL;
01657       if(fx!=0)  printf(",");
01658     }
01659 
01660   AutoTimingMethod mthd= autotiming2method( rfdevice->autoTimingMethod);
01661   printf("%s",automethod2text(mthd));
01662   if(!BLCommand::isUndefined(rfdevice->autoTimingZlocal))
01663     printf(",atZlocal=%gmm ",rfdevice->autoTimingZlocal);
01664   else
01665     printf(" ");
01666 
01667   printf("%s", 
01668          rfdevice->what2adjust==AUTOADJUST_UNKNOWN ? "AUTOADJUST_UNKNOWN" :
01669          rfdevice->what2adjust==AUTOADJUST_PHASE ? "AUTOADJUST_PHASE" :
01670          rfdevice->what2adjust==AUTOADJUST_GRADIENT ? "AUTOADJUST_GRADIENT" :
01671          rfdevice->what2adjust==AUTOADJUST_OUTPUT ? "AUTOADJUST_OUTPUT" : "?");
01672 
01673   if(rfdevice->what2adjust==AUTOADJUST_GRADIENT)
01674     {
01675       printf("=%gMV/m ",rfdevice->maxGradient/(megavolt/meter));
01676     }
01677   else if(rfdevice->what2adjust==AUTOADJUST_PHASE)
01678     {
01679       if(state==ATWORKING_ESTIMATE || state==ATWORKING_FINETUNE)
01680         {
01681           printf("=%gdegRF ",timingPhase/deg);  //FYI only
01682         }
01683       else if(state==ATWORKING_FINAL || state==ATWORKING_DONE)
01684         {
01685           printf("=%gdegRF ",rfdevice->phaseAcc/deg);  //FYI only
01686         }
01687       else if(state==ATWORKING_BASE)
01688         {
01689           printf("=0degRF ");  //phase temporarially set to zero for base tracking
01690         }
01691       else
01692         {
01693           printf(" ");
01694         }
01695     }
01696   else
01697     {
01698       printf(" ");
01699     }
01700 
01701   printf("%s%g%s\n",pre,wrkval,suf);
01702 }

void RFdeviceField::reset (  ) 

reset() resets various internal used by autoTime to initial settings

References ampl, ATWORKING_UNKNOWN, cycle, drift, maxGradient, revisited_timingZero, stateOfPlacement, timeCount, timeCount000, timeOffset, timingGrad, timingGradStep, timingPhase, timingPhaseStep, timingZero, timingZeroStep, BLCommand::undefined(), and validSaveTrack.

Referenced by UserSteppingAction().

01451 {
01452         stateOfPlacement= ATWORKING_UNKNOWN;
01453         maxGradient= BLCommand::undefined();
01454         timeOffset= BLCommand::undefined();
01455 
01456         timeCount = 0;
01457         validSaveTrack = false;
01458 
01459         int timeCount000= 0;         
01460         G4bool revisited_timingZero= false;   
01461         double timingZero= 0;           
01462         double timingPhase= 0;           
01463         double timingZeroStep= 0;         
01464         double timingPhaseStep= 0;   
01465         double timingGrad= 0;       
01466         double timingGradStep=0;      
01467         int cycle= 0;              
01468         double ampl= 0;               
01469         double drift= 0;                 
01470 }


Friends And Related Function Documentation

friend class BLCMDrfdevice [friend]


Member Data Documentation

G4String RFdeviceField::name [private]

Referenced by getName(), and RFdeviceField().

G4VPhysicalVolume* RFdeviceField::timingPV [private]

G4RotationMatrix* RFdeviceField::rotation [private]

G4Track RFdeviceField::saveTrack [private]

Referenced by UserSteppingAction().

G4int RFdeviceField::timeCount [private]

G4double RFdeviceField::maxGradient [private]

G4double RFdeviceField::timeOffset [private]

G4int RFdeviceField::redo [private]

char RFdeviceField::pbname[256] [private]

double RFdeviceField::timingZero [private]

double RFdeviceField::timingPhase [private]

double RFdeviceField::timingGrad [private]

Referenced by UserSteppingAction().

int RFdeviceField::cycle [private]

double RFdeviceField::ampl [private]

double RFdeviceField::drift [private]

Referenced by UserSteppingAction().

Referenced by UserSteppingAction().

Referenced by UserSteppingAction().

Referenced by UserSteppingAction().


The documentation for this class was generated from the following file:
g4beamline