Changeset 2045 in Sophya
- Timestamp:
- Jun 7, 2002, 4:21:22 PM (23 years ago)
- Location:
- trunk/ArchTOIPipe/ProcWSophya
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ArchTOIPipe/ProcWSophya/simoffset.cc
r2034 r2045 12 12 #include "ctimer.h" 13 13 #include "ntuple.h" 14 #include "sopemtx.h" 14 15 15 16 #include "flagtoidef.h" 16 17 18 17 19 SimpleOffsetEstimator::SimpleOffsetEstimator(int mwsz, int nptfit, int degpol) 18 : poly((degpol > 1)?degpol :1)20 : poly((degpol > 1)?degpol+1:2) 19 21 { 20 22 SetParams(mwsz, nptfit, degpol); … … 24 26 bgalcut = false; 25 27 ns_flgcut = ns_bgalcut = 0; 28 npb_fitpoly = 0; 26 29 SavePolyNTuple(); 27 30 } … … 51 54 os << "\n ------------------------------------------------------ \n" 52 55 << " SimpleOffsetEstimator::PrintStatus() - MeanWSize= " << mWSz << " NPtFit=" 53 << nPtFit << " DegPoly=" << degPol << " poly.Degre()=" << poly.Degre() <<endl;56 << nPtFit << " DegPoly=" << degPol << endl; 54 57 if (bgalcut) 55 58 os << " bGalCut = Yes , bGalMin = " << bmincut << " bGalMax= " << bmaxcut << endl; … … 57 60 TOIProcessor::PrintStatus(os); 58 61 os << " ProcessedSampleCount=" << ProcessedSampleCount() 59 << " NS_FlgCut= " << ns_flgcut << " NS_BGalCut= " << ns_bgalcut << endl; 62 << " NS_FlgCut= " << ns_flgcut << " NS_BGalCut= " << ns_bgalcut 63 << " NPb_FitPoly= " << npb_fitpoly << endl; 60 64 os << " ------------------------------------------------------ " << endl; 61 65 } … … 118 122 NTuple xntp(11, nomsnt); 119 123 124 char ans[20]; 125 120 126 try { 121 127 … … 168 174 int nblk = (sne-snb+1)/wsize; 169 175 for(kb=0; kb<nblk; kb++) { 176 // cout << " SimpleOffsetEstimator::run - Loop " << kb << " NbBlkOK= " 177 // << nbblkok << " <CR> to continue / q --> QUIT ... \n" ; 178 // gets(ans); if (ans[0] == 'q') break; 170 179 k = kb*wsize+snb; 171 180 // for(k=snb;k<=sne-wsize+1;k+=wsize) { … … 236 245 fg_last_meansig = true; 237 246 } 238 247 248 239 249 if (((nok>3.5) || fg_last_meansig) && (nbblkok >= nPtFit) ) { 240 250 // On force le fit a garder une certaine continuite … … 248 258 X0 = X; 249 259 X0 -= sn0; 250 Vector polsave(degPol); 251 for(int jj=0; jj<=poly.Degre(); jj++) polsave(jj) = poly[jj]; 252 try { 253 poly.Fit(X0,Y,YErr,degPol,errCoef); 254 } 255 catch (CaughtSignalExc& excsig) { 256 cout << " -- simoffset.cc/ catched CaughtSignalExc - Msg= " 257 << excsig.Msg() << " kb=" << kb << " k=" << k << endl; 258 cout << " X0= " << X0 << " Y=" << Y << " YErr=" << YErr << endl; 259 for(int jj=0; jj<=poly.Degre(); jj++) poly[jj] = polsave(jj); 260 } 260 FitPoly(X0, Y, YErr); 261 261 } 262 262 else { 263 263 if (nbblkok < 2) { 264 264 sn0 = k+1; 265 poly [0]= mean;266 for(int jj=1; jj<= poly.Degre(); jj++) poly[jj]= 0.;265 poly(0) = mean; 266 for(int jj=1; jj<=degPol; jj++) poly(jj) = 0.; 267 267 } 268 268 else if (nbblkok < nPtFit) { 269 poly [0]= 0.5*(Y(nbblkok-1)+Y(0));270 poly [1]= (Y(nbblkok-1) - Y(0))/(X(nbblkok-1)-X(0));269 poly(0) = 0.5*(Y(nbblkok-1)+Y(0)); 270 poly(1) = (Y(nbblkok-1) - Y(0))/(X(nbblkok-1)-X(0)); 271 271 sn0 = 0.5*(X(nbblkok-1)+X(0)); 272 for(int jj=2; jj<= poly.Degre(); jj++) poly[jj]= 0.;272 for(int jj=2; jj<=degPol; jj++) poly(jj) = 0.; 273 273 } 274 274 sn_last = sn0; 275 275 y_last = poly(sn_last-sn0); 276 276 } 277 277 278 if (ntpoly) { // Remplissage du XNTuple de controle 278 279 float xnt[12]; … … 282 283 xnt[3] = mean; 283 284 xnt[4] = sig; 284 xnt[5] = poly [0];285 xnt[6] = poly [1];286 xnt[7] = poly [2];287 xnt[8] = poly(k-sn0);285 xnt[5] = poly(0); 286 xnt[6] = poly(1); 287 xnt[7] = poly(2); 288 xnt[8] = ApplyPoly(k-sn0); 288 289 xnt[9] = nok; 289 290 xnt[10] = nbblkok; … … 291 292 } 292 293 293 /* 294 if (nbblkok < 8) { 295 cout << "------ DBG-X " << nbblkok << "," << nok << " degre=" << poly.Degre() << endl; 296 cout << "DBG-A X0=" << X0 << endl; 297 cout << "DBG-A Y=" << Y << endl; 298 cout << "DBG-A YErr=" << YErr << endl; 299 cout << "DBG-A poly= " << poly << endl; 300 } 301 */ 302 294 303 295 if (fgincopie) putData(2, k, wsize, vin.Data(), vfg.Data()); 304 296 305 297 if (kb < nPtFit/2) continue; 306 Vector vinc; 298 Vector vinc; 307 299 TVector<uint_8> vfgc; 308 300 int kbs = kb-nPtFit/2; … … 332 324 // Calcul des valeurs d'offset en sortie 333 325 for(j=0; j<wsize; j++) 334 voff(j) = poly(k+j-sn0);326 voff(j) = ApplyPoly(k+j-sn0); 335 327 sn_last = k+wsize; 336 y_last = poly(sn_last-sn0); 337 328 y_last = ApplyPoly(sn_last-sn0); 338 329 if (fgoffset) putData(0, k, wsize, voff.Data()); 339 330 if (fgout) { … … 341 332 putData(1, k, wsize, vinc.Data(), vfgc.Data()); 342 333 } 343 /*344 if (fgmeany) {345 vout = mean;346 putData(4, k, wsize, vout.Data());347 }348 if (fgsigy) {349 vout = sig;350 putData(5, k, wsize, vout.Data());351 }352 353 if (fgmeanx) {354 vout = meanx;355 putData(6, k, wsize, vout.Data());356 }357 */358 334 359 335 klast+=wsize; 360 336 totnscount+=wsize; 361 337 totnbblock++; 362 338 // cout << " SimpleOffset::run " << totnbblock << " totnscount " << totnscount << endl; 363 339 } // Fin boucle sur les samples, par pas de wsize 364 340 … … 379 355 380 356 for(j=0; j<wsize; j++) 381 voff(j) = poly(k+j-sn0);357 voff(j) = ApplyPoly(k+j-sn0); 382 358 if (fgoffset) putData(0, k, wsize, voff.Data()); 383 359 if (fgincopie) putData(2, k, wsize, vin.Data(), vfg.Data()); … … 425 401 } 426 402 } 403 404 405 double SimpleOffsetEstimator::ApplyPoly(double x) 406 { 407 if (degPol == 0) return(poly(0)); 408 else if (degPol == 1) return(poly(0)+poly(1)*x); 409 else if (degPol == 2) return(poly(0)+poly(1)*x+poly(2)*x*x); 410 else if (degPol == 3) return(poly(0)+poly(1)*x+poly(2)*x*x+poly(3)*x*x*x); 411 else { 412 double ret = poly(0); 413 double xx = x; 414 for(int k=1; k<degPol+1; k++) { ret += xx*poly(k); xx *= x; } 415 return(ret); 416 } 417 } 418 419 // Fonction pour faire LinFit d'un polynome 420 r_8 rzpoly_f(uint_4 k, r_8 x ) 421 { 422 if (k == 0) return(1.); 423 else if (k == 1) return(x); 424 else if (k == 2) return(x*x); 425 else if (k == 3) return(x*x*x); 426 else { 427 r_8 ret = x; 428 for(int i=1; i<k; i++) ret *= x; 429 return(ret); 430 } 431 } 432 433 void SimpleOffsetEstimator::FitPoly(Vector& X0, Vector& Y, Vector& YErr) 434 { 435 Vector cpol(degPol+1); 436 Vector errcoef(degPol+1); 437 LinFitter<r_8> lfit; 438 try { 439 lfit.LinFit(X0, Y, YErr, degPol+1, rzpoly_f, cpol, errcoef); 440 poly = cpol; 441 } 442 catch (PException & exc) { 443 if (npb_fitpoly < 50) 444 cout << " -- SimpleOffsetEstimator::FitPoly/ Catched Exception " 445 << (string)typeid(exc).name() << "\n .... Msg= " << exc.Msg() << endl; 446 if (npb_fitpoly < 10) 447 cout << " X0= " << X0 << " Y=" << Y << " YErr=" << YErr << endl; 448 npb_fitpoly++; 449 } 450 return; 451 } 452 -
trunk/ArchTOIPipe/ProcWSophya/simoffset.h
r2014 r2045 11 11 #include "toiprocessor.h" 12 12 #include "tvector.h" 13 #include "poly.h"14 13 15 14 // ---- Calcul de ligne de base … … 42 41 inline void SavePolyNTuple(bool fg=false, string name="") { ntpoly = fg; ntpolyname=name; } 43 42 protected: 43 virtual double ApplyPoly(double x); 44 virtual void FitPoly(Vector& X0, Vector& Y, Vector& YErr); 45 44 46 int_8 totnscount; // Nombre total d'echantillon processe 45 47 int_8 totnbblock; // Nombre total de blocs … … 47 49 int nPtFit; 48 50 int degPol; 49 Poly poly; 51 // Poly poly; Pb SEGV lors de Poly.Fit 52 Vector poly; 53 int_4 npb_fitpoly; 50 54 bool ntpoly; 51 55 string ntpolyname;
Note:
See TracChangeset
for help on using the changeset viewer.