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
 map containing the conditions
 

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

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

Referenced by super_sort_matrix_rows().

144  {
145  std::vector<l1t::L1Candidate> output_array (n_keep*(n_keep+1)/2);
146  unsigned int max_row = n_keep-1;
147  unsigned int max_col = n_keep-1;
148 
149  //compute size
150  if(input_matrix.size() < n_keep) max_row = input_matrix.size()-1;
151  if(input_matrix[0].size() < n_keep) max_col = input_matrix[0].size()-1;
152 
153  unsigned int array_position = 0;
154  for(unsigned int i=0; i<=max_row; i++){
155  for(unsigned int j=0; j<=max_col-i; j++){
156  //cout << input_matrix[i][j].hwPt() << endl;
157  output_array[array_position] = input_matrix[i][j];
158  array_position++;
159  }//j
160  }//i
161 
162  //fill rest with zeros
163  l1t::L1Candidate dummyJet;
164  dummyJet.setHwPt(0);
165  dummyJet.setHwPhi(99);
166  dummyJet.setHwEta(99);
167  dummyJet.setHwQual(0x10);
168  for(unsigned int k=array_position; k<output_array.size(); k++){
169  output_array[k]=dummyJet;
170  }
171 
172  //printVector(output_array);
173  return output_array;
174 }
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 94 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().

94  {
95  std::vector<std::vector<l1t::L1Candidate> > output_matrix(row_f-row_i+1,std::vector<l1t::L1Candidate>(col_f-col_i+1));
96  l1t::L1Candidate dummyJet;
97  dummyJet.setHwPt(0);
98  dummyJet.setHwPhi(99);
99  dummyJet.setHwEta(99);
100  dummyJet.setHwQual(0x10);
101  for(unsigned int i=0; i<row_f-row_i+1; i++){
102  for(unsigned int j=0; j<col_f-col_i+1; j++){
103  if(row_i+i > input_matrix.size()-1) output_matrix[i][j] = dummyJet;
104  else output_matrix[i][j] = input_matrix[row_i+i][col_i+j];
105  }//j
106  }//i
107  return output_matrix;
108 }
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 52 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().

52  {
53 
54  int row_block_length = energies.size() / cols;
55  if(energies.size() % cols != 0) row_block_length++;
56 
57  l1t::L1Candidate dummyJet;
58  dummyJet.setHwPt(0);
59  dummyJet.setHwPhi(99);
60  dummyJet.setHwEta(99);
61  dummyJet.setHwQual(0x10);
62  std::vector<std::vector<l1t::L1Candidate> > sorted_energies (rows, std::vector<l1t::L1Candidate>(cols, dummyJet));
63  if(verbose) print2DVector( sorted_energies );
64 
65  unsigned int row=0, col=0;
66  std::vector<l1t::L1Candidate> energy_feeder (cols, dummyJet);
67  std::vector<l1t::L1Candidate> energy_result (cols, dummyJet);
68  for(int r=0; r<rows; r++){
69  for(int c=0; c<cols; c++){
70 
71  row = (r % row_block_length)*cols+c;//row goes up to 19 and we pad with zeros
72 
73  if(row < energies.size()){
74  energy_feeder[c] = energies[row][col];
75  }
76  else{
77  energy_feeder[c] = dummyJet;
78  }
79 
80  }//c
81 
82  energy_result = sort_array(energy_feeder);//sort!
83 
84  sorted_energies[r] = energy_result;
85 
86  if(r % row_block_length == row_block_length - 1) col++;
87 
88  }//r
89  if(verbose) print2DVector( sorted_energies );
90 
91  return sorted_energies;
92 }
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 202 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().

202  {
203 
204  int row_block_length = input_egamma.size() / cols;
205  if(input_egamma.size() % cols != 0) row_block_length++;
206 
207  //Initialize output
208  l1t::L1Candidate dummyJet;
209  dummyJet.setHwPt(0);
210  dummyJet.setHwPhi(99);
211  dummyJet.setHwEta(99);
212  dummyJet.setHwQual(0x10);
213  std::vector<std::vector<l1t::L1Candidate> > sorted_energies (rows, std::vector<l1t::L1Candidate>(cols, dummyJet));
214  if(verbose) print2DVector( sorted_energies );
215 
216  unsigned int row=0, col=0;
217  std::vector<l1t::L1Candidate> energy_feeder (cols, dummyJet);
218  std::vector<l1t::L1Candidate> energy_result (cols, dummyJet);
219  for(int r=0; r<rows; r++){
220  for(int c=0; c<cols; c++){
221 
222  row = (r % row_block_length)*cols+c;//row goes up to 19 and we pad with zeros
223  //cout << "row, col = " << row << ", " << col << endl;
224 
225  if(row < input_egamma.size()){
226  energy_feeder[c] = input_egamma[row];
227  }
228  else{
229  energy_feeder[c] = dummyJet;
230  }
231 
232  }//c
233 
234  energy_result = sort_array(energy_feeder);//sort!
235 
236  sorted_energies[r] = energy_result;
237 
238  if(r % row_block_length == row_block_length - 1) col++;
239 
240  }//r
241  if(verbose) print2DVector( sorted_energies );
242 
243  return sorted_energies;
244 }
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 25 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().

25  {
26  int nrows = myVector.size();
27  int ncols = myVector[0].size();
28  std::cout << std::endl;
29  std::cout << "rows: " << nrows << std::endl;
30  std::cout << "cols: " << ncols << std::endl;
31 
32  for(int r=0; r<nrows; r++){
33  for(int c=0; c<ncols; c++){
34  std::cout << std::setw(5) << myVector[r][c].hwPt() << ' ';
35  }
36  std::cout << std::endl;
37  }
38 }
tuple cout
Definition: gather_cfg.py:121
std::vector<l1t::L1Candidate> sort_array ( std::vector< l1t::L1Candidate inputArray)

Definition at line 40 of file HardwareSortingMethods.cc.

References i, and j.

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

40  {
41  std::vector<l1t::L1Candidate> outputArray(inputArray.size());
42  for(unsigned int i=0; i<inputArray.size(); i++){
43  int rank=0;
44  for(unsigned int j=0; j<inputArray.size(); j++){
45  if( (inputArray[i].hwPt() > inputArray[j].hwPt()) || ( (inputArray[i].hwPt() == inputArray[j].hwPt()) && i<j) ) rank++;
46  }//j
47  outputArray[outputArray.size()-1-rank] = inputArray[i];
48  }//i
49  return outputArray;
50 }
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 124 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().

124  {
125  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
126  //std::vector<std::vector<l1t::L1Candidate> > output_matrix(input_matrix.size()+(input_matrix.size() % group_size), std::vector<l1t::L1Candidate> (input_matrix[0].size()));
127  std::vector<std::vector<l1t::L1Candidate> > output_matrix(input_matrix.size()
128  +(group_size*(1 - ((input_matrix.size()/group_size)*group_size)/input_matrix.size()))
129  -(input_matrix.size() % group_size), std::vector<l1t::L1Candidate> (input_matrix[0].size()));
130 
131  for(int g=0; g<n_groups; g++){
132  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 );
133  small_output_matrix = sort_matrix_rows(small_output_matrix);
134 
135  for(unsigned int i=0; i<small_output_matrix.size(); i++){
136  output_matrix[g*group_size+i]=small_output_matrix[i];
137  }
138  }
139 
140  if(verbose) print2DVector( output_matrix );
141  return output_matrix;
142 }
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 110 of file HardwareSortingMethods.cc.

References i, and j.

Referenced by sort_by_row_in_groups().

110  {
111  std::vector<std::vector<l1t::L1Candidate> > output_matrix( input_matrix.size(), std::vector<l1t::L1Candidate> (input_matrix[0].size()));
112 
113  for(unsigned int i=0; i<input_matrix.size(); i++){
114  int rank=0;
115  for (unsigned int j=0; j<input_matrix.size(); j++){
116  if( (input_matrix[i][0].hwPt() > input_matrix[j][0].hwPt()) || ((input_matrix[i][0].hwPt() == input_matrix[j][0].hwPt()) && i<j)) rank++;
117  }//j
118  output_matrix[input_matrix.size()-1-rank] = input_matrix[i];
119  }//i
120 
121  return output_matrix;
122 }
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 176 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().

176  {
177  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
178  std::vector<std::vector<l1t::L1Candidate> > output_matrix(n_groups, std::vector<l1t::L1Candidate>(n_keep));
179 
180  for(unsigned int g=0; g<n_groups; g++){
181  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 );
182  std::vector<l1t::L1Candidate> unsorted_array = array_from_row_sorted_matrix(small_output_matrix, n_keep);
183  std::vector<l1t::L1Candidate> unsorted_array_without_largest (unsorted_array.size()-1);//we know first element is the biggest
184  for(unsigned int i=0; i<unsorted_array.size()-1; i++){
185  unsorted_array_without_largest[i] = unsorted_array[1+i];
186  }
187  std::vector<l1t::L1Candidate> sorted_array_without_largest = sort_array(unsorted_array_without_largest);
188 
189  std::vector<l1t::L1Candidate> sorted_array (n_keep);
190  sorted_array[0] = unsorted_array[0];
191  for(unsigned int i=0; i<n_keep-1; i++){
192  sorted_array[1+i]=sorted_array_without_largest[i];
193  }
194 
195  output_matrix[g] = sorted_array;
196  }//g
197 
198  if(verbose) print2DVector(output_matrix);
199  return output_matrix;
200 }
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