Changeset 5593 for trunk/MagicSoft/Mars/msignal
- Timestamp:
- 12/14/04 17:15:28 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/msignal
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc
r5545 r5593 325 325 fAbMax = 0.; 326 326 fAbMaxPos = 0.; 327 Byte_tmaxpos = 0;327 Int_t maxpos = 0; 328 328 329 329 // … … 340 340 { 341 341 fAbMax = signal; 342 maxpos = p-first;342 maxpos = count; 343 343 } 344 344 345 345 if (*p++ >= fSaturationLimit) 346 sat++;347 346 sat++; 347 348 348 count++; 349 349 } … … 360 360 const Float_t signal = (Float_t)*logain - pedmean[(ids+abflag) & 0x1]; 361 361 fHiGainSignal[range] = signal; 362 range++;363 362 364 363 if (signal > fAbMax) 365 364 { 366 365 fAbMax = signal; 367 maxpos = logain-first;366 maxpos = range; 368 367 } 369 368 … … 371 370 sat++; 372 371 372 range++; 373 373 logain++; 374 374 } … … 395 395 fHiGainSecondDeriv[k] /= 6.; 396 396 397 if (IsNoiseCalculation() && IsExtractionType(kAmplitude))398 { 399 if (fRandomIter == (TMath::Floor(1./fResolution)))397 if (IsNoiseCalculation()) 398 { 399 if (fRandomIter == int(1./fResolution)) 400 400 fRandomIter = 0; 401 402 const Float_t b = fRandomIter * fResolution; 403 const Float_t a = 1. - b; 404 401 402 const Float_t nsx = fRandomIter * fResolution; 403 404 if (IsExtractionType(kAmplitude)) 405 { 406 const Float_t b = nsx; 407 const Float_t a = 1. - nsx; 408 409 sum = a*fHiGainSignal[1] 410 + b*fHiGainSignal[2] 411 + (a*a*a-a)*fHiGainSecondDeriv[1] 412 + (b*b*b-b)*fHiGainSecondDeriv[2]; 413 } 414 else 415 { 416 Float_t start = 2. + nsx; 417 Float_t last = start + fRiseTime + fFallTime; 418 419 if (int(last) > range) 420 { 421 const Int_t diff = range - int(last); 422 last -= diff; 423 start -= diff; 424 } 425 426 CalcIntegralHiGain(sum, start, last); 427 } 405 428 fRandomIter++; 406 407 sum = a*fHiGainSignal[1]408 + b*fHiGainSignal[2]409 + (a*a*a-a)*fHiGainSecondDeriv[1]410 + (b*b*b-b)*fHiGainSecondDeriv[2];411 429 return; 412 430 } 413 431 414 if (IsNoiseCalculation() && IsExtractionType(kIntegral)) 415 { 416 // 417 // Take the spline value at the middle of the third slice (to avoid egde effects) 418 // 419 Int_t first = 2; 420 Int_t last = first + (Int_t)(fRiseTime+fFallTime); 421 CalcIntegralHiGain(sum,first,last); 422 return; 423 } 424 425 // 426 // Allow no saturated slice 432 // 433 // Allow one saturated slice 427 434 // and 428 // Don't start if the maxpos is too close to the l eft limit.429 // 430 if ( (sat || maxpos < 2))435 // Don't start if the maxpos is too close to the limits. 436 // 437 if (sat > 1 || maxpos < 2 || maxpos > range-2) 431 438 { 432 439 time = IsExtractionType(kMaximum) 433 440 ? (Float_t)(fHiGainFirst + maxpos) 434 441 : (Float_t)(fHiGainFirst + maxpos - 1); 435 sum = IsExtractionType(kAmplitude) 436 ? fAbMax : 0.; 442 443 if (IsExtractionType(kAmplitude)) 444 { 445 sum = fAbMax; 446 return; 447 } 448 449 if (maxpos > range - 2) 450 CalcIntegralHiGain(sum, (Float_t)range - fRiseTime - fFallTime, (Float_t)range - 0.001); 451 else 452 CalcIntegralHiGain(sum, 0.001, fRiseTime + fFallTime); 453 437 454 return; 438 455 } … … 442 459 // 443 460 Float_t step = 0.2; // start with step size of 1ns and loop again with the smaller one 444 Float_t lower = (Float_t)maxpos-1.;461 Float_t lower = -1. + maxpos; 445 462 Float_t upper = (Float_t)maxpos; 446 463 fAbMaxPos = upper; … … 474 491 } 475 492 476 // *fLog << err << x << " " << y << " " << fAbMaxPos<< endl;477 493 } 478 494 … … 483 499 { 484 500 485 upper = (Float_t)maxpos+1.;501 upper = 1. + maxpos; 486 502 lower = (Float_t)maxpos; 487 503 x = lower; … … 508 524 fAbMaxPos = x; 509 525 } 510 // *fLog << inf << x << " " << y << " " << fAbMaxPos << endl;511 512 526 } 513 527 } 514 515 528 516 529 // … … 545 558 fAbMaxPos = x; 546 559 } 547 // *fLog << inf << x << " " << y << " " << fAbMaxPos << endl;548 560 } 549 561 … … 558 570 // which requires new setting of klocont and khicont 559 571 // 560 if (x < klo+ fResolution/2.)572 if (x < lower + fResolution/2.) 561 573 { 562 574 klo--; 563 575 khi--; 564 upper --;565 lower --;576 upper += 1.; 577 lower -= 1.; 566 578 } 567 579 … … 586 598 fAbMaxPos = x; 587 599 } 588 // *fLog << warn << x << " " << y << " " << fAbMaxPos << endl;589 600 } 590 601 … … 674 685 // Now integrate the whole thing! 675 686 // 676 Int_t startslice = (Int_t)(fAbMaxPos - fRiseTime); 677 Int_t lastslice = (Int_t)(fAbMaxPos + fFallTime); 678 679 if (lastslice > range) 680 { 681 lastslice = range; 682 startslice += (lastslice - range); 683 } 684 685 CalcIntegralHiGain(sum, startslice, lastslice); 686 } 687 687 688 Float_t start = fAbMaxPos - fRiseTime; 689 Float_t last = fAbMaxPos + fFallTime; 690 691 const Int_t diff = int(last) - range; 692 693 if (diff > 0) 694 { 695 last -= diff; 696 start -= diff; 697 } 698 699 CalcIntegralHiGain(sum, start, last); 700 } 688 701 } 689 702 … … 703 716 Int_t count = 0; 704 717 705 Float_t pedes= ped.GetPedestal();718 const Float_t pedes = ped.GetPedestal(); 706 719 const Float_t ABoffs = ped.GetPedestalABoffset(); 707 720 … … 712 725 fAbMax = 0.; 713 726 fAbMaxPos = 0.; 714 Byte_tmaxpos = 0;727 Int_t maxpos = 0; 715 728 716 729 // … … 720 733 { 721 734 722 const Int_t ids = fLoGainFirst + count;735 const Int_t ids = count + fLoGainFirst; 723 736 const Float_t signal = (Float_t)*p - pedmean[(ids+abflag) & 0x1]; 724 737 fLoGainSignal[count] = signal; 725 738 726 if (signal > fAbMax )739 if (signal > fAbMax + 0.1) 727 740 { 728 741 fAbMax = signal; 729 maxpos = p-first;730 } 731 732 if (*p >= fSaturationLimit)742 maxpos = count; 743 } 744 745 if (*p++ >= fSaturationLimit) 733 746 sat++; 734 735 p++; 747 736 748 count++; 737 749 } … … 751 763 752 764 fLoGainSecondDeriv[range-1] = 0.; 765 753 766 for (Int_t k=range-2;k>=0;k--) 754 767 fLoGainSecondDeriv[k] = fLoGainSecondDeriv[k]*fLoGainSecondDeriv[k+1] + fLoGainFirstDeriv[k]; … … 756 769 fLoGainSecondDeriv[k] /= 6.; 757 770 758 if (IsNoiseCalculation() && IsExtractionType(kAmplitude)) 759 { 760 // 761 // Take the spline value at the middle of the third slice (to avoid egde effects) 762 // 763 sum = 0.5*fLoGainSignal[2] 764 + 0.5*fLoGainSignal[3] 765 + (-0.375)*fLoGainSecondDeriv[2] 766 + (-0.375)*fLoGainSecondDeriv[3]; 771 if (IsNoiseCalculation()) 772 { 773 if (fRandomIter == int(1./fResolution)) 774 fRandomIter = 0; 775 776 const Float_t nsx = fRandomIter * fResolution; 777 778 if (IsExtractionType(kAmplitude)) 779 { 780 const Float_t b = nsx; 781 const Float_t a = 1. - nsx; 782 783 sum = a*fLoGainSignal[1] 784 + b*fLoGainSignal[2] 785 + (a*a*a-a)*fLoGainSecondDeriv[1] 786 + (b*b*b-b)*fLoGainSecondDeriv[2]; 787 } 788 else 789 { 790 Float_t start = 2. + nsx; 791 Float_t last = start + fRiseTime + fFallTime; 792 793 if (int(last) > range) 794 { 795 const Int_t diff = range - int(last); 796 last -= diff; 797 start -= diff; 798 } 799 800 CalcIntegralLoGain(sum, start, last); 801 } 802 fRandomIter++; 767 803 return; 768 804 } 769 770 if (IsNoiseCalculation() && IsExtractionType(kIntegral))771 {772 //773 // Take the spline value at the middle of the third slice (to avoid egde effects)774 //775 Int_t first = 2;776 Int_t last = first + (Int_t)(fRiseTime+fFallTime);777 CalcIntegralLoGain(sum,first,last);778 return;779 }780 781 805 // 782 806 // Allow no saturated slice 783 807 // and 784 // Don't start if the maxpos is too close to the l eft limit.785 // 786 if (sat || maxpos < 1)808 // Don't start if the maxpos is too close to the limits. 809 // 810 if (sat || maxpos < 2 || maxpos > range-2) 787 811 { 788 812 time = IsExtractionType(kMaximum) 789 813 ? (Float_t)(fLoGainFirst + maxpos) 790 814 : (Float_t)(fLoGainFirst + maxpos - 1); 815 816 if (IsExtractionType(kAmplitude)) 817 { 818 sum = fAbMax; 819 return; 820 } 821 822 if (maxpos > range-2) 823 CalcIntegralLoGain(sum, (Float_t)range - fRiseTime - fFallTime-1., (Float_t)range - 0.001); 824 else 825 CalcIntegralLoGain(sum, 0.001, fRiseTime + fFallTime + 1.); 826 791 827 return; 792 828 } 793 794 if (maxpos < 2 && IsExtractionType(kHalfMaximum))795 {796 time = (Float_t)(fLoGainFirst + maxpos - 1);797 return;798 }799 829 800 830 // … … 802 832 // 803 833 Float_t step = 0.2; // start with step size of 1ns and loop again with the smaller one 804 Float_t lower = (Float_t)maxpos-1.;834 Float_t lower = -1. + maxpos; 805 835 Float_t upper = (Float_t)maxpos; 806 836 fAbMaxPos = upper; … … 834 864 } 835 865 836 // *fLog << err << x << " " << y << " " << fAbMaxPos<< endl;837 866 } 838 867 … … 844 873 { 845 874 846 upper = (Float_t)maxpos+1.;875 upper = 1. + maxpos; 847 876 lower = (Float_t)maxpos; 848 877 x = lower; … … 869 898 fAbMaxPos = x; 870 899 } 871 // *fLog << inf << x << " " << y << " " << fAbMaxPos << endl;872 873 900 } 874 901 } … … 906 933 fAbMaxPos = x; 907 934 } 908 // *fLog << inf << x << " " << y << " " << fAbMaxPos << endl;909 935 } 910 936 … … 919 945 // which requires new setting of klocont and khicont 920 946 // 921 if (x < klo+ fResolution/2.)947 if (x < lower + fResolution/2.) 922 948 { 923 949 klo--; 924 950 khi--; 925 upper --;926 lower --;951 upper += 1.; 952 lower -= 1.; 927 953 } 928 954 … … 947 973 fAbMaxPos = x; 948 974 } 949 // *fLog << warn << x << " " << y << " " << fAbMaxPos << endl;950 975 } 951 976 952 977 if (IsExtractionType(kMaximum)) 953 978 { 954 time = (Float_t)fLoGainFirst + fAbMaxPos;979 time = fAbMaxPos + (Int_t)fLoGainFirst; 955 980 dtime = fResolution; 956 981 } … … 1020 1045 } 1021 1046 1022 time = (Float_t)fLoGainFirst + x;1047 time = x + (Int_t)fLoGainFirst; 1023 1048 dtime = fResolution; 1024 1049 } … … 1035 1060 // Now integrate the whole thing! 1036 1061 // 1037 Int_t startslice = (Int_t)(fAbMaxPos - fRiseTime); 1038 Int_t lastslice = (Int_t)(fAbMaxPos + fFallTime + 1); 1039 1040 if (lastslice > range) 1041 { 1042 lastslice = range; 1043 startslice += (lastslice - range); 1044 } 1045 CalcIntegralLoGain(sum, startslice, lastslice); 1062 Float_t start = fAbMaxPos - fRiseTime; 1063 Float_t last = fAbMaxPos + fFallTime + 1.; 1064 1065 const Int_t diff = int(last) - range; 1066 1067 if (diff > 0) 1068 { 1069 last -= diff; 1070 start -= diff; 1071 } 1072 CalcIntegralLoGain(sum, start, last); 1046 1073 } 1047 1074 } 1048 1075 1049 void MExtractTimeAndChargeSpline::CalcIntegralHiGain(Float_t &sum, Int_t startslice, Int_t lastslice)1076 void MExtractTimeAndChargeSpline::CalcIntegralHiGain(Float_t &sum, Float_t start, Float_t last) 1050 1077 { 1051 1078 1052 if (startslice < 0) 1053 { 1054 lastslice -= startslice; 1055 startslice = 0; 1056 } 1057 1058 Int_t i = startslice; 1059 sum = 0.5*fHiGainSignal[i]; 1060 1061 // 1062 // We sum 1.5 times the second deriv. coefficients because these had been 1063 // divided by 6. already. Usually, 0.25*fHiGainSecondDeriv should be added. 1064 // 1065 for (i=startslice+1; i<lastslice; i++) 1066 sum += fHiGainSignal[i] + 1.5*fHiGainSecondDeriv[i]; 1067 1068 sum += 0.5*fHiGainSignal[lastslice]; 1069 1079 const Float_t step = 0.1; 1080 1081 if (start < 0) 1082 { 1083 last -= start; 1084 start = 0.; 1085 } 1086 1087 Int_t klo = int(start); 1088 Int_t khi = klo+1; 1089 1090 Float_t up = TMath::Ceil(start); 1091 Float_t lo = TMath::Floor(start); 1092 1093 const Int_t m = int((start-klo)/step); 1094 start = step*m + klo; // Correct start for the digitization due to resolution 1095 1096 Float_t x = start; 1097 Float_t a = up-start; 1098 Float_t b = start-lo; 1099 1100 while (1) 1101 { 1102 1103 while (x<up) 1104 { 1105 x += step; 1106 1107 if (x > last) 1108 { 1109 sum *= step; 1110 return; 1111 } 1112 1113 a -= step; 1114 b += step; 1115 1116 sum += a*fHiGainSignal[klo] 1117 + b*fHiGainSignal[khi] 1118 + (a*a*a-a)*fHiGainSecondDeriv[klo] 1119 + (b*b*b-b)*fHiGainSecondDeriv[khi]; 1120 } 1121 1122 up += 1.; 1123 lo += 1.; 1124 klo++; 1125 khi++; 1126 start += 1.; 1127 a = 1.; 1128 b = 0.; 1129 } 1130 1070 1131 } 1071 1072 void MExtractTimeAndChargeSpline::CalcIntegralLoGain(Float_t &sum, Int_t startslice, Int_t lastslice) 1132 void MExtractTimeAndChargeSpline::CalcIntegralLoGain(Float_t &sum, Float_t start, Float_t last) 1073 1133 { 1074 1134 1075 if (startslice < 0) 1076 { 1077 lastslice -= startslice; 1078 startslice = 0; 1079 } 1080 1081 Int_t i = startslice; 1082 sum = 0.5*fLoGainSignal[i]; 1083 1084 // 1085 // We sum 1.5 times the second deriv. coefficients because these had been 1086 // divided by 6. already. Usually, 0.25*fLoGainSecondDeriv should be added. 1087 // 1088 for (i=startslice+1; i<lastslice; i++) 1089 sum += fLoGainSignal[i] + 1.5*fLoGainSecondDeriv[i]; 1090 1091 sum += 0.5*fLoGainSignal[lastslice]; 1092 1135 const Float_t step = 0.1; 1136 1137 if (start < 0) 1138 { 1139 last -= start; 1140 start = 0.; 1141 } 1142 1143 Int_t klo = int(start); 1144 Int_t khi = klo+1; 1145 1146 Float_t up = TMath::Ceil(start); 1147 Float_t lo = TMath::Floor(start); 1148 1149 const Int_t m = int((start-klo)/step); 1150 start = step*m + klo; // Correct start for the digitization due to resolution 1151 1152 Float_t x = start; 1153 Float_t a = up-start; 1154 Float_t b = start-lo; 1155 1156 while (1) 1157 { 1158 1159 while (x<up) 1160 { 1161 x += step; 1162 1163 if (x > last) 1164 { 1165 sum *= step; 1166 return; 1167 } 1168 1169 a -= step; 1170 b += step; 1171 1172 sum += a*fHiGainSignal[klo] 1173 + b*fHiGainSignal[khi] 1174 + (a*a*a-a)*fHiGainSecondDeriv[klo] 1175 + (b*b*b-b)*fHiGainSecondDeriv[khi]; 1176 } 1177 1178 up += 1.; 1179 lo += 1.; 1180 klo++; 1181 khi++; 1182 start += 1.; 1183 a = 1.; 1184 b = 0.; 1185 } 1093 1186 } 1187 1094 1188 1095 1189 -
trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.h
r5544 r5593 39 39 Float_t fFallTime; // The usual fall time of the pulse 40 40 41 UInt_tfRandomIter; // Counter used to randomize weights for noise calculation41 Int_t fRandomIter; // Counter used to randomize weights for noise calculation 42 42 43 43 Byte_t fFlags; // Bit-field to hold the time extraction types … … 47 47 Bool_t InitArrays(); 48 48 49 void CalcIntegralHiGain(Float_t &sum, Int_t startslice, Int_t lastslice);50 void CalcIntegralLoGain(Float_t &sum, Int_t startslice, Int_t lastslice);49 void CalcIntegralHiGain(Float_t &sum, Float_t start, Float_t last); 50 void CalcIntegralLoGain(Float_t &sum, Float_t start, Float_t last); 51 51 52 52 public: … … 82 82 Byte_t &sat, const MPedestalPix &ped, const Bool_t abflag); 83 83 84 ClassDef(MExtractTimeAndChargeSpline, 0) // Task to Extract Arrival Times and Charges using a Fast Cubic Spline84 ClassDef(MExtractTimeAndChargeSpline, 1) // Task to Extract Arrival Times and Charges using a Fast Cubic Spline 85 85 }; 86 86
Note:
See TracChangeset
for help on using the changeset viewer.