/***************************************************************************** * Project: BaBar detector at the SLAC PEP-II B-factory * Package: RooDKDalitz * File: $Id: RooDKFitMaster.cc,v 1.346 2010-06-30 09:24:58 martinef Exp $ * Authors: * Fernando Martinez-Vidal martinef@slac.stanford.edu, IFIC-Valencia & INFN-Pisa * Nicola Neri neri@slac.stanford.edu, INFN-Pisa * History: * - Jan 27: creation * Copyright (C) 2004 INFN-Pisa *****************************************************************************/ // -- CLASS DESCRIPTION [MISC] -- // Master class for running the gamma DK Dalitz fit. #include //#include #include #include #include "RooDKDalitz/RooDKFitMaster.hh" #include "TGaxis.h" #include "TFile.h" #include "TRandom.h" #include "TString.h" #include "TCanvas.h" #include "TStyle.h" #include "TLatex.h" #include "TText.h" #include "TLine.h" #include "TROOT.h" #include "TObjectTable.h" #include "TH2.h" #include "TTree.h" #include "TPaletteAxis.h" #include "RooFitCore/RooHist.hh" #include "RooFitCore/RooStringVar.hh" #include "RooFitCore/RooRealConstant.hh" #include "RooFitCore/RooSuperCategory.hh" #include "RooFitCore/Roo1DTable.hh" #include "RooFitCore/RooNLLVar.hh" #include "RooFitCore/RooChi2Var.hh" //#include "RooDKDalitz/RooDKChi2Var.hh" //#include "RooFitCore/RooMinuit.hh" #include "RooFitCore/RooDataHist.hh" #include "RooFitCore/RooRandom.hh" #include "RooFitCore/RooAddPdf.hh" #include "RooFitCore/RooProdPdf.hh" #include "RooFitCore/RooGenericPdf.hh" #include "RooFitCore/RooHistPdf.hh" #include "RooFitCore/RooPlot.hh" #include "RooFitCore/RooMCStudy.hh" #include "RooFitCore/RooNumIntConfig.hh" #include "RooFitCore/RooHistError.hh" #include "RooDKDalitz/RooJohnsonSU.hh" #include "RooDKDalitz/RooDKDalitzTools.hh" #include "RooDKDalitz/RooDalitzAmp.hh" #include "RooDKDalitz/RooDKFitProto.hh" #include "RooDKDalitz/RooDKMIBinning.hh" #include "RooDKDalitz/RooDKPdfMaker.hh" #include "RooDKDalitz/RooBaBarStyle.hh" #include "RooDKDalitz/RooContoursCartesians.hh" #ifdef NAG_C_ROOT #include "RooDKDalitz/RooNag.hh" #endif using namespace RooDKDalitzTools; using namespace RooBaBarStyle; ClassImp(RooDKFitMaster) ; RooDKFitMaster::RooDKFitMaster(const char* config) : _configFile((char*)config), _nll(0),_chi2(0), _mMinuit(0), _generator(0), #ifdef NAG_C_ROOT _mNag(0), #endif _fitData(0),_fitDataToyMc(0),_fitDataSel(0),_fitDataSelToyMc(0), _pdfSel(0),_pdfGlobal(0),_pdfMIGlobal(0),_pdfSelRaw(0),_pdfGlobalRaw(0),_pdfMIGlobalRaw(0), _pdfGlobalToyMc(0),_pdfMIGlobalToyMc(0),_pdfGlobalRawToyMc(0),_pdfMIGlobalRawToyMc(0), _fitSelResults(0),_fitResults(0),_fitMIResults(0), _fitSelResultsToyMc(0),_fitResultsToyMc(0),_fitMIResultsToyMc(0), _paramsSelInit(0),_paramsInit(0),_paramsMIInit(0),_mgr(0) { int mpi_rank = get_mpi_rank(); if (mpi_rank==0) cout << "RooDKFitMaster: configFile = '" << _configFile << "'" << endl ; RooRealVar::printScientific(1) ; // Read the [Input Data] section of the configuration file _dataRootFile=new RooStringVar("dataRootFile","ROOT file with persisted data dataset","") ; _resultsRootFile=new RooStringVar("resultsRootFile","ROOT file with persisted fit results","") ; _dkDir=new RooStringVar("dkDir","Directory with DK ASCII files","") ; _dkFiles=new RooStringVar("dkFiles","List of DK ASCII files","",4096) ; _dpiDir=new RooStringVar("dpiDir","Directory with DPi ASCII files","") ; _dpiFiles=new RooStringVar("dpiFiles","List of DPi ASCII files","",4096) ; //_dkFiles_bbbar=new RooStringVar("dkFiles_bbbar","List of DK ASCII files for BBbar","",2048) ; //_dpiFiles_bbbar=new RooStringVar("dpiFiles_bbbar","List of DPi ASCII files for BBbar","",2048) ; _dsel_dk=new RooStringVar("dsel_dk","Data selection for DK modes","") ; _dsel_dpi=new RooStringVar("dsel_dpi","Data selection for DPi modes","") ; _dsel_runBlock=new RooStringVar("dsel_runBlock","Data run block selection","") ; _fileConfigIOData.addOwned(RooArgSet(*_dataRootFile, *_dkDir,*_dkFiles,*_dpiDir,*_dpiFiles)) ; //_fileConfigIOData.addOwned(RooArgSet(*_dkFiles_bbbar,*_dpiFiles_bbbar)) ; _fileConfigIOData.addOwned(RooArgSet(*_dsel_dk,*_dsel_dpi,*_dsel_runBlock,*_resultsRootFile)) ; _fileConfigIOData.readFromFile(_configFile,0,"Input/Output Data") ; // Read the [Driver Options] section of the configuration file _qABBins=new RooRealVar("qABBins","qABBins",100.) ; _qACBins=new RooRealVar("qACBins","qACBins",100.) ; _qBCBins=new RooRealVar("qBCBins","qBCBins",100.) ; _mESMax=new RooRealVar("mESMax","mESMax",5.30) ; _mESMin=new RooRealVar("mESMin","mESMin",5.20) ; _mESBins=new RooRealVar("mESBins","mESBins",100.) ; _deltaEBins=new RooRealVar("deltaEBins","deltaEBins",100.) ; _deltaEMax_dkSel=new RooRealVar("deltaEMax_dkSel","deltaEMax_dkSel",0.3) ; _deltaEMin_dkSel=new RooRealVar("deltaEMin_dkSel","deltaEMin_dkSel",-0.3) ; _deltaEMax_dpiSel=new RooRealVar("deltaEMax_dpiSel","deltaEMax_dpiSel",0.3) ; _deltaEMin_dpiSel=new RooRealVar("deltaEMin_dpiSel","deltaEMin_dpiSel",-0.3) ; _deltaEMax_dk=new RooRealVar("deltaEMax_dk","deltaEMax_dk",0.3) ; _deltaEMin_dk=new RooRealVar("deltaEMin_dk","deltaEMin_dk",-0.3) ; _deltaEMax_dpi=new RooRealVar("deltaEMax_dpi","deltaEMax_dpi",0.3) ; _deltaEMin_dpi=new RooRealVar("deltaEMin_dpi","deltaEMin_dpi",-0.3) ; _deltaEshiftMax=new RooRealVar("deltaEshiftMax","deltaEshiftMax",0.12) ; _deltaEshiftMin=new RooRealVar("deltaEshiftMin","deltaEshiftMin",0.) ; _deltaEshiftBins=new RooRealVar("deltaEshiftBins","deltaEshiftBins",100.) ; _mDMax=new RooRealVar("mDMax","mDMax",1.965) ; _mDMin=new RooRealVar("mDMin","mDMin",1.765) ; _mDMax_Sel=new RooRealVar("mDMax_Sel","mDMax_Sel",-5.) ; // Opposite signs to assign same values as (fisherMax,fisherMin) _mDMin_Sel=new RooRealVar("mDMin_Sel","mDMin_Sel",5) ; // for back compatibility _mDBins=new RooRealVar("mDBins","mDBins",100.) ; _deltamMax=new RooRealVar("deltamMax","deltamMax",0.150) ; _deltamMin=new RooRealVar("deltamMin","deltamMin",0.130) ; _deltamMax_Sel=new RooRealVar("deltamMax_Sel","deltamMax_Sel",-5.) ; // Opposite signs to assign same values as (fisherMax,fisherMin) _deltamMin_Sel=new RooRealVar("deltamMin_Sel","deltamMin_Sel",5.) ; // for back compatibility _deltamBins=new RooRealVar("deltamBins","deltamBins",100.) ; _tRecoMax=new RooRealVar("tRecoMax","tRecoMax",4.) ; _tRecoMin=new RooRealVar("tRecoMin","tRecoMin",-2.) ; _tRecoBins=new RooRealVar("tRecoBins","tRecoBins",100.) ; _tErrMax=new RooRealVar("tErrMax","tErrMax",4.) ; _tErrMin=new RooRealVar("tErrMin","tErrMin",0.) ; _tErrBins=new RooRealVar("tErrBins","tErrBins",100.) ; _tTrueMax=new RooRealVar("tTrueMax","tTrueMax",+1e9) ; _tTrueMin=new RooRealVar("tTrueMin","tTrueMin",-1e9) ; _tTrueBins=new RooRealVar("tTrueBins","tTrueBins",100.) ; _fisherMax=new RooRealVar("fisherMax","fisherMax",5.) ; _fisherMin=new RooRealVar("fisherMin","fisherMin",-5.) ; _fisherMax_Sel=new RooRealVar("fisherMax_Sel","fisherMax_Sel",-5.) ; // Opposite signs to assign same values as (fisherMax,fisherMin) _fisherMin_Sel=new RooRealVar("fisherMin_Sel","fisherMin_Sel",5.) ; // for back compatibility _fisherBins=new RooRealVar("fisherBins","fisherBins",100.) ; _minimizer=new RooCategory("minimizer","Minimizer") ; _minimizer->defineType("Minuit"); #ifdef NAG_C_ROOT _minimizer->defineType("Nag"); #endif _minimizer->setLabel("Minuit"); _simplex=new RooCategory("simplex","Switch to execute Simplex before Migrad") ; _simplex->defineType("Yes"); _simplex->defineType("No"); _simplex->setLabel("No"); _doMinosPhys=new RooCategory("doMinosPhys","Physics parameters MINOS switch") ; _doMinosPhys->defineType("No"); _doMinosPhys->defineType("Yes"); _doMinosPhys->setLabel("No"); _doBinnedFit=new RooCategory("doBinnedFit","Binned Dalitz fit switch") ; _doBinnedFit->defineType("No"); _doBinnedFit->defineType("Yes"); _doBinnedFit->setLabel("No"); _typeBinnedFit=new RooCategory("typeBinnedFit","Type of binned Dalitz fit") ; _typeBinnedFit->defineType("Likelihood"); _typeBinnedFit->defineType("Chi2"); _typeBinnedFit->setLabel("Likelihood"); _flavorOption=new RooCategory("flavorOption","flavor information option"); _flavorOption->defineType("reco"); _flavorOption->defineType("truth"); _flavorOption->setLabel("reco"); _deltaEDhOption=new RooCategory("deltaEDhOption","deltaEDh PDF option"); _deltaEDhOption->defineType("none"); _deltaEDhOption->defineType("deltaEshift"); _deltaEDhOption->defineType("independent"); _deltaEDhOption->setLabel("none"); _mESOption=new RooCategory("mESOption","mES PDF option"); _mESOption->defineType("in"); _mESOption->defineType("out"); _mESOption->setLabel("in"); _fisherOption=new RooCategory("fisherOption","Fisher PDF option"); _fisherOption->defineType("in"); _fisherOption->defineType("out"); _fisherOption->setLabel("in"); _mDOption=new RooCategory("mDOption","mD PDF option"); _mDOption->defineType("in"); _mDOption->defineType("out"); _mDOption->setLabel("out"); _deltamOption=new RooCategory("deltamOption","Deltam PDF option"); _deltamOption->defineType("in"); _deltamOption->defineType("out"); _deltamOption->setLabel("out"); _tErrOption=new RooCategory("tErrOption","Proper time error PDF option (for Punzi effect)"); _tErrOption->defineType("in"); _tErrOption->defineType("out"); _tErrOption->setLabel("out"); _fitVerbose=new RooCategory("fitVerbose","CPT fit verbose") ; _fitVerbose->defineType("Yes"); _fitVerbose->defineType("No"); _fitVerbose->setLabel("No"); _fixShapeParams=new RooCategory("fixShapeParams","Switch to fix selection shape parameters in Dalitz fits") ; _fixShapeParams->defineType("Yes"); _fixShapeParams->defineType("No"); _fixShapeParams->setLabel("Yes"); _fixYieldParams=new RooCategory("fixYieldParams","Switch to fix selection yield parameters in Dalitz fits") ; _fixYieldParams->defineType("Yes"); _fixYieldParams->defineType("No"); _fixYieldParams->setLabel("No"); _fixDhYieldParams=new RooCategory("fixDhYieldParams","Switch to fix Dh selection yield parameters in Dalitz fits") ; _fixDhYieldParams->defineType("Yes"); _fixDhYieldParams->defineType("No"); _fixDhYieldParams->setLabel("No"); _integTypeNorm=new RooCategory("integTypeNorm","Normalization integral type") ; _integTypeNorm->defineType("Grid",RooDalitzAmp::Grid); _integTypeNorm->defineType("Adaptive",RooDalitzAmp::Adaptive); _integTypeNorm->defineType("MC",RooDalitzAmp::MC); _integTypeNorm->setLabel("Grid"); _nBins1DNorm=new RooRealVar("nBins1DNorm","Number of bins for 1D grid integral",100) ; _nBins2DNorm=new RooRealVar("nBins2DNorm","Number of bins for 2D grid integral",100) ; _nBins2DeffMap=new RooRealVar("nBins2DeffMap","Number of bins for 2D efficiency map histogram",80) ; _removeEvtsOutPS=new RooCategory("removeEvtsOutPS","Switch to remove events outside phase space region, for nominal masses") ; _removeEvtsOutPS->defineType("Yes"); _removeEvtsOutPS->defineType("No"); _removeEvtsOutPS->setLabel("Yes"); RooCategory* _binningMIOption = new RooCategory("binningMIOption","Option for Dalitz plot MI Binning") ; _binningMIOption->defineType("GRID",RooDKMIBinning::GRID) ; _nMcExpMICoefs=new RooRealVar("nMcExpMICoefs","Number of MC experiments per bin for Ci,Si,Ti coefs estimation",1000) ; _phaseShiftWatson=new RooCategory("phaseShiftWatson","Apply Watson phase shift") ; _phaseShiftWatson->defineType("Yes"); _phaseShiftWatson->defineType("No"); _phaseShiftWatson->setLabel("No"); _coherentAmpFakeD=new RooCategory("coherentAmpFakeD","Coherent amplitudes for fake D's (Cont, BB and DstarFakeD)") ; _coherentAmpFakeD->defineType("Yes"); _coherentAmpFakeD->defineType("No"); _coherentAmpFakeD->setLabel("No"); _resFcn=new RooCategory("resFcn","Proper time resolution function") ; _resFcn->defineType("Unknown"); _resFcn->defineType("3GSig3GBkgEventError"); // 3G resolution for signal and bkg with per-event error _resFcn->defineType("3GSig3GBkgGlobalError"); // 3G resolution for signal and bkg with global error _resFcn->defineType("3GSigEffBkgGlobalError"); // effective bkg parameterization only works with global error for signal _resFcn->defineType("3GSigEffBkgEventError"); // effective bkg parameterization with event error for signal _resFcn->defineType("Truth"); _resFcn->setLabel("Unknown"); _diskCachePrefix=new RooStringVar("diskCachePrefix","Prefix for diskCache files","") ; _maxHashMapSize=new RooRealVar("maxHashMapSize","maxHashMapSize",0) ; _fileConfigDriver.addOwned(RooArgSet(*_qABBins,*_qACBins,*_qBCBins)) ; _fileConfigDriver.addOwned(RooArgSet(*_mESMax,*_mESMin,*_mESBins)); _fileConfigDriver.addOwned(RooArgSet(*_deltaEBins,*_deltaEshiftMax,*_deltaEshiftMin,*_deltaEshiftBins)); _fileConfigDriver.addOwned(RooArgSet(*_deltaEMax_dkSel,*_deltaEMin_dkSel,*_deltaEMax_dpiSel,*_deltaEMin_dpiSel)); _fileConfigDriver.addOwned(RooArgSet(*_deltaEMax_dk,*_deltaEMin_dk,*_deltaEMax_dpi,*_deltaEMin_dpi)); _fileConfigDriver.addOwned(RooArgSet(*_mDMax,*_mDMin,*_mDMax_Sel,*_mDMin_Sel,*_mDBins)); _fileConfigDriver.addOwned(RooArgSet(*_fisherMax,*_fisherMin,*_fisherMax_Sel,*_fisherMin_Sel,*_fisherBins)) ; _fileConfigDriver.addOwned(RooArgSet(*_deltamMax,*_deltamMin,*_deltamMax_Sel,*_deltamMin_Sel,*_deltamBins)); _fileConfigDriver.addOwned(RooArgSet(*_tRecoMax,*_tRecoMin,*_tRecoBins,*_tErrMax,*_tErrMin,*_tErrBins,*_tTrueMax,*_tTrueMin,*_tTrueBins)); _fileConfigDriver.addOwned(RooArgSet(*_fitVerbose,*_fixShapeParams,*_fixYieldParams,*_fixDhYieldParams,*_flavorOption,*_deltaEDhOption,*_mESOption,*_fisherOption,*_nMcExpMICoefs)) ; _fileConfigDriver.addOwned(RooArgSet(*_mDOption,*_deltamOption,*_tErrOption)); _fileConfigDriver.addOwned(RooArgSet(*_minimizer,*_simplex,*_doMinosPhys,*_doBinnedFit,*_typeBinnedFit)); _fileConfigDriver.addOwned(RooArgSet(*_integTypeNorm,*_nBins1DNorm,*_nBins2DNorm,*_nBins2DeffMap,*_removeEvtsOutPS,*_binningMIOption)); _fileConfigDriver.addOwned(RooArgSet(*_phaseShiftWatson,*_coherentAmpFakeD,*_resFcn,*_diskCachePrefix,*_maxHashMapSize)); _fileConfigDriver.readFromFile(_configFile,0,"Driver Options") ; /* // define all cuts // check first that Dalitz deltaE cuts are tighter than selection deltaE cuts assert(_deltaEMin_dkSel->getVal()<=_deltaEMin_dk->getVal()); assert(_deltaEMax_dkSel->getVal()>=_deltaEMax_dk->getVal()); assert(_deltaEMin_dpiSel->getVal()<=_deltaEMin_dpi->getVal()); assert(_deltaEMax_dpiSel->getVal()>=_deltaEMax_dpi->getVal()); // selection TString cut_dkSel("(deltaE_dk>="); cut_dkSel.Append(*_deltaEMin_dkSel->format(2,"F")); cut_dkSel.Append(")&&(deltaE_dk<="); cut_dkSel.Append(*_deltaEMax_dkSel->format(2,"F")); cut_dkSel.Append(")"); TString cut_dpiSel("(deltaE_dpi>="); cut_dpiSel.Append(*_deltaEMin_dpiSel->format(2,"F")); cut_dpiSel.Append(")&&(deltaE_dpi<="); cut_dpiSel.Append(*_deltaEMax_dpiSel->format(2,"F")); cut_dpiSel.Append(")"); // Dalitz TString cut_dk("(deltaE_dk>="); cut_dk.Append(*_deltaEMin_dk->format(2,"F")); cut_dk.Append(")&&(deltaE_dk<="); cut_dk.Append(*_deltaEMax_dk->format(2,"F")); cut_dk.Append(")"); TString cut_dpi("(deltaE_dpi>="); cut_dpi.Append(*_deltaEMin_dpi->format(2,"F")); cut_dpi.Append(")&&(deltaE_dpi<="); cut_dpi.Append(*_deltaEMax_dpi->format(2,"F")); cut_dpi.Append(")"); // Fisher // check first that Dalitz deltaE cuts are tighter than selection deltaE cuts if (_fisherMin_Sel->getVal()>_fisherMax_Sel->getVal()) { // for back compatibility _fisherMin_Sel->setVal(_fisherMin->getVal()); _fisherMax_Sel->setVal(_fisherMax->getVal()); } assert(_fisherMin_Sel->getVal()<=_fisherMin->getVal()); assert(_fisherMax_Sel->getVal()>=_fisherMax->getVal()); // selection TString cut_fisherSel("(fisher>="); cut_fisherSel.Append(*_fisherMin_Sel->format(2,"F")); cut_fisherSel.Append(")&&(fisher<="); cut_fisherSel.Append(*_fisherMax_Sel->format(2,"F")); cut_fisherSel.Append(")"); // Dalitz TString cut_fisher("(fisher>="); cut_fisher.Append(*_fisherMin->format(2,"F")); cut_fisher.Append(")&&(fisher<="); cut_fisher.Append(*_fisherMax->format(2,"F")); cut_fisher.Append(")"); // mD if (_mDMin_Sel->getVal()>_mDMax_Sel->getVal()) { // for back compatibility _mDMin_Sel->setVal(_mDMin->getVal()); _mDMax_Sel->setVal(_mDMax->getVal()); } assert(_mDMin_Sel->getVal()<=_mDMin->getVal()); assert(_mDMax_Sel->getVal()>=_mDMax->getVal()); // selection TString cut_mDSel("(mD>="); cut_mDSel.Append(*_mDMin_Sel->format(6,"F")); cut_mDSel.Append(")&&(mD<="); cut_mDSel.Append(*_mDMax_Sel->format(6,"F")); cut_mDSel.Append(")"); // Dalitz TString cut_mD("(mD>="); cut_mD.Append(*_mDMin->format(6,"F")); cut_mD.Append(")&&(mD<="); cut_mD.Append(*_mDMax->format(6,"F")); cut_mD.Append(")"); // m(D*)-m(D) if (_deltamMin_Sel->getVal()>_deltamMax_Sel->getVal()) { // for back compatibility _deltamMin_Sel->setVal(_deltamMin->getVal()); _deltamMax_Sel->setVal(_deltamMax->getVal()); } assert(_deltamMin_Sel->getVal()<=_deltamMin->getVal()); assert(_deltamMax_Sel->getVal()>=_deltamMax->getVal()); // selection TString cut_deltamSel("(deltam>="); cut_deltamSel.Append(*_deltamMin_Sel->format(6,"F")); cut_deltamSel.Append(")&&(deltam<="); cut_deltamSel.Append(*_deltamMax_Sel->format(6,"F")); cut_deltamSel.Append(")"); // Dalitz TString cut_deltam("(deltam>="); cut_deltam.Append(*_deltamMin->format(6,"F")); cut_deltam.Append(")&&(deltam<="); cut_deltam.Append(*_deltamMax->format(6,"F")); cut_deltam.Append(")"); // overall selection cuts _dsel_fitSel=new RooStringVar("dsel_fitSel","Data selection for DK selection fit","") ; TString dsel_dk_fitSel(_dsel_dk->getVal()); TString dsel_dpi_fitSel(_dsel_dpi->getVal()); addCut(dsel_dk_fitSel,cut_dkSel,"&&"); addCut(dsel_dpi_fitSel,cut_dpiSel,"&&"); addCut(_dsel_fitSel,dsel_dk_fitSel,"||"); addCut(_dsel_fitSel,dsel_dpi_fitSel,"||"); // _dsel_fit=new RooStringVar("dsel_fit","Data selection for DK Dalitz fit","") ; TString dsel_dk_fit(_dsel_dk->getVal()); TString dsel_dpi_fit(_dsel_dpi->getVal()); addCut(dsel_dk_fit,cut_dk,"&&"); addCut(dsel_dpi_fit,cut_dpi,"&&"); addCut(_dsel_fit,dsel_dk_fit,"||"); addCut(_dsel_fit,dsel_dpi_fit,"||"); _dsel_dk_fit=new RooStringVar("dsel_dk_fit","Data selection for DK Dalitz fit",dsel_dk_fit) ; _dsel_dpi_fit=new RooStringVar("dsel_dpi_fit","Data selection for DK Dalitz fit",dsel_dpi_fit) ; // include Fisher selection addCut(_dsel_dk_fit,cut_fisherSel,"&&"); addCut(_dsel_dpi_fit,cut_fisherSel,"&&"); addCut(_dsel_fitSel,cut_fisherSel,"&&"); addCut(_dsel_fit,cut_fisher,"&&"); // include mD selection addCut(_dsel_dk_fit,cut_mDSel,"&&"); addCut(_dsel_dpi_fit,cut_mDSel,"&&"); addCut(_dsel_fitSel,cut_mDSel,"&&"); addCut(_dsel_fit,cut_mD,"&&"); // include m(D*)-m(D) selection //if (*_deltamOption=="in") { if (*_resFcn!="Unknown") { addCut(_dsel_dk_fit,cut_deltamSel,"&&"); addCut(_dsel_dpi_fit,cut_deltamSel,"&&"); addCut(_dsel_fitSel,cut_deltamSel,"&&"); addCut(_dsel_fit,cut_deltam,"&&"); } // include run block selection addCut(_dsel_dk_fit,_dsel_runBlock,"&&"); addCut(_dsel_dpi_fit,_dsel_runBlock,"&&"); addCut(_dsel_fitSel,_dsel_runBlock,"&&"); addCut(_dsel_fit,_dsel_runBlock,"&&"); //cout << _dsel_fitSel->getVal() << endl; //cout << _dsel_fit->getVal() << endl; //cout << _dsel_dk_fit->getVal() << endl; //cout << _dsel_dpi_fit->getVal() << endl; //assert(0); */ // define all cuts TString dsel_fitSel,dsel_fit; TString dsel_dk_fit,dsel_dpi_fit; buildAllCuts(1,1,1,1,1,dsel_fitSel,dsel_fit,dsel_dk_fit,dsel_dpi_fit); _dsel_fitSel=new RooStringVar("dsel_fitSel","Data selection for DK selection fit",dsel_fitSel) ; _dsel_fit=new RooStringVar("dsel_fit","Data selection for DK Dalitz fit",dsel_fit) ; _dsel_dk_fit=new RooStringVar("dsel_dk_fit","Data selection for DK Dalitz fit",dsel_dk_fit) ; _dsel_dpi_fit=new RooStringVar("dsel_dpi_fit","Data selection for DK Dalitz fit",dsel_dpi_fit) ; //cout << endl << _dsel_fitSel->getVal() << endl; //cout << _dsel_fit->getVal() << endl; //cout << _dsel_dk_fit->getVal() << endl; //cout << _dsel_dpi_fit->getVal() << endl; //assert(0); // print configuration inputs if (mpi_rank==0) { cout << "RooDKFitMaster: Basic Configuration read from " << _configFile << endl; cout << "RooDKFitMaster: qABBins = " << _qABBins->getVal() << endl; cout << "RooDKFitMaster: qACBins = " << _qACBins->getVal() << endl; cout << "RooDKFitMaster: qBCBins = " << _qBCBins->getVal() << endl; cout << "RooDKFitMaster: mESMax = " << _mESMax->getVal() << endl; cout << "RooDKFitMaster: mESMin = " << _mESMin->getVal() << endl; cout << "RooDKFitMaster: mESBins = " << _mESBins->getVal() << endl; cout << "RooDKFitMaster: deltaEBins = " << _deltaEBins->getVal() << endl; cout << "RooDKFitMaster: deltaEMax_dkSel = " << _deltaEMax_dkSel->getVal() << endl; cout << "RooDKFitMaster: deltaEMin_dkSel = " << _deltaEMin_dkSel->getVal() << endl; cout << "RooDKFitMaster: deltaEMax_dpiSel = " << _deltaEMax_dpiSel->getVal() << endl; cout << "RooDKFitMaster: deltaEMin_dpiSel = " << _deltaEMin_dpiSel->getVal() << endl; cout << "RooDKFitMaster: deltaEMax_dk = " << _deltaEMax_dk->getVal() << endl; cout << "RooDKFitMaster: deltaEMin_dk = " << _deltaEMin_dk->getVal() << endl; cout << "RooDKFitMaster: deltaEMax_dpi = " << _deltaEMax_dpi->getVal() << endl; cout << "RooDKFitMaster: deltaEMin_dpi = " << _deltaEMin_dpi->getVal() << endl; cout << "RooDKFitMaster: deltaEshiftMax = " << _deltaEshiftMax->getVal() << endl; cout << "RooDKFitMaster: deltaEshiftMin = " << _deltaEshiftMin->getVal() << endl; cout << "RooDKFitMaster: deltaEshiftBins = " << _deltaEshiftBins->getVal() << endl; cout << "RooDKFitMaster: mDMax = " << _mDMax->getVal() << endl; cout << "RooDKFitMaster: mDMin = " << _mDMin->getVal() << endl; cout << "RooDKFitMaster: mDMax_Sel = " << _mDMax_Sel->getVal() << endl; cout << "RooDKFitMaster: mDMin_Sel = " << _mDMin_Sel->getVal() << endl; cout << "RooDKFitMaster: mDBins = " << _mDBins->getVal() << endl; cout << "RooDKFitMaster: deltamMax = " << _deltamMax->getVal() << endl; cout << "RooDKFitMaster: deltamMin = " << _deltamMin->getVal() << endl; cout << "RooDKFitMaster: deltamMax_Sel = " << _deltamMax_Sel->getVal() << endl; cout << "RooDKFitMaster: deltamMin_Sel = " << _deltamMin_Sel->getVal() << endl; cout << "RooDKFitMaster: deltamBins = " << _deltamBins->getVal() << endl; cout << "RooDKFitMaster: tRecoMax = " << _tRecoMax->getVal() << endl; cout << "RooDKFitMaster: tRecoMin = " << _tRecoMin->getVal() << endl; cout << "RooDKFitMaster: tRecoBins = " << _tRecoBins->getVal() << endl; cout << "RooDKFitMaster: tErrMax = " << _tErrMax->getVal() << endl; cout << "RooDKFitMaster: tErrMin = " << _tErrMin->getVal() << endl; cout << "RooDKFitMaster: tErrBins = " << _tErrBins->getVal() << endl; cout << "RooDKFitMaster: tTrueMax = " << _tTrueMax->getVal() << endl; cout << "RooDKFitMaster: tTrueMin = " << _tTrueMin->getVal() << endl; cout << "RooDKFitMaster: tTrueBins = " << _tTrueBins->getVal() << endl; cout << "RooDKFitMaster: fisherMax = " << _fisherMax->getVal() << endl; cout << "RooDKFitMaster: fisherMin = " << _fisherMin->getVal() << endl; cout << "RooDKFitMaster: fisherMax_Sel = " << _fisherMax_Sel->getVal() << endl; cout << "RooDKFitMaster: fisherMin_Sel = " << _fisherMin_Sel->getVal() << endl; cout << "RooDKFitMaster: fisherBins = " << _fisherBins->getVal() << endl; cout << "RooDKFitMaster: minimizer = " << _minimizer->getLabel() << endl; cout << "RooDKFitMaster: simplex = " << _simplex->getLabel() << endl; cout << "RooDKFitMaster: doMinosPhys = " << _doMinosPhys->getLabel() << endl; cout << "RooDKFitMaster: doBinnedFit = " << _doBinnedFit->getLabel() << endl; } if (*_doBinnedFit=="No") _typeBinnedFit->setLabel("Likelihood"); if (mpi_rank==0) { cout << "RooDKFitMaster: typeBinnedFit = " << _typeBinnedFit->getLabel() << endl; cout << "RooDKFitMaster: flavorOption = " << _flavorOption->getLabel() << endl; cout << "RooDKFitMaster: deltaEDhOption = " << _deltaEDhOption->getLabel() << endl; cout << "RooDKFitMaster: mESOption = " << _mESOption->getLabel() << endl; cout << "RooDKFitMaster: fisherOption = " << _fisherOption->getLabel() << endl; cout << "RooDKFitMaster: mDOption = " << _mDOption->getLabel() << endl; cout << "RooDKFitMaster: deltamOption= " << _deltamOption->getLabel() << endl; cout << "RooDKFitMaster: tErrOption = " << _tErrOption->getLabel() << endl; cout << "RooDKFitMaster: fitVerbose = " << _fitVerbose->getLabel() << endl; cout << "RooDKFitMaster: fixShapeParams = " << _fixShapeParams->getLabel() << endl; cout << "RooDKFitMaster: fixYieldParams = " << _fixYieldParams->getLabel() << endl; cout << "RooDKFitMaster: fixDhYieldParams = " << _fixDhYieldParams->getLabel() << endl; cout << "RooDKFitMaster: integTypeNorm = " << _integTypeNorm->getLabel() << endl; cout << "RooDKFitMaster: nBins1DNorm = " << _nBins1DNorm->getVal() << endl; cout << "RooDKFitMaster: nBins2DNorm = " << _nBins2DNorm->getVal() << endl; cout << "RooDKFitMaster: nBins2DeffMap = " << _nBins2DeffMap->getVal() << endl; cout << "RooDKFitMaster: removeEvtsOutPS = " << _removeEvtsOutPS->getLabel() << endl; cout << "RooDKFitMaster: binningMIOption = " << _binningMIOption->getLabel() << endl; cout << "RooDKFitMaster: nMcExpMICoefs = " << _nMcExpMICoefs->getVal() << endl; cout << "RooDKFitMaster: phaseShiftWatson = " << _phaseShiftWatson->getLabel() << endl; cout << "RooDKFitMaster: coherentAmpFakeD = " << _coherentAmpFakeD->getLabel() << endl; cout << "RooDKFitMaster: resFcn = " << _resFcn->getLabel() << endl; cout << "RooDKFitMaster: diskCachePrefix = " << _diskCachePrefix->getVal() << endl; cout << "RooDKFitMaster: maxHashMapSize = " << (Int_t)_maxHashMapSize->getVal() << endl; cout << endl; cout << "RooDKFitMaster: dsel_runBlock = " << _dsel_runBlock->getVal() << endl; cout << "RooDKFitMaster: dsel_dk = " << _dsel_dk->getVal() << endl; cout << "RooDKFitMaster: dsel_dpi = " << _dsel_dpi->getVal() << endl; cout << "RooDKFitMaster: dsel_fitSel = " << _dsel_fitSel->getVal() << endl; cout << "RooDKFitMaster: dsel_fit = " << _dsel_fit->getVal() << endl; cout << "RooDKFitMaster: dsel_dk_fit = " << _dsel_dk_fit->getVal() << endl; cout << "RooDKFitMaster: dsel_dpi_fit = " << _dsel_dpi_fit->getVal() << endl; } // Setup blinding configuration // rb _blindString_rb= new RooStringVar("blindString_rb","Blinding String rb","") ; _blindSigma_rb= new RooRealVar("blindSigma_rb","Blinding Sigma rb",0) ; _blindConfig.addOwned(RooArgSet(*_blindString_rb,*_blindSigma_rb)); // phaseW _blindString_phaseW= new RooStringVar("blindString_phaseW","Blinding String phaseW","") ; _blindSigma_phaseW= new RooRealVar("blindSigma_phaseW","Blinding Sigma phaseW",0) ; _blindConfig.addOwned(RooArgSet(*_blindString_phaseW,*_blindSigma_phaseW)); // phaseS _blindString_phaseS= new RooStringVar("blindString_phaseS","Blinding String phaseS","") ; _blindSigma_phaseS= new RooRealVar("blindSigma_phaseS","Blinding Sigma phaseS",0) ; _blindConfig.addOwned(RooArgSet(*_blindString_phaseS,*_blindSigma_phaseS)); // phaseM _blindString_phaseM= new RooStringVar("blindString_phaseM","Blinding String phaseM","") ; _blindSigma_phaseM= new RooRealVar("blindSigma_phaseM","Blinding Sigma phaseM",0) ; _blindConfig.addOwned(RooArgSet(*_blindString_phaseM,*_blindSigma_phaseM)); // phaseP _blindString_phaseP= new RooStringVar("blindString_phaseP","Blinding String phaseP","") ; _blindSigma_phaseP= new RooRealVar("blindSigma_phaseP","Blinding Sigma phaseP",0) ; _blindConfig.addOwned(RooArgSet(*_blindString_phaseP,*_blindSigma_phaseP)); // reM _blindString_reM= new RooStringVar("blindString_reM","Blinding String reM","") ; _blindSigma_reM= new RooRealVar("blindSigma_reM","Blinding Sigma reM",0) ; _blindConfig.addOwned(RooArgSet(*_blindString_reM,*_blindSigma_reM)); // imM _blindString_imM= new RooStringVar("blindString_imM","Blinding String imM","") ; _blindSigma_imM= new RooRealVar("blindSigma_imM","Blinding Sigma imM",0) ; _blindConfig.addOwned(RooArgSet(*_blindString_imM,*_blindSigma_imM)); // reP _blindString_reP= new RooStringVar("blindString_reP","Blinding String reP","") ; _blindSigma_reP= new RooRealVar("blindSigma_reP","Blinding Sigma reP",0) ; _blindConfig.addOwned(RooArgSet(*_blindString_reP,*_blindSigma_reP)); // imP _blindString_imP= new RooStringVar("blindString_imP","Blinding String imP","") ; _blindSigma_imP= new RooRealVar("blindSigma_imP","Blinding Sigma imP",0) ; _blindConfig.addOwned(RooArgSet(*_blindString_imP,*_blindSigma_imP)); // D mixing: absqOverp _blindString_absqOverp= new RooStringVar("blindString_absqOverp","Blinding String absqOverp","") ; _blindSigma_absqOverp= new RooRealVar("blindSigma_absqOverp","Blinding Sigma absqOverp",0) ; _blindConfig.addOwned(RooArgSet(*_blindString_absqOverp,*_blindSigma_absqOverp)); // D mixing: argqOverp _blindString_argqOverp= new RooStringVar("blindString_argqOverp","Blinding String argqOverp","") ; _blindSigma_argqOverp= new RooRealVar("blindSigma_argqOverp","Blinding Sigma argqOverp",0) ; _blindConfig.addOwned(RooArgSet(*_blindString_argqOverp,*_blindSigma_argqOverp)); // D mixing: x _blindString_x= new RooStringVar("blindString_x","Blinding String x","") ; _blindSigma_x= new RooRealVar("blindSigma_x","Blinding Sigma x",0) ; _blindConfig.addOwned(RooArgSet(*_blindString_x,*_blindSigma_x)); // D mixing: y _blindString_y= new RooStringVar("blindString_y","Blinding String y","") ; _blindSigma_y= new RooRealVar("blindSigma_y","Blinding Sigma y",0) ; _blindConfig.addOwned(RooArgSet(*_blindString_y,*_blindSigma_y)); // _blindConfig.readFromFile(_configFile,"READ","Blinding") ; if (mpi_rank==0) { cout << "RooDKFitMaster: Blinding configuration read from " << _configFile << endl; _blindConfig.Print("v") ; RooArgSet* blindNotRead = (RooArgSet*)_blindConfig.selectByAttrib("READ",kFALSE) ; if (blindNotRead->getSize()>0) { cout << "***** WARNING: missing blinding configuration. Missing parts are: " << endl ; blindNotRead->Print("1") ; cout << "***** Please, make sure this is not a configuration error. " << endl ; delete blindNotRead; } } // instantiate RooDKFitProto object RooDKMIBinning::BinningType optMI; switch (_binningMIOption->getIndex()) { case RooDKMIBinning::GRID: { optMI = RooDKMIBinning::GRID; break; } default: { assert(0); break; } } // Make DKFitProto _gFit = new RooDKFitProto(_blindConfig,_configFile, (RooDalitzAmp::IntegralType)_integTypeNorm->getIndex(), (Int_t)_nBins1DNorm->getVal(),(Int_t)_nBins2DNorm->getVal(),(Int_t)_nBins2DeffMap->getVal(),//_DmassLineShape, optMI,_deltaEDhOption->getLabel(),_mESOption->getLabel(),_fisherOption->getLabel(), _mDOption->getLabel(),_deltamOption->getLabel(),_tErrOption->getLabel(), _flavorOption->getLabel(), AC,AB,AC,AB, _diskCachePrefix->getVal(),(Int_t)_maxHashMapSize->getVal(),(*_coherentAmpFakeD=="Yes")? kTRUE:kFALSE,_resFcn->getLabel()); //cout << endl << " Sono qui: DKFitProto" << endl; // Build D0 mass lineshape (for MC integration) /* if (_integTypeNorm->getIndex()==RooDalitzAmp::MC) { RooAbsPdf* mDlineShapePdf = (RooAbsPdf*)_gFit->_protoPdfSet.find("mDlineShapePdf"); assert(mDlineShapePdf); RooSimPdfBuilder* mgr_lineShape = new RooSimPdfBuilder(*mDlineShapePdf) ; RooArgSet* config_lineShape = mgr_lineShape->createProtoBuildConfig() ; config_lineShape->setStringValue("physModels","mDlineShapePdf") ; // Prototype Pdf to use config_lineShape->setStringValue("splitCats" ,"DdecayMode") ; // We will use 'DdecayMode' to split parameters config_lineShape->setStringValue("mDlineShapePdf", "DdecayMode : mDSigGMean,mDSigG1Width,mDSigG2Width,mDSigG1Frac,fSig,mDContCombC1"); // Split parameters RooDataSet* data_lineShape_dummy = new RooDataSet("data_lineShape_dummy","data_lineShape_dummy",RooArgList(*_gFit->_mD,*_gFit->_DdecayMode)) ; const RooSimultaneous* mDlineShapePdf_sim = mgr_lineShape->buildPdf(*config_lineShape,data_lineShape_dummy) ; RooArgSet* params = mDlineShapePdf_sim->getParameters(data_lineShape_dummy); params->readFromFile(_configFile,0,"MC integration D0 mass lineshape"); Int_t N2 = (Int_t)pow(_nBins2DNorm->getVal(),2); cout << "RooDKFitMaster: Generating " << N2 << " D0 lineshape mass values for MC integration from PDF with parameters " << endl; params->Print("v") ; TIterator *tIterD = _gFit->_DdecayMode->typeIterator() ; while (RooCatType* typeD = (RooCatType*)tIterD->Next()) { TString name("{"); name += typeD->GetName(); name += "}"; cout << " DdecayMode : " << name << " : "; RooAbsPdf* pdfToGen = mDlineShapePdf_sim->getPdf(name); //cout << pdfToGen << endl; _gFit->_mD->setRange(_mDMin->getVal(),_mDMax->getVal()); RooDataSet* data_lineShape = pdfToGen->generate(*_gFit->_mD,N2); //data_lineShape->Print("v"); //_gFit->_mD->Print("v"); //cout << data_lineShape->numEntries() << endl; //cout << "mDMin = " << _mDMin->getVal() << " mDMax = " << _mDMax->getVal() << endl; std::vector lineShape; for (Int_t i=0;inumEntries();i++) { Double_t mD = ((RooRealVar*)data_lineShape->get(i)->find("mD"))->getVal(); if (mD>=_mDMin->getVal() && mD<=_mDMax->getVal()) lineShape.push_back(mD); //lineShape.push_back(mD); //if (mD>=_mDMin->getVal() && mD<=_mDMax->getVal()) lineShape.push_back(1.8645); //cout << i << " " << lineShape[i] << endl; } _DmassLineShape.push_back(lineShape); cout << lineShape.size() << " events within mD window" << endl; delete data_lineShape; } delete tIterD; delete params; delete mDlineShapePdf_sim; delete data_lineShape_dummy; delete mgr_lineShape; } else { // dummy _DmassLineShape for Grid integration TIterator *tIterD = _gFit->_DdecayMode->typeIterator() ; while (RooCatType* typeD = (RooCatType*)tIterD->Next()) { std::vector lineShape; _DmassLineShape.push_back(lineShape); } delete tIterD; } */ // Rebuild proto Pdfs //_gFit->buildProtoPdfs(_DmassLineShape); //_gFit->buildProtoPdfs(); // Apply cuts on likelihood variables and set number of bins (used by binned likelihood) _gFit->_mESraw->setRange(_mESMin->getVal(),_mESMax->getVal()); _gFit->_mES->setRange(_mESMin->getVal(),_mESMax->getVal()); _gFit->_deltaE->setRange(minVal(_deltaEMin_dkSel->getVal(),_deltaEMin_dpiSel->getVal()), maxVal(_deltaEMax_dkSel->getVal(),_deltaEMax_dpiSel->getVal())); _gFit->_deltaEshift->setRange(_deltaEshiftMin->getVal(),_deltaEshiftMax->getVal()); _gFit->_mD->setRange(minVal(_mDMin_Sel->getVal(),_mDMin->getVal()), maxVal(_mDMax_Sel->getVal(),_mDMax->getVal())); _gFit->_deltam->setRange(minVal(_deltamMin_Sel->getVal(),_deltamMin->getVal()), maxVal(_deltamMax_Sel->getVal(),_deltamMax->getVal())); _gFit->_tReco->setRange(_tRecoMin->getVal(),_tRecoMax->getVal()); _gFit->_tTrue->setRange(_tTrueMin->getVal(),_tTrueMax->getVal()); _gFit->_tErr->setRange(_tErrMin->getVal(),_tErrMax->getVal()); _gFit->_fisher->setRange(minVal(_fisherMin_Sel->getVal(),_fisherMin->getVal()), maxVal(_fisherMax_Sel->getVal(),_fisherMax->getVal())); // define deltaE_dk and deltaE_dpi dependents and their limits //_deltaE_dk_func = new RooFormulaVar("deltaE_dk","deltaE for DK","@0",*_gFit->_deltaE); _deltaE_dk_func = new RooFormulaVar("deltaE_dk","#DeltaE_{K}","@0",*_gFit->_deltaE); _deltaE_dk = (RooRealVar*)_deltaE_dk_func->createFundamental() ; _deltaE_dk->setUnit("GeV"); _deltaE_dk_dummy_func = new RooFormulaVar("deltaE_dk","#DeltaE_{K}","@0",RooRealConstant::value(-999.)); Double_t min_dk = _deltaEMin_dkSel->getVal(); Double_t max_dk = _deltaEMax_dkSel->getVal(); _deltaE_dk->setRange(min_dk,max_dk); // has to be redefined later for each type of fit (selection or Dalitz fit) _deltaE_dk->setVal(min_dk+0.5*(max_dk-min_dk)); _deltaE_dpi_func = new RooFormulaVar("deltaE_dpi","deltaE for DPi","@0",*_gFit->_deltaE); _deltaE_dpi = (RooRealVar*)_deltaE_dpi_func->createFundamental() ; _deltaE_dpi->setUnit("GeV"); _deltaE_dpi_dummy_func = new RooFormulaVar("deltaE_dpi","deltaE for DPi","@0",RooRealConstant::value(-999.)); Double_t min_dpi = _deltaEMin_dpiSel->getVal(); Double_t max_dpi = _deltaEMax_dpiSel->getVal(); _deltaE_dpi->setRange(min_dpi,max_dpi); // has to be redefined later for each type of fit (selection or Dalitz fit) _deltaE_dpi->setVal(min_dpi+0.5*(max_dpi-min_dpi)); // add deltaE_dk and deltaE_dpi to set of selection data vars _gFit->_selDataVars.add(RooArgSet(*_deltaE_dk,*_deltaE_dpi)); // set number of bins on likelihood variables (used by binned likelihood) _gFit->_qAB->setBins((Int_t)_qABBins->getVal()); _gFit->_qAC->setBins((Int_t)_qACBins->getVal()); _gFit->_qBC->setBins((Int_t)_qBCBins->getVal()); _gFit->_mES->setBins((Int_t)_mESBins->getVal()); _gFit->_deltaE->setBins((Int_t)_deltaEBins->getVal()); _deltaE_dk->setBins((Int_t)_deltaEBins->getVal()); _deltaE_dpi->setBins((Int_t)_deltaEBins->getVal()); _gFit->_deltaEshift->setBins((Int_t)_deltaEshiftBins->getVal()); _gFit->_mD->setBins((Int_t)_mDBins->getVal()); _gFit->_deltam->setBins((Int_t)_deltamBins->getVal()); _gFit->_fisher->setBins((Int_t)_fisherBins->getVal()); _gFit->_tReco->setBins((Int_t)_tRecoBins->getVal()); _gFit->_tTrue->setBins((Int_t)_tTrueBins->getVal()); _gFit->_tErr->setBins((Int_t)_tErrBins->getVal()); // Build now proto PDFs (moved on Nov'07 from RooDKFitProto, since requires rebinning) _gFit->buildProtoPdfs(); // Input/Output toyMc configuration IOToyMc(); // Set BABAR style plots setStylePlots(); } RooDKFitMaster::~RooDKFitMaster() { int mpi_rank = get_mpi_rank(); if (mpi_rank==0) cout << "RooDKFitMaster: Delete data members" << endl; delete _dsel_fitSel; delete _dsel_fit; // if (mpi_rank==0) cout << "RooDKFitMaster: Delete datasets from memory" << endl; // if (_fitData) delete _fitData ; if (_fitDataToyMc) delete _fitDataToyMc ; if (_fitDataSel) delete _fitDataSel ; if (_fitDataSelToyMc) delete _fitDataSelToyMc ; // if (mpi_rank==0) cout << "RooDKFitMaster: Delete PDF's and results from memory" << endl; if (_mgr) delete _mgr; for (Int_t i=0;i<_cust_list.size();i++) if (_cust_list[i]) delete _cust_list[i]; _cust_list.clear(); //if (_pdfSelRaw) delete _pdfSelRaw; // comment to avoid crash in Root 5.14.00e //if (_pdfGlobalRaw) delete _pdfGlobalRaw; //if (_pdfMIGlobalRaw) delete _pdfMIGlobalRaw; //if (_pdfGlobalRawToyMc) delete _pdfGlobalRawToyMc; //if (_pdfMIGlobalRawToyMc) delete _pdfMIGlobalRawToyMc; _pdfSel=0; // _cust owns _pdfSel _pdfGlobal=0; // _cust owns _pdfGlobal _pdfMIGlobal=0; // _cust owns _pdfMIGlobal _pdfGlobalToyMc=0; // _cust owns _pdfGlobalToyMc _pdfMIGlobalToyMc=0; // _cust owns _pdfMIGlobalToyMc if (_fitSelResults) delete _fitSelResults ; if (_fitResults) delete _fitResults ; if (_fitMIResults) delete _fitMIResults ; if (_fitSelResultsToyMc) delete _fitSelResultsToyMc ; if (_fitResultsToyMc) delete _fitResultsToyMc ; if (_fitMIResultsToyMc) delete _fitMIResultsToyMc ; if (_paramsSelInit) delete _paramsSelInit ; if (_paramsInit) delete _paramsInit ; if (_paramsMIInit) delete _paramsMIInit ; delete _gFit; delete _deltaE_dk_func; delete _deltaE_dk_dummy_func; delete _deltaE_dpi_func; delete _deltaE_dpi_dummy_func; delete _deltaE_dk; delete _deltaE_dpi; if (_nll) delete _nll; if (_chi2) delete _chi2; if (_mMinuit) delete _mMinuit; #ifdef NAG_C_ROOT if (_mNag) delete _mNag; #endif // //_DmassLineShape.clear(); } // load ascii files, build raw datasets, apply cuts and build dataset for fitting into EXTERNAL container void RooDKFitMaster::load_datasets() { int mpi_rank = get_mpi_rank(); if (mpi_rank==0) cout << endl << "Load datasets" << endl; // Read the ASCII files listed in [Input Data] if (mpi_rank==0) cout << "RooDKFitMaster::load_datasets: reading events from ASCII files" << endl ; // Make the raw datasets from the ascii files // dk RooDataSet* dkRawData = _gFit->loadAsciiFiles(_dkFiles->getVal(),_dkDir->getVal(),"q") ; RooDataSet* dkfitDataSel = (RooDataSet*) dkRawData->reduce(_gFit->_selDataVars) ; dkfitDataSel->addColumn(*_deltaE_dk_func) ; dkfitDataSel->addColumn(*_deltaE_dpi_dummy_func) ; if (mpi_rank==0) cout << "dkRawData has " << dkRawData->numEntries() << " entries" << endl; // dpi RooDataSet* dpiRawData = _gFit->loadAsciiFiles(_dpiFiles->getVal(),_dpiDir->getVal(),"q") ; RooDataSet* dpifitDataSel = (RooDataSet*) dpiRawData->reduce(_gFit->_selDataVars) ; dpifitDataSel->addColumn(*_deltaE_dpi_func) ; dpifitDataSel->addColumn(*_deltaE_dk_dummy_func) ; if (mpi_rank==0) cout << "dpiRawData has " << dpiRawData->numEntries() << " entries" << endl; // dk_bbbar //RooDataSet* dkRawData_bbbar = _gFit->loadAsciiFiles(_dkFiles_bbbar->getVal(),_dkDir->getVal(),"q") ; //RooDataSet* dkfitDataSel_bbbar = (RooDataSet*) dkRawData_bbbar->reduce(_gFit->_selDataVars) ; //dkfitDataSel_bbbar->addColumn(*_deltaE_dk_func) ; //dkfitDataSel_bbbar->addColumn(*_deltaE_dpi_dummy_func) ; //if (mpi_rank==0) cout << "dkRawData_bbbar has " << dkRawData_bbbar->numEntries() << " entries" << endl; //// dpi_bbbar //RooDataSet* dpiRawData_bbbar = _gFit->loadAsciiFiles(_dpiFiles_bbbar->getVal(),_dpiDir->getVal(),"q") ; //RooDataSet* dpifitDataSel_bbbar = (RooDataSet*) dpiRawData_bbbar->reduce(_gFit->_selDataVars) ; //dpifitDataSel_bbbar->addColumn(*_deltaE_dpi_func) ; //dpifitDataSel_bbbar->addColumn(*_deltaE_dk_dummy_func) ; //if (mpi_rank==0) cout << "dpiRawData_bbbar has " << dpiRawData_bbbar->numEntries() << " entries" << endl; // Make a combined dataset of selected ascii variables if (_fitDataSel) delete _fitDataSel ; _fitDataSel = dkfitDataSel; _fitDataSel->append(*dpifitDataSel); if ( _fitDataSel->numEntries()==0 ) { if (mpi_rank==0) cout << "fitDataSel has no entries; must be a configuration error" << endl; assert(0); } else if (mpi_rank==0) cout << "fitDataSel has " << _fitDataSel->numEntries() << " entries" << endl; // //if (_fitDataSel_bbbar) delete _fitDataSel_bbbar ; //_fitDataSel_bbbar = dkfitDataSel_bbbar; //_fitDataSel_bbbar->append(*dpifitDataSel_bbbar); //if (mpi_rank==0) cout << "fitDataSel_bbbar has " << _fitDataSel_bbbar->numEntries() << " entries" << endl; // clean=up delete dkRawData; delete dpiRawData; delete dpifitDataSel; // //delete dkRawData_bbbar; //delete dpiRawData_bbbar; //delete dpifitDataSel_bbbar; // Removal of events outside phase space. Needed while no mass resolution available Int_t nReject(0); RooDataSet *dataSel(0); if (*_removeEvtsOutPS=="Yes") { if (mpi_rank==0) cout << "RooDKFitMaster::load_datasets: removing events outside phase space." << endl; dataSel = new RooDataSet("dataSel","dataSel",*_fitDataSel->get()); for (Int_t iEvt=0;iEvt<_fitDataSel->numEntries();iEvt++) { const RooArgSet* event = _fitDataSel->get(iEvt); RooCategory* DdecayModeLF = dynamic_cast(event->find("DdecayModeLF"));assert(DdecayModeLF); RooRealVar* qAB = dynamic_cast(event->find("qAB"));assert(qAB); RooRealVar* qAC = dynamic_cast(event->find("qAC"));assert(qAC); RooRealVar* qBC = dynamic_cast(event->find("qBC"));assert(qBC); EvtDalitzPlot dp(EvtDecayMode(DdecayModeLF->getLabel())); //EvtDalitzPoint dpoint(dp.mA(),dp.mB(),dp.mC(),qAB->getVal(),dp.sum()-qAB->getVal()-qAC->getVal(),qAC->getVal()); EvtDalitzPoint dpoint(dp.mA(),dp.mB(),dp.mC(),qAB->getVal(),qBC->getVal(),qAC->getVal()); if (dpoint.isValid()) dataSel->add(*event); else nReject++; } if (mpi_rank==0) cout << "RooDKFitMaster::load_datasets: rejected " << nReject << " events, which represent a " << (Double_t)nReject/(Double_t)_fitDataSel->numEntries()*100. << "% of the events." << endl; if (_fitDataSel) delete _fitDataSel ; _fitDataSel=dataSel; //assert(0); } // //RooDataSet *dataSel_bbbar(0); //dataSel_bbbar = new RooDataSet("dataSel_bbbar","dataSel_bbbar",*_fitDataSel_bbbar->get()); //nReject=0; //for (Int_t iEvt=0;iEvt<_fitDataSel_bbbar->numEntries();iEvt++) { // const RooArgSet* event = _fitDataSel_bbbar->get(iEvt); // RooCategory* DdecayModeLF = dynamic_cast(event->find("DdecayModeLF"));assert(DdecayModeLF); // RooRealVar* qAB = dynamic_cast(event->find("qAB"));assert(qAB); // RooRealVar* qAC = dynamic_cast(event->find("qAC"));assert(qAC); // RooRealVar* qBC = dynamic_cast(event->find("qBC"));assert(qBC); // EvtDalitzPlot dp(EvtDecayMode(DdecayModeLF->getLabel())); // EvtDalitzPoint dpoint(dp.mA(),dp.mB(),dp.mC(),qAB->getVal(),dp.sum()-qAB->getVal()-qAC->getVal(),qAC->getVal()); // //EvtDalitzPoint dpoint(dp.mA(),dp.mB(),dp.mC(),qAB->getVal(),qBC->getVal(),qAC->getVal()); // if (dpoint.isValid()) dataSel_bbbar->add(*event); else nReject++; //} //if (_fitDataSel_bbbar->numEntries()>0) { // cout << "RooDKFitMaster::load_datasets: rejected " << nReject << " BBbar events, which represent a " // << (Double_t)nReject/(Double_t)_fitDataSel_bbbar->numEntries()*100. << "% of the events." << endl; //} //if (_fitDataSel_bbbar) delete _fitDataSel_bbbar ; //_fitDataSel_bbbar=dataSel_bbbar; // calculate corrected mES by hand // correction 1: shift +20 MeV for off-resonance data // correction 2: shift -0.4 MeV for Run4 runBlock. Not applied RooArgSet dataSelDeps(*_fitDataSel->get()); dataSelDeps.replace(*_fitDataSel->get()->find("mES"),*_gFit->_mES); dataSel = new RooDataSet("dataSel","dataSel",dataSelDeps); nReject=0; for (Int_t iEvt=0;iEvt<_fitDataSel->numEntries();iEvt++) { const RooArgSet* columns = _fitDataSel->get(iEvt); //columns->Print("v"); assert(0); RooRealVar* mESraw = (RooRealVar*)columns->find("mESraw"); assert(mESraw); RooCategory* onOffRes = (RooCategory*)columns->find("onOffRes"); assert(onOffRes); RooCategory* runBlock = (RooCategory*)columns->find("runBlock"); assert(runBlock); RooRealVar* mES = (RooRealVar*)columns->find("mES"); assert(mES); //RooCategory* BdecayMode = (RooCategory*)columns->find("BdecayMode"); assert(BdecayMode); Double_t mESval = mESraw->getVal(); if (onOffRes->getIndex()==0) mESval += 0.020; //if (runBlock->getIndex()==4) mESval += 0.0004; //if (BdecayMode->getIndex()==7 || BdecayMode->getIndex()==8) mESval -= 0.00175;; if (mESval>=_gFit->_mES->getMin() && mESval<=_gFit->_mES->getMax()) { _gFit->_mES->setVal(mESval); dataSel->add(dataSelDeps); } else nReject++; } if (mpi_rank==0) cout << "RooDKFitMaster::load_datasets: rejected " << nReject << " events after mES corrections, which represent a " << (Double_t)nReject/(Double_t)_fitDataSel->numEntries()*100. << "% of the events." << endl; if (_fitDataSel) delete _fitDataSel; _fitDataSel=dataSel; /* // Removal of D0pi0 events in D0gamma sample (cross-feed) if (mpi_rank==0) cout << "RooDKFitMaster::load_datasets: removing B -> [D0pi0]K/Pi cross-feed in B -> [D0gamma]K/Pi sample." << endl; dataSel = new RooDataSet("dataSel","dataSel",*_fitDataSel->get()); Int_t nDgammaK(0),nDgammaPi(0); Int_t nDgammaKReject(0),nDgammaPiReject(0); for (Int_t iEvt=0;iEvt<_fitDataSel->numEntries();iEvt++) { const RooArgSet* event_i = _fitDataSel->get(iEvt); //event_i->Print("v"); Int_t BdecayMode_i = (dynamic_cast(event_i->find("BdecayMode")))->getIndex(); if (BdecayMode_i==5 || BdecayMode_i==6) { // a DgammaK or DgammaPi has been reconstructed Int_t runNumber_i = (Int_t)(dynamic_cast(event_i->find("runNumber")))->getVal(); TString tstampl_i = (dynamic_cast(event_i->find("tstampl")))->getVal(); TString tstamph_i = (dynamic_cast(event_i->find("tstamph")))->getVal(); Bool_t accept_i(kTRUE); BdecayMode_i==5? nDgammaK++ : nDgammaPi++; for (Int_t jEvt=0;jEvt<_fitDataSel->numEntries();jEvt++) { const RooArgSet* event_j = _fitDataSel->get(jEvt); Int_t BdecayMode_j = (dynamic_cast(event_j->find("BdecayMode")))->getIndex(); if (BdecayMode_i==(BdecayMode_j+2)) { Int_t runNumber_j = (Int_t)(dynamic_cast(event_j->find("runNumber")))->getVal(); TString tstampl_j = (dynamic_cast(event_j->find("tstampl")))->getVal(); TString tstamph_j = (dynamic_cast(event_j->find("tstamph")))->getVal(); if (runNumber_i==runNumber_j && tstampl_i== tstampl_j && tstamph_i== tstamph_j) { accept_i = kFALSE; break; } } } if (accept_i) dataSel->add(*event_i); else BdecayMode_i==5? nDgammaKReject++ : nDgammaPiReject++; } } if (mpi_rank==0) cout << "RooDKFitMaster::load_datasets: rejected " << nDgammaKReject << " B -> [D0gamma]K events, which represent a " << (Double_t)nDgammaKReject/(Double_t)nDgammaK*100. << "% of the B -> [D0gamma]K events." << endl; if (mpi_rank==0) cout << "RooDKFitMaster::load_datasets: rejected " << nDgammaPiReject << " B -> [D0gamma]Pi events, which represent a " << (Double_t)nDgammaPiReject/(Double_t)nDgammaPi*100. << "% of the B -> [D0gamma]Pi events." << endl; if (_fitDataSel) delete _fitDataSel ; _fitDataSel=dataSel; */ /* // add recState by hand RooDataSet* data_recState = new RooDataSet("data_recState","data_recState",*_gFit->_recState); for (Int_t iEvt=0;iEvt<_fitData->numEntries();iEvt++) { const RooArgSet *columns = _fitData->get(iEvt); RooRealVar* pRecBRec = (RooRealVar*)columns->find("pRecBRec"); assert(pRecBRec); if (pRecBRec->getVal()>0.5) _gFit->_recState->setIndex(+1); else _gFit->_recState->setIndex(-1); data_recState->add(*_gFit->_recState); } _fitData->merge(data_recState); */ // make final datasets for fitting (in selection and Dalitz DeltaE regions) if (mpi_rank==0) cout << "dsel_fitSel: " << _dsel_fitSel->getVal() << endl; if (mpi_rank==0) cout << "dsel_fit : " << _dsel_fit->getVal() << endl; dataSel = (RooDataSet*) _fitDataSel->reduce(_dsel_fitSel->getVal()) ; if (_fitDataSel) delete _fitDataSel ; _fitDataSel = dataSel; if (_fitData) delete _fitData ; _fitData = (RooDataSet*) _fitDataSel->reduce(_dsel_fit->getVal()) ; // //if (mpi_rank==0) cout << "dsel_fitSel_bbbar: " << _dsel_fitSel->getVal() << endl; //if (mpi_rank==0) cout << "dsel_fit_bbbar : " << _dsel_fit->getVal() << endl; //dataSel_bbbar = (RooDataSet*) _fitDataSel_bbbar->reduce(_dsel_fitSel->getVal()) ; //if (_fitDataSel_bbbar) delete _fitDataSel_bbbar ; //_fitDataSel_bbbar = dataSel_bbbar; //if (_fitData_bbbar) delete _fitData_bbbar ; //_fitData_bbbar = (RooDataSet*) _fitDataSel_bbbar->reduce(_dsel_fit->getVal()) ; // statistics tables if (mpi_rank==0) { //for (Int_t iEvt=0;iEvt<_fitDataSel->numEntries();iEvt++) _fitDataSel->get(iEvt)->Print("v"); cout << endl; cout << "RooDKFitMaster::load_datasets: fitDataSel has " << _fitDataSel->numEntries() << " events" << endl; cout << endl; statisticsTables(_fitDataSel); // //for (Int_t iEvt=0;iEvt<_fitData->numEntries();iEvt++) _fitData->get(iEvt)->Print("v"); cout << endl; cout << "RooDKFitMaster::load_datasets: fitData has " << _fitData->numEntries() << " events" << endl; cout << endl; statisticsTables(_fitData); //assert(0); //_fitDataSel->Print("v"); _fitData->Print("v"); assert(0); } } // statistics tables void RooDKFitMaster::statisticsTables(RooDataSet* data) { if (get_mpi_rank()>0) return; RooArgSet vars(*_gFit->_BdecayMode,*_gFit->_DdecayMode); RooSuperCategory superCat("superCat","B and D decay modes",vars); cout << "Statistics table per B and D decay modes" << endl; Roo1DTable* table = data->table(superCat); table->Print(); delete table; cout << "Statistics table per B and D decay modes and B charge state" << endl; vars.add(*_gFit->_recState); RooSuperCategory superCat2("superCat2","B and D decay modes and B charge state",vars); table = data->table(superCat2); table->Print(); delete table; } // build global PDF from prototypes void RooDKFitMaster::build_pdfs(Method method, Container container) { int mpi_rank = get_mpi_rank(); // Read the PDF configurations from the configuration file and build the PDFs accordingly //cout << endl << " Sono qui: Build PDFs" << endl; if (mpi_rank==0) cout << endl << "Build PDFs" << endl; // build selection PDF prototypes //_gFit->buildProtoPdfs( // AC,AB,AC,AB); // //AC,BC,AC,AB); // //AC,BC,AC,BC); // //_fitDataSel_bbbar); // Instantiate PDF builder with PDF prototypes and replicate PDF's if (_mgr==0) _mgr = new RooSimPdfBuilder(_gFit->_protoPdfSet) ; RooArgSet* rsbConfig = _mgr->createProtoBuildConfig() ; cout << endl; // Build list of auxiliary categories RooArgSet auxCat; auxCat.add(*(RooAbsArg*)_gFit->_superBdecayMode_func); auxCat.add(*(RooAbsArg*)_gFit->_BdecayModeKPi_func); auxCat.add(*(RooAbsArg*)_gFit->_superBdecayModeKPi_func); // Selection: fractions (yields) and shapes RooSimultaneous *pdfSelRaw(0),*pdfSel(0); if (method==SEL) { TString header("Selection PDF configuration"); if (container==TOYMC) header.Prepend("Toy Monte Carlo "); if (mpi_rank==0) cout << endl; rsbConfig->readFromFile(_configFile,0,header) ; pdfSelRaw = (RooSimultaneous*)_mgr->buildPdf(*rsbConfig,_gFit->_selDataVars,auxCat); if (container==TOYMC) pdfSelRaw->SetName("pdfSelRawToyMc"); else pdfSelRaw->SetName("pdfSelRaw"); // Perform customization RooCategory *phaseFormat = (RooCategory*)pdfSelRaw->getParameters(_gFit->_selDataVars)->find("phaseFormat"); if (phaseFormat) RooArgSet(*phaseFormat).readFromFile(_configFile,"READ",header) ; pdfSel = doCustomize(pdfSelRaw,_gFit->_selDataVars); if (container==TOYMC) pdfSel->SetName("pdfSelToyMc"); else pdfSel->SetName("pdfSel"); // Get list of parameters after replication RooArgSet* paramsSel = pdfSel->getParameters(_gFit->_selDataVars); // Read the initial parameters from configuration file header="Selection PDF configuration: parameter values"; if (container==TOYMC) header.Prepend("Toy Monte Carlo "); paramsSel->readFromFile(_configFile,"READ",header) ; if (mpi_rank==0) cout << endl << header << " from '" << _configFile << "' : " << endl; // snapshot of params if (_paramsSelInit) delete _paramsSelInit; _paramsSelInit = (RooArgSet*)paramsSel->snapshot(kFALSE) ; // print-out if (mpi_rank==0) { cout << "Initial parameters configured "; paramsSel->selectByAttrib("READ",kTRUE)->Print("v"); cout << "Initial parameters NOT configured "; paramsSel->selectByAttrib("READ",kFALSE)->Print("v"); } // clean delete paramsSel; // assign data members switch(container) { case EXTERNAL: { if (_pdfSelRaw) delete _pdfSelRaw; _pdfSelRaw = pdfSelRaw; _pdfSel = pdfSel; break; } case TOYMC: { assert(0); break; } default: { assert(0); break; } } } // Model Dependent RooSimultaneous *pdfGlobalRaw(0),*pdfGlobal(0); if ((method==MD)||(method==MI)) { // MD PDF is needed for the MI PDF //cout << endl << " Sono qui: Dalitz PDF configuration" << endl; TString header("Dalitz PDF configuration"); if (container==TOYMC) header.Prepend("Toy Monte Carlo "); if (mpi_rank==0) cout << endl; rsbConfig->readFromFile(_configFile,0,header) ; //cout << endl << " Sono qui: rsbConfig->readFromFile" << endl; pdfGlobalRaw = (RooSimultaneous*)_mgr->buildPdf(*rsbConfig,_gFit->_selDataVars,auxCat); //cout << endl << " Sono qui: pdfGlobalRaw" << endl; if (container==TOYMC) pdfGlobalRaw->SetName("pdfGlobalRawToyMc"); else pdfGlobalRaw->SetName("pdfGlobalRaw"); // Perform customization //cout << endl << " Sono qui: perform customization" << endl; RooCategory *phaseFormat = (RooCategory*)pdfGlobalRaw->getParameters(_gFit->_selDataVars)->find("phaseFormat"); if (phaseFormat) RooArgSet(*phaseFormat).readFromFile(_configFile,"READ",header) ; pdfGlobal = doCustomize(pdfGlobalRaw,_gFit->_selDataVars); if (container==TOYMC) pdfGlobal->SetName("pdfGlobalToyMc"); else pdfGlobal->SetName("pdfGlobal"); // Get list of parameters after replication, and remove those not relpicated //cout << endl << " Sono qui: get list of parameters after replication" << endl; RooArgSet* params = pdfGlobal->getParameters(_gFit->_selDataVars); removeDdecayParsNotReplicated(params); // Read the initial parameters from configuration file header="Dalitz PDF configuration: parameter values"; if (container==TOYMC) header.Prepend("Toy Monte Carlo "); params->readFromFile(_configFile,"READ",header) ; if (mpi_rank==0) cout << endl << header << " from '" << _configFile << "' : " << endl; // Make replacement of Dalitz phase differences for K* resonances below K-eta' threshold (1.440 GeV), based in Watson theorem if (*_phaseShiftWatson=="Yes") { pdfGlobal = doPhaseWatsonCustomize(pdfGlobal,_gFit->_selDataVars); delete params; params = pdfGlobal->getParameters(_gFit->_selDataVars); removeDdecayParsNotReplicated(params); } // print-out if (mpi_rank==0) { cout << "Initial parameters configured "; params->selectByAttrib("READ",kTRUE)->Print("v"); cout << "Initial parameters NOT configured "; params->selectByAttrib("READ",kFALSE)->Print("v"); } // replace "AmpX" by "AmpX"+configured amplitude name replaceAmpXbyAmpName(params); // Make replacement of Dalitz parameters //params->Print("v"); pdfGlobal = doDalitzParsCustomize(pdfGlobal,_gFit->_selDataVars); delete params; params = pdfGlobal->getParameters(_gFit->_selDataVars); removeDdecayParsNotReplicated(params); if (mpi_rank==0) params->Print("v"); //assert(0); // snapshot of params if (_paramsInit) delete _paramsInit; _paramsInit = (RooArgSet*)params->snapshot(kFALSE) ; // clean delete params; // assign data members switch(container) { case EXTERNAL: { if (_pdfGlobalRaw) delete _pdfGlobalRaw; _pdfGlobalRaw = pdfGlobalRaw; _pdfGlobal = pdfGlobal; break; } case TOYMC: { if (_pdfGlobalRawToyMc) delete _pdfGlobalRawToyMc; _pdfGlobalRawToyMc = pdfGlobalRaw; _pdfGlobalToyMc = pdfGlobal; break; } default: { assert(0); break; } } } // Model Independent RooSimultaneous *pdfMIGlobalRaw(0),*pdfMIGlobal(0); if (method==MI) { if (mpi_rank==0) cout << endl; TString header("MI Dalitz PDF configuration"); if (container==TOYMC) header.Prepend("Toy Monte Carlo "); if (mpi_rank==0) cout << endl; rsbConfig->readFromFile(_configFile,0,header) ; pdfMIGlobalRaw = (RooSimultaneous*)_mgr->buildPdf(*rsbConfig,_gFit->_selDataVars,auxCat); if (container==TOYMC) pdfMIGlobalRaw->SetName("pdfMIGlobalRawToyMc"); else pdfMIGlobalRaw->SetName("pdfMIGlobalRaw"); // Perform customization RooCategory *phaseFormat = (RooCategory*)pdfMIGlobalRaw->getParameters(_gFit->_selDataVars)->find("phaseFormat"); if (phaseFormat) RooArgSet(*phaseFormat).readFromFile(_configFile,"READ",header) ; pdfMIGlobal = doCustomize(pdfMIGlobalRaw,_gFit->_selDataVars); if (container==TOYMC) pdfMIGlobal->SetName("pdfMIGlobalToyMc"); else pdfMIGlobal->SetName("pdfMIGlobal"); // Estimate MI coefficients using model dependent parameters RooArgSet varsConfig; TIterator *tIterB = _gFit->_BdecayMode->typeIterator() ; TIterator *tIterD = _gFit->_DdecayMode->typeIterator() ; //Int_t ntypeRun = (pdfGlobal->getDependents(_gFit->_selDataVars)->find("runBlock"))? _gFit->_runBlock->numTypes() : 0; //Int_t itypeRun(0); //while (itypeRun<=ntypeRun) { //RooCatType* typeRun = (ntypeRun>0)? (RooCatType*)_gFit->_runBlock->lookupType(itypeRun) : 0; while (RooCatType* typeB = (RooCatType*)tIterB->Next()) { std::list< RooDKMIBinning* >::const_iterator iter_MIBinning = _gFit->_list_MIBinning.begin(); tIterD->Reset(); while (iter_MIBinning != _gFit->_list_MIBinning.end()) { RooDKMIBinning* binning=*iter_MIBinning; RooCatType* typeD = (RooCatType*)tIterD->Next(); TString name; RooAbsPdf* pdf = getPdfComp(pdfGlobal,0,typeB,typeD,name); if (pdf) { // get MD parameters RooArgSet* pars = pdf->getParameters(_gFit->_selDataVars); // get MI PDF and parameters RooAbsPdf* pdfMI = pdfMIGlobal->getPdf(name); RooArgSet* parsMI = pdfMI->getParameters(_gFit->_selDataVars); // calculate MI coefficients (they are dumped into the proto parameters) if (mpi_rank==0) cout << "RooDKFitMaster::build_pdfs: Estimating Ci, Si and Ti MI coefficients for PDF component: " << name << endl; //pars->Print("v"); parsMI->Print("v"); assert(0); binning->build(_configFile,*pars,*parsMI,(Int_t)_nMcExpMICoefs->getVal()); if (mpi_rank==0) parsMI->selectByAttrib("USED",kTRUE)->Print("v"); delete parsMI; delete pars; } iter_MIBinning++; } } //itypeRun++; //} delete tIterD; delete tIterB; // Get list of parameters after replication RooArgSet* paramsMI = pdfMIGlobal->getParameters(_gFit->_selDataVars); removeMIDdecayParsNotUsed(paramsMI); // Read the initial parameters from configuration file header="MI Dalitz PDF configuration: parameter values"; if (container==TOYMC) header.Prepend("Toy Monte Carlo "); paramsMI->readFromFile(_configFile,"READ",header) ; if (mpi_rank==0) cout << endl << header << " from '" << _configFile << "' : " << endl; // Clone for init parameter list if (_paramsMIInit) delete _paramsMIInit; _paramsMIInit = (RooArgSet*)paramsMI->snapshot(kFALSE) ; // print-out if (mpi_rank==0) { cout << "Initial parameters configured "; paramsMI->selectByAttrib("READ",kTRUE)->Print("v"); cout << "Initial parameters NOT configured "; paramsMI->selectByAttrib("READ",kFALSE)->Print("v"); } // clean-up delete paramsMI; // assign data members switch(container) { case EXTERNAL: { if (_pdfMIGlobalRaw) delete _pdfMIGlobalRaw; _pdfMIGlobalRaw = pdfMIGlobalRaw; _pdfMIGlobal = pdfMIGlobal; break; } case TOYMC: { if (_pdfMIGlobalRawToyMc) delete _pdfMIGlobalRawToyMc; _pdfMIGlobalRawToyMc = pdfMIGlobalRaw; _pdfMIGlobalToyMc = pdfMIGlobal; break; } default: { assert(0); break; } } } // clean-up delete rsbConfig; } // generate toy Mc samples and put into TOYMC container void RooDKFitMaster::generateToyMc(Method method) { int mpi_rank = get_mpi_rank(); if (mpi_rank==0) cout << endl << "Toy Monte Carlo generation" << endl; // get pdf to be used RooSimultaneous* pdfToyMc(0); switch(method) { case SEL: { assert(0); break; } case MD : { pdfToyMc = _pdfGlobalToyMc; break; } case MI : { pdfToyMc = _pdfMIGlobalToyMc; break; } default : { assert(0); break; } } // read fit results if (*_toyMcParamsFromResultsRootFile=="Yes") read_fitresults_fromRoot(); // read driver options RooArgSet varsConfig; // seed and MC generation option _toyMcOption = new RooCategory("toyMcOption","Toy MC option") ; _toyMcOption->defineType("prototype") ; _toyMcOption->defineType("allRandom") ; _toyMcOption->setLabel("allRandom"); _toyMcFixYields = new RooCategory("toyMcFixYields","Toy MC fixed yields") ; _toyMcFixYields->defineType("No") ; _toyMcFixYields->defineType("Yes") ; _toyMcFixYields->setLabel("No"); varsConfig.addOwned(RooArgSet(*_toyMcOption,*_toyMcFixYields)); // number of events to be generated (per B and D decay mode), and deltaEshift parameters TString name; name="toyMcPTrkThick"; RooRealVar* pTrkThick = new RooRealVar(name,name,0.065); varsConfig.addOwned(*pTrkThick); name="toyMcPTrkMin"; RooRealVar* pTrkMin = new RooRealVar(name,name,1.571); varsConfig.addOwned(*pTrkMin); name="toyMcPTrkMax"; RooRealVar* pTrkMax = new RooRealVar(name,name,3.605); varsConfig.addOwned(*pTrkMax); // TIterator *tIterD = _gFit->_DdecayMode->typeIterator() ; while (RooCatType* typeD = (RooCatType*)tIterD->Next()) { name="toyMctErrMean_"+TString(typeD->GetName()); RooRealVar* tErrMean = new RooRealVar(name,name,0.071); varsConfig.addOwned(*tErrMean); name="toyMctErrWidth_"+TString(typeD->GetName()); RooRealVar* tErrWidth = new RooRealVar(name,name,0.020); varsConfig.addOwned(*tErrWidth); name="toyMctErrDelta_"+TString(typeD->GetName()); RooRealVar* tErrDelta = new RooRealVar(name,name,1.85); varsConfig.addOwned(*tErrDelta); name="toyMctErrGamma_"+TString(typeD->GetName()); RooRealVar* tErrGamma = new RooRealVar(name,name,-5.62); varsConfig.addOwned(*tErrGamma); } delete tIterD; // read from file varsConfig.readFromFile(_configFile,"READ","Toy Monte Carlo configuration: Driver Options") ; if (mpi_rank==0) varsConfig.Print("v"); //assert(0); // generation if (mpi_rank==0) cout << " Start toy Monte Carlo generation " << endl; // get list of pdf dependents RooArgSet depsPdf(*pdfToyMc->getDependents(_gFit->_selDataVars)); //depsPdf.Print("v"); assert(0); // get list of pdf parameters RooArgSet paramsPdf(*pdfToyMc->getParameters(_gFit->_selDataVars)); //paramsPdf.Print("v"); //assert(0); if (*_toyMcRandomizePhysParams=="Yes") randomizePhysParams(paramsPdf); if (mpi_rank==0) cout << endl << "Generating events with the following parameter values: " << endl; if (mpi_rank==0) paramsPdf.Print("v"); // assert(0); // get pointers to selection variables RooRealVar* mES = (RooRealVar*)depsPdf.find("mES"); RooRealVar* fisher = (RooRealVar*)depsPdf.find("fisher"); RooRealVar* recState = (RooRealVar*)depsPdf.find("recState"); RooRealVar* mD = (RooRealVar*)depsPdf.find("mD"); RooRealVar* deltam = (RooRealVar*)depsPdf.find("deltam"); RooRealVar* deltaE_dk = (RooRealVar*)depsPdf.find("deltaE_dk"); RooRealVar* deltaE_dpi = (RooRealVar*)depsPdf.find("deltaE_dpi"); RooRealVar* deltaE = (RooRealVar*)depsPdf.find("deltaE"); // build list of common pdf dependents to generate RooArgSet depsToGen; if (method==MD) { RooRealVar* qAB = (RooRealVar*)depsPdf.find("qAB"); if (qAB) depsToGen.add(*qAB); RooRealVar* qAC = (RooRealVar*)depsPdf.find("qAC"); if (qAC) depsToGen.add(*qAC); RooRealVar* qBC = (RooRealVar*)depsPdf.find("qBC"); if (qBC) depsToGen.add(*qBC); RooCategory* recState = (RooCategory*)depsPdf.find("recState"); if (recState) depsToGen.add(*recState); RooRealVar* tReco = (RooRealVar*)depsPdf.find("tReco"); if (tReco) depsToGen.add(*tReco); RooRealVar* tTrue = (RooRealVar*)depsPdf.find("tTrue"); if (tTrue) depsToGen.add(*tTrue); //RooRealVar* tErr = (RooRealVar*)depsPdf.find("tErr"); //if (tErr) depsToGen.add(*tErr); } if (method==MI) depsToGen.add(RooArgSet(*_gFit->_iBinACAB,*_gFit->_iBinStateACAB)); // delete previous data set if (_fitDataSelToyMc) delete _fitDataSelToyMc; if (_fitDataToyMc) delete _fitDataToyMc; // generation allRandom if (*_toyMcOption=="allRandom") { if (mpi_rank==0) cout << endl << "Generating events with allRandom option" << endl << endl; //if (!TString(pdfToyMc->GetName()).Contains("Extend")) { // if (mpi_rank==0) cout << "RooDKFitMaster::generateToyMc: configuration error. The allRandom Toy MC generation PDF has to be of extended type." << endl; // assert(0); //} if (mES) depsToGen.add(*mES); if (fisher) depsToGen.add(*fisher); if (mD) depsToGen.add(*mD); if (deltam) depsToGen.add(*deltam); if (deltaE_dk) depsToGen.add(*deltaE_dk); if (deltaE_dpi) depsToGen.add(*deltaE_dpi); if (deltaE) depsToGen.add(*deltaE); //TIterator *tIterRun = _gFit->_runBlock->typeIterator() ; TIterator* tIterB = _gFit->_BdecayMode->typeIterator() ; TIterator *tIterD = _gFit->_DdecayMode->typeIterator() ; RooArgSet depsProto(*_gFit->_BdecayMode,*_gFit->_BdecayModeLF,*_gFit->_DdecayMode,*_gFit->_DdecayModeLF,*_gFit->_DdecayMode_split,*_gFit->_betagammaBoost); depsProto.add(*_gFit->_runBlock); depsProto.add(*_gFit->_recState); // must be in the list. Actual value will be assigned by generator //depsProto.add(*_gFit->_BdecayClass); //while (RooCatType* typeRun = (RooCatType*)tIterRun->Next()) { //tIterB->Reset(); while (RooCatType* typeB = (RooCatType*)tIterB->Next()) { tIterD->Reset(); while (RooCatType* typeD = (RooCatType*)tIterD->Next()) { TString namePdfComp; RooAbsPdf* pdfComp = getPdfComp(pdfToyMc,0,typeB,typeD,namePdfComp); if (pdfComp) { // define B, D decay mode and p_trk pdf (used for prototype) RooRealVar* pTrkThick = (RooRealVar*) varsConfig.find("toyMcPTrkThick"); RooRealVar* pTrkMin = (RooRealVar*) varsConfig.find("toyMcPTrkMin"); RooRealVar* pTrkMax = (RooRealVar*) varsConfig.find("toyMcPTrkMax"); RooRealVar* tErrMean = (RooRealVar*) varsConfig.find("toyMctErrMean_"+TString(typeD->GetName())); RooRealVar* tErrWidth = (RooRealVar*) varsConfig.find("toyMctErrWidth_"+TString(typeD->GetName())); RooRealVar* tErrDelta = (RooRealVar*) varsConfig.find("toyMctErrDelta_"+TString(typeD->GetName())); RooRealVar* tErrGamma = (RooRealVar*) varsConfig.find("toyMctErrGamma_"+TString(typeD->GetName())); _gFit->_BdecayMode->setLabel(typeB->GetName()); _gFit->_DdecayMode->setLabel(typeD->GetName()); _gFit->_BdecayModeLF->setIndex(_gFit->_BdecayMode->getIndex()); _gFit->_DdecayModeLF->setIndex(_gFit->_DdecayMode->getIndex()); _gFit->_DdecayMode_split->setIndex(_gFit->_DdecayMode->getIndex()); _gFit->_betagammaBoost->setVal(0.556); _gFit->_runNumber->setVal(-atol(_toyMcSeed->getVal())); //_gFit->_BdecayClass->setIndex( (typeB->getVal()>6)? 0 : 1 ); //cout << typeB->GetName() << " " << typeB->getVal() << endl; //RooAbsPdf* pTrkPdf = (TString(_deltaEDhOption->getLabel())=="deltaEshift" && typeB->getVal()<=6)? RooAbsPdf* pTrkPdf = (TString(_deltaEDhOption->getLabel())=="deltaEshift")? new RooGenericPdf("pTrkPdf","pTrk parameterized PDF","( 1/(1+exp(-(@0-@2)/@1)) + 1/(1+exp((@0-@3)/@1)) ) - 1", RooArgList(*_gFit->_pTrk,*pTrkThick,*pTrkMin,*pTrkMax)) : (RooAbsPdf*)0 ; //RooAbsPdf* tErrPdf = (TString(_resFcn->getLabel()).EndsWith("EventError"))? // to generate prototype tErr distribution (DdecayMode dependent) //RooAbsPdf* tErrPdf = ((TString(_resFcn->getLabel())!="Unknown") && (TString(_resFcn->getLabel())!="Truth")) ? RooAbsPdf* tErrPdf = (TString(_resFcn->getLabel())!="Unknown") ? // to generate prototype tErr distribution (DdecayMode dependent) new RooJohnsonSU("tErrPdf","tErr parameterized PDF",*_gFit->_tErr,*tErrMean,*tErrWidth,*tErrGamma,*tErrDelta) : (RooAbsPdf*)0 ; // generate selection range data set //depsProto.Print("v");depsToGen.Print("v"); //assert(0); RooDataSet *data_genSel = generateComp(pdfComp,depsProto,depsToGen,pTrkPdf,tErrPdf,0,0); // add deltaE (from deltaE_dk or deltaE_dpi) if (deltaE==0 && (deltaE_dk || deltaE_dpi) && data_genSel && data_genSel->numEntries()>0) { RooDataSet* data_deltaE = new RooDataSet("data_deltaE","data_deltaE",*_gFit->_deltaE); for (Int_t iEvt=0;iEvtnumEntries();iEvt++) { const RooArgSet *columns = data_genSel->get(iEvt); RooRealVar* deltaE_data_dk = (RooRealVar*)columns->find("deltaE_dk"); RooRealVar* deltaE_data_dpi = (RooRealVar*)columns->find("deltaE_dpi"); Double_t deltaEVal = (deltaE_data_dk)? deltaE_data_dk->getVal() : deltaE_data_dpi->getVal(); _gFit->_deltaE->setVal(deltaEVal); data_deltaE->add(*_gFit->_deltaE); } data_genSel->merge(data_deltaE); } if (data_genSel && data_genSel->numEntries()>0) { // add 3rd Dalitz plot variable const RooArgSet* vars = data_genSel->get(); RooRealVar* qAB = (RooRealVar*)vars->find("qAB"); RooRealVar* qAC = (RooRealVar*)vars->find("qAC"); RooRealVar* qBC = (RooRealVar*)vars->find("qBC"); if (!(qAB==0 && qAC==0 && qBC==0)) { assert(qAB && qAC && qBC==0); _gFit->_DdecayModeLF->setIndex(typeD->getVal()); EvtDalitzPlot dp(EvtDecayMode(_gFit->_DdecayModeLF->getLabel())); RooRealVar dpSum("dpSum","dpSum",dp.sum()); RooFormulaVar* qBC_func = new RooFormulaVar("qBC","qBC","@0-@1-@2",RooArgList(dpSum,*qAB,*qAC)); //RooRealVar* qBC = (RooRealVar*)qBC_func.createFundamental(); (RooRealVar*) data_genSel->addColumn(*qBC_func) ; } // add to deltaE selection range data set if (_fitDataSelToyMc) _fitDataSelToyMc->append(*data_genSel); else _fitDataSelToyMc = data_genSel; // create Dalitz range cut /* TString cut; if (deltaE_dpi && deltaE_dk) cut=_dsel_fit->getVal(); else { if (deltaE_dpi) cut=_dsel_dpi->getVal(); else if (deltaE_dk) cut=_dsel_dk->getVal(); } */ TString dsel_fitSel,dsel_fit; TString dsel_dk_fit,dsel_dpi_fit; buildAllCuts(deltaE!=0,fisher!=0,mD!=0,deltam!=0,1,dsel_fitSel,dsel_fit,dsel_dk_fit,dsel_dpi_fit); if (mpi_rank==0) cout << "RooDKFitMaster::generateToyMc(): dsel_fitSel = " << _dsel_fitSel->getVal() << endl; //RooDataSet *data_gen = (RooDataSet*)data_genSel->reduce(_gFit->_selDataVars,dsel_fit); RooDataSet *data_gen = (dsel_fit=="")? (RooDataSet*)data_genSel->Clone() : (RooDataSet*)data_genSel->reduce(dsel_fit); // add to Dalitz range data set if (_fitDataToyMc) _fitDataToyMc->append(*data_gen); else _fitDataToyMc = data_gen; // clean-up if (pTrkPdf) delete pTrkPdf; } } } //} } //_fitDataToyMc->Print("v"); _fitDataToyMc->write("results/fitDataToyMc.dat"); //assert(0); // clean-up delete tIterB; delete tIterD; //delete tIterRun; } // generation prototype (not updated for D-mixing. Update if needed) if (*_toyMcOption=="prototype") { if (mpi_rank==0) cout << endl << "Generating events with prototype option" << endl << endl; assert(0); // Long time w/o checking. Obsolete // create first prototype data RooArgSet depsProto(*_fitDataSel->get(0)); RooAbsArg *qAB = depsProto.find("qAB"); if (qAB) depsProto.remove(*qAB); RooAbsArg *qAC = depsProto.find("qAC"); if (qAC) depsProto.remove(*qAC); RooAbsArg *qBC = depsProto.find("qBC"); if (qBC) depsProto.remove(*qBC); RooAbsArg *recState = depsProto.find("recState"); if (recState) depsProto.remove(*recState); RooDataSet* data_proto = new RooDataSet("data_proto","data_proto",depsProto); for (Int_t iEvt=0;iEvt<_fitDataSel->numEntries();iEvt++) { RooArgSet event(*_fitDataSel->get(iEvt)); RooAbsArg *qAB = event.find("qAB"); if (qAB) event.remove(*qAB); RooAbsArg *qAC = event.find("qAC"); if (qAC) event.remove(*qAC); RooAbsArg *qBC = event.find("qBC"); if (qBC) event.remove(*qBC); RooAbsArg *recState = event.find("recState"); if (recState) event.remove(*recState); data_proto->add(event); } // deltaE selection range data set if (deltaE_dk) deltaE_dk->setRange(_deltaEMin_dkSel->getVal(),_deltaEMax_dkSel->getVal()); if (deltaE_dpi) deltaE_dpi->setRange(_deltaEMin_dpiSel->getVal(),_deltaEMax_dpiSel->getVal()); fisher->setRange(_fisherMin_Sel->getVal(),_fisherMax_Sel->getVal()); mD->setRange(_mDMin_Sel->getVal(),_mDMax_Sel->getVal()); if (deltam) deltam->setRange(_deltamMin_Sel->getVal(),_deltamMax_Sel->getVal()); TIterator* tIterB = _gFit->_BdecayMode->typeIterator() ; TIterator *tIterD = _gFit->_DdecayMode->typeIterator() ; while (RooCatType* typeB = (RooCatType*)tIterB->Next()) { tIterD->Reset(); while (RooCatType* typeD = (RooCatType*)tIterD->Next()) { TString namePdfComp; RooAbsPdf* pdfComp = getPdfComp(pdfToyMc,0,typeB,typeD,namePdfComp); if (pdfComp) { TString cutProj("(BdecayMode==BdecayMode::"); cutProj.Append(typeB->GetName()); cutProj.Append(")&&(DdecayMode==DdecayMode::"); cutProj.Append(typeD->GetName()); cutProj.Append(")"); if (mpi_rank==0) cout << "RooDKFitMaster::generateToyMc: generating with prototype option component " << typeB->GetName() << "," << typeD->GetName() << endl; if (mpi_rank==0) cout << "Projection cut: " << cutProj << endl; if (!pdfComp->canBeExtended()) { if (mpi_rank==0) cout << "RooDKFitMaster::generateToyMc: configuration error. The Toy MC generation PDF must be of extended type." << endl; assert(0); } RooDataSet* data_protoComp = (RooDataSet*)data_proto->reduce(cutProj); //RooMCStudy mcStudy(*pdfComp,*pdfComp,depsToGen,0,0,data_protoComp); // we use RooMCStudy only to generate RooMCStudy mcStudy(*pdfComp,*pdfComp,depsToGen,"r",0,data_protoComp); // we use RooMCStudy only to generate //RooMCStudy mcStudy(*pdfComp,*pdfComp,depsToGen,"er",0,data_protoComp); // we use RooMCStudy only to generate ////Double_t NevtsExp = pdfComp->expectedEvents(); Double_t NevtsExp = (Double_t)data_protoComp->numEntries(); Int_t Nevts = _generator->Poisson(NevtsExp); // with fluctuations mcStudy.generate(1,Nevts,kTRUE); //mcStudy.generate(1,0,kTRUE); RooDataSet* data_genSel = (RooDataSet*)mcStudy.genData(0)->Clone(); //RooDataSet* data_genSel = (RooDataSet*)pdfComp->generate(depsToGen,*data_protoComp); if (_fitDataSelToyMc) _fitDataSelToyMc->append(*data_genSel); else _fitDataSelToyMc = data_genSel; delete data_protoComp; } } } delete tIterB; delete tIterD; // create deltaE Dalitz range data _fitDataToyMc = (RooDataSet*)_fitDataSelToyMc->reduce(_dsel_fit->getVal()); // clean-up delete data_proto; } // statistics tables if (_fitDataSelToyMc==0) return; if (mpi_rank==0) { //for (Int_t iEvt=0;iEvt<_fitDataSelToyMc->numEntries();iEvt++) _fitDataSelToyMc->get(iEvt)->Print("v"); cout << endl; cout << "RooDKFitMaster::generateToyMc: fitDataSelToyMc has " << _fitDataSelToyMc->numEntries() << " events" << endl; cout << endl; statisticsTables(_fitDataSelToyMc); } // if (_fitDataToyMc==0) return; if (mpi_rank==0) { //for (Int_t iEvt=0;iEvt<_fitDataToyMc->numEntries();iEvt++) _fitDataToyMc->get(iEvt)->Print("v"); cout << endl; cout << "RooDKFitMaster::generateToyMc: fitDataToyMc has " << _fitDataToyMc->numEntries() << " events" << endl; cout << endl; statisticsTables(_fitDataToyMc); //assert(0); } } RooDataSet* RooDKFitMaster::generateComp(RooAbsPdf* pdfComp, RooArgSet& depsProto, RooArgSet& depsToGen, RooAbsPdf* pTrkPdf, RooAbsPdf* tErrPdf, Int_t charge, Int_t nTotEvts) { // If nTotEvents>0, the generate the given number of events, using the fractions or yields of each component of the pdf to weight the component // If charge=0, generate the two charge states (half and half) // The number of events is fixed (i.e. no Poisson fluctuations) // If nTotEvents=0 and extended likelihood, generate using expected number of events (takes into account charge asymmetries), // i.e. positive and negative charge number of events // Can add or not Poisson fluctuations // If charge=+1,-1 generate only the given charge state int mpi_rank = get_mpi_rank(); // initialization and sanity checks assert(charge==0 || charge==+1 || charge==-1); Bool_t Extend = TString(pdfComp->GetName()).Contains("Extend"); if (!Extend && nTotEvts==0) { if (mpi_rank==0) cout << "RooDKFitMaster::generateComp: configuration error. The Toy MC generation PDF has to be of extended type or must specify nTotEvts>0" << endl; assert(0); } RooDataSet* data_genSel(0); if (mpi_rank==0) cout << " PDF to be generated is of type RooAddPdf. Generating each of the "; RooArgList *coefList,*pdfList; if (dynamic_cast(pdfComp)) { coefList = (RooArgList*)&((RooAddPdf*)pdfComp)->coefList(); pdfList = (RooArgList*)&((RooAddPdf*)pdfComp)->pdfList(); } else { coefList = new RooArgList("coefList"); pdfList = new RooArgList(*pdfComp,"pdfList"); } Int_t nComp(pdfList->getSize()); assert((Extend && coefList->getSize()==nComp) || (!Extend && (coefList->getSize()+1)==nComp)); // another sanity check if (mpi_rank==0) cout << nComp << " components separately" << endl; // get parameters and pointer to recState variable RooArgSet* pdfParams = pdfComp->getParameters(_gFit->_selDataVars); RooCategory* recState = (RooCategory*)pdfParams->find("recState"); //pdfComp->getDependents(_gFit->_selDataVars)->Print("v"); //pdfParams->Print("v"); //assert(0); // make sure there are no common variables in dataProto and depsProto /* if (dataProto && depsProto.getSize()>0) { const RooArgSet *columns = dataProto->get(0); TIterator* iter = depsProto.createIterator(); RooAbsArg* item; while (item = (RooAbsArg*)iter->Next()) { if (columns->find(item->GetName())) { if (mpi_rank==0) { cout << "RooDKFitMaster::generateComp() ERROR: duplicated variable in dataProto and depsProto" << endl; dataProto->Print("v"); depsProto.Print("v"); } assert(0); } } delete iter; } */ // get deltaE dependent and define selection region Double_t min, max, minSel, maxSel; RooRealVar* deltaE = getDeltaEComp(pdfComp,min,max,minSel,maxSel,kTRUE); //std::vector pdfnames; //std::vector coefs,coefsSel,ratios; //rescalePdfCoefs(*pdfList,*coefList,deltaE,min,max,minSel,maxSel,pdfnames,coefs,coefsSel,ratios); //if (deltaE) deltaE->setRange(minSel,maxSel); // generate events in selection deltaE region // calculate sum of coeficients Double_t NevtsCompSum_minus(0.),NevtsCompSum_plus(0.); Double_t sumcoef(0.); for (Int_t iComp=0;iCompat(iComp); Double_t coef_val(0.),coef_val_minus(0.),coef_val_plus(0.); if (Extend && nTotEvts==0) { if (recState) { recState->setIndex(-1); coef_val_minus = coef->getVal(pdfParams); recState->setIndex(+1); coef_val_plus = coef->getVal(pdfParams); } else { coef_val_minus = 0.5*coef->getVal(pdfParams); coef_val_plus = 0.5*coef->getVal(pdfParams); } } else { // this happens in practice when nTotEvents>0 assert(nTotEvts>0); if (coef) { coef_val = coef->getVal()*nTotEvts; //cout << coef->getVal() << " " << coef_val << endl; sumcoef += coef_val; } else { coef_val = nTotEvts - sumcoef; //cout << coef_val << endl; } coef_val_minus = coef_val; coef_val_plus = coef_val; } NevtsCompSum_minus += coef_val_minus; //cout << iComp << " " << " coeficient charge -1 = " << coef_val; NevtsCompSum_plus += coef_val_minus; //cout << " " << " coeficient charge +1 = " << coef_val << endl; } // generate events component by component sumcoef=0.; for (Int_t iComp=0;iCompat(iComp); RooAbsReal* coef = (RooRealVar*)coefList->at(iComp); Double_t coef_val(0.),coef_val_minus(0.),coef_val_plus(0.); if (Extend && nTotEvts==0) { if (recState) { recState->setIndex(-1); coef_val_minus = coef->getVal(pdfParams); recState->setIndex(+1); coef_val_plus = coef->getVal(pdfParams); } else { coef_val_minus = 0.5*coef->getVal(pdfParams); coef_val_plus = 0.5*coef->getVal(pdfParams); } } else { assert(nTotEvts>0); if (coef) { coef_val = coef->getVal()*nTotEvts; //cout << coef->getVal() << " " << coef_val << endl; sumcoef += coef_val; } else { coef_val = nTotEvts - sumcoef; } coef_val_minus = coef_val; coef_val_plus = coef_val; //cout << coef_val << " " << coef_val_minus << " " << coef_val_plus << endl; } Int_t Nevts_minus(0),Nevts_plus(0); Double_t NevtsExp_minus(0),NevtsExp_plus(0); NevtsExp_minus = (nTotEvts==0)? coef_val_minus : (Double_t)nTotEvts*coef_val_minus/NevtsCompSum_minus; NevtsExp_plus = (nTotEvts==0)? coef_val_plus : (Double_t)nTotEvts*coef_val_plus/NevtsCompSum_plus; if (nTotEvts!=0 && charge==0) { // half and half for charge zero NevtsExp_minus /= 2.; NevtsExp_plus /= 2.; } if (charge==-1) NevtsExp_plus = 0; // generate on charge plus if (charge==+1) NevtsExp_minus = 0; // generate only charge plus if(nTotEvts==0){ assert(_toyMcFixYields!=0); if (*_toyMcFixYields=="No") { Nevts_minus = _generator->Poisson(NevtsExp_minus); // with fluctuations Nevts_plus = _generator->Poisson(NevtsExp_plus); // with fluctuations } else { Nevts_minus = (Int_t)NevtsExp_minus; // no fluctuations Nevts_plus = (Int_t)NevtsExp_plus; // no fluctuations } } else { Nevts_minus = (Int_t)NevtsExp_minus; Nevts_plus = (Int_t)NevtsExp_plus; } if (mpi_rank==0) cout << " PDF component " << iComp << "[" << pdf->GetName() << "]" << " will be generated with " << Nevts_minus << " B- events and " << Nevts_plus << " B+ events (" << Nevts_minus+Nevts_plus << " events total)" << endl; if (Nevts_minus>0 || Nevts_plus>0) { //depsProto.Print("v"); assert(depsProto.find(_gFit->_recState->GetName())); RooDataSet* data_proto = new RooDataSet("data_proto","data_proto",depsProto); _gFit->_recState->setIndex(-1); for (Int_t iEvt=0;iEvtadd(depsProto); _gFit->_recState->setIndex(+1); for (Int_t iEvt=0;iEvtadd(depsProto); RooDataSet* data_pTrk(0); if (pTrkPdf) { data_pTrk = pTrkPdf->generate(*_gFit->_pTrk,Nevts_minus+Nevts_plus); data_proto->merge(data_pTrk); data_proto->addColumn(*_gFit->_deltaEshift_func); } RooDataSet* data_tErr(0); if (tErrPdf) { data_tErr = tErrPdf->generate(*_gFit->_tErr,Nevts_minus+Nevts_plus); data_proto->merge(data_tErr); } //depsToGen.Print("v"); data_proto->get(0)->Print("v"); assert(0); //for (Int_t iEvt=0;iEvtnumEntries();iEvt++) data_proto->get(iEvt)->Print("v"); //data_proto->Print("v"); data_proto->write("results/data_proto.dat") ; //assert(0); // Print flat file for data_proto RooDataSet* data_genSel_comp = pdf->generate(depsToGen,*data_proto); //for (Int_t iEvt=0;iEvtnumEntries();iEvt++) data_genSel_comp->get(iEvt)->Print("v"); //data_genSel_comp->Print("v"); data_genSel_comp->write("results/data_genSel_comp.dat") ; //assert(0); // Print flat file for data_genSel_comp if (data_genSel) data_genSel->append(*data_genSel_comp); else data_genSel = data_genSel_comp; if (data_pTrk) delete data_pTrk; delete data_proto; } } // cleanup if (dynamic_cast(pdfComp)==0) { delete coefList; delete pdfList; } delete pdfParams; // return generated data set return data_genSel; } void RooDKFitMaster::rescalePdfCoefs(const RooArgList& pdfList, const RooArgList& coefList, const RooArgSet& deps, const char* rangeName_init, const char* rangeName_final, std::vector& pdfnames, std::vector& coefs_init, std::vector& coefs_final, std::vector& ratios) { // Rescale PDF coeficients from initial variable(s) range(s) to final variable(s) range(s), given a pdfList, coefList, and deps // check that output lists are clean assert(pdfnames.size()==0 && coefs_init.size()==0 && coefs_final.size()==0 && ratios.size()==0); // loop over all PDF components, evaluate initial and final variable range PDF integrals of each component, and evaluate ratio of the two Double_t sum(0.); Int_t nComp(pdfList.getSize()); Bool_t extend(coefList.getSize()==nComp); for (Int_t iComp=0;iCompgetVal() ); RooAbsPdf* pdf = (RooAbsPdf*)pdfList.at(iComp); pdfnames.push_back(pdf->GetName()); if (pdfnames[iComp].BeginsWith("gbl")) { // if global PDF, then take the first item of the product (must be the selection PDF) RooProdPdf* pdfProd = dynamic_cast(pdf); assert(pdfProd); const RooArgList& pdfProdList = pdfProd->pdfList(); pdf = (RooAbsPdf*)pdfProdList.at(0); pdfnames[iComp] = pdf->GetName(); assert( pdfnames[iComp].BeginsWith("sel") ) ; } else assert( pdfnames[iComp].BeginsWith("sel") ); // make integrals RooNumIntConfig* intConfig = (RooNumIntConfig*)pdf->getIntegratorConfig(); //cout << "RooDKFitMaster::rescalePdfCoef(): Original RooNumIntConfig precision: epsRel = " << intConfig->epsRel() << " , epsAbs = " << intConfig->epsAbs() << endl; intConfig->setEpsRel(1e-4); //intConfig->setEpsAbs(1e-7); //cout << "RooDKFitMaster::rescalePdfCoef(): New RooNumIntConfig precision: epsRel = " << intConfig->epsRel() << " , epsAbs = " << intConfig->epsAbs() << endl; RooAbsReal* pdfInt_final = pdf->createIntegral(deps,NormSet(deps),Range(rangeName_final)); Double_t f_final = pdfInt_final->getVal(); RooAbsReal* pdfInt_init = pdf->createIntegral(deps,NormSet(deps),Range(rangeName_init)); Double_t f_init = pdfInt_init->getVal(); // fill output vectors ratios.push_back( f_init>0.? f_final/f_init : (f_final>0.? 1e30 : 0.) ); //cout << pdfnames[iComp] << " f_init = " << f_init << " f_final = " << f_final << " f_final/f_init = " << f_final/f_init << endl; coefs_final.push_back(ratios[iComp]*coefs_init[iComp]); sum += coefs_final[iComp]; } if (!extend) for (Int_t iComp=0;iComp_BdecayMode->lookupType(BMode); RooCatType* typeD = (RooCatType*)_gFit->_DdecayMode->lookupType(DMode); TString nameComp; RooAbsPdf* pdf = getPdfComp(_pdfSel,0,typeB,typeD,nameComp); if (pdf==0) return; // get coef and pdf lists RooArgList *coefList(0),*pdfList(0); if (dynamic_cast(pdf)) { coefList = (RooArgList*)&((RooAddPdf*)pdf)->coefList(); pdfList = (RooArgList*)&((RooAddPdf*)pdf)->pdfList(); } else { coefList = new RooArgList("coefList"); pdfList = new RooArgList(*pdf,"pdfList"); } //Int_t nComp(pdfList->getSize()); //Bool_t extend(coefList->getSize()==nComp); // extended PDF? // get scale factors std::vector pdfnames; std::vector coefsSel,coefs,ratios; RooArgSet* deps = pdf->getDependents(_gFit->_selDataVars); RooRealVar* mD = (RooRealVar*)deps->find("mD"); RooRealVar* deltam = (RooRealVar*)deps->find("deltam"); if (mD) { mD->setRange("DalRange",_mDMin->getVal(),_mDMax->getVal()); mD->setRange("SelRange",_mDMin_Sel->getVal(),_mDMax_Sel->getVal()); } if (deltam) { deltam->setRange("DalRange",_deltamMin->getVal(),_deltamMax->getVal()); deltam->setRange("SelRange",_deltamMin_Sel->getVal(),_deltamMax_Sel->getVal()); } /* RooRealVar* deltaE_dk = (RooRealVar*)deps->find("deltaE_dk"); if (deltaE_dk) { deltaE_dk->setRange("DalRange",_deltaEMin_dk->getVal(),_deltaEMax_dk->getVal()); deltaE_dk->setRange("SelRange",_deltaEMin_dkSel->getVal(),_deltaEMax_dkSel->getVal()); } RooRealVar* deltaEshift = (RooRealVar*)deps->find("deltaEshift"); if (deltaEshift) { //deltaEshift->setRange("DalRange",_deltaEshiftMin->getVal(),_deltaEshiftMax->getVal()); //deltaEshift->setRange("SelRange",_deltaEshiftMin->getVal(),_deltaEshiftMax->getVal()); deltaEshift->setVal(0.050); deltaEshift->setRange("DalRange",0.049,0.051); deltaEshift->setRange("SelRange",0.049,0.051); } cout << "RooDKFitMaster::rescaleYields() deps::" << endl; deps->Print("v"); */ rescalePdfCoefs(*pdfList,*coefList,*deps,"SelRange","DalRange",pdfnames,coefsSel,coefs,ratios); // print-out if (mpi_rank==0) cout << endl << "RooDKFitMaster::rescaleYields() for (BMode,DMode) = " << BMode << "," << DMode << endl; for (Int_t i=0;isnapshot(); for (Int_t i=0;i(coefList->at(i)); RooRealVar* var_final = dynamic_cast(coefList_copy->at(i)); if (var_init && var_final) { var_final->setVal( var_init->getVal()*ratios[i] ); var_final->setError( var_init->getError()*ratios[i] ); } } if (mpi_rank==0) cout << endl << "Rescaled yields..." << endl; RooArgSet(*coefList_copy).writeToStream(os,kFALSE); if (mpi_rank==0) cout << endl; // clean-up delete deps; pdfnames.clear(); coefsSel.clear(); coefs.clear(); ratios.clear(); if (dynamic_cast(pdf)==0) { delete coefList; delete pdfList; } } RooRealVar* RooDKFitMaster::getDeltaEComp(RooAbsPdf* pdf, Double_t& min, Double_t& max, Double_t& minSel, Double_t& maxSel, Bool_t rangeSel) { RooArgSet* deps_pdf = pdf->getDependents(_gFit->_selDataVars); //deps_pdf->Print("v"); RooRealVar* deltaE = (RooRealVar*)deps_pdf->find("deltaE_dk"); if (deltaE) { min=_deltaEMin_dk->getVal(); max=_deltaEMax_dk->getVal(); minSel=_deltaEMin_dkSel->getVal(); maxSel=_deltaEMax_dkSel->getVal(); } else { deltaE = (RooRealVar*)deps_pdf->find("deltaE_dpi"); if (deltaE) { min=_deltaEMin_dpi->getVal(); max=_deltaEMax_dpi->getVal(); minSel=_deltaEMin_dpiSel->getVal(); maxSel=_deltaEMax_dpiSel->getVal(); } } delete deps_pdf; if (deltaE) { if (rangeSel) deltaE->setRange(minSel,maxSel); else deltaE->setRange(min,max); } return deltaE; } // configure I/O toy MC generation void RooDKFitMaster::IOToyMc() { int mpi_rank = get_mpi_rank(); if (mpi_rank==0) cout << "Configuring I/O for toy Monte Carlo generation" << endl; // create and read general toy MC configuration data _toyMcParamsFromResultsRootFile = new RooCategory("toyMcParamsFromResultsRootFile","Switch: PDF params from ROOT file") ; _toyMcParamsFromResultsRootFile->defineType("Yes") ; _toyMcParamsFromResultsRootFile->defineType("No") ; _toyMcParamsFromResultsRootFile->setLabel("No") ; _toyMcDataRootFile = new RooStringVar("toyMcDataRootFile","ROOT file with persisted toy MC data","") ; _toyMcResultsRootFile = new RooStringVar("toyMcResultsRootFile","ROOT file with persisted toy MC fit results","") ; _toyMcRandomizePhysParams = new RooCategory("toyMcRandomizePhysParams","Switch: Randomize PHYSICS parameters") ; _toyMcRandomizePhysParams->defineType("No") ; _toyMcRandomizePhysParams->defineType("Yes") ; _toyMcRandomizePhysParams->setLabel("No") ; _toyMcSeed = new RooStringVar("toyMcSeed","Toy MC random seed","-1") ; _fileConfigToyMcGen.addOwned(RooArgSet(*_toyMcParamsFromResultsRootFile,*_toyMcResultsRootFile,*_toyMcDataRootFile)); _fileConfigToyMcGen.addOwned(RooArgSet(*_toyMcRandomizePhysParams,*_toyMcSeed)); _fileConfigToyMcGen.readFromFile(_configFile,"READ","Toy Monte Carlo configuration: Input/Output") ; if (mpi_rank==0) _fileConfigToyMcGen.Print("v") ; // // get and apply random seed UInt_t seed = atol(_toyMcSeed->getVal()); // if zero, machine clock (precision 1 s) if (seed<=0) { if (mpi_rank==0) cout << " Error in Toy MC configuration: random Seed must be a non-zero positive number" << endl; assert(0); } _generator = RooRandom::randomGenerator(); _generator->SetSeed(seed); } // perform fit on given dataset container void RooDKFitMaster::perform_fit(Method method, Container container, Int_t nCPUs) { int mpi_rank = get_mpi_rank(); //_fitData->Print("v"); _fitData->write("results/fitData.dat"); assert(0); //_fitDataToyMc->Print("v"); _fitDataToyMc->write("results/fitDataToyMc.dat"); assert(0); // assign data set according to container RooDataSet* data(0); switch(method) { case SEL: { data = (container==EXTERNAL)? _fitDataSel : _fitDataSelToyMc ; break; } case MD : { data = (container==EXTERNAL)? _fitData : _fitDataToyMc ; break; } case MI : { data = (container==EXTERNAL)? _fitData : _fitDataToyMc; break; } default : { assert(0); break; } } // assign pdf. For MI: // 1) build data set with additional columns (iBinACAB,iBinStateACAB) // 2) set to zero and constant coefficients for empty Bins RooSimultaneous* pdf = _pdfGlobal; if (method==SEL) pdf = _pdfSel; RooDataSet* dataMI(0); if (method==MI) { pdf = _pdfMIGlobal; TIterator *tIterD = _gFit->_DdecayMode->typeIterator() ; std::list< RooDKMIBinning* >::const_iterator iter_MIBinning = _gFit->_list_MIBinning.begin(); while (iter_MIBinning != _gFit->_list_MIBinning.end()) { RooDKMIBinning* binning=*iter_MIBinning; RooCatType* typeD = (RooCatType*)tIterD->Next(); TString cut(_gFit->_DdecayMode->GetName()); cut.Append("=="); cut.Append(_gFit->_DdecayMode->GetName()); cut.Append("::"); cut.Append(typeD->GetName()); RooDataSet* dataDdecay = (RooDataSet*)data->reduce(cut); if (dataDdecay->numEntries()>0) { // build new data set with (iBinACAB,iBinStateACAB) columns if these two columns does not already exist in the dataset const RooArgSet* columns = dataDdecay->get(); //columns->Print("v"); RooCategory *iBinACAB = (RooCategory*)columns->find(_gFit->_iBinACAB->GetName()); RooCategory *iBinStateACAB = (RooCategory*)columns->find(_gFit->_iBinStateACAB->GetName()); assert( (iBinACAB==0 && iBinStateACAB==0) || (iBinACAB!=0 && iBinStateACAB!=0) ); if (iBinACAB==0 && iBinStateACAB==0) { RooDataSet* dataDdecayBins = binning->getDataSetBins(*dataDdecay); dataDdecay->merge(dataDdecayBins); } //const RooArgSet* columns2 = dataDdecay->get(); columns2->Print("v"); assert(0); if (dataMI==0) dataMI=dataDdecay; else dataMI->append(*dataDdecay); // fix to zero coefficients for Bins with zero entries Int_t* entries = binning->getEntriesBins(*dataDdecay); //Int_t ntypeRun = (_pdfMIGlobal->getDependents(_gFit->_selDataVars)->find("runBlock"))? _gFit->_runBlock->numTypes() : 0; TIterator* tIterB = _gFit->_BdecayMode->typeIterator() ; //Int_t itypeRun(0); //while (itypeRun<=ntypeRun) { //RooCatType* typeRun = (ntypeRun>0)? (RooCatType*)_gFit->_runBlock->lookupType(itypeRun) : 0; while (RooCatType* typeB = (RooCatType*)tIterB->Next()) { TString name; RooAbsPdf* pdfMI=getPdfComp(_pdfMIGlobal,0,typeB,typeD,name); if (pdfMI) { RooArgSet* parsMI = pdfMI->getParameters(_gFit->_selDataVars); //parsMI->Print("v"); RooAbsArg* par; TString name; for (Int_t i=0;igetBinDalitzBin()->getNBins();i++) { if (entries[i]==0) { name="coef_c"; name.Append(itostr(i+1)); setConstant(findByName(parsMI,name,'_')); name.Append("Conj"); setConstant(findByName(parsMI,name,'_')); name="coef_s"; name.Append(itostr(i+1)); setConstant(findByName(parsMI,name,'_')); name.Append("Conj"); setConstant(findByName(parsMI,name,'_')); name="coef_T"; name.Append(itostr(i+1)); setConstant(findByName(parsMI,name,'_')); name.Append("Conj"); setConstant(findByName(parsMI,name,'_')); } } delete parsMI; } } //itypeRun++; //} delete tIterB; } else delete dataDdecay; iter_MIBinning++; } delete tIterD; //for (Int_t iEvt=0;iEvtnumEntries();iEvt++) dataMI->get(iEvt)->Print("v"); } if (dataMI) data=dataMI; // binned data set for MD RooDataSet* dataBinnedMD(0); if ((method==MD)&&(*_doBinnedFit=="Yes")&&(*_typeBinnedFit=="Likelihood")) { RooArgSet deps(*pdf->getDependents(data)); //deps.Print("v");assert(0); RooCategory *DMode = (RooCategory*)deps.find("DdecayMode"); assert(DMode); //RooCategory *DModeLF = (RooCategory*)deps.find("DdecayModeLF"); assert(DModeLF); deps.remove(*DMode); //deps.remove(*DModeLF); TIterator *tIterD = _gFit->_DdecayMode->typeIterator() ; TIterator *tIterDLF = _gFit->_DdecayModeLF->typeIterator() ; while (RooCatType* typeD = (RooCatType*)tIterD->Next()) { if (mpi_rank==0) cout << "RooDKFitMaster::perform_fit: making binned data set (MD method) for D decay mode: " << typeD->GetName() << endl; TString name(_gFit->_DdecayMode->GetName()); TString cut(name);cut.Append("==");cut.Append(name);cut.Append("::");cut.Append(typeD->GetName()); RooDataSet *data_deps = (RooDataSet*)data->reduce(deps,cut); if (data_deps->numEntries()>0) { EvtDalitzPlot dp(EvtDecayMode(tIterDLF->Next()->GetName())); Double_t qACmin = dp.qAbsMin(AC); Double_t qACmax = dp.qAbsMax(AC); Double_t qABmin = dp.qAbsMin(AB); Double_t qABmax = dp.qAbsMax(AB); Double_t qBCmin = dp.qAbsMin(BC); Double_t qBCmax = dp.qAbsMax(BC); //cout << qABmin << " " << qABmax << " " << qACmin << " " << qACmax << " " << qBCmin << " " << qBCmax << endl; /* assert(dp.bigM()>=_mDMin->getVal() && dp.bigM()<=_mDMax->getVal()); for (Int_t i=0;i<=1;i++) { EvtDalitzPlot dp_running(dp.mA(),dp.mB(),dp.mB(), (i==0)? _mDMin->getVal() : _mDMax->getVal() ); if (dp_running.qAbsMin(AC)qACmax) qACmax = dp_running.qAbsMax(AC); if (dp_running.qAbsMin(AB)qABmax) qABmax = dp_running.qAbsMax(AB); if (dp_running.qAbsMin(BC)qBCmax) qBCmax = dp_running.qAbsMax(BC); } */ /* std::vector& lineShape = _DmassLineShape[getIndexCat(typeD->getVal())]; if (lineShape.size()>0) { for (Int_t i=0;iqACmax) qACmax = dp_running.qAbsMax(AC); if (dp_running.qAbsMin(AB)qABmax) qABmax = dp_running.qAbsMax(AB); if (dp_running.qAbsMin(BC)qBCmax) qBCmax = dp_running.qAbsMax(BC); } } */ RooRealVar* qAB = (RooRealVar*)deps.find("qAB"); if (qAB) qAB->setRange(qABmin,qABmax); RooRealVar* qAC = (RooRealVar*)deps.find("qAC"); if (qAC) qAC->setRange(qACmin,qACmax); RooRealVar* qBC = (RooRealVar*)deps.find("qBC"); if (qBC) qBC->setRange(qBCmin,qBCmax); //deps.Print("v"); //cout << qABmin << " " << qABmax << " " << qACmin << " " << qACmax << " " << qBCmin << " " << qBCmax << endl; //assert(0); //cout << endl << "Sono prima del binned dataset" << endl; RooDataSet *dataBinnedMD_DMode = binnedDataSet("databinnedMD_DMode",data_deps,deps, //"weight","binCenter",kFALSE); "weight","centerOfGravity",kFALSE); //cout << endl << "Sono dopo il binned dataset" << endl; //cout << "qABmin,qABmax,getBinWidth=" << qABmin << " " << qABmax << " " << qAB->getBinWidth(0) << endl; assert(0); //RooDataSet *data_DMode = new RooDataSet("data_DMode","data_DMode",RooArgSet(*_gFit->_DdecayMode,*_gFit->_DdecayModeLF)); RooDataSet *data_DMode = new RooDataSet("data_DMode","data_DMode",RooArgSet(*_gFit->_DdecayMode)); _gFit->_DdecayMode->setIndex(typeD->getVal()); _gFit->_DdecayModeLF->setIndex(typeD->getVal()); for (Int_t iEvt=0;iEvtnumEntries();iEvt++) //data_DMode->add(RooArgSet(*_gFit->_DdecayMode,*_gFit->_DdecayModeLF)); data_DMode->add(RooArgSet(*_gFit->_DdecayMode)); dataBinnedMD_DMode->merge(data_DMode); if (dataBinnedMD) dataBinnedMD->append(*dataBinnedMD_DMode); else dataBinnedMD=dataBinnedMD_DMode; } delete data_deps; } delete tIterD; delete tIterDLF; _gFit->_qAB->setBins((Int_t)_qABBins->getVal()); _gFit->_qAC->setBins((Int_t)_qACBins->getVal()); _gFit->_qBC->setBins((Int_t)_qBCBins->getVal()); } if (dataBinnedMD) { dataBinnedMD->setWeightVar("weight"); data=dataBinnedMD; //dataBinnedMD->Print("v"); // assert(0); /* for (Int_t i=0;inumEntries();i++) { const RooArgSet* event = data->get(i); cout << "iEvt " << i+1 << " with weight " << data->weight() << endl; event->Print("v"); } assert(0); */ } // // RooDataHist* data_hist(0); if ((method==MD)&&(*_doBinnedFit=="Yes")&&(*_typeBinnedFit=="Chi2")) { if (mpi_rank==0) cout << "RooDKFitMaster::perform_fit: making binned data set (MD method, RooDataHist)" << endl; RooArgSet deps(*pdf->getDependents(data)); //deps.Print("v"); data_hist = new RooDataHist("data_hist","data_hist",deps,*data); if (mpi_rank==0) data_hist->Print("v"); assert(0); } // fix selection parameters in Dalitz fits if ( method!=SEL && _pdfSel ) { RooArgSet* selVars = _pdfSel->getParameters(_gFit->_selDataVars) ; // get list of yields and shape parameters RooArgSet yieldVars,shapeVars,yieldDhVars; TIterator* iter = selVars->createIterator(); RooRealVar* item; while (item = (RooRealVar*)iter->Next()) { TString title(item->GetTitle()); TString name(item->GetName()); if (title.Contains("yield")) { yieldVars.add(*item); if (name.BeginsWith("nDh")) yieldDhVars.add(*item); } //else else if (!name.BeginsWith("fmesBBPkg_") && !name.BeginsWith("fdeBBPkg_") && !name.BeginsWith("fmDBBPkg_") && !name.BeginsWith("fmDContPkg_")) // exclude peaking bkg shapes from the shape parameter list (control with configuration file) shapeVars.add(*item); } delete iter; // set constant shape parameters if (*_fixShapeParams=="Yes") { if (mpi_rank==0) cout << endl << "RooDKFitMaster: Selection PDF shape paramaters will be fixed to these values: " << endl; shapeVars.setAttribAll("Constant",kTRUE) ; } else { if (mpi_rank==0) cout << endl << "RooDKFitMaster: Selection PDF shape paramaters will be floated with these starting values: " << endl; if (mpi_rank==0) shapeVars.Print("v") ; } // set constant yields if ((*_fixYieldParams=="Yes")&&(yieldVars.getSize()>0)){ if (mpi_rank==0) cout << endl << "RooDKFitMaster: Selection PDF yield paramaters will be fixed to these values: " << endl; yieldVars.setAttribAll("Constant",kTRUE) ; } else if ((*_fixDhYieldParams=="Yes")&&(yieldDhVars.getSize()>0)){ if (mpi_rank==0) cout << endl << "RooDKFitMaster: Selection PDF Dh yield paramaters will be fixed to these values: " << endl; yieldDhVars.setAttribAll("Constant",kTRUE) ; } else { if (mpi_rank==0) cout << endl << "RooDKFitMaster: Selection PDF yield paramaters will be floated with these starting values: " << endl; if (mpi_rank==0) yieldVars.Print("v") ; } /* // rescaling yields/fractions from selection to Dalitz deltaE region cout << "Fractions/Yields after rescaling from selection to Dalitz fit deltaE range:" << endl; TIterator* tIterB = _gFit->_BdecayMode->typeIterator() ; TIterator *tIterD = _gFit->_DdecayMode->typeIterator() ; while (RooCatType* typeB = (RooCatType*)tIterB->Next()) { tIterD->Reset(); while (RooCatType* typeD = (RooCatType*)tIterD->Next()) { TString nameComp; RooAbsPdf* pdfSelComp = getPdfComp(_pdfSel,typeB,typeD,nameComp); if (pdfSelComp) { RooArgList *coefList,*pdfList; if (dynamic_cast(pdfSelComp)) { coefList = (RooArgList*)&((RooAddPdf*)pdfSelComp)->coefList(); pdfList = (RooArgList*)&((RooAddPdf*)pdfSelComp)->pdfList(); } else { coefList = new RooArgList("coefList"); pdfList = new RooArgList(*pdfSelComp,"pdfList"); } Int_t nComp(pdfList->getSize()); Bool_t extend(coefList->getSize()==nComp); // extended PDF? // get deltaE dependent and define Dalitz region Double_t min, max, minSel, maxSel; RooRealVar* deltaE = getDeltaEComp(pdfSelComp,min,max,minSel,maxSel,kFALSE); if (deltaE) { // rescale only if deltaE variable is used in the PDF // get coefficients and rescale std::vector pdfnames; std::vector coefs,coefsSel,ratios; rescalePdfCoefs(*pdfList,*coefList,deltaE,minSel,maxSel,min,max,pdfnames,coefsSel,coefs,ratios); Double_t nSig(0),nCont(0),nDh(0),nSigWS(0),nBB(0),nDhWS(0); for (Int_t iComp=0;iCompat(iComp); val=var->getVal()*ratios[iComp]; } else val=coefs[iComp]; if (name.BeginsWith("selSigWS")) nSigWS += val; else if (name.BeginsWith("selSig")) nSig += val; else if (name.BeginsWith("selCont")) nCont += val; else if (name.BeginsWith("selDhWS")) nDhWS += val; else if (name.BeginsWith("selDh")) nDh += val; else if (name.BeginsWith("selBB")) nBB += val; else assert(0); } Double_t nTot(nSigWS+nSig+nCont+nDhWS+nDh+nBB); // set rescaled coeficients RooArgSet* pars = pdfSelComp->getParameters(_gFit->_selDataVars); TIterator* iter = pars->createIterator(); RooRealVar* item; while (item = (RooRealVar*)iter->Next()) { //TString name_orig(item->GetName()); TString name(item->GetName()); name.Replace(0,1,"n"); Double_t val(-1e30); if (name.BeginsWith("nSigWS")) val=nSigWS; else if (name.BeginsWith("nSig")) val=nSig; else if (name.BeginsWith("nCont")) val=nCont; else if (name.BeginsWith("nDhWS")) val=nDhWS; else if (name.BeginsWith("nDh")) val=nDh; else if (name.BeginsWith("nBB")) val=nBB; if (val>-1e30) { Double_t errval = (item->getVal()>0.)? val/item->getVal()*item->getError() : 0 ; item->setVal(val); item->setError(errval); // very approximate error if (extend) { Double_t fr = (nTot>0.)? val/nTot : 0. ; Double_t errfr = (nTot>0.)? errval/nTot : 0. ; TString fname(item->GetName()); fname.Replace(0,1,"f"); cout << fname << " = " << fr << " +/- " << errfr << " C L(0 - 1) " << endl; //cout << name_orig << " = " << val << " +/- " << errval << " L(" << item->getMin() << " - " << item->getMax() << ")" << endl; } } } // clean-up delete iter; delete pars; pdfnames.clear(); coefs.clear(); coefsSel.clear(); ratios.clear(); } // clean-up if (dynamic_cast(pdfSelComp)==0) { delete coefList; delete pdfList; } } } } delete tIterB; delete tIterD; */ // end of rescaling //selVars->Print("v") ; delete selVars; } // define deltaE_dk and deltaE_dpi limits if ( method==SEL ) { _deltaE_dk->setRange(_deltaEMin_dkSel->getVal(),_deltaEMax_dkSel->getVal()); _deltaE_dpi->setRange(_deltaEMin_dpiSel->getVal(),_deltaEMax_dpiSel->getVal()); _gFit->_fisher->setRange(_fisherMin_Sel->getVal(),_fisherMax_Sel->getVal()); _gFit->_mD->setRange(_mDMin_Sel->getVal(),_mDMax_Sel->getVal()); _gFit->_deltam->setRange(_deltamMin_Sel->getVal(),_deltamMax_Sel->getVal()); } else { _deltaE_dk->setRange(_deltaEMin_dk->getVal(),_deltaEMax_dk->getVal()); _deltaE_dpi->setRange(_deltaEMin_dpi->getVal(),_deltaEMax_dpi->getVal()); _gFit->_fisher->setRange(_fisherMin->getVal(),_fisherMax->getVal()); _gFit->_mD->setRange(_mDMin->getVal(),_mDMax->getVal()); _gFit->_deltam->setRange(_deltamMin->getVal(),_deltamMax->getVal()); } // perform fit RooArgSet* fitVars = pdf->getParameters(_gFit->_selDataVars) ; removeDdecayParsNotReplicated(fitVars); removeMIDdecayParsNotUsed(fitVars); RooArgSet* fitVarsPhys = selectPHYSParams(fitVars); if (mpi_rank==0) cout << endl << "RooDKFitMaster: PDF parameters before fitting" << endl; if (mpi_rank==0) fitVars->Print("v"); delete fitVars; RooArgSet* depsVars = pdf->getDependents(_gFit->_selDataVars) ; if (mpi_rank==0) cout << endl << "RooDKFitMaster: PDF dependents for fitting" << endl; if (mpi_rank==0) depsVars->Print("v"); delete depsVars; RooFitResult* fitRes = perform_fit(pdf,data,data_hist,fitVarsPhys,nCPUs) ; delete fitVarsPhys; // assign fit results if (container==EXTERNAL) { if (method==SEL) { if (_fitSelResults) delete _fitSelResults; _fitSelResults = fitRes; } else if (method==MD) { if (_fitResults) delete _fitResults; _fitResults = fitRes; } else if (method==MI) { if (_fitMIResults) delete _fitMIResults; _fitMIResults = fitRes; } else assert(0); } else if (container==TOYMC) { if (method==SEL) { if (_fitSelResultsToyMc) delete _fitSelResultsToyMc; _fitSelResultsToyMc = fitRes; } else if (method==MD) { if (_fitResultsToyMc) delete _fitResultsToyMc; _fitResultsToyMc = fitRes; } else if (method==MI) { if (_fitMIResultsToyMc) delete _fitMIResultsToyMc; _fitMIResultsToyMc = fitRes; } else assert(0); } else assert(0); // clean-up if (dataMI) delete dataMI; //if (dataMD) delete dataMD; if (dataBinnedMD) delete dataBinnedMD; // print-out fractions if (mpi_rank==0) cout << "Fractions after extended likelihood fit:" << endl; TIterator* tIterB = _gFit->_BdecayMode->typeIterator() ; TIterator *tIterD = _gFit->_DdecayMode->typeIterator() ; //Int_t ntypeRun = (_pdfSel->getDependents(_gFit->_selDataVars)->find("runBlock"))? _gFit->_runBlock->numTypes() : 0; //Int_t itypeRun(0); //while (itypeRun<=ntypeRun) { //RooCatType* typeRun = (ntypeRun>0)? (RooCatType*)_gFit->_runBlock->lookupType(itypeRun) : 0; while (RooCatType* typeB = (RooCatType*)tIterB->Next()) { tIterD->Reset(); while (RooCatType* typeD = (RooCatType*)tIterD->Next()) { TString nameComp; RooAbsPdf* pdfSelComp = getPdfComp(_pdfSel,0,typeB,typeD,nameComp); if (pdfSelComp) { RooArgSet* pars = pdfSelComp->getParameters(_gFit->_selDataVars); TIterator* iter = pars->createIterator(); RooRealVar* item; Double_t nTot(0); while (item = (RooRealVar*)iter->Next()) { TString title(item->GetTitle()); if (title.Contains("yield")) nTot += item->getVal(); } iter->Reset(); while (item = (RooRealVar*)iter->Next()) { TString title(item->GetTitle()); TString fname(item->GetName()); if (title.Contains("yield")) { fname.Replace(0,1,"f"); Double_t fr = (nTot>0.)? item->getVal()/nTot : 0. ; Double_t errfr = (nTot>0.)? item->getError()/nTot : 0. ; if (mpi_rank==0) cout << fname << " = " << fr << " +/- " << errfr << " C L(0 - 1) " << endl; } } delete iter; delete pars; } } } //itypeRun++; //} delete tIterB; delete tIterD; } // perform fit for generic pdf and data sample RooFitResult* RooDKFitMaster::perform_fit(RooAbsPdf* pdf, RooDataSet* data, RooDataHist* data_hist, RooArgSet* physVarsForMinos, Int_t nCPUs) { int mpi_rank = get_mpi_rank(); if (mpi_rank==0) { cout << endl; cout << "**********************************" << endl; cout << "* *" << endl; cout << "* PERFORMING RooDKDalitz FIT *" << endl ; cout << "* *" << endl; cout << "**********************************" << endl; } assert(pdf); assert(data); assert(data->numEntries()); if (mpi_rank==0) data->Print("v"); if (*_typeBinnedFit=="Likelihood") { if (_nll) delete _nll; _nll = getNLLVar(pdf,data,0,nCPUs) ; } else if (*_typeBinnedFit=="Chi2") { if (_chi2) delete _chi2; //_chi2 = (RooChi2Var*)getChi2Var(pdf,0,data_hist,nCPUs) ; assert(0); } else assert(0); RooFitResult* result(0); // minimize with Minuit if (*_minimizer=="Minuit") { if (_mMinuit) delete _mMinuit; if (*_typeBinnedFit=="Likelihood") _mMinuit = new RooMinuit(*_nll) ; else _mMinuit = new RooMinuit(*_chi2) ; if (*_fitVerbose=="Yes") _mMinuit->setVerbose(kTRUE); else _mMinuit->setVerbose(kFALSE); _mMinuit->setPrintLevel(1); _mMinuit->setProfile(kTRUE); _mMinuit->optimizeConst(1) ; _mMinuit->setStrategy(1) ; if (*_simplex=="Yes") _mMinuit->simplex() ; _mMinuit->migrad() ; _mMinuit->hesse() ; if ((*_doMinosPhys=="Yes")&&(physVarsForMinos)) _mMinuit->minos(*physVarsForMinos); result=_mMinuit->save(); } #ifdef NAG_C_ROOT if (*_minimizer=="Nag") { if (_mNag) delete _mNag; if (*_typeBinnedFit=="Likelihood") _mNag = new RooNag(*_nll) ; else _mNag = new RooNag(*_chi2) ; if (*_fitVerbose=="Yes") _mNag->setVerbose(kTRUE); else _mNag->setVerbose(kFALSE); _mNag->setPrintLevel(1); _mNag->setProfile(kTRUE); _mNag->optimizeConst(1) ; _mNag->setLineSearchTolerance(0.8); _mNag->setOptimalToleranceFactor(100.); _mNag->setScalingOption(RooNag::params); if (*_simplex=="Yes") { _mNag->setOptimalToleranceFactor(1e6); _mNag->simplex() ; _mNag->setOptimalToleranceFactor(100.); } _mNag->migrad() ; _mNag->setOptimalToleranceFactor(1.); _mNag->setScalingOption(RooNag::all); _mNag->hesse() ; if ((*_doMinosPhys=="Yes")&&(physVarsForMinos)) _mNag->minos(*physVarsForMinos); result=_mNag->save(); } #endif return result; } // dump fit fractions (D* samples) void RooDKFitMaster::dumpFractions(TString BMode, TString DMode, TString pdfNameCompRoot, const char* filename, Int_t iAmpInit, Int_t iAmpFinal) { // set decay modes _gFit->_DdecayMode->setLabel(DMode); _gFit->_DdecayModeLF->setIndex(_gFit->_DdecayMode->getIndex()); _gFit->_BdecayMode->setLabel(BMode); _gFit->_BdecayModeLF->setIndex(_gFit->_BdecayMode->getIndex()); // pdf component name TString pdfComp("{"); pdfComp.Append(DMode); pdfComp.Append(";"); pdfComp.Append(BMode); pdfComp.Append("}"); if (get_mpi_rank()==0) cout << "RooDKFitMaster::dumpFractions: Pdf component: " << pdfComp << endl; // get PDF RooAbsPdf* pdf = (_pdfGlobal)? (RooAbsPdf*)_pdfGlobal->getPdf(pdfComp) : 0; if (pdf==0) return; // output stream ofstream ofs(filename) ; if (ofs.fail()) { if (get_mpi_rank()==0) cout << "RooDKFitMaster::dumpFractions(): error opening file " << filename << endl ; assert(0); } ostream& os = ofs; // dump fit fractions for Dstar samples TString pdfNameComp(pdfNameCompRoot); pdfNameComp += "_{"; pdfNameComp += BMode; pdfNameComp += ";"; pdfNameComp += DMode; pdfNameComp += "}"; RooArgSet* components = pdf->getComponents(); //components->Print("v"); RooDKPdfMaker* pdfDalitz = (RooDKPdfMaker*)components->find(pdfNameComp); if (pdfDalitz==0) pdfDalitz = (RooDKPdfMaker*)components->find(pdfNameComp+"_cust"); if (pdfDalitz) { if (get_mpi_rank()==0) cout << "Evaluating fit fractions for PDF name = " << pdfDalitz->GetName() << endl; pdfDalitz->dumpFractions(ofs); if (iAmpInit>0 && iAmpFinal>0 && iAmpFinal>iAmpInit) pdfDalitz->dumpFractions(ofs, iAmpInit, iAmpFinal); } else if (get_mpi_rank()==0) cout << "Evaluating fit fractions for PDF name = " << pdfDalitz << endl; delete components; if (get_mpi_rank()==0) cout << "RooDKFitMaster::dumpFractions(): writting file " << filename << endl ; } RooNLLVar* RooDKFitMaster::getNLLVar(RooAbsPdf* pdf, RooDataSet* data, RooDataHist* data_hist, Int_t nCPUs) { assert(pdf); assert(data || data_hist); if (data) assert(data->numEntries()); if (data_hist) assert(data_hist->numEntries()); //_gFit->_DdecayMode->setIndex(1);_gFit->_DdecayModeLF->setIndex(1); //for (Int_t iEvt=0;iEvtnumEntries();iEvt++) data->get(iEvt)->Print("v"); //pdf->getDependents(_gFit->_selDataVars)->Print("v"); RooArgSet projDeps; // no projections, integrate over B charge states and phase-space if (TString(_deltaEDhOption->getLabel())=="deltaEshift") projDeps.add(*_gFit->_deltaEshift); // project over deltaEshift RooArgSet pdf_deps(*pdf->getDependents(_gFit->_selDataVars)); //pdf_deps.Print("v"); assert(0); //if (TString(_resFcn->getLabel()).EndsWith("EventError") // && pdf_deps.find("tErr") && (pdf_deps.find("tReco") || pdf_deps.find("tTrue"))) projDeps.add(*_gFit->_tErr); // project over sigma_t assert( !(TString(_resFcn->getLabel()).EndsWith("GlobalError") && pdf_deps.find("tErr")) ); // with GlobalError the pdf cannot contain tErr if (pdf_deps.find("tErr")) projDeps.add(*_gFit->_tErr); // project over sigma_t for EventError and Truth //projDeps.Print("v"); assert(0); //projDeps.add(*_gFit->_DdecayModeLF); // project over DdecayModeLF projDeps.add(*_gFit->_DdecayMode); // project over DdecayMode projDeps.add(*_gFit->_BdecayMode); // project over BdecayMode projDeps.add(*_gFit->_recState); // project over recState Bool_t extended(kFALSE) ; if ( (pdf->extendMode()==RooAbsPdf::CanBeExtended)|| (pdf->extendMode()==RooAbsPdf::MustBeExtended) ) extended=kTRUE; //RooArgSet* deps = pdf->getDependents(_gFit->_selDataVars); //deps->Print("v"); //data->Print("v"); //data_hist->Print("v"); //assert(0); //delete deps; //cout << nCPUs << endl; assert(0); return new RooNLLVar("nll","-log(likelihood)",*pdf,*data,projDeps,extended,0,0,nCPUs) ; } /* RooChi2Var* RooDKFitMaster::getChi2Var(RooAbsPdf* pdf, RooDataSet* data, RooDataHist* data_hist, Int_t nCPUs) { assert(pdf); assert(data || data_hist); if (data) assert(data->numEntries()); if (data_hist) assert(data_hist->numEntries()); //_gFit->_DdecayMode->setIndex(1);_gFit->_DdecayModeLF->setIndex(1); //for (Int_t iEvt=0;iEvtnumEntries();iEvt++) data->get(iEvt)->Print("v"); //pdf->getDependents(_gFit->_selDataVars)->Print("v"); RooArgSet projDeps; // no projections, integrate over B charge states and phase-space if (TString(_deltaEDhOption->getLabel())=="deltaEshift") projDeps.add(*_gFit->_deltaEshift); // project over deltaEshift //projDeps.add(*_gFit->_DdecayModeLF); // project over DdecayModeLF projDeps.add(*_gFit->_DdecayMode); // project over DdecayMode projDeps.add(*_gFit->_BdecayMode); // project over BdecayMode projDeps.add(*_gFit->_recState); // project over recState Bool_t extended(kFALSE) ; if ( (pdf->extendMode()==RooAbsPdf::CanBeExtended)|| (pdf->extendMode()==RooAbsPdf::MustBeExtended) ) extended=kTRUE; //RooArgSet* deps = pdf->getDependents(_gFit->_selDataVars); //deps->Print("v"); //data->Print("v"); //data_hist->Print("v"); //assert(0); //delete deps; //return new RooDKChi2Var("chi2","Chi2",*pdf,*data,projDeps,extended,0,0,nCPUs) ; return new RooChi2Var("chi2","Chi2",*pdf,*data_hist,projDeps,extended,0,0,nCPUs) ; } */ // contour for given pair of variables TH2F* RooDKFitMaster::contour(RooRealVar& var1, RooRealVar& var2, Double_t n1, Double_t n2, Double_t n3) { int mpi_rank = get_mpi_rank(); if (*_minimizer=="Minuit") { if (_mMinuit==0) { if (mpi_rank==0) cout << "RooDKFitMaster::contour: the fit has to be performed first." << endl; assert(0); } return _mMinuit->contour(var1, var2, n1, n2, n3); } #ifdef NAG_C_ROOT if (*_minimizer=="Nag") { assert(0); if (_mNag==0) { if (mpi_rank==0) cout << "RooDKFitMaster::contour: the fit has to be performed first." << endl; assert(0); } return _mNag->contour(var1, var2, n1, n2, n3); } #endif } // Build all cuts void RooDKFitMaster::buildAllCuts(Bool_t deltaEin, Bool_t fisherin, Bool_t mDin, Bool_t deltamin, Bool_t runBlockin, TString& dsel_fitSel, TString& dsel_fit, TString& dsel_dk_fit, TString& dsel_dpi_fit) { // define deltaE_dk and deltaE_dpi cuts // check first that Dalitz deltaE cuts are tighter than selection deltaE cuts assert(_deltaEMin_dkSel->getVal()<=_deltaEMin_dk->getVal()); assert(_deltaEMax_dkSel->getVal()>=_deltaEMax_dk->getVal()); assert(_deltaEMin_dpiSel->getVal()<=_deltaEMin_dpi->getVal()); assert(_deltaEMax_dpiSel->getVal()>=_deltaEMax_dpi->getVal()); // selection TString cut_dkSel("(deltaE_dk>="); cut_dkSel.Append(*_deltaEMin_dkSel->format(2,"F")); cut_dkSel.Append(")&&(deltaE_dk<="); cut_dkSel.Append(*_deltaEMax_dkSel->format(2,"F")); cut_dkSel.Append(")"); TString cut_dpiSel("(deltaE_dpi>="); cut_dpiSel.Append(*_deltaEMin_dpiSel->format(2,"F")); cut_dpiSel.Append(")&&(deltaE_dpi<="); cut_dpiSel.Append(*_deltaEMax_dpiSel->format(2,"F")); cut_dpiSel.Append(")"); // Dalitz TString cut_dk("(deltaE_dk>="); cut_dk.Append(*_deltaEMin_dk->format(2,"F")); cut_dk.Append(")&&(deltaE_dk<="); cut_dk.Append(*_deltaEMax_dk->format(2,"F")); cut_dk.Append(")"); TString cut_dpi("(deltaE_dpi>="); cut_dpi.Append(*_deltaEMin_dpi->format(2,"F")); cut_dpi.Append(")&&(deltaE_dpi<="); cut_dpi.Append(*_deltaEMax_dpi->format(2,"F")); cut_dpi.Append(")"); // Fisher // check first that Dalitz deltaE cuts are tighter than selection deltaE cuts if (_fisherMin_Sel->getVal()>_fisherMax_Sel->getVal()) { // for back compatibility _fisherMin_Sel->setVal(_fisherMin->getVal()); _fisherMax_Sel->setVal(_fisherMax->getVal()); } assert(_fisherMin_Sel->getVal()<=_fisherMin->getVal()); assert(_fisherMax_Sel->getVal()>=_fisherMax->getVal()); // selection TString cut_fisherSel("(fisher>="); cut_fisherSel.Append(*_fisherMin_Sel->format(2,"F")); cut_fisherSel.Append(")&&(fisher<="); cut_fisherSel.Append(*_fisherMax_Sel->format(2,"F")); cut_fisherSel.Append(")"); // Dalitz TString cut_fisher("(fisher>="); cut_fisher.Append(*_fisherMin->format(2,"F")); cut_fisher.Append(")&&(fisher<="); cut_fisher.Append(*_fisherMax->format(2,"F")); cut_fisher.Append(")"); // mD if (_mDMin_Sel->getVal()>_mDMax_Sel->getVal()) { // for back compatibility _mDMin_Sel->setVal(_mDMin->getVal()); _mDMax_Sel->setVal(_mDMax->getVal()); } assert(_mDMin_Sel->getVal()<=_mDMin->getVal()); assert(_mDMax_Sel->getVal()>=_mDMax->getVal()); // selection TString cut_mDSel("(mD>="); cut_mDSel.Append(*_mDMin_Sel->format(6,"F")); cut_mDSel.Append(")&&(mD<="); cut_mDSel.Append(*_mDMax_Sel->format(6,"F")); cut_mDSel.Append(")"); // Dalitz TString cut_mD("(mD>="); cut_mD.Append(*_mDMin->format(6,"F")); cut_mD.Append(")&&(mD<="); cut_mD.Append(*_mDMax->format(6,"F")); cut_mD.Append(")"); // m(D*)-m(D) if (_deltamMin_Sel->getVal()>_deltamMax_Sel->getVal()) { // for back compatibility _deltamMin_Sel->setVal(_deltamMin->getVal()); _deltamMax_Sel->setVal(_deltamMax->getVal()); } assert(_deltamMin_Sel->getVal()<=_deltamMin->getVal()); assert(_deltamMax_Sel->getVal()>=_deltamMax->getVal()); // selection TString cut_deltamSel("(deltam>="); cut_deltamSel.Append(*_deltamMin_Sel->format(6,"F")); cut_deltamSel.Append(")&&(deltam<="); cut_deltamSel.Append(*_deltamMax_Sel->format(6,"F")); cut_deltamSel.Append(")"); // Dalitz TString cut_deltam("(deltam>="); cut_deltam.Append(*_deltamMin->format(6,"F")); cut_deltam.Append(")&&(deltam<="); cut_deltam.Append(*_deltamMax->format(6,"F")); cut_deltam.Append(")"); // overall selection cuts dsel_fitSel=""; TString dsel_dk_fitSel(_dsel_dk->getVal()); TString dsel_dpi_fitSel(_dsel_dpi->getVal()); if (deltaEin) { addCut(dsel_dk_fitSel,cut_dkSel,"&&"); addCut(dsel_dpi_fitSel,cut_dpiSel,"&&"); } addCut(dsel_fitSel,dsel_dk_fitSel,"||"); addCut(dsel_fitSel,dsel_dpi_fitSel,"||"); // dsel_fit=""; dsel_dk_fit=_dsel_dk->getVal(); dsel_dpi_fit=_dsel_dpi->getVal(); if (deltaEin) { addCut(dsel_dk_fit,cut_dk,"&&"); addCut(dsel_dpi_fit,cut_dpi,"&&"); } addCut(dsel_fit,dsel_dk_fit,"||"); addCut(dsel_fit,dsel_dpi_fit,"||"); // include Fisher selection if (fisherin) { addCut(dsel_dk_fit,cut_fisherSel,"&&"); addCut(dsel_dpi_fit,cut_fisherSel,"&&"); addCut(dsel_fitSel,cut_fisherSel,"&&"); addCut(dsel_fit,cut_fisher,"&&"); } // include mD selection if (mDin) { //if (*_deltamOption=="in") { if (*_resFcn!="Unknown") { addCut(dsel_dk_fit,cut_mDSel,"&&"); addCut(dsel_dpi_fit,cut_mDSel,"&&"); addCut(dsel_fitSel,cut_mDSel,"&&"); addCut(dsel_fit,cut_mD,"&&"); } } // include m(D*)-m(D) selection if (deltamin) { //if (*_deltamOption=="in") { if (*_resFcn!="Unknown") { addCut(dsel_dk_fit,cut_deltamSel,"&&"); addCut(dsel_dpi_fit,cut_deltamSel,"&&"); addCut(dsel_fitSel,cut_deltamSel,"&&"); addCut(dsel_fit,cut_deltam,"&&"); } } // include run block selection if (runBlockin) { addCut(dsel_dk_fit,_dsel_runBlock->getVal(),"&&"); addCut(dsel_dpi_fit,_dsel_runBlock->getVal(),"&&"); addCut(dsel_fitSel,_dsel_runBlock->getVal(),"&&"); addCut(dsel_fit,_dsel_runBlock->getVal(),"&&"); } } // Add new cut selection to current cut void RooDKFitMaster::addCut(RooStringVar* currentCut, const char* newCut, const char* opt) { TString chain(currentCut->getVal()); addCut(chain,newCut,opt); currentCut->setVal(chain); } void RooDKFitMaster::addCut(TString& currentCut, const char* newCut, const char* opt) { TString& chain = currentCut; if (TString(newCut)=="") return; if (chain!="") { chain.Prepend("("); chain.Append(")"); assert((opt=="&&")||(opt=="||")); chain.Append(opt); chain.Append("("); chain.Append(newCut); chain.Append(")"); } else { chain.Append(newCut); } } // persist given fit dataset contained in Root file void RooDKFitMaster::persist_datasets_toRoot(Method method, Container container) { if (method==SEL) { switch(container) { case EXTERNAL: { persist_datasets_toRoot(_fitDataSel,_dataRootFile->getVal()); break; } case TOYMC: { persist_datasets_toRoot(_fitDataSelToyMc,_toyMcDataRootFile->getVal()); break; } default: { assert(0); break; } } } else if (method==MD || method==MI) { switch(container) { case EXTERNAL: { persist_datasets_toRoot(_fitData,_dataRootFile->getVal()); break; } case TOYMC: { persist_datasets_toRoot(_fitDataToyMc,_toyMcDataRootFile->getVal()); break; } default: { assert(0); break; } } } } void RooDKFitMaster::persist_datasets_toRoot(RooDataSet* data, const char* file) { if (get_mpi_rank()>0) return; if (data==0) { cout << "RooDKFitMaster: data to persist does not exist" << endl; } else { cout << "RooDKFitMaster: writting datasets to ROOT file : " << file << endl; TFile f(file,"recreate") ; data->Write("dataset"); f.Close(); cout << "RooDKFitMaster: datasets writting done" << endl; } } // read fit dataset contained in Root file void RooDKFitMaster::read_datasets_fromRoot(Container container) { switch(container) { case EXTERNAL: { if (_fitDataSel) delete _fitDataSel; if (_fitData) delete _fitData; _fitDataSel = read_datasets_fromRoot(_dataRootFile->getVal()); _fitData = (RooDataSet*) _fitDataSel->reduce(_gFit->_selDataVars,_dsel_fit->getVal()) ; break; } case TOYMC: { if (_fitDataSelToyMc) delete _fitDataSelToyMc; if (_fitDataToyMc) delete _fitDataToyMc; _fitDataSelToyMc = read_datasets_fromRoot(_toyMcDataRootFile->getVal()); TString dsel; RooArgSet* event = (RooArgSet*)_fitDataSelToyMc->get(0); RooRealVar* deltaE_dk = (RooRealVar*)event->find("deltaE_dk"); RooRealVar* deltaE_dpi = (RooRealVar*)event->find("deltaE_dpi"); if (deltaE_dk && deltaE_dpi) dsel=_dsel_fit->getVal(); else if (deltaE_dk) dsel=_dsel_dk_fit->getVal(); else if (deltaE_dpi) dsel=_dsel_dpi_fit->getVal(); _fitDataToyMc = (RooDataSet*) _fitDataSelToyMc->reduce(_gFit->_selDataVars,dsel) ; break; } default: { assert(0); break; } } } RooDataSet* RooDKFitMaster::read_datasets_fromRoot(const char* file) { int mpi_rank = get_mpi_rank(); if (mpi_rank==0) cout << "Read back datasets from ROOT file: " << file << endl; TFile f(file,"read") ; RooDataSet* data = (RooDataSet*)f.Get("dataset")->Clone() ; //RooDataSet* data = (RooDataSet*)f.Get("dataset"); if (mpi_rank==0) cout << "Events read: " << data->numEntries() << endl; return data; } // persist fit result for given fit dataset container in Root file void RooDKFitMaster::persist_fitresults_toRoot(Container container) { switch(container) { case EXTERNAL: { persist_fitresults_toRoot(_fitSelResults,_paramsSelInit, _fitResults,_paramsInit, _fitMIResults,_paramsMIInit, _resultsRootFile->getVal()); break; } case TOYMC: { persist_fitresults_toRoot(_fitSelResultsToyMc,_paramsSelInit, _fitResultsToyMc,_paramsInit, _fitMIResultsToyMc,_paramsMIInit, _toyMcResultsRootFile->getVal()); break; } default: { assert(0); break; } } } void RooDKFitMaster::persist_fitresults_toRoot(RooFitResult* fitSelRes, RooArgSet* paramsSelInit, RooFitResult* fitRes, RooArgSet* paramsInit, RooFitResult* fitMIRes, RooArgSet* paramsMIInit, const char* file) { if (get_mpi_rank()>0) return; cout << "RooDKFitMaster: Persisting in ROOT format available fit results to file : " << file << endl; TFile f(file,"recreate") ; if (fitSelRes) fitSelRes->Write("fitSelResults"); if (fitRes) fitRes->Write("fitResults"); if (fitMIRes) fitMIRes->Write("fitMIResults"); if (paramsSelInit) paramsSelInit->Write("paramsSelInit"); if (paramsInit) paramsInit->Write("paramsInit"); if (paramsMIInit) paramsMIInit->Write("paramsMIInit"); f.Close(); cout << "RooDKFitMaster: Root persistence finished " << endl; } // read back from Root file fit results and put into EXTERNAL dataset container void RooDKFitMaster::read_fitresults_fromRoot() { read_fitresults_fromRoot(_resultsRootFile->getVal()); } void RooDKFitMaster::read_fitresults_fromRoot(const char* file) { int mpi_rank = get_mpi_rank(); if (mpi_rank==0) cout << "Read back fit results from ROOT file: " << file << endl; // read back fit results TFile f(file,"read") ; // RooArgSet parsBack; RooFitResult* r = (RooFitResult*)f.Get("fitResults"); if (r) { if (_fitResults) delete _fitResults; _fitResults = (RooFitResult*)r->clone(); if (mpi_rank==0) cout << "RooDKFitMaster: retrieved fit results" << endl; parsBack.add(_fitResults->floatParsFinal()); parsBack.add(_fitResults->constPars()); } else if (mpi_rank==0) cout << "RooDKFitMaster: failed to retrieve fit results" << endl; // RooArgSet parsMIBack; RooFitResult* rMI = (RooFitResult*)f.Get("fitMIResults"); if (rMI) { if (_fitMIResults) delete _fitMIResults; _fitMIResults = (RooFitResult*)rMI->clone(); if (mpi_rank==0) cout << "RooDKFitMaster: retrieved MI fit results" << endl; parsMIBack.add(_fitMIResults->floatParsFinal()); parsMIBack.add(_fitMIResults->constPars()); } else if (mpi_rank==0) cout << "RooDKFitMaster: failed to retrieve MI fit results" << endl; // RooArgSet parsSelBack; RooFitResult* rSel = (RooFitResult*)f.Get("fitSelResults"); if (rSel) { if (_fitSelResults) delete _fitSelResults; _fitSelResults = (RooFitResult*)rSel->clone(); if (mpi_rank==0) cout << "RooDKFitMaster: retrieved selection fit results" << endl; parsSelBack.add(_fitSelResults->floatParsFinal()); parsSelBack.add(_fitSelResults->constPars()); } else if (mpi_rank==0) cout << "RooDKFitMaster: failed to retrieve selection fit results" << endl; // //parsBack.remove(parsSelBack,kTRUE,kTRUE); //parsBack.add(parsSelBack); //parsMIBack.remove(parsSelBack,kTRUE,kTRUE); //parsMIBack.add(parsSelBack); // /* RooArgSet* initParams = (RooArgSet*)f.Get("paramsInit"); if (initParams) { if (paramsInit) delete paramsInit; paramsInit = (RooArgSet*)initParams->snapshot(kFALSE) ; cout << "RooDKFitMaster: retrieved initParams" << endl; } else cout << "RooDKFitMaster: failed to retrieve initParams" << endl; */ f.Close(); // now assign fit results to PDF parameters. Ordering matters: first selection fit results, later Dalitz results (if exists) RooArgSet* paramsSel = (_pdfSel)? _pdfSel->getParameters(_gFit->_selDataVars) : 0; assignFitResultsToPdfParams(paramsSel,parsSelBack); //if (paramsSel) paramsSel->Print("v"); if (mpi_rank==0) cout << "RooDKFitMaster: assign fit results to PDF parameters " << endl; RooArgSet* params = (_pdfGlobal)? _pdfGlobal->getParameters(_gFit->_selDataVars) : 0; assignFitResultsToPdfParams(params,parsBack); //if (params) params->Print("v"); RooArgSet* paramsMI = (_pdfMIGlobal)? _pdfMIGlobal->getParameters(_gFit->_selDataVars) : 0; assignFitResultsToPdfParams(paramsMI,parsMIBack); //if (paramsMI) paramsMI->Print("v"); // the new PDF parameter values are in fact the new initial values thereafter. Order also matters here if (mpi_rank==0) cout << "RooDKFitMaster: assign fit results to initial PDF parameters (initial values for any new fit) " << endl; if (_paramsSelInit) delete _paramsSelInit; _paramsSelInit = (paramsSel)? (RooArgSet*)paramsSel->snapshot(kFALSE) : 0; if (paramsSel) delete paramsSel; // if (_paramsInit) delete _paramsInit; if (params) removeDdecayParsNotReplicated(params); _paramsInit = (params)? (RooArgSet*)params->snapshot(kFALSE) : 0; if (params) delete params; // if (_paramsMIInit) delete _paramsMIInit; _paramsMIInit = (paramsMI)? (RooArgSet*)paramsMI->snapshot(kFALSE) : 0 ; if (paramsMI) delete paramsMI; // now assign fit results to Toy MC PDF parameters if (mpi_rank==0) cout << "RooDKFitMaster: assign fit results to Toy MC PDF parameters " << endl; params = (_pdfGlobalToyMc)? _pdfGlobalToyMc->getParameters(_gFit->_selDataVars) : 0; assignFitResultsToPdfParams(params,parsBack); paramsMI = (_pdfMIGlobalToyMc)? _pdfMIGlobalToyMc->getParameters(_gFit->_selDataVars) : 0; assignFitResultsToPdfParams(paramsMI,parsMIBack); if (params) delete params; if (paramsMI) delete paramsMI; } // assign parameters from fitParams to pdfParams // (only those floated) void RooDKFitMaster::assignFitResultsToPdfParams(RooArgSet* pdfParams, RooArgSet& fitParams) { RooAbsArg* itemPdf; if (pdfParams==0) return; TIterator* iter = pdfParams->createIterator(); while (itemPdf = (RooAbsArg*)iter->Next()) { RooRealVar* var = dynamic_cast(fitParams.find(itemPdf->GetName())); if (var) { RooRealVar* itemPdfReal = dynamic_cast(itemPdf) ; assert(itemPdfReal); // sanity check /* itemPdfReal->setRange(var->getMin(),var->getMax()); itemPdfReal->setVal(var->getVal()); if (var->getAttribute("Constant")) itemPdf->setAttribute("Constant",kTRUE); else itemPdf->setAttribute("Constant",kFALSE); */ assert ( itemPdfReal->getAttribute("Constant")==var->getAttribute("Constant") ); if (!var->getAttribute("Constant")) { itemPdfReal->setRange(var->getMin(),var->getMax()); itemPdfReal->setVal(var->getVal()); } } } delete iter; } // get pdf component given DdecayMode and BdecayMode category RooAbsPdf* RooDKFitMaster::getPdfComp(RooSimultaneous* pdf, RooCatType* typeRunBlock, RooCatType* typeBdecay, RooCatType* typeDdecay, TString& nameComp) { assert(pdf); // try all orderings of categories (one does not know the ordering in the config file) Int_t i(0),j,k; RooAbsPdf *pdfComp(0); while (i<3 && pdfComp==0) { j=0; while (j<3 && pdfComp==0) { k=0; while (k<3 && pdfComp==0) { if ((i!=j)&&(i!=k)&&(j!=k)) { RooCatType *type1,*type2,*type3; if (i==0) type1=typeRunBlock; else if (i==1) type1=typeBdecay; else type1=typeDdecay; if (j==0) type2=typeRunBlock; else if (j==1) type2=typeBdecay; else type2=typeDdecay; if (k==0) type3=typeRunBlock; else if (k==1) type3=typeBdecay; else type3=typeDdecay; if ((type1&&type2)||(type1&&type3)||(type2&&type3)) nameComp="{"; if (type1) { nameComp.Append(type1->GetName()); if (type2||type3) nameComp.Append(";"); } if (type2) { nameComp.Append(type2->GetName()); if (type3) nameComp.Append(";"); } if (type3) nameComp.Append(type3->GetName()); nameComp.Append("}"); pdfComp = pdf->getPdf(nameComp); //cout << nameComp << " " << pdfComp << endl; } k++; } j++; } i++; } return pdfComp; } // set a parameter as constant void RooDKFitMaster::setConstant(RooAbsArg* arg) { int mpi_rank = get_mpi_rank(); if (arg) { if (mpi_rank==0) cout << "Parameter " << arg->GetName() << " set constant" << endl; arg->setAttribute("Constant",kTRUE); } } // remove D decay parameters not replicated. The method is invasive void RooDKFitMaster::removeDdecayParsNotReplicated(RooArgSet* pars) { assert(pars); TIterator* iter = pars->createIterator(); for (Int_t i=0;i<=3;i++) { TString fake=""; if (i==1) fake="FakeD"; else if (i==2) fake="BBFakeD"; else if (i==3) fake="FakeDKsKs"; for (Int_t iAmp=MAXAMP;iAmp>=1;iAmp--) { TString str(strAmp("",iAmp)); str.Append(fake); TString str_(str);str_.Append("_"); iter->Reset(); while (RooAbsArg* item = (RooAbsArg*)iter->Next()) { TString name(item->GetName()); if ( name.EndsWith(str) && !name.Contains(str_) ) pars->remove(*item); } } } delete iter; } // replace string "AmpX_" by the amplitude name+"_". The method is invasive void RooDKFitMaster::replaceAmpXbyAmpName(RooArgSet* pars) { assert(pars); TIterator* iter = pars->createIterator(); TIterator* iter2 = pars->createIterator(); for (Int_t i=0;i<=3;i++) { TString fake=""; if (i==1) fake="FakeD"; else if (i==2) fake="BBFakeD"; else if (i==3) fake="FakeDKsKs"; for (Int_t iAmp=MAXAMP;iAmp>=1;iAmp--) { TString str(strAmp("",iAmp));str.Append(fake); TString str_(str);str_.Append("_"); iter->Reset(); while (RooAbsArg* item = (RooAbsArg*)iter->Next()) { TString itemName(item->GetName()); TString name("name");name.Append(str_); if (itemName.BeginsWith(name)) { TString suffix( std::string(itemName).substr(name.Length()) ); iter2->Reset(); while (RooAbsArg* item2 = (RooAbsArg*)iter2->Next()) { TString item2Name(item2->GetName()); //if ( !item2Name.BeginsWith(name) && item2Name.Contains(str_) && item2Name.EndsWith(suffix) ) { if ( item2Name.Contains(str_) && item2Name.EndsWith(suffix) ) { TString nameAmp(dynamic_cast(item)->getLabel()); nameAmp.Prepend("(");nameAmp.Prepend(str);nameAmp.Append(")"); //cout << " old name = " << item2Name; item2Name.ReplaceAll(str,nameAmp); //cout << " new name = " << item2Name << endl; item2->SetName(item2Name); } } } } } } // clean-up delete iter; delete iter2; } // remove MI D decay parameters not USED. The method is invasive void RooDKFitMaster::removeMIDdecayParsNotUsed(RooArgSet* pars) { assert(pars); RooArgSet parsCopy(*pars); TIterator* iter = parsCopy.createIterator(); TString str("coef_"); while (RooAbsArg* item = (RooAbsArg*)iter->Next()) { if ( (TString(item->GetName()).BeginsWith(str)) && (!item->getAttribute("USED")) ) pars->remove(*item); } } // execute the customizer to remove duplicated parameters RooSimultaneous* RooDKFitMaster::doCustomize(RooSimultaneous* pdf, const RooArgSet& selDataVars) { int mpi_rank = get_mpi_rank(); assert(pdf); // // replace deltaE by deltaE_dk or deltaE_dpi RooAbsCategoryLValue& indexCat = (RooAbsCategoryLValue&) pdf->indexCat() ; TString pdfCustName(pdf->GetName()); pdfCustName.Append("Cust"); RooSimultaneous* pdfCust = new RooSimultaneous(pdfCustName,pdfCustName,indexCat); Int_t ntypeRun = (pdf->getDependents(_gFit->_selDataVars)->find("runBlock"))? _gFit->_runBlock->numTypes() : 0; TIterator *tIterB = _gFit->_BdecayMode->typeIterator() ; TIterator *tIterD = _gFit->_DdecayMode->typeIterator() ; Int_t itypeRun(0); while (itypeRun<=ntypeRun) { RooCatType* typeRun = (ntypeRun>0)? (RooCatType*)_gFit->_runBlock->lookupType(itypeRun) : 0; tIterB->Reset(); while (RooCatType* typeB = (RooCatType*)tIterB->Next()) { TString typeBName(typeB->GetName()); tIterD->Reset(); while (RooCatType* typeD = (RooCatType*)tIterD->Next()) { TString pdfCompName; RooAbsPdf* pdfComp = getPdfComp(pdf,typeRun,typeB,typeD,pdfCompName); if (pdfComp) { if (mpi_rank==0) cout << "Pdf component : " << pdfCompName << endl; RooCustomizer *cust = new RooCustomizer(*pdfComp,"cust") ; _cust_list.push_back(cust); // replace deltaE by deltaE_dk or deltaE_dpi if ((typeBName=="DK")||(typeBName=="Dpi0K")||(typeBName=="DgammaK")|| (typeBName=="DKspi")||(typeBName=="DKpi0")||(typeBName=="DRho0pi")||(typeBName=="DPipi0")) cust->replaceArg(*_gFit->_deltaE,*_deltaE_dk); else if ((typeBName=="DPi")||(typeBName=="Dpi0Pi")||(typeBName=="DgammaPi")) cust->replaceArg(*_gFit->_deltaE,*_deltaE_dpi); // add component RooAbsPdf *pdfCompCust = (RooAbsPdf*)cust->build(kFALSE); if (mpi_rank==0) cust->Print(); pdfCust->addPdf(*pdfCompCust,pdfCompName); } } } itypeRun++; } delete tIterD; delete tIterB; // // Take into account strong phase difference of pi between Dpi0 and Dgamma B modes RooArgSet *parsPdf = pdfCust->getParameters(selDataVars); RooCustomizer *cust = new RooCustomizer(*pdfCust,"cust") ; _cust_list.push_back(cust); RooCategory* phaseFormat = (RooCategory*)parsPdf->find("phaseFormat"); if (phaseFormat) { //if ( phaseFormat->getIndex()==RooDKFitProto::CARTESIAN ) { // cartesian format //cout << "RooDKFitMaster::doCustomize: cartesian format" << endl; replaceArgDstStrongPhase(cust,parsPdf,"reM_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"imM_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"reM_","DgammaPi","Dpi0Pi"); replaceArgDstStrongPhase(cust,parsPdf,"imM_","DgammaPi","Dpi0Pi"); replaceArgDstStrongPhase(cust,parsPdf,"reP_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"imP_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"reP_","DgammaPi","Dpi0Pi"); replaceArgDstStrongPhase(cust,parsPdf,"imP_","DgammaPi","Dpi0Pi"); // replaceArgDstStrongPhase(cust,parsPdf,"reMDh_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"imMDh_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"reMDh_","DgammaPi","Dpi0Pi"); replaceArgDstStrongPhase(cust,parsPdf,"imMDh_","DgammaPi","Dpi0Pi"); replaceArgDstStrongPhase(cust,parsPdf,"rePDh_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"imPDh_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"rePDh_","DgammaPi","Dpi0Pi"); replaceArgDstStrongPhase(cust,parsPdf,"imPDh_","DgammaPi","Dpi0Pi"); // replaceArgDstStrongPhase(cust,parsPdf,"reMBB_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"imMBB_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"reMBB_","DgammaPi","Dpi0Pi"); replaceArgDstStrongPhase(cust,parsPdf,"imMBB_","DgammaPi","Dpi0Pi"); replaceArgDstStrongPhase(cust,parsPdf,"rePBB_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"imPBB_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"rePBB_","DgammaPi","Dpi0Pi"); replaceArgDstStrongPhase(cust,parsPdf,"imPBB_","DgammaPi","Dpi0Pi"); //} else if ( (phaseFormat->getIndex()==RooDKFitProto::THETAM_THETAP_POLAR_RAD) || // (phaseFormat->getIndex()==RooDKFitProto::THETAM_THETAP_POLAR_DEG) ) { //cout << "RooDKFitMaster::doCustomize: theta-, theta+ phases format" << endl; // theta+, theta- phase format replaceArgDstStrongPhase(cust,parsPdf,"phaseM_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"phaseM_","DgammaPi","Dpi0Pi"); replaceArgDstStrongPhase(cust,parsPdf,"phaseP_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"phaseP_","DgammaPi","Dpi0Pi"); // replaceArgDstStrongPhase(cust,parsPdf,"phaseMDh_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"phaseMDh_","DgammaPi","Dpi0Pi"); replaceArgDstStrongPhase(cust,parsPdf,"phasePDh_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"phasePDh_","DgammaPi","Dpi0Pi"); // replaceArgDstStrongPhase(cust,parsPdf,"phaseMBB_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"phaseMBB_","DgammaPi","Dpi0Pi"); replaceArgDstStrongPhase(cust,parsPdf,"phasePBB_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"phasePBB_","DgammaPi","Dpi0Pi"); //} else if ( (phaseFormat->getIndex()==RooDKFitProto::WEAK_STRONG_POLAR_RAD) || // (phaseFormat->getIndex()==RooDKFitProto::WEAK_STRONG_POLAR_DEG) ) { // weak, strong phase format //cout << "RooDKFitMaster::doCustomize: weak, strong phases format" << endl; replaceArgDstStrongPhase(cust,parsPdf,"phaseS_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"phaseS_","DgammaPi","Dpi0Pi"); // replaceArgDstStrongPhase(cust,parsPdf,"phaseSDh_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"phaseSDh_","DgammaPi","Dpi0Pi"); // replaceArgDstStrongPhase(cust,parsPdf,"phaseSBB_","DgammaK","Dpi0K"); replaceArgDstStrongPhase(cust,parsPdf,"phaseSBB_","DgammaPi","Dpi0Pi"); //} } // RooSimultaneous *pdfCust2 = (RooSimultaneous*)cust->build(kFALSE); if (mpi_rank==0) cust->Print(); delete parsPdf; // RooArgSet* deps = pdfCust2->getDependents(_gFit->_selDataVars); if (mpi_rank==0) deps->Print("v"); delete deps; return pdfCust2; } // make argument replacement void RooDKFitMaster::replaceArg(RooCustomizer *cust, RooArgSet* pars, TString& name, TString& name2) { int mpi_rank = get_mpi_rank(); assert(cust); assert(pars); if (mpi_rank==0) cout << "Trying to replace " << name << " by " << name2 << endl; RooRealVar* par = (RooRealVar*)pars->find(name); // par2 replaces par RooRealVar* par2 = (RooRealVar*)pars->find(name2); if (par && par2 && par!=par2) cust->replaceArg(*par,*par2) ; } // make replacement of Dpi0/Dgamma strong phases to take into account strong phase difference of pi rad void RooDKFitMaster::replaceArgDstStrongPhase(RooCustomizer *cust, RooArgSet* pars, const char* name_root, const char* suffix, const char* suffix2) { int mpi_rank = get_mpi_rank(); assert(cust); assert(pars); RooCategory* phaseFormat = (RooCategory*)pars->find("phaseFormat"); //assert(phaseFormat); //assert(phaseFormat->getIndex()!=RooDKFitProto::UNKNOWN); if (phaseFormat==0 || phaseFormat->getIndex()==RooDKFitProto::UNKNOWN) return; TString name(name_root); name.Append(suffix); TString name2(name_root); name2.Append(suffix2); RooAbsReal* par = (RooRealVar*)pars->find(name); // par2 replaces par RooAbsReal* par2 = (RooRealVar*)pars->find(name2); if (par && par2 && par!=par2) { if (mpi_rank==0) cout << "Trying to replace " << name << " by " << name2 << endl; RooAbsReal* par_new(0); if (phaseFormat->getIndex()==RooDKFitProto::CARTESIAN) par_new = new RooFormulaVar(name,par->GetTitle(),"-@0",*par2) ; // cos(theta+-)(Dgamma)=-cos(theta+-)(Dpi0), sin(theta+-)(Dgamma)=-sin(theta+-)(Dpi0) else { RooArgList list(*par2); (phaseFormat->getIndex()==RooDKFitProto::WEAK_STRONG_POLAR_RAD || phaseFormat->getIndex()==RooDKFitProto::THETAM_THETAP_POLAR_RAD)? list.add(RooRealConstant::value(EvtConst::pi)) : list.add(RooRealConstant::value(180.)) ; //par_new = new RooFormulaVar(name,par->GetTitle(),"@0",*par2) ; // delta(Dgamma)=delta(Dpi0), theta+-(Dgamma)=theta+-(Dpi0) par_new = new RooFormulaVar(name,par->GetTitle(),"@0-@1",list) ; // delta(Dgamma)=delta(Dpi0)-180, theta+-(Dgamma)=theta+-(Dpi0)-180 // CAUTION with this when blinding !!! } cust->replaceArg(*par,*par_new) ; } } // make replacement of Dalitz parameters when identical (needed only for parameters which are left floated) RooSimultaneous* RooDKFitMaster::doDalitzParsCustomize(RooSimultaneous* pdf, const RooArgSet& selDataVars) { int mpi_rank = get_mpi_rank(); RooCustomizer *cust = new RooCustomizer(*pdf,"cust") ; _cust_list.push_back(cust); RooArgSet *parsPdf = pdf->getParameters(selDataVars); replaceDalitzPars(cust,parsPdf,"(K*m)","(K*p)","massAmp",""); replaceDalitzPars(cust,parsPdf,"(K*m)","(K*p)","widthAmp",""); // replaceDalitzPars(cust,parsPdf,"(K2*m_1430)","(K2*p_1430)","massAmp",""); replaceDalitzPars(cust,parsPdf,"(K2*m_1430)","(K2*p_1430)","widthAmp",""); // replaceDalitzPars(cust,parsPdf,"(K*m_1410)","(K*p_1410)","massAmp",""); replaceDalitzPars(cust,parsPdf,"(K*m_1410)","(K*p_1410)","widthAmp",""); // replaceDalitzPars(cust,parsPdf,"(K*m_1680)","(K*p_1680)","massAmp",""); replaceDalitzPars(cust,parsPdf,"(K*m_1680)","(K*p_1680)","widthAmp",""); // replaceDalitzPars(cust,parsPdf,"(K0*m_1430)","(K0*p_1430)","massAmp",""); replaceDalitzPars(cust,parsPdf,"(K0*m_1430)","(K0*p_1430)","widthAmp",""); // replaceDalitzPars(cust,parsPdf,"(K0*m_1430)","(K0*p_1430)","alassAmp",""); replaceDalitzPars(cust,parsPdf,"(K0*m_1430)","(K0*p_1430)","rlassAmp",""); replaceDalitzPars(cust,parsPdf,"(K0*m_1430)","(K0*p_1430)","BlassAmp",""); replaceDalitzPars(cust,parsPdf,"(K0*m_1430)","(K0*p_1430)","phiBlassAmp",""); replaceDalitzPars(cust,parsPdf,"(K0*m_1430)","(K0*p_1430)","RlassAmp",""); replaceDalitzPars(cust,parsPdf,"(K0*m_1430)","(K0*p_1430)","phiRlassAmp",""); // replaceDalitzPars(cust,parsPdf,"(a00_980)","(a0p_980)","massAmp",""); replaceDalitzPars(cust,parsPdf,"(a00_980)","(a0p_980)","widthAmp",""); replaceDalitzPars(cust,parsPdf,"(a00_980)","(a0p_980)","width2Amp",""); replaceDalitzPars(cust,parsPdf,"(a00_980)","(a0m_980)","massAmp",""); replaceDalitzPars(cust,parsPdf,"(a00_980)","(a0m_980)","widthAmp",""); replaceDalitzPars(cust,parsPdf,"(a00_980)","(a0m_980)","width2Amp",""); // replaceDalitzPars(cust,parsPdf,"(a00_1450)","(a0p_1450)","massAmp",""); replaceDalitzPars(cust,parsPdf,"(a00_1450)","(a0p_1450)","widthAmp",""); replaceDalitzPars(cust,parsPdf,"(a00_1450)","(a0m_1450)","massAmp",""); replaceDalitzPars(cust,parsPdf,"(a00_1450)","(a0m_1450)","widthAmp",""); // replaceDalitzPars(cust,parsPdf,"(a20_1320)","(a2p_1320)","massAmp",""); replaceDalitzPars(cust,parsPdf,"(a20_1320)","(a2p_1320)","widthAmp",""); replaceDalitzPars(cust,parsPdf,"(a20_1320)","(a2m_1320)","massAmp",""); replaceDalitzPars(cust,parsPdf,"(a20_1320)","(a2m_1320)","widthAmp",""); // RooSimultaneous *pdfCust = (RooSimultaneous*)cust->build(kFALSE); if (mpi_rank==0) cust->Print(); delete parsPdf; return pdfCust; } // void RooDKFitMaster::replaceDalitzPars(RooCustomizer *cust, RooArgSet* pars, const char* nameAmp, const char* nameAmp2, const char* namePar, TString faked) { assert(cust); assert(pars); assert(TString(nameAmp)!=TString(nameAmp2)); assert(namePar); assert(faked=="" || faked=="FakeD" || faked=="BBFakeD" || faked=="FakeDKsKs"); TIterator* iter = pars->createIterator(); RooAbsArg* item; RooAbsArg* parToBekept(0); // find parameter to be kept while (item = (RooAbsArg*)iter->Next()) { TString name(item->GetName()); if ( name.BeginsWith(namePar) && name.Contains(nameAmp) && // ((FakeD && name.Contains("FakeD")) || (!FakeD && !name.Contains("FakeD"))) ( (faked=="FakeD" && name.Contains("FakeD") && !name.Contains("BBFakeD") && !name.Contains("FakeDKsKs")) || (faked=="BBFakeD" && name.Contains("BBFakeD")) || (faked=="" && !name.Contains("FakeD") && !name.Contains("BBFakeD") && !name.Contains("FakeDKsKs")) ) ) { parToBekept=item; break; } } if (parToBekept==0) return; // nothing to be replaced //cout << "parToBekept = " << parToBekept->GetName() << endl; // find parameters to be replaced iter->Reset(); while (item = (RooAbsArg*)iter->Next()) { TString name(item->GetName()); if ( name.BeginsWith(namePar) && name.Contains(nameAmp2) && ( //(FakeD && name.Contains("FakeD")) || (!FakeD && !name.Contains("FakeD"))) (faked=="FakeD" && name.Contains("FakeD") && !name.Contains("BBFakeD") && !name.Contains("FakeDKsKs")) || (faked=="BBFakeD" && name.Contains("BBFakeD")) || (faked=="" && !name.Contains("FakeD") && !name.Contains("BBFakeD") && !name.Contains("FakeDKsKs")) ) ) { cout << "Trying to replace " << item->GetName() << " by " << parToBekept->GetName() << endl; cust->replaceArg(*item,*parToBekept) ; } } } // make replacement of Dalitz phases based on Watson theorem RooSimultaneous* RooDKFitMaster::doPhaseWatsonCustomize(RooSimultaneous* pdf, const RooArgSet& selDataVars) { int mpi_rank = get_mpi_rank(); RooCustomizer *cust = new RooCustomizer(*pdf,"cust") ; _cust_list.push_back(cust); RooArgSet *parsPdf = pdf->getParameters(selDataVars); replacePhaseWatson(cust,parsPdf,"_KsPiPi","K*m","K*p",180.); replacePhaseWatson(cust,parsPdf,"_KsPiPi","K0*m_1430","K0*p_1430",0.); replacePhaseWatson(cust,parsPdf,"_KsPiPi","K2*m_1430","K2*p_1430",0.); RooSimultaneous *pdfCust = (RooSimultaneous*)cust->build(kFALSE); if (mpi_rank==0) cust->Print(); delete parsPdf; return pdfCust; } // void RooDKFitMaster::replacePhaseWatson(RooCustomizer *cust, RooArgSet* pars, const char* suffix, const char* nameAmpCF, const char* nameAmpDCS, Double_t phaseShiftDeg) { int mpi_rank = get_mpi_rank(); assert(cust); assert(pars); RooCategory* formatCoef = (RooCategory*)pars->find("formatCoef"); //assert(formatCoef); if (formatCoef==0) return; char* buffer = new char[30]; TIterator* iter = pars->createIterator(); RooAbsArg* item; Int_t indexCF(-1),indexDCS(-1); while (item = (RooAbsArg*)iter->Next()) { TString name(item->GetName()); if (name.BeginsWith("nameAmp") && name.EndsWith(suffix)) { TString label(((RooCategory*)item)->getLabel()); for (Int_t i=1;i<=MAXAMP;i++) { sprintf(buffer,"nameAmp%i",i); TString namei(buffer); namei.Append(suffix); if ( (namei==name) && (label==TString(nameAmpCF)) ) indexCF =i; if ( (namei==name) && (label==TString(nameAmpDCS)) ) indexDCS=i; } } } if (mpi_rank==0) cout << indexCF << " " << indexDCS << endl; delete iter; if (indexCF=-1 && indexDCS!=-1) { sprintf(buffer,"phaseCoefAmp%i",indexCF); TString nameCF(buffer); nameCF.Append(suffix); RooRealVar* parCF = (RooRealVar*)pars->find(nameCF); sprintf(buffer,"phaseCoefAmp%i",indexDCS); TString nameDCS(buffer); nameDCS.Append(suffix); RooRealVar* parDCS = (RooRealVar*)pars->find(nameDCS); if (parCF && parDCS && parCF!=parDCS) { if (mpi_rank==0) cout << "Trying to replace " << nameDCS << " by " << nameCF << endl; RooArgList list(*parCF); if (formatCoef->getIndex()==RooDalitzAmp::POLAR_RAD) list.add(RooRealConstant::value(phaseShiftDeg/EvtConst::radToDegrees)); else if (formatCoef->getIndex()==RooDalitzAmp::POLAR_DEG) list.add(RooRealConstant::value(phaseShiftDeg)) ; else assert(0); RooAbsReal* parDCS_new = new RooFormulaVar(nameDCS,parDCS->GetTitle(),"@0+@1",list) ; // phase(DCS)=phase(CF)+phaseShiftDeg cust->replaceArg(*parDCS,*parDCS_new) ; } } delete buffer; } // returns list containing physics (PHYS) parameters RooArgSet* RooDKFitMaster::selectPHYSParams(const RooArgSet* list) { RooArgSet* pars = new RooArgSet(); TIterator* iter = list->createIterator(); RooRealVar* item; while (item = (RooRealVar*)iter->Next()) { TString title(item->GetTitle()); if (title.Contains("(PHYS)")) pars->add(*item); } delete iter; return pars; } // ========================================= // Start tools for plotting // ========================================= // making PDF shape plots void RooDKFitMaster::makePlots(TString BMode, TString DMode, TString opt, const char* epsfile_root, Bool_t kToyMc, Bool_t kPdfSel, Int_t nbins, TString bkgCompOpt, Bool_t nice, Double_t epsRel, Bool_t plotPdf, Bool_t logScale) { // DMode exists? if (!_gFit->_DdecayMode->isValidLabel(DMode)) return; //gROOT->SetStyle("BABAR"); // BABARSmartLabel(0.9,0.9,1.0,"null",0.5,"R"); // set decay modes _gFit->_DdecayMode->setLabel(DMode); _gFit->_DdecayModeLF->setIndex(_gFit->_DdecayMode->getIndex()); _gFit->_BdecayMode->setLabel(BMode); _gFit->_BdecayModeLF->setIndex(_gFit->_BdecayMode->getIndex()); // eps root file name TString file_root; if (epsfile_root) { file_root.Append(epsfile_root); file_root.Append("_"); } file_root.Append(BMode); file_root.Append("_"); file_root.Append(DMode); std::string rootPlotsFile = (const char*) ( file_root + ".plots.root" ); file_root.Append("_"); // pdf component name TString pdfComp("{"); pdfComp.Append(DMode); pdfComp.Append(";"); pdfComp.Append(BMode); pdfComp.Append("}"); if (get_mpi_rank()==0) cout << "RooDKFitMaster::makePlots: Pdf component: " << pdfComp << endl; // get PDF RooAbsPdf* pdf(0); if (kPdfSel&&_pdfSel) pdf = _pdfSel->getPdf(pdfComp); if (!kPdfSel&&_pdfGlobal) pdf = _pdfGlobal->getPdf(pdfComp); if (pdf==0) return; // define precision numerical integral for plotting (in case it is used by RooFit) if (pdf) { RooNumIntConfig* intConfig = (RooNumIntConfig*)pdf->getIntegratorConfig(); if (get_mpi_rank()==0) cout << "RooDKFitMaster::makePlots(): Original RooNumIntConfig precision: epsRel = " << intConfig->epsRel() << " , epsAbs = " << intConfig->epsAbs() << endl; intConfig->setEpsRel(epsRel); intConfig->setEpsAbs(epsRel); if (get_mpi_rank()==0) cout << "RooDKFitMaster::makePlots(): New RooNumIntConfig precision: epsRel = " << intConfig->epsRel() << " , epsAbs = " << intConfig->epsAbs() << endl; } // get dependents and set limits for DeltaE RooArgSet* deps(0); RooRealVar *mD(0),*deltam(0),*mES(0),*fisher(0),*deltaE(0),*tReco(0),*tErr(0),*tTrue(0); if (pdf) { deps = pdf->getDependents(_gFit->_selDataVars); //deps->Print("v"); mD = (RooRealVar*)deps->find("mD"); if (mD) { if (kPdfSel) mD->setRange(_mDMin_Sel->getVal(),_mDMax_Sel->getVal()); else mD->setRange(_mDMin->getVal(),_mDMax->getVal()); } deltam = (RooRealVar*)deps->find("deltam"); if (deltam) { if (kPdfSel) deltam->setRange(_deltamMin_Sel->getVal(),_deltamMax_Sel->getVal()); else deltam->setRange(_deltamMin->getVal(),_deltamMax->getVal()); } mES = (RooRealVar*)deps->find("mES"); fisher = (RooRealVar*)deps->find("fisher"); deltaE = (RooRealVar*)deps->find("deltaE_dk"); if (deltaE) { if (kPdfSel) deltaE->setRange(_deltaEMin_dkSel->getVal(),_deltaEMax_dkSel->getVal()); else deltaE->setRange(_deltaEMin_dk->getVal(),_deltaEMax_dk->getVal()); } else { deltaE = (RooRealVar*)deps->find("deltaE_dpi"); //assert(deltaE); if (deltaE) { if (kPdfSel) deltaE->setRange(_deltaEMin_dpiSel->getVal(),_deltaEMax_dpiSel->getVal()); else deltaE->setRange(_deltaEMin_dpi->getVal(),_deltaEMax_dpi->getVal()); } } if (deltaE) if (get_mpi_rank()==0) cout << deltaE->GetName() << " range: [" << deltaE->getMin() << "," << deltaE->getMax() << "]" << endl; tReco = (RooRealVar*)deps->find("tReco"); tErr = (RooRealVar*)deps->find("tErr"); tTrue = (RooRealVar*)deps->find("tTrue"); } // projection cut TString cutProj("(BdecayMode==BdecayMode::"); cutProj.Append(BMode); cutProj.Append(")&&(DdecayMode==DdecayMode::"); cutProj.Append(DMode); cutProj.Append(")"); if (deltaE) { cutProj.Append("&&("); cutProj.Append(deltaE->GetName()); cutProj.Append("<="); char* buffer = new char[30]; //sprintf(buffer,"%.2e",deltaE->getMax()); sprintf(buffer,"%e",deltaE->getMax()); cutProj.Append(buffer); cutProj.Append(")&&("); cutProj.Append(deltaE->GetName()); cutProj.Append(">="); sprintf(buffer,"%e",deltaE->getMin()); cutProj.Append(buffer); cutProj.Append(")"); delete buffer; } if (get_mpi_rank()==0) cout << "RooDKFitMaster::makePlots: Data projection cut: " << cutProj << endl; // get projected data set RooDataSet* data(0); if (kToyMc) { if (kPdfSel) data = (RooDataSet*)_fitDataSelToyMc->reduce(cutProj); else data = (RooDataSet*)_fitDataToyMc->reduce(cutProj); } else { if (kPdfSel) data = (RooDataSet*)_fitDataSel->reduce(cutProj); else data = (RooDataSet*)_fitData->reduce(cutProj); } if (data==0 || (data&&data->numEntries()==0)) { if (deps) delete deps; return; } // projections RooArgSet projDataDeps; RooAbsData* projData(0); RooArgSet pdf_deps(*pdf->getDependents(_gFit->_selDataVars)); if (TString(_deltaEDhOption->getLabel())=="deltaEshift") projDataDeps.add(*_gFit->_deltaEshift); //if (TString(_resFcn->getLabel()).EndsWith("EventError") // && pdf_deps.find("tErr") && (pdf_deps.find("tReco") || pdf_deps.find("tTrue"))) projDataDeps.add(*_gFit->_tErr); // project over sigma_t assert( !(TString(_resFcn->getLabel()).EndsWith("GlobalError") && pdf_deps.find("tErr")) ); // with GlobalError the pdf cannot contain tErr if (pdf_deps.find("tErr")) projDataDeps.add(*_gFit->_tErr); // project over sigma_t for EventError and Truth projDataDeps.add(*_gFit->_recState); //projDataDeps.add(*_gFit->_DdecayMode); //projDataDeps.Print("v"); assert(0); RooArgSet projDataDeps_no_deltaEshift(projDataDeps); projDataDeps_no_deltaEshift.remove(*_gFit->_deltaEshift); projData = data; // unbinned since too many dependents RooDataHist projData_hist("projData_hist","projData_hist",projDataDeps,*data); RooDataHist projData_no_deltaEshift_hist("projData_hist","projData_hist",projDataDeps_no_deltaEshift,*data); // plotting the D0-Deltam scatter plot if (mD&&deltam&&((opt=="mD")||(opt=="Deltam")||(opt=="All"))) { if (get_mpi_rank()==0) cout << "Producing mD-Deltam plot..." << endl; TH2F* h2 = data->createHistogram(*mD,*deltam,nbins,nbins,0,"h2") ; TCanvas *c1 = new TCanvas( "mD-dM", "allevents",600,600); c1 -> SetFillColor(10); c1 -> SetTitle(""); h2->SetMarkerSize(0.4); //h2->Draw(); //h2->Draw("BOX"); h2->Draw("COLZ"); gStyle->SetPalette(1); // make ps if (get_mpi_rank()==0) { TString file(file_root); file.Append("mD-Deltam"); c1->Print(file+".eps"); //c1->Print(file+".gif"); } // Write the canvas into the file with the appropriate name. if (get_mpi_rank()==0) { TFile plotsFile( rootPlotsFile.c_str(), "update" ); std::string plotName = std::string( BMode + "_" + DMode + "_mD_deltaM" ); c1->Write( plotName.c_str() ); // Save the histogram to the file. plotsFile.Close(); } delete c1; } // plotting the D0 mass if (mD&&((opt=="mD")||(opt=="All"))) makePlotsVar(mD,"mD",data,pdf,nbins,logScale,plotPdf,bkgCompOpt,nice,"m_{D}","GeV/c^{2}",file_root,projDataDeps,&projData_hist); // plotting the D*-D0 mass if (deltam&&((opt=="Deltam")||(opt=="All"))) makePlotsVar(deltam,"Deltam",data,pdf,nbins,logScale,plotPdf,bkgCompOpt,nice,"#Delta m","GeV/c^{2}",file_root,projDataDeps,&projData_hist); // plotting the tReco (proper time) if (tReco&&((opt=="tReco")||(opt=="All"))) makePlotsVar(tReco,"tReco",data,pdf,nbins,logScale,plotPdf,bkgCompOpt,nice,"t","ps",file_root,projDataDeps,&projData_hist); // plotting the tErr (error on proper time) if (tErr&&(TString(_resFcn->getLabel())!="Unknown") && (TString(_resFcn->getLabel())!="Truth")&&((opt=="tErr")||(opt=="All"))) { Bool_t plotPdf_tErr = (tReco || tTrue)? kFALSE : plotPdf; makePlotsVar(tErr,"tErr",data,pdf,nbins,logScale,plotPdf_tErr,bkgCompOpt,nice,"#sigma t","ps",file_root,projDataDeps,&projData_hist); } // plotting the tTrue (true proper time) if (tTrue&&((opt=="tTrue")||(opt=="All"))) makePlotsVar(tTrue,"tTrue",data,pdf,nbins,logScale,plotPdf,bkgCompOpt,nice,"t","ps",file_root,projDataDeps,&projData_hist); // plotting mES if (mES&&((opt=="mES")||(opt=="All"))) { if (get_mpi_rank()==0) cout << "Producing mES plot..." << endl; if (nice) mES->setRange(5.2,5.29); TCanvas *c1 = (nice && bkgCompOpt.Contains("A"))? new TCanvas("c1","allevents",600,600) : new TCanvas("c1","allevents",600,600); c1 -> SetFillColor(10); RooPlot* xframe = mES->frame(nbins); xframe -> SetTitle(""); data->plotOn(xframe); //xframe->getAttMarker()->SetMarkerSize(0.5); xframe->getAttMarker()->SetMarkerSize(1.0); //data->statOn(xframe,"NRM","",2); pdf->plotOn(xframe,ProjWData(projDataDeps_no_deltaEshift,projData_no_deltaEshift_hist),LineColor(kBlack)); //pdf->plotOn(xframe,LineColor(kBlack)); //pdf->plotOn(xframe,LineColor(kBlack),Range(5.18,5.29)); //xframe->getAttLine()->SetLineWidth(1.0); xframe->getAttLine()->SetLineStyle(1); if (bkgCompOpt.Contains("Y")) { if (nice && bkgCompOpt.Contains("A")) { xframe->getAttLine()->SetLineWidth(4); //pdf->plotOn(xframe,Components("mesContPdf*,mesBBPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kRed)); pdf->plotOn(xframe,Components("mesContPdf*,mesBBPdf*"),LineColor(kRed)); //xframe->getAttLine()->SetLineStyle(3); // dotted //xframe->getAttLine()->SetLineStyle(2); // very short dashed xframe->getAttLine()->SetLineStyle(7); // short dashed xframe->getAttLine()->SetLineWidth(4); //pdf->plotOn(xframe,Components("mesContPdf*,mesBBPdf*,mesDhPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kBlue)); // for DK channels if (BMode=="DK" || BMode=="Dpi0K" || BMode=="DgammaK" || BMode=="DKspi" || BMode=="DRho0pi") pdf->plotOn(xframe,Components("mesContPdf*,mesBBPdf*,mesDhPdf*"),LineColor(kBlue)); // for DK channels else if (BMode=="DPi" || BMode=="Dpi0Pi" || BMode=="DgammaPi") pdf->plotOn(xframe,Components("mesContPdf*,mesBBPdf*,mesSigPdf*"),LineColor(kBlue)); // for DPi channels //else if (BMode=="DRho0pi") // {;} // do nothing else assert(0); xframe->getAttLine()->SetLineStyle(9); // long dashed xframe->getAttLine()->SetLineWidth(4); } else { /* pdf->plotOn(xframe,Components("mesContPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kMagenta)); pdf->plotOn(xframe,Components("mesDhPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kBlue)); pdf->plotOn(xframe,Components("mesBBPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kGreen)); pdf->plotOn(xframe,Components("mesSigPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kRed)); */ pdf->plotOn(xframe,Components("mesContPdf*"),ProjWData(projDataDeps_no_deltaEshift,projData_no_deltaEshift_hist),LineColor(kMagenta)); pdf->plotOn(xframe,Components("mesContPdf*,mesBBPdf*"),ProjWData(projDataDeps_no_deltaEshift,projData_no_deltaEshift_hist),LineColor(kGreen)); if (BMode=="DK" || BMode=="Dpi0K" || BMode=="DgammaK" || BMode=="DKspi" || BMode=="DRho0pi") { // for DK channels pdf->plotOn(xframe,Components("mesContPdf*,mesBBPdf*,mesDhPdf*"),ProjWData(projDataDeps_no_deltaEshift,projData_no_deltaEshift_hist),LineColor(kBlue)); pdf->plotOn(xframe,Components("mesContPdf*,mesBBPdf*,mesDhPdf*,mesSigPdf*"),ProjWData(projDataDeps_no_deltaEshift,projData_no_deltaEshift_hist),LineColor(kRed)); } else if (BMode=="DPi" || BMode=="Dpi0Pi" || BMode=="DgammaPi") { // for DPi channels pdf->plotOn(xframe,Components("mesContPdf*,mesBBPdf*,mesSigPdf*"),ProjWData(projDataDeps_no_deltaEshift,projData_no_deltaEshift_hist),LineColor(kRed)); pdf->plotOn(xframe,Components("mesContPdf*,mesBBPdf*,mesSigPdf*,mesDhPdf*"),ProjWData(projDataDeps_no_deltaEshift,projData_no_deltaEshift_hist),LineColor(kBlue)); } xframe->getAttLine()->SetLineStyle(1); } } /* // patch for D0a1 if (BMode=="DRho0pi") { TLine* l = new TLine(5.2,0.,5.2,300.); l->SetLineStyle(1); l->SetLineWidth(6); l->SetLineColor(10); xframe->addObject(l); TLine* l2 = new TLine(5.2,0.,5.2,300.); l2->SetLineWidth(1); l2->SetLineColor(1); xframe->addObject(l2); } */ // if (nice) { c1->SetBottomMargin(0.15); c1->SetLeftMargin(0.15); TAxis *xaxis = xframe->GetXaxis(); TAxis *yaxis = xframe->GetYaxis(); xaxis->SetNdivisions(502); yaxis->SetNdivisions(5); //xframe->SetTitleOffset(0.65,"X"); //define the frame //xframe->SetTitleOffset(0.8,"Y");//for babar style xframe->SetTitleOffset(1.1,"X"); //define the frame xframe->SetTitleOffset(1.45,"Y");//for babar style //xaxis->SetLabelSize(0.10); // def is 0.04 //xaxis->SetTitleSize(0.10); // def is 0.04 //yaxis->SetLabelSize(0.10); // def is 0.04 //yaxis->SetTitleSize(0.10); // def is 0.04 xaxis->SetLabelSize(0.06); // def is 0.04 xaxis->SetTitleSize(0.06); // def is 0.04 yaxis->SetLabelSize(0.05); // def is 0.04 yaxis->SetTitleSize(0.06); // def is 0.04 //xaxis->SetLabelOffset(-0.02); // default 0.005 //yaxis->SetLabelOffset(0.015); // default 0.005 xaxis->SetLabelOffset(0.02); // default 0.005 yaxis->SetLabelOffset(0.02); // default 0.005 yaxis->SetTitle("Events/2.25 MeV/c^{2}"); // 40 bins //yaxis->SetTitle("Events/3 MeV/c^{2}"); // 30 bins //yaxis->SetTitle("Events/1.5 MeV/c^{2}"); // 60 bins } xframe->Draw(); //if (nice && bkgCompOpt.Contains("A")) { // if (BMode=="DK" || BMode=="DPi") BABARSmartLabel(0.80,0.92,1.4,""); // //BABARSmartLabel(0.26,1.0,1,"a)",1.2,"R",kFALSE); // BABARSmartLabel(0.40,0.92,1,"preliminary"); //} else if (nice) { if (nice) { //BABARSmartLabel(0.40,0.92,1,"preliminary"); //BABARSmartLabel(0.40,0.92,1,""); //BABARSmartLabel(0.23,0.86,1,"a)",0.8,"R",kFALSE); BABARSmartLabel(0.25,0.94,1,"a)",0.8,"R",kFALSE); } // make ps if (get_mpi_rank()==0) { TString file(file_root); file.Append("mES"); c1->Print(file+".eps"); //c1->Print(file+".gif"); } // Write the canvas into the file with the appropriate name. if (get_mpi_rank()==0) { TFile plotsFile( rootPlotsFile.c_str(), "update" ); std::string plotName = std::string( BMode + "_" + DMode + "_mES" ); c1->Write( plotName.c_str() ); // Save the histogram to the file. plotsFile.Close(); } //getchar(); delete c1; } // plotting deltaE if (deltaE&&((opt=="DeltaE")||(opt=="All"))) { if (get_mpi_rank()==0) cout << "Producing DeltaE plot..." << endl; TCanvas *c1 = new TCanvas("deltaE","allevents",600,600); c1 -> SetFillColor(10); RooPlot* xframe = deltaE->frame(nbins); xframe -> SetTitle(""); data->plotOn(xframe); xframe->getAttMarker()->SetMarkerSize(1.0); pdf->plotOn(xframe,ProjWData(projDataDeps,projData_hist),LineColor(kBlack)); xframe->getAttLine()->SetLineStyle(1); if (bkgCompOpt.Contains("Y")) { if (nice && bkgCompOpt.Contains("A")) { xframe->getAttLine()->SetLineWidth(4); //pdf->plotOn(xframe,Components("deContPdf*,deBBPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kRed)); pdf->plotOn(xframe,Components("deContPdf*,deBBPdf*"),LineColor(kRed)); //xframe->getAttLine()->SetLineStyle(3); // dotted //xframe->getAttLine()->SetLineStyle(2); // very short dashed xframe->getAttLine()->SetLineStyle(7); // short dashed xframe->getAttLine()->SetLineWidth(4); //pdf->plotOn(xframe,Components("deContPdf*,deBBPdf*,deDhPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kBlue)); // for DK channels if (BMode=="DK" || BMode=="Dpi0K" || BMode=="DgammaK" || BMode=="DKspi" || BMode=="DRho0pi") pdf->plotOn(xframe,Components("deContPdf*,deBBPdf*,deDhPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kBlue)); // for DK channels else if (BMode=="DPi" || BMode=="Dpi0Pi" || BMode=="DgammaPi") pdf->plotOn(xframe,Components("deContPdf*,deBBPdf*,deSigPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kBlue)); // for DPi channels //else if (BMode=="DRho0pi") // {;} // do nothing else assert(0); xframe->getAttLine()->SetLineStyle(9); // long dashed xframe->getAttLine()->SetLineWidth(4); } else { /* pdf->plotOn(xframe,Components("deContPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kMagenta)); pdf->plotOn(xframe,Components("deDhPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kBlue)); pdf->plotOn(xframe,Components("deBBPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kGreen)); pdf->plotOn(xframe,Components("deSigPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kRed)); */ pdf->plotOn(xframe,Components("deContPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kMagenta)); pdf->plotOn(xframe,Components("deContPdf*,deBBPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kGreen)); if (BMode=="DK" || BMode=="Dpi0K" || BMode=="DgammaK" || BMode=="DKspi" || BMode=="DRho0pi") { // for DK channels pdf->plotOn(xframe,Components("deContPdf*,deBBPdf*,deDhPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kBlue)); pdf->plotOn(xframe,Components("deContPdf*,deBBPdf*,deDhPdf*,deSigPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kRed)); } else if (BMode=="DPi" || BMode=="Dpi0Pi" || BMode=="DgammaPi") { // for DPi channels pdf->plotOn(xframe,Components("deContPdf*,deBBPdf*,deSigPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kRed)); pdf->plotOn(xframe,Components("deContPdf*,deBBPdf*,deSigPdf*,deDhPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kBlue)); } xframe->getAttLine()->SetLineStyle(1); } } if (nice) { c1->SetBottomMargin(0.15); c1->SetLeftMargin(0.15); TAxis *xaxis = xframe->GetXaxis(); TAxis *yaxis = xframe->GetYaxis(); xaxis->SetNdivisions(605); yaxis->SetNdivisions(5); xframe->SetTitleOffset(1.2,"X"); //define the frame xframe->SetTitleOffset(1.2,"Y");//for babar style // xaxis->SetLabelSize(0.06); // def is 0.04 xaxis->SetTitleSize(0.06); // def is 0.04 yaxis->SetLabelSize(0.05); // def is 0.04 yaxis->SetTitleSize(0.06); // def is 0.04 //xaxis->SetLabelOffset(-0.02); // default 0.005 //yaxis->SetLabelOffset(0.015); // default 0.005 xaxis->SetLabelOffset(0.02); // default 0.005 yaxis->SetLabelOffset(0.02); // default 0.005 xaxis->SetTitle("#DeltaE (GeV)"); // 40 bins yaxis->SetTitle("Events/5 MeV"); // 40 bins } xframe->Draw(); if (nice) { //BABARSmartLabel(0.90,0.92,1,"preliminary"); //BABARSmartLabel(0.90,0.94,1,"c)",0.8,"R",kFALSE); BABARSmartLabel(0.25,0.94,1,"a)",0.8,"R",kFALSE); } // make ps if (get_mpi_rank()==0) { TString file(file_root); file.Append("DeltaE"); c1->Print(file+".eps"); //c1->Print(file+".gif"); } // Write the canvas into the file with the appropriate name. if (get_mpi_rank()==0) { TFile plotsFile( rootPlotsFile.c_str(), "update" ); std::string plotName = std::string( BMode + "_" + DMode + "_deltaE" ); c1->Write( plotName.c_str() ); // Save the histogram to the file. plotsFile.Close(); } //getchar(); delete c1; } // plotting Fisher if (fisher&&((opt=="Fisher")||(opt=="All"))) { if (get_mpi_rank()==0) cout << "Producing Fisher plot..." << endl; if (nice) fisher->setRange(-1.4,1.4); TCanvas *c1 = (nice && bkgCompOpt.Contains("A"))? new TCanvas("c1","allevents",600,600) : new TCanvas("c1","allevents",600,600); c1 -> SetFillColor(10); RooPlot* xframe = fisher->frame(nbins); xframe -> SetTitle(""); data->plotOn(xframe); //xframe->getAttMarker()->SetMarkerSize(0.5); xframe->getAttMarker()->SetMarkerSize(1.0); //data->statOn(xframe,"NRM","",2); //pdf->plotOn(xframe,ProjWData(projDataDeps,projData_hist),LineColor(kBlack)); pdf->plotOn(xframe,ProjWData(projDataDeps_no_deltaEshift,projData_no_deltaEshift_hist),LineColor(kBlack)); //xframe->getAttLine()->SetLineWidth(1.0); xframe->getAttLine()->SetLineStyle(1); if (bkgCompOpt.Contains("Y")) { if (nice && bkgCompOpt.Contains("A")) { xframe->getAttLine()->SetLineWidth(4); //pdf->plotOn(xframe,Components("fiContPdf*,fiBBPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kRed)); pdf->plotOn(xframe,Components("fiContPdf*,fiBBPdf*"),LineColor(kRed)); //xframe->getAttLine()->SetLineStyle(3); // dotted //xframe->getAttLine()->SetLineStyle(2); // very short dashed xframe->getAttLine()->SetLineStyle(7); // short dashed xframe->getAttLine()->SetLineWidth(4); //pdf->plotOn(xframe,Components("fiContPdf*,fiBBPdf*,fiDhPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kBlue)); // for DK channels if (BMode=="DK" || BMode=="Dpi0K" || BMode=="DgammaK" || BMode=="DKspi" || BMode=="DRho0pi") pdf->plotOn(xframe,Components("fiContPdf*,fiBBPdf*,fiDhPdf*"),LineColor(kBlue)); // for DK channels else if (BMode=="DPi" || BMode=="Dpi0Pi" || BMode=="DgammaPi") pdf->plotOn(xframe,Components("fiContPdf*,fiBBPdf*,fiSigPdf*"),LineColor(kBlue)); // for DPi channels //else if (BMode=="DRho0pi") // {;} // do nothing else assert(0); xframe->getAttLine()->SetLineStyle(9); // long dashed xframe->getAttLine()->SetLineWidth(4); } else { /* pdf->plotOn(xframe,Components("fiContPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kMagenta)); pdf->plotOn(xframe,Components("fiDhPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kBlue)); pdf->plotOn(xframe,Components("fiBBPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kGreen)); pdf->plotOn(xframe,Components("fiSigPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kRed)); */ //pdf->plotOn(xframe,Components("fiContPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kMagenta)); //pdf->plotOn(xframe,Components("fiContPdf*,fiBBPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kGreen)); pdf->plotOn(xframe,Components("fiContPdf*"),ProjWData(projDataDeps_no_deltaEshift,projData_no_deltaEshift_hist),LineColor(kMagenta)); pdf->plotOn(xframe,Components("fiContPdf*,fiBBPdf*"),ProjWData(projDataDeps_no_deltaEshift,projData_no_deltaEshift_hist),LineColor(kGreen)); if (BMode=="DK" || BMode=="Dpi0K" || BMode=="DgammaK" || BMode=="DKspi" || BMode=="DRho0pi") { // for DK channels //pdf->plotOn(xframe,Components("fiContPdf*,fiBBPdf*,fiDhPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kBlue)); //pdf->plotOn(xframe,Components("fiContPdf*,fiBBPdf*,fiDhPdf*,fiSigPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kRed)); pdf->plotOn(xframe,Components("fiContPdf*,fiBBPdf*,fiDhPdf*"),ProjWData(projDataDeps_no_deltaEshift,projData_no_deltaEshift_hist),LineColor(kBlue)); pdf->plotOn(xframe,Components("fiContPdf*,fiBBPdf*,fiDhPdf*,mesSigPdf*"),ProjWData(projDataDeps_no_deltaEshift,projData_no_deltaEshift_hist),LineColor(kRed)); } else if (BMode=="DPi" || BMode=="Dpi0Pi" || BMode=="DgammaPi") { // for DPi channels //pdf->plotOn(xframe,Components("fiContPdf*,fiBBPdf*,fiSigPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kRed)); //pdf->plotOn(xframe,Components("fiContPdf*,fiBBPdf*,fiSigPdf*,fiDhPdf*"),ProjWData(projDataDeps,projData_hist),LineColor(kBlue)); pdf->plotOn(xframe,Components("fiContPdf*,fiBBPdf*,fiSigPdf*"),ProjWData(projDataDeps_no_deltaEshift,projData_no_deltaEshift_hist),LineColor(kRed)); pdf->plotOn(xframe,Components("fiContPdf*,fiBBPdf*,fiSigPdf*,fiDhPdf*"),ProjWData(projDataDeps_no_deltaEshift,projData_no_deltaEshift_hist),LineColor(kBlue)); } } } if (nice) { c1->SetBottomMargin(0.15); c1->SetLeftMargin(0.15); TAxis *xaxis = xframe->GetXaxis(); xaxis->SetNdivisions(605); TAxis *yaxis = xframe->GetYaxis(); yaxis->SetNdivisions(5); xframe->SetTitleOffset(1.2,"X"); //define the frame //xframe->SetTitleOffset(1.2,"Y");//for babar style xframe->SetTitleOffset(1.3,"Y");//for babar style xaxis->SetLabelSize(0.06); // def is 0.04 xaxis->SetTitleSize(0.06); // def is 0.04 yaxis->SetLabelSize(0.05); // def is 0.04 yaxis->SetTitleSize(0.06); // def is 0.04 xaxis->SetLabelOffset(0.02); // default 0.005 yaxis->SetLabelOffset(0.02); // default 0.005 yaxis->SetTitle("Events/0.007"); // 40 bins, for range [-1.4,1.4] xaxis->SetTitle("Fisher"); } xframe->Draw(); if (nice) { //BABARSmartLabel(0.90,0.92,1,"preliminary"); //BABARSmartLabel(0.90,0.94,1,"a)",0.8,"R",kFALSE); BABARSmartLabel(0.25,0.94,1,"a)",0.8,"R",kFALSE); } // make ps if (get_mpi_rank()==0) { TString file(file_root); file.Append("Fisher"); c1->Print(file+".eps"); //c1->Print(file+".gif"); } // Write the canvas into the file with the appropriate name. if (get_mpi_rank()==0) { TFile plotsFile( rootPlotsFile.c_str(), "update" ); std::string plotName = std::string( BMode + "_" + DMode + "_fisher" ); c1->Write( plotName.c_str() ); // Save the histogram to the file. plotsFile.Close(); } //getchar(); delete c1; } // clean-up delete data; if (deps) delete deps; } // tool for making a single var PDF shape plot void RooDKFitMaster::makePlotsVar(RooRealVar* var, TString varName, RooDataSet* data, RooAbsPdf* pdf, Int_t nbins, Bool_t logScale, Bool_t plotPdf, TString bkgCompOpt, Bool_t nice, TString niceName, TString niceUnits, TString file_root, RooArgSet& projDataDeps, RooAbsData* projData) { // plotting the "var" variable if (get_mpi_rank()==0) cout << "Producing " << varName << " plot..." << endl; if (nice) { var->setUnit(niceUnits); var->SetTitle(niceName); } //RooPlot* xframe = (TString(var->GetName())=="tReco" || TString(var->GetName())=="tTrue")? var->frame(-4.,4.,nbins) : var->frame(nbins); RooPlot* xframe = (TString(var->GetName())=="tReco")? var->frame(-4.,4.,nbins) : (TString(var->GetName())=="tTrue")? var->frame(0.,4.,nbins) : var->frame(nbins); RooPlot* plot_data = data->plotOn(xframe); //xframe->getAttMarker()->SetMarkerSize(0.5); xframe->getAttMarker()->SetMarkerSize(1.0); TCanvas* c1 = 0; if (plotPdf) { //RooPlot* plot_pdf = pdf->plotOn(xframe,LineColor(kBlue)); RooPlot* plot_pdf = pdf->plotOn(xframe,LineColor(kBlue),ProjWData(projDataDeps,*projData)); if (nice) xframe->getAttLine()->SetLineColor(9); //xframe->getAttLine()->SetLineWidth(1.0); RooPlot *plot_pdfComp1(0),*plot_pdfComp2(0),*plot_pdfComp3(0),*plot_pdfComp4(0),*plot_pdfComp5(0),*plot_pdfComp6(0); if (bkgCompOpt.Contains("Y")) { if (nice && bkgCompOpt.Contains("A")) { //plot_pdfComp1 = pdf->plotOn(xframe,Components("mDContCombPdf_*"),ProjWData(projDataDeps,*projData),LineStyle(kDashed),LineColor(kRed)); assert(0); // to be implemented } else { ////plot_pdfComp1 = pdf->plotOn(xframe,Components("mDContPdf*"),ProjWData(projDataDeps,*projData),LineColor(kMagenta)); ////plot_pdfComp2 = pdf->plotOn(xframe,Components("mDDhPdf*"),ProjWData(projDataDeps,*projData),LineColor(kBlue)); ////plot_pdfComp3 = pdf->plotOn(xframe,Components("mDBBPdf*"),ProjWData(projDataDeps,*projData),LineColor(kGreen)); //plot_pdfComp1 = pdf->plotOn(xframe,Components("mDSigPdf*"),ProjWData(projDataDeps,*projData),LineColor(kRed)); //plot_pdfComp2 = pdf->plotOn(xframe,Components("mDContCombPdf_*"),ProjWData(projDataDeps,*projData),LineStyle(kDashed)); // for D mixing //pdf->Print("v"); // assert(0); TString comp = "*DstarContFakeDT*"; // Cat 4 plot_pdfComp1 = pdf->plotOn(xframe,LineColor(kGreen),ProjWData(projDataDeps,*projData),Components(comp)); comp += ",*DstarContGoodDT*,*DstarContGoodDRST*,*DstarContGoodDWST*"; // Cat 2 plot_pdfComp2 = pdf->plotOn(xframe,LineColor(kOrange),ProjWData(projDataDeps,*projData),Components(comp)); //enum EColor { kWhite =0, kBlack =1, kGray=920 // ,kRed =632, kGreen =416, kBlue=600, kYellow=400, kMagenta=616, kCyan=432 // ,kOrange=800, kSpring=820, kTeal=840, kAzure =860, kViolet =880, kPink=900}; comp += ",*DstarSigFakeDT*"; // Cat 3 plot_pdfComp3 = pdf->plotOn(xframe,LineColor(kMagenta),ProjWData(projDataDeps,*projData),Components(comp)); //comp += ",selDstarSigFakeD4udsT*"; // Cat 5 //plot_pdfComp4 = pdf->plotOn(xframe,LineColor(kBlack),ProjWData(projDataDeps,*projData),Components(comp)); comp += ",*DstarSigFakeDKsKsT*"; // Cat 6 plot_pdfComp5 = pdf->plotOn(xframe,LineColor(kRed),ProjWData(projDataDeps,*projData),Components(comp)); comp += ",*DstarSigGoodDT*,*DstarSigGoodDRST*,*DstarSigGoodDWST*"; // Cat 1 plot_pdfComp6 = pdf->plotOn(xframe,LineColor(kBlue),ProjWData(projDataDeps,*projData),Components(comp)); } } //cout << plot_data << " " << plot_pdf << " " << plot_pdfComp1 << " " << plot_pdfComp2 << " " << plot_pdfComp3 << " " << plot_pdfComp4 << " " << // plot_pdfComp5 << " " << plot_pdfComp6 << endl; c1 = makePlotAndResid(plot_data,plot_pdf,plot_pdfComp1,plot_pdfComp2,plot_pdfComp3,plot_pdfComp4,plot_pdfComp5,plot_pdfComp6,0.2,logScale,!nice); } else c1 = makePlot(plot_data,0.2,logScale); /* if (nice) { TAxis *xaxis = xframe->GetXaxis(); xaxis->SetNdivisions(605); TAxis *yaxis = xframe->GetYaxis(); yaxis->SetNdivisions(5); xframe->SetTitleOffset(1.2,"X"); //define the frame xframe->SetTitleOffset(1.2,"Y");//for babar style } xframe->Draw(); if (nice) { BABARSmartLabel(0.40,0.92,1,"preliminary"); BABARSmartLabel(0.23,0.86,1,"a)",0.8,"R",kFALSE); } */ // make ps if (get_mpi_rank()==0) { TString file(file_root); file.Append(varName); c1->Print(file+".eps"); //c1->Print(file+".gif"); } // Write the canvas into the file with the appropriate name. if (get_mpi_rank()==0) { std::string rootPlotsFile = (const char*) file_root; // Get the B and D modes from the root file name. std::size_t endDmode = rootPlotsFile.rfind( "_" ); std::size_t iniDmode = rootPlotsFile.rfind( "_", endDmode - 1 ); std::size_t iniBmode = rootPlotsFile.rfind( "_", iniDmode - 1 ); std::string Dmode = rootPlotsFile.substr( iniDmode + 1, endDmode - iniDmode - 1 ); std::string Bmode = rootPlotsFile.substr( iniBmode + 1, iniDmode - iniBmode - 1 ); // Strip the _Bmode_Dmode_ part of the file name, for the plots root file. rootPlotsFile = rootPlotsFile.substr( 0, iniBmode ); // Add the plots extension to the plots root file. rootPlotsFile += ".plots.root"; TFile plotsFile( rootPlotsFile.c_str(), "update" ); std::string plotName = std::string( Bmode + "_" + Dmode + "_" + varName ); c1->Write( plotName.c_str() ); // Save the histogram to the file. plotsFile.Close(); } //getchar(); delete c1; } // general tool to make PDF shape plots with residuals //TCanvas* RooDKFitMaster::makePlotAndResid(RooPlot* dataPlot, RooPlot* pdfPlot, RooAbsPdf* pdf, RooPlot* pdfPlotComp1, RooPlot* pdfPlotComp2, RooPlot* pdfPlotComp3, // RooPlot* pdfPlotComp4, RooPlot* pdfPlotComp5, RooPlot* pdfPlotComp6, Float_t r, Bool_t logScale, Bool_t doResid) TCanvas* RooDKFitMaster::makePlotAndResid(RooPlot* dataPlot, RooPlot* pdfPlot, RooPlot* pdfPlotComp1, RooPlot* pdfPlotComp2, RooPlot* pdfPlotComp3, RooPlot* pdfPlotComp4, RooPlot* pdfPlotComp5, RooPlot* pdfPlotComp6, Float_t r, Bool_t logScale, Bool_t doResid) { // canvas division and scaling factors // Float_t s1 = 1./(1-r); Float_t sr = 1./r; // global options // gStyle->SetPadBorderMode(0); gStyle->SetFrameBorderMode(0); Float_t small = 0; TString cs("cPlotAndResid"); TCanvas* c1 = new TCanvas(cs); c1 -> SetFillColor(10); c1 -> SetTitle(""); c1 -> SetBottomMargin(0.2); // divide the canvas // if (doResid && pdfPlot) c1->Divide(1, 2, 0.1, 0.1); // get the TPad pointers // TPad *p1(0),*p2(0); if (doResid && pdfPlot) { p1 = (TPad*)c1->FindObject(cs+"_1"); p2 = (TPad*)c1->FindObject(cs+"_2"); } // modify the TPad sizes // if (doResid && pdfPlot) { p1->SetPad(0, r, 1.,1.); p2->SetPad(0, 0, 1.,r); p2->SetBottomMargin(0.25); p1->SetBottomMargin(small); p2->SetTopMargin(small); } // get the histogram properties // TAxis* x1 = dataPlot->GetXaxis(); TAxis* x2 = pdfPlot? pdfPlot->GetXaxis() : dataPlot->GetXaxis(); Int_t n1 = x1->GetNbins(); Int_t n2 = x2->GetNbins(); Float_t x1min = x1->GetXmin(); Float_t x1max = x1->GetXmax(); Float_t x2min = x2->GetXmin(); Float_t x2max = x2->GetXmax(); // check for compatibility // Int_t compatible = (n1 == n2 && x1min==x2min && x1max==x2max); if (compatible == 0) return c1; // draw the data histogram // if (doResid && pdfPlot) p1->cd(); if(logScale) { gPad->SetLogy(1); gPad->Modified(); } dataPlot->Draw(); // scale the data histogram graphics to preserve original font size // // It is assumed that the axis divisions, etc. have been defined externally // x1->SetTickLength(x1->GetTickLength()*s1); TAxis* y1 = dataPlot->GetYaxis(); y1->SetLabelSize(y1->GetLabelSize()*s1); TH1F* pullHist = (doResid && pdfPlot)? new TH1F("r","residual", n1, x1min, x1max) : 0; // draw the pdf Histogram if (pdfPlot) { pdfPlot->SetLineWidth(3); //pdfPlot->SetLineColor(kBlue); pdfPlot->Draw("SAME C"); // draw the pdf componnent Histograms if (pdfPlotComp1) pdfPlotComp1->Draw("SAME C"); if (pdfPlotComp2) pdfPlotComp2->Draw("SAME C"); if (pdfPlotComp3) pdfPlotComp3->Draw("SAME C"); if (pdfPlotComp4) pdfPlotComp4->Draw("SAME C"); if (pdfPlotComp5) pdfPlotComp5->Draw("SAME C"); if (pdfPlotComp6) pdfPlotComp6->Draw("SAME C"); } // define the poisson residual histogram if (doResid && pdfPlot) { //cout << endl << endl << dataPlot->nameOf(0) << " " << dataPlot->nameOf(1) << endl; //cout << pdfPlot->nameOf(0) << " " << pdfPlot->nameOf(1) << endl << endl; RooHist* obj_hist = (RooHist*)pdfPlot->getObject(0); // this is the data histogram RooCurve* obj_pdf = (RooCurve*)pdfPlot->getObject(1); // this is the fit curve //cout << obj_hist << " " << obj_pdf << endl; assert(obj_hist!=0 && obj_pdf!=0); // /* RooArgSet* deps = pdf->getDependents(_gFit->_selDataVars); RooArgSet* nset = pdf->getDependents(_gFit->_selDataVars); //nset->Print("v"); RooRealVar* plotVar = (RooRealVar*)nset->find(dataPlot->getPlotVar()->GetName()); nset->remove(*plotVar); // set of dependents to integrate //cout << "After removal: " << endl; nset->Print("v"); */ //TH1F* pullHist = new TH1F("r","residual", n1, x1min, x1max); Double_t chi2tot(0.),chitot(0.); Int_t dofs(0); Double_t x,y; Double_t y_tot(0); /* for (int i = 0; i < n1; ++i) { obj_hist->GetPoint(i,x,y); y_tot += y; } */ for (int i = 0; i < n1; ++i) { obj_hist->GetPoint(i,x,y); Double_t bin_width = obj_hist->getNominalBinWidth(); //Double_t y_pdf = obj_pdf->Eval(x,0,""); // value at bin center //Double_t y_pdf = obj_pdf->interpolate(x); // indentical to the above Double_t y_pdf = obj_pdf->average(x-0.5*bin_width,x+0.5*bin_width); // average over bin //Double_t y_pdf(0.); //Int_t pts(1000); //for (Int_t j=0;jEval(x-0.5*bin_width+bin_width/pts*j,0,""); //y_pdf /= pts; //cout << obj_pdf->Eval(x,0,"") << " " << obj_pdf->interpolate(x) << " " << obj_pdf->average(x-0.5*bin_width,x+0.5*bin_width) << " " // << obj_pdf->Eval(x-0.4*bin_width,0,"") << " " << obj_pdf->Eval(x+0.4*bin_width,0,"") << " " << y_pdf << endl; Double_t res = y_pdf - y; //Double_t res = obj_pdf->Eval(x,0,"") - y; // value at bin center /* plotVar->setVal(x); //cout << "deps : " << endl; deps->Print("v"); //cout << "nset : " << endl; nset->Print("v"); //RooRealIntegral integral_deps("integral_deps","integral_deps",*pdf,*deps,deps); //RooRealIntegral integral_nset("integral_nset","integral_nset",*pdf,*nset,deps); //cout << integral_deps.getVal() << " " << integral_nset.getVal() << endl; //cout << "x = " << x << " pdf = " << pdf->getVal(nset)*bin_width*y_tot << " y = " << y << " y_pdf = " << y_pdf << endl; //cout << "x = " << x << " pdf = " << pdf->getVal(deps)*bin_width*y_tot << " y = " << y << " y_pdf = " << y_pdf << endl; Int_t pts(1000); plotVar->setVal(x-0.5*bin_width); Double_t y_pdf2 = pdf->getVal(deps); for (Int_t j=1;jsetVal(x-0.5*bin_width+bin_width/pts*j); y_pdf2 += 2*pdf->getVal(deps); } plotVar->setVal(x+0.5*bin_width); y_pdf2 += pdf->getVal(deps); y_pdf2 *= 0.5*bin_width/(pts+1)*y_tot; cout << "x = " << x << " y_pdf2 = " << y_pdf2 << " y = " << y << " y_pdf = " << y_pdf << endl; */ // errors Double_t eyHi = obj_hist->GetErrorYhigh(i); Double_t eyLo = obj_hist->GetErrorYlow(i); Double_t ey = (res>0) ? eyHi : eyLo ; Double_t chi(0),chi2(0); /* if (ey>0.) { chi = res/ey; chi2 = chi*chi; dofs++; chi2tot += chi2; chitot += chi; } */ if (y>0. && y_pdf>0.) { chi2 = 2.*(y_pdf - y) + 2.*y*log(y/y_pdf); // Poisson chi2 (S.Baker, R.D.Cousins, NIM 221 (1984) 437-442 //chi2 = 2.*y*log(y/y_pdf); // Multinomial chi2 chi2 += 1.e-10; //to solve numerical inconsistencies assert(chi2>=0.); chi = (y>=y_pdf)? sqrt(chi2) : -sqrt(chi2); // Signed chi, as in BAD1291, page 17-18 //chi = sqrt(chi2); // Unsigned chi dofs++; chi2tot += chi2; chitot += chi; } //cout << i << " x = " << x << " y = " << y << " eyHi = " << eyHi << " eyLo = " << eyLo << " y_pdf = " << y_pdf << " chi = " << chi << endl; pullHist->SetBinContent(i+1, chi); pullHist->SetBinError(i+1, 1.0); } /* delete deps; delete nset; */ if (get_mpi_rank()==0) cout << "Total chi2 for histogram " << obj_hist->GetName() << " = " << chi2tot << " for ndof = " << dofs << ". Reduced total chi2 = "; if (get_mpi_rank()==0) if (dofs>0) cout << chi2tot/dofs << endl; else cout << 0. << endl; //cout << "Total chi for histogram " << obj_hist->GetName() << " = " << chitot << " for ndof = " << dofs << ". Reduced total chi = "; //if (dofs>0) cout << chitot/dofs << endl; else cout << 0. << endl; } if (doResid && pdfPlot) { TAxis* xr = pullHist->GetXaxis(); // on the residual histogram, scale the axis labels, xaxis tick marks, axis divisions // and title // xr->SetTickLength(xr->GetTickLength()*sr); xr->SetLabelSize(xr->GetLabelSize()*sr); xr->SetTitleSize(xr->GetTitleSize()*sr); xr->SetLabelOffset(xr->GetLabelOffset()*sr); xr->SetTitle(x1->GetTitle()); xr->CenterTitle(); pullHist->SetMinimum(-5); pullHist->SetMaximum(+5); TAxis* yr = pullHist->GetYaxis(); yr->SetNdivisions(504); yr->SetLabelSize(yr->GetLabelSize()*sr); pullHist->SetMarkerStyle(20); pullHist->SetTitle(""); pullHist->SetStats(0); // go to the residual histogram pad and plot it // p2->cd(); pullHist->Draw(); TLine* centerLine = new TLine(x1min, 0, x1max, 0); centerLine->Draw("SAME"); TLine* m2SigLine = new TLine(x1min, -2, x1max, -2); m2SigLine->SetLineColor(kRed); m2SigLine->Draw("SAME"); TLine* p2SigLine = new TLine(x1min, +2, x1max, +2); p2SigLine->SetLineColor(kRed); p2SigLine->Draw("SAME"); } return c1; } // making Dalitz plots void RooDKFitMaster::makeDalitzPlots(TString BMode, TString DMode, Int_t charge, TString opt, const char* epsfile_root, Bool_t kToyMc, Int_t nbins, Int_t nevtsToyMc, char* epsfile_suffix, TString bkgCompOpt, TString slice_cut, Bool_t nice, Double_t epsRel, Bool_t plotPdf, Bool_t logScale, const char* logFileChi2Plots, const char* logFileChi2AdaptivePlots, Int_t nbinsIntegralChi2, Int_t nentriesChi2AdaptiveThr) { // nbinsIntegralChi2 ensures a nbinsIntegralChi2xnbinsIntegralChi2 binning for the evaluation of chi2 integral (full DP range) // opt="Dalitz","DalitzChi2","DalitzChi2Adaptive","DalitzOther","Other" assert(opt=="Dalitz" || opt=="DalitzChi2" || opt=="DalitzChi2Adaptive" || opt=="DalitzOther" || opt=="Other"); // DMode exists? if (!_gFit->_DdecayMode->isValidLabel(DMode)) return; // charge = -1, +1, 0 (for both, -1 and +1) assert (charge==-1 || charge==+1 || charge==0); //gROOT->SetStyle("BABAR"); // define stat option gStyle->SetOptStat(0); // define palette for normalized residuals /* Int_t* colors = new Int_t[20]; colors[0]=100+28; colors[1]=102; colors[2]=103; colors[3]=104; colors[4]=105; colors[5]=106; colors[6]=107; colors[7]=108; colors[8]=109; colors[9]=100+11; colors[10]=150+11; colors[11]=159; colors[12]=158; colors[13]=157; colors[14]=156; colors[15]=155; colors[16]=154; colors[17]=153; colors[18]=152; colors[19]=150+28; */ Int_t colors[]={100+28,102,103,104,105,106,107,108,109,100+11,150+11,159,158,157,156,155,154,153,152,150+28}; Int_t colors_bw[]={10,19,18,17,16,15,14,13,12,1}; // bw palette // set decay modes _gFit->_DdecayMode->setLabel(DMode); _gFit->_DdecayModeLF->setIndex(_gFit->_DdecayMode->getIndex()); _gFit->_BdecayMode->setLabel(BMode); _gFit->_BdecayModeLF->setIndex(_gFit->_BdecayMode->getIndex()); // root plots file name. std::string rootPlotsFile = epsfile_root; rootPlotsFile += ".plots.root"; // eps root file name TString file_root; if (epsfile_root) { file_root.Append(epsfile_root); file_root.Append("_"); } file_root.Append(BMode); file_root.Append("_"); file_root.Append(DMode); file_root.Append("_"); // pdf component name TString pdfComp("{"); pdfComp.Append(DMode); pdfComp.Append(";"); pdfComp.Append(BMode); pdfComp.Append("}"); if (get_mpi_rank()==0) cout << "RooDKFitMaster::makeDalitzPlots: Pdf component: " << pdfComp << endl; // get PDF RooAbsPdf* pdf = (_pdfGlobal)? (RooAbsPdf*)_pdfGlobal->getPdf(pdfComp) : 0; if (pdf==0) return; // define precision numerical integral for plotting if (pdf) { RooNumIntConfig* intConfig = (RooNumIntConfig*)pdf->getIntegratorConfig(); if (get_mpi_rank()==0) cout << "RooDKFitMaster::makeDalitzPlots(): Original RooNumIntConfig precision: epsRel = " << intConfig->epsRel() << " , epsAbs = " << intConfig->epsAbs() << endl; intConfig->setEpsRel(epsRel); intConfig->setEpsAbs(epsRel); if (get_mpi_rank()==0) cout << "RooDKFitMaster::makeDalitzPlots(): New RooNumIntConfig precision: epsRel = " << intConfig->epsRel() << " , epsAbs = " << intConfig->epsAbs() << endl; } // get dependents and set limits for DeltaE RooArgSet* deps(0); RooRealVar *mD(0),*deltam(0),*mES(0),*fisher(0),*deltaE(0),*tReco(0),*tTrue(0),*tErr(0); if (pdf) { deps = pdf->getDependents(_gFit->_selDataVars); mD = (RooRealVar*)deps->find("mD"); if (mD) mD->setRange(_mDMin->getVal(),_mDMax->getVal()); deltam = (RooRealVar*)deps->find("deltam"); if (deltam) deltam->setRange(_deltamMin->getVal(),_deltamMax->getVal()); mES = (RooRealVar*)deps->find("mES"); fisher = (RooRealVar*)deps->find("fisher"); deltaE = (RooRealVar*)deps->find("deltaE_dk"); if (deltaE) deltaE->setRange(_deltaEMin_dk->getVal(),_deltaEMax_dk->getVal()); else { deltaE = (RooRealVar*)deps->find("deltaE_dpi"); if (deltaE) deltaE->setRange(_deltaEMin_dpi->getVal(),_deltaEMax_dpi->getVal()); } if (deltaE) if (get_mpi_rank()==0) cout << deltaE->GetName() << " range: [" << deltaE->getMin() << "," << deltaE->getMax() << "]" << endl; if (mES) if (get_mpi_rank()==0) cout << mES->GetName() << " range: [" << mES->getMin() << "," << mES->getMax() << "]" << endl; tReco = (RooRealVar*)deps->find("tReco"); tTrue = (RooRealVar*)deps->find("tTrue"); tErr = (RooRealVar*)deps->find("tErr"); assert( (tTrue && !tReco) || (!tTrue && tReco) || (!tTrue && !tReco) ); } // projection cut TString cutProj("(BdecayMode==BdecayMode::"); cutProj.Append(BMode); cutProj.Append(")&&(DdecayMode==DdecayMode::"); cutProj.Append(DMode); cutProj.Append(")"); if (charge!=0) { cutProj.Append("&&(recState==recState::"); if (BMode=="Dstar") { if (charge==-1) cutProj.Append("Bplus)"); else cutProj.Append("Bminus)"); } else { if (charge==-1) cutProj.Append("Bminus)"); else cutProj.Append("Bplus)"); } } if (deltaE) { cutProj.Append("&&("); cutProj.Append(deltaE->GetName()); cutProj.Append("<="); char* buffer = new char[30]; //sprintf(buffer,"%.2e",deltaE->getMax()); sprintf(buffer,"%e",deltaE->getMax()); cutProj.Append(buffer); cutProj.Append(")&&("); cutProj.Append(deltaE->GetName()); cutProj.Append(">="); sprintf(buffer,"%e",deltaE->getMin()); cutProj.Append(buffer); cutProj.Append(")"); delete buffer; } if (get_mpi_rank()==0) cout << "RooDKFitMaster::makeDalitzPlots: Data projection cut: " << cutProj << endl; // get projected data set RooDataSet* data(0); if (kToyMc) data = (RooDataSet*)_fitDataToyMc->reduce(cutProj); else data = (RooDataSet*)_fitData->reduce(cutProj); //cout << pdf << " " << data << endl; assert(0); //cout << _fitDataToyMc->numEntries() << " " << data->numEntries() << endl; assert(0); if (data==0 || (data&&data->numEntries()==0)) { if (deps) delete deps; return; } //if (kToyMc) {_fitDataToyMc->Print("v"); _fitDataToyMc->write("results/fitDataToyMc.dat");} //else {_fitData->Print("v"); _fitData->write("results/fitData.dat");} //assert(0); // keep pointers to original qAB, qAC, qBC, etc RooRealVar* qAC = _gFit->_qAC; RooRealVar* qAB = _gFit->_qAB; RooRealVar* qBC = _gFit->_qBC; RooRealVar* deltaE_dk = _deltaE_dk; RooRealVar* deltaEshift = _gFit->_deltaEshift; RooCategory* recState = _gFit->_recState; //pdf->getDependents(_gFit->_selDataVars)->Print("v"); assert(0); // define pairs and pointers to independent variables //deps->Print("v"); RooRealVar *qPair1(0),*qPair2(0),*qPair3(0); EvtCyclic3::Pair pair1,pair2,pair3; RooRealVar* var = (RooRealVar*)deps->find(qAC->GetName()); if (var) { qPair1 = qAC; pair1 = EvtCyclic3::AC; } else { qPair3 = qAC; pair3 = EvtCyclic3::AC; } var = (RooRealVar*)deps->find(qAB->GetName()); if (var) { if (qPair1) { qPair2 = qAB; pair2 = EvtCyclic3::AB; } else { qPair1 = qAB; pair1 = EvtCyclic3::AB; } } else { qPair3 = qAB; pair3 = EvtCyclic3::AB; } var = (RooRealVar*)deps->find(qBC->GetName()); if (var) { if (qPair1) { if (qPair2) { qPair3 = qBC; pair3 = EvtCyclic3::BC; } else { qPair2 = qBC; pair2 = EvtCyclic3::BC; } } else { qPair1 = qBC; pair1 = EvtCyclic3::BC; } } else { qPair3 = qBC; pair3 = EvtCyclic3::BC; } // If the Dalitz is not defined in the model, make sure there will be no attempts to plot it. Bool_t skipDalitzPlots = (qPair1 == 0) || (qPair2 == 0) || (qPair3 == 0); if (!skipDalitzPlots) { assert( (qPair1 != 0) && (qPair2 != 0) && (qPair3 != 0) ); assert(qPair1 != qPair2); assert(qPair1 != qPair3); assert(qPair2 != qPair3); } if (!skipDalitzPlots) { if (get_mpi_rank()==0) cout << " Pair 1: " << pair1 << " " << qPair1->GetName() << " Pair 2: " << pair2 << " " << qPair2->GetName() << " Pair 3: " << pair3 << " " << qPair3->GetName() << endl; if (nice) { qAC->setUnit("GeV^{2}/c^{4}"); qAB->setUnit("GeV^{2}/c^{4}"); qBC->setUnit("GeV^{2}/c^{4}"); if (DMode=="KsPiPi") { //qAC->SetTitle("m_{-}^{2}"); //qAB->SetTitle("m_{+}^{2}"); //qBC->SetTitle("m_{0}^{2}"); qAC->SetTitle("s_{-}"); qAB->SetTitle("s_{+}"); qBC->SetTitle("s_{0}"); } else if (DMode=="KsKK") { //qAC->SetTitle("m_{+}^{2}"); //qAB->SetTitle("m_{0}^{2}"); //qBC->SetTitle("m_{-}^{2}"); qAC->SetTitle("s_{+}"); qAB->SetTitle("s_{0}"); qBC->SetTitle("s_{-}"); } else assert(0); } } // build Dalitz plot EvtDalitzPlot dp(EvtDecayMode(_gFit->_DdecayModeLF->getLabel())); RooFormulaVar* qPair3_func(0); RooFormulaVar* qPair2_func(0); RooFormulaVar* qPair1_func(0); Double_t qPair1min(0.); Double_t qPair1max(0.); Double_t qPair2min(0.); Double_t qPair2max(0.); Double_t qPair3min(0.); Double_t qPair3max(0.); RooRealVar dpSum("dpSum","dpSum",dp.sum()); if (!skipDalitzPlots) { if (get_mpi_rank()==0) cout << "Making EvtDalitzPlot for decay mode : " << _gFit->_DdecayModeLF->getLabel() << endl; // define qPair3, qPair2, qPair1 functions //cout << dpSum.getVal() << endl; assert(0); qPair3_func = new RooFormulaVar(qPair3->GetName(),qPair3->GetTitle(),"@0-@1-@2",RooArgList(dpSum,*qPair1,*qPair2)); qPair2_func = new RooFormulaVar(qPair2->GetName(),qPair2->GetTitle(),"@0-@1-@2",RooArgList(dpSum,*qPair1,*qPair3)); qPair1_func = new RooFormulaVar(qPair1->GetName(),qPair1->GetTitle(),"@0-@1-@2",RooArgList(dpSum,*qPair2,*qPair3)); // define Dalitz plot limits qPair1min=dp.qAbsMin(pair1); qPair1max=dp.qAbsMax(pair1); qPair2min=dp.qAbsMin(pair2); qPair2max=dp.qAbsMax(pair2); qPair3min=dp.qAbsMin(pair3); qPair3max=dp.qAbsMax(pair3); /* assert(dp.bigM()>=_mDMin->getVal() && dp.bigM()<=_mDMax->getVal()); for (Int_t i=0;i<=1;i++) { EvtDalitzPlot dp_running(dp.mA(),dp.mB(),dp.mB(), (i==0)? _mDMin->getVal() : _mDMax->getVal() ); //dp_running.print(); if (dp_running.qAbsMin(pair1)qPair1max) qPair1max = dp_running.qAbsMax(pair1); if (dp_running.qAbsMin(pair2)qPair2max) qPair2max = dp_running.qAbsMax(pair2); if (dp_running.qAbsMin(pair3)qPair3max) qPair3max = dp_running.qAbsMax(pair3); } */ /* std::vector& lineShape = _DmassLineShape[getIndexCat(DMode)]; if (lineShape.size()>0) { for (Int_t i=0;iqPair1max) qPair1max = dp_running.qAbsMax(pair1); if (dp_running.qAbsMin(pair2)qPair2max) qPair2max = dp_running.qAbsMax(pair2); if (dp_running.qAbsMin(pair3)qPair3max) qPair3max = dp_running.qAbsMax(pair3); } } */ if (nice) { TString name(qPair1->GetName()); if (DMode=="KsPiPi") { if (name=="qBC") {qPair1min=0.0; qPair1max=2.0;} else {qPair1min=0.3; qPair1max=3.1;} name=qPair2->GetName(); if (name=="qBC") {qPair2min=0.0; qPair2max=2.0;} else {qPair2min=0.3; qPair2max=3.1;} name=qPair3->GetName(); if (name=="qBC") {qPair3min=0.0; qPair3max=2.0;} else {qPair3min=0.3; qPair3max=3.1;} } else if (DMode=="KsKK") { qPair1min=0.94; qPair1max=1.9; qPair2min=0.94; qPair2max=1.9; qPair3min=0.94; qPair3max=1.9; } } qPair1->setRange(qPair1min,qPair1max); qPair1->setBins(nbins); qPair2->setRange(qPair2min,qPair2max); qPair2->setBins(nbins); qPair3->setRange(qPair3min,qPair3max); qPair3->setBins(nbins); //qPair1->setRange(0.4,1.1); //qPair1->setBins(nbins); //qPair2->setRange(1.,3.); //qPair2->setBins(nbins); //qPair3->setRange(0.5,0.7); //qPair3->setBins(nbins); } if (tReco) tReco->setBins(nbins); if (tTrue) tTrue->setBins(nbins); if (tErr) tErr->setBins(nbins); // define boundary 2D Dalitz plot (assuming PDG mass for the mother, i.e. no lineshape) RooArgList data_common_vars; RooRealVar* q12(0); RooRealVar* q13(0); RooRealVar* q23(0); TGraph *grboundMax(0),*grboundMin(0); RooFormulaVar* q12_func(0); RooFormulaVar* q13_func(0); RooFormulaVar* q23_func(0); if (!skipDalitzPlots) { Int_t nbinsbound(10000); Double_t x[nbinsbound+1], ymin[nbinsbound+1], ymax[nbinsbound+1] ; for (Int_t i=0;i<=nbinsbound;i++) { Double_t qpair1 = (i/Double_t(nbinsbound))*(dp.qAbsMax(pair1)-dp.qAbsMin(pair1)) + dp.qAbsMin(pair1); if (i==0) qpair1 += 1e-15; if (i==nbinsbound) qpair1 -= 1e-15; x[i]=qpair1; ymin[i]=dp.qMin(pair2,pair1,qpair1) ; ymax[i]=dp.qMax(pair2,pair1,qpair1) ; } grboundMax = new TGraph(nbinsbound+1,x,ymax); grboundMin = new TGraph(nbinsbound+1,x,ymin); grboundMax->SetLineColor(kRed); grboundMin->SetLineColor(kRed); // create common B+/B- dataset (same ordering of particles for charge=0) // for D0-> K_S0 pi+ pi-: AC=Ks pi- AB=Ks pi+ BC=pi+ pi- // for D0-> K+ K- K_S0 : AC=Ks K+ AB=K+ K- BC=Ks K- RooArgList listarg(*_gFit->_DdecayMode,*recState); listarg.add(RooArgList(*qAC,*qAB,*qBC)); // TString formula12; if (BMode!="Dstar") { //if (charge==0) formula12="(@0==1)*((@1==-1)*@3+(@1==+1)*@2) + (@0==2)*((@1==-1)*@2+(@1==+1)*@4)"; // 12=AC(AC) B-, AB(BC) B+, Kspipi(KsKK) if (charge==0) formula12="(@0==1)*((@1==-1)*@2+(@1==+1)*@3) + (@0==2)*((@1==-1)*@2+(@1==+1)*@4)"; // 12=AC(AC) B-, AB(BC) B+, Kspipi(KsKK) else formula12="(@0==1)*((@1==-1)*@2+(@1==+1)*@3) + (@0==2)*((@1==-1)*@2+(@1==+1)*@2)"; // 12=AC(AC) B-, AB(AC) B+, Kspipi(KsKK) } else { if (charge==0) formula12="(@0==1)*((@1==+1)*@2+(@1==-1)*@3) + (@0==2)*((@1==+1)*@2+(@1==-1)*@4)"; // 12=AC(AC) D*+, AB(BC) D*-, Kspipi(KsKK) else formula12="(@0==1)*((@1==+1)*@2+(@1==-1)*@3) + (@0==2)*((@1==+1)*@2+(@1==-1)*@2)"; // 12=AC(AC) D*+, AB(AC) D*-, Kspipi(KsKK) } q12_func = new RooFormulaVar("q12","Invariant mass square of pair 12",formula12,listarg); // TString formula13; if (BMode!="Dstar") { //if (charge==0) formula13="(@0==1)*((@1==-1)*@2+(@1==+1)*@3) + (@0==2)*((@1==-1)*@3+(@1==+1)*@3)"; // 13=AB(AB) B-, AC(AB) B+, Kspipi(KsKK) if (charge==0) formula13="(@0==1)*((@1==-1)*@3+(@1==+1)*@2) + (@0==2)*((@1==-1)*@3+(@1==+1)*@3)"; // 13=AB(AB) B-, AC(AB) B+, Kspipi(KsKK) else formula13="(@0==1)*((@1==-1)*@3+(@1==+1)*@2) + (@0==2)*((@1==-1)*@3+(@1==+1)*@3)"; // 13=AB(AB) B-, AC(AB) B+, Kspipi(KsKK) } else { if (charge==0) formula13="(@0==1)*((@1==+1)*@3+(@1==-1)*@2) + (@0==2)*((@1==+1)*@3+(@1==-1)*@3)"; // 13=AB(AB) D*+, AC(AB) D*-, Kspipi(KsKK) else formula13="(@0==1)*((@1==+1)*@3+(@1==-1)*@2) + (@0==2)*((@1==+1)*@3+(@1==-1)*@3)"; // 13=AB(AB) D*+, AC(AB) D*-, Kspipi(KsKK) } q13_func = new RooFormulaVar("q13","Invariant mass square of pair 13",formula13,listarg); // TString formula23; if (BMode!="Dstar") { if (charge==0) formula23="(@0==1)*((@1==-1)*@4+(@1==+1)*@4) + (@0==2)*((@1==-1)*@4+(@1==+1)*@2)"; // 23=BC(BC) B-, BC(AC) B+, Kspipi(KsKK) else formula23="(@0==1)*((@1==-1)*@4+(@1==+1)*@4) + (@0==2)*((@1==-1)*@4+(@1==+1)*@4)"; // 23=BC(BC) B-, BC(BC) B+, Kspipi(KsKK) } else { if (charge==0) formula23="(@0==1)*((@1==+1)*@4+(@1==-1)*@4) + (@0==2)*((@1==+1)*@4+(@1==-1)*@2)"; // 23=BC(BC) D*+, BC(AC) D*-, Kspipi(KsKK) else formula23="(@0==1)*((@1==+1)*@4+(@1==-1)*@4) + (@0==2)*((@1==+1)*@4+(@1==-1)*@4)"; // 23=BC(BC) D*+, BC(BC) D*-, Kspipi(KsKK) } q23_func = new RooFormulaVar("q23","Invariant mass square of pair 23",formula23,listarg); // q12 = (RooRealVar*)q12_func->createFundamental(); q13 = (RooRealVar*)q13_func->createFundamental(); q23 = (RooRealVar*)q23_func->createFundamental(); (RooRealVar*) data->addColumn(*q12_func) ; (RooRealVar*) data->addColumn(*q13_func) ; (RooRealVar*) data->addColumn(*q23_func) ; data_common_vars.add(RooArgList(*qAC,*qAB,*qBC)); } if (BMode=="Dstar") { if (deps->find(_gFit->_mD->GetName())) data_common_vars.add(*mD); if (deps->find(_gFit->_deltam->GetName())) data_common_vars.add(*deltam); if (deps->find(_gFit->_tReco->GetName())) data_common_vars.add(*tReco); if (deps->find(_gFit->_tTrue->GetName())) data_common_vars.add(*tTrue); if (deps->find(_gFit->_tErr->GetName())) data_common_vars.add(*tErr); } else { if (deps->find(_gFit->_mES->GetName())) data_common_vars.add(*mES); if (deps->find(deltaE_dk->GetName())) data_common_vars.add(*deltaE_dk); if (deps->find(_gFit->_fisher->GetName())) data_common_vars.add(*fisher); if (deps->find(deltaEshift->GetName())) data_common_vars.add(*deltaEshift); } //Bool_t recStateUseTmp(kTRUE); Bool_t recStateUseTmp = nevtsToyMc>0; if (slice_cut!="" || nevtsToyMc>0 || recStateUseTmp) data_common_vars.add(*recState); RooDataSet* data_common = new RooDataSet("data_common","data_common",data_common_vars); // for (Int_t iEvt=0;iEvtnumEntries();iEvt++) { const RooArgSet* columns = data->get(iEvt); //columns->Print("v"); //assert(0); if (!skipDalitzPlots) { RooRealVar* q12_col = (RooRealVar*)columns->find(q12->GetName()); RooRealVar* q13_col = (RooRealVar*)columns->find(q13->GetName()); RooRealVar* q23_col = (RooRealVar*)columns->find(q23->GetName()); qAC->setVal(q12_col->getVal()); qAB->setVal(q13_col->getVal()); qBC->setVal(q23_col->getVal()); } if (slice_cut!="" || nevtsToyMc>0 || recStateUseTmp) { RooCategory* recState_col = (RooCategory*)columns->find(recState->GetName()); if (recState_col) { if (charge==0) recState->setIndex(recState_col->getIndex()); else { if (BMode=="Dstar") { if (charge==-1) recState->setIndex(+1); else recState->setIndex(-1); } else { if (charge==-1) recState->setIndex(-1); else recState->setIndex(+1); } } } } if (BMode=="Dstar") { RooRealVar* mD_col = (RooRealVar*)columns->find("mD"); RooRealVar* deltam_col = (RooRealVar*)columns->find("deltam"); RooRealVar* tReco_col = (RooRealVar*)columns->find("tReco"); RooRealVar* tTrue_col = (RooRealVar*)columns->find("tTrue"); RooRealVar* tErr_col = (RooRealVar*)columns->find("tErr"); if (mD_col && data_common_vars.find("mD")) mD->setVal(mD_col->getVal()); if (deltam_col && data_common_vars.find("deltam")) deltam->setVal(deltam_col->getVal()); if (tReco_col && data_common_vars.find("tReco")) tReco->setVal(tReco_col->getVal()); if (tTrue_col && data_common_vars.find("tTrue")) tTrue->setVal(tTrue_col->getVal()); if (tErr_col && data_common_vars.find("tErr")) tErr->setVal(tErr_col->getVal()); } else { RooRealVar* mES_col = (RooRealVar*)columns->find("mES"); RooRealVar* fisher_col = (RooRealVar*)columns->find("fisher"); RooRealVar* deltaE_dk_col = (RooRealVar*)columns->find("deltaE_dk"); RooRealVar* deltaEshift_col = (RooRealVar*)columns->find("deltaEshift"); if (mES_col && data_common_vars.find("mES")) mES->setVal(mES_col->getVal()); if (fisher_col && data_common_vars.find("fisher")) fisher->setVal(fisher_col->getVal()); if (deltaE_dk_col && data_common_vars.find("deltaE_dk")) deltaE_dk->setVal(deltaE_dk_col->getVal()); if (deltaEshift_col && data_common_vars.find("deltaEshift")) deltaEshift->setVal(deltaEshift_col->getVal()); } data_common->add(data_common_vars); } //data_common->Print("v"); data_common->write("results/data_common.dat"); assert(0); // projections /* RooArgSet projDataDeps; RooAbsData* projData(0); //if (TString(_deltaEDhOption->getLabel())=="deltaEshift") projDataDeps.add(*_gFit->_deltaEshift); // project over deltaEshift // To be precise, we must ProjWData for deltaEshift. However, the pdf for DK samples does not depend on _deltaEshift, so // it is not really needed. Moreover, ProjWData for deltaEshift takes infinite time (too many dimensions)... // For DPi samples maybe needed, but I suspect the effect is small (signal box in DeltaE...), but I haven't check... projData = data_common; // unbinned since too many dependents RooArgSet data_common_vars_excludeProjDataDeps(data_common_vars); data_common_vars_excludeProjDataDeps.remove(projDataDeps); */ RooArgSet projDataDeps; RooAbsData* projData(0); RooArgSet pdf_deps(*pdf->getDependents(_gFit->_selDataVars)); if (TString(_deltaEDhOption->getLabel())=="deltaEshift") projDataDeps.add(*_gFit->_deltaEshift); //if (TString(_resFcn->getLabel()).EndsWith("EventError") // && pdf_deps.find("tErr") && (pdf_deps.find("tReco") || pdf_deps.find("tTrue"))) projDataDeps.add(*_gFit->_tErr); // project over sigma_t assert( !(TString(_resFcn->getLabel()).EndsWith("GlobalError") && pdf_deps.find("tErr")) ); // with GlobalError the pdf cannot contain tErr if (pdf_deps.find("tErr")) projDataDeps.add(*_gFit->_tErr); // project over sigma_t for EventError and Truth if (slice_cut!="" || nevtsToyMc>0 || recStateUseTmp) projDataDeps.add(*_gFit->_recState); //projDataDeps.add(*_gFit->_DdecayMode); //projDataDeps.Print("v"); assert(0); RooArgSet projDataDeps_no_deltaEshift(projDataDeps); projDataDeps_no_deltaEshift.remove(*_gFit->_deltaEshift); projData = data_common; // unbinned since too many dependents RooDataHist projData_hist("projData_hist","projData_hist",projDataDeps,*data_common); RooDataHist projData_no_deltaEshift_hist("projData_hist","projData_hist",projDataDeps_no_deltaEshift,*data); RooArgSet data_common_vars_excludeProjDataDeps(data_common_vars); data_common_vars_excludeProjDataDeps.remove(projDataDeps); RooDataHist* tErrHist(0); RooHistPdf* tErrPdf(0); if (tErr && (TString(_resFcn->getLabel())!="Unknown") && (TString(_resFcn->getLabel())!="Truth")) { tErrHist = new RooDataHist("tErrHist","tErrHist",*_gFit->_tErr,*data_common); tErrPdf = new RooHistPdf("tErrPdf","tErrPdf",*_gFit->_tErr,*tErrHist); } //cout << tErrPdf << endl; deps->Print("v"); assert(0); // define recState value (for pdf projections) if (!(slice_cut!="" || nevtsToyMc>0 || recStateUseTmp)) { /* if (charge==0) { if (BMode=="Dstar") _gFit->_recState->setLabel("Bplus"); else _gFit->_recState->setLabel("Bminus"); } else { if (BMode=="Dstar") { if (charge==+1) _gFit->_recState->setLabel("Bplus"); else _gFit->_recState->setLabel("Bplus"); } else { if (charge==+1) _gFit->_recState->setLabel("Bminus"); else _gFit->_recState->setLabel("Bminus"); } } */ if (BMode=="Dstar") _gFit->_recState->setLabel("Bplus"); else _gFit->_recState->setLabel("Bminus"); } // pdf from toy mc RooDataSet* slice_data_common(0); RooDataSet* toymc_common(0); RooDataSet* slice_toymc_common(0); RooDataHist *qpair1_hist_slice_toymc_common(0); RooHistPdf *qpair1_pdf_slice_toymc_common(0); RooDataHist *qpair2_hist_slice_toymc_common(0); RooHistPdf *qpair2_pdf_slice_toymc_common(0); RooDataHist *qpair3_hist_slice_toymc_common(0); RooHistPdf *qpair3_pdf_slice_toymc_common(0); RooDataHist *time_hist_slice_toymc_common(0); RooHistPdf *time_pdf_slice_toymc_common(0); RooDataHist *tErr_hist_slice_toymc_common(0); RooHistPdf *tErr_pdf_slice_toymc_common(0); RooDataHist *mES_hist_slice_toymc_common(0); RooHistPdf *mES_pdf_slice_toymc_common(0); /* RooDataHist *fisher_hist_slice_toymc_common(0); RooHistPdf *fisher_pdf_slice_toymc_common(0); */ if (slice_cut!="" || nevtsToyMc>0) { slice_data_common = (slice_cut!="")? (RooDataSet*)data_common->reduce(slice_cut) : (RooDataSet*)data_common->Clone(); if (plotPdf) { //RooArgSet depsToGen(data_common_vars); RooArgSet depsToGen(data_common_vars_excludeProjDataDeps); if (!skipDalitzPlots) depsToGen.remove(*qPair3); RooArgSet depsProto(*_gFit->_BdecayMode,*_gFit->_DdecayMode); depsProto.add(*_gFit->_recState); // must be in the list. Actual value will be assigned inside generateComp() toymc_common = generateComp(pdf,depsProto,depsToGen,0,tErrPdf,charge,nevtsToyMc); if (!skipDalitzPlots) toymc_common->addColumn(*qPair3_func); //toymc_common->Print("v"); assert(0); //if (charge==0) { // create common toymc for charge=0 RooArgSet toymc_common_vars(*toymc_common->get(0)); TIterator* toymc_common_vars_iter = toymc_common_vars.createIterator(); RooDataSet* toymc_common_2 = new RooDataSet("toymc_common_2","toymc_common_2",toymc_common_vars); if (!skipDalitzPlots) { (RooRealVar*) toymc_common->addColumn(*q12_func) ; (RooRealVar*) toymc_common->addColumn(*q13_func) ; (RooRealVar*) toymc_common->addColumn(*q23_func) ; } for (Int_t i=0;inumEntries();i++) { RooArgSet* event = (RooArgSet*)toymc_common->get(i); RooRealVar *q12_event = q12_event = (RooRealVar*)event->find("q12"); RooRealVar *q13_event = q13_event = (RooRealVar*)event->find("q13"); RooRealVar *q23_event = q23_event = (RooRealVar*)event->find("q23"); toymc_common_vars_iter->Reset(); RooRealVar* item; while (item = (RooRealVar*)toymc_common_vars_iter->Next()) { TString name(item->GetName()); RooRealVar *item_event = (RooRealVar*)event->find(name); assert(item_event); //cout << name << " = " << endl; item->Print("v"); if (name=="qAC") item->setVal(q12_event->getVal()); else if (name=="qAB") item->setVal(q13_event->getVal()); else if (name=="qBC") item->setVal(q23_event->getVal()); } toymc_common_2->add(toymc_common_vars); } delete toymc_common_vars_iter; delete toymc_common; toymc_common = toymc_common_2; //} slice_toymc_common = (slice_cut!="")? (RooDataSet*)toymc_common->reduce(slice_cut) : (RooDataSet*)toymc_common->Clone(); //toymc_common->Print("v"); slice_toymc_common->Print("v"); slice_toymc_common->write("results/test.dat") ; //assert(0); // Print flat file for generated sample Int_t order(0); // interpolation order if (!skipDalitzPlots) { qpair1_hist_slice_toymc_common = new RooDataHist("qpair1_hist_slice_toymc_common","qpair1_hist_slice_toymc_common",*qPair1,*slice_toymc_common); qpair1_pdf_slice_toymc_common = new RooHistPdf("qpair1_pdf_slice_toymc_common","qpair1_pdf_slice_toymc_common",*qPair1,*qpair1_hist_slice_toymc_common,order); qpair2_hist_slice_toymc_common = new RooDataHist("qpair2_hist_slice_toymc_common","qpair2_hist_slice_toymc_common",*qPair2,*slice_toymc_common); qpair2_pdf_slice_toymc_common = new RooHistPdf("qpair2_pdf_slice_toymc_common","qpair2_pdf_slice_toymc_common",*qPair2,*qpair2_hist_slice_toymc_common,order); qpair3_hist_slice_toymc_common = new RooDataHist("qpair3_hist_slice_toymc_common","qpair3_hist_slice_toymc_common",*qPair3,*slice_toymc_common); qpair3_pdf_slice_toymc_common = new RooHistPdf("qpair3_pdf_slice_toymc_common","qpair3_pdf_slice_toymc_common",*qPair3,*qpair3_hist_slice_toymc_common,order); } if (tTrue || tReco) { time_hist_slice_toymc_common = new RooDataHist("time_hist_slice_toymc_common","time_hist_slice_toymc_common",tTrue? *tTrue : *tReco,*slice_toymc_common); time_pdf_slice_toymc_common = new RooHistPdf("time_pdf_slice_toymc_common","time_pdf_slice_toymc_common",tTrue? *tTrue : *tReco,*time_hist_slice_toymc_common,order); } if (tErr && (TString(_resFcn->getLabel())!="Unknown") && (TString(_resFcn->getLabel())!="Truth")) { tErr_hist_slice_toymc_common = new RooDataHist("tErr_hist_slice_toymc_common","tErr_hist_slice_toymc_common",*tErr,*slice_toymc_common); tErr_pdf_slice_toymc_common = new RooHistPdf("tErr_pdf_slice_toymc_common","tErr_pdf_slice_toymc_common",*tErr,*tErr_hist_slice_toymc_common,order); } if (mES) { mES_hist_slice_toymc_common = new RooDataHist("mES_hist_slice_toymc_common","mES_hist_slice_toymc_common",*mES,*slice_toymc_common); mES_pdf_slice_toymc_common = new RooHistPdf("mES_pdf_slice_toymc_common","mES_pdf_slice_toymc_common",*mES,*mES_hist_slice_toymc_common,order); } /* if (fisher) { fisher_hist_slice_toymc_common = new RooDataHist("fisher_hist_slice_toymc_common","fisher_hist_slice_toymc_common",*fisher,*slice_toymc_common); fisher_pdf_slice_toymc_common = new RooHistPdf("fisher_pdf_slice_toymc_common","fisher_pdf_slice_toymc_common",*fisher,*fisher_hist_slice_toymc_common,order); } */ } } // create 2D Dalitz histos TH2F* h2(0); TH2F* h2_chi2(0); TH2F* h2_chi2adaptive(0); if (!skipDalitzPlots) { h2 = (slice_cut!="" || nevtsToyMc>0)? slice_data_common->createHistogram(*qPair1,*qPair2,nbins,nbins,0,"h2") : data_common->createHistogram(*qPair1,*qPair2,nbins,nbins,0,"h2") ; if (nice) { h2->SetTitle(""); TString titleX(qPair1->GetTitle()); titleX.Append(" (GeV^{2}/c^{4}) "); h2->SetXTitle(titleX); TString titleY(qPair2->GetTitle()); titleY.Append(" (GeV^{2}/c^{4}) "); h2->SetYTitle(titleY); //h2->SetTitleOffset(0.9,"X"); //define the frame //h2->SetTitleOffset(0.8,"Y"); //for babar style h2->SetTitleOffset(1.1,"X"); //define the frame h2->SetTitleOffset(1.2,"Y"); //for babar style TAxis *xaxis = h2->GetXaxis(); xaxis->SetNdivisions(605); TAxis *yaxis = h2->GetYaxis(); yaxis->SetNdivisions(605); //xaxis->SetTitleSize(0.08); // 0.04 is default //xaxis->SetLabelSize(0.08); // 0.04 is default //yaxis->SetTitleSize(0.08); // 0.04 is default //yaxis->SetLabelSize(0.08); // 0.04 is default xaxis->SetTitleSize(0.07); // 0.04 is default xaxis->SetLabelSize(0.06); // 0.04 is default yaxis->SetTitleSize(0.07); // 0.04 is default yaxis->SetLabelSize(0.06); // 0.04 is default xaxis->SetLabelOffset(0.02); // default 0.005 yaxis->SetLabelOffset(0.02); // default 0.005 TAxis *zaxis = h2->GetZaxis(); // for "COLZ" only zaxis->SetLabelSize(0.055); // 0.04 is default } else { TString title("Dalitz plot "); title.Append(_gFit->_DdecayMode->getLabel()); title.Append(" for "); title.Append(_gFit->_BdecayMode->getLabel()); h2->SetTitle(title); h2->SetXTitle(qPair1->GetTitle()); h2->SetYTitle(qPair2->GetTitle()); } h2_chi2 = new TH2F(*h2); h2_chi2->SetName("h2_chi2"); TString title = "Normalized residual "; title.Append(h2->GetTitle()); h2_chi2->SetTitle(title); h2_chi2->Reset(); // h2_chi2adaptive = new TH2F(*h2); h2_chi2adaptive->SetName("h2_chi2adaptive"); title = "Adaptive Normalized Residual "; title.Append(h2->GetTitle()); h2_chi2adaptive->SetTitle(title); h2_chi2adaptive->Reset(); } // Dalitz plots, Proper time plots if (opt=="Dalitz" || opt=="DalitzOther" || opt=="Other") { // // plotting B-/B+ dataset. if (!skipDalitzPlots && opt.Contains("Dalitz") ) { TCanvas *c1 = new TCanvas("dalitz","allevents",600,600); c1 -> SetFillColor(10); c1 -> SetTitle(""); //cout << data_common->numEntries() << endl; //data_common->tree()->Draw("q12:q13"); if (nice) { Bool_t paletteopt(kTRUE); c1->SetBottomMargin(0.17); c1->SetLeftMargin(0.17); h2->SetMarkerStyle(20); if (BMode=="Dstar") { if (DMode=="KsKK") h2->SetMarkerSize(0.1); else if (DMode=="KsPiPi") h2->SetMarkerSize(0.05); else assert(0); } //else h2->SetMarkerSize(0.4); else h2->SetMarkerSize(0.7); if (paletteopt) { c1->SetBottomMargin( 0.17 ); //c1->SetLeftMargin( 0.25 ); //c1->SetRightMargin( 0.13 ); c1->SetRightMargin( 0.15 ); gStyle->SetPalette(10,colors_bw); //gStyle->SetPalette(1); gStyle->SetBarOffset(0.); gPad->SetLogz(1); h2->Draw("COLZ"); gPad -> Update(); TPaletteAxis* palette = (TPaletteAxis*)h2->GetListOfFunctions()->FindObject("palette"); //palette->SetX1NDC( 0.875 ); //palette->SetX2NDC( 0.93 ); palette->SetX1NDC( 0.855 ); palette->SetX2NDC( 0.91 ); } else h2->Draw(); /* TAxis *xaxis = h2->GetXaxis(); TAxis *yaxis = h2->GetYaxis(); xaxis->SetLabelOffset(0.02); // default 0.005 yaxis->SetLabelOffset(0.02); // default 0.005 */ grboundMax->Draw("C"); grboundMin->Draw("C"); //BABARSmartLabel(0.88,0.91,1,"preliminary"); //BABARSmartLabel(0.88,0.91,1.2,""); //BABARSmartLabel(0.88,0.82,1,"a)",0.8,"R",kFALSE); //BABARSmartLabel(0.41,1.0,1,"a)",0.8,"R",kFALSE); //BABARSmartLabel(0.86,0.94,1,"a)",0.8,"R",kFALSE); BABARSmartLabel(0.84,0.94,1,"a)",0.8,"R",kFALSE); } else { h2->SetMarkerSize(0.4); h2->Draw("COLZ"); //h2->SetMarkerSize(0.4); h2->Draw("BOX"); //h2->Draw("COLZ"); //h2->Draw("CONTZ"); grboundMax->Draw("C"); grboundMin->Draw("C"); } //RooDKDalitzBinGrid *BinGrid= new RooDKDalitzBinGrid(dp,pair1,pair2); //BinGrid->read("./config/GRIDcustomization.config",DdecayMode->getLabel()); //TH2F *GridPlot = BinGrid->plotBinDivision(h2); // make eps //gStyle->SetPalette(1); if (get_mpi_rank()==0) { TString file(file_root); //file.Append(opt); file.Append("Dalitz"); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair1->GetName()); file.Append("-"); file.Append(qPair2->GetName()); if (slice_cut!="") file.Append("_slice"); if (charge==+1) file.Append("_Bplus"); else if (charge==-1) file.Append("_Bminus"); c1->Print(file+".eps"); //c1->Print(file+".gif"); } // Write the canvas into the file with the appropriate name. if (get_mpi_rank()==0) { TFile plotsFile( rootPlotsFile.c_str(), "update" ); std::string plotName = std::string( "dalitz_" ) + std::string( BMode + "_" + DMode + "_m2AB_m2AC" ); c1->Write( plotName.c_str() ); // Save the canvas into the file. plotsFile.Close(); } delete c1; gStyle->SetPalette(0); } // // Bool_t makeProjs(kTRUE); //Bool_t makeProjs(kFALSE); if (makeProjs) { // start projections // projections /* if (nice && DMode=="KsKK" && BMode=="Dstar") { TString name(qPair1->GetName()); if (name=="qAB") qPair1->setRange(0.94,1.2); name=qPair2->GetName(); if (name=="qAB") qPair1->setRange(0.94,1.2); name=qPair3->GetName(); if (name=="qAB") qPair1->setRange(0.94,1.2); } */ // proper time if ((tTrue || tReco) && opt.Contains("Other")) makeDalitzPlotProjectionsTool(BMode,charge,nbins,nevtsToyMc,bkgCompOpt,slice_cut,nice,plotPdf, data_common,slice_data_common,pdf,tTrue? tTrue : tReco,time_pdf_slice_toymc_common,projDataDeps,projData_hist, file_root,opt,epsfile_suffix,logScale); //file_root,opt,epsfile_suffix,kFALSE); //file_root,opt,epsfile_suffix,kTRUE); // proper time error if ((tErr&&(TString(_resFcn->getLabel())!="Unknown") && (TString(_resFcn->getLabel())!="Truth")) && opt.Contains("Other")) makeDalitzPlotProjectionsTool(BMode,charge,nbins,nevtsToyMc,bkgCompOpt,slice_cut,nice,plotPdf, data_common,slice_data_common,pdf,tErr,tErr_pdf_slice_toymc_common,projDataDeps,projData_hist, file_root,opt,epsfile_suffix,logScale); //file_root,opt,epsfile_suffix,kFALSE); //file_root,opt,epsfile_suffix,kTRUE); // mES if (mES && opt.Contains("Other")) makeDalitzPlotProjectionsTool(BMode,charge,nbins,nevtsToyMc,bkgCompOpt,slice_cut,nice,plotPdf, data_common,slice_data_common,pdf,mES,mES_pdf_slice_toymc_common,projDataDeps_no_deltaEshift,projData_no_deltaEshift_hist, file_root,opt,epsfile_suffix,kFALSE); /* // Fisher if (fisher && opt.Contains("Other")) makeDalitzPlotProjectionsTool(BMode,charge,nbins,nevtsToyMc,bkgCompOpt,slice_cut,nice,plotPdf, data_common,slice_data_common,pdf,fisher,fisher_pdf_slice_toymc_common,projDataDeps,projData_hist, file_root,opt,epsfile_suffix,kFALSE); */ // plot first projection if (!skipDalitzPlots && opt.Contains("Dalitz")) makeDalitzPlotProjectionsTool(BMode,charge,nbins,nevtsToyMc,bkgCompOpt,slice_cut,nice,plotPdf, data_common,slice_data_common,pdf,qPair1,qpair1_pdf_slice_toymc_common,projDataDeps,projData_hist, file_root,opt,epsfile_suffix); // // plot second projection if (!skipDalitzPlots && opt.Contains("Dalitz")) makeDalitzPlotProjectionsTool(BMode,charge,nbins,nevtsToyMc,bkgCompOpt,slice_cut,nice,plotPdf, data_common,slice_data_common,pdf,qPair2,qpair2_pdf_slice_toymc_common,projDataDeps,projData_hist, file_root,opt,epsfile_suffix); // // plot third projection (numerical) if (!skipDalitzPlots && opt.Contains("Dalitz")) makeDalitzPlotProjectionsTool(BMode,charge,nbins,nevtsToyMc,bkgCompOpt,slice_cut,nice,plotPdf, data_common,slice_data_common,pdf,qPair3,qpair3_pdf_slice_toymc_common,projDataDeps,projData_hist, file_root,opt,epsfile_suffix, kFALSE,kTRUE,qPair1,qPair1_func); } // end projections } // end opt=="Dalitz" or opt=="DalitzOther" or opt=="Other" // // Chi2 plot if (opt=="DalitzChi2" && !skipDalitzPlots) { // log file for plots ofstream ofs(logFileChi2Plots); if (logFileChi2Plots!=0) { if (ofs.fail()) { if (get_mpi_rank()==0) cout << "RooDKFitMaster::makeDalitzPlots(): error opening file " << logFileChi2Plots << endl ; assert(0); } } ostream& os = ofs; // gStyle->SetPalette(0); Stat_t entries = h2->GetEntries(); if (get_mpi_rank()==0) { cout << "Making 2D histogram with chi2 distribution for " << BMode << " and " << DMode << endl; cout << "Total number of events = " << entries << endl; cout << "Binning = " << nbins << "x" << nbins << " bins " << endl; if (logFileChi2Plots!=0) { os << "Making 2D histogram with chi2 distribution for " << BMode << " and " << DMode << endl; os << "Total number of events = " << entries << endl; os << "Binning = " << nbins << "x" << nbins << " bins " << endl; } } double dx = (qPair1max-qPair1min)/nbins; double dy = (qPair2max-qPair2min)/nbins; RooArgSet* components = pdf->getComponents(); //components->Print("v"); // // Number of cells within a bin for integrating PDF in a bin Int_t nsubdiv = nbinsIntegralChi2/nbins; // ensures a nbinsIntegralChi2xnbinsIntegralChi2 binning for the evaluation of chi2 integral (full DP range) // normalization Double_t norm(0.); RooArgSet normSet(*qPair1,*qPair2); RooRealIntegral integral("integral","integral",*pdf,normSet); Double_t integralval = integral.getVal(); cout << "normalization integral = " << integralval << endl; /* for (Int_t i=0;isetVal(x); qPair2->setVal(y); norm += pdf->getVal()*dx*dy/(nsubdiv*nsubdiv); } } } } cout << "normalization = " << norm << endl; */ norm = integralval; // number of floated parameters RooArgSet* params = pdf->getParameters(_gFit->_selDataVars); TIterator* iterParams = params->createIterator(); RooAbsArg* item; Int_t nParamsFloat(0); while (item = (RooAbsArg*)iterParams->Next()) if (!item->getAttribute("Constant")) nParamsFloat++; delete iterParams; //cout << nParamsFloat << endl; assert(0); // // chi2 double chi2tot(0.); Int_t dofs(0); for (Int_t i=0;iGetBinContent(i+1,j+1); double f = entries/norm*makeIntegralBinTool(pdf,qPair1,qPair2,qPair1min+i*dx,dx,qPair2min+j*dy,dy,nsubdiv,nsubdiv); /* TAxis *xaxis = h2->GetXaxis(); TAxis *yaxis = h2->GetYaxis(); Double_t xbinCenter = xaxis->GetBinCenter(i+1); Double_t xbinLow = xaxis->GetBinLowEdge(i+1); Double_t xbinUp = xaxis->GetBinUpEdge(i+1); Double_t ybinCenter = yaxis->GetBinCenter(j+1); Double_t ybinLow = yaxis->GetBinLowEdge(j+1); Double_t ybinUp = yaxis->GetBinUpEdge(j+1); */ /* double x = qPair1min+i*dx+dx/2.; double y = qPair2min+j*dy+dy/2.; cout << "Bin("< SetFillColor(10); cchi2 -> SetTitle(""); //Int_t colors1[]={1,22,33,42,0,0,2,8,9,7}; // old Int_t colors1[]={46,7,3,37,5,0,33,8,9,2}; //h2_chi2->SetBinContent(0,0,+9.9); // to set the maximum scale of the colored map //h2_chi2->SetBinContent(nbins,nbins,-9.9); // to set the mininum scale of the colored map h2_chi2->SetMaximum(5); h2_chi2->SetMinimum(-5); gStyle->SetPalette(10,colors1); gStyle->SetOptStat(""); h2_chi2->Draw("COLZ"); //BABARLabel(0.73,0.85,1.0); // TGraph *grboundMax(0),*grboundMin(0); Int_t nbinsbound(10000); Double_t x[nbinsbound+1], ymin[nbinsbound+1], ymax[nbinsbound+1] ; for (Int_t i=0;i<=nbinsbound;i++) { Double_t qpair1 = (i/Double_t(nbinsbound))*(dp.qAbsMax(pair1)-dp.qAbsMin(pair1)) + dp.qAbsMin(pair1); if (i==0) qpair1 += 1e-15; if (i==nbinsbound) qpair1 -= 1e-15; x[i]=qpair1; ymin[i]=dp.qMin(pair2,pair1,qpair1) ; ymax[i]=dp.qMax(pair2,pair1,qpair1) ; } grboundMax = new TGraph(nbinsbound+1,x,ymax); grboundMin = new TGraph(nbinsbound+1,x,ymin); grboundMax->SetLineColor(kRed); grboundMin->SetLineColor(kRed); grboundMax->Draw("C"); grboundMin->Draw("C"); // // make eps //gStyle->SetPalette(20,colors); if (get_mpi_rank()==0) { TString file(file_root); //file.Append(opt); file.Append("DalitzChi2"); if (epsfile_suffix) file.Append(epsfile_suffix); if (charge==+1) file.Append("_Bplus"); else if (charge==-1) file.Append("_Bminus"); file.Append(".eps"); cchi2->Print(file); //getchar(); } // Write the canvas into the file with the appropriate name. if (get_mpi_rank()==0) { TFile plotsFile( rootPlotsFile.c_str(), "update" ); std::string plotName = std::string( "dalitz_" ) + std::string( BMode + "_" + DMode + "_chi2" ); cchi2->Write( plotName.c_str() ); // Save the canvas into the file. plotsFile.Close(); } delete grboundMax; delete grboundMin; delete cchi2; gStyle->SetPalette(0); } // // // // Chi2 with Adaptive binning if (opt=="DalitzChi2Adaptive" && !skipDalitzPlots) { // log file for plots ofstream ofs(logFileChi2AdaptivePlots); if (logFileChi2AdaptivePlots!=0) { if (ofs.fail()) { if (get_mpi_rank()==0) cout << "RooDKFitMaster::makeDalitzPlots(): error opening file " << logFileChi2AdaptivePlots << endl ; assert(0); } } ostream& os = ofs; // gStyle->SetPalette(0); std::vector xmin_bins,ymin_bins,xmax_bins,ymax_bins,occ_bins; adaptive2dBinning(data_common,qPair1,qPair2,nentriesChi2AdaptiveThr,xmin_bins,ymin_bins,xmax_bins,ymax_bins,occ_bins); std::vector normRes_bins; Double_t entries(0.); for (Int_t i=0;i SetFillColor(10); cchi2 -> SetTitle(""); //Int_t colors1[]={1,22,33,42,0,0,2,8,9,7}; // old Int_t colors1[]={46,7,3,37,5,0,33,8,9,2}; h2_chi2adaptive->SetBinContent(0,0,+9.9); // to set the maximum scale of the colored map h2_chi2adaptive->SetBinContent(nbins,nbins,-9.9); // to set the mininum scale of the colored map h2_chi2adaptive->SetMaximum(5); h2_chi2adaptive->SetMinimum(-5); gStyle->SetPalette(10,colors1); gStyle->SetOptStat(""); h2_chi2adaptive->Draw("COLZ"); // assert(xmin_bins.size()>0); assert(xmin_bins.size()==normRes_bins.size()); Double_t* xbin = new Double_t[4+1]; Double_t* ybin = new Double_t[4+1]; for (Int_t i=0;i=0. && normRes<=1.) gr->SetFillColor(colors1[5]); else if (normRes>1. && normRes<=2.) gr->SetFillColor(colors1[6]); else if (normRes>2. && normRes<=3.) gr->SetFillColor(colors1[7]); else if (normRes>3. && normRes<=4.) gr->SetFillColor(colors1[8]); else if (normRes>4.) gr->SetFillColor(colors1[9]); else if (normRes<0. && normRes>=-1.) gr->SetFillColor(colors1[4]); else if (normRes<-1. && normRes>=-2.) gr->SetFillColor(colors1[3]); else if (normRes<-2. && normRes>=-3.) gr->SetFillColor(colors1[2]); else if (normRes<-3. && normRes>=-4.) gr->SetFillColor(colors1[1]); else if (normRes<-4.) gr->SetFillColor(colors1[0]); else assert(0); // this should never happen gr->Draw("LF"); // polyline, fill //gr->SetLineStyle(1); //gr->SetLineWidth(1); //gr->SetLineColor(1); //gr->Draw("L"); // polyline only } // //BABARLabel(0.73,0.85,1.0); // TGraph *grboundMax(0),*grboundMin(0); Int_t nbinsbound(10000); Double_t x[nbinsbound+1], ymin[nbinsbound+1], ymax[nbinsbound+1] ; for (Int_t i=0;i<=nbinsbound;i++) { Double_t qpair1 = (i/Double_t(nbinsbound))*(dp.qAbsMax(pair1)-dp.qAbsMin(pair1)) + dp.qAbsMin(pair1); if (i==0) qpair1 += 1e-15; if (i==nbinsbound) qpair1 -= 1e-15; x[i]=qpair1; ymin[i]=dp.qMin(pair2,pair1,qpair1) ; ymax[i]=dp.qMax(pair2,pair1,qpair1) ; } grboundMax = new TGraph(nbinsbound+1,x,ymax); grboundMin = new TGraph(nbinsbound+1,x,ymin); grboundMax->SetLineColor(kRed); grboundMin->SetLineColor(kRed); grboundMax->Draw("C"); grboundMin->Draw("C"); // // make eps if (get_mpi_rank()==0) { TString file(file_root); //file.Append(opt); file.Append("DalitzChi2Adaptive"); if (epsfile_suffix) file.Append(epsfile_suffix); if (charge==+1) file.Append("_Bplus"); else if (charge==-1) file.Append("_Bminus"); file.Append(".eps"); cchi2->Print(file); //getchar(); } // Write the canvas into the file with the appropriate name. if (get_mpi_rank()==0) { TFile plotsFile( rootPlotsFile.c_str(), "update" ); std::string plotName = std::string( "dalitz_" ) + std::string( BMode + "_" + DMode + "_chi2adaptive" ); cchi2->Write( plotName.c_str() ); // Save the canvas into the file. plotsFile.Close(); } delete grboundMax; delete grboundMin; delete cchi2; } // // clean-up delete data; delete data_common; if (slice_data_common) delete slice_data_common; if (toymc_common) delete toymc_common; if (slice_toymc_common) delete slice_toymc_common; if (qpair1_hist_slice_toymc_common) delete qpair1_hist_slice_toymc_common; if (qpair1_pdf_slice_toymc_common) delete qpair1_pdf_slice_toymc_common; if (qpair2_hist_slice_toymc_common) delete qpair2_hist_slice_toymc_common; if (qpair2_pdf_slice_toymc_common) delete qpair2_pdf_slice_toymc_common; if (qpair3_hist_slice_toymc_common) delete qpair3_hist_slice_toymc_common; if (qpair3_pdf_slice_toymc_common) delete qpair3_pdf_slice_toymc_common; if (time_hist_slice_toymc_common) delete time_hist_slice_toymc_common; if (time_pdf_slice_toymc_common) delete time_pdf_slice_toymc_common; if (tErr_hist_slice_toymc_common) delete tErr_hist_slice_toymc_common; if (tErr_pdf_slice_toymc_common) delete tErr_pdf_slice_toymc_common; if (mES_hist_slice_toymc_common) delete mES_hist_slice_toymc_common; if (mES_pdf_slice_toymc_common) delete mES_pdf_slice_toymc_common; /* if (fisher_hist_slice_toymc_common) delete fisher_hist_slice_toymc_common; if (fisher_pdf_slice_toymc_common) delete fisher_pdf_slice_toymc_common; */ if (qPair3_func) delete qPair3_func; if (qPair2_func) delete qPair2_func; if (qPair1_func) delete qPair1_func; if (q12) delete q12; if (q13) delete q13; if (q23) delete q23; if (q12_func) delete q12_func; if (q13_func) delete q13_func; if (q23_func) delete q23_func; if (grboundMax) delete grboundMax; if (grboundMin) delete grboundMin; if (h2) delete h2; if (h2_chi2) delete h2_chi2; if (h2_chi2adaptive) delete h2_chi2adaptive; //delete colors; if (deps) delete deps; if (tErrHist) delete tErrHist; if (tErrPdf) delete tErrPdf; } // tools for bin integration (2D chi2 calculation) Double_t RooDKFitMaster::makeIntegralBinTool(EvtDalitzPlot& dp, RooAbsPdf* pdf, RooRealVar* qPair1, EvtCyclic3::Pair pair1, RooRealVar* qPair2, EvtCyclic3::Pair pair2, Double_t qPair1binLow, Double_t qPair1binWidth, Double_t qPair2binLow, Double_t qPair2binWidth, Int_t ndivPair1, Int_t ndivPair2) { double f(0.); for (Int_t idiv=0;idiv<=ndivPair1;idiv++) { for (Int_t jdiv=0;jdiv<=ndivPair2;jdiv++) { double x = qPair1binLow + idiv/float(ndivPair1)*qPair1binWidth + 1e-6; if (idiv==ndivPair1) x -= 2e-6; double y = qPair2binLow + jdiv/float(ndivPair2)*qPair2binWidth + 1e-6; if (jdiv==ndivPair2) y -= 2e-6; EvtDalitzCoord dc(pair1,x,pair2,y); EvtDalitzPoint xdp(dp,dc); if (xdp.isValid()) { qPair1->setVal(x); qPair2->setVal(y); f += pdf->getVal(); } } } f *= qPair1binWidth*qPair2binWidth/float((ndivPair1+1)*(ndivPair2+1)); return f; } // Double_t RooDKFitMaster::makeIntegralBinTool(RooAbsPdf* pdf, RooRealVar* qPair1, RooRealVar* qPair2, Double_t qPair1binLow, Double_t qPair1binWidth, Double_t qPair2binLow, Double_t qPair2binWidth, Int_t ndivPair1, Int_t ndivPair2) { double f(0.); for (Int_t idiv=0;idiv<=ndivPair1;idiv++) { for (Int_t jdiv=0;jdiv<=ndivPair2;jdiv++) { double x = qPair1binLow+idiv/float(ndivPair1)*qPair1binWidth+1e-6; if (idiv==ndivPair1) x -= 2e-6; double y = qPair2binLow+jdiv/float(ndivPair2)*qPair2binWidth+1e-6; if (jdiv==ndivPair2) y -= 2e-6; qPair1->setVal(x); qPair2->setVal(y); f += pdf->getVal(); } } f *= qPair1binWidth*qPair2binWidth/float((ndivPair1+1)*(ndivPair2+1)); return f; } // common tool to plot Dalitz plot projections void RooDKFitMaster::makeDalitzPlotProjectionsTool(TString BMode, Int_t charge, Int_t nbins, Int_t nevtsToyMc, TString bkgCompOpt, TString slice_cut, Bool_t nice, Bool_t plotPdf, RooDataSet* data_common, RooDataSet* slice_data_common, RooAbsPdf* pdf, RooRealVar* qPair, RooHistPdf *qpair_pdf_slice_toymc_common, RooArgSet& projDataDeps, RooDataHist& projData_hist, TString file_root, TString opt, char* epsfile_suffix, Bool_t logScale, Bool_t thirdProjection, RooRealVar* qPair_other, RooFormulaVar* qPair_other_func) { TCanvas* c1 = 0; RooPlot* xframe = (TString(qPair->GetName())=="tReco" || TString(qPair->GetName())=="tTrue")? qPair->frame(-4.,4.,nbins) : qPair->frame(nbins); RooPlot* plot_data(0); if (slice_cut!="" || nevtsToyMc>0) plot_data = slice_data_common->plotOn(xframe); else plot_data = data_common->plotOn(xframe); //const char* histname = xframe->findObject(0)->GetName(); xframe->getAttMarker()->SetMarkerSize(0.5); //if (nice && TString(BMode)=="Dstar") xframe->getAttMarker()->SetMarkerSize(0.9); if (nice) { //if (BMode=="Dstar") xframe->getAttMarker()->SetMarkerSize(0.4); if (BMode=="Dstar") xframe->getAttMarker()->SetMarkerSize(0.9); // !!! else xframe->getAttMarker()->SetMarkerSize(0.9); if (BMode=="Dstar") gStyle->SetEndErrorSize(0); // to remove little ticks at the end of vertical and horizontal error bars //if (BMode=="Dstar") xframe->getAttMarker()->SetMarkerStyle(2); // idem, pero esto no funciona } else xframe->getAttMarker()->SetMarkerSize(0.5); RooAbsPdf *pdf3(0); RooCustomizer *cust(0); if (pdf && plotPdf && !(slice_cut!="" || nevtsToyMc>0) ) { if (thirdProjection) { assert(qPair_other); assert(qPair_other_func); //RooArgSet* deps = pdf->getDependents(_gFit->_selDataVars); //deps->Print("v"); //delete deps; RooCustomizer *cust = new RooCustomizer(*pdf,"cust_makeDalitzPlots") ; cust->replaceArg(*qPair_other,*qPair_other_func); pdf3 = (RooAbsPdf*)cust->build(kTRUE); //deps = pdf3->getDependents(_gFit->_selDataVars); //deps->Print("v"); //delete deps; } } RooPlot *plot_pdf(0); RooPlot *plot_pdfComp1(0),*plot_pdfComp2(0),*plot_pdfComp3(0),*plot_pdfComp4(0),*plot_pdfComp5(0),*plot_pdfComp6(0); if(plotPdf){ if (slice_cut!="" || nevtsToyMc>0) { plot_pdf = qpair_pdf_slice_toymc_common->plotOn(xframe,LineColor(kBlue)); } else { if (!thirdProjection) plot_pdf = pdf->plotOn(xframe,ProjWData(projDataDeps,projData_hist),LineColor(kBlue)); else { //plot_pdf = pdf3->plotOn(xframe3,Project(data_common_vars_excludeProjDataDeps),ProjWData(projDataDeps,*projData),LineColor(kBlack),Range(0.51,0.69,kTRUE)); //plot_pdf = pdf3->plotOn(xframe3,Project(data_common_vars_excludeProjDataDeps),ProjWData(projDataDeps,*projData),LineColor(kBlack)); plot_pdf = pdf3->plotOn(xframe,ProjWData(projDataDeps,projData_hist),LineColor(kBlue)); } } xframe->getAttLine()->SetLineWidth(2); if (nice && BMode=="Dstar") xframe->getAttLine()->SetLineColor(9); // plot components if (slice_cut=="" && nevtsToyMc==0 && bkgCompOpt.Contains("Y")) { //assert(0); // to be reviewed if (nice && bkgCompOpt.Contains("A")) { assert(0); // to be reviewed /* TString bkg("dalitzContGoodDRSPdf*,dalitzContGoodDWSPdf*,dalitzContFakeDPdf*,effMapContFakeDPdf*,effMapContFakeDSymPdf*"); bkg.Append("dalitzDhPdf*"); bkg.Append("dalitzBBGoodDRSPdf*,dalitzBBGoodDWSPdf*,dalitzBBFakeDPdf*,effMapBBFakeDPdf*,effMapBBFakeDSymPdf*"); if (!thirdProjection) { pdf->plotOn(xframe,Components(bkg),LineColor(kBlue)); //pdf->plotOn(xframe,Components(bkg),Slice(*recState),LineColor(kBlue)); // to plot B-/B+ projections } else { //pdf3->plotOn(xframe,Project(data_common_vars_excludeProjDataDeps),ProjWData(projDataDeps,*projData),LineColor(kBlue),Components(bkg)); pdf3->plotOn(xframe,ProjWData(projDataDeps,projData_hist),LineColor(kBlue),Components(bkg)); } xframe->getAttLine()->SetLineStyle(2); xframe->getAttLine()->SetLineWidth(2); if (!thirdProjection) { pdf->plotOn(xframe,Components("dalitzSigPdf*"),LineColor(kRed)); //pdf->plotOn(xframe,Components("dalitzSigPdf*"),Slice(*recState),LineColor(kRed)); // to plot B-/B+ projections } else { //pdf3->plotOn(xframe,Project(data_common_vars_excludeProjDataDeps),ProjWData(projDataDeps,*projData),LineColor(kRed),Components("dalitzSigPdf*")); pdf3->plotOn(xframe,ProjWData(projDataDeps,projData_hist),LineColor(kRed),Components("dalitzSigPdf*")); } xframe->getAttLine()->SetLineStyle(4); xframe->getAttLine()->SetLineWidth(2); */ } else { if (!thirdProjection) { if (BMode=="Dstar") { // For D*'s TString comp = "*DstarContFakeDT*"; // Cat 4 plot_pdfComp1 = pdf->plotOn(xframe,LineColor(kGreen),ProjWData(projDataDeps,projData_hist),Components(comp)); comp += ",*DstarContGoodDT*,*DstarContGoodDRST*,*DstarContGoodDWST*"; // Cat 2 plot_pdfComp2 = pdf->plotOn(xframe,LineColor(kOrange),ProjWData(projDataDeps,projData_hist),Components(comp)); //enum EColor { kWhite =0, kBlack =1, kGray=920 // ,kRed =632, kGreen =416, kBlue=600, kYellow=400, kMagenta=616, kCyan=432 // ,kOrange=800, kSpring=820, kTeal=840, kAzure =860, kViolet =880, kPink=900}; comp += ",*DstarSigFakeDT*"; // Cat 3 plot_pdfComp3 = pdf->plotOn(xframe,LineColor(kMagenta),ProjWData(projDataDeps,projData_hist),Components(comp)); //comp += ",selDstarSigFakeD4udsT*"; // Cat 5 //plot_pdfComp4 = pdf->plotOn(xframe,LineColor(kBlack),ProjWData(projDataDeps,projData_hist),Components(comp)); comp += ",*DstarSigFakeDKsKsT*,*DstarSigFakeDKsKsRST*,*DstarSigFakeDKsKsWST*"; // Cat 6 plot_pdfComp5 = pdf->plotOn(xframe,LineColor(kRed),ProjWData(projDataDeps,projData_hist),Components(comp)); comp += ",*DstarSigGoodDT*,*DstarSigGoodDRST*,*DstarSigGoodDWST*"; // Cat 1 plot_pdfComp6 = pdf->plotOn(xframe,LineColor(kBlue),ProjWData(projDataDeps,projData_hist),Components(comp)); } else { // For B's TString comp = "*ContGoodD*Pdf*,*ContFakeD*Pdf*"; plot_pdfComp1 = pdf->plotOn(xframe,LineColor(kMagenta),ProjWData(projDataDeps,projData_hist),Components(comp)); comp += ",*BBGoodD*Pdf*,*BBFakeD*Pdf*"; plot_pdfComp2 = pdf->plotOn(xframe,LineColor(kGreen),ProjWData(projDataDeps,projData_hist),Components(comp)); if (BMode=="DK" || BMode=="Dpi0K" || BMode=="DgammaK" || BMode=="DKspi" || BMode=="DRho0pi") { // for DK channels comp += ",*Dh*Pdf*"; plot_pdfComp3 = pdf->plotOn(xframe,LineColor(kBlue),ProjWData(projDataDeps,projData_hist),Components(comp)); comp += ",*Sig*Pdf*"; plot_pdfComp4 = pdf->plotOn(xframe,LineColor(kRed),ProjWData(projDataDeps,projData_hist),Components(comp)); } else { // for DPi channels comp += ",*Sig*Pdf*"; plot_pdfComp3 = pdf->plotOn(xframe,LineColor(kBlue),ProjWData(projDataDeps,projData_hist),Components(comp)); comp += ",*Dh*Pdf*"; plot_pdfComp4 = pdf->plotOn(xframe,LineColor(kRed),ProjWData(projDataDeps,projData_hist),Components(comp)); } } } else { if (BMode=="Dstar") { // For D*'s TString comp = "*DstarContFakeDT*"; // Cat 4 plot_pdfComp1 = pdf3->plotOn(xframe,LineColor(kGreen),ProjWData(projDataDeps,projData_hist),Components(comp)); comp += ",*DstarContGoodDT*,*DstarContGoodDRST*,*DstarContGoodDWST*"; // Cat 2 plot_pdfComp2 = pdf3->plotOn(xframe,LineColor(kOrange),ProjWData(projDataDeps,projData_hist),Components(comp)); //enum EColor { kWhite =0, kBlack =1, kGray=920 // ,kRed =632, kGreen =416, kBlue=600, kYellow=400, kMagenta=616, kCyan=432 // ,kOrange=800, kSpring=820, kTeal=840, kAzure =860, kViolet =880, kPink=900}; comp += ",*DstarSigFakeDT*"; // Cat 3 plot_pdfComp3 = pdf3->plotOn(xframe,LineColor(kMagenta),ProjWData(projDataDeps,projData_hist),Components(comp)); //comp += ",selDstarSigFakeD4udsT*"; // Cat 5 //plot_pdfComp4 = pdf3->plotOn(xframe,LineColor(kBlack),ProjWData(projDataDeps,projData_hist),Components(comp)); comp += ",*DstarSigFakeDKsKsT*,*DstarSigFakeDKsKsRST*,*DstarSigFakeDKsKsWST*"; // Cat 6 plot_pdfComp5 = pdf3->plotOn(xframe,LineColor(kRed),ProjWData(projDataDeps,projData_hist),Components(comp)); comp += ",*DstarSigGoodDT*,*DstarSigGoodDRST*,*DstarSigGoodDWST*"; // Cat 1 plot_pdfComp6 = pdf3->plotOn(xframe,LineColor(kBlue),ProjWData(projDataDeps,projData_hist),Components(comp)); } else { // For B's TString comp = "*ContGoodD*Pdf*,*ContFakeD*Pdf*"; plot_pdfComp1 = pdf->plotOn(xframe,LineColor(kMagenta),ProjWData(projDataDeps,projData_hist),Components(comp)); comp += ",*BBGoodD*Pdf*,*BBFakeD*Pdf*"; plot_pdfComp2 = pdf->plotOn(xframe,LineColor(kGreen),ProjWData(projDataDeps,projData_hist),Components(comp)); if (BMode=="DK" || BMode=="Dpi0K" || BMode=="DgammaK" || BMode=="DKspi" || BMode=="DRho0pi") { // for DK channels comp += ",*Dh*Pdf*"; plot_pdfComp3 = pdf->plotOn(xframe,LineColor(kBlue),ProjWData(projDataDeps,projData_hist),Components(comp)); comp += ",*Sig*Pdf*"; plot_pdfComp4 = pdf->plotOn(xframe,LineColor(kRed),ProjWData(projDataDeps,projData_hist),Components(comp)); } else { // for DPi channels comp += ",*Sig*Pdf*"; plot_pdfComp3 = pdf->plotOn(xframe,LineColor(kBlue),ProjWData(projDataDeps,projData_hist),Components(comp)); comp += ",*Dh*Pdf*"; plot_pdfComp4 = pdf->plotOn(xframe,LineColor(kRed),ProjWData(projDataDeps,projData_hist),Components(comp)); } } } xframe->getAttLine()->SetLineStyle(1); xframe->getAttLine()->SetLineWidth(2); } } } //if (pdf3) delete pdf3; //if (cust) delete cust; // if (plot_pdf) c1 = makePlotAndResid(plot_data,plot_pdf,plot_pdfComp1,plot_pdfComp2,plot_pdfComp3,plot_pdfComp4,plot_pdfComp5,plot_pdfComp6,0.2,logScale,!nice); else c1 = makePlot(plot_data,0.2,logScale); c1 -> SetFillColor(10); // if (nice) { c1->SetBottomMargin(0.15); c1->SetLeftMargin(0.15); plot_data->SetTitle(""); if (plot_pdf) plot_pdf->SetTitle(""); TAxis *xaxis = xframe->GetXaxis(); xaxis->SetNdivisions(605); TAxis *yaxis = xframe->GetYaxis(); yaxis->SetNdivisions(6); //xframe->SetTitleOffset(0.9,"X"); //define the frame //xframe->SetTitleOffset(1.2,"Y");//for babar style //xframe->SetTitleOffset(1.1,"X"); //define the frame //xframe->SetTitleOffset(1.35,"Y");//for babar style xframe->SetTitleOffset(1.0,"X"); //define the frame // !!! xframe->SetTitleOffset(1.1,"Y");//for babar style // !!! xframe->SetTitle(""); //xaxis->SetTitleSize(0.08); // 0.04 is default //xaxis->SetLabelSize(0.08); // 0.04 is default //yaxis->SetTitleSize(0.07); // 0.04 is default //yaxis->SetLabelSize(0.06); // 0.04 is default //xaxis->SetTitleSize(0.07); // 0.04 is default //xaxis->SetLabelSize(0.06); // 0.04 is default //yaxis->SetTitleSize(0.07); // 0.04 is default //yaxis->SetLabelSize(0.06); // 0.04 is default // //xaxis->SetTitleSize(0.06); // 0.04 is default //xaxis->SetLabelSize(0.05); // 0.04 is default xaxis->SetTitleSize(0.07); // 0.04 is default // !!! xaxis->SetLabelSize(0.07); // 0.04 is default // !!! //yaxis->SetTitleSize(0.06); // 0.04 is default yaxis->SetTitleSize(0.07); // 0.04 is default /// !!! yaxis->SetLabelSize(0.05); // 0.04 is default //yaxis->SetTitle("Events/0.028 GeV^{2}/c^{4}"); // for 100 bins xframe->Draw(); //BABARSmartLabel(0.88,0.88,1,"preliminary"); //BABARSmartLabel(0.88,0.96,1,"b)",0.8,"R",kFALSE); BABARSmartLabel(0.89,0.94,1,"a)",0.8,"R",kFALSE); } // make eps if (get_mpi_rank()==0) { TString file(file_root); //file.Append(opt); //Bool_t DalitzVar = TString(qPair->GetName())=="qAB" || TString(qPair->GetName())=="qAC" || TString(qPair->GetName())=="qBC"; //if (DalitzVar) file.Append("Dalitz"); file.Append("Dalitz"); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair->GetName()); if (slice_cut!="") file.Append("_slice"); if (charge==+1) file.Append("_Bplus"); else if (charge==-1) file.Append("_Bminus"); c1->Print(file+".eps"); //c1->Print(file+".gif"); } // Translate some strings into others. std::map< std::string, std::string > dict; dict[ qPair->GetName() ] = qPair->GetName(); // Translate to itself if no translation requested. dict[ "qAB" ] = "m2AB"; dict[ "qAC" ] = "m2AC"; dict[ "qBC" ] = "m2BC"; // Write the canvas into the file with the appropriate name. if (get_mpi_rank()==0) { std::string rootPlotsFile = (const char*) file_root; // Get the B and D modes from the root file name. std::size_t endDmode = rootPlotsFile.rfind( "_" ); std::size_t iniDmode = rootPlotsFile.rfind( "_", endDmode - 1 ); std::size_t iniBmode = rootPlotsFile.rfind( "_", iniDmode - 1 ); std::string Dmode = rootPlotsFile.substr( iniDmode + 1, endDmode - iniDmode - 1 ); std::string Bmode = rootPlotsFile.substr( iniBmode + 1, iniDmode - iniBmode - 1 ); // Strip the _Bmode_Dmode_ part of the file name, for the plots root file. rootPlotsFile = rootPlotsFile.substr( 0, iniBmode ); // Add the plots extension to the plots root file. rootPlotsFile += ".plots.root"; TFile plotsFile( rootPlotsFile.c_str(), "update" ); std::string plotName = std::string( "dalitz_" + Bmode + "_" + Dmode + "_" + dict[ qPair->GetName() ] ); c1->Write( plotName.c_str() ); // Save the canvas into the file. plotsFile.Close(); } delete c1; } // making cartesian contour plots void RooDKFitMaster::makeContourPlots(TString BMode, const char* epsfile_root, Int_t nPointsContour, Bool_t c1, Bool_t c2, Bool_t c3, Bool_t c4, Bool_t c5, Bool_t c6) { // countour plots for B modes are for the cartesian CP parameters // for Dstar mode are for the mixing parameters assert((BMode=="DzK")||(BMode=="DstK")||(BMode=="DzKst")||(BMode=="DzPi")||(BMode=="DstPi")||(BMode=="Dstar")); RooAbsPdf* pdf = _pdfGlobal; RooFitResult* fitResults = _fitResults; RooDataSet* data = _fitData; if (get_mpi_rank()==0) cout << pdf << " " << fitResults << " " << data << endl; RooArgSet* pars = pdf->getParameters(_gFit->_selDataVars); Bool_t dk = (BMode=="DzK") || (BMode=="DstK") || (BMode=="DzKst") ; Bool_t dpi = (BMode=="DzPi")||(BMode=="DstPi") ; Bool_t mixing = (BMode=="Dstar"); // D-mixing //Double_t lo = dk? -0.6 : ( dpi? -0.15 : -0.02 ) ; //Double_t up = dk? 0.6 : ( dpi? 0.15 : 0.02 ); //Double_t lo = dk? -0.8 : ( dpi? -0.15 : -0.02 ) ; //Double_t up = dk? 0.8 : ( dpi? 0.15 : 0.02 ); Double_t lo = dk? -0.8 : ( dpi? -0.15 : -0.2 ) ; Double_t up = dk? 0.8 : ( dpi? 0.15 : 0.2 ); /* Double_t lo = dk? -0.6 : ( dpi? -0.10 : -0.2 ) ; Double_t up = dk? 0.6 : ( dpi? 0.10 : 0.2 ); // changes over dk or dpi defaults if (BMode=="DzKst") { lo = -1.2; up = 1.2; } if (BMode=="DstPi") { lo = -0.2; up = 0.2; } */ Bool_t zoom(kFALSE); if (zoom) { lo = dk? -0.35 : ( dpi? -0.08 : -0.2 ) ; up = dk? 0.35 : ( dpi? 0.08 : 0.2 ); } if (BMode=="DzKst") { if (!zoom) { lo = -0.9; up = 0.9; } else { lo = -0.35; up = 0.35; } } Double_t reM_val, imM_val, reP_val, imP_val ; // TString name_reM,name_imM,name_reP,name_imP; if (BMode=="DzK") { name_reM = "reM_DK"; name_imM = "imM_DK"; name_reP = "reP_DK"; name_imP = "imP_DK"; } else if (BMode=="DstK") { name_reM = "reM_Dpi0K"; name_imM = "imM_Dpi0K"; name_reP = "reP_Dpi0K"; name_imP = "imP_Dpi0K"; } else if (BMode=="DzPi") { name_reM = "reMDh_DPi"; name_imM = "imMDh_DPi"; name_reP = "rePDh_DPi"; name_imP = "imPDh_DPi"; } else if (BMode=="DstPi") { name_reM = "reMDh_Dpi0Pi"; name_imM = "imMDh_Dpi0Pi"; name_reP = "rePDh_Dpi0Pi"; name_imP = "imPDh_Dpi0Pi"; } else if (BMode=="DzKst") { name_reM = "reM_DKspi"; name_imM = "imM_DKspi"; name_reP = "reP_DKspi"; name_imP = "imP_DKspi"; } else if (BMode=="Dstar") { // D-mixing RooRealVar* x = (RooRealVar*)pars->find("x") ; RooRealVar* y = (RooRealVar*)pars->find("y") ; RooRealVar* x_DstarPlus = (RooRealVar*)pars->find("x_DstarPlus") ; RooRealVar* y_DstarPlus = (RooRealVar*)pars->find("y_DstarPlus") ; RooRealVar* x_DstarMinus = (RooRealVar*)pars->find("x_DstarMinus") ; RooRealVar* y_DstarMinus = (RooRealVar*)pars->find("y_DstarMinus") ; if (x && y) { // CP is conserved name_reM = ""; name_imM = ""; name_reP = "x"; name_imP = "y"; } else if (x_DstarPlus && y_DstarPlus && x_DstarMinus && y_DstarMinus) { // CPV is allowed name_reM = "x_DstarMinus"; name_imM = "y_DstarMinus"; name_reP = "x_DstarPlus"; name_imP = "y_DstarPlus"; } else if (x_DstarPlus && y_DstarPlus) { // CPV is allowed name_reM = ""; name_imM = ""; name_reP = "x_DstarPlus"; name_imP = "y_DstarPlus"; } else if (x_DstarMinus && y_DstarMinus) { // CPV is allowed name_reM = "x_DstarMinus"; name_imM = "y_DstarMinus"; name_reP = ""; name_imP = ""; } else assert(0); } RooRealVar* reM = (name_reM!="")? (RooRealVar*)pars->find(name_reM) : 0 ; RooRealVar* imM = (name_imM!="")? (RooRealVar*)pars->find(name_imM) : 0 ; RooRealVar* reP = (name_reP!="")? (RooRealVar*)pars->find(name_reP) : 0 ; RooRealVar* imP = (name_imP!="")? (RooRealVar*)pars->find(name_imP) : 0 ; if (get_mpi_rank()==0) cout << reM << " " << imM << " " << reP << " " << imP << " " << endl; if (reM==0 && imM==0 && reP==0 && imP==0) return; // nothing to do assert( (reM!=0 && imM!=0 && reP!=0 && imP!=0) || (reM!=0 && imM!=0) || (reP!=0 && imP!=0) ); if (reM && imM) { reM->setRange(lo,up); reM_val = reM->getVal(); imM->setRange(lo,up); imM_val = imM->getVal(); } if (reP && imP) { reP->setRange(lo,up); reP_val = reP->getVal(); imP->setRange(lo,up); imP_val = imP->getVal(); } // Double_t sVal[6]; if (mixing) { sVal[0] = c1? sqrt(2.30) : 0.; sVal[1] = c2? sqrt(6.18) : 0.; sVal[2] = c3? sqrt(11.83) : 0.; sVal[3] = c4? sqrt(19.33) : 0.; sVal[4] = c5? sqrt(28.74) : 0.; sVal[5] = c6? sqrt(40.09) : 0.; } else { sVal[0] = c1? 1. : 0.; sVal[1] = c2? 2. : 0.; sVal[2] = c3? 3. : 0.; sVal[3] = c4? 4. : 0.; sVal[4] = c5? 5. : 0.; sVal[5] = c6? 6. : 0.; } if (reM!=0 && imM!=0 && reP!=0 && imP!=0) RooContoursCartesians contours(BMode,*_mMinuit,*reM,*imM,*reP,*imP,epsfile_root,nPointsContour,sVal[0],sVal[1],sVal[2],sVal[3],sVal[4],sVal[5]); else if (reM!=0 && imM!=0) RooContoursCartesians contours(BMode,*_mMinuit,*reM,*imM,epsfile_root,nPointsContour,sVal[0],sVal[1],sVal[2],sVal[3],sVal[4],sVal[5]); else RooContoursCartesians contours(BMode,*_mMinuit,*reP,*imP,epsfile_root,nPointsContour,sVal[0],sVal[1],sVal[2],sVal[3],sVal[4],sVal[5]); } void RooDKFitMaster::makeHarmonicsPlots(TString BMode, TString DMode, Int_t charge, TString opt, const char* epsfile_root, Bool_t kToyMc, Int_t nbins, Int_t nevtsToyMc, char* epsfile_suffix, Bool_t nice, Bool_t mESenhanced, Double_t epsRel) { // charge = -1, +1, 0 (for both, -1 and +1) assert (charge==-1 || charge==+1 || charge==0); //gROOT->SetStyle("BABAR"); // define stat option gStyle->SetOptStat(0); // define palette for normalized residuals Int_t* colors = new Int_t[20]; colors[0]=100+28; colors[1]=102; colors[2]=103; colors[3]=104; colors[4]=105; colors[5]=106; colors[6]=107; colors[7]=108; colors[8]=109; colors[9]=100+11; colors[10]=150+11; colors[11]=159; colors[12]=158; colors[13]=157; colors[14]=156; colors[15]=155; colors[16]=154; colors[17]=153; colors[18]=152; colors[19]=150+28; // set decay modes _gFit->_DdecayMode->setLabel(DMode); _gFit->_DdecayModeLF->setIndex(_gFit->_DdecayMode->getIndex()); _gFit->_BdecayMode->setLabel(BMode); _gFit->_BdecayModeLF->setIndex(_gFit->_BdecayMode->getIndex()); // eps root file name TString file_root; if (epsfile_root) { file_root.Append(epsfile_root); file_root.Append("_"); } file_root.Append(BMode); file_root.Append("_"); file_root.Append(DMode); file_root.Append("_"); // pdf component name TString pdfComp("{"); pdfComp.Append(DMode); pdfComp.Append(";"); pdfComp.Append(BMode); pdfComp.Append("}"); if (get_mpi_rank()==0) cout << "RooDKFitMaster::makeHarmonicsPlots: Pdf component: " << pdfComp << endl; // get PDF RooAbsPdf* pdf = (_pdfGlobal)? (RooAbsPdf*)_pdfGlobal->getPdf(pdfComp) : 0; if (pdf==0) return; // get DeltaE and set limits RooArgSet* deps(0); //RooRealVar* deltaE(0); //RooRealVar* mES(0); if (pdf) { deps = pdf->getDependents(_gFit->_selDataVars); deps->Print("v"); // deltaE = (RooRealVar*)deps->find("deltaE_dk"); // mES = (RooRealVar*)deps->find("mES"); // if (deltaE) deltaE->setRange(_deltaEMin_dk->getVal(),_deltaEMax_dk->getVal()); // else { // deltaE = (RooRealVar*)deps->find("deltaE_dpi"); // if (deltaE) deltaE->setRange(_deltaEMin_dpi->getVal(),_deltaEMax_dpi->getVal()); // } // if (deltaE) cout << deltaE->GetName() << " range: [" << deltaE->getMin() << "," << deltaE->getMax() << "]" << endl; // if (mES) cout << mES->GetName() << " range: [" << mES->getMin() << "," << mES->getMax() << "]" << endl; } // projection cut TString cutProj("(BdecayMode==BdecayMode::"); cutProj.Append(BMode); cutProj.Append(")&&(DdecayMode==DdecayMode::"); cutProj.Append(DMode); cutProj.Append(")"); if (charge!=0) { cutProj.Append("&&(recState==recState::"); if (charge==-1) cutProj.Append("Bminus)"); else cutProj.Append("Bplus)"); } if (get_mpi_rank()==0) cout << "RooDKFitMaster::makeHarmonicsPlots: Data projection cut: " << cutProj << endl; // get projected data set RooDataSet* data(0); if (kToyMc) data = (RooDataSet*)_fitDataToyMc->reduce(Cut(cutProj)); else data = (RooDataSet*)_fitData->reduce(Cut(cutProj)); //cout << pdf << " " << data << endl; assert(0); //cout << _fitDataToyMc->numEntries() << " " << data->numEntries() << endl; assert(0); if (data==0 || (data&&data->numEntries()==0)) { if (deps) delete deps; return; } // keep pointers to original qAB, qAC, qBC, recState, mD RooRealVar* qAB = _gFit->_qAB; RooRealVar* qAC = _gFit->_qAC; RooRealVar* qBC = _gFit->_qBC; RooCategory* recState = _gFit->_recState; RooRealVar* mD = _gFit->_mD; // define recState value (for pdf projections) recState->setLabel("Bminus"); // define pairs and pointers to independent variables //deps->Print("v"); RooRealVar *qPair1(0),*qPair2(0),*qPair3(0); EvtCyclic3::Pair pair1,pair2,pair3; RooRealVar* var = (RooRealVar*)deps->find(qAC->GetName()); if (var) { qPair1 = qAC; pair1 = EvtCyclic3::AC; } else { qPair3 = qAC; pair3 = EvtCyclic3::AC; } var = (RooRealVar*)deps->find(qAB->GetName()); if (var) { if (qPair1) { qPair2 = qAB; pair2 = EvtCyclic3::AB; } else { qPair1 = qAB; pair1 = EvtCyclic3::AB; } } else { qPair3 = qAB; pair3 = EvtCyclic3::AB; } var = (RooRealVar*)deps->find(qBC->GetName()); if (var) { if (qPair1) { if (qPair2) { qPair3 = qBC; pair3 = EvtCyclic3::BC; } else { qPair2 = qBC; pair2 = EvtCyclic3::BC; } } else { qPair1 = qBC; pair1 = EvtCyclic3::BC; } } else { qPair3 = qBC; pair3 = EvtCyclic3::BC; } assert(qPair1 != qPair2); assert(qPair1 != qPair3); assert(qPair2 != qPair3); if (get_mpi_rank()==0) cout << " Pair 1: " << pair1 << " " << qPair1->GetName() << " Pair 2: " << pair2 << " " << qPair2->GetName() << " Pair 3: " << pair3 << " " << qPair3->GetName() << endl; if (nice) { qAC->SetTitle("m_{-}^{2}"); qAC->setUnit("GeV^{2}/c^{4}"); qAB->SetTitle("m_{+}^{2}"); qAB->setUnit("GeV^{2}/c^{4}"); qBC->SetTitle("m^{2}_{#pi+#pi-}"); qBC->setUnit("GeV^{2}/c^{4}"); } // build Dalitz plot if (get_mpi_rank()==0) cout << "Making EvtDalitzPlot for decay mode : " << _gFit->_DdecayModeLF->getLabel() << endl; EvtDalitzPlot dp(EvtDecayMode(_gFit->_DdecayModeLF->getLabel())); // define qPair3, qPair2, qPair1 functions RooRealVar dpSum("dpSum","dpSum",dp.sum()); //cout << dpSum.getVal() << endl; assert(0); RooFormulaVar* qPair3_func = new RooFormulaVar(qPair3->GetName(),qPair3->GetTitle(),"@0-@1-@2",RooArgList(dpSum,*qPair1,*qPair2)); RooFormulaVar* qPair2_func = new RooFormulaVar(qPair2->GetName(),qPair2->GetTitle(),"@0-@1-@2",RooArgList(dpSum,*qPair1,*qPair3)); RooFormulaVar* qPair1_func = new RooFormulaVar(qPair1->GetName(),qPair1->GetTitle(),"@0-@1-@2",RooArgList(dpSum,*qPair2,*qPair3)); // define Dalitz plot limits Double_t qPair1min=dp.qAbsMin(pair1); Double_t qPair1max=dp.qAbsMax(pair1); Double_t qPair2min=dp.qAbsMin(pair2); Double_t qPair2max=dp.qAbsMax(pair2); Double_t qPair3min=dp.qAbsMin(pair3); Double_t qPair3max=dp.qAbsMax(pair3); if (nice) { TString name(qPair1->GetName()); if (name=="qAB" || name=="qAC") {qPair1min=0.3; qPair1max=3.1;} else {qPair1min=0.; qPair1max=2.0;} name=qPair2->GetName(); if (name=="qAB" || name=="qAC") {qPair2min=0.3; qPair2max=3.1;} else {qPair2min=0.; qPair2max=2.0;} name=qPair3->GetName(); if (name=="qAB" || name=="qAC") {qPair3min=0.3; qPair3max=3.1;} else {qPair3min=0.; qPair3max=2.0;} } qPair1->setRange(qPair1min,qPair1max); qPair1->setBins(nbins); qPair2->setRange(qPair2min,qPair2max); qPair2->setBins(nbins); qPair3->setRange(qPair3min,qPair3max); qPair3->setBins(nbins); // define boundary 2D Dalitz plot (assuming PDG mass for the mother, i.e. no lineshape) TGraph *grboundMax(0),*grboundMin(0); Int_t nbinsbound(10000); Double_t x[nbinsbound+1], ymin[nbinsbound+1], ymax[nbinsbound+1] ; for (Int_t i=0;i<=nbinsbound;i++) { Double_t qpair1 = (i/Double_t(nbinsbound))*(dp.qAbsMax(pair1)-dp.qAbsMin(pair1)) + dp.qAbsMin(pair1); if (i==0) qpair1 += 1e-15; if (i==nbinsbound) qpair1 -= 1e-15; x[i]=qpair1; ymin[i]=dp.qMin(pair2,pair1,qpair1) ; ymax[i]=dp.qMax(pair2,pair1,qpair1) ; } grboundMax = new TGraph(nbinsbound+1,x,ymax); grboundMin = new TGraph(nbinsbound+1,x,ymin); grboundMax->SetLineColor(kRed); grboundMin->SetLineColor(kRed); // create B+/B- dataset with same ordering of particles // for D0-> K_S0 pi+ pi-: AC=Ks pi- AB=Ks pi+ BC=pi+ pi- // for D0-> K+ K- K_S0 : AC=Ks K+ AB=K+ K- BC=Ks K- //TString formula("0.5*(1-@0)*@1+0.5*(1+@0)*@2"); //RooFormulaVar q12_func("q12","Invariant mass square of pair 12",formula,RooArgList(*_gFit->_recState,*qAB,*qAC)); //RooFormulaVar q13_func("q13","Invariant mass square of pair 13",formula,RooArgList(*_gFit->_recState,*qAC,*qAB)); //RooFormulaVar q23_func("q23","Invariant mass square of pair 23","@0",*qBC); TString formula12("(@0==1)*((@1==-1)*@2+(@1==+1)*@3) + (@0==2)*((@1==-1)*@2+(@1==+1)*@2)"); // 12=AB for B-, AC(AB) for B+ and Kspipi(KsKK) RooFormulaVar q12_func("q12","Invariant mass square of pair 12",formula12,RooArgList(*_gFit->_DdecayMode,*_gFit->_recState,*qAB,*qAC,*qBC)); TString formula13("(@0==1)*((@1==-1)*@3+(@1==+1)*@2) + (@0==2)*((@1==-1)*@3+(@1==+1)*@4)"); // 13=AC for B-, AB(BC) for B+ and Kspipi(KsKK) RooFormulaVar q13_func("q13","Invariant mass square of pair 13",formula13,RooArgList(*_gFit->_DdecayMode,*_gFit->_recState,*qAB,*qAC,*qBC)); TString formula23("(@0==1)*((@1==-1)*@4+(@1==+1)*@4) + (@0==2)*((@1==-1)*@4+(@1==+1)*@2)"); // 23=BC for B-, BC(AC) for B+ and Kspipi(KsKK) RooFormulaVar q23_func("q23","Invariant mass square of pair 23",formula23,RooArgList(*_gFit->_DdecayMode,*_gFit->_recState,*qAC,*qAB,*qBC)); RooRealVar* q12 = (RooRealVar*)q12_func.createFundamental(); RooRealVar* q13 = (RooRealVar*)q13_func.createFundamental(); RooRealVar* q23 = (RooRealVar*)q23_func.createFundamental(); (RooRealVar*) data->addColumn(q12_func) ; (RooRealVar*) data->addColumn(q13_func) ; (RooRealVar*) data->addColumn(q23_func) ; //RooArgSet data_common_vars(*qAC,*qAB,*qBC,*recState); RooArgSet data_common_vars(*qAC,*qAB,*qBC); //RooArgSet data_common_vars(*qAC,*qAB,*qBC,*mD); RooDataSet* data_common = new RooDataSet("data_common","data_common",data_common_vars); //qPair3 = (RooRealVar*) data->get(0)->find(qPair3->GetName()); //if (qPair3==0) qPair3 = (RooRealVar*) data->addColumn(*qPair3_func) ; for (Int_t iEvt=0;iEvtnumEntries();iEvt++) { const RooArgSet* columns = data->get(iEvt); //columns->Print("v"); //assert(0); RooRealVar* q12_col = (RooRealVar*)columns->find(q12->GetName()); RooRealVar* q13_col = (RooRealVar*)columns->find(q13->GetName()); RooRealVar* q23_col = (RooRealVar*)columns->find(q23->GetName()); //RooCategory* recState_col = (RooCategory*)columns->find(recState->GetName()); qAB->setVal(q12_col->getVal()); qAC->setVal(q13_col->getVal()); qBC->setVal(q23_col->getVal()); //recState->setIndex(recState_col->getIndex()); //if (recState_col->getIndex()==-1) //RooRealVar* mD_col = (RooRealVar*)columns->find(mD->GetName()); //mD->setVal(mD_col->getVal()); data_common->add(data_common_vars); } // Dalitz plots if (opt=="Dalitz") { // // TCanvas *c1 = new TCanvas("c1","allevents",600,600); TString file(file_root); Bool_t makeProjs(kTRUE); if (makeProjs) { // start projections //******************************************************************** //setting particle conventions Double_t mD0_nom = 1.8645; Double_t mKs_nom = 0.49767; Double_t mK_nom = 0.49368; Double_t mPi_nom = 0.139570; Double_t mTrk_nom = (DMode=="KsPiPi")? mPi_nom : mK_nom; Double_t massD = mD0_nom; Double_t mass1 = mKs_nom; Double_t mass2 = mTrk_nom; Double_t mass3 = mTrk_nom; //*********************************************************************** // plotting harmonics from data TH1F *q12_Original = new TH1F("q12_Original","q12_Original",nbins,qPair2->getMin()+1.5e-02,qPair2->getMax()-1.5e-02); TH1F *q13_Original = new TH1F("q13_Original","q13_Original",nbins,qPair1->getMin()+1.5e-02,qPair1->getMax()-1.5e-02); TH1F *q23_Original = new TH1F("q23_Original","q23_Original",nbins,qPair3->getMin()+1.5e-02,qPair3->getMax()-1.5e-02); TH1F *q12_Y00 = new TH1F("q12_Y00","q12_Y00",nbins,qPair2->getMin()+1.5e-02,qPair2->getMax()-1.5e-02); TH1F *q13_Y00 = new TH1F("q13_Y00","q13_Y00",nbins,qPair1->getMin()+1.5e-02,qPair1->getMax()-1.5e-02); TH1F *q23_Y00 = new TH1F("q23_Y00","q23_Y00",nbins,qPair3->getMin()+1.5e-02,qPair3->getMax()-1.5e-02); TH1F *q12_Y10 = new TH1F("q12_Y10","q12_Y10",nbins,qPair2->getMin()+1.5e-02,qPair2->getMax()-1.5e-02); TH1F *q13_Y10 = new TH1F("q13_Y10","q13_Y10",nbins,qPair1->getMin()+1.5e-02,qPair1->getMax()-1.5e-02); TH1F *q23_Y10 = new TH1F("q23_Y10","q23_Y10",nbins,qPair3->getMin()+1.5e-02,qPair3->getMax()-1.5e-02); TH1F *q12_Y20 = new TH1F("q12_Y20","q12_Y20",nbins,qPair2->getMin()+1.5e-02,qPair2->getMax()-1.5e-02); TH1F *q13_Y20 = new TH1F("q13_Y20","q13_Y20",nbins,qPair1->getMin()+1.5e-02,qPair1->getMax()-1.5e-02); TH1F *q23_Y20 = new TH1F("q23_Y20","q23_Y20",nbins,qPair3->getMin()+1.5e-02,qPair3->getMax()-1.5e-02); TH1F *q12_Y30 = new TH1F("q12_Y30","q12_Y30",nbins,qPair2->getMin()+1.5e-02,qPair2->getMax()-1.5e-02); TH1F *q13_Y30 = new TH1F("q13_Y30","q13_Y30",nbins,qPair1->getMin()+1.5e-02,qPair1->getMax()-1.5e-02); TH1F *q23_Y30 = new TH1F("q23_Y30","q23_Y30",nbins,qPair3->getMin()+1.5e-02,qPair3->getMax()-1.5e-02); TH1F *q12_Y40 = new TH1F("q12_Y40","q12_Y40",nbins,qPair2->getMin()+1.5e-02,qPair2->getMax()-1.5e-02); TH1F *q13_Y40 = new TH1F("q13_Y40","q13_Y40",nbins,qPair1->getMin()+1.5e-02,qPair1->getMax()-1.5e-02); TH1F *q23_Y40 = new TH1F("q23_Y40","q23_Y40",nbins,qPair3->getMin()+1.5e-02,qPair3->getMax()-1.5e-02); //MC TH1F *q12_Original_MC = new TH1F("q12_Original_MC","q12_Original_MC",nbins,qPair2->getMin()+1.5e-02,qPair2->getMax()-1.5e-02); TH1F *q13_Original_MC = new TH1F("q13_Original_MC","q13_Original_MC",nbins,qPair1->getMin()+1.5e-02,qPair1->getMax()-1.5e-02); TH1F *q23_Original_MC = new TH1F("q23_Original_MC","q23_Original_MC",nbins,qPair3->getMin()+1.5e-02,qPair3->getMax()-1.5e-02); TH1F *q12_Y00_MC = new TH1F("q12_Y00_MC","q12_Y00_MC",nbins,qPair2->getMin()+1.5e-02,qPair2->getMax()-1.5e-02); TH1F *q13_Y00_MC = new TH1F("q13_Y00_MC","q13_Y00_MC",nbins,qPair1->getMin()+1.5e-02,qPair1->getMax()-1.5e-02); TH1F *q23_Y00_MC = new TH1F("q23_Y00_MC","q23_Y00_MC",nbins,qPair3->getMin()+1.5e-02,qPair3->getMax()-1.5e-02); TH1F *q12_Y10_MC = new TH1F("q12_Y10_MC","q12_Y10_MC",nbins,qPair2->getMin()+1.5e-02,qPair2->getMax()-1.5e-02); TH1F *q13_Y10_MC = new TH1F("q13_Y10_MC","q13_Y10_MC",nbins,qPair1->getMin()+1.5e-02,qPair1->getMax()-1.5e-02); TH1F *q23_Y10_MC = new TH1F("q23_Y10_MC","q23_Y10_MC",nbins,qPair3->getMin()+1.5e-02,qPair3->getMax()-1.5e-02); TH1F *q12_Y20_MC = new TH1F("q12_Y20_MC","q12_Y20_MC",nbins,qPair2->getMin()+1.5e-02,qPair2->getMax()-1.5e-02); TH1F *q13_Y20_MC = new TH1F("q13_Y20_MC","q13_Y20_MC",nbins,qPair1->getMin()+1.5e-02,qPair1->getMax()-1.5e-02); TH1F *q23_Y20_MC = new TH1F("q23_Y20_MC","q23_Y20_MC",nbins,qPair3->getMin()+1.5e-02,qPair3->getMax()-1.5e-02); TH1F *q12_Y30_MC = new TH1F("q12_Y30_MC","q12_Y30_MC",nbins,qPair2->getMin()+1.5e-02,qPair2->getMax()-1.5e-02); TH1F *q13_Y30_MC = new TH1F("q13_Y30_MC","q13_Y30_MC",nbins,qPair1->getMin()+1.5e-02,qPair1->getMax()-1.5e-02); TH1F *q23_Y30_MC = new TH1F("q23_Y30_MC","q23_Y30_MC",nbins,qPair3->getMin()+1.5e-02,qPair3->getMax()-1.5e-02); TH1F *q12_Y40_MC = new TH1F("q12_Y40_MC","q12_Y40_MC",nbins,qPair2->getMin()+1.5e-02,qPair2->getMax()-1.5e-02); TH1F *q13_Y40_MC = new TH1F("q13_Y40_MC","q13_Y40_MC",nbins,qPair1->getMin()+1.5e-02,qPair1->getMax()-1.5e-02); TH1F *q23_Y40_MC = new TH1F("q23_Y40_MC","q23_Y40_MC",nbins,qPair3->getMin()+1.5e-02,qPair3->getMax()-1.5e-02); if (get_mpi_rank()==0) cout << "RooDKFitMaster::makeHarmonicsPlots: Filling Histos for Data: " << pdfComp << endl; for (Int_t iEvt=0;iEvtnumEntries();iEvt++) { const RooArgSet* columns = data_common->get(iEvt); RooRealVar* myq12 = (RooRealVar*)columns->find(qAB->GetName()); RooRealVar* myq13 = (RooRealVar*)columns->find(qAC->GetName()); RooRealVar* myq23 = (RooRealVar*)columns->find(qBC->GetName()); Double_t q12_val = myq12->getVal(); Double_t q13_val = myq13->getVal(); Double_t q23_val = myq23->getVal(); //original q12_Original->Fill(q12_val); q13_Original->Fill(q13_val); q23_Original->Fill(q23_val); //Y00 Double_t q12_Y00w = giveMeHarmonics(massD,mass1,mass3,mass2,q12_val,q13_val,0,1.); Double_t q13_Y00w = giveMeHarmonics(massD,mass1,mass2,mass3,q13_val,q12_val,0,1.); Double_t q23_Y00w = giveMeHarmonics(massD,mass3,mass1,mass2,q23_val,q13_val,0,1.); q12_Y00->Fill(q12_val,q12_Y00w); q13_Y00->Fill(q13_val,q13_Y00w); q23_Y00->Fill(q23_val,q23_Y00w); //Y10 Double_t q12_Y10w = giveMeHarmonics(massD,mass1,mass3,mass2,q12_val,q13_val,1,1.); Double_t q13_Y10w = giveMeHarmonics(massD,mass1,mass2,mass3,q13_val,q12_val,1,1.); Double_t q23_Y10w = giveMeHarmonics(massD,mass3,mass1,mass2,q23_val,q13_val,1,1.); q12_Y10->Fill(q12_val,q12_Y10w); q13_Y10->Fill(q13_val,q13_Y10w); q23_Y10->Fill(q23_val,q23_Y10w); //Y20 Double_t q12_Y20w = giveMeHarmonics(massD,mass1,mass3,mass2,q12_val,q13_val,2,1.); Double_t q13_Y20w = giveMeHarmonics(massD,mass1,mass2,mass3,q13_val,q12_val,2,1.); Double_t q23_Y20w = giveMeHarmonics(massD,mass3,mass1,mass2,q23_val,q13_val,2,1.); q12_Y20->Fill(q12_val,q12_Y20w); q13_Y20->Fill(q13_val,q13_Y20w); q23_Y20->Fill(q23_val,q23_Y20w); //Y30 Double_t q12_Y30w = giveMeHarmonics(massD,mass1,mass3,mass2,q12_val,q13_val,3,1.); Double_t q13_Y30w = giveMeHarmonics(massD,mass1,mass2,mass3,q13_val,q12_val,3,1.); Double_t q23_Y30w = giveMeHarmonics(massD,mass3,mass1,mass2,q23_val,q13_val,3,1.); q12_Y30->Fill(q12_val,q12_Y30w); q13_Y30->Fill(q13_val,q13_Y30w); q23_Y30->Fill(q23_val,q23_Y30w); //Y40 Double_t q12_Y40w = giveMeHarmonics(massD,mass1,mass3,mass2,q12_val,q13_val,4,1.); Double_t q13_Y40w = giveMeHarmonics(massD,mass1,mass2,mass3,q13_val,q12_val,4,1.); Double_t q23_Y40w = giveMeHarmonics(massD,mass3,mass1,mass2,q23_val,q13_val,4,1.); q12_Y40->Fill(q12_val,q12_Y40w); q13_Y40->Fill(q13_val,q13_Y40w); q23_Y40->Fill(q23_val,q23_Y40w); } if (get_mpi_rank()==0) cout << "RooDKFitMaster::makeHarmonicsPlots: Generating MC from pdf: " << pdfComp << endl; RooDataSet *data_common_mc = pdf->generate(RooArgSet(*qAC,*qAB),nevtsToyMc); //data_common_mc->addColumn(q23_func); Double_t f = (Double_t)data_common->numEntries()/nevtsToyMc; if (get_mpi_rank()==0) cout<numEntries()<<" "<numEntries()<<" "<numEntries();iEvt++) { const RooArgSet* columns_mc = data_common_mc->get(iEvt); RooRealVar* myq12_mc = (RooRealVar*)columns_mc->find(qAB->GetName()); RooRealVar* myq13_mc = (RooRealVar*)columns_mc->find(qAC->GetName()); Double_t myq23_mc = dp.sum()-myq12_mc->getVal()-myq13_mc->getVal(); Double_t q12_val = myq12_mc->getVal(); Double_t q13_val = myq13_mc->getVal(); Double_t q23_val = myq23_mc; //original q12_Original_MC->Fill(q12_val,f); q13_Original_MC->Fill(q13_val,f); q23_Original_MC->Fill(q23_val,f); //Y00 Double_t q12_Y00w = giveMeHarmonics(massD,mass1,mass3,mass2,q12_val,q13_val,0,f); Double_t q13_Y00w = giveMeHarmonics(massD,mass1,mass2,mass3,q13_val,q12_val,0,f); Double_t q23_Y00w = giveMeHarmonics(massD,mass3,mass1,mass2,q23_val,q13_val,0,f); q12_Y00_MC->Fill(q12_val,q12_Y00w); q13_Y00_MC->Fill(q13_val,q13_Y00w); q23_Y00_MC->Fill(q23_val,q23_Y00w); //Y10 Double_t q12_Y10w = giveMeHarmonics(massD,mass1,mass3,mass2,q12_val,q13_val,1,f); Double_t q13_Y10w = giveMeHarmonics(massD,mass1,mass2,mass3,q13_val,q12_val,1,f); Double_t q23_Y10w = giveMeHarmonics(massD,mass3,mass1,mass2,q23_val,q13_val,1,f); q12_Y10_MC->Fill(q12_val,q12_Y10w); q13_Y10_MC->Fill(q13_val,q13_Y10w); q23_Y10_MC->Fill(q23_val,q23_Y10w); //Y20 Double_t q12_Y20w = giveMeHarmonics(massD,mass1,mass3,mass2,q12_val,q13_val,2,f); Double_t q13_Y20w = giveMeHarmonics(massD,mass1,mass2,mass3,q13_val,q12_val,2,f); Double_t q23_Y20w = giveMeHarmonics(massD,mass3,mass1,mass2,q23_val,q13_val,2,f); q12_Y20_MC->Fill(q12_val,q12_Y20w); q13_Y20_MC->Fill(q13_val,q13_Y20w); q23_Y20_MC->Fill(q23_val,q23_Y20w); //Y30 Double_t q12_Y30w = giveMeHarmonics(massD,mass1,mass3,mass2,q12_val,q13_val,3,f); Double_t q13_Y30w = giveMeHarmonics(massD,mass1,mass2,mass3,q13_val,q12_val,3,f); Double_t q23_Y30w = giveMeHarmonics(massD,mass3,mass1,mass2,q23_val,q13_val,3,f); q12_Y30_MC->Fill(q12_val,q12_Y30w); q13_Y30_MC->Fill(q13_val,q13_Y30w); q23_Y30_MC->Fill(q23_val,q23_Y30w); //Y40 Double_t q12_Y40w = giveMeHarmonics(massD,mass1,mass3,mass2,q12_val,q13_val,4,f); Double_t q13_Y40w = giveMeHarmonics(massD,mass1,mass2,mass3,q13_val,q12_val,4,f); Double_t q23_Y40w = giveMeHarmonics(massD,mass3,mass1,mass2,q23_val,q13_val,4,f); q12_Y40_MC->Fill(q12_val,q12_Y40w); q13_Y40_MC->Fill(q13_val,q13_Y40w); q23_Y40_MC->Fill(q23_val,q23_Y40w); //cout<<"values: "< SetFillColor(10); c12 -> SetTitle(""); c12->Divide(2,3); c12->cd(1); //q12_Original_MC->Print("all"); q12_Original->Draw(""); q12_Original_MC->Draw("SAME C"); q12_Original_MC->SetLineColor(2); q12_Original->GetXaxis()->SetTitle(qPair2->GetName()); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair2->GetName()); file.Append("_Original.eps"); if (get_mpi_rank()==0) c12->cd(1)->Print(file); c12->cd(2); q12_Y00->Draw(""); q12_Y00_MC->Draw("SAME C"); q12_Y00_MC->SetLineColor(2); q12_Y00->GetXaxis()->SetTitle(qPair2->GetName()); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair2->GetName()); file.Append("_Y00.eps"); if (get_mpi_rank()==0) c12->cd(2)->Print(file); c12->cd(3); q12_Y10->Draw(""); q12_Y10_MC->Draw("SAME C"); q12_Y10_MC->SetLineColor(2); q12_Y10->GetXaxis()->SetTitle(qPair2->GetName()); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair2->GetName()); file.Append("_Y10.eps"); if (get_mpi_rank()==0) c12->cd(3)->Print(file); c12->cd(4); //q12_Y20_MC->Print("all"); q12_Y20->Draw(""); q12_Y20_MC->Draw("SAME C"); q12_Y20_MC->SetLineColor(2); q12_Y20->GetXaxis()->SetTitle(qPair2->GetName()); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair2->GetName()); file.Append("_Y20.eps"); if (get_mpi_rank()==0) c12->cd(4)->Print(file); c12->cd(5); q12_Y30->Draw(""); q12_Y30_MC->Draw("SAME C"); q12_Y30_MC->SetLineColor(2); q12_Y30->GetXaxis()->SetTitle(qPair2->GetName()); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair2->GetName()); file.Append("_Y30.eps"); if (get_mpi_rank()==0) c12->cd(5)->Print(file); c12->cd(6); q12_Y40->Draw(""); q12_Y40_MC->Draw("SAME C"); q12_Y40_MC->SetLineColor(2); q12_Y40->GetXaxis()->SetTitle(qPair2->GetName()); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair2->GetName()); file.Append("_Y40.eps"); if (get_mpi_rank()==0) c12->cd(6)->Print(file); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair2->GetName()); file.Append("_Summary.eps"); if (get_mpi_rank()==0) c12->Print(file); // delete c12; TCanvas *c13 = new TCanvas("c13","allevents13",500,500); c13 -> SetFillColor(10); c13 -> SetTitle(""); c13->Divide(2,3); c13->cd(1); //q13_Original_MC->Print("all"); q13_Original->Draw(""); q13_Original_MC->Draw("SAME C"); q13_Original_MC->SetLineColor(2); q13_Original->GetXaxis()->SetTitle(qPair1->GetName()); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair1->GetName()); file.Append("_Original.eps"); if (get_mpi_rank()==0) c13->cd(1)->Print(file); c13->cd(2); q13_Y00->Draw(""); q13_Y00_MC->Draw("SAME C"); q13_Y00_MC->SetLineColor(2); q13_Y00->GetXaxis()->SetTitle(qPair1->GetName()); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair1->GetName()); file.Append("_Y00.eps"); if (get_mpi_rank()==0) c13->cd(2)->Print(file); c13->cd(3); q13_Y10->Draw(""); q13_Y10_MC->Draw("SAME C"); q13_Y10_MC->SetLineColor(2); q13_Y10->GetXaxis()->SetTitle(qPair1->GetName()); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair1->GetName()); file.Append("_Y10.eps"); if (get_mpi_rank()==0) c13->cd(3)->Print(file); c13->cd(4); //q13_Y20_MC->Print("all"); q13_Y20->Draw(""); q13_Y20_MC->Draw("SAME C"); q13_Y20_MC->SetLineColor(2); q13_Y20->GetXaxis()->SetTitle(qPair1->GetName()); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair1->GetName()); file.Append("_Y20.eps"); if (get_mpi_rank()==0) c13->cd(4)->Print(file); c13->cd(5); q13_Y30->Draw(""); q13_Y30_MC->Draw("SAME C"); q13_Y30_MC->SetLineColor(2); q13_Y30->GetXaxis()->SetTitle(qPair1->GetName()); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair1->GetName()); file.Append("_Y30.eps"); if (get_mpi_rank()==0) c13->cd(5)->Print(file); c13->cd(6); q13_Y40->Draw(""); q13_Y40_MC->Draw("SAME C"); q13_Y40_MC->SetLineColor(2); q13_Y40->GetXaxis()->SetTitle(qPair1->GetName()); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair1->GetName()); file.Append("_Y40.eps"); if (get_mpi_rank()==0) c13->cd(6)->Print(file); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair1->GetName()); file.Append("_Summary.eps"); if (get_mpi_rank()==0) c13->Print(file); TCanvas *c23 = new TCanvas("c23","allevents23",500,500); c23 -> SetFillColor(10); c23 -> SetTitle(""); c23->Divide(2,3); c23->cd(1); //q23_Original_MC->Print("all"); q23_Original->Draw(""); q23_Original_MC->Draw("SAME C"); q23_Original_MC->SetLineColor(2); q23_Original->GetXaxis()->SetTitle(qPair3->GetName()); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair3->GetName()); file.Append("_Original.eps"); if (get_mpi_rank()==0) c23->cd(1)->Print(file); c23->cd(2); q23_Y00->Draw(""); q23_Y00_MC->Draw("SAME C"); q23_Y00_MC->SetLineColor(2); q23_Y00->GetXaxis()->SetTitle(qPair3->GetName()); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair3->GetName()); file.Append("_Y00.eps"); if (get_mpi_rank()==0) c23->cd(2)->Print(file); c23->cd(3); q23_Y10->Draw(""); q23_Y10_MC->Draw("SAME C"); q23_Y10_MC->SetLineColor(2); q23_Y10->GetXaxis()->SetTitle(qPair3->GetName()); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair3->GetName()); file.Append("_Y10.eps"); if (get_mpi_rank()==0) c23->cd(3)->Print(file); c23->cd(4); //q23_Y20_MC->Print("all"); q23_Y20->Draw(""); q23_Y20_MC->Draw("SAME C"); q23_Y20_MC->SetLineColor(2); q23_Y20->GetXaxis()->SetTitle(qPair3->GetName()); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair3->GetName()); file.Append("_Y20.eps"); if (get_mpi_rank()==0) c23->cd(4)->Print(file); c23->cd(5); q23_Y30->Draw(""); q23_Y30_MC->Draw("SAME C"); q23_Y30_MC->SetLineColor(2); q23_Y30->GetXaxis()->SetTitle(qPair3->GetName()); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair3->GetName()); file.Append("_Y30.eps"); if (get_mpi_rank()==0) c23->cd(5)->Print(file); c23->cd(6); q23_Y40->Draw(""); q23_Y40_MC->Draw("SAME C"); q23_Y40_MC->SetLineColor(2); q23_Y40->GetXaxis()->SetTitle(qPair3->GetName()); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair3->GetName()); file.Append("_Y40.eps"); if (get_mpi_rank()==0) c23->cd(6)->Print(file); file=file_root; file.Append(opt); if (epsfile_suffix) file.Append(epsfile_suffix); file.Append(qPair3->GetName()); file.Append("_Summary.eps"); if (get_mpi_rank()==0) c23->Print(file); delete data_common_mc; } // end projections // } delete data; delete data_common; delete qPair3_func; delete qPair2_func; delete qPair1_func; delete q12; delete q13; delete colors; } Double_t RooDKFitMaster::giveMeHarmonics(Double_t m, Double_t m1, Double_t m2, Double_t m3, Double_t m2rest, Double_t m2angle, Int_t L, Double_t f) { Double_t out(0.); Double_t A = (m*m-m2rest-m2*m2)*(m2rest+m1*m1-m3*m3); Double_t B = 2.*m2rest*(m1*m1+m2*m2-m2angle); Double_t C = sqrt(m2rest*m2rest+m1*m1*m1*m1+m3*m3*m3*m3-2.*m2rest*m1*m1-2.*m2rest*m3*m3-2.*m1*m1*m3*m3); Double_t D = sqrt(m2rest*m2rest+m*m*m*m+m2*m2*m2*m2-2.*m2rest*m*m-2.*m2rest*m2*m2-2.*m*m*m2*m2); Double_t coshel = (A+B)/((C*D)+1e-7); if(L==0) out = 1./sqrt(2.); else if(L==1) out = sqrt(3./2.)*coshel; else if(L==2) out = sqrt(5./2.)*0.5*(3.*coshel*coshel-1.); else if(L==3) out = sqrt(7./2.)*0.5*(5.*coshel*coshel*coshel-3.*coshel); else if(L==4) out = sqrt(9./2.)*(1./8.)*(35*coshel*coshel*coshel*coshel-30.*coshel*coshel+3.); else assert(0); if((out*f==0)||(out*f>1e7)) if (get_mpi_rank()==0) cout<<"giveMeHarmonics:: WARNING, zero or huge weigth: "<_DdecayMode->typeIterator() ; while (RooCatType* type = (RooCatType*)tIter->Next()) { if (type->getVal()==indexCatDdecayMode) break; index++; } delete tIter; return index; } Int_t RooDKFitMaster::getIndexCat(TString catDdecayMode) const { Int_t index(0); TIterator *tIter = _gFit->_DdecayMode->typeIterator() ; while (RooCatType* type = (RooCatType*)tIter->Next()) { if (type->GetName()==catDdecayMode) break; index++; } delete tIter; return index; } void RooDKFitMaster::randomizePhysParams(RooArgSet& params) { assert(_generator); TIterator* iter = params.createIterator(); RooRealVar* item; while (item = (RooRealVar*)iter->Next()) { TString title(item->GetTitle()); TString name(item->GetName()); if (title.Contains("(PHYS)") && !item->getAttribute("Constant")) { Double_t newval = _generator->Gaus(item->getVal(),item->getError()); item->setVal(newval); } } delete iter; } /* void RooDKFitMaster::numericIntegrationDalitz(RooAbsPdf* pdf, RooRealVar* qPair_integral, RooRealVar* qPair_plot, RooPlot* xframe, Int_t nEvents, Double_t norm, TString subPdfName) { Double_t frac(0.); RooAbsPdf* newPdf(0); //first we look for the correct pdf if(subPdfName == "0"){ frac = 1.; newPdf = pdf; }else{ RooArgList pdfList = dynamic_cast(pdf)->pdfList(); RooArgList pdfCoef = dynamic_cast(pdf)->coefList(); cout<<"RooDKFitMaster::numericIntegrationDalitz: List of components"<Next())){ indexComponent++; TString name(component->GetName()); if(name.BeginsWith(subPdfName)){ newPdf = component; } else break; } RooRealVar* fracVar; if(isExtended){ fracVar = (RooRealVar*)pdfCoef.at(indexComponent); frac = fracVar->getVal(); }else{ if(indexComponent < (nComponents-1)){ fracVar = (RooRealVar*)pdfCoef.at(indexComponent); frac = fracVar->getVal(); }else{ Double_t pdfCoefSum(0); for(Int_t j=0;j<(nComponents-1);j++) { fracVar = (RooRealVar*)pdfCoef.at(j); pdfCoefSum += fracVar->getVal(); } frac = 1-pdfCoefSum; } } cout<GetName()<<" with coef. "<getVal(); cout<<"RooDKFitMaster::numericIntegrationDalitz with ("<getMin(); TH1F *hist = new TH1F("histo","histo",steps,qPair_plot->getMin(),qPair_plot->getMax()); // memory leak warnings // projection cout<<"RooDKFitMaster::numericIntegrationDalitz: Calculating projection..."<getMax()-qPair_plot->getMin())/steps; Double_t pos_plot = (Double_t)init_plot+i*step_plot; qPair_plot->setVal(pos_plot); Double_t init_integral = qPair_integral->getMin(); Double_t intValue = 0.; Double_t step_integral = (Double_t)fabs(qPair_integral->getMax()-qPair_integral->getMin())/steps; for(Int_t j=0 ; jsetVal(pos_integral); Double_t pdf_before = newPdf->getVal(); qPair_integral->setVal(pos_integral_inc); Double_t pdf_after = newPdf->getVal(); // int intValue = intValue; //intValue += pdf_before*step_integral; //rectangle //intValue += fabs(pdf_before-pdf_after)*step_integral/2.; //triangle qPair_integral->setVal(pos_integral+step_integral/2.); intValue += newPdf->getVal()*step_integral; } cout << "intValue Diego = " << intValue << endl; RooArgSet normSet(*qPair_integral); //RooRealIntegral pdf_integral("pdf_integral","pdf_integral",*newPdf,normSet); //intValue = pdf_integral.getVal(); intValue = newPdf->getVal(&normSet); cout << "intValue pdf = " << intValue << endl; //pdf->getParameters(RooArgSet())->Print("v"); assert(0); Double_t norm_coeff = frac*nEvents*fabs(qPair_plot->getMax()-qPair_plot->getMin())/(norm*xframe->GetNbinsX()); intValue *= norm_coeff; //cout<<"Position_3: "<SetBinContent(i+1,intValue); } //assert(0); // TH1* histToPlot(0); histToPlot = hist; xframe->addTH1(histToPlot,"L"); //delete hist; } Double_t RooDKFitMaster::numericIntegrationDalitzNorm(RooAbsPdf* pdf, RooRealVar* qPairA, RooRealVar* qPairB) { Int_t steps = (Int_t)_nBins2DNorm->getVal(); Double_t norm_tot_int = 0.; Double_t value_before = 0; Double_t value_tot_int_init = 0; Double_t init_B = qPairB->getMin(); cout<<"RooDKFitMaster::numericIntegrationDalitzNorm with ("<getMax()-qPairB->getMin())/steps; Double_t norm_pos_B = (Double_t)init_B+i*norm_step_B; qPairB->setVal(norm_pos_B); Double_t norm_init_A = qPairA->getMin(); Double_t norm_step_A = (Double_t)fabs(qPairA->getMax()-qPairA->getMin())/steps; Double_t norm_intValue = 0.; for(Int_t j=0 ; jsetVal(norm_pos_A); Double_t norm_pdf_before = pdf->getVal(); qPairA->setVal(norm_pos_A_inc); Double_t norm_pdf_after = pdf->getVal(); // int norm_intValue = norm_intValue; //norm_intValue += norm_pdf_before*norm_step_A; //rectangle //norm_intValue += fabs(norm_pdf_before-norm_pdf_after)*norm_step_A/2.; //triangle qPairA->setVal(norm_pos_A+norm_step_A/2.); qPairB->setVal(norm_pos_B+norm_step_B/2.); RooArgSet normSet(*qPairA,*qPairB); norm_intValue += pdf->getVal(&normSet)*norm_step_A; } norm_tot_int = value_tot_int_init; norm_tot_int += norm_intValue*norm_step_B;//rectangle //norm_tot_int += fabs(norm_intValue-value_before)*norm_step_B/2.;//triangle value_before = norm_intValue; value_tot_int_init = norm_tot_int; //cout<<"Value this point: "<0) return; // set decay modes _gFit->_DdecayMode->setLabel(DMode); _gFit->_DdecayModeLF->setIndex(_gFit->_DdecayMode->getIndex()); _gFit->_BdecayMode->setLabel(BMode); _gFit->_BdecayModeLF->setIndex(_gFit->_BdecayMode->getIndex()); // pdf component name TString pdfComp("{"); pdfComp.Append(DMode); pdfComp.Append(";"); pdfComp.Append(BMode); pdfComp.Append("}"); cout << "RooDKFitMaster::dumpDalitzAmplitude(): Pdf component: " << pdfComp << endl; TString filename = "results/DalitzAmplitude_" + DMode + ".dat"; // get PDF RooAbsPdf* pdf = (_pdfGlobal)? (RooAbsPdf*)_pdfGlobal->getPdf(pdfComp) : 0; if (pdf==0) return; // output stream ofstream ofs(filename) ; if (ofs.fail()) { cout << "RooDKFitMaster::dumpDalitzAmplitude(): error opening file " << filename << endl ; return; } ostream& os = ofs; // dump fit fractions for Dstar samples TString pdfNameComp(pdfNameCompRoot); pdfNameComp += "_{"; pdfNameComp += BMode; pdfNameComp += ";"; pdfNameComp += DMode; pdfNameComp += "}"; RooArgSet* components = pdf->getComponents(); //cout<< "print components"<Print("v"); RooDKPdfMaker* pdfDalitz = (RooDKPdfMaker*)components->find(pdfNameComp); //RooDKPdfMaker* pdfDalitz = dynamic_cast(pdf); if (pdfDalitz==0) pdfDalitz = (RooDKPdfMaker*)components->find(pdfNameComp+"_cust"); if (pdfDalitz) { cout << "Evaluating fit fractions for PDF name = " << pdfDalitz->GetName() << endl; //We have the SigDalitzPDF at this point RooArgSet* deps(0); deps = pdfDalitz->getDependents(_gFit->_selDataVars); deps->Print("v"); //RooRealVar* qAB = (RooRealVar*)deps->find("qAB"); //RooRealVar* qAC = (RooRealVar*)deps->find("qAC"); RooCategory* recState = _gFit->_recState; recState->setLabel("Bplus"); //Defining knematic boundaries double mD0_nom = 1.8645; double mKs_nom = 0.49767; double mPi_nom = 0.139570; double mK_nom = 0.49368; double mTrk_nom = (DMode=="KsPiPi")? mPi_nom : mK_nom ; double qAB_min = pow(mKs_nom+mTrk_nom,2); double qAC_min = pow(mKs_nom+mTrk_nom,2); double qBC_min = pow(2*mTrk_nom,2); double qAB_max = pow(mD0_nom-mTrk_nom,2); double qAC_max = pow(mD0_nom-mTrk_nom,2); double qBC_max = pow(mD0_nom-mKs_nom,2); //double pair1_min = (DMode=="KsPiPi")? qAB_min : qBC_min; //double pair1_max = (DMode=="KsPiPi")? qAB_max : qBC_max; //double pair2_min = (DMode=="KsPiPi")? qAC_min : qAB_min; //double pair2_max = (DMode=="KsPiPi")? qAC_max : qAB_max; double pair1_min = (DMode=="KsPiPi")? qAB_min : qAB_min; double pair1_max = (DMode=="KsPiPi")? qAB_max : qAB_max; double pair2_min = (DMode=="KsPiPi")? qAC_min : qBC_min; double pair2_max = (DMode=="KsPiPi")? qAC_max : qBC_max; double step1 = (double)(pair1_max-pair1_min)/nbin; double step2 = (double)(pair2_max-pair2_min)/nbin; double N=0; for(Int_t i=1 ; i<=nbin; i++){ double pos1 = pair1_min + double(i*step1) - step1/2.; for(Int_t j=1 ; j<=nbin; j++){ double pos2 = pair2_min + double(j*step2) - step2/2.; // double pos3 = pow(mD0_nom,2)+2.*pow(mTrk_nom,2)+pow(mKs_nom,2)-pos1-pos2; EvtComplex amplitude = pdfDalitz->evaluateDalitzAmplitude(pos1, pos2); if((real(amplitude) == -999) && (imag(amplitude) == -999)) continue; else{ N=N+abs2(amplitude)*step1*step2; } } } double norm=0; for(Int_t i=1 ; i<=nbin; i++){ double pos1 = pair1_min + double(i*step1) - step1/2.; for(Int_t j=1 ; j<=nbin; j++){ double pos2 = pair2_min + double(j*step2) - step2/2.; double pos3 = pow(mD0_nom,2)+2.*pow(mTrk_nom,2)+pow(mKs_nom,2)-pos1-pos2; EvtComplex amplitude = pdfDalitz->evaluateDalitzAmplitude(pos1, pos2); if((real(amplitude) == -999) && (imag(amplitude) == -999)) continue; else { //cout << recState->getLabel() << " " << pos1 << " " << pos2 << " " << pos3 << " " << real(amplitude) << " " << imag(amplitude) << " " << abs(amplitude) << " " << arg(amplitude) << " " << abs2(amplitude) << endl; ofs << pos1 << " " << pos2 << " " << pos3 << " " << arg(amplitude) << " " << abs2(amplitude)/N << endl; } norm=norm+abs2(amplitude)/N*step1*step2; // cout<<"norm="<0) return; RooFitResult* fitSelResults = _fitSelResults; if (kToyMcResults) fitSelResults = _fitSelResultsToyMc; RooFitResult* fitResults = _fitResults; if (kToyMcResults) fitResults = _fitResultsToyMc; RooFitResult* fitMIResults = _fitMIResults; if (kToyMcResults) fitMIResults = _fitMIResultsToyMc; //cout << fitSelResults << " " << fitResults << " " << fitMIResults << endl; dumpParametersToAscii(fitSelResults,fitResults,fitMIResults,asciifile); //dump auxiliary file results_input dumpParametersToAscii_input(asciifile); } void RooDKFitMaster::dumpParametersToAscii(const char* rootfile,const char* asciifile) { if (get_mpi_rank()>0) return; TFile f(rootfile,"read") ; RooFitResult* fitSelResults = (RooFitResult*)f.Get("fitSelResults"); RooFitResult* fitResults = (RooFitResult*)f.Get("fitResults"); RooFitResult* fitMIResults = (RooFitResult*)f.Get("fitMIResults"); dumpParametersToAscii(fitSelResults,fitResults,fitMIResults,asciifile); f.Close(); } void RooDKFitMaster::dumpParametersToAscii(RooFitResult* fitSelResults, RooFitResult* fitResults, RooFitResult* fitMIResults, const char* asciifile) { if (get_mpi_rank()>0) return; RooArgSet pars,parsMI,parsSel; RooArgSet pars_latex,parsMI_latex,parsSel_latex; // add here MINUIT status code (status), MINUIT quality code of covariance // matrix (covQual), number calls with bad (zero,negative) likelihood (numBadNLL), // NLL at minimum (minNLL) and estimated distance to minimum (edm) if (fitSelResults!=0) { RooRealVar* statusSel = new RooRealVar("statusSel","statusSel",fitSelResults->status()) ; RooRealVar* minNllSel = new RooRealVar("minNllSel","minNllSel",fitSelResults->minNll()) ; RooRealVar* covQualSel = new RooRealVar("covQualSel","covQualSel",fitSelResults->covQual()) ; RooRealVar* edmSel = new RooRealVar("edmSel","edmSel",fitSelResults->edm()) ; RooRealVar* numInvalidNLLSel = new RooRealVar("numInvalidNLLSel","numInvalidNLLSel",fitSelResults->numInvalidNLL()) ; parsSel.add(RooArgSet(*statusSel,*minNllSel,*covQualSel,*edmSel,*numInvalidNLLSel)); } if (fitResults!=0) { RooRealVar* status = new RooRealVar("status","status",fitResults->status()) ; RooRealVar* minNll = new RooRealVar("minNll","minNll",fitResults->minNll()) ; RooRealVar* covQual = new RooRealVar("covQual","covQual",fitResults->covQual()) ; RooRealVar* edm = new RooRealVar("edm","edm",fitResults->edm()) ; RooRealVar* numInvalidNLL = new RooRealVar("numInvalidNLL","numInvalidNLL",fitResults->numInvalidNLL()) ; pars.add(RooArgSet(*status,*minNll,*covQual,*edm,*numInvalidNLL)); } if (fitMIResults!=0) { RooRealVar* statusMI = new RooRealVar("statusMI","statusMI",fitMIResults->status()) ; RooRealVar* minNllMI = new RooRealVar("minNllMI","minNllMI",fitMIResults->minNll()) ; RooRealVar* covQualMI = new RooRealVar("covQualMI","covQualMI",fitMIResults->covQual()) ; RooRealVar* edmMI = new RooRealVar("edmMI","edmMI",fitMIResults->edm()) ; RooRealVar* numInvalidNLLMI = new RooRealVar("numInvalidNLLMI","numInvalidNLLMI",fitMIResults->numInvalidNLL()) ; parsMI.add(RooArgSet(*statusMI,*minNllMI,*covQualMI,*edmMI,*numInvalidNLLMI)); } // add here parameters if (fitSelResults!=0) { parsSel.add(fitSelResults->floatParsFinal()); //parsSel.add(fitSelResults->constPars()); parsSel_latex.add(fitSelResults->floatParsFinal()); } if (fitResults!=0) { pars.add(fitResults->floatParsFinal()); //pars.add(fitResults->constPars()); pars_latex.add(fitResults->floatParsFinal()); } if (fitMIResults!=0) { parsMI.add(fitMIResults->floatParsFinal()); //parsMI.add(fitMIResults->constPars()); parsMI_latex.add(fitMIResults->floatParsFinal()); } // add here correlations among physics parameters RooArgSet rhosSel,rhos,rhosMI ; getListOfRhos(fitSelResults,rhosSel); parsSel.add(rhosSel); getListOfRhos(fitResults,rhos); pars.add(rhos); getListOfRhos(fitMIResults,rhosMI); parsMI.add(rhosMI); // use in MD and MI list of params those from the SEL fits //pars.remove(parsSel,kTRUE,kTRUE); pars.add(parsSel); pars_latex.add(parsSel_latex); //parsMI.remove(parsSel,kTRUE,kTRUE); parsMI.add(parsSel); parsMI_latex.add(parsSel_latex); // write //pars.Print("v"); RooArgSet parsAll(pars); parsAll.add(parsMI); parsAll.writeToFile(asciifile); rhosSel.removeAll(); rhos.removeAll(); rhosMI.removeAll(); // RooArgSet parsAll_latex(pars_latex); parsAll_latex.add(parsMI_latex); parsAll_latex.printLatex(RooFit::Format("NEAU"),RooFit::OutputFile(TString(asciifile)+"_latex")); } void RooDKFitMaster::getListOfRhos(RooFitResult* fitRes, RooArgSet& listOfRhos) { if (fitRes==0) return; RooArgSet setOfFloatParams(fitRes->floatParsFinal()); if (setOfFloatParams.getSize()<=1) return; TIterator* iter = setOfFloatParams.createIterator(); Int_t i(0); RooAbsReal* item(0); while (item = (RooAbsReal*)iter->Next()) { TIterator* iter2 = setOfFloatParams.createIterator(); Int_t j(0); RooAbsReal* item2(0); while (item2 = (RooAbsReal*)iter2->Next()) { if (j>i) { Double_t rho = fitRes->correlation(*item,*item2); TString* name = new TString("C["); name->Append(item->GetName()); name->Append(","); name->Append(item2->GetName()); name->Append("]"); RooRealVar* rhovar = new RooRealVar(*name,*name,rho) ; //cout << *name << " : " << rho << endl; listOfRhos.addOwned(*rhovar); } j++; } i++; delete iter2; } delete iter; } void RooDKFitMaster::dumpParametersToAscii_input(const char* asciifile) { if (get_mpi_rank()>0) return; cout<<"Writing results_input"<>line; if(line.Contains("(") && line.Contains(")")){ Int_t l = line.Index("("); Int_t h = line.Index(")"); line.Remove(l,h-l+1); }; if(line.BeginsWith("C["))break; if (line=="//" || (line.Contains("[") && line.Contains("]")) ) continue; else outfile<0) return; RooAbsPdf* pdfMD = _pdfGlobalToyMc; RooAbsPdf* pdfMI = _pdfMIGlobalToyMc; RooArgSet parsAll; if (pdfMD) { RooArgSet* parsMD = pdfMD->getParameters(_gFit->_selDataVars); parsAll.add(*parsMD); } if (pdfMI) { RooArgSet* parsMI = pdfMI->getParameters(_gFit->_selDataVars); parsAll.add(*parsMI); } parsAll.writeToFile(asciifile); } // ========================================= // Tool for Dalitz plot adaptive binning // ========================================= // 2D adaptive Dalitz plot binning void RooDKFitMaster::adaptive2dBinning(const RooDataSet* data, const RooRealVar* qPair1, const RooRealVar* qPair2, const Float_t occ_min, std::vector& xmin, std::vector& ymin, std::vector& xmax, std::vector& ymax, std::vector& occ) { // xmin,ymin,xmax,ymax,occ: array of edges for each bin // occ: array of occupancies for each bin std::vector xdata; std::vector ydata; std::vector weightdata; for (Int_t iEvt=0;iEvtnumEntries();iEvt++) { const RooArgSet* columns = data->get(iEvt); RooRealVar* qPair1_col = (RooRealVar*)columns->find(qPair1->GetName()); RooRealVar* qPair2_col = (RooRealVar*)columns->find(qPair2->GetName()); xdata.push_back(qPair1_col->getVal()); ydata.push_back(qPair2_col->getVal()); weightdata.push_back(1.); } //for (Int_t iEvt=0;iEvtocc_min) adaptive2dBinning_tool(xdata,ydata,weightdata,xmin,ymin,xm,ym,occ_min,bins); else { std::vector bin; bin.push_back(xmin); bin.push_back(ymin); bin.push_back(xm); bin.push_back(ym); bin.push_back(occ1); bins.push_back(bin); //cout << "Quad 1: " << xmin << " " << ymin << " " << xm << " " << ym << " " << occ1 << endl; } // if (occ2>occ_min) adaptive2dBinning_tool(xdata,ydata,weightdata,xmin,ym,xm,ymax,occ_min,bins); else { std::vector bin; bin.push_back(xmin); bin.push_back(ym); bin.push_back(xm); bin.push_back(ymax); bin.push_back(occ2); bins.push_back(bin); //cout << "Quad 2: " << xmin << " " << ym << " " << xm << " " << ymax << " " << occ2 << endl; } // if (occ3>occ_min) adaptive2dBinning_tool(xdata,ydata,weightdata,xm,ym,xmax,ymax,occ_min,bins); else { std::vector bin; bin.push_back(xm); bin.push_back(ym); bin.push_back(xmax); bin.push_back(ymax); bin.push_back(occ3); bins.push_back(bin); //cout << "Quad 3: " << xm << " " << ym << " " << xmax << " " << ymax << " " << occ3 << endl; } // if (occ4>occ_min) adaptive2dBinning_tool(xdata,ydata,weightdata,xm,ymin,xmax,ym,occ_min,bins); else { std::vector bin; bin.push_back(xm); bin.push_back(ymin); bin.push_back(xmax); bin.push_back(ym); bin.push_back(occ4); bins.push_back(bin); //cout << "Quad 4: " << xm << " " << ymin << " " << xmax << " " << ym << " " << occ4 << endl; } }