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

#include <TimeBinning.h>

Classes

class  Bin
 

Public Types

typedef std::deque< BinBins
 
typedef std::deque< BinsBins2D
 

Public Member Functions

 TimeBinning (const std::vector< double > &, HadronicParameters::BinningPtr, double)
 
 TimeBinning (const std::string &, const std::string &fname="")
 
virtual ~TimeBinning ()
 
void add (IDalitzEvent &, int, double, double weight=1.)
 
HadronicParameters::BinningPtr phaseBinning () const
 
int timeBin (double) const
 
void Print (const std::string &, std::ostream &os=std::cout) const
 
void write (const std::string &, const std::string &) const
 
double chiSquared (unsigned, unsigned, double, double) const
 
unsigned nBinsTime () const
 
unsigned nBinsPhase () const
 
const BinintegratedBin (unsigned) const
 
const Binbin (unsigned, unsigned) const
 
const BinbinBar (unsigned, unsigned) const
 
std::deque< TH1F > plotVsTime (const std::string &, unsigned, int) const
 
std::deque< std::deque< TH1F > > plotsVsTime (const std::string &) const
 
void savePlotsVsTime (const std::string &, TFile &) const
 
double meanUnmixedTime (unsigned) const
 
double meanUnmixedTime2 (unsigned) const
 
void setLifetime (double)
 
double getLifetime () const
 
bool isConsistent (const TimeBinning &) const
 Check that two TimeBinnings use the same binning scheme. More...
 
TimeBinning operator+ (TimeBinning) const
 
TimeBinningoperator+= (const TimeBinning &)
 

Private Member Functions

Bin_integratedBin (unsigned)
 
Bin_bin (unsigned, unsigned)
 
Bin_binBar (unsigned, unsigned)
 
virtual double unmixedTimeMoment (unsigned, double, int) const
 

Private Attributes

std::vector< double > m_timeBins
 
std::vector< double > m_meant
 
std::vector< double > m_meant2
 
double m_lifetime
 
Bins2D m_bins
 
Bins2D m_binsBar
 
Bins m_binsInt
 
HadronicParameters::BinningPtr m_phaseBinning
 

Detailed Description

Definition at line 12 of file TimeBinning.h.

Member Typedef Documentation

◆ Bins

typedef std::deque<Bin> TimeBinning::Bins

Definition at line 41 of file TimeBinning.h.

◆ Bins2D

typedef std::deque<Bins> TimeBinning::Bins2D

Definition at line 42 of file TimeBinning.h.

Constructor & Destructor Documentation

◆ TimeBinning() [1/2]

TimeBinning::TimeBinning ( const std::vector< double > &  ,
HadronicParameters::BinningPtr  ,
double   
)

◆ TimeBinning() [2/2]

TimeBinning::TimeBinning ( const std::string &  ,
const std::string &  fname = "" 
)

◆ ~TimeBinning()

virtual TimeBinning::~TimeBinning ( )
inlinevirtual

Definition at line 46 of file TimeBinning.h.

46 {};

Member Function Documentation

◆ _bin()

TimeBinning::Bin & TimeBinning::_bin ( unsigned  iTimeBin,
unsigned  iPhaseBin 
)
private

Definition at line 274 of file TimeBinning.cpp.

274  {
275  return m_bins.at(iTimeBin).at(iPhaseBin-1) ;
276 }
Bins2D m_bins
Definition: TimeBinning.h:76

◆ _binBar()

TimeBinning::Bin & TimeBinning::_binBar ( unsigned  iTimeBin,
unsigned  iPhaseBin 
)
private

Definition at line 278 of file TimeBinning.cpp.

278  {
279  return m_binsBar.at(iTimeBin).at(iPhaseBin-1) ;
280 }
Bins2D m_binsBar
Definition: TimeBinning.h:77

◆ _integratedBin()

TimeBinning::Bin & TimeBinning::_integratedBin ( unsigned  i)
private

Definition at line 270 of file TimeBinning.cpp.

270  {
271  return m_binsInt.at(i) ;
272 }
Bins m_binsInt
Definition: TimeBinning.h:78

◆ add()

void TimeBinning::add ( IDalitzEvent evt,
int  tag,
double  t,
double  weight = 1. 
)

