1 #include "StDetectorDbMaker/St_tpcChargeEventC.h"
2 #include "St_starClockOnlC.h"
5 double St_tpcChargeEventC::timeDifference(
unsigned long long bunchCrossingNumber,
int idx) {
7 return ((
double) (bunchCrossingNumber - eventBunchCrossing(idx))) /
8 (St_starClockOnlC::instance()->Frequency());
11 int St_tpcChargeEventC::indexBeforeBunchCrossing(
unsigned long long bunchCrossingNumber) {
15 int lastIndex = nChargeEvents() - 1;
16 if (lastIndex < 0)
return -999;
18 if (localSearchUpperIndex < 0) {
20 localSearchLowerIndex = nChargeEvents() / 2;
21 localSearchUpperIndex = localSearchLowerIndex;
26 if (bunchCrossingNumber >= eventBunchCrossing(localSearchUpperIndex) &&
27 localSearchLowerIndex != lastIndex) direction = 1;
28 else if (bunchCrossingNumber < eventBunchCrossing(localSearchLowerIndex)) direction = -1;
29 else return localSearchLowerIndex;
33 while (direction > 0) {
34 localSearchLowerIndex = localSearchUpperIndex;
35 localSearchUpperIndex = std::min(lastIndex,localSearchUpperIndex + delta);
36 delta = localSearchUpperIndex - localSearchLowerIndex;
37 if (bunchCrossingNumber < eventBunchCrossing(localSearchUpperIndex)) direction = 0;
38 else if (localSearchUpperIndex == lastIndex) {
39 localSearchLowerIndex = lastIndex;
43 while (direction < 0) {
44 localSearchUpperIndex = localSearchLowerIndex;
45 localSearchLowerIndex = std::max(0,localSearchLowerIndex - delta);
46 delta = localSearchUpperIndex - localSearchLowerIndex;
47 if (bunchCrossingNumber >= eventBunchCrossing(localSearchLowerIndex)) direction = 0;
48 else if (localSearchLowerIndex == 0) {
49 localSearchUpperIndex = 0;
56 int tempIndex = localSearchLowerIndex + (delta/2);
57 if (bunchCrossingNumber < eventBunchCrossing(tempIndex)) localSearchUpperIndex = tempIndex;
58 else localSearchLowerIndex = tempIndex;
59 delta = localSearchUpperIndex - localSearchLowerIndex;
62 return localSearchLowerIndex;
65 int St_tpcChargeEventC::findChargeTimes(
unsigned long long bunchCrossingNumber,
unsigned long long bunchCrossingWindow) {
66 int idx2 = indexBeforeBunchCrossing(bunchCrossingNumber);
67 int idx1 = indexBeforeBunchCrossing(bunchCrossingNumber-bunchCrossingWindow);
70 localStoreCharges.Set(n,&(eventCharges()[idx1]));
71 localStoreTimesSinceCharges.Set(n);
72 for (
int i=0; i<n; i++)
73 localStoreTimesSinceCharges.AddAt(timeDifference(bunchCrossingNumber,idx1+i),i);
77 int St_tpcChargeEventC::findChargeTimes(
unsigned long long bunchCrossingNumber,
double timeWindow) {
78 return findChargeTimes(bunchCrossingNumber,
79 (
unsigned long long) (timeWindow*(St_starClockOnlC::instance()->Frequency())));