CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Namespaces | Functions | Variables
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 > > input_matrix, unsigned int n_keep)
 
std::vector< std::vector
< l1t::L1Candidate > > 
extract_sub_jet_energy_position_matrix (std::vector< std::vector< l1t::L1Candidate > > 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 > > energies, int rows, int cols)
 
std::vector< std::vector
< l1t::L1Candidate > > 
presort_egamma (std::vector< l1t::L1Candidate > input_egamma, int rows, int cols)
 
void print2DVector (std::vector< std::vector< l1t::L1Candidate > > myVector)
 
std::vector< l1t::L1Candidatesort_array (std::vector< l1t::L1Candidate > inputArray)
 
std::vector< std::vector
< l1t::L1Candidate > > 
sort_by_row_in_groups (std::vector< std::vector< l1t::L1Candidate > > input_matrix, int group_size)
 
std::vector< std::vector
< l1t::L1Candidate > > 
sort_matrix_rows (std::vector< std::vector< l1t::L1Candidate > > 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 > > input_matrix, unsigned int group_size, unsigned int n_keep)
 

Variables

int fw_to_gt_phi_map [] = {4, 3, 2, 1, 0, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5}
 
int gt_to_fw_phi_map [] = {4, 3, 2, 1, 0, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5}
 
bool verbose = false
 

Function Documentation

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

Definition at line 154 of file HardwareSortingMethods.cc.

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

Referenced by super_sort_matrix_rows().

154  {
155  std::vector<l1t::L1Candidate> output_array (n_keep*(n_keep+1)/2);
156  unsigned int max_row = n_keep-1;
157  unsigned int max_col = n_keep-1;
158 
159  //compute size
160  if(input_matrix.size() < n_keep) max_row = input_matrix.size()-1;
161  if(input_matrix[0].size() < n_keep) max_col = input_matrix[0].size()-1;
162 
163  unsigned int array_position = 0;
164  for(unsigned int i=0; i<=max_row; i++){
165  for(unsigned int j=0; j<=max_col-i; j++){
166  //cout << input_matrix[i][j].hwPt() << endl;
167  output_array[array_position] = input_matrix[i][j];
168  array_position++;
169  }//j
170  }//i
171 
172  //fill rest with zeros
173  l1t::L1Candidate dummyJet;
174  dummyJet.setHwPt(0);
175  dummyJet.setHwPhi(99);
176  dummyJet.setHwEta(99);
177  dummyJet.setHwQual(0x10);
178  for(unsigned int k=array_position; k<output_array.size(); k++){
179  output_array[k]=dummyJet;
180  }
181 
182  //printVector(output_array);
183  return output_array;
184 }
int i
Definition: DBlmapReader.cc:9
void setHwQual(int qual)
Definition: L1Candidate.cc:64
int j
Definition: DBlmapReader.cc:9
void setHwPhi(int phi)
Definition: L1Candidate.cc:54
void setHwPt(int pt)
Definition: L1Candidate.cc:44
void setHwEta(int eta)
Definition: L1Candidate.cc:49
tuple size
Write out results.
std::vector<std::vector<l1t::L1Candidate> > extract_sub_jet_energy_position_matrix ( std::vector< std::vector< l1t::L1Candidate > >  input_matrix,
unsigned int  row_i,
unsigned int  row_f,
unsigned int  col_i,
unsigned int  col_f 
)

Definition at line 104 of file HardwareSortingMethods.cc.

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

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

Definition at line 62 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().

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

Definition at line 212 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().

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

Definition at line 35 of file HardwareSortingMethods.cc.

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

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

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

Definition at line 50 of file HardwareSortingMethods.cc.

References i, and j.

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

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

Definition at line 134 of file HardwareSortingMethods.cc.

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

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

