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