CMS 3D CMS Logo

Namespaces | Functions
HardwareSortingMethods.cc File Reference
#include <iostream>
#include "L1Trigger/L1TCalorimeter/interface/HardwareSortingMethods.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

Go to the source code of this file.

Namespaces

 l1t
 delete x;
 

Functions

std::vector< l1t::L1Candidatearray_from_row_sorted_matrix (std::vector< std::vector< l1t::L1Candidate > > const &input_matrix, unsigned int n_keep)
 
std::vector< std::vector< l1t::L1Candidate > > extract_sub_jet_energy_position_matrix (std::vector< std::vector< l1t::L1Candidate > > const &input_matrix, unsigned int row_i, unsigned int row_f, unsigned int col_i, unsigned int col_f)
 
unsigned int l1t::pack15bits (int pt, int eta, int phi)
 
unsigned int l1t::pack16bits (int pt, int eta, int phi)
 
unsigned int l1t::pack16bitsEgammaSpecial (int pt, int eta, int phi)
 
std::vector< std::vector< l1t::L1Candidate > > presort (std::vector< std::vector< l1t::L1Candidate > > const &energies, int rows, int cols)
 
std::vector< std::vector< l1t::L1Candidate > > presort_egamma (std::vector< l1t::L1Candidate > const &input_egamma, int rows, int cols)
 
void print2DVector (std::vector< std::vector< l1t::L1Candidate > > const &myVector)
 
std::vector< l1t::L1Candidatesort_array (std::vector< l1t::L1Candidate > const &inputArray)
 
std::vector< std::vector< l1t::L1Candidate > > sort_by_row_in_groups (std::vector< std::vector< l1t::L1Candidate > > const &input_matrix, int group_size)
 
std::vector< std::vector< l1t::L1Candidate > > sort_matrix_rows (std::vector< std::vector< l1t::L1Candidate > > const &input_matrix)
 
void l1t::SortEGammas (std::vector< l1t::EGamma > *input, std::vector< l1t::EGamma > *output)
 
void l1t::SortJets (std::vector< l1t::Jet > *input, std::vector< l1t::Jet > *output)
 
void l1t::SortTaus (std::vector< l1t::Tau > *input, std::vector< l1t::Tau > *output)
 
std::vector< std::vector< l1t::L1Candidate > > super_sort_matrix_rows (std::vector< std::vector< l1t::L1Candidate > > const &input_matrix, unsigned int group_size, unsigned int n_keep)
 

Function Documentation

◆ array_from_row_sorted_matrix()

std::vector<l1t::L1Candidate> array_from_row_sorted_matrix ( std::vector< std::vector< l1t::L1Candidate > > const &  input_matrix,
unsigned int  n_keep 
)

Definition at line 176 of file HardwareSortingMethods.cc.

177  {
178  std::vector<l1t::L1Candidate> output_array(n_keep * (n_keep + 1) / 2);
179  unsigned int max_row = n_keep - 1;
180  unsigned int max_col = n_keep - 1;
181 
182  //compute size
183  if (input_matrix.size() < n_keep)
184  max_row = input_matrix.size() - 1;
185  if (input_matrix[0].size() < n_keep)
186  max_col = input_matrix[0].size() - 1;
187 
188  unsigned int array_position = 0;
189  for (unsigned int i = 0; i <= max_row; i++) {
190  for (unsigned int j = 0; j <= max_col - i; j++) {
191  //cout << input_matrix[i][j].hwPt() << endl;
192  output_array[array_position] = input_matrix[i][j];
193  array_position++;
194  } //j
195  } //i
196 
197  //fill rest with zeros
198  l1t::L1Candidate dummyJet;
199  dummyJet.setHwPt(0);
200  dummyJet.setHwPhi(99);
201  dummyJet.setHwEta(99);
202  dummyJet.setHwQual(0x10);
203  for (unsigned int k = array_position; k < output_array.size(); k++) {
204  output_array[k] = dummyJet;
205  }
206 
207  //printVector(output_array);
208  return output_array;
209 }

