-
Notifications
You must be signed in to change notification settings - Fork 2
/
HZZ2L2QRooPdfs.cc
477 lines (371 loc) · 11.1 KB
/
HZZ2L2QRooPdfs.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
#include <iostream>
#include <math.h>
#include "TMath.h"
//#include "../interface/RooDoubleCB.h"
//#include "../interface/RooFermi.h"
//#include "../interface/RooRelBW.h"
#include "../interface/HZZ2L2QRooPdfs.h"
#include "RooRealVar.h"
#include "RooRealConstant.h"
using namespace RooFit;
using namespace std;
ClassImp(RooCB)
RooCB::RooCB(){}
RooCB::RooCB(const char *name, const char *title,
RooAbsReal& _x,
RooAbsReal& _mean,
RooAbsReal& _width,
RooAbsReal& _alpha,
RooAbsReal& _n,
RooAbsReal& _theta
) :
RooAbsPdf(name,title),
x("x","x",this,_x),
mean("mean","mean",this,_mean),
width("width","width",this,_width),
alpha("alpha","alpha",this,_alpha),
n("n","n",this,_n),
theta("theta","theta",this,_theta)
{
}
RooCB::RooCB(const RooCB& other, const char* name) :
RooAbsPdf(other,name),
x("x",this,other.x),
mean("mean",this,other.mean),
width("width",this,other.width),
alpha("alpha",this,other.alpha),
n("n",this,other.n),
theta("theta",this,other.theta)
{
}
double RooCB::evaluate() const
{
double a = cos(theta)*alpha - sin(theta)*width;
double w = sin(theta)*alpha + cos(theta)*width;
double t = (x-mean)/w;
if(a<0) t = -t;
double absa = fabs((double)a);
double A = TMath::Power(n/absa,n)*exp(-0.5*absa*absa);
double B = n/absa-absa;
if(t >= -absa){
return exp(-0.5*t*t);
}else{
return A/TMath::Power(B-t,n);
}
}
ClassImp(RooDoubleCB)
RooDoubleCB::RooDoubleCB(){}
RooDoubleCB::RooDoubleCB(const char *name, const char *title,
RooAbsReal& _x,
RooAbsReal& _mean,
RooAbsReal& _width,
RooAbsReal& _alpha1,
RooAbsReal& _n1,
RooAbsReal& _alpha2,
RooAbsReal& _n2
) :
RooAbsPdf(name,title),
x("x","x",this,_x),
mean("mean","mean",this,_mean),
width("width","width",this,_width),
alpha1("alpha1","alpha1",this,_alpha1),
n1("n1","n1",this,_n1),
alpha2("alpha2","alpha2",this,_alpha2),
n2("n2","n2",this,_n2)
{
}
RooDoubleCB::RooDoubleCB(const RooDoubleCB& other, const char* name) :
RooAbsPdf(other,name),
x("x",this,other.x),
mean("mean",this,other.mean),
width("width",this,other.width),
alpha1("alpha1",this,other.alpha1),
n1("n1",this,other.n1),
alpha2("alpha2",this,other.alpha2),
n2("n2",this,other.n2)
{
}
double RooDoubleCB::evaluate() const
{
double t = (x-mean)/width;
if(t>-alpha1 && t<alpha2){
return exp(-0.5*t*t);
}else if(t<-alpha1){
double A1 = pow(n1/fabs(alpha1),n1)*exp(-alpha1*alpha1/2);
double B1 = n1/fabs(alpha1)-fabs(alpha1);
return A1*pow(B1-t,-n1);
}else if(t>alpha2){
double A2 = pow(n2/fabs(alpha2),n2)*exp(-alpha2*alpha2/2);
double B2 = n2/fabs(alpha2)-fabs(alpha2);
return A2*pow(B2+t,-n2);
}else{
cout << "ERROR evaluating range..." << endl;
return 99;
}
}
Int_t RooDoubleCB::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* range) const
{
if (matchArgs(allVars,analVars,x)) return 1;
return 0;
}
Double_t RooDoubleCB::analyticalIntegral(Int_t code, const char* rangeName) const
{
assert(code==1) ;
double central=0;
double left=0;
double right=0;
static const Double_t root2 = sqrt(2) ;
static const Double_t rootPiBy2 = sqrt(atan2(0.0,-1.0)/2.0);
Double_t xscale = root2*width;
//compute gaussian contribution
double central_low =max(x.min(rangeName),mean - alpha1*width );
double central_high=min(x.max(rangeName),mean + alpha2*width );
if(central_low < central_high) // is the gaussian part in range?
central = rootPiBy2*width*(TMath::Erf((central_high-mean)/xscale)-TMath::Erf((central_low-mean)/xscale));
//compute left tail;
double A1 = pow(n1/fabs(alpha1),n1)*exp(-alpha1*alpha1/2);
double B1 = n1/fabs(alpha1)-fabs(alpha1);
double left_low=x.min(rangeName);
double left_high=min(x.max(rangeName),mean - alpha1*width);
if(left_low < left_high){ //is the left tail in range?
if(fabs(n1-1.0)>1.e-5)
left = A1/(-n1+1.0)*width*(pow(B1-(left_low-mean)/width,-n1+1.)-pow(B1-(left_high-mean)/width,-n1+1.));
else
left = A1*width*(log(B1-(left_low-mean)/width) - log(B1-(left_high-mean)/width) );
}
//compute right tail;
double A2 = pow(n2/fabs(alpha2),n2)*exp(-alpha2*alpha2/2);
double B2 = n2/fabs(alpha2)-fabs(alpha2);
double right_low=max(x.min(rangeName),mean + alpha2*width);
double right_high=x.max(rangeName);
if(right_low < right_high){ //is the right tail in range?
if(fabs(n2-1.0)>1.e-5)
right = A2/(-n2+1.0)*width*(pow(B2+(right_high-mean)/width,-n2+1.)-pow(B2+(right_low-mean)/width,-n2+1.));
else
right = A2*width*(log(B2+(right_high-mean)/width) - log(B2+(right_low-mean)/width) );
}
return left+central+right;
}
ClassImp(RooFermi)
RooFermi::RooFermi(){}
RooFermi::RooFermi(const char *name, const char *title,
RooAbsReal& _x,
RooAbsReal& _cutOff,
RooAbsReal& _beta
) :
RooAbsPdf(name,title),
x("x","x",this,_x),
cutOff("cutOff","cutOff",this,_cutOff),
beta("beta","beta",this,_beta)
{
}
RooFermi::RooFermi(const RooFermi& other, const char* name) :
RooAbsPdf(other,name),
x("x",this,other.x),
cutOff("cutOff",this,other.cutOff),
beta("beta",this,other.beta)
{
}
double RooFermi::evaluate() const
{
return 1.0/(exp((cutOff-x)/beta)+1);
}
ClassImp(RooRelBW)
RooRelBW::RooRelBW(){}
RooRelBW::RooRelBW(const char *name, const char *title,
RooAbsReal& _x,
RooAbsReal& _mean,
RooAbsReal& _width,
RooAbsReal& _n
) :
RooAbsPdf(name,title),
x("x","x",this,_x),
mean("mean","mean",this,_mean),
width("width","width",this,_width),
n("n","n",this,_n)
{
}
RooRelBW::RooRelBW(const RooRelBW& other, const char* name) :
RooAbsPdf(other,name),
x("x",this,other.x),
mean("mean",this,other.mean),
width("width",this,other.width),
n("n",this,other.n)
{
}
double RooRelBW::evaluate() const
{
return pow(x*x,n)/((x*x-mean*mean)*(x*x-mean*mean)+pow(x*x/(mean*mean),2*n)*mean*mean*width*width);
}
ClassImp(Triangle)
Triangle::Triangle(){}
Triangle::Triangle(const char *name, const char *title,
RooAbsReal& _m,
RooAbsReal& _start,
RooAbsReal& _turn,
RooAbsReal& _stop
):
RooAbsPdf(name, title),
m("m", "Dependent", this, _m),
start("start","start",this,_start),
turn("turn","turn",this,_turn),
stop("stop","stop",this,_stop)
{
}
Triangle::Triangle(const Triangle& other, const char* name) :
RooAbsPdf(other, name), m("m", this, other.m),start("start", this, other.start), turn("turn", this, other.turn), stop("stop", this, other.stop)
{
}
Double_t Triangle::evaluate() const
{
//std::cout << m << " "<<1.+(start-m)/turn << " " << 1+(turn-m)/stop << std::endl;
if(m<turn && m > turn+start)
return 1.+(turn-m)/start;
if(m>=turn && m < turn+stop)
return 1.+(turn-m)/stop;
return 0;
}
Int_t Triangle::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* range) const
{
if (matchArgs(allVars,analVars,m)) return 1;
return 0;
}
Double_t Triangle::analyticalIntegral(Int_t code, const char* rangeName) const
{
// WARNING, ASSSUMES TURN TO BE IN INTERVAL
assert(code==1) ;
//whole triangle
Double_t sumleft = sqrt(1+ (turn+start)*(turn+start) ) ;
Double_t sumright= sqrt(1+ (turn+stop)*(turn+stop) );
if(m.min() < turn+start)// correct for left missing bit
sumleft -= sumleft*(m.min()-(turn+start))/fabs(start);
if(m.max() > turn+stop)// correct for right missing bit
sumright -= sumright*(turn+stop -m.max())/fabs(stop);
return sumleft+sumright;
}
ClassImp(RooLevelledExp)
RooLevelledExp::RooLevelledExp(){}
RooLevelledExp::RooLevelledExp(const char *name, const char *title,
RooAbsReal& _x,
RooAbsReal& _sigma,
RooAbsReal& _alpha,
RooAbsReal& _m,
RooAbsReal& _theta):
RooAbsPdf(name,title),
x("x","x",this,_x),
sigma("sigma","sigma",this,_sigma),
alpha("alpha","alpha",this,_alpha),
m("m","m",this,_m),
// k("k","k",this,_k),
theta("theta","theta",this,_theta)
{
}
RooLevelledExp::RooLevelledExp(const RooLevelledExp& other, const char* name) :
RooAbsPdf(other,name),
x("x",this,other.x),
sigma("sigma",this,other.sigma),
alpha("alpha",this,other.alpha),
m("m",this,other.m),
theta("theta",this,other.theta)
{
}
double RooLevelledExp::evaluate() const
{
double res=0.0;
double s = cos(theta)*sigma - sin(theta)*alpha;
double a = sin(theta)*sigma + cos(theta)*alpha;
//original
double t = fabs(x-m);
double den = (s + a*t);
res=exp(-1.0*t/den);
return res;
}
///////////////////
ClassImp(RooLevelledExp2)
RooLevelledExp2::RooLevelledExp2(){}
RooLevelledExp2::RooLevelledExp2(const char *name, const char *title,
RooAbsReal& _x,
RooAbsReal& _sigma,
RooAbsReal& _alpha,
RooAbsReal& _beta,
RooAbsReal& _m,
RooAbsReal& _theta):
RooAbsPdf(name,title),
x("x","x",this,_x),
sigma("sigma","sigma",this,_sigma),
alpha("alpha","alpha",this,_alpha),
beta("beta","beta",this,_beta),
m("m","m",this,_m),
// k("k","k",this,_k),
theta("theta","theta",this,_theta)
{
}
RooLevelledExp2::RooLevelledExp2(const RooLevelledExp2& other, const char* name) :
RooAbsPdf(other,name),
x("x",this,other.x),
sigma("sigma",this,other.sigma),
alpha("alpha",this,other.alpha),
beta("beta",this,other.beta),
m("m",this,other.m),
theta("theta",this,other.theta)
{
}
double RooLevelledExp2::evaluate() const
{
double res=0.0;
double s = cos(theta)*sigma - sin(theta)*alpha;
double a = sin(theta)*sigma + cos(theta)*alpha;
//original
double t = fabs(x-m);
double den = (s + a*t + beta*t*t);
res=exp(-1.0*t/den);
return res;
}
///////////////////
ClassImp(RooLevExpFlatTail)
RooLevExpFlatTail::RooLevExpFlatTail(){}
RooLevExpFlatTail::RooLevExpFlatTail(const char *name, const char *title,
RooAbsReal& _x,
RooAbsReal& _sigma,
RooAbsReal& _alpha,
RooAbsReal& _beta,
RooAbsReal& _m,
RooAbsReal& _theta,
RooAbsReal& _tail):
RooAbsPdf(name,title),
x("x","x",this,_x),
sigma("sigma","sigma",this,_sigma),
alpha("alpha","alpha",this,_alpha),
beta("beta","beta",this,_beta),
m("m","m",this,_m),
// k("k","k",this,_k),
theta("theta","theta",this,_theta),
tail("tail","tail",this,_tail)
{
}
RooLevExpFlatTail::RooLevExpFlatTail(const RooLevExpFlatTail& other, const char* name) :
RooAbsPdf(other,name),
x("x",this,other.x),
sigma("sigma",this,other.sigma),
alpha("alpha",this,other.alpha),
beta("beta",this,other.beta),
m("m",this,other.m),
theta("theta",this,other.theta),
tail("tail",this,other.tail)
{
}
double RooLevExpFlatTail::evaluate() const
{
double res=0.0;
double s = cos(theta)*sigma - sin(theta)*alpha;
double a = sin(theta)*sigma + cos(theta)*alpha;
double t = fabs(x-m);
//to be tested:
if(x>2200)t=fabs(2200-m);
double den = (s + a*t + beta*t*t);
res=exp(-1.0*t/den);
//original
//if(x<2200)res=exp(-1.0*t/den);
// else res=tail;
return res;
}