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

#include <TimeDependentGeneratorOld.h>

Classes

class  GenTimeEvent
 
class  GenTimePoint
 

Public Types

typedef std::list< GenTimePointGenList
 
typedef std::map< int, GenListGenMap
 
typedef std::pair< std::complex< double >, std::complex< double > > AmpPair
 

Public Member Functions

 TimeDependentGeneratorOld (const std::string &name, const bool overwrite, TRandom3 *rndm, double precision, const DalitzEventPattern &pattern, double width, double deltam, double deltagamma, double qoverp, double phi, double tmax, int ntimepoints, const bool saveIntegEvents=true, double tmin=0., TH1F *h_efficiency=NULL, float resWidth=0.05, bool addExpEffects=false)
 
AmpPair amplitude_coefficients (const int tag, const double decaytime)
 
int generate_tag () const
 
double generate_decay_time (const int tag) const
 
MINT::counted_ptr< IDalitzEventgenerate_dalitz_event (const int tag, const double decaytime) const
 
MINT::counted_ptr< IDalitzEventgenerate_event () const
 
const std::map< int, SplineGeneratortime_generators () const
 

Static Public Member Functions

static DalitzEventPattern anti (DalitzEventPattern pat)
 

Private Attributes

const std::string m_name
 
TRandom3 * m_rndm
 
const DalitzEventPattern m_pattern
 
const DalitzEventPattern m_cppattern
 
const double m_width
 
const double m_deltam
 
const double m_deltagamma
 
const double m_qoverp
 
const double m_phi
 
const double m_tmax
 
const double m_tmin
 
const int m_ntimepoints
 
GenMap m_genmap
 
std::map< int, SplineGeneratorm_timegenerators
 
double m_tagintegralfrac
 
double m_precision
 
TH1F * m_h_efficiency
 
TSpline3 m_efficiencyFit
 
float m_resWidth
 
bool m_addExpEffects
 

Detailed Description

Definition at line 17 of file TimeDependentGeneratorOld.h.

Member Typedef Documentation

◆ AmpPair

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

Definition at line 34 of file TimeDependentGeneratorOld.h.

◆ GenList

Definition at line 32 of file TimeDependentGeneratorOld.h.

◆ GenMap

Definition at line 33 of file TimeDependentGeneratorOld.h.

Constructor & Destructor Documentation

◆ TimeDependentGeneratorOld()

TimeDependentGeneratorOld::TimeDependentGeneratorOld ( const std::string &  name,
const bool  overwrite,
TRandom3 *  rndm,
double  precision,
const DalitzEventPattern pattern,
double  width,
double  deltam,
double  deltagamma,
double  qoverp,
double  phi,
double  tmax,
int  ntimepoints,
const bool  saveIntegEvents = true,
double  tmin = 0.,
TH1F *  h_efficiency = NULL,
float  resWidth = 0.05,
bool  addExpEffects = false 
)

Definition at line 98 of file TimeDependentGeneratorOld.cpp.

104  :
105  m_name(name),
106  m_rndm(rndm),
107  m_pattern(pattern),
108  m_cppattern(anti(pattern)),
109  m_width(width),
110  m_deltam(deltam),
111  m_deltagamma(deltagamma),
112  m_qoverp(qoverp),
113  m_phi(phi),
114  m_tmax(tmax),
115  m_tmin(tmin),
116  m_ntimepoints(ntimepoints),
117  m_genmap(),
119  m_tagintegralfrac(0.),
120  m_precision(precision),
121  m_h_efficiency(h_efficiency),
122  m_resWidth(resWidth),
123  m_addExpEffects(addExpEffects),
125 {
126  // If overwrite is true and the integrators directory exists, delete it.
127  if(overwrite && exists(name)){
128  cout << "Deleting previous integrators in directory " << name << endl ;
129  string cmd("rm -rf " + name) ;
130  system(cmd.c_str()) ;
131  }
132 
133  if(!exists(name)){
134  string cmd("mkdir -p " + name) ;
135  system(cmd.c_str()) ;
136  }
137 
138  const DalitzEventPattern* patterns[] = {&m_cppattern, &m_pattern} ;
139  double sampleinterval = m_ntimepoints > 1 ? (m_tmax - m_tmin)/(m_ntimepoints-1) : 0. ;
140  // Loop over flavours.
141  for(int tag = -1 ; tag <= 1 ; tag += 2) {
142  m_genmap[tag] = GenList() ;
143  const DalitzEventPattern* evtpat = patterns[(tag+1)/2] ;
144  const DalitzEventPattern* antipat = patterns[((tag+1)/2 + 1) % 2] ;
145  // cout << "evtpat " ;
146  // evtpat->print() ;
147  // cout << " antipat " ;
148  // antipat->print() ;
149  // cout << endl ;
150  vector<double> times ;
151  vector<double> integrals ;
152  // Loop over decay time sample points.
153  for(int i = 0 ; i < m_ntimepoints ; ++i){
154  double decaytime = m_tmin + i * sampleinterval ;
155  AmpPair amps = amplitude_coefficients(tag, decaytime) ;
156  FitAmpSum* model(new FitAmpSum(*evtpat)) ;
157  *model *= amps.first ;
158  if(amps.second != complex<double>(0., 0.)){
159  FitAmpSum antimodel(*antipat) ;
160  antimodel *= amps.second ;
161  model->add(antimodel) ;
162  }
163  SignalGenerator* generator = new SignalGenerator(*evtpat, model) ;
164  //cout << "Time point " << i << endl ;
165  //model->print() ;
166  //auto evt = generator->newEvent() ;
167  //model->printAllAmps(*evt) ;
168  ostringstream fname ;
169  fname << m_name << "/tag_" << tag << "_decaytime_" << decaytime ;
170  double integral(0.) ;
171  // Calculate the integral if necessary.
172  if(!exists(fname.str())){
173  const string eventsFile(fname.str() + "_events.root") ;
174  DalitzPdfSaveInteg dalitz(*evtpat, model, m_precision, fname.str(),
175  eventsFile, "topUp", fname.str()) ;
176  integral = dalitz.getIntegralValue() ;
177  dalitz.saveIntegrator(fname.str()) ;
178  if(!saveIntegEvents){
179  string cmd("rm " + eventsFile) ;
180  system(cmd.c_str()) ;
181  }
182  }
183  // Else retrive the integral from a file.
184  else {
185  auto intcalc = model->makeIntegrationCalculator() ;
186  intcalc->retrieve(fname.str()) ;
187  integral = intcalc->integral() ;
188  }
189  cout << "Make generator with tag " << tag << ", decay time " << decaytime
190  << ", coeffprod " << amps.first.real()
191  << " + " << amps.first.imag() << " j, "
192  << " coeffmix " << amps.second.real() << " + " << amps.second.imag()
193  << " j, integral " << integral << endl ;
194  if(integral == 0.){
195  complex<double> coeff = amps.first + amps.second ;
196  integral = sqrt(coeff.real() * coeff.real() + coeff.imag() * coeff.imag()) ;
197  }
198  m_genmap[tag].push_back(GenTimePoint(decaytime, model, integral, generator)) ;
199  times.push_back(decaytime) ;
200  integrals.push_back(integral) ;
201  }
202  // Make a spline interpolator of the decay time distributions, to be used to generate
203  // the decay times.
204  ostringstream splinename ;
205  splinename << "timespline_tag_" << tag ;
206  string splinenamestr = splinename.str() ;
207  TSpline3 timespline(splinenamestr.c_str(), &times[0], &integrals[0], times.size()) ;
208  timespline.SetName(splinenamestr.c_str()) ;
209  m_timegenerators.insert(make_pair(tag, SplineGenerator(rndm, timespline))) ;
210  }
211  // Calculate the integrated CP asymmetry.
212  double integminus = m_timegenerators.find(-1)->second.integral() ;
213  double integplus = m_timegenerators.find(1)->second.integral() ;
214  cout << "Integrated CP asymmetry is " << (integplus - integminus)/(integplus + integminus) << endl ;
215  m_tagintegralfrac = integminus/(integminus + integplus) ;
216  double tauminus = m_timegenerators.find(-1)->second.mean() ;
217  double tauplus = m_timegenerators.find(1)->second.mean() ;
218  cout << "Tau minus: " << tauminus << endl ;
219  cout << "Tau plus: " << tauplus << endl ;
220  cout << "AGamma: " << (tauminus - tauplus)/(tauminus + tauplus) << endl ;
221 
222  if( m_h_efficiency != NULL){
223  m_efficiencyFit = TSpline3(m_h_efficiency) ;
224  }
225 }
const DalitzEventPattern m_cppattern
bool add(const AmpPair &other)
Definition: AmpPair.cpp:91
bool exists(const string &fname)
const DalitzEventPattern m_pattern
std::list< GenTimePoint > GenList
AmpPair amplitude_coefficients(const int tag, const double decaytime)
std::map< int, SplineGenerator > m_timegenerators
static DalitzEventPattern anti(DalitzEventPattern pat)

Member Function Documentation

◆ amplitude_coefficients()

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

Definition at line 230 of file TimeDependentGeneratorOld.cpp.

230  {
231  double coeff = exp(-decaytime * 0.5 * (m_width + 0.5 * m_deltagamma)) ;
232  complex<double> expterm = exp(complex<double>(0.5 * m_deltagamma * decaytime, m_deltam * decaytime)) ;
233  complex<double> plusterm = 1. + expterm ;
234  complex<double> minusterm = 1. - expterm ;
235  complex<double> coeffprod = coeff * plusterm ;
236  complex<double> coeffmix = pow(polar(m_qoverp, m_phi), tag) * coeff * minusterm ;
237  return AmpPair(coeffprod, coeffmix) ;
238 }
std::pair< std::complex< double >, std::complex< double > > AmpPair

◆ anti()

DalitzEventPattern TimeDependentGeneratorOld::anti ( DalitzEventPattern  pat)
static

Definition at line 78 of file TimeDependentGeneratorOld.cpp.

78  {
79  pat[0].antiThis() ;
80  return pat ;
81 }

◆ generate_dalitz_event()

MINT::counted_ptr< IDalitzEvent > TimeDependentGeneratorOld::generate_dalitz_event ( const int  tag,
const double  decaytime 
) const

Definition at line 257 of file TimeDependentGeneratorOld.cpp.

257  {
258  const GenList& genlist = m_genmap.find(tag)->second ;
259  GenList::const_iterator igen = genlist.begin() ;
260  while(igen->decaytime < decaytime && igen != genlist.end())
261  ++igen ;
262  if(igen == genlist.end()){
263  cerr << "TimeDependentGeneratorOld::generate_dalitz_event: ERROR: Got impossible decay time: "
264  << decaytime << " (tmax = " << m_tmax << ")" << endl ;
266  }
267  // Unlikely, but best to check.
268  if(decaytime == igen->decaytime)
269  return igen->generator->newEvent() ;
270  GenList::const_iterator igenprev(igen) ;
271  --igen ;
272  // Pick between the generators either side of the decay time according to how close they are to it.
273  double gensel = m_rndm->Rndm() ;
274  if(gensel < 1. - (decaytime - igenprev->decaytime)/(igen->decaytime - igenprev->decaytime))
275  return igenprev->generator->newEvent() ;
276  return igen->generator->newEvent() ;
277 }
std::list< GenTimePoint > GenList

◆ generate_decay_time()

double TimeDependentGeneratorOld::generate_decay_time ( const int  tag) const

Definition at line 249 of file TimeDependentGeneratorOld.cpp.

249  {
250  double decaytime = m_tmax + 1. ;
251  while(decaytime > m_tmax)
252  decaytime = m_timegenerators.find(tag)->second.gen_random() ;
253  return decaytime ;
254 }
std::map< int, SplineGenerator > m_timegenerators

◆ generate_event()

MINT::counted_ptr< IDalitzEvent > TimeDependentGeneratorOld::generate_event ( ) const

Definition at line 280 of file TimeDependentGeneratorOld.cpp.

280  {
281  int tag = generate_tag() ;
282  double decaytime = generate_decay_time(tag) ;
283  double smeareddecaytime = -999. ;
284 
285  smeareddecaytime = decaytime + m_rndm->Gaus(0, m_resWidth) ;
286 
287  if ( (m_h_efficiency != NULL) && (m_addExpEffects) ){
288  int i = 0 ;
289  float efficiency = 0 ;
290  int maxiter = 100000 ;
291  while(true){
292  if( smeareddecaytime > m_efficiencyFit.GetXmax() ){
293  efficiency = m_efficiencyFit.Eval( m_efficiencyFit.GetXmax() ) ;
294  }
295  else if( smeareddecaytime > m_efficiencyFit.GetXmin() ){
296  efficiency = m_efficiencyFit.Eval( smeareddecaytime ) ;
297  }
298  else{
299  efficiency = m_efficiencyFit.Eval( m_efficiencyFit.GetXmin() ) ;
300  }
301 
302  if(m_rndm->Rndm() < efficiency){
303  break;
304  }
305 
306  tag = generate_tag() ;
307  decaytime = generate_decay_time(tag) ;
308  smeareddecaytime = decaytime + m_rndm->Gaus(0, m_resWidth);
309 
310  i += 1 ;
311  if( i > maxiter ){
312  cout << "WARNING: Decay time generation limit exceeded." << endl ;
313  break ;
314  }
315  }
316  }
318  return MINT::counted_ptr<IDalitzEvent>(new GenTimeEvent(*evt, tag, decaytime, smeareddecaytime)) ;
319 }
MINT::counted_ptr< IDalitzEvent > generate_dalitz_event(const int tag, const double decaytime) const
double generate_decay_time(const int tag) const

◆ generate_tag()

int TimeDependentGeneratorOld::generate_tag ( ) const

Definition at line 241 of file TimeDependentGeneratorOld.cpp.

241  {
242  double rndm = m_rndm->Rndm() ;
243  if(rndm < m_tagintegralfrac)
244  return -1 ;
245  return 1 ;
246 }

◆ time_generators()

const map< int, SplineGenerator > TimeDependentGeneratorOld::time_generators ( ) const

Definition at line 322 of file TimeDependentGeneratorOld.cpp.

322  {
323  return m_timegenerators;
324 }
std::map< int, SplineGenerator > m_timegenerators

Member Data Documentation

◆ m_addExpEffects

bool TimeDependentGeneratorOld::m_addExpEffects
private

Definition at line 126 of file TimeDependentGeneratorOld.h.

◆ m_cppattern

const DalitzEventPattern TimeDependentGeneratorOld::m_cppattern
private

Definition at line 103 of file TimeDependentGeneratorOld.h.

◆ m_deltagamma

const double TimeDependentGeneratorOld::m_deltagamma
private

Definition at line 107 of file TimeDependentGeneratorOld.h.

◆ m_deltam

const double TimeDependentGeneratorOld::m_deltam
private

Definition at line 106 of file TimeDependentGeneratorOld.h.

◆ m_efficiencyFit

TSpline3 TimeDependentGeneratorOld::m_efficiencyFit
private

Definition at line 123 of file TimeDependentGeneratorOld.h.

◆ m_genmap

GenMap TimeDependentGeneratorOld::m_genmap
private

Definition at line 115 of file TimeDependentGeneratorOld.h.

◆ m_h_efficiency

TH1F* TimeDependentGeneratorOld::m_h_efficiency
private

Definition at line 122 of file TimeDependentGeneratorOld.h.

◆ m_name

const std::string TimeDependentGeneratorOld::m_name
private

Definition at line 100 of file TimeDependentGeneratorOld.h.

◆ m_ntimepoints

const int TimeDependentGeneratorOld::m_ntimepoints
private

Definition at line 113 of file TimeDependentGeneratorOld.h.

◆ m_pattern

const DalitzEventPattern TimeDependentGeneratorOld::m_pattern
private

Definition at line 102 of file TimeDependentGeneratorOld.h.

◆ m_phi

const double TimeDependentGeneratorOld::m_phi
private

Definition at line 109 of file TimeDependentGeneratorOld.h.

◆ m_precision

double TimeDependentGeneratorOld::m_precision
private

Definition at line 120 of file TimeDependentGeneratorOld.h.

◆ m_qoverp

const double TimeDependentGeneratorOld::m_qoverp
private

Definition at line 108 of file TimeDependentGeneratorOld.h.

◆ m_resWidth

float TimeDependentGeneratorOld::m_resWidth
private

Definition at line 125 of file TimeDependentGeneratorOld.h.

◆ m_rndm

TRandom3* TimeDependentGeneratorOld::m_rndm
private

Definition at line 101 of file TimeDependentGeneratorOld.h.

◆ m_tagintegralfrac

double TimeDependentGeneratorOld::m_tagintegralfrac
private

Definition at line 119 of file TimeDependentGeneratorOld.h.

◆ m_timegenerators

std::map<int, SplineGenerator> TimeDependentGeneratorOld::m_timegenerators
private

Definition at line 117 of file TimeDependentGeneratorOld.h.

◆ m_tmax

const double TimeDependentGeneratorOld::m_tmax
private

Definition at line 111 of file TimeDependentGeneratorOld.h.

◆ m_tmin

const double TimeDependentGeneratorOld::m_tmin
private

Definition at line 112 of file TimeDependentGeneratorOld.h.

◆ m_width

const double TimeDependentGeneratorOld::m_width
private

Definition at line 105 of file TimeDependentGeneratorOld.h.


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