Commit 71afb17a authored by shengy3's avatar shengy3
Browse files

Optimize GetDifferential function using two sliding windows

parent 1e17fc77
......@@ -276,26 +276,41 @@ void WFAnalysis::MedianFilter( Channel* Ch ){
*/
void WFAnalysis::GetDifferential( Channel* Ch ){
//Pad the front of the vector with 0s
for(int bin = 0; bin < Ch->diffSmoothing; bin ++) Ch->vDiff.push_back( 0.0 );
// Loop over histogram
for( unsigned int bin = Ch->diffSmoothing; bin < Ch->WF_histo->GetNbinsX() - Ch->diffSmoothing ; bin++ ){
//decalare temp variable to store the sum before and after the i data point
double sum_before = 0;
double sum_after = 0;
//calculate the sum before and after the i data point
for (int i = 0; i < Ch->diffSmoothing; i++ ){
sum_before += Ch->WF.at( bin - i );
sum_after += Ch->WF.at( bin + i );
}
//decalare temp variable to store the sum before and after the i data point
double sum_before = 0;
double sum_after = 0;
// Generate 2 sliding window, sum_before and sum_after
// Calculate the sum before and after the start data point
for (int i = 1; i <= Ch->diffSmoothing; i++ ){
sum_before += Ch->WF.at( Ch->diffSmoothing - i );
sum_after += Ch->WF.at( Ch->diffSmoothing + i );
}
// Loop over histogram
for( unsigned int bin = Ch->diffSmoothing; bin < Ch->WF_histo->GetNbinsX() - Ch->diffSmoothing - 1 ; bin++ ){
//set the bin to the calculated derivative value
Ch->vDiff.push_back( sum_after - sum_before);
Ch->FirstDerivative->SetBinContent(bin,(sum_after - sum_before));
// Move the sum_before window forward
sum_before += Ch->WF.at( bin );
sum_before -= Ch->WF.at( bin - Ch->diffSmoothing );
// Move the sum_after window forward
sum_after -= Ch->WF.at( bin + 1);
sum_after += Ch->WF.at( bin + Ch->diffSmoothing + 1);
}//end derivative loop
//Pad the back of the vector with 0s
for(int bin = 0; bin < Ch->diffSmoothing; bin ++) Ch->vDiff.push_back( 0.0 );
for(int bin = 0; bin <= Ch->diffSmoothing; bin ++) Ch->vDiff.push_back( 0.0 );
}
/** @brief GetRMS method for WFAnalysis
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment