Skip to content

Commit

Permalink
Merge pull request #42 from rest-for-physics/fix-some-time-calculations
Browse files Browse the repository at this point in the history
fix integral threshold trigger mode
  • Loading branch information
lobis authored Feb 28, 2024
2 parents ba16bf1 + 9109fab commit fbb5bfa
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions src/TRestDetectorSignalToRawSignalProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ TRestEvent* TRestDetectorSignalToRawSignalProcess::ProcessEvent(TRestEvent* inpu
return nullptr;
}

double maxTime = 0;
double maxTime = std::numeric_limits<float>::min();
double minTime = std::numeric_limits<float>::max();
for (const auto& signal : tpcSignals) {
const auto maxSignalTime = signal->GetMaxTime();
Expand All @@ -321,23 +321,21 @@ TRestEvent* TRestDetectorSignalToRawSignalProcess::ProcessEvent(TRestEvent* inpu
return nullptr;
}
if (minTime < 0) {
RESTWarning
<< "TRestDetectorSignalToRawSignalProcess::ProcessEvent: " << inputEvent->GetID()
<< " signal minTime < 0. Setting min time to 0, but this should probably never happen"
<< RESTendl;
minTime = 0;
// TODO: this should raise an exception
// exit(1);
RESTError << "TRestDetectorSignalToRawSignalProcess::ProcessEvent: " << inputEvent->GetID()
<< " signal minTime < 0. Setting min time to 0, but this should never happen"
<< RESTendl;
exit(1);
}

double t = minTime;
double triggerTime = minTime;
bool thresholdReached = false;
double maxEnergy = 0;
while (t < maxTime) {
while (triggerTime <= maxTime + fSampling) {
// iterate over number of signals
double energy = 0;
const double startTime = triggerTime - fSampling * fNPoints;
for (const auto& signal : tpcSignals) {
energy += signal->GetIntegralWithTime(t - fSampling * fNPoints, t);
energy += signal->GetIntegralWithTime(startTime, triggerTime);
}
if (energy > maxEnergy) {
maxEnergy = energy;
Expand All @@ -346,22 +344,16 @@ TRestEvent* TRestDetectorSignalToRawSignalProcess::ProcessEvent(TRestEvent* inpu
thresholdReached = true;
break;
}
t += fSampling;
triggerTime += fSampling;
}

if (!thresholdReached) {
/*
cout << "TRestDetectorSignalToRawSignalProcess::ProcessEvent: "
<< "Integral threshold for trigger not reached. Maximum energy reached: " << maxEnergy
<< endl;
*/
return nullptr;
}

double startTime = t;
startTimeNoOffset = startTime;
startTimeNoOffset = triggerTime;

SetObservableValue("triggerTimeTPC", startTime);
SetObservableValue("triggerTimeTPC", triggerTime);
}

} else if (fTriggerMode == "fixed") {
Expand Down

0 comments on commit fbb5bfa

Please sign in to comment.