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

AlgAdapt.h

Go to the documentation of this file.
00001 #ifndef ANP_ALGADAPT_H
00002 #define ANP_ALGADAPT_H
00003 
00004 // 
00005 // $Id: AlgAdapt.h,v 1.12 2009/10/15 18:30:13 jyuko Exp $
00006 //
00007 // ABC for algorithm that changes true or reco quantities in a fit
00008 
00009 // Inheriting algorithms have access to 5 base vectors:
00010 //    fCurErr:  current error vector<double>
00011 //    fCurPar:  current parameter vector<double>
00012 //    fDefErr:  default error vector<double>
00013 //    fDefPar:  default parameter vector<double>
00014 //    fParName: optional names of parameters
00015 //
00016 
00017 // C++
00018 #include <iostream>
00019 #include <sstream>
00020 #include <string>
00021 #include <vector>
00022 
00023 // MINOS
00024 #include "Util/UtilString.h"
00025 
00026 // Local
00027 #include "PhysicsNtuple/Handle.h"
00028 #include "PhysicsNtuple/RecoNu.h"
00029 #include "PhysicsNtuple/TrueNu.h"
00030 
00031 class Registry;
00032 class TDirectory;
00033 
00034 namespace Anp
00035 {
00036    class AlgAdapt: public virtual Base
00037    {      
00038    public:      
00039       
00040       AlgAdapt();
00041       virtual ~AlgAdapt();
00042 
00043       virtual bool Init() = 0;
00044       
00045       virtual long double GetPT() const;
00046 
00047       virtual unsigned int GetNPar() const = 0;
00048 
00049       virtual void InitReco(RecoNu &) const;
00050       virtual void InitTrue(TrueNu &) const;
00051 
00052       virtual double GetWeight(const TrueNu &) const;
00053 
00054       virtual void Vary(RecoNu &, const TrueNu &) const;
00055 
00056       virtual const std::vector<double>& Get(const std::string &key) const;
00057 
00058       virtual void Set(const std::vector<double> &dvec, const std::string &key);
00059 
00060       virtual const std::vector<std::string>& GetParName() const;
00061 
00062       virtual void Config(const Registry &) = 0;
00063      
00064       virtual void Print(std::ostream &os = std::cout) const;
00065 
00066       virtual void Read(const std::string &fname);
00067       virtual void Save(const std::string &fname);
00068 
00069    protected:
00070 
00071       void ReadVec(const std::string &prefix, const Registry &reg);
00072 
00073       const std::vector<double> GetVec(const std::string &key, const Registry &reg) const;
00074 
00075       void PrintVec(std::ostream &o, int w=7, int p=5) const;
00076 
00077       void PrintVec(const std::vector<double> &v, std::ostream &o, int w=7, int p=5) const;
00078 
00079    protected:
00080 
00081       //
00082       // !!!Derived classes must not redefine variables defined below!!!
00083       //
00084       std::vector<double> fCurErr;
00085       std::vector<double> fCurPar;
00086       std::vector<double> fDefErr;
00087       std::vector<double> fDefPar;
00088       
00089       std::vector<std::string> fParName;
00090    };
00091 
00092    //
00093    // Global helper functions
00094    //
00095    const std::string ConvertVector2String(const std::vector<double> &dvec);
00096    const std::vector<double> ConvertString2Vector(const std::string &dstr);
00097 
00098    //
00099    // Inlined member functions
00100    //
00101    inline const std::vector<std::string>& AlgAdapt::GetParName() const
00102    {
00103       return fParName;
00104    }
00105 
00106    inline void AlgAdapt::InitReco(RecoNu &) const {}
00107    inline void AlgAdapt::InitTrue(TrueNu &) const {}
00108 
00109    inline double AlgAdapt::GetWeight(const TrueNu &) const { return 1.0; }
00110    inline void AlgAdapt::Vary(RecoNu &, const TrueNu &) const {}
00111 
00112    //
00113    // Template global functions
00114    //
00115 
00116    template<class T>
00117       const std::string ConvertVectorToString(const std::vector<T> &dvec)
00118    {
00119       std::stringstream dstr;
00120       for(typename std::vector<T>::const_iterator dit = dvec.begin(); dit != dvec.end(); ++dit)
00121       {
00122          dstr << *dit;
00123          if(dit + 1 != dvec.end()) dstr << ", ";
00124       }
00125       
00126       return dstr.str();
00127    }
00128 
00129   template<class T>
00130      const std::vector<T> ConvertStringToVector(const std::string &dstr)
00131   {
00132      std::vector<T> dvec;
00133 
00134      //
00135      // Parse into individual strings
00136      //
00137      std::vector<std::string> svec;
00138      UtilString::StringTok(svec, dstr, ", ");
00139      
00140      if(svec.empty())
00141      {
00142         return dvec;
00143      }
00144 
00145      for(unsigned int i = 0; i < svec.size(); ++i)
00146      {
00147         std::stringstream temp;
00148         temp << svec[i];
00149         
00150         T value;
00151         temp >> value;
00152         
00153         if(!temp.fail())
00154         {
00155            dvec.push_back(value);
00156         }
00157         else
00158         {
00159            std::cerr << "Anp::ConvertString2Vector - stringstream >> failed for " << svec[i] << std::endl;
00160         }
00161      }
00162      
00163      return dvec;
00164   }
00165 }
00166 
00167 #endif

Generated on Mon Feb 15 11:06:16 2010 for loon by  doxygen 1.3.9.1