<commit_before>#include <cmath>
#include "CartesianGrid.hpp"
#include "observers.hpp"
#include "Photon.hpp"
#include "Random.hpp"
#include "Directions.hpp"
#include "IDust.hpp"

Photon::Photon( Vector3d const& pos, std::uint64_t cellId, Direction3d const& dir, double weight, std::uint32_t nscat, double fi, double fq, double fu, double fv )
    : pos_{ pos }
    , dir_{ dir }
    , nscat_{ nscat }
    , cellId_{ cellId }
    , weight_{ weight }
    , fi_{ fi }
    , fq_{ fq }
    , fu_{ fu }
    , fv_{ fv }
{}


double Photon::Scatt(IDustCRef dust, Direction3d const& dir, Random* ran)
{
    // cos(Theta), where Theta is angle between incident
    // and outgoing (i.e., observed) photon direction
    double const cosTheta = dir_.vector() * dir.vector();
    double const hgfrac = dust->fraction(cosTheta) / 4. / PI;
       
    Stokes(dust, dir, cosTheta, true, ran);
    return hgfrac;
}


void Photon::Scatt( Model const &m, Directions const &dirs, IGridCRef grid, std::vector<Observer>& observers, Random* ran)
{
    if (nscat_ == m.MonteCarloStart() )
    {
        Photon ph(*this);
        int tflag = 0;
        ph.Stokes( m.dust(), Direction3d(), 0.0, false, ran);
        tflag = grid->movePhotonAtRandomDepth(ph, ran);
        ph.nscat()+=1;
        while ( !tflag && ( ph.nscat() <= m.nscat() ) )
        {
            ph.weight() *= m.dust()->albedo();
            // Do peeling off and project weighted photons into image
            for (Observer& observer : observers)
            {
                grid->peeloff(ph, observer, m.dust());
            }

            // Scatter photon into new direction and update Stokes parameters
            ph.Stokes( m.dust(), Direction3d(), 0.0, false, ran);
            ph.nscat()+=1;
            if (ph.nscat() > m.nscat()) break;
            // Find next scattering location
            tflag = grid->movePhotonAtRandomDepth(ph, ran);
        }
    } else {
        double calpha;
        double hgfrac;
        // normalizing
        double sum=0;
        for (std::uint64_t j=0; j!=dirs.number(); ++j)
        {
            calpha = dir_.vector() * dirs.direction(j);
            sum += dirs.w(j) * m.dust()->fraction(calpha);
        }

        for (std::uint64_t j=0; j!=dirs.number(); ++j)
        {
            // Release photon from point source
            calpha = dir_.vector() * dirs.direction(j);
            hgfrac = m.dust()->fraction(calpha);
            Photon ph0(pos_, cellId_, dir_, weight_ * dirs.w( j )*hgfrac/sum, nscat_+1, fi_, fq_, fu_, fv_ );
            ph0.Stokes(m.dust(), dirs.direction(j), calpha, true, ran);<commit_msg>Rename hgfrac to fraction as it is not connected with <NAME> now<commit_after>#include <cmath>
#include "CartesianGrid.hpp"
#include "observers.hpp"
#include "Photon.hpp"
#include "Random.hpp"
#include "Directions.hpp"
#include "IDust.hpp"

Photon::Photon( Vector3d const& pos, std::uint64_t cellId, Direction3d const& dir, double weight, std::uint32_t nscat, double fi, double fq, double fu, double fv )
    : pos_{ pos }
    , dir_{ dir }
    , nscat_{ nscat }
    , cellId_{ cellId }
    , weight_{ weight }
    , fi_{ fi }
    , fq_{ fq }
    , fu_{ fu }
    , fv_{ fv }
{}


double Photon::Scatt(IDustCRef dust, Direction3d const& dir, Random* ran)
{
    // cos(Theta), where Theta is angle between incident
    // and outgoing (i.e., observed) photon direction
    double const cosTheta = dir_.vector() * dir.vector();
    double const fraction = dust->fraction(cosTheta) / 4. / PI;
       
    Stokes(dust, dir, cosTheta, true, ran);
    return fraction;
}


void Photon::Scatt( Model const &m, Directions const &dirs, IGridCRef grid, std::vector<Observer>& observers, Random* ran)
{
    if (nscat_ == m.MonteCarloStart() )
    {
        Photon ph(*this);
        int tflag = 0;
        ph.Stokes( m.dust(), Direction3d(), 0.0, false, ran);
        tflag = grid->movePhotonAtRandomDepth(ph, ran);
        ph.nscat()+=1;
        while ( !tflag && ( ph.nscat() <= m.nscat() ) )
        {
            ph.weight() *= m.dust()->albedo();
            // Do peeling off and project weighted photons into image
            for (Observer& observer : observers)
            {
                grid->peeloff(ph, observer, m.dust());
            }

            // Scatter photon into new direction and update Stokes parameters
            ph.Stokes( m.dust(), Direction3d(), 0.0, false, ran);
            ph.nscat()+=1;
            if (ph.nscat() > m.nscat()) break;
            // Find next scattering location
            tflag = grid->movePhotonAtRandomDepth(ph, ran);
        }
    } else {
        double calpha;
        double fraction;
        // normalizing
        double sum=0;
        for (std::uint64_t j=0; j!=dirs.number(); ++j)
        {
            calpha = dir_.vector() * dirs.direction(j);
            sum += dirs.w(j) * m.dust()->fraction(calpha);
        }

        for (std::uint64_t j=0; j!=dirs.number(); ++j)
        {
            // Release photon from point source
            calpha = dir_.vector() * dirs.direction(j);
            fraction = m.dust()->fraction(calpha);
            Photon ph0(pos_, cellId_, dir_, weight_ * dirs.w( j )*fraction/sum, nscat_+1, fi_, fq_, fu_, fv_ );
            ph0.Stokes(m.dust(), dirs.direction(j), calpha, true, ran);
{'fraction_non_alphanumeric': 0.14628614628614628, 'fraction_numerical': 0.010206010206010205, 'mean_word_length': 2.2386780905752754, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6111023', 'n_tokens_mistral': 1826, 'n_tokens_neox': 1756, 'n_words': 460}