/* Incoherent sum of multiple models for unpolarized reflectometry */ static void incoherent_unpolarized_theory(fitinfo *fit) { Real total_weight; /* Total weight of all models */ int i, k; profile p; /* Incoherent model profile */ Real *A, *B, *C, *D; /* Make space for incoherent models. */ extend_work(fit,4*fit->nQ); A = fit->work; B = fit->work + fit->nQ; C = fit->work + 2*fit->nQ; D = fit->work + 3*fit->nQ; /* Incoherent sum of the theory functions. */ profile_init(&p); for (i=0; i < fit->number_incoherent; i++) { profile_reset(&p); model_profile(fit->incoherent_models[i], &p); /* profile_print(&p,NULL); */ if (fit->m.is_magnetic) { #ifdef HAVE_MAGNETIC magnetic_reflectivity(p.n, p.d, p.rho, p.mu,fit->beam.lambda, fit->beam.alignment, p.P, p.expth, fit->beam.Aguide, fit->nQ, fit->fitQ, A, B, C, D); for (k=0; k < fit->nQ; k++) { A[k] = (A[k]+B[k]+C[k]+D[k])/2.; } #else fprintf(stderr,"Need to configure with --enable-magnetic\n"); exit(1); #endif } else { reflectivity(p.n, p.d, p.rho, p.mu, fit->beam.lambda, fit->beam.alignment, fit->nQ, fit->fitQ, A); } for (k=0; k < fit->nQ; k++) { fit->fitA[k] += A[k] * fit->incoherent_weights[i]; } } profile_destroy(&p); /* Incoherent sum of models requires relative model weighting. * The base model is assumed to have weight 1. The remaining * models can have their weights adjusted, with the result * normalized by the total weight. */ total_weight = 1.; for (i=0; i < fit->number_incoherent; i++) { total_weight += fit->incoherent_weights[i]; } for (k=0; k < fit->nQ; k++) { fit->fitA[k] /= total_weight; } }
void __profile_hit(CYG_ADDRWORD pc) { int bucket; if (! profile_enabled ) { if (! profile_reset_pending) { return; } // reset_pending can be set by the gdb script to request resetting // the data. It avoids having to do lots of memory updates via the // gdb protocol, which is too slow. profile_reset_pending = 0; profile_reset(); profile_enabled = 1; } if ((pc >= (CYG_ADDRWORD)profile_hist_hdr.low_pc) && (pc <= (CYG_ADDRWORD)profile_hist_hdr.high_pc)) { bucket = (pc - (CYG_ADDRWORD)profile_hist_hdr.low_pc) >> bucket_shift; if (profile_hist_data[bucket] < (unsigned short)0xFFFF) { profile_hist_data[bucket]++; } }
void model_profile(model *m, profile *p) { int layer, repeat_start, R, R_start, R_end, R_count; profile_reset(p); /* Insert vacuum layers */ if (!profile_extend(p,1)) return; profile_slice(p,10.,m->rho[0],m->mu[0] #ifdef HAVE_MAGNETIC ,m->P[0],m->theta[0] #endif ); add_interface_left(m,p,0,1); p->vacuum_offset = profile_depth(p); /* vacuum interface thickness */ /* initialize R_start, R_end, R_count */ model_repeat(m,R=0,&R_start,&R_end,&R_count); repeat_start = -1; for (layer=1; layer<m->n-1; layer++) { /* Remember where the repeat section starts */ if (layer == R_start+1) repeat_start = p->n; /* Check if we need to repeat */ if (layer == R_end) { /* The interface between repeats is different from the * interface into the first repeat and out of the last * repeat. So instead of repeating R1 R2 R3 R4 as in: * Ln|R1 R2 R3 R4|R1 R2 R3 R4|R1 R2 R3 R4|Ln+1 * we have to repeat R2 R3 R1 as in: * Ln R1*|R2 R3 R4 R1|R2 R3 R4 R1|R2 R3 R4* Ln+1 * with the last repeat only extending from R_start+1 to * R_end-1. * * At this point we have: * Ln R1*|R2 R3 * so we need to add R4 and R1 to complete the repeating * section, then copy that section R_count-2 times (first * repeat is done, last repeat is special), then copy * what we have of the last repeat, leaving us at: * Ln R1* R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 * and layer == R4, so continue as normal. */ int r, repeat_length, repeat_interface; repeat_interface = p->n; /* add interface between repeating sections */ add_layer(m,p,R_end-1,R_end,R_start); add_layer(m,p,R_end,R_start,R_start+1); /* do bulk repeats of R_start+1 to R_start */ assert(repeat_start > 0); repeat_length = p->n - repeat_start; profile_extend(p,R_count*repeat_length); /* make sure there is room */ for (r=1; r < R_count-1; r++) profile_copy(p, repeat_start, repeat_length); /* copy layers from R_start to I_start */ profile_copy(p, repeat_start, repeat_interface-repeat_start); /* Look for next repeat */ model_repeat(m,++R,&R_start,&R_end,&R_count); repeat_start = -1; } add_layer(m,p,layer-1,layer,layer+1); } /* Insert substrate layers */ add_interface_right(m,p,layer-1,layer); if (!profile_extend(p,1)) return; profile_slice(p,10.,m->rho[layer],m->mu[layer] #ifdef HAVE_MAGNETIC ,m->P[layer],m->theta[layer] #endif ); /* Convert polar to cartesian for magnetic layers */ profile_expth(p); }