References mps_fire::i, dqmiolumiharvest::j, dqmdumpme::k, l1t::L1Candidate::setHwEta(), l1t::L1Candidate::setHwPhi(), l1t::L1Candidate::setHwPt(), l1t::L1Candidate::setHwQual(), and findQualityFiles::size.

Referenced by super_sort_matrix_rows().

◆ extract_sub_jet_energy_position_matrix()

std::vector<std::vector<l1t::L1Candidate> > extract_sub_jet_energy_position_matrix ( std::vector< std::vector< l1t::L1Candidate > > const &  input_matrix,
unsigned int  row_i,
unsigned int  row_f,
unsigned int  col_i,
unsigned int  col_f 
)

Definition at line 107 of file HardwareSortingMethods.cc.

112  {
113  std::vector<std::vector<l1t::L1Candidate> > output_matrix(row_f - row_i + 1,
114  std::vector<l1t::L1Candidate>(col_f - col_i + 1));
115  l1t::L1Candidate dummyJet;
116  dummyJet.setHwPt(0);
117  dummyJet.setHwPhi(99);
118  dummyJet.setHwEta(99);
119  dummyJet.setHwQual(0x10);
120  for (unsigned int i = 0; i < row_f - row_i + 1; i++) {
121  for (unsigned int j = 0; j < col_f - col_i + 1; j++) {
122  if (row_i + i > input_matrix.size() - 1)
123  output_matrix[i][j] = dummyJet;
124  else
125  output_matrix[i][j] = input_matrix[row_i + i][col_i + j];
126  } //j
127  } //i
128  return output_matrix;
129 }

References mps_fire::i, dqmiolumiharvest::j, l1t::L1Candidate::setHwEta(), l1t::L1Candidate::setHwPhi(), l1t::L1Candidate::setHwPt(), and l1t::L1Candidate::setHwQual().

Referenced by sort_by_row_in_groups(), and super_sort_matrix_rows().

◆ presort()

std::vector<std::vector<l1t::L1Candidate> > presort ( std::vector< std::vector< l1t::L1Candidate > > const &  energies,
int  rows,
int  cols 
)

Definition at line 62 of file HardwareSortingMethods.cc.

64  {
65  int row_block_length = energies.size() / cols;
66  if (energies.size() % cols != 0)
67  row_block_length++;
68 
69  l1t::L1Candidate dummyJet;
70  dummyJet.setHwPt(0);
71  dummyJet.setHwPhi(99);
72  dummyJet.setHwEta(99);
73  dummyJet.setHwQual(0x10);
74  std::vector<std::vector<l1t::L1Candidate> > sorted_energies(rows, std::vector<l1t::L1Candidate>(cols, dummyJet));
75  if (verbose)
76  print2DVector(sorted_energies);
77 
78  unsigned int row = 0, col = 0;
79  std::vector<l1t::L1Candidate> energy_feeder(cols, dummyJet);
80  std::vector<l1t::L1Candidate> energy_result(cols, dummyJet);
81  for (int r = 0; r < rows; r++) {
82  for (int c = 0; c < cols; c++) {
83  row = (r % row_block_length) * cols + c; //row goes up to 19 and we pad with zeros
84 
85  if (row < energies.size()) {
86  energy_feeder[c] = energies[row][col];
87  } else {
88  energy_feeder[c] = dummyJet;
89  }
90 
91  } //c
92 
93  energy_result = sort_array(energy_feeder); //sort!
94 
95  sorted_energies[r] = energy_result;
96 
97  if (r % row_block_length == row_block_length - 1)
98  col++;
99 
100  } //r
101  if (verbose)
102  print2DVector(sorted_energies);
103 
104  return sorted_energies;
105 }

References HltBtagPostValidation_cff::c, cuy::col, print2DVector(), alignCSCRings::r, postprocess-scan-build::rows, l1t::L1Candidate::setHwEta(), l1t::L1Candidate::setHwPhi(), l1t::L1Candidate::setHwPt(), l1t::L1Candidate::setHwQual(), sort_array(), and verbose.

