source: Sophya/trunk/Cosmo/RadioBeam/brsrc.cc@ 3803

Last change on this file since 3803 was 3572, checked in by cmv, 17 years ago

char* -> const char* pour regler les problemes de deprecated string const... + comparaison unsigned signed + suppression EVOL_PLANCK rz+cmv 07/02/2009

File size: 3.5 KB
RevLine 
[3160]1#include "brsrc.h"
2#include "srandgen.h"
3#include "fioarr.h"
4#include "vector3d.h"
5
6//=================================================
7BRSourceGen::BRSourceGen()
8{
9 int ns = 3*9*5;
10 freq.SetSize(ns);
11 amp.SetSize(ns);
12 angX.SetSize(ns);
13 angY.SetSize(ns);
14 phase.SetSize(ns);
15
16 amp = 1.;
17 phase = RandomSequence(RandomSequence::Flat, 0., M_PI);
18
19 double fr[3] = {0.1, 0.25, 0.4}; // attention 0 <= f < 0.5
20 int k = 0;
21 for(int kf=0; kf<3; kf++) {
22 for(int ja=-4; ja<=4; ja++) {
23 for(int ia=-2; ia<=2; ia++) {
24 freq(k) = fr[kf];
25 // Pour lambda=50 cm, angle M_PI/12. -> delta phi = 2 pi sur ~ 1.9 m
26 angX(k) = M_PI/12.*(double)ja;
27 // Pour lambda=50 cm, angle M_PI/5000. -> delta phi = 2 pi sur ~ 800 m
28 angY(k) = M_PI/3000.*(double)ia;
29 k++;
30 }
31 }
32 }
33}
34
35BRSourceGen::BRSourceGen(int ns, double maxangXrad, double maxangYrad,
36 double minfreq, double minamp, double maxamp)
37{
38 freq.SetSize(ns);
39 amp.SetSize(ns);
40 angX.SetSize(ns);
41 angY.SetSize(ns);
42 phase.SetSize(ns);
43
44 if (minfreq>=0.5) {
45 cout << "BRSourceGen::BRSourceGen()/Warning minfreq=" << minfreq << " >=0.5 --> =0." << endl;
46 minfreq = 0.;
47 }
48 for(int i=0; i<ns; i++) {
49 freq(i) = minfreq+drand01()*(0.5-minfreq);
50 amp(i) = minamp+drand01()*(maxamp-minamp);
51 angX(i) = drandpm1()*maxangXrad;
52 angY(i) = drandpm1()*maxangYrad;
53 }
54 phase = RandomSequence(RandomSequence::Flat, 0., M_PI);
55}
56
57BRSourceGen::BRSourceGen(vector<double> f, int nsf, double maxangXrad, double maxangYrad,
58 double minfreq, double minamp, double maxamp)
59{
60 int ns = nsf*f.size();
61
62 freq.SetSize(ns);
63 amp.SetSize(ns);
64 angX.SetSize(ns);
65 angY.SetSize(ns);
66 phase.SetSize(ns);
67 if (minfreq>=0.5) {
68 cout << "BRSourceGen::BRSourceGen()/Warning minfreq=" << minfreq << " >=0.5 --> =0." << endl;
69 minfreq = 0.;
70 }
71
72 int j = 0;
[3192]73 for(int k=0; k<(int)f.size(); k++) {
[3160]74 if (f[k] >= 0.5) {
75 cout << "BRSourceGen::BRSourceGen() f[k=" << k << "]=" << f[k] << " >=0.5 ignored " << endl;
76 continue;
77 }
78 for(int i=0; i<nsf; i++) {
79 freq(j) = f[k];
80 amp(j) = minamp+drand01()*(maxamp-minamp);
81 angX(j) = drandpm1()*maxangXrad;
82 angY(j) = drandpm1()*maxangYrad;
83 j++;
84 }
85 }
86 phase = RandomSequence(RandomSequence::Flat, 0., M_PI);
87}
88
89BRSourceGen::BRSourceGen(string ppfname)
90{
91 ReadPPF(ppfname);
92}
93
94void BRSourceGen::WritePPF(string ppfname)
95{
96 POutPersist po(ppfname);
97 po << freq << amp << angX << angY << phase;
98}
99
100void BRSourceGen::ReadPPF(string ppfname)
101{
102 PInPersist pi(ppfname);
103 pi >> freq >> amp >> angX >> angY >> phase;
104}
105
106void BRSourceGen::Print(ostream& os)
107{
108 os << "---- BRSourceGen::Print() - NSources= " << freq.Size() << endl;
109 for(int k=0; k<freq.Size(); k++) {
110 os << k << " - f=" << freq(k) << " amp=" << amp(k) << " angX=" << angX(k)
111 << " rad =" << Angle(angX(k)).ToDegree() << " deg angY="
112 << " rad =" << Angle(angX(k)).ToArcMin() << " arcmin"
113 << " phase=" << phase(k) << endl;
114 }
115}
116
117
118NTuple BRSourceGen::Convert2Table(double freq0)
119{
[3572]120 const char* nomsntsrc[9] = {"num","freq","freqred","amp","angrad","angdeg","phase",
121 "angyrad","angymin"};
[3160]122 NTuple nt(9, nomsntsrc);
123 double xnt[15];
124 for(int kk=0; kk<freq.Size(); kk++) {
125 xnt[0] = kk;
126 xnt[1] = freq(kk)+freq0;
127 xnt[2] = freq(kk);
128 xnt[3] = amp(kk);
129 xnt[4] = angX(kk);
130 xnt[5] = Angle(angX(kk)).ToDegree();
131 xnt[6] = phase(kk);
132 xnt[7] = angY(kk);
133 xnt[8] = Angle(angY(kk)).ToArcMin();
134 nt.Fill(xnt);
135 }
136
137 return nt;
138}
Note: See TracBrowser for help on using the repository browser.