test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
UECalibration.h
Go to the documentation of this file.
1 #ifndef __HiJetAlgos_UECalibration_h__
2 #define __HiJetAlgos_UECalibration_h__
3 
5 // SVD Block Predictor
6 #include <fstream>
7 #include <sstream>
8 
10 
11 struct UECalibration {
12  UECalibration(const std::vector<float> &v)
13  {
14  np[0] = 3; // Number of reduced PF ID (track, ECAL, HCAL)
15  np[1] = 15; // Number of pseudorapidity block
16  np[2] = 5; // Fourier series order
17  np[3] = 2; // Re or Im
18  np[4] = 82; // Number of feature parameter
19 
20  ni0[0] = np[1];
21  ni0[1] = 344;
22 
23  ni1[0] = np[1];
24  ni1[1] = 344;
25 
26  ni2[0] = np[1];
27  ni2[1] = 82;
28 
29  unsigned int Nnp_full = np[0] * np[1] * np[2] * np[3] * np[4];
30  unsigned int Nnp = np[0] * np[1] * (1 + (np[2] - 1) * np[3]) * np[4];
31  unsigned int Nni0 = ni0[0]*ni0[1];
32  unsigned int Nni1 = ni1[0]*ni1[1];
33  unsigned int Nni2 = ni2[0]*ni2[1];
34 
35  memset(ue_predictor_pf, 0, Nnp_full * sizeof(float));
36  memset(ue_interpolation_pf0, 0, Nni0 * sizeof(float));
37  memset(ue_interpolation_pf1, 0, Nni1 * sizeof(float));
38  memset(ue_interpolation_pf2, 0, Nni2 * sizeof(float));
39 
40  for (index = 0; index < Nnp + Nni0 + Nni1 + Nni2; index++) {
41  float val = v[index];
42  int bin0, bin1, bin2, bin3, bin4;
43 
44  if (index < Nnp){
45  bin4 = index % np[4];
46 
47  unsigned int u = (index / np[4]) % (1 + (np[2] - 1) * np[3]);
48 
49  if (u == 0) {
50  bin2 = 0;
51  bin3 = 0;
52  }
53  else {
54  bin2 = (u - 1) / np[3] + 1;
55  bin3 = (u - 1) % np[3];
56  }
57 
58  bin1 = ((index / np[4]) / (1 + (np[2] - 1) * np[3])) % np[1];
59  bin0 = ((index / np[4]) / (1 + (np[2] - 1) * np[3])) / np[1];
60 
61  ue_predictor_pf[bin0][bin1][bin2][bin3][bin4] = val;
62  }
63  else if (index < Nnp + Nni0) {
64  bin1 = (index - Nnp) % ni0[1];
65  bin0 = (index - Nnp) / ni0[1];
66  ue_interpolation_pf0[bin0][bin1] = val;
67  }
68  else if (index < Nnp + Nni0 + Nni1) {
69  bin1 = (index - Nnp - Nni0) % ni1[1];
70  bin0 = (index - Nnp - Nni0) / ni1[1];
71  ue_interpolation_pf1[bin0][bin1] = val;
72  }
73  else {
74  bin1 = (index - Nnp - Nni0 - Nni1) % ni2[1];
75  bin0 = (index - Nnp - Nni0 - Nni1) / ni2[1];
76  ue_interpolation_pf2[bin0][bin1] = val;
77  }
78  }
79  }
80 
81  UECalibration(std::string calibrationFile){
82  np[0] = 3; // Number of reduced PF ID (track, ECAL, HCAL)
83  np[1] = 15; // Number of pseudorapidity block
84  np[2] = 5; // Fourier series order
85  np[3] = 2; // Re or Im
86  np[4] = 82; // Number of feature parameter
87 
88  ni0[0] = np[1];
89  ni0[1] = 344;
90 
91  ni1[0] = np[1];
92  ni1[1] = 344;
93 
94  ni2[0] = np[1];
95  ni2[1] = 82;
96 
97  index = 0;
98 
99  unsigned int Nnp_full = np[0] * np[1] * np[2] * np[3] * np[4];
100  unsigned int Nnp = np[0] * np[1] * (1 + (np[2] - 1) * np[3]) * np[4];
101  unsigned int Nni0 = ni0[0]*ni0[1];
102  unsigned int Nni1 = ni1[0]*ni1[1];
103  unsigned int Nni2 = ni2[0]*ni2[1];
104 
105  memset(ue_predictor_pf, 0, Nnp_full * sizeof(float));
106  memset(ue_interpolation_pf0, 0, Nni0 * sizeof(float));
107  memset(ue_interpolation_pf1, 0, Nni1 * sizeof(float));
108  memset(ue_interpolation_pf2, 0, Nni2 * sizeof(float));
109 
110  edm::FileInPath ueData(calibrationFile.data());
111  std::string qpDataName = ueData.fullPath();
112  std::ifstream in( qpDataName.c_str() );
114 
115  while( std::getline( in, line)){
116  if(!line.size() || line[0]=='#') {
117  continue;
118  }
119  std::istringstream linestream(line);
120  float val;
121  int bin0, bin1, bin2, bin3, bin4;
122  if(index < Nnp){
123  // cout<<"predictor "<<bin0<<" "<<bin1<<" "<<bin2<<" "<<bin3<<" "<<bin4<<" "<<val<<endl;
124  linestream>>bin0>>bin1>>bin2>>bin3>>bin4>>val;
125  ue_predictor_pf[bin0][bin1][bin2][bin3][bin4] = val;
126  }else if(index < Nnp + Nni0){
127  // cout<<"inter_0 "<<bin0<<" "<<bin1<<" "<<bin2<<" "<<bin3<<" "<<bin4<<" "<<val<<endl;
128  linestream>>bin0>>bin1>>val;
129  ue_interpolation_pf0[bin0][bin1] = val;
130  }else if(index < Nnp + Nni0 + Nni1){
131  // cout<<"inter_1 "<<bin0<<" "<<bin1<<" "<<bin2<<" "<<bin3<<" "<<bin4<<" "<<val<<endl;
132  linestream>>bin0>>bin1>>val;
133  ue_interpolation_pf1[bin0][bin1] = val;
134  }else if(index < Nnp + Nni0 + Nni1 + Nni2){
135  // cout<<"inter_2 "<<bin0<<" "<<bin1<<" "<<bin2<<" "<<bin3<<" "<<bin4<<" "<<val<<endl;
136  linestream>>bin0>>bin1>>val;
137  ue_interpolation_pf2[bin0][bin1] = val;
138  }
139  ++index;
140  }
141  }
142 
143  unsigned int index,
144  np[5],
145  ni0[2],
146  ni1[2],
147  ni2[2];
148 
149  float ue_predictor_pf[3][15][5][2][82],
150  ue_interpolation_pf0[15][344],
151  ue_interpolation_pf1[15][344],
152  ue_interpolation_pf2[15][82];
153 
154 };
155 
156 
157 #endif
158 
159 
160 
unsigned int ni0[2]
unsigned int index
UECalibration(const std::vector< float > &v)
Definition: UECalibration.h:12
unsigned int ni2[2]
unsigned int np[5]
unsigned int ni1[2]
float ue_interpolation_pf0[15][344]
UECalibration(std::string calibrationFile)
Definition: UECalibration.h:81
float ue_predictor_pf[3][15][5][2][82]
float ue_interpolation_pf1[15][344]
float ue_interpolation_pf2[15][82]