128 double *
obj,
double *rhs,
double *lbound,
double *ubound,
130 double *diag,
double *odiag,
134 double *dxs,
double *dxsn,
double *
up,
138 double *ddspr,
double *ddsprn,
double *dsup,
double *ddsup,
143 double *ddv,
double *ddvn,
double *prinf,
145 double *upinf,
double *duinf,
double *
scale,
155 int *ecolpnt,
int *
count,
int *vcstat,
int *pivots,
156 int *invprm,
int *snhead,
int *nodtyp,
int *inta1,
166 int *iter,
int *corect,
int *fixn,
int *dropn,
int *fnzmax,
167 int *fnzmin,
double *addobj,
double *bigbou,
177 #pragma clang diagnostic push
178 #pragma clang diagnostic ignored "-Wunused-const-variable"
182 static const int minimize = 1;
183 static const int maximize = -1;
184 static const char less_equal =
'L';
185 static const char equal =
'E';
186 static const char greater_equal =
'G';
187 static const char range =
'R';
188 #pragma clang diagnostic pop
191 bool _variable_named;
193 std::vector<double> _rhs;
194 std::vector<char> _constraint_sense;
195 std::vector<double> _range_value;
196 std::vector<char *> _row_name;
198 std::vector<double> _objective;
199 std::vector<double> _lower_bound;
200 std::vector<double> _upper_bound;
201 std::vector<char *> _column_name;
203 std::vector<int> _coefficient_row;
204 std::vector<int> _coefficient_column;
205 std::vector<double> _coefficient_value;
210 _constraint_sense.clear();
211 for (std::vector<char *>::const_iterator iterator =
213 iterator != _row_name.end(); iterator++) {
218 void clear_column(
void)
221 _lower_bound.clear();
222 _upper_bound.clear();
223 for (std::vector<char *>::const_iterator iterator =
224 _column_name.begin();
225 iterator != _column_name.end(); iterator++) {
228 _column_name.clear();
230 void clear_coefficient(
void)
232 _coefficient_row.clear();
233 _coefficient_column.clear();
234 _coefficient_value.clear();
236 void to_csr(std::vector<int> &column_pointer,
237 std::vector<int> &row_index,
238 std::vector<double> &nonzero_value,
239 const int index_start = 1)
244 std::vector<std::vector<std::pair<int, double> > >
245 column_index(_objective.size(),
246 std::vector<std::pair<int, double> >());
248 std::vector<int>::const_iterator iterator_row =
249 _coefficient_row.begin();
250 std::vector<int>::const_iterator iterator_column =
251 _coefficient_column.begin();
252 std::vector<double>::const_iterator iterator_value =
253 _coefficient_value.begin();
255 for (; iterator_value != _coefficient_value.end();
256 iterator_row++, iterator_column++, iterator_value++) {
257 column_index[*iterator_column].push_back(
258 std::pair<int, double>(
260 *iterator_row + index_start, *iterator_value));
263 for (std::vector<std::vector<std::pair<int, double> > >::
264 iterator iterator_outer = column_index.begin();
265 iterator_outer != column_index.end(); iterator_outer++) {
267 column_pointer.push_back(row_index.size() + index_start);
268 std::sort(iterator_outer->begin(), iterator_outer->end());
269 for (std::vector<std::pair<int, double> >::const_iterator
270 iterator_inner = iterator_outer->begin();
271 iterator_inner != iterator_outer->end();
273 row_index.push_back(iterator_inner->first);
274 nonzero_value.push_back(iterator_inner->second);
278 column_pointer.push_back(row_index.size() + index_start);
281 problem_t(
const bool variable_named)
282 : _optimized(
false), _variable_named(variable_named)
295 virtual int populate(
void) = 0;
296 size_t nrow(
void)
const
300 size_t ncolumn(
void)
const
302 return _objective.size();
304 void push_back_row(
const char constraint_sense,
308 _constraint_sense.push_back(constraint_sense);
310 if (_variable_named) {
314 snprintf(name, name_length,
"c%llu",
315 static_cast<unsigned long long>(_rhs.size()));
316 _row_name.push_back(name);
319 void push_back_row(
const std::string &constraint_sense,
324 if (constraint_sense ==
"<=") {
326 push_back_row(rhs, cplex_sense);
328 else if (constraint_sense ==
"==") {
330 push_back_row(rhs, cplex_sense);
332 else if (constraint_sense ==
">=") {
334 push_back_row(rhs, cplex_sense);
337 fprintf(stderr,
"%s:%d: illegal sense (`%s')\n",
338 __FILE__, __LINE__, constraint_sense.c_str());
341 void push_back_column(
const double objective,
342 const double lower_bound,
343 const double upper_bound)
345 _objective.push_back(objective);
346 _lower_bound.push_back(lower_bound);
347 _upper_bound.push_back(upper_bound);
349 if (_variable_named) {
350 static const size_t name_length = 24;
353 snprintf(name, name_length,
"x%llu",
354 static_cast<unsigned long long>(
356 _column_name.push_back(name);
359 void push_back_coefficient(
360 const int row,
const int column,
const double value)
362 _coefficient_row.push_back(row);
363 _coefficient_column.push_back(column);
364 _coefficient_value.push_back(value);
366 virtual int optimize(
void) = 0;
367 int optimize_primal_simplex(
void)
371 int optimize_dual_simplex(
void)
375 int optimize_barrier(
void)
379 int optimize_network(
void)
383 int optimize_sifting(
void)
387 int optimize_concurrent(
void)
391 int optimize_deterministic_concurrent(
void)
397 int &solution_status,
double &objective_value,
398 std::vector<double> &variable_primal,
399 std::vector<double> &variable_dual,
400 std::vector<double> &variable_slack_surplus,
401 std::vector<double> &reduced_cost) = 0;
403 double &objective_value,
404 std::vector<double> &variable_primal,
405 std::vector<double> &variable_dual,
406 std::vector<double> &variable_slack_surplus,
407 std::vector<double> &reduced_cost)
411 return solve(solution_status, objective_value,
412 variable_primal, variable_dual,
413 variable_slack_surplus, reduced_cost);
416 std::vector<double> &variable_primal,
417 std::vector<double> &variable_dual,
418 std::vector<double> &variable_slack_surplus,
419 std::vector<double> &reduced_cost)
422 double objective_value;
424 return solve(solution_status, objective_value,
425 variable_primal, variable_dual,
426 variable_slack_surplus, reduced_cost);
429 int &solution_status,
double &objective_value,
430 std::vector<double> &variable_primal,
431 std::vector<double> &variable_dual)
433 std::vector<double> variable_slack_surplus;
434 std::vector<double> reduced_cost;
436 return solve(solution_status, objective_value,
437 variable_primal, variable_dual,
438 variable_slack_surplus, reduced_cost);
441 std::vector<double> &variable_primal,
442 std::vector<double> &variable_dual)
445 double objective_value;
447 return solve(solution_status, objective_value, variable_primal,
451 std::vector<double> &variable_primal)
453 std::vector<double> variable_dual;
455 return solve(variable_primal, variable_dual);
459 class environment_t {
461 std::vector<problem_t *> _problem;
464 #ifndef BPMPD_INFINITY_BOUND
465 #define BPMPD_INFINITY_BOUND 1e+30
466 #endif // BPMPD_INFINITY_BOUND
468 #ifndef BPMPD_VERSION_STRING
469 #define BPMPD_VERSION_STRING "Version 2.11 (1996 December)"
470 #endif // BPMPD_VERSION_STRING
472 class bpmpd_environment_t;
474 class bpmpd_problem_t :
public problem_t {
476 #pragma clang diagnostic push
477 #pragma clang diagnostic ignored "-Wunused-const-variable"
479 #pragma clang diagnostic pop
481 double _objective_sense;
482 double _objective_value;
483 std::vector<double> _variable_primal;
484 std::vector<double> _variable_dual;
485 int _solution_status;
487 int ampl_solution_status(
const int termination_code)
489 switch (termination_code) {
503 fprintf(stderr,
"%s:%d: error: unknown termination code "
504 "%d\n", __FILE__, __LINE__, termination_code);
507 fprintf(stderr,
"%s:%d: %d\n", __FILE__, __LINE__,
510 void set_bpmpd_parameter(
void)
595 void append_constraint_sense_bound(
596 std::vector<double> &lower_bound_bpmpd,
597 std::vector<double> &upper_bound_bpmpd)
599 for (std::vector<char>::const_iterator iterator =
600 _constraint_sense.begin();
601 iterator != _constraint_sense.end(); iterator++) {
605 upper_bound_bpmpd.push_back(0);
608 lower_bound_bpmpd.push_back(0);
609 upper_bound_bpmpd.push_back(0);
612 lower_bound_bpmpd.push_back(0);
618 iterator - _constraint_sense.begin();
620 lower_bound_bpmpd.push_back(0);
621 upper_bound_bpmpd.push_back(_range_value[index] -
627 lower_bound_bpmpd.reserve(
dims_.
mn);
628 lower_bound_bpmpd.insert(lower_bound_bpmpd.end(),
629 _lower_bound.begin(),
631 upper_bound_bpmpd.reserve(
dims_.
mn);
632 upper_bound_bpmpd.insert(upper_bound_bpmpd.end(),
633 _upper_bound.begin(),
642 bpmpd_problem_t(
void)
643 : problem_t(
false), _objective_sense(1.0),
644 _objective_value(NAN)
647 inline size_t nrow(
void)
const
651 inline size_t ncolumn(
void)
const
655 inline void set_objective_sense(
int sense)
657 _objective_sense = sense;
666 void push_back_column(
const double objective,
667 const double lower_bound = 0,
670 problem_t::push_back_column(objective, lower_bound,
673 void set_size(
const size_t nonzero_value_size,
674 const double mf = 6.0,
const size_t ma = 0)
676 dims_.
n = _objective.size();
690 std::max(static_cast<size_t>(0), ma);
697 std::vector<int> column_pointer;
699 std::vector<int> row_index;
701 std::vector<double> nonzero_value;
703 to_csr(column_pointer, row_index, nonzero_value);
706 std::bind1st(std::multiplies<double>(),
710 for (
size_t i = 0;
i < 3;
i++) {
711 set_size(nonzero_value.size(), 6.0 * (1 <<
i));
716 set_bpmpd_parameter();
718 std::vector<double> diag(
dims_.
mn, 0);
719 std::vector<double> odiag(
dims_.
mn, 0);
720 std::vector<double> dxs(
dims_.
mn, 0);
721 std::vector<double> dxsn(
dims_.
mn, 0);
723 std::vector<double> dual_residual(
dims_.
mn, 0);
724 std::vector<double> ddspr(
dims_.
mn, 0);
725 std::vector<double> ddsprn(
dims_.
mn, 0);
726 std::vector<double> dsup(
dims_.
mn, 0);
727 std::vector<double> ddsup(
dims_.
mn, 0);
728 std::vector<double> ddsupn(
dims_.
mn, 0);
729 std::vector<double> ddv(
dims_.
m, 0);
730 std::vector<double> ddvn(
dims_.
m, 0);
731 std::vector<double> prinf(
dims_.
m, 0);
732 std::vector<double> upinf(
dims_.
mn, 0);
733 std::vector<double> duinf(
dims_.
mn, 0);
735 std::vector<int> vartyp(
dims_.
n, 0);
736 std::vector<int> slktyp(
dims_.
m, 0);
737 std::vector<int> colpnt(
dims_.
n1, 0);
738 std::vector<int> ecolpnt(
dims_.
mn, 0);
740 std::vector<int> vcstat(
dims_.
mn, 0);
741 std::vector<int> pivots(
dims_.
mn, 0);
742 std::vector<int> invprm(
dims_.
mn, 0);
743 std::vector<int> snhead(
dims_.
mn, 0);
744 std::vector<int> nodtyp(
dims_.
mn, 0);
745 std::vector<int> inta1(
dims_.
mn, 0);
746 std::vector<int> prehis(
dims_.
mn, 0);
748 int termination_code;
757 double bigbou = 1
e+15;
761 _variable_primal.resize(
dims_.
mn);
762 _variable_dual.resize(
dims_.
m);
764 std::vector<double> lower_bound_bpmpd = _lower_bound;
765 std::vector<double> upper_bound_bpmpd = _upper_bound;
767 append_constraint_sense_bound(lower_bound_bpmpd,
770 solver_(&_objective[0], &_rhs[0], &lower_bound_bpmpd[0],
771 &upper_bound_bpmpd[0], &diag[0], &odiag[0],
772 &_variable_primal[0], &dxs[0], &dxsn[0], &
up[0],
773 &dual_residual[0], &ddspr[0], &ddsprn[0],
774 &dsup[0], &ddsup[0], &ddsupn[0],
775 &_variable_dual[0], &ddv[0], &ddvn[0], &prinf[0],
776 &upinf[0], &duinf[0], &
scale[0],
777 &nonzero_value[0], &vartyp[0], &slktyp[0],
778 &column_pointer[0], &ecolpnt[0], &
count[0],
779 &vcstat[0], &pivots[0], &invprm[0], &snhead[0],
780 &nodtyp[0], &inta1[0], &prehis[0], &row_index[0],
781 &rindex[0], &termination_code, &_objective_value,
782 &iter, &correct, &fixn, &dropn, &fnzmax, &fnzmin,
783 &addobj, &bigbou, &infinity_copy, &ft);
785 _objective_value *= _objective_sense;
786 _solution_status = ampl_solution_status(termination_code);
787 if (termination_code != -2) {
793 return _solution_status == 0 ? 0 : 1;
796 int &solution_status,
double &objective_value,
797 std::vector<double> &variable_primal,
798 std::vector<double> &variable_dual,
799 std::vector<double> &variable_slack_surplus,
800 std::vector<double> &reduced_cost)
808 int &solution_status,
double &objective_value,
809 std::vector<double> &variable_primal,
810 std::vector<double> &variable_dual)
812 variable_primal = std::vector<double>(
813 _variable_primal.begin(),
814 _variable_primal.begin() + _objective.size());
815 variable_dual = _variable_dual;
819 friend class bpmpd_environment_t;
822 class bpmpd_environment_t :
public environment_t {
824 bpmpd_environment_t(
void)
827 ~bpmpd_environment_t(
void)
830 int set_verbose(
void);
831 int set_data_checking(
void);
838 return bpmpd_problem_t();
846 double angular_range_reduce(
const double x)
848 if (!std::isfinite(x)) {
852 static const double cody_waite_x_max = 1608.4954386379741381;
853 static const double two_pi_0 = 6.2831853071795649157;
854 static const double two_pi_1 = 2.1561211432631314669e-14;
855 static const double two_pi_2 = 1.1615423895917441336e-27;
858 if (x >= -cody_waite_x_max && x <= cody_waite_x_max) {
859 static const double inverse_two_pi =
860 0.15915494309189534197;
861 const double k = rint(x * inverse_two_pi);
862 ret = ((x - (k * two_pi_0)) - k * two_pi_1) -
875 double hermite_h_normalized(
const size_t n,
const double x)
880 case 3: y = -3.913998411780905*x + 2.6093322745206033*
std::pow(x,3);
break;
881 case 5: y = 4.931174490213579*x - 6.574899320284771*
std::pow(x,3) + 1.3149798640569543*
std::pow(x,5);
break;
882 case 7: y = -5.773117374387059*x + 11.546234748774118*
std::pow(x,3) - 4.618493899509647*
std::pow(x,5) + 0.43985656185806166*
std::pow(x,7);
break;
883 case 9: y = 6.507479403136423*x - 17.353278408363792*
std::pow(x,3) + 10.411967045018276*
std::pow(x,5) - 1.9832318180987192*
std::pow(x,7) + 0.11017954544992885*
std::pow(x,9);
break;
884 case 11: y = -7.167191940825306*x + 23.89063980275102*
std::pow(x,3) - 19.112511842200817*
std::pow(x,5) + 5.460717669200234*
std::pow(x,7) - 0.6067464076889149*
std::pow(x,9) + 0.02206350573414236*
std::pow(x,11);
break;
885 case 13: y = 7.771206704387521*x - 31.084826817550084*
std::pow(x,3) + 31.084826817550084*
std::pow(x,5) - 11.841838787638126*
std::pow(x,7) + 1.9736397979396878*
std::pow(x,9) - 0.14353743985015913*
std::pow(x,11) + 0.0036804471756451056*
std::pow(x,13);
break;
886 case 15: y = -8.331608118589472*x + 38.88083788675087*
std::pow(x,3) - 46.65700546410104*
std::pow(x,5) + 22.217621649571925*
std::pow(x,7) - 4.9372492554604275*
std::pow(x,9) + 0.5386090096865921*
std::pow(x,11) - 0.027620974855722673*
std::pow(x,13) + 0.00052611380677567*
std::pow(x,15);
break;
887 case 17: y = 8.856659222944476*x - 47.23551585570387*
std::pow(x,3) + 66.12972219798543*
std::pow(x,5) - 37.7884126845631*
std::pow(x,7) + 10.496781301267527*
std::pow(x,9) - 1.5268045529116403*
std::pow(x,11) + 0.11744650407012618*
std::pow(x,13) - 0.004474152536004807*
std::pow(x,15) + 0.0000657963608236001*
std::pow(x,17);
break;
898 static const size_t ncms_hcal_edge_pseudorapidity = 82 + 1;
899 static const double cms_hcal_edge_pseudorapidity[
900 ncms_hcal_edge_pseudorapidity] = {
901 -5.191, -4.889, -4.716, -4.538, -4.363, -4.191, -4.013,
902 -3.839, -3.664, -3.489, -3.314, -3.139, -2.964, -2.853,
903 -2.650, -2.500, -2.322, -2.172, -2.043, -1.930, -1.830,
904 -1.740, -1.653, -1.566, -1.479, -1.392, -1.305, -1.218,
905 -1.131, -1.044, -0.957, -0.879, -0.783, -0.696, -0.609,
906 -0.522, -0.435, -0.348, -0.261, -0.174, -0.087,
908 0.087, 0.174, 0.261, 0.348, 0.435, 0.522, 0.609,
909 0.696, 0.783, 0.879, 0.957, 1.044, 1.131, 1.218,
910 1.305, 1.392, 1.479, 1.566, 1.653, 1.740, 1.830,
911 1.930, 2.043, 2.172, 2.322, 2.500, 2.650, 2.853,
912 2.964, 3.139, 3.314, 3.489, 3.664, 3.839, 4.013,
913 4.191, 4.363, 4.538, 4.716, 4.889, 5.191
917 cms_hcal_edge_pseudorapidity,
918 cms_hcal_edge_pseudorapidity +
919 ncms_hcal_edge_pseudorapidity);
921 static const size_t ncms_ecal_edge_pseudorapidity = 344 + 1;
923 for (
size_t i = 0;
i < ncms_ecal_edge_pseudorapidity;
i++) {
926 (ncms_ecal_edge_pseudorapidity - 1)) -
947 for (std::vector<particle_t>::const_iterator iterator =
949 iterator !=
_event.end(); iterator++) {
950 const unsigned int reduced_id =
951 iterator->reduced_particle_flow_id;
955 if (iterator->momentum.Eta() >=
957 iterator->momentum.Eta() <
959 const double azimuth =
960 iterator->momentum.Phi();
963 (*_perp_fourier)[
k - 1][reduced_id]
965 iterator->momentum.Pt() *
967 (*_perp_fourier)[
k - 1][reduced_id]
969 iterator->momentum.Pt() *
978 const size_t nfeature = 2 *
nfourier - 1;
991 scale[0] = 1.0 / 5400.0;
994 scale[1] = 1.0 / 130.0;
997 scale[2] = 1.0 / 220.0;
1000 const size_t index_edge_end =
1006 ((*_perp_fourier)[0 ][
j][0][0] +
1007 (*_perp_fourier)[index_edge_end][
j][0][0]);
1014 ((*_perp_fourier)[0 ][
j][
k][0] +
1015 (*_perp_fourier)[index_edge_end][
j][
k][0]);
1020 ((*_perp_fourier)[0 ][
j][
k][1] +
1021 (*_perp_fourier)[index_edge_end][
j][
k][1]);
1040 #ifdef HAVE_SPARSEHASH
1042 const voronoi_diagram_t::Face face_empty;
1043 google::dense_hash_map<voronoi_diagram_t::Face_handle,
1044 size_t, hash<voronoi_diagram_t::Face_handle> >
1047 face_index.set_empty_key(face_empty);
1048 #else // HAVE_SPARSEHASH
1049 std::map<voronoi_diagram_t::Face_handle, size_t>
1051 #endif // HAVE_SPARSEHASH
1053 for (std::vector<particle_t>::const_iterator iterator =
1055 iterator !=
_event.end(); iterator++) {
1059 for (
int k = -1;
k <= 1;
k++) {
1061 iterator->momentum.Eta(),
1062 iterator->momentum.Phi() +
1064 const voronoi_diagram_t::Face_handle
handle =
1074 for (std::vector<particle_t>::iterator iterator =
1076 iterator !=
_event.end(); iterator++) {
1077 const voronoi_diagram_t::Locate_result
result =
1078 diagram.locate(*iterator);
1079 const voronoi_diagram_t::Face_handle *face =
1080 boost::get<voronoi_diagram_t::Face_handle>(
1082 double polygon_area;
1085 voronoi_diagram_t::Ccb_halfedge_circulator
1086 circulator_start = (*face)->outer_ccb();
1087 bool unbounded =
false;
1090 voronoi_diagram_t::Ccb_halfedge_circulator
1091 circulator = circulator_start;
1096 if (circulator->has_target()) {
1098 circulator->target()->point());
1099 _event[face_index[*face]].incident.
1102 face_index[circulator->twin()->
1110 while (++circulator != circulator_start);
1112 polygon_area = INFINITY;
1115 polygon_area = polygon.area();
1121 iterator->area = fabs(polygon_area);
1126 for (std::vector<particle_t>::iterator iterator =
1128 iterator !=
_event.end(); iterator++) {
1129 int predictor_index = -1;
1130 int interpolation_index = -1;
1135 if (iterator->momentum.Eta() >=
1137 iterator->momentum.Eta() <
1139 predictor_index =
l - 1;
1148 if (iterator->momentum.Eta() >=
1150 iterator->momentum.Eta() <
1152 interpolation_index =
l - 1;
1160 if (iterator->momentum.Eta() >=
1162 iterator->momentum.Eta() <
1164 interpolation_index =
l - 1;
1169 if (predictor_index >= 0 && interpolation_index >= 0) {
1173 const double azimuth = iterator->momentum.Phi();
1174 const float (*
p)[2][82] =
1176 ue_predictor_pf[
j][predictor_index]
1179 #endif // STANDALONE
1184 const size_t norder =
l == 0 ? 9 : 1;
1186 for (
size_t m = 0;
m < 2;
m++) {
1187 float u =
p[
l][
m][0];
1189 for (
size_t n = 0;
n < 2 * nfourier - 1;
n++) {
1190 if ((
l == 0 &&
n == 0) || (
l == 2 && (
n == 3 ||
n == 4))) {
1192 for (
size_t o = 2;
o < norder + 1;
o++) {
1193 u +=
p[
l][
m][9 *
n +
o] *
1194 hermite_h_normalized(
1195 2 *
o - 1, _feature[
n]) *
1196 exp(-_feature[n] * _feature[n]);
1201 pred += u * (
l == 0 ? 1.0 : 2.0) *
1202 (
m == 0 ?
cos(l * azimuth) :
1204 if (l == 0 &&
m == 0) {
1218 ue_interpolation_pf0[predictor_index][
1219 interpolation_index];
1223 ue_interpolation_pf1[predictor_index][
1224 interpolation_index];
1228 ue_interpolation_pf2[predictor_index][
1229 interpolation_index];
1235 interpolation_index];
1240 interpolation_index];
1245 interpolation_index];
1247 #endif // STANDALONE
1259 if (std::isfinite(iterator->area) && density >= 0) {
1262 iterator->momentum_perp_subtracted =
1263 iterator->momentum.Pt() -
1264 density * iterator->area;
1267 iterator->momentum_perp_subtracted =
1268 iterator->momentum.Pt();
1270 iterator->momentum_perp_subtracted_unequalized =
1271 iterator->momentum_perp_subtracted;
1276 boost::multi_array<double, 2> radial_distance_square(
1279 for (std::vector<particle_t>::const_iterator
1280 iterator_outer =
_event.begin();
1281 iterator_outer !=
_event.end(); iterator_outer++) {
1282 radial_distance_square
1283 [iterator_outer -
_event.begin()]
1284 [iterator_outer -
_event.begin()] = 0;
1286 for (std::vector<particle_t>::const_iterator
1287 iterator_inner =
_event.begin();
1288 iterator_inner != iterator_outer;
1290 const double deta = iterator_outer->momentum.Eta() -
1291 iterator_inner->momentum.Eta();
1292 const double dphi = angular_range_reduce(
1293 iterator_outer->momentum.Phi() -
1294 iterator_inner->momentum.Phi());
1296 radial_distance_square
1297 [iterator_outer -
_event.begin()]
1298 [iterator_inner -
_event.begin()] =
1299 deta * deta + dphi * dphi;
1300 radial_distance_square
1301 [iterator_inner -
_event.begin()]
1302 [iterator_outer -
_event.begin()] =
1303 radial_distance_square
1304 [iterator_outer -
_event.begin()]
1305 [iterator_inner -
_event.begin()];
1311 for (std::vector<particle_t>::const_iterator
1312 iterator_outer =
_event.begin();
1313 iterator_outer !=
_event.end(); iterator_outer++) {
1314 double incident_area_sum = iterator_outer->area;
1316 for (std::set<std::vector<particle_t>::iterator>::
1317 const_iterator iterator_inner =
1318 iterator_outer->incident.begin();
1320 iterator_outer->incident.end();
1322 incident_area_sum += (*iterator_inner)->area;
1324 _active.push_back(incident_area_sum < 2.0);
1329 _event.size(), std::vector<size_t>());
1331 _event.size(), std::vector<size_t>());
1337 static const size_t npair_max = 36;
1339 for (
size_t i = 0;
i <
_event.size();
i++) {
1340 for (
size_t j = 0;
j <
_event.size();
j++) {
1342 const size_t incident_count =
1347 (radial_distance_square[
i][
j] <
1349 incident_count > 0)) {
1354 if (
_event[
i].momentum_perp_subtracted < 0) {
1355 std::vector<double> radial_distance_square_list;
1357 for (std::vector<size_t>::const_iterator iterator =
1361 const size_t j = *iterator;
1363 if (
_event[j].momentum_perp_subtracted > 0) {
1364 radial_distance_square_list.push_back(
1365 radial_distance_square[
i][j]);
1369 double radial_distance_square_max_equalization_cut =
1372 if (radial_distance_square_list.size() >= npair_max) {
1373 std::sort(radial_distance_square_list.begin(),
1374 radial_distance_square_list.end());
1375 radial_distance_square_max_equalization_cut =
1376 radial_distance_square_list[npair_max - 1];
1379 for (std::vector<size_t>::const_iterator iterator =
1383 const size_t j = *iterator;
1385 if (
_event[j].momentum_perp_subtracted > 0 &&
1386 radial_distance_square[
i][j] <
1387 radial_distance_square_max_equalization_cut) {
1393 std::pair<size_t, size_t>(
i, j));
1395 radial_distance_square[
i][j] /
1404 bpmpd_problem_t *
p =
reinterpret_cast<bpmpd_problem_t *
>(lp_problem);
1425 p->set_objective_sense(bpmpd_problem_t::minimize);
1429 static const size_t nsector_azimuth = 12;
1434 static const size_t ncms_hcal_edge_pseudorapidity = 19 + 1;
1435 static const double cms_hcal_edge_pseudorapidity[
1436 ncms_hcal_edge_pseudorapidity] = {
1437 -5.191, -4.538, -4.013,
1438 -3.489, -2.853, -2.322, -1.830, -1.305, -0.783, -0.261,
1439 0.261, 0.783, 1.305, 1.830, 2.322, 2.853, 3.489,
1444 const double *edge_pseudorapidity;
1446 nedge_pseudorapidity = ncms_hcal_edge_pseudorapidity;
1447 edge_pseudorapidity = cms_hcal_edge_pseudorapidity;
1449 const size_t nsuperblock = (nedge_pseudorapidity - 2) *
1452 size_t index_row = 0;
1453 for (
size_t index_pseudorapidity = 0;
1454 index_pseudorapidity < nedge_pseudorapidity - 2;
1455 index_pseudorapidity++) {
1456 for (
size_t index_azimuth = 0;
1457 index_azimuth < nsector_azimuth - 1;
1459 const size_t index_column =
1460 index_pseudorapidity * nsector_azimuth +
1463 bpmpd_problem_t::greater_equal, 0);
1464 p->push_back_coefficient(
1465 index_row, index_column, 1);
1466 p->push_back_coefficient(
1467 index_row, nsuperblock + index_column, -1);
1470 bpmpd_problem_t::greater_equal, 0);
1471 p->push_back_coefficient(
1472 index_row, index_column, 1);
1473 p->push_back_coefficient(
1474 index_row, nsuperblock + index_column + 1, -1);
1477 bpmpd_problem_t::greater_equal, 0);
1478 p->push_back_coefficient(
1479 index_row, index_column, 1);
1480 p->push_back_coefficient(
1482 nsuperblock + index_column + nsector_azimuth, -1);
1485 bpmpd_problem_t::greater_equal, 0);
1486 p->push_back_coefficient(
1487 index_row, index_column, 1);
1488 p->push_back_coefficient(
1490 nsuperblock + index_column + nsector_azimuth + 1,
1494 const size_t index_column =
1495 index_pseudorapidity * nsector_azimuth +
1496 nsector_azimuth - 1;
1498 bpmpd_problem_t::greater_equal, 0);
1499 p->push_back_coefficient(
1500 index_row, index_column, 1);
1501 p->push_back_coefficient(
1502 index_row, nsuperblock + index_column, -1);
1505 bpmpd_problem_t::greater_equal, 0);
1506 p->push_back_coefficient(
1507 index_row, index_column, 1);
1508 p->push_back_coefficient(
1510 nsuperblock + index_column - (nsector_azimuth - 1),
1514 bpmpd_problem_t::greater_equal, 0);
1515 p->push_back_coefficient(
1516 index_row, index_column, 1);
1517 p->push_back_coefficient(
1519 nsuperblock + index_column + nsector_azimuth, -1);
1522 bpmpd_problem_t::greater_equal, 0);
1523 p->push_back_coefficient(
1524 index_row, index_column, 1);
1525 p->push_back_coefficient(
1527 nsuperblock + index_column + nsector_azimuth -
1528 (nsector_azimuth - 1),
1533 const size_t nstaggered_block =
1534 (nedge_pseudorapidity - 1) * nsector_azimuth;
1535 const size_t nblock = nsuperblock + 2 * nstaggered_block;
1541 size_t positive_count = 0;
1543 for (std::vector<particle_t>::const_iterator iterator =
1545 iterator !=
_event.end(); iterator++) {
1546 if (iterator->momentum_perp_subtracted >= 0) {
1547 positive_index[iterator -
_event.begin()] =
1553 _ncost = nblock + positive_count;
1560 std::vector<particle_t>::const_iterator
1561 iterator_particle =
_event.begin();
1562 std::vector<bool>::const_iterator iterator_active =
1564 std::vector<std::vector<size_t> >::const_iterator
1565 iterator_recombine_index_outer =
1567 std::vector<std::vector<size_t> >::const_iterator
1568 iterator_recombine_unsigned_outer =
1570 size_t index_column_max =
_ncost - 1;
1571 for (; iterator_particle !=
_event.end();
1572 iterator_particle++, iterator_active++,
1573 iterator_recombine_index_outer++,
1574 iterator_recombine_unsigned_outer++) {
1575 if (*iterator_active) {
1576 int index_pseudorapidity = -1;
1580 if (iterator_particle->momentum.Eta() >= edge_pseudorapidity[
i - 1] &&
1581 iterator_particle->momentum.Eta() < edge_pseudorapidity[
i]) {
1582 index_pseudorapidity =
i - 1;
1586 const int index_azimuth = floor(
1587 (iterator_particle->momentum.Phi() +
M_PI) *
1588 ((nsector_azimuth >> 1) /
M_PI));
1590 if (index_pseudorapidity != -1) {
1598 iterator_particle->momentum_perp_subtracted >= 0 ?
1600 bpmpd_problem_t::greater_equal,
1601 iterator_particle->momentum_perp_subtracted);
1604 const double sign = iterator_particle->momentum_perp_subtracted >= 0 ? 1 : -1;
1605 const size_t index_column_block_subtract =
1607 (nedge_pseudorapidity - 1) * nsector_azimuth +
1608 index_pseudorapidity * nsector_azimuth +
1612 index_column_block_subtract;
1614 if (iterator_particle->momentum_perp_subtracted >= 0) {
1615 const size_t index_column_cost =
1616 nblock + positive_index[iterator_particle -
_event.begin()];
1618 p->push_back_coefficient(
1619 index_row, index_column_cost, 1);
1621 std::max(index_column_max, index_column_cost);
1623 p->push_back_coefficient(
1624 index_row, index_column_block_subtract, 1);
1626 std::max(index_column_max, index_column_block_subtract);
1628 for (std::vector<size_t>::const_iterator
1629 iterator_recombine_index_inner =
1630 iterator_recombine_index_outer->begin();
1631 iterator_recombine_index_inner !=
1632 iterator_recombine_index_outer->end();
1633 iterator_recombine_index_inner++) {
1634 const size_t index_column =
1635 *iterator_recombine_index_inner +
1638 p->push_back_coefficient(
1639 index_row, index_column, sign);
1641 std::max(index_column_max, index_column);
1645 const size_t index_column_block =
1647 index_pseudorapidity * nsector_azimuth +
1655 double sum_unequalized;
1657 sum_unequalized = 0;
1658 for (std::vector<size_t>::const_iterator
1659 iterator_recombine_unsigned_inner =
1660 iterator_recombine_unsigned_outer->begin();
1661 iterator_recombine_unsigned_inner !=
1662 iterator_recombine_unsigned_outer->end();
1663 iterator_recombine_unsigned_inner++) {
1665 _event[*iterator_recombine_unsigned_inner].momentum_perp_subtracted;
1667 sum_unequalized =
std::max(0.0, sum_unequalized);
1669 if (sum_unequalized >= sum_unequalized_3 ||
1670 (sum_unequalized >= sum_unequalized_2 &&
1671 (iterator_particle -
_event.begin()) % 2 == 0) ||
1672 (sum_unequalized >= sum_unequalized_1 &&
1673 (iterator_particle -
_event.begin()) % 4 == 0) ||
1674 (sum_unequalized >= sum_unequalized_0 &&
1675 (iterator_particle -
_event.begin()) % 8 == 0)) {
1677 const double weight = sum_unequalized *
1679 iterator_particle->area));
1683 bpmpd_problem_t::greater_equal,
1686 p->push_back_coefficient(
1687 index_row, index_column_block, 1.0 / weight);
1689 for (std::vector<size_t>::const_iterator
1690 iterator_recombine_unsigned_inner =
1691 iterator_recombine_unsigned_outer->begin();
1692 iterator_recombine_unsigned_inner !=
1693 iterator_recombine_unsigned_outer->end();
1694 iterator_recombine_unsigned_inner++) {
1695 if (
_event[*iterator_recombine_unsigned_inner].momentum_perp_subtracted >= 0) {
1696 const size_t index_column_cost =
1698 positive_index[*iterator_recombine_unsigned_inner];
1700 p->push_back_coefficient(
1701 index_row, index_column_cost, 1);
1703 std::max(index_column_max, index_column_cost);
1709 bpmpd_problem_t::greater_equal,
1712 p->push_back_coefficient(
1715 for (std::vector<size_t>::const_iterator iterator_recombine_unsigned_inner = iterator_recombine_unsigned_outer->begin();
1716 iterator_recombine_unsigned_inner != iterator_recombine_unsigned_outer->end();
1717 iterator_recombine_unsigned_inner++) {
1718 if (
_event[*iterator_recombine_unsigned_inner].momentum_perp_subtracted >= 0) {
1719 const size_t index_column_cost =
1721 positive_index[*iterator_recombine_unsigned_inner];
1723 p->push_back_coefficient(
1724 index_row, index_column_cost, -1);
1726 std::max(index_column_max, index_column_cost);
1740 static const double epsilon_degeneracy = 1
e-2;
1746 for (
size_t i = 0;
i < nsuperblock;
i++) {
1747 p->push_back_column(
1750 for (
size_t i = nsuperblock;
i < nsuperblock + nstaggered_block;
i++) {
1751 p->push_back_column(
1754 for (
size_t i = nsuperblock + nstaggered_block;
i < nsuperblock + 2 * nstaggered_block;
i++) {
1755 p->push_back_column(
1758 for (
size_t i = nsuperblock + 2 * nstaggered_block;
i <
_ncost;
i++) {
1759 p->push_back_column(
1765 for (
size_t i = _ncost;
i <= index_column_max;
i++) {
1766 p->push_back_column(
1773 bpmpd_problem_t lp_problem =
reinterpret_cast<bpmpd_environment_t *
>(
_lp_environment)->problem();
1777 lp_problem.optimize();
1779 int solution_status;
1780 double objective_value;
1781 std::vector<double>
x;
1782 std::vector<double>
pi;
1784 lp_problem.solve(solution_status, objective_value,
1787 for (
size_t k =
_ncost;
k < x.size();
k++) {
1789 momentum_perp_subtracted < 0 &&
1791 momentum_perp_subtracted >= 0 && x[
k] >= 0) {
1793 momentum_perp_subtracted += x[
k];
1795 momentum_perp_subtracted -= x[
k];
1798 for (
size_t k = 0;
k <
_event.size();
k++) {
1801 _event[
k].momentum_perp_subtracted -=
1808 for (std::vector<particle_t>::iterator iterator =
1810 iterator !=
_event.end(); iterator++) {
1811 iterator->momentum_perp_subtracted =
std::max(
1812 0.0, iterator->momentum_perp_subtracted);
1832 const double dr_max,
1833 const std::pair<double, double> equalization_threshold,
1834 const bool remove_nonpositive)
1835 : _remove_nonpositive(remove_nonpositive),
1836 _equalization_threshold(equalization_threshold),
1837 _radial_distance_square_max(dr_max * dr_max),
1838 _positive_bound_scale(0.2),
1846 -5.191, -2.650, -2.043, -1.740, -1.479, -1.131, -0.783, -0.522, 0.522, 0.783, 1.131, 1.479, 1.740, 2.043, 2.650, 5.191
1850 edge_pseudorapidity,
1870 const double perp,
const double pseudorapidity,
1871 const double azimuth,
1872 const unsigned int reduced_particle_flow_id)
1896 std::vector<double>
ret;
1898 for (std::vector<particle_t>::const_iterator iterator =
1900 iterator !=
_event.end(); iterator++) {
1901 ret.push_back(iterator->momentum_perp_subtracted);
1910 std::vector<double>
ret;
1912 for (std::vector<particle_t>::const_iterator iterator =
1914 iterator !=
_event.end(); iterator++) {
1915 ret.push_back(iterator->momentum_perp_subtracted_unequalized);
1930 std::vector<double>
ret;
1932 for (std::vector<particle_t>::const_iterator iterator =
1934 iterator !=
_event.end(); iterator++) {
1935 ret.push_back(iterator->area);
1952 std::vector<std::set<size_t> >
ret;
1954 for (std::vector<particle_t>::const_iterator
1955 iterator_outer =
_event.begin();
1956 iterator_outer !=
_event.end(); iterator_outer++) {
1959 for (std::set<std::vector<particle_t>::iterator>::
1960 const_iterator iterator_inner =
1961 iterator_outer->incident.begin();
1962 iterator_inner != iterator_outer->incident.begin();
1964 e.insert(*iterator_inner -
_event.begin());
1975 return std::vector<double>(
std::vector< bool > _active
std::vector< std::vector< size_t > > _recombine_index
std::vector< double > perp_fourier(void)
void subtract_momentum(void)
Sin< T >::type sin(const T &t)
CGAL::Voronoi_diagram_2< delaunay_triangulation_t, CGAL::Delaunay_triangulation_adaptation_traits_2< delaunay_triangulation_t >, CGAL::Delaunay_triangulation_caching_degeneracy_removal_policy_2< delaunay_triangulation_t > > voronoi_diagram_t
double _positive_bound_scale
void remove_nonpositive(void)
std::vector< double > _edge_pseudorapidity
void initialize_geometry(void)
std::vector< double > _recombine_tie
bool equal(const T &first, const T &second)
int solver_(double *obj, double *rhs, double *lbound, double *ubound, double *diag, double *odiag, double *xs, double *dxs, double *dxsn, double *up, double *dspr, double *ddspr, double *ddsprn, double *dsup, double *ddsup, double *ddsupn, double *dv, double *ddv, double *ddvn, double *prinf, double *upinf, double *duinf, double *scale, double *nonzeros, int *vartyp, int *slktyp, int *colpnt, int *ecolpnt, int *count, int *vcstat, int *pivots, int *invprm, int *snhead, int *nodtyp, int *inta1, int *prehis, int *rowidx, int *rindex, int *code, double *opt, int *iter, int *corect, int *fixn, int *dropn, int *fnzmax, int *fnzmin, double *addobj, double *bigbou, double *big, int *ft)
U second(std::pair< T, U > const &p)
T x() const
Cartesian x coordinate.
delaunay_triangulation_t::Point point_2d_t
std::vector< double > _cms_ecal_edge_pseudorapidity
std::vector< double > particle_area(void)
void lp_populate(void *lp_problem)
void subtract_if_necessary(void)
void push_back_particle(const double perp, const double pseudorapidity, const double azimuth, const unsigned int reduced_particle_flow_id)
std::vector< std::pair< size_t, size_t > > _recombine
#define BPMPD_VERSION_STRING
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
static const size_t nreduced_particle_flow_id
std::vector< std::set< size_t > > particle_incident(void)
void recombine_link(void)
Cos< T >::type cos(const T &t)
static const size_t nfourier
std::vector< size_t > _nblock_subtract
std::vector< double > _feature
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
double _radial_distance_square_max
boost::multi_array< double, 4 > * _perp_fourier
PtEtaPhiELorentzVectorD PtEtaPhiELorentzVector
Lorentz vector with cartesian internal representation.
std::vector< std::vector< size_t > > _recombine_unsigned
float ue_interpolation_pf0[15][344]
void feature_extract(void)
VoronoiAlgorithm(const UECalibration *ue, const double dr_max, const std::pair< double, double > equalization_threshold=std::pair< double, double >(5.0, 35.0), const bool remove_nonpositive=true)
T perp() const
Magnitude of transverse component.
void voronoi_area_incident(void)
std::pair< double, double > _equalization_threshold
size_t nedge_pseudorapidity(void) const
float ue_predictor_pf[3][15][5][2][82]
std::vector< double > _cms_hcal_edge_pseudorapidity
volatile std::atomic< bool > shutdown_flag false
CGAL::Polygon_2< CGAL::Exact_predicates_inexact_constructions_kernel > polygon_t
std::vector< double > subtracted_unequalized_perp(void)
float ue_interpolation_pf1[15][344]
float ue_interpolation_pf2[15][82]
std::vector< double > subtracted_equalized_perp(void)
Power< A, B >::type pow(const A &a, const B &b)
#define BPMPD_INFINITY_BOUND