44 RooDstD0BG::RooDstD0BG(
const char *name,
const char *title,
45 RooAbsReal& _dm, RooAbsReal& _dm0,
46 RooAbsReal& _c, RooAbsReal& _a, RooAbsReal& _b) :
47 RooAbsPdf(name,title),
48 dm(
"dm",
"Dstar-D0 Mass Diff",this, _dm),
49 dm0(
"dm0",
"Threshold",this, _dm0),
50 C(
"C",
"Shape Parameter",this, _c),
51 A(
"A",
"Shape Parameter 2",this, _a),
52 B(
"B",
"Shape Parameter 3",this, _b)
58 RooDstD0BG::RooDstD0BG(
const RooDstD0BG& other,
const char *name) :
59 RooAbsPdf(other,name), dm(
"dm",this,other.dm), dm0(
"dm0",this,other.dm0),
60 C(
"C",this,other.C), A(
"A",this,other.A), B(
"B",this,other.B)
66 Double_t RooDstD0BG::evaluate()
const
68 Double_t arg= dm- dm0;
69 if (arg <= 0 )
return 0;
70 Double_t ratio= dm/dm0;
71 Double_t val= (1- exp(-arg/C))* TMath::Power(ratio, A) + B*(ratio-1);
73 return (val > 0 ? val : 0) ;
79 template<
class Tdm,
class Tdm0,
class TC,
class TA,
class TB>
80 void compute(
size_t batchSize,
double * __restrict output,
81 Tdm DM, Tdm0 DM0, TC C, TA A, TB B)
83 for (
size_t i=0; i<batchSize; i++) {
84 const double ratio = DM[i] / DM0[i];
85 const double arg1 = (DM0[i]-DM[i]) / C[i];
86 const double arg2 = A[i]*_rf_fast_log(ratio);
87 output[i] = (1 -_rf_fast_exp(arg1)) * _rf_fast_exp(arg2) +B[i]*(ratio-1);
90 for (
size_t i=0; i<batchSize; i++) {
91 if (output[i]<0) output[i] = 0;
96 RooSpan<double> RooDstD0BG::evaluateBatch(std::size_t begin, std::size_t batchSize)
const {
97 using namespace BatchHelpers;
99 EvaluateInfo info = getInfo( {&dm, &dm0, &C, &A, &B}, begin, batchSize );
100 if (info.nBatches == 0) {
103 auto output = _batchData.makeWritableBatchUnInit(begin, batchSize);
104 auto dmData = dm.getValBatch(begin, info.size);
106 if (info.nBatches==1 && !dmData.empty()) {
107 compute(info.size, output.data(), dmData.data(),
108 BracketAdapter<double> (dm0),
109 BracketAdapter<double> (C),
110 BracketAdapter<double> (A),
111 BracketAdapter<double> (B));
114 compute(info.size, output.data(),
115 BracketAdapterWithMask (dm,dm.getValBatch(begin,info.size)),
116 BracketAdapterWithMask (dm0,dm0.getValBatch(begin,info.size)),
117 BracketAdapterWithMask (C,C.getValBatch(begin,info.size)),
118 BracketAdapterWithMask (A,A.getValBatch(begin,info.size)),
119 BracketAdapterWithMask (B,B.getValBatch(begin,info.size)));
127 Int_t RooDstD0BG::getAnalyticalIntegral(RooArgSet& , RooArgSet& ,
const char* )
const
134 Double_t RooDstD0BG::analyticalIntegral(Int_t code,
const char* rangeName)
const
139 Double_t min= dm.min(rangeName);
140 Double_t max= dm.max(rangeName);
141 if (max <= dm0 )
return 0;
142 else if (min < dm0) min = dm0;
144 Bool_t doNumerical= kFALSE;
145 if ( A != 0 ) doNumerical= kTRUE;
152 if ( 1- exp(-(max-dm0)/C) + B*(max/dm0 -1) < 0) doNumerical= kTRUE;
154 if ( ! doNumerical ) {
155 return (max-min)+ C* exp(dm0/C)* (exp(-max/C)- exp(-min/C)) +
156 B * (0.5* (max*max - min*min)/dm0 - (max- min));
163 RooArgSet vset(dm.arg(),
"vset");
164 RooAbsFunc *func= bindVars(vset);
165 RooIntegrator1D integrator(*func,min,max);
166 return integrator.integral();