CMS 3D CMS Logo

HiEvtPlaneFlatten.h
Go to the documentation of this file.
1 #ifndef __HiEvtPlaneFlatten__
2 #define __HiEvtPlaneFlatten__
3 #include <memory>
4 #include <iostream>
5 #include <string>
6 
9 
12 
14 
17 
19 
20 #include <vector>
21 #include <cmath>
22 
23 //
24 // class declaration
25 //
26 
28 public:
29  explicit HiEvtPlaneFlatten() {
30  hbins_ = 1;
31  hOrder_ = 9;
32  vorder_ = 2; //sets default order of event plane
33  }
34 
35  void init(int order, int nbins, std::string tag, int vord) {
36  hOrder_ = order; //order of flattening
37  vorder_ = vord; //1(v1), 2(v2), 3(v3), 4(v4)
38  caloCentRefMinBin_ = -1;
39  caloCentRefMaxBin_ = -1;
40  hbins_ = nbins * nvtxbins_ * hOrder_;
41  obins_ = nbins * nvtxbins_;
42  if (hbins_ > MAXCUT) {
43  hbins_ = 1;
44  hOrder_ = 9;
45  }
46  for (int i = 0; i < hbins_; i++) {
47  flatX_[i] = 0;
48  flatY_[i] = 0;
49  flatXDB_[i] = 0;
50  flatYDB_[i] = 0;
51  flatCnt_[i] = 0;
52  }
53  for (int i = 0; i < obins_; i++) {
54  xoff_[i] = 0;
55  yoff_[i] = 0;
56  xoffDB_[i] = 0;
57  yoffDB_[i] = 0;
58  xyoffcnt_[i] = 0;
59  xyoffmult_[i] = 0;
60  pt_[i] = 0;
61  pt2_[i] = 0;
62  ptDB_[i] = 0;
63  pt2DB_[i] = 0;
64  ptcnt_[i] = 0;
65  }
66  }
67 
68  int getCutIndx(int centbin, double vtx, int iord) const {
69  int cut;
70  if (centbin < 0)
71  return -1;
72  int ibin = centbin;
73  int ivtx = (vtx - minvtx_) / delvtx_;
74  if (vtx < minvtx_ || ivtx >= nvtxbins_)
75  return -1;
76  cut = hOrder_ * nvtxbins_ * ibin + hOrder_ * ivtx + iord;
77  if (cut < 0 || cut >= hbins_)
78  return -1;
79  return cut;
80  }
81 
82  int getOffsetIndx(int centbin, double vtx) const {
83  int cut;
84  if (centbin < 0)
85  return -1;
86  int ibin = centbin;
87  int ivtx = (vtx - minvtx_) / delvtx_;
88  if (ivtx < 0 || ivtx > nvtxbins_)
89  return -1;
90  cut = nvtxbins_ * ibin + ivtx;
91  if (cut < 0 || cut > hbins_)
92  return -1;
93  return cut;
94  }
95 
96  void fill(double psi, double vtx, int centbin) {
97  if (fabs(psi) > 4)
98  return;
99  for (int k = 0; k < hOrder_; k++) {
100  double fsin = sin(vorder_ * (k + 1) * psi);
101  double fcos = cos(vorder_ * (k + 1) * psi);
102  int indx = getCutIndx(centbin, vtx, k);
103  if (indx >= 0) {
104  flatX_[indx] += fcos;
105  flatY_[indx] += fsin;
106  ++flatCnt_[indx];
107  }
108  }
109  }
110  void fillOffset(double s, double c, uint m, double vtx, int centbin) {
111  int indx = getOffsetIndx(centbin, vtx);
112  if (indx >= 0) {
113  xoff_[indx] += c;
114  yoff_[indx] += s;
115  xyoffmult_[indx] += m;
116  ++xyoffcnt_[indx];
117  }
118  }
119  void fillPt(double ptval, double vtx, int centbin) {
120  int indx = getOffsetIndx(centbin, vtx);
121  if (indx >= 0) {
122  pt_[indx] += ptval;
123  pt2_[indx] += ptval * ptval;
124  ++ptcnt_[indx];
125  }
126  }
127 
128  void setCaloCentRefBins(const int caloCentRefMinBin, const int caloCentRefMaxBin) {
129  caloCentRefMinBin_ = caloCentRefMinBin;
130  caloCentRefMaxBin_ = caloCentRefMaxBin;
131  }
132 
133  double getEtScale(double vtx, int centbin) const {
134  int refmin = getOffsetIndx(caloCentRefMinBin_, vtx);
135  int refmax = getOffsetIndx(caloCentRefMaxBin_, vtx);
136  double caloCentRefVal_ = 0;
137  for (int i = refmin; i <= refmax; i++) {
138  caloCentRefVal_ += getPtDB(i);
139  }
140  caloCentRefVal_ /= refmax - refmin + 1.;
141  if (caloCentRefMinBin_ < 0)
142  return 1.;
143  int indx = getOffsetIndx(centbin, vtx);
144  if (indx < 0 || caloCentRefVal_ == 0 || getPtDB(indx) == 0)
145  return 1.;
146  return caloCentRefVal_ / getPtDB(indx);
147  }
148 
149  double getW(double pt, double vtx, int centbin) const {
150  int indx = getOffsetIndx(centbin, vtx);
151  if (indx >= 0) {
152  double scale = getEtScale(vtx, centbin);
153  double ptval = getPtDB(indx) * scale;
154  double pt2val = getPt2DB(indx) * pow(scale, 2);
155  if (ptval > 0)
156  return pt * scale - pt2val / ptval;
157  }
158  return 0.;
159  }
160 
161  double getFlatPsi(double psi, double vtx, int centbin) const {
162  double correction = 0;
163  for (int k = 0; k < hOrder_; k++) {
164  int indx = getCutIndx(centbin, vtx, k);
165  if (indx >= 0)
166  correction += (2. / (double)((k + 1) * vorder_)) *
167  (flatXDB_[indx] * sin(vorder_ * (k + 1) * psi) - flatYDB_[indx] * cos(vorder_ * (k + 1) * psi));
168  }
169  psi += correction;
170  psi = bounds(psi);
171  psi = bounds2(psi);
172  return psi;
173  }
174 
175  double getSoffset(double s, double vtx, int centbin) const {
176  int indx = getOffsetIndx(centbin, vtx);
177  if (indx >= 0)
178  return s - yoffDB_[indx];
179  else
180  return s;
181  }
182 
183  double getCoffset(double c, double vtx, int centbin) const {
184  int indx = getOffsetIndx(centbin, vtx);
185  if (indx >= 0)
186  return c - xoffDB_[indx];
187  else
188  return c;
189  }
190 
191  double getOffsetPsi(double s, double c) const {
192  double psi = atan2(s, c) / vorder_;
193  if ((fabs(s) < 1e-4) && (fabs(c) < 1e-4))
194  psi = 0.;
195  psi = bounds(psi);
196  psi = bounds2(psi);
197  return psi;
198  }
199 
201  int getHBins() const { return hbins_; }
202  int getOBins() const { return obins_; }
203  int getNvtx() const { return nvtxbins_; }
204  double getVtxMin() const { return minvtx_; }
205  double getVtxMax() const { return minvtx_ + nvtxbins_ * delvtx_; }
206  int getNcent() const { return hbins_; }
207 
208  double getX(unsigned int bin) const { return flatX_[bin]; }
209  double getY(unsigned int bin) const { return flatY_[bin]; }
210  double getXoff(unsigned int bin) const { return xoff_[bin]; }
211  double getYoff(unsigned int bin) const { return yoff_[bin]; }
212  double getXoffDB(unsigned int bin) const { return xoffDB_[bin]; }
213  double getYoffDB(unsigned int bin) const { return yoffDB_[bin]; }
214  double getXYoffcnt(unsigned int bin) const { return xyoffcnt_[bin]; }
215  double getXYoffmult(unsigned int bin) const { return xyoffmult_[bin]; }
216  double getPt(unsigned int bin) const { return pt_[bin]; }
217  double getPt2(unsigned int bin) const { return pt2_[bin]; }
218  double getPtDB(unsigned int bin) const {
219  if (bin < MAXCUTOFF) {
220  return ptDB_[bin];
221  } else {
222  return 0.;
223  }
224  }
225  double getPt2DB(unsigned int bin) const {
226  if (bin < MAXCUTOFF) {
227  return pt2DB_[bin];
228  } else {
229  return 0.;
230  }
231  }
232  double getPtcnt(unsigned int bin) const { return ptcnt_[bin]; }
233  double getXDB(unsigned int bin) const { return flatXDB_[bin]; }
234  double getYDB(unsigned int bin) const { return flatYDB_[bin]; }
235 
236  double getCnt(unsigned int bin) const { return flatCnt_[bin]; }
237  void setXDB(unsigned int indx, double val) { flatXDB_[indx] = val; }
238  void setYDB(unsigned int indx, double val) { flatYDB_[indx] = val; }
239  void setXoffDB(unsigned int indx, double val) { xoffDB_[indx] = val; }
240  void setYoffDB(unsigned int indx, double val) { yoffDB_[indx] = val; }
241  void setPtDB(unsigned int indx, double val) { ptDB_[indx] = val; }
242  void setPt2DB(unsigned int indx, double val) { pt2DB_[indx] = val; }
243  double bounds(double ang) const {
244  if (ang < -M_PI)
245  ang += 2. * M_PI;
246  if (ang > M_PI)
247  ang -= 2. * M_PI;
248  return ang;
249  }
250  double bounds2(double ang) const {
251  double range = M_PI / (double)vorder_;
252  while (ang < -range) {
253  ang += 2 * range;
254  }
255  while (ang > range) {
256  ang -= 2 * range;
257  }
258  return ang;
259  }
260  void setCentRes1(unsigned int bin, double res, double err) {
261  if (bin < 100) {
262  centRes1_[bin] = res;
263  centResErr1_[bin] = err;
264  }
265  }
266  void setCentRes2(unsigned int bin, double res, double err) {
267  if (bin < 50) {
268  centRes2_[bin] = res;
269  centResErr2_[bin] = err;
270  }
271  }
272  void setCentRes5(unsigned int bin, double res, double err) {
273  if (bin < 20) {
274  centRes5_[bin] = res;
275  centResErr5_[bin] = err;
276  }
277  }
278  void setCentRes10(unsigned int bin, double res, double err) {
279  if (bin < 10) {
280  centRes10_[bin] = res;
281  centResErr10_[bin] = err;
282  }
283  }
284  void setCentRes20(unsigned int bin, double res, double err) {
285  if (bin < 5) {
286  centRes20_[bin] = res;
287  centResErr20_[bin] = err;
288  }
289  }
290  void setCentRes25(unsigned int bin, double res, double err) {
291  if (bin < 4) {
292  centRes25_[bin] = res;
293  centResErr25_[bin] = err;
294  }
295  }
296  void setCentRes30(unsigned int bin, double res, double err) {
297  if (bin < 3) {
298  centRes30_[bin] = res;
299  centResErr30_[bin] = err;
300  }
301  }
302  void setCentRes40(unsigned int bin, double res, double err) {
303  if (bin < 2) {
304  centRes40_[bin] = res;
305  centResErr40_[bin] = err;
306  }
307  }
308 
309  double getCentRes1(unsigned int bin) const {
310  if (bin < 100) {
311  return centRes1_[bin];
312  } else {
313  return 0.;
314  }
315  }
316  double getCentRes2(unsigned int bin) const {
317  if (bin < 50) {
318  return centRes2_[bin];
319  } else {
320  return 0.;
321  }
322  }
323  double getCentRes5(unsigned int bin) const {
324  if (bin < 20) {
325  return centRes5_[bin];
326  } else {
327  return 0.;
328  }
329  }
330  double getCentRes10(unsigned int bin) const {
331  if (bin < 10) {
332  return centRes10_[bin];
333  } else {
334  return 0.;
335  }
336  }
337  double getCentRes20(unsigned int bin) const {
338  if (bin < 5) {
339  return centRes20_[bin];
340  } else {
341  return 0.;
342  }
343  }
344  double getCentRes25(unsigned int bin) const {
345  if (bin < 4) {
346  return centRes25_[bin];
347  } else {
348  return 0.;
349  }
350  }
351  double getCentRes30(unsigned int bin) const {
352  if (bin < 3) {
353  return centRes30_[bin];
354  } else {
355  return 0.;
356  }
357  }
358  double getCentRes40(unsigned int bin) const {
359  if (bin < 2) {
360  return centRes40_[bin];
361  } else {
362  return 0.;
363  }
364  }
365 
366  double getCentResErr1(unsigned int bin) const {
367  if (bin < 100) {
368  return centResErr1_[bin];
369  } else {
370  return 0.;
371  }
372  }
373  double getCentResErr2(unsigned int bin) const {
374  if (bin < 50) {
375  return centResErr2_[bin];
376  } else {
377  return 0.;
378  }
379  }
380  double getCentResErr5(unsigned int bin) const {
381  if (bin < 20) {
382  return centResErr5_[bin];
383  } else {
384  return 0.;
385  }
386  }
387  double getCentResErr10(unsigned int bin) const {
388  if (bin < 10) {
389  return centResErr10_[bin];
390  } else {
391  return 0.;
392  }
393  }
394  double getCentResErr20(unsigned int bin) const {
395  if (bin < 5) {
396  return centResErr20_[bin];
397  } else {
398  return 0.;
399  }
400  }
401  double getCentResErr25(unsigned int bin) const {
402  if (bin < 4) {
403  return centResErr25_[bin];
404  } else {
405  return 0.;
406  }
407  }
408  double getCentResErr30(unsigned int bin) const {
409  if (bin < 3) {
410  return centResErr30_[bin];
411  } else {
412  return 0.;
413  }
414  }
415  double getCentResErr40(unsigned int bin) const {
416  if (bin < 2) {
417  return centResErr40_[bin];
418  } else {
419  return 0.;
420  }
421  }
422 
423 private:
424  static constexpr int nvtxbins_ = 10;
425  static constexpr double minvtx_ = -25.;
426  static constexpr double delvtx_ = 5.;
427  static const int MAXCUT = 10000;
428  static const int MAXCUTOFF = 1000;
429 
430  double flatX_[MAXCUT];
431  double flatY_[MAXCUT];
432  double flatXDB_[MAXCUT];
433  double flatYDB_[MAXCUT];
434  double flatCnt_[MAXCUT];
435 
436  double xoff_[MAXCUTOFF];
437  double yoff_[MAXCUTOFF];
442 
443  double pt_[MAXCUTOFF];
444  double pt2_[MAXCUTOFF];
445  double ptDB_[MAXCUTOFF];
446  double pt2DB_[MAXCUTOFF];
447  double ptcnt_[MAXCUTOFF];
448 
449  double centRes1_[100];
450  double centResErr1_[100];
451 
452  double centRes2_[50];
453  double centResErr2_[50];
454 
455  double centRes5_[20];
456  double centResErr5_[20];
457 
458  double centRes10_[10];
459  double centResErr10_[10];
460 
461  double centRes20_[5];
462  double centResErr20_[5];
463 
464  double centRes25_[4];
465  double centResErr25_[4];
466 
467  double centRes30_[3];
468  double centResErr30_[3];
469 
470  double centRes40_[2];
471  double centResErr40_[2];
472 
473  int hOrder_; //flattening order
474  int hbins_; //number of bins needed for flattening
475  int obins_; //number of (x,y) offset bins
476  int vorder_; //order of flattened event plane
477  int caloCentRefMinBin_; //min ref centrality bin for calo weight scale
478  int caloCentRefMaxBin_; //max ref centrality bin for calo weight scale
479 };
480 
481 #endif
void init(int order, int nbins, std::string tag, int vord)
double getCentResErr25(unsigned int bin) const
double xoffDB_[MAXCUTOFF]
void fillOffset(double s, double c, uint m, double vtx, int centbin)
static const int MAXCUTOFF
double centResErr1_[100]
double getPt2DB(unsigned int bin) const
void setCentRes1(unsigned int bin, double res, double err)
double bounds(double ang) const
static const int MAXCUT
void setXoffDB(unsigned int indx, double val)
double getPtDB(unsigned int bin) const
double getXYoffmult(unsigned int bin) const
void setXDB(unsigned int indx, double val)
static double delvtx_
double getXYoffcnt(unsigned int bin) const
double getPtcnt(unsigned int bin) const
double getCentResErr5(unsigned int bin) const
double getY(unsigned int bin) const
double getSoffset(double s, double vtx, int centbin) const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
double getOffsetPsi(double s, double c) const
double ptcnt_[MAXCUTOFF]
double yoffDB_[MAXCUTOFF]
double getYoffDB(unsigned int bin) const
double getCentRes30(unsigned int bin) const
double pt_[MAXCUTOFF]
double xoff_[MAXCUTOFF]
void setCaloCentRefBins(const int caloCentRefMinBin, const int caloCentRefMaxBin)
void setYDB(unsigned int indx, double val)
double getCentRes1(unsigned int bin) const
void setCentRes30(unsigned int bin, double res, double err)
double getCentResErr40(unsigned int bin) const
double flatX_[MAXCUT]
double ptDB_[MAXCUTOFF]
double getCnt(unsigned int bin) const
std::map< std::string, int, std::less< std::string > > psi
double getCentResErr30(unsigned int bin) const
Definition: Electron.h:6
void setCentRes5(unsigned int bin, double res, double err)
double getCentRes40(unsigned int bin) const
double getEtScale(double vtx, int centbin) const
void setCentRes25(unsigned int bin, double res, double err)
void setYoffDB(unsigned int indx, double val)
double getCentResErr1(unsigned int bin) const
double getCentResErr20(unsigned int bin) const
double yoff_[MAXCUTOFF]
void setPt2DB(unsigned int indx, double val)
double getCentRes10(unsigned int bin) const
void setCentRes2(unsigned int bin, double res, double err)
int getOffsetIndx(int centbin, double vtx) const
double bounds2(double ang) const
void fill(double psi, double vtx, int centbin)
int getCutIndx(int centbin, double vtx, int iord) const
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
double getPt2(unsigned int bin) const
double getCoffset(double c, double vtx, int centbin) const
uint xyoffmult_[MAXCUTOFF]
double getVtxMin() const
double getXoff(unsigned int bin) const
double pt2DB_[MAXCUTOFF]
double getCentRes20(unsigned int bin) const
double getFlatPsi(double psi, double vtx, int centbin) const
double getYoff(unsigned int bin) const
#define M_PI
double getVtxMax() const
void setCentRes40(unsigned int bin, double res, double err)
double getW(double pt, double vtx, int centbin) const
double flatCnt_[MAXCUT]
double pt2_[MAXCUTOFF]
double getYDB(unsigned int bin) const
double getCentResErr2(unsigned int bin) const
double getCentRes5(unsigned int bin) const
double getCentRes25(unsigned int bin) const
double xyoffcnt_[MAXCUTOFF]
double getX(unsigned int bin) const
static double minvtx_
double getCentRes2(unsigned int bin) const
double flatYDB_[MAXCUT]
double getPt(unsigned int bin) const
double flatXDB_[MAXCUT]
void setCentRes20(unsigned int bin, double res, double err)
void setCentRes10(unsigned int bin, double res, double err)
void setPtDB(unsigned int indx, double val)
double getXoffDB(unsigned int bin) const
double getXDB(unsigned int bin) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
#define constexpr
void fillPt(double ptval, double vtx, int centbin)
double flatY_[MAXCUT]
double getCentResErr10(unsigned int bin) const