Skip to content

Commit

Permalink
Change to using Eigen
Browse files Browse the repository at this point in the history
- Fix model #3
  • Loading branch information
sfegan committed Mar 21, 2016
1 parent f151aea commit 93942ac
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
6 changes: 3 additions & 3 deletions include/simulation/pmt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SignalSource
public:
virtual ~SignalSource();
virtual double rv() = 0;
virtual void rvs(std::vector<double>& n, unsigned size = 1);
virtual Eigen::VectorXd rvs(unsigned size = 1);
};

class PMTSimPolya: public SignalSource
Expand All @@ -49,8 +49,8 @@ class PMTSimPolya: public SignalSource
//virtual void rvs(std::vector<double>& n, unsigned size = 1);

// Slow function to calculate PMF using Prescott (1965).
Eigen::VectorXd calc_pmf(bool log_progress = false,
double precision = 0.0001) const;
Eigen::VectorXd calc_pmf(double precision = 0.0001,
bool log_progress = false) const;

double stage_gain(unsigned istage) const;
double total_gain() const { return total_gain_; }
Expand Down
17 changes: 7 additions & 10 deletions src/simulation/pmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ SignalSource::~SignalSource()
// nothing to see here
}

void SignalSource::rvs(std::vector<double>& n, unsigned size)
Eigen::VectorXd SignalSource::rvs(unsigned size)
{
if(size==0)size = n.size();
else n.resize(size);
Eigen::VectorXd n(size);
for(unsigned irv=0;irv<size;irv++)n[irv] = rv();
return n;
}

calin::ix::simulation::pmt::PMTSimAbbreviatedConfig PMTSimPolya::cta_model_1()
Expand All @@ -65,20 +65,17 @@ calin::ix::simulation::pmt::PMTSimAbbreviatedConfig PMTSimPolya::cta_model_2()
calin::ix::simulation::pmt::PMTSimAbbreviatedConfig PMTSimPolya::cta_model_3()
{
auto config = cta_model_2();
config.set_stage_0_gain(9.1);
config.set_stage_0_prob_skip(0.1);
config.set_stage_0_prob_skip(0.1);
return config;
}


PMTSimPolya::
PMTSimPolya(const calin::ix::simulation::pmt::PMTSimAbbreviatedConfig& config,
math::rng::RNG* rng):
SignalSource(),
rng_(rng), my_rng_(0), napprox_limit_(50)
SignalSource(), rng_(rng), my_rng_(0), napprox_limit_(50)
{
if(config.num_stage()==0)
throw std::runtime_error("PMTSimPolya: number of stages must be positive");
throw std::runtime_error("PMTSimPolya: number of stages must be positive.");

if(rng==nullptr)rng_ = my_rng_ = new RNG();
rng_->save_to_proto(config_.mutable_rng_config());
Expand Down Expand Up @@ -207,7 +204,7 @@ double PMTSimPolya::rv()
// Prescott may not have known about it.

Eigen::VectorXd PMTSimPolya::
calc_pmf(bool log_progress, double precision) const
calc_pmf(double precision, bool log_progress) const
{
std::vector<double> pk(2);
pk[0] = 0;
Expand Down
2 changes: 1 addition & 1 deletion swig/simulation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.

set(CALIN_SWIG_FILES atmosphere.i vs_optics.i)
set(CALIN_SWIG_FILES atmosphere.i vs_optics.i pmt.i)
set(CALIN_SWIG_TARGET simulation)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
Expand Down
2 changes: 0 additions & 2 deletions swig/simulation/pmt.i
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/-*-mode:swig;-*-

/*
calin/simulation/pmt.i -- Stephen Fegan -- 2016-03-21
Expand Down

0 comments on commit 93942ac

Please sign in to comment.