CMS 3D CMS Logo

Measurement.cc

Go to the documentation of this file.
00001 // COCOA class implementation file
00002 // Id:  Measurement.cc
00003 // CAT: Model
00004 // ---------------------------------------------------------------------------
00005 // History: v1.0 
00006 // Authors:
00007 //   Pedro Arce
00008 
00009 #include "Alignment/CocoaModel/interface/Model.h"
00010 
00011 //#include <algorithm>
00012 #include <iomanip> 
00013 #include <iostream>
00014 #include <algo.h>
00015 
00016 #include "Alignment/CocoaModel/interface/Entry.h"
00017 #include "Alignment/CocoaUtilities/interface/ALIFileIn.h"
00018 #include "Alignment/CocoaModel/interface/Measurement.h"
00019 #include "Alignment/CocoaModel/interface/OpticalObject.h"
00020 #include "Alignment/CocoaModel/interface/ParameterMgr.h"
00021 #ifdef COCOA_VIS
00022 #include "Alignment/CocoaVisMgr/interface/ALIVRMLMgr.h"
00023 #include "Alignment/IgCocoaFileWriter/interface/IgCocoaFileMgr.h"
00024 #endif
00025 #include "CondFormats/OptAlignObjects/interface/OpticalAlignMeasurementInfo.h"
00026 
00027 
00028 ALIdouble Measurement::cameraScaleFactor = 1.;
00029 ALIstring Measurement::theMeasurementsFileName = "";
00030 ALIstring Measurement::theCurrentDate = "99/99/99";
00031 ALIstring Measurement::theCurrentTime = "99:99";
00032 
00033 ALIbool Measurement::only1 = 0;
00034 ALIstring Measurement::only1Date = "";
00035 ALIstring Measurement::only1Time = "";
00036 
00037 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00038 //@@ constructor:
00039 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00040 Measurement::Measurement( const ALIint measdim, ALIstring& type, ALIstring& name ) 
00041 : theDim(measdim), theType(type), theName( name )
00042 {
00043   //  _OptOnames = new ALIstring[theDim];
00044   theValue = new ALIdouble[theDim];
00045   theSigma = new ALIdouble[theDim];
00046   theValueType = new ALIstring[theDim];
00047 
00048   theValueSimulated = new ALIdouble[theDim];
00049   theValueSimulated_orig = new ALIdouble[theDim];
00050   theValueIsSimulated = new ALIbool[theDim];
00051 
00052 }
00053 
00054 
00055 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00056 //@@ construct (read from file)
00057 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00058 void Measurement::construct() 
00059 {
00060 
00061   ALIFileIn& filein = ALIFileIn::getInstance( Model::SDFName() );
00062 
00063   //---------- Read OptOs that take part in this Measurement
00064   std::vector<ALIstring> wordlist;
00065   filein.getWordsInLine( wordlist );
00066 
00067   //--------- Fill the list of names of OptOs that take part in this measurement ( names only )
00068   buildOptONamesList( wordlist );
00069   
00070   if(ALIUtils::debug >= 3) {
00071     std::cout << "@@@@ Reading Measurement " << name() << " TYPE= " << type() << std::endl
00072               << " MEASURED OPTO NAMES: ";
00073     std::ostream_iterator<ALIstring> outs(std::cout," ");
00074     copy(wordlist.begin(), wordlist.end(), outs);
00075     std::cout << std::endl;
00076   }
00077 
00078 
00079   //---------- Read the data 
00080   for ( uint ii=0; ii<dim(); ii++){
00081     filein.getWordsInLine( wordlist );
00082     fillData( ii, wordlist );
00083   }
00084 
00085   if( !valueIsSimulated(0) ) correctValueAndSigma();
00086 
00087   postConstruct();
00088 }
00089 
00090 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00091 void Measurement::constructFromOA( OpticalAlignMeasurementInfo&  measInfo ) 
00092 {
00093   //---- Build wordlist to build object name list
00094   std::vector<std::string> objNames = measInfo.measObjectNames_;
00095   std::vector<std::string>::const_iterator site;
00096   std::vector<ALIstring> wordlist;
00097   for( site = objNames.begin(); site != objNames.end(); site++) {
00098     if( site != objNames.begin() ) wordlist.push_back("&");
00099     wordlist.push_back(*site);
00100   }
00101   //--- Fill the list of names of OptOs that take part in this measurement ( names only )
00102   buildOptONamesList( wordlist );
00103   
00104   if(ALIUtils::debug >= 3) {
00105     std::cout << "@@@@ Reading Measurement " << name() << " TYPE= " << type() << " " << measInfo << std::endl
00106               << " MEASURED OPTO NAMES: ";
00107     std::ostream_iterator<ALIstring> outs(std::cout," ");
00108     copy(wordlist.begin(), wordlist.end(), outs);
00109     std::cout << std::endl;
00110   }
00111 
00112 
00113   //---------- No data, set to simulated_value
00114   for ( uint ii=0; ii<dim(); ii++){
00115     wordlist.clear();
00116     wordlist.push_back( (measInfo.values_)[ii].name_ );
00117     char ctmp[20];
00118     if( measInfo.isSimulatedValue_[ii] ){
00119       if ( ALIUtils::debug >= 5 ) {
00120         std::cout << "Measurement::constructFromOA:  meas value " << ii << " "  << dim() << " = simulated_value" << std::endl;
00121       }
00122       wordlist.push_back("simulated_value");
00123     } else { 
00124       if ( ALIUtils::debug >= 5 ) {
00125         std::cout << "Measurement::constructFromOA:  meas value " << ii << " "  << dim() << " = " << measInfo.values_.size() << std::endl;
00126       }
00127       ALIdouble val = (measInfo.values_)[ii].value_ / valueDimensionFactor(); //in XML  values are without dimensions, so neutralize multiplying by valueDimensionFactor() in fillData
00128       gcvt( val, 10, ctmp );
00129       wordlist.push_back( ctmp );
00130     }
00131     ALIdouble err = (measInfo.values_)[ii].error_ / sigmaDimensionFactor(); //in XML  values are without dimensions, so neutralize multiplying by valueDimensionFactor() in fillData
00132     gcvt( err, 10, ctmp );
00133     wordlist.push_back( ctmp );
00134     std::cout << " sigma " << err << " = " << ctmp << " " << (measInfo.values_)[ii].error_ << std::endl;
00135     //-    wordlist.push_back( "simulated_value" );
00136     //-   wordlist.push_back( "1." );
00137       if ( ALIUtils::debug >= 5 ) ALIUtils::dumpVS(wordlist, " Measurement: calling fillData ");
00138     //-    std::cout << " MEAS INFO " << measInfo << std::endl;
00139     //-   std::cout << ii << " MEAS INFO PARAM " <<  (measInfo.values_)[ii] << std::endl;
00140     //- std::cout << ii << " MEAS INFO PARAM VALUE " <<  (measInfo.values_)[ii].value_ << std::endl;
00141     fillData( ii, wordlist );
00142   }
00143 
00144   postConstruct();
00145 
00146 }
00147 
00148 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00149 void Measurement::postConstruct()
00150 {
00151   //---------- Set name as name of last OptO 
00152   setName();
00153 
00154   //---------- Transform for each Measurement the Measured OptO names to Measured OptO pointers
00155   buildOptOList();
00156 
00157   //---------- Build list of Entries that affect a Measurement 
00158   buildAffectingEntryList();
00159   
00160   //---------- add this measurement to the global list of measurements
00161   Model::addMeasurementToList( this );
00162 
00163   if ( ALIUtils::debug >= 10 ) {
00164     std::cout << Model::MeasurementList().size() << std::endl;
00165   }
00166 }
00167 
00168 
00169 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00170 //@@ Fills a list of names of OpticalObjects that take part in this measurement
00171 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00172 void Measurement::buildOptONamesList( const std::vector<ALIstring>& wl ) 
00173 {
00174 
00175   int NPairs = (wl.size()+1)/2;   // Number of OptO names ( pair of name and '&' )
00176 
00177   //--------- Fill list with names 
00178   for ( int ii=0; ii<NPairs; ii++ ) {
00179     _OptONameList.push_back( wl[ii*2] );
00180     // Check for separating '&'
00181     if (ii != NPairs-1 && wl[2*ii+1] != ALIstring("&") ) {
00182       //      ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00183       std::cerr << "!!! Measured Optical Objects should be separated by '&', not by" 
00184                 << wl[2*ii+1] << std::endl; 
00185       exit(2);
00186     }
00187   }
00188  
00189 }
00190 
00191 
00192 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00193 //@@ Fill the data of measurement coordinate 'coor' with values in 'wordlist'
00194 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00195 void Measurement::fillData( ALIuint coor, const std::vector<ALIstring>& wordlist) 
00196 {
00197   if ( ALIUtils::debug >= 3 ) {
00198     std::cout << "@@ Reading coordinate " << coor << std::endl ;
00199     //-   ostream_iterator<ALIstring> outs(std::cout," ");
00200     //-  copy(wordlist.begin(), wordlist.end(), outs);
00201   }
00202   
00203   ParameterMgr* parmgr = ParameterMgr::getInstance();
00204 
00205   //---------- Check that there are 3 attributes: name, value, error
00206   if( wordlist.size() != 3 ) {
00207     //    ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00208     std::cerr << " Incorrect format for Measurement value:" << std::endl; 
00209     std::ostream_iterator<ALIstring> outs(std::cout," ");
00210     copy(wordlist.begin(), wordlist.end(), outs);
00211     std::cout << std::endl << "There should be three words: name value sigma " << std::endl;
00212     exit(2);
00213   }
00214 
00215   //---------- check coor value
00216   if (coor >= theDim ) {
00217     // ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00218     std::cerr << "Trying to fill Measurement coordinate No "
00219          << coor << " but the dimension is " << theDim << std::endl; 
00220     exit(2);
00221   }
00222 
00223   //---------- set data members 
00224   //----- Set valueType
00225   theValueType[coor] = wordlist[0];
00226 
00227   //----- Set value (translate it if a PARAMETER is used)
00228   ALIdouble val = 0.;
00229   theValueIsSimulated[coor] = 0;
00230   if( !ALIUtils::IsNumber(wordlist[1]) ) {
00231     if ( parmgr->getParameterValue( wordlist[1], val ) == 0 ) {
00232       if( wordlist[1] == ALIstring("simulated_value") ) {
00233         theValueIsSimulated[coor] = 1;
00234       } else {
00235         //      ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00236         std::cerr << "!!! parameter for value not found: " << wordlist[1].c_str() << std::endl;
00237         exit(2);
00238       }
00239     }
00240     //d val *= valueDimensionFactor();
00241   } else {
00242     //d val = DimensionMgr()::getInstance()->extractValue( wordlist[1], ValueDimensionFactor() );
00243     val = atof( wordlist[1].c_str() ); 
00244   }
00245   val *= valueDimensionFactor();
00246   if( ALIUtils::debug >= 3 ) std::cout << "Meas VALUE= " << val << " (ValueDimensionFactor= " << valueDimensionFactor() <<std::endl;
00247 
00248   //----- Set sigma (translate it if a PARAMETER is used)
00249   ALIdouble sig = 0.;
00250   if( !ALIUtils::IsNumber(wordlist[2]) ) {
00251     if ( parmgr->getParameterValue( wordlist[2], sig ) == 0 ) {
00252       // ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00253       std::cerr << "!!! parameter for sigma not found: " << wordlist[2].c_str() << std::endl;
00254       exit(2);
00255     }
00256     //d sig *= sigmaDimensionFactor();
00257   } else {
00258     //    sig = DimensionMgr()::getInstance()->extractValue( wordlist[2], ValueDimensionFactor() );
00259     sig = atof( wordlist[2].c_str() );  
00260   }
00261   sig *= sigmaDimensionFactor();
00262   if( ALIUtils::debug >= 3) std::cout << "SIGMA= " << sig << " (SigmaDimensionFactor= " << sigmaDimensionFactor() <<std::endl;
00263   
00264   //----- set theValue & theSigma
00265   theValue[coor] = val;
00266   theSigma[coor] = sig;
00267 
00268 }
00269 
00270 
00271 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00272 //@@ Once the complete list of OptOs is read, convert OptO names to pointers
00273 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00274 void Measurement::buildOptOList()
00275 {
00276   //-  if ( ALIUtils::debug >= 3 ) std::cout << std::endl << " MEASUREMENT: " << " " << this->name() << std::endl; 
00277   ALIstring twopoints(".."); // .. goes one level up in the tree fo OptOs
00278 
00279 //---------------------------------------- Loop OptONameList
00280   std::vector<ALIstring>::iterator vsite;
00281   for (vsite = _OptONameList.begin();
00282        vsite != _OptONameList.end(); vsite++) {
00283 //----------------------------------- Count how many '..' there are in the name
00284     ALIuint ii = 0;
00285     //    ALIuint slen = (*vsite).length();
00286     ALIuint Ntwopoints = 0;    //---- No '..' in ALIstring
00287     for(;;) {
00288       int i2p = (*vsite).find_first_of( twopoints, 3*ii ); // if it is ., it also finds it!!!
00289       if ( i2p < 0 ) break;
00290       if ( i2p != ALIint(3*ii)) {
00291         std::cerr << i2p << "!!! Bad position of '..' in reference ALIstring: " 
00292              << (*vsite).c_str() << std::endl; 
00293         exit(2);
00294       } else {
00295         Ntwopoints++;
00296         if ( ALIUtils::debug >=9 ) std::cout << "N2p" << Ntwopoints;
00297       }
00298       ii++;   
00299     }     
00300     //------ Substitute '..' by reference (the last OptO in list)
00301     if (Ntwopoints != 0) {
00302       Substitute2p( (*vsite), *(_OptONameList.end()-1), Ntwopoints);
00303     }
00304     //----- Get OpticalObject* that correspond to ALIstring and fill list
00305     ALIstring referenceOptO = (*vsite);
00306     //--- a ':' is used in OptOs that have several possible behavious
00307     ALIint colon = referenceOptO.find(':');
00308     if ( colon != -1 ) {
00309       if (ALIUtils::debug >=99) { 
00310         std::cout << "colon in reference OptO name " << colon << 
00311           referenceOptO.c_str() << std::endl;
00312       }
00313       referenceOptO = referenceOptO.substr( 0, colon );
00314     }
00315     OpticalObject* OptOitem = Model::getOptOByName( referenceOptO );
00316     if ( ALIUtils::debug >= 3 ) std::cout << "Measurement::buildOptOList: OptO in Measurement: " << OptOitem->name() << std::endl;
00317     if ( OptOitem != (OpticalObject*)0 ) {
00318       _OptOList.push_back( OptOitem);
00319     } else {
00320       std::cerr << "!!! Error in Measurement: can't find Optical Object " <<
00321         (*vsite).c_str() << std::endl;
00322       exit(2);
00323     }      
00324   }
00325 }
00326 
00327 
00328 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00329 //@@ Build the list of all entries of every OptO that take part in this 
00330 //@@ Measurement and also the list of all entries of their OptO ancestors
00331 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00332 void Measurement::buildAffectingEntryList(){
00333   
00334   //---------- Loop OptO MeasuredList
00335   std::vector< OpticalObject* >::const_iterator vocite;
00336   for (vocite = _OptOList.begin();
00337        vocite != _OptOList.end(); vocite++) {
00338       addAffectingEntriesFromOptO( *vocite );
00339   }
00340 }
00341 
00342 
00343 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00344 //@@ Get the list of all entries of this OptO that take part in this Measurement
00345 //@@ and of their OptO ancestors
00346 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00347 void Measurement::addAffectingEntriesFromOptO( const OpticalObject* optoP )
00348 {
00349   if(ALIUtils::debug >= 3)  std::cout << "Measurement::addAffectingEntriesFromOptO: OptO taking part in Measurement: " << optoP->name() << std::endl;
00350       //---------- Loop entries in this OptO           
00351   std::vector< Entry* >::const_iterator vecite;
00352   std::vector< Entry* >::const_iterator fvecite;
00353   for (vecite = optoP->CoordinateEntryList().begin();
00354       vecite != optoP->CoordinateEntryList().end(); vecite++) {
00355     //T     if( find( theAffectingEntryList.begin(), theAffectingEntryList.end(), (*vecite) ) == theAffectingEntryList.end() ){
00356     //t      theAffectingEntryList.push_back(*vecite);
00357     //T    }
00358     fvecite = find( theAffectingEntryList.begin(), theAffectingEntryList.end(), (*vecite) );
00359     if (fvecite == theAffectingEntryList.end() ){
00360       theAffectingEntryList.push_back(*vecite);
00361       if(ALIUtils::debug >= 4)  std::cout << "Entry that may affect Measurement: " << (*vecite)->name() << std::endl;
00362     }
00363   }
00364   for (vecite = optoP->ExtraEntryList().begin();
00365       vecite != optoP->ExtraEntryList().end(); vecite++) {
00366     fvecite = find( theAffectingEntryList.begin(), theAffectingEntryList.end(), (*vecite) );
00367     if (fvecite == theAffectingEntryList.end() ){
00368       theAffectingEntryList.push_back(*vecite);
00369       if(ALIUtils::debug >= 4)  std::cout << "Entry that may affect Measurement: " << (*vecite)->name() << std::endl;
00370     }
00371   }
00372   if(optoP->parent() != 0) {
00373     addAffectingEntriesFromOptO( optoP->parent() );
00374   }
00375 }
00376 
00377 
00378 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00379 //@@ Substitute '..' in 'ref' by name of parent OptO ('firstref')
00380 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00381 void Measurement::Substitute2p( ALIstring& ref, const ALIstring& firstref, int Ntwopoints) 
00382 {
00383   // '/' sets hierarchy of OptOs
00384   ALIstring slash("/");
00385   
00386   int pos1st = firstref.length();
00387   // Go back an '/' in firstref for each '..' in ref
00388   for (int ii=0; ii < Ntwopoints; ii++) {
00389       pos1st = firstref.find_last_of( slash, pos1st-1);
00390       if ( ALIUtils::debug >=9 ) std::cout << "pos1st=" << pos1st;
00391   }
00392 
00393   if ( ALIUtils::debug >=9 ) std::cout << "before change ref: " << ref << " 1ref " << firstref << std::endl;
00394   // Substitute name
00395   ref.replace( 0, (Ntwopoints*3)-1, firstref, 0, pos1st);
00396   if ( ALIUtils::debug >=9 ) std::cout << "after change ref: " << ref << " 1ref " << firstref << std::endl;
00397 
00398 }
00399 
00400  
00401 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00402 void Measurement::printStartCalculateSimulatedValue( const Measurement* meas) 
00403 {
00404   std::cout << std::endl << "@@@@ Start calculation of simulated value of " << meas->type() << " Measurement " << meas->name() << std::endl;
00405 }
00406 
00407 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00408 //@@ Calculate the simulated value of the Measurement propagating the LightRay when all the entries have their original values
00409 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00410 void Measurement::calculateOriginalSimulatedValue() 
00411 {
00412   //----------  Calculate the simulated value of the Measurement
00413   calculateSimulatedValue( 1 );
00414 
00415 #ifdef COCOA_VIS
00416   if( ALIUtils::getFirstTime() ) {
00417     GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00418     if(gomgr->GlobalOptions()["VisWriteVRML"] > 1) {
00419       ALIVRMLMgr::getInstance().newLightRay();
00420     }
00421     /*-    if(Model::GlobalOptions()["VisWriteIguana"] > 1) {
00422            IgCocoaFileMgr::getInstance().newLightPath( theName );
00423            } */
00424   }
00425 #endif
00426 
00427   //---------- Set original simulated values to it
00428   //-  if(ALIUtils::debug >= 5) std::cout << "MEAS DIMENSION" << dim() << std::endl;
00429   for ( ALIuint ii = 0; ii < dim(); ii++) {
00430     setValueSimulated_orig( ii, valueSimulated(ii) );
00431     if ( ALIUtils::debug >= 4 ) std::cout << "SETsimuvalOriginal" << valueSimulated(ii) << std::endl;
00432     //----- If Measurement has as value 'simulated_value', set the value to the simulated one
00433     if( valueIsSimulated(ii) == 1 ){
00434       setValue( ii, valueSimulated(ii) );
00435       //- std::cout << ii << " setting value as simulated " <<  valueSimulated(ii) << " " << value(ii) << this << std::endl;
00436     }
00437   }
00438  
00439 }
00440 
00441 
00442 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00443 //@@ 
00444 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00445 void Measurement::DumpBadOrderOptOs() 
00446 {
00447   std::cerr << " Detector can not make measurement with these optical objects " << std::endl;
00448   if (ALIUtils::debug >= 1) {
00449     //  std::vector<OpticalObject*>::iterator voite;
00450     //      for ( voite = _OptOList.begin(); 
00451     //     voite != _OptOList.end(); voite++) {
00452     //    std::cout << (*voite)->type() << " : " << (*voite)->name() << std::endl;
00453     // }
00454     std::vector<ALIstring>::const_iterator vsite;
00455     for ( vsite = OptONameList().begin(); 
00456           vsite != OptONameList().end(); vsite++) {
00457       std::cerr << (*vsite) << " : " ;
00458     }
00459     std::cerr << std::endl;
00460   }
00461   exit(2);
00462 
00463 }
00464 
00465 
00466 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00467 //@@ 
00468 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00469 ALIdouble* Measurement::DerivativeRespectEntry( Entry* entry )
00470 {
00471   //---------- std::vector of derivatives to return
00472   ALIdouble* deriv; 
00473   deriv = new ALIdouble[theDim];
00474   ALIdouble sumderiv;
00475   
00476   //---------- displacement to start with 
00477   ALIdouble displacement = entry->startingDisplacement();
00478   //----- all angles are in radians, so, if displace is not, rescale it before making the displacement 
00479   //-  displacement *= entry->SigmaDimensionFactor();
00480   if( ALIUtils::debug >= 3) std::cout << std::endl << "%%% Derivative w.r.t. entry " << entry->name() << ": displacement = " << displacement << std::endl;
00481   
00482   ALIint count_itera = 0; 
00483   
00484   //---------- Loop decreasing the displacement a factor 2, until the precision set is reached
00485   do {
00486     count_itera++;
00487     entry->displace( displacement );
00488     
00489     if ( ALIUtils::debug >= 5) std::cout << "Get simulated value for displacement " << displacement << std::endl;
00490     calculateSimulatedValue( 0 ); 
00491     
00492     //---------- Get sum of derivatives
00493     sumderiv = 0;   
00494     for ( ALIuint ii = 0; ii < theDim; ii++) {
00495       sumderiv += fabs( theValueSimulated[ii] - theValueSimulated_orig[ii] );
00496       if( ALIUtils::debug >= 4 ) {
00497         std::cout << "iteration " << count_itera << " COOR " << ii 
00498              << " difference =" << ( theValueSimulated[ii] - theValueSimulated_orig[ii] )
00499           //-             << "  " << theValueSimulated[ii] << "  " << theValueSimulated_orig[ii] 
00500              << " derivative = " << (theValueSimulated[ii] - theValueSimulated_orig[ii]) /displacement << " disp " << displacement 
00501              << " sum derivatives = " << sumderiv << std::endl;
00502       }
00503       if( ALIUtils::debug >= 5 ) {
00504         std::cout << " new simu value= " << theValueSimulated[ii] << " orig simu value " << theValueSimulated_orig[ii] << std::endl;
00505        }
00506     }
00507     if (count_itera >= 100) {
00508       std::cerr << "EXITING: too many iterations in derivative, displacement is " <<
00509         displacement << " sum of derivatives is " << sumderiv << std::endl;
00510       exit(3);   
00511     }
00512     displacement /= 2.; 
00513     //-    std::cout << "sumderiv " << sumderiv << " maximu " <<  Fit::maximum_deviation_derivative << std::endl;
00514   }while( sumderiv > ALIUtils::getMaximumDeviationDerivative() );
00515   displacement *= 2; 
00516   
00517   //---------- Enough precision reached: pass result
00518   for ( ALIuint ii = 0; ii < theDim; ii++) {
00519     deriv[ii] = ( theValueSimulated[ii] - theValueSimulated_orig[ii] ) / displacement;
00520     //----- change it to entry sigma dimensions
00521     //     deriv[ii] /= entry->SigmaDimensionFactor();
00522     if( ALIUtils::debug >= 1) std::cout << name() << ": " <<  entry->OptOCurrent()->name() << " " <<  entry->name() << " " << ii << "### DERIVATIVE: " << deriv[ii] <<  std::endl;
00523   }
00524   //-  if(ALIUtils::debug >= 5) std::cout << "END derivative: " << deriv << "disp" << displacement << std::endl;
00525   
00526   //--------------------- Reset _centreGlob and _rmGlob of OptO entry belongs to (and component OptOs)
00527   entry->OptOCurrent()->resetGlobalCoordinates();
00528   
00529   return deriv;
00530  
00531 }
00532 
00533 
00534 
00535 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00536 //@@ destructor
00537 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00538 Measurement::~Measurement() 
00539 {
00540   //  delete[] _name; 
00541   delete[] theValue;
00542   delete[] theSigma;
00543 
00544 }
00545 
00546 
00547 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00548 //@@ get the ':X' that determines how the behaviour of the OptO w.r.t. this Measurement 
00549 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00550 ALIstring Measurement::getMeasuringBehaviour( const std::vector< OpticalObject* >::const_iterator vocite ){ 
00551   std::vector<ALIstring>::const_iterator vscite = _OptONameList.begin() +
00552     ( vocite - _OptOList.begin() ); // point to corresponding name of this OptO
00553   ALIint colon = (*vscite).find(':');
00554   ALIstring behav;
00555   if(colon != -1 ) {
00556     behav = (*vscite).substr(colon+1,(*vscite).size());
00557   } else {
00558     behav = " ";
00559   }
00560   return behav;
00561 }
00562 
00563 
00564 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00565 //@@ Get the previous OptOs in the list of OptO that take part in this measurement
00566 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00567 const OpticalObject* Measurement::getPreviousOptO( const OpticalObject* Popto ) const 
00568 {
00569   //--------- Loop OptOs that take part in this measurement
00570   std::vector<OpticalObject*>::const_iterator vocite;
00571   for( vocite = _OptOList.begin(); vocite != _OptOList.end(); vocite++ ){
00572     if( *vocite == Popto ) {
00573       if( vocite == _OptOList.begin() ) {
00574         std::cerr << " ERROR in  getPreviousOptO of measurement " << name() << std::endl;
00575         std::cerr << " OptO " << Popto->name() << " is the first one " << std::endl;
00576         exit(1);
00577       } else {
00578         return *(vocite-1);
00579       }
00580     }
00581   }
00582   
00583   std::cerr << " ERROR in  getPreviousOptO of measurement " << name() << std::endl;
00584   std::cerr << " OptO " << Popto->name() << " not found " << std::endl;
00585   exit(1);
00586 }
00587 
00588 
00589 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00590 void Measurement::setCurrentDate( const std::vector<ALIstring>& wl )
00591 {
00592 
00593   if( wl.size() != 3 ){
00594     std::cerr << "!!!EXITING: reading DATE of measurements set: it must have three words, it is though " << std::endl;
00595     ALIUtils::dumpVS(wl, " ");
00596    exit(1);
00597   } else if(wl[0] != "DATE:" ){ 
00598     std::cerr << "!!!EXITING: reading DATE of measurements set: first word must be 'DATE:', it is though " << std::endl;
00599     ALIUtils::dumpVS( wl, " ");
00600     exit(1);
00601   } else {
00602     theCurrentDate = wl[1];
00603     theCurrentTime = wl[2];
00604  }
00605 } 
00606 
00607 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00608 void Measurement::copyMeas( Measurement* meas, const std::string& subsstr1, const std::string& subsstr2 )
00609 {
00610   theDim = meas->dim();
00611   theType = meas->type();
00612   theName =  ALIUtils::changeName( meas->name(), subsstr1, subsstr2);
00613 
00614    //  _OptOnames = new ALIstring[theDim];
00615   theValueSimulated = new ALIdouble[theDim];
00616   theValueSimulated_orig = new ALIdouble[theDim];
00617   theValueIsSimulated = new ALIbool[theDim];
00618   theValue = const_cast<ALIdouble*>(meas->value());
00619   theSigma = const_cast<ALIdouble*>(meas->sigma());
00620 
00621   uint ii;
00622   for(ii = 0; ii < theDim; ii++) {
00623     theValueSimulated[ii] = meas->valueSimulated( ii );
00624     theValueSimulated_orig[ii] = meas->valueSimulated_orig( ii );
00625     theValueIsSimulated[ii] = meas->valueIsSimulated( ii );
00626   }
00627 
00628   //--------- Fill the list of names of OptOs that take part in this measurement ( names only )
00629 
00630   std::vector<std::string> wordlist;
00631   std::vector<OpticalObject*>& optolist = meas->OptOList();
00632   ALIuint nOptos = optolist.size();
00633   for ( ALIuint ii = 0; ii < nOptos; ii++ ) {
00634     wordlist.push_back( ALIUtils::changeName( optolist[ii]->longName(), subsstr1, subsstr2) );
00635     std::cout << " copymeas " << ALIUtils::changeName( optolist[ii]->longName(), subsstr1, subsstr2) << std::endl;
00636     if( ii != nOptos -1 ) wordlist.push_back("&");
00637   }
00638 
00639   buildOptONamesList( wordlist );
00640   
00641   if(ALIUtils::debug >= 3) {
00642     std::cout << "@@@@ Reading Measurement " << name() << " TYPE= " << type() << std::endl
00643               << " MEASURED OPTO NAMES: ";
00644     std::ostream_iterator<ALIstring> outs(std::cout," ");
00645     copy(wordlist.begin(), wordlist.end(), outs);
00646     std::cout << std::endl;
00647   }
00648 
00649 
00650   postConstruct();
00651 
00652 }
00653 
00654 
00655 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00656 void Measurement::setName()
00657 {
00658   // name already set by passing one argument with sensor type
00659   if( theName != "" ) return;
00660   if( _OptONameList.size() == 0) {
00661     std::cerr << " !!! Error in your code, you cannot ask for the name of the Measurement before the OptONameList is build " << std::endl;
00662     exit(9);
00663   }
00664   std::vector<ALIstring>::iterator vsite = (_OptONameList.end()-1);
00665   theName = type() + ":" + (*vsite);
00666 }

Generated on Tue Jun 9 17:23:37 2009 for CMSSW by  doxygen 1.5.4