CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Alignment/CocoaModel/src/Entry.cc

Go to the documentation of this file.
00001 //   COCOA class implementation file
00002 //Id:  Entry.cc
00003 //CAT: Model
00004 //
00005 //   History: v1.0 
00006 //   Pedro Arce
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 //@@ Constructor
00021 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00022 Entry::Entry( const ALIstring& type ) : type_(type), fitPos_(-1)
00023 {
00024   //  std::cout << "entry" << std::endl;
00025   //---------- Set displacement by fitting to zero
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   //----- Check format of input file
00040   if (ALIUtils::debug >=4) std::cout << "@@@ Filling entry: " << name() << std::endl;
00041   //--- Check there are 4 attributes
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   /*t
00058   if( name_ == "centre_R" || name_ == "centre_PHI" || name_ == "centre_THE" ){
00059     if( EntryMgr::getInstance()->numberOfEntries() > 0 ) {
00060       std::cerr << "!!!!FATAL ERROR:  Filling entry from 'report.out' while entry is in cylindrical or spherical coordinates is not supported yet. " << OptOCurrent()->name() << " " << name_ << std::endl;
00061       abort();
00062     }
00063   }
00064   */
00065 
00066   ALIdouble fre;
00067   gomgr->getGlobalOptionValue("reportOutReadValue", fre );
00068   if( entryData != 0 && fre == 1) {
00069     //    std::cout << OptOCurrent()->name() << " " << name_ << "call fillFromReportOutFileValue " << type_ <<  std::endl;
00070     fillFromReportOutFileValue( entryData );
00071   } else {
00072     //  std::cout << OptOCurrent()->name() << " " << name_ << "call fillFromInputFileValue " << type_ <<  std::endl;
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   //-  ALIUtils::dumpVS( wordlist, " fillFromInputFileValue " ); //-
00095   ParameterMgr* parmgr = ParameterMgr::getInstance();
00096   //---------- Translate parameter used for value_
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     //d val *= ValueDimensionFactor();
00105   } else { 
00106     //d val = DimensionMgr()::getInstance()->extractValue( wordlist[1], ValueDimensionFactor() );
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   //---------- translate parameter used for sigma_
00126   /*  ALIdouble sig;
00127   char** endptr;
00128   sig = strtod( wordlist[2].c_str(), endptr );
00129   //  ALIint isNumber =  sscanf(wordlist[2].c_str(),"%f",sig);
00130   if ( *endptr == wordlist[2].c_str() ) {
00131   // if ( !isNumber ) { */
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       //      std::cerr << "!!! parameter for sigma not found: " << wordlist[2].c_str() << std::endl;
00137       std::cerr << "!!! parameter for sigma not found: " << wordlist[0] << " " << wordlist[1] << " " <<  wordlist[2] << std::endl;
00138       exit(2);
00139     }
00140     //d    sig *= SigmaDimensionFactor();
00141     //-    std::cout << sig<< " valueparam " << wordlist[2] << std::endl;
00142   } else { 
00143     //d sig = DimensionMgr()::getInstance()->extractValue( wordlist[2], ValueDimensionFactor() );
00144     sig = atof( wordlist[2].c_str() );
00145     // for range studies, make all 'cal' entries 'fix'
00146     ALIdouble rs;
00147     GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00148     gomgr->getGlobalOptionValue("range_studies", rs );
00149     if(rs == 1) sig *= 1.E-6;
00150 
00151     //-    std::cout << sig << " valuem " << wordlist[2] << std::endl;
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   //---------- set _quality
00166   if( wordlist[3] == ALIstring("unk") ) {
00167     quality_ = 2;
00168   } else if( wordlist[3] == ALIstring("cal") ) {
00169     quality_ = 1;
00170     //t  // for range studies, make all 'cal' entries 'fix'
00171     //t ALIdouble rs;
00172     //t Model::getGlobalOptionValue("range_studies", rs );
00173     //t if(rs == 1) quality_ = 0;
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   //------ If sigma_ = 0 make quality_ 'fix'
00182   if( sigma_ == 0) {
00183     //      std::cout << "SIG=0" << std::endl;
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 //@@  Fill the attributes with values read from a 'report.out' file
00195 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00196 void Entry::fillFromReportOutFileValue( EntryData* entryData )
00197 {
00198   value_ = entryData->valueOriginal();
00199   //---- For extra entries, value is not in proper units, as the 'report.out' file does not have the type (length/angle/nodim)
00200   EntryMgr* entryMgr = EntryMgr::getInstance();
00201   //-  std::cout << OptOCurrent()->name() << " " << name_ << " fillFromReportOutFileValue " << type_ << std::endl;
00202   if( type_ == "centre" || type_ == "length" ) {
00203    value_ *= entryMgr->getDimOutLengthVal();
00204    //set valueDisp as it will be used to displace entries
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   //---- For extra entries, value is not in proper units, as the 'report.out' file does not have the type (length/angle/nodim)
00222   EntryMgr* entryMgr = EntryMgr::getInstance();
00223   if( type_ == "centre" || type_ == "length" ) {
00224    sigma_ *= entryMgr->getDimOutLengthSig();
00225    //-   std::cout << " fillFromReportOut " << value_ << " +- " << sigma_ << std::endl;
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 //@@ Fill the name (in derived classes is not simply calling setName)
00242 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00243 void Entry::fillName( const ALIstring& name )
00244 {
00245   setName( name );
00246 }
00247 
00248 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00249 //@@  Fill the attributes  
00250 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00251 void Entry::fillNull()
00252 {
00253   //-  fillName( name );
00254   value_ = 0.;
00255   valueOriginalOriginal_ = value_;
00256   sigma_ = 0.;
00257   sigmaOriginalOriginal_ = sigma_;
00258   quality_ = 0;
00259 
00260 }
00261 
00262 
00263 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00264 //@@ Displace an extra entry (coordinate entries have their own classes) 
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 //@@ Displace an extra entry Original value for iteratin in non linear fit (coordinate entries have their own classes) 
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 //@@ Displace an extra entry OriginalOriginal value for iteratin in non linear fit (coordinate entries have their own classes) 
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 //@@ Destructor
00304 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00305 Entry::~Entry()
00306 {
00307 }
00308 
00309 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00310 //@@ Add fitted displacement to value: save it as valueDisplacementByFitting_, as when the value is asked for, it will get the original value + this displacement
00311 //@@ Then update the rmGlob, centreGlob 
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   //---------- Displace original centre, rotation matrix, ...
00320   displaceOriginal( val );
00321   OptOCurrent()->resetGlobalCoordinates();
00322 
00323 }
00324 
00325 
00326 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00327 //@@ Add fitted displacement to value: save it as theValueDisplacementByFitting, as when the value is asked for, it will get the origianl value + this displacement
00328 //@@ Then update the rmGlob, centreGlob 
00329 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00330 void Entry::substractToHalfFittedDisplacementToValue()
00331 {
00332   addFittedDisplacementToValue( -lastAdditionToValueDisplacementByFitting_/2. );
00333   // addFittedDisplacementToValue( -1.01*theLastAdditionToValueDisplacementByFitting );
00334   //addFittedDisplacementToValue( -theLastAdditionToValueDisplacementByFitting );
00335   lastAdditionToValueDisplacementByFitting_ *= -1;
00336   //  addFittedDisplacementToValue( 0. );
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