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 
30  explicit HiEvtPlaneFlatten()
31  {
32  hbins_ = 1;
33  hOrder_ = 9;
34  vorder_ = 2; //sets default order of event plane
35  }
36 
37 
38  void init(int order, int nbins, std::string tag, int vord)
39  {
40  hOrder_ = order; //order of flattening
41  vorder_ = vord; //1(v1), 2(v2), 3(v3), 4(v4)
42  caloCentRefMinBin_ = -1;
43  caloCentRefMaxBin_ = -1;
44  hbins_ = nbins*nvtxbins_*hOrder_;
45  obins_ = nbins*nvtxbins_;
46  if(hbins_>MAXCUT) {
47  hbins_ = 1;
48  hOrder_ = 9;
49  }
50  for(int i = 0; i<hbins_; i++) {
51  flatX_[i]=0;
52  flatY_[i]=0;
53  flatXDB_[i]=0;
54  flatYDB_[i]=0;
55  flatCnt_[i]=0;
56  }
57  for(int i = 0; i<obins_; i++) {
58  xoff_[i]=0;
59  yoff_[i]=0;
60  xoffDB_[i]=0;
61  yoffDB_[i]=0;
62  xyoffcnt_[i]=0;
63  xyoffmult_[i]=0;
64  pt_[i]=0;
65  pt2_[i]=0;
66  ptDB_[i]=0;
67  pt2DB_[i]=0;
68  ptcnt_[i]=0;
69  }
70  }
71 
72  int getCutIndx(int centbin, double vtx, int iord) const
73  {
74  int cut;
75  if(centbin < 0 ) return -1;
76  int ibin = centbin;
77  int ivtx = (vtx-minvtx_)/delvtx_;
78  if(vtx < minvtx_ || ivtx >= nvtxbins_) return -1;
79  cut = hOrder_*nvtxbins_*ibin + hOrder_*ivtx + iord;
80  if(cut<0 || cut>=hbins_) return -1;
81  return cut;
82  }
83 
84  int getOffsetIndx(int centbin, double vtx) const
85  {
86  int cut;
87  if(centbin < 0 ) return -1;
88  int ibin = centbin;
89  int ivtx = (vtx-minvtx_)/delvtx_;
90  if(ivtx < 0 || ivtx > nvtxbins_) return -1;
91  cut = nvtxbins_*ibin + ivtx ;
92  if(cut<0 || cut>hbins_) return -1;
93  return cut;
94  }
95 
96  void fill(double psi, double vtx, int centbin)
97  {
98  if(fabs(psi)>4 ) 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  {
112  int indx = getOffsetIndx(centbin,vtx);
113  if(indx>=0) {
114  xoff_[indx]+=c;
115  yoff_[indx]+=s;
116  xyoffmult_[indx]+=m;
117  ++xyoffcnt_[indx];
118  }
119  }
120  void fillPt(double ptval, double vtx, int centbin)
121  {
122  int indx = getOffsetIndx(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 getEtScale(double vtx, int centbin) const {
136  int refmin = getOffsetIndx(caloCentRefMinBin_,vtx);
137  int refmax = getOffsetIndx(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) return 1.;
144  int indx = getOffsetIndx(centbin,vtx);
145  if(indx < 0 || caloCentRefVal_ == 0 || getPtDB(indx)==0) return 1.;
146  return caloCentRefVal_/getPtDB(indx);
147  }
148 
149  double getW(double pt, double vtx, int centbin) const
150  {
151  int indx = getOffsetIndx(centbin,vtx);
152  if(indx>=0) {
153  double scale = getEtScale(vtx,centbin);
154  double ptval = getPtDB(indx)*scale;
155  double pt2val = getPt2DB(indx)*pow(scale,2);
156  if(ptval>0) return pt*scale-pt2val/ptval;
157  }
158  return 0.;
159  }
160 
161  double getFlatPsi(double psi, double vtx, int centbin) const
162  {
163  double correction = 0;
164  for(int k = 0; k<hOrder_; k++) {
165  int indx = getCutIndx(centbin,vtx,k);
166  if(indx>=0) correction+=(2./(double)((k+1)*vorder_))*(flatXDB_[indx]*sin(vorder_*(k+1)*psi)-flatYDB_[indx]*cos(vorder_*(k+1)*psi));
167  }
168  psi+=correction;
169  psi=bounds(psi);
170  psi=bounds2(psi);
171  return psi;
172  }
173 
174  double getSoffset(double s, double vtx, int centbin) const
175  {
176  int indx = getOffsetIndx(centbin,vtx);
177  if ( indx >= 0 ) return s-yoffDB_[indx];
178  else return s;
179  }
180 
181  double getCoffset(double c, double vtx, int centbin) const
182  {
183  int indx = getOffsetIndx(centbin,vtx);
184  if ( indx >= 0 ) return c-xoffDB_[indx];
185  else return c;
186  }
187 
188  double getOffsetPsi(double s, double c) const
189  {
190  double psi = atan2(s, c)/vorder_;
191  if((fabs(s)<1e-4) && (fabs(c)<1e-4)) psi = 0.;
192  psi=bounds(psi);
193  psi=bounds2(psi);
194  return psi;
195  }
196 
198  int getHBins() const {return hbins_;}
199  int getOBins() const {return obins_;}
200  int getNvtx() const {return nvtxbins_;}
201  double getVtxMin() const {return minvtx_;}
202  double getVtxMax() const {return minvtx_+nvtxbins_*delvtx_;}
203  int getNcent() const {return hbins_;}
204 
205  double getX(unsigned int bin) const {return flatX_[bin];}
206  double getY(unsigned int bin) const {return flatY_[bin];}
207  double getXoff(unsigned int bin) const {return xoff_[bin];}
208  double getYoff(unsigned int bin) const {return yoff_[bin];}
209  double getXoffDB(unsigned int bin) const {return xoffDB_[bin];}
210  double getYoffDB(unsigned int bin) const {return yoffDB_[bin];}
211  double getXYoffcnt(unsigned int bin) const {return xyoffcnt_[bin];}
212  double getXYoffmult(unsigned int bin) const {return xyoffmult_[bin];}
213  double getPt(unsigned int bin) const {return pt_[bin];}
214  double getPt2(unsigned int bin) const {return pt2_[bin];}
215  double getPtDB(unsigned int bin) const {if(bin<MAXCUTOFF) {return ptDB_[bin];} else {return 0.;}}
216  double getPt2DB(unsigned int bin) const {if(bin<MAXCUTOFF) {return pt2DB_[bin];} else {return 0.;}}
217  double getPtcnt(unsigned int bin) const {return ptcnt_[bin];}
218  double getXDB(unsigned int bin) const {return flatXDB_[bin];}
219  double getYDB(unsigned int bin) const {return flatYDB_[bin];}
220 
221 
222  double getCnt(unsigned int bin) const {return flatCnt_[bin];}
223  void setXDB(unsigned int indx, double val) {flatXDB_[indx]=val;}
224  void setYDB(unsigned int indx, double val) {flatYDB_[indx]=val;}
225  void setXoffDB(unsigned int indx, double val) {xoffDB_[indx]=val;}
226  void setYoffDB(unsigned int indx, double val) {yoffDB_[indx]=val;}
227  void setPtDB(unsigned int indx, double val) {ptDB_[indx]=val;}
228  void setPt2DB(unsigned int indx, double val) {pt2DB_[indx]=val;}
229  double bounds(double ang) const {
230  if(ang<-M_PI) ang+=2.*M_PI;
231  if(ang>M_PI) ang-=2.*M_PI;
232  return ang;
233  }
234  double bounds2(double ang) const {
235  double range = M_PI/(double) vorder_;
236  while(ang<-range) { ang+=2*range; }
237  while(ang>range) {ang-=2*range; }
238  return ang;
239  }
240  void setCentRes1(unsigned int bin, double res, double err){ if(bin<100) {centRes1_[bin]=res; centResErr1_[bin]=err;}}
241  void setCentRes2(unsigned int bin, double res, double err){ if(bin<50) {centRes2_[bin]=res; centResErr2_[bin]=err;}}
242  void setCentRes5(unsigned int bin, double res, double err){ if(bin<20) {centRes5_[bin]=res; centResErr5_[bin]=err;}}
243  void setCentRes10(unsigned int bin, double res, double err){ if(bin<10) {centRes10_[bin]=res; centResErr10_[bin]=err;}}
244  void setCentRes20(unsigned int bin, double res, double err){ if(bin<5) {centRes20_[bin]=res; centResErr20_[bin]=err;}}
245  void setCentRes25(unsigned int bin, double res, double err){ if(bin<4) {centRes25_[bin]=res; centResErr25_[bin]=err;}}
246  void setCentRes30(unsigned int bin, double res, double err){ if(bin<3) {centRes30_[bin]=res; centResErr30_[bin]=err;}}
247  void setCentRes40(unsigned int bin, double res, double err){ if(bin<2) {centRes40_[bin]=res; centResErr40_[bin]=err;}}
248 
249  double getCentRes1(unsigned int bin) const { if(bin<100) {return centRes1_[bin];} else {return 0.;}}
250  double getCentRes2(unsigned int bin) const { if(bin<50) {return centRes2_[bin];} else {return 0.;}}
251  double getCentRes5(unsigned int bin) const { if(bin<20 ) {return centRes5_[bin];} else {return 0.;}}
252  double getCentRes10(unsigned int bin) const { if(bin<10) {return centRes10_[bin];} else {return 0.;}}
253  double getCentRes20(unsigned int bin) const { if(bin<5) {return centRes20_[bin];} else {return 0.;}}
254  double getCentRes25(unsigned int bin) const { if(bin<4) {return centRes25_[bin];} else {return 0.;}}
255  double getCentRes30(unsigned int bin) const { if(bin<3) {return centRes30_[bin];} else {return 0.;}}
256  double getCentRes40(unsigned int bin) const { if(bin<2 ) {return centRes40_[bin];} else {return 0.;}}
257 
258  double getCentResErr1(unsigned int bin) const { if(bin<100) {return centResErr1_[bin];} else {return 0.;}}
259  double getCentResErr2(unsigned int bin) const { if(bin<50) {return centResErr2_[bin];} else {return 0.;}}
260  double getCentResErr5(unsigned int bin) const { if(bin<20) {return centResErr5_[bin];} else {return 0.;}}
261  double getCentResErr10(unsigned int bin) const { if(bin<10) {return centResErr10_[bin];} else {return 0.;}}
262  double getCentResErr20(unsigned int bin) const { if(bin<5) {return centResErr20_[bin];} else {return 0.;}}
263  double getCentResErr25(unsigned int bin) const { if(bin<4) {return centResErr25_[bin];} else {return 0.;}}
264  double getCentResErr30(unsigned int bin) const { if(bin<3) {return centResErr30_[bin];} else {return 0.;}}
265  double getCentResErr40(unsigned int bin) const { if(bin<2) {return centResErr40_[bin];} else {return 0.;}}
266 
267 private:
268  static constexpr int nvtxbins_ = 10;
269  static constexpr double minvtx_ = -25.;
270  static constexpr double delvtx_ = 5.;
271  static const int MAXCUT = 10000;
272  static const int MAXCUTOFF = 1000;
273 
274  double flatX_[MAXCUT];
275  double flatY_[MAXCUT];
276  double flatXDB_[MAXCUT];
277  double flatYDB_[MAXCUT];
278  double flatCnt_[MAXCUT];
279 
280 
281 
282  double xoff_[MAXCUTOFF];
283  double yoff_[MAXCUTOFF];
288 
289  double pt_[MAXCUTOFF];
290  double pt2_[MAXCUTOFF];
291  double ptDB_[MAXCUTOFF];
292  double pt2DB_[MAXCUTOFF];
293  double ptcnt_[MAXCUTOFF];
294 
295  double centRes1_[100];
296  double centResErr1_[100];
297 
298  double centRes2_[50];
299  double centResErr2_[50];
300 
301  double centRes5_[20];
302  double centResErr5_[20];
303 
304  double centRes10_[10];
305  double centResErr10_[10];
306 
307  double centRes20_[5];
308  double centResErr20_[5];
309 
310  double centRes25_[4];
311  double centResErr25_[4];
312 
313  double centRes30_[3];
314  double centResErr30_[3];
315 
316  double centRes40_[2];
317  double centResErr40_[2];
318 
319 
320  int hOrder_; //flattening order
321  int hbins_; //number of bins needed for flattening
322  int obins_; //number of (x,y) offset bins
323  int vorder_; //order of flattened event plane
324  int caloCentRefMinBin_; //min ref centrality bin for calo weight scale
325  int caloCentRefMaxBin_; //max ref centrality bin for calo weight scale
326 
327 };
328 
329 #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
int k[5][pyjets_maxn]
bin
set the eta bin as selection string.
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
def uint(string)
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:40
#define constexpr
void fillPt(double ptval, double vtx, int centbin)
double flatY_[MAXCUT]
double getCentResErr10(unsigned int bin) const