Referenced by l1t::SortJets(), and l1t::SortTaus().

◆ presort_egamma()

std::vector<std::vector<l1t::L1Candidate> > presort_egamma ( std::vector< l1t::L1Candidate > const &  input_egamma,
int  rows,
int  cols 
)

Definition at line 243 of file HardwareSortingMethods.cc.

245  {
246  int row_block_length = input_egamma.size() / cols;
247  if (input_egamma.size() % cols != 0)
248  row_block_length++;
249 
250  //Initialize output
251  l1t::L1Candidate dummyJet;
252  dummyJet.setHwPt(0);
253  dummyJet.setHwPhi(99);
254  dummyJet.setHwEta(99);
255  dummyJet.setHwQual(0x10);
256  std::vector<std::vector<l1t::L1Candidate> > sorted_energies(rows, std::vector<l1t::L1Candidate>(cols, dummyJet));
257  if (verbose)
258  print2DVector(sorted_energies);
259 
260  unsigned int row = 0, col = 0;
261  std::vector<l1t::L1Candidate> energy_feeder(cols, dummyJet);
262  std::vector<l1t::L1Candidate> energy_result(cols, dummyJet);
263  for (int r = 0; r < rows; r++) {
264  for (int c = 0; c < cols; c++) {
265  row = (r % row_block_length) * cols + c; //row goes up to 19 and we pad with zeros
266  //cout << "row, col = " << row << ", " << col << endl;
267 
268  if (row < input_egamma.size()) {
269  energy_feeder[c] = input_egamma[row];
270  } else {
271  energy_feeder[c] = dummyJet;
272  }
273 
274  } //c
275 
276  energy_result = sort_array(energy_feeder); //sort!
277 
278  sorted_energies[r] = energy_result;
279 
280  if (r % row_block_length == row_block_length - 1)
281  col++;
282 
283  } //r
284  if (verbose)
285  print2DVector(sorted_energies);
286 
287  return sorted_energies;
288 }

References HltBtagPostValidation_cff::c, cuy::col, print2DVector(), alignCSCRings::r, postprocess-scan-build::rows, l1t::L1Candidate::setHwEta(), l1t::L1Candidate::setHwPhi(), l1t::L1Candidate::setHwPt(), l1t::L1Candidate::setHwQual(), sort_array(), and verbose.

Referenced by l1t::SortEGammas().

◆ print2DVector()

void print2DVector ( std::vector< std::vector< l1t::L1Candidate > > const &  myVector)

Definition at line 34 of file HardwareSortingMethods.cc.

34  {
35  int nrows = myVector.size();
36  int ncols = myVector[0].size();
37  std::cout << std::endl;
38  std::cout << "rows: " << nrows << std::endl;
39  std::cout << "cols: " << ncols << std::endl;
40 
41  for (int r = 0; r < nrows; r++) {
42  for (int c = 0; c < ncols; c++) {
43  std::cout << std::setw(5) << myVector[r][c].hwPt() << ' ';
44  }
45  std::cout << std::endl;
46  }
47 }

References HltBtagPostValidation_cff::c, gather_cfg::cout, hgcalPlots::ncols, and alignCSCRings::r.

Referenced by presort(), presort_egamma(), sort_by_row_in_groups(), and super_sort_matrix_rows().

◆ sort_array()

std::vector<l1t::L1Candidate> sort_array ( std::vector< l1t::L1Candidate > const &  inputArray)

Definition at line 49 of file HardwareSortingMethods.cc.

49  {
50  std::vector<l1t::L1Candidate> outputArray(inputArray.size());
51  for (unsigned int i = 0; i < inputArray.size(); i++) {
52  int rank = 0;
53  for (unsigned int j = 0; j < inputArray.size(); j++) {
54  if ((inputArray[i].hwPt() > inputArray[j].hwPt()) || ((inputArray[i].hwPt() == inputArray[j].hwPt()) && i < j))
55  rank++;
56  } //j
57  outputArray[outputArray.size() - 1 - rank] = inputArray[i];
58  } //i
59  return outputArray;
60 }

