19 #include "RooRealConstant.h" 20 #include "RooAbsReal.h" 21 #include "RooRealVar.h" 22 #include "RooDataSet.h" 23 #include "RooGlobalFunc.h" 24 #include "RooRealVar.h" 26 #include "RooBDecay.h" 28 #include "RooEffProd.h" 29 #include "RooGenericPdf.h" 30 #include "RooGaussModel.h" 31 #include "RooProdPdf.h" 32 #include "RooConstVar.h" 33 #include "RooCategory.h" 34 #include "RooDataHist.h" 35 #include "RooHistPdf.h" 36 #include "RooAddPdf.h" 37 #include "RooUniform.h" 38 #include "RooExponential.h" 39 #include "RooRandom.h" 40 #include "RooGaussian.h" 41 #include "RooMultiVarGaussian.h" 42 #include "RooTruthModel.h" 44 #include "RooGlobalFunc.h" 68 #include <TLorentzVector.h> 74 using namespace RooFit ;
181 double val = un_normalised(evt);
244 std::pair<double, double>
getCalibratedMistag(
double eta,
double avg_eta,
double p0,
double p1,
double delta_p0,
double delta_p1 ){
260 if(0 == evt)
return 0;
264 if(0 == evt)
return 0;
265 return getVal_withPs(*evt);
268 if(0 == evt)
return 0;
269 return getVal_noPs(*evt);
280 for(
int i=0; i< eventListData.
size(); i++)
285 int N_sample = eventListDataSideband.
size();
287 vector<int> b_indices;
288 while( b_indices.size() < N )b_indices.push_back(TMath::Nint(gRandom->Uniform(0,N_sample)));
289 sort(b_indices.begin(), b_indices.end());
292 for(
int i=0; i< N; i++)
294 DalitzEvent evt = eventListDataSideband[b_indices[i]];
297 saveEventListToFile(eventList);
302 cout <<
"Generating " << N <<
" events" << endl;
305 RooDataSet* sample = sampleEvents(N);
307 for(
int i = 0; i < sample->numEntries(); i++){
309 RooArgSet* sample_set= (RooArgSet*)sample->get(i);
311 double t_MC = ((RooRealVar*)sample_set->find(
"t"))->getVal() ;
312 double dt_MC = ((RooRealVar*)sample_set->find(
"dt"))->getVal() ;
313 double eta_OS_MC = ((RooRealVar*)sample_set->find(
"eta_OS"))->getVal() ;
314 double eta_SS_MC = ((RooRealVar*)sample_set->find(
"eta_SS"))->getVal() ;
316 int f_MC = ((RooCategory*)sample_set->find(
"qf"))->getIndex() ;
317 int q_OS_MC = ((RooCategory*)sample_set->find(
"q_OS"))->getIndex() ;
318 int q_SS_MC = ((RooCategory*)sample_set->find(
"q_SS"))->getIndex() ;
338 time_t startTime = time(0);
340 cout <<
"Generating " << N <<
" events" << endl;
345 for(
int i = 0; i < 100000; i++){
351 cout <<
"Now calculating maximum val " << vals.size() << endl;
356 if(!TMath::IsNaN(pmax) && pmax > 0 && pmax < 100 * amax)pdf_max = pmax;
357 else if(!TMath::IsNaN(amax))pdf_max = amax;
361 cout <<
"pdf_max " << pdf_max << endl;
369 const double height = gRandom->Uniform(0,pdf_max);
372 if( pdfVal > pdf_max ){
373 std::cout <<
"ERROR: PDF above determined maximum." << std::endl;
374 std::cout << pdfVal <<
" > " << pdf_max << std::endl;
375 pdf_max = pdf_max * 2.;
379 if( height < pdfVal ) {
390 cout <<
" Done. " <<
" Total time since start " << (time(0) - startTime)/60.0 <<
" min." << endl;
391 cout <<
"Generated " << N_gen <<
" events ! Efficiecy = " << (double)N_gen/(
double)N_tot << endl;
399 TFile* out =
new TFile(name.c_str(),
"RECREATE");
400 TTree* tree =
new TTree(
"DecayTree",
"DecayTree");
417 TBranch* br_mB = tree->Branch(
"Bs_DTF_MM", &mB,
"Bs_DTF_MM/D" );
418 TBranch* br_sw = tree->Branch(
"N_Bs_sw", &sw,
"N_Bs_sw/D" );
419 TBranch* br_w = tree->Branch(
"weight", &w,
"weight/D" );
421 TBranch* br_t = tree->Branch(
"Bs_BsDTF_TAU", &t,
"Bs_BsDTF_TAU/D" );
422 TBranch* br_dt = tree->Branch(
"Bs_BsDTF_TAUERR", &dt,
"Bs_BsDTF_TAUERR/D" );
424 TBranch* br_Ds_ID = tree->Branch(
"Ds_ID",&Ds_ID,
"Ds_ID/I");
426 TBranch* br_q_OS =tree->Branch(
"OS_Combination_DEC",&q_OS,
"OS_Combination_DEC/I");
427 TBranch* br_eta_OS = tree->Branch(
"OS_Combination_PROB",&eta_OS,
"OS_Combination_PROB/D");
428 TBranch* br_q_SS = tree->Branch(
"SS_Kaon_DEC",&q_SS,
"SS_Kaon_DEC/I");
429 TBranch* br_eta_SS = tree->Branch(
"SS_Kaon_PROB",&eta_SS,
"SS_Kaon_PROB/D");
431 TBranch* br_run = tree->Branch(
"run",&run,
"run/I");
432 TBranch* br_year = tree->Branch(
"year", &year,
"year/I" );
433 TBranch* br_trigger = tree->Branch(
"TriggerCat",&trigger,
"TriggerCat/I");
435 TBranch* br_K0 = tree->Branch(
"BsDTF_Kplus_PX",&K[0],
"BsDTF_Kplus_PX/D");
436 TBranch* br_K1 =tree->Branch(
"BsDTF_Kplus_PY",&K[1],
"BsDTF_Kplus_PY/D");
437 TBranch* br_K2 =tree->Branch(
"BsDTF_Kplus_PZ",&K[2],
"BsDTF_Kplus_PZ/D");
438 TBranch* br_K3 =tree->Branch(
"BsDTF_Kplus_PE",&K[3],
"BsDTF_Kplus_PE/D");
440 TBranch* br_pip0 =tree->Branch(
"BsDTF_piplus_PX",&pip[0],
"BsDTF_piplus_PX/D");
441 TBranch* br_pip1 =tree->Branch(
"BsDTF_piplus_PY",&pip[1],
"BsDTF_piplus_PY/D");
442 TBranch* br_pip2 =tree->Branch(
"BsDTF_piplus_PZ",&pip[2],
"BsDTF_piplus_PZ/D");
443 TBranch* br_pip3 =tree->Branch(
"BsDTF_piplus_PE",&pip[3],
"BsDTF_piplus_PE/D");
445 TBranch* br_pim0 =tree->Branch(
"BsDTF_piminus_PX",&pim[0],
"BsDTF_piminus_PX/D");
446 TBranch* br_pim1 =tree->Branch(
"BsDTF_piminus_PY",&pim[1],
"BsDTF_piminus_PY/D");
447 TBranch* br_pim2 =tree->Branch(
"BsDTF_piminus_PZ",&pim[2],
"BsDTF_piminus_PZ/D");
448 TBranch* br_pim3 =tree->Branch(
"BsDTF_piminus_PE",&pim[3],
"BsDTF_piminus_PE/D");
450 TBranch* br_Ds0 =tree->Branch(
"BsDTF_Ds_PX",&Ds[0],
"BsDTF_Ds_PX/D");
451 TBranch* br_Ds1 =tree->Branch(
"BsDTF_Ds_PY",&Ds[1],
"BsDTF_Ds_PY/D");
452 TBranch* br_Ds2 =tree->Branch(
"BsDTF_Ds_PZ",&Ds[2],
"BsDTF_Ds_PZ/D");
453 TBranch* br_Ds3 =tree->Branch(
"BsDTF_Ds_PE",&Ds[3],
"BsDTF_Ds_PE/D");
455 for(
int i= 0; i < eventList.
size(); i++){
457 t = eventList[i].getValueFromVector(0);
458 dt = eventList[i].getValueFromVector(1);
460 Ds_ID = - eventList[i].getValueFromVector(2);
462 q_OS = eventList[i].getValueFromVector(3);
463 eta_OS = eventList[i].getValueFromVector(4);
465 q_SS = eventList[i].getValueFromVector(5);
466 eta_SS = eventList[i].getValueFromVector(6);
468 run = eventList[i].getValueFromVector(7);
469 if(run == 2) year = 16;
470 else if(run == 3) year = 17;
472 trigger = eventList[i].getValueFromVector(8);
474 mB = eventList[i].p(0).M();
475 sw = eventList[i].getWeight();
476 w = eventList[i].getWeight();
478 Ds[0] = eventList[i].p(1).Px()/
MeV;
479 Ds[1] = eventList[i].p(1).Py()/
MeV;
480 Ds[2] = eventList[i].p(1).Pz()/
MeV;
481 Ds[3] = eventList[i].p(1).E()/
MeV;
483 K[0] = eventList[i].p(2).Px()/
MeV;
484 K[1] = eventList[i].p(2).Py()/
MeV;
485 K[2] = eventList[i].p(2).Pz()/
MeV;
486 K[3] = eventList[i].p(2).E()/
MeV;
488 pip[0] = eventList[i].p(3).Px()/
MeV;
489 pip[1] = eventList[i].p(3).Py()/
MeV;
490 pip[2] = eventList[i].p(3).Pz()/
MeV;
491 pip[3] = eventList[i].p(3).E()/
MeV;
493 pim[0] = eventList[i].p(4).Px()/
MeV;
494 pim[1] = eventList[i].p(4).Py()/
MeV;
495 pim[2] = eventList[i].p(4).Pz()/
MeV;
496 pim[3] = eventList[i].p(4).E()/
MeV;
509 double t_MC = gRandom->Exp(1./_Gamma);
511 if(t_MC > _max_TAU || t_MC < _min_TAU)
continue;
516 double dt_MC = marginal_vals[0] ;
517 double eta_OS_MC = marginal_vals[1] ;
518 double eta_SS_MC = marginal_vals[2] ;
520 int f_MC = (gRandom->Uniform() > 0.5) ? 1 : -1;
523 int q_MC = (gRandom->Uniform() > 0.5) ? 1 : -1;
525 int q_SS_MC = (gRandom->Uniform() > 2./3.) ? 0 : q_MC ;
526 int q_OS_MC = (gRandom->Uniform() > 2./3.) ? 0 : q_MC ;
528 q_OS_MC = (gRandom->Uniform() < 0.5) ? - q_OS_MC : q_OS_MC;
529 q_SS_MC = (gRandom->Uniform() < 0.5) ? - q_SS_MC : q_SS_MC;
531 eta_OS_MC = (q_OS_MC == 0) ? 0.5 : eta_OS_MC;
532 eta_SS_MC = (q_SS_MC == 0) ? 0.5 : eta_SS_MC;
577 _offset_sigma_dt(offset_sigma_dt),
578 _scale_mean_dt(scale_mean_dt),
579 _scale_sigma_dt(scale_sigma_dt),
580 _scale_sigma_2_dt(scale_sigma_2_dt),
593 _delta_p0_os(delta_p0_os),
594 _delta_p1_os(delta_p1_os),
595 _avg_eta_os(avg_eta_os),
596 _tageff_os(tageff_os),
597 _tageff_asym_os(tageff_asym_os),
600 _delta_p0_ss(delta_p0_ss),
601 _delta_p1_ss(delta_p1_ss),
602 _avg_eta_ss(avg_eta_ss),
603 _tageff_ss(tageff_ss),
604 _tageff_asym_ss(tageff_asym_ss),
605 _production_asym(production_asym),
606 _detection_asym(detection_asym),
607 _marginalPdfsPrefix(marginalPdfsPrefix),
608 _min_TAU(
"min_TAU", 0.4),
609 _max_TAU(
"max_TAU", 10.),
610 _min_TAUERR(
"min_TAUERR", 0.),
611 _max_TAUERR(
"max_TAUERR", 0.1)
614 ,_offset_sigma_dt, _scale_mean_dt, _scale_sigma_dt, _scale_sigma_2_dt
619 _p0_os, _p1_os, _delta_p0_os, _delta_p1_os,
620 _avg_eta_os, _tageff_os, _tageff_asym_os,
621 _p0_ss, p1_ss, _delta_p0_ss, _delta_p1_ss,
622 _avg_eta_ss, _tageff_ss, _tageff_asym_ss,
623 _production_asym, _detection_asym,_marginalPdfsPrefix);
629 _k * _D, _k * _D_bar,
630 _k * _S, _k * _S_bar );
std::pair< double, double > getCalibratedMistag_SS(double &eta_SS)
virtual double getValueFromVector(unsigned int i) const
const MINT::FitParameter & _c2
virtual bool Add(const EVENT_TYPE &evt)
vector< double > getRandom_marginalVals()
double getCalibratedResolution(double dt)
const FitParameter & _D_bar
std::pair< double, double > getCalibratedMistag_SS(IDalitzEvent &evt)
const MINT::FitParameter & _dGamma
const MINT::FitParameter & _p1_ss
const MINT::FitParameter & _scale_sigma_dt
const MINT::FitParameter & _tageff_asym_ss
DalitzEventList generateToys(int N=10000, int run=-1, int trigger=-1)
RooDataSet * sampleEvents(int N=10000)
NamedParameter< double > _min_TAUERR
NamedParameter< double > _max_TAU
virtual void CP_conjugateYourself()
void saveEventListToFile(DalitzEventList &eventList, string name="toys.root")
DalitzEvent generateWeightedEvent()
const MINT::FitParameter & _c9
double un_normalised(IDalitzEvent &evt)
double get_cosh_term_Integral(IDalitzEvent &evt)
void setCP_coeff(double norm, double norm_bar, double C, double C_bar, double D, double D_bar, double S, double S_bar)
double getNorm(IDalitzEvent &evt)
const FitParameter & _S_bar
double generalisedPareto_estimateMaximum(const std::vector< double > &input, double CL=0.001)
virtual void setValueInVector(unsigned int i, double value)
const MINT::FitParameter & _tageff_ss
const MINT::FitParameter & _scale_sigma_2_dt
DalitzEventList generateToysRooFit(int N=10000, int run=-1, int trigger=-1)
double get_cos_term_Val(IDalitzEvent &evt)
double getCalibratedResolution(double &dt)
virtual double getVal_withPs(IDalitzEvent *evt)
FullTimePdf(const MINT::FitParameter &C, const MINT::FitParameter &D, const MINT::FitParameter &D_bar, const MINT::FitParameter &S, const MINT::FitParameter &S_bar, const MINT::FitParameter &k, const MINT::FitParameter &Gamma, const MINT::FitParameter &dGamma, const MINT::FitParameter &dm, const MINT::FitParameter &offset_sigma_dt, const MINT::FitParameter &scale_mean_dt, const MINT::FitParameter &scale_sigma_dt, const MINT::FitParameter &scale_sigma_2_dt, const MINT::FitParameter &c0, const MINT::FitParameter &c1, const MINT::FitParameter &c2, const MINT::FitParameter &c3, const MINT::FitParameter &c4, const MINT::FitParameter &c5, const MINT::FitParameter &c6, const MINT::FitParameter &c7, const MINT::FitParameter &c8, const MINT::FitParameter &c9, const MINT::FitParameter &p0_os, const MINT::FitParameter &p1_os, const MINT::FitParameter &delta_p0_os, const MINT::FitParameter &delta_p1_os, const MINT::FitParameter &avg_eta_os, const MINT::FitParameter &tageff_os, const MINT::FitParameter &tageff_asym_os, const MINT::FitParameter &p0_ss, const MINT::FitParameter &p1_ss, const MINT::FitParameter &delta_p0_ss, const MINT::FitParameter &delta_p1_ss, const MINT::FitParameter &avg_eta_ss, const MINT::FitParameter &tageff_ss, const MINT::FitParameter &tageff_asym_ss, const MINT::FitParameter &production_asym, const MINT::FitParameter &detection_asym, string marginalPdfsPrefix="")
const MINT::FitParameter & _p0_ss
const MINT::FitParameter & _c8
std::pair< double, double > getCalibratedMistag(double eta, double avg_eta, double p0, double p1, double delta_p0, double delta_p1)
double get_sinh_term_Integral(IDalitzEvent &evt)
double getSamplingPdfVal(IDalitzEvent &evt)
double getSampledPdfVal(IDalitzEvent &evt)
const MINT::FitParameter & _tageff_asym_os
const MINT::FitParameter & _c0
virtual double getVal(IDalitzEvent *evt)
void setAllFitParameters()
double get_sin_term_Integral(IDalitzEvent &evt)
TimePdfMaster * _timePdfMaster
std::pair< double, double > getCalibratedMistag_SS(IDalitzEvent &evt)
NamedParameter< double > _min_TAU
const MINT::FitParameter & _production_asym
const MINT::FitParameter & _c4
std::pair< double, double > getCalibratedMistag(double eta, double avg_eta, double p0, double p1, double delta_p0, double delta_p1)
std::pair< double, double > getCalibratedMistag_OS(IDalitzEvent &evt)
const MINT::FitParameter & _c5
virtual double getVal_withPs(IDalitzEvent &evt)
virtual double getGeneratorPdfRelativeToPhaseSpace() const
const MINT::FitParameter & _avg_eta_os
const MINT::FitParameter & _tageff_os
double getCalibratedResolution(double &dt, double &scale_sigma_dt, double &scale_sigma_2_dt)
virtual double getVal(IDalitzEvent &evt)
const MINT::FitParameter & _c6
void listFitParDependencies()
double get_sin_term_Val(IDalitzEvent &evt)
const FitParameter & _C
fit parameters
const std::vector< T > & getVector() const
double get_cosh_term_Val(IDalitzEvent &evt)
virtual double getVal_noPs(IDalitzEvent &evt)
const MINT::FitParameter & _c7
RooDataSet * sampleEvents(int N=10000)
std::pair< double, double > getCalibratedMistag_OS(IDalitzEvent &evt, double &avg_eta_os, double &p0_os, double &p1_os, double &delta_p0_os, double &delta_p1_os)
const MINT::FitParameter & _c3
std::pair< double, double > getCalibratedMistag_OS(double &eta_OS)
const MINT::FitParameter & _avg_eta_ss
virtual unsigned int size() const
const MINT::FitParameter & _dm
double get_sinh_term_Val(IDalitzEvent &evt)
const MINT::FitParameter & _offset_sigma_dt
double get_cos_term_Integral(IDalitzEvent &evt)
const MINT::FitParameter & _delta_p1_os
void generateBkgToys(int N, DalitzEventList &eventListData)
NamedParameter< double > _max_TAUERR
virtual void setGeneratorPdfRelativeToPhaseSpace(double gpdf)
const MINT::FitParameter & _detection_asym
const MINT::FitParameter & _delta_p1_ss
const MINT::FitParameter & _p1_os
const MINT::FitParameter & _c1
string _marginalPdfsPrefix
const MINT::FitParameter & _Gamma
const MINT::FitParameter & _delta_p0_os
const MINT::FitParameter & _p0_os
const MINT::FitParameter & _scale_mean_dt
void setAllObservablesAndFitParameters(IDalitzEvent &evt)
const MINT::FitParameter & _delta_p0_ss
std::pair< double, double > getCalibratedMistag_SS(IDalitzEvent &evt, double &avg_eta_ss, double &p0_ss, double &p1_ss, double &delta_p0_ss, double &delta_p1_ss)
virtual double getVal_noPs(IDalitzEvent *evt)
std::pair< double, double > getCalibratedMistag_OS(IDalitzEvent &evt)