Definition at line 229 of file TimeBinning.cpp.

229  {
230  int timeBinNo = timeBin(t) ;
231  if(timeBinNo < 0)
232  return ;
233  int phaseBin = m_phaseBinning->binNumber(evt) ;
234  bool isPlus = phaseBin > 0 ;
235  if(tag > 0){
236  _bin(timeBinNo, abs(phaseBin)).add(t, isPlus, weight) ;
237  }
238  else{
239  isPlus = !isPlus ;
240  _binBar(timeBinNo, abs(phaseBin)).add(t, isPlus, weight) ;
241  }
242  _integratedBin(timeBinNo).add(t, isPlus, weight) ;
243 }
int timeBin(double) const
Bin & _binBar(unsigned, unsigned)
HadronicParameters::BinningPtr m_phaseBinning
Definition: TimeBinning.h:79
Bin & _bin(unsigned, unsigned)
Bin & _integratedBin(unsigned)
void add(double, bool, double weight=1.)
Definition: TimeBinning.cpp:72

◆ bin()

const TimeBinning::Bin & TimeBinning::bin ( unsigned  iTimeBin,
unsigned  iPhaseBin 
) const

Definition at line 262 of file TimeBinning.cpp.

262  {
263  return m_bins.at(iTimeBin).at(iPhaseBin-1) ;
264 }
Bins2D m_bins
Definition: TimeBinning.h:76

◆ binBar()

const TimeBinning::Bin & TimeBinning::binBar ( unsigned  iTimeBin,
unsigned  iPhaseBin 
) const

Definition at line 266 of file TimeBinning.cpp.

266  {
267  return m_binsBar.at(iTimeBin).at(iPhaseBin-1) ;
268 }
Bins2D m_binsBar
Definition: TimeBinning.h:77

◆ chiSquared()

double TimeBinning::chiSquared ( unsigned  iTimeBin,
unsigned  iPhaseBin,
double  Rplus,
double  Rminus 
) const

Definition at line 245 of file TimeBinning.cpp.

245  {
246  return bin(iTimeBin, iPhaseBin).chiSquared(Rplus)
247  + binBar(iTimeBin, iPhaseBin).chiSquared(Rminus) ;
248 }
const Bin & binBar(unsigned, unsigned) const
const Bin & bin(unsigned, unsigned) const
double chiSquared(double) const

◆ getLifetime()

double TimeBinning::getLifetime ( ) const

Definition at line 353 of file TimeBinning.cpp.

353  {
354  return m_lifetime ;
355 }
double m_lifetime
Definition: TimeBinning.h:75

◆ integratedBin()

const TimeBinning::Bin & TimeBinning::integratedBin ( unsigned  i) const

Definition at line 258 of file TimeBinning.cpp.

258  {
259  return m_binsInt.at(i) ;
260 }
Bins m_binsInt
Definition: TimeBinning.h:78

◆ isConsistent()

bool TimeBinning::isConsistent ( const TimeBinning other) const

Check that two TimeBinnings use the same binning scheme.

Definition at line 366 of file TimeBinning.cpp.

366  {
367  return m_timeBins == other.m_timeBins && m_meant == other.m_meant && m_meant2 == other.m_meant2 \
368  && m_lifetime == other.m_lifetime && *m_phaseBinning == *other.m_phaseBinning;
369 }
double m_lifetime
Definition: TimeBinning.h:75
HadronicParameters::BinningPtr m_phaseBinning
Definition: TimeBinning.h:79
std::vector< double > m_meant2
Definition: TimeBinning.h:74
std::vector< double > m_meant
Definition: TimeBinning.h:73
std::vector< double > m_timeBins
Definition: TimeBinning.h:72

◆ meanUnmixedTime()

double TimeBinning::meanUnmixedTime ( unsigned  ibin) const

Definition at line 357 of file TimeBinning.cpp.

357  {
358  return m_meant.at(ibin) ;
359 }
std::vector< double > m_meant
Definition: TimeBinning.h:73

◆ meanUnmixedTime2()

double TimeBinning::meanUnmixedTime2 ( unsigned  ibin) const

