Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RooArgusBG.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitModels *
4  * @(#)root/roofit:$Id$
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 
17 /** \class RooArgusBG
18  \ingroup Roofit
19 
20 RooArgusBG is a RooAbsPdf implementation describing the ARGUS background shape.
21 \f[
22  \mathrm{Argus}(m, m_0, c, p) = \mathcal{N} \cdot m \cdot \left[ 1 - \left( \frac{m}{m_0} \right)^2 \right]^p
23  \cdot \exp\left[ c \cdot \left(1 - \left(\frac{m}{m_0}\right)^2 \right) \right]
24 \f]
25 \image html RooArgusBG.png
26 */
27 
28 #include "RooArgusBG.h"
29 #include "RooRealVar.h"
30 #include "RooRealConstant.h"
31 #include "RooMath.h"
32 #include "BatchHelpers.h"
33 #include "RooVDTHeaders.h"
34 
35 #include "TMath.h"
36 
37 #include <cmath>
38 using namespace std;
39 
40 ClassImp(RooArgusBG);
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// Constructor.
44 
45 RooArgusBG::RooArgusBG(const char *name, const char *title,
46  RooAbsReal& _m, RooAbsReal& _m0, RooAbsReal& _c) :
47  RooAbsPdf(name, title),
48  m("m","Mass",this,_m),
49  m0("m0","Resonance mass",this,_m0),
50  c("c","Slope parameter",this,_c),
51  p("p","Power",this,(RooRealVar&)RooRealConstant::value(0.5))
52 {
53 }
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// Constructor.
57 
58 RooArgusBG::RooArgusBG(const char *name, const char *title,
59  RooAbsReal& _m, RooAbsReal& _m0, RooAbsReal& _c, RooAbsReal& _p) :
60  RooAbsPdf(name, title),
61  m("m","Mass",this,_m),
62  m0("m0","Resonance mass",this,_m0),
63  c("c","Slope parameter",this,_c),
64  p("p","Power",this,_p)
65 {
66 }
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// Constructor.
70 
71 RooArgusBG::RooArgusBG(const RooArgusBG& other, const char* name) :
72  RooAbsPdf(other,name),
73  m("m",this,other.m),
74  m0("m0",this,other.m0),
75  c("c",this,other.c),
76  p("p",this,other.p)
77 {
78 }
79 
80 ////////////////////////////////////////////////////////////////////////////////
81 
82 Double_t RooArgusBG::evaluate() const {
83  Double_t t= m/m0;
84  if(t >= 1) return 0;
85 
86  Double_t u= 1 - t*t;
87  //cout << "c = " << c << " result = " << m*TMath::Power(u,p)*exp(c*u) << endl ;
88  return m*TMath::Power(u,p)*exp(c*u) ;
89 }
90 
91 ////////////////////////////////////////////////////////////////////////////////
92 
93 namespace {
94 //Author: Emmanouil Michalainas, CERN 19 AUGUST 2019
95 
96 template<class Tm, class Tm0, class Tc, class Tp>
97 void compute( size_t batchSize,
98  double * __restrict output,
99  Tm M, Tm0 M0, Tc C, Tp P)
100 {
101  for (size_t i=0; i<batchSize; i++) {
102  const double t = M[i]/M0[i];
103  const double u = 1 - t*t;
104  output[i] = C[i]*u + P[i]*_rf_fast_log(u);
105  }
106  for (size_t i=0; i<batchSize; i++) {
107  if (M[i] >= M0[i]) output[i] = 0.0;
108  else output[i] = M[i]*_rf_fast_exp(output[i]);
109  }
110 }
111 };
112 
113 RooSpan<double> RooArgusBG::evaluateBatch(std::size_t begin, std::size_t batchSize) const {
114  using namespace BatchHelpers;
115 
116  EvaluateInfo info = getInfo( {&m, &m0, &c, &p}, begin, batchSize );
117  if (info.nBatches == 0) {
118  return {};
119  }
120  auto output = _batchData.makeWritableBatchUnInit(begin, batchSize);
121  auto mData = m.getValBatch(begin, info.size);
122 
123  if (info.nBatches==1 && !mData.empty()) {
124  compute(info.size, output.data(), mData.data(),
125  BracketAdapter<double> (m0),
126  BracketAdapter<double> (c),
127  BracketAdapter<double> (p));
128  }
129  else {
130  compute(info.size, output.data(),
131  BracketAdapterWithMask (m,m.getValBatch(begin,info.size)),
132  BracketAdapterWithMask (m0,m0.getValBatch(begin,info.size)),
133  BracketAdapterWithMask (c,c.getValBatch(begin,info.size)),
134  BracketAdapterWithMask (p,p.getValBatch(begin,info.size)));
135  }
136  return output;
137 }
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 
141 Int_t RooArgusBG::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const
142 {
143  if (p.arg().isConstant()) {
144  // We can integrate over m if power = 0.5
145  if (matchArgs(allVars,analVars,m) && p == 0.5) return 1;
146  }
147  return 0;
148 
149 }
150 
151 ////////////////////////////////////////////////////////////////////////////////
152 
153 Double_t RooArgusBG::analyticalIntegral(Int_t code, const char* rangeName) const
154 {
155  R__ASSERT(code==1);
156  // Formula for integration over m when p=0.5
157  static const Double_t pi = atan2(0.0,-1.0);
158  Double_t min = (m.min(rangeName) < m0) ? m.min(rangeName) : m0;
159  Double_t max = (m.max(rangeName) < m0) ? m.max(rangeName) : m0;
160  Double_t f1 = (1.-TMath::Power(min/m0,2));
161  Double_t f2 = (1.-TMath::Power(max/m0,2));
162  Double_t aLow, aHigh ;
163  if ( c < 0. ) {
164  aLow = -0.5*m0*m0*(exp(c*f1)*sqrt(f1)/c + 0.5/TMath::Power(-c,1.5)*sqrt(pi)*RooMath::erf(sqrt(-c*f1)));
165  aHigh = -0.5*m0*m0*(exp(c*f2)*sqrt(f2)/c + 0.5/TMath::Power(-c,1.5)*sqrt(pi)*RooMath::erf(sqrt(-c*f2)));
166  } else if ( c == 0. ) {
167  aLow = -m0*m0/3.*f1*sqrt(f1);
168  aHigh = -m0*m0/3.*f1*sqrt(f2);
169  } else {
170  aLow = 0.5*m0*m0*exp(c*f1)/(c*sqrt(c)) * (0.5*sqrt(pi)*(RooMath::faddeeva(sqrt(c*f1))).imag() - sqrt(c*f1));
171  aHigh = 0.5*m0*m0*exp(c*f2)/(c*sqrt(c)) * (0.5*sqrt(pi)*(RooMath::faddeeva(sqrt(c*f2))).imag() - sqrt(c*f2));
172  }
173  Double_t area = aHigh - aLow;
174  //cout << "c = " << c << "aHigh = " << aHigh << " aLow = " << aLow << " area = " << area << endl ;
175  return area;
176 
177 }