
#
# Global resource data for OAG applications. This file allows 
# customizing to a different environment.
#
# $Log: not supported by cvs2svn $
# Revision 1.35  2011/06/02 16:53:36  borland
# Added saving/loading of correction() array.
#
# Revision 1.34  2011/06/02 16:21:50  borland
# For FMA, can now specify using a single job (good for parallel mode).
#
# Revision 1.33  2011/06/02 16:16:31  borland
# Added ability to control number of orbit correction SVs.
#
# Revision 1.32  2011/06/01 23:50:45  borland
# Added features to improve portability to other systems.
#
# Revision 1.31  2011/05/31 16:08:36  borland
# Added initialization of variables for monitor errors in elegantRingAnalysis.
#
# Revision 1.30  2011/05/26 17:05:37  borland
# Added option to use multiple cores for DA with errors jobs.
#
# Revision 1.29  2011/04/06 02:35:38  borland
# Added FMA for x/y vs delta with errors.
#
# Revision 1.28  2011/01/25 20:24:10  soliday
# Updated the OAGWebDirectory to /home/oxygen/OAG/oagWWW-$env(EPICS_HOST_ARCH)
#
# Revision 1.27  2010/10/19 00:08:12  borland
# Better FMA-with-errors analysis, including use of Pelegant.
#
# Revision 1.26  2010/05/28 20:00:46  borland
# Revised parameters for dynamic aperture.
#
# Revision 1.25  2010/04/08 22:28:23  borland
# Added ability to run kick aperture with multiple processors per job.
# Fixed problems with postprocessing.
#
# Revision 1.24  2010/04/06 14:43:28  borland
# Added initialization of two parameters for momentum aperture search.
#
# Revision 1.23  2010/04/04 00:11:58  borland
# Added KickAperture computation.
#
# Revision 1.22  2010/02/23 14:23:12  borland
# Added starting values for elegantRingAnalysis momentum aperture search.
#
# Revision 1.21  2009/03/10 19:52:13  borland
# Added optional driving term computation.
#
# Revision 1.20  2009/03/06 22:45:19  borland
# Added option for input of errors from a parameter file.
#
# Revision 1.19  2009/03/03 18:52:26  borland
# Added moments computation for elegantRingAnalysis.
#
# Revision 1.18  2009/01/30 00:16:57  borland
# Changes for elegantRingAnalysis:
# 1. Use DynamicApertureErrorsTemplate.ele if no template is named.
# 2. Check for existence of parameter files.
#
# Revision 1.17  2008/08/26 18:26:09  borland
# Added element type pattern for momentum aperture determination.
#
# Revision 1.16  2008/08/21 22:03:12  borland
# Set default value for elegant diffusion calculation flag.
#
# Revision 1.15  2008/04/22 19:30:54  borland
# Set another parameter for elegantRingAnalysis.
#
# Revision 1.14  2008/04/14 21:18:24  borland
# Modified parameters for elegant momentum aperture.
#
# Revision 1.13  2007/12/21 17:09:05  borland
# Added default for basicComputation(bodyOrder).
#
# Revision 1.12  2007/11/16 13:52:25  borland
# Added template filename to entry array for dynamic aperture calculations,
# so the user can change it if desired.
#
# Revision 1.11  2006/08/22 20:02:26  borland
# Shang's version with new globals for elegantRingAnalysis.
#
# Revision 1.10  2006/06/02 13:25:22  borland
# The dynamic aperture with errors calculation in elegantRingAnalysis now uses
# line search modes.
#
# Revision 1.9  2006/03/25 21:53:30  borland
# elegantRingAnalysis momentum aperture scan now proceeds from outside toward
# inside and makes use of new algorithm.
#
# Revision 1.8  2006/03/24 18:50:19  borland
# Added momentumAperture array to elegant globals.
#
# Revision 1.7  2005/07/06 13:03:34  borland
# APSSetElegantGlobals added by Shang.
#
# Revision 1.6  2005/05/21 20:45:02  borland
# Added AtAPS member to OAG global array.
#
# Revision 1.5  2005/01/12 22:08:11  soliday
# Added definition of OAGLoggingDirectory
#
# Revision 1.4  2004/04/06 21:50:19  borland
# Added definition of OAGGlobalAppConfigDataDirectory.
#
# Revision 1.3  2004/03/11 20:20:32  borland
# Added entries for SRCalibratedModelsDirectory, OAGMonitoringDirectory, and
# OAGWebDirectory.  All are needed by SRSourceParameters PCAS server.
#
# Revision 1.2  2004/02/09 19:09:27  soliday
# Added LogOnChange directory
#
# Revision 1.1  2004/01/15 18:17:52  borland
# Added APSSetOAGGlobal procedure. It is called by APSStandardSetup and is
# used to set global parameters like main directory names.
#
#

