Commit 23e71e7c authored by Riccardo Longo's avatar Riccardo Longo
Browse files

Merge branch 'shengy3-master-patch-92248' into 'master'

Optimize GetDifferential function using two sliding windows

See merge request !3
parents 1e17fc77 71afb17a
...@@ -276,26 +276,41 @@ void WFAnalysis::MedianFilter( Channel* Ch ){ ...@@ -276,26 +276,41 @@ void WFAnalysis::MedianFilter( Channel* Ch ){
*/ */
void WFAnalysis::GetDifferential( Channel* Ch ){ void WFAnalysis::GetDifferential( Channel* Ch ){
//Pad the front of the vector with 0s //Pad the front 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 );
// 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 //decalare temp variable to store the sum before and after the i data point
double sum_before = 0; double sum_before = 0;
double sum_after = 0; double sum_after = 0;
//calculate the sum before and after the i data point
for (int i = 0; i < Ch->diffSmoothing; i++ ){ // Generate 2 sliding window, sum_before and sum_after
sum_before += Ch->WF.at( bin - i ); // Calculate the sum before and after the start data point
sum_after += Ch->WF.at( bin + i ); 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 //set the bin to the calculated derivative value
Ch->vDiff.push_back( sum_after - sum_before); Ch->vDiff.push_back( sum_after - sum_before);
Ch->FirstDerivative->SetBinContent(bin,(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 }//end derivative loop
//Pad the back of the vector with 0s //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 /** @brief GetRMS method for WFAnalysis
......
Supports Markdown
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