References mps_fire::i, and dqmiolumiharvest::j.

Referenced by presort(), presort_egamma(), and super_sort_matrix_rows().

◆ sort_by_row_in_groups()

std::vector<std::vector<l1t::L1Candidate> > sort_by_row_in_groups ( std::vector< std::vector< l1t::L1Candidate > > const &  input_matrix,
int  group_size 
)

Definition at line 149 of file HardwareSortingMethods.cc.

150  {
151  int n_groups =
152  input_matrix.size() / group_size +
153  (1 - input_matrix.size() / group_size * group_size / input_matrix.size()); //constants must make this an integer
154  //std::vector<std::vector<l1t::L1Candidate> > output_matrix(input_matrix.size()+(input_matrix.size() % group_size), std::vector<l1t::L1Candidate> (input_matrix[0].size()));
155  std::vector<std::vector<l1t::L1Candidate> > output_matrix(
156  input_matrix.size() +
157  (group_size * (1 - ((input_matrix.size() / group_size) * group_size) / input_matrix.size())) -
158  (input_matrix.size() % group_size),
159  std::vector<l1t::L1Candidate>(input_matrix[0].size()));
160 
161  for (int g = 0; g < n_groups; g++) {
162  std::vector<std::vector<l1t::L1Candidate> > small_output_matrix = extract_sub_jet_energy_position_matrix(
163  input_matrix, g * group_size, (g + 1) * group_size - 1, 0, input_matrix[0].size() - 1);
164  small_output_matrix = sort_matrix_rows(small_output_matrix);
165 
166  for (unsigned int i = 0; i < small_output_matrix.size(); i++) {
167  output_matrix[g * group_size + i] = small_output_matrix[i];
168  }
169  }
170 
171  if (verbose)
172  print2DVector(output_matrix);
173  return output_matrix;
174 }

References extract_sub_jet_energy_position_matrix(), g, mps_fire::i, print2DVector(), findQualityFiles::size, sort_matrix_rows(), and verbose.

Referenced by l1t::SortEGammas(), l1t::SortJets(), and l1t::SortTaus().

◆ sort_matrix_rows()

std::vector<std::vector<l1t::L1Candidate> > sort_matrix_rows ( std::vector< std::vector< l1t::L1Candidate > > const &  input_matrix)

Definition at line 131 of file HardwareSortingMethods.cc.

132  {
133  std::vector<std::vector<l1t::L1Candidate> > output_matrix(input_matrix.size(),
134  std::vector<l1t::L1Candidate>(input_matrix[0].size()));
135 
136  for (unsigned int i = 0; i < input_matrix.size(); i++) {
137  int rank = 0;
138  for (unsigned int j = 0; j < input_matrix.size(); j++) {
139  if ((input_matrix[i][0].hwPt() > input_matrix[j][0].hwPt()) ||
140  ((input_matrix[i][0].hwPt() == input_matrix[j][0].hwPt()) && i < j))
141  rank++;
142  } //j
143  output_matrix[input_matrix.size() - 1 - rank] = input_matrix[i];
144  } //i
145 
146  return output_matrix;
147 }

References mps_fire::i, dqmiolumiharvest::j, and findQualityFiles::size.

Referenced by sort_by_row_in_groups().

◆ super_sort_matrix_rows()

std::vector<std::vector<l1t::L1Candidate> > super_sort_matrix_rows ( std::vector< std::vector< l1t::L1Candidate > > const &  input_matrix,
unsigned int  group_size,
unsigned int  n_keep 
)

Definition at line 211 of file HardwareSortingMethods.cc.

