#include <BLTune.hh>
The tune command (class BLCMDtune) will tune arguments to commands with the goal of achieving some specified measure of performance. Tuning occurs when the Tune Particle is tracked, and only those aspects of performance that can be achieved during that tracking can be tuned. The example used here is to tune the current in a genericbend so the reference particle had dxdz=0 after the magnet.
Tunable arguments to a command must: a) be declared with argTunable() in defineArgs() b) be referenced indirectly by each placement class of the element; that is, the placement object cannot keep a local copy, but must always reference the actual parameter variable of the Element. c) be copied using BLTune::copyTunableArg() in the element's copy constructor
Tunable arguments are set on either the element or place command using the usual name=expression syntax. The expression can contain the name of any enclosing tune command as a variable, and the value of the variable will always be the current value during tuning, and will be the final result after tuning is complete.
Public Member Functions | |
BLTune () | |
Constructor. | |
virtual | ~BLTune () |
Destructor. | |
Static Public Member Functions | |
static void | defineTunableArg (G4double &arg, G4double units, G4String expr) |
defineTunableArg() will define a tunable argument. | |
static void | copyTunableArg (G4double *newArg, const G4double *oldArg) |
copyTunableArg() will copy a tunable argument; for use in the copy constructor of Element classes. | |
static bool | isSet (G4String name) |
isSet() returns true if the varaible name is set. | |
static void | set (G4String &name, G4double value) |
set() will set the value of a tune variable, and update all arguments that use it. | |
static void | unset (G4String &name) |
unset() will remove a tune variable. | |
static void | update () |
update() will update all tunable args with their current values. | |
Static Private Attributes | |
static BLEvaluator | eval |
static std::map< G4double *, G4String > | tuneExpr |
static std::map< G4double *, G4double > | tuneUnits |
void BLTune::defineTunableArg | ( | G4double & | arg, | |
G4double | units, | |||
G4String | expr | |||
) | [static] |
defineTunableArg() will define a tunable argument.
References eval, BLEvaluator::evaluate(), BLCommand::printError(), tuneExpr, and tuneUnits.
Referenced by BLCommand::argTunable(), and copyTunableArg().
00011 { 00012 tuneUnits[&arg] = units; 00013 tuneExpr[&arg] = expr; 00014 if(!eval.findFunction("sin",1)) eval.setStdMath(); 00015 arg = eval.evaluate(expr) * units; 00016 if(eval.status() != HepTool::Evaluator::OK) { 00017 BLCommand::printError("Invalid expression '%s'",expr.c_str()); 00018 } 00019 }
void BLTune::copyTunableArg | ( | G4double * | newArg, | |
const G4double * | oldArg | |||
) | [static] |
copyTunableArg() will copy a tunable argument; for use in the copy constructor of Element classes.
References defineTunableArg(), tuneExpr, and tuneUnits.
Referenced by BLCMDfieldexpr::BLCMDfieldexpr(), BLCMDfieldmap::BLCMDfieldmap(), BLCMDgenericbend::BLCMDgenericbend(), BLCMDidealsectorbend::BLCMDidealsectorbend(), BLCMDpillbox::BLCMDpillbox(), and BLCMDrfdevice::BLCMDrfdevice().
00022 { 00023 if(tuneExpr.count((G4double*)oldArg) == 0) 00024 defineTunableArg(*newArg,1,"0"); 00025 else 00026 defineTunableArg(*newArg,tuneUnits[(G4double*)oldArg], 00027 tuneExpr[(G4double*)oldArg]); 00028 *newArg = *oldArg; 00029 }
bool BLTune::isSet | ( | G4String | name | ) | [static] |
isSet() returns true if the varaible name is set.
References eval.
Referenced by BLCMDtune::command().
00032 { 00033 return eval.findVariable(name); 00034 }
void BLTune::set | ( | G4String & | name, | |
G4double | value | |||
) | [static] |
set() will set the value of a tune variable, and update all arguments that use it.
References eval, and update().
Referenced by BLCMDtune::command(), and BLCMDtune::UserZSteppingAction().
void BLTune::unset | ( | G4String & | name | ) | [static] |
void BLTune::update | ( | ) | [static] |
update() will update all tunable args with their current values.
References eval, BLEvaluator::evaluate(), BLCommand::printError(), tuneExpr, and tuneUnits.
Referenced by set().
00048 { 00049 if(!eval.findFunction("sin",1)) eval.setStdMath(); 00050 00051 std::map<G4double*,G4String>::iterator i; 00052 for(i=tuneExpr.begin(); i!=tuneExpr.end(); ++i) { 00053 G4double *p = i->first; 00054 G4String expr = i->second; 00055 G4double units = tuneUnits[p]; 00056 *p = eval.evaluate(expr) * units; 00057 if(eval.status() != HepTool::Evaluator::OK) { 00058 BLCommand::printError("Invalid expression '%s'", 00059 expr.c_str()); 00060 } 00061 } 00062 }
BLEvaluator BLTune::eval [static, private] |
Referenced by defineTunableArg(), isSet(), set(), unset(), and update().
std::map< G4double *, G4String > BLTune::tuneExpr [static, private] |
Referenced by copyTunableArg(), defineTunableArg(), and update().
std::map< G4double *, G4double > BLTune::tuneUnits [static, private] |
Referenced by copyTunableArg(), defineTunableArg(), and update().