OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
Ctunes.cpp
Go to the documentation of this file.
1/*****************************************************************************/
2/* */
3/* Class TUNE */
4/* ============== */
5/* */
6/* ASM, September 2001 */
7/*****************************************************************************/
8#include <algorithm>
9#include <cstring>
10#include <iomanip>
11#include <memory>
12#include <vector>
13
14#include "Utility/Inform.h"
15
16#include "Algorithms/Ctunes.h"
17#include "Algorithms/lomb.h"
18
19extern Inform *gmsg;
20
21//RANLIB_class rndm(265314159,4);
22
23
25 ofac(0.0),
26 hifac(0.0),
27 Qmin(0.0),
28 Qmax(0.0)
29/*---------------------------------------------------------------------------*
30 * constructor
31 * ===========
32 *
33 *---------------------------------------------------------------------------*/
34{
35}
36
38/*---------------------------------------------------------------------------*
39 * destructor
40 * ==========
41 *
42 *---------------------------------------------------------------------------*/
43{
44
45 // Do nothing......
46
47}
48
49int TUNE_class::lombAnalysis(std::vector<double> &x, std::vector<double> &y, int /*nhis*/, double Norm)
50/*-----------------------------------------------------------------------------
51 * Launch Lomb analysis and plot results
52 * =======================================
53 *
54 *---------------------------------------------------------------------------*/
55{
56
57 int Ndat = x.size();
58 int i, nout, jmax;
59 int pairc;
60 int datcnt = 0;
61 int stat = 0;
62 double prob, probi;
63 double tofac = 0.8;
64
65 LOMB_TYPE tlom;
66
67 CI_lt p, q;
68
69 std::vector<LOMB_TYPE> lodata, lodata2;
70 /*---------------------------------------------------------------------------*/
71
72 /*
73 * Do Lomb analysis
74 * ================
75 */
76
77 for(int j = 0; j < Ndat; j++) {
78 tlom.x = x[j];
79 tlom.y = y[j];
80 lodata.push_back(tlom);
81 }
82
83 p = lodata.begin();
84 q = lodata.end();
85
86 datcnt = (int) count_if(p, q, Lomb_eq(0.));
87
88 if(datcnt > (q - p - 10)) {
89 *gmsg << "* Just found " << datcnt << " data points that are == 0!" << endl;
90 return(-1);
91 }
92
93 // this parameterset works ok in most cases.....
94 ofac = 4.0;
95 hifac = 0.8;
96 Qmin = 0.2;
97 Qmax = 0.4;
98
99 std::unique_ptr<LOMB_class> la(new LOMB_class(1));
100
101 stat = 0;
102 stat = la->period(&lodata, &lodata2, ofac, hifac, &nout, &jmax, &prob, 0);
103 if(stat != 0) {
104 *gmsg << "* @C3ERROR: Lomb analysis failed!" << endl;
105 return(-1);
106 }
107
108 std::vector<double> pairx(nout);
109 std::vector<double> pairy(nout);
110
111 pairc = 0;
112 for(i = 0; i < nout; i++) {
113 if(lodata2[i].y > 2.) {
114 pairx[pairc] = lodata2[i].x;
115 pairy[pairc] = lodata2[i].y;
116 if((pairy[pairc] > pairy[pairc-1]) &&
117 (pairy[pairc] > lodata2[i+1].y)) {
118 probi = la->signi(&pairy[pairc], &nout, &tofac);
119 if(pairy[pairc] > 4.) {
120 *gmsg << std::fixed
121 << std::setw(12) << std::setprecision(8) << pairx[pairc]*Norm << " "
122 << std::setw(8) << std::setprecision(2) << pairy[pairc] << " "
123 << std::setw(8) << std::setprecision(3) << probi << " "
124 << i << endl;
125 }
126 }
127 pairc++;
128 }
129 }
130
131 *gmsg << "* ===> Max: "
132 << std::fixed
133 << std::setw(12) << std::setprecision(8) << lodata2[jmax].x * Norm << " "
134 << std::setw(8) << std::setprecision(2) << lodata2[jmax].y << " "
135 << endl;
136
137 return(0);
138}
139
140
141int TUNE_class::lombAnalysis(double *x, double *y, int Ndat, int /*nhis*/)
142/*-----------------------------------------------------------------------------
143 * Launch Lomb analysis and plot results
144 * =======================================
145 *
146 *---------------------------------------------------------------------------*/
147{
148 int i, nout, jmax;
149 int pairc;
150 int datcnt = 0;
151 int stat = 0;
152 double prob, probi;
153 double tofac = 0.8;
154
155 LOMB_TYPE tlom;
156
157 CI_lt p, q;
158
159 std::vector<LOMB_TYPE> lodata, lodata2;
160 /*---------------------------------------------------------------------------*/
161
162 *gmsg << "* TUNE_class LombAnalysis requested" << endl;
163
164 /*
165 * Do Lomb analysis
166 * ================
167 */
168
169 for(int j = 0; j < Ndat; j++) {
170 tlom.x = x[j];
171 tlom.y = y[j];
172 lodata.push_back(tlom);
173 }
174
175 p = lodata.begin();
176 q = lodata.end();
177
178 datcnt = count_if(p, q, Lomb_eq(0.));
179
180 if(datcnt > (q - p - 10)) {
181 *gmsg << "* Just found " << datcnt << "data points that are == 0!" << endl;
182 return(-1);
183 }
184
185 // this parameterset works ok in most cases.....
186 ofac = 4.0;
187 hifac = 0.8;
188 Qmin = 0.2;
189 Qmax = 0.4;
190
191 std::unique_ptr<LOMB_class> la(new LOMB_class(1));
192
193 stat = 0;
194 stat = la->period(&lodata, &lodata2, ofac, hifac, &nout, &jmax, &prob, 0);
195 if(stat != 0) {
196 *gmsg << "* @C3ERROR: Lomb analysis failed!" << endl;
197 return(-1);
198 }
199
200 *gmsg << "* =====> jmax = " << jmax << endl;
201
202 std::vector<double> pairx(nout);
203 std::vector<double> pairy(nout);
204
205 *gmsg << "* ********** Peaks in Data: **************" << endl;
206
207 /*
208 ada make histogram
209 hbook1(nhis,"Lomb data",nout,
210 (float)lodata2[0].x,
211 (float)lodata2[nout-1].x);
212
213 */
214 pairc = 0;
215 for(i = 0; i < nout; i++) {
216 /* ada book histogram
217 Hf1(nhis,(float)lodata2[i].x,(float)lodata2[i].y);
218 */
219 if(lodata2[i].y > 2.) {
220 pairx[pairc] = lodata2[i].x;
221 pairy[pairc] = lodata2[i].y;
222 if((pairy[pairc] > pairy[pairc-1]) &&
223 (pairy[pairc] > lodata2[i+1].y)) {
224 probi = la->signi(&pairy[pairc], &nout, &tofac);
225 if(pairy[pairc] > 4.) {
226 *gmsg << std::fixed
227 << std::setw(12) << std::setprecision(8) << pairx[pairc] << " "
228 << std::setw(8) << std::setprecision(2) << pairy[pairc] << " "
229 << std::setw(8) << std::setprecision(3) << probi << " "
230 << i << endl;
231 }
232 }
233 pairc++;
234 }
235 }
236
237 *gmsg << "* ===> Max: "
238 << std::fixed
239 << std::setw(12) << std::setprecision(8) << lodata2[jmax].x << " "
240 << std::setw(8) << std::setprecision(2) << lodata2[jmax].y << " "
241 << endl;
242
243 return(0);
244
245}
Inform * gmsg
Definition Main.cpp:69
Inform * gmsg
Definition Main.cpp:69
std::vector< LOMB_TYPE >::const_iterator CI_lt
Definition lomb.h:17
Inform & endl(Inform &inf)
Definition Inform.cpp:42
double hifac
Definition Ctunes.h:16
int lombAnalysis(double *x, double *y, int Ndat, int nhis)
Definition Ctunes.cpp:141
virtual ~TUNE_class(void)
Definition Ctunes.cpp:37
double Qmax
Definition Ctunes.h:17
double Qmin
Definition Ctunes.h:17
double ofac
Definition Ctunes.h:16
double x
Definition lomb.h:14
double y
Definition lomb.h:14
Definition lomb.h:20