Logo ROOT  
Reference Guide
RooBreitWigner.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitModels *
4 * @(#)root/roofit:$Id$
5 * Authors: *
6 * AS, Abi Soffer, Colorado State University, abi@slac.stanford.edu *
7 * TS, Thomas Schietinger, SLAC, schieti@slac.stanford.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * Colorado State University *
11 * and Stanford University. All rights reserved. *
12 * *
13 * Redistribution and use in source and binary forms, *
14 * with or without modification, are permitted according to the terms *
15 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
16 *****************************************************************************/
17
18/** \class RooBreitWigner
19 \ingroup Roofit
20
21Class RooBreitWigner is a RooAbsPdf implementation
22that models a non-relativistic Breit-Wigner shape
23**/
24
25#include "RooFit.h"
26
27#include "Riostream.h"
28#include <math.h>
29
30#include "RooBreitWigner.h"
31#include "RooAbsReal.h"
32#include "RooRealVar.h"
33#include "BatchHelpers.h"
34// #include "RooFitTools/RooRandom.h"
35
36using namespace std;
37
39
40////////////////////////////////////////////////////////////////////////////////
41
42RooBreitWigner::RooBreitWigner(const char *name, const char *title,
43 RooAbsReal& _x, RooAbsReal& _mean,
44 RooAbsReal& _width) :
45 RooAbsPdf(name,title),
46 x("x","Dependent",this,_x),
47 mean("mean","Mean",this,_mean),
48 width("width","Width",this,_width)
49{
50}
51
52////////////////////////////////////////////////////////////////////////////////
53
55 RooAbsPdf(other,name), x("x",this,other.x), mean("mean",this,other.mean),
56 width("width",this,other.width)
57{
58}
59
60////////////////////////////////////////////////////////////////////////////////
61
63{
64 Double_t arg= x - mean;
65 return 1. / (arg*arg + 0.25*width*width);
66}
67
68////////////////////////////////////////////////////////////////////////////////
69
70namespace {
71//Author: Emmanouil Michalainas, CERN 21 August 2019
72
73template<class Tx, class Tmean, class Twidth>
74void compute( size_t batchSize,
75 double * __restrict output,
76 Tx X, Tmean M, Twidth W)
77{
78 for (size_t i=0; i<batchSize; i++) {
79 const double arg = X[i]-M[i];
80 output[i] = 1 / (arg*arg + 0.25*W[i]*W[i]);
81 }
82}
83};
84
85RooSpan<double> RooBreitWigner::evaluateBatch(std::size_t begin, std::size_t batchSize) const {
86 using namespace BatchHelpers;
87 auto xData = x.getValBatch(begin, batchSize);
88 auto meanData = mean.getValBatch(begin, batchSize);
89 auto widthData = width.getValBatch(begin, batchSize);
90 const bool batchX = !xData.empty();
91 const bool batchMean = !meanData.empty();
92 const bool batchWidth = !widthData.empty();
93
94 if (!batchX && !batchMean && !batchWidth) {
95 return {};
96 }
97 batchSize = findSize({ xData, meanData, widthData });
98 auto output = _batchData.makeWritableBatchUnInit(begin, batchSize);
99
100 if (batchX && !batchMean && !batchWidth ) {
101 compute(batchSize, output.data(), xData, BracketAdapter<double>(mean), BracketAdapter<double>(width));
102 }
103 else if (!batchX && batchMean && !batchWidth ) {
104 compute(batchSize, output.data(), BracketAdapter<double>(x), meanData, BracketAdapter<double>(width));
105 }
106 else if (batchX && batchMean && !batchWidth ) {
107 compute(batchSize, output.data(), xData, meanData, BracketAdapter<double>(width));
108 }
109 else if (!batchX && !batchMean && batchWidth ) {
110 compute(batchSize, output.data(), BracketAdapter<double>(x), BracketAdapter<double>(mean), widthData);
111 }
112 else if (batchX && !batchMean && batchWidth ) {
113 compute(batchSize, output.data(), xData, BracketAdapter<double>(mean), widthData);
114 }
115 else if (!batchX && batchMean && batchWidth ) {
116 compute(batchSize, output.data(), BracketAdapter<double>(x), meanData, widthData);
117 }
118 else if (batchX && batchMean && batchWidth ) {
119 compute(batchSize, output.data(), xData, meanData, widthData);
120 }
121 return output;
122}
123
124////////////////////////////////////////////////////////////////////////////////
125
126Int_t RooBreitWigner::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const
127{
128 if (matchArgs(allVars,analVars,x)) return 1 ;
129 return 0 ;
130}
131
132////////////////////////////////////////////////////////////////////////////////
133
134Double_t RooBreitWigner::analyticalIntegral(Int_t code, const char* rangeName) const
135{
136 switch(code) {
137 case 1:
138 {
139 Double_t c = 2./width;
140 return c*(atan(c*(x.max(rangeName)-mean)) - atan(c*(x.min(rangeName)-mean)));
141 }
142 }
143
144 assert(0) ;
145 return 0 ;
146}
#define c(i)
Definition: RSha256.hxx:101
#define ClassImp(name)
Definition: Rtypes.h:361
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
char name[80]
Definition: TGX11.cxx:109
double atan(double)
RooSpan< double > makeWritableBatchUnInit(std::size_t begin, std::size_t batchSize, const RooArgSet *const normSet=nullptr, Tag_t ownerTag=kUnspecified)
Make a batch and return a span pointing to the pdf-local memory.
Definition: BatchData.cxx:118
Little adapter that gives a bracket operator to types that don't have one.
Definition: BatchHelpers.h:58
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:60
Bool_t matchArgs(const RooArgSet &allDeps, RooArgSet &numDeps, const RooArgProxy &a) const
Utility function for use in getAnalyticalIntegral().
BatchHelpers::BatchData _batchData
Definition: RooAbsReal.h:450
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
Class RooBreitWigner is a RooAbsPdf implementation that models a non-relativistic Breit-Wigner shape.
Double_t evaluate() const
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
RooSpan< double > evaluateBatch(std::size_t begin, std::size_t batchSize) const
Evaluate function for a batch of input data points.
RooRealProxy width
RooRealProxy mean
Double_t analyticalIntegral(Int_t code, const char *rangeName=0) const
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
RooRealProxy x
A simple container to hold a batch of data values.
Definition: RooSpan.h:32
double min(const char *rname=0) const
Query lower limit of range. This requires the payload to be RooAbsRealLValue or derived.
double max(const char *rname=0) const
Query upper limit of range. This requires the payload to be RooAbsRealLValue or derived.
RooSpan< const typename T::value_type > getValBatch(std::size_t begin, std::size_t batchSize) const
Retrieve a batch of real or category data.
Double_t x[n]
Definition: legend1.C:17
size_t findSize(std::vector< RooSpan< const double > > parameters)
This function returns the minimum size of the non-zero-sized batches.
static void output(int code)
Definition: gifencode.c:226