File indexing completed on 2024-04-06 11:56:01
0001
0002
0003
0004
0005
0006
0007
0008 #include "Alignment/CocoaModel/interface/Entry.h"
0009 #include "Alignment/CocoaModel/interface/Model.h"
0010 #include "Alignment/CocoaModel/interface/OpticalObject.h"
0011 #include "Alignment/CocoaUtilities/interface/ALIFileIn.h"
0012 #include "Alignment/CocoaUtilities/interface/ALIUtils.h"
0013 #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
0014 #include "Alignment/CocoaModel/interface/ParameterMgr.h"
0015 #include "Alignment/CocoaModel/interface/EntryMgr.h"
0016 #include "Alignment/CocoaModel/interface/EntryData.h"
0017 #include <cstdlib>
0018
0019
0020
0021
0022 Entry::Entry(const ALIstring& type) : type_(type), fitPos_(-1) {
0023
0024
0025 valueDisplacementByFitting_ = 0.;
0026 if (ALIUtils::debug >= 5)
0027 std::cout << this << " theValueDisplacementByFitting set " << valueDisplacementByFitting_ << std::endl;
0028 }
0029
0030
0031 void Entry::fill(const std::vector<ALIstring>& wordlist) {
0032 ALIdouble byshort;
0033 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
0034 gomgr->getGlobalOptionValue("reportOutEntriesByShortName", byshort);
0035
0036
0037 if (ALIUtils::debug >= 4)
0038 std::cout << "@@@ Filling entry: " << name() << std::endl;
0039
0040 if (wordlist.size() != 4) {
0041 ALIFileIn::getInstance(Model::SDFName()).ErrorInLine();
0042 ALIUtils::dumpVS(wordlist, " !!! Incorrect format for Entry:", std::cerr);
0043 std::cerr << std::endl << " There should be four words: name value sigma quality " << std::endl;
0044 exit(2);
0045 }
0046
0047 EntryData* entryData;
0048 if (byshort == 0) {
0049 entryData = EntryMgr::getInstance()->findEntryByLongName(OptOCurrent()->longName(), name());
0050 } else {
0051 entryData = EntryMgr::getInstance()->findEntryByShortName(OptOCurrent()->longName(), name());
0052 }
0053 if (ALIUtils::debug >= 5)
0054 std::cout << " entryData " << entryData << " " << OptOCurrent()->longName() << " " << name() << std::endl;
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065 ALIdouble fre;
0066 gomgr->getGlobalOptionValue("reportOutReadValue", fre);
0067 if (entryData != nullptr && fre == 1) {
0068
0069 fillFromReportOutFileValue(entryData);
0070 } else {
0071
0072 fillFromInputFileValue(wordlist);
0073 }
0074 gomgr->getGlobalOptionValue("reportOutReadSigma", fre);
0075 if (entryData != nullptr && fre == 1) {
0076 fillFromReportOutFileSigma(entryData);
0077 } else {
0078 fillFromInputFileSigma(wordlist);
0079 }
0080 gomgr->getGlobalOptionValue("reportOutReadQuality", fre);
0081 if (entryData != nullptr && fre == 1) {
0082 fillFromReportOutFileQuality(entryData);
0083 } else {
0084 fillFromInputFileQuality(wordlist);
0085 }
0086 }
0087
0088
0089 void Entry::fillFromInputFileValue(const std::vector<ALIstring>& wordlist) {
0090
0091 ParameterMgr* parmgr = ParameterMgr::getInstance();
0092
0093 ALIdouble val = 0.;
0094 if (!ALIUtils::IsNumber(wordlist[1])) {
0095 if (parmgr->getParameterValue(wordlist[1], val) == 0) {
0096 ALIFileIn::getInstance(Model::SDFName()).ErrorInLine();
0097 std::cerr << "!!! parameter for value not found: " << wordlist[1].c_str() << std::endl;
0098 exit(2);
0099 }
0100
0101 } else {
0102
0103 val = atof(wordlist[1].c_str());
0104 }
0105 val *= ValueDimensionFactor();
0106 if (ALIUtils::debug >= 4) {
0107 std::cout << "VALUE = " << val << " (ValueDimensionFactor= " << ValueDimensionFactor() << std::endl;
0108 }
0109
0110 value_ = val;
0111 valueOriginalOriginal_ = value_;
0112 }
0113
0114 void Entry::fillFromInputFileSigma(const std::vector<ALIstring>& wordlist) {
0115 ParameterMgr* parmgr = ParameterMgr::getInstance();
0116
0117
0118
0119
0120
0121
0122
0123 ALIdouble sig = 0.;
0124 if (!ALIUtils::IsNumber(wordlist[2])) {
0125 if (parmgr->getParameterValue(wordlist[2], sig) == 0) {
0126 ALIFileIn::getInstance(Model::SDFName()).ErrorInLine();
0127
0128 std::cerr << "!!! parameter for sigma not found: " << wordlist[0] << " " << wordlist[1] << " " << wordlist[2]
0129 << std::endl;
0130 exit(2);
0131 }
0132
0133
0134 } else {
0135
0136 sig = atof(wordlist[2].c_str());
0137
0138 ALIdouble rs;
0139 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
0140 gomgr->getGlobalOptionValue("range_studies", rs);
0141 if (rs == 1)
0142 sig *= 1.E-6;
0143
0144
0145 }
0146 sig *= SigmaDimensionFactor();
0147 if (ALIUtils::debug >= 4) {
0148 std::cout << "SIGMA = " << sig << " (SigmaDimensionFactor= " << SigmaDimensionFactor() << std::endl;
0149 }
0150 sigma_ = sig;
0151 sigmaOriginalOriginal_ = sigma_;
0152 }
0153
0154
0155 void Entry::fillFromInputFileQuality(const std::vector<ALIstring>& wordlist) {
0156
0157 if (wordlist[3] == ALIstring("unk")) {
0158 quality_ = 2;
0159 } else if (wordlist[3] == ALIstring("cal")) {
0160 quality_ = 1;
0161
0162
0163
0164
0165 } else if (wordlist[3] == ALIstring("fix")) {
0166 quality_ = 0;
0167 } else {
0168 ALIFileIn::getInstance(Model::SDFName()).ErrorInLine();
0169 std::cerr << " quality should be 'unk' or 'cal' or 'fix', instead of " << wordlist[3] << std::endl;
0170 exit(3);
0171 }
0172
0173 if (sigma_ == 0) {
0174
0175 quality_ = 0;
0176 }
0177 if (ALIUtils::debug >= 4)
0178 std::cout << OptOCurrent()->name() << " " << name() << " " << sigma_ << "QUALITY:" << quality_ << std::endl;
0179
0180 sigmaOriginalOriginal_ = sigma_;
0181 }
0182
0183
0184
0185
0186 void Entry::fillFromReportOutFileValue(EntryData* entryData) {
0187 value_ = entryData->valueOriginal();
0188
0189 EntryMgr* entryMgr = EntryMgr::getInstance();
0190
0191 if (type_ == "centre" || type_ == "length") {
0192 value_ *= entryMgr->getDimOutLengthVal();
0193
0194 entryData->setValueDisplacement(entryData->valueDisplacement() * entryMgr->getDimOutLengthVal());
0195 if (ALIUtils::debug >= 5)
0196 std::cout << " fillFromReportOut " << OptOCurrent()->name() << " " << name() << "" << value_ << " disp "
0197 << entryData->valueDisplacement() * entryMgr->getDimOutLengthVal() << std::endl;
0198 } else if (type_ == "angles" || type_ == "angle") {
0199 value_ *= entryMgr->getDimOutAngleVal();
0200 entryData->setValueDisplacement(entryData->valueDisplacement() * entryMgr->getDimOutAngleVal());
0201 if (ALIUtils::debug >= 5)
0202 std::cout << " fillFromReportOut " << OptOCurrent()->name() << " " << name() << "" << value_ << " disp "
0203 << entryData->valueDisplacement() * entryMgr->getDimOutAngleVal() << std::endl;
0204 }
0205
0206 valueOriginalOriginal_ = value_;
0207 }
0208
0209
0210 void Entry::fillFromReportOutFileSigma(const EntryData* entryData) {
0211 sigma_ = entryData->sigma();
0212
0213 EntryMgr* entryMgr = EntryMgr::getInstance();
0214 if (type_ == "centre" || type_ == "length") {
0215 sigma_ *= entryMgr->getDimOutLengthSig();
0216
0217 } else if (type_ == "angles" || type_ == "angle") {
0218 sigma_ *= entryMgr->getDimOutAngleSig();
0219 }
0220
0221 sigmaOriginalOriginal_ = sigma_;
0222 }
0223
0224
0225 void Entry::fillFromReportOutFileQuality(const EntryData* entryData) { quality_ = entryData->quality(); }
0226
0227
0228
0229
0230 void Entry::fillName(const ALIstring& name) { setName(name); }
0231
0232
0233
0234
0235 void Entry::fillNull() {
0236
0237 value_ = 0.;
0238 valueOriginalOriginal_ = value_;
0239 sigma_ = 0.;
0240 sigmaOriginalOriginal_ = sigma_;
0241 quality_ = 0;
0242 }
0243
0244
0245
0246
0247 void Entry::displace(ALIdouble disp) {
0248 if (ALIUtils::debug >= 9)
0249 std::cout << "ExtraEntry::Displace" << disp << std::endl;
0250 ALIuint entryNo = OptOCurrent()->extraEntryNo(name());
0251
0252 OptOCurrent()->displaceExtraEntry(entryNo, disp);
0253 }
0254
0255
0256
0257
0258 void Entry::displaceOriginal(ALIdouble disp) {
0259 if (ALIUtils::debug >= 9)
0260 std::cout << "ExtraEntry::DisplaceOriginal" << disp << std::endl;
0261 ALIuint entryNo = OptOCurrent()->extraEntryNo(name());
0262
0263 OptOCurrent()->displaceExtraEntryOriginal(entryNo, disp);
0264 }
0265
0266
0267
0268
0269 void Entry::displaceOriginalOriginal(ALIdouble disp) {
0270 if (ALIUtils::debug >= 9)
0271 std::cout << "ExtraEntry::DisplaceOriginalOriginal" << disp << std::endl;
0272 ALIuint entryNo = OptOCurrent()->extraEntryNo(name());
0273
0274 OptOCurrent()->displaceExtraEntryOriginalOriginal(entryNo, disp);
0275 }
0276
0277
0278
0279
0280 Entry::~Entry() {}
0281
0282
0283
0284
0285
0286 void Entry::addFittedDisplacementToValue(const ALIdouble val) {
0287 valueDisplacementByFitting_ += val;
0288 lastAdditionToValueDisplacementByFitting_ = val;
0289 if (ALIUtils::debug >= 3)
0290 std::cout << OptOCurrent()->name() << " " << name() << " Entry::addFittedDisplacementToValue " << val
0291 << " total= " << valueDisplacementByFitting_ << std::endl;
0292
0293
0294 displaceOriginal(val);
0295 OptOCurrent()->resetGlobalCoordinates();
0296 }
0297
0298
0299
0300
0301
0302 void Entry::substractToHalfFittedDisplacementToValue() {
0303 addFittedDisplacementToValue(-lastAdditionToValueDisplacementByFitting_ / 2.);
0304
0305
0306 lastAdditionToValueDisplacementByFitting_ *= -1;
0307
0308 }
0309
0310
0311 ALIdouble Entry::valueDisplaced() const {
0312 ALIuint entryNo = OptOCurrent()->extraEntryNo(name());
0313 if (ALIUtils::debug >= 5)
0314 std::cout << entryNo << " Entry::valueDisplaced " << name() << " in " << OptOCurrent()->name() << " orig "
0315 << OptOCurrent()->ExtraEntryValueOriginalList()[entryNo] << " new "
0316 << OptOCurrent()->ExtraEntryValueList()[entryNo] << std::endl;
0317 return OptOCurrent()->ExtraEntryValueList()[entryNo] - OptOCurrent()->ExtraEntryValueOriginalList()[entryNo];
0318 }
0319
0320
0321 void Entry::resetValueDisplacementByFitting() { valueDisplacementByFitting_ = 0.; }
0322
0323
0324 std::ostream& operator<<(std::ostream& os, const Entry& c) {
0325 os << "ENTRY: " << c.name() << " of type: " << c.type() << std::endl
0326 << " value " << c.value_ << " original " << c.valueOriginalOriginal_ << std::endl
0327 << " sigma " << c.sigma_ << " original " << c.sigmaOriginalOriginal_ << std::endl
0328 << " quality " << c.quality_ << " opto " << (c.OptOCurrent_)->name() << std::endl
0329 << " fitpos " << c.fitPos_ << " valueDisplacementByFitting " << c.valueDisplacementByFitting_
0330 << " lastAdditionToValueDisplacementByFitting " << c.lastAdditionToValueDisplacementByFitting_ << std::endl;
0331
0332 return os;
0333 }
0334
0335
0336 const ALIstring Entry::longName() const { return OptOCurrent_->name() + "/" + name_; }