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