Program Listing for File ParticleMapsContainer.h

Return to documentation for file (include/crpropa/magneticLens/ParticleMapsContainer.h)

#ifndef CRPROPA_PARTICLEMAPSCONTAINER_HH
#define CRPROPA_PARTICLEMAPSCONTAINER_HH

#include <map>
#include <vector>
#include "crpropa/magneticLens/Pixelization.h"
#include "crpropa/magneticLens/MagneticLens.h"

#include "crpropa/Vector3.h"

namespace crpropa {
class ParticleMapsContainer {
private:
        std::map<int, std::map <int, double*> > _data;
        Pixelization _pixelization;
        double _deltaLogE;
        double _bin0lowerEdge;

        // get the bin number of the energy
        int energy2Idx(double energy) const;
        double idx2Energy(int idx) const;

        // weights of the particles
        double _sumOfWeights;
        std::map<int, double > _weightsPID;
        std::map<int, map<int, double> > _weights_pidEnergy;

        // lazy update of weights
        bool _weightsUpToDate;
        void _updateWeights();

public:
        ParticleMapsContainer(double deltaLogE = 0.02, double bin0lowerEdge = 17.99) : _deltaLogE(deltaLogE), _bin0lowerEdge(bin0lowerEdge), _pixelization(6), _weightsUpToDate(false), _sumOfWeights(0) {
        }
        ~ParticleMapsContainer();

        size_t getNumberOfPixels() {
                return _pixelization.getNumberOfPixels();
        }

        double *getMap(const int particleId, double energy);

        void addParticle(const int particleId, double energy, double galacticLongitude, double galacticLatitude, double weight = 1);
        void addParticle(const int particleId, double energy, const Vector3d &v, double weight = 1);

        std::vector<int> getParticleIds();

        std::vector<double> getEnergies(int pid);

        void applyLens(MagneticLens &lens);;

        void getRandomParticles(size_t N, vector<int> &particleId,
                vector<double> &energy, vector<double> &galacticLongitudes,
                vector<double> &galacticLatitudes);

        bool placeOnMap(int pid, double energy, double &galacticLongitude, double &galacticLatitude);

        void forceWeightUpdate();

        double getSumOfWeights() {
                if (!_weightsUpToDate)
                        _updateWeights();
                return _sumOfWeights;
        }

        double getWeight(int pid, double energy) {
                if (!_weightsUpToDate)
                        _updateWeights();
                return _weights_pidEnergy[pid][energy2Idx(energy)];
        }
};
} // namespace crpropa

#endif // CRPROPA_PARTICLEMAPSCONTAINER_HH