OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
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 <vector>
10 #include <cstring>
11 
12 #include "Utility/Inform.h"
13 
14 #include "Algorithms/Ctunes.h"
15 #include "Algorithms/lomb.h"
16 
17 extern Inform *gmsg;
18 
19 //RANLIB_class rndm(265314159,4);
20 
21 
23  ofac(0.0),
24  hifac(0.0),
25  Qmin(0.0),
26  Qmax(0.0)
27 /*---------------------------------------------------------------------------*
28  * constructor
29  * ===========
30  *
31  *---------------------------------------------------------------------------*/
32 {
33 }
34 
36 /*---------------------------------------------------------------------------*
37  * destructor
38  * ==========
39  *
40  *---------------------------------------------------------------------------*/
41 {
42 
43  // Do nothing......
44 
45 }
46 
47 int TUNE_class::lombAnalysis(std::vector<double> &x, std::vector<double> &y, int /*nhis*/, double Norm)
48 /*-----------------------------------------------------------------------------
49  * Launch Lomb analysis and plot results
50  * =======================================
51  *
52  *---------------------------------------------------------------------------*/
53 {
54 
55  int Ndat = x.size();
56  int i, nout, jmax;
57  int pairc;
58  int datcnt = 0;
59  int stat = 0;
60  double prob, probi;
61  double tofac = 0.8;
62 
63  LOMB_TYPE tlom;
64 
65  CI_lt p, q;
66 
67  char mess[80];
68  LOMB_class *la;
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  memset(mess, '\0', sizeof(mess));
90  sprintf(mess, "Just found %d data points that are == 0!", datcnt);
91  *gmsg << "* " << mess << endl;
92  return(-1);
93  }
94 
95  // this parameterset works ok in most cases.....
96  ofac = 4.0;
97  hifac = 0.8;
98  Qmin = 0.2;
99  Qmax = 0.4;
100 
101  la = new LOMB_class(1);
102 
103  stat = 0;
104  stat = la->period(&lodata, &lodata2, ofac, hifac, &nout, &jmax, &prob, 0);
105  if(stat != 0) {
106  memset(mess, '\0', sizeof(mess));
107  sprintf(mess, "@C3ERROR: Lomb analysis failed!");
108  *gmsg << "* " << mess << endl;
109 
110  delete la;
111  la = NULL;
112  return(-1);
113  }
114 
115  double pairx[nout];
116  double pairy[nout];
117 
118  pairc = 0;
119  for(i = 0; i < nout; i++) {
120  if(lodata2[i].y > 2.) {
121  pairx[pairc] = lodata2[i].x;
122  pairy[pairc] = lodata2[i].y;
123  if((pairy[pairc] > pairy[pairc-1]) &&
124  (pairy[pairc] > lodata2[i+1].y)) {
125  probi = la->signi(&pairy[pairc], &nout, &tofac);
126  if(pairy[pairc] > 4.) {
127  memset(mess, '\0', sizeof(mess));
128  sprintf(mess, "%12.8f %8.2f %8.3f %d", pairx[pairc]*Norm, pairy[pairc], probi, i);
129  *gmsg << "* " << mess << endl;
130  }
131  }
132  pairc++;
133  }
134  }
135 
136  memset(mess, '\0', sizeof(mess));
137  sprintf(mess, " ===> Max: %12.8f %8.3f\n", lodata2[jmax].x * Norm, lodata2[jmax].y);
138  *gmsg << "* " << mess << endl;
139 
140  delete la;
141  la = NULL;
142  return(0);
143 }
144 
145 
146 int TUNE_class::lombAnalysis(double *x, double *y, int Ndat, int /*nhis*/)
147 /*-----------------------------------------------------------------------------
148  * Launch Lomb analysis and plot results
149  * =======================================
150  *
151  *---------------------------------------------------------------------------*/
152 {
153  int i, nout, jmax;
154  int pairc;
155  int datcnt = 0;
156  int stat = 0;
157  double prob, probi;
158  double tofac = 0.8;
159 
160  LOMB_TYPE tlom;
161 
162  CI_lt p, q;
163 
164  char mess[80];
165  LOMB_class *la;
166  std::vector<LOMB_TYPE> lodata, lodata2;
167  /*---------------------------------------------------------------------------*/
168 
169  sprintf(mess, "TUNE_class LombAnalysis requested");
170  *gmsg << "* " << mess << endl;
171 
172  /*
173  * Do Lomb analysis
174  * ================
175  */
176 
177  for(int j = 0; j < Ndat; j++) {
178  tlom.x = x[j];
179  tlom.y = y[j];
180  lodata.push_back(tlom);
181  }
182 
183  p = lodata.begin();
184  q = lodata.end();
185 
186  datcnt = count_if(p, q, Lomb_eq(0.));
187 
188  if(datcnt > (q - p - 10)) {
189  memset(mess, '\0', sizeof(mess));
190  sprintf(mess, "Just found %d data points that are == 0!", datcnt);
191  *gmsg << "* " << mess << endl;
192  return(-1);
193  }
194 
195  // this parameterset works ok in most cases.....
196  ofac = 4.0;
197  hifac = 0.8;
198  Qmin = 0.2;
199  Qmax = 0.4;
200 
201  la = new LOMB_class(1);
202 
203  stat = 0;
204  stat = la->period(&lodata, &lodata2, ofac, hifac, &nout, &jmax, &prob, 0);
205  if(stat != 0) {
206  memset(mess, '\0', sizeof(mess));
207  sprintf(mess, "@C3ERROR: Lomb analysis failed!");
208  *gmsg << "* " << mess << endl;
209 
210  delete la;
211  la = NULL;
212  return(-1);
213  }
214 
215  memset(mess, '\0', sizeof(mess));
216  sprintf(mess, "=====> jmax = %d", jmax);
217  *gmsg << "* " << mess << endl;
218 
219  double pairx[nout];
220  double pairy[nout];
221 
222  memset(mess, '\0', sizeof(mess));
223  sprintf(mess, "\n********** Peaks in Data: **************");
224  *gmsg << "* " << mess << endl;
225 
226  /*
227  ada make histogram
228  hbook1(nhis,"Lomb data",nout,
229  (float)lodata2[0].x,
230  (float)lodata2[nout-1].x);
231 
232  */
233  pairc = 0;
234  for(i = 0; i < nout; i++) {
235  /* ada book histogram
236  Hf1(nhis,(float)lodata2[i].x,(float)lodata2[i].y);
237  */
238  if(lodata2[i].y > 2.) {
239  pairx[pairc] = lodata2[i].x;
240  pairy[pairc] = lodata2[i].y;
241  if((pairy[pairc] > pairy[pairc-1]) &&
242  (pairy[pairc] > lodata2[i+1].y)) {
243  probi = la->signi(&pairy[pairc], &nout, &tofac);
244  if(pairy[pairc] > 4.) {
245  memset(mess, '\0', sizeof(mess));
246  sprintf(mess, "%12.8f %8.2f %8.3f %d", pairx[pairc], pairy[pairc],
247  probi, i);
248  *gmsg << "* " << mess << endl;
249  }
250  }
251  pairc++;
252  }
253  }
254 
255  memset(mess, '\0', sizeof(mess));
256  sprintf(mess, "\n===> Max: %12.8f %8.3f\n", lodata2[jmax].x, lodata2[jmax].y);
257  *gmsg << "* " << mess << endl;
258 
259  delete la;
260  la = NULL;
261 
262  return(0);
263 
264 }
Inform * gmsg
Definition: Main.cpp:62
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:146
virtual ~TUNE_class(void)
Definition: Ctunes.cpp:35
double Qmax
Definition: Ctunes.h:17
double Qmin
Definition: Ctunes.h:17
double ofac
Definition: Ctunes.h:16
TUNE_class()
Definition: Ctunes.cpp:22
Definition: lomb.h:13
double x
Definition: lomb.h:14
double y
Definition: lomb.h:14
Definition: lomb.h:20
double signi(double *peak, int *nout, double *ofac)
Definition: lomb.cpp:221
int period(std::vector< LOMB_TYPE > *indata, std::vector< LOMB_TYPE > *outdata, double ofac, double hifac, int *nout, int *jmax, double *prob, int amp)
Definition: lomb.cpp:34
Definition: Inform.h:42