2 # ctfDeterminationByBayes : $Revision$
5 # Usage : ctfDeterminationByBayes
15 #define GLOBAL_DECLARATION
16 #include "../inc/config.h"
19 #include "ctffuncforbayes.h"
24 #include "ctfDeterminationByBayes.h"
29 typedef struct lctfDeterminationByBayesInfo {
32 } lctfDeterminationByBayesInfo;
34 typedef enum lctfDeterminationByBayesMode {
37 } lctfDeterminationByBayesMode;
40 void DefocusEstimationLoop(ctfDeterminationByBayesInfo info, eosBayes* out, ctfInfo* ctfinfo, ctfforbayes* ctf, intensityforbayes* intensity, defocuslikelihoodforbayes* likelihood, int count, int mode);
43 main(int argc, char* argv[])
49 ctfDeterminationByBayesInfo info;
51 eosBayesDistributionInfo llinfo;
56 intensityforbayes intensity;
57 defocuslikelihoodforbayes likelihood;
64 argCheck(&info, argc, argv);
67 DEBUGPRINT("Program Start\n");
72 leosBayesInit(&out, info.numDistribution, info.numLikelihood, info.mode);
73 eosBayesCondition(info.fptIn, &out, &llinfo, 0);
74 eosBayesPriorWrite(&out,0);
75 DistributionChangeCheck(&out, 0, 0);
78 /*For CTF and intensity*/
79 ctfforbayesInit(info.fptIn2,&ctf,0);
80 intensityforbayesInit(&intensity,ctf.n,info.MTFmode,info.Ainmode,0);
81 spatialfrequencyRead(info.fptIn2,&ctf,info.rmax,info.rmin,0);
82 ctfInfoRead(info.fptIn3,&ctfinfo,"",0);
83 DEBUGPRINT6("kV:%f Cs:%f Ain:%f Cc:%f MTF:%f ctfMode:%ld\n",ctfinfo.kV,ctfinfo.Cs,ctfinfo.Ain,ctfinfo.Cc,ctfinfo.BofMTF,ctfinfo.mode);
84 DEBUGPRINT1("flagIn4:%ld\n",info.flagIn4);
88 Rintermediate = info.rintermediate;
90 /*global carse search*/
91 DEBUGPRINT("carse search start\n");
94 DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax);
95 DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,0,0);
96 DEBUGPRINT("carse search finish\n");
97 ctfforbayescheckIntensityOfMaxPosterior(ctf,out.posterior,out.numDistribution,&ctfinfo,intensity.MTFmode,intensity.Ainmode,1,1);
99 /*MTF,B serch start\n*/
100 DEBUGPRINT("MTF,B search start\n");
102 ctf.rmin = Rintermediate;
103 DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax);
105 DEBUGPRINT("set maxposteriorflag of df, A, k\n");
106 eosBayesMaxposteriorflagSet(&out,0);
107 eosBayesMaxposteriorflagSet(&out,1);
108 eosBayesMaxposteriorflagSet(&out,3);
110 DEBUGPRINT("----maxflagcheck----\n");
112 for(i=0;i<out.numDistribution;i++){
113 printf("dist%d:%d\n",i,(out.posterior[i].maxposteriorflag));
117 DEBUGPRINT("set canstantflag of Ain");
118 out.posterior[5].constantflag = 1;
120 DEBUGPRINT("set resetflag of \n");
121 out.prior[4].resetflag = 1;
122 eosBayesProbabilityReset(info.fptIn,&out,10,0);
124 DEBUGPRINT("set rangechangeflag of B\n");
125 out.posterior[2].rangechangeflag = 1;
126 eosBayesProbabilityRangeChange(&out,100,0.95,0);
128 DistributionChangeCheck(&out, 1, 0);
130 DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,1,1);
131 DEBUGPRINT("MTF,B search finish\n");
133 DEBUGPRINT("----maxflagcheck----\n");
135 for(i=0;i<out.numDistribution;i++){
136 printf("dist%d:%d\n",i,(out.posterior[i].maxposteriorflag));
140 ctfforbayescheckIntensityOfMaxPosterior(ctf,out.posterior,out.numDistribution,&ctfinfo,intensity.MTFmode,intensity.Ainmode,1,1);
144 DEBUGPRINT("df, A, k search start\n");
145 ctf.rmax = Rintermediate;
147 DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax);
149 DEBUGPRINT("set maxposteriorflag of MTF,B\n");
150 // eosBayesMaxposteriorflagSet(&out,2);
151 eosBayesMaxposteriorflagSet(&out,4);
153 DEBUGPRINT("set canstantflag of Ain");
154 // out.posterior[3].constantflag = 1;
155 out.posterior[5].constantflag = 1;
157 DEBUGPRINT("set resetflag of df,k\n");
158 out.prior[0].resetflag = 1;
159 out.prior[1].resetflag = 1;
160 out.prior[3].resetflag = 1;
161 out.prior[5].resetflag = 1;
162 eosBayesProbabilityReset(info.fptIn,&out,1,0);
165 DEBUGPRINT("set rangechangeflag of A\n");
166 out.posterior[2].rangechangeflag = 1;
167 eosBayesProbabilityRangeChange(&out,30,0.98,0);
169 DistributionChangeCheck(&out, 4, 0);
170 DEBUGPRINT("----maxflagcheck----\n");
172 for(i=0;i<out.numDistribution;i++){
173 printf("dist%d:%d\n",i,(out.posterior[i].maxposteriorflag));
177 DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,4,1);
178 DEBUGPRINT("A,df,k search finish\n");
179 ctfforbayescheckIntensityOfMaxPosterior(ctf,out.posterior,out.numDistribution,&ctfinfo,intensity.MTFmode,intensity.Ainmode,1,1);
184 DEBUGPRINT("df, A, k search start\n");
185 ctf.rmax = Rintermediate;
187 DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax);
189 DEBUGPRINT("set maxposteriorflag of MTF,B\n");
190 // eosBayesMaxposteriorflagSet(&out,2);
191 eosBayesMaxposteriorflagSet(&out,4);
193 DEBUGPRINT("set canstantflag of Ain");
194 out.posterior[5].constantflag = 1;
196 DEBUGPRINT("set resetflag of df,k\n");
197 out.prior[0].resetflag = 1;
198 // out.prior[1].resetflag = 1;
199 // out.prior[2].resetflag = 1;
200 out.prior[3].resetflag = 1;
201 eosBayesProbabilityReset(info.fptIn,&out,1,0);
204 DEBUGPRINT("set rangechangeflag of A\n");
205 out.posterior[1].rangechangeflag = 1;
206 out.posterior[2].rangechangeflag = 1;
207 eosBayesProbabilityRangeChange(&out,40,0.98,0);
209 DistributionChangeCheck(&out, 2, 0);
210 DEBUGPRINT("----maxflagcheck----\n");
212 for(i=0;i<out.numDistribution;i++){
213 printf("dist%d:%d\n",i,(out.posterior[i].maxposteriorflag));
217 DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,2,1);
218 DEBUGPRINT("A,df,k search finish\n");
219 ctfforbayescheckIntensityOfMaxPosterior(ctf,out.posterior,out.numDistribution,&ctfinfo,intensity.MTFmode,intensity.Ainmode,1,1);
225 DEBUGPRINT("df serch start\n");
226 ctf.rmax = Rintermediate;
228 DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax);
230 DEBUGPRINT("set maxposteriorflag of defocus,A,B\n");
231 eosBayesMaxposteriorflagSet(&out,1);
232 eosBayesMaxposteriorflagSet(&out,2);
233 eosBayesMaxposteriorflagSet(&out,3);
234 eosBayesMaxposteriorflagSet(&out,4);
236 DEBUGPRINT("set canstantflag of Ain");
237 out.posterior[5].constantflag = 1;
239 DEBUGPRINT("set resetflag of df\n");
240 out.prior[0].resetflag = 1;
241 eosBayesProbabilityReset(info.fptIn,&out,5,0);
242 DistributionChangeCheck(&out, 3, 0);
244 DEBUGPRINT("----maxflagcheck----\n");
246 for(i=0;i<out.numDistribution;i++){
247 printf("dist%d:%d\n",i,(out.posterior[i].maxposteriorflag));
251 DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,3,1);
252 DEBUGPRINT("df search finish\n");
253 ctfforbayescheckIntensityOfMaxPosterior(ctf,out.posterior,out.numDistribution,&ctfinfo,intensity.MTFmode,intensity.Ainmode,1,1);
256 /*MTF and B refinement*/
258 DEBUGPRINT("MTF and B refinement\n");
260 ctf.rmin = Rintermediate;
261 DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax);
263 DEBUGPRINT("set maxposteriorflag of defocus,A,B,k\n");
264 eosBayesMaxposteriorflagSet(&out,0);
265 eosBayesMaxposteriorflagSet(&out,1);
266 eosBayesMaxposteriorflagSet(&out,3);
268 DEBUGPRINT("set canstantflag of Ain");
269 out.posterior[5].constantflag = 1;
271 DEBUGPRINT("set resetflag of MTF\n");
272 out.prior[4].resetflag = 1;
273 eosBayesProbabilityReset(info.fptIn,&out,5,0);
275 DEBUGPRINT("set rangechangeflag of B\n");
276 out.posterior[2].rangechangeflag = 1;
277 eosBayesProbabilityRangeChange(&out,100,0.9,0);
279 DistributionChangeCheck(&out, 4, 0);
281 DEBUGPRINT("----maxflagcheck----\n");
283 for(i=0;i<out.numDistribution;i++){
284 printf("dist%d:%d\n",i,(out.posterior[i].maxposteriorflag));
288 DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,4,1);
289 DEBUGPRINT("MTF refinement finish\n");
290 ctfforbayescheckIntensityOfMaxPosterior(ctf,out.posterior,out.numDistribution,&ctfinfo,intensity.MTFmode,intensity.Ainmode,1,1);
296 >>>>>>> 2a62a3046b5d765cfdcc331395154d3f4a9e081f
299 DEBUGPRINT("df serch 2 start\n");
300 ctf.rmax = Rintermediate;
302 DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax);
304 DEBUGPRINT("set maxposteriorflag of defocus,A,B\n");
305 eosBayesMaxposteriorflagSet(&out,1);
306 eosBayesMaxposteriorflagSet(&out,2);
307 eosBayesMaxposteriorflagSet(&out,3);
308 eosBayesMaxposteriorflagSet(&out,4);
310 DEBUGPRINT("set canstantflag of Ain");
311 out.posterior[5].constantflag = 1;
313 DEBUGPRINT("set resetflag of df\n");
314 out.prior[0].resetflag = 1;
315 eosBayesProbabilityReset(info.fptIn,&out,5,0);
316 DistributionChangeCheck(&out, 5, 0);
318 DEBUGPRINT("----maxflagcheck----\n");
320 for(i=0;i<out.numDistribution;i++){
321 printf("dist%d:%d\n",i,(out.posterior[i].maxposteriorflag));
325 DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,5,1);
326 DEBUGPRINT("df search2 finish\n");
327 ctfforbayescheckIntensityOfMaxPosterior(ctf,out.posterior,out.numDistribution,&ctfinfo,intensity.MTFmode,intensity.Ainmode,1,1);
329 /*defocus refinement*/
331 DEBUGPRINT("defocus refinement start\n");
332 ctf.rmax = Rintermediate;
334 DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax);
336 DEBUGPRINT("set maxposteriorflag of defocus,A,B,MTF\n");
337 out.posterior[0].maxposteriorflag = 0;
338 out.posterior[1].maxposteriorflag = 0;
339 out.posterior[3].maxposteriorflag = 0;
340 // out.posterior[5].maxposteriorflag = 0;
341 // eosBayesMaxposteriorflagSet(&out,2);
342 eosBayesMaxposteriorflagSet(&out,4);
343 // eosBayesMaxposteriorflagSet(&out,5);
345 DEBUGPRINT("set canstantflag of Ain");
346 out.posterior[5].constantflag = 0;
348 DEBUGPRINT("set refmode\n");
349 out.posterior[0].refmode = 1;
350 out.posterior[1].refmode = 1;
351 out.posterior[2].refmode = 1;
352 out.posterior[3].refmode = 1;
353 out.posterior[4].refmode = 0;
354 out.posterior[5].refmode = 0;
356 eosBayesRefinementCondition(info.fptIn,&out,&llinfo,5,0);
357 DistributionChangeCheck(&out, 6, 0);
358 defocusLikelihoodInit(&likelihood,&out,1);
360 DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,6,1);
361 DEBUGPRINT("defocus refinement finish\n");
362 ctfforbayescheckIntensityOfMaxPosterior(ctf,out.posterior,out.numDistribution,&ctfinfo,intensity.MTFmode,intensity.Ainmode,1,1);
364 eosBayesPosteriorWrite(&out,0);
366 ctfforbayesFree(&ctf,&intensity,&likelihood,out.numLikelihood);
373 void DefocusEstimationLoop(ctfDeterminationByBayesInfo info, eosBayes* out, ctfInfo* ctfinfo, ctfforbayes* ctf, intensityforbayes* intensity, defocuslikelihoodforbayes* likelihood, int count,int mode){
376 defocusLikelihoodInit(likelihood,out,mode);
377 DEBUGPRINT("In DefocusEstimationLoop\n");
378 for(i=0;i<info.flagIn4;i++){
380 intensityRead(info.In4[i],intensity,i,0);
381 DEBUGPRINT("ctf start\n");
382 ctfFunctionforbayes(ctf,intensity,out,ctfinfo,likelihood,count,1);
384 DEBUGPRINT("estimate start\n");
385 eosBayesEstimation(out,0);
386 DistributionChangeCheck(out,count,1);
388 DEBUGPRINT("change start\n");
389 eosBayesPosteriortoPrior(out,0);
398 fprintf(stderr, "----- Additional Usage -----\n");