129 double *
obj,
double *rhs,
double *lbound,
double *ubound,
131 double *diag,
double *odiag,
135 double *dxs,
double *dxsn,
double *
up,
139 double *ddspr,
double *ddsprn,
double *dsup,
double *ddsup,
144 double *ddv,
double *ddvn,
double *prinf,
146 double *upinf,
double *duinf,
double *
scale,
156 int *ecolpnt,
int *
count,
int *vcstat,
int *pivots,
157 int *invprm,
int *snhead,
int *nodtyp,
int *inta1,
167 int *iter,
int *corect,
int *fixn,
int *dropn,
int *fnzmax,
168 int *fnzmin,
double *addobj,
double *bigbou,
178 #pragma clang diagnostic push
179 #pragma clang diagnostic ignored "-Wunused-const-variable"
183 static const int minimize = 1;
184 static const int maximize = -1;
185 static const char less_equal =
'L';
186 static const char equal =
'E';
187 static const char greater_equal =
'G';
188 static const char range =
'R';
189 #pragma clang diagnostic pop
192 bool _variable_named;
194 std::vector<double> _rhs;
195 std::vector<char> _constraint_sense;
196 std::vector<double> _range_value;
197 std::vector<char *> _row_name;
199 std::vector<double> _objective;
200 std::vector<double> _lower_bound;
201 std::vector<double> _upper_bound;
202 std::vector<char *> _column_name;
204 std::vector<int> _coefficient_row;
205 std::vector<int> _coefficient_column;
206 std::vector<double> _coefficient_value;
211 _constraint_sense.clear();
212 for (std::vector<char *>::const_iterator iterator =
214 iterator != _row_name.end(); iterator++) {
219 void clear_column(
void)
222 _lower_bound.clear();
223 _upper_bound.clear();
224 for (std::vector<char *>::const_iterator iterator =
225 _column_name.begin();
226 iterator != _column_name.end(); iterator++) {
229 _column_name.clear();
231 void clear_coefficient(
void)
233 _coefficient_row.clear();
234 _coefficient_column.clear();
235 _coefficient_value.clear();
237 void to_csr(std::vector<int> &column_pointer,
238 std::vector<int> &row_index,
239 std::vector<double> &nonzero_value,
240 const int index_start = 1)
245 std::vector<std::vector<std::pair<int, double> > >
246 column_index(_objective.size(),
247 std::vector<std::pair<int, double> >());
249 std::vector<int>::const_iterator iterator_row =
250 _coefficient_row.begin();
251 std::vector<int>::const_iterator iterator_column =
252 _coefficient_column.begin();
253 std::vector<double>::const_iterator iterator_value =
254 _coefficient_value.begin();
256 for (; iterator_value != _coefficient_value.end();
257 iterator_row++, iterator_column++, iterator_value++) {
258 column_index[*iterator_column].push_back(
259 std::pair<int, double>(
261 *iterator_row + index_start, *iterator_value));
264 for (std::vector<std::vector<std::pair<int, double> > >::
265 iterator iterator_outer = column_index.begin();
266 iterator_outer != column_index.end(); iterator_outer++) {
268 column_pointer.push_back(row_index.size() + index_start);
269 std::sort(iterator_outer->begin(), iterator_outer->end());
270 for (std::vector<std::pair<int, double> >::const_iterator
271 iterator_inner = iterator_outer->begin();
272 iterator_inner != iterator_outer->end();
274 row_index.push_back(iterator_inner->first);
275 nonzero_value.push_back(iterator_inner->second);
279 column_pointer.push_back(row_index.size() + index_start);
282 problem_t(
const bool variable_named)
283 : _optimized(
false), _variable_named(variable_named)
296 virtual int populate(
void) = 0;
297 size_t nrow(
void)
const
301 size_t ncolumn(
void)
const
303 return _objective.size();
305 void push_back_row(
const char constraint_sense,
309 _constraint_sense.push_back(constraint_sense);
311 if (_variable_named) {
315 snprintf(name, name_length,
"c%llu",
316 static_cast<unsigned long long>(_rhs.size()));
317 _row_name.push_back(name);
320 void push_back_row(
const std::string &constraint_sense,
325 if (constraint_sense ==
"<=") {
327 push_back_row(rhs, cplex_sense);
329 else if (constraint_sense ==
"==") {
331 push_back_row(rhs, cplex_sense);
333 else if (constraint_sense ==
">=") {
335 push_back_row(rhs, cplex_sense);
339 <<
"illegal sense (`" << constraint_sense <<
"')"
343 void push_back_column(
const double objective,
344 const double lower_bound,
345 const double upper_bound)
347 _objective.push_back(objective);
348 _lower_bound.push_back(lower_bound);
349 _upper_bound.push_back(upper_bound);
351 if (_variable_named) {
352 static const size_t name_length = 24;
355 snprintf(name, name_length,
"x%llu",
356 static_cast<unsigned long long>(
358 _column_name.push_back(name);
361 void push_back_coefficient(
362 const int row,
const int column,
const double value)
364 _coefficient_row.push_back(row);
365 _coefficient_column.push_back(column);
366 _coefficient_value.push_back(value);
368 virtual int optimize(
void) = 0;
369 int optimize_primal_simplex(
void)
373 int optimize_dual_simplex(
void)
377 int optimize_barrier(
void)
381 int optimize_network(
void)
385 int optimize_sifting(
void)
389 int optimize_concurrent(
void)
393 int optimize_deterministic_concurrent(
void)
399 int &solution_status,
double &objective_value,
400 std::vector<double> &variable_primal,
401 std::vector<double> &variable_dual,
402 std::vector<double> &variable_slack_surplus,
403 std::vector<double> &reduced_cost) = 0;
405 double &objective_value,
406 std::vector<double> &variable_primal,
407 std::vector<double> &variable_dual,
408 std::vector<double> &variable_slack_surplus,
409 std::vector<double> &reduced_cost)
413 return solve(solution_status, objective_value,
414 variable_primal, variable_dual,
415 variable_slack_surplus, reduced_cost);
418 std::vector<double> &variable_primal,
419 std::vector<double> &variable_dual,
420 std::vector<double> &variable_slack_surplus,
421 std::vector<double> &reduced_cost)
424 double objective_value;
426 return solve(solution_status, objective_value,
427 variable_primal, variable_dual,
428 variable_slack_surplus, reduced_cost);
431 int &solution_status,
double &objective_value,
432 std::vector<double> &variable_primal,
433 std::vector<double> &variable_dual)
435 std::vector<double> variable_slack_surplus;
436 std::vector<double> reduced_cost;
438 return solve(solution_status, objective_value,
439 variable_primal, variable_dual,
440 variable_slack_surplus, reduced_cost);
443 std::vector<double> &variable_primal,
444 std::vector<double> &variable_dual)
447 double objective_value;
449 return solve(solution_status, objective_value, variable_primal,
453 std::vector<double> &variable_primal)
455 std::vector<double> variable_dual;
457 return solve(variable_primal, variable_dual);
461 class environment_t {
463 std::vector<problem_t *> _problem;
466 #ifndef BPMPD_INFINITY_BOUND
467 #define BPMPD_INFINITY_BOUND 1e+30
468 #endif // BPMPD_INFINITY_BOUND
470 #ifndef BPMPD_VERSION_STRING
471 #define BPMPD_VERSION_STRING "Version 2.11 (1996 December)"
472 #endif // BPMPD_VERSION_STRING
474 class bpmpd_environment_t;
476 class bpmpd_problem_t :
public problem_t {
478 #pragma clang diagnostic push
479 #pragma clang diagnostic ignored "-Wunused-const-variable"
481 #pragma clang diagnostic pop
483 double _objective_sense;
484 double _objective_value;
485 std::vector<double> _variable_primal;
486 std::vector<double> _variable_dual;
487 int _solution_status;
489 int ampl_solution_status(
const int termination_code)
491 switch (termination_code) {
506 <<
"unknown termination code "
507 << termination_code << std::endl;
511 void set_bpmpd_parameter(
void)
596 void append_constraint_sense_bound(
597 std::vector<double> &lower_bound_bpmpd,
598 std::vector<double> &upper_bound_bpmpd)
600 for (std::vector<char>::const_iterator iterator =
601 _constraint_sense.begin();
602 iterator != _constraint_sense.end(); iterator++) {
606 upper_bound_bpmpd.push_back(0);
609 lower_bound_bpmpd.push_back(0);
610 upper_bound_bpmpd.push_back(0);
613 lower_bound_bpmpd.push_back(0);
619 iterator - _constraint_sense.begin();
621 lower_bound_bpmpd.push_back(0);
622 upper_bound_bpmpd.push_back(_range_value[index] -
628 lower_bound_bpmpd.reserve(
dims_.
mn);
629 lower_bound_bpmpd.insert(lower_bound_bpmpd.end(),
630 _lower_bound.begin(),
632 upper_bound_bpmpd.reserve(
dims_.
mn);
633 upper_bound_bpmpd.insert(upper_bound_bpmpd.end(),
634 _upper_bound.begin(),
643 bpmpd_problem_t(
void)
644 : problem_t(
false), _objective_sense(1.0),
645 _objective_value(NAN)
648 inline size_t nrow(
void)
const
652 inline size_t ncolumn(
void)
const
656 inline void set_objective_sense(
int sense)
658 _objective_sense = sense;
667 void push_back_column(
const double objective,
668 const double lower_bound = 0,
671 problem_t::push_back_column(objective, lower_bound,
674 void set_size(
const size_t nonzero_value_size,
675 const double mf = 6.0,
const size_t ma = 0)
677 dims_.
n = _objective.size();
691 std::max(static_cast<size_t>(0), ma);
698 std::vector<int> column_pointer;
700 std::vector<int> row_index;
702 std::vector<double> nonzero_value;
704 to_csr(column_pointer, row_index, nonzero_value);
707 std::bind1st(std::multiplies<double>(),
711 for (
size_t i = 0;
i < 3;
i++) {
712 set_size(nonzero_value.size(), 6.0 * (1 <<
i));
717 set_bpmpd_parameter();
719 std::vector<double> diag(
dims_.
mn, 0);
720 std::vector<double> odiag(
dims_.
mn, 0);
721 std::vector<double> dxs(
dims_.
mn, 0);
722 std::vector<double> dxsn(
dims_.
mn, 0);
724 std::vector<double> dual_residual(
dims_.
mn, 0);
725 std::vector<double> ddspr(
dims_.
mn, 0);
726 std::vector<double> ddsprn(
dims_.
mn, 0);
727 std::vector<double> dsup(
dims_.
mn, 0);
728 std::vector<double> ddsup(
dims_.
mn, 0);
729 std::vector<double> ddsupn(
dims_.
mn, 0);
730 std::vector<double> ddv(
dims_.
m, 0);
731 std::vector<double> ddvn(
dims_.
m, 0);
732 std::vector<double> prinf(
dims_.
m, 0);
733 std::vector<double> upinf(
dims_.
mn, 0);
734 std::vector<double> duinf(
dims_.
mn, 0);
736 std::vector<int> vartyp(
dims_.
n, 0);
737 std::vector<int> slktyp(
dims_.
m, 0);
738 std::vector<int> colpnt(
dims_.
n1, 0);
739 std::vector<int> ecolpnt(
dims_.
mn, 0);
741 std::vector<int> vcstat(
dims_.
mn, 0);
742 std::vector<int> pivots(
dims_.
mn, 0);
743 std::vector<int> invprm(
dims_.
mn, 0);
744 std::vector<int> snhead(
dims_.
mn, 0);
745 std::vector<int> nodtyp(
dims_.
mn, 0);
746 std::vector<int> inta1(
dims_.
mn, 0);
747 std::vector<int> prehis(
dims_.
mn, 0);
749 int termination_code;
758 double bigbou = 1
e+15;
762 _variable_primal.resize(
dims_.
mn);
763 _variable_dual.resize(
dims_.
m);
765 std::vector<double> lower_bound_bpmpd = _lower_bound;
766 std::vector<double> upper_bound_bpmpd = _upper_bound;
768 append_constraint_sense_bound(lower_bound_bpmpd,
771 solver_(&_objective[0], &_rhs[0], &lower_bound_bpmpd[0],
772 &upper_bound_bpmpd[0], &diag[0], &odiag[0],
773 &_variable_primal[0], &dxs[0], &dxsn[0], &
up[0],
774 &dual_residual[0], &ddspr[0], &ddsprn[0],
775 &dsup[0], &ddsup[0], &ddsupn[0],
776 &_variable_dual[0], &ddv[0], &ddvn[0], &prinf[0],
777 &upinf[0], &duinf[0], &
scale[0],
778 &nonzero_value[0], &vartyp[0], &slktyp[0],
779 &column_pointer[0], &ecolpnt[0], &
count[0],
780 &vcstat[0], &pivots[0], &invprm[0], &snhead[0],
781 &nodtyp[0], &inta1[0], &prehis[0], &row_index[0],
782 &rindex[0], &termination_code, &_objective_value,
783 &iter, &correct, &fixn, &dropn, &fnzmax, &fnzmin,
784 &addobj, &bigbou, &infinity_copy, &ft);
786 _objective_value *= _objective_sense;
787 _solution_status = ampl_solution_status(termination_code);
788 if (termination_code != -2) {
794 return _solution_status == 0 ? 0 : 1;
797 int &solution_status,
double &objective_value,
798 std::vector<double> &variable_primal,
799 std::vector<double> &variable_dual,
800 std::vector<double> &variable_slack_surplus,
801 std::vector<double> &reduced_cost)
809 int &solution_status,
double &objective_value,
810 std::vector<double> &variable_primal,
811 std::vector<double> &variable_dual)
813 variable_primal = std::vector<double>(
814 _variable_primal.begin(),
815 _variable_primal.begin() + _objective.size());
816 variable_dual = _variable_dual;
820 friend class bpmpd_environment_t;
823 class bpmpd_environment_t :
public environment_t {
825 bpmpd_environment_t(
void)
828 ~bpmpd_environment_t(
void)
831 int set_verbose(
void);
832 int set_data_checking(
void);
839 return bpmpd_problem_t();
847 double angular_range_reduce(
const double x)
849 if (!std::isfinite(x)) {
853 static const double cody_waite_x_max = 1608.4954386379741381;
854 static const double two_pi_0 = 6.2831853071795649157;
855 static const double two_pi_1 = 2.1561211432631314669e-14;
856 static const double two_pi_2 = 1.1615423895917441336e-27;
859 if (x >= -cody_waite_x_max && x <= cody_waite_x_max) {
860 static const double inverse_two_pi =
861 0.15915494309189534197;
862 const double k = rint(x * inverse_two_pi);
863 ret = ((x - (k * two_pi_0)) - k * two_pi_1) -
876 double hermite_h_normalized(
const size_t n,
const double x)
881 case 3: y = -3.913998411780905*x + 2.6093322745206033*
std::pow(x,3);
break;
882 case 5: y = 4.931174490213579*x - 6.574899320284771*
std::pow(x,3) + 1.3149798640569543*
std::pow(x,5);
break;
883 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;
884 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;
885 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;
886 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;
887 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;
888 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;
899 static const size_t ncms_hcal_edge_pseudorapidity = 82 + 1;
900 static const double cms_hcal_edge_pseudorapidity[
901 ncms_hcal_edge_pseudorapidity] = {
902 -5.191, -4.889, -4.716, -4.538, -4.363, -4.191, -4.013,
903 -3.839, -3.664, -3.489, -3.314, -3.139, -2.964, -2.853,
904 -2.650, -2.500, -2.322, -2.172, -2.043, -1.930, -1.830,
905 -1.740, -1.653, -1.566, -1.479, -1.392, -1.305, -1.218,
906 -1.131, -1.044, -0.957, -0.879, -0.783, -0.696, -0.609,
907 -0.522, -0.435, -0.348, -0.261, -0.174, -0.087,
909 0.087, 0.174, 0.261, 0.348, 0.435, 0.522, 0.609,
910 0.696, 0.783, 0.879, 0.957, 1.044, 1.131, 1.218,
911 1.305, 1.392, 1.479, 1.566, 1.653, 1.740, 1.830,
912 1.930, 2.043, 2.172, 2.322, 2.500, 2.650, 2.853,
913 2.964, 3.139, 3.314, 3.489, 3.664, 3.839, 4.013,
914 4.191, 4.363, 4.538, 4.716, 4.889, 5.191
918 cms_hcal_edge_pseudorapidity,
919 cms_hcal_edge_pseudorapidity +
920 ncms_hcal_edge_pseudorapidity);
922 static const size_t ncms_ecal_edge_pseudorapidity = 344 + 1;
924 for (
size_t i = 0;
i < ncms_ecal_edge_pseudorapidity;
i++) {
927 (ncms_ecal_edge_pseudorapidity - 1)) -
948 for (std::vector<particle_t>::const_iterator iterator =
950 iterator !=
_event.end(); iterator++) {
951 const unsigned int reduced_id =
952 iterator->reduced_particle_flow_id;
956 if (iterator->momentum.Eta() >=
958 iterator->momentum.Eta() <
960 const double azimuth =
961 iterator->momentum.Phi();
964 (*_perp_fourier)[
k - 1][reduced_id]
966 iterator->momentum.Pt() *
968 (*_perp_fourier)[
k - 1][reduced_id]
970 iterator->momentum.Pt() *
979 const size_t nfeature = 2 *
nfourier - 1;
992 scale[0] = 1.0 / 5400.0;
995 scale[1] = 1.0 / 130.0;
998 scale[2] = 1.0 / 220.0;
1001 const size_t index_edge_end =
1007 ((*_perp_fourier)[0 ][
j][0][0] +
1008 (*_perp_fourier)[index_edge_end][
j][0][0]);
1015 ((*_perp_fourier)[0 ][
j][
k][0] +
1016 (*_perp_fourier)[index_edge_end][
j][
k][0]);
1021 ((*_perp_fourier)[0 ][
j][
k][1] +
1022 (*_perp_fourier)[index_edge_end][
j][
k][1]);
1041 #ifdef HAVE_SPARSEHASH
1043 const voronoi_diagram_t::Face face_empty;
1044 google::dense_hash_map<voronoi_diagram_t::Face_handle,
1045 size_t, hash<voronoi_diagram_t::Face_handle> >
1048 face_index.set_empty_key(face_empty);
1049 #else // HAVE_SPARSEHASH
1050 std::map<voronoi_diagram_t::Face_handle, size_t>
1052 #endif // HAVE_SPARSEHASH
1054 for (std::vector<particle_t>::const_iterator iterator =
1056 iterator !=
_event.end(); iterator++) {
1061 for (
int j = -1;
j <= 1;
j++) {
1062 const double parity =
j == 0 ? 1 : -1;
1063 const double origin =
j == 0 ? 0 :
1067 for (
int k = -1;
k <= 1;
k++) {
1069 origin + parity * iterator->momentum.Eta(),
1070 k * (2 *
M_PI) + iterator->momentum.Phi());
1071 const voronoi_diagram_t::Face_handle
handle =
1082 for (std::vector<particle_t>::iterator iterator =
1084 iterator !=
_event.end(); iterator++) {
1085 const voronoi_diagram_t::Locate_result
result =
1086 diagram.locate(*iterator);
1087 const voronoi_diagram_t::Face_handle *face =
1088 boost::get<voronoi_diagram_t::Face_handle>(
1090 double polygon_area;
1093 voronoi_diagram_t::Ccb_halfedge_circulator
1094 circulator_start = (*face)->outer_ccb();
1095 bool unbounded =
false;
1098 voronoi_diagram_t::Ccb_halfedge_circulator
1099 circulator = circulator_start;
1104 if (circulator->has_target()) {
1106 circulator->target()->point());
1107 _event[face_index[*face]].incident.
1110 face_index[circulator->twin()->
1118 while (++circulator != circulator_start);
1120 polygon_area = INFINITY;
1123 polygon_area = polygon.area();
1129 iterator->area = fabs(polygon_area);
1134 for (std::vector<particle_t>::iterator iterator =
1136 iterator !=
_event.end(); iterator++) {
1137 int predictor_index = -1;
1138 int interpolation_index = -1;
1143 if (iterator->momentum.Eta() >=
1145 iterator->momentum.Eta() <
1147 predictor_index =
l - 1;
1156 if (iterator->momentum.Eta() >=
1158 iterator->momentum.Eta() <
1160 interpolation_index =
l - 1;
1168 if (iterator->momentum.Eta() >=
1170 iterator->momentum.Eta() <
1172 interpolation_index =
l - 1;
1177 if (predictor_index >= 0 && interpolation_index >= 0) {
1181 const double azimuth = iterator->momentum.Phi();
1182 const float (*
p)[2][82] =
1184 ue_predictor_pf[
j][predictor_index]
1187 #endif // STANDALONE
1192 const size_t norder =
l == 0 ? 9 : 1;
1194 for (
size_t m = 0;
m < 2;
m++) {
1195 float u =
p[
l][
m][0];
1197 for (
size_t n = 0;
n < 2 * nfourier - 1;
n++) {
1198 if ((
l == 0 &&
n == 0) || (
l == 2 && (
n == 3 ||
n == 4))) {
1200 for (
size_t o = 2;
o < norder + 1;
o++) {
1201 u +=
p[
l][
m][9 *
n +
o] *
1202 hermite_h_normalized(
1203 2 *
o - 1, _feature[
n]) *
1204 exp(-_feature[n] * _feature[n]);
1209 pred += u * (
l == 0 ? 1.0 : 2.0) *
1210 (
m == 0 ?
cos(l * azimuth) :
1212 if (l == 0 &&
m == 0) {
1226 ue_interpolation_pf0[predictor_index][
1227 interpolation_index];
1231 ue_interpolation_pf1[predictor_index][
1232 interpolation_index];
1236 ue_interpolation_pf2[predictor_index][
1237 interpolation_index];
1243 interpolation_index];
1248 interpolation_index];
1253 interpolation_index];
1255 #endif // STANDALONE
1267 if (std::isfinite(iterator->area) && density >= 0) {
1270 iterator->momentum_perp_subtracted =
1271 iterator->momentum.Pt() -
1272 density * iterator->area;
1275 iterator->momentum_perp_subtracted =
1276 iterator->momentum.Pt();
1278 iterator->momentum_perp_subtracted_unequalized =
1279 iterator->momentum_perp_subtracted;
1284 boost::multi_array<double, 2> radial_distance_square(
1287 for (std::vector<particle_t>::const_iterator
1288 iterator_outer =
_event.begin();
1289 iterator_outer !=
_event.end(); iterator_outer++) {
1290 radial_distance_square
1291 [iterator_outer -
_event.begin()]
1292 [iterator_outer -
_event.begin()] = 0;
1294 for (std::vector<particle_t>::const_iterator
1295 iterator_inner =
_event.begin();
1296 iterator_inner != iterator_outer;
1298 const double deta = iterator_outer->momentum.Eta() -
1299 iterator_inner->momentum.Eta();
1300 const double dphi = angular_range_reduce(
1301 iterator_outer->momentum.Phi() -
1302 iterator_inner->momentum.Phi());
1304 radial_distance_square
1305 [iterator_outer -
_event.begin()]
1306 [iterator_inner -
_event.begin()] =
1307 deta * deta + dphi * dphi;
1308 radial_distance_square
1309 [iterator_inner -
_event.begin()]
1310 [iterator_outer -
_event.begin()] =
1311 radial_distance_square
1312 [iterator_outer -
_event.begin()]
1313 [iterator_inner -
_event.begin()];
1319 for (std::vector<particle_t>::const_iterator
1320 iterator_outer =
_event.begin();
1321 iterator_outer !=
_event.end(); iterator_outer++) {
1322 double incident_area_sum = iterator_outer->area;
1324 for (std::set<std::vector<particle_t>::iterator>::
1325 const_iterator iterator_inner =
1326 iterator_outer->incident.begin();
1328 iterator_outer->incident.end();
1330 incident_area_sum += (*iterator_inner)->area;
1332 _active.push_back(incident_area_sum < 2.0);
1337 _event.size(), std::vector<size_t>());
1339 _event.size(), std::vector<size_t>());
1345 static const size_t npair_max = 36;
1347 for (
size_t i = 0;
i <
_event.size();
i++) {
1348 for (
size_t j = 0;
j <
_event.size();
j++) {
1350 const size_t incident_count =
1355 (radial_distance_square[
i][
j] <
1357 incident_count > 0)) {
1362 if (
_event[
i].momentum_perp_subtracted < 0) {
1363 std::vector<double> radial_distance_square_list;
1365 for (std::vector<size_t>::const_iterator iterator =
1369 const size_t j = *iterator;
1371 if (
_event[j].momentum_perp_subtracted > 0) {
1372 radial_distance_square_list.push_back(
1373 radial_distance_square[
i][j]);
1377 double radial_distance_square_max_equalization_cut =
1380 if (radial_distance_square_list.size() >= npair_max) {
1381 std::sort(radial_distance_square_list.begin(),
1382 radial_distance_square_list.end());
1383 radial_distance_square_max_equalization_cut =
1384 radial_distance_square_list[npair_max - 1];
1387 for (std::vector<size_t>::const_iterator iterator =
1391 const size_t j = *iterator;
1393 if (
_event[j].momentum_perp_subtracted > 0 &&
1394 radial_distance_square[
i][j] <
1395 radial_distance_square_max_equalization_cut) {
1401 std::pair<size_t, size_t>(
i, j));
1403 radial_distance_square[
i][j] /
1412 bpmpd_problem_t *
p =
reinterpret_cast<bpmpd_problem_t *
>(lp_problem);
1433 p->set_objective_sense(bpmpd_problem_t::minimize);
1437 static const size_t nsector_azimuth = 12;
1442 static const size_t ncms_hcal_edge_pseudorapidity = 19 + 1;
1443 static const double cms_hcal_edge_pseudorapidity[
1444 ncms_hcal_edge_pseudorapidity] = {
1445 -5.191, -4.538, -4.013,
1446 -3.489, -2.853, -2.322, -1.830, -1.305, -0.783, -0.261,
1447 0.261, 0.783, 1.305, 1.830, 2.322, 2.853, 3.489,
1452 const double *edge_pseudorapidity;
1454 nedge_pseudorapidity = ncms_hcal_edge_pseudorapidity;
1455 edge_pseudorapidity = cms_hcal_edge_pseudorapidity;
1457 const size_t nsuperblock = (nedge_pseudorapidity - 2) *
1460 size_t index_row = 0;
1461 for (
size_t index_pseudorapidity = 0;
1462 index_pseudorapidity < nedge_pseudorapidity - 2;
1463 index_pseudorapidity++) {
1464 for (
size_t index_azimuth = 0;
1465 index_azimuth < nsector_azimuth - 1;
1467 const size_t index_column =
1468 index_pseudorapidity * nsector_azimuth +
1471 bpmpd_problem_t::greater_equal, 0);
1472 p->push_back_coefficient(
1473 index_row, index_column, 1);
1474 p->push_back_coefficient(
1475 index_row, nsuperblock + index_column, -1);
1478 bpmpd_problem_t::greater_equal, 0);
1479 p->push_back_coefficient(
1480 index_row, index_column, 1);
1481 p->push_back_coefficient(
1482 index_row, nsuperblock + index_column + 1, -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);
1493 bpmpd_problem_t::greater_equal, 0);
1494 p->push_back_coefficient(
1495 index_row, index_column, 1);
1496 p->push_back_coefficient(
1498 nsuperblock + index_column + nsector_azimuth + 1,
1502 const size_t index_column =
1503 index_pseudorapidity * nsector_azimuth +
1504 nsector_azimuth - 1;
1506 bpmpd_problem_t::greater_equal, 0);
1507 p->push_back_coefficient(
1508 index_row, index_column, 1);
1509 p->push_back_coefficient(
1510 index_row, nsuperblock + index_column, -1);
1513 bpmpd_problem_t::greater_equal, 0);
1514 p->push_back_coefficient(
1515 index_row, index_column, 1);
1516 p->push_back_coefficient(
1518 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, -1);
1530 bpmpd_problem_t::greater_equal, 0);
1531 p->push_back_coefficient(
1532 index_row, index_column, 1);
1533 p->push_back_coefficient(
1535 nsuperblock + index_column + nsector_azimuth -
1536 (nsector_azimuth - 1),
1541 const size_t nstaggered_block =
1542 (nedge_pseudorapidity - 1) * nsector_azimuth;
1543 const size_t nblock = nsuperblock + 2 * nstaggered_block;
1549 size_t positive_count = 0;
1551 for (std::vector<particle_t>::const_iterator iterator =
1553 iterator !=
_event.end(); iterator++) {
1554 if (iterator->momentum_perp_subtracted >= 0) {
1555 positive_index[iterator -
_event.begin()] =
1561 _ncost = nblock + positive_count;
1568 std::vector<particle_t>::const_iterator
1569 iterator_particle =
_event.begin();
1570 std::vector<bool>::const_iterator iterator_active =
1572 std::vector<std::vector<size_t> >::const_iterator
1573 iterator_recombine_index_outer =
1575 std::vector<std::vector<size_t> >::const_iterator
1576 iterator_recombine_unsigned_outer =
1578 size_t index_column_max =
_ncost - 1;
1579 for (; iterator_particle !=
_event.end();
1580 iterator_particle++, iterator_active++,
1581 iterator_recombine_index_outer++,
1582 iterator_recombine_unsigned_outer++) {
1583 if (*iterator_active) {
1584 int index_pseudorapidity = -1;
1588 if (iterator_particle->momentum.Eta() >= edge_pseudorapidity[
i - 1] &&
1589 iterator_particle->momentum.Eta() < edge_pseudorapidity[
i]) {
1590 index_pseudorapidity =
i - 1;
1594 const int index_azimuth = floor(
1595 (iterator_particle->momentum.Phi() +
M_PI) *
1596 ((nsector_azimuth >> 1) /
M_PI));
1598 if (index_pseudorapidity != -1) {
1606 iterator_particle->momentum_perp_subtracted >= 0 ?
1608 bpmpd_problem_t::greater_equal,
1609 iterator_particle->momentum_perp_subtracted);
1612 const double sign = iterator_particle->momentum_perp_subtracted >= 0 ? 1 : -1;
1613 const size_t index_column_block_subtract =
1615 (nedge_pseudorapidity - 1) * nsector_azimuth +
1616 index_pseudorapidity * nsector_azimuth +
1620 index_column_block_subtract;
1622 if (iterator_particle->momentum_perp_subtracted >= 0) {
1623 const size_t index_column_cost =
1624 nblock + positive_index[iterator_particle -
_event.begin()];
1626 p->push_back_coefficient(
1627 index_row, index_column_cost, 1);
1629 std::max(index_column_max, index_column_cost);
1631 p->push_back_coefficient(
1632 index_row, index_column_block_subtract, 1);
1634 std::max(index_column_max, index_column_block_subtract);
1636 for (std::vector<size_t>::const_iterator
1637 iterator_recombine_index_inner =
1638 iterator_recombine_index_outer->begin();
1639 iterator_recombine_index_inner !=
1640 iterator_recombine_index_outer->end();
1641 iterator_recombine_index_inner++) {
1642 const size_t index_column =
1643 *iterator_recombine_index_inner +
1646 p->push_back_coefficient(
1647 index_row, index_column, sign);
1649 std::max(index_column_max, index_column);
1653 const size_t index_column_block =
1655 index_pseudorapidity * nsector_azimuth +
1663 double sum_unequalized;
1665 sum_unequalized = 0;
1666 for (std::vector<size_t>::const_iterator
1667 iterator_recombine_unsigned_inner =
1668 iterator_recombine_unsigned_outer->begin();
1669 iterator_recombine_unsigned_inner !=
1670 iterator_recombine_unsigned_outer->end();
1671 iterator_recombine_unsigned_inner++) {
1673 _event[*iterator_recombine_unsigned_inner].momentum_perp_subtracted;
1675 sum_unequalized =
std::max(0.0, sum_unequalized);
1677 if (sum_unequalized >= sum_unequalized_3 ||
1678 (sum_unequalized >= sum_unequalized_2 &&
1679 (iterator_particle -
_event.begin()) % 2 == 0) ||
1680 (sum_unequalized >= sum_unequalized_1 &&
1681 (iterator_particle -
_event.begin()) % 4 == 0) ||
1682 (sum_unequalized >= sum_unequalized_0 &&
1683 (iterator_particle -
_event.begin()) % 8 == 0)) {
1685 const double weight = sum_unequalized *
1687 iterator_particle->area));
1691 bpmpd_problem_t::greater_equal,
1694 p->push_back_coefficient(
1695 index_row, index_column_block, 1.0 / weight);
1697 for (std::vector<size_t>::const_iterator
1698 iterator_recombine_unsigned_inner =
1699 iterator_recombine_unsigned_outer->begin();
1700 iterator_recombine_unsigned_inner !=
1701 iterator_recombine_unsigned_outer->end();
1702 iterator_recombine_unsigned_inner++) {
1703 if (
_event[*iterator_recombine_unsigned_inner].momentum_perp_subtracted >= 0) {
1704 const size_t index_column_cost =
1706 positive_index[*iterator_recombine_unsigned_inner];
1708 p->push_back_coefficient(
1709 index_row, index_column_cost, 1);
1711 std::max(index_column_max, index_column_cost);
1717 bpmpd_problem_t::greater_equal,
1720 p->push_back_coefficient(
1723 for (std::vector<size_t>::const_iterator iterator_recombine_unsigned_inner = iterator_recombine_unsigned_outer->begin();
1724 iterator_recombine_unsigned_inner != iterator_recombine_unsigned_outer->end();
1725 iterator_recombine_unsigned_inner++) {
1726 if (
_event[*iterator_recombine_unsigned_inner].momentum_perp_subtracted >= 0) {
1727 const size_t index_column_cost =
1729 positive_index[*iterator_recombine_unsigned_inner];
1731 p->push_back_coefficient(
1732 index_row, index_column_cost, -1);
1734 std::max(index_column_max, index_column_cost);
1748 static const double epsilon_degeneracy = 1
e-2;
1754 for (
size_t i = 0;
i < nsuperblock;
i++) {
1755 p->push_back_column(
1758 for (
size_t i = nsuperblock;
i < nsuperblock + nstaggered_block;
i++) {
1759 p->push_back_column(
1762 for (
size_t i = nsuperblock + nstaggered_block;
i < nsuperblock + 2 * nstaggered_block;
i++) {
1763 p->push_back_column(
1766 for (
size_t i = nsuperblock + 2 * nstaggered_block;
i <
_ncost;
i++) {
1767 p->push_back_column(
1772 for (
size_t i = _ncost;
i <= index_column_max;
i++) {
1773 p->push_back_column(
1780 bpmpd_problem_t lp_problem =
reinterpret_cast<bpmpd_environment_t *
>(
_lp_environment)->problem();
1784 lp_problem.optimize();
1786 int solution_status;
1787 double objective_value;
1788 std::vector<double>
x;
1789 std::vector<double>
pi;
1791 lp_problem.solve(solution_status, objective_value,
1794 for (
size_t k =
_ncost;
k < x.size();
k++) {
1796 momentum_perp_subtracted < 0 &&
1798 momentum_perp_subtracted >= 0 && x[
k] >= 0) {
1800 momentum_perp_subtracted += x[
k];
1802 momentum_perp_subtracted -= x[
k];
1805 for (
size_t k = 0;
k <
_event.size();
k++) {
1808 _event[
k].momentum_perp_subtracted -=
1815 for (std::vector<particle_t>::iterator iterator =
1817 iterator !=
_event.end(); iterator++) {
1818 iterator->momentum_perp_subtracted =
std::max(
1819 0.0, iterator->momentum_perp_subtracted);
1839 const double dr_max,
1840 const std::pair<double, double> equalization_threshold,
1841 const bool remove_nonpositive)
1842 : _remove_nonpositive(remove_nonpositive),
1843 _equalization_threshold(equalization_threshold),
1844 _radial_distance_square_max(dr_max * dr_max),
1845 _positive_bound_scale(0.2),
1853 -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
1857 edge_pseudorapidity,
1877 const double perp,
const double pseudorapidity,
1878 const double azimuth,
1879 const unsigned int reduced_particle_flow_id)
1903 std::vector<double>
ret;
1905 for (std::vector<particle_t>::const_iterator iterator =
1907 iterator !=
_event.end(); iterator++) {
1908 ret.push_back(iterator->momentum_perp_subtracted);
1917 std::vector<double>
ret;
1919 for (std::vector<particle_t>::const_iterator iterator =
1921 iterator !=
_event.end(); iterator++) {
1922 ret.push_back(iterator->momentum_perp_subtracted_unequalized);
1937 std::vector<double>
ret;
1939 for (std::vector<particle_t>::const_iterator iterator =
1941 iterator !=
_event.end(); iterator++) {
1942 ret.push_back(iterator->area);
1959 std::vector<std::set<size_t> >
ret;
1961 for (std::vector<particle_t>::const_iterator
1962 iterator_outer =
_event.begin();
1963 iterator_outer !=
_event.end(); iterator_outer++) {
1966 for (std::set<std::vector<particle_t>::iterator>::
1967 const_iterator iterator_inner =
1968 iterator_outer->incident.begin();
1969 iterator_inner != iterator_outer->incident.begin();
1971 e.insert(*iterator_inner -
_event.begin());
1982 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