#ifndef GledCore_LegendreCoefs_H
#define GledCore_LegendreCoefs_H
#include <Glasses/ZGlass.h>
class HPointD;
class TTree;
class LegendreCoefs : public ZGlass
{
MAC_RNR_FRIENDS(LegendreCoefs);
public:
struct Evaluator
{
const LegendreCoefs *fCoefs;
Double_t fScale;
Int_t fLMax;
Evaluator(const LegendreCoefs* lc, Double_t s=1, Int_t lm=-1) :
fCoefs(lc), fScale(s), fLMax(lm) {}
Double_t Eval(Double_t cos_theta, Double_t phi) const;
Double_t Eval(const HPointD& vec) const;
};
struct MultiEval
{
vector<Double_t> fMVec;
vector<Double_t> fPhis;
vector<Int_t> fIdcs;
vector<void*> fUserData;
Int_t fN;
MultiEval() {}
void Init(Int_t n);
void AddPoint (Double_t cos_theta, Double_t phi, void* ud);
void AddPoint (Double_t x, Double_t y, Double_t z, void* ud);
void AddPointUnitR(Double_t x, Double_t y, Double_t z, void* ud);
void Sort();
};
private:
void _init();
protected:
Int_t mLMax;
vector<Double_t> mC;
Double_t& coef(Int_t l, Int_t m) { return mC[l*l + l + m]; }
Double_t sum_m(Int_t l, Int_t m, Double_t cos_mphi, Double_t sin_mphi) const
{
if (m == 0) {
return mC[l*l + l];
} else {
Int_t idx = l*l + l - m;
return mC[idx + 2*m] * cos_mphi + mC[idx] * sin_mphi;
}
}
public:
LegendreCoefs(const Text_t* n="LegendreCoefs", const Text_t* t=0);
virtual ~LegendreCoefs();
void InitRandom(Int_t l_max, Double_t abs_scale=0.1, Double_t pow_scale=2.7);
void InitToValue(Int_t l_max, Double_t value=0);
void SetCoef(Int_t l, Int_t m, Double_t v);
void ReadEgmFile(const TString& egm, Int_t l_max);
Double_t Coef(Int_t l, Int_t m) const { return mC[l*l + l + m]; }
Double_t Eval(Double_t cos_theta, Double_t phi, Int_t l_max=-1) const;
Double_t Eval(const HPointD& vec, Int_t l_max=-1) const;
void EvalMulti(MultiEval& me, Int_t l_max) const;
void MakeRandomSamplingHisto(Int_t max_l=-1, Int_t n_samples=10000,
const TString& canvas_name = "RndSampling",
const TString& canvas_title = "Distribution of LegendreCoef values over random points on sphere");
void MakeThetaGraph(Int_t max_l=-1, Double_t phi=0, Int_t n_div=100,
const TString& canvas_name = "ThetaGraph",
const TString& canvas_title = "Graph of LegendreCoefs values versus theta");
TTree* MakeCoefTree(const TString& name="T", const TString& title="");
#include "LegendreCoefs.h7"
ClassDef(LegendreCoefs, 1);
};
#endif