From 4d8fd13fe18c45fa11903ae69a1e885ca350959f Mon Sep 17 00:00:00 2001 From: redford_s Date: Wed, 6 Feb 2019 10:59:41 +0100 Subject: [PATCH] More general functions to find the fit ranges. Results unchanged. The plus/minus 1 in the starting point is important to catch the case where in one gain there are no points atall without switching. --- DB_analysis.cpp | 50 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/DB_analysis.cpp b/DB_analysis.cpp index 94b8bd4..e24826d 100644 --- a/DB_analysis.cpp +++ b/DB_analysis.cpp @@ -11,6 +11,42 @@ #include "TPaveStats.h" #include "TLegend.h" +double highestPointBeforeSwitching(const vector &lower_filter, const vector &higher_filter) { + + // find the highest value in lower_filter that is lower than all entries in higher_filter + double highest_point_before_switching = *min_element(lower_filter.begin(),lower_filter.end())-1.; + + double lowest_entry_in_higher_filter = *min_element(higher_filter.begin(),higher_filter.end()); + for(vector::const_iterator it = lower_filter.begin(); it != lower_filter.end(); ++it) { + if (*it < lowest_entry_in_higher_filter) { + if (*it > highest_point_before_switching) { + highest_point_before_switching = *it; + } + } + } + + return highest_point_before_switching; + +} + +double lowestPointAfterSwitching(const vector &higher_filter, const vector &lower_filter) { + + // find the lowest value in higher_filter that is higher than all entries in lower_filter + double lowest_point_after_switching = *max_element(higher_filter.begin(),higher_filter.end())+1; + + double highest_entry_in_lower_filter = *max_element(lower_filter.begin(),lower_filter.end()); + for(vector::const_iterator it = higher_filter.begin(); it != higher_filter.end(); ++it) { + if (*it > highest_entry_in_lower_filter) { + if (*it < lowest_point_after_switching) { + lowest_point_after_switching = *it; + } + } + } + + return lowest_point_after_switching; + +} + int main(int argc, char* argv[]) { jungfrauStyle(); gROOT->SetBatch(1); @@ -402,12 +438,7 @@ int main(int argc, char* argv[]) { rangemin0 = 4; } - double rangemax0 = *min_element(r1_filter.begin(),r1_filter.end()); - if (nsteps == 40) { - rangemax0 = rangemax0 - 2.; - } else if (nsteps == 80) { - rangemax0 = rangemax0 - 1.; - } + double rangemax0 = highestPointBeforeSwitching(r0_filter,r1_filter); range0maxhist->Fill(rangemax0); range0maxmap->Fill(i%NC,i/NC,rangemax0); @@ -431,12 +462,7 @@ int main(int argc, char* argv[]) { fit1_e->SetLineColor(kBlue); fit1_e->SetLineStyle(2); - double rangemin1 = *max_element(r0_filter.begin(),r0_filter.end()); - if (nsteps == 40) { - rangemin1 = rangemin1 + 2.; - } else if (nsteps == 80) { - rangemin1 = rangemin1 + 1.; - } + double rangemin1 = lowestPointAfterSwitching(r1_filter,r0_filter); range1minhist->Fill(rangemin1); range1minmap->Fill(i%NC,i/NC,rangemin1);