38 {
39
40 if(DoubleAndWeights.empty()) return 0.;
41 if(DoubleAndWeights.size() == 1) return DoubleAndWeights.begin()->first;
42
43#ifdef FSMWMODE1DFINDER_DEBUG
44 msg(MSG::DEBUG) <<
"entered FsmwMode1dFinder::GetMode " <<
endmsg;
45#endif
46
47
49
50
51 std::vector<DoubleAndWeight>::const_iterator
begin=DoubleAndWeights.begin();
52 std::vector<DoubleAndWeight>::const_iterator
end=DoubleAndWeights.end();
53
54 double overallweight(0.);
55 std::vector<DoubleAndWeight>::const_iterator best_begin=
begin;
56 std::vector<DoubleAndWeight>::const_iterator best_end=
end;
57
58#ifdef FSMWMODE1DFINDER_DEBUG
59 msg(MSG::DEBUG) <<
"Size of incoming vector is" << DoubleAndWeights.size() <<
endmsg;
60#endif
61
62
63 double last_value(1e100);
64
65 bool isthelast=false;
66
69 while (!isthelast) {
70
72 if (counter==2) {
74 }
75
76#ifdef FSMWMODE1DFINDER_DEBUG
77 if(
msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"Before \"int step = (int)std::floor(fraction*(end-begin+1))\" " <<
endmsg;
78#endif
79 int step = (
int)std::floor(fraction*(end-begin+1));
80 overallweight=0.;
81 {
82 std::vector<DoubleAndWeight>::const_iterator
i=
begin;
83 if (step>0) {
84 std::vector<DoubleAndWeight>::const_iterator j_end=
i+
step-1;
85 for (std::vector<DoubleAndWeight>::const_iterator j=i;j!=j_end;++j) {
86#ifdef FSMWMODE1DFINDER_DEBUG
87 if(
msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"In the single interval, the component number unknown, value: " << j->first <<
" weight "
89#endif
90 overallweight+=j->second;
91 }
92 }
93 }
94
95 std::vector<DoubleAndWeight>::const_iterator i_last =
begin+
step-1;
96
97#ifdef FSMWMODE1DFINDER_DEBUG
98 if(
msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"After \"int step = (int)std::floor(fraction*(end-begin+1))\" " <<
endmsg;
99#endif
100 for (std::vector<DoubleAndWeight>::const_iterator i=begin;
i!=(
end-
step+1);++
i, ++i_last) {
101#ifdef FSMWMODE1DFINDER_DEBUG
102 if(
msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"Interval number unknown, value: " <<
i->first <<
endmsg;
103#endif
104
105
106 overallweight+= i_last->second;
107
108 #ifdef FSMWMODE1DFINDER_DEBUG
109 if (debug_counter>0)
110 {
111 --debug_counter;
112 double alt_overallweight=0.;
113 for (std::vector<DoubleAndWeight>::const_iterator j=i;j!=
i+
step;j++) {
114#ifdef FSMWMODE1DFINDER_DEBUG
115 if(
msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"In the single interval, the component number unknown, value: " << j->first <<
" weight "
117#endif
118 alt_overallweight+=j->second;
119 }
120 if (std::abs(alt_overallweight - overallweight) > alt_overallweight * std::numeric_limits<double>::epsilon() * 16 ) {
121 ATH_MSG_ERROR(
"Weights differ: " << alt_overallweight <<
" != " << overallweight);
122 }
123 }
124 #endif
125
126
127 double new_value = ((
i+
step-1)->first-
i->first)/overallweight;
128 if (new_value<last_value) {
129#ifdef FSMWMODE1DFINDER_DEBUG
130 msg(MSG::DEBUG) <<
"New value: " << ((
i+
step-1)->first-
i->first)/overallweight <<
" while the previous one was " <<
132 if(
msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"Best case since ever now" <<
endmsg;
133#endif
134 last_value=((
i+
step-1)->first-
i->first)/overallweight;
137 }
138 overallweight-=
i->second;
139
140 }
141
142#ifdef FSMWMODE1DFINDER_DEBUG
143 msg(MSG::DEBUG) <<
"Ended a cycle with success" <<
endmsg;
144 if (begin==best_begin && end ==best_end) {
146 }
147#endif
148
151 last_value=1e100;
152
153
154 if (best_end-best_begin<=2) isthelast=true;
155 }
156
157
158
159
160
161
162 if (best_end-best_begin==2)
163 {
164 std::vector<DoubleAndWeight>::const_iterator medium=
begin;
165 ++medium;
166 return (
begin->first*
begin->second+medium->first*medium->second+
end->first*
end->second)/(
begin->second+medium->second+
end->second);
167 }
168
169
171
172 }