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

DistRandomiser1D.cxx

Go to the documentation of this file.
00001 #include "FastShowerUtils/Normalisers/DistRandomiser1D.h"
00002 
00003 // CLHEP
00004 #include "CLHEP/Matrix/Vector.h"
00005 
00006 #include <cmath>
00007 #include <string>
00008 #include <algorithm>
00009 #include <iostream>
00010 #include <fstream>
00011 namespace FastShower{
00012 
00013   DistRandomiser1D::DistRandomiser1D(const std::string& f){
00014 
00015     // get data form file (histogram)
00016     std::vector<double> v;
00017     readData(f,v);
00018     
00019     // needed to initialise RandGeneral
00020     std::vector<double>::size_type n =  v.size(); // # of bins
00021     double dist[50];
00022     assert(n == 50);
00023     // 
00024     int i;
00025     std::vector<double>::const_iterator itr = v.begin();
00026     std::vector<double>::const_iterator end = v.end();
00027     for (i=0, itr; itr!=end; ++i, ++itr){
00028       dist[i] = (*itr);
00029     }
00030     m_Dist = new RandGeneral(dist, n, 0);
00031   }
00032   //
00033   void
00034   DistRandomiser1D::readData(const std::string& f, std::vector<double>& v) const {
00035     ifstream data(f.c_str());
00036     istream_iterator<int> dataItr(data);
00037     istream_iterator<int> endOfData;
00038     copy(dataItr,endOfData,back_inserter(v));
00039   }
00040   //
00041   double DistRandomiser1D::sample() const {
00042     return 2.0*m_Dist->fire();
00043   }
00044   //
00045   DistRandomiser1D::~DistRandomiser1D(){
00046     delete m_Dist;
00047   }
00048 }//namespace
00049 

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