ROOT logo
// $Id: LegendreCoefs.h 2510 2011-08-15 06:41:33Z matevz $

// Copyright (C) 1999-2008, Matevz Tadel. All rights reserved.
// This file is part of GLED, released under GNU General Public License version 2.
// For the licensing terms see $GLEDSYS/LICENSE or http://www.gnu.org/.

#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; // |cos-theta| on input, legend sum on output
    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; // X{G} 7 ValOut()
  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); // X{E} 7 MCWButt()
  void InitToValue(Int_t l_max, Double_t value=0); // X{E} 7 MCWButt()
  void SetCoef(Int_t l, Int_t m, Double_t v);      // X{E} 7 MCWButt()

  void ReadEgmFile(const TString& egm, Int_t l_max); // X{E} 7 MCWButt()

  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"); //! X{ED} 7 MCWButt()

  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"); //! X{ED} 7 MCWButt()

  TTree* MakeCoefTree(const TString& name="T", const TString& title="");

#include "LegendreCoefs.h7"
  ClassDef(LegendreCoefs, 1);
}; // endclass LegendreCoefs

#endif
 LegendreCoefs.h:1
 LegendreCoefs.h:2
 LegendreCoefs.h:3
 LegendreCoefs.h:4
 LegendreCoefs.h:5
 LegendreCoefs.h:6
 LegendreCoefs.h:7
 LegendreCoefs.h:8
 LegendreCoefs.h:9
 LegendreCoefs.h:10
 LegendreCoefs.h:11
 LegendreCoefs.h:12
 LegendreCoefs.h:13
 LegendreCoefs.h:14
 LegendreCoefs.h:15
 LegendreCoefs.h:16
 LegendreCoefs.h:17
 LegendreCoefs.h:18
 LegendreCoefs.h:19
 LegendreCoefs.h:20
 LegendreCoefs.h:21
 LegendreCoefs.h:22
 LegendreCoefs.h:23
 LegendreCoefs.h:24
 LegendreCoefs.h:25
 LegendreCoefs.h:26
 LegendreCoefs.h:27
 LegendreCoefs.h:28
 LegendreCoefs.h:29
 LegendreCoefs.h:30
 LegendreCoefs.h:31
 LegendreCoefs.h:32
 LegendreCoefs.h:33
 LegendreCoefs.h:34
 LegendreCoefs.h:35
 LegendreCoefs.h:36
 LegendreCoefs.h:37
 LegendreCoefs.h:38
 LegendreCoefs.h:39
 LegendreCoefs.h:40
 LegendreCoefs.h:41
 LegendreCoefs.h:42
 LegendreCoefs.h:43
 LegendreCoefs.h:44
 LegendreCoefs.h:45
 LegendreCoefs.h:46
 LegendreCoefs.h:47
 LegendreCoefs.h:48
 LegendreCoefs.h:49
 LegendreCoefs.h:50
 LegendreCoefs.h:51
 LegendreCoefs.h:52
 LegendreCoefs.h:53
 LegendreCoefs.h:54
 LegendreCoefs.h:55
 LegendreCoefs.h:56
 LegendreCoefs.h:57
 LegendreCoefs.h:58
 LegendreCoefs.h:59
 LegendreCoefs.h:60
 LegendreCoefs.h:61
 LegendreCoefs.h:62
 LegendreCoefs.h:63
 LegendreCoefs.h:64
 LegendreCoefs.h:65
 LegendreCoefs.h:66
 LegendreCoefs.h:67
 LegendreCoefs.h:68
 LegendreCoefs.h:69
 LegendreCoefs.h:70
 LegendreCoefs.h:71
 LegendreCoefs.h:72
 LegendreCoefs.h:73
 LegendreCoefs.h:74
 LegendreCoefs.h:75
 LegendreCoefs.h:76
 LegendreCoefs.h:77
 LegendreCoefs.h:78
 LegendreCoefs.h:79
 LegendreCoefs.h:80
 LegendreCoefs.h:81
 LegendreCoefs.h:82
 LegendreCoefs.h:83
 LegendreCoefs.h:84
 LegendreCoefs.h:85
 LegendreCoefs.h:86
 LegendreCoefs.h:87
 LegendreCoefs.h:88
 LegendreCoefs.h:89
 LegendreCoefs.h:90
 LegendreCoefs.h:91
 LegendreCoefs.h:92
 LegendreCoefs.h:93
 LegendreCoefs.h:94
 LegendreCoefs.h:95
 LegendreCoefs.h:96
 LegendreCoefs.h:97
 LegendreCoefs.h:98
 LegendreCoefs.h:99
 LegendreCoefs.h:100
 LegendreCoefs.h:101
 LegendreCoefs.h:102
 LegendreCoefs.h:103