CMS 3D CMS Logo

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