Program Listing for File ParticleMapsContainer.h

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


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

#include "crpropa/Vector3.h"

namespace crpropa {
class ParticleMapsContainer {
        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();

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

        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)
                return _sumOfWeights;

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