source: Sophya/trunk/ArchTOIPipe/ProcWSophya/ktoibad.cc@ 1733

Last change on this file since 1733 was 1733, checked in by cmv, 24 years ago

intro deglitcheur FlagGlitch et prog de test cmv 5/11/2001

File size: 6.3 KB
RevLine 
[1733]1#include "machdefs.h"
2#include "toimanager.h"
3#include "pexceptions.h"
4#include "ntuple.h"
5#include "ktoibad.h"
6
7////////////////////////////////////////////////////////////////////////
8// Recherche des glitches :
9// INPUT:
10// lg : longeur maxi d'un glitch (impair, si pair lg++)
11// doit etre suffisamment long pour que les glitches soient <lg
12// suffisamment court pour ne pas tuer la galaxie
13// lm : longueur de la fenetre glissante (de chaque cote)
14// <---lm---><--lg--><---lm--->
15// doit etre suffisamment long pour avoir une bonne stabilite
16// des calculs (a0,a1) et suffisamment court pour ne pas
17// tuer la galaxie.
18// nsg : nombre de sigmas pour valider un glitch
19////////////////////////////////////////////////////////////////////////
20
21////////////////////////////////////////////////////////////////////////
22FlagGlitch::FlagGlitch(uint_4 lg,uint_4 lm,r_8 nsg)
23 : mLP(0), mLPsnb(-1), mLPsne(-1)
24{
25 // Mise en forme des arguments
26 if(nsg<=0) nsg = 3.;
27 if(lg<=0) lg=3; if(lg%2==0) lg++;
28 if(lm<3) lm = 5*lg;
29
30 LGlitch = lg;
31 LSide = lm;
32 NSCut = nsg;
33 Slpb[0] = Slpb[1] = NULL;
34 DoNotLookAt();
35 SetFlag();
36 SetBuffUpd();
37}
38
39FlagGlitch::~FlagGlitch()
40{
41 for(int i=0;i<2;i++) {if(Slpb[i]) delete Slpb[i]; Slpb[i]=NULL;}
42}
43
44////////////////////////////////////////////////////////////////////////
45void FlagGlitch::Print(ostream & os)
46{
47 os<<"FlagGlitch::Print"
48 <<" LGlitch="<<LGlitch<<" LSide="<<LSide<<" NSCut="<<NSCut
49 <<" flgNotLookAt="<<flgNotLookAt<<" flgGlitch="<<flgGlitch
50 <<" BuffUpdate="<<BuffUpdate<<endl;
51}
52
53////////////////////////////////////////////////////////////////////////
54void FlagGlitch::init() {
55 if(mLP) cout << "FlagGlitch::init" << endl;
56 declareInput("BoloIn"); // input index 0
57 declareOutput("BoloOut"); // output index 0
58
59 for(int i=0;i<2;i++)
60 Slpb[i] = new SLinParBuff(LSide,BuffUpdate,0.,0.,true);
61
62 int_4 lbuff = 2*LSide + LGlitch +10;
63 if(neededHistory<lbuff) setNeededHistory(lbuff);
64}
65
66////////////////////////////////////////////////////////////////////////
67void FlagGlitch::run()
68{
69long snb = getMinIn();
70long sne = getMaxIn();
71
72if(snb>sne) {
73 cout<<"FlagGlitch::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
74 throw ParmError("FlagGlitch::run() - Bad sample interval");
75}
76if(!checkInputTOIIndex(0)) {
77 cout<<"FlagGlitch::run() - Input TOI (BoloIn) not connected! "<<endl;
78 throw ParmError("FlagGlitch::run() Input TOI (BoloIn) not connected!");
79}
80if(!checkOutputTOIIndex(0)) {
81 cout<<"FlagGlitch::run() - Output TOI (BoloOut) not connected! "<<endl;
82 throw ParmError("FlagGlitch::run() Output TOI (BoloOut) not connected!");
83}
84
85//---------------------------------------------------------
86try {
87
88char* nament_[8] = {"s","bol","sg","sd","slg","sld","ypg","ypd"};
89r_4 xnt_[8];
90NTuple nt_(8,nament_);
91int intuple = mLP/10;
92
93if(mLP) cout<<"FlagGlitch::run(): SampleNum de "<<snb<<" a "<<sne<<endl;
94uint_4 nflag=0;
95r_8 nsg = NSCut;
96int_4 lg = LGlitch;
97int_4 lgs2 = (lg-1)/2;
98int_4 lm = LSide;
99int_4 lmmin = lm/2; if(lmmin<2) lmmin=2;
100
101for(int_4 sn=snb;sn<=sne;sn++) {
102 int_4 lp = (mLPsnb<=sn && sn<=mLPsne) ? mLP%10: 0;
103 r_8 bolog; uint_8 fgbolog=0;
104
105 getData(0,sn,bolog,fgbolog);
106 if(fgbolog && flgNotLookAt) {
107 putData(0,sn,bolog,fgbolog);
108 continue;
109 }
110
111 // i
112 // <---lm---><--lg--><---lm--->
113 // | c=0 | | c=1 |
114 // ideb | | ifin
115 // ifin ideb
116 r_8 bolo; uint_8 fgbolo=0;
117 int_4 ifill[2] = {sn-lgs2-1,sn+lgs2+lm};
118 if(lp>1) printf(">>>> sn=%d v=(%f,%ld) ifill=[%d,%d]\n"
119 ,sn,bolog,fgbolog,ifill[0],ifill[1]);
120
121 if(ifill[0]<snb) {
122 putData(0,sn,bolog,fgbolog);
123 continue;
124 }
125 getData(0,ifill[0],bolo,fgbolo);
126 if(fgbolo&flgNotLookAt) Slpb[0]->Pop();
127 else Slpb[0]->Push((r_8)ifill[0],bolo);
128 if((int_4)Slpb[0]->NPoints()<lmmin) {
129 putData(0,sn,bolog,fgbolog);
130 continue;
131 }
132
133 if(ifill[1]<=sne) {
134 getData(0,ifill[1],bolo,fgbolo);
135 if(fgbolo&flgNotLookAt) Slpb[1]->Pop();
136 else Slpb[1]->Push((r_8)ifill[1],bolo);
137 } else Slpb[1]->Pop();
138 if((int_4)Slpb[1]->NPoints()<lmmin) {
139 putData(0,sn,bolog,fgbolog);
140 continue;
141 }
142
143 // Calcul des valeurs pour decider
144 double s[2],slin[2],ypred[2];
145 for(int c=0;c<2;c++) {
146 r_8 mean,a0,a1;
147 s[c] = Slpb[c]->Compute(mean);
148 slin[c] = Slpb[c]->Compute(a0,a1);
149 ypred[c] = a0+a1*sn;
150 if(lp>1) printf("... c=%d m=%f s=%f ypred=%f slin=%f (%d)\n"
151 ,c,mean,s[c],ypred[c],slin[c],Slpb[c]->NPoints());
152 if(slin[c]<0. || s[c]<0.) {
153 putData(0,sn,bolog,fgbolog);
154 continue;
155 }
156 }
157
158 if(intuple>0) {
159 xnt_[0] = sn; xnt_[1] = bolog;
160 xnt_[2] = s[0]; xnt_[3] = s[1];
161 xnt_[4] = slin[0]; xnt_[5] = slin[1];
162 xnt_[6] = ypred[0]; xnt_[7] = ypred[1];
163 nt_.Fill(xnt_);
164 }
165
166 // Si les predictions ne sont pas compatibles (sig), pas de deglitch
167 r_8 yy = ypred[1]-ypred[0];
168 r_8 sy = nsg*sqrt(s[0]*s[0]+s[1]*s[1]);
169 if(lp>1) printf("... yy=|%f| > sy=%f ???\n",yy,sy);
170 if(fabs(yy) > sy) {
171 putData(0,sn,bolog,fgbolog);
172 continue;
173 }
174
175 // Si la valeur est entre les 2 predictions, pas de deglitch
176 r_8 dp0 = ypred[0];
177 r_8 dp1 = ypred[1];
178 if(ypred[1]<ypred[0]) {dp0 = ypred[1]; dp1 = ypred[0];}
179 if(lp>1) printf("... %f dans [%f,%f] ???\n",bolog,dp0,dp1);
180 if(dp0<bolog && bolog<dp1) {
181 putData(0,sn,bolog,fgbolog);
182 continue;
183 }
184
185 // A + de N sigmas (lin) des 2 predictions
186 dp0 = fabs(bolog-ypred[0]); slin[0] *= nsg;
187 dp1 = fabs(bolog-ypred[1]); slin[1] *= nsg;
188 if(lp>1) printf("... dp0=%f > %f et dp1=%f > %f ???\n"
189 ,dp0,slin[0],dp1,slin[1]);
190 if(dp0 < slin[0] || dp1 < slin[1]) {
191 putData(0,sn,bolog,fgbolog);
192 continue;
193 }
194
195 // C'est un glitch
196 nflag++;
197 fgbolog |= flgGlitch;
198 if(lp>1)
199 printf("......... Glitch en sn=%d ... %d glitches found\n",sn,nflag);
200 putData(0,sn,bolog,fgbolog);
201
202}
203if(mLP) cout<<"FlagGlitch::run(): Fin de boucle: nflag="<<nflag
204 <<" / "<<sne-snb+1<<endl;
205
206if(intuple>0) {
207 char *fileout_ = "flagglitch.ppf";
208 string tag_ = "nfg";
209 POutPersist pos_(fileout_); pos_.PutObject(nt_,tag_);
210}
211
212//---------------------------------------------------------
213} catch (PException & exc) {
214 cout<<"FlagGlitch: Catched Exception "<<(string)typeid(exc).name()
215 <<"\n .... Msg= "<<exc.Msg()<<endl;
216}
217
218return;
219}
Note: See TracBrowser for help on using the repository browser.