CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
PuncturedSmearedExp.cc
Go to the documentation of this file.
1// -*- C++ -*-
2// $Id: PuncturedSmearedExp.cc,v 1.4 2010/06/16 18:22:01 garren Exp $
3#include "CLHEP/GenericFunctions/PuncturedSmearedExp.hh"
4#include <sstream>
5#include <cmath>
6#include <vector>
7
8namespace Genfun {
9FUNCTION_OBJECT_IMP(PuncturedSmearedExp)
10
12 _lifetime ("Lifetime", 1.0, 0.0), // Bounded from below by zero, by default
13 _sigma ("Sigma", 1.0, 0.0) // Bounded from below by zero, by default
14{
15}
16
18 AbsFunction(right),
19 _lifetime (right._lifetime),
20 _sigma (right._sigma),
21 _punctures (right._punctures)
22{
23}
24
25void PuncturedSmearedExp::puncture(double xmin, double xmax) {
26 std::ostringstream mn, mx;
27 mn << "Min_" << _punctures.size()/2;
28 mx << "Max_" << _punctures.size()/2;
29 _punctures.push_back(Parameter(mn.str(), xmin, 0.0, 10.0));
30 _punctures.push_back(Parameter(mx.str(), xmax, 0.0, 10.0));
31}
32
33
35 return _punctures[2*i];
36}
37
38const Parameter & PuncturedSmearedExp::min(unsigned int i) const {
39 return _punctures[2*i];
40}
41
42
44 return _punctures[2*i+1];
45
46}
47
48const Parameter & PuncturedSmearedExp::max(unsigned int i) const {
49 return _punctures[2*i+1];
50}
51
52
54}
55
57 return _lifetime;
58}
59
61 return _lifetime;
62}
63
65 return _sigma;
66}
67
69 return _sigma;
70}
71
72
73double PuncturedSmearedExp::operator() (double argument) const {
74 // Fetch the paramters. This operator does not convolve numerically.
75 static const double sqrtTwo = sqrt(2.0);
76
77 double xsigma = _sigma.getValue();
78 double tau = _lifetime.getValue();
79 double x = argument;
80
81 // Copy:
82 std::vector<double> punctures(_punctures.size());
83 for (size_t i=0;i<_punctures.size();i++) punctures[i]=_punctures[i].getValue();
84
85 // Overlap elimination:
86 bool overlap=true;
87
88 while (overlap) {
89
90 overlap=false;
91
92 for (size_t i=0;i<punctures.size()/2;i++) {
93 std::sort(punctures.begin()+2*i, punctures.begin()+2*i+2);
94 double min1=punctures[2*i];
95 double max1=punctures[2*i+1];
96 for (size_t j=i+1;j<punctures.size()/2;j++) {
97 std::sort(punctures.begin()+2*j, punctures.begin()+2*j+2);
98 double min2=punctures[2*j];
99 double max2=punctures[2*j+1];
100 if ((min2>min1 && max1>min2) || (min1>min2 && max2<min1)) {
101 punctures[2*i] =std::min(min1,min2);
102 punctures[2*i+1]=std::max(max1,max2);
103 std::vector<double>::iterator t0=punctures.begin()+2*j, t1=t0+2;
104 punctures.erase(t0,t1);
105 overlap=true;
106 break;
107 }
108 }
109 if (overlap) break;
110 }
111 }
112
113 double expG=0,norm=0;
114 for (size_t i=0;i<punctures.size()/2;i++) {
115
116 double a = punctures[2*i];
117 double b = punctures[2*i+1];
118
119 double alpha = (a/xsigma + xsigma/tau)/sqrtTwo;
120 double beta = (b/xsigma + xsigma/tau)/sqrtTwo;
121 double delta = 1/sqrtTwo/xsigma;
122
123
124 norm += 2*tau*exp(1/(4*delta*delta*tau*tau))*(exp(-alpha/(delta*tau)) - exp(-beta/(delta*tau)));
125
126 expG += ((erfc(alpha-delta*x) - erfc(beta-delta*x))*exp(-x/tau) );
127
128
129 }
130
131 // protection:
132 if (norm==0) return norm;
133
134 return expG/norm;
135}
136
137double PuncturedSmearedExp::erfc(double x) const {
138 // This is accurate to 7 places.
139 // See Numerical Recipes P 221
140 double t, z, ans;
141 z = (x < 0) ? -x : x;
142 t = 1.0/(1.0+.5*z);
143 ans = t*exp(-z*z-1.26551223+t*(1.00002368+t*(0.37409196+t*(0.09678418+
144 t*(-0.18628806+t*(0.27886807+t*(-1.13520398+t*(1.48851587+
145 t*(-0.82215223+t*0.17087277 ))) ))) )));
146 if ( x < 0 ) ans = 2.0 - ans;
147 return ans;
148}
149
150double PuncturedSmearedExp::pow(double x,int n) const {
151 double val=1;
152 for(int i=0;i<n;i++){
153 val=val*x;
154 }
155 return val;
156}
157
158} // namespace Genfun
159
160
#define FUNCTION_OBJECT_IMP(classname)
Definition: AbsFunction.hh:149
virtual double getValue() const
Definition: Parameter.cc:29
void puncture(double min, double max)
Parameter & min(unsigned int i)
Parameter & max(unsigned int i)
virtual double operator()(double argument) const override
Definition: Abs.hh:14