Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "Alignment/CocoaModel/interface/ParameterMgr.h"
00008 #include "Alignment/CocoaUtilities/interface/ALIUtils.h"
00009 #include "Alignment/CocoaModel/interface/ALIUnitsTable.h"
00010 #include <CLHEP/Random/RandGauss.h>
00011 #include <CLHEP/Random/Random.h>
00012 #include <cstdlib>
00013
00014
00015
00016 ParameterMgr* ParameterMgr::theInstance = 0;
00017
00018
00019 ParameterMgr* ParameterMgr::getInstance()
00020 {
00021 if( !theInstance ) {
00022 theInstance = new ParameterMgr;
00023 }
00024
00025 return theInstance;
00026
00027 }
00028
00029
00030
00031 ALIdouble ParameterMgr::getVal( const ALIstring& str, const ALIdouble dimensionFactor )
00032 {
00033
00034 ALIint iast = str.find('*');
00035
00036 if( iast != -1 ) {
00037 ALIstring valstr = str.substr( 0, iast );
00038 ALIstring unitstr = str.substr(iast+1, str.length() );
00039
00040
00041 if( !ALIUtils::IsNumber( valstr ) ) {
00042 std::cerr << " ParameterMgr::getVal of an ALIstring that is not a number: " << valstr << std::endl;
00043 abort();
00044 }
00045
00046
00047 return atof( valstr.c_str() ) * ALIUnitDefinition::GetValueOf(unitstr);
00048 } else {
00049
00050 if( !ALIUtils::IsNumber( str ) ) {
00051
00052 ALIdouble val;
00053 if( getParameterValue( str, val ) ) {
00054 return val;
00055 } else {
00056 std::cerr << " ParameterMgr::getVal of an string that is not a number nor a previous parameter: " << str << std::endl;
00057 abort();
00058 }
00059 }
00060
00061
00062
00063 return atof( str.c_str() ) * dimensionFactor;
00064 }
00065 }
00066
00067
00068
00069 void ParameterMgr::addParameter( const ALIstring& name, const ALIstring& valstr )
00070 {
00071 if( theParameters.find( name ) != theParameters.end() ) {
00072 if( ALIUtils::debug >= 1) std::cerr << "!! WARNING: PARAMETER " << name << " appears twice, it will take first value " << std::endl;
00073 } else {
00074 theParameters[name] = getVal( valstr );
00075 }
00076
00077 }
00078
00079
00080 void ParameterMgr::setRandomSeed( const long seed )
00081 {
00082 CLHEP::HepRandom::setTheSeed( seed );
00083 }
00084
00085
00086
00087 void ParameterMgr::addRandomGaussParameter( const ALIstring& name, const ALIstring& valMean, const ALIstring& valStdDev )
00088 {
00089 if( theParameters.find( name ) != theParameters.end() ) {
00090 if( ALIUtils::debug >= 1) std::cerr << "!! WARNING: PARAMETER " << name << " appears twice, it will take first value " << std::endl;
00091 } else {
00092 ALIdouble mean = getVal( valMean );
00093 ALIdouble stddev = getVal( valStdDev );
00094 ALIdouble val = CLHEP::RandGauss::shoot( mean, stddev );
00095 theParameters[name] = val;
00096 if( ALIUtils::debug >= -2 ) std::cout << " addRandomGaussParameter " << name << " " << valMean << " " << valStdDev << " = " << val << std::endl;
00097 }
00098
00099 }
00100
00101
00102
00103 void ParameterMgr::addRandomFlatParameter( const ALIstring& name, const ALIstring& valMean, const ALIstring& valInterval )
00104 {
00105 if( theParameters.find( name ) != theParameters.end() ) {
00106 if( ALIUtils::debug >= 1) std::cerr << "!! WARNING: PARAMETER " << name << " appears twice, it will take first value " << std::endl;
00107 } else {
00108 ALIdouble mean = getVal( valMean );
00109 ALIdouble interval = getVal( valInterval );
00110 ALIdouble val = CLHEP::HepRandom::getTheEngine()->flat();
00111
00112 val = val * 2*interval + mean-interval;
00113 theParameters[name] = val;
00114 if( ALIUtils::debug >= 2 )std::cout << " addRandomFlatParameter " << name << " " << valMean << " " << valInterval << " = " << val << std::endl;
00115 }
00116
00117 }
00118
00119
00120
00121
00122 ALIint ParameterMgr::getParameterValue( const ALIstring& name, ALIdouble& val )
00123 {
00124
00125
00126 ALIstring namet = name;
00127 ALIint negpar = 1;
00128 if( namet[0] == '-' ) {
00129 negpar = -1;
00130 namet = namet.substr(1, namet.length() );
00131 }
00132
00133
00134 msd::iterator ite = theParameters.find( namet );
00135 if( ite == theParameters.end() ) {
00136
00137
00138
00139
00140
00141 return 0;
00142 } else {
00143 val = (*ite).second * negpar;
00144
00145 return 1;
00146 }
00147
00148 }
00149
00150