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

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 156 of file HardwareSortingMethods.cc.

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

Referenced by super_sort_matrix_rows().

156  {
157  std::vector<l1t::L1Candidate> output_array (n_keep*(n_keep+1)/2);
158  unsigned int max_row = n_keep-1;
159  unsigned int max_col = n_keep-1;
160 
161  //compute size
162  if(input_matrix.size() < n_keep) max_row = input_matrix.size()-1;
163  if(input_matrix[0].size() < n_keep) max_col = input_matrix[0].size()-1;
164 
165  unsigned int array_position = 0;
166  for(unsigned int i=0; i<=max_row; i++){
167  for(unsigned int j=0; j<=max_col-i; j++){
168  //cout << input_matrix[i][j].hwPt() << endl;
169  output_array[array_position] = input_matrix[i][j];
170  array_position++;
171  }//j
172  }//i
173 
174  //fill rest with zeros
175  l1t::L1Candidate dummyJet;
176  dummyJet.setHwPt(0);
177  dummyJet.setHwPhi(99);
178  dummyJet.setHwEta(99);
179  dummyJet.setHwQual(0x10);
180  for(unsigned int k=array_position; k<output_array.size(); k++){
181  output_array[k]=dummyJet;
182  }
183 
184  //printVector(output_array);
185  return output_array;
186 }
size
Write out results.
void setHwQual(int qual)
Definition: L1Candidate.h:44
int k[5][pyjets_maxn]
void setHwPhi(int phi)
Definition: L1Candidate.h:43
void setHwPt(int pt)
Definition: L1Candidate.h:41
void setHwEta(int eta)
Definition: L1Candidate.h:42
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 106 of file HardwareSortingMethods.cc.

References mps_fire::i, 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().

106  {
107  std::vector<std::vector<l1t::L1Candidate> > output_matrix(row_f-row_i+1,std::vector<l1t::L1Candidate>(col_f-col_i+1));
108  l1t::L1Candidate dummyJet;
109  dummyJet.setHwPt(0);
110  dummyJet.setHwPhi(99);
111  dummyJet.setHwEta(99);
112  dummyJet.setHwQual(0x10);
113  for(unsigned int i=0; i<row_f-row_i+1; i++){
114  for(unsigned int j=0; j<col_f-col_i+1; j++){
115  if(row_i+i > input_matrix.size()-1) output_matrix[i][j] = dummyJet;
116  else output_matrix[i][j] = input_matrix[row_i+i][col_i+j];
117  }//j
118  }//i
119  return output_matrix;
120 }
void setHwQual(int qual)
Definition: L1Candidate.h:44
void setHwPhi(int phi)
Definition: L1Candidate.h:43
void setHwPt(int pt)
Definition: L1Candidate.h:41
void setHwEta(int eta)
Definition: L1Candidate.h:42
std::vector<std::vector<l1t::L1Candidate> > presort ( std::vector< std::vector< l1t::L1Candidate > > const &  energies,
int  rows,
int  cols 
)

Definition at line 64 of file HardwareSortingMethods.cc.

References EnergyCorrector::c, cuy::col, print2DVector(), alignCSCRings::r, tablePrinter::rows, l1t::L1Candidate::setHwEta(), l1t::L1Candidate::setHwPhi(), l1t::L1Candidate::setHwPt(), l1t::L1Candidate::setHwQual(), and sort_array().

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

64  {
65 
66  int row_block_length = energies.size() / cols;
67  if(energies.size() % cols != 0) 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) print2DVector( sorted_energies );
76 
77  unsigned int row=0, col=0;
78  std::vector<l1t::L1Candidate> energy_feeder (cols, dummyJet);
79  std::vector<l1t::L1Candidate> energy_result (cols, dummyJet);
80  for(int r=0; r<rows; r++){
81  for(int c=0; c<cols; c++){
82 
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  }
88  else{
89  energy_feeder[c] = dummyJet;
90  }
91 
92  }//c
93 
94  energy_result = sort_array(energy_feeder);//sort!
95 
96  sorted_energies[r] = energy_result;
97 
98  if(r % row_block_length == row_block_length - 1) col++;
99 
100  }//r
101  if(verbose) print2DVector( sorted_energies );
102 
103  return sorted_energies;
104 }
void print2DVector(std::vector< std::vector< l1t::L1Candidate > > const &myVector)
void setHwQual(int qual)
Definition: L1Candidate.h:44
void setHwPhi(int phi)
Definition: L1Candidate.h:43
std::vector< l1t::L1Candidate > sort_array(std::vector< l1t::L1Candidate > const &inputArray)
void setHwPt(int pt)
Definition: L1Candidate.h:41
col
Definition: cuy.py:1010
void setHwEta(int eta)
Definition: L1Candidate.h:42
std::vector<std::vector<l1t::L1Candidate> > presort_egamma ( std::vector< l1t::L1Candidate > const &  input_egamma,
int  rows,
int  cols 
)

Definition at line 214 of file HardwareSortingMethods.cc.

References EnergyCorrector::c, cuy::col, print2DVector(), alignCSCRings::r, tablePrinter::rows, l1t::L1Candidate::setHwEta(), l1t::L1Candidate::setHwPhi(), l1t::L1Candidate::setHwPt(), l1t::L1Candidate::setHwQual(), and sort_array().

Referenced by l1t::SortEGammas().

214  {
215 
216  int row_block_length = input_egamma.size() / cols;
217  if(input_egamma.size() % cols != 0) row_block_length++;
218 
219  //Initialize output
220  l1t::L1Candidate dummyJet;
221  dummyJet.setHwPt(0);
222  dummyJet.setHwPhi(99);
223  dummyJet.setHwEta(99);
224  dummyJet.setHwQual(0x10);
225  std::vector<std::vector<l1t::L1Candidate> > sorted_energies (rows, std::vector<l1t::L1Candidate>(cols, dummyJet));
226  if(verbose) print2DVector( sorted_energies );
227 
228  unsigned int row=0, col=0;
229  std::vector<l1t::L1Candidate> energy_feeder (cols, dummyJet);
230  std::vector<l1t::L1Candidate> energy_result (cols, dummyJet);
231  for(int r=0; r<rows; r++){
232  for(int c=0; c<cols; c++){
233 
234  row = (r % row_block_length)*cols+c;//row goes up to 19 and we pad with zeros
235  //cout << "row, col = " << row << ", " << col << endl;
236 
237  if(row < input_egamma.size()){
238  energy_feeder[c] = input_egamma[row];
239  }
240  else{
241  energy_feeder[c] = dummyJet;
242  }
243 
244  }//c
245 
246  energy_result = sort_array(energy_feeder);//sort!
247 
248  sorted_energies[r] = energy_result;
249 
250  if(r % row_block_length == row_block_length - 1) col++;
251 
252  }//r
253  if(verbose) print2DVector( sorted_energies );
254 
255  return sorted_energies;
256 }
void print2DVector(std::vector< std::vector< l1t::L1Candidate > > const &myVector)
void setHwQual(int qual)
Definition: L1Candidate.h:44
void setHwPhi(int phi)
Definition: L1Candidate.h:43
std::vector< l1t::L1Candidate > sort_array(std::vector< l1t::L1Candidate > const &inputArray)
void setHwPt(int pt)
Definition: L1Candidate.h:41
col
Definition: cuy.py:1010
void setHwEta(int eta)
Definition: L1Candidate.h:42
void print2DVector ( std::vector< std::vector< l1t::L1Candidate > > const &  myVector)

Definition at line 37 of file HardwareSortingMethods.cc.

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

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

37  {
38  int nrows = myVector.size();
39  int ncols = myVector[0].size();
40  std::cout << std::endl;
41  std::cout << "rows: " << nrows << std::endl;
42  std::cout << "cols: " << ncols << std::endl;
43 
44  for(int r=0; r<nrows; r++){
45  for(int c=0; c<ncols; c++){
46  std::cout << std::setw(5) << myVector[r][c].hwPt() << ' ';
47  }
48  std::cout << std::endl;
49  }
50 }
std::vector<l1t::L1Candidate> sort_array ( std::vector< l1t::L1Candidate > const &  inputArray)

Definition at line 52 of file HardwareSortingMethods.cc.

References mps_fire::i.

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

52  {
53  std::vector<l1t::L1Candidate> outputArray(inputArray.size());
54  for(unsigned int i=0; i<inputArray.size(); i++){
55  int rank=0;
56  for(unsigned int j=0; j<inputArray.size(); j++){
57  if( (inputArray[i].hwPt() > inputArray[j].hwPt()) || ( (inputArray[i].hwPt() == inputArray[j].hwPt()) && i<j) ) rank++;
58  }//j
59  outputArray[outputArray.size()-1-rank] = inputArray[i];
60  }//i
61  return outputArray;
62 }
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 136 of file HardwareSortingMethods.cc.

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

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

