OpalCyclotron.cpp 6.58 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
// ------------------------------------------------------------------------
// $RCSfile: OpalCyclotron.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: OpalCyclotron
//   The class of OPAL cyclotron.
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:39 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------

#include "Elements/OpalCyclotron.h"
#include "AbstractObjects/Attribute.h"
#include "Attributes/Attributes.h"
#include "BeamlineCore/CyclotronRep.h"
#include "Physics/Physics.h"


// Class OpalCyclotron
// ------------------------------------------------------------------------

OpalCyclotron::OpalCyclotron():
    OpalElement(SIZE, "CYCLOTRON",
                "The \"CYCLOTRON\" defines an cyclotron") {
    itsAttr[CYHARMON] = Attributes::makeReal
                        ("CYHARMON", "the harmonic number of the cyclotron");
    itsAttr[SYMMETRY] = Attributes::makeReal
                        ("SYMMETRY", "defines how the field is stored");
    itsAttr[RINIT] = Attributes::makeReal
                     ("RINIT", "Initial radius of the reference particle [m]");
    itsAttr[PRINIT] = Attributes::makeReal
39
                      ("PRINIT", "Initial radial momentum of the reference particle, pr=beta_r*gamma");
gsell's avatar
gsell committed
40 41 42 43 44 45 46 47 48 49 50 51
    itsAttr[PHIINIT] = Attributes::makeReal
                       ("PHIINIT", "Initial azimuth of the reference particle [deg]");
    itsAttr[FMAPFN] = Attributes::makeString
                      ("FMAPFN", "Filename for the B fieldmap");
    itsAttr[BSCALE] = Attributes::makeReal
                      ("BSCALE", "Scale factor for the B-field", 1.0);

    itsAttr[RFFREQ] = Attributes::makeRealArray
                      ("RFFREQ", "RF Frequency(ies) [MHz]");

    itsAttr[ESCALE] = Attributes::makeRealArray
                      ("ESCALE", "Scale factor for the RF field(s)");
52 53 54
    
    itsAttr[SUPERPOSE] = Attributes::makeBool
 	       ("SUPERPOSE", "Option Whether all of the electric field maps are superposed, only used when TYPE = BANDRF", true);
gsell's avatar
gsell committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

    itsAttr[RFMAPFN] = Attributes::makeStringArray
                      ("RFMAPFN", "Filename for the RF fieldmap(s)");

    itsAttr[RFPHI] = Attributes::makeRealArray
                     ("RFPHI", "Initial phase(s) of the electric field map(s) [deg]");

    itsAttr[TYPE] = Attributes::makeString
                    ("TYPE", "Used to identify special cyclotron types");    
    itsAttr[TCR1] = Attributes::makeReal
                    ("TCR1", "trim coil r1 [mm]");
    itsAttr[TCR2] = Attributes::makeReal
                    ("TCR2", "trim coil r2 [mm]");
    itsAttr[MBTC] = Attributes::makeReal
                    ("MBTC", "max bfield of trim coil [kG]");
    itsAttr[SLPTC] = Attributes::makeReal
                     ("SLPTC", "slope of the rising edge");

    registerStringAttribute("FMAPFN");
    registerStringAttribute("RFMAPFN");
    registerStringAttribute("TYPE");
    registerRealAttribute("CYHARMON");
    registerRealAttribute("RINIT");
    registerRealAttribute("PRINIT");
    registerRealAttribute("PHIINIT");
    registerRealAttribute("SYMMETRY");
    registerRealAttribute("RFFREQ");
    registerRealAttribute("BSCALE");
    registerRealAttribute("ESCALE");
    registerRealAttribute("TCR1");
    registerRealAttribute("TCR2");
    registerRealAttribute("MBTC");
    registerRealAttribute("SLPTC");
    registerRealAttribute("RFPHI");
    setElement((new CyclotronRep("CYCLOTRON"))->makeAlignWrapper());
}


OpalCyclotron::OpalCyclotron(const string &name, OpalCyclotron *parent):
    OpalElement(name, parent) {
    setElement((new CyclotronRep(name))->makeAlignWrapper());
}


OpalCyclotron::~OpalCyclotron()
{}


OpalCyclotron *OpalCyclotron::clone(const string &name) {
    return new OpalCyclotron(name, this);
}


void OpalCyclotron::
fillRegisteredAttributes(const ElementBase &base, ValueFlag flag) {
    OpalElement::fillRegisteredAttributes(base, flag);
}


void OpalCyclotron::update() {
    using Physics::two_pi;
    CyclotronRep *cycl =
        dynamic_cast<CyclotronRep *>(getElement()->removeWrappers());

    string fmapfm = Attributes::getString(itsAttr[FMAPFN]);

    string type = Attributes::getString(itsAttr[TYPE]);

    double harmnum = Attributes::getReal(itsAttr[CYHARMON]);
    double symmetry = Attributes::getReal(itsAttr[SYMMETRY]);
    double rinit = Attributes::getReal(itsAttr[RINIT]);
    double prinit = Attributes::getReal(itsAttr[PRINIT]);
    double phiinit = Attributes::getReal(itsAttr[PHIINIT]);
    double bscale = Attributes::getReal(itsAttr[BSCALE]);

    double tcr1 = Attributes::getReal(itsAttr[TCR1]);
    double tcr2 = Attributes::getReal(itsAttr[TCR2]);
    double mbtc = Attributes::getReal(itsAttr[MBTC]);
    double slptc = Attributes::getReal(itsAttr[SLPTC]);
134 135
    bool   superpose = Attributes::getBool(itsAttr[SUPERPOSE]);
    
gsell's avatar
gsell committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
    cycl->setFieldMapFN(fmapfm);
    cycl->setSymmetry(symmetry);

    cycl->setRinit(rinit);
    cycl->setPRinit(prinit);
    cycl->setPHIinit(phiinit);
    cycl->setBScale(bscale);

    cycl->setType(type);
    cycl->setCyclHarm(harmnum);

    cycl->setTCr1(tcr1);
    cycl->setTCr2(tcr2);
    cycl->setMBtc(mbtc);
    cycl->setSLPtc(slptc);
151
    cycl->setSuperpose(superpose);
gsell's avatar
gsell committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179

    std::vector<string> fm_str = Attributes::getStringArray(itsAttr[RFMAPFN]);
    std::vector<double> scale_str = Attributes::getRealArray(itsAttr[ESCALE]);
    std::vector<double> phi_str = Attributes::getRealArray(itsAttr[RFPHI]);
    std::vector<double> rff_str = Attributes::getRealArray(itsAttr[RFFREQ]);

    // if ((fm_str.size() == scale_str.size()) && 
    //     (fm_str.size() == phi_str.size()) && 
    //     (fm_str.size() == rff_str.size())) {

    //     std::vector<string>::const_iterator fm    = fm_str.begin();
    //     std::vector<double>::const_iterator scale = scale_str.begin();        
    //     std::vector<double>::const_iterator phi   = phi_str.begin();
    //     std::vector<double>::const_iterator rff   = rff_str.begin();
        
    //     for( ; fm != fm_str.end(); ++fm,++scale,++phi,++rff)
    //         INFOMSG(" FM= " << *fm << "\t SCALE= " << *scale << "\t PHI= " << *phi << "\t FREQU= " << *rff << endl;);
    // }

    cycl->setRfPhi(phi_str);
    cycl->setEScale(scale_str);
    cycl->setRfFieldMapFN(fm_str);
    cycl->setRfFrequ(rff_str);
    // Transmit "unknown" attributes.
    OpalElement::updateUnknown(cycl);
}

//  LocalWords:  rfphi