00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "RooFit.h"
00029
00030 #include "Riostream.h"
00031 #include "Riostream.h"
00032 #include "RooRealVar.h"
00033 #include "RooRandom.h"
00034 #include "RooBCPGenDecay.h"
00035 #include "RooRealIntegral.h"
00036
00037 ClassImp(RooBCPGenDecay)
00038 ;
00039
00040
00041
00042
00043 RooBCPGenDecay::RooBCPGenDecay(const char *name, const char *title,
00044 RooRealVar& t, RooAbsCategory& tag,
00045 RooAbsReal& tau, RooAbsReal& dm,
00046 RooAbsReal& avgMistag,
00047 RooAbsReal& a, RooAbsReal& b,
00048 RooAbsReal& delMistag,
00049 RooAbsReal& mu,
00050 const RooResolutionModel& model, DecayType type) :
00051 RooAbsAnaConvPdf(name,title,model,t),
00052 _avgC("C","Coefficient of cos term",this,a),
00053 _avgS("S","Coefficient of cos term",this,b),
00054 _avgMistag("avgMistag","Average mistag rate",this,avgMistag),
00055 _delMistag("delMistag","Delta mistag rate",this,delMistag),
00056 _mu("mu","Tagg efficiency difference",this,mu),
00057 _t("t","time",this,t),
00058 _tau("tau","decay time",this,tau),
00059 _dm("dm","mixing frequency",this,dm),
00060 _tag("tag","CP state",this,tag),
00061 _genB0Frac(0),
00062 _type(type)
00063 {
00064
00065 switch(type) {
00066 case SingleSided:
00067 _basisExp = declareBasis("exp(-@0/@1)",RooArgList(tau,dm)) ;
00068 _basisSin = declareBasis("exp(-@0/@1)*sin(@0*@2)",RooArgList(tau,dm)) ;
00069 _basisCos = declareBasis("exp(-@0/@1)*cos(@0*@2)",RooArgList(tau,dm)) ;
00070 break ;
00071 case Flipped:
00072 _basisExp = declareBasis("exp(@0)/@1)",RooArgList(tau,dm)) ;
00073 _basisSin = declareBasis("exp(@0/@1)*sin(@0*@2)",RooArgList(tau,dm)) ;
00074 _basisCos = declareBasis("exp(@0/@1)*cos(@0*@2)",RooArgList(tau,dm)) ;
00075 break ;
00076 case DoubleSided:
00077 _basisExp = declareBasis("exp(-abs(@0)/@1)",RooArgList(tau,dm)) ;
00078 _basisSin = declareBasis("exp(-abs(@0)/@1)*sin(@0*@2)",RooArgList(tau,dm)) ;
00079 _basisCos = declareBasis("exp(-abs(@0)/@1)*cos(@0*@2)",RooArgList(tau,dm)) ;
00080 break ;
00081 }
00082 }
00083
00084
00085
00086
00087 RooBCPGenDecay::RooBCPGenDecay(const RooBCPGenDecay& other, const char* name) :
00088 RooAbsAnaConvPdf(other,name),
00089 _avgC("C",this,other._avgC),
00090 _avgS("S",this,other._avgS),
00091 _avgMistag("avgMistag",this,other._avgMistag),
00092 _delMistag("delMistag",this,other._delMistag),
00093 _mu("mu",this,other._mu),
00094 _t("t",this,other._t),
00095 _tau("tau",this,other._tau),
00096 _dm("dm",this,other._dm),
00097 _tag("tag",this,other._tag),
00098 _genB0Frac(other._genB0Frac),
00099 _type(other._type),
00100 _basisExp(other._basisExp),
00101 _basisSin(other._basisSin),
00102 _basisCos(other._basisCos)
00103 {
00104
00105 }
00106
00107
00108
00109
00110 RooBCPGenDecay::~RooBCPGenDecay()
00111 {
00112
00113 }
00114
00115
00116
00117
00118 Double_t RooBCPGenDecay::coefficient(Int_t basisIndex) const
00119 {
00120
00121
00122
00123 if (basisIndex==_basisExp) {
00124
00125 return (1 - _tag*_delMistag + _mu*_tag*(1. - 2.*_avgMistag)) ;
00126
00127 }
00128
00129 if (basisIndex==_basisSin) {
00130
00131 return (_tag*(1-2*_avgMistag) + _mu*(1. - _tag*_delMistag))*_avgS ;
00132
00133 }
00134
00135 if (basisIndex==_basisCos) {
00136
00137 return -1.*(_tag*(1-2*_avgMistag) + _mu*(1. - _tag*_delMistag))*_avgC ;
00138
00139 }
00140
00141 return 0 ;
00142 }
00143
00144
00145
00146
00147 Int_t RooBCPGenDecay::getCoefAnalyticalIntegral(Int_t , RooArgSet& allVars, RooArgSet& analVars, const char* rangeName) const
00148 {
00149 if (rangeName) return 0 ;
00150 if (matchArgs(allVars,analVars,_tag)) return 1 ;
00151 return 0 ;
00152 }
00153
00154
00155
00156
00157 Double_t RooBCPGenDecay::coefAnalyticalIntegral(Int_t basisIndex, Int_t code, const char* ) const
00158 {
00159 switch(code) {
00160
00161 case 0: return coefficient(basisIndex) ;
00162
00163
00164 case 1:
00165 if (basisIndex==_basisExp) {
00166 return 2 ;
00167 }
00168
00169 if (basisIndex==_basisSin) {
00170 return 2*_mu*_avgS ;
00171 }
00172 if (basisIndex==_basisCos) {
00173 return -2*_mu*_avgC ;
00174 }
00175 break ;
00176
00177 default:
00178 assert(0) ;
00179 }
00180
00181 return 0 ;
00182 }
00183
00184
00185
00186
00187 Int_t RooBCPGenDecay::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t staticInitOK) const
00188 {
00189 if (staticInitOK) {
00190 if (matchArgs(directVars,generateVars,_t,_tag)) return 2 ;
00191 }
00192 if (matchArgs(directVars,generateVars,_t)) return 1 ;
00193 return 0 ;
00194 }
00195
00196
00197
00198
00199 void RooBCPGenDecay::initGenerator(Int_t code)
00200 {
00201 if (code==2) {
00202
00203 Double_t sumInt = RooRealIntegral("sumInt","sum integral",*this,RooArgSet(_t.arg(),_tag.arg())).getVal() ;
00204 _tag = 1 ;
00205 Double_t b0Int = RooRealIntegral("mixInt","mix integral",*this,RooArgSet(_t.arg())).getVal() ;
00206 _genB0Frac = b0Int/sumInt ;
00207 }
00208 }
00209
00210
00211
00212
00213 void RooBCPGenDecay::generateEvent(Int_t code)
00214 {
00215
00216 if (code==2) {
00217 Double_t rand = RooRandom::uniform() ;
00218 _tag = (rand<=_genB0Frac) ? 1 : -1 ;
00219 }
00220
00221
00222 while(1) {
00223 Double_t rand = RooRandom::uniform() ;
00224 Double_t tval(0) ;
00225
00226 switch(_type) {
00227 case SingleSided:
00228 tval = -_tau*log(rand);
00229 break ;
00230 case Flipped:
00231 tval= +_tau*log(rand);
00232 break ;
00233 case DoubleSided:
00234 tval = (rand<=0.5) ? -_tau*log(2*rand) : +_tau*log(2*(rand-0.5)) ;
00235 break ;
00236 }
00237
00238
00239 Double_t maxDil = 1.0 ;
00240
00241 Double_t maxAcceptProb = 2 + fabs(maxDil*_avgS) + fabs(maxDil*_avgC);
00242 Double_t acceptProb = (1-_tag*_delMistag + _mu*_tag*(1. - 2.*_avgMistag))
00243 + (_tag*(1-2*_avgMistag) + _mu*(1. - _tag*_delMistag))*_avgS*sin(_dm*tval)
00244 - (_tag*(1-2*_avgMistag) + _mu*(1. - _tag*_delMistag))*_avgC*cos(_dm*tval);
00245
00246 Bool_t accept = maxAcceptProb*RooRandom::uniform() < acceptProb ? kTRUE : kFALSE ;
00247
00248 if (tval<_t.max() && tval>_t.min() && accept) {
00249 _t = tval ;
00250 break ;
00251 }
00252 }
00253
00254 }
00255