Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

ProcessedNormalTester.cxx

Go to the documentation of this file.
00001 // ================================================
00002 // Test program for ProcessedNormal
00003 // ================================================
00004 
00005 #include "FastShowerUtils/ProcessedNormalTester.h"
00006 #include "FastShowerUtils/ProcessedNormal.h"
00007 #include "FastShowerUtils/IDistProcessor.h"
00008 #include "FastShowerUtils/LinearProcessor.h"
00009 #include "FastShowerUtils/TestStat.h"
00010 #include <pair.h>
00011 #include <cmath>
00012 
00013 namespace FastShower{
00014   using std::pair;
00015   //**********************************************************     
00016   TestStat ProcessedNormalTester::test(){
00017     m_ts+=this->test1();
00018     return m_ts;
00019   }
00020   //**********************************************************     
00021   TestStat ProcessedNormalTester::test1(){
00022     TestStat ts;
00023     std::vector<pair<double, double> > pars;
00024     pars.push_back( pair<double, double>(1., 0.) );
00025     pars.push_back( pair<double, double>(2., 0.) );
00026     pars.push_back( pair<double, double>(1., 1.) );
00027     
00028     std::vector<pair<double, double> >::const_iterator pptr = pars.begin();
00029     std::vector<pair<double, double> >::const_iterator pend = pars.end();
00030     
00031     const int maxtry = 100000;
00032     const double dmaxtry = static_cast<double>(maxtry);
00033 
00034     for(; pptr!=pend; ++pptr){
00035       double a = (*pptr).first;
00036       double b = (*pptr).second;
00037     
00038       const IDistProcessor* lp = new LinearProcessor(a, b);
00039       ProcessedNormal pn;
00040 
00041       int i        = 0;
00042       double sum   = 0.;
00043       double sumsq = 0.;
00044       double samp;
00045 
00046       for(; i!=maxtry; ++i){
00047         samp=pn.sample(lp);
00048         //      cout<< "a, b, samp "<<a<<" "<<b<<" "<<samp<<endl;
00049         sum+=samp;
00050         sumsq+=samp*samp;
00051       }
00052 
00053       double mean = sum/dmaxtry;
00054       double var= (sumsq/dmaxtry)-( mean*mean );
00055       
00056       //      cout<<"a,b "<<a<<" "<<b<<endl;
00057       //      cout<<"mean, var: "<<mean<<" "<<var<<endl;
00058       
00059       (abs(mean-b)<0.01 && abs(var-(a*a))<0.1) ? ts.incPass():ts.incFail();
00060     }
00061       return ts;
00062   }
00063   //**********************************************************     
00064   void ProcessedNormalTester::results() const{
00065     cout<<"ProcessedNormalTester: "<<m_ts;
00066     if(!m_ts) cout<<" Failures! ";
00067     cout<<endl;
00068   }
00069   
00070 }//namespace
00071 
00072 
00073 
00074 
00075 
00076 

Generated on Tue Mar 18 11:50:04 2003 for FastShowerUtils by doxygen1.3-rc1