RooBCPGenDecay.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitModels                                                     *
00004  * @(#)root/roofit:$Id: RooBCPGenDecay.cxx 36230 2010-10-09 20:21:02Z wouter $
00005  * Authors:                                                                  *
00006  *   JGS, Jim Smith    , University of Colorado, jgsmith@pizero.colorado.edu *
00007  * History:
00008  *   15-Aug-2002 JGS Created initial version
00009  *   11-Sep-2002 JGS Mods to introduce mu (Mirna van Hoek, JGS, Nick Danielson)
00010  *                                                                           *
00011  * Copyright (c) 2000-2005, Regents of the University of California,         *
00012  *                          University of Colorado                           *
00013  *                          and Stanford University. All rights reserved.    *
00014  *                                                                           *
00015  * Redistribution and use in source and binary forms,                        *
00016  * with or without modification, are permitted according to the terms        *
00017  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00018  *****************************************************************************/
00019 
00020 //////////////////////////////////////////////////////////////////////////////
00021 //
00022 // BEGIN_HTML
00023 // Implement standard CP physics model with S and C (no mention of lambda)
00024 // Suitably stolen and modified from RooBCPEffDecay
00025 // END_HTML
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   // Constructor
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   // Copy constructor
00105 }
00106 
00107 
00108 
00109 //_____________________________________________________________________________
00110 RooBCPGenDecay::~RooBCPGenDecay()
00111 {
00112   // Destructor
00113 }
00114 
00115 
00116 
00117 //_____________________________________________________________________________
00118 Double_t RooBCPGenDecay::coefficient(Int_t basisIndex) const 
00119 {
00120   // B0    : _tag = +1 
00121   // B0bar : _tag = -1 
00122 
00123   if (basisIndex==_basisExp) {
00124     //exp term: (1 -/+ dw + mu*_tag*w)
00125     return (1 - _tag*_delMistag + _mu*_tag*(1. - 2.*_avgMistag)) ;
00126     // =    1 + _tag*deltaDil/2 + _mu*avgDil
00127   }
00128 
00129   if (basisIndex==_basisSin) {
00130     //sin term: (+/- (1-2w) + _mu*(1 -/+ delw))*S
00131     return (_tag*(1-2*_avgMistag) + _mu*(1. - _tag*_delMistag))*_avgS ;
00132     // =   (_tag*avgDil + _mu*(1 + tag*deltaDil/2)) * S
00133   }
00134   
00135   if (basisIndex==_basisCos) {
00136     //cos term: -(+/- (1-2w) + _mu*(1 -/+ delw))*C
00137     return -1.*(_tag*(1-2*_avgMistag) + _mu*(1. - _tag*_delMistag))*_avgC ;
00138     // =   -(_tag*avgDil + _mu*(1 + _tag*deltaDil/2) )* C
00139   } 
00140   
00141   return 0 ;
00142 }
00143 
00144 
00145 
00146 //_____________________________________________________________________________
00147 Int_t RooBCPGenDecay::getCoefAnalyticalIntegral(Int_t /*code*/, 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* /*rangeName*/) const 
00158 {
00159   switch(code) {
00160     // No integration
00161   case 0: return coefficient(basisIndex) ;
00162 
00163     // Integration over 'tag'
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     // Calculate the fraction of mixed events to generate
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   // Generate mix-state dependent
00216   if (code==2) {
00217     Double_t rand = RooRandom::uniform() ;
00218     _tag = (rand<=_genB0Frac) ? 1 : -1 ;
00219   }
00220 
00221   // Generate delta-t dependent
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     // Accept event if T is in generated range
00239     Double_t maxDil = 1.0 ;
00240 // 2 in next line is conservative and inefficient - allows for delMistag=1!
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 

Generated on Tue Jul 5 14:54:33 2011 for ROOT_528-00b_version by  doxygen 1.5.1