MINT2
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
TimeDependentGenerator Class Reference

#include <TimeDependentGenerator.h>

Classes

class  GenTimeEvent
 

Public Types

typedef std::pair< std::complex< double >, std::complex< double > > AmpPair
 

Public Member Functions

 TimeDependentGenerator (const DalitzEventPattern &pattern, double width, double deltam, double deltagamma, double qoverp, double phi, TRandom3 *rndm, TH1F *h_efficiency=NULL, float resWidth=0.05, bool addExpEffects=false, Eff3piSymmetric *sEfficiency=NULL)
 
 TimeDependentGenerator (MINT::counted_ptr< FitAmpSum > model, MINT::counted_ptr< FitAmpSum > cpmodel, double width, double deltam, double deltagamma, double qoverp, double phi, TRandom3 *, TH1F *h_efficiency=NULL, float resWidth=0.05, bool addExpEffects=false, Eff3piSymmetric *sEfficiency=NULL)
 
std::pair< double, double > generate_decay_time () const
 Generate a decay time, optionally including experimental effects. More...
 
MINT::counted_ptr< IDalitzEventgenerate_event ()
 Generate a flavour, decay time and Dalitz event. More...
 
MINT::counted_ptr< IDalitzEventgenerate_event (const double s13, const double s23)
 Generate a 3-body event at a given point in phase space. More...
 
bool accept_or_reject (const int tag, const double decaytime, IDalitzEvent &)
 Decide whether the generated event should be accepted or rejected. More...
 
double get_scale () const
 
float get_gen_efficiency () const
 
double pdf_value (int, double, IDalitzEvent &)
 
double pdf_value (IDalitzEvent &)
 
double envelope_value (const double, IDalitzEvent &)
 
AmpPair amplitude_coefficients (const int tag, const double decaytime)
 
TH1F draw_pdf_vs_time (IDalitzEvent &, unsigned, float, float, const std::string &name="pdf_vs_time")
 
TH1F draw_envelope_vs_time (IDalitzEvent &, unsigned, float, float, const std::string &name="envelope_vs_time")
 

Static Public Member Functions

static DalitzEventPattern anti (DalitzEventPattern pat)
 Take the CP conjugate of the head of the decay pattern. More...
 

Private Member Functions

void init ()
 

Private Attributes

TRandom3 * m_rndm
 
const DalitzEventPattern m_pattern
 
const DalitzEventPattern m_cppattern
 
MINT::counted_ptr< FitAmpSumm_model
 
MINT::counted_ptr< FitAmpSumm_cpmodel
 
FitAmpIncoherentSum m_bothmodel
 
SignalGenerator m_generator
 
const double m_width
 
const double m_deltam
 
const double m_deltagamma
 
const std::complex< double > m_qoverp
 
double m_scale
 
unsigned m_ngen
 
unsigned m_naccept
 
TH1F * m_h_efficiency
 
TSpline3 m_efficiencyFit
 
float m_resWidth
 
bool m_addExpEffects
 
Eff3piSymmetricm_sEfficiency
 

Detailed Description

Definition at line 20 of file TimeDependentGenerator.h.

Member Typedef Documentation

◆ AmpPair

typedef std::pair<std::complex<double>, std::complex<double> > TimeDependentGenerator::AmpPair

Definition at line 106 of file TimeDependentGenerator.h.

Constructor & Destructor Documentation

◆ TimeDependentGenerator() [1/2]

TimeDependentGenerator::TimeDependentGenerator ( const DalitzEventPattern pattern,
double  width,
double  deltam,
double  deltagamma,
double  qoverp,
double  phi,
TRandom3 *  rndm,
TH1F *  h_efficiency = NULL,
float  resWidth = 0.05,
bool  addExpEffects = false,
Eff3piSymmetric sEfficiency = NULL 
)

Constructor, takes: pattern : The event pattern to be used (the CP conjugate will automatically be added). width : the decay width in 1/ps. deltam : the delta-mass in 1/ps. deltagamma : the delta-gamma in 1/ps. qoverp : the magnitude of q/p. phi : the phase of q/p. rndm : The random number generator to use. h_efficiency : (optional) histogram to which efficiency plot will be fitted resWidth : the width of the Gaussian decay-time resolution to apply addExpEffects : whether to add efficiency and resolution to the decay time.

Definition at line 70 of file TimeDependentGenerator.cpp.

73  :
74  m_rndm(rndm),
75  m_pattern(pattern),
76  m_cppattern(anti(pattern)),
77  m_model(new FitAmpSum(pattern)),
81  m_width(width),
82  m_deltam(deltam),
83  m_deltagamma(deltagamma),
84  m_qoverp(polar(qoverp, phi)),
85  m_scale(1.),
86  m_ngen(0),
87  m_naccept(0),
88  m_h_efficiency(h_efficiency),
90  m_resWidth(resWidth),
91  m_addExpEffects(addExpEffects),
92  m_sEfficiency(sEfficiency)
93 {
94  init() ;
95 }
FitAmpIncoherentSum m_bothmodel
static DalitzEventPattern anti(DalitzEventPattern pat)
Take the CP conjugate of the head of the decay pattern.
MINT::counted_ptr< FitAmpSum > m_cpmodel
const std::complex< double > m_qoverp
const DalitzEventPattern m_pattern
MINT::counted_ptr< FitAmpSum > m_model
const DalitzEventPattern m_cppattern

◆ TimeDependentGenerator() [2/2]

TimeDependentGenerator::TimeDependentGenerator ( MINT::counted_ptr< FitAmpSum model,
MINT::counted_ptr< FitAmpSum cpmodel,
double  width,
double  deltam,
double  deltagamma,
double  qoverp,
double  phi,
TRandom3 *  rndm,
TH1F *  h_efficiency = NULL,
float  resWidth = 0.05,
bool  addExpEffects = false,
Eff3piSymmetric sEfficiency = NULL 
)

Constructor, takes: model : the amplitude model for the decay cpmodel : the amplitude model for the CP conjugate decay width : the decay width in 1/ps. deltam : the delta-mass in 1/ps. deltagamma : the delta-gamma in 1/ps. qoverp : the magnitude of q/p. phi : the phase of q/p. rndm : The random number generator to use. h_efficiency : (optional) histogram to which efficiency plot will be fitted resWidth : the width of the Gaussian decay-time resolution to apply addExpEffects : whether to add efficiency and resolution to the decay time.

Definition at line 98 of file TimeDependentGenerator.cpp.

103  :
104  m_rndm(rndm),
105  m_pattern(model->getAmpPtr(0)->getTreePattern()),
106  m_cppattern(cpmodel->getAmpPtr(0)->getTreePattern()),
107  m_model(model),
108  m_cpmodel(cpmodel),
111  m_width(width),
112  m_deltam(deltam),
113  m_deltagamma(deltagamma),
114  m_qoverp(polar(qoverp, phi)),
115  m_scale(1.),
116  m_ngen(0),
117  m_naccept(0),
118  m_h_efficiency(h_efficiency),
119  m_efficiencyFit(),
120  m_resWidth(resWidth),
121  m_addExpEffects(addExpEffects),
122  m_sEfficiency(sEfficiency)
123 {
124  init() ;
125 }
DalitzEventPattern getTreePattern() const
Definition: FitAmplitude.h:169
virtual FitAmplitude * getAmpPtr(unsigned int i)
FitAmpIncoherentSum m_bothmodel
MINT::counted_ptr< FitAmpSum > m_cpmodel
const std::complex< double > m_qoverp
const DalitzEventPattern m_pattern
MINT::counted_ptr< FitAmpSum > m_model
const DalitzEventPattern m_cppattern

Member Function Documentation

◆ accept_or_reject()

bool TimeDependentGenerator::accept_or_reject ( const int  tag,
const double  decaytime,
IDalitzEvent evt 
)

Decide whether the generated event should be accepted or rejected.

Definition at line 236 of file TimeDependentGenerator.cpp.

236  {
237  ++m_ngen ;
238 
239  double pdfval = pdf_value(tag, decaytime, evt) ;
240 
241  double maxval = envelope_value(decaytime, evt) ;
242  if(pdfval > maxval){
243  cout << "pdfval " << pdfval << " maxval " << maxval << endl ;
244  //throw out_of_range("pdfval > maxval. That shouldn't happen!") ;
245  m_scale *= pdfval / maxval ;
246  cout << "scale " << m_scale << endl ;
247  ++m_naccept ;
248  return true ;
249  }
250  if(m_rndm->Rndm() * maxval < pdfval){
251  ++m_naccept ;
252  return true ;
253  }
254  return false ;
255 }
double envelope_value(const double, IDalitzEvent &)
double pdf_value(int, double, IDalitzEvent &)

◆ amplitude_coefficients()

TimeDependentGenerator::AmpPair TimeDependentGenerator::amplitude_coefficients ( const int  tag,
const double  decaytime 
)

Get the coefficients of the amplitudes for the produced flavour and the mixed flavour given the tag and decay time.

Definition at line 296 of file TimeDependentGenerator.cpp.

296  {
297  double coeff = 0.5 * exp(-decaytime * 0.5 * (m_width + 0.5 * m_deltagamma)) ;
298  complex<double> expterm = exp(complex<double>(0.5 * m_deltagamma * decaytime, m_deltam * decaytime)) ;
299  complex<double> plusterm = 1. + expterm ;
300  complex<double> minusterm = 1. - expterm ;
301  complex<double> coeffprod = coeff * plusterm ;
302  complex<double> coeffmix = pow(m_qoverp, tag) * coeff * minusterm ;
303  return AmpPair(coeffprod, coeffmix) ;
304 }
const std::complex< double > m_qoverp
std::pair< std::complex< double >, std::complex< double > > AmpPair

◆ anti()

DalitzEventPattern TimeDependentGenerator::anti ( DalitzEventPattern  pat)
static

Take the CP conjugate of the head of the decay pattern.

Definition at line 65 of file TimeDependentGenerator.cpp.

65  {
66  pat[0].antiThis() ;
67  return pat ;
68 }

◆ draw_envelope_vs_time()

TH1F TimeDependentGenerator::draw_envelope_vs_time ( IDalitzEvent evt,
unsigned  nbins,
float  tmin,
float  tmax,
const std::string &  name = "envelope_vs_time" 
)

Draw the envelope value vs time at the given point in phase space.

Definition at line 319 of file TimeDependentGenerator.cpp.

320  {
321  TH1F histo(name.c_str(), "", nbins, tmin, tmax) ;
322  for(unsigned i = 1 ; i < nbins + 1 ; ++i){
323  double time = histo.GetXaxis()->GetBinCenter(i) ;
324  double val = envelope_value(time, evt) ;
325  histo.SetBinContent(i, val) ;
326  histo.SetBinError(i, 0.) ;
327  }
328  return histo ;
329 }
double envelope_value(const double, IDalitzEvent &)

◆ draw_pdf_vs_time()

TH1F TimeDependentGenerator::draw_pdf_vs_time ( IDalitzEvent evt,
unsigned  nbins,
float  tmin,
float  tmax,
const std::string &  name = "pdf_vs_time" 
)

Draw the PDF value vs time at the given point in phase space (assumes the event has a tag).

Definition at line 306 of file TimeDependentGenerator.cpp.

307  {
308  TH1F histo(name.c_str(), "", nbins, tmin, tmax) ;
309  int tag = int(evt.getValueFromVector(GenTimeEvent::ITAG)) ;
310  for(unsigned i = 1 ; i < nbins + 1 ; ++i){
311  double time = histo.GetXaxis()->GetBinCenter(i) ;
312  double val = pdf_value(tag, time, evt) ;
313  histo.SetBinContent(i, val) ;
314  histo.SetBinError(i, 0.) ;
315  }
316  return histo ;
317 }
double pdf_value(int, double, IDalitzEvent &)
virtual double getValueFromVector(unsigned int i) const =0

◆ envelope_value()

double TimeDependentGenerator::envelope_value ( const double  decaytime,
IDalitzEvent evt 
)

Get the value of the incoherent sum PDF that's used as an envelope to generate events at the given point in phase space and time.

Definition at line 232 of file TimeDependentGenerator.cpp.

232  {
233  return m_bothmodel.Prob(evt) * m_scale * exp(-decaytime * m_width) * m_width ;
234 }
FitAmpIncoherentSum m_bothmodel
virtual double Prob(IDalitzEvent &evt)

◆ generate_decay_time()

pair< double, double > TimeDependentGenerator::generate_decay_time ( ) const

Generate a decay time, optionally including experimental effects.

Definition at line 143 of file TimeDependentGenerator.cpp.

143  {
144  double decaytime = m_rndm->Exp(1./m_width) ;
145  double smeareddecaytime = decaytime ;
146 
147  if ( (m_h_efficiency != NULL) && (m_addExpEffects) ){
148  int i = 0 ;
149  float efficiency = 0 ;
150  int maxiter = 100000 ;
151 
152  smeareddecaytime = decaytime + m_rndm->Gaus(0, m_resWidth);
153 
154  while(true){
155  if( smeareddecaytime > m_efficiencyFit.GetXmax() ){
156  efficiency = m_efficiencyFit.Eval( m_efficiencyFit.GetXmax() ) ;
157  }
158  else if( smeareddecaytime > m_efficiencyFit.GetXmin() ){
159  efficiency = m_efficiencyFit.Eval( smeareddecaytime ) ;
160  }
161  else{
162  efficiency = m_efficiencyFit.Eval( m_efficiencyFit.GetXmin() ) ;
163  }
164 
165  if(m_rndm->Rndm() < efficiency){
166  break;
167  }
168 
169  decaytime = m_rndm->Exp(1./m_width) ;
170  smeareddecaytime = decaytime + m_rndm->Gaus(0, m_resWidth);
171 
172  i += 1 ;
173  if( i > maxiter ){
174  cout << "WARNING: Decay time generation limit exceeded." << endl ;
175  break ;
176  }
177  }
178  }
179  return pair<double, double>(decaytime, smeareddecaytime) ;
180 }

◆ generate_event() [1/2]

MINT::counted_ptr< IDalitzEvent > TimeDependentGenerator::generate_event ( )

Generate a flavour, decay time and Dalitz event.

Definition at line 207 of file TimeDependentGenerator.cpp.

207  {
208  int tag(0) ;
209  double decaytime(0.) ;
210  double smeareddecaytime(0.) ;
211 
213 
214  unsigned i = 0 ;
215  unsigned maxattempts = 100000 ;
216  // Accept/reject using the incoherent sum in m_bothmodel as an envelope to generate
217  // events.
218  while(true) {
219  tag = m_rndm->Rndm() > 0.5 ? 1 : -1 ;
220  tie(decaytime, smeareddecaytime) = generate_decay_time() ;
221  evt = m_generator.newEvent() ;
222  if(accept_or_reject(tag, decaytime, *evt))
223  break ;
224  i += 1 ;
225  if( i >= maxattempts)
226  throw range_error("Failed to generate an event in 100000 attempts!") ;
227  }
228 
229  return MINT::counted_ptr<IDalitzEvent>(new GenTimeEvent(*evt, tag, decaytime, smeareddecaytime)) ;
230 }
virtual MINT::counted_ptr< IDalitzEvent > newEvent()
std::pair< double, double > generate_decay_time() const
Generate a decay time, optionally including experimental effects.
bool accept_or_reject(const int tag, const double decaytime, IDalitzEvent &)
Decide whether the generated event should be accepted or rejected.

◆ generate_event() [2/2]

MINT::counted_ptr< IDalitzEvent > TimeDependentGenerator::generate_event ( const double  s13,
const double  s23 
)

Generate a 3-body event at a given point in phase space.

Definition at line 182 of file TimeDependentGenerator.cpp.

182  {
183  int tag(0) ;
184  double decaytime(0.) ;
185  double smeareddecaytime(0.) ;
186 
188 
189  unsigned i = 0 ;
190  unsigned maxattempts = 100000 ;
191  // Accept/reject using the incoherent sum in m_bothmodel as an envelope to generate
192  // events.
193  while(true) {
194  tag = m_rndm->Rndm() > 0.5 ? 1 : -1 ;
195  tie(decaytime, smeareddecaytime) = generate_decay_time() ;
196  evt = MINT::counted_ptr<IDalitzEvent>(new DalitzEvent(tag == 1 ? m_pattern : m_cppattern, s13, s23)) ;
197  if(accept_or_reject(tag, decaytime, *evt))
198  break ;
199  i += 1 ;
200  if( i >= maxattempts)
201  throw range_error("Failed to generate an event in 100000 attempts!") ;
202  }
203 
204  return MINT::counted_ptr<IDalitzEvent>(new GenTimeEvent(*evt, tag, decaytime, smeareddecaytime)) ;
205 }
std::pair< double, double > generate_decay_time() const
Generate a decay time, optionally including experimental effects.
bool accept_or_reject(const int tag, const double decaytime, IDalitzEvent &)
Decide whether the generated event should be accepted or rejected.
const DalitzEventPattern m_pattern
const DalitzEventPattern m_cppattern

◆ get_gen_efficiency()

float TimeDependentGenerator::get_gen_efficiency ( ) const

Definition at line 261 of file TimeDependentGenerator.cpp.

261  {
262  return m_ngen > 0 ? float(m_naccept)/m_ngen : 0. ;
263 }

◆ get_scale()

double TimeDependentGenerator::get_scale ( ) const

Definition at line 257 of file TimeDependentGenerator.cpp.

257  {
258  return m_scale ;
259 }

◆ init()

void TimeDependentGenerator::init ( )
private

Definition at line 127 of file TimeDependentGenerator.cpp.

127  {
129  if( m_h_efficiency != NULL ){
130  m_efficiencyFit = TSpline3(m_h_efficiency) ;
131  }
132  if( m_sEfficiency != NULL ){
135  }
136  // Ensure the models are fully initialised.
138  m_model->getVal(evt) ;
139  m_cpmodel->getVal(evt) ;
140  m_bothmodel.getVal(evt) ;
141 }
FitAmpIncoherentSum m_bothmodel
void setEfficiency(const MINT::counted_ptr< MINT::IReturnRealForEvent< IDalitzEvent > > &eff)
virtual std::complex< double > getVal(IDalitzEvent &evt)
Definition: FitAmpSum.cpp:182
virtual int addAsList(const FitAmpListBase &other, double factor=1)
double getVal(IDalitzEvent &evt)
MINT::counted_ptr< FitAmpSum > m_cpmodel
const DalitzEventPattern m_pattern
MINT::counted_ptr< FitAmpSum > m_model

◆ pdf_value() [1/2]

double TimeDependentGenerator::pdf_value ( int  tag,
double  decaytime,
IDalitzEvent evt 
)

Get the value of the PDF given the tag, decay time and point in phase space

Definition at line 265 of file TimeDependentGenerator.cpp.

265  {
266  complex<double> Ap = m_model->ComplexVal(evt) ;
267  complex<double> Am = m_cpmodel->ComplexVal(evt) ;
268  if(tag == -1)
269  swap(Ap, Am) ;
270  // This is gives the same values as the below using the amplitude coefficients.
271  /*double magAp = norm(Ap) ;
272  double magAm = norm(Am) ;
273  complex<double> crossterm = pow(m_qoverp, tag) * conj(Ap) * Am ;
274  double magqoverp = pow(norm(m_qoverp), tag) ;
275  double deltamt = m_deltam * decaytime ;
276  double halfdgammat = 0.5 * m_deltagamma * decaytime ;
277  double pdfval = 0.5 * exp(-m_width * decaytime)
278  * ((magAp + magqoverp * magAm) * cosh(halfdgammat)
279  + (magAp - magqoverp * magAm) * cos(deltamt)
280  - 2 * crossterm.real() * sinh(halfdgammat)
281  + 2 * crossterm.imag() * sin(deltamt)) ;
282  return pdfval ;*/
283  AmpPair coeffs = amplitude_coefficients(tag, decaytime) ;
284  complex<double> Amp = coeffs.first * Ap + coeffs.second * Am ;
285  double ampnorm = norm(Amp) ;
286  return ampnorm ;
287 }
virtual std::complex< double > ComplexVal(IDalitzEvent &evt)
Definition: FitAmpSum.h:122
MINT::counted_ptr< FitAmpSum > m_cpmodel
AmpPair amplitude_coefficients(const int tag, const double decaytime)
MINT::counted_ptr< FitAmpSum > m_model

◆ pdf_value() [2/2]

double TimeDependentGenerator::pdf_value ( IDalitzEvent evt)

Get the value of the PDF, assuming the tag & decay time are stored in the DalitzEvent like a GenTimeEvent

Definition at line 289 of file TimeDependentGenerator.cpp.

Member Data Documentation

◆ m_addExpEffects

bool TimeDependentGenerator::m_addExpEffects
private

Definition at line 140 of file TimeDependentGenerator.h.

◆ m_bothmodel

FitAmpIncoherentSum TimeDependentGenerator::m_bothmodel
private

Definition at line 125 of file TimeDependentGenerator.h.

◆ m_cpmodel

MINT::counted_ptr<FitAmpSum> TimeDependentGenerator::m_cpmodel
private

Definition at line 124 of file TimeDependentGenerator.h.

◆ m_cppattern

const DalitzEventPattern TimeDependentGenerator::m_cppattern
private

Definition at line 122 of file TimeDependentGenerator.h.

◆ m_deltagamma

const double TimeDependentGenerator::m_deltagamma
private

Definition at line 130 of file TimeDependentGenerator.h.

◆ m_deltam

const double TimeDependentGenerator::m_deltam
private

Definition at line 129 of file TimeDependentGenerator.h.

◆ m_efficiencyFit

TSpline3 TimeDependentGenerator::m_efficiencyFit
private

Definition at line 137 of file TimeDependentGenerator.h.

◆ m_generator

SignalGenerator TimeDependentGenerator::m_generator
private

Definition at line 126 of file TimeDependentGenerator.h.

◆ m_h_efficiency

TH1F* TimeDependentGenerator::m_h_efficiency
private

Definition at line 136 of file TimeDependentGenerator.h.

◆ m_model

MINT::counted_ptr<FitAmpSum> TimeDependentGenerator::m_model
private

Definition at line 123 of file TimeDependentGenerator.h.

◆ m_naccept

unsigned TimeDependentGenerator::m_naccept
private

Definition at line 134 of file TimeDependentGenerator.h.

◆ m_ngen

unsigned TimeDependentGenerator::m_ngen
private

Definition at line 133 of file TimeDependentGenerator.h.

◆ m_pattern

const DalitzEventPattern TimeDependentGenerator::m_pattern
private

Definition at line 121 of file TimeDependentGenerator.h.

◆ m_qoverp

const std::complex<double> TimeDependentGenerator::m_qoverp
private

Definition at line 131 of file TimeDependentGenerator.h.

◆ m_resWidth

float TimeDependentGenerator::m_resWidth
private

Definition at line 139 of file TimeDependentGenerator.h.

◆ m_rndm

TRandom3* TimeDependentGenerator::m_rndm
private

Definition at line 120 of file TimeDependentGenerator.h.

◆ m_scale

double TimeDependentGenerator::m_scale
private

Definition at line 132 of file TimeDependentGenerator.h.

◆ m_sEfficiency

Eff3piSymmetric* TimeDependentGenerator::m_sEfficiency
private

Definition at line 142 of file TimeDependentGenerator.h.

◆ m_width

const double TimeDependentGenerator::m_width
private

Definition at line 128 of file TimeDependentGenerator.h.


The documentation for this class was generated from the following files: