1313#define fEpsilon 1 .e-2
1414using std::cout;
1515using std::endl;
16- void csvc_interface::obtain_probabilities (double c_p , double g_p, int eval_bkg){
17- cout << " Entering the obtain probabilities function ... " << endl;
18- cout << " input variables - C: " << c_p <<
19- " gamma: " << g_p <<
20- " highest accuracy cut: " << highest_accur_cut <<
21- " # of bkg events in eval sample: " << eval_bkg << endl;
16+ void csvc_interface::obtain_probabilities (const double c_p , const double g_p, const int eval_bkg, std::vector< int > * output ){
17+ cout << " \n Classifying the evaluation sample ... " << endl;
18+ cout << " input variables - C: " << c_p <<
19+ " gamma: " << g_p <<
20+ " highest significance cut on probability: " << highest_accur_cut <<
21+ " # of bkg events in eval sample: " << eval_bkg << endl;
2222 timer deltat;
2323 disc_S = new TH1D (" svm_disc_signal" , " SVM probability signal" , disc_nbin , 0 ., 1 .);
2424 disc_B = new TH1D (" svm_disc_background" , " SVM probability background" , disc_nbin , 0 ., 1 .);
@@ -34,6 +34,7 @@ void csvc_interface::obtain_probabilities(double c_p , double g_p, int eval_bkg)
3434 disc_B->Sumw2 ();
3535 /* svm prob container */
3636 double prob[2 ];
37+ bool pre_doprobabilitycalc = doprobabilitycalc ;
3738 doprobabilitycalc = true ;
3839 set_parameters ();
3940 set_indexes ();
@@ -45,7 +46,7 @@ void csvc_interface::obtain_probabilities(double c_p , double g_p, int eval_bkg)
4546 if (min_features.empty () && max_features.empty ()){
4647 get_extrema_features (sample_train, min_features, max_features);
4748 }
48- scale (sample_train, min_features, max_features);
49+ scale (sample_train, min_features, max_features, true );
4950 scale (sample_eval, min_features, max_features);
5051 // adjust_weights(sample_train, kBkg, (double)nsig_train/(double)nbkg_train);
5152 deltat.start ();
@@ -71,10 +72,12 @@ void csvc_interface::obtain_probabilities(double c_p , double g_p, int eval_bkg)
7172 for (int comp = 0 ; comp < nsamp_eval; comp++){
7273 svm_predict_probability (csvc_svm_model, sample_eval.x [comp], prob);
7374 if (eval_bkg > comp){
75+ if (output) output -> push_back (0 );
7476 disc_B -> Fill (prob[1 ], sample_eval.W [comp]);
7577 disc_B_roc-> Fill (prob[1 ], sample_eval.W [comp]);
7678 if (prob[1 ] > highest_accur_cut) {bkg_yield += sample_eval.W [comp];}
7779 } else {
80+ if (output) output -> push_back (1 );
7881 disc_S -> Fill (prob[1 ], sample_eval.W [comp]);
7982 disc_S_roc-> Fill (prob[1 ], sample_eval.W [comp]);
8083 if (prob[1 ] > highest_accur_cut) {sig_yield += sample_eval.W [comp];}
@@ -87,13 +90,19 @@ void csvc_interface::obtain_probabilities(double c_p , double g_p, int eval_bkg)
8790 tut->Close ();
8891 /* assume 25% uncertainty */
8992 fom FOM (systematical_unc);
90- FOM.maxSignificance (disc_S, disc_B, true , 0 ., cuteff);
93+ if (!pre_doprobabilitycalc){
94+ FOM.maxSignificance (disc_S, disc_B, true , 0 ., cuteff);
95+ } else {
96+ FOM.maxSignificance (disc_S, disc_B, false , 0 ., cuteff);
97+ }
9198 roc = FOM.ROC (disc_S_roc, disc_B_roc);
9299 FOM.setSignal (sig_yield);
93100 FOM.setBackground (bkg_yield);
94- cout << " Significance obtained from the given cut: " << FOM.getSignificance (fom::asimov) <<
101+ if (pre_doprobabilitycalc){
102+ cout << " Significance obtained from the given cut: " << FOM.getSignificance (fom::asimov) <<
95103 " signal yield: " << sig_yield <<
96104 " background yield: " << bkg_yield << endl;
105+ }
97106}
98107void csvc_interface::set_gamma_array (std::vector<double > & gamma_arr, unsigned iter){
99108 int mid = (gamma_arr.size () - 1 )/2 ;
@@ -220,7 +229,7 @@ double csvc_interface::parameter_comparison(const vvvector<double>& vSig, const
220229 high_accuracy_settings[3 ] = gamma[highest];
221230 highest_accur_gamma = gamma[highest];
222231 cout <<" For given C value: " << std::setprecision (16 ) << C <<
223- " highest accuracy : " << std::setprecision (6 ) << accuracy->at (highest) <<
232+ " highest significance : " << std::setprecision (6 ) << accuracy->at (highest) <<
224233 " obtained with gamma: " << std::setprecision (16 ) << gamma [highest] <<
225234 " on the bin " << std::setprecision (6 ) << max_cut_bin->at (highest) <<
226235 " in the iteration " << iteration << endl;
@@ -251,20 +260,20 @@ bool csvc_interface::parameter_decision() {
251260 if (highest_accur_C > C_cut && highest_accur_C / above_cut_inc > C_cut){
252261 above_cut_inc -= (above_cut_inc - 1 .) * 4 . / 5 .;
253262 below_cut_inc -= (below_cut_inc - 1 .) * 4 . / 5 .;
254- cout << " entering precise scan with initial C " << highest_accur_C / (above_cut_inc * above_cut_inc) << " and previous accuracy " << it_max->at (0 ) << endl;
263+ cout << " entering precise scan with initial C " << highest_accur_C / (above_cut_inc * above_cut_inc) << " and previous signifincance " << it_max->at (0 ) << endl;
255264 this ->parameter_scan (highest_accur_C - 2 . * above_cut_inc , it_max->at (0 ));
256265 } else {
257266 above_cut_inc -= (above_cut_inc - 1 .) * 4 . / 5 .;
258267 below_cut_inc -= (below_cut_inc - 1 .) * 4 . / 5 .;
259- cout << " entering precise scan with initial C " << highest_accur_C / (below_cut_inc * below_cut_inc) << " and previous accuracy " << it_max->at (0 ) << endl;
268+ cout << " entering precise scan with initial C " << highest_accur_C / (below_cut_inc * below_cut_inc) << " and previous significance " << it_max->at (0 ) << endl;
260269 this ->parameter_scan (highest_accur_C / (below_cut_inc * below_cut_inc) , it_max->at (0 ));
261270 }
262271 } else {
263- cout << " Optimized C " << std::setprecision (16 ) << std::fixed << highest_accur_C <<
272+ cout << " \n Optimized C " << std::setprecision (16 ) << std::fixed << highest_accur_C <<
264273 " optimized gamma " << std::setprecision (16 ) << std::fixed << highest_accur_gamma <<
265274 " optimized discriminator cut " << std::setprecision (4 ) << std::fixed << highest_accur_cut <<
266- " with the accuracy of " << std::setprecision (4 ) << std::fixed << it_max->at (0 ) <<
267- " in the test sample " << std::setprecision (12 ) << endl;
275+ " with the significance of " << std::setprecision (4 ) << std::fixed << it_max->at (0 ) <<
276+ " in the test sample \n " << std::setprecision (12 ) << endl;
268277 clean (para_scan_problem_test);
269278 clean (para_scan_problem_train);
270279 return true ;
@@ -349,10 +358,10 @@ void csvc_interface::get_extrema_features (const svm_problem &tbs, std::vector<d
349358 }
350359 }
351360}
352- void csvc_interface::scale (svm_problem &tbs, const std::vector<double > & min, const std::vector<double > & max){
353- cout << " Entering scale function: " << endl;
361+ void csvc_interface::scale (svm_problem &tbs, const std::vector<double > & min, const std::vector<double > & max, const bool print_out ){
362+ if (print_out) cout << " Entering scale function: " << endl;
354363 for (unsigned feat = 0 ; feat < nfeature; feat++) {
355- cout << " feature: " << feat + 1 << " min: " << min.at (feat) << " max: " << max.at (feat) << endl;
364+ if (print_out) cout << " feature: " << feat + 1 << " min: " << min.at (feat) << " max: " << max.at (feat) << endl;
356365 }
357366 for (unsigned ind = 0 ; ind < tbs.l ; ind++) {
358367 for ( unsigned feat = 0 ; feat < nfeature; feat++) {
0 commit comments