136  {
137  int n_groups = input_matrix.size()/group_size + (1 - input_matrix.size()/group_size*group_size/input_matrix.size()); //constants must make this an integer
138  //std::vector<std::vector<l1t::L1Candidate> > output_matrix(input_matrix.size()+(input_matrix.size() % group_size), std::vector<l1t::L1Candidate> (input_matrix[0].size()));
139  std::vector<std::vector<l1t::L1Candidate> > output_matrix(input_matrix.size()
140  +(group_size*(1 - ((input_matrix.size()/group_size)*group_size)/input_matrix.size()))
141  -(input_matrix.size() % group_size), std::vector<l1t::L1Candidate> (input_matrix[0].size()));
142 
143  for(int g=0; g<n_groups; g++){
144  std::vector<std::vector<l1t::L1Candidate> > small_output_matrix = extract_sub_jet_energy_position_matrix(input_matrix, g*group_size, (g+1)*group_size-1, 0, input_matrix[0].size()-1 );
145  small_output_matrix = sort_matrix_rows(small_output_matrix);
146 
147  for(unsigned int i=0; i<small_output_matrix.size(); i++){
148  output_matrix[g*group_size+i]=small_output_matrix[i];
149  }
150  }
151 
152  if(verbose) print2DVector( output_matrix );
153  return output_matrix;
154 }
size
Write out results.
void print2DVector(std::vector< std::vector< l1t::L1Candidate > > const &myVector)
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
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)
std::vector< std::vector< l1t::L1Candidate > > sort_matrix_rows(std::vector< std::vector< l1t::L1Candidate > > const &input_matrix)
std::vector<std::vector<l1t::L1Candidate> > sort_matrix_rows ( std::vector< std::vector< l1t::L1Candidate > > const &  input_matrix)

Definition at line 122 of file HardwareSortingMethods.cc.

References mps_fire::i.

Referenced by sort_by_row_in_groups().

122  {
123  std::vector<std::vector<l1t::L1Candidate> > output_matrix( input_matrix.size(), std::vector<l1t::L1Candidate> (input_matrix[0].size()));
124 
125  for(unsigned int i=0; i<input_matrix.size(); i++){
126  int rank=0;
127  for (unsigned int j=0; j<input_matrix.size(); j++){
128  if( (input_matrix[i][0].hwPt() > input_matrix[j][0].hwPt()) || ((input_matrix[i][0].hwPt() == input_matrix[j][0].hwPt()) && i<j)) rank++;
129  }//j
130  output_matrix[input_matrix.size()-1-rank] = input_matrix[i];
131  }//i
132 
133  return output_matrix;
134 }
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 188 of file HardwareSortingMethods.cc.

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

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

188  {
189  unsigned int n_groups = input_matrix.size()/group_size + (1 - input_matrix.size()/group_size*group_size/input_matrix.size()); //constants must make this an integer
190  std::vector<std::vector<l1t::L1Candidate> > output_matrix(n_groups, std::vector<l1t::L1Candidate>(n_keep));
191 
192  for(unsigned int g=0; g<n_groups; g++){
193  std::vector<std::vector<l1t::L1Candidate> > small_output_matrix = extract_sub_jet_energy_position_matrix(input_matrix, g*group_size, (g+1)*group_size-1, 0, input_matrix[0].size()-1 );
194  std::vector<l1t::L1Candidate> unsorted_array = array_from_row_sorted_matrix(small_output_matrix, n_keep);
195  std::vector<l1t::L1Candidate> unsorted_array_without_largest (unsorted_array.size()-1);//we know first element is the biggest
196  for(unsigned int i=0; i<unsorted_array.size()-1; i++){
197  unsorted_array_without_largest[i] = unsorted_array[1+i];
198  }
199  std::vector<l1t::L1Candidate> sorted_array_without_largest = sort_array(unsorted_array_without_largest);
200 
201  std::vector<l1t::L1Candidate> sorted_array (n_keep);
202  sorted_array[0] = unsorted_array[0];
203  for(unsigned int i=0; i<n_keep-1; i++){
204  sorted_array[1+i]=sorted_array_without_largest[i];
205  }
206 
207  output_matrix[g] = sorted_array;
208  }//g
209 
210  if(verbose) print2DVector(output_matrix);
211  return output_matrix;
212 }
size
Write out results.
void print2DVector(std::vector< std::vector< l1t::L1Candidate > > const &myVector)
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
std::vector< l1t::L1Candidate > array_from_row_sorted_matrix(std::vector< std::vector< l1t::L1Candidate > > const &input_matrix, unsigned int n_keep)
std::vector< l1t::L1Candidate > sort_array(std::vector< l1t::L1Candidate > const &inputArray)
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)