212  {
213  unsigned int n_groups =
214  input_matrix.size() / group_size +
215  (1 - input_matrix.size() / group_size * group_size / input_matrix.size()); //constants must make this an integer
216  std::vector<std::vector<l1t::L1Candidate> > output_matrix(n_groups, std::vector<l1t::L1Candidate>(n_keep));
217 
218  for (unsigned int g = 0; g < n_groups; g++) {
219  std::vector<std::vector<l1t::L1Candidate> > small_output_matrix = extract_sub_jet_energy_position_matrix(
220  input_matrix, g * group_size, (g + 1) * group_size - 1, 0, input_matrix[0].size() - 1);
221  std::vector<l1t::L1Candidate> unsorted_array = array_from_row_sorted_matrix(small_output_matrix, n_keep);
222  std::vector<l1t::L1Candidate> unsorted_array_without_largest(unsorted_array.size() -
223  1); //we know first element is the biggest
224  for (unsigned int i = 0; i < unsorted_array.size() - 1; i++) {
225  unsorted_array_without_largest[i] = unsorted_array[1 + i];
226  }
227  std::vector<l1t::L1Candidate> sorted_array_without_largest = sort_array(unsorted_array_without_largest);
228 
229  std::vector<l1t::L1Candidate> sorted_array(n_keep);
230  sorted_array[0] = unsorted_array[0];
231  for (unsigned int i = 0; i < n_keep - 1; i++) {
232  sorted_array[1 + i] = sorted_array_without_largest[i];
233  }
234 
235  output_matrix[g] = sorted_array;
236  } //g
237 
238  if (verbose)
239  print2DVector(output_matrix);
240  return output_matrix;
241 }

References array_from_row_sorted_matrix(), extract_sub_jet_energy_position_matrix(), g, mps_fire::i, print2DVector(), findQualityFiles::size, sort_array(), and verbose.

Referenced by l1t::SortEGammas(), l1t::SortJets(), and l1t::SortTaus().

hgcalPlots.ncols
ncols
Definition: hgcalPlots.py:105
mps_fire.i
i
Definition: mps_fire.py:355
print2DVector
void print2DVector(std::vector< std::vector< l1t::L1Candidate > > const &myVector)
Definition: HardwareSortingMethods.cc:34
cuy.col
col
Definition: cuy.py:1010
gather_cfg.cout
cout
Definition: gather_cfg.py:144
sort_array
std::vector< l1t::L1Candidate > sort_array(std::vector< l1t::L1Candidate > const &inputArray)
Definition: HardwareSortingMethods.cc:49
sort_matrix_rows
std::vector< std::vector< l1t::L1Candidate > > sort_matrix_rows(std::vector< std::vector< l1t::L1Candidate > > const &input_matrix)
Definition: HardwareSortingMethods.cc:131
l1t::L1Candidate
Definition: L1Candidate.h:15
l1t::L1Candidate::setHwQual
void setHwQual(int qual)
Definition: L1Candidate.h:31
array_from_row_sorted_matrix
std::vector< l1t::L1Candidate > array_from_row_sorted_matrix(std::vector< std::vector< l1t::L1Candidate > > const &input_matrix, unsigned int n_keep)
Definition: HardwareSortingMethods.cc:176
verbose
static constexpr int verbose
Definition: HLTExoticaSubAnalysis.cc:25
dqmdumpme.k
k
Definition: dqmdumpme.py:60
l1t::L1Candidate::setHwPt
void setHwPt(int pt)
Definition: L1Candidate.h:28
l1t::L1Candidate::setHwEta
void setHwEta(int eta)
Definition: L1Candidate.h:29
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
extract_sub_jet_energy_position_matrix
std::vector< std::vector< l1t::L1Candidate > > extract_sub_jet_energy_position_matrix(std::vector< std::vector< l1t::L1Candidate > > const &input_matrix, unsigned int row_i, unsigned int row_f, unsigned int col_i, unsigned int col_f)
Definition: HardwareSortingMethods.cc:107
alignCSCRings.r
r
Definition: alignCSCRings.py:93
l1t::L1Candidate::setHwPhi
void setHwPhi(int phi)
Definition: L1Candidate.h:30
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
postprocess-scan-build.rows
rows
Definition: postprocess-scan-build.py:11
g
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443