| 471 | Combining everything into a single query is a bit tricky but works: |
| 472 | |
| 473 | {{{ |
| 474 | SELECT |
| 475 | @S := COUNT(IF(Weight>0, 1, NULL)) AS `Signal`, |
| 476 | @B := COUNT(IF(Weight<0, 1, NULL)) AS `Background`, |
| 477 | @E := @S - 0.2*@B AS `Excess`, |
| 478 | @LiMa := LiMa(@S, @B/5, 0.2) AS `Significance` |
| 479 | FROM |
| 480 | ( |
| 481 | |
| 482 | SELECT |
| 483 | Size, |
| 484 | Angle, |
| 485 | NumUsedPixels, |
| 486 | NumIslands, |
| 487 | Leakage1, |
| 488 | Weight, |
| 489 | PI()*Width*Length AS Area, |
| 490 | @PX := cosa*X - sina*Y, |
| 491 | @PY := cosa*Y + sina*X, |
| 492 | @DX := MeanX-@PX/1.02, |
| 493 | @DY := MeanY-@PY/1.02, |
| 494 | @Norm := SQRT(@DX*@DX + @DY*@DY), |
| 495 | @Dist := @Norm*0.0117193246260285378 AS Dist, |
| 496 | @LX := TRUNCATE((CosDelta*@DY - SinDelta*@DX)/@Norm, 6), |
| 497 | @LY := TRUNCATE((CosDelta*@DX + SinDelta*@DY)/@Norm, 6), |
| 498 | @Alpha := ASIN(@LX) AS Alpha, |
| 499 | @Sign := SIGN(@LY) AS Sign, |
| 500 | @M3L := M3Long*@Sign*0.0117193246260285378, |
| 501 | @Slope := SlopeLong*@Sign/0.0117193246260285378 AS Slope, |
| 502 | @Xi := 1.39252 + 0.154247*@Slope + 1.67972*(1-1/(1+4.86232*Leakage1)), |
| 503 | @Sign1 := @M3L+0.07, |
| 504 | @Sign2 := (@Dist-0.5)*7.2-@Slope, |
| 505 | @Disp := IF (SIGN(@Sign1)<0 || SIGN(@Sign2)<0, -@Xi, @Xi) * (1-Width/Length), |
| 506 | @ThetaSq := (@Disp*@Disp + @Dist*@Dist - 2*@Disp*@Dist*SQRT(1-@LX*@LX)) AS ThetaSq |
| 507 | FROM RunInfo |
| 508 | LEFT JOIN Events USING (FileId) |
| 509 | LEFT JOIN Position USING (FileId, EvtNumber) |
| 510 | CROSS JOIN Wobble |
| 511 | WHERE |
| 512 | fSourceKey=5 |
| 513 | AND |
| 514 | fRunTypeKey=1 |
| 515 | AND |
| 516 | FileId BETWEEN 131101000 AND 131107000 |
| 517 | AND |
| 518 | fZenithDistanceMax<35 |
| 519 | AND |
| 520 | fR750Cor>0.9*fR750Ref |
| 521 | ) TableAlias |
| 522 | |
| 523 | WHERE |
| 524 | ThetaSq<0.156 |
| 525 | AND |
| 526 | Area < LOG10(Size)*898-1535 |
| 527 | AND |
| 528 | NumUsedPixels>5.5 |
| 529 | AND |
| 530 | NumIslands<3.5 |
| 531 | AND |
| 532 | Leakage1<0.1 |
| 533 | }}} |
| 534 | |