Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

FunctionRep1.cxx

Go to the documentation of this file.
00001 
00012 // for truncation warning in debug mode
00013 #ifdef _MSC_VER
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016 
00017 #include "FunctionRep.h"
00018 
00019 #include "datasrcs/DataSource.h"
00020 #include "datasrcs/TupleCut.h"
00021 
00022 #include "functions/FunctionBase.h"
00023 
00024 #include "minimizers/Fitter.h"
00025 #include "minimizers/NTupleFCN.h"
00026 #include "projectors/FunctionProjector.h"
00027 #include "reps/LinePointRep.h"
00028 
00029 using std::string;
00030 using std::vector;
00031 
00032 FunctionRep::FunctionRep ( const std::string & name, DataRep * rep )
00033 {
00034   m_target = rep;
00035   m_target -> addObserver ( this );
00036 
00037   const DataSource * ntuple = rep -> getProjectedValues ();
00038   DataSource * nt = const_cast < DataSource * > ( ntuple );
00039   nt -> addObserver ( this );
00040 
00041   m_name = "Function";
00042 
00043   ProjectorBase * target = rep -> getProjector ();    
00044   m_projector = new FunctionProjector ( name, target );
00045   m_rep = new LinePointRep(); 
00046   // The above deleted in ~DataRep()
00047 
00048   m_rep->setColor ( Color::red );
00049   
00050   if ( name == "Linear Sum" ){
00051     m_rep->setSize ( 2 );
00052     m_rep->setColor ( Color::blue );
00053   }
00054 }
00055 
00056 FunctionRep::FunctionRep ( FunctionBase * function, DataRep * rep )
00057 {
00058   m_target = rep;
00059   m_target -> addObserver ( this );
00060 
00061   const DataSource * ntuple = rep -> getProjectedValues ();
00062   DataSource * nt = const_cast < DataSource * > ( ntuple );
00063   nt -> addObserver ( this );
00064 
00065   m_name = "Function";
00066 
00067   ProjectorBase * target = rep -> getProjector ();    
00068   m_projector = new FunctionProjector ( function, target );
00069 
00070   // The following is needed to ensure FunctionProjector::principleErrors()
00071   // knows the correct number of parameters for this function.
00072   dynamic_cast<FunctionProjector *>(m_projector)->saveParameters();
00073 
00074   m_rep = new LinePointRep(); 
00075   // The above deleted in ~DataRep()
00076 
00077   m_rep->setColor ( Color::red );
00078 }
00079 
00080 FunctionRep::
00081 FunctionRep ( const FunctionRep & rep )
00082   : DataRep ( rep )
00083 {
00084   CutList_t::const_iterator first = rep.m_cut_list.begin ();
00085   while ( first != m_cut_list.end () ) {
00086     m_cut_list.push_back ( *first++ );
00087   }
00088 }
00089 
00090 FunctionRep::
00091 ~FunctionRep ()
00092 {
00093   m_target -> removeObserver ( this );
00094 
00095   const DataSource * target = m_target -> getProjectedValues ();
00096   DataSource * nt = const_cast < DataSource * > ( target );
00097   nt -> removeObserver ( this );
00098 }
00099 
00100 DataRep * FunctionRep::clone ()
00101 {
00102   return new FunctionRep ( *this );
00103 }
00104 
00105 bool FunctionRep::hasNTupleBindings () const
00106 {
00107   return false;
00108 }
00109 
00110 void FunctionRep::initializeWith ( DataRep * rep )
00111 {
00112   m_target = rep;
00113   ProjectorBase * projector = rep -> getProjector ();
00114 
00115   FunctionProjector * fp = dynamic_cast < FunctionProjector * > ( m_projector);
00116 
00117   fp->initializeFunction ( projector );
00118 }
00119 
00120 FunctionBase * FunctionRep::getFunction () const
00121 {
00122   FunctionProjector * fp = dynamic_cast < FunctionProjector * > ( m_projector);
00123 
00124   return fp->function ();
00125 }
00126 
00127 DataRep * FunctionRep::getTarget () const
00128 {
00129   return m_target;
00130 }
00131 
00132 void FunctionRep::setTarget ( DataRep * target )
00133 {
00134   m_target = target;
00135 }
00136 
00137 bool FunctionRep::isComposite () const
00138 {
00139   FunctionBase * function = getFunction();
00140   return function->isComposite ();
00141 }
00142 
00143 void
00144 FunctionRep::
00145 setFitter ( Fitter * fitter )
00146 {
00147   FunctionProjector * fp = dynamic_cast < FunctionProjector * > ( m_projector);
00148   assert ( fp );
00149 
00150   fp -> setFitter ( fitter );
00151 }
00152 
00153 Fitter *
00154 FunctionRep::
00155 getFitter ( ) const
00156 {
00157   FunctionProjector * fp = dynamic_cast < FunctionProjector * > ( m_projector);
00158   assert ( fp );
00159 
00160   return fp -> getFitter ();
00161 }
00162 
00166 const string &
00167 FunctionRep::
00168 getFitterName () const
00169 {
00170   Fitter * fitter = getFitter ();
00171 
00172   return fitter -> name ();
00173 }
00174 
00175 bool FunctionRep::fitFunction ( )
00176 {
00177 
00178   FunctionProjector * fp = dynamic_cast < FunctionProjector * > ( m_projector);
00179   assert ( fp );
00180 
00181   bool ok = fp->fitFunction ( );
00182   
00183   notifyObservers ();
00184 
00185   return ok;
00186 }
00187 
00188 const vector< double > & FunctionRep::principleErrors() const
00189 {
00190   FunctionProjector * fp = dynamic_cast < FunctionProjector * > ( m_projector);
00191   assert ( fp );
00192   
00193   return fp->principleErrors();
00194 }
00195 
00196 void FunctionRep::saveParameters ( )
00197 {
00198   FunctionProjector * fp = dynamic_cast < FunctionProjector * > ( m_projector);
00199   fp->saveParameters ();
00200 }
00201 
00202 void FunctionRep::restoreParameters ()
00203 {
00204   FunctionProjector * fp = dynamic_cast < FunctionProjector * > ( m_projector);
00205   fp->restoreParameters ();
00206   notifyObservers ();
00207 }
00208 
00209 void FunctionRep::setParameters ( const std::vector<double> & params )
00210 {
00211   FunctionProjector * fp = dynamic_cast < FunctionProjector * > ( m_projector);
00212   fp->setParameters (params);
00213   notifyObservers ();
00214 }
00215 
00216 void
00217 FunctionRep::
00218 setFixedFlags ( const std::vector < int > & flags )
00219 {
00220   Fitter * fitter = getFitter ();
00221   fitter -> setFixedFlags ( flags );
00222 }
00223 
00224 const vector < string > & FunctionRep::parmNames () const
00225 {
00226   FunctionBase * function = getFunction ();
00227 
00228   return function->parmNames ();
00229 }
00230 
00231 const vector < double > & FunctionRep::parameters () const
00232 {
00233   FunctionBase * function = getFunction ();
00234 
00235   return function->getParameters ();
00236 }
00237 
00238 const vector < int > &
00239 FunctionRep::
00240 getFixedFlags ( ) const
00241 {
00242   const Fitter * fitter = getFitter ();
00243 
00244   return fitter -> getFixedFlags ();
00245 }
00246 
00251 void
00252 FunctionRep::
00253 update ( const Observable * observed )
00254 {
00255   const DataSource * ntuple = dynamic_cast < const DataSource * > ( observed );
00256   if ( ntuple == 0 ) return;
00257 
00258   Fitter * fitter = getFitter ();
00259   if ( fitter != 0 ) {
00260     StatedFCN * fcn = fitter -> getFCN ();
00261     NTupleFCN * ntfcn = dynamic_cast < NTupleFCN * > ( fcn );
00262     ntfcn -> setUseErrors ();
00263   }
00264 
00265   DataRep::update ( observed );
00266 }
00267 
00268 bool
00269 FunctionRep::
00270 isTargetable () const
00271 {
00272   return false;
00273 }
00274 
00275 using namespace hippodraw;
00276 
00277 bool
00278 FunctionRep::
00279 hasAxis ( hippodraw::Axes::Type axis ) const
00280 {
00281   return axis == Axes::X || axis == Axes::Y;
00282 }
00283 
00284 void
00285 FunctionRep::
00286 setCutRange ( const Range & range )
00287 {
00288   if ( m_cut_list.empty () ) {
00289     TupleCut cut;
00290     m_cut_list.push_back ( cut );
00291   }
00292 
00293   TupleCut & cut = m_cut_list.front(); // to be index later
00294   const ProjectorBase * target = m_target -> getProjector ();
00295   const string & label = target -> getXLabel ();
00296   cut.setLabel ( label );
00297   cut.setRange ( range );
00298 
00299   FunctionProjector * projector 
00300     = dynamic_cast < FunctionProjector * > ( m_projector );
00301   assert ( projector != 0 );
00302 
00303   projector -> setFitCut ( & cut );
00304   projector -> setFitRange ( true );
00305 }
00306 
00307 void
00308 FunctionRep::
00309 setCutRange ( bool yes )
00310 {
00311   FunctionProjector * projector 
00312     = dynamic_cast < FunctionProjector * > ( m_projector );
00313   assert ( projector != 0 );
00314 
00315   projector -> setFitRange ( yes );
00316 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3