source: Sophya/trunk/FrEROS/AnaLC/nbsreadu_bosse.cc@ 3801

Last change on this file since 3801 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

  • Property svn:executable set to *
File size: 10.1 KB
Line 
1/* definitions */
2#define NbossMAX 400
3/* type de recherche de bosse */
4#define BOSSEN
5/* define FILTMED */
6
7#include "sopnamsp.h"
8#include "machdefs.h"
9#include <stdlib.h>
10#include <math.h>
11#include <stdio.h>
12#include <string.h>
13
14#include "nomfits.h"
15#include "fsvcache.h"
16#include "nbtri.h"
17#include "nbrandom.h"
18#include "nbmath.h"
19#include "fmath.h"
20#include "filtccd.h"
21#include "hbook.h"
22#include "fsvst.h"
23#include "transfost.h"
24#include "nbsread.h"
25#include "nbgene.h"
26
27#include "ntuple.h"
28
29void FILL_USER(void);
30
31float *TimeU[NCOULMX],*FluxU[NCOULMX],*eFluxU[NCOULMX]
32 ,*FluxflU[NCOULMX],*eFluxflU[NCOULMX];
33int_4 npt[NCOULMX];
34int nslues,nsgood;
35
36POutPersist *pos_ = NULL;
37NTuple *ntbosse = NULL;
38
39/*==========================================================================*/
40void UINIT(void)
41{
42 pos_ = new POutPersist("nbsread_bosse.ppf");
43}
44
45/*===========================================================================*/
46#define NXNT 48
47void UINITCCD(void)
48{
49int_4 ic,n;
50nslues = nsgood = 0;
51for(ic=0;ic<NCOULMX;ic++) {
52 n = ( nmesure[ic] > 0 ) ? nmesure[ic] : 1 ;
53 TimeU[ic] = (float*) malloc((size_t) n*sizeof(float));
54 FluxU[ic] = (float*) malloc((size_t) n*sizeof(float));
55 eFluxU[ic] = (float*) malloc((size_t) n*sizeof(float));
56 FluxflU[ic] = (float*) malloc((size_t) n*sizeof(float));
57 eFluxflU[ic] = (float*) malloc((size_t) n*sizeof(float));
58}
59
60// Create NTuple
61const char *nament[NXNT] = {
62 "etr","etb","fr","fb",
63 "dmin1","dmin2","dm21","dm22",
64 "x1","y1","nptr","nptb",
65 "mostr","mostb","sintr","sintb",
66 "u0","t0","tau","a0",
67 "nbosr","nbosb",
68 "t1Pr","t2Pr","pkPr","nPr","i1Pr","i2Pr",
69 "t1Pb","t2Pb","pkPb","nPb","i1Pb","i2Pb",
70 "t1Sr","t2Sr","pkSr","nSr","i1Sr","i2Sr",
71 "t1Sb","t2Sb","pkSb","nSb","i1Sb","i2Sb",
72 "rec1","rec2"
73};
74if(ntbosse == NULL) delete ntbosse;
75ntbosse = new NTuple(NXNT,nament);
76
77}
78
79/*=========================================================================*/
80void UDATCLEAN(int coul)
81/* pour tuer une photo selon des criteres utilisateur, mettre date a GRAND2 */
82{
83int_4 ic = coul-1;
84if(nmes[ic]<=0) return;
85for(int i=0;i<nmes[ic];i++) {
86 if(date[ic][i]<0.) date[ic][i] = GRAND2;
87 if(timeu[ic][i].FgCalib<=0) date[ic][i] = GRAND2;
88}
89}
90
91/*=========================================================================*/
92void UEVT(void)
93{
94int_4 i,n,ic
95 ,nbosse[NCOULMX],npoint[NCOULMX][NbossMAX],rc[NCOULMX]
96 ,ideb[NCOULMX][NbossMAX],ifin[NCOULMX][NbossMAX]
97 ,classB[NCOULMX][NbossMAX],I[NCOULMX],II[NCOULMX]
98 ,I1[NCOULMX],I2[NCOULMX],II1[NCOULMX],II2[NCOULMX];
99float xnt[NXNT],t1p[NCOULMX],t2p[NCOULMX],t1s[NCOULMX],t2s[NCOULMX]
100 ,min,max,dt0,dt1,recouv1,recouv2;
101float SigmaI[NCOULMX],Most[NCOULMX],/* Mean[NCOULMX], */Sigma[NCOULMX]
102 ,chi2[NCOULMX][NbossMAX],Probchi2[NCOULMX][NbossMAX];
103float *FlU[NCOULMX], *eFlU[NCOULMX];
104
105nslues++;
106
107/* association rouge-bleu existante et correcte */
108if(iet[1] <= 0 ) return;
109if(staru[0].XRef <= 0 ) return;
110if(staru[0].NumEt <= 0 ) return;
111if(staru[0].FluxRef<= 0.) return;
112if(staru[0].XRef>0) if(staru[1].FluxRef<= 0.) return;
113FILL_USER();
114/* nombre de mesures suffisant */
115if( npt[0]<3 || npt[1]<3 ) return;
116
117if( iet[0]%50 == 0 )
118 printf("UEVT: et=[%7d,%7d] pt nmesure=[%5d,%5d] npt=[%5d,%5d]\n"
119 ,iet[0],iet[1],nmesure[0],nmesure[1],npt[0],npt[1]);
120
121nsgood++;
122
123/****************** Filtre Median *******************************/
124for(ic=0;ic<NCOULMX;ic++) {
125 n = npt[ic];
126 rc[ic] = FiltMed(FluxU[ic],eFluxU[ic],FluxflU[ic],eFluxflU[ic],n);
127}
128if(rc[0]<0 && rc[1]<0) return;
129
130/**************** Choix du tableau pour les bosses ***************/
131#if defined(FILTMED)
132for(ic=0;ic<NCOULMX;ic++) {FlU[ic] = FluxU[ic]; eFlU[ic] = eFluxU[ic];}
133#else
134for(ic=0;ic<NCOULMX;ic++) {FlU[ic] = FluxflU[ic]; eFlU[ic] = eFluxflU[ic];}
135#endif
136
137/*********************** Calcul du sigma interne *****************/
138for(ic=0;ic<NCOULMX;ic++) {
139 n = npt[ic];
140 SigmaI[ic] = SigmaInt(TimeU[ic],FlU[ic],eFlU[ic],&n,4.);
141}
142if(SigmaI[0]<=0 && SigmaI[1]<=0) return;
143
144/****************** Calcul de la base ***************************/
145
146/*
147for(ic=0;ic<NCOULMX;ic++) {
148 n = npt[ic];
149 rc[ic] = BaseLine(FlU[ic],eFlU[ic],&n,4.,SigmaI[ic],&Mean[ic],&Sigma[ic],&Most[ic]);
150}
151if(rc[0]<0 || rc[1]<0) return;
152*/
153/*
154for(ic=0;ic<NCOULMX;ic++)
155 rc[ic] = BaseLineP(FlU[ic],eFlU[ic],npt[ic],-5,&Most[ic]);
156if(rc[0]<=0 || rc[1]<=0) return;
157*/
158for(ic=0;ic<NCOULMX;ic++)
159 rc[ic] = BaseLineS(FlU[ic],eFlU[ic],npt[ic],-5,&Most[ic],&Sigma[ic]);
160if(rc[0]<=0 || rc[1]<=0) return;
161
162/****************** Recherche des bosses *****************************/
163
164for(ic=0;ic<NCOULMX;ic++) {
165 n = npt[ic];
166#if defined(BOSSEN)
167 nbosse[ic] = BosseN(FlU[ic],eFlU[ic],n,Most[ic],1.5,4,1.,4,
168 &chi2[ic][0],&npoint[ic][0],&Probchi2[ic][0],&ideb[ic][0],&ifin[ic][0],
169 &classB[ic][0],NbossMAX);
170#else
171 nbosse[ic] = Bosse(FlU[ic],eFlU[ic],n,Most[ic],5,1.,3.,
172 &chi2[ic][0],&npoint[ic][0],&Probchi2[ic][0],&ideb[ic][0],&ifin[ic][0],
173 &classB[ic][0],NbossMAX);
174#endif
175 if(nbosse[ic]>0) {
176 I[ic]= classB[ic][0];
177 I1[ic]= ideb[ic][I[ic]];
178 I2[ic]= ifin[ic][I[ic]];
179 t1p[ic] = TimeU[ic][I1[ic]];
180 t2p[ic] = TimeU[ic][I2[ic]];
181 if(nbosse[ic]>1) {
182 II[ic]= classB[ic][1];
183 II1[ic]= ideb[ic][II[ic]];
184 II2[ic]= ifin[ic][II[ic]];
185 t1s[ic] = TimeU[ic][II1[ic]];
186 t2s[ic] = TimeU[ic][II2[ic]];
187 }
188 }
189}
190
191/********************** calcul du recouvrement R/B ************************/
192
193recouv1 = -1.;
194if (nbosse[0]>0 && nbosse[1]>0) {
195 dt0 = t2p[0] - t1p[1];
196 dt1 = t2p[1] - t1p[0];
197 if ((t2p[0]-t1p[0]) < (t2p[1]-t1p[1])) {
198 min = (t2p[0]-t1p[0]);
199 max = (t2p[1]-t1p[1]);
200 } else {
201 min = (t2p[1]-t1p[1]);
202 max = (t2p[0]-t1p[0]);
203 }
204 if ( dt0*dt1 < 0.) recouv1 = 0.;
205 else if ((min<dt0) && (min<dt1)) recouv1 = min/max;
206 else recouv1 = (dt0>dt1) ? dt1/dt0 : dt0/dt1;
207}
208
209recouv2 = -1.;
210if (nbosse[0]>1 && nbosse[1]>1) {
211 dt0 = t2s[0] - t1s[1];
212 dt1 = t2s[1] - t1s[0];
213 if ((t2s[0]-t1s[0]) < (t2s[1]-t1s[1])) {
214 min = (t2s[0]-t1s[0]);
215 max = (t2s[1]-t1s[1]);
216 } else {
217 min = (t2s[1]-t1s[1]);
218 max = (t2s[0]-t1s[0]);
219 }
220 if ( dt0*dt1 < 0.) recouv2 = 0.;
221 else if ((min<dt0) && (min<dt1)) recouv2 = min/max;
222 else recouv2 = (dt0>dt1) ? dt1/dt0 : dt0/dt1;
223}
224
225/********************** on remplit le ntuple de selection **********************/
226
227for(i=0;i<NXNT;i++) xnt[i] = -1.;
228xnt[0]= iet[0]; /* etr */
229xnt[1]= iet[1]; /* etb */
230xnt[2] = staru[0].FluxRef; /* fr */
231xnt[3] = staru[1].FluxRef; /* fb */
232xnt[4] = staru[0].DisMin; /* dmin1 */
233xnt[5] = staru[1].DisMin; /* dmin2 */
234xnt[6] = staru[0].DisM2; /* dm21 */
235xnt[7] = staru[1].DisM2; /* dm22 */
236xnt[8] = staru[0].XPos; /* x1 */
237xnt[9] = staru[0].YPos; /* y1 */
238xnt[10] = npt[0]; /* nptr */
239xnt[11] = npt[1]; /* nptb */
240
241xnt[12] = Most[0]; /* mostr */
242xnt[13] = Most[1]; /* mostb */
243xnt[14] = SigmaI[0]; /* sintr */
244xnt[15] = SigmaI[1]; /* sintb */
245
246xnt[16] = mc.U0Sim; /* u0 */
247xnt[17] = mc.T0Sim; /* t0 */
248xnt[18] = mc.TauSim; /* tau */
249xnt[19] = mc.A0Max; /* a0 */
250
251xnt[20] = nbosse[0]; /* nbosr */
252xnt[21] = nbosse[1]; /* nbosb */
253
254/* bosse rouge 1ere */
255if(nbosse[0]>0) {
256 xnt[22] = t1p[0]; /* t1Pr */
257 xnt[23] = t2p[0]; /* t2Pr */
258 xnt[24] = Probchi2[0][I[0]]; /* pkPr */
259 xnt[25] = npoint[0][I[0]]; /* nPr */
260 xnt[26] = I1[0]; /* i1Pr */
261 xnt[27] = I2[0]; /* i2Pr */
262}
263
264/* bosse bleue 1ere */
265if(nbosse[1]>0) {
266 xnt[28] = t1p[1]; /* t1Pb */
267 xnt[29] = t2p[1]; /* t2Pb */
268 xnt[30] = Probchi2[1][I[1]]; /* pkPb */
269 xnt[31] = npoint[1][I[1]]; /* nPb */
270 xnt[32] = I1[1]; /* i1Pb */
271 xnt[33] = I2[1]; /* i2Pb */
272}
273
274/* bosse rouge 2sd */
275if(nbosse[0]>1) {
276 xnt[34] = t1s[0]; /* t1Sr */
277 xnt[35] = t2s[0]; /* t2Sr */
278 xnt[36] = Probchi2[0][II[0]]; /* pkSr */
279 xnt[37] = npoint[0][II[0]]; /* nSr */
280 xnt[38] = II1[0]; /* i1Sr */
281 xnt[39] = II2[0]; /* i2Sr */
282}
283
284/* bosse bleue 2sd */
285if(nbosse[1]>1) {
286 xnt[40] = t1s[1]; /* t1Sb */
287 xnt[41] = t2s[1]; /* t2Sb */
288 xnt[42] = Probchi2[1][II[1]]; /* pkSb */
289 xnt[43] = npoint[1][II[1]]; /* nSb */
290 xnt[44] = II1[1]; /* i1Sb */
291 xnt[45] = II2[1]; /* i2Sb */
292}
293
294/* recouvrement 1ere 2sd */
295xnt[46] = recouv1; /* rec1 */
296xnt[47] = recouv2; /* rec2 */
297
298 ntbosse->Fill(xnt);
299
300}
301
302/*=========================================================================*/
303void UENDCCD(void)
304{
305int ic;
306printf("Nombre d etoiles lues= %d, bonnes= %d, mauvaises=%d\n"
307 ,nslues,nsgood,nslues-nsgood);
308fflush(stdout);
309for(ic=0;ic<NCOULMX;ic++) {
310 free(TimeU[ic]);
311 free(FluxU[ic]);
312 free(eFluxU[ic]);
313 free(FluxflU[ic]);
314 free(eFluxflU[ic]);
315}
316
317if(ntbosse->NEntry()>0) pos_->PutObject(*ntbosse,"ntbosse");
318if(ntbosse!=NULL) delete ntbosse; ntbosse = NULL;
319}
320
321/*=========================================================================*/
322void UEND(void)
323{
324 if(pos_!=NULL) delete pos_; pos_ = NULL;
325}
326
327/*=========================================================================*/
328void FILL_USER(void)
329{
330int ic,i,j;
331double Flux,FluxB,Xi2,ErrFlux;
332
333for(ic=0;ic<NCOULMX;ic++) {
334 npt[ic]=0;
335 for(i=0;i<nmesure[ic];i++) {
336 j = indexu[ic][i];
337 FluxB = mesu[ic][j].FluxB;
338 Flux = mesu[ic][j].Flux;
339 ErrFlux = mesu[ic][j].ErrFlux;
340 Xi2 = mesu[ic][j].Xi2;
341 if( ErrFlux<0 ) ErrFlux *= -1.;
342 if(Xi2<=0.) continue;
343 TimeU[ic][npt[ic]] = date[ic][j];
344 if(mc.montecar > 0) Flux *= ampli[ic][j];
345 FluxU[ic][npt[ic]] = Flux;
346 eFluxU[ic][npt[ic]] = ErrFlux;
347 npt[ic]++;
348 }
349}
350
351}
Note: See TracBrowser for help on using the repository browser.