proc APSSetOAGGlobal {} {
    global OAGGlobal env
    set OAGGlobal(OAGDataDirectory) /home/helios/oagData
    set OAGGlobal(AlarmLogDirectory) $OAGGlobal(OAGDataDirectory)/Alarms
    set OAGGlobal(LogOnChangeDirectory) $OAGGlobal(OAGDataDirectory)/logonchange
    set OAGGlobal(SRCalibratedModelsDirectory) $OAGGlobal(OAGDataDirectory)/sr/calibratedModels
    set OAGGlobal(OAGMonitoringDirectory) $OAGGlobal(OAGDataDirectory)/monitoring
    set OAGGlobal(OAGLoggingDirectory) $OAGGlobal(OAGDataDirectory)/logging
    set OAGGlobal(OAGWebDirectory) /net/epics-ops/web_roots/ops
    if ![info exists env(OAG_TOP_DIR)] {
	set env(OAG_TOP_DIR) /usr/local
    }
    set OAGGlobal(OAGAppConfigDataDirectory) $env(OAG_TOP_DIR)/oag/apps/configData

    set OAGGlobal(BoosterLatticesDirectory) /home/helios/oagData/booster/lattices
    set OAGGlobal(BTSLatticesDirectory)     /home/helios/oagData/BTS/lattices
    set OAGGlobal(ITSLatticesDirectory)     /home/helios/oagData/ITS/lattices
    set OAGGlobal(LinacLatticesDirectory)   /home/helios/oagData/linac/lattices
    set OAGGlobal(LTPLatticesDirectory)     /home/helios/oagData/LTP/lattices
    set OAGGlobal(PARLatticesDirectory)     /home/helios/oagData/par/lattices
    set OAGGlobal(PTBLatticesDirectory)     /home/helios/oagData/ptb/lattices
    set OAGGlobal(SRLatticesDirectory)      /home/helios/oagData/sr/lattices
    foreach name "Booster BTS ITS Linac LTP PAR PTB SR" {
        set name2 [string toupper $name]
        if [info exists env(OAG_${name2}_LATTICE_DIR)] {
            set OAGGlobal(${name}LatticesDirectory) $env(OAG_${name2}_LATTICE_DIR)
        }
    }

    set OAGGlobal(AtAPS) 1
}

proc APSSetElegantGlobals {} {
    global errors correction
    set errors(on) 0
    set errors(maskTable) 0
    set errors(numberOfSeeds) 50
    set errors(seed) 98777521
    set errors(seeds) 50
    set errors(dxBend) 1e-4
    set errors(dyBend) 1e-4
    set errors(dtiltBend) 1e-4
    set errors(fseBend) 1e-4
    set errors(dxQuad) 1e-4
    set errors(dyQuad) 1e-4
    set errors(dtiltQuad) 1e-4
    set errors(fseQuad) 1e-4
    set errors(dxSext) 1e-4
    set errors(dySext) 1e-4
    set errors(dtiltSext) 1e-4
    set errors(fseSext) 1e-4
    set errors(dxMoni) 1e-4
    set errors(dyMoni) 1e-4
    set errors(dtiltMoni) ignored
    set errors(fseMoni) ignored

    set correction(horizontalSVs) 0
    set correction(verticalSVs) 0
    set correction(disableOrbitCorrection) 0
    set correction(orbitIterations) 500
    set correction(orbitAccuracy) 1e-9
    set correction(orbitIterationFraction) 0.5

    global basicComputations
    foreach item [list Chromaticity HigherOrderChromaticity ChromaticTuneSpread \
                    RadiationIntegrals DrivingTerms ] {
        set basicComputations(do$item) 0
    }
    set basicComputations(chromaticTuneSpreadMomentumSpread) 0.015
    set basicComputations(driftDivisions) 1
    set basicComputations(dipoleDivisions) 1
    set basicComputations(quadDivisions) 1
    set basicComputations(sextDivisions) 1
    set basicComputations(edgeOrder) 1
    set basicComputations(bodyOrder) 2
    set basicComputations(finalSTwiss) 0.0
    set basicComputations(userSuffix) ""
    
    global momentsComputations
    set momentsComputations(order) 2
    set momentsComputations(edgeOrder) 2
    set momentsComputations(bodyOrder) 2
    set momentsComputations(sourcePointNamePattern) *
    set momentsComputations(sourcePointTypePattern) *
    set momentsComputations(userSuffix) ""

    global collectiveEffects
    set collectiveEffects(scanPoints) 10
    set collectiveEffects(charge0) 1.0e-9
    set collectiveEffects(charge1) 1.0e-9
    set collectiveEffects(rfVoltage0) 9.5e6
    set collectiveEffects(rfVoltage1) 9.5e6
    set collectiveEffects(emittanceRatio0) 0.01
    set collectiveEffects(emittanceRatio1) 0.01
    set collectiveEffects(BBImpedance0) 0.5
    set collectiveEffects(BBImpedance1) 0.5
    set collectiveEffects(rfHarmonic) 1296
    set collectiveEffects(superPeriods) 1
    set collectiveEffects(VHarmonic0) 0
    set collectiveEffects(VHarmonic1) 0
    set collectiveEffects(harmonicRatio) 3
    set collectiveEffects(prefix) ""

    global phaseSpaceTracking
    set phaseSpaceTracking(offsetPlane) X
    set phaseSpaceTracking(otherPlane) Y
    set phaseSpaceTracking(initialOffset) 1e-6
    set phaseSpaceTracking(finalOffset)   1e-3
    set phaseSpaceTracking(otherCoord) 0.0
    set phaseSpaceTracking(delta) 0.0
    set phaseSpaceTracking(sweepPoints) 11
    set phaseSpaceTracking(turns) 1024
    set phaseSpaceTracking(userSuffix) ""
    
    global mainParameterFile
    set mainParameterFile(1) ""
    set mainParameterFile(2) ""
    set mainParameterFile(3) ""
    set mainParameterFile(4) ""
    
    global offMomentumTuneTracking
    set offMomentumTuneTracking(initialOffset) -0.01
    set offMomentumTuneTracking(finalOffset) 0.01
    set offMomentumTuneTracking(xOffset) 1e-6
    set offMomentumTuneTracking(yOffset) 1e-6
    set offMomentumTuneTracking(sweepPoints) 11
    set offMomentumTuneTracking(turns) 1024
    set offMomentumTuneTracking(superperiodicity) 1
    set offMomentumTuneTracking(userSuffix) ""
    
    global offMomentumDynamicAperture
    set offMomentumDynamicAperture(xMinimum) -0.01
    set offMomentumDynamicAperture(xMaximum)  0.01
    set offMomentumDynamicAperture(yMaximum)  0.01
    set offMomentumDynamicAperture(xPoints)   31
    set offMomentumDynamicAperture(yPoints)   16
    set offMomentumDynamicAperture(deltaMinimum) -0.01
    set offMomentumDynamicAperture(deltaMaximum) 0.01
    set offMomentumDynamicAperture(deltaPoints) 11
    set offMomentumDynamicAperture(turns) 500
    set offMomentumDynamicAperture(userSuffix) ""
    set offMomentumDynamicAperture(includeApertures) 1

    global higherOrderDispersion
    set higherOrderDispersion(initialOffset) -0.01
    set higherOrderDispersion(finalOffset) 0.01
    set higherOrderDispersion(sweepPoints) 11
    
    global dynamicApertureErrors
    set dynamicApertureErrors(xMaximum)  0.01
    set dynamicApertureErrors(yMaximum)  0.01
    set dynamicApertureErrors(delta)  0.0
    set dynamicApertureErrors(steps)   12
    set dynamicApertureErrors(splits)  4
    set dynamicApertureErrors(mode)   none
    set dynamicApertureErrors(lines)   11
    set dynamicApertureErrors(turns) 500
    set dynamicApertureErrors(nCores) 1
    set dynamicApertureErrors(includeApertures) 1
    set dynamicApertureErrors(template) ""

    global dynamicAperture
    set dynamicAperture(xMinimum) -0.01
    set dynamicAperture(xMaximum)  0.01
    set dynamicAperture(yMaximum)  0.01
    set dynamicAperture(xPoints)   31
    set dynamicAperture(yPoints)   16
    set dynamicAperture(turns) 500
    set dynamicAperture(includeApertures) 1
    set dynamicAperture(userSuffix) ""
    
    global kickApertureErrors
    set kickApertureErrors(minimumKick)  -0.01
    set kickApertureErrors(maximumKick)  0.01
    set kickApertureErrors(steps)   20
    set kickApertureErrors(turns) 500
    set kickApertureErrors(particles) 1000
    set kickApertureErrors(emittanceRatio) 0.01
    set kickApertureErrors(elementName) ""
    set kickApertureErrors(userSuffix) ""
    set kickApertureErrors(includeApertures) 1
    set kickApertureErrors(apertureFile) ""
    set kickApertureErrors(processors) 1

    global fineDynamicAperture
    set fineDynamicAperture(xMinimum) -0.01
    set fineDynamicAperture(xMaximum)  0.01
    set fineDynamicAperture(yMaximum)  0.01
    set fineDynamicAperture(xPoints)   101
    set fineDynamicAperture(yPoints)   51
    set fineDynamicAperture(turns)     500
    set fineDynamicAperture(delta)     0.0
    set fineDynamicAperture(userSuffix)    ""
    set fineDynamicAperture(includeApertures) 1

    global frequencyMap
    set frequencyMap(xMinimum)  1e-6
    set frequencyMap(xMaximum)  0.01
    set frequencyMap(yMinimum)  1e-6
    set frequencyMap(yMaximum)  0.01
    set frequencyMap(xPoints)   101
    set frequencyMap(yPoints)   51
    set frequencyMap(turns)     500
    set frequencyMap(delta)     0.0
    set frequencyMap(userSuffix)    ""
    set frequencyMap(includeApertures) 1
    set frequencyMap(includeChanges) 0
    set frequencyMap(processors) 1
    set frequencyMap(singleJob) 0

    global frequencyMapDelta
    set frequencyMapDelta(xyMinimum)  -0.01
    set frequencyMapDelta(xyMaximum)   0.01
    set frequencyMapDelta(deltaMinimum) -0.02
    set frequencyMapDelta(deltaMaximum)  0.02
    set frequencyMapDelta(xyPoints)   51
    set frequencyMapDelta(deltaPoints)   51
    set frequencyMapDelta(turns)     500
    set frequencyMapDelta(userSuffix)    ""
    set frequencyMapDelta(otherCoordinate) 1e-6
    set frequencyMapDelta(plane) X
    set frequencyMapDelta(includeApertures) 1
    set frequencyMapDelta(processors) 1

    global momentumAperture
    set momentumAperture(xInitial) 0.0
    set momentumAperture(yInitial) 0.0
    set momentumAperture(deltaNegativeStart) 0.0
    set momentumAperture(deltaPositiveStart) 0.0
    set momentumAperture(deltaNegativeLimit) -0.10
    set momentumAperture(deltaPositiveLimit) 0.10
    set momentumAperture(initialDeltaStep) 0.01
    set momentumAperture(splits) 1
    set momentumAperture(stepsBack) 1
    set momentumAperture(stepDivisor) 10
    set momentumAperture(sStart) 0.0
    set momentumAperture(sEnd) 1e10
    set momentumAperture(pattern) *
    set momentumAperture(typePattern) *
    set momentumAperture(turns) 500
    set momentumAperture(includeApertures) 1
    set momentumAperture(includeRadiation) 0
    set momentumAperture(numberOfJobs) 50
    set momentumAperture(userSuffix) ""
    set momentumAperture(defaultOrder) 2
    set momentumAperture(deltaNegativeStart) 0.0
    set momentumAperture(deltaPositiveStart) 0.0
    set momentumAperture(nCores) 1

    global elegantSaveVarList elegantGlobalArrays
    set elegantSaveVarList ""
    lappend elegantSaveVarList momentum matrixLatticeFile \
	kickLatticeFile mainParameterFile mainDirectory mainPrefix \
	gridEngine forceOccurence
    lappend elegantSaveVarList matrixBeamline kickBeamline \
	matrixOffsetElement kickOffsetElement
    lappend elegantSaveVarList basicComputations phaseSpaceTracking \
	offMomentumTuneTracking higherOrderDispersion
    lappend elegantSaveVarList dynamicAperture \
	offMomentumDynamicAperture fineDynamicAperture
    lappend elegantSaveVarList frequencyMap collectiveEffects \
	dynamicApertureErrors frequencyMapDelta momentumAperture kickApertureErrors
    
    #array variables
    set elegantGlobalArrays [list errors correction mainParameterFile basicComputations momentsComputations \
                               phaseSpaceTracking higherOrderDispersion \
                               offMomentumTuneTracking dynamicAperture \
                               offMomentumDynamicAperture \
                               dynamicApertureErrors \
                               fineDynamicAperture \
                               frequencyMap frequencyMapDelta collectiveEffects \
                               momentumAperture kickApertureErrors]
}