134  {
135  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
136  //std::vector<std::vector<l1t::L1Candidate> > output_matrix(input_matrix.size()+(input_matrix.size() % group_size), std::vector<l1t::L1Candidate> (input_matrix[0].size()));
137  std::vector<std::vector<l1t::L1Candidate> > output_matrix(input_matrix.size()
138  +(group_size*(1 - ((input_matrix.size()/group_size)*group_size)/input_matrix.size()))
139  -(input_matrix.size() % group_size), std::vector<l1t::L1Candidate> (input_matrix[0].size()));
140 
141  for(int g=0; g<n_groups; g++){
142  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 );
143  small_output_matrix = sort_matrix_rows(small_output_matrix);
144 
145  for(unsigned int i=0; i<small_output_matrix.size(); i++){
146  output_matrix[g*group_size+i]=small_output_matrix[i];
147  }
148  }
149 
150  if(verbose) print2DVector( output_matrix );
151  return output_matrix;
152 }
int i
Definition: DBlmapReader.cc:9
std::vector< std::vector< l1t::L1Candidate > > sort_matrix_rows(std::vector< std::vector< l1t::L1Candidate > > input_matrix)
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
void print2DVector(std::vector< std::vector< l1t::L1Candidate > > myVector)
std::vector< std::vector< l1t::L1Candidate > > extract_sub_jet_energy_position_matrix(std::vector< std::vector< l1t::L1Candidate > > input_matrix, unsigned int row_i, unsigned int row_f, unsigned int col_i, unsigned int col_f)
tuple size
Write out results.
std::vector<std::vector<l1t::L1Candidate> > sort_matrix_rows ( std::vector< std::vector< l1t::L1Candidate > >  input_matrix)

Definition at line 120 of file HardwareSortingMethods.cc.

References i, and j.

Referenced by sort_by_row_in_groups().

120  {
121  std::vector<std::vector<l1t::L1Candidate> > output_matrix( input_matrix.size(), std::vector<l1t::L1Candidate> (input_matrix[0].size()));
122 
123  for(unsigned int i=0; i<input_matrix.size(); i++){
124  int rank=0;
125  for (unsigned int j=0; j<input_matrix.size(); j++){
126  if( (input_matrix[i][0].hwPt() > input_matrix[j][0].hwPt()) || ((input_matrix[i][0].hwPt() == input_matrix[j][0].hwPt()) && i<j)) rank++;
127  }//j
128  output_matrix[input_matrix.size()-1-rank] = input_matrix[i];
129  }//i
130 
131  return output_matrix;
132 }
int i
Definition: DBlmapReader.cc:9
int j
Definition: DBlmapReader.cc:9
std::vector<std::vector<l1t::L1Candidate> > super_sort_matrix_rows ( std::vector< std::vector< l1t::L1Candidate > >  input_matrix,
unsigned int  group_size,
unsigned int  n_keep 
)

Definition at line 186 of file HardwareSortingMethods.cc.

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

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

186  {
187  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
188  std::vector<std::vector<l1t::L1Candidate> > output_matrix(n_groups, std::vector<l1t::L1Candidate>(n_keep));
189 
190  for(unsigned int g=0; g<n_groups; g++){
191  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 );
192  std::vector<l1t::L1Candidate> unsorted_array = array_from_row_sorted_matrix(small_output_matrix, n_keep);
193  std::vector<l1t::L1Candidate> unsorted_array_without_largest (unsorted_array.size()-1);//we know first element is the biggest
194  for(unsigned int i=0; i<unsorted_array.size()-1; i++){
195  unsorted_array_without_largest[i] = unsorted_array[1+i];
196  }
197  std::vector<l1t::L1Candidate> sorted_array_without_largest = sort_array(unsorted_array_without_largest);
198 
199  std::vector<l1t::L1Candidate> sorted_array (n_keep);
200  sorted_array[0] = unsorted_array[0];
201  for(unsigned int i=0; i<n_keep-1; i++){
202  sorted_array[1+i]=sorted_array_without_largest[i];
203  }
204 
205  output_matrix[g] = sorted_array;
206  }//g
207 
208  if(verbose) print2DVector(output_matrix);
209  return output_matrix;
210 }
int i
Definition: DBlmapReader.cc:9
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
void print2DVector(std::vector< std::vector< l1t::L1Candidate > > myVector)
std::vector< std::vector< l1t::L1Candidate > > extract_sub_jet_energy_position_matrix(std::vector< std::vector< l1t::L1Candidate > > input_matrix, unsigned int row_i, unsigned int row_f, unsigned int col_i, unsigned int col_f)
std::vector< l1t::L1Candidate > array_from_row_sorted_matrix(std::vector< std::vector< l1t::L1Candidate > > input_matrix, unsigned int n_keep)
std::vector< l1t::L1Candidate > sort_array(std::vector< l1t::L1Candidate > inputArray)
tuple size
Write out results.

Variable Documentation

int fw_to_gt_phi_map[] = {4, 3, 2, 1, 0, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5}

Definition at line 15 of file HardwareSortingMethods.cc.

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

int gt_to_fw_phi_map[] = {4, 3, 2, 1, 0, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5}

Definition at line 16 of file HardwareSortingMethods.cc.

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

bool verbose = false