Definition at line 361 of file TimeBinning.cpp.

361  {
362  return m_meant2.at(ibin) ;
363 }
std::vector< double > m_meant2
Definition: TimeBinning.h:74

◆ nBinsPhase()

unsigned TimeBinning::nBinsPhase ( ) const

Definition at line 254 of file TimeBinning.cpp.

254  {
255  return m_phaseBinning->nBins ;
256 }
HadronicParameters::BinningPtr m_phaseBinning
Definition: TimeBinning.h:79

◆ nBinsTime()

unsigned TimeBinning::nBinsTime ( ) const

Definition at line 250 of file TimeBinning.cpp.

250  {
251  return m_timeBins.size()-1 ;
252 }
std::vector< double > m_timeBins
Definition: TimeBinning.h:72

◆ operator+()

TimeBinning TimeBinning::operator+ ( TimeBinning  other) const

Definition at line 371 of file TimeBinning.cpp.

371  {
372  return other += *this;
373 }

◆ operator+=()

TimeBinning & TimeBinning::operator+= ( const TimeBinning other)

Definition at line 390 of file TimeBinning.cpp.

390  {
391  if(!isConsistent(other))
392  throw std::invalid_argument("Attempt to combine incompatible TimeBinning instances!");
393  //m_bins += other.m_bins;
394  //m_binsBar += other.m_binsBar;
395  //m_binsInt += other.m_binsInt;
396  for(unsigned iTimeBin = 0; iTimeBin < nBinsTime(); ++iTimeBin){
397  m_binsInt.at(iTimeBin) += other.m_binsInt.at(iTimeBin);
398  for(unsigned iPhaseBin = 0; iPhaseBin < nBinsPhase(); ++iPhaseBin){
399  m_bins.at(iTimeBin).at(iPhaseBin) += other.m_bins.at(iTimeBin).at(iPhaseBin);
400  m_binsBar.at(iTimeBin).at(iPhaseBin) += other.m_binsBar.at(iTimeBin).at(iPhaseBin);
401  }
402  }
403  return *this;
404 }
unsigned nBinsPhase() const
Bins2D m_bins
Definition: TimeBinning.h:76
Bins m_binsInt
Definition: TimeBinning.h:78
bool isConsistent(const TimeBinning &) const
Check that two TimeBinnings use the same binning scheme.
Bins2D m_binsBar
Definition: TimeBinning.h:77
unsigned nBinsTime() const

◆ phaseBinning()

HadronicParameters::BinningPtr TimeBinning::phaseBinning ( ) const

Definition at line 218 of file TimeBinning.cpp.

218  {
219  return m_phaseBinning ;
220 }
HadronicParameters::BinningPtr m_phaseBinning
Definition: TimeBinning.h:79

◆ plotsVsTime()

deque< deque< TH1F > > TimeBinning::plotsVsTime ( const std::string &  ) const

Definition at line 308 of file TimeBinning.cpp.

308  {
309  deque<deque<TH1F> > histos ;
310  for(unsigned iphase = 1 ; iphase < m_phaseBinning->nBins + 1 ; ++iphase){
311  histos.push_back(deque<TH1F>()) ;
312  deque<TH1F>& binhistos = histos.back() ;
313  for(int tag = -1 ; tag < 2 ; tag += 2){
314  deque<TH1F> taghistos = plotVsTime(name, iphase, tag) ;
315  binhistos.insert(binhistos.end(), taghistos.begin(), taghistos.end()) ;
316  }
317  TH1F rdiff(binhistos.back()) ;
318  string rdiffname(Bin::getName(name + "_phase", iphase) + "ratiodiff") ;
319  rdiff.SetName(rdiffname.c_str()) ;
320  rdiff.Add(&binhistos[2], -1.) ;
321  binhistos.push_back(rdiff) ;
322  }
323  return histos ;
324 }
std::deque< TH1F > plotVsTime(const std::string &, unsigned, int) const
static std::string getName(const std::string &, unsigned)
Definition: TimeBinning.cpp:66
HadronicParameters::BinningPtr m_phaseBinning
Definition: TimeBinning.h:79

◆ plotVsTime()

deque< TH1F > TimeBinning::plotVsTime ( const std::string &  ,
unsigned  ,
int   
) const

Definition at line 282 of file TimeBinning.cpp.

282  {
283  ostringstream stag ;
284  stag << tag ;
285  string name = Bin::getName(_name + "_" + stag.str() + "_phase", phaseBin) ;
286 
287  TH1F hplus((name + "nPlus").c_str(), "", nBinsTime(), &m_timeBins[0]) ;
288  TH1F hminus((name + "nMinus").c_str(), "", nBinsTime(), &m_timeBins[0]) ;
289  TH1F hr((name + "ratio").c_str(), "", nBinsTime(), &m_timeBins[0]) ;
290  for(unsigned i = 1 ; i < nBinsTime()+1 ; ++i) {
291  const Bin& pbin = tag > 0 ? bin(i-1, phaseBin) : binBar(i-1, phaseBin) ;
292  hplus.SetBinContent(i, pbin.nPlus()) ;
293  hplus.SetBinError(i, pbin.nPlusErr()) ;
294  hminus.SetBinContent(i, pbin.nMinus()) ;
295  hminus.SetBinError(i, pbin.nMinusErr()) ;
296  double r = pbin.nPlus() > 0. ? pbin.nMinus()/pbin.nPlus() : 0. ;
297  double rerr = r > 0 && pbin.nMinus() > 0 ? r * sqrt(pow(pbin.nPlusErr()/pbin.nPlus(), 2) + pow(pbin.nMinusErr()/pbin.nMinus(), 2)) : 0. ;
298  hr.SetBinContent(i, r) ;
299  hr.SetBinError(i, rerr) ;
300  }
301  deque<TH1F> histos ;
302  histos.push_back(hplus) ;
303  histos.push_back(hminus) ;
304  histos.push_back(hr) ;
305  return histos ;
306 }
static std::string getName(const std::string &, unsigned)
Definition: TimeBinning.cpp:66
const Bin & binBar(unsigned, unsigned) const
const Bin & bin(unsigned, unsigned) const
std::vector< double > m_timeBins
Definition: TimeBinning.h:72
double nPlus() const
Definition: TimeBinning.cpp:96
unsigned nBinsTime() const

◆ Print()

void TimeBinning::Print ( const std::string &  ,
std::ostream &  os = std::cout 
) const

Definition at line 189 of file TimeBinning.cpp.

189  {
190  os.precision(16) ;
191  os << name << "_timeBins" ;
192  for(const auto& bin : m_timeBins)
193  os << "\t" << bin ;
194  os << endl ;
195  os << name << "_lifetime\t" << m_lifetime << endl ;
196  string nameint = name + "_int" ;
197  string nameplus = name + "_plus" ;
198  string nameminus = name + "_minus" ;
199  for(unsigned iTimeBin = 0 ; iTimeBin < nBinsTime() ; ++iTimeBin){
200  m_binsInt[iTimeBin].Print(nameint, iTimeBin, os) ;
201  string nameplusbin = Bin::getName(nameplus + "_time", iTimeBin) + "phase" ;
202  string nameminusbin = Bin::getName(nameminus + "_time", iTimeBin) + "phase" ;
203  for(unsigned iPhaseBin = 1 ; iPhaseBin < m_phaseBinning->nBins + 1; ++iPhaseBin){
204  bin(iTimeBin, iPhaseBin).Print(nameplusbin, iPhaseBin, os) ;
205  binBar(iTimeBin, iPhaseBin).Print(nameminusbin, iPhaseBin, os) ;
206  }
207  }
208  m_phaseBinning->Print(name, os) ;
209 }
static std::string getName(const std::string &, unsigned)
Definition: TimeBinning.cpp:66
const Bin & binBar(unsigned, unsigned) const
double m_lifetime
Definition: TimeBinning.h:75
void Print(const std::string &, unsigned, std::ostream &os=std::cout) const
Definition: TimeBinning.cpp:53
HadronicParameters::BinningPtr m_phaseBinning
Definition: TimeBinning.h:79
Bins m_binsInt
Definition: TimeBinning.h:78
const Bin & bin(unsigned, unsigned) const
std::vector< double > m_timeBins
Definition: TimeBinning.h:72
unsigned nBinsTime() const

◆ savePlotsVsTime()

void TimeBinning::savePlotsVsTime ( const std::string &  ,
TFile &   
) const

Definition at line 326 of file TimeBinning.cpp.

326  {
327  outputfile.cd() ;
328  deque<deque<TH1F> > histos = plotsVsTime(name) ;
329  for(auto& binhistos : histos)
330  for(auto& histo : binhistos)
331  histo.Write() ;
332 }
std::deque< std::deque< TH1F > > plotsVsTime(const std::string &) const

◆ setLifetime()

void TimeBinning::setLifetime ( double  lifetime)

Definition at line 345 of file TimeBinning.cpp.

345  {
346  m_lifetime = lifetime ;
347  for(unsigned ibin = 0 ; ibin < nBinsTime() ; ++ibin){
348  m_meant.at(ibin) = unmixedTimeMoment(ibin, lifetime, 1) ;
349  m_meant2.at(ibin) = unmixedTimeMoment(ibin, lifetime, 2) ;
350  }
351 }
double m_lifetime
Definition: TimeBinning.h:75
std::vector< double > m_meant2
Definition: TimeBinning.h:74
virtual double unmixedTimeMoment(unsigned, double, int) const
std::vector< double > m_meant
Definition: TimeBinning.h:73
unsigned nBinsTime() const

◆ timeBin()

int TimeBinning::timeBin ( double  t) const

Definition at line 222 of file TimeBinning.cpp.

222  {
223  for(unsigned i = 0 ; i < nBinsTime() ; ++i)
224  if(m_timeBins[i] <= t && t < m_timeBins[i+1])
225  return i ;
226  return -1 ;
227 }
std::vector< double > m_timeBins
Definition: TimeBinning.h:72
unsigned nBinsTime() const

◆ unmixedTimeMoment()

double TimeBinning::unmixedTimeMoment ( unsigned  ibin,
double  lifetime,
int  moment 
) const
privatevirtual

Definition at line 334 of file TimeBinning.cpp.

334  {
335  const double& tmin = m_timeBins.at(ibin) ;
336  const double& tmax = m_timeBins.at(ibin+1) ;
337  double norm = exp(-tmin/lifetime) - exp(-tmax/lifetime) ;
338  double timeMoment = (pow(tmin, moment) * exp(-tmin/lifetime) - pow(tmax, moment) * exp(-tmax/lifetime))/norm ;
339  if(moment == 0)
340  return timeMoment ;
341  timeMoment += moment * lifetime * unmixedTimeMoment(ibin, lifetime, moment-1) ;
342  return timeMoment ;
343 }
virtual double unmixedTimeMoment(unsigned, double, int) const
std::vector< double > m_timeBins
Definition: TimeBinning.h:72

◆ write()

void TimeBinning::write ( const std::string &  ,
const std::string &   
) const

Definition at line 211 of file TimeBinning.cpp.

211  {
212  ofstream outfile ;
213  outfile.open(fname) ;
214  Print(name, outfile) ;
215  outfile.close() ;
216 }
void Print(const std::string &, std::ostream &os=std::cout) const

Member Data Documentation

◆ m_bins

Bins2D TimeBinning::m_bins
private

Definition at line 76 of file TimeBinning.h.

◆ m_binsBar

Bins2D TimeBinning::m_binsBar
private

Definition at line 77 of file TimeBinning.h.

◆ m_binsInt

Bins TimeBinning::m_binsInt
private

Definition at line 78 of file TimeBinning.h.

◆ m_lifetime

double TimeBinning::m_lifetime
private

Definition at line 75 of file TimeBinning.h.

◆ m_meant

std::vector<double> TimeBinning::m_meant
private

Definition at line 73 of file TimeBinning.h.

◆ m_meant2

std::vector<double> TimeBinning::m_meant2
private

Definition at line 74 of file TimeBinning.h.

◆ m_phaseBinning

HadronicParameters::BinningPtr TimeBinning::m_phaseBinning
private

Definition at line 79 of file TimeBinning.h.

◆ m_timeBins

std::vector<double> TimeBinning::m_timeBins
private

Definition at line 72 of file TimeBinning.h.


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