Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "Alignment/CocoaModel/interface/Entry.h"
00009 #include "Alignment/CocoaModel/interface/Model.h"
00010 #include "Alignment/CocoaModel/interface/OpticalObject.h"
00011 #include "Alignment/CocoaUtilities/interface/ALIFileIn.h"
00012 #include "Alignment/CocoaUtilities/interface/ALIUtils.h"
00013 #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
00014 #include "Alignment/CocoaModel/interface/ParameterMgr.h"
00015 #include "Alignment/CocoaModel/interface/EntryMgr.h"
00016 #include "Alignment/CocoaModel/interface/EntryData.h"
00017 #include <cstdlib>
00018
00019
00020
00021
00022 Entry::Entry( const ALIstring& type ) : type_(type), fitPos_(-1)
00023 {
00024
00025
00026 valueDisplacementByFitting_ = 0.;
00027 if( ALIUtils::debug >= 5 ) std::cout << this << " theValueDisplacementByFitting set " << valueDisplacementByFitting_ << std::endl;
00028 }
00029
00030
00031
00032 void Entry::fill( const std::vector<ALIstring>& wordlist )
00033 {
00034
00035 ALIdouble byshort;
00036 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00037 gomgr->getGlobalOptionValue("reportOutEntriesByShortName", byshort );
00038
00039
00040 if (ALIUtils::debug >=4) std::cout << "@@@ Filling entry: " << name() << std::endl;
00041
00042 if ( wordlist.size() != 4 ) {
00043 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00044 ALIUtils::dumpVS( wordlist, " !!! Incorrect format for Entry:", std::cerr );
00045 std::cerr << std::endl << " There should be four words: name value sigma quality " << std::endl;
00046 exit(2);
00047 }
00048
00049 EntryData* entryData;
00050 if( byshort == 0 ) {
00051 entryData = EntryMgr::getInstance()->findEntryByLongName( OptOCurrent()->longName(), name() );
00052 } else {
00053 entryData = EntryMgr::getInstance()->findEntryByShortName( OptOCurrent()->longName(), name() );
00054 }
00055 if(ALIUtils::debug >= 5) std::cout << " entryData " << entryData << " " << OptOCurrent()->longName() << " " << name() << std::endl;
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 ALIdouble fre;
00067 gomgr->getGlobalOptionValue("reportOutReadValue", fre );
00068 if( entryData != 0 && fre == 1) {
00069
00070 fillFromReportOutFileValue( entryData );
00071 } else {
00072
00073 fillFromInputFileValue( wordlist );
00074 }
00075 gomgr->getGlobalOptionValue("reportOutReadSigma", fre );
00076 if( entryData != 0 && fre == 1) {
00077 fillFromReportOutFileSigma( entryData );
00078 } else {
00079 fillFromInputFileSigma( wordlist );
00080 }
00081 gomgr->getGlobalOptionValue("reportOutReadQuality", fre );
00082 if( entryData != 0 && fre == 1) {
00083 fillFromReportOutFileQuality( entryData );
00084 } else {
00085 fillFromInputFileQuality( wordlist );
00086 }
00087 }
00088
00089
00090
00091 void Entry::fillFromInputFileValue( const std::vector<ALIstring>& wordlist )
00092 {
00093
00094
00095 ParameterMgr* parmgr = ParameterMgr::getInstance();
00096
00097 ALIdouble val = 0.;
00098 if ( !ALIUtils::IsNumber( wordlist[1] ) ) {
00099 if ( parmgr->getParameterValue( wordlist[1], val ) == 0 ) {
00100 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00101 std::cerr << "!!! parameter for value not found: " << wordlist[1].c_str() << std::endl;
00102 exit(2);
00103 }
00104
00105 } else {
00106
00107 val = atof( wordlist[1].c_str() );
00108 }
00109 val *= ValueDimensionFactor();
00110 if ( ALIUtils::debug >= 4 ) {
00111 std::cout << "VALUE = " << val << " (ValueDimensionFactor= " << ValueDimensionFactor() <<std::endl;
00112 }
00113
00114 value_ = val;
00115 valueOriginalOriginal_ = value_;
00116
00117
00118 }
00119
00120
00121 void Entry::fillFromInputFileSigma( const std::vector<ALIstring>& wordlist )
00122 {
00123
00124 ParameterMgr* parmgr = ParameterMgr::getInstance();
00125
00126
00127
00128
00129
00130
00131
00132 ALIdouble sig = 0.;
00133 if ( !ALIUtils::IsNumber( wordlist[2] ) ) {
00134 if ( parmgr->getParameterValue( wordlist[2], sig ) == 0 ) {
00135 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00136
00137 std::cerr << "!!! parameter for sigma not found: " << wordlist[0] << " " << wordlist[1] << " " << wordlist[2] << std::endl;
00138 exit(2);
00139 }
00140
00141
00142 } else {
00143
00144 sig = atof( wordlist[2].c_str() );
00145
00146 ALIdouble rs;
00147 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00148 gomgr->getGlobalOptionValue("range_studies", rs );
00149 if(rs == 1) sig *= 1.E-6;
00150
00151
00152 }
00153 sig *= SigmaDimensionFactor();
00154 if (ALIUtils::debug >= 4) {
00155 std::cout << "SIGMA = " << sig << " (SigmaDimensionFactor= " << SigmaDimensionFactor() << std::endl;
00156 }
00157 sigma_ = sig;
00158 sigmaOriginalOriginal_ = sigma_;
00159
00160 }
00161
00162
00163 void Entry::fillFromInputFileQuality( const std::vector<ALIstring>& wordlist )
00164 {
00165
00166 if( wordlist[3] == ALIstring("unk") ) {
00167 quality_ = 2;
00168 } else if( wordlist[3] == ALIstring("cal") ) {
00169 quality_ = 1;
00170
00171
00172
00173
00174 } else if( wordlist[3] == ALIstring("fix") ) {
00175 quality_ = 0;
00176 } else {
00177 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00178 std::cerr << " quality should be 'unk' or 'cal' or 'fix', instead of " << wordlist[3] << std::endl;
00179 exit(3);
00180 }
00181
00182 if( sigma_ == 0) {
00183
00184 quality_ = 0;
00185 }
00186 if ( ALIUtils::debug >= 4 ) std::cout << OptOCurrent()->name() << " " << name() << " " << sigma_ << "QUALITY:" << quality_ << std::endl;
00187
00188 sigmaOriginalOriginal_ = sigma_;
00189
00190 }
00191
00192
00193
00194
00195
00196 void Entry::fillFromReportOutFileValue( EntryData* entryData )
00197 {
00198 value_ = entryData->valueOriginal();
00199
00200 EntryMgr* entryMgr = EntryMgr::getInstance();
00201
00202 if( type_ == "centre" || type_ == "length" ) {
00203 value_ *= entryMgr->getDimOutLengthVal();
00204
00205 entryData->setValueDisplacement( entryData->valueDisplacement() * entryMgr->getDimOutLengthVal());
00206 if(ALIUtils::debug >= 5) std::cout << " fillFromReportOut " << OptOCurrent()->name() << " " << name() << "" << value_ << " disp " << entryData->valueDisplacement() * entryMgr->getDimOutLengthVal() << std::endl;
00207 }else if( type_ == "angles" || type_ == "angle" ) {
00208 value_ *= entryMgr->getDimOutAngleVal();
00209 entryData->setValueDisplacement( entryData->valueDisplacement() * entryMgr->getDimOutAngleVal());
00210 if(ALIUtils::debug >= 5) std::cout << " fillFromReportOut " << OptOCurrent()->name() << " " << name() << "" << value_ << " disp " << entryData->valueDisplacement() * entryMgr->getDimOutAngleVal() << std::endl;
00211 }
00212
00213 valueOriginalOriginal_ = value_;
00214
00215 }
00216
00217
00218 void Entry::fillFromReportOutFileSigma( const EntryData* entryData )
00219 {
00220 sigma_ = entryData->sigma();
00221
00222 EntryMgr* entryMgr = EntryMgr::getInstance();
00223 if( type_ == "centre" || type_ == "length" ) {
00224 sigma_ *= entryMgr->getDimOutLengthSig();
00225
00226 }else if( type_ == "angles" || type_ == "angle" ) {
00227 sigma_ *= entryMgr->getDimOutAngleSig();
00228 }
00229
00230 sigmaOriginalOriginal_ = sigma_;
00231
00232 }
00233
00234
00235 void Entry::fillFromReportOutFileQuality( const EntryData* entryData )
00236 {
00237 quality_ = entryData->quality();
00238 }
00239
00240
00241
00242
00243 void Entry::fillName( const ALIstring& name )
00244 {
00245 setName( name );
00246 }
00247
00248
00249
00250
00251 void Entry::fillNull()
00252 {
00253
00254 value_ = 0.;
00255 valueOriginalOriginal_ = value_;
00256 sigma_ = 0.;
00257 sigmaOriginalOriginal_ = sigma_;
00258 quality_ = 0;
00259
00260 }
00261
00262
00263
00264
00265
00266 void Entry::displace( ALIdouble disp )
00267 {
00268 if(ALIUtils::debug>=9) std::cout << "ExtraEntry::Displace" << disp <<std::endl;
00269 ALIuint entryNo = OptOCurrent()->extraEntryNo( name() );
00270
00271 OptOCurrent()->displaceExtraEntry( entryNo, disp );
00272
00273 }
00274
00275
00276
00277
00278
00279 void Entry::displaceOriginal( ALIdouble disp )
00280 {
00281 if(ALIUtils::debug>=9) std::cout << "ExtraEntry::DisplaceOriginal" << disp <<std::endl;
00282 ALIuint entryNo = OptOCurrent()->extraEntryNo( name() );
00283
00284 OptOCurrent()->displaceExtraEntryOriginal( entryNo, disp );
00285
00286 }
00287
00288
00289
00290
00291
00292 void Entry::displaceOriginalOriginal( ALIdouble disp )
00293 {
00294 if(ALIUtils::debug>=9) std::cout << "ExtraEntry::DisplaceOriginalOriginal" << disp <<std::endl;
00295 ALIuint entryNo = OptOCurrent()->extraEntryNo( name() );
00296
00297 OptOCurrent()->displaceExtraEntryOriginalOriginal( entryNo, disp );
00298
00299 }
00300
00301
00302
00303
00304
00305 Entry::~Entry()
00306 {
00307 }
00308
00309
00310
00311
00312
00313 void Entry::addFittedDisplacementToValue( const ALIdouble val )
00314 {
00315 valueDisplacementByFitting_ += val;
00316 lastAdditionToValueDisplacementByFitting_ = val;
00317 if( ALIUtils::debug >= 3 ) std::cout << OptOCurrent()->name() << " " << name() << " Entry::addFittedDisplacementToValue " << val << " total= " << valueDisplacementByFitting_ << std::endl;
00318
00319
00320 displaceOriginal( val );
00321 OptOCurrent()->resetGlobalCoordinates();
00322
00323 }
00324
00325
00326
00327
00328
00329
00330 void Entry::substractToHalfFittedDisplacementToValue()
00331 {
00332 addFittedDisplacementToValue( -lastAdditionToValueDisplacementByFitting_/2. );
00333
00334
00335 lastAdditionToValueDisplacementByFitting_ *= -1;
00336
00337
00338 }
00339
00340
00341
00342 ALIdouble Entry::valueDisplaced() const
00343 {
00344 ALIuint entryNo = OptOCurrent()->extraEntryNo( name() );
00345 if(ALIUtils::debug >= 5) std::cout << entryNo << " Entry::valueDisplaced " << name() << " in " << OptOCurrent()->name()
00346 << " orig " << OptOCurrent()->ExtraEntryValueOriginalList()[entryNo] << " new " << OptOCurrent()->ExtraEntryValueList()[entryNo] << std::endl;
00347 return OptOCurrent()->ExtraEntryValueList()[entryNo] - OptOCurrent()->ExtraEntryValueOriginalList()[entryNo];
00348 }
00349
00350
00351 void Entry::resetValueDisplacementByFitting()
00352 {
00353 valueDisplacementByFitting_ = 0.;
00354 }
00355
00356
00357 std::ostream& operator << (std::ostream& os, const Entry& c)
00358 {
00359
00360 os << "ENTRY: " << c.name() << " of type: " << c.type() << std::endl
00361 << " value " << c.value_ << " original " << c.valueOriginalOriginal_ << std::endl
00362 << " sigma " << c.sigma_ << " original " << c.sigmaOriginalOriginal_ << std::endl
00363 << " quality " << c.quality_ << " opto " << (c.OptOCurrent_)->name() << std::endl
00364 << " fitpos " << c.fitPos_ << " valueDisplacementByFitting " << c.valueDisplacementByFitting_ << " lastAdditionToValueDisplacementByFitting " << c.lastAdditionToValueDisplacementByFitting_ << std::endl;
00365
00366 return os;
00367
00368 }
00369
00370
00371 const ALIstring Entry::longName() const
00372 {
00373 return OptOCurrent_->name()+"/"+name_;
00374 }
00375
00376