@@ -90,27 +90,33 @@ float WeightCalculatorFromHistogram::checkIntegral(std::vector<float> wgt1, std:
90
90
float myint=0 ;
91
91
float refint=0 ;
92
92
for (int i=0 ; i<(int )wgt1.size (); ++i) {
93
+ if (verbose_) {
94
+ std::cout << " i = " << i << " : wgt1 = " << wgt1[i] << " ; wgt2 = " << wgt2[i] << " ; refvals = " << refvals_[i] << ' \n ' ;
95
+ }
93
96
myint += wgt1[i]*refvals_[i];
94
97
refint += wgt2[i]*refvals_[i];
95
98
}
99
+ if (verbose_) {
100
+ std::cout << " myint = " << myint << " \n refint = " << refint << ' \n ' ;
101
+ }
96
102
return (myint-refint)/refint;
97
103
}
98
104
99
105
void WeightCalculatorFromHistogram::fixLargeWeights (std::vector<float > &weights, float maxshift,float hardmax) {
100
- float maxw = std::min (*(std::max_element (weights.begin (),weights.end ())),float (5 .));
101
- std::vector<float > cropped;
102
- while (maxw > hardmax) {
103
- cropped.clear ();
104
- for (int i=0 ; i<(int )weights.size (); ++i) cropped.push_back (std::min (maxw,weights[i]));
105
- float shift = checkIntegral (cropped,weights);
106
- if (verbose_) std::cout << " For maximum weight " << maxw << " : integral relative change: " << shift << std::endl;
107
- if (fabs (shift) > maxshift) break ;
108
- maxw *= 0.95 ;
109
- }
110
- maxw /= 0.95 ;
111
- if (cropped.size ()>0 ) {
112
- for (int i=0 ; i<(int )weights.size (); ++i) cropped[i] = std::min (maxw,weights[i]);
113
- float normshift = checkIntegral (cropped,weights);
114
- for (int i=0 ; i<(int )weights.size (); ++i) weights[i] = cropped[i]*(1 -normshift);
106
+ if (verbose_) {
107
+ std::cout << " hardmax = " << hardmax << " \n "
108
+ " maxshift = " << maxshift << ' \n ' ;
115
109
}
110
+ std::vector<float > cropped = weights;
111
+ float sf = 1 .;
112
+ do {
113
+ for (int i=0 ; i<(int )cropped.size (); ++i) cropped[i] = std::min (hardmax,cropped[i]);
114
+ float shift = checkIntegral (cropped,weights);
115
+ sf = 1 . / (1 . + shift);
116
+ if (verbose_) {
117
+ std::cout << " For maximum weight " << hardmax << " : integral relative change: " << shift << ' \n ' ;
118
+ }
119
+ for (int i=0 ; i<(int )cropped.size (); ++i) cropped[i] *= sf;
120
+ } while ( sf > (1 . + maxshift) );
121
+ for (int i=0 ; i<(int )weights.size (); ++i) weights[i] = cropped[i];
116
122
}
0 commit comments