diff --git a/inc/LauBsCPFitModel.hh b/inc/LauBsCPFitModel.hh index d080144..1c51773 100644 --- a/inc/LauBsCPFitModel.hh +++ b/inc/LauBsCPFitModel.hh @@ -1,595 +1,595 @@ /* Copyright 2015 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauBsCPFitModel.hh \brief File containing declaration of LauBsCPFitModel class. */ /*! \class LauBsCPFitModel \brief Class for defining a CP fit model. LauBsCPFitModel is a class that allows the user to define a three-body Dalitz plot according to the isobar model, i.e. defining a set of resonances that have complex amplitudes that can interfere with each other. It extends the LauSimpleFitModel in that it allows simultaneous fitting of two parent flavours simultaneously. By default, it assumes perfect tagging of those flavours but it can also be used in an untagged scenario. */ #ifndef LAU_BS_CP_FIT_MODEL #define LAU_BS_CP_FIT_MODEL #include #include "TString.h" #include "LauAbsFitModel.hh" #include "LauComplex.hh" #include "LauParameter.hh" class TH2; class LauAbsBkgndDPModel; class LauAbsCoeffSet; class LauIsobarDynamics; class LauAbsPdf; class LauEffModel; class LauEmbeddedData; class LauKinematics; class LauScfMap; class LauBsCPFitModel : public LauAbsFitModel { public: //! Constructor /*! \param [in] negModel DP model for the antiparticle \param [in] posModel DP model for the particle \param [in] D the time-integration scaling factor for A_DeltaGamma */ LauBsCPFitModel(LauIsobarDynamics* negModel, LauIsobarDynamics* posModel, Double_t D); //! Destructor virtual ~LauBsCPFitModel(); //! Set the signal event yield /*! \param [in] nSigEvents contains the signal yield and option to fix it */ virtual void setNSigEvents(LauParameter* nSigEvents); //! Set the background event yield(s) /*! The name of the parameter must be that of the corresponding background category (so that it can be correctly assigned) \param [in] nBkgndEvents contains the name, yield and option to fix the yield of the background */ - virtual void setNBkgndEvents(LauParameter* nBkgndEvents); + virtual void setNBkgndEvents(LauAbsRValue* nBkgndEvents); //! Set the background DP models /*! \param [in] bkgndClass the name of the background class \param [in] model the DP model of the background */ void setBkgndDPModel(const TString& bkgndClass, LauAbsBkgndDPModel* model); //! Split the signal component into well-reconstructed and mis-reconstructed parts /*! The nomenclature used here is TM (truth-matched) and SCF (self cross feed) In this option, the SCF fraction is DP-dependent Can also optionally provide a smearing matrix to smear the SCF DP PDF \param [in] dpHisto the DP histogram of the SCF fraction value \param [in] upperHalf whether this histogram is only in the upper half of a symmetric DP \param [in] fluctuateBins whether the bins on the histogram should be varied in accordance with their uncertainties (for evaluation of systematic uncertainties) \param [in] scfMap the (optional) smearing matrix */ void splitSignalComponent( const TH2* dpHisto, const Bool_t upperHalf = kFALSE, const Bool_t fluctuateBins = kFALSE, LauScfMap* scfMap = 0 ); //! Split the signal component into well reconstructed and mis-reconstructed parts /*! The nomenclature used here is TM (truth-matched) and SCF (self cross feed) In this option, the SCF fraction is a single global number \param [in] scfFrac the SCF fraction value \param [in] fixed whether the SCF fraction is fixed or floated in the fit */ void splitSignalComponent( const Double_t scfFrac, const Bool_t fixed ); //! Determine whether we are splitting the signal into TM and SCF parts Bool_t useSCF() const { return useSCF_; } //! Determine whether the SCF fraction is DP-dependent Bool_t useSCFHist() const { return useSCFHist_; } //! Determine if we are smearing the SCF DP PDF Bool_t smearSCFDP() const { return (scfMap_ != 0); } // Set the DeltaE and mES models, i.e. give us the PDFs //! Set the signal PDFs /*! \param [in] pdf the PDF to be added to the signal model */ void setSignalPdf(LauAbsPdf* pdf); //! Set the SCF PDF for a given variable /*! \param [in] pdf the PDF to be added to the signal model */ void setSCFPdf(LauAbsPdf* pdf); //! Set the background PDFs /*! \param [in] bkgndClass the name of the background class \param [in] pdf the PDF to be added to the background model */ void setBkgndPdf(const TString& bkgndClass, LauAbsPdf* pdf); //! Set the DP amplitude coefficients /*! \param [in] coeffSet the set of coefficients */ virtual void setAmpCoeffSet(LauAbsCoeffSet* coeffSet); //! Weight events based on the DP model /*! \param [in] dataFileName the name of the data file \param [in] dataTreeName the name of the data tree */ virtual void weightEvents( const TString& dataFileName, const TString& dataTreeName ); protected: //! Define a map to be used to store a category name and numbers typedef std::map< std::pair, std::pair > LauGenInfo; //! Typedef for a vector of background DP models typedef std::vector LauBkgndDPModelList; //! Typedef for a vector of background PDFs typedef std::vector LauBkgndPdfsList; //! Typedef for a vector of background yields - typedef std::vector LauBkgndYieldList; + typedef std::vector LauBkgndYieldList; //! Typedef for a vector of embedded data objects typedef std::vector LauBkgndEmbDataList; //! Typedef for a vector of booleans to flag if events are reused typedef std::vector LauBkgndReuseEventsList; //! Initialise the fit virtual void initialise(); //! Initialise the signal DP models virtual void initialiseDPModels(); //! Recalculate Normalization the signal DP models virtual void recalculateNormalisation(); //! Update the coefficients virtual void updateCoeffs(); //! Toy MC generation and fitting overloaded functions virtual Bool_t genExpt(); //! Calculate things that depend on the fit parameters after they have been updated by Minuit virtual void propagateParUpdates(); //! Read in the input fit data variables, e.g. m13Sq and m23Sq virtual void cacheInputFitVars(); //! Check the initial fit parameters virtual void checkInitFitParams(); //! Get the fit results and store them /*! \param [in] tablePrefixName prefix for the name of the output file */ virtual void finaliseFitResults(const TString& tablePrefixName); //! Print the fit fractions, total DP rate and mean efficiency /*! \param [out] output the stream to which to print */ virtual void printFitFractions(std::ostream& output); //! Save the pdf Plots for all the resonances of experiment number fitExp /*! TODO - not working in this model!! \param [in] label prefix for the file name to be saved */ virtual void savePDFPlots(const TString& label); //! Save the pdf Plots for the sum of ressonances correspondint to "sin" of experiment number fitExp /*! TODO - not working in this model!! \param [in] label prefix for the file name to be saved \param [in] spin spin of the wave to be saved */ virtual void savePDFPlotsWave(const TString& label, const Int_t& spin); //! Print the asymmetries /*! \param [out] output the stream to which to print */ virtual void printAsymmetries(std::ostream& output); //! Write the fit results in latex table format /*! \param [in] outputFile the name of the output file */ virtual void writeOutTable(const TString& outputFile); //! Store the per event likelihood values virtual void storePerEvtLlhds(); // Methods to do with calculating the likelihood functions // and manipulating the fitting parameters. //! Get the total likelihood for each event /*! \param [in] iEvt the event number */ virtual Double_t getTotEvtLikelihood(UInt_t iEvt); //! Calculate the signal and background likelihoods for the DP for a given event /*! \param [in] iEvt the event number */ virtual void getEvtDPLikelihood(UInt_t iEvt); //! Calculate the SCF likelihood for the DP for a given event /*! \param [in] iEvt the event number */ virtual Double_t getEvtSCFDPLikelihood(UInt_t iEvt); //! Determine the signal and background likelihood for the extra variables for a given event /*! \param [in] iEvt the event number */ virtual void getEvtExtraLikelihoods(UInt_t iEvt); //! Calculate the complete DP amplitude from the B and Bbar parts virtual void calculateDPterms(); //! Store the decay-time DP normalisation for both f anf fbar final states void calculateAmplitudeNorm(); //! Calculate the total integral of the interference term void calcInterTermNorm(); //! Calculate the component integrals of the interference term void calcInterferenceTermIntegrals(); //! Get the total number of events /*! \return the total number of events */ virtual Double_t getEventSum() const; //! Set the fit parameters for the DP model void setSignalDPParameters(); //! Set the fit parameters for the extra PDFs void setExtraPdfParameters(); //! Set the initial yields void setFitNEvents(); //! Set-up other parameters that are derived from the fit results, e.g. fit fractions void setExtraNtupleVars(); //! Randomise the initial fit parameters void randomiseInitFitPars(); //! Calculate the CP-conserving and CP-violating fit fractions /*! \param [in] initValues is this before or after the fit */ void calcExtraFractions(Bool_t initValues = kFALSE); //! Calculate the CP asymmetries /*! \param [in] initValues is this before or after the fit */ void calcAsymmetries(Bool_t initValues = kFALSE); //! Define the length of the background vectors virtual void setupBkgndVectors(); //! Determine the number of events to generate for each hypothesis LauGenInfo eventsToGenerate(); //! Generate signal event Bool_t generateSignalEvent(); //! Generate background event /*! \param [in] bgID ID number of the background class */ Bool_t generateBkgndEvent(UInt_t bgID); //! Setup the required ntuple branches void setupGenNtupleBranches(); //! Store all of the DP information void setDPBranchValues(); //! Generate from the extra PDFs /*! \param [in] extraPdfs the list of extra PDFs */ void generateExtraPdfValues(LauPdfList* extraPdfs); //! Add sPlot branches for the extra PDFs /*! \param [in] extraPdfs the list of extra PDFs \param [in] prefix the list of prefixes for the branch names */ void addSPlotNtupleBranches(const LauPdfList* extraPdfs, const TString& prefix); //! Set the branches for the sPlot ntuple with extra PDFs /*! \param [in] extraPdfs the list of extra PDFs \param [in] prefix the list of prefixes for the branch names \param [in] iEvt the event number */ Double_t setSPlotNtupleBranchValues(LauPdfList* extraPdfs, const TString& prefix, UInt_t iEvt); //! Update the signal events after Minuit sets background parameters void updateSigEvents(); //! Add branches to store experiment number and the event number within the experiment virtual void setupSPlotNtupleBranches(); //! Returns the names of all variables in the fit virtual LauSPlot::NameSet variableNames() const; //! Returns the names and yields of species that are free in the fit virtual LauSPlot::NumbMap freeSpeciesNames() const; //! Returns the names and yields of species that are fixed in the fit virtual LauSPlot::NumbMap fixdSpeciesNames() const; //! Returns the species and variables for all 2D PDFs in the fit virtual LauSPlot::TwoDMap twodimPDFs() const; //! Check if the signal is split into well-reconstructed and mis-reconstructed types virtual Bool_t splitSignal() const {return this->useSCF();} //! Check if the mis-reconstructed signal is to be smeared in the DP virtual Bool_t scfDPSmear() const {return (scfMap_ != 0);} //! Append fake data points to the inputData for each bin in the SCF smearing matrix /*! We'll be caching the DP amplitudes and efficiencies of the centres of the true bins. To do so, we attach some fake points at the end of inputData, the number of the entry minus the total number of events corresponding to the number of the histogram for that given true bin in the LauScfMap object. (What this means is that when Laura is provided with the LauScfMap object by the user, it's the latter who has to make sure that it contains the right number of histograms and in exactly the right order!) \param [in] inputData the fit data */ void appendBinCentres( LauFitDataTree* inputData ); private: //! Copy constructor (not implemented) LauBsCPFitModel(const LauBsCPFitModel& rhs); //! Copy assignment operator (not implemented) LauBsCPFitModel& operator=(const LauBsCPFitModel& rhs); //! The B- signal Dalitz plot model LauIsobarDynamics *negSigModel_; //! The B+ signal Dalitz plot model LauIsobarDynamics *posSigModel_; //! The background Dalitz plot models LauBkgndDPModelList bkgndDPModels_; //! The B- Dalitz plot kinematics object LauKinematics *negKinematics_; //! The B+ Dalitz plot kinematics object LauKinematics *posKinematics_; //! The time-integration scaling factor for A_DeltaGamma const Double_t D_; //! The signal PDFs LauPdfList signalPdfs_; //! The SCF PDFs LauPdfList scfPdfs_; //! The background PDFs LauBkgndPdfsList bkgndPdfs_; //! Background boolean Bool_t usingBkgnd_; //! Number of signal components UInt_t nSigComp_; //! Number of signal DP parameters UInt_t nSigDPPar_; //! Number of extra PDF parameters UInt_t nExtraPdfPar_; //! Number of normalisation parameters (yields, asymmetries) UInt_t nNormPar_; //! Magnitudes and Phases std::vector coeffPars_; //! Integrals of the efficiency corrected amplitude terms /*! The integrals of the efficiency corrected amplitude cross terms for each pair of amplitude components for the same f final state, e.g. |Abar->f|x |A*-> f| Calculated as the sum of A* x Abar x efficiency */ std::vector< std::vector > fifjEffSum_; //! The normalisation for the term Re(|A->f*|Abar->f|*phiMix) Double_t interTermReNorm_; //! The normalisation for the complete DP amplitude Double_t normDP_; //! The B- fit fractions LauParArray negFitFrac_; //! The B+ fit fractions LauParArray posFitFrac_; //! Fit B- fractions (uncorrected for the efficiency) LauParArray negFitFracEffUnCorr_; //! Fit B+ fractions (uncorrected for the efficiency) LauParArray posFitFracEffUnCorr_; //! The CP violating fit fraction LauParArray CPVFitFrac_; //! The CP conserving fit fraction LauParArray CPCFitFrac_; //! The fit fraction asymmetries std::vector fitFracAsymm_; //! A_CP parameter std::vector acp_; //! The mean efficiency for B- model LauParameter negMeanEff_; //! The mean efficiency for B+ model LauParameter posMeanEff_; //! The average DP rate for B- LauParameter negDPRate_; //! The average DP rate for B+ LauParameter posDPRate_; //! Signal yield LauParameter* signalEvents_; //! Background yield(s) LauBkgndYieldList bkgndEvents_; //! Is the signal split into TM and SCF Bool_t useSCF_; //! Is the SCF fraction DP-dependent Bool_t useSCFHist_; //! The (global) SCF fraction parameter LauParameter scfFrac_; //! The histogram giving the DP-dependence of the SCF fraction LauEffModel* scfFracHist_; //! The smearing matrix for the SCF DP PDF LauScfMap* scfMap_; //! The cached values of the SCF fraction for each event std::vector recoSCFFracs_; //! The cached values of the SCF fraction for each bin centre std::vector fakeSCFFracs_; //! The cached values of the sqDP jacobians for each event std::vector recoJacobians_; //! The cached values of the sqDP jacobians for each true bin std::vector fakeJacobians_; //! Run choice variables Bool_t compareFitData_; //! Name of the parent particle TString negParent_; //! Name of the parent particle TString posParent_; //! The complex coefficients for B- std::vector negCoeffs_; //! The complex coefficients for B+ std::vector posCoeffs_; // Toy generation stuff //! The maximum allowed number of attempts when generating an event Int_t iterationsMax_; //! The number of unsucessful attempts to generate an event so far Int_t nGenLoop_; //! The value of A squared for the current event Double_t ASq_; //! The maximum value of A squared that has been seen so far while generating Double_t aSqMaxVar_; //! The maximum allowed value of A squared Double_t aSqMaxSet_; // Likelihood values //! Signal DP likelihood value Double_t sigDPLike_; //! SCF DP likelihood value Double_t scfDPLike_; //! Background DP likelihood value(s) std::vector bkgndDPLike_; //! Signal likelihood from extra PDFs Double_t sigExtraLike_; //! SCF likelihood from extra PDFs Double_t scfExtraLike_; //! Background likelihood value(s) from extra PDFs std::vector bkgndExtraLike_; //! Total signal likelihood Double_t sigTotalLike_; //! Total SCF likelihood Double_t scfTotalLike_; //! Total background likelihood(s) std::vector bkgndTotalLike_; ClassDef(LauBsCPFitModel,0) // CP fit/ToyMC model }; #endif diff --git a/inc/LauTimeDepFitModel.hh b/inc/LauTimeDepFitModel.hh index 83f6516..0b18650 100644 --- a/inc/LauTimeDepFitModel.hh +++ b/inc/LauTimeDepFitModel.hh @@ -1,640 +1,640 @@ /* Copyright 2006 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauTimeDepFitModel.hh \brief File containing declaration of LauTimeDepFitModel class. */ /*! \class LauTimeDepFitModel \brief Class for defining a time-dependent fit model. LauTimeDepFitModel is a class that allows the user to define a three-body Dalitz plot according to the isobar model, i.e. defining a set of resonances that have complex amplitudes that can interfere with each other. It extends the LauSimpleFitModel and LauCPFitModel models in that it allows the fitting of time-dependent particle/antiparticle decays to flavour-conjugate Dalitz plots, including their interference through mixing. */ #ifndef LAU_TIMEDEP_FIT_MODEL #define LAU_TIMEDEP_FIT_MODEL #include #include #include #include #include "TString.h" #include "TStopwatch.h" #include "TSystem.h" #include "LauAbsFitModel.hh" #include "LauConstants.hh" #include "LauEmbeddedData.hh" #include "LauParameter.hh" #include "LauFlavTag.hh" class LauAbsBkgndDPModel; class LauAbsCoeffSet; class LauAbsPdf; class LauDecayTimePdf; class LauIsobarDynamics; class LauKinematics; class LauScfMap; class LauTimeDepFitModel : public LauAbsFitModel { public: //! Possible CP eigenvalues (the intrinsic CP of the final state particles) enum CPEigenvalue { CPOdd = -1, /*!< CP odd final state */ CPEven = 1 /*!< CP even final state */ }; //! Constructor /*! \param [in] modelB0bar DP model for the antiparticle \param [in] modelB0 DP model for the particle \param [in] flavTag flavour tagging information */ LauTimeDepFitModel(LauIsobarDynamics* modelB0bar, LauIsobarDynamics* modelB0, LauFlavTag* flavTag); //! Destructor virtual ~LauTimeDepFitModel(); //! Set the signal event yield /*! \param [in] nSigEvents contains the signal yield and option to fix it */ virtual void setNSigEvents(LauParameter* nSigEvents); //! Set the signal event yield and asymmetry /*! \param [in] nSigEvents contains the signal yield and option to fix it \param [in] sigAsym contains the signal asymmetry and option to fix it */ virtual void setNSigEvents(LauParameter* nSigEvents, LauParameter* sigAsym); //! Set the number of background events /*! The name of the parameter must be that of the corresponding background category (so that it can be correctly assigned) \param [in] nBkgndEvents contains the name, yield and option to fix the yield of the background */ - virtual void setNBkgndEvents(LauParameter* nBkgndEvents); + virtual void setNBkgndEvents(LauAbsRValue* nBkgndEvents); //! Set the background event yield and asymmetry /*! \param [in] nBkgEvents contains the background yield and option to fix it \param [in] BkgAsym contains the background asymmetry and option to fix it */ - virtual void setNBkgndEvents(LauParameter* nBkgndEvents, LauParameter* bkgndAsym); + virtual void setNBkgndEvents(LauAbsRValue* nBkgndEvents, LauAbsRValue* bkgndAsym); //! Switch on/off storage of amplitude info in generated ntuple void storeGenAmpInfo(Bool_t storeInfo) { storeGenAmpInfo_ = storeInfo; } //! Set CP eigenvalue /*! The CP eigenvalue can be supplied on an event-by-event basis, e.g. if the data contains daughters that are D0 mesons that can decay to either K+ K- (CP even) or KS pi0 (CP odd). This method allows you to set the default value that should be used if the data does not contain this information as well as the name of the variable in the data that will specify this information. If completely unspecified all events will be assumed to be CP even. \param defaultCPEV the default for the eigenvalue \param evVarName the variable name in the data tree that specifies the CP eigenvalue */ inline void setCPEigenvalue( const CPEigenvalue defaultCPEV, const TString& cpevVarName = "" ) { cpEigenValue_ = defaultCPEV; cpevVarName_ = cpevVarName; } //! Set the DP amplitude coefficients /*! \param [in] coeffSet the set of coefficients */ void setAmpCoeffSet(LauAbsCoeffSet* coeffSet); //! Set the decay time PDFs /*! \param [in] tagCat the tagging category for which the PDF should be used \param [in] pdf the signal decay time PDF */ void setSignalDtPdf(const Int_t tagCat, LauDecayTimePdf* pdf); //! Set the signal PDF for a given variable /*! \param [in] tagCat the tagging category for which the PDF should be used \param [in] pdf the PDF to be added to the signal model */ void setSignalPdfs(const Int_t tagCat, LauAbsPdf* pdf); void setSignalFlavTagPdfs( const Int_t tagCat, LauAbsPdf* pdf); void setBkgdFlavTagPdfs( const TString name, LauAbsPdf* pdf); //! Embed full simulation events for the signal, rather than generating toy from the PDFs /*! \param [in] tagCat the tagging category for which the file should be used \param [in] fileName the name of the file containing the events \param [in] treeName the name of the tree \param [in] reuseEventsWithinEnsemble \param [in] reuseEventsWithinExperiment \param [in] useReweighting */ void embedSignal(const Int_t tagCat, const TString& fileName, const TString& treeName, const Bool_t reuseEventsWithinEnsemble, const Bool_t reuseEventsWithinExperiment = kFALSE); //! Set the value of the mixing phase /*! \param [in] phiMix the value of the mixing phase \param [in] fixPhiMix whether the value should be fixed or floated \param [in] useSinCos whether to use the sine and cosine as separate parameters or to just use the mixing phase itself */ void setPhiMix(const Double_t phiMix, const Bool_t fixPhiMix, const Bool_t useSinCos = kFALSE); //! Initialise the fit virtual void initialise(); //! Initialise the signal DP model virtual void initialiseDPModels(); //! Recalculate Normalization the signal DP models virtual void recalculateNormalisation(); //! Update the coefficients virtual void updateCoeffs(); // Toy MC generation and fitting overloaded functions virtual Bool_t genExpt(); //! Set the maximum value of A squared to be used in the accept/reject /*! \param [in] value the new value */ inline void setASqMaxValue(const Double_t value) {aSqMaxSet_ = value;} //! Weight events based on the DP model /*! \param [in] dataFileName the name of the data file \param [in] dataTreeName the name of the data tree */ virtual void weightEvents( const TString& dataFileName, const TString& dataTreeName ); //! Calculate things that depend on the fit parameters after they have been updated by Minuit virtual void propagateParUpdates(); //! Read in the input fit data variables, e.g. m13Sq and m23Sq virtual void cacheInputFitVars(); //! Check the initial fit parameters virtual void checkInitFitParams(); //! Get the fit results and store them /*! \param [in] tablePrefixName prefix for the name of the output file */ virtual void finaliseFitResults(const TString& tablePrefixName); //! Save the pdf Plots for all the resonances of experiment number fitExp /*! TODO - not working in this model!! \param [in] label prefix for the file name to be saved */ virtual void savePDFPlots(const TString& label); //! Save the pdf Plots for the sum of ressonances correspondint to "sin" of experiment number fitExp /*! TODO - not working in this model!! \param [in] label prefix for the file name to be saved \param [in] spin spin of the wave to be saved */ virtual void savePDFPlotsWave(const TString& label, const Int_t& spin); //! Print the fit fractions, total DP rate and mean efficiency /*! \param [out] output the stream to which to print */ virtual void printFitFractions(std::ostream& output); //! Print the asymmetries /*! \param [out] output the stream to which to print */ virtual void printAsymmetries(std::ostream& output); //! Write the fit results in latex table format /*! \param [in] outputFile the name of the output file */ virtual void writeOutTable(const TString& outputFile); //! Store the per event likelihood values virtual void storePerEvtLlhds(); // Methods to do with calculating the likelihood functions // and manipulating the fitting parameters. //! Get the total likelihood for each event /*! \param [in] iEvt the event number */ virtual Double_t getTotEvtLikelihood(const UInt_t iEvt); //! Calculate the signal and background likelihoods for the DP for a given event /*! \param [in] iEvt the event number */ virtual void getEvtDPDtLikelihood(const UInt_t iEvt); //! Determine the signal and background likelihood for the extra variables for a given event /*! \param [in] iEvt the event number */ virtual void getEvtExtraLikelihoods(const UInt_t iEvt); virtual void getEvtFlavTagLikelihood(const UInt_t iEvt); //! Get the total number of events /*! \return the total number of events */ virtual Double_t getEventSum() const; //! Set the fit parameters for the DP model void setSignalDPParameters(); //! Set the fit parameters for the decay time PDFs void setDecayTimeParameters(); //! Set the fit parameters for the extra PDFs void setExtraPdfParameters(); //! Set the initial yields void setFitNEvents(); //! Set the calibration parameters, if floating void setCalibParams(); //! Set-up other parameters that are derived from the fit results, e.g. fit fractions void setExtraNtupleVars(); //! Randomise the initial fit parameters void randomiseInitFitPars(); //! Method to set up the storage for background-related quantities called by setBkgndClassNames virtual void setupBkgndVectors(); //! Calculate the CP asymmetries /*! \param [in] initValues is this before or after the fit */ void calcAsymmetries(const Bool_t initValues = kFALSE); //! Finalise value of mixing phase void checkMixingPhase(); protected: typedef std::map< Int_t, LauDecayTimePdf*> LauTagCatDtPdfMap; typedef std::map< Int_t, LauParameter> LauTagCatParamMap; typedef std::map< Int_t, LauPdfList > LauTagCatPdfListMap; typedef std::map< Int_t, LauAbsPdf* > LauTagCatPdfMap; typedef std::map< TString, LauAbsPdf* > LauBkgdPdfMap; typedef std::map< Int_t, Int_t > LauTagCatEventsMap; typedef std::map< Int_t, LauEmbeddedData* > LauTagCatEmbDataMap; typedef std::map< Int_t, std::pair > LauTagCatGenInfo; typedef std::map< std::pair, LauTagCatGenInfo > LauGenInfo; typedef std::vector LauTagCatEmbDataMapList; typedef std::vector LauBkgndDPModelList; typedef std::vector LauBkgndPdfsList; - typedef std::vector LauBkgndYieldList; + typedef std::vector LauBkgndYieldList; typedef std::vector LauBkgndReuseEventsList; //! Determine the number of events to generate for each hypothesis LauGenInfo eventsToGenerate(); //! Generate signal event Bool_t generateSignalEvent(); //! Setup the required ntuple branches void setupGenNtupleBranches(); //! Store all of the DP and decay time information void setDPDtBranchValues(); //! Generate from the extra PDFs /*! \param [in] extraPdfs the list of extra PDFs \param [in] embeddedData the embedded data sample */ void generateExtraPdfValues(LauPdfList* extraPdfs, LauEmbeddedData* embeddedData); //! Add sPlot branches for the extra PDFs /*! \param [in] extraPdfs the list of extra PDFs \param [in] prefix the list of prefixes for the branch names */ void addSPlotNtupleBranches(const LauPdfList* extraPdfs, const TString& prefix); //! Set the branches for the sPlot ntuple with extra PDFs /*! \param [in] extraPdfs the list of extra PDFs \param [in] prefix the list of prefixes for the branch names \param [in] iEvt the event number */ Double_t setSPlotNtupleBranchValues(LauPdfList* extraPdfs, const TString& prefix, UInt_t iEvt); //! Update the signal events after Minuit sets background parameters void updateSigEvents(); //! Add branches to store experiment number and the event number within the experiment virtual void setupSPlotNtupleBranches(); //! Returns the names of all variables in the fit virtual LauSPlot::NameSet variableNames() const; //! Returns the names and yields of species that are free in the fit virtual LauSPlot::NumbMap freeSpeciesNames() const; //! Returns the names and yields of species that are fixed in the fit virtual LauSPlot::NumbMap fixdSpeciesNames() const; //! Returns the species and variables for all 2D PDFs in the fit virtual LauSPlot::TwoDMap twodimPDFs() const; //! Check if the signal is split into well-reconstructed and mis-reconstructed types virtual Bool_t splitSignal() const { return kFALSE; } //! Check if the mis-reconstructed signal is to be smeared in the DP virtual Bool_t scfDPSmear() const { return kFALSE; } //! Add the parameters from each PDF into the fit /*! \param [in] theMap the container of PDFs */ UInt_t addParametersToFitList(LauTagCatPdfListMap& theMap); //! Add the parameters from each decay time PDF into the fit /*! \param [in] theMap the container of PDFs */ UInt_t addParametersToFitList(LauTagCatDtPdfMap& theMap); //! Calculate the component integrals of the interference term void calcInterferenceTermIntegrals(); //! Calculate the total integral of the interference term void calcInterTermNorm(); private: //! Dalitz plot PDF for the antiparticle LauIsobarDynamics* sigModelB0bar_; //! Dalitz plot PDF for the particle LauIsobarDynamics* sigModelB0_; //! Kinematics object for antiparticle LauKinematics* kinematicsB0bar_; //! Kinematics object for particle LauKinematics* kinematicsB0_; //! The B0 background Dalitz plot models LauBkgndDPModelList BkgndDPModelsB0_; //! The B0-bar background Dalitz plot models LauBkgndDPModelList BkgndDPModelsB0bar_; //! The B0 background PDFs LauBkgndPdfsList BkgndPdfsB0_; //! The B0bar background PDFs LauBkgndPdfsList BkgndPdfsB0bar_; //! LauFlavTag object for flavour tagging LauFlavTag* flavTag_; //! Flavour tag for current event Int_t curEvtTagFlv_; //! Tagging category for current event Int_t curEvtTagCat_; //! Per event mistag for current event Double_t curEvtMistag_; //! Number of signal components UInt_t nSigComp_; //! Number of signal DP parameters UInt_t nSigDPPar_; //! Number of decay time PDF parameters UInt_t nDecayTimePar_; //! Number of extra PDF parameters UInt_t nExtraPdfPar_; //! Number of normalisation parameters (yields, asymmetries) UInt_t nNormPar_; //! Number of calibration parameters (p0, p1) UInt_t nCalibPar_; //! The complex coefficients for antiparticle std::vector coeffsB0bar_; //! The complex coefficients for particle std::vector coeffsB0_; //! Magnitudes and Phases or Real and Imaginary Parts std::vector coeffPars_; //! The integrals of the efficiency corrected amplitude cross terms for each pair of amplitude components /*! Calculated as the sum of A* x Abar x efficiency */ std::vector< std::vector > fifjEffSum_; //! The normalisation for the term 2.0*Re(A*Abar*phiMix) Double_t interTermReNorm_; //! The normalisation for the term 2.0*Im(A*Abar*phiMix) Double_t interTermImNorm_; //! The antiparticle fit fractions LauParArray fitFracB0bar_; //! The particle fit fractions LauParArray fitFracB0_; //! The fit fraction asymmetries std::vector fitFracAsymm_; //! A_CP parameter std::vector acp_; //! The mean efficiency for the antiparticle LauParameter meanEffB0bar_; //! The mean efficiency for the particle LauParameter meanEffB0_; //! The average DP rate for the antiparticle LauParameter DPRateB0bar_; //! The average DP rate for the particle LauParameter DPRateB0_; //! Signal yields LauParameter* signalEvents_; //! Signal asymmetry LauParameter* signalAsym_; //! Background yield(s) LauBkgndYieldList bkgndEvents_; //! Background asymmetries(s) LauBkgndYieldList bkgndAsym_; //! CP eigenvalue variable name TString cpevVarName_; //! CP eigenvalue for current event CPEigenvalue cpEigenValue_; //! Vector to store event CP eigenvalues std::vector evtCPEigenVals_; //! The mass difference between the neutral mass eigenstates LauParameter deltaM_; //! The width difference between the neutral mass eigenstates LauParameter deltaGamma_; //! The lifetime LauParameter tau_; //! The mixing phase LauParameter phiMix_; //! The sine of the mixing phase LauParameter sinPhiMix_; //! The cosine of the mixing phase LauParameter cosPhiMix_; //! Flag whether to use the sine and cosine of the mixing phase or the phase itself as the fit parameters Bool_t useSinCos_; //! e^{-i*phiMix} LauComplex phiMixComplex_; //! Decay time PDFs (one per tagging category) LauTagCatDtPdfMap signalDecayTimePdfs_; //! Decay time for the current event Double_t curEvtDecayTime_; //! Decay time error for the current event Double_t curEvtDecayTimeErr_; //! PDFs for other variables LauTagCatPdfListMap sigExtraPdf_; //! eta PDFs for each TagCat LauTagCatPdfMap sigFlavTagPdf_; //! eta PDFs for each background LauBkgdPdfMap bkgdFlavTagPdf_; // Toy generation stuff //! The maximum allowed number of attempts when generating an event Int_t iterationsMax_; //! The number of unsucessful attempts to generate an event so far Int_t nGenLoop_; //! The value of A squared for the current event Double_t ASq_; //! The maximum value of A squared that has been seen so far while generating Double_t aSqMaxVar_; //! The maximum allowed value of A squared Double_t aSqMaxSet_; //! Flag for storage of amplitude info in generated ntuple Bool_t storeGenAmpInfo_; //! The signal event tree for embedding fully simulated events LauTagCatEmbDataMap signalTree_; //! The background event tree for embedding fully simulated events LauTagCatEmbDataMapList bkgndTree_; //! Boolean to control reuse of embedded signal events Bool_t reuseSignal_; //! Vector of booleans to reuse background events LauBkgndReuseEventsList reuseBkgnd_; // Likelihood values //! Signal DP likelihood value Double_t sigDPLike_; //! Signal likelihood from extra PDFs Double_t sigExtraLike_; Double_t sigFlavTagLike_; Double_t bkgdFlavTagLike_; //! Total signal likelihood Double_t sigTotalLike_; //! Background DP likelihood value(s) std::vector bkgndDPLike_; //! Background likelihood value(s) from extra PDFs std::vector bkgndExtraLike_; //! Total background likelihood(s) std::vector bkgndTotalLike_; ClassDef(LauTimeDepFitModel,0) // Time-dependent neutral model }; #endif diff --git a/inc/LauTimeDepFlavModel.hh b/inc/LauTimeDepFlavModel.hh index 41a12d8..8144f9e 100644 --- a/inc/LauTimeDepFlavModel.hh +++ b/inc/LauTimeDepFlavModel.hh @@ -1,633 +1,633 @@ /* Copyright 2015 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauTimeDepFlavModel.hh \brief File containing declaration of LauTimeDepFlavModel class. */ /*! \class LauTimeDepFlavModel \brief Class for defining a time-dependent fit model. LauTimeDepFlavModel is a class that allows the user to define a three-body Dalitz plot according to the isobar model, i.e. defining a set of resonances that have complex amplitudes that can interfere with each other. It extends the LauSimpleFitModel and LauCPFitModel models in that it allows the fitting of time-dependent particle/antiparticle decays to flavour-conjugate Dalitz plots, including their interference through mixing. */ #ifndef LAU_TIMEDEP_FLAV_MODEL #define LAU_TIMEDEP_FLAV_MODEL #include #include #include #include #include "TString.h" #include "TStopwatch.h" #include "TSystem.h" #include "LauAbsFitModel.hh" #include "LauConstants.hh" #include "LauEmbeddedData.hh" #include "LauParameter.hh" class LauAbsBkgndDPModel; class LauAbsCoeffSet; class LauAbsPdf; class LauDecayTimePdf; class LauIsobarDynamics; class LauKinematics; class LauScfMap; class LauTimeDepFlavModel : public LauAbsFitModel { public: //! Possible CP eigenvalues (the intrinsic CP of the final state particles) enum CPEigenvalue { CPOdd = -1, /*!< CP odd final state */ CPEven = 1 /*!< CP even final state */ }; //! Constructor /*! \param [in] modelB0bar DP model for the antiparticle \param [in] modelB0 DP model for the particle \param [in] useUntaggedEvents should the untagged sample be used or excluded? \param [in] tagVarName the variable name in the data tree that specifies the event tag \param [in] tagCatVarName the variable name in the data tree that specifies the event tagging category */ LauTimeDepFlavModel(LauIsobarDynamics* modelB0bar, LauIsobarDynamics* modelB0, const Bool_t useUntaggedEvents = kTRUE, const TString& tagVarName = "tagFlv", const TString& tagCatVarName = "tagCat"); //! Destructor virtual ~LauTimeDepFlavModel(); //! Set the signal event yield /*! \param [in] nSigEvents contains the signal yield and option to fix it */ virtual void setNSigEvents(LauParameter* nSigEvents); //! Set the signal event yield and asymmetry /*! \param [in] nSigEvents contains the signal yield and option to fix it \param [in] sigAsym contains the signal asymmetry and option to fix it */ virtual void setNSigEvents(LauParameter* nSigEvents, LauParameter* sigAsym); //! Set the number of background events /*! The name of the parameter must be that of the corresponding background category (so that it can be correctly assigned) \param [in] nBkgndEvents contains the name, yield and option to fix the yield of the background */ - virtual void setNBkgndEvents(LauParameter* nBkgndEvents); + virtual void setNBkgndEvents(LauAbsRValue* nBkgndEvents); //! Switch on/off storage of amplitude info in generated ntuple void storeGenAmpInfo(Bool_t storeInfo) { storeGenAmpInfo_ = storeInfo; } //! Set CP eigenvalue /*! The CP eigenvalue can be supplied on an event-by-event basis, e.g. if the data contains daughters that are D0 mesons that can decay to either K+ K- (CP even) or KS pi0 (CP odd). This method allows you to set the default value that should be used if the data does not contain this information as well as the name of the variable in the data that will specify this information. If completely unspecified all events will be assumed to be CP even. \param defaultCPEV the default for the eigenvalue \param evVarName the variable name in the data tree that specifies the CP eigenvalue */ inline void setCPEigenvalue( const CPEigenvalue defaultCPEV, const TString& cpevVarName = "" ) { cpEigenValue_ = defaultCPEV; cpevVarName_ = cpevVarName; } //! Add a tagging category to the list of valid categories /*! NB category 0 is always valid and corresponds to untagged events. Whether untagged events are used in the fit or note is controlled by a constructor argument. \param [in] tagCat the tagging category ID */ void addValidTagCat(const Int_t tagCat); //! Add several tagging categories to the list of valid categories /*! NB category 0 is always valid and corresponds to untagged events. Whether untagged events are used in the fit or note is controlled by a constructor argument. \param [in] tagCats the list of tagging category IDs */ void addValidTagCats(const std::vector& tagCats); //! Check the validity of the given tagging category /*! \param [in] tagCat the tagging category ID */ Bool_t validTagCat(const Int_t tagCat) const; //! Set the DP amplitude coefficients /*! \param [in] coeffSet the set of coefficients */ void setAmpCoeffSet(LauAbsCoeffSet* coeffSet); //! Set the DP amplitude coefficients for the two Dalitz plots /*! \param [in] coeffSet_B0f_B0barfbar the set of coefficients for B0 (B0bar) -> f (fbar) \param [in] coeffSet_B0fbar_B0barf the set of coefficients for B0 (B0bar) -> fbar (f) */ //void setBothDPAmpCoeffSet(LauAbsCoeffSet* coeffSet_B0f_B0barfbar, LauAbsCoeffSet* coeffSet_B0fbar_B0barf); //! Change the dilutions, delta dilutions and tagCatFrac for signal if needed /*! \param [in] tagCat the tagging category to adjust \param [in] tagCatFrac the tagging category fraction \param [in] dilution the tagging category average dilution = (1 - 2 * avg_mistag_fraction) \param [in] deltaDilution the tagging category dilution difference TODO - check sign convention \param [in] fixTCFrac whether to fix or float the tagging category fraction */ void setSignalTagCatPars(const Int_t tagCat, const Double_t tagCatFrac, const Double_t dilution, const Double_t deltaDilution, const Bool_t fixTCFrac = kTRUE); //! Set the decay time PDFs /*! \param [in] tagCat the tagging category for which the PDF should be used \param [in] pdf the signal decay time PDF */ void setSignalDtPdf(const Int_t tagCat, LauDecayTimePdf* pdf); //! Set the signal PDF for a given variable /*! \param [in] tagCat the tagging category for which the PDF should be used \param [in] pdf the PDF to be added to the signal model */ void setSignalPdfs(const Int_t tagCat, LauAbsPdf* pdf); //! Embed full simulation events for the signal, rather than generating toy from the PDFs /*! \param [in] tagCat the tagging category for which the file should be used \param [in] fileName the name of the file containing the events \param [in] treeName the name of the tree \param [in] reuseEventsWithinEnsemble \param [in] reuseEventsWithinExperiment \param [in] useReweighting */ void embedSignal(const Int_t tagCat, const TString& fileName, const TString& treeName, const Bool_t reuseEventsWithinEnsemble, const Bool_t reuseEventsWithinExperiment = kFALSE); //! Set the value of the mixing phase /*! \param [in] phiMix the value of the mixing phase \param [in] fixPhiMix whether the value should be fixed or floated \param [in] useSinCos whether to use the sine and cosine as separate parameters or to just use the mixing phase itself */ void setPhiMix(const Double_t phiMix, const Bool_t fixPhiMix, const Bool_t useSinCos = kFALSE); //! Initialise the fit virtual void initialise(); //! Initialise the signal DP model virtual void initialiseDPModels(); //! Recalculate Normalization the signal DP models virtual void recalculateNormalisation(); //! Update the coefficients virtual void updateCoeffs(); // Toy MC generation and fitting overloaded functions virtual Bool_t genExpt(); //! Set the maximum value of A squared to be used in the accept/reject /*! \param [in] value the new value */ inline void setASqMaxValue(const Double_t value) {aSqMaxSet_ = value;} //! Weight events based on the DP model /*! \param [in] dataFileName the name of the data file \param [in] dataTreeName the name of the data tree */ virtual void weightEvents( const TString& dataFileName, const TString& dataTreeName ); //! Calculate things that depend on the fit parameters after they have been updated by Minuit virtual void propagateParUpdates(); //! Read in the input fit data variables, e.g. m13Sq and m23Sq virtual void cacheInputFitVars(); //! Check the initial fit parameters virtual void checkInitFitParams(); //! Get the fit results and store them /*! \param [in] tablePrefixName prefix for the name of the output file */ virtual void finaliseFitResults(const TString& tablePrefixName); //! Print the fit fractions, total DP rate and mean efficiency /*! \param [out] output the stream to which to print */ virtual void printFitFractions(std::ostream& output); //! Print the asymmetries /*! \param [out] output the stream to which to print */ virtual void printAsymmetries(std::ostream& output); //! Write the fit results in latex table format /*! \param [in] outputFile the name of the output file */ virtual void writeOutTable(const TString& outputFile); //! Store the per event likelihood values virtual void storePerEvtLlhds(); // Methods to do with calculating the likelihood functions // and manipulating the fitting parameters. //! Get the total likelihood for each event /*! \param [in] iEvt the event number */ virtual Double_t getTotEvtLikelihood(const UInt_t iEvt); //! Calculate the signal and background likelihoods for the DP for a given event /*! \param [in] iEvt the event number */ virtual void getEvtDPDtLikelihood(const UInt_t iEvt); //! Determine the signal and background likelihood for the extra variables for a given event /*! \param [in] iEvt the event number */ virtual void getEvtExtraLikelihoods(const UInt_t iEvt); //! Get the total number of events /*! \return the total number of events */ virtual Double_t getEventSum() const; //! Set the fit parameters for the DP model void setSignalDPParameters(); //! Set the fit parameters for the decay time PDFs void setDecayTimeParameters(); //! Set the fit parameters for the extra PDFs void setExtraPdfParameters(); //! Set the initial yields void setFitNEvents(); //! Set-up other parameters that are derived from the fit results, e.g. fit fractions void setExtraNtupleVars(); //! Randomise the initial fit parameters void randomiseInitFitPars(); //! Method to set up the storage for background-related quantities called by setBkgndClassNames virtual void setupBkgndVectors(); //! Calculate the CP asymmetries /*! \param [in] initValues is this before or after the fit */ void calcAsymmetries(const Bool_t initValues = kFALSE); //! Finalise value of mixing phase void checkMixingPhase(); protected: typedef std::map< Int_t, LauDecayTimePdf*> LauTagCatDtPdfMap; typedef std::map< Int_t, LauParameter> LauTagCatParamMap; typedef std::map< Int_t, LauPdfList > LauTagCatPdfMap; typedef std::map< Int_t, Int_t > LauTagCatEventsMap; typedef std::map< Int_t, LauEmbeddedData* > LauTagCatEmbDataMap; typedef std::map< Int_t, std::pair > LauTagCatGenInfo; typedef std::map< std::pair, LauTagCatGenInfo > LauGenInfo; //! Determine the number of events to generate for each hypothesis LauGenInfo eventsToGenerate(); //! Generate signal event Bool_t generateSignalEvent(); //! Setup the required ntuple branches void setupGenNtupleBranches(); //! Store all of the DP and decay time information void setDPDtBranchValues(); //! Generate from the extra PDFs /*! \param [in] extraPdfs the list of extra PDFs \param [in] embeddedData the embedded data sample */ void generateExtraPdfValues(LauPdfList* extraPdfs, LauEmbeddedData* embeddedData); //! Add sPlot branches for the extra PDFs /*! \param [in] extraPdfs the list of extra PDFs \param [in] prefix the list of prefixes for the branch names */ void addSPlotNtupleBranches(const LauPdfList* extraPdfs, const TString& prefix); //! Set the branches for the sPlot ntuple with extra PDFs /*! \param [in] extraPdfs the list of extra PDFs \param [in] prefix the list of prefixes for the branch names \param [in] iEvt the event number */ Double_t setSPlotNtupleBranchValues(LauPdfList* extraPdfs, const TString& prefix, UInt_t iEvt); //! Update the signal events after Minuit sets background parameters void updateSigEvents(); //! Add branches to store experiment number and the event number within the experiment virtual void setupSPlotNtupleBranches(); //! Returns the names of all variables in the fit virtual LauSPlot::NameSet variableNames() const; //! Returns the names and yields of species that are free in the fit virtual LauSPlot::NumbMap freeSpeciesNames() const; //! Returns the names and yields of species that are fixed in the fit virtual LauSPlot::NumbMap fixdSpeciesNames() const; //! Returns the species and variables for all 2D PDFs in the fit virtual LauSPlot::TwoDMap twodimPDFs() const; //! Check if the signal is split into well-reconstructed and mis-reconstructed types virtual Bool_t splitSignal() const { return kFALSE; } //! Check if the mis-reconstructed signal is to be smeared in the DP virtual Bool_t scfDPSmear() const { return kFALSE; } //! Check that the tagging category fractions are all present and sum to unity /*! \param [in] theMap the container of tagcat fractions */ Bool_t checkTagCatFracMap(const LauTagCatParamMap& theMap) const; //! Check the signal tagging category fractions void checkSignalTagCatFractions(); //! Calculates the fraction of the first tagging category based on the others /*! \param [in,out] theMap the container of tagcat fractions */ void setFirstTagCatFrac(LauTagCatParamMap& theMap); //! Add the parameters from each PDF into the fit /*! \param [in] theMap the container of PDFs */ UInt_t addParametersToFitList(LauTagCatPdfMap& theMap); //! Add the parameters from each decay time PDF into the fit /*! \param [in] theMap the container of PDFs */ UInt_t addParametersToFitList(LauTagCatDtPdfMap& theMap); //! Calculate the component integrals of the interference term void calcInterferenceTermIntegrals(); //! Calculate the total integral of the interference term void calcInterTermNorm(); private: //! Dalitz plot PDF for the antiparticle LauIsobarDynamics* sigModelB0bar_; //! Dalitz plot PDF for the particle LauIsobarDynamics* sigModelB0_; //! Kinematics object for antiparticle LauKinematics* kinematicsB0bar_; //! Kinematics object for particle LauKinematics* kinematicsB0_; //! Whether or not to use untagged events Bool_t useUntaggedEvents_; //! Number of signal components UInt_t nSigComp_; //! Number of signal DP parameters UInt_t nSigDPPar_; //! Number of decay time PDF parameters UInt_t nDecayTimePar_; //! Number of extra PDF parameters UInt_t nExtraPdfPar_; //! Number of normalisation parameters (yields, asymmetries) UInt_t nNormPar_; //! The complex coefficients for antiparticle std::vector coeffsB0bar_; //! The complex coefficients for particle std::vector coeffsB0_; //! Magnitudes and Phases or Real and Imaginary Parts std::vector coeffPars_; //! The integrals of the efficiency corrected amplitude cross terms for each pair of amplitude components /*! Calculated as the sum of A* x Abar x efficiency */ std::vector< std::vector > fifjEffSum_; //! The normalisation for the term 2.0*Re(A*Abar*phiMix) Double_t interTermReNorm_; //! The normalisation for the term 2.0*Im(A*Abar*phiMix) Double_t interTermImNorm_; //! The antiparticle fit fractions LauParArray fitFracB0bar_; //! The particle fit fractions LauParArray fitFracB0_; //! The fit fraction asymmetries std::vector fitFracAsymm_; //! A_CP parameter std::vector acp_; //! The mean efficiency for the antiparticle LauParameter meanEffB0bar_; //! The mean efficiency for the particle LauParameter meanEffB0_; //! The average DP rate for the antiparticle LauParameter DPRateB0bar_; //! The average DP rate for the particle LauParameter DPRateB0_; //! Signal yields LauParameter* signalEvents_; //! Signal asymmetry LauParameter* signalAsym_; //! Signal tagging category fractions LauTagCatParamMap signalTagCatFrac_; //! Flavour tagging variable name TString tagVarName_; //! Tagging category variable name TString tagCatVarName_; //! CP eigenvalue variable name TString cpevVarName_; //! The allowed tagging categories std::set validTagCats_; //! Flavour tag for current event Int_t curEvtTagFlv_; //! Tagging category for current event Int_t curEvtTagCat_; //! CP eigenvalue for current event CPEigenvalue cpEigenValue_; //! Vector to store event flavour tags std::vector evtTagFlvVals_; //! Vector to store event tagging categories std::vector evtTagCatVals_; //! Vector to store event CP eigenvalues std::vector evtCPEigenVals_; //! Average dilutions LauTagCatParamMap dilution_; //! Dilution differences LauTagCatParamMap deltaDilution_; //! The mass difference between the neutral mass eigenstates LauParameter deltaM_; //! The width difference between the neutral mass eigenstates LauParameter deltaGamma_; //! The lifetime LauParameter tau_; //! The mixing phase LauParameter phiMix_; //! The sine of the mixing phase LauParameter sinPhiMix_; //! The cosine of the mixing phase LauParameter cosPhiMix_; //! Flag whether to use the sine and cosine of the mixing phase or the phase itself as the fit parameters Bool_t useSinCos_; //! e^{-i*phiMix} LauComplex phiMixComplex_; //! Decay time PDFs (one per tagging category) LauTagCatDtPdfMap signalDecayTimePdfs_; //! Decay time for the current event Double_t curEvtDecayTime_; //! Decay time error for the current event Double_t curEvtDecayTimeErr_; //! PDFs for other variables LauTagCatPdfMap sigExtraPdf_; // Toy generation stuff //! The maximum allowed number of attempts when generating an event Int_t iterationsMax_; //! The number of unsucessful attempts to generate an event so far Int_t nGenLoop_; //! The value of A squared for the current event Double_t ASq_; //! The maximum value of A squared that has been seen so far while generating Double_t aSqMaxVar_; //! The maximum allowed value of A squared Double_t aSqMaxSet_; //! Flag for storage of amplitude info in generated ntuple Bool_t storeGenAmpInfo_; //! The signal event tree for embedding fully simulated events LauTagCatEmbDataMap signalTree_; //! Boolean to control reuse of embedded signal events Bool_t reuseSignal_; // Likelihood values //! Signal DP likelihood value Double_t sigDPLike_; //! Signal likelihood from extra PDFs Double_t sigExtraLike_; //! Total signal likelihood Double_t sigTotalLike_; ClassDef(LauTimeDepFlavModel,0) // Time-dependent neutral model }; #endif diff --git a/inc/LauTimeDepNonFlavModel.hh b/inc/LauTimeDepNonFlavModel.hh index c1f7e56..929a5de 100644 --- a/inc/LauTimeDepNonFlavModel.hh +++ b/inc/LauTimeDepNonFlavModel.hh @@ -1,730 +1,730 @@ /* Copyright 2015 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauTimeDepNonFlavModel.hh \brief File containing declaration of LauTimeDepNonFlavModel class. */ /*! \class LauTimeDepNonFlavModel \brief Class for defining a time-dependent fit model for non flavour conjugate Dalitz plots. LauTimeDepNonFlavModel is a class that allows the user to define a three-body Dalitz plot according to the isobar model, i.e. defining a set of resonances that have complex amplitudes that can interfere with each other. It extends the LauTimeDepFlavModel to allow fitting two simultaneous Dalitz plots which are not flavour conjugate, including accordingly the interference through the mixing. */ #ifndef LAU_TIMEDEP_NONFLAV_MODEL #define LAU_TIMEDEP_NONFLAV_MODEL #include #include #include #include #include "TString.h" #include "TStopwatch.h" #include "TSystem.h" #include "LauAbsFitModel.hh" #include "LauConstants.hh" #include "LauEmbeddedData.hh" #include "LauParameter.hh" class LauAbsBkgndDPModel; class LauAbsCoeffSet; class LauAbsPdf; class LauDecayTimePdf; class LauIsobarDynamics; class LauKinematics; class LauScfMap; class LauTimeDepNonFlavModel : public LauAbsFitModel { public: //! Possible CP eigenvalues (the intrinsic CP of the final state particles) enum CPEigenvalue { CPOdd = -1, /*!< CP odd final state */ CPEven = 1 /*!< CP even final state */ }; //! Constructor /*! \param [in] modelB0bar_DP1 Dalitz model for the antiparticle in the f final state \param [in] modelB0_DP1 Dalitz model for the particle in the f final state \param [in] modelB0bar_DP2 Dalitz model for the antiparticle in the fbar final state \param [in] modelB0_DP2 Dalitz model for the particle in the fbar final state \param [in] useUntaggedEvents should the untagged sample be used or excluded? \param [in] tagVarName the variable name in the data tree that specifies the event tag \param [in] tagCatVarName the variable name in the data tree that specifies the event tagging category */ LauTimeDepNonFlavModel(LauIsobarDynamics* modelB0bar_f, LauIsobarDynamics* modelB0_f, LauIsobarDynamics* modelB0bar_fbar, LauIsobarDynamics* modelB0_fbar, const Bool_t useUntaggedEvents = kTRUE, const TString& tagVarName = "tagFlv", const TString& tagCatVarName = "tagCat"); //! Destructor virtual ~LauTimeDepNonFlavModel(); //! Set the signal event yield /*! \param [in] nSigEvents contains the signal yield and option to fix it */ virtual void setNSigEvents(LauParameter* nSigEvents); //! Set the signal event yield and asymmetry /*! \param [in] nSigEvents contains the signal yield and option to fix it \param [in] sigAsym contains the signal asymmetry and option to fix it */ virtual void setNSigEvents(LauParameter* nSigEvents, LauParameter* sigAsym); //! Set the number of background events /*! The name of the parameter must be that of the corresponding background category (so that it can be correctly assigned) \param [in] nBkgndEvents contains the name, yield and option to fix the yield of the background */ - virtual void setNBkgndEvents(LauParameter* nBkgndEvents); + virtual void setNBkgndEvents(LauAbsRValue* nBkgndEvents); //! Switch on/off storage of amplitude info in generated ntuple void storeGenAmpInfo(Bool_t storeInfo) { storeGenAmpInfo_ = storeInfo; } //! Set CP eigenvalue /*! The CP eigenvalue can be supplied on an event-by-event basis, e.g. if the data contains daughters that are D0 mesons that can decay to either K+ K- (CP even) or KS pi0 (CP odd). This method allows you to set the default value that should be used if the data does not contain this information as well as the name of the variable in the data that will specify this information. If completely unspecified all events will be assumed to be CP even. \param defaultCPEV the default for the eigenvalue \param evVarName the variable name in the data tree that specifies the CP eigenvalue */ inline void setCPEigenvalue( const CPEigenvalue defaultCPEV, const TString& cpevVarName = "" ) { cpEigenValue_ = defaultCPEV; cpevVarName_ = cpevVarName; } //! Add a tagging category to the list of valid categories /*! NB category 0 is always valid and corresponds to untagged events. Whether untagged events are used in the fit or note is controlled by a constructor argument. \param [in] tagCat the tagging category ID */ void addValidTagCat(const Int_t tagCat); //! Add several tagging categories to the list of valid categories /*! NB category 0 is always valid and corresponds to untagged events. Whether untagged events are used in the fit or note is controlled by a constructor argument. \param [in] tagCats the list of tagging category IDs */ void addValidTagCats(const std::vector& tagCats); //! Check the validity of the given tagging category /*! \param [in] tagCat the tagging category ID */ Bool_t validTagCat(const Int_t tagCat) const; //! Set the DP amplitude coefficients //! TODO: remove this function /*! \param [in] coeffSet the set of coefficients */ void setAmpCoeffSet(LauAbsCoeffSet* coeffSet); //! Set the DP amplitude coefficients for the two Dalitz plots /*! \param [in] coeffSet_B0f_B0barfbar the set of coefficients for B0 (B0bar) -> f (fbar) \param [in] coeffSet_B0fbar_B0barf the set of coefficients for B0 (B0bar) -> fbar (f) */ void setAmpCoeffSet(LauAbsCoeffSet* coeffSet_B0f_B0barfbar, LauAbsCoeffSet* coeffSet_B0fbar_B0barf); //! Change the dilutions, delta dilutions and tagCatFrac for signal if needed /*! \param [in] tagCat the tagging category to adjust \param [in] tagCatFrac the tagging category fraction \param [in] dilution the tagging category average dilution = (1 - 2 * avg_mistag_fraction) \param [in] deltaDilution the tagging category dilution difference TODO - check sign convention \param [in] fixTCFrac whether to fix or float the tagging category fraction */ void setSignalTagCatPars(const Int_t tagCat, const Double_t tagCatFrac, const Double_t dilution, const Double_t deltaDilution, const Bool_t fixTCFrac = kTRUE); //! Set the decay time PDFs /*! \param [in] tagCat the tagging category for which the PDF should be used \param [in] pdf the signal decay time PDF */ void setSignalDtPdf(const Int_t tagCat, LauDecayTimePdf* pdf); //! Set the signal PDF for a given variable /*! \param [in] tagCat the tagging category for which the PDF should be used \param [in] pdf the PDF to be added to the signal model */ void setSignalPdfs(const Int_t tagCat, LauAbsPdf* pdf); //! Embed full simulation events for the signal, rather than generating toy from the PDFs /*! \param [in] tagCat the tagging category for which the file should be used \param [in] fileName the name of the file containing the events \param [in] treeName the name of the tree \param [in] reuseEventsWithinEnsemble \param [in] reuseEventsWithinExperiment \param [in] useReweighting */ void embedSignal(const Int_t tagCat, const TString& fileName, const TString& treeName, const Bool_t reuseEventsWithinEnsemble, const Bool_t reuseEventsWithinExperiment = kFALSE); //! Set the value of the mixing phase /*! \param [in] phiMix the value of the mixing phase \param [in] fixPhiMix whether the value should be fixed or floated \param [in] useSinCos whether to use the sine and cosine as separate parameters or to just use the mixing phase itself */ void setPhiMix(const Double_t phiMix, const Bool_t fixPhiMix, const Bool_t useSinCos = kFALSE); //! Initialise the fit virtual void initialise(); //! Initialise the signal DP model virtual void initialiseDPModels(); //! Recalculate Normalization the signal DP models virtual void recalculateNormalisation(); //! Update the coefficients virtual void updateCoeffs(); // Toy MC generation and fitting overloaded functions virtual Bool_t genExpt(); //! Set the maximum value of A squared to be used in the accept/reject /*! \param [in] value the new value */ inline void setASqMaxValue(const Double_t value) {aSqMaxSet_ = value;} //! Weight events based on the DP model /*! \param [in] dataFileName the name of the data file \param [in] dataTreeName the name of the data tree */ virtual void weightEvents( const TString& dataFileName, const TString& dataTreeName ); //! Calculate things that depend on the fit parameters after they have been updated by Minuit virtual void propagateParUpdates(); //! Read in the input fit data variables, e.g. m13Sq and m23Sq virtual void cacheInputFitVars(); //! Check the initial fit parameters virtual void checkInitFitParams(); //! Get the fit results and store them /*! \param [in] tablePrefixName prefix for the name of the output file */ virtual void finaliseFitResults(const TString& tablePrefixName); //! Print the fit fractions, total DP rate and mean efficiency /*! \param [out] output the stream to which to print */ virtual void printFitFractions(std::ostream& output); //! Save the pdf Plots for all the resonances of experiment number fitExp /*! TODO - not working in this model!! \param [in] label prefix for the file name to be saved */ virtual void savePDFPlots(const TString& label); //! Save the pdf Plots for the sum of ressonances correspondint to "sin" of experiment number fitExp /*! TODO - not working in this model!! \param [in] label prefix for the file name to be saved \param [in] spin spin of the wave to be saved */ virtual void savePDFPlotsWave(const TString& label, const Int_t& spin); //! Print the asymmetries /*! \param [out] output the stream to which to print */ virtual void printAsymmetries(std::ostream& output); //! Write the fit results in latex table format /*! \param [in] outputFile the name of the output file */ virtual void writeOutTable(const TString& outputFile); //! Store the per event likelihood values virtual void storePerEvtLlhds(); // Methods to do with calculating the likelihood functions // and manipulating the fitting parameters. //! Get the total likelihood for each event /*! \param [in] iEvt the event number */ virtual Double_t getTotEvtLikelihood(const UInt_t iEvt); //! Calculate the signal and background likelihoods for the DP for a given event /*! \param [in] iEvt the event number */ virtual void getEvtDPDtLikelihood(const UInt_t iEvt); //! Determine the signal and background likelihood for the extra variables for a given event /*! \param [in] iEvt the event number */ virtual void getEvtExtraLikelihoods(const UInt_t iEvt); //! Get the total number of events /*! \return the total number of events */ virtual Double_t getEventSum() const; //! Set the fit parameters for the DP model void setSignalDPParameters(); //! Set the fit parameters for the decay time PDFs void setDecayTimeParameters(); //! Set the fit parameters for the extra PDFs void setExtraPdfParameters(); //! Set the initial yields void setFitNEvents(); //! Set-up other parameters that are derived from the fit results, e.g. fit fractions void setExtraNtupleVars(); //! Randomise the initial fit parameters void randomiseInitFitPars(); //! Method to set up the storage for background-related quantities called by setBkgndClassNames virtual void setupBkgndVectors(); //! Calculate the CP asymmetries /*! \param [in] initValues is this before or after the fit */ void calcAsymmetries(const Bool_t initValues = kFALSE); //! Finalise value of mixing phase void checkMixingPhase(); protected: typedef std::map< Int_t, LauDecayTimePdf*> LauTagCatDtPdfMap; typedef std::map< Int_t, LauParameter> LauTagCatParamMap; typedef std::map< Int_t, LauPdfList > LauTagCatPdfMap; typedef std::map< Int_t, Int_t > LauTagCatEventsMap; typedef std::map< Int_t, LauEmbeddedData* > LauTagCatEmbDataMap; typedef std::map< Int_t, std::pair > LauTagCatGenInfo; typedef std::map< std::pair, LauTagCatGenInfo > LauGenInfo; //! Determine the number of events to generate for each hypothesis LauGenInfo eventsToGenerate(); //! Generate signal event Bool_t generateSignalEvent(); //! Determine the decay amplitude for A and Abar for a given f/fbar final state void calculateDPterms(LauDecayTimePdf* decayTimePdf, LauIsobarDynamics* sigModelB0bar, LauIsobarDynamics* sigModelB0); //! Store the decay-time DP normalisation for both f anf fbar final states void calculateAmplitudeNorm(LauDecayTimePdf* decayTimePdf); //! Setup the required ntuple branches void setupGenNtupleBranches(); //! Store all of the DP and decay time information void setDPDtBranchValues(); //! Generate from the extra PDFs /*! \param [in] extraPdfs the list of extra PDFs \param [in] embeddedData the embedded data sample */ void generateExtraPdfValues(LauPdfList* extraPdfs, LauEmbeddedData* embeddedData); //! Add sPlot branches for the extra PDFs /*! \param [in] extraPdfs the list of extra PDFs \param [in] prefix the list of prefixes for the branch names */ void addSPlotNtupleBranches(const LauPdfList* extraPdfs, const TString& prefix); //! Set the branches for the sPlot ntuple with extra PDFs /*! \param [in] extraPdfs the list of extra PDFs \param [in] prefix the list of prefixes for the branch names \param [in] iEvt the event number */ Double_t setSPlotNtupleBranchValues(LauPdfList* extraPdfs, const TString& prefix, UInt_t iEvt); //! Update the signal events after Minuit sets background parameters void updateSigEvents(); //! Add branches to store experiment number and the event number within the experiment virtual void setupSPlotNtupleBranches(); //! Returns the names of all variables in the fit virtual LauSPlot::NameSet variableNames() const; //! Returns the names and yields of species that are free in the fit virtual LauSPlot::NumbMap freeSpeciesNames() const; //! Returns the names and yields of species that are fixed in the fit virtual LauSPlot::NumbMap fixdSpeciesNames() const; //! Returns the species and variables for all 2D PDFs in the fit virtual LauSPlot::TwoDMap twodimPDFs() const; //! Check if the signal is split into well-reconstructed and mis-reconstructed types virtual Bool_t splitSignal() const { return kFALSE; } //! Check if the mis-reconstructed signal is to be smeared in the DP virtual Bool_t scfDPSmear() const { return kFALSE; } //! Check that the tagging category fractions are all present and sum to unity /*! \param [in] theMap the container of tagcat fractions */ Bool_t checkTagCatFracMap(const LauTagCatParamMap& theMap) const; //! Check the signal tagging category fractions void checkSignalTagCatFractions(); //! Calculates the fraction of the first tagging category based on the others /*! \param [in,out] theMap the container of tagcat fractions */ void setFirstTagCatFrac(LauTagCatParamMap& theMap); //! Add the parameters from each PDF into the fit /*! \param [in] theMap the container of PDFs */ UInt_t addParametersToFitList(LauTagCatPdfMap& theMap); //! Add the parameters from each decay time PDF into the fit /*! \param [in] theMap the container of PDFs */ UInt_t addParametersToFitList(LauTagCatDtPdfMap& theMap); //! Calculate the component integrals of the interference term void calcInterferenceTermIntegrals(); //! Calculate the total integral of the interference term void calcInterTermNorm(); private: //! Dalitz plot PDF for the antiparticle decaying into the f final state LauIsobarDynamics* sigModelB0bar_f_; //! Dalitz plot PDF for the particle decaying into the f final state LauIsobarDynamics* sigModelB0_f_; //! Dalitz plot PDF for the antiparticle decaying into the fbar final state LauIsobarDynamics* sigModelB0bar_fbar_; //! Dalitz plot PDF for the particle decaying into the fbar final state LauIsobarDynamics* sigModelB0_fbar_; //! Kinematics object for antiparticle decaying into the f final state LauKinematics* kinematicsB0bar_f_; //! Kinematics object for particle decaying into the f final state LauKinematics* kinematicsB0_f_; //! Kinematics object for antiparticle decaying into the fbar final state LauKinematics* kinematicsB0bar_fbar_; //! Kinematics object for particle decaying into the fbar final state LauKinematics* kinematicsB0_fbar_; //! Whether or not to use untagged events Bool_t useUntaggedEvents_; //! Number of signal components UInt_t nSigComp_; //! Number of signal DP parameters UInt_t nSigDPPar_; //! Number of decay time PDF parameters UInt_t nDecayTimePar_; //! Number of extra PDF parameters UInt_t nExtraPdfPar_; //! Number of normalisation parameters (yields, asymmetries) UInt_t nNormPar_; //! The complex coefficients for antiparticle decaying into f final state std::vector coeffsB0bar_f_; //! The complex coefficients for particle decaying into f final state std::vector coeffsB0_f_; //! The complex coefficients for antiparticle decaying into fbar final state std::vector coeffsB0bar_fbar_; //! The complex coefficients for particle decaying into fbar final state std::vector coeffsB0_fbar_; //! Magnitudes and Phases or Real and Imaginary Parts for B0 (B0bar) -> f (fbar) std::vector coeffPars_B0f_B0barfbar_; //! Magnitudes and Phases or Real and Imaginary Parts for B0 (B0bar) -> fbar (f) std::vector coeffPars_B0fbar_B0barf_; //! The integrals of the efficiency corrected amplitude cross terms for each pair of amplitude components //! for the same f final state, e.g. |Abar->f|x |A*-> f| /*! Calculated as the sum of A* x Abar x efficiency */ std::vector< std::vector > fifjEffSum_f_; //! The integrals of the efficiency corrected amplitude cross terms for each pair of amplitude components //! for the same f final state, e.g. |Abar->fbar|x |A*-> fbar| /*! Calculated as the sum of A* x Abar x efficiency */ std::vector< std::vector > fifjEffSum_fbar_; //! The normalisation for the term 2.0*Re(|A->f*|Abar->f|*phiMix) Double_t interTermReNorm_f_; //! The normalisation for the term 2.0*Re(|A->fbar*|Abar->fbar|*phiMix) Double_t interTermReNorm_fbar_; //! The normalisation for the term 2.0*Im(|A->f|*|Abar->f|*phiMix) Double_t interTermImNorm_f_; //! The normalisation for the term 2.0*Im(|A->fbar|*|Abar->fbar|*phiMix) Double_t interTermImNorm_fbar_; //! The antiparticle decaying to the final state f fit fractions LauParArray fitFracB0bar_f_; //! The particle decaying to the final state f fit fraction LauParArray fitFracB0_f_; //! The antiparticle decaying to the final state fbar fit fractions LauParArray fitFracB0bar_fbar_; //! The particle decaying to the final state fbar fit fraction LauParArray fitFracB0_fbar_; //! The fit fraction asymmetries between B0 -> f and B0bar -> fbar std::vector fitFracAsymm_B0f_B0barfbar_; //! The fit fraction asymmetries between B0 -> fbar and B0bar -> f std::vector fitFracAsymm_B0fbar_B0barf_; //! A_CP parameter between B0 -> f and B0bar -> fbar std::vector acp_B0f_B0barfbar_; //! A_CP parameter between B0 -> fbar and B0bar -> f std::vector acp_B0fbar_B0barf_; //! The mean efficiency for the antiparticle decaying to the f final state LauParameter meanEffB0bar_f_; //! The mean efficiency for the particle decaying to teh f final state LauParameter meanEffB0_f_; //! The mean efficiency for the antiparticle decaying to the fbar final state LauParameter meanEffB0bar_fbar_; //! The mean efficiency for the particle decaying to teh fbar final state LauParameter meanEffB0_fbar_; //! The average DP rate for the antiparticle decaying to the f final state LauParameter DPRateB0bar_f_; //! The average DP rate for the particle decaying to the f final state LauParameter DPRateB0_f_; //! The average DP rate for the antiparticle decaying to the fbar final state LauParameter DPRateB0bar_fbar_; //! The average DP rate for the particle decaying to the fbar final state LauParameter DPRateB0_fbar_; //! Signal yields LauParameter* signalEvents_; //! Signal asymmetry LauParameter* signalAsym_; //! Signal tagging category fractions LauTagCatParamMap signalTagCatFrac_; //! Flavour tagging variable name TString tagVarName_; //! Tagging category variable name TString tagCatVarName_; //! CP eigenvalue variable name TString cpevVarName_; //! The allowed tagging categories std::set validTagCats_; //! Flavour tag for current event Int_t curEvtTagFlv_; //! Tagging category for current event Int_t curEvtTagCat_; //! CP eigenvalue for current event CPEigenvalue cpEigenValue_; //! Vector to store event flavour tags std::vector evtTagFlvVals_; //! Vector to store event tagging categories std::vector evtTagCatVals_; //! Vector to store event CP eigenvalues std::vector evtCPEigenVals_; //! Average dilutions LauTagCatParamMap dilution_; //! Dilution differences LauTagCatParamMap deltaDilution_; //! The mass difference between the neutral mass eigenstates LauParameter deltaM_; //! The width difference between the neutral mass eigenstates LauParameter deltaGamma_; //! The lifetime LauParameter tau_; //! The mixing phase LauParameter phiMix_; //! The sine of the mixing phase LauParameter sinPhiMix_; //! The cosine of the mixing phase LauParameter cosPhiMix_; //! Flag whether to use the sine and cosine of the mixing phase or the phase itself as the fit parameters Bool_t useSinCos_; //! e^{-i*phiMix} LauComplex phiMixComplex_; //! Decay time PDFs (one per tagging category) LauTagCatDtPdfMap signalDecayTimePdfs_; //! Decay time for the current event Double_t curEvtDecayTime_; //! Decay time error for the current event Double_t curEvtDecayTimeErr_; //! Dilution term Double_t qD_; //! Delta dilution term Double_t qDDo2_; //! PDFs for other variables LauTagCatPdfMap sigExtraPdf_; //! Final state type with +1 (-1) for the f (fbar) final state Double_t finalState_; // Toy generation stuff //! The maximum allowed number of attempts when generating an event Int_t iterationsMax_; //! The number of unsucessful attempts to generate an event so far Int_t nGenLoop_; //! The value of A squared for the current event Double_t ASq_; //! The maximum value of A squared that has been seen so far while generating Double_t aSqMaxVar_; //! The maximum allowed value of A squared Double_t aSqMaxSet_; //! The time-dependent Dalitz plot Normalisation term for the f final state Double_t normTimeDP_f_; //! The time-dependent Dalitz plot Normalisation term for the fbar final state Double_t normTimeDP_fbar_; //! Flag for storage of amplitude info in generated ntuple Bool_t storeGenAmpInfo_; //! The signal event tree for embedding fully simulated events LauTagCatEmbDataMap signalTree_; //! Boolean to control reuse of embedded signal events Bool_t reuseSignal_; // Likelihood values //! Signal DP likelihood value Double_t sigDPLike_; //! Signal likelihood from extra PDFs Double_t sigExtraLike_; //! Total signal likelihood Double_t sigTotalLike_; ClassDef(LauTimeDepNonFlavModel,0) // Time-dependent neutral model }; #endif diff --git a/src/LauBsCPFitModel.cc b/src/LauBsCPFitModel.cc index 052d12f..9d1d149 100644 --- a/src/LauBsCPFitModel.cc +++ b/src/LauBsCPFitModel.cc @@ -1,2679 +1,2705 @@ /* Copyright 2015 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauBsCPFitModel.cc \brief File containing implementation of LauBsCPFitModel class. */ #include #include #include #include #include "TVirtualFitter.h" #include "TSystem.h" #include "TMinuit.h" #include "TRandom.h" #include "TFile.h" #include "TMath.h" #include "TH2.h" #include "LauAbsBkgndDPModel.hh" #include "LauAbsCoeffSet.hh" #include "LauIsobarDynamics.hh" #include "LauAbsPdf.hh" #include "LauAsymmCalc.hh" #include "LauComplex.hh" #include "LauConstants.hh" #include "LauBsCPFitModel.hh" #include "LauDaughters.hh" #include "LauEffModel.hh" #include "LauFitNtuple.hh" #include "LauKinematics.hh" #include "LauPrint.hh" #include "LauRandom.hh" #include "LauScfMap.hh" #include "LauDPPartialIntegralInfo.hh" ClassImp(LauBsCPFitModel) LauBsCPFitModel::LauBsCPFitModel(LauIsobarDynamics* negModel, LauIsobarDynamics* posModel, Double_t D) : LauAbsFitModel(), negSigModel_(negModel), posSigModel_(posModel), negKinematics_(negModel ? negModel->getKinematics() : 0), posKinematics_(posModel ? posModel->getKinematics() : 0), D_(D), usingBkgnd_(kFALSE), nSigComp_(0), nSigDPPar_(0), nExtraPdfPar_(0), nNormPar_(0), interTermReNorm_(0.0), normDP_(0.0), negMeanEff_("negMeanEff",0.0,0.0,1.0), posMeanEff_("posMeanEff",0.0,0.0,1.0), negDPRate_("negDPRate",0.0,0.0,100.0), posDPRate_("posDPRate",0.0,0.0,100.0), signalEvents_(0), useSCF_(kFALSE), useSCFHist_(kFALSE), scfFrac_("scfFrac",0.0,0.0,1.0), scfFracHist_(0), scfMap_(0), compareFitData_(kFALSE), negParent_("B_s0_bar"), posParent_("B_s0"), iterationsMax_(100000), nGenLoop_(0), ASq_(0.0), aSqMaxVar_(0.0), aSqMaxSet_(1.25), sigDPLike_(0.0), scfDPLike_(0.0), sigExtraLike_(0.0), scfExtraLike_(0.0), sigTotalLike_(0.0), scfTotalLike_(0.0) { const LauDaughters* negDaug = negSigModel_->getDaughters(); if (negDaug != 0) {negParent_ = negDaug->getNameParent();} const LauDaughters* posDaug = posSigModel_->getDaughters(); if (posDaug != 0) {posParent_ = posDaug->getNameParent();} } LauBsCPFitModel::~LauBsCPFitModel() { delete scfFracHist_; } void LauBsCPFitModel::setupBkgndVectors() { UInt_t nBkgnds = this->nBkgndClasses(); bkgndDPModels_.resize( nBkgnds ); bkgndPdfs_.resize( nBkgnds ); bkgndEvents_.resize( nBkgnds ); bkgndDPLike_.resize( nBkgnds ); bkgndExtraLike_.resize( nBkgnds ); bkgndTotalLike_.resize( nBkgnds ); } void LauBsCPFitModel::setNSigEvents(LauParameter* nSigEvents) { if ( nSigEvents == 0 ) { std::cerr << "ERROR in LauBsCPFitModel::setNSigEvents : The LauParameter pointer is null." << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( signalEvents_ != 0 ) { std::cerr << "ERROR in LauBsCPFitModel::setNSigEvents : You are trying to overwrite the signal yield." << std::endl; return; } signalEvents_ = nSigEvents; TString name = signalEvents_->name(); if ( ! name.Contains("signalEvents") && !( name.BeginsWith("signal") && name.EndsWith("Events") ) ) { signalEvents_->name("signalEvents"); } Double_t value = nSigEvents->value(); signalEvents_->range(-2.0*(TMath::Abs(value)+1.0), 2.0*(TMath::Abs(value)+1.0)); } -void LauBsCPFitModel::setNBkgndEvents( LauParameter* nBkgndEvents ) +void LauBsCPFitModel::setNBkgndEvents( LauAbsRValue* nBkgndEvents ) { if ( nBkgndEvents == 0 ) { std::cerr << "ERROR in LauBsCPFitModel::setNBgkndEvents : The background yield LauParameter pointer is null." << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( ! this->validBkgndClass( nBkgndEvents->name() ) ) { std::cerr << "ERROR in LauBsCPFitModel::setNBkgndEvents : Invalid background class \"" << nBkgndEvents->name() << "\"." << std::endl; std::cerr << " : Background class names must be provided in \"setBkgndClassNames\" before any other background-related actions can be performed." << std::endl; gSystem->Exit(EXIT_FAILURE); } UInt_t bkgndID = this->bkgndClassID( nBkgndEvents->name() ); if ( bkgndEvents_[bkgndID] != 0 ) { std::cerr << "ERROR in LauBsCPFitModel::setNBkgndEvents : You are trying to overwrite the background yield." << std::endl; return; } + nBkgndEvents->name( nBkgndEvents->name()+"Events" ); + if ( nBkgndEvents->isLValue() ) { + Double_t value = nBkgndEvents->value(); + LauParameter* yield = dynamic_cast( nBkgndEvents ); + yield->range(-2.0*(TMath::Abs(value)+1.0), 2.0*(TMath::Abs(value)+1.0)); + } bkgndEvents_[bkgndID] = nBkgndEvents; - bkgndEvents_[bkgndID]->name( nBkgndEvents->name()+"Events" ); - Double_t value = nBkgndEvents->value(); - bkgndEvents_[bkgndID]->range(-2.0*(TMath::Abs(value)+1.0), 2.0*(TMath::Abs(value)+1.0)); } void LauBsCPFitModel::splitSignalComponent( const TH2* dpHisto, const Bool_t upperHalf, const Bool_t fluctuateBins, LauScfMap* scfMap ) { if ( useSCF_ == kTRUE ) { std::cerr << "ERROR in LauBsCPFitModel::splitSignalComponent : Have already setup SCF." << std::endl; return; } if ( dpHisto == 0 ) { std::cerr << "ERROR in LauBsCPFitModel::splitSignalComponent : The histogram pointer is null." << std::endl; return; } const LauDaughters* daughters = negSigModel_->getDaughters(); scfFracHist_ = new LauEffModel( daughters, 0 ); scfFracHist_->setEffHisto( dpHisto, kTRUE, fluctuateBins, 0.0, 0.0, upperHalf, daughters->squareDP() ); scfMap_ = scfMap; useSCF_ = kTRUE; useSCFHist_ = kTRUE; } void LauBsCPFitModel::splitSignalComponent( const Double_t scfFrac, const Bool_t fixed ) { if ( useSCF_ == kTRUE ) { std::cerr << "ERROR in LauBsCPFitModel::splitSignalComponent : Have already setup SCF." << std::endl; return; } scfFrac_.range( 0.0, 1.0 ); scfFrac_.value( scfFrac ); scfFrac_.initValue( scfFrac ); scfFrac_.genValue( scfFrac ); scfFrac_.fixed( fixed ); useSCF_ = kTRUE; useSCFHist_ = kFALSE; } void LauBsCPFitModel::setBkgndDPModel(const TString& bkgndClass, LauAbsBkgndDPModel* model) { if (model==0){ std::cerr << "ERROR in LauBsCPFitModel::setBkgndDPModels : the model pointer is null." << std::endl; return; } // check that this background name is valid if ( ! this->validBkgndClass( bkgndClass) ) { std::cerr << "ERROR in LauBsCPFitModel::setBkgndDPModel : Invalid background class \"" << bkgndClass << "\"." << std::endl; std::cerr << " : Background class names must be provided in \"setBkgndClassNames\" before any other background-related actions can be performed." << std::endl; return; } UInt_t bkgndID = this->bkgndClassID( bkgndClass ); bkgndDPModels_[bkgndID] = model; usingBkgnd_ = kTRUE; } void LauBsCPFitModel::setSignalPdf(LauAbsPdf* pdf) { // if we're doing an untagged analysis we will only use the negative PDFs if ( pdf==0 ) { std::cerr << "ERROR in LauBsCPFitModel::setSignalPdfs : The PDF pointer is null." << std::endl; return; } signalPdfs_.push_back(pdf); } void LauBsCPFitModel::setSCFPdf(LauAbsPdf* pdf) { // if we're doing an untagged analysis we will only use the negative PDFs if ( pdf==0 ) { std::cerr << "ERROR in LauBsCPFitModel::setSCFPdfs : The PDF pointer is null." << std::endl; return; } scfPdfs_.push_back(pdf); } void LauBsCPFitModel::setBkgndPdf(const TString& bkgndClass, LauAbsPdf* pdf) { // if we're doing an untagged analysis we will only use the negative PDFs if ( pdf==0 ) { std::cerr << "ERROR in LauBsCPFitModel::setBkgndPdfs : The PDF pointer is null." << std::endl; return; } // check that this background name is valid if ( ! this->validBkgndClass( bkgndClass ) ) { std::cerr << "ERROR in LauBsCPFitModel::setBkgndPdfs : Invalid background class \"" << bkgndClass << "\"." << std::endl; std::cerr << " : Background class names must be provided in \"setBkgndClassNames\" before any other background-related actions can be performed." << std::endl; return; } UInt_t bkgndID = this->bkgndClassID( bkgndClass ); bkgndPdfs_[bkgndID].push_back(pdf); usingBkgnd_ = kTRUE; } void LauBsCPFitModel::setAmpCoeffSet(LauAbsCoeffSet* coeffSet) { // Is there a component called compName in the signal model? TString compName(coeffSet->name()); Bool_t negOK = negSigModel_->hasResonance(compName); Bool_t posOK = posSigModel_->hasResonance(compName); if (!negOK) { std::cerr << "ERROR in LauBsCPFitModel::setMagPhase : " << negParent_ << " signal DP model doesn't contain component \"" << compName << "\"." << std::endl; return; } if (!posOK) { std::cerr << "ERROR in LauBsCPFitModel::setMagPhase : " << posParent_ << " signal DP model doesn't contain component \"" << compName << "\"." << std::endl; return; } // Do we already have it in our list of names? for (std::vector::const_iterator iter=coeffPars_.begin(); iter!=coeffPars_.end(); ++iter) { if ((*iter)->name() == compName) { std::cerr << "ERROR in LauBsCPFitModel::setAmpCoeffSet : Have already set coefficients for \"" << compName << "\"." << std::endl; return; } } coeffSet->index(nSigComp_); coeffPars_.push_back(coeffSet); TString parName = coeffSet->baseName(); parName += "FitFracAsym"; fitFracAsymm_.push_back(LauParameter(parName, 0.0, -1.0, 1.0)); acp_.push_back(coeffSet->acp()); ++nSigComp_; std::cout << "INFO in LauBsCPFitModel::setAmpCoeffSet : Added coefficients for component \"" << compName << "\" to the fit model." << std::endl; coeffSet->printParValues(); } void LauBsCPFitModel::initialise() { // From the initial parameter values calculate the coefficients // so they can be passed to the signal model this->updateCoeffs(); // Initialisation if (this->useDP() == kTRUE) { this->initialiseDPModels(); } if (!this->useDP() && signalPdfs_.empty()) { std::cerr << "ERROR in LauBsCPFitModel::initialise : Signal model doesn't exist for any variable." << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( this->useDP() ) { // Check that we have all the Dalitz-plot models if ((negSigModel_ == 0) || (posSigModel_ == 0)) { std::cerr << "ERROR in LauBsCPFitModel::initialise : the pointer to one (neg or pos) of the signal DP models is null.\n"; std::cerr << " : Removing the Dalitz Plot from the model." << std::endl; this->useDP(kFALSE); } if ( usingBkgnd_ ) { if ( bkgndDPModels_.empty() ) { std::cerr << "ERROR in LauBsCPFitModel::initialise : No background DP models found.\n"; std::cerr << " : Removing the Dalitz plot from the model." << std::endl; this->useDP(kFALSE); } for (LauBkgndDPModelList::const_iterator dpmodel_iter = bkgndDPModels_.begin(); dpmodel_iter != bkgndDPModels_.end(); ++dpmodel_iter ) { if ( (*dpmodel_iter) == 0 ) { std::cerr << "ERROR in LauBsCPFitModel::initialise : The pointer to one of the background DP models is null.\n"; std::cerr << " : Removing the Dalitz Plot from the model." << std::endl; this->useDP(kFALSE); break; } } } } // Next check that, if a given component is being used we've got the // right number of PDFs for all the variables involved // TODO - should probably check variable names and so on as well UInt_t nsigpdfvars(0); for ( LauPdfList::const_iterator pdf_iter = signalPdfs_.begin(); pdf_iter != signalPdfs_.end(); ++pdf_iter ) { std::vector varNames = (*pdf_iter)->varNames(); for ( std::vector::const_iterator var_iter = varNames.begin(); var_iter != varNames.end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { ++nsigpdfvars; } } } if (useSCF_) { UInt_t nscfpdfvars(0); for ( LauPdfList::const_iterator pdf_iter = scfPdfs_.begin(); pdf_iter != scfPdfs_.end(); ++pdf_iter ) { std::vector varNames = (*pdf_iter)->varNames(); for ( std::vector::const_iterator var_iter = varNames.begin(); var_iter != varNames.end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { ++nscfpdfvars; } } } if (nscfpdfvars != nsigpdfvars) { std::cerr << "ERROR in LauBsCPFitModel::initialise : There are " << nsigpdfvars << " TM signal PDF variables but " << nscfpdfvars << " SCF signal PDF variables." << std::endl; gSystem->Exit(EXIT_FAILURE); } } if (usingBkgnd_) { for (LauBkgndPdfsList::const_iterator bgclass_iter = bkgndPdfs_.begin(); bgclass_iter != bkgndPdfs_.end(); ++bgclass_iter) { UInt_t nbkgndpdfvars(0); const LauPdfList& pdfList = (*bgclass_iter); for ( LauPdfList::const_iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter ) { std::vector varNames = (*pdf_iter)->varNames(); for ( std::vector::const_iterator var_iter = varNames.begin(); var_iter != varNames.end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { ++nbkgndpdfvars; } } } if (nbkgndpdfvars != nsigpdfvars) { std::cerr << "ERROR in LauBsCPFitModel::initialise : There are " << nsigpdfvars << " signal PDF variables but " << nbkgndpdfvars << " bkgnd PDF variables." << std::endl; gSystem->Exit(EXIT_FAILURE); } } } // Clear the vectors of parameter information so we can start from scratch this->clearFitParVectors(); // Set the fit parameters for signal and background models this->setSignalDPParameters(); // Set the fit parameters for the various extra PDFs this->setExtraPdfParameters(); // Set the initial bg and signal events this->setFitNEvents(); // Check that we have the expected number of fit variables const LauParameterPList& fitVars = this->fitPars(); if (fitVars.size() != (nSigDPPar_ + nExtraPdfPar_ + nNormPar_)) { std::cerr << "ERROR in LauBsCPFitModel::initialise : Number of fit parameters not of expected size. Exiting" << std::endl; gSystem->Exit(EXIT_FAILURE); } this->setExtraNtupleVars(); } void LauBsCPFitModel::recalculateNormalisation() { //std::cout << "INFO in LauBsCPFitModel::recalculateNormalizationInDPModels : Recalc Norm in DP model" << std::endl; negSigModel_->recalculateNormalisation(); posSigModel_->recalculateNormalisation(); negSigModel_->modifyDataTree(); posSigModel_->modifyDataTree(); this->calcInterferenceTermIntegrals(); } void LauBsCPFitModel::initialiseDPModels() { // Need to check that the number of components we have and that the dynamics has matches up UInt_t nNegAmp = negSigModel_->getnTotAmp(); UInt_t nPosAmp = posSigModel_->getnTotAmp(); if ( nNegAmp != nPosAmp ) { std::cerr << "ERROR in LauBsCPFitModel::initialiseDPModels : Unequal number of signal DP components in the negative and positive models: " << nNegAmp << " != " << nPosAmp << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( nNegAmp != nSigComp_ ) { std::cerr << "ERROR in LauBsCPFitModel::initialiseDPModels : Number of signal DP components in the model (" << nNegAmp << ") not equal to number of coefficients supplied (" << nSigComp_ << ")." << std::endl; gSystem->Exit(EXIT_FAILURE); } std::cout << "INFO in LauBsCPFitModel::initialiseDPModels : Initialising signal DP model" << std::endl; negSigModel_->initialise(negCoeffs_); posSigModel_->initialise(posCoeffs_); if (usingBkgnd_ == kTRUE) { for (LauBkgndDPModelList::iterator iter = bkgndDPModels_.begin(); iter != bkgndDPModels_.end(); ++iter) { (*iter)->initialise(); } } fifjEffSum_.clear(); fifjEffSum_.resize(nSigComp_); for (UInt_t iAmp = 0; iAmp < nSigComp_; ++iAmp) { fifjEffSum_[iAmp].resize(nSigComp_); } // calculate the integrals of the A*Abar terms this->calcInterferenceTermIntegrals(); this->calcInterTermNorm(); this->calculateAmplitudeNorm(); } void LauBsCPFitModel::calcInterferenceTermIntegrals() { const std::vector& integralInfoListB0bar = negSigModel_->getIntegralInfos(); const std::vector& integralInfoListB0 = posSigModel_->getIntegralInfos(); LauComplex A, Abar, fifjEffSumTerm; for (UInt_t iAmp = 0; iAmp < nSigComp_; ++iAmp) { for (UInt_t jAmp = 0; jAmp < nSigComp_; ++jAmp) { fifjEffSum_[iAmp][jAmp].zero(); } } const UInt_t nIntegralRegions = integralInfoListB0bar.size(); for ( UInt_t iRegion(0); iRegion < nIntegralRegions; ++iRegion ) { const LauDPPartialIntegralInfo* integralInfoB0bar = integralInfoListB0bar[iRegion]; const LauDPPartialIntegralInfo* integralInfoB0 = integralInfoListB0[iRegion]; const UInt_t nm13Points = integralInfoB0bar->getnm13Points(); const UInt_t nm23Points = integralInfoB0bar->getnm23Points(); for (UInt_t m13 = 0; m13 < nm13Points; ++m13) { for (UInt_t m23 = 0; m23 < nm23Points; ++m23) { const Double_t weight = integralInfoB0bar->getWeight(m13,m23); const Double_t eff = integralInfoB0bar->getEfficiency(m13,m23); const Double_t effWeight = eff*weight; // TODO - do we need to check that this point is within the DP or will the values stored for such points be appropriate? Or are they random junk? for (UInt_t iAmp = 0; iAmp < nSigComp_; ++iAmp) { A = integralInfoB0->getAmplitude(m13, m23, iAmp); // TODO - this loop over j perhaps needs only to be from jAmp = iAmp (we only need the upper half of the matrix) for (UInt_t jAmp = 0; jAmp < nSigComp_; ++jAmp) { Abar = integralInfoB0bar->getAmplitude(m13, m23, jAmp); fifjEffSumTerm = Abar*A.conj(); fifjEffSumTerm.rescale(effWeight); fifjEffSum_[iAmp][jAmp] += fifjEffSumTerm; } } } } } } void LauBsCPFitModel::setSignalDPParameters() { // Set the fit parameters for the signal model. nSigDPPar_ = 0; if ( ! this->useDP() ) { return; } std::cout << "INFO in LauBsCPFitModel::setSignalDPParameters : Setting the initial fit parameters for the signal DP model." << std::endl; // Place isobar coefficient parameters in vector of fit variables LauParameterPList& fitVars = this->fitPars(); for (UInt_t i = 0; i < nSigComp_; i++) { LauParameterPList pars = coeffPars_[i]->getParameters(); for (LauParameterPList::iterator iter = pars.begin(); iter != pars.end(); ++iter) { if ( !(*iter)->clone() ) { fitVars.push_back(*iter); ++nSigDPPar_; } } } // Obtain the resonance parameters and place them in the vector of fit variables and in a separate vector // Need to make sure that they are unique because some might appear in both DP models LauParameterPSet& resVars = this->resPars(); resVars.clear(); LauParameterPList& negSigDPPars = negSigModel_->getFloatingParameters(); LauParameterPList& posSigDPPars = posSigModel_->getFloatingParameters(); for ( LauParameterPList::iterator iter = negSigDPPars.begin(); iter != negSigDPPars.end(); ++iter ) { if ( resVars.insert(*iter).second ) { fitVars.push_back(*iter); ++nSigDPPar_; } } for ( LauParameterPList::iterator iter = posSigDPPars.begin(); iter != posSigDPPars.end(); ++iter ) { if ( resVars.insert(*iter).second ) { fitVars.push_back(*iter); ++nSigDPPar_; } } } void LauBsCPFitModel::setExtraPdfParameters() { // Include all the parameters of the PDF in the fit // NB all of them are passed to the fit, even though some have been fixed through parameter.fixed(kTRUE) // With the new "cloned parameter" scheme only "original" parameters are passed to the fit. // Their clones are updated automatically when the originals are updated. nExtraPdfPar_ = 0; nExtraPdfPar_ += this->addFitParameters(signalPdfs_); if (useSCF_ == kTRUE) { nExtraPdfPar_ += this->addFitParameters(scfPdfs_); } if (usingBkgnd_ == kTRUE) { for (LauBkgndPdfsList::iterator iter = bkgndPdfs_.begin(); iter != bkgndPdfs_.end(); ++iter) { nExtraPdfPar_ += this->addFitParameters(*iter); } } } void LauBsCPFitModel::setFitNEvents() { if ( signalEvents_ == 0 ) { std::cerr << "ERROR in LauBsCPFitModel::setFitNEvents : Signal yield not defined." << std::endl; return; } nNormPar_ = 0; // initialise the total number of events to be the sum of all the hypotheses Double_t nTotEvts = signalEvents_->value(); for (LauBkgndYieldList::const_iterator iter = bkgndEvents_.begin(); iter != bkgndEvents_.end(); ++iter) { nTotEvts += (*iter)->value(); if ( (*iter) == 0 ) { std::cerr << "ERROR in LauBsCPFitModel::setFitNEvents : Background yield not defined." << std::endl; return; } } this->eventsPerExpt(TMath::FloorNint(nTotEvts)); LauParameterPList& fitVars = this->fitPars(); // if doing an extended ML fit add the number of signal events into the fit parameters if (this->doEMLFit()) { std::cout << "INFO in LauBsCPFitModel::setFitNEvents : Initialising number of events for signal and background components..." << std::endl; // add the signal fraction to the list of fit parameters fitVars.push_back(signalEvents_); ++nNormPar_; } else { std::cout << "INFO in LauBsCPFitModel::setFitNEvents : Initialising number of events for background components (and hence signal)..." << std::endl; } if (useSCF_ && !useSCFHist_) { fitVars.push_back(&scfFrac_); ++nNormPar_; } if (usingBkgnd_ == kTRUE) { for (LauBkgndYieldList::iterator iter = bkgndEvents_.begin(); iter != bkgndEvents_.end(); ++iter) { - LauParameter* parameter = (*iter); - fitVars.push_back(parameter); - ++nNormPar_; + std::vector parameters = (*iter)->getPars(); + for ( LauParameter* parameter : parameters ) { + if(!parameter->clone()) { + fitVars.push_back(parameter); + ++nNormPar_; + } + } } } } void LauBsCPFitModel::setExtraNtupleVars() { // Set-up other parameters derived from the fit results, e.g. fit fractions. if (this->useDP() != kTRUE) { return; } // First clear the vectors so we start from scratch this->clearExtraVarVectors(); LauParameterList& extraVars = this->extraPars(); // Add the positive and negative fit fractions for each signal component negFitFrac_ = negSigModel_->getFitFractions(); if (negFitFrac_.size() != nSigComp_) { std::cerr << "ERROR in LauBsCPFitModel::setExtraNtupleVars : Initial Fit Fraction array of unexpected dimension: " << negFitFrac_.size() << std::endl; gSystem->Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } posFitFrac_ = posSigModel_->getFitFractions(); if (posFitFrac_.size() != nSigComp_) { std::cerr << "ERROR in LauBsCPFitModel::setExtraNtupleVars : Initial Fit Fraction array of unexpected dimension: " << posFitFrac_.size() << std::endl; gSystem->Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } // Add the positive and negative fit fractions that have not been corrected for the efficiency for each signal component negFitFracEffUnCorr_ = negSigModel_->getFitFractionsEfficiencyUncorrected(); if (negFitFracEffUnCorr_.size() != nSigComp_) { std::cerr << "ERROR in LauBsCPFitModel::setExtraNtupleVars : Initial Fit Fraction array of unexpected dimension: " << negFitFracEffUnCorr_.size() << std::endl; gSystem->Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } posFitFracEffUnCorr_ = posSigModel_->getFitFractionsEfficiencyUncorrected(); if (posFitFracEffUnCorr_.size() != nSigComp_) { std::cerr << "ERROR in LauBsCPFitModel::setExtraNtupleVars : Initial Fit Fraction array of unexpected dimension: " << posFitFracEffUnCorr_.size() << std::endl; gSystem->Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } for (UInt_t i(0); i negExtraPars = negSigModel_->getExtraParameters(); std::vector::iterator negExtraIter; for (negExtraIter = negExtraPars.begin(); negExtraIter != negExtraPars.end(); ++negExtraIter) { LauParameter negExtraParameter = (*negExtraIter); extraVars.push_back(negExtraParameter); } std::vector posExtraPars = posSigModel_->getExtraParameters(); std::vector::iterator posExtraIter; for (posExtraIter = posExtraPars.begin(); posExtraIter != posExtraPars.end(); ++posExtraIter) { LauParameter posExtraParameter = (*posExtraIter); extraVars.push_back(posExtraParameter); } // Now add in the DP efficiency value Double_t initMeanEff = negSigModel_->getMeanEff().initValue(); negMeanEff_.value(initMeanEff); negMeanEff_.genValue(initMeanEff); negMeanEff_.initValue(initMeanEff); extraVars.push_back(negMeanEff_); initMeanEff = posSigModel_->getMeanEff().initValue(); posMeanEff_.value(initMeanEff); posMeanEff_.genValue(initMeanEff); posMeanEff_.initValue(initMeanEff); extraVars.push_back(posMeanEff_); // Also add in the DP rates Double_t initDPRate = negSigModel_->getDPRate().initValue(); negDPRate_.value(initDPRate); negDPRate_.genValue(initDPRate); negDPRate_.initValue(initDPRate); extraVars.push_back(negDPRate_); initDPRate = posSigModel_->getDPRate().initValue(); posDPRate_.value(initDPRate); posDPRate_.genValue(initDPRate); posDPRate_.initValue(initDPRate); extraVars.push_back(posDPRate_); // Calculate the CPC and CPV Fit Fractions, ACPs and FitFrac asymmetries this->calcExtraFractions(kTRUE); this->calcAsymmetries(kTRUE); // Add the CP violating and CP conserving fit fractions for each signal component for (UInt_t i = 0; i < nSigComp_; i++) { for (UInt_t j = i; j < nSigComp_; j++) { extraVars.push_back(CPVFitFrac_[i][j]); } } for (UInt_t i = 0; i < nSigComp_; i++) { for (UInt_t j = i; j < nSigComp_; j++) { extraVars.push_back(CPCFitFrac_[i][j]); } } // Add the Fit Fraction asymmetry for each signal component for (UInt_t i = 0; i < nSigComp_; i++) { extraVars.push_back(fitFracAsymm_[i]); } // Add the calculated CP asymmetry for each signal component for (UInt_t i = 0; i < nSigComp_; i++) { extraVars.push_back(acp_[i]); } } void LauBsCPFitModel::calcExtraFractions(Bool_t initValues) { // Calculate the CP-conserving and CP-violating fit fractions if (initValues) { // create the structure CPCFitFrac_.clear(); CPVFitFrac_.clear(); CPCFitFrac_.resize(nSigComp_); CPVFitFrac_.resize(nSigComp_); for (UInt_t i(0); iacp(); LauAsymmCalc asymmCalc(negFitFrac_[i][i].value(), posFitFrac_[i][i].value()); Double_t asym = asymmCalc.getAsymmetry(); fitFracAsymm_[i].value(asym); if (initValues) { fitFracAsymm_[i].genValue(asym); fitFracAsymm_[i].initValue(asym); } } } void LauBsCPFitModel::finaliseFitResults(const TString& tablePrefixName) { // Retrieve parameters from the fit results for calculations and toy generation // and eventually store these in output root ntuples/text files // Now take the fit parameters and update them as necessary // i.e. to make mag > 0.0, phase in the right range. // This function will also calculate any other values, such as the // fit fractions, using any errors provided by fitParErrors as appropriate. // Also obtain the pull values: (measured - generated)/(average error) if (this->useDP() == kTRUE) { for (UInt_t i = 0; i < nSigComp_; ++i) { // Check whether we have "a/b > 0.0", and phases in the right range coeffPars_[i]->finaliseValues(); } } // update the pulls on the event fractions and asymmetries if (this->doEMLFit()) { signalEvents_->updatePull(); } if (useSCF_ && !useSCFHist_) { scfFrac_.updatePull(); } if (usingBkgnd_ == kTRUE) { for (LauBkgndYieldList::iterator iter = bkgndEvents_.begin(); iter != bkgndEvents_.end(); ++iter) { - (*iter)->updatePull(); + std::vector parameters = (*iter)->getPars(); + for ( LauParameter* parameter : parameters ) { + parameter->updatePull(); + } } } // Update the pulls on all the extra PDFs' parameters this->updateFitParameters(signalPdfs_); if (useSCF_ == kTRUE) { this->updateFitParameters(scfPdfs_); } if (usingBkgnd_ == kTRUE) { for (LauBkgndPdfsList::iterator iter = bkgndPdfs_.begin(); iter != bkgndPdfs_.end(); ++iter) { this->updateFitParameters(*iter); } } // Fill the fit results to the ntuple // update the coefficients and then calculate the fit fractions and ACP's if (this->useDP() == kTRUE) { this->updateCoeffs(); negSigModel_->updateCoeffs(negCoeffs_); negSigModel_->calcExtraInfo(); posSigModel_->updateCoeffs(posCoeffs_); posSigModel_->calcExtraInfo(); LauParArray negFitFrac = negSigModel_->getFitFractions(); if (negFitFrac.size() != nSigComp_) { std::cerr << "ERROR in LauBsCPFitModel::finaliseFitResults : Fit Fraction array of unexpected dimension: " << negFitFrac.size() << std::endl; gSystem->Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } LauParArray posFitFrac = posSigModel_->getFitFractions(); if (posFitFrac.size() != nSigComp_) { std::cerr << "ERROR in LauBsCPFitModel::finaliseFitResults : Fit Fraction array of unexpected dimension: " << posFitFrac.size() << std::endl; gSystem->Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } LauParArray negFitFracEffUnCorr = negSigModel_->getFitFractionsEfficiencyUncorrected(); if (negFitFracEffUnCorr.size() != nSigComp_) { std::cerr << "ERROR in LauBsCPFitModel::finaliseFitResults : Fit Fraction array of unexpected dimension: " << negFitFracEffUnCorr.size() << std::endl; gSystem->Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } LauParArray posFitFracEffUnCorr = posSigModel_->getFitFractionsEfficiencyUncorrected(); if (posFitFracEffUnCorr.size() != nSigComp_) { std::cerr << "ERROR in LauBsCPFitModel::finaliseFitResults : Fit Fraction array of unexpected dimension: " << posFitFracEffUnCorr.size() << std::endl; gSystem->Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } for (UInt_t i(0); igetMeanEff().value()); posMeanEff_.value(posSigModel_->getMeanEff().value()); negDPRate_.value(negSigModel_->getDPRate().value()); posDPRate_.value(posSigModel_->getDPRate().value()); this->calcExtraFractions(); this->calcAsymmetries(); // Then store the final fit parameters, and any extra parameters for // the signal model (e.g. fit fractions, FF asymmetries, ACPs, mean efficiency and DP rate) this->clearExtraVarVectors(); LauParameterList& extraVars = this->extraPars(); // Add the positive and negative fit fractions for each signal component for (UInt_t i(0); i negExtraPars = negSigModel_->getExtraParameters(); std::vector::iterator negExtraIter; for (negExtraIter = negExtraPars.begin(); negExtraIter != negExtraPars.end(); ++negExtraIter) { LauParameter negExtraParameter = (*negExtraIter); extraVars.push_back(negExtraParameter); } std::vector posExtraPars = posSigModel_->getExtraParameters(); std::vector::iterator posExtraIter; for (posExtraIter = posExtraPars.begin(); posExtraIter != posExtraPars.end(); ++posExtraIter) { LauParameter posExtraParameter = (*posExtraIter); extraVars.push_back(posExtraParameter); } extraVars.push_back(negMeanEff_); extraVars.push_back(posMeanEff_); extraVars.push_back(negDPRate_); extraVars.push_back(posDPRate_); for (UInt_t i = 0; i < nSigComp_; i++) { for (UInt_t j(i); jprintFitFractions(std::cout); this->printAsymmetries(std::cout); } const LauParameterPList& fitVars = this->fitPars(); const LauParameterList& extraVars = this->extraPars(); LauFitNtuple* ntuple = this->fitNtuple(); ntuple->storeParsAndErrors(fitVars, extraVars); // find out the correlation matrix for the parameters ntuple->storeCorrMatrix(this->iExpt(), this->fitStatus(), this->covarianceMatrix()); // Fill the data into ntuple ntuple->updateFitNtuple(); // Print out the partial fit fractions, phases and the // averaged efficiency, reweighted by the dynamics (and anything else) if (this->writeLatexTable()) { TString sigOutFileName(tablePrefixName); sigOutFileName += "_"; sigOutFileName += this->iExpt(); sigOutFileName += "Expt.tex"; this->writeOutTable(sigOutFileName); } } void LauBsCPFitModel::printFitFractions(std::ostream& output) { // Print out Fit Fractions, total DP rate and mean efficiency // First for the B- events for (UInt_t i = 0; i < nSigComp_; i++) { const TString compName(coeffPars_[i]->name()); output << negParent_ << " FitFraction for component " << i << " (" << compName << ") = " << negFitFrac_[i][i] << std::endl; } output << negParent_ << " overall DP rate (integral of matrix element squared) = " << negDPRate_ << std::endl; output << negParent_ << " average efficiency weighted by whole DP dynamics = " << negMeanEff_ << std::endl; // Then for the positive sample for (UInt_t i = 0; i < nSigComp_; i++) { const TString compName(coeffPars_[i]->name()); //const TString conjName(negSigModel_->getConjResName(compName)); output << posParent_ << " FitFraction for component " << i << " (" << compName << ") = " << posFitFrac_[i][i] << std::endl; } output << posParent_ << " overall DP rate (integral of matrix element squared) = " << posDPRate_ << std::endl; output << posParent_ << " average efficiency weighted by whole DP dynamics = " << posMeanEff_ << std::endl; } void LauBsCPFitModel::printAsymmetries(std::ostream& output) { for (UInt_t i = 0; i < nSigComp_; i++) { const TString compName(coeffPars_[i]->name()); output << "Fit Fraction asymmetry for component " << i << " (" << compName << ") = " << fitFracAsymm_[i] << std::endl; } for (UInt_t i = 0; i < nSigComp_; i++) { const TString compName(coeffPars_[i]->name()); output << "ACP for component " << i << " (" << compName << ") = " << acp_[i] << std::endl; } } void LauBsCPFitModel::writeOutTable(const TString& outputFile) { // Write out the results of the fit to a tex-readable table // TODO - need to include the yields in this table std::ofstream fout(outputFile); LauPrint print; std::cout << "INFO in LauBsCPFitModel::writeOutTable : Writing out results of the fit to the tex file " << outputFile << std::endl; if (this->useDP() == kTRUE) { // print the fit coefficients in one table coeffPars_.front()->printTableHeading(fout); for (UInt_t i = 0; i < nSigComp_; i++) { coeffPars_[i]->printTableRow(fout); } fout << "\\hline" << std::endl; fout << "\\end{tabular}" << std::endl << std::endl; // print the fit fractions and asymmetries in another fout << "\\begin{tabular}{|l|c|c|c|c|}" << std::endl; fout << "\\hline" << std::endl; fout << "Component & " << negParent_ << " Fit Fraction & " << posParent_ << " Fit Fraction & Fit Fraction Asymmetry & ACP \\\\" << std::endl; fout << "\\hline" << std::endl; Double_t negFitFracSum(0.0); Double_t posFitFracSum(0.0); for (UInt_t i = 0; i < nSigComp_; i++) { TString resName = coeffPars_[i]->name(); resName = resName.ReplaceAll("_", "\\_"); Double_t negFitFrac = negFitFrac_[i][i].value(); Double_t posFitFrac = posFitFrac_[i][i].value(); negFitFracSum += negFitFrac; posFitFracSum += posFitFrac; Double_t fitFracAsymm = fitFracAsymm_[i].value(); Double_t acp = acp_[i].value(); Double_t acpErr = acp_[i].error(); fout << resName << " & $"; print.printFormat(fout, negFitFrac); fout << "$ & $"; print.printFormat(fout, posFitFrac); fout << "$ & $"; print.printFormat(fout, fitFracAsymm); fout << "$ & $"; print.printFormat(fout, acp); fout << " \\pm "; print.printFormat(fout, acpErr); fout << "$ \\\\" << std::endl; } fout << "\\hline" << std::endl; // Also print out sum of fit fractions fout << "Fit Fraction Sum & $"; print.printFormat(fout, negFitFracSum); fout << "$ & $"; print.printFormat(fout, posFitFracSum); fout << "$ & & \\\\" << std::endl; fout << "\\hline" << std::endl; fout << "DP rate & $"; print.printFormat(fout, negDPRate_.value()); fout << "$ & $"; print.printFormat(fout, posDPRate_.value()); fout << "$ & & \\\\" << std::endl; fout << "$< \\varepsilon > $ & $"; print.printFormat(fout, negMeanEff_.value()); fout << "$ & $"; print.printFormat(fout, posMeanEff_.value()); fout << "$ & & \\\\" << std::endl; fout << "\\hline" << std::endl; fout << "\\end{tabular}" << std::endl << std::endl; } if (!signalPdfs_.empty()) { fout << "\\begin{tabular}{|l|c|}" << std::endl; fout << "\\hline" << std::endl; if (useSCF_ == kTRUE) { fout << "\\Extra TM Signal PDFs' Parameters: & \\\\" << std::endl; } else { fout << "\\Extra Signal PDFs' Parameters: & \\\\" << std::endl; } this->printFitParameters(signalPdfs_, fout); if (useSCF_ == kTRUE && !scfPdfs_.empty()) { fout << "\\hline" << std::endl; fout << "\\Extra SCF Signal PDFs' Parameters: & \\\\" << std::endl; this->printFitParameters(scfPdfs_, fout); } if (usingBkgnd_ == kTRUE && !bkgndPdfs_.empty()) { fout << "\\hline" << std::endl; fout << "\\Extra Background PDFs' Parameters: & \\\\" << std::endl; for (LauBkgndPdfsList::const_iterator iter = bkgndPdfs_.begin(); iter != bkgndPdfs_.end(); ++iter) { this->printFitParameters(*iter, fout); } } fout << "\\hline \n\\end{tabular}" << std::endl << std::endl; } } void LauBsCPFitModel::checkInitFitParams() { // Update the number of signal events to be total-sum(background events) this->updateSigEvents(); // Check whether we want to have randomised initial fit parameters for the signal model if (this->useRandomInitFitPars() == kTRUE) { std::cout << "INFO in LauBsCPFitModel::checkInitFitParams : Setting random parameters for the signal model" << std::endl; this->randomiseInitFitPars(); } } void LauBsCPFitModel::randomiseInitFitPars() { // Only randomise those parameters that are not fixed! std::cout << "INFO in LauBsCPFitModel::randomiseInitFitPars : Randomising the initial fit magnitudes and phases of the components..." << std::endl; for (UInt_t i = 0; i < nSigComp_; i++) { coeffPars_[i]->randomiseInitValues(); } } LauBsCPFitModel::LauGenInfo LauBsCPFitModel::eventsToGenerate() { // Determine the number of events to generate for each hypothesis // If we're smearing then smear each one individually LauGenInfo nEvtsGen; + // Keep track of whether any yield or asymmetry parameters are blinded + Bool_t blind = kFALSE; + // Signal Double_t evtWeight(1.0); Double_t nEvts = signalEvents_->genValue(); if ( nEvts < 0.0 ) { evtWeight = -1.0; nEvts = TMath::Abs( nEvts ); } + if ( signalEvents_->blind() ) { + blind = kTRUE; + } Double_t asym(0.0); Double_t sigAsym(0.0); Double_t negRate = negSigModel_->getDPNorm(); Double_t posRate = posSigModel_->getDPNorm(); if (negRate+posRate>1e-30) { sigAsym = (negRate-posRate)/(negRate+posRate); } asym = sigAsym; Int_t nPosEvts = static_cast((nEvts/2.0 * (1.0 - asym)) + 0.5); Int_t nNegEvts = static_cast((nEvts/2.0 * (1.0 + asym)) + 0.5); if (this->doPoissonSmearing()) { nNegEvts = LauRandom::randomFun()->Poisson(nNegEvts); nPosEvts = LauRandom::randomFun()->Poisson(nPosEvts); } nEvtsGen[std::make_pair("signal",-1)] = std::make_pair(nNegEvts,evtWeight); nEvtsGen[std::make_pair("signal",+1)] = std::make_pair(nPosEvts,evtWeight); // backgrounds const UInt_t nBkgnds = this->nBkgndClasses(); for ( UInt_t bkgndID(0); bkgndID < nBkgnds; ++bkgndID ) { const TString& bkgndClass = this->bkgndClassName(bkgndID); - const LauParameter* evtsPar = bkgndEvents_[bkgndID]; + const LauAbsRValue* evtsPar = bkgndEvents_[bkgndID]; + if ( evtsPar->blind() ) { + blind = kTRUE; + } evtWeight = 1.0; nEvts = TMath::FloorNint( evtsPar->genValue() ); if ( nEvts < 0 ) { evtWeight = -1.0; nEvts = TMath::Abs( nEvts ); } Int_t nBkgEvts = nEvts; if (this->doPoissonSmearing()) { nBkgEvts = LauRandom::randomFun()->Poisson(nBkgEvts); } nEvtsGen[std::make_pair(bkgndClass,+1)] = std::make_pair(nBkgEvts,evtWeight); } - std::cout << "INFO in LauBsCPFitModel::eventsToGenerate : Generating toy MC with:" << std::endl; - std::cout << " : Signal asymmetry = " << sigAsym << " and number of signal events = " << signalEvents_->genValue() << std::endl; - for ( UInt_t bkgndID(0); bkgndID < nBkgnds; ++bkgndID ) { - const TString& bkgndClass = this->bkgndClassName(bkgndID); - const LauParameter* evtsPar = bkgndEvents_[bkgndID]; - std::cout << " : Number of " << bkgndClass << " events = " << evtsPar->genValue() << std::endl; + // Print out the information on what we're generating, but only if none of the parameters are blind (otherwise we risk unblinding them!) + if ( !blind ) { + std::cout << "INFO in LauBsCPFitModel::eventsToGenerate : Generating toy MC with:" << std::endl; + std::cout << " : Signal asymmetry = " << sigAsym << " and number of signal events = " << signalEvents_->genValue() << std::endl; + for ( UInt_t bkgndID(0); bkgndID < nBkgnds; ++bkgndID ) { + const TString& bkgndClass = this->bkgndClassName(bkgndID); + const LauAbsRValue* evtsPar = bkgndEvents_[bkgndID]; + std::cout << " : Number of " << bkgndClass << " events = " << evtsPar->genValue() << std::endl; + } } return nEvtsGen; } Bool_t LauBsCPFitModel::genExpt() { // Routine to generate toy Monte Carlo events according to the various models we have defined. // Determine the number of events to generate for each hypothesis LauGenInfo nEvts = this->eventsToGenerate(); Bool_t genOK(kTRUE); Int_t evtNum(0); const UInt_t nBkgnds = this->nBkgndClasses(); std::vector bkgndClassNames(nBkgnds); std::vector bkgndClassNamesGen(nBkgnds); for ( UInt_t iBkgnd(0); iBkgnd < nBkgnds; ++iBkgnd ) { TString name( this->bkgndClassName(iBkgnd) ); bkgndClassNames[iBkgnd] = name; bkgndClassNamesGen[iBkgnd] = "gen"+name; } const Bool_t storeSCFTruthInfo = useSCF_; // Loop over the hypotheses and generate the requested number of events for each one for (LauGenInfo::const_iterator iter = nEvts.begin(); iter != nEvts.end(); ++iter) { const TString& type(iter->first.first); Double_t evtWeight( iter->second.second ); Int_t nEvtsGen( iter->second.first ); for (Int_t iEvt(0); iEvtsetGenNtupleDoubleBranchValue( "evtWeight", evtWeight ); this->setGenNtupleDoubleBranchValue( "efficiency", 1.0 ); if (type == "signal") { this->setGenNtupleIntegerBranchValue("genSig",1); for ( UInt_t iBkgnd(0); iBkgnd < nBkgnds; ++iBkgnd ) { this->setGenNtupleIntegerBranchValue( bkgndClassNamesGen[iBkgnd], 0 ); } genOK = this->generateSignalEvent(); this->setGenNtupleDoubleBranchValue( "efficiency", negSigModel_->getEvtEff() ); } else { this->setGenNtupleIntegerBranchValue("genSig",0); if ( storeSCFTruthInfo ) { this->setGenNtupleIntegerBranchValue("genTMSig",0); this->setGenNtupleIntegerBranchValue("genSCFSig",0); } UInt_t bkgndID(0); for ( UInt_t iBkgnd(0); iBkgnd < nBkgnds; ++iBkgnd ) { Int_t gen(0); if ( bkgndClassNames[iBkgnd] == type ) { gen = 1; bkgndID = iBkgnd; } this->setGenNtupleIntegerBranchValue( bkgndClassNamesGen[iBkgnd], gen ); } genOK = this->generateBkgndEvent(bkgndID); } if (!genOK) { // If there was a problem with the generation then break out and return. // The problem model will have adjusted itself so that all should be OK next time. break; } if (this->useDP() == kTRUE) { this->setDPBranchValues(); } // Store the event number (within this experiment) // and then increment it this->setGenNtupleIntegerBranchValue("iEvtWithinExpt",evtNum); ++evtNum; this->fillGenNtupleBranches(); if (iEvt%500 == 0) {std::cout << "INFO in LauBsCPFitModel::genExpt : Generated event number " << iEvt << " out of " << nEvtsGen << " " << type << " events." << std::endl;} } if (!genOK) { break; } } if (this->useDP() && genOK) { negSigModel_->checkToyMC(kTRUE,kTRUE); posSigModel_->checkToyMC(kTRUE,kTRUE); // Get the fit fractions if they're to be written into the latex table if (this->writeLatexTable()) { LauParArray negFitFrac = negSigModel_->getFitFractions(); if (negFitFrac.size() != nSigComp_) { std::cerr << "ERROR in LauBsCPFitModel::genExpt : Fit Fraction array of unexpected dimension: " << negFitFrac.size() << std::endl; gSystem->Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } LauParArray posFitFrac = posSigModel_->getFitFractions(); if (posFitFrac.size() != nSigComp_) { std::cerr << "ERROR in LauBsCPFitModel::genExpt : Fit Fraction array of unexpected dimension: " << posFitFrac.size() << std::endl; gSystem->Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } for (UInt_t i(0); igetMeanEff().value()); posMeanEff_.value(posSigModel_->getMeanEff().value()); negDPRate_.value(negSigModel_->getDPRate().value()); posDPRate_.value(posSigModel_->getDPRate().value()); } } return genOK; } Bool_t LauBsCPFitModel::generateSignalEvent() { // Generate signal event Bool_t genOK(kTRUE); Bool_t genSCF(kFALSE); Bool_t generatedEvent(kFALSE); //LauPdfList* sigPdfs(0); //LauPdfList* scfPdfs(0); if (this->useDP()) { nGenLoop_ = 0; while (generatedEvent == kFALSE && nGenLoop_ < iterationsMax_) { // DP variables Double_t m13Sq(0.0), m23Sq(0.0); // Generate DP position negKinematics_->genFlatPhaseSpace(m13Sq, m23Sq); posKinematics_->updateKinematics(m13Sq, m23Sq); // Calculate the total A and Abar for the given DP position negSigModel_->calcLikelihoodInfo(m13Sq, m23Sq); posSigModel_->calcLikelihoodInfo(m13Sq, m23Sq); // Calculate DP terms this->calculateDPterms(); //Finally we throw the dice to see whether this event should be generated Double_t randNo = LauRandom::randomFun()->Rndm(); if (randNo <= ASq_/aSqMaxSet_ ) { generatedEvent = kTRUE; nGenLoop_ = 0; if (ASq_ > aSqMaxVar_) {aSqMaxVar_ = ASq_;} } else { nGenLoop_++; } } // Check whether we have generated the toy MC OK. if (nGenLoop_ >= iterationsMax_) { aSqMaxSet_ = 1.01 * aSqMaxVar_; genOK = kFALSE; std::cerr<<"WARNING in LauTimeDepNonFlavModel::generateSignalEvent : Hit max iterations: setting aSqMaxSet_ to "< aSqMaxSet_) { aSqMaxSet_ = 1.01 * aSqMaxVar_; genOK = kFALSE; std::cerr<<"WARNING in LauTimeDepNonFlavModel::generateSignalEvent : Found a larger ASq value: setting aSqMaxSet_ to "<calcEfficiency( negKinematics_ ); } else { frac = scfFrac_.genValue(); } if ( frac < LauRandom::randomFun()->Rndm() ) { this->setGenNtupleIntegerBranchValue("genTMSig",1); this->setGenNtupleIntegerBranchValue("genSCFSig",0); genSCF = kFALSE; } else { this->setGenNtupleIntegerBranchValue("genTMSig",0); this->setGenNtupleIntegerBranchValue("genSCFSig",1); genSCF = kTRUE; // Optionally smear the DP position // of the SCF event if ( scfMap_ != 0 ) { Double_t xCoord(0.0), yCoord(0.0); if ( negKinematics_->squareDP() ) { xCoord = negKinematics_->getmPrime(); yCoord = negKinematics_->getThetaPrime(); } else { xCoord = negKinematics_->getm13Sq(); yCoord = negKinematics_->getm23Sq(); } // Find the bin number where this event is generated Int_t binNo = scfMap_->binNumber( xCoord, yCoord ); // Retrieve the migration histogram TH2* histo = scfMap_->trueHist( binNo ); const LauAbsEffModel * effModel = negSigModel_->getEffModel(); do { // Get a random point from the histogram histo->GetRandom2( xCoord, yCoord ); // Update the kinematics if ( negKinematics_->squareDP() ) { negKinematics_->updateSqDPKinematics( xCoord, yCoord ); } else { negKinematics_->updateKinematics( xCoord, yCoord ); } } while ( ! effModel->passVeto( negKinematics_ ) ); } } } } else { if ( useSCF_ ) { Double_t frac = scfFrac_.genValue(); if ( frac < LauRandom::randomFun()->Rndm() ) { this->setGenNtupleIntegerBranchValue("genTMSig",1); this->setGenNtupleIntegerBranchValue("genSCFSig",0); genSCF = kFALSE; } else { this->setGenNtupleIntegerBranchValue("genTMSig",0); this->setGenNtupleIntegerBranchValue("genSCFSig",1); genSCF = kTRUE; } } } if (genOK) { // TODO! Check if the removal is right //sigPdfs = &signalPdfs_; //scfPdfs = &scfPdfs_; if ( useSCF_ ) { if ( genSCF ) { this->generateExtraPdfValues(&scfPdfs_); } else { this->generateExtraPdfValues(&signalPdfs_); } } else { this->generateExtraPdfValues(&signalPdfs_); } } return genOK; } void LauBsCPFitModel::calculateDPterms() { // Retrieve the amplitudes and efficiency from the dynamics const LauComplex& Abar = negSigModel_->getEvtDPAmp(); const LauComplex& A = posSigModel_->getEvtDPAmp(); Double_t eff = negSigModel_->getEvtEff(); // Calculate the DP terms Double_t aSqSum = A.abs2() + Abar.abs2(); LauComplex inter = Abar * A.conj(); Double_t interTermRe = inter.re(); // Total amplitude and multiply by the efficiency ASq_ = aSqSum - 2.0 * D_ * interTermRe; ASq_ *= eff; } Bool_t LauBsCPFitModel::generateBkgndEvent(UInt_t bkgndID) { // Generate Bkgnd event Bool_t genOK(kTRUE); LauAbsBkgndDPModel* model(0); LauPdfList* extraPdfs(0); //LauKinematics* kinematics(0); // TODO: Check charge again /* if (curEvtCharge_<0) { model = negBkgndDPModels_[bkgndID]; if (this->enableEmbedding()) { embeddedData = negBkgndTree_[bkgndID]; } extraPdfs = &negBkgndPdfs_[bkgndID]; kinematics = negKinematics_; } else { model = posBkgndDPModels_[bkgndID]; if (this->enableEmbedding()) { embeddedData = posBkgndTree_[bkgndID]; } if ( tagged_ ) { extraPdfs = &posBkgndPdfs_[bkgndID]; } else { extraPdfs = &negBkgndPdfs_[bkgndID]; } kinematics = posKinematics_; } */ model = bkgndDPModels_[bkgndID]; //if (this->enableEmbedding()) { // embeddedData = bkgndTree_[bkgndID]; //} extraPdfs = &bkgndPdfs_[bkgndID]; //kinematics = negKinematics_; // Finishing here if (this->useDP()) { // TODO! Check! /*if (embeddedData) { embeddedData->getEmbeddedEvent(kinematics); } else {*/ if (model == 0) { const TString& bkgndClass = this->bkgndClassName(bkgndID); std::cerr << "ERROR in LauBsCPFitModel::generateBkgndEvent : Can't find the DP model for background class \"" << bkgndClass << "\"." << std::endl; gSystem->Exit(EXIT_FAILURE); } genOK = model->generate(); //} //} else { // if (embeddedData) { // embeddedData->getEmbeddedEvent(0); // } } if (genOK) { this->generateExtraPdfValues(extraPdfs); } return genOK; } void LauBsCPFitModel::setupGenNtupleBranches() { // Setup the required ntuple branches this->addGenNtupleDoubleBranch("evtWeight"); this->addGenNtupleIntegerBranch("genSig"); this->addGenNtupleDoubleBranch("efficiency"); if ( useSCF_ ) { this->addGenNtupleIntegerBranch("genTMSig"); this->addGenNtupleIntegerBranch("genSCFSig"); } const UInt_t nBkgnds = this->nBkgndClasses(); for ( UInt_t iBkgnd(0); iBkgnd < nBkgnds; ++iBkgnd ) { TString name( this->bkgndClassName(iBkgnd) ); name.Prepend("gen"); this->addGenNtupleIntegerBranch(name); } if (this->useDP() == kTRUE) { this->addGenNtupleDoubleBranch("m12"); this->addGenNtupleDoubleBranch("m23"); this->addGenNtupleDoubleBranch("m13"); this->addGenNtupleDoubleBranch("m12Sq"); this->addGenNtupleDoubleBranch("m23Sq"); this->addGenNtupleDoubleBranch("m13Sq"); this->addGenNtupleDoubleBranch("cosHel12"); this->addGenNtupleDoubleBranch("cosHel23"); this->addGenNtupleDoubleBranch("cosHel13"); if (negKinematics_->squareDP() && posKinematics_->squareDP()) { this->addGenNtupleDoubleBranch("mPrime"); this->addGenNtupleDoubleBranch("thPrime"); } } for (LauPdfList::const_iterator pdf_iter = signalPdfs_.begin(); pdf_iter != signalPdfs_.end(); ++pdf_iter) { std::vector varNames = (*pdf_iter)->varNames(); for ( std::vector::const_iterator var_iter = varNames.begin(); var_iter != varNames.end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { this->addGenNtupleDoubleBranch( (*var_iter) ); } } } } void LauBsCPFitModel::setDPBranchValues() { // Store all the DP information this->setGenNtupleDoubleBranchValue("m12", negKinematics_->getm12()); this->setGenNtupleDoubleBranchValue("m23", negKinematics_->getm23()); this->setGenNtupleDoubleBranchValue("m13", negKinematics_->getm13()); this->setGenNtupleDoubleBranchValue("m12Sq", negKinematics_->getm12Sq()); this->setGenNtupleDoubleBranchValue("m23Sq", negKinematics_->getm23Sq()); this->setGenNtupleDoubleBranchValue("m13Sq", negKinematics_->getm13Sq()); this->setGenNtupleDoubleBranchValue("cosHel12", negKinematics_->getc12()); this->setGenNtupleDoubleBranchValue("cosHel23", negKinematics_->getc23()); this->setGenNtupleDoubleBranchValue("cosHel13", negKinematics_->getc13()); if (negKinematics_->squareDP()) { this->setGenNtupleDoubleBranchValue("mPrime", negKinematics_->getmPrime()); this->setGenNtupleDoubleBranchValue("thPrime", negKinematics_->getThetaPrime()); } } void LauBsCPFitModel::generateExtraPdfValues(LauPdfList* extraPdfs) { if (!extraPdfs) { std::cerr << "ERROR in LauBsCPFitModel::generateExtraPdfValues : Null pointer to PDF list." << std::endl; gSystem->Exit(EXIT_FAILURE); } if (extraPdfs->empty()) { //std::cerr << "WARNING in LauBsCPFitModel::generateExtraPdfValues : PDF list is empty." << std::endl; return; } // Generate from the extra PDFs for (LauPdfList::iterator pdf_iter = extraPdfs->begin(); pdf_iter != extraPdfs->end(); ++pdf_iter) { LauFitData genValues; genValues = (*pdf_iter)->generate(negKinematics_); for ( LauFitData::const_iterator var_iter = genValues.begin(); var_iter != genValues.end(); ++var_iter ) { TString varName = var_iter->first; if ( varName != "m13Sq" && varName != "m23Sq" ) { Double_t value = var_iter->second; this->setGenNtupleDoubleBranchValue(varName,value); } } } } void LauBsCPFitModel::propagateParUpdates() { // Update the signal parameters and then the total normalisation for the signal likelihood if (this->useDP() == kTRUE) { this->updateCoeffs(); negSigModel_->updateCoeffs(negCoeffs_); posSigModel_->updateCoeffs(posCoeffs_); this->calcInterTermNorm(); this->calculateAmplitudeNorm(); } // Update the signal fraction from the background fractions if not doing an extended fit if ( !this->doEMLFit() && !signalEvents_->fixed() ) { this->updateSigEvents(); } } void LauBsCPFitModel::updateSigEvents() { // The background parameters will have been set from Minuit. // We need to update the signal events using these. Double_t nTotEvts = this->eventsPerExpt(); signalEvents_->range(-2.0*nTotEvts,2.0*nTotEvts); for (LauBkgndYieldList::iterator iter = bkgndEvents_.begin(); iter != bkgndEvents_.end(); ++iter) { - (*iter)->range(-2.0*nTotEvts,2.0*nTotEvts); + LauAbsRValue* nBkgndEvents = (*iter); + if ( nBkgndEvents->isLValue() ) { + LauParameter* yield = dynamic_cast( nBkgndEvents ); + yield->range(-2.0*nTotEvts,2.0*nTotEvts); + } } if (signalEvents_->fixed()) { return; } // Subtract background events (if any) from signal. Double_t signalEvents = nTotEvts; if (usingBkgnd_ == kTRUE) { for (LauBkgndYieldList::const_iterator iter = bkgndEvents_.begin(); iter != bkgndEvents_.end(); ++iter) { signalEvents -= (*iter)->value(); } } signalEvents_->value(signalEvents); } void LauBsCPFitModel::cacheInputFitVars() { // Fill the internal data trees of the signal and background models. // Note that we store the events of both charges in both the // negative and the positive models. It's only later, at the stage // when the likelihood is being calculated, that we separate them. LauFitDataTree* inputFitData = this->fitData(); // First the Dalitz plot variables (m_ij^2) if (this->useDP() == kTRUE) { // need to append SCF smearing bins before caching DP amplitudes if ( scfMap_ != 0 ) { this->appendBinCentres( inputFitData ); } negSigModel_->fillDataTree(*inputFitData); posSigModel_->fillDataTree(*inputFitData); if (usingBkgnd_ == kTRUE) { for (LauBkgndDPModelList::iterator iter = bkgndDPModels_.begin(); iter != bkgndDPModels_.end(); ++iter) { (*iter)->fillDataTree(*inputFitData); } } } // ...and then the extra PDFs this->cacheInfo(signalPdfs_, *inputFitData); this->cacheInfo(scfPdfs_, *inputFitData); for (LauBkgndPdfsList::iterator iter = bkgndPdfs_.begin(); iter != bkgndPdfs_.end(); ++iter) { this->cacheInfo((*iter), *inputFitData); } // the SCF fractions and jacobians if ( useSCF_ && useSCFHist_ ) { if ( !inputFitData->haveBranch( "m13Sq" ) || !inputFitData->haveBranch( "m23Sq" ) ) { std::cerr << "ERROR in LauBsCPFitModel::cacheInputFitVars : Input data does not contain DP branches and so can't cache the SCF fraction." << std::endl; gSystem->Exit(EXIT_FAILURE); } UInt_t nEvents = inputFitData->nEvents(); recoSCFFracs_.clear(); recoSCFFracs_.reserve( nEvents ); if ( negKinematics_->squareDP() ) { recoJacobians_.clear(); recoJacobians_.reserve( nEvents ); } for (UInt_t iEvt = 0; iEvt < nEvents; iEvt++) { const LauFitData& dataValues = inputFitData->getData(iEvt); LauFitData::const_iterator m13_iter = dataValues.find("m13Sq"); LauFitData::const_iterator m23_iter = dataValues.find("m23Sq"); negKinematics_->updateKinematics( m13_iter->second, m23_iter->second ); Double_t scfFrac = scfFracHist_->calcEfficiency( negKinematics_ ); recoSCFFracs_.push_back( scfFrac ); if ( negKinematics_->squareDP() ) { recoJacobians_.push_back( negKinematics_->calcSqDPJacobian() ); } } } } void LauBsCPFitModel::appendBinCentres( LauFitDataTree* inputData ) { // We'll be caching the DP amplitudes and efficiencies of the centres of the true bins. // To do so, we attach some fake points at the end of inputData, the number of the entry // minus the total number of events corresponding to the number of the histogram for that // given true bin in the LauScfMap object. (What this means is that when Laura is provided with // the LauScfMap object by the user, it's the latter who has to make sure that it contains the // right number of histograms and in exactly the right order!) // Get the x and y co-ordinates of the bin centres std::vector binCentresXCoords; std::vector binCentresYCoords; scfMap_->listBinCentres(binCentresXCoords, binCentresYCoords); // The SCF histograms could be in square Dalitz plot histograms. // The dynamics takes normal Dalitz plot coords, so we might have to convert them back. Bool_t sqDP = negKinematics_->squareDP(); UInt_t nBins = binCentresXCoords.size(); fakeSCFFracs_.clear(); fakeSCFFracs_.reserve( nBins ); if ( sqDP ) { fakeJacobians_.clear(); fakeJacobians_.reserve( nBins ); } for (UInt_t iBin = 0; iBin < nBins; ++iBin) { if ( sqDP ) { negKinematics_->updateSqDPKinematics(binCentresXCoords[iBin],binCentresYCoords[iBin]); binCentresXCoords[iBin] = negKinematics_->getm13Sq(); binCentresYCoords[iBin] = negKinematics_->getm23Sq(); fakeJacobians_.push_back( negKinematics_->calcSqDPJacobian() ); } else { negKinematics_->updateKinematics(binCentresXCoords[iBin],binCentresYCoords[iBin]); } fakeSCFFracs_.push_back( scfFracHist_->calcEfficiency( negKinematics_ ) ); } // Set up inputFitVars_ object to hold the fake events inputData->appendFakePoints(binCentresXCoords,binCentresYCoords); } Double_t LauBsCPFitModel::getTotEvtLikelihood(UInt_t iEvt) { // Find out whether we have B- or B+ // Get the DP likelihood for signal and backgrounds this->getEvtDPLikelihood(iEvt); // Get the combined extra PDFs likelihood for signal and backgrounds this->getEvtExtraLikelihoods(iEvt); // If appropriate, combine the TM and SCF likelihoods Double_t sigLike = sigDPLike_ * sigExtraLike_; if ( useSCF_ ) { Double_t scfFrac(0.0); if (useSCFHist_) { scfFrac = recoSCFFracs_[iEvt]; } else { scfFrac = scfFrac_.unblindValue(); } sigLike *= (1.0 - scfFrac); if ( (scfMap_ != 0) && (this->useDP() == kTRUE) ) { // if we're smearing the SCF DP PDF then the SCF frac // is already included in the SCF DP likelihood sigLike += (scfDPLike_ * scfExtraLike_); } else { sigLike += (scfFrac * scfDPLike_ * scfExtraLike_); } } // Signal asymmetry is built into the DP model... Double_t signalEvents = signalEvents_->unblindValue(); // Construct the total event likelihood Double_t likelihood(0.0); if (usingBkgnd_) { likelihood = sigLike*signalEvents; const UInt_t nBkgnds = this->nBkgndClasses(); for ( UInt_t bkgndID(0); bkgndID < nBkgnds; ++bkgndID ) { Double_t bkgndEvents = bkgndEvents_[bkgndID]->unblindValue(); likelihood += bkgndEvents*bkgndDPLike_[bkgndID]*bkgndExtraLike_[bkgndID]; } } else { // TODO: receives this 1/2 term? //likelihood = sigLike*0.5; likelihood = sigLike; } return likelihood; } Double_t LauBsCPFitModel::getEventSum() const { Double_t eventSum(0.0); eventSum += signalEvents_->unblindValue(); if (usingBkgnd_) { for (LauBkgndYieldList::const_iterator iter = bkgndEvents_.begin(); iter != bkgndEvents_.end(); ++iter) { eventSum += (*iter)->unblindValue(); } } return eventSum; } void LauBsCPFitModel::getEvtDPLikelihood(UInt_t iEvt) { // Function to return the signal and background likelihoods for the // Dalitz plot for the given event evtNo. if ( ! this->useDP() ) { // There's always going to be a term in the likelihood for the // signal, so we'd better not zero it. sigDPLike_ = 1.0; scfDPLike_ = 1.0; const UInt_t nBkgnds = this->nBkgndClasses(); for ( UInt_t bkgndID(0); bkgndID < nBkgnds; ++bkgndID ) { if (usingBkgnd_ == kTRUE) { bkgndDPLike_[bkgndID] = 1.0; } else { bkgndDPLike_[bkgndID] = 0.0; } } return; } const UInt_t nBkgnds = this->nBkgndClasses(); // Completely revised posSigModel_->calcLikelihoodInfo(iEvt); negSigModel_->calcLikelihoodInfo(iEvt); this->calculateDPterms(); sigDPLike_ = ASq_; for ( UInt_t bkgndID(0); bkgndID < nBkgnds; ++bkgndID ) { if (usingBkgnd_ == kTRUE) { bkgndDPLike_[bkgndID] = bkgndDPModels_[bkgndID]->getLikelihood(iEvt); } else { bkgndDPLike_[bkgndID] = 0.0; } } if ( useSCF_ == kTRUE ) { if ( scfMap_ == 0 ) { // we're not smearing the SCF DP position // so the likelihood is the same as the TM scfDPLike_ = sigDPLike_; } else { // calculate the smeared SCF DP likelihood scfDPLike_ = this->getEvtSCFDPLikelihood(iEvt); } } // Calculate the signal normalisation // NB the 2.0 is there so that the 0.5 factor is applied to // signal and background in the same place otherwise you get // normalisation problems when you switch off the DP in the fit // TODO: need to fix this sigDPLike_ *= 1.0/normDP_; scfDPLike_ *= 1.0/normDP_; } void LauBsCPFitModel::calculateAmplitudeNorm() { // Integrals of the sum of the ampltudes to the f(fbar) integral( |A|^2 + |Abar|^2 ) dP Double_t normASq = posSigModel_->getDPNorm(); Double_t normAbarSq = negSigModel_->getDPNorm(); // Integrals of cross terms Abar*Aconj Double_t normInterTerm = interTermReNorm_; // Complete DP normalisation terms normDP_ = normASq + normAbarSq - 2.0 * D_ * normInterTerm; } void LauBsCPFitModel::calcInterTermNorm() { const std::vector fNormB0 = posSigModel_->getFNorm(); const std::vector fNormB0bar = negSigModel_->getFNorm(); // TODO - compare this implementation with that of LauIsobarDynamics::calcSigDPNorm LauComplex norm; for (UInt_t iAmp = 0; iAmp < nSigComp_; ++iAmp) { for (UInt_t jAmp = 0; jAmp < nSigComp_; ++jAmp) { LauComplex coeffTerm = negCoeffs_[jAmp]*posCoeffs_[iAmp].conj(); coeffTerm *= fifjEffSum_[iAmp][jAmp]; coeffTerm.rescale(fNormB0bar[jAmp] * fNormB0[iAmp]); norm += coeffTerm; } } interTermReNorm_ = norm.re(); //interTermImNorm_f_ = norm_f.im(); } Double_t LauBsCPFitModel::getEvtSCFDPLikelihood(UInt_t iEvt) { Double_t scfDPLike(0.0); Double_t recoJacobian(1.0); Double_t xCoord(0.0); Double_t yCoord(0.0); Bool_t squareDP = negKinematics_->squareDP(); if ( squareDP ) { xCoord = negSigModel_->getEvtmPrime(); yCoord = negSigModel_->getEvtthPrime(); recoJacobian = recoJacobians_[iEvt]; } else { xCoord = negSigModel_->getEvtm13Sq(); yCoord = negSigModel_->getEvtm23Sq(); } // Find the bin that our reco event falls in Int_t recoBin = scfMap_->binNumber( xCoord, yCoord ); // Find out which true Bins contribute to the given reco bin const std::vector* trueBins = scfMap_->trueBins(recoBin); const Int_t nDataEvents = this->eventsPerExpt(); // Loop over the true bins for (std::vector::const_iterator iter = trueBins->begin(); iter != trueBins->end(); ++iter) { Int_t trueBin = (*iter); // prob of a true event in the given true bin migrating to the reco bin Double_t pRecoGivenTrue = scfMap_->prob( recoBin, trueBin ); Double_t pTrue(0.0); // We've cached the DP amplitudes and the efficiency for the // true bin centres, just after the data points // TODO: Check this!! /*if ( tagged_ ) { LauIsobarDynamics* sigModel(0); if (curEvtCharge_<0) { sigModel = negSigModel_; } else { sigModel = posSigModel_; } sigModel->calcLikelihoodInfo( nDataEvents + trueBin ); pTrue = sigModel->getEvtDPAmp().abs2() * sigModel->getEvtEff(); } else {*/ posSigModel_->calcLikelihoodInfo( nDataEvents + trueBin ); negSigModel_->calcLikelihoodInfo( nDataEvents + trueBin ); //pTrue = 0.5 * ( posSigModel_->getEvtDPAmp().abs2() * posSigModel_->getEvtEff() + // negSigModel_->getEvtDPAmp().abs2() * negSigModel_->getEvtEff() ); const LauComplex& A = posSigModel_->getEvtDPAmp(); const LauComplex& Abar = negSigModel_->getEvtDPAmp(); const LauComplex AstAbar = A.conj() * Abar; pTrue = A.abs2() * posSigModel_->getEvtEff() + Abar.abs2() * negSigModel_->getEvtEff() - 2.0 * D_ * AstAbar.re(); //} // Get the cached SCF fraction (and jacobian if we're using the square DP) Double_t scfFraction = fakeSCFFracs_[ trueBin ]; Double_t jacobian(1.0); if ( squareDP ) { jacobian = fakeJacobians_[ trueBin ]; } scfDPLike += pTrue * jacobian * scfFraction * pRecoGivenTrue; } // Divide by the reco jacobian scfDPLike /= recoJacobian; return scfDPLike; } void LauBsCPFitModel::getEvtExtraLikelihoods(UInt_t iEvt) { // Function to return the signal and background likelihoods for the // extra variables for the given event evtNo. sigExtraLike_ = 1.0; const UInt_t nBkgnds = this->nBkgndClasses(); // TODO: Not sure here about this! // I will comment out the minimum I can /*if ( ! tagged_ || curEvtCharge_ < 0 ) { sigExtraLike_ = this->prodPdfValue( negSignalPdfs_, iEvt ); if (useSCF_) { scfExtraLike_ = this->prodPdfValue( negScfPdfs_, iEvt ); } for ( UInt_t bkgndID(0); bkgndID < nBkgnds; ++bkgndID ) { if (usingBkgnd_) { bkgndExtraLike_[bkgndID] = this->prodPdfValue( negBkgndPdfs_[bkgndID], iEvt ); } else { bkgndExtraLike_[bkgndID] = 0.0; } } } else { sigExtraLike_ = this->prodPdfValue( posSignalPdfs_, iEvt ); if (useSCF_) { scfExtraLike_ = this->prodPdfValue( posScfPdfs_, iEvt ); } for ( UInt_t bkgndID(0); bkgndID < nBkgnds; ++bkgndID ) { if (usingBkgnd_) { bkgndExtraLike_[bkgndID] = this->prodPdfValue( posBkgndPdfs_[bkgndID], iEvt ); } else { bkgndExtraLike_[bkgndID] = 0.0; } } } */ sigExtraLike_ = this->prodPdfValue( signalPdfs_, iEvt ); if (useSCF_) { scfExtraLike_ = this->prodPdfValue( scfPdfs_, iEvt ); } for ( UInt_t bkgndID(0); bkgndID < nBkgnds; ++bkgndID ) { if (usingBkgnd_) { bkgndExtraLike_[bkgndID] = this->prodPdfValue( bkgndPdfs_[bkgndID], iEvt ); } else { bkgndExtraLike_[bkgndID] = 0.0; } } } void LauBsCPFitModel::updateCoeffs() { negCoeffs_.clear(); posCoeffs_.clear(); negCoeffs_.reserve(nSigComp_); posCoeffs_.reserve(nSigComp_); for (UInt_t i = 0; i < nSigComp_; i++) { negCoeffs_.push_back(coeffPars_[i]->antiparticleCoeff()); posCoeffs_.push_back(coeffPars_[i]->particleCoeff()); } } void LauBsCPFitModel::setupSPlotNtupleBranches() { // add branches for storing the experiment number and the number of // the event within the current experiment this->addSPlotNtupleIntegerBranch("iExpt"); this->addSPlotNtupleIntegerBranch("iEvtWithinExpt"); // Store the efficiency of the event (for inclusive BF calculations). if (this->storeDPEff()) { this->addSPlotNtupleDoubleBranch("efficiency"); if ( negSigModel_->usingScfModel() && posSigModel_->usingScfModel() ) { this->addSPlotNtupleDoubleBranch("scffraction"); } } // Store the total event likelihood for each species. if (useSCF_) { this->addSPlotNtupleDoubleBranch("sigTMTotalLike"); this->addSPlotNtupleDoubleBranch("sigSCFTotalLike"); this->addSPlotNtupleDoubleBranch("sigSCFFrac"); } else { this->addSPlotNtupleDoubleBranch("sigTotalLike"); } if (usingBkgnd_) { const UInt_t nBkgnds = this->nBkgndClasses(); for ( UInt_t iBkgnd(0); iBkgnd < nBkgnds; ++iBkgnd ) { TString name( this->bkgndClassName(iBkgnd) ); name += "TotalLike"; this->addSPlotNtupleDoubleBranch(name); } } // Store the DP likelihoods if (this->useDP()) { if (useSCF_) { this->addSPlotNtupleDoubleBranch("sigTMDPLike"); this->addSPlotNtupleDoubleBranch("sigSCFDPLike"); } else { this->addSPlotNtupleDoubleBranch("sigDPLike"); } if (usingBkgnd_) { const UInt_t nBkgnds = this->nBkgndClasses(); for ( UInt_t iBkgnd(0); iBkgnd < nBkgnds; ++iBkgnd ) { TString name( this->bkgndClassName(iBkgnd) ); name += "DPLike"; this->addSPlotNtupleDoubleBranch(name); } } } // Store the likelihoods for each extra PDF if (useSCF_) { this->addSPlotNtupleBranches(&signalPdfs_, "sigTM"); this->addSPlotNtupleBranches(&scfPdfs_, "sigSCF"); } else { this->addSPlotNtupleBranches(&signalPdfs_, "sig"); } if (usingBkgnd_) { const UInt_t nBkgnds = this->nBkgndClasses(); for ( UInt_t iBkgnd(0); iBkgnd < nBkgnds; ++iBkgnd ) { const TString& bkgndClass = this->bkgndClassName(iBkgnd); const LauPdfList* pdfList = &(bkgndPdfs_[iBkgnd]); this->addSPlotNtupleBranches(pdfList, bkgndClass); } } } void LauBsCPFitModel::addSPlotNtupleBranches(const LauPdfList* extraPdfs, const TString& prefix) { if (extraPdfs) { // Loop through each of the PDFs for (LauPdfList::const_iterator pdf_iter = extraPdfs->begin(); pdf_iter != extraPdfs->end(); ++pdf_iter) { // Count the number of input variables that are not // DP variables (used in the case where there is DP // dependence for e.g. MVA) UInt_t nVars(0); std::vector varNames = (*pdf_iter)->varNames(); for ( std::vector::const_iterator var_iter = varNames.begin(); var_iter != varNames.end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { ++nVars; } } if ( nVars == 1 ) { // If the PDF only has one variable then // simply add one branch for that variable TString varName = (*pdf_iter)->varName(); TString name(prefix); name += varName; name += "Like"; this->addSPlotNtupleDoubleBranch(name); } else if ( nVars == 2 ) { // If the PDF has two variables then we // need a branch for them both together and // branches for each TString allVars(""); for ( std::vector::const_iterator var_iter = varNames.begin(); var_iter != varNames.end(); ++var_iter ) { allVars += (*var_iter); TString name(prefix); name += (*var_iter); name += "Like"; this->addSPlotNtupleDoubleBranch(name); } TString name(prefix); name += allVars; name += "Like"; this->addSPlotNtupleDoubleBranch(name); } else { std::cerr << "WARNING in LauBsCPFitModel::addSPlotNtupleBranches : Can't yet deal with 3D PDFs." << std::endl; } } } } Double_t LauBsCPFitModel::setSPlotNtupleBranchValues(LauPdfList* extraPdfs, const TString& prefix, UInt_t iEvt) { // Store the PDF value for each variable in the list Double_t totalLike(1.0); Double_t extraLike(0.0); if (extraPdfs) { for (LauPdfList::iterator pdf_iter = extraPdfs->begin(); pdf_iter != extraPdfs->end(); ++pdf_iter) { // calculate the likelihood for this event (*pdf_iter)->calcLikelihoodInfo(iEvt); extraLike = (*pdf_iter)->getLikelihood(); totalLike *= extraLike; // Count the number of input variables that are not // DP variables (used in the case where there is DP // dependence for e.g. MVA) UInt_t nVars(0); std::vector varNames = (*pdf_iter)->varNames(); for ( std::vector::const_iterator var_iter = varNames.begin(); var_iter != varNames.end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { ++nVars; } } if ( nVars == 1 ) { // If the PDF only has one variable then // simply store the value for that variable TString varName = (*pdf_iter)->varName(); TString name(prefix); name += varName; name += "Like"; this->setSPlotNtupleDoubleBranchValue(name, extraLike); } else if ( nVars == 2 ) { // If the PDF has two variables then we // store the value for them both together // and for each on their own TString allVars(""); for ( std::vector::const_iterator var_iter = varNames.begin(); var_iter != varNames.end(); ++var_iter ) { allVars += (*var_iter); TString name(prefix); name += (*var_iter); name += "Like"; Double_t indivLike = (*pdf_iter)->getLikelihood( (*var_iter) ); this->setSPlotNtupleDoubleBranchValue(name, indivLike); } TString name(prefix); name += allVars; name += "Like"; this->setSPlotNtupleDoubleBranchValue(name, extraLike); } else { std::cerr << "WARNING in LauBsCPFitModel::setSPlotNtupleBranchValues : Can't yet deal with 3D PDFs." << std::endl; } } } return totalLike; } LauSPlot::NameSet LauBsCPFitModel::variableNames() const { LauSPlot::NameSet nameSet; if (this->useDP()) { nameSet.insert("DP"); } // Loop through all the signal PDFs for (LauPdfList::const_iterator pdf_iter = signalPdfs_.begin(); pdf_iter != signalPdfs_.end(); ++pdf_iter) { // Loop over the variables involved in each PDF std::vector varNames = (*pdf_iter)->varNames(); for ( std::vector::const_iterator var_iter = varNames.begin(); var_iter != varNames.end(); ++var_iter ) { // If they are not DP coordinates then add them if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { nameSet.insert( (*var_iter) ); } } } return nameSet; } LauSPlot::NumbMap LauBsCPFitModel::freeSpeciesNames() const { LauSPlot::NumbMap numbMap; if (!signalEvents_->fixed() && this->doEMLFit()) { numbMap["sig"] = signalEvents_->genValue(); } if ( usingBkgnd_ ) { const UInt_t nBkgnds = this->nBkgndClasses(); for ( UInt_t iBkgnd(0); iBkgnd < nBkgnds; ++iBkgnd ) { const TString& bkgndClass = this->bkgndClassName(iBkgnd); - const LauParameter* par = bkgndEvents_[iBkgnd]; + const LauAbsRValue* par = bkgndEvents_[iBkgnd]; if (!par->fixed()) { numbMap[bkgndClass] = par->genValue(); } } } return numbMap; } LauSPlot::NumbMap LauBsCPFitModel::fixdSpeciesNames() const { LauSPlot::NumbMap numbMap; if (signalEvents_->fixed() && this->doEMLFit()) { numbMap["sig"] = signalEvents_->genValue(); } if ( usingBkgnd_ ) { const UInt_t nBkgnds = this->nBkgndClasses(); for ( UInt_t iBkgnd(0); iBkgnd < nBkgnds; ++iBkgnd ) { const TString& bkgndClass = this->bkgndClassName(iBkgnd); - const LauParameter* par = bkgndEvents_[iBkgnd]; + const LauAbsRValue* par = bkgndEvents_[iBkgnd]; if (par->fixed()) { numbMap[bkgndClass] = par->genValue(); } } } return numbMap; } LauSPlot::TwoDMap LauBsCPFitModel::twodimPDFs() const { // This makes the assumption that the form of the positive and // negative PDFs are the same, which seems reasonable to me LauSPlot::TwoDMap twodimMap; for (LauPdfList::const_iterator pdf_iter = signalPdfs_.begin(); pdf_iter != signalPdfs_.end(); ++pdf_iter) { // Count the number of input variables that are not DP variables UInt_t nVars(0); std::vector varNames = (*pdf_iter)->varNames(); for ( std::vector::const_iterator var_iter = varNames.begin(); var_iter != varNames.end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { ++nVars; } } if ( nVars == 2 ) { if (useSCF_) { twodimMap.insert( std::make_pair( "sigTM", std::make_pair( varNames[0], varNames[1] ) ) ); } else { twodimMap.insert( std::make_pair( "sig", std::make_pair( varNames[0], varNames[1] ) ) ); } } } if ( useSCF_ ) { for (LauPdfList::const_iterator pdf_iter = scfPdfs_.begin(); pdf_iter != scfPdfs_.end(); ++pdf_iter) { // Count the number of input variables that are not DP variables UInt_t nVars(0); std::vector varNames = (*pdf_iter)->varNames(); for ( std::vector::const_iterator var_iter = varNames.begin(); var_iter != varNames.end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { ++nVars; } } if ( nVars == 2 ) { twodimMap.insert( std::make_pair( "sigSCF", std::make_pair( varNames[0], varNames[1] ) ) ); } } } if (usingBkgnd_) { const UInt_t nBkgnds = this->nBkgndClasses(); for ( UInt_t iBkgnd(0); iBkgnd < nBkgnds; ++iBkgnd ) { const TString& bkgndClass = this->bkgndClassName(iBkgnd); const LauPdfList& pdfList = bkgndPdfs_[iBkgnd]; for (LauPdfList::const_iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) { // Count the number of input variables that are not DP variables UInt_t nVars(0); std::vector varNames = (*pdf_iter)->varNames(); for ( std::vector::const_iterator var_iter = varNames.begin(); var_iter != varNames.end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { ++nVars; } } if ( nVars == 2 ) { twodimMap.insert( std::make_pair( bkgndClass, std::make_pair( varNames[0], varNames[1] ) ) ); } } } } return twodimMap; } void LauBsCPFitModel::storePerEvtLlhds() { std::cout << "INFO in LauBsCPFitModel::storePerEvtLlhds : Storing per-event likelihood values..." << std::endl; // if we've not been using the DP model then we need to cache all // the info here so that we can get the efficiency from it LauFitDataTree* inputFitData = this->fitData(); if (!this->useDP() && this->storeDPEff()) { negSigModel_->initialise(negCoeffs_); posSigModel_->initialise(posCoeffs_); negSigModel_->fillDataTree(*inputFitData); posSigModel_->fillDataTree(*inputFitData); } UInt_t evtsPerExpt(this->eventsPerExpt()); //LauIsobarDynamics* sigModel(0); LauPdfList* sigPdfs(0); LauPdfList* scfPdfs(0); LauBkgndPdfsList* bkgndPdfs(0); for (UInt_t iEvt = 0; iEvt < evtsPerExpt; ++iEvt) { this->setSPlotNtupleIntegerBranchValue("iExpt",this->iExpt()); this->setSPlotNtupleIntegerBranchValue("iEvtWithinExpt",iEvt); // Find out whether we have B- or B+ // TODO: Check this (Commented out for the time being) /*if ( tagged_ ) { const LauFitData& dataValues = inputFitData->getData(iEvt); LauFitData::const_iterator iter = dataValues.find("charge"); curEvtCharge_ = static_cast(iter->second); if (curEvtCharge_==+1) { sigModel = posSigModel_; sigPdfs = &posSignalPdfs_; scfPdfs = &posScfPdfs_; bkgndPdfs = &posBkgndPdfs_; } else { sigModel = negSigModel_; sigPdfs = &negSignalPdfs_; scfPdfs = &negScfPdfs_; bkgndPdfs = &negBkgndPdfs_; } } else { sigPdfs = &negSignalPdfs_; scfPdfs = &negScfPdfs_; bkgndPdfs = &negBkgndPdfs_; } */ //sigModel = negSigModel_; sigPdfs = &signalPdfs_; scfPdfs = &scfPdfs_; bkgndPdfs = &bkgndPdfs_; // the DP information this->getEvtDPLikelihood(iEvt); if (this->storeDPEff()) { if (!this->useDP()) { posSigModel_->calcLikelihoodInfo(iEvt); negSigModel_->calcLikelihoodInfo(iEvt); } /*if ( tagged_ ) { this->setSPlotNtupleDoubleBranchValue("efficiency",sigModel->getEvtEff()); if ( negSigModel_->usingScfModel() && posSigModel_->usingScfModel() ) { this->setSPlotNtupleDoubleBranchValue("scffraction",sigModel->getEvtScfFraction()); } } else {*/ // TODO: Does it matter? this->setSPlotNtupleDoubleBranchValue("efficiency",0.5*(posSigModel_->getEvtEff() + negSigModel_->getEvtEff()) ); if ( negSigModel_->usingScfModel() && posSigModel_->usingScfModel() ) { this->setSPlotNtupleDoubleBranchValue("scffraction",0.5*(posSigModel_->getEvtScfFraction() + negSigModel_->getEvtScfFraction())); } //} } if (this->useDP()) { sigTotalLike_ = sigDPLike_; if (useSCF_) { scfTotalLike_ = scfDPLike_; this->setSPlotNtupleDoubleBranchValue("sigTMDPLike",sigDPLike_); this->setSPlotNtupleDoubleBranchValue("sigSCFDPLike",scfDPLike_); } else { this->setSPlotNtupleDoubleBranchValue("sigDPLike",sigDPLike_); } if (usingBkgnd_) { const UInt_t nBkgnds = this->nBkgndClasses(); for ( UInt_t iBkgnd(0); iBkgnd < nBkgnds; ++iBkgnd ) { TString name = this->bkgndClassName(iBkgnd); name += "DPLike"; this->setSPlotNtupleDoubleBranchValue(name,bkgndDPLike_[iBkgnd]); } } } else { sigTotalLike_ = 1.0; if (useSCF_) { scfTotalLike_ = 1.0; } if (usingBkgnd_) { const UInt_t nBkgnds = this->nBkgndClasses(); for ( UInt_t iBkgnd(0); iBkgnd < nBkgnds; ++iBkgnd ) { bkgndTotalLike_[iBkgnd] = 1.0; } } } // the signal PDF values if ( useSCF_ ) { sigTotalLike_ *= this->setSPlotNtupleBranchValues(sigPdfs, "sigTM", iEvt); scfTotalLike_ *= this->setSPlotNtupleBranchValues(scfPdfs, "sigSCF", iEvt); } else { sigTotalLike_ *= this->setSPlotNtupleBranchValues(sigPdfs, "sig", iEvt); } // the background PDF values if (usingBkgnd_) { const UInt_t nBkgnds = this->nBkgndClasses(); for ( UInt_t iBkgnd(0); iBkgnd < nBkgnds; ++iBkgnd ) { const TString& bkgndClass = this->bkgndClassName(iBkgnd); LauPdfList& pdfs = (*bkgndPdfs)[iBkgnd]; bkgndTotalLike_[iBkgnd] *= this->setSPlotNtupleBranchValues(&(pdfs), bkgndClass, iEvt); } } // the total likelihoods if (useSCF_) { Double_t scfFrac(0.0); if ( useSCFHist_ ) { scfFrac = recoSCFFracs_[iEvt]; } else { scfFrac = scfFrac_.unblindValue(); } this->setSPlotNtupleDoubleBranchValue("sigSCFFrac",scfFrac); sigTotalLike_ *= ( 1.0 - scfFrac ); if ( scfMap_ == 0 ) { scfTotalLike_ *= scfFrac; } this->setSPlotNtupleDoubleBranchValue("sigTMTotalLike",sigTotalLike_); this->setSPlotNtupleDoubleBranchValue("sigSCFTotalLike",scfTotalLike_); } else { this->setSPlotNtupleDoubleBranchValue("sigTotalLike",sigTotalLike_); } if (usingBkgnd_) { const UInt_t nBkgnds = this->nBkgndClasses(); for ( UInt_t iBkgnd(0); iBkgnd < nBkgnds; ++iBkgnd ) { TString name = this->bkgndClassName(iBkgnd); name += "TotalLike"; this->setSPlotNtupleDoubleBranchValue(name,bkgndTotalLike_[iBkgnd]); } } // fill the tree this->fillSPlotNtupleBranches(); } std::cout << "INFO in LauBsCPFitModel::storePerEvtLlhds : Finished storing per-event likelihood values." << std::endl; } /* void LauBsCPFitModel::embedNegSignal(const TString& fileName, const TString& treeName, Bool_t reuseEventsWithinEnsemble, Bool_t reuseEventsWithinExperiment, Bool_t useReweighting) { if (negSignalTree_) { std::cerr << "ERROR in LauBsCPFitModel::embedNegSignal : Already embedding signal from a file." << std::endl; return; } if (!reuseEventsWithinEnsemble && reuseEventsWithinExperiment) { std::cerr << "WARNING in LauBsCPFitModel::embedNegSignal : Conflicting options provided, will not reuse events at all." << std::endl; reuseEventsWithinExperiment = kFALSE; } negSignalTree_ = new LauEmbeddedData(fileName,treeName,reuseEventsWithinExperiment); Bool_t dataOK = negSignalTree_->findBranches(); if (!dataOK) { delete negSignalTree_; negSignalTree_ = 0; std::cerr << "ERROR in LauBsCPFitModel::embedNegSignal : Problem creating data tree for embedding." << std::endl; return; } reuseSignal_ = reuseEventsWithinEnsemble; useNegReweighting_ = useReweighting; if (this->enableEmbedding() == kFALSE) {this->enableEmbedding(kTRUE);} } void LauBsCPFitModel::embedBkgnd(const TString& bkgndClass, const TString& fileName, const TString& treeName, Bool_t reuseEventsWithinEnsemble, Bool_t reuseEventsWithinExperiment) { if ( ! this->validBkgndClass( bkgndClass ) ) { std::cerr << "ERROR in LauBsCPFitModel::embedBkgnd : Invalid background class \"" << bkgndClass << "\"." << std::endl; std::cerr << " : Background class names must be provided in \"setBkgndClassNames\" before any other background-related actions can be performed." << std::endl; return; } UInt_t bkgndID = this->bkgndClassID( bkgndClass ); if (bkgndTree_[bkgndID]) { std::cerr << "ERROR in LauBsCPFitModel::embedBkgnd : Already embedding background from a file." << std::endl; return; } if (!reuseEventsWithinEnsemble && reuseEventsWithinExperiment) { std::cerr << "WARNING in LauBsCPFitModel::embedBkgnd : Conflicting options provided, will not reuse events at all." << std::endl; reuseEventsWithinExperiment = kFALSE; } bkgndTree_[bkgndID] = new LauEmbeddedData(fileName,treeName,reuseEventsWithinExperiment); Bool_t dataOK = bkgndTree_[bkgndID]->findBranches(); if (!dataOK) { delete bkgndTree_[bkgndID]; bkgndTree_[bkgndID] = 0; std::cerr << "ERROR in LauBsCPFitModel::embedBkgnd : Problem creating data tree for embedding." << std::endl; return; } reuseBkgnd_[bkgndID] = reuseEventsWithinEnsemble; if (this->enableEmbedding() == kFALSE) {this->enableEmbedding(kTRUE);} } void LauBsCPFitModel::embedPosSignal(const TString& fileName, const TString& treeName, Bool_t reuseEventsWithinEnsemble, Bool_t reuseEventsWithinExperiment, Bool_t useReweighting) { if (posSignalTree_) { std::cerr << "ERROR in LauBsCPFitModel::embedPosSignal : Already embedding signal from a file." << std::endl; return; } if (!reuseEventsWithinEnsemble && reuseEventsWithinExperiment) { std::cerr << "WARNING in LauBsCPFitModel::embedPosSignal : Conflicting options provided, will not reuse events at all." << std::endl; reuseEventsWithinExperiment = kFALSE; } posSignalTree_ = new LauEmbeddedData(fileName,treeName,reuseEventsWithinExperiment); Bool_t dataOK = posSignalTree_->findBranches(); if (!dataOK) { delete posSignalTree_; posSignalTree_ = 0; std::cerr << "ERROR in LauBsCPFitModel::embedPosSignal : Problem creating data tree for embedding." << std::endl; return; } reuseSignal_ = reuseEventsWithinEnsemble; usePosReweighting_ = useReweighting; if (this->enableEmbedding() == kFALSE) {this->enableEmbedding(kTRUE);} } */ void LauBsCPFitModel::weightEvents( const TString& /*dataFileName*/, const TString& /*dataTreeName*/ ) { std::cerr << "ERROR in LauBsCPFitModel::weightEvents : Method not available for this fit model." << std::endl; return; } void LauBsCPFitModel::savePDFPlots(const TString& /*label*/) { } void LauBsCPFitModel::savePDFPlotsWave(const TString& /*label*/, const Int_t& /*spin*/) { } diff --git a/src/LauTimeDepFitModel.cc b/src/LauTimeDepFitModel.cc index 0975ff3..312eb4c 100644 --- a/src/LauTimeDepFitModel.cc +++ b/src/LauTimeDepFitModel.cc @@ -1,2336 +1,2345 @@ /* Copyright 2006 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauTimeDepFitModel.cc \brief File containing implementation of LauTimeDepFitModel class. */ #include #include #include #include #include #include "TFile.h" #include "TMinuit.h" #include "TRandom.h" #include "TSystem.h" #include "TVirtualFitter.h" #include "LauAbsBkgndDPModel.hh" #include "LauAbsCoeffSet.hh" #include "LauAbsPdf.hh" #include "LauAsymmCalc.hh" #include "LauComplex.hh" #include "LauConstants.hh" #include "LauDPPartialIntegralInfo.hh" #include "LauDaughters.hh" #include "LauDecayTimePdf.hh" #include "LauFitNtuple.hh" #include "LauGenNtuple.hh" #include "LauIsobarDynamics.hh" #include "LauKinematics.hh" #include "LauPrint.hh" #include "LauRandom.hh" #include "LauScfMap.hh" #include "LauTimeDepFitModel.hh" ClassImp(LauTimeDepFitModel) LauTimeDepFitModel::LauTimeDepFitModel(LauIsobarDynamics* modelB0bar, LauIsobarDynamics* modelB0, LauFlavTag* flavTag) : LauAbsFitModel(), sigModelB0bar_(modelB0bar), sigModelB0_(modelB0), kinematicsB0bar_(modelB0bar ? modelB0bar->getKinematics() : 0), kinematicsB0_(modelB0 ? modelB0->getKinematics() : 0), flavTag_(flavTag), nSigComp_(0), nSigDPPar_(0), nDecayTimePar_(0), nExtraPdfPar_(0), nNormPar_(0), nCalibPar_(0), coeffsB0bar_(0), coeffsB0_(0), coeffPars_(0), fitFracB0bar_(0), fitFracB0_(0), fitFracAsymm_(0), acp_(0), meanEffB0bar_("meanEffB0bar",0.0,0.0,1.0), meanEffB0_("meanEffB0",0.0,0.0,1.0), DPRateB0bar_("DPRateB0bar",0.0,0.0,100.0), DPRateB0_("DPRateB0",0.0,0.0,100.0), signalEvents_(0), signalAsym_(0), cpevVarName_(""), cpEigenValue_(CPEven), evtCPEigenVals_(0), deltaM_("deltaM",0.0), deltaGamma_("deltaGamma",0.0), tau_("tau",LauConstants::tauB0), phiMix_("phiMix", 2.0*LauConstants::beta, -LauConstants::threePi, LauConstants::threePi, kFALSE), sinPhiMix_("sinPhiMix", TMath::Sin(2.0*LauConstants::beta), -3.0, 3.0, kFALSE), cosPhiMix_("cosPhiMix", TMath::Cos(2.0*LauConstants::beta), -3.0, 3.0, kFALSE), useSinCos_(kFALSE), phiMixComplex_(TMath::Cos(-2.0*LauConstants::beta),TMath::Sin(-2.0*LauConstants::beta)), signalDecayTimePdfs_(), curEvtDecayTime_(0.0), curEvtDecayTimeErr_(0.0), sigExtraPdf_(), sigFlavTagPdf_(), bkgdFlavTagPdf_(), iterationsMax_(500000), nGenLoop_(0), ASq_(0.0), aSqMaxVar_(0.0), aSqMaxSet_(1.25), storeGenAmpInfo_(kFALSE), signalTree_(), reuseSignal_(kFALSE), sigDPLike_(0.0), sigExtraLike_(0.0), sigFlavTagLike_(0.0), bkgdFlavTagLike_(0.0), sigTotalLike_(0.0) { // Set up ftag here? // Make sure that the integration scheme will be symmetrised sigModelB0bar_->forceSymmetriseIntegration(kTRUE); sigModelB0_->forceSymmetriseIntegration(kTRUE); } LauTimeDepFitModel::~LauTimeDepFitModel() { for (LauTagCatEmbDataMap::iterator iter = signalTree_.begin(); iter != signalTree_.end(); ++iter){ delete iter->second; } for (LauTagCatEmbDataMapList::iterator iterlist = bkgndTree_.begin(); iterlist != bkgndTree_.end(); ++iterlist){ for (LauTagCatEmbDataMap::iterator iter = (*iterlist).begin(); iter != (*iterlist).end(); ++iter){ delete iter->second; } } } void LauTimeDepFitModel::setupBkgndVectors() { UInt_t nBkgnds = this->nBkgndClasses(); BkgndDPModelsB0_.resize( nBkgnds ); BkgndDPModelsB0bar_.resize( nBkgnds ); BkgndPdfsB0_.resize( nBkgnds ); BkgndPdfsB0bar_.resize( nBkgnds ); bkgndEvents_.resize( nBkgnds ); bkgndAsym_.resize( nBkgnds ); bkgndTree_.resize( nBkgnds ); reuseBkgnd_.resize( nBkgnds ); bkgndDPLike_.resize( nBkgnds ); bkgndExtraLike_.resize( nBkgnds ); bkgndTotalLike_.resize( nBkgnds ); } void LauTimeDepFitModel::setNSigEvents(LauParameter* nSigEvents) { if ( nSigEvents == 0 ) { std::cerr << "ERROR in LauTimeDepFitModel::setNSigEvents : The LauParameter pointer is null." << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( signalEvents_ != 0 ) { std::cerr << "ERROR in LauTimeDepFitModel::setNSigEvents : You are trying to overwrite the signal yield." << std::endl; return; } if ( signalAsym_ != 0 ) { std::cerr << "ERROR in LauTimeDepFitModel::setNSigEvents : You are trying to overwrite the signal asymmetry." << std::endl; return; } signalEvents_ = nSigEvents; signalEvents_->name("signalEvents"); Double_t value = nSigEvents->value(); signalEvents_->range(-2.0*(TMath::Abs(value)+1.0),2.0*(TMath::Abs(value)+1.0)); signalAsym_ = new LauParameter("signalAsym",0.0,-1.0,1.0,kTRUE); } void LauTimeDepFitModel::setNSigEvents(LauParameter* nSigEvents, LauParameter* sigAsym) { if ( nSigEvents == 0 ) { std::cerr << "ERROR in LauTimeDepFitModel::setNSigEvents : The event LauParameter pointer is null." << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( sigAsym == 0 ) { std::cerr << "ERROR in LauTimeDepFitModel::setNSigEvents : The asym LauParameter pointer is null." << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( signalEvents_ != 0 ) { std::cerr << "ERROR in LauTimeDepFitModel::setNSigEvents : You are trying to overwrite the signal yield." << std::endl; return; } if ( signalAsym_ != 0 ) { std::cerr << "ERROR in LauTimeDepFitModel::setNSigEvents : You are trying to overwrite the signal asymmetry." << std::endl; return; } signalEvents_ = nSigEvents; signalEvents_->name("signalEvents"); Double_t value = nSigEvents->value(); signalEvents_->range(-2.0*(TMath::Abs(value)+1.0), 2.0*(TMath::Abs(value)+1.0)); signalAsym_ = sigAsym; signalAsym_->name("signalAsym"); signalAsym_->range(-1.0,1.0); } -void LauTimeDepFitModel::setNBkgndEvents(LauParameter* nBkgndEvents) +void LauTimeDepFitModel::setNBkgndEvents(LauAbsRValue* nBkgndEvents) { if ( nBkgndEvents == 0 ) { std::cerr << "ERROR in LauTimeDepFitModel::setNBgkndEvents : The background yield LauParameter pointer is null." << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( ! this->validBkgndClass( nBkgndEvents->name() ) ) { std::cerr << "ERROR in LauTimeDepFitModel::setNBkgndEvents : Invalid background class \"" << nBkgndEvents->name() << "\"." << std::endl; std::cerr << " : Background class names must be provided in \"setBkgndClassNames\" before any other background-related actions can be performed." << std::endl; gSystem->Exit(EXIT_FAILURE); } UInt_t bkgndID = this->bkgndClassID( nBkgndEvents->name() ); if ( bkgndEvents_[bkgndID] != 0 ) { std::cerr << "ERROR in LauTimeDepFitModel::setNBkgndEvents : You are trying to overwrite the background yield." << std::endl; return; } if ( bkgndAsym_[bkgndID] != 0 ) { std::cerr << "ERROR in LauTimeDepFitModel::setNBkgndEvents : You are trying to overwrite the background asymmetry." << std::endl; return; } + nBkgndEvents->name( nBkgndEvents->name()+"Events" ); + if ( nBkgndEvents->isLValue() ) { + Double_t value = nBkgndEvents->value(); + LauParameter* yield = dynamic_cast( nBkgndEvents ); + yield->range(-2.0*(TMath::Abs(value)+1.0), 2.0*(TMath::Abs(value)+1.0)); + } bkgndEvents_[bkgndID] = nBkgndEvents; - bkgndEvents_[bkgndID]->name( nBkgndEvents->name()+"Events" ); - Double_t value = nBkgndEvents->value(); - bkgndEvents_[bkgndID]->range(-2.0*(TMath::Abs(value)+1.0), 2.0*(TMath::Abs(value)+1.0)); bkgndAsym_[bkgndID] = new LauParameter(nBkgndEvents->name()+"Asym",0.0,-1.0,1.0,kTRUE); } -void LauTimeDepFitModel::setNBkgndEvents(LauParameter* nBkgndEvents, LauParameter* bkgndAsym) +void LauTimeDepFitModel::setNBkgndEvents(LauAbsRValue* nBkgndEvents, LauAbsRValue* bkgndAsym) { if ( nBkgndEvents == 0 ) { std::cerr << "ERROR in LauTimeDepFitModel::setNBkgndEvents : The background yield LauParameter pointer is null." << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( bkgndAsym == 0 ) { std::cerr << "ERROR in LauTimeDepFitModel::setNBkgndEvents : The background asym LauParameter pointer is null." << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( ! this->validBkgndClass( nBkgndEvents->name() ) ) { std::cerr << "ERROR in LauTimeDepFitModel::setNBkgndEvents : Invalid background class \"" << nBkgndEvents->name() << "\"." << std::endl; std::cerr << " : Background class names must be provided in \"setBkgndClassNames\" before any other background-related actions can be performed." << std::endl; gSystem->Exit(EXIT_FAILURE); } UInt_t bkgndID = this->bkgndClassID( nBkgndEvents->name() ); if ( bkgndEvents_[bkgndID] != 0 ) { std::cerr << "ERROR in LauTimeDepFitModel::setNBkgndEvents : You are trying to overwrite the background yield." << std::endl; return; } if ( bkgndAsym_[bkgndID] != 0 ) { std::cerr << "ERROR in LauTimeDepFitModel::setNBkgndEvents : You are trying to overwrite the background asymmetry." << std::endl; return; } - bkgndEvents_[bkgndID] = nBkgndEvents; bkgndEvents_[bkgndID]->name( nBkgndEvents->name()+"Events" ); - Double_t value = nBkgndEvents->value(); - bkgndEvents_[bkgndID]->range(-2.0*(TMath::Abs(value)+1.0), 2.0*(TMath::Abs(value)+1.0)); + if ( nBkgndEvents->isLValue() ) { + Double_t value = nBkgndEvents->value(); + LauParameter* yield = dynamic_cast( nBkgndEvents ); + yield->range(-2.0*(TMath::Abs(value)+1.0), 2.0*(TMath::Abs(value)+1.0)); + } + bkgndEvents_[bkgndID] = nBkgndEvents; - bkgndAsym_[bkgndID] = bkgndAsym; bkgndAsym_[bkgndID]->name( nBkgndEvents->name()+"Asym" ); - bkgndAsym_[bkgndID]->range(-1.0,1.0); + if ( bkgndAsym->isLValue() ) { + LauParameter* asym = dynamic_cast( bkgndAsym ); + asym->range(-1.0, 1.0); + } + bkgndAsym_[bkgndID] = bkgndAsym; } void LauTimeDepFitModel::setSignalDtPdf(Int_t tagCat, LauDecayTimePdf* pdf) { if (!flavTag_->validTagCat(tagCat)) { std::cerr<<"ERROR in LauTimeDepFitModel::setSignalDtPdf : Tagging category \""<validTagCat(tagCat)) { std::cerr<<"ERROR in LauTimeDepFitModel::setSignalPdfs : Tagging category \""<updateCoeffs(); // Initialisation if (this->useDP() == kTRUE) { this->initialiseDPModels(); } //Flavour tagging flavTag_->initialise(); if (!this->useDP() && sigExtraPdf_.empty()) { std::cerr<<"ERROR in LauTimeDepFitModel::initialise : Signal model doesn't exist for any variable."<Exit(EXIT_FAILURE); } if (this->useDP() == kTRUE) { // Check that we have all the Dalitz-plot models if ((sigModelB0bar_ == 0) || (sigModelB0_ == 0)) { std::cerr<<"ERROR in LauTimeDepFitModel::initialise : the pointer to one (particle or anti-particle) of the signal DP models is null."<Exit(EXIT_FAILURE); } } // Clear the vectors of parameter information so we can start from scratch this->clearFitParVectors(); // Set the fit parameters for signal and background models this->setSignalDPParameters(); // Set the fit parameters for the decay time models this->setDecayTimeParameters(); // Set the fit parameters for the extra PDFs this->setExtraPdfParameters(); // Set the initial bg and signal events this->setFitNEvents(); // Handle flavour-tagging calibration parameters this->setCalibParams(); // Check that we have the expected number of fit variables const LauParameterPList& fitVars = this->fitPars(); if (fitVars.size() != (nSigDPPar_ + nDecayTimePar_ + nExtraPdfPar_ + nNormPar_ + nCalibPar_)) { std::cerr<<"ERROR in LauTimeDepFitModel::initialise : Number of fit parameters not of expected size."<Exit(EXIT_FAILURE); } this->setExtraNtupleVars(); } void LauTimeDepFitModel::recalculateNormalisation() { sigModelB0bar_->recalculateNormalisation(); sigModelB0_->recalculateNormalisation(); sigModelB0bar_->modifyDataTree(); sigModelB0_->modifyDataTree(); this->calcInterferenceTermIntegrals(); } void LauTimeDepFitModel::initialiseDPModels() { if (sigModelB0bar_ == 0) { std::cerr<<"ERROR in LauTimeDepFitModel::initialiseDPModels : B0bar signal DP model doesn't exist"<Exit(EXIT_FAILURE); } if (sigModelB0_ == 0) { std::cerr<<"ERROR in LauTimeDepFitModel::initialiseDPModels : B0 signal DP model doesn't exist"<Exit(EXIT_FAILURE); } // Need to check that the number of components we have and that the dynamics has matches up const UInt_t nAmpB0bar = sigModelB0bar_->getnTotAmp(); const UInt_t nAmpB0 = sigModelB0_->getnTotAmp(); if ( nAmpB0bar != nAmpB0 ) { std::cerr << "ERROR in LauTimeDepFitModel::initialiseDPModels : Unequal number of signal DP components in the particle and anti-particle models: " << nAmpB0bar << " != " << nAmpB0 << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( nAmpB0bar != nSigComp_ ) { std::cerr << "ERROR in LauTimeDepFitModel::initialiseDPModels : Number of signal DP components in the model (" << nAmpB0bar << ") not equal to number of coefficients supplied (" << nSigComp_ << ")." << std::endl; gSystem->Exit(EXIT_FAILURE); } std::cout<<"INFO in LauTimeDepFitModel::initialiseDPModels : Initialising signal DP model"<initialise(coeffsB0bar_); sigModelB0_->initialise(coeffsB0_); fifjEffSum_.clear(); fifjEffSum_.resize(nSigComp_); for (UInt_t iAmp = 0; iAmp < nSigComp_; ++iAmp) { fifjEffSum_[iAmp].resize(nSigComp_); } // calculate the integrals of the A*Abar terms this->calcInterferenceTermIntegrals(); this->calcInterTermNorm(); } void LauTimeDepFitModel::calcInterferenceTermIntegrals() { const std::vector& integralInfoListB0bar = sigModelB0bar_->getIntegralInfos(); const std::vector& integralInfoListB0 = sigModelB0_->getIntegralInfos(); // TODO should check (first time) that they match in terms of number of entries in the vectors and that each entry has the same number of points, ranges, weights etc. LauComplex A, Abar, fifjEffSumTerm; for (UInt_t iAmp = 0; iAmp < nSigComp_; ++iAmp) { for (UInt_t jAmp = 0; jAmp < nSigComp_; ++jAmp) { fifjEffSum_[iAmp][jAmp].zero(); } } const UInt_t nIntegralRegions = integralInfoListB0bar.size(); for ( UInt_t iRegion(0); iRegion < nIntegralRegions; ++iRegion ) { const LauDPPartialIntegralInfo* integralInfoB0bar = integralInfoListB0bar[iRegion]; const LauDPPartialIntegralInfo* integralInfoB0 = integralInfoListB0[iRegion]; const UInt_t nm13Points = integralInfoB0bar->getnm13Points(); const UInt_t nm23Points = integralInfoB0bar->getnm23Points(); for (UInt_t m13 = 0; m13 < nm13Points; ++m13) { for (UInt_t m23 = 0; m23 < nm23Points; ++m23) { const Double_t weight = integralInfoB0bar->getWeight(m13,m23); const Double_t eff = integralInfoB0bar->getEfficiency(m13,m23); const Double_t effWeight = eff*weight; for (UInt_t iAmp = 0; iAmp < nSigComp_; ++iAmp) { A = integralInfoB0->getAmplitude(m13, m23, iAmp); for (UInt_t jAmp = 0; jAmp < nSigComp_; ++jAmp) { Abar = integralInfoB0bar->getAmplitude(m13, m23, jAmp); fifjEffSumTerm = Abar*A.conj(); fifjEffSumTerm.rescale(effWeight); fifjEffSum_[iAmp][jAmp] += fifjEffSumTerm; } } } } } } void LauTimeDepFitModel::calcInterTermNorm() { const std::vector& fNormB0bar = sigModelB0bar_->getFNorm(); const std::vector& fNormB0 = sigModelB0_->getFNorm(); LauComplex norm; for (UInt_t iAmp = 0; iAmp < nSigComp_; ++iAmp) { for (UInt_t jAmp = 0; jAmp < nSigComp_; ++jAmp) { LauComplex coeffTerm = coeffsB0bar_[jAmp]*coeffsB0_[iAmp].conj(); coeffTerm *= fifjEffSum_[iAmp][jAmp]; coeffTerm.rescale(fNormB0bar[jAmp] * fNormB0[iAmp]); norm += coeffTerm; } } norm *= phiMixComplex_; interTermReNorm_ = 2.0*norm.re(); interTermImNorm_ = 2.0*norm.im(); } void LauTimeDepFitModel::setAmpCoeffSet(LauAbsCoeffSet* coeffSet) { // Is there a component called compName in the signal models? TString compName = coeffSet->name(); TString conjName = sigModelB0bar_->getConjResName(compName); const LauDaughters* daughtersB0bar = sigModelB0bar_->getDaughters(); const LauDaughters* daughtersB0 = sigModelB0_->getDaughters(); const Bool_t conjugate = daughtersB0bar->isConjugate( daughtersB0 ); if ( ! sigModelB0bar_->hasResonance(compName) ) { if ( ! sigModelB0bar_->hasResonance(conjName) ) { std::cerr<<"ERROR in LauTimeDepFitModel::setAmpCoeffSet : B0bar signal DP model doesn't contain component \""<name( compName ); } if ( conjugate ) { if ( ! sigModelB0_->hasResonance(conjName) ) { std::cerr<<"ERROR in LauTimeDepFitModel::setAmpCoeffSet : B0 signal DP model doesn't contain component \""<hasResonance(compName) ) { std::cerr<<"ERROR in LauTimeDepFitModel::setAmpCoeffSet : B0 signal DP model doesn't contain component \""<::const_iterator iter=coeffPars_.begin(); iter!=coeffPars_.end(); ++iter) { if ((*iter)->name() == compName) { std::cerr<<"ERROR in LauTimeDepFitModel::setAmpCoeffSet : Have already set coefficients for \""<index(nSigComp_); coeffPars_.push_back(coeffSet); TString parName = coeffSet->baseName(); parName += "FitFracAsym"; fitFracAsymm_.push_back(LauParameter(parName, 0.0, -1.0, 1.0)); acp_.push_back(coeffSet->acp()); ++nSigComp_; std::cout<<"INFO in LauTimeDepFitModel::setAmpCoeffSet : Added coefficients for component \""<acp(); LauAsymmCalc asymmCalc(fitFracB0bar_[i][i].value(), fitFracB0_[i][i].value()); Double_t asym = asymmCalc.getAsymmetry(); fitFracAsymm_[i].value(asym); if (initValues) { fitFracAsymm_[i].genValue(asym); fitFracAsymm_[i].initValue(asym); } } } void LauTimeDepFitModel::setSignalDPParameters() { // Set the fit parameters for the signal model. nSigDPPar_ = 0; if ( ! this->useDP() ) { return; } std::cout << "INFO in LauTimeDepFitModel::setSignalDPParameters : Setting the initial fit parameters for the signal DP model." << std::endl; // Place isobar coefficient parameters in vector of fit variables LauParameterPList& fitVars = this->fitPars(); for (UInt_t i = 0; i < nSigComp_; ++i) { LauParameterPList pars = coeffPars_[i]->getParameters(); for (LauParameterPList::iterator iter = pars.begin(); iter != pars.end(); ++iter) { if ( !(*iter)->clone() ) { fitVars.push_back(*iter); ++nSigDPPar_; } } } // Obtain the resonance parameters and place them in the vector of fit variables and in a separate vector // Need to make sure that they are unique because some might appear in both DP models LauParameterPSet& resVars = this->resPars(); resVars.clear(); LauParameterPList& sigDPParsB0bar = sigModelB0bar_->getFloatingParameters(); LauParameterPList& sigDPParsB0 = sigModelB0_->getFloatingParameters(); for ( LauParameterPList::iterator iter = sigDPParsB0bar.begin(); iter != sigDPParsB0bar.end(); ++iter ) { if ( resVars.insert(*iter).second ) { fitVars.push_back(*iter); ++nSigDPPar_; } } for ( LauParameterPList::iterator iter = sigDPParsB0.begin(); iter != sigDPParsB0.end(); ++iter ) { if ( resVars.insert(*iter).second ) { fitVars.push_back(*iter); ++nSigDPPar_; } } } UInt_t LauTimeDepFitModel::addParametersToFitList(LauTagCatDtPdfMap& theMap) { UInt_t counter(0); LauParameterPList& fitVars = this->fitPars(); // loop through the map for (LauTagCatDtPdfMap::iterator iter = theMap.begin(); iter != theMap.end(); ++iter) { // grab the pdf and then its parameters LauDecayTimePdf* thePdf = (*iter).second; // The first one is the tagging category LauAbsRValuePList& rvalues = thePdf->getParameters(); // loop through the parameters for (LauAbsRValuePList::iterator pars_iter = rvalues.begin(); pars_iter != rvalues.end(); ++pars_iter) { LauParameterPList params = (*pars_iter)->getPars(); for (LauParameterPList::iterator params_iter = params.begin(); params_iter != params.end(); ++params_iter) { // for each "original" parameter add it to the list of fit parameters and increment the counter if ( !(*params_iter)->clone() && ( !(*params_iter)->fixed() || (this->twoStageFit() && (*params_iter)->secondStage()) ) ) { fitVars.push_back(*params_iter); ++counter; } } } } return counter; } UInt_t LauTimeDepFitModel::addParametersToFitList(LauTagCatPdfListMap& theMap) { UInt_t counter(0); // loop through the map for (LauTagCatPdfListMap::iterator iter = theMap.begin(); iter != theMap.end(); ++iter) { counter += this->addFitParameters(iter->second); // first is the tagging category } return counter; } void LauTimeDepFitModel::setDecayTimeParameters() { nDecayTimePar_ = 0; // Loop over the Dt PDFs nDecayTimePar_ += this->addParametersToFitList(signalDecayTimePdfs_); LauParameterPList& fitVars = this->fitPars(); if (useSinCos_) { fitVars.push_back(&sinPhiMix_); fitVars.push_back(&cosPhiMix_); nDecayTimePar_ += 2; } else { fitVars.push_back(&phiMix_); ++nDecayTimePar_; } } void LauTimeDepFitModel::setExtraPdfParameters() { // Include the parameters of the PDF for each tagging category in the fit // NB all of them are passed to the fit, even though some have been fixed through parameter.fixed(kTRUE) // With the new "cloned parameter" scheme only "original" parameters are passed to the fit. // Their clones are updated automatically when the originals are updated. nExtraPdfPar_ = 0; nExtraPdfPar_ += this->addParametersToFitList(sigExtraPdf_); } void LauTimeDepFitModel::setFitNEvents() { nNormPar_ = 0; // Initialise the total number of events to be the sum of all the hypotheses Double_t nTotEvts = signalEvents_->value(); this->eventsPerExpt(TMath::FloorNint(nTotEvts)); LauParameterPList& fitVars = this->fitPars(); // if doing an extended ML fit add the signal fraction into the fit parameters if (this->doEMLFit()) { std::cout<<"INFO in LauTimeDepFitModel::setFitNEvents : Initialising number of events for signal and background components..."<useDP() == kFALSE) { fitVars.push_back(signalAsym_); ++nNormPar_; } // TODO arguably should delegate this LauTagCatParamMap& signalTagCatFrac = flavTag_->getSignalTagCatFrac(); // tagging-category fractions for signal events for (LauTagCatParamMap::iterator iter = signalTagCatFrac.begin(); iter != signalTagCatFrac.end(); ++iter) { if (iter == signalTagCatFrac.begin()) { continue; } LauParameter* par = &((*iter).second); fitVars.push_back(par); ++nNormPar_; } } void LauTimeDepFitModel::setCalibParams() { std::vector calibParams = flavTag_->getCalibParameters(); // If calib params aren't fixed, add them to the vector of floating parameters LauParameter * p0 = calibParams[0]; LauParameter * p1 = calibParams[1]; if (!p0->fixed()) { LauParameterPList& fitVars = this->fitPars(); nCalibPar_ += 1; fitVars.push_back(p0); } if (!p1->fixed()) { LauParameterPList& fitVars = this->fitPars(); nCalibPar_ += 1; fitVars.push_back(p1); } } void LauTimeDepFitModel::setExtraNtupleVars() { // Set-up other parameters derived from the fit results, e.g. fit fractions. if (this->useDP() != kTRUE) { return; } // First clear the vectors so we start from scratch this->clearExtraVarVectors(); LauParameterList& extraVars = this->extraPars(); // Add the B0 and B0bar fit fractions for each signal component fitFracB0bar_ = sigModelB0bar_->getFitFractions(); if (fitFracB0bar_.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepFitModel::setExtraNtupleVars : Initial Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } for (UInt_t i(0); igetFitFractions(); if (fitFracB0_.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepFitModel::setExtraNtupleVars : Initial Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } for (UInt_t i(0); icalcAsymmetries(kTRUE); // Add the Fit Fraction asymmetry for each signal component for (UInt_t i = 0; i < nSigComp_; i++) { extraVars.push_back(fitFracAsymm_[i]); } // Add the calculated CP asymmetry for each signal component for (UInt_t i = 0; i < nSigComp_; i++) { extraVars.push_back(acp_[i]); } // Now add in the DP efficiency values Double_t initMeanEffB0bar = sigModelB0bar_->getMeanEff().initValue(); meanEffB0bar_.value(initMeanEffB0bar); meanEffB0bar_.initValue(initMeanEffB0bar); meanEffB0bar_.genValue(initMeanEffB0bar); extraVars.push_back(meanEffB0bar_); Double_t initMeanEffB0 = sigModelB0_->getMeanEff().initValue(); meanEffB0_.value(initMeanEffB0); meanEffB0_.initValue(initMeanEffB0); meanEffB0_.genValue(initMeanEffB0); extraVars.push_back(meanEffB0_); // Also add in the DP rates Double_t initDPRateB0bar = sigModelB0bar_->getDPRate().initValue(); DPRateB0bar_.value(initDPRateB0bar); DPRateB0bar_.initValue(initDPRateB0bar); DPRateB0bar_.genValue(initDPRateB0bar); extraVars.push_back(DPRateB0bar_); Double_t initDPRateB0 = sigModelB0_->getDPRate().initValue(); DPRateB0_.value(initDPRateB0); DPRateB0_.initValue(initDPRateB0); DPRateB0_.genValue(initDPRateB0); extraVars.push_back(DPRateB0_); } void LauTimeDepFitModel::finaliseFitResults(const TString& tablePrefixName) { // Retrieve parameters from the fit results for calculations and toy generation // and eventually store these in output root ntuples/text files // Now take the fit parameters and update them as necessary // i.e. to make mag > 0.0, phase in the right range. // This function will also calculate any other values, such as the // fit fractions, using any errors provided by fitParErrors as appropriate. // Also obtain the pull values: (measured - generated)/(average error) if (this->useDP() == kTRUE) { for (UInt_t i = 0; i < nSigComp_; ++i) { // Check whether we have "a > 0.0", and phases in the right range coeffPars_[i]->finaliseValues(); } } // update the pulls on the event fractions and asymmetries if (this->doEMLFit()) { signalEvents_->updatePull(); } if (this->useDP() == kFALSE) { signalAsym_->updatePull(); } // Finalise the pulls on the decay time parameters for (LauTagCatDtPdfMap::iterator iter = signalDecayTimePdfs_.begin(); iter != signalDecayTimePdfs_.end(); ++iter) { LauDecayTimePdf* pdf = (*iter).second; pdf->updatePulls(); } if (useSinCos_) { cosPhiMix_.updatePull(); sinPhiMix_.updatePull(); } else { this->checkMixingPhase(); } // Update the pulls on all the extra PDFs' parameters for (LauTagCatPdfListMap::iterator iter = sigExtraPdf_.begin(); iter != sigExtraPdf_.end(); ++iter) { this->updateFitParameters(iter->second); } LauTagCatParamMap& signalTagCatFrac = flavTag_->getSignalTagCatFrac(); // Tagging-category fractions for signal and background events Double_t firstCatFrac(1.0); Int_t firstCat(0); for (LauTagCatParamMap::iterator iter = signalTagCatFrac.begin(); iter != signalTagCatFrac.end(); ++iter) { if (iter == signalTagCatFrac.begin()) { firstCat = iter->first; continue; } LauParameter& par = (*iter).second; firstCatFrac -= par.value(); // update the parameter pull par.updatePull(); } signalTagCatFrac[firstCat].value(firstCatFrac); signalTagCatFrac[firstCat].updatePull(); // Fill the fit results to the ntuple // update the coefficients and then calculate the fit fractions and ACP's if (this->useDP() == kTRUE) { this->updateCoeffs(); sigModelB0bar_->updateCoeffs(coeffsB0bar_); sigModelB0bar_->calcExtraInfo(); sigModelB0_->updateCoeffs(coeffsB0_); sigModelB0_->calcExtraInfo(); LauParArray fitFracB0bar = sigModelB0bar_->getFitFractions(); if (fitFracB0bar.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepFitModel::finaliseFitResults : Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } LauParArray fitFracB0 = sigModelB0_->getFitFractions(); if (fitFracB0.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepFitModel::finaliseFitResults : Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } for (UInt_t i(0); igetMeanEff().value()); meanEffB0_.value(sigModelB0_->getMeanEff().value()); DPRateB0bar_.value(sigModelB0bar_->getDPRate().value()); DPRateB0_.value(sigModelB0_->getDPRate().value()); this->calcAsymmetries(); // Then store the final fit parameters, and any extra parameters for // the signal model (e.g. fit fractions, FF asymmetries, ACPs, mean efficiency and DP rate) this->clearExtraVarVectors(); LauParameterList& extraVars = this->extraPars(); for (UInt_t i(0); iprintFitFractions(std::cout); this->printAsymmetries(std::cout); } const LauParameterPList& fitVars = this->fitPars(); const LauParameterList& extraVars = this->extraPars(); LauFitNtuple* ntuple = this->fitNtuple(); ntuple->storeParsAndErrors(fitVars, extraVars); // find out the correlation matrix for the parameters ntuple->storeCorrMatrix(this->iExpt(), this->fitStatus(), this->covarianceMatrix()); // Fill the data into ntuple ntuple->updateFitNtuple(); // Print out the partial fit fractions, phases and the // averaged efficiency, reweighted by the dynamics (and anything else) if (this->writeLatexTable()) { TString sigOutFileName(tablePrefixName); sigOutFileName += "_"; sigOutFileName += this->iExpt(); sigOutFileName += "Expt.tex"; this->writeOutTable(sigOutFileName); } } void LauTimeDepFitModel::printFitFractions(std::ostream& output) { // Print out Fit Fractions, total DP rate and mean efficiency // First for the B0bar events for (UInt_t i = 0; i < nSigComp_; i++) { const TString compName(coeffPars_[i]->name()); output<<"B0bar FitFraction for component "<useDP() == kTRUE) { // print the fit coefficients in one table coeffPars_.front()->printTableHeading(fout); for (UInt_t i = 0; i < nSigComp_; i++) { coeffPars_[i]->printTableRow(fout); } fout<<"\\hline"<name(); resName = resName.ReplaceAll("_", "\\_"); fout< =$ & $"; print.printFormat(fout, meanEffB0bar_.value()); fout << "$ & $"; print.printFormat(fout, meanEffB0_.value()); fout << "$ & & \\\\" << std::endl; if (useSinCos_) { fout << "$\\sinPhiMix =$ & $"; print.printFormat(fout, sinPhiMix_.value()); fout << " \\pm "; print.printFormat(fout, sinPhiMix_.error()); fout << "$ & & & & & & & \\\\" << std::endl; fout << "$\\cosPhiMix =$ & $"; print.printFormat(fout, cosPhiMix_.value()); fout << " \\pm "; print.printFormat(fout, cosPhiMix_.error()); fout << "$ & & & & & & & \\\\" << std::endl; } else { fout << "$\\phiMix =$ & $"; print.printFormat(fout, phiMix_.value()); fout << " \\pm "; print.printFormat(fout, phiMix_.error()); fout << "$ & & & & & & & \\\\" << std::endl; } fout << "\\hline \n\\end{tabular}" << std::endl; } if (!sigExtraPdf_.empty()) { fout<<"\\begin{tabular}{|l|c|}"<printFitParameters(iter->second, fout); } fout<<"\\hline \n\\end{tabular}"<updateSigEvents(); // Check whether we want to have randomised initial fit parameters for the signal model if (this->useRandomInitFitPars() == kTRUE) { this->randomiseInitFitPars(); } } void LauTimeDepFitModel::randomiseInitFitPars() { // Only randomise those parameters that are not fixed! std::cout<<"INFO in LauTimeDepFitModel::randomiseInitFitPars : Randomising the initial values of the coefficients of the DP components (and phiMix)..."<randomiseInitValues(); } phiMix_.randomiseValue(-LauConstants::pi, LauConstants::pi); if (useSinCos_) { sinPhiMix_.initValue(TMath::Sin(phiMix_.initValue())); cosPhiMix_.initValue(TMath::Cos(phiMix_.initValue())); } } LauTimeDepFitModel::LauGenInfo LauTimeDepFitModel::eventsToGenerate() { // Determine the number of events to generate for each hypothesis // If we're smearing then smear each one individually // NB this individual smearing has to be done individually per tagging category as well LauGenInfo nEvtsGen; LauTagCatGenInfo eventsB0, eventsB0bar; // Signal // If we're including the DP and decay time we can't decide on the tag // yet, since it depends on the whole DP+dt PDF, however, if // we're not then we need to decide. Double_t evtWeight(1.0); Double_t nEvts = signalEvents_->genValue(); if ( nEvts < 0.0 ) { evtWeight = -1.0; nEvts = TMath::Abs( nEvts ); } LauTagCatParamMap& signalTagCatFrac = flavTag_->getSignalTagCatFrac(); Double_t sigAsym(0.0); if (this->useDP() == kFALSE) { sigAsym = signalAsym_->genValue(); for (LauTagCatParamMap::const_iterator iter = signalTagCatFrac.begin(); iter != signalTagCatFrac.end(); ++iter) { const LauParameter& par = iter->second; Double_t eventsbyTagCat = par.value() * nEvts; Double_t eventsB0byTagCat = TMath::Nint(eventsbyTagCat/2.0 * (1.0 - sigAsym)); Double_t eventsB0barbyTagCat = TMath::Nint(eventsbyTagCat/2.0 * (1.0 + sigAsym)); if (this->doPoissonSmearing()) { eventsB0byTagCat = LauRandom::randomFun()->Poisson(eventsB0byTagCat); eventsB0barbyTagCat = LauRandom::randomFun()->Poisson(eventsB0barbyTagCat); } eventsB0[iter->first] = std::make_pair( TMath::Nint(eventsB0byTagCat), evtWeight ); eventsB0bar[iter->first] = std::make_pair( TMath::Nint(eventsB0barbyTagCat), evtWeight ); } // CONVENTION WARNING nEvtsGen[std::make_pair("signal",-1)] = eventsB0; nEvtsGen[std::make_pair("signal",+1)] = eventsB0bar; } else { Double_t rateB0bar = sigModelB0bar_->getDPRate().value(); Double_t rateB0 = sigModelB0_->getDPRate().value(); if ( rateB0bar+rateB0 > 1e-30) { sigAsym = (rateB0bar-rateB0)/(rateB0bar+rateB0); } for (LauTagCatParamMap::const_iterator iter = signalTagCatFrac.begin(); iter != signalTagCatFrac.end(); ++iter) { const LauParameter& par = iter->second; Double_t eventsbyTagCat = par.value() * nEvts; if (this->doPoissonSmearing()) { eventsbyTagCat = LauRandom::randomFun()->Poisson(eventsbyTagCat); } eventsB0[iter->first] = std::make_pair( TMath::Nint(eventsbyTagCat), evtWeight ); } nEvtsGen[std::make_pair("signal",0)] = eventsB0; // generate signal event, decide tag later. } std::cout<<"INFO in LauTimeDepFitModel::eventsToGenerate : Generating toy MC with:"<setGenNtupleIntegerBranchValue("genSig",1); // All the generate*Event() methods have to fill in curEvtDecayTime_ and curEvtDecayTimeErr_ // In addition, generateSignalEvent has to decide on the tag and fill in curEvtTagFlv_ genOK = this->generateSignalEvent(); } else { genOK = kFALSE; } if (!genOK) { // If there was a problem with the generation then break out and return. // The problem model will have adjusted itself so that all should be OK next time. break; } if (this->useDP() == kTRUE) { this->setDPDtBranchValues(); // store DP, decay time and tagging variables in the ntuple } // Store the event's tag and tagging category this->setGenNtupleIntegerBranchValue("cpEigenvalue", cpEigenValue_); this->setGenNtupleIntegerBranchValue("tagCat",curEvtTagCat_); this->setGenNtupleIntegerBranchValue("tagFlv",curEvtTagFlv_); this->setGenNtupleDoubleBranchValue(flavTag_->getMistagVarName(),curEvtMistag_); // Store the event number (within this experiment) // and then increment it this->setGenNtupleIntegerBranchValue("iEvtWithinExpt",evtNum); ++evtNum; // Write the values into the tree this->fillGenNtupleBranches(); // Print an occasional progress message if (iEvt%1000 == 0) {std::cout<<"INFO in LauTimeDepFitModel::genExpt : Generated event number "<useDP() && genOK) { sigModelB0bar_->checkToyMC(kTRUE); sigModelB0_->checkToyMC(kTRUE); std::cout<<"aSqMaxSet = "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } LauParArray fitFracB0 = sigModelB0_->getFitFractions(); if (fitFracB0.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepFitModel::generate : Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } for (UInt_t i(0); igetMeanEff().value()); meanEffB0_.value(sigModelB0_->getMeanEff().value()); DPRateB0bar_.value(sigModelB0bar_->getDPRate().value()); DPRateB0_.value(sigModelB0_->getDPRate().value()); } } // If we're reusing embedded events or if the generation is being // reset then clear the lists of used events //if (!signalTree_.empty() && (reuseSignal_ || !genOK)) { if (reuseSignal_ || !genOK) { for(LauTagCatEmbDataMap::const_iterator iter = signalTree_.begin(); iter != signalTree_.end(); ++iter) { (iter->second)->clearUsedList(); } } return genOK; } Bool_t LauTimeDepFitModel::generateSignalEvent() { // Generate signal event, including SCF if necessary. // DP:DecayTime generation follows. // If it's ok, we then generate mES, DeltaE, Fisher/NN... Bool_t genOK(kTRUE); Bool_t generatedEvent(kFALSE); Bool_t doSquareDP = kinematicsB0bar_->squareDP(); doSquareDP &= kinematicsB0_->squareDP(); LauKinematics* kinematics(kinematicsB0bar_); // find the right decay time PDF for the current tagging category LauTagCatDtPdfMap::const_iterator dt_iter = signalDecayTimePdfs_.find(curEvtTagCat_); LauDecayTimePdf* decayTimePdf = (dt_iter != signalDecayTimePdfs_.end()) ? dt_iter->second : 0; // find the right embedded data for the current tagging category LauTagCatEmbDataMap::const_iterator emb_iter = signalTree_.find(curEvtTagCat_); LauEmbeddedData* embeddedData = (emb_iter != signalTree_.end()) ? emb_iter->second : 0; // find the right extra PDFs for the current tagging category LauTagCatPdfListMap::iterator extra_iter = sigExtraPdf_.find(curEvtTagCat_); LauPdfList* extraPdfs = (extra_iter != sigExtraPdf_.end()) ? &(extra_iter->second) : 0; if (this->useDP()) { if (embeddedData) { embeddedData->getEmbeddedEvent(kinematics); curEvtTagFlv_ = TMath::Nint(embeddedData->getValue("tagFlv")); curEvtDecayTimeErr_ = embeddedData->getValue(decayTimePdf->varErrName()); curEvtDecayTime_ = embeddedData->getValue(decayTimePdf->varName()); if (embeddedData->haveBranch("mcMatch")) { Int_t match = TMath::Nint(embeddedData->getValue("mcMatch")); if (match) { this->setGenNtupleIntegerBranchValue("genTMSig",1); this->setGenNtupleIntegerBranchValue("genSCFSig",0); } else { this->setGenNtupleIntegerBranchValue("genTMSig",0); this->setGenNtupleIntegerBranchValue("genSCFSig",1); } } } else { nGenLoop_ = 0; // generate the decay time error (NB the kTRUE forces the generation of a new value) curEvtDecayTimeErr_ = decayTimePdf->generateError(kTRUE); while (generatedEvent == kFALSE && nGenLoop_ < iterationsMax_) { // Calculate the unnormalised truth-matched signal likelihood // First let define the tag flavour CONVENTION WARNING Double_t randNo = LauRandom::randomFun()->Rndm(); if (randNo < 0.5) { curEvtTagFlv_ = +1; // B0 tag } else { curEvtTagFlv_ = -1; // B0bar tag } // Calculate event quantities that depend only on the tagCat and tagFlv Double_t qD(0.); Double_t qDDo2(0.); if(flavTag_->getUsePerEvtMistag() && curEvtTagCat_!=0 ){ curEvtMistag_ = flavTag_->getEtaGen(sigFlavTagPdf_[curEvtTagCat_]); Double_t omega = flavTag_->getOmegaGen(curEvtMistag_); qD = curEvtTagFlv_*(1.0-2.0*omega); //qD = curEvtTagFlv_*(1-2*curEvtMistag_); }else{ curEvtMistag_ = 0.5; LauTagCatParamMap dilution_ = flavTag_->getDilution(); LauTagCatParamMap deltaDilution_ = flavTag_->getDeltaDilution(); qD = curEvtTagFlv_*dilution_[curEvtTagCat_].unblindValue(); qDDo2 = curEvtTagFlv_*0.5*deltaDilution_[curEvtTagCat_].unblindValue(); } // Generate the DP position Double_t m13Sq(0.0), m23Sq(0.0); kinematicsB0bar_->genFlatPhaseSpace(m13Sq, m23Sq); // Next, calculate the total A and Abar for the given DP position sigModelB0_->calcLikelihoodInfo(m13Sq, m23Sq); sigModelB0bar_->calcLikelihoodInfo(m13Sq, m23Sq); // Retrieve the amplitudes and efficiency from the dynamics const LauComplex& Abar = sigModelB0bar_->getEvtDPAmp(); const LauComplex& A = sigModelB0_->getEvtDPAmp(); Double_t eff = sigModelB0bar_->getEvtEff(); // Next calculate the DP terms Double_t aSqSum = A.abs2() + Abar.abs2(); Double_t aSqDif = A.abs2() - Abar.abs2(); LauComplex inter = Abar * A.conj() * phiMixComplex_; Double_t interTermIm = 2.0 * inter.im(); Double_t interTermRe = 2.0 * inter.re(); // Generate decay time const Double_t tMin = decayTimePdf->minAbscissa(); const Double_t tMax = decayTimePdf->maxAbscissa(); curEvtDecayTime_ = LauRandom::randomFun()->Rndm()*(tMax-tMin) + tMin; // Calculate all the decay time info decayTimePdf->calcLikelihoodInfo(curEvtDecayTime_,curEvtDecayTimeErr_); // ...and check that the calculation went ok, otherwise loop again if (decayTimePdf->state() != LauDecayTimePdf::Good) { std::cout<<"decayTimePdf state is bad"<getExpTerm(); Double_t dtCos = decayTimePdf->getCosTerm(); Double_t dtSin = decayTimePdf->getSinTerm(); Double_t dtCosh = decayTimePdf->getCoshTerm(); Double_t dtSinh = decayTimePdf->getSinhTerm(); //std::cout << dtCos << " " << dtSin << " " << dtCosh << " " << dtSinh << std::endl; // Combine all terms Double_t cosTerm = dtCos * qD * aSqDif; Double_t sinTerm = dtSin * qD * interTermIm; Double_t coshTerm = dtCosh * (1.0 + qDDo2) * aSqSum; Double_t sinhTerm = dtSinh * (1.0 + qDDo2) * interTermRe; //std::cout << "dtCos * qD * aSqDif (dtSin * interTermIm) " << dtCos << " " << qD << " " << aSqDif << " " << dtSin << " " << interTermIm << std::endl; if ( cpEigenValue_ == CPOdd ) { sinTerm *= -1.0; sinhTerm *= -1.0; } // ... to get the total and multiply by the efficiency Double_t ASq = coshTerm + cosTerm - sinTerm + sinhTerm; //std::cout<<"Cosh Cos Sin Sinh "<< coshTerm<< " " << cosTerm << " " << sinTerm << " " << sinhTerm << std::endl; //std::cout << "Total Amplitude : " << ASq << std::endl; //ASq /= decayTimePdf->getNormTerm(); ASq *= eff; //std::cout << "Total Amplitude Eff: " << ASq << std::endl; //Finally we throw the dice to see whether this event should be generated //We make a distinction between the likelihood of TM and SCF to tag the SCF events as such randNo = LauRandom::randomFun()->Rndm(); if (randNo <= ASq/aSqMaxSet_ ) { generatedEvent = kTRUE; nGenLoop_ = 0; if (ASq > aSqMaxVar_) {aSqMaxVar_ = ASq;} } else { nGenLoop_++; } } // end of while !generatedEvent loop } // end of if (embeddedData) else control } else { if ( embeddedData ) { embeddedData->getEmbeddedEvent(0); curEvtTagFlv_ = TMath::Nint(embeddedData->getValue("tagFlv")); curEvtDecayTimeErr_ = embeddedData->getValue(decayTimePdf->varErrName()); curEvtDecayTime_ = embeddedData->getValue(decayTimePdf->varName()); } } // Check whether we have generated the toy MC OK. if (nGenLoop_ >= iterationsMax_) { aSqMaxSet_ = 1.01 * aSqMaxVar_; genOK = kFALSE; std::cerr<<"WARNING in LauTimeDepFitModel::generateSignalEvent : Hit max iterations: setting aSqMaxSet_ to "< aSqMaxSet_) { aSqMaxSet_ = 1.01 * aSqMaxVar_; genOK = kFALSE; std::cerr<<"WARNING in LauTimeDepFitModel::generateSignalEvent : Found a larger ASq value: setting aSqMaxSet_ to "<updateKinematics(kinematicsB0bar_->getm13Sq(), kinematicsB0bar_->getm23Sq() ); this->generateExtraPdfValues(extraPdfs, embeddedData); } // Check for problems with the embedding if (embeddedData && (embeddedData->nEvents() == embeddedData->nUsedEvents())) { std::cerr<<"WARNING in LauTimeDepFitModel::generateSignalEvent : Source of embedded signal events used up, clearing the list of used events."<clearUsedList(); } return genOK; } void LauTimeDepFitModel::setupGenNtupleBranches() { // Setup the required ntuple branches this->addGenNtupleDoubleBranch("evtWeight"); this->addGenNtupleIntegerBranch("genSig"); this->addGenNtupleIntegerBranch("cpEigenvalue"); this->addGenNtupleIntegerBranch("tagFlv"); this->addGenNtupleIntegerBranch("tagCat"); if (this->useDP() == kTRUE) { // Let's add the decay time variables. if (signalDecayTimePdfs_.begin() != signalDecayTimePdfs_.end()) { LauDecayTimePdf* pdf = signalDecayTimePdfs_.begin()->second; this->addGenNtupleDoubleBranch(pdf->varName()); this->addGenNtupleDoubleBranch(pdf->varErrName()); } this->addGenNtupleDoubleBranch("m12"); this->addGenNtupleDoubleBranch("m23"); this->addGenNtupleDoubleBranch("m13"); this->addGenNtupleDoubleBranch("m12Sq"); this->addGenNtupleDoubleBranch("m23Sq"); this->addGenNtupleDoubleBranch("m13Sq"); this->addGenNtupleDoubleBranch("cosHel12"); this->addGenNtupleDoubleBranch("cosHel23"); this->addGenNtupleDoubleBranch("cosHel13"); if (kinematicsB0bar_->squareDP() && kinematicsB0_->squareDP()) { this->addGenNtupleDoubleBranch("mPrime"); this->addGenNtupleDoubleBranch("thPrime"); } // Can add the real and imaginary parts of the B0 and B0bar total // amplitudes seen in the generation (restrict this with a flag // that defaults to false) if ( storeGenAmpInfo_ ) { this->addGenNtupleDoubleBranch("reB0Amp"); this->addGenNtupleDoubleBranch("imB0Amp"); this->addGenNtupleDoubleBranch("reB0barAmp"); this->addGenNtupleDoubleBranch("imB0barAmp"); } } // Let's look at the extra variables for signal in one of the tagging categories if ( ! sigExtraPdf_.empty() ) { LauPdfList oneTagCatPdfList = sigExtraPdf_.begin()->second; for (LauPdfList::const_iterator pdf_iter = oneTagCatPdfList.begin(); pdf_iter != oneTagCatPdfList.end(); ++pdf_iter) { for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { this->addGenNtupleDoubleBranch( (*var_iter) ); } } } } } void LauTimeDepFitModel::setDPDtBranchValues() { // Store the decay time variables. if (signalDecayTimePdfs_.begin() != signalDecayTimePdfs_.end()) { LauDecayTimePdf* pdf = signalDecayTimePdfs_.begin()->second; this->setGenNtupleDoubleBranchValue(pdf->varName(),curEvtDecayTime_); this->setGenNtupleDoubleBranchValue(pdf->varErrName(),curEvtDecayTimeErr_); } // CONVENTION WARNING LauKinematics* kinematics(0); if (curEvtTagFlv_<0) { kinematics = kinematicsB0_; } else { kinematics = kinematicsB0bar_; } // Store all the DP information this->setGenNtupleDoubleBranchValue("m12", kinematics->getm12()); this->setGenNtupleDoubleBranchValue("m23", kinematics->getm23()); this->setGenNtupleDoubleBranchValue("m13", kinematics->getm13()); this->setGenNtupleDoubleBranchValue("m12Sq", kinematics->getm12Sq()); this->setGenNtupleDoubleBranchValue("m23Sq", kinematics->getm23Sq()); this->setGenNtupleDoubleBranchValue("m13Sq", kinematics->getm13Sq()); this->setGenNtupleDoubleBranchValue("cosHel12", kinematics->getc12()); this->setGenNtupleDoubleBranchValue("cosHel23", kinematics->getc23()); this->setGenNtupleDoubleBranchValue("cosHel13", kinematics->getc13()); if (kinematics->squareDP()) { this->setGenNtupleDoubleBranchValue("mPrime", kinematics->getmPrime()); this->setGenNtupleDoubleBranchValue("thPrime", kinematics->getThetaPrime()); } // Can add the real and imaginary parts of the B0 and B0bar total // amplitudes seen in the generation (restrict this with a flag // that defaults to false) if ( storeGenAmpInfo_ ) { if ( this->getGenNtupleIntegerBranchValue("genSig")==1 ) { LauComplex Abar = sigModelB0bar_->getEvtDPAmp(); LauComplex A = sigModelB0_->getEvtDPAmp(); this->setGenNtupleDoubleBranchValue("reB0Amp", A.re()); this->setGenNtupleDoubleBranchValue("imB0Amp", A.im()); this->setGenNtupleDoubleBranchValue("reB0barAmp", Abar.re()); this->setGenNtupleDoubleBranchValue("imB0barAmp", Abar.im()); } else { this->setGenNtupleDoubleBranchValue("reB0Amp", 0.0); this->setGenNtupleDoubleBranchValue("imB0Amp", 0.0); this->setGenNtupleDoubleBranchValue("reB0barAmp", 0.0); this->setGenNtupleDoubleBranchValue("imB0barAmp", 0.0); } } } void LauTimeDepFitModel::generateExtraPdfValues(LauPdfList* extraPdfs, LauEmbeddedData* embeddedData) { // CONVENTION WARNING LauKinematics* kinematics(0); if (curEvtTagFlv_<0) { kinematics = kinematicsB0_; } else { kinematics = kinematicsB0bar_; } // Generate from the extra PDFs if (extraPdfs) { for (LauPdfList::iterator pdf_iter = extraPdfs->begin(); pdf_iter != extraPdfs->end(); ++pdf_iter) { LauFitData genValues; if (embeddedData) { genValues = embeddedData->getValues( (*pdf_iter)->varNames() ); } else { genValues = (*pdf_iter)->generate(kinematics); } for ( LauFitData::const_iterator var_iter = genValues.begin(); var_iter != genValues.end(); ++var_iter ) { TString varName = var_iter->first; if ( varName != "m13Sq" && varName != "m23Sq" ) { Double_t value = var_iter->second; this->setGenNtupleDoubleBranchValue(varName,value); } } } } } void LauTimeDepFitModel::propagateParUpdates() { // Update the complex mixing phase if (useSinCos_) { phiMixComplex_.setRealPart(cosPhiMix_.unblindValue()); phiMixComplex_.setImagPart(-1.0*sinPhiMix_.unblindValue()); } else { phiMixComplex_.setRealPart(TMath::Cos(-1.0*phiMix_.unblindValue())); phiMixComplex_.setImagPart(TMath::Sin(-1.0*phiMix_.unblindValue())); } // Update the total normalisation for the signal likelihood if (this->useDP() == kTRUE) { this->updateCoeffs(); sigModelB0bar_->updateCoeffs(coeffsB0bar_); sigModelB0_->updateCoeffs(coeffsB0_); this->calcInterTermNorm(); } // Update the signal events from the background numbers if not doing an extended fit // And update the tagging category fractions this->updateSigEvents(); } void LauTimeDepFitModel::updateSigEvents() { // The background parameters will have been set from Minuit. // We need to update the signal events using these. if (!this->doEMLFit()) { Double_t nTotEvts = this->eventsPerExpt(); Double_t signalEvents = nTotEvts; // TODO loop over the background yields and subtract signalEvents_->range(-2.0*nTotEvts,2.0*nTotEvts); if ( ! signalEvents_->fixed() ) { signalEvents_->value(signalEvents); } } // tagging-category fractions for signal events flavTag_->setFirstTagCatFractions(); } void LauTimeDepFitModel::cacheInputFitVars() { // Fill the internal data trees of the signal and background models. // Note that we store the events of both charges in both the // negative and the positive models. It's only later, at the stage // when the likelihood is being calculated, that we separate them. LauFitDataTree* inputFitData = this->fitData(); evtCPEigenVals_.clear(); const Bool_t hasCPEV = ( (cpevVarName_ != "") && inputFitData->haveBranch( cpevVarName_ ) ); UInt_t nEvents = inputFitData->nEvents(); evtCPEigenVals_.reserve( nEvents ); LauFitData::const_iterator fitdata_iter; for (UInt_t iEvt = 0; iEvt < nEvents; iEvt++) { const LauFitData& dataValues = inputFitData->getData(iEvt); // if the CP-eigenvalue is in the data use those, otherwise use the default if ( hasCPEV ) { fitdata_iter = dataValues.find( cpevVarName_ ); const Int_t cpEV = static_cast( fitdata_iter->second ); if ( cpEV == 1 ) { cpEigenValue_ = CPEven; } else if ( cpEV == -1 ) { cpEigenValue_ = CPOdd; } else { std::cerr<<"WARNING in LauTimeDepFitModel::cacheInputFitVars : Unknown value: "<cacheInputFitVars(inputFitData); if (this->useDP() == kTRUE) { // DecayTime and SigmaDecayTime for (LauTagCatDtPdfMap::iterator dt_iter = signalDecayTimePdfs_.begin(); dt_iter != signalDecayTimePdfs_.end(); ++dt_iter) { (*dt_iter).second->cacheInfo(*inputFitData); } } // ...and then the extra PDFs for (LauTagCatPdfListMap::iterator pdf_iter = sigExtraPdf_.begin(); pdf_iter != sigExtraPdf_.end(); ++pdf_iter) { this->cacheInfo(pdf_iter->second, *inputFitData); } if (this->useDP() == kTRUE) { sigModelB0bar_->fillDataTree(*inputFitData); sigModelB0_->fillDataTree(*inputFitData); } } Double_t LauTimeDepFitModel::getTotEvtLikelihood(const UInt_t iEvt) { // Find out whether the tag-side B was a B0 or a B0bar. curEvtTagFlv_ = flavTag_->getEvtTagFlvVals(iEvt); // Also get the tagging category. curEvtTagCat_ = flavTag_->getEvtTagCatVals(iEvt); // Get the CP eigenvalue of the current event cpEigenValue_ = evtCPEigenVals_[iEvt]; // Get the DP and DecayTime likelihood for signal (TODO and eventually backgrounds) this->getEvtDPDtLikelihood(iEvt); // Get the flavour tagging likelihood from eta PDFs (per tagging category - TODO backgrounds to come later) this->getEvtFlavTagLikelihood(iEvt); // Get the combined extra PDFs likelihood for signal (TODO and eventually backgrounds) this->getEvtExtraLikelihoods(iEvt); // Construct the total likelihood for signal, qqbar and BBbar backgrounds Double_t sigLike = sigDPLike_ * sigFlavTagLike_ * sigExtraLike_; //std::cout << "DP like = " << sigDPLike_ << std::endl; //std::cout << "flav tag like = " << sigFlavTagLike_ << std::endl; //std::cout << "extra like = " << sigExtraLike_ << std::endl; Double_t signalEvents = signalEvents_->unblindValue(); if (this->useDP() == kFALSE) { signalEvents *= 0.5 * (1.0 + curEvtTagFlv_ * signalAsym_->unblindValue()); } // TODO better to store this info for each event LauTagCatParamMap& signalTagCatFrac = flavTag_->getSignalTagCatFrac(); const Double_t sigTagCatFrac = signalTagCatFrac[curEvtTagCat_].unblindValue(); //std::cout << "Signal tag cat frac = " << sigTagCatFrac << std::endl; // Construct the total event likelihood Double_t likelihood(sigLike*sigTagCatFrac); //std::cout << "Likelihoood = " << likelihood << std::endl; if ( ! signalEvents_->fixed() ) { likelihood *= signalEvents; } return likelihood; } Double_t LauTimeDepFitModel::getEventSum() const { Double_t eventSum(0.0); eventSum += signalEvents_->unblindValue(); return eventSum; } void LauTimeDepFitModel::getEvtDPDtLikelihood(const UInt_t iEvt) { // Function to return the signal and background likelihoods for the // Dalitz plot for the given event evtNo. sigDPLike_ = 1.0; //There's always a likelihood term for signal, so we better not zero it. if ( this->useDP() == kFALSE ) { return; } // Mistag probabilities. Defined as: omega = prob of the tagging B0 being reported as B0bar // Whether we want omega or omegaBar depends on q_tag, hence curEvtTagFlv_*... in the previous lines //Double_t misTagFrac = 0.5 * (1.0 - dilution_[curEvtTagCat_] - qDDo2); //Double_t misTagFracBar = 0.5 * (1.0 - dilution_[curEvtTagCat_] + qDDo2); // Calculate event quantities Double_t qD(0); Double_t qDDo2(0); if (flavTag_->getUsePerEvtMistag()){ //qDDo2 term accounted for automatically with per event information Double_t omega = flavTag_->getOmega(iEvt); qD = curEvtTagFlv_*(1.0-2.0*omega); } else { // TODO need to sort out references here LauTagCatParamMap dilution_ = flavTag_->getDilution(); LauTagCatParamMap deltaDilution_ = flavTag_->getDeltaDilution(); qD = curEvtTagFlv_*dilution_[curEvtTagCat_].unblindValue(); qDDo2 = curEvtTagFlv_*0.5*deltaDilution_[curEvtTagCat_].unblindValue(); } // Get the dynamics to calculate everything required for the likelihood calculation sigModelB0bar_->calcLikelihoodInfo(iEvt); sigModelB0_->calcLikelihoodInfo(iEvt); // Retrieve the amplitudes and efficiency from the dynamics const LauComplex& Abar = sigModelB0bar_->getEvtDPAmp(); const LauComplex& A = sigModelB0_->getEvtDPAmp(); Double_t eff = sigModelB0bar_->getEvtEff(); // Next calculate the DP terms Double_t aSqSum = A.abs2() + Abar.abs2(); Double_t aSqDif = A.abs2() - Abar.abs2(); LauComplex inter = Abar * A.conj() * phiMixComplex_; Double_t interTermIm = 2.0 * inter.im(); Double_t interTermRe = 2.0 * inter.re(); // First get all the decay time terms LauDecayTimePdf* decayTimePdf = signalDecayTimePdfs_[curEvtTagCat_]; decayTimePdf->calcLikelihoodInfo(iEvt); // First get all the decay time terms Double_t dtCos = decayTimePdf->getCosTerm(); Double_t dtSin = decayTimePdf->getSinTerm(); Double_t dtCosh = decayTimePdf->getCoshTerm(); Double_t dtSinh = decayTimePdf->getSinhTerm(); Double_t cosTerm = dtCos * qD * aSqDif; Double_t sinTerm = dtSin * qD * interTermIm; Double_t coshTerm = dtCosh * (1.0 + qDDo2) * aSqSum; Double_t sinhTerm = dtSinh * (1.0 + qDDo2) * interTermRe; if ( cpEigenValue_ == CPOdd ) { sinTerm *= -1.0; sinhTerm *= -1.0; } // ... to get the total and multiply by the efficiency Double_t ASq = coshTerm + cosTerm - sinTerm + sinhTerm; ASq *= eff; // Calculate the DP and time normalisation Double_t normTermIndep = sigModelB0bar_->getDPNorm() + sigModelB0_->getDPNorm(); Double_t normTermCosh(0.0); Double_t norm(0.0); if (decayTimePdf->getFuncType() == LauDecayTimePdf::ExpTrig){ normTermCosh = decayTimePdf->getNormTermExp(); norm = normTermIndep*normTermCosh; } if (decayTimePdf->getFuncType() == LauDecayTimePdf::ExpHypTrig){ normTermCosh = decayTimePdf->getNormTermCosh(); Double_t normTermDep = interTermReNorm_; Double_t normTermSinh = decayTimePdf->getNormTermSinh(); norm = normTermIndep*normTermCosh + normTermDep*normTermSinh; } // Calculate the normalised signal likelihood //std::cout << "ASq = " << ASq << std::endl; //std::cout << "norm = " << norm << std::endl; sigDPLike_ = ASq / norm; } void LauTimeDepFitModel::getEvtExtraLikelihoods(const UInt_t iEvt) { // Function to return the signal and background likelihoods for the // extra variables for the given event evtNo. sigExtraLike_ = 1.0; //There's always a likelihood term for signal, so we better not zero it. // First, those independent of the tagging of the event: // signal LauTagCatPdfListMap::iterator sig_iter = sigExtraPdf_.find(curEvtTagCat_); LauPdfList* pdfList = (sig_iter != sigExtraPdf_.end())? &(sig_iter->second) : 0; if (pdfList) { sigExtraLike_ = this->prodPdfValue( *pdfList, iEvt ); } } void LauTimeDepFitModel::getEvtFlavTagLikelihood(const UInt_t iEvt) { // Function to return the signal and background likelihoods for the // extra variables for the given event evtNo. sigFlavTagLike_ = 1.0; //There's always a likelihood term for signal, so we better not zero it. // First, those independent of the tagging of the event: // signal LauAbsPdf* pdf = sigFlavTagPdf_[curEvtTagCat_]; if (pdf) { pdf->calcLikelihoodInfo(iEvt); sigFlavTagLike_ = pdf->getLikelihood(); } // TODO Add in the background components too } void LauTimeDepFitModel::updateCoeffs() { coeffsB0bar_.clear(); coeffsB0_.clear(); coeffsB0bar_.reserve(nSigComp_); coeffsB0_.reserve(nSigComp_); for (UInt_t i = 0; i < nSigComp_; ++i) { coeffsB0bar_.push_back(coeffPars_[i]->antiparticleCoeff()); coeffsB0_.push_back(coeffPars_[i]->particleCoeff()); } } void LauTimeDepFitModel::checkMixingPhase() { Double_t phase = phiMix_.value(); Double_t genPhase = phiMix_.genValue(); // Check now whether the phase lies in the right range (-pi to pi). Bool_t withinRange(kFALSE); while (withinRange == kFALSE) { if (phase > -LauConstants::pi && phase < LauConstants::pi) { withinRange = kTRUE; } else { // Not within the specified range if (phase > LauConstants::pi) { phase -= LauConstants::twoPi; } else if (phase < -LauConstants::pi) { phase += LauConstants::twoPi; } } } // A further problem can occur when the generated phase is close to -pi or pi. // The phase can wrap over to the other end of the scale - // this leads to artificially large pulls so we wrap it back. Double_t diff = phase - genPhase; if (diff > LauConstants::pi) { phase -= LauConstants::twoPi; } else if (diff < -LauConstants::pi) { phase += LauConstants::twoPi; } // finally store the new value in the parameter // and update the pull phiMix_.value(phase); phiMix_.updatePull(); } void LauTimeDepFitModel::embedSignal(Int_t tagCat, const TString& fileName, const TString& treeName, Bool_t reuseEventsWithinEnsemble, Bool_t reuseEventsWithinExperiment) { if (signalTree_[tagCat]) { std::cerr<<"ERROR in LauTimeDepFitModel::embedSignal : Already embedding signal from file for tagging category "<findBranches(); if (!dataOK) { delete signalTree_[tagCat]; signalTree_[tagCat] = 0; std::cerr<<"ERROR in LauTimeDepFitModel::embedSignal : Problem creating data tree for embedding."<addSPlotNtupleIntegerBranch("iExpt"); this->addSPlotNtupleIntegerBranch("iEvtWithinExpt"); // Store the efficiency of the event (for inclusive BF calculations). if (this->storeDPEff()) { this->addSPlotNtupleDoubleBranch("efficiency"); } // Store the total event likelihood for each species. this->addSPlotNtupleDoubleBranch("sigTotalLike"); // Store the DP likelihoods if (this->useDP()) { this->addSPlotNtupleDoubleBranch("sigDPLike"); } // Store the likelihoods for each extra PDF const LauPdfList* pdfList( &(sigExtraPdf_.begin()->second) ); this->addSPlotNtupleBranches(pdfList, "sig"); } void LauTimeDepFitModel::addSPlotNtupleBranches(const LauPdfList* extraPdfs, const TString& prefix) { if (!extraPdfs) { return; } // Loop through each of the PDFs for (LauPdfList::const_iterator pdf_iter = extraPdfs->begin(); pdf_iter != extraPdfs->end(); ++pdf_iter) { // Count the number of input variables that are not // DP variables (used in the case where there is DP // dependence for e.g. MVA) UInt_t nVars(0); for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { ++nVars; } } if ( nVars == 1 ) { // If the PDF only has one variable then // simply add one branch for that variable TString varName = (*pdf_iter)->varName(); TString name(prefix); name += varName; name += "Like"; this->addSPlotNtupleDoubleBranch(name); } else if ( nVars == 2 ) { // If the PDF has two variables then we // need a branch for them both together and // branches for each TString allVars(""); for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { allVars += (*var_iter); TString name(prefix); name += (*var_iter); name += "Like"; this->addSPlotNtupleDoubleBranch(name); } TString name(prefix); name += allVars; name += "Like"; this->addSPlotNtupleDoubleBranch(name); } else { std::cerr<<"WARNING in LauTimeDepFitModel::addSPlotNtupleBranches : Can't yet deal with 3D PDFs."<begin(); pdf_iter != extraPdfs->end(); ++pdf_iter) { // calculate the likelihood for this event (*pdf_iter)->calcLikelihoodInfo(iEvt); extraLike = (*pdf_iter)->getLikelihood(); totalLike *= extraLike; // Count the number of input variables that are not // DP variables (used in the case where there is DP // dependence for e.g. MVA) UInt_t nVars(0); for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { ++nVars; } } if ( nVars == 1 ) { // If the PDF only has one variable then // simply store the value for that variable TString varName = (*pdf_iter)->varName(); TString name(prefix); name += varName; name += "Like"; this->setSPlotNtupleDoubleBranchValue(name, extraLike); } else if ( nVars == 2 ) { // If the PDF has two variables then we // store the value for them both together // and for each on their own TString allVars(""); for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { allVars += (*var_iter); TString name(prefix); name += (*var_iter); name += "Like"; Double_t indivLike = (*pdf_iter)->getLikelihood( (*var_iter) ); this->setSPlotNtupleDoubleBranchValue(name, indivLike); } TString name(prefix); name += allVars; name += "Like"; this->setSPlotNtupleDoubleBranchValue(name, extraLike); } else { std::cerr<<"WARNING in LauAllFitModel::setSPlotNtupleBranchValues : Can't yet deal with 3D PDFs."<useDP()) { nameSet.insert("DP"); } LauPdfList pdfList( (sigExtraPdf_.begin()->second) ); for (LauPdfList::const_iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) { // Loop over the variables involved in each PDF for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { // If they are not DP coordinates then add them if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { nameSet.insert( (*var_iter) ); } } } return nameSet; } LauSPlot::NumbMap LauTimeDepFitModel::freeSpeciesNames() const { LauSPlot::NumbMap numbMap; if (!signalEvents_->fixed() && this->doEMLFit()) { numbMap["sig"] = signalEvents_->genValue(); } return numbMap; } LauSPlot::NumbMap LauTimeDepFitModel::fixdSpeciesNames() const { LauSPlot::NumbMap numbMap; if (signalEvents_->fixed() && this->doEMLFit()) { numbMap["sig"] = signalEvents_->genValue(); } return numbMap; } LauSPlot::TwoDMap LauTimeDepFitModel::twodimPDFs() const { LauSPlot::TwoDMap twodimMap; const LauPdfList* pdfList = &(sigExtraPdf_.begin()->second); for (LauPdfList::const_iterator pdf_iter = pdfList->begin(); pdf_iter != pdfList->end(); ++pdf_iter) { // Count the number of input variables that are not DP variables UInt_t nVars(0); for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { ++nVars; } } if ( nVars == 2 ) { twodimMap.insert( std::make_pair( "sig", std::make_pair( (*pdf_iter)->varNames()[0], (*pdf_iter)->varNames()[1] ) ) ); } } return twodimMap; } void LauTimeDepFitModel::storePerEvtLlhds() { std::cout<<"INFO in LauTimeDepFitModel::storePerEvtLlhds : Storing per-event likelihood values..."<fitData(); // if we've not been using the DP model then we need to cache all // the info here so that we can get the efficiency from it if (!this->useDP() && this->storeDPEff()) { sigModelB0bar_->initialise(coeffsB0bar_); sigModelB0_->initialise(coeffsB0_); sigModelB0bar_->fillDataTree(*inputFitData); sigModelB0_->fillDataTree(*inputFitData); } UInt_t evtsPerExpt(this->eventsPerExpt()); LauIsobarDynamics* sigModel(sigModelB0bar_); for (UInt_t iEvt = 0; iEvt < evtsPerExpt; ++iEvt) { // Find out whether we have B0bar or B0 curEvtTagFlv_ = flavTag_->getEvtTagFlvVals(iEvt); curEvtTagCat_ = flavTag_->getEvtTagCatVals(iEvt); curEvtMistag_ = flavTag_->getOmega(iEvt); LauTagCatPdfListMap::iterator sig_iter = sigExtraPdf_.find(curEvtTagCat_); LauPdfList* sigPdfs = (sig_iter != sigExtraPdf_.end())? &(sig_iter->second) : 0; // the DP information this->getEvtDPDtLikelihood(iEvt); if (this->storeDPEff()) { if (!this->useDP()) { sigModel->calcLikelihoodInfo(iEvt); } this->setSPlotNtupleDoubleBranchValue("efficiency",sigModel->getEvtEff()); } if (this->useDP()) { sigTotalLike_ = sigDPLike_; this->setSPlotNtupleDoubleBranchValue("sigDPLike",sigDPLike_); } else { sigTotalLike_ = 1.0; } // the signal PDF values sigTotalLike_ *= this->setSPlotNtupleBranchValues(sigPdfs, "sig", iEvt); // the total likelihoods this->setSPlotNtupleDoubleBranchValue("sigTotalLike",sigTotalLike_); // fill the tree this->fillSPlotNtupleBranches(); } std::cout<<"INFO in LauTimeDepFitModel::storePerEvtLlhds : Finished storing per-event likelihood values."<validTagCat(tagCat)) { std::cerr<<"ERROR in LauTimeDepFitModel::setSignalFlavTagPdfs : Tagging category \""< #include #include #include #include #include "TFile.h" #include "TMinuit.h" #include "TRandom.h" #include "TSystem.h" #include "TVirtualFitter.h" #include "LauAbsBkgndDPModel.hh" #include "LauAbsCoeffSet.hh" #include "LauAbsPdf.hh" #include "LauAsymmCalc.hh" #include "LauComplex.hh" #include "LauConstants.hh" #include "LauDPPartialIntegralInfo.hh" #include "LauDaughters.hh" #include "LauDecayTimePdf.hh" #include "LauFitNtuple.hh" #include "LauGenNtuple.hh" #include "LauIsobarDynamics.hh" #include "LauKinematics.hh" #include "LauPrint.hh" #include "LauRandom.hh" #include "LauScfMap.hh" #include "LauTimeDepFlavModel.hh" ClassImp(LauTimeDepFlavModel) LauTimeDepFlavModel::LauTimeDepFlavModel(LauIsobarDynamics* modelB0bar, LauIsobarDynamics* modelB0, const Bool_t useUntaggedEvents, const TString& tagVarName, const TString& tagCatVarName) : LauAbsFitModel(), sigModelB0bar_(modelB0bar), sigModelB0_(modelB0), kinematicsB0bar_(modelB0bar ? modelB0bar->getKinematics() : 0), kinematicsB0_(modelB0 ? modelB0->getKinematics() : 0), useUntaggedEvents_(useUntaggedEvents), nSigComp_(0), nSigDPPar_(0), nDecayTimePar_(0), nExtraPdfPar_(0), nNormPar_(0), coeffsB0bar_(0), coeffsB0_(0), coeffPars_(0), fitFracB0bar_(0), fitFracB0_(0), fitFracAsymm_(0), acp_(0), meanEffB0bar_("meanEffB0bar",0.0,0.0,1.0), meanEffB0_("meanEffB0",0.0,0.0,1.0), DPRateB0bar_("DPRateB0bar",0.0,0.0,100.0), DPRateB0_("DPRateB0",0.0,0.0,100.0), signalEvents_(0), signalAsym_(0), signalTagCatFrac_(), tagVarName_(tagVarName), tagCatVarName_(tagCatVarName), cpevVarName_(""), validTagCats_(), curEvtTagFlv_(0), curEvtTagCat_(0), cpEigenValue_(CPEven), evtTagFlvVals_(0), evtTagCatVals_(0), evtCPEigenVals_(0), dilution_(), deltaDilution_(), //deltaM_("deltaM",LauConstants::deltaMd), deltaM_("deltaM",0.0), deltaGamma_("deltaGamma",0.0), tau_("tau",LauConstants::tauB0), phiMix_("phiMix", 2.0*LauConstants::beta, -LauConstants::threePi, LauConstants::threePi, kFALSE), sinPhiMix_("sinPhiMix", TMath::Sin(2.0*LauConstants::beta), -3.0, 3.0, kFALSE), cosPhiMix_("cosPhiMix", TMath::Cos(2.0*LauConstants::beta), -3.0, 3.0, kFALSE), useSinCos_(kFALSE), phiMixComplex_(TMath::Cos(-2.0*LauConstants::beta),TMath::Sin(-2.0*LauConstants::beta)), signalDecayTimePdfs_(), curEvtDecayTime_(0.0), curEvtDecayTimeErr_(0.0), sigExtraPdf_(), iterationsMax_(500000), nGenLoop_(0), ASq_(0.0), aSqMaxVar_(0.0), aSqMaxSet_(1.25), storeGenAmpInfo_(kFALSE), signalTree_(), reuseSignal_(kFALSE), sigDPLike_(0.0), sigExtraLike_(0.0), sigTotalLike_(0.0) { // Add the untagged category as a valid category this->addValidTagCat(0); // Set the fraction, average dilution and dilution difference for the untagged category this->setSignalTagCatPars(0, 1.0, 0.0, 0.0, kTRUE); } LauTimeDepFlavModel::~LauTimeDepFlavModel() { // TODO - need to delete the various embedded data structures here } void LauTimeDepFlavModel::setupBkgndVectors() { } void LauTimeDepFlavModel::setNSigEvents(LauParameter* nSigEvents) { if ( nSigEvents == 0 ) { std::cerr << "ERROR in LauTimeDepFlavModel::setNSigEvents : The LauParameter pointer is null." << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( signalEvents_ != 0 ) { std::cerr << "ERROR in LauTimeDepFlavModel::setNSigEvents : You are trying to overwrite the signal yield." << std::endl; return; } if ( signalAsym_ != 0 ) { std::cerr << "ERROR in LauTimeDepFlavModel::setNSigEvents : You are trying to overwrite the signal asymmetry." << std::endl; return; } signalEvents_ = nSigEvents; signalEvents_->name("signalEvents"); Double_t value = nSigEvents->value(); signalEvents_->range(-2.0*(TMath::Abs(value)+1.0),2.0*(TMath::Abs(value)+1.0)); signalAsym_ = new LauParameter("signalAsym",0.0,-1.0,1.0,kTRUE); } void LauTimeDepFlavModel::setNSigEvents(LauParameter* nSigEvents, LauParameter* sigAsym) { if ( nSigEvents == 0 ) { std::cerr << "ERROR in LauTimeDepFlavModel::setNSigEvents : The event LauParameter pointer is null." << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( sigAsym == 0 ) { std::cerr << "ERROR in LauTimeDepFlavModel::setNSigEvents : The asym LauParameter pointer is null." << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( signalEvents_ != 0 ) { std::cerr << "ERROR in LauTimeDepFlavModel::setNSigEvents : You are trying to overwrite the signal yield." << std::endl; return; } if ( signalAsym_ != 0 ) { std::cerr << "ERROR in LauTimeDepFlavModel::setNSigEvents : You are trying to overwrite the signal asymmetry." << std::endl; return; } signalEvents_ = nSigEvents; signalEvents_->name("signalEvents"); Double_t value = nSigEvents->value(); signalEvents_->range(-2.0*(TMath::Abs(value)+1.0), 2.0*(TMath::Abs(value)+1.0)); signalAsym_ = sigAsym; signalAsym_->name("signalAsym"); signalAsym_->range(-1.0,1.0); } -void LauTimeDepFlavModel::setNBkgndEvents(LauParameter* /*nBkgndEvents*/) +void LauTimeDepFlavModel::setNBkgndEvents(LauAbsRValue* /*nBkgndEvents*/) { std::cerr << "WARNING in LauTimeDepFlavModel::setNBkgndEvents : This model does not yet support backgrounds" << std::endl; } void LauTimeDepFlavModel::addValidTagCats(const std::vector& tagCats) { for (std::vector::const_iterator iter = tagCats.begin(); iter != tagCats.end(); ++iter) { this->addValidTagCat(*iter); } } void LauTimeDepFlavModel::addValidTagCat(Int_t tagCat) { validTagCats_.insert(tagCat); } void LauTimeDepFlavModel::setSignalTagCatPars(const Int_t tagCat, const Double_t tagCatFrac, const Double_t dilution, const Double_t deltaDilution, const Bool_t fixTCFrac) { if (!this->validTagCat(tagCat)) { std::cerr<<"ERROR in LauTimeDepFlavModel::setSignalTagCatPars : Tagging category \""<checkSignalTagCatFractions(); only when the user has //set them all up, in this->initialise(); } void LauTimeDepFlavModel::checkSignalTagCatFractions() { Double_t totalTaggedFrac(0.0); for (LauTagCatParamMap::const_iterator iter=signalTagCatFrac_.begin(); iter!=signalTagCatFrac_.end(); ++iter) { if (iter->first != 0) { const LauParameter& par = iter->second; totalTaggedFrac += par.value(); } } if ( ((totalTaggedFrac < (1.0-1.0e-8))&&!useUntaggedEvents_) || (totalTaggedFrac > (1.0+1.0e-8)) ) { std::cerr<<"WARNING in LauTimeDepFlavModel::checkSignalTagCatFractions : Tagging category fractions add up to "<second; Double_t newVal = par.value() / totalTaggedFrac; par.value(newVal); par.initValue(newVal); par.genValue(newVal); } } else if (useUntaggedEvents_) { Double_t tagCatFrac = 1.0 - totalTaggedFrac; TString tagCatFracName("signalTagCatFrac0"); signalTagCatFrac_[0].name(tagCatFracName); signalTagCatFrac_[0].range(0.0,1.0); signalTagCatFrac_[0].value(tagCatFrac); signalTagCatFrac_[0].initValue(tagCatFrac); signalTagCatFrac_[0].genValue(tagCatFrac); signalTagCatFrac_[0].fixed(kTRUE); TString dilutionName("dilution0"); dilution_[0].name(dilutionName); dilution_[0].range(0.0,1.0); dilution_[0].value(0.0); dilution_[0].initValue(0.0); dilution_[0].genValue(0.0); TString deltaDilutionName("deltaDilution0"); deltaDilution_[0].name(deltaDilutionName); deltaDilution_[0].range(-2.0,2.0); deltaDilution_[0].value(0.0); deltaDilution_[0].initValue(0.0); deltaDilution_[0].genValue(0.0); } for (LauTagCatParamMap::const_iterator iter=dilution_.begin(); iter!=dilution_.end(); ++iter) { std::cout<<"INFO in LauTimeDepFlavModel::checkSignalTagCatFractions : Setting dilution for tagging category "<<(*iter).first<<" to "<<(*iter).second<validTagCat(tagCat)) { std::cerr<<"ERROR in LauTimeDepFlavModel::setSignalDtPdf : Tagging category \""<validTagCat(tagCat)) { std::cerr<<"ERROR in LauTimeDepFlavModel::setSignalPdfs : Tagging category \""<updateCoeffs(); // Initialisation if (this->useDP() == kTRUE) { this->initialiseDPModels(); } if (!this->useDP() && sigExtraPdf_.empty()) { std::cerr<<"ERROR in LauTimeDepFlavModel::initialise : Signal model doesn't exist for any variable."<Exit(EXIT_FAILURE); } if (this->useDP() == kTRUE) { // Check that we have all the Dalitz-plot models if ((sigModelB0bar_ == 0) || (sigModelB0_ == 0)) { std::cerr<<"ERROR in LauTimeDepFlavModel::initialise : the pointer to one (particle or anti-particle) of the signal DP models is null."<Exit(EXIT_FAILURE); } } // Check here that the tagging category fractions add up to 1, otherwise "normalise". Also set up the untagged cat. // NB this has to be done early in the initialization as other methods access the tagCats map. this->checkSignalTagCatFractions(); // Clear the vectors of parameter information so we can start from scratch this->clearFitParVectors(); // Set the fit parameters for signal and background models this->setSignalDPParameters(); // Set the fit parameters for the decay time models this->setDecayTimeParameters(); // Set the fit parameters for the extra PDFs this->setExtraPdfParameters(); // Set the initial bg and signal events this->setFitNEvents(); // Check that we have the expected number of fit variables const LauParameterPList& fitVars = this->fitPars(); if (fitVars.size() != (nSigDPPar_ + nDecayTimePar_ + nExtraPdfPar_ + nNormPar_)) { std::cerr<<"ERROR in LauTimeDepFlavModel::initialise : Number of fit parameters not of expected size."<Exit(EXIT_FAILURE); } this->setExtraNtupleVars(); } void LauTimeDepFlavModel::recalculateNormalisation() { sigModelB0bar_->recalculateNormalisation(); sigModelB0_->recalculateNormalisation(); sigModelB0bar_->modifyDataTree(); sigModelB0_->modifyDataTree(); this->calcInterferenceTermIntegrals(); } void LauTimeDepFlavModel::initialiseDPModels() { if (sigModelB0bar_ == 0) { std::cerr<<"ERROR in LauTimeDepFlavModel::initialiseDPModels : B0bar signal DP model doesn't exist"<Exit(EXIT_FAILURE); } if (sigModelB0_ == 0) { std::cerr<<"ERROR in LauTimeDepFlavModel::initialiseDPModels : B0 signal DP model doesn't exist"<Exit(EXIT_FAILURE); } // Need to check that the number of components we have and that the dynamics has matches up //const UInt_t nAmpB0bar = sigModelB0bar_->getnAmp(); //const UInt_t nAmpB0 = sigModelB0_->getnAmp(); const UInt_t nAmpB0bar = sigModelB0bar_->getnTotAmp(); const UInt_t nAmpB0 = sigModelB0_->getnTotAmp(); if ( nAmpB0bar != nAmpB0 ) { std::cerr << "ERROR in LauTimeDepFlavModel::initialiseDPModels : Unequal number of signal DP components in the particle and anti-particle models: " << nAmpB0bar << " != " << nAmpB0 << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( nAmpB0bar != nSigComp_ ) { std::cerr << "ERROR in LauTimeDepFlavModel::initialiseDPModels : Number of signal DP components in the model (" << nAmpB0bar << ") not equal to number of coefficients supplied (" << nSigComp_ << ")." << std::endl; gSystem->Exit(EXIT_FAILURE); } std::cout<<"INFO in LauTimeDepFlavModel::initialiseDPModels : Initialising signal DP model"<initialise(coeffsB0bar_); sigModelB0_->initialise(coeffsB0_); fifjEffSum_.clear(); fifjEffSum_.resize(nSigComp_); for (UInt_t iAmp = 0; iAmp < nSigComp_; ++iAmp) { fifjEffSum_[iAmp].resize(nSigComp_); } // calculate the integrals of the A*Abar terms this->calcInterferenceTermIntegrals(); this->calcInterTermNorm(); } void LauTimeDepFlavModel::calcInterferenceTermIntegrals() { const std::vector& integralInfoListB0bar = sigModelB0bar_->getIntegralInfos(); const std::vector& integralInfoListB0 = sigModelB0_->getIntegralInfos(); // TODO should check (first time) that they match in terms of number of entries in the vectors and that each entry has the same number of points, ranges, weights etc. LauComplex A, Abar, fifjEffSumTerm; for (UInt_t iAmp = 0; iAmp < nSigComp_; ++iAmp) { for (UInt_t jAmp = 0; jAmp < nSigComp_; ++jAmp) { fifjEffSum_[iAmp][jAmp].zero(); } } const UInt_t nIntegralRegions = integralInfoListB0bar.size(); for ( UInt_t iRegion(0); iRegion < nIntegralRegions; ++iRegion ) { const LauDPPartialIntegralInfo* integralInfoB0bar = integralInfoListB0bar[iRegion]; const LauDPPartialIntegralInfo* integralInfoB0 = integralInfoListB0[iRegion]; const UInt_t nm13Points = integralInfoB0bar->getnm13Points(); const UInt_t nm23Points = integralInfoB0bar->getnm23Points(); for (UInt_t m13 = 0; m13 < nm13Points; ++m13) { for (UInt_t m23 = 0; m23 < nm23Points; ++m23) { const Double_t weight = integralInfoB0bar->getWeight(m13,m23); const Double_t eff = integralInfoB0bar->getEfficiency(m13,m23); const Double_t effWeight = eff*weight; for (UInt_t iAmp = 0; iAmp < nSigComp_; ++iAmp) { A = integralInfoB0->getAmplitude(m13, m23, iAmp); for (UInt_t jAmp = 0; jAmp < nSigComp_; ++jAmp) { Abar = integralInfoB0bar->getAmplitude(m13, m23, jAmp); fifjEffSumTerm = Abar*A.conj(); fifjEffSumTerm.rescale(effWeight); fifjEffSum_[iAmp][jAmp] += fifjEffSumTerm; } } } } } } void LauTimeDepFlavModel::calcInterTermNorm() { const std::vector fNormB0bar = sigModelB0bar_->getFNorm(); const std::vector fNormB0 = sigModelB0_->getFNorm(); LauComplex norm; for (UInt_t iAmp = 0; iAmp < nSigComp_; ++iAmp) { for (UInt_t jAmp = 0; jAmp < nSigComp_; ++jAmp) { LauComplex coeffTerm = coeffsB0bar_[jAmp]*coeffsB0_[iAmp].conj(); coeffTerm *= fifjEffSum_[iAmp][jAmp]; coeffTerm.rescale(fNormB0bar[jAmp] * fNormB0[iAmp]); norm += coeffTerm; } } norm *= phiMixComplex_; interTermReNorm_ = 2.0*norm.re(); interTermImNorm_ = 2.0*norm.im(); } void LauTimeDepFlavModel::setAmpCoeffSet(LauAbsCoeffSet* coeffSet) { // Is there a component called compName in the signal models? TString compName = coeffSet->name(); TString conjName = sigModelB0bar_->getConjResName(compName); //TODO this part needs work - it doesn't work for e.g. pi+ pi- K_S0, where you want the daughters to be in the same order but it is still conjugate! const LauDaughters* daughtersB0bar = sigModelB0bar_->getDaughters(); const LauDaughters* daughtersB0 = sigModelB0_->getDaughters(); const Bool_t conjugate = daughtersB0bar->isConjugate( daughtersB0 ); if ( ! sigModelB0bar_->hasResonance(compName) ) { if ( ! sigModelB0bar_->hasResonance(conjName) ) { std::cerr<<"ERROR in LauTimeDepFlavModel::setAmpCoeffSet : B0bar signal DP model doesn't contain component \""<name( compName ); } if ( conjugate ) { if ( ! sigModelB0_->hasResonance(conjName) ) { std::cerr<<"ERROR in LauTimeDepFlavModel::setAmpCoeffSet : B0 signal DP model doesn't contain component \""<hasResonance(compName) ) { std::cerr<<"ERROR in LauTimeDepFlavModel::setAmpCoeffSet : B0 signal DP model doesn't contain component \""<::const_iterator iter=coeffPars_.begin(); iter!=coeffPars_.end(); ++iter) { if ((*iter)->name() == compName) { std::cerr<<"ERROR in LauTimeDepFlavModel::setAmpCoeffSet : Have already set coefficients for \""<index(nSigComp_); coeffPars_.push_back(coeffSet); TString parName = coeffSet->baseName(); parName += "FitFracAsym"; fitFracAsymm_.push_back(LauParameter(parName, 0.0, -1.0, 1.0)); acp_.push_back(coeffSet->acp()); ++nSigComp_; std::cout<<"INFO in LauTimeDepFlavModel::setAmpCoeffSet : Added coefficients for component \""<acp(); LauAsymmCalc asymmCalc(fitFracB0bar_[i][i].value(), fitFracB0_[i][i].value()); Double_t asym = asymmCalc.getAsymmetry(); fitFracAsymm_[i].value(asym); if (initValues) { fitFracAsymm_[i].genValue(asym); fitFracAsymm_[i].initValue(asym); } } } void LauTimeDepFlavModel::setSignalDPParameters() { // Set the fit parameters for the signal model. nSigDPPar_ = 0; if ( ! this->useDP() ) { return; } std::cout << "INFO in LauTimeDepFlavModel::setSignalDPParameters : Setting the initial fit parameters for the signal DP model." << std::endl; // Place isobar coefficient parameters in vector of fit variables LauParameterPList& fitVars = this->fitPars(); for (UInt_t i = 0; i < nSigComp_; i++) { LauParameterPList pars = coeffPars_[i]->getParameters(); for (LauParameterPList::iterator iter = pars.begin(); iter != pars.end(); ++iter) { if ( !(*iter)->clone() ) { fitVars.push_back(*iter); ++nSigDPPar_; } } } // Obtain the resonance parameters and place them in the vector of fit variables and in a separate vector // Need to make sure that they are unique because some might appear in both DP models LauParameterPSet& resVars = this->resPars(); resVars.clear(); LauParameterPList& sigDPParsB0bar = sigModelB0bar_->getFloatingParameters(); LauParameterPList& sigDPParsB0 = sigModelB0_->getFloatingParameters(); for ( LauParameterPList::iterator iter = sigDPParsB0bar.begin(); iter != sigDPParsB0bar.end(); ++iter ) { if ( resVars.insert(*iter).second ) { fitVars.push_back(*iter); ++nSigDPPar_; } } for ( LauParameterPList::iterator iter = sigDPParsB0.begin(); iter != sigDPParsB0.end(); ++iter ) { if ( resVars.insert(*iter).second ) { fitVars.push_back(*iter); ++nSigDPPar_; } } } UInt_t LauTimeDepFlavModel::addParametersToFitList(LauTagCatDtPdfMap& theMap) { UInt_t counter(0); LauParameterPList& fitVars = this->fitPars(); // loop through the map for (LauTagCatDtPdfMap::iterator iter = theMap.begin(); iter != theMap.end(); ++iter) { // grab the pdf and then its parameters LauDecayTimePdf* thePdf = (*iter).second; // The first one is the tagging category LauAbsRValuePList& rvalues = thePdf->getParameters(); // loop through the parameters for (LauAbsRValuePList::iterator pars_iter = rvalues.begin(); pars_iter != rvalues.end(); ++pars_iter) { LauParameterPList params = (*pars_iter)->getPars(); for (LauParameterPList::iterator params_iter = params.begin(); params_iter != params.end(); ++params_iter) { // for each "original" parameter add it to the list of fit parameters and increment the counter if ( !(*params_iter)->clone() && ( !(*params_iter)->fixed() || (this->twoStageFit() && (*params_iter)->secondStage()) ) ) { fitVars.push_back(*params_iter); ++counter; } } } } return counter; } UInt_t LauTimeDepFlavModel::addParametersToFitList(LauTagCatPdfMap& theMap) { UInt_t counter(0); // loop through the map for (LauTagCatPdfMap::iterator iter = theMap.begin(); iter != theMap.end(); ++iter) { counter += this->addFitParameters(iter->second); // first is the tagging category } return counter; } void LauTimeDepFlavModel::setDecayTimeParameters() { nDecayTimePar_ = 0; // Loop over the Dt PDFs nDecayTimePar_ += this->addParametersToFitList(signalDecayTimePdfs_); LauParameterPList& fitVars = this->fitPars(); if (useSinCos_) { fitVars.push_back(&sinPhiMix_); fitVars.push_back(&cosPhiMix_); nDecayTimePar_ += 2; } else { fitVars.push_back(&phiMix_); ++nDecayTimePar_; } } void LauTimeDepFlavModel::setExtraPdfParameters() { // Include the parameters of the PDF for each tagging category in the fit // NB all of them are passed to the fit, even though some have been fixed through parameter.fixed(kTRUE) // With the new "cloned parameter" scheme only "original" parameters are passed to the fit. // Their clones are updated automatically when the originals are updated. nExtraPdfPar_ = 0; nExtraPdfPar_ += this->addParametersToFitList(sigExtraPdf_); } void LauTimeDepFlavModel::setFitNEvents() { nNormPar_ = 0; // Initialise the total number of events to be the sum of all the hypotheses Double_t nTotEvts = signalEvents_->value(); this->eventsPerExpt(TMath::FloorNint(nTotEvts)); LauParameterPList& fitVars = this->fitPars(); // if doing an extended ML fit add the signal fraction into the fit parameters if (this->doEMLFit()) { std::cout<<"INFO in LauTimeDepFlavModel::setFitNEvents : Initialising number of events for signal and background components..."<useDP() == kFALSE) { fitVars.push_back(signalAsym_); ++nNormPar_; } // tagging-category fractions for signal events for (LauTagCatParamMap::iterator iter = signalTagCatFrac_.begin(); iter != signalTagCatFrac_.end(); ++iter) { if (iter == signalTagCatFrac_.begin()) { continue; } LauParameter* par = &((*iter).second); fitVars.push_back(par); ++nNormPar_; } } void LauTimeDepFlavModel::setExtraNtupleVars() { // Set-up other parameters derived from the fit results, e.g. fit fractions. if (this->useDP() != kTRUE) { return; } // First clear the vectors so we start from scratch this->clearExtraVarVectors(); LauParameterList& extraVars = this->extraPars(); // Add the B0 and B0bar fit fractions for each signal component fitFracB0bar_ = sigModelB0bar_->getFitFractions(); if (fitFracB0bar_.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepFlavModel::setExtraNtupleVars : Initial Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } for (UInt_t i(0); igetFitFractions(); if (fitFracB0_.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepFlavModel::setExtraNtupleVars : Initial Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } for (UInt_t i(0); icalcAsymmetries(kTRUE); // Add the Fit Fraction asymmetry for each signal component for (UInt_t i = 0; i < nSigComp_; i++) { extraVars.push_back(fitFracAsymm_[i]); } // Add the calculated CP asymmetry for each signal component for (UInt_t i = 0; i < nSigComp_; i++) { extraVars.push_back(acp_[i]); } // Now add in the DP efficiency values Double_t initMeanEffB0bar = sigModelB0bar_->getMeanEff().initValue(); meanEffB0bar_.value(initMeanEffB0bar); meanEffB0bar_.initValue(initMeanEffB0bar); meanEffB0bar_.genValue(initMeanEffB0bar); extraVars.push_back(meanEffB0bar_); Double_t initMeanEffB0 = sigModelB0_->getMeanEff().initValue(); meanEffB0_.value(initMeanEffB0); meanEffB0_.initValue(initMeanEffB0); meanEffB0_.genValue(initMeanEffB0); extraVars.push_back(meanEffB0_); // Also add in the DP rates Double_t initDPRateB0bar = sigModelB0bar_->getDPRate().initValue(); DPRateB0bar_.value(initDPRateB0bar); DPRateB0bar_.initValue(initDPRateB0bar); DPRateB0bar_.genValue(initDPRateB0bar); extraVars.push_back(DPRateB0bar_); Double_t initDPRateB0 = sigModelB0_->getDPRate().initValue(); DPRateB0_.value(initDPRateB0); DPRateB0_.initValue(initDPRateB0); DPRateB0_.genValue(initDPRateB0); extraVars.push_back(DPRateB0_); } void LauTimeDepFlavModel::finaliseFitResults(const TString& tablePrefixName) { // Retrieve parameters from the fit results for calculations and toy generation // and eventually store these in output root ntuples/text files // Now take the fit parameters and update them as necessary // i.e. to make mag > 0.0, phase in the right range. // This function will also calculate any other values, such as the // fit fractions, using any errors provided by fitParErrors as appropriate. // Also obtain the pull values: (measured - generated)/(average error) if (this->useDP() == kTRUE) { for (UInt_t i = 0; i < nSigComp_; ++i) { // Check whether we have "a > 0.0", and phases in the right range coeffPars_[i]->finaliseValues(); } } // update the pulls on the event fractions and asymmetries if (this->doEMLFit()) { signalEvents_->updatePull(); } if (this->useDP() == kFALSE) { signalAsym_->updatePull(); } // Finalise the pulls on the decay time parameters for (LauTagCatDtPdfMap::iterator iter = signalDecayTimePdfs_.begin(); iter != signalDecayTimePdfs_.end(); ++iter) { LauDecayTimePdf* pdf = (*iter).second; pdf->updatePulls(); } if (useSinCos_) { cosPhiMix_.updatePull(); sinPhiMix_.updatePull(); } else { this->checkMixingPhase(); } // Update the pulls on all the extra PDFs' parameters for (LauTagCatPdfMap::iterator iter = sigExtraPdf_.begin(); iter != sigExtraPdf_.end(); ++iter) { this->updateFitParameters(iter->second); } // Tagging-category fractions for signal and background events Double_t firstCatFrac(1.0); Int_t firstCat(0); for (LauTagCatParamMap::iterator iter = signalTagCatFrac_.begin(); iter != signalTagCatFrac_.end(); ++iter) { if (iter == signalTagCatFrac_.begin()) { firstCat = iter->first; continue; } LauParameter& par = (*iter).second; firstCatFrac -= par.value(); // update the parameter pull par.updatePull(); } signalTagCatFrac_[firstCat].value(firstCatFrac); signalTagCatFrac_[firstCat].updatePull(); // Fill the fit results to the ntuple // update the coefficients and then calculate the fit fractions and ACP's if (this->useDP() == kTRUE) { this->updateCoeffs(); sigModelB0bar_->updateCoeffs(coeffsB0bar_); sigModelB0bar_->calcExtraInfo(); sigModelB0_->updateCoeffs(coeffsB0_); sigModelB0_->calcExtraInfo(); LauParArray fitFracB0bar = sigModelB0bar_->getFitFractions(); if (fitFracB0bar.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepFlavModel::finaliseFitResults : Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } LauParArray fitFracB0 = sigModelB0_->getFitFractions(); if (fitFracB0.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepFlavModel::finaliseFitResults : Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } for (UInt_t i(0); igetMeanEff().value()); meanEffB0_.value(sigModelB0_->getMeanEff().value()); DPRateB0bar_.value(sigModelB0bar_->getDPRate().value()); DPRateB0_.value(sigModelB0_->getDPRate().value()); this->calcAsymmetries(); // Then store the final fit parameters, and any extra parameters for // the signal model (e.g. fit fractions, FF asymmetries, ACPs, mean efficiency and DP rate) this->clearExtraVarVectors(); LauParameterList& extraVars = this->extraPars(); for (UInt_t i(0); iprintFitFractions(std::cout); this->printAsymmetries(std::cout); } const LauParameterPList& fitVars = this->fitPars(); const LauParameterList& extraVars = this->extraPars(); LauFitNtuple* ntuple = this->fitNtuple(); ntuple->storeParsAndErrors(fitVars, extraVars); // find out the correlation matrix for the parameters ntuple->storeCorrMatrix(this->iExpt(), this->fitStatus(), this->covarianceMatrix()); // Fill the data into ntuple ntuple->updateFitNtuple(); // Print out the partial fit fractions, phases and the // averaged efficiency, reweighted by the dynamics (and anything else) if (this->writeLatexTable()) { TString sigOutFileName(tablePrefixName); sigOutFileName += "_"; sigOutFileName += this->iExpt(); sigOutFileName += "Expt.tex"; this->writeOutTable(sigOutFileName); } } void LauTimeDepFlavModel::printFitFractions(std::ostream& output) { // Print out Fit Fractions, total DP rate and mean efficiency // First for the B0bar events for (UInt_t i = 0; i < nSigComp_; i++) { const TString compName(coeffPars_[i]->name()); output<<"B0bar FitFraction for component "<useDP() == kTRUE) { // print the fit coefficients in one table coeffPars_.front()->printTableHeading(fout); for (UInt_t i = 0; i < nSigComp_; i++) { coeffPars_[i]->printTableRow(fout); } fout<<"\\hline"<name(); resName = resName.ReplaceAll("_", "\\_"); fout< =$ & $"; print.printFormat(fout, meanEffB0bar_.value()); fout << "$ & $"; print.printFormat(fout, meanEffB0_.value()); fout << "$ & & \\\\" << std::endl; if (useSinCos_) { fout << "$\\sinPhiMix =$ & $"; print.printFormat(fout, sinPhiMix_.value()); fout << " \\pm "; print.printFormat(fout, sinPhiMix_.error()); fout << "$ & & & & & & & \\\\" << std::endl; fout << "$\\cosPhiMix =$ & $"; print.printFormat(fout, cosPhiMix_.value()); fout << " \\pm "; print.printFormat(fout, cosPhiMix_.error()); fout << "$ & & & & & & & \\\\" << std::endl; } else { fout << "$\\phiMix =$ & $"; print.printFormat(fout, phiMix_.value()); fout << " \\pm "; print.printFormat(fout, phiMix_.error()); fout << "$ & & & & & & & \\\\" << std::endl; } fout << "\\hline \n\\end{tabular}" << std::endl; } if (!sigExtraPdf_.empty()) { fout<<"\\begin{tabular}{|l|c|}"<printFitParameters(iter->second, fout); } fout<<"\\hline \n\\end{tabular}"<updateSigEvents(); // Check whether we want to have randomised initial fit parameters for the signal model if (this->useRandomInitFitPars() == kTRUE) { this->randomiseInitFitPars(); } } void LauTimeDepFlavModel::randomiseInitFitPars() { // Only randomise those parameters that are not fixed! std::cout<<"INFO in LauTimeDepFlavModel::randomiseInitFitPars : Randomising the initial values of the coefficients of the DP components (and phiMix)..."<randomiseInitValues(); } phiMix_.randomiseValue(-LauConstants::pi, LauConstants::pi); if (useSinCos_) { sinPhiMix_.initValue(TMath::Sin(phiMix_.initValue())); cosPhiMix_.initValue(TMath::Cos(phiMix_.initValue())); } } LauTimeDepFlavModel::LauGenInfo LauTimeDepFlavModel::eventsToGenerate() { // Determine the number of events to generate for each hypothesis // If we're smearing then smear each one individually // NB this individual smearing has to be done individually per tagging category as well LauGenInfo nEvtsGen; LauTagCatGenInfo eventsB0, eventsB0bar; // Signal // If we're including the DP and decay time we can't decide on the tag // yet, since it depends on the whole DP+dt PDF, however, if // we're not then we need to decide. Double_t evtWeight(1.0); Double_t nEvts = signalEvents_->genValue(); if ( nEvts < 0.0 ) { evtWeight = -1.0; nEvts = TMath::Abs( nEvts ); } Double_t sigAsym(0.0); if (this->useDP() == kFALSE) { sigAsym = signalAsym_->genValue(); for (LauTagCatParamMap::const_iterator iter = signalTagCatFrac_.begin(); iter != signalTagCatFrac_.end(); ++iter) { const LauParameter& par = iter->second; Double_t eventsbyTagCat = par.value() * nEvts; Double_t eventsB0byTagCat = TMath::Nint(eventsbyTagCat/2.0 * (1.0 - sigAsym)); Double_t eventsB0barbyTagCat = TMath::Nint(eventsbyTagCat/2.0 * (1.0 + sigAsym)); if (this->doPoissonSmearing()) { eventsB0byTagCat = LauRandom::randomFun()->Poisson(eventsB0byTagCat); eventsB0barbyTagCat = LauRandom::randomFun()->Poisson(eventsB0barbyTagCat); } eventsB0[iter->first] = std::make_pair( TMath::Nint(eventsB0byTagCat), evtWeight ); eventsB0bar[iter->first] = std::make_pair( TMath::Nint(eventsB0barbyTagCat), evtWeight ); } nEvtsGen[std::make_pair("signal",-1)] = eventsB0; nEvtsGen[std::make_pair("signal",+1)] = eventsB0bar; } else { Double_t rateB0bar = sigModelB0bar_->getDPRate().value(); Double_t rateB0 = sigModelB0_->getDPRate().value(); if ( rateB0bar+rateB0 > 1e-30) { sigAsym = (rateB0bar-rateB0)/(rateB0bar+rateB0); } for (LauTagCatParamMap::const_iterator iter = signalTagCatFrac_.begin(); iter != signalTagCatFrac_.end(); ++iter) { const LauParameter& par = iter->second; Double_t eventsbyTagCat = par.value() * nEvts; if (this->doPoissonSmearing()) { eventsbyTagCat = LauRandom::randomFun()->Poisson(eventsbyTagCat); } eventsB0[iter->first] = std::make_pair( TMath::Nint(eventsbyTagCat), evtWeight ); } nEvtsGen[std::make_pair("signal",0)] = eventsB0; // generate signal event, decide tag later. } std::cout<<"INFO in LauTimeDepFlavModel::eventsToGenerate : Generating toy MC with:"<setGenNtupleIntegerBranchValue("genSig",1); // All the generate*Event() methods have to fill in curEvtDecayTime_ and curEvtDecayTimeErr_ // In addition, generateSignalEvent has to decide on the tag and fill in curEvtTagFlv_ genOK = this->generateSignalEvent(); } else { genOK = kFALSE; } if (!genOK) { // If there was a problem with the generation then break out and return. // The problem model will have adjusted itself so that all should be OK next time. break; } if (this->useDP() == kTRUE) { this->setDPDtBranchValues(); // store DP, decay time and tagging variables in the ntuple } // Store the event's tag and tagging category this->setGenNtupleIntegerBranchValue("cpEigenvalue", cpEigenValue_); this->setGenNtupleIntegerBranchValue("tagCat",curEvtTagCat_); this->setGenNtupleIntegerBranchValue("tagFlv",curEvtTagFlv_); // Store the event number (within this experiment) // and then increment it this->setGenNtupleIntegerBranchValue("iEvtWithinExpt",evtNum); ++evtNum; // Write the values into the tree this->fillGenNtupleBranches(); // Print an occasional progress message if (iEvt%1000 == 0) {std::cout<<"INFO in LauTimeDepFlavModel::genExpt : Generated event number "<useDP() && genOK) { sigModelB0bar_->checkToyMC(kTRUE); sigModelB0_->checkToyMC(kTRUE); std::cout<<"aSqMaxSet = "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } LauParArray fitFracB0 = sigModelB0_->getFitFractions(); if (fitFracB0.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepFlavModel::generate : Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } for (UInt_t i(0); igetMeanEff().value()); meanEffB0_.value(sigModelB0_->getMeanEff().value()); DPRateB0bar_.value(sigModelB0bar_->getDPRate().value()); DPRateB0_.value(sigModelB0_->getDPRate().value()); } } // If we're reusing embedded events or if the generation is being // reset then clear the lists of used events //if (!signalTree_.empty() && (reuseSignal_ || !genOK)) { if (reuseSignal_ || !genOK) { for(LauTagCatEmbDataMap::const_iterator iter = signalTree_.begin(); iter != signalTree_.end(); ++iter) { (iter->second)->clearUsedList(); } } return genOK; } Bool_t LauTimeDepFlavModel::generateSignalEvent() { // Generate signal event, including SCF if necessary. // DP:DecayTime generation follows. // If it's ok, we then generate mES, DeltaE, Fisher/NN... Bool_t genOK(kTRUE); Bool_t generatedEvent(kFALSE); Bool_t doSquareDP = kinematicsB0bar_->squareDP(); doSquareDP &= kinematicsB0_->squareDP(); LauKinematics* kinematics(kinematicsB0bar_); // find the right decay time PDF for the current tagging category LauTagCatDtPdfMap::const_iterator dt_iter = signalDecayTimePdfs_.find(curEvtTagCat_); LauDecayTimePdf* decayTimePdf = (dt_iter != signalDecayTimePdfs_.end()) ? dt_iter->second : 0; // find the right embedded data for the current tagging category LauTagCatEmbDataMap::const_iterator emb_iter = signalTree_.find(curEvtTagCat_); LauEmbeddedData* embeddedData = (emb_iter != signalTree_.end()) ? emb_iter->second : 0; // find the right extra PDFs for the current tagging category LauTagCatPdfMap::iterator extra_iter = sigExtraPdf_.find(curEvtTagCat_); LauPdfList* extraPdfs = (extra_iter != sigExtraPdf_.end()) ? &(extra_iter->second) : 0; if (this->useDP()) { if (embeddedData) { embeddedData->getEmbeddedEvent(kinematics); curEvtTagFlv_ = TMath::Nint(embeddedData->getValue("tagFlv")); curEvtDecayTimeErr_ = embeddedData->getValue(decayTimePdf->varErrName()); curEvtDecayTime_ = embeddedData->getValue(decayTimePdf->varName()); if (embeddedData->haveBranch("mcMatch")) { Int_t match = TMath::Nint(embeddedData->getValue("mcMatch")); if (match) { this->setGenNtupleIntegerBranchValue("genTMSig",1); this->setGenNtupleIntegerBranchValue("genSCFSig",0); } else { this->setGenNtupleIntegerBranchValue("genTMSig",0); this->setGenNtupleIntegerBranchValue("genSCFSig",1); } } } else { nGenLoop_ = 0; // generate the decay time error (NB the kTRUE forces the generation of a new value) curEvtDecayTimeErr_ = decayTimePdf->generateError(kTRUE); while (generatedEvent == kFALSE && nGenLoop_ < iterationsMax_) { // Calculate the unnormalised truth-matched signal likelihood // First let define the tag flavour Double_t randNo = LauRandom::randomFun()->Rndm(); if (randNo < 0.5) { curEvtTagFlv_ = +1; // B0 tag } else { curEvtTagFlv_ = -1; // B0bar tag } // Calculate event quantities that depend only on the tagCat and tagFlv Double_t qD = curEvtTagFlv_*dilution_[curEvtTagCat_].unblindValue(); Double_t qDDo2 = curEvtTagFlv_*0.5*deltaDilution_[curEvtTagCat_].unblindValue(); // Generate the DP position Double_t m13Sq(0.0), m23Sq(0.0); kinematicsB0bar_->genFlatPhaseSpace(m13Sq, m23Sq); // Next, calculate the total A and Abar for the given DP position sigModelB0_->calcLikelihoodInfo(m13Sq, m23Sq); sigModelB0bar_->calcLikelihoodInfo(m13Sq, m23Sq); // Retrieve the amplitudes and efficiency from the dynamics const LauComplex& Abar = sigModelB0bar_->getEvtDPAmp(); const LauComplex& A = sigModelB0_->getEvtDPAmp(); Double_t eff = sigModelB0bar_->getEvtEff(); // Next calculate the DP terms Double_t aSqSum = A.abs2() + Abar.abs2(); Double_t aSqDif = A.abs2() - Abar.abs2(); LauComplex inter = Abar * A.conj() * phiMixComplex_; Double_t interTermIm = 2.0 * inter.im(); Double_t interTermRe = 2.0 * inter.re(); // Generate decay time const Double_t tMin = decayTimePdf->minAbscissa(); const Double_t tMax = decayTimePdf->maxAbscissa(); curEvtDecayTime_ = LauRandom::randomFun()->Rndm()*(tMax-tMin) + tMin; // Calculate all the decay time info decayTimePdf->calcLikelihoodInfo(curEvtDecayTime_, curEvtDecayTimeErr_); // ...and check that the calculation went ok, otherwise loop again if (decayTimePdf->state() != LauDecayTimePdf::Good) { ++nGenLoop_; continue; } // First get all the decay time terms //Double_t dtExp = decayTimePdf->getExpTerm(); Double_t dtCos = decayTimePdf->getCosTerm(); Double_t dtSin = decayTimePdf->getSinTerm(); Double_t dtCosh = decayTimePdf->getCoshTerm(); Double_t dtSinh = decayTimePdf->getSinhTerm(); // Combine all terms Double_t cosTerm = dtCos * qD * aSqDif; Double_t sinTerm = dtSin * qD * interTermIm; Double_t coshTerm = dtCosh * (1.0 + qDDo2) * aSqSum; Double_t sinhTerm = dtSinh * (1.0 + qDDo2) * interTermRe; if ( cpEigenValue_ == CPOdd ) { sinTerm *= -1.0; sinhTerm *= -1.0; } // ... to get the total and multiply by the efficiency Double_t ASq = coshTerm + cosTerm - sinTerm + sinhTerm; //ASq /= decayTimePdf->getNormTerm(); ASq *= eff; //Finally we throw the dice to see whether this event should be generated //We make a distinction between the likelihood of TM and SCF to tag the SCF events as such randNo = LauRandom::randomFun()->Rndm(); if (randNo <= ASq/aSqMaxSet_ ) { generatedEvent = kTRUE; nGenLoop_ = 0; if (ASq > aSqMaxVar_) {aSqMaxVar_ = ASq;} } else { nGenLoop_++; } } // end of while !generatedEvent loop } // end of if (embeddedData) else control } else { if ( embeddedData ) { embeddedData->getEmbeddedEvent(0); curEvtTagFlv_ = TMath::Nint(embeddedData->getValue("tagFlv")); curEvtDecayTimeErr_ = embeddedData->getValue(decayTimePdf->varErrName()); curEvtDecayTime_ = embeddedData->getValue(decayTimePdf->varName()); } } // Check whether we have generated the toy MC OK. if (nGenLoop_ >= iterationsMax_) { aSqMaxSet_ = 1.01 * aSqMaxVar_; genOK = kFALSE; std::cerr<<"WARNING in LauTimeDepFlavModel::generateSignalEvent : Hit max iterations: setting aSqMaxSet_ to "< aSqMaxSet_) { aSqMaxSet_ = 1.01 * aSqMaxVar_; genOK = kFALSE; std::cerr<<"WARNING in LauTimeDepFlavModel::generateSignalEvent : Found a larger ASq value: setting aSqMaxSet_ to "<updateKinematics(kinematicsB0bar_->getm13Sq(), kinematicsB0bar_->getm23Sq() ); this->generateExtraPdfValues(extraPdfs, embeddedData); } // Check for problems with the embedding if (embeddedData && (embeddedData->nEvents() == embeddedData->nUsedEvents())) { std::cerr<<"WARNING in LauTimeDepFlavModel::generateSignalEvent : Source of embedded signal events used up, clearing the list of used events."<clearUsedList(); } return genOK; } void LauTimeDepFlavModel::setupGenNtupleBranches() { // Setup the required ntuple branches this->addGenNtupleDoubleBranch("evtWeight"); this->addGenNtupleIntegerBranch("genSig"); this->addGenNtupleIntegerBranch("cpEigenvalue"); this->addGenNtupleIntegerBranch("tagFlv"); this->addGenNtupleIntegerBranch("tagCat"); if (this->useDP() == kTRUE) { // Let's add the decay time variables. if (signalDecayTimePdfs_.begin() != signalDecayTimePdfs_.end()) { LauDecayTimePdf* pdf = signalDecayTimePdfs_.begin()->second; this->addGenNtupleDoubleBranch(pdf->varName()); this->addGenNtupleDoubleBranch(pdf->varErrName()); } this->addGenNtupleDoubleBranch("m12"); this->addGenNtupleDoubleBranch("m23"); this->addGenNtupleDoubleBranch("m13"); this->addGenNtupleDoubleBranch("m12Sq"); this->addGenNtupleDoubleBranch("m23Sq"); this->addGenNtupleDoubleBranch("m13Sq"); this->addGenNtupleDoubleBranch("cosHel12"); this->addGenNtupleDoubleBranch("cosHel23"); this->addGenNtupleDoubleBranch("cosHel13"); if (kinematicsB0bar_->squareDP() && kinematicsB0_->squareDP()) { this->addGenNtupleDoubleBranch("mPrime"); this->addGenNtupleDoubleBranch("thPrime"); } // Can add the real and imaginary parts of the B0 and B0bar total // amplitudes seen in the generation (restrict this with a flag // that defaults to false) if ( storeGenAmpInfo_ ) { this->addGenNtupleDoubleBranch("reB0Amp"); this->addGenNtupleDoubleBranch("imB0Amp"); this->addGenNtupleDoubleBranch("reB0barAmp"); this->addGenNtupleDoubleBranch("imB0barAmp"); } } // Let's look at the extra variables for signal in one of the tagging categories if ( ! sigExtraPdf_.empty() ) { LauPdfList oneTagCatPdfList = sigExtraPdf_.begin()->second; for (LauPdfList::const_iterator pdf_iter = oneTagCatPdfList.begin(); pdf_iter != oneTagCatPdfList.end(); ++pdf_iter) { for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { this->addGenNtupleDoubleBranch( (*var_iter) ); } } } } } void LauTimeDepFlavModel::setDPDtBranchValues() { // Store the decay time variables. if (signalDecayTimePdfs_.begin() != signalDecayTimePdfs_.end()) { LauDecayTimePdf* pdf = signalDecayTimePdfs_.begin()->second; this->setGenNtupleDoubleBranchValue(pdf->varName(),curEvtDecayTime_); this->setGenNtupleDoubleBranchValue(pdf->varErrName(),curEvtDecayTimeErr_); } LauKinematics* kinematics(0); if (curEvtTagFlv_<0) { kinematics = kinematicsB0_; } else { kinematics = kinematicsB0bar_; } // Store all the DP information this->setGenNtupleDoubleBranchValue("m12", kinematics->getm12()); this->setGenNtupleDoubleBranchValue("m23", kinematics->getm23()); this->setGenNtupleDoubleBranchValue("m13", kinematics->getm13()); this->setGenNtupleDoubleBranchValue("m12Sq", kinematics->getm12Sq()); this->setGenNtupleDoubleBranchValue("m23Sq", kinematics->getm23Sq()); this->setGenNtupleDoubleBranchValue("m13Sq", kinematics->getm13Sq()); this->setGenNtupleDoubleBranchValue("cosHel12", kinematics->getc12()); this->setGenNtupleDoubleBranchValue("cosHel23", kinematics->getc23()); this->setGenNtupleDoubleBranchValue("cosHel13", kinematics->getc13()); if (kinematics->squareDP()) { this->setGenNtupleDoubleBranchValue("mPrime", kinematics->getmPrime()); this->setGenNtupleDoubleBranchValue("thPrime", kinematics->getThetaPrime()); } // Can add the real and imaginary parts of the B0 and B0bar total // amplitudes seen in the generation (restrict this with a flag // that defaults to false) if ( storeGenAmpInfo_ ) { if ( this->getGenNtupleIntegerBranchValue("genSig")==1 ) { LauComplex Abar = sigModelB0bar_->getEvtDPAmp(); LauComplex A = sigModelB0_->getEvtDPAmp(); this->setGenNtupleDoubleBranchValue("reB0Amp", A.re()); this->setGenNtupleDoubleBranchValue("imB0Amp", A.im()); this->setGenNtupleDoubleBranchValue("reB0barAmp", Abar.re()); this->setGenNtupleDoubleBranchValue("imB0barAmp", Abar.im()); } else { this->setGenNtupleDoubleBranchValue("reB0Amp", 0.0); this->setGenNtupleDoubleBranchValue("imB0Amp", 0.0); this->setGenNtupleDoubleBranchValue("reB0barAmp", 0.0); this->setGenNtupleDoubleBranchValue("imB0barAmp", 0.0); } } } void LauTimeDepFlavModel::generateExtraPdfValues(LauPdfList* extraPdfs, LauEmbeddedData* embeddedData) { LauKinematics* kinematics(0); if (curEvtTagFlv_<0) { kinematics = kinematicsB0_; } else { kinematics = kinematicsB0bar_; } // Generate from the extra PDFs if (extraPdfs) { for (LauPdfList::iterator pdf_iter = extraPdfs->begin(); pdf_iter != extraPdfs->end(); ++pdf_iter) { LauFitData genValues; if (embeddedData) { genValues = embeddedData->getValues( (*pdf_iter)->varNames() ); } else { genValues = (*pdf_iter)->generate(kinematics); } for ( LauFitData::const_iterator var_iter = genValues.begin(); var_iter != genValues.end(); ++var_iter ) { TString varName = var_iter->first; if ( varName != "m13Sq" && varName != "m23Sq" ) { Double_t value = var_iter->second; this->setGenNtupleDoubleBranchValue(varName,value); } } } } } void LauTimeDepFlavModel::propagateParUpdates() { // Update the complex mixing phase if (useSinCos_) { phiMixComplex_.setRealPart(cosPhiMix_.unblindValue()); phiMixComplex_.setImagPart(-1.0*sinPhiMix_.unblindValue()); } else { phiMixComplex_.setRealPart(TMath::Cos(-1.0*phiMix_.unblindValue())); phiMixComplex_.setImagPart(TMath::Sin(-1.0*phiMix_.unblindValue())); } // Update the total normalisation for the signal likelihood if (this->useDP() == kTRUE) { this->updateCoeffs(); sigModelB0bar_->updateCoeffs(coeffsB0bar_); sigModelB0_->updateCoeffs(coeffsB0_); this->calcInterTermNorm(); } // Update the signal events from the background numbers if not doing an extended fit if (!this->doEMLFit()) { this->updateSigEvents(); } } void LauTimeDepFlavModel::updateSigEvents() { // The background parameters will have been set from Minuit. // We need to update the signal events using these. Double_t nTotEvts = this->eventsPerExpt(); Double_t signalEvents = nTotEvts; // tagging-category fractions for signal events this->setFirstTagCatFrac(signalTagCatFrac_); signalEvents_->range(-2.0*nTotEvts,2.0*nTotEvts); if ( ! signalEvents_->fixed() ) { signalEvents_->value(signalEvents); } } void LauTimeDepFlavModel::setFirstTagCatFrac(LauTagCatParamMap& theMap) { Double_t firstCatFrac = 1.0; Int_t firstCat(0); for (LauTagCatParamMap::iterator iter = theMap.begin(); iter != theMap.end(); ++iter) { if (iter == theMap.begin()) { firstCat = iter->first; continue; } LauParameter& par = iter->second; firstCatFrac -= par.unblindValue(); } theMap[firstCat].value(firstCatFrac); } void LauTimeDepFlavModel::cacheInputFitVars() { // Fill the internal data trees of the signal and background models. // Note that we store the events of both charges in both the // negative and the positive models. It's only later, at the stage // when the likelihood is being calculated, that we separate them. LauFitDataTree* inputFitData = this->fitData(); // Start by caching the tagging and CP-eigenstate information evtTagCatVals_.clear(); evtTagFlvVals_.clear(); evtCPEigenVals_.clear(); if ( ! inputFitData->haveBranch( tagCatVarName_ ) ) { std::cerr << "ERROR in LauTimeDepFlavModel::cacheInputFitVars : Input data does not contain branch \"" << tagCatVarName_ << "\"." << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( ! inputFitData->haveBranch( tagVarName_ ) ) { std::cerr << "ERROR in LauTimeDepFlavModel::cacheInputFitVars : Input data does not contain branch \"" << tagVarName_ << "\"." << std::endl; gSystem->Exit(EXIT_FAILURE); } const Bool_t hasCPEV = ( (cpevVarName_ != "") && inputFitData->haveBranch( cpevVarName_ ) ); UInt_t nEvents = inputFitData->nEvents(); evtTagCatVals_.reserve( nEvents ); evtTagFlvVals_.reserve( nEvents ); evtCPEigenVals_.reserve( nEvents ); LauFitData::const_iterator fitdata_iter; for (UInt_t iEvt = 0; iEvt < nEvents; iEvt++) { const LauFitData& dataValues = inputFitData->getData(iEvt); fitdata_iter = dataValues.find( tagCatVarName_ ); curEvtTagCat_ = static_cast( fitdata_iter->second ); if ( ! this->validTagCat( curEvtTagCat_ ) ) { std::cerr << "WARNING in LauTimeDepFlavModel::cacheInputFitVars : Invalid tagging category " << curEvtTagCat_ << " for event " << iEvt << ", setting it to untagged" << std::endl; curEvtTagCat_ = 0; } evtTagCatVals_.push_back( curEvtTagCat_ ); fitdata_iter = dataValues.find( tagVarName_ ); curEvtTagFlv_ = static_cast( fitdata_iter->second ); if ( TMath::Abs( curEvtTagFlv_ ) != 1 ) { if ( curEvtTagFlv_ > 0 ) { std::cerr << "WARNING in LauTimeDepFlavModel::cacheInputFitVars : Invalid tagging output " << curEvtTagFlv_ << " for event " << iEvt << ", setting it to +1" << std::endl; curEvtTagFlv_ = +1; } else { std::cerr << "WARNING in LauTimeDepFlavModel::cacheInputFitVars : Invalid tagging output " << curEvtTagFlv_ << " for event " << iEvt << ", setting it to -1" << std::endl; curEvtTagFlv_ = -1; } } evtTagFlvVals_.push_back( curEvtTagFlv_ ); // if the CP-eigenvalue is in the data use those, otherwise use the default if ( hasCPEV ) { fitdata_iter = dataValues.find( cpevVarName_ ); const Int_t cpEV = static_cast( fitdata_iter->second ); if ( cpEV == 1 ) { cpEigenValue_ = CPEven; } else if ( cpEV == -1 ) { cpEigenValue_ = CPOdd; } else { std::cerr<<"WARNING in LauTimeDepFlavModel::cacheInputFitVars : Unknown value: "<useDP() == kTRUE) { // DecayTime and SigmaDecayTime for (LauTagCatDtPdfMap::iterator dt_iter = signalDecayTimePdfs_.begin(); dt_iter != signalDecayTimePdfs_.end(); ++dt_iter) { (*dt_iter).second->cacheInfo(*inputFitData); } } // ...and then the extra PDFs for (LauTagCatPdfMap::iterator pdf_iter = sigExtraPdf_.begin(); pdf_iter != sigExtraPdf_.end(); ++pdf_iter) { this->cacheInfo(pdf_iter->second, *inputFitData); } if (this->useDP() == kTRUE) { sigModelB0bar_->fillDataTree(*inputFitData); sigModelB0_->fillDataTree(*inputFitData); } } Double_t LauTimeDepFlavModel::getTotEvtLikelihood(const UInt_t iEvt) { // Find out whether the tag-side B was a B0 or a B0bar. curEvtTagFlv_ = evtTagFlvVals_[iEvt]; // Also get the tagging category. curEvtTagCat_ = evtTagCatVals_[iEvt]; // Get the CP eigenvalue of the current event cpEigenValue_ = evtCPEigenVals_[iEvt]; // Get the DP and DecayTime likelihood for signal (TODO and eventually backgrounds) this->getEvtDPDtLikelihood(iEvt); // Get the combined extra PDFs likelihood for signal (TODO and eventually backgrounds) this->getEvtExtraLikelihoods(iEvt); // Construct the total likelihood for signal, qqbar and BBbar backgrounds Double_t sigLike = sigDPLike_ * sigExtraLike_; Double_t signalEvents = signalEvents_->unblindValue(); if (this->useDP() == kFALSE) { signalEvents *= 0.5 * (1.0 + curEvtTagFlv_ * signalAsym_->unblindValue()); } // Construct the total event likelihood Double_t likelihood(sigLike*signalTagCatFrac_[curEvtTagCat_].unblindValue()); if ( ! signalEvents_->fixed() ) { likelihood *= signalEvents; } return likelihood; } Double_t LauTimeDepFlavModel::getEventSum() const { Double_t eventSum(0.0); eventSum += signalEvents_->unblindValue(); return eventSum; } void LauTimeDepFlavModel::getEvtDPDtLikelihood(const UInt_t iEvt) { // Function to return the signal and background likelihoods for the // Dalitz plot for the given event evtNo. sigDPLike_ = 1.0; //There's always a likelihood term for signal, so we better not zero it. if ( this->useDP() == kFALSE ) { return; } // Mistag probabilities. Defined as: omega = prob of the tagging B0 being reported as B0bar // Whether we want omega or omegaBar depends on q_tag, hence curEvtTagFlv_*... in the previous lines //Double_t misTagFrac = 0.5 * (1.0 - dilution_[curEvtTagCat_] - qDDo2); //Double_t misTagFracBar = 0.5 * (1.0 - dilution_[curEvtTagCat_] + qDDo2); // Calculate event quantities Double_t qD = curEvtTagFlv_*dilution_[curEvtTagCat_].unblindValue(); Double_t qDDo2 = curEvtTagFlv_*0.5*deltaDilution_[curEvtTagCat_].unblindValue(); // Get the dynamics to calculate everything required for the likelihood calculation sigModelB0bar_->calcLikelihoodInfo(iEvt); sigModelB0_->calcLikelihoodInfo(iEvt); // Retrieve the amplitudes and efficiency from the dynamics const LauComplex& Abar = sigModelB0bar_->getEvtDPAmp(); const LauComplex& A = sigModelB0_->getEvtDPAmp(); Double_t eff = sigModelB0bar_->getEvtEff(); // Next calculate the DP terms Double_t aSqSum = A.abs2() + Abar.abs2(); Double_t aSqDif = A.abs2() - Abar.abs2(); LauComplex inter = Abar * A.conj() * phiMixComplex_; Double_t interTermIm = 2.0 * inter.im(); Double_t interTermRe = 2.0 * inter.re(); // First get all the decay time terms //LauDecayTimePdf* signalDtPdf = signalDecayTimePdfs_[curEvtTagCat_]; LauDecayTimePdf* decayTimePdf = signalDecayTimePdfs_[curEvtTagCat_]; decayTimePdf->calcLikelihoodInfo(iEvt); // First get all the decay time terms Double_t dtCos = decayTimePdf->getCosTerm(); Double_t dtSin = decayTimePdf->getSinTerm(); Double_t dtCosh = decayTimePdf->getCoshTerm(); Double_t dtSinh = decayTimePdf->getSinhTerm(); Double_t cosTerm = dtCos * qD * aSqDif; Double_t sinTerm = dtSin * qD * interTermIm; Double_t coshTerm = dtCosh * (1.0 + qDDo2) * aSqSum; Double_t sinhTerm = dtSinh * (1.0 + qDDo2) * interTermRe; if ( cpEigenValue_ == CPOdd ) { sinTerm *= -1.0; sinhTerm *= -1.0; } // ... to get the total and multiply by the efficiency Double_t ASq = coshTerm + cosTerm - sinTerm + sinhTerm; ASq *= eff; // Calculate the DP and time normalisation Double_t normTermIndep = sigModelB0bar_->getDPNorm() + sigModelB0_->getDPNorm(); Double_t normTermCosh = decayTimePdf->getNormTermCosh(); Double_t normTermDep = interTermReNorm_; Double_t normTermSinh = decayTimePdf->getNormTermSinh(); Double_t norm = normTermIndep*normTermCosh + normTermDep*normTermSinh; // Calculate the normalised signal likelihood sigDPLike_ = ASq / norm; } void LauTimeDepFlavModel::getEvtExtraLikelihoods(const UInt_t iEvt) { // Function to return the signal and background likelihoods for the // extra variables for the given event evtNo. sigExtraLike_ = 1.0; //There's always a likelihood term for signal, so we better not zero it. // First, those independent of the tagging of the event: // signal LauTagCatPdfMap::iterator sig_iter = sigExtraPdf_.find(curEvtTagCat_); LauPdfList* pdfList = (sig_iter != sigExtraPdf_.end())? &(sig_iter->second) : 0; if (pdfList) { sigExtraLike_ = this->prodPdfValue( *pdfList, iEvt ); } } void LauTimeDepFlavModel::updateCoeffs() { coeffsB0bar_.clear(); coeffsB0_.clear(); coeffsB0bar_.reserve(nSigComp_); coeffsB0_.reserve(nSigComp_); for (UInt_t i = 0; i < nSigComp_; ++i) { coeffsB0bar_.push_back(coeffPars_[i]->antiparticleCoeff()); coeffsB0_.push_back(coeffPars_[i]->particleCoeff()); } } Bool_t LauTimeDepFlavModel::validTagCat(Int_t tagCat) const { return (validTagCats_.find(tagCat) != validTagCats_.end()); } Bool_t LauTimeDepFlavModel::checkTagCatFracMap(const LauTagCatParamMap& theMap) const { // First check that there is an entry for each tagging category. // NB an entry won't have been added if it isn't a valid category // so don't need to check for that here. if (theMap.size() != signalTagCatFrac_.size()) { std::cerr<<"ERROR in LauTimeDepFlavModel::checkTagCatFracMap : Not all tagging categories present."< 1E-10) { std::cerr<<"ERROR in LauTimeDepFlavModel::checkTagCatFracMap : Tagging category event fractions do not sum to unity."< -LauConstants::pi && phase < LauConstants::pi) { withinRange = kTRUE; } else { // Not within the specified range if (phase > LauConstants::pi) { phase -= LauConstants::twoPi; } else if (phase < -LauConstants::pi) { phase += LauConstants::twoPi; } } } // A further problem can occur when the generated phase is close to -pi or pi. // The phase can wrap over to the other end of the scale - // this leads to artificially large pulls so we wrap it back. Double_t diff = phase - genPhase; if (diff > LauConstants::pi) { phase -= LauConstants::twoPi; } else if (diff < -LauConstants::pi) { phase += LauConstants::twoPi; } // finally store the new value in the parameter // and update the pull phiMix_.value(phase); phiMix_.updatePull(); } void LauTimeDepFlavModel::embedSignal(Int_t tagCat, const TString& fileName, const TString& treeName, Bool_t reuseEventsWithinEnsemble, Bool_t reuseEventsWithinExperiment) { if (signalTree_[tagCat]) { std::cerr<<"ERROR in LauTimeDepFlavModel::embedSignal : Already embedding signal from file for tagging category "<findBranches(); if (!dataOK) { delete signalTree_[tagCat]; signalTree_[tagCat] = 0; std::cerr<<"ERROR in LauTimeDepFlavModel::embedSignal : Problem creating data tree for embedding."<addSPlotNtupleIntegerBranch("iExpt"); this->addSPlotNtupleIntegerBranch("iEvtWithinExpt"); // Store the efficiency of the event (for inclusive BF calculations). if (this->storeDPEff()) { this->addSPlotNtupleDoubleBranch("efficiency"); } // Store the total event likelihood for each species. this->addSPlotNtupleDoubleBranch("sigTotalLike"); // Store the DP likelihoods if (this->useDP()) { this->addSPlotNtupleDoubleBranch("sigDPLike"); } // Store the likelihoods for each extra PDF const LauPdfList* pdfList( &(sigExtraPdf_.begin()->second) ); this->addSPlotNtupleBranches(pdfList, "sig"); } void LauTimeDepFlavModel::addSPlotNtupleBranches(const LauPdfList* extraPdfs, const TString& prefix) { if (!extraPdfs) { return; } // Loop through each of the PDFs for (LauPdfList::const_iterator pdf_iter = extraPdfs->begin(); pdf_iter != extraPdfs->end(); ++pdf_iter) { // Count the number of input variables that are not // DP variables (used in the case where there is DP // dependence for e.g. MVA) UInt_t nVars(0); for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { ++nVars; } } if ( nVars == 1 ) { // If the PDF only has one variable then // simply add one branch for that variable TString varName = (*pdf_iter)->varName(); TString name(prefix); name += varName; name += "Like"; this->addSPlotNtupleDoubleBranch(name); } else if ( nVars == 2 ) { // If the PDF has two variables then we // need a branch for them both together and // branches for each TString allVars(""); for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { allVars += (*var_iter); TString name(prefix); name += (*var_iter); name += "Like"; this->addSPlotNtupleDoubleBranch(name); } TString name(prefix); name += allVars; name += "Like"; this->addSPlotNtupleDoubleBranch(name); } else { std::cerr<<"WARNING in LauTimeDepFlavModel::addSPlotNtupleBranches : Can't yet deal with 3D PDFs."<begin(); pdf_iter != extraPdfs->end(); ++pdf_iter) { // calculate the likelihood for this event (*pdf_iter)->calcLikelihoodInfo(iEvt); extraLike = (*pdf_iter)->getLikelihood(); totalLike *= extraLike; // Count the number of input variables that are not // DP variables (used in the case where there is DP // dependence for e.g. MVA) UInt_t nVars(0); for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { ++nVars; } } if ( nVars == 1 ) { // If the PDF only has one variable then // simply store the value for that variable TString varName = (*pdf_iter)->varName(); TString name(prefix); name += varName; name += "Like"; this->setSPlotNtupleDoubleBranchValue(name, extraLike); } else if ( nVars == 2 ) { // If the PDF has two variables then we // store the value for them both together // and for each on their own TString allVars(""); for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { allVars += (*var_iter); TString name(prefix); name += (*var_iter); name += "Like"; Double_t indivLike = (*pdf_iter)->getLikelihood( (*var_iter) ); this->setSPlotNtupleDoubleBranchValue(name, indivLike); } TString name(prefix); name += allVars; name += "Like"; this->setSPlotNtupleDoubleBranchValue(name, extraLike); } else { std::cerr<<"WARNING in LauAllFitModel::setSPlotNtupleBranchValues : Can't yet deal with 3D PDFs."<useDP()) { nameSet.insert("DP"); } LauPdfList pdfList( (sigExtraPdf_.begin()->second) ); for (LauPdfList::const_iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) { // Loop over the variables involved in each PDF for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { // If they are not DP coordinates then add them if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { nameSet.insert( (*var_iter) ); } } } return nameSet; } LauSPlot::NumbMap LauTimeDepFlavModel::freeSpeciesNames() const { LauSPlot::NumbMap numbMap; if (!signalEvents_->fixed() && this->doEMLFit()) { numbMap["sig"] = signalEvents_->genValue(); } return numbMap; } LauSPlot::NumbMap LauTimeDepFlavModel::fixdSpeciesNames() const { LauSPlot::NumbMap numbMap; if (signalEvents_->fixed() && this->doEMLFit()) { numbMap["sig"] = signalEvents_->genValue(); } return numbMap; } LauSPlot::TwoDMap LauTimeDepFlavModel::twodimPDFs() const { LauSPlot::TwoDMap twodimMap; const LauPdfList* pdfList = &(sigExtraPdf_.begin()->second); for (LauPdfList::const_iterator pdf_iter = pdfList->begin(); pdf_iter != pdfList->end(); ++pdf_iter) { // Count the number of input variables that are not DP variables UInt_t nVars(0); for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { ++nVars; } } if ( nVars == 2 ) { twodimMap.insert( std::make_pair( "sig", std::make_pair( (*pdf_iter)->varNames()[0], (*pdf_iter)->varNames()[1] ) ) ); } } return twodimMap; } void LauTimeDepFlavModel::storePerEvtLlhds() { std::cout<<"INFO in LauTimeDepFlavModel::storePerEvtLlhds : Storing per-event likelihood values..."<fitData(); // if we've not been using the DP model then we need to cache all // the info here so that we can get the efficiency from it if (!this->useDP() && this->storeDPEff()) { sigModelB0bar_->initialise(coeffsB0bar_); sigModelB0_->initialise(coeffsB0_); sigModelB0bar_->fillDataTree(*inputFitData); sigModelB0_->fillDataTree(*inputFitData); } UInt_t evtsPerExpt(this->eventsPerExpt()); LauIsobarDynamics* sigModel(sigModelB0bar_); for (UInt_t iEvt = 0; iEvt < evtsPerExpt; ++iEvt) { // Find out whether we have B0bar or B0 curEvtTagFlv_ = evtTagFlvVals_[iEvt]; curEvtTagCat_ = evtTagCatVals_[iEvt]; LauTagCatPdfMap::iterator sig_iter = sigExtraPdf_.find(curEvtTagCat_); LauPdfList* sigPdfs = (sig_iter != sigExtraPdf_.end())? &(sig_iter->second) : 0; // the DP information this->getEvtDPDtLikelihood(iEvt); if (this->storeDPEff()) { if (!this->useDP()) { sigModel->calcLikelihoodInfo(iEvt); } this->setSPlotNtupleDoubleBranchValue("efficiency",sigModel->getEvtEff()); } if (this->useDP()) { sigTotalLike_ = sigDPLike_; this->setSPlotNtupleDoubleBranchValue("sigDPLike",sigDPLike_); } else { sigTotalLike_ = 1.0; } // the signal PDF values sigTotalLike_ *= this->setSPlotNtupleBranchValues(sigPdfs, "sig", iEvt); // the total likelihoods this->setSPlotNtupleDoubleBranchValue("sigTotalLike",sigTotalLike_); // fill the tree this->fillSPlotNtupleBranches(); } std::cout<<"INFO in LauTimeDepFlavModel::storePerEvtLlhds : Finished storing per-event likelihood values."< #include #include #include #include #include "TFile.h" #include "TMinuit.h" #include "TRandom.h" #include "TSystem.h" #include "TVirtualFitter.h" #include "LauAbsBkgndDPModel.hh" #include "LauAbsCoeffSet.hh" #include "LauAbsPdf.hh" #include "LauAsymmCalc.hh" #include "LauComplex.hh" #include "LauConstants.hh" #include "LauDPPartialIntegralInfo.hh" #include "LauDaughters.hh" #include "LauDecayTimePdf.hh" #include "LauFitNtuple.hh" #include "LauGenNtuple.hh" #include "LauIsobarDynamics.hh" #include "LauKinematics.hh" #include "LauPrint.hh" #include "LauRandom.hh" #include "LauScfMap.hh" #include "LauTimeDepNonFlavModel.hh" ClassImp(LauTimeDepNonFlavModel) LauTimeDepNonFlavModel::LauTimeDepNonFlavModel(LauIsobarDynamics* modelB0bar_f, LauIsobarDynamics* modelB0_f, LauIsobarDynamics* modelB0bar_fbar, LauIsobarDynamics* modelB0_fbar, const Bool_t useUntaggedEvents, const TString& tagVarName, const TString& tagCatVarName) : LauAbsFitModel(), sigModelB0bar_f_(modelB0bar_f), sigModelB0_f_(modelB0_f), sigModelB0bar_fbar_(modelB0bar_fbar), sigModelB0_fbar_(modelB0_fbar), kinematicsB0bar_f_(modelB0bar_f ? modelB0bar_f->getKinematics() : 0), kinematicsB0_f_(modelB0_f ? modelB0_f->getKinematics() : 0), kinematicsB0bar_fbar_(modelB0bar_fbar ? modelB0bar_fbar->getKinematics() : 0), kinematicsB0_fbar_(modelB0_fbar ? modelB0_fbar->getKinematics() : 0), useUntaggedEvents_(useUntaggedEvents), nSigComp_(0), nSigDPPar_(0), nDecayTimePar_(0), nExtraPdfPar_(0), nNormPar_(0), coeffsB0bar_f_(0), coeffsB0_f_(0), coeffsB0bar_fbar_(0), coeffsB0_fbar_(0), coeffPars_B0f_B0barfbar_(0), coeffPars_B0fbar_B0barf_(0), interTermReNorm_f_(0), interTermReNorm_fbar_(0), interTermImNorm_f_(0), interTermImNorm_fbar_(0), fitFracB0bar_f_(0), fitFracB0_f_(0), fitFracB0bar_fbar_(0), fitFracB0_fbar_(0), fitFracAsymm_B0f_B0barfbar_(0), fitFracAsymm_B0fbar_B0barf_(0), acp_B0f_B0barfbar_(0), acp_B0fbar_B0barf_(0), meanEffB0bar_f_("meanEffB0bar_f",0.0,0.0,1.0), meanEffB0_f_("meanEffB0_f",0.0,0.0,1.0), meanEffB0bar_fbar_("meanEffB0bar_fbar",0.0,0.0,1.0), meanEffB0_fbar_("meanEffB0_fbar",0.0,0.0,1.0), DPRateB0bar_f_("DPRateB0bar_f",0.0,0.0,100.0), DPRateB0_f_("DPRateB0_f",0.0,0.0,100.0), DPRateB0bar_fbar_("DPRateB0bar_fbar",0.0,0.0,100.0), DPRateB0_fbar_("DPRateB0_fbar",0.0,0.0,100.0), signalEvents_(0), signalAsym_(0), signalTagCatFrac_(), tagVarName_(tagVarName), tagCatVarName_(tagCatVarName), cpevVarName_(""), validTagCats_(), curEvtTagFlv_(0), curEvtTagCat_(0), cpEigenValue_(CPEven), evtTagFlvVals_(0), evtTagCatVals_(0), evtCPEigenVals_(0), dilution_(), deltaDilution_(), deltaM_("deltaM",0.0), deltaGamma_("deltaGamma",0.0), tau_("tau",LauConstants::tauB0), phiMix_("phiMix", 2.0*LauConstants::beta, -LauConstants::threePi, LauConstants::threePi, kFALSE), sinPhiMix_("sinPhiMix", TMath::Sin(2.0*LauConstants::beta), -3.0, 3.0, kFALSE), cosPhiMix_("cosPhiMix", TMath::Cos(2.0*LauConstants::beta), -3.0, 3.0, kFALSE), useSinCos_(kFALSE), phiMixComplex_(TMath::Cos(-2.0*LauConstants::beta),TMath::Sin(-2.0*LauConstants::beta)), signalDecayTimePdfs_(), curEvtDecayTime_(0.0), curEvtDecayTimeErr_(0.0), qD_(0.0), qDDo2_(0.0), sigExtraPdf_(), finalState_(0.0), iterationsMax_(500000), nGenLoop_(0), ASq_(0.0), aSqMaxVar_(0.0), aSqMaxSet_(1.25), normTimeDP_f_(0.0), normTimeDP_fbar_(0.0), storeGenAmpInfo_(kFALSE), signalTree_(), reuseSignal_(kFALSE), sigDPLike_(0.0), sigExtraLike_(0.0), sigTotalLike_(0.0) { // Add the untagged category as a valid category this->addValidTagCat(0); // Set the fraction, average dilution and dilution difference for the untagged category this->setSignalTagCatPars(0, 1.0, 0.0, 0.0, kTRUE); } LauTimeDepNonFlavModel::~LauTimeDepNonFlavModel() { // TODO - need to delete the various embedded data structures here } void LauTimeDepNonFlavModel::setupBkgndVectors() { } void LauTimeDepNonFlavModel::setNSigEvents(LauParameter* nSigEvents) { if ( nSigEvents == 0 ) { std::cerr << "ERROR in LauTimeDepNonFlavModel::setNSigEvents : The LauParameter pointer is null." << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( signalEvents_ != 0 ) { std::cerr << "ERROR in LauTimeDepNonFlavModel::setNSigEvents : You are trying to overwrite the signal yield." << std::endl; return; } if ( signalAsym_ != 0 ) { std::cerr << "ERROR in LauTimeDepNonFlavModel::setNSigEvents : You are trying to overwrite the signal asymmetry." << std::endl; return; } signalEvents_ = nSigEvents; signalEvents_->name("signalEvents"); Double_t value = nSigEvents->value(); signalEvents_->range(-2.0*(TMath::Abs(value)+1.0),2.0*(TMath::Abs(value)+1.0)); signalAsym_ = new LauParameter("signalAsym",0.0,-1.0,1.0,kTRUE); } void LauTimeDepNonFlavModel::setNSigEvents(LauParameter* nSigEvents, LauParameter* sigAsym) { if ( nSigEvents == 0 ) { std::cerr << "ERROR in LauTimeDepNonFlavModel::setNSigEvents : The event LauParameter pointer is null." << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( sigAsym == 0 ) { std::cerr << "ERROR in LauTimeDepNonFlavModel::setNSigEvents : The asym LauParameter pointer is null." << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( signalEvents_ != 0 ) { std::cerr << "ERROR in LauTimeDepNonFlavModel::setNSigEvents : You are trying to overwrite the signal yield." << std::endl; return; } if ( signalAsym_ != 0 ) { std::cerr << "ERROR in LauTimeDepNonFlavModel::setNSigEvents : You are trying to overwrite the signal asymmetry." << std::endl; return; } signalEvents_ = nSigEvents; signalEvents_->name("signalEvents"); Double_t value = nSigEvents->value(); signalEvents_->range(-2.0*(TMath::Abs(value)+1.0), 2.0*(TMath::Abs(value)+1.0)); signalAsym_ = sigAsym; signalAsym_->name("signalAsym"); signalAsym_->range(-1.0,1.0); } -void LauTimeDepNonFlavModel::setNBkgndEvents(LauParameter* /*nBkgndEvents*/) +void LauTimeDepNonFlavModel::setNBkgndEvents(LauAbsRValue* /*nBkgndEvents*/) { std::cerr << "WARNING in LauTimeDepNonFlavModel::setNBkgndEvents : This model does not yet support backgrounds" << std::endl; } void LauTimeDepNonFlavModel::addValidTagCats(const std::vector& tagCats) { for (std::vector::const_iterator iter = tagCats.begin(); iter != tagCats.end(); ++iter) { this->addValidTagCat(*iter); } } void LauTimeDepNonFlavModel::addValidTagCat(Int_t tagCat) { validTagCats_.insert(tagCat); } void LauTimeDepNonFlavModel::setSignalTagCatPars(const Int_t tagCat, const Double_t tagCatFrac, const Double_t dilution, const Double_t deltaDilution, const Bool_t fixTCFrac) { if (!this->validTagCat(tagCat)) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::setSignalTagCatPars : Tagging category \""<checkSignalTagCatFractions(); only when the user has //set them all up, in this->initialise(); } void LauTimeDepNonFlavModel::checkSignalTagCatFractions() { Double_t totalTaggedFrac(0.0); for (LauTagCatParamMap::const_iterator iter=signalTagCatFrac_.begin(); iter!=signalTagCatFrac_.end(); ++iter) { if (iter->first != 0) { const LauParameter& par = iter->second; totalTaggedFrac += par.value(); } } if ( ((totalTaggedFrac < (1.0-1.0e-8))&&!useUntaggedEvents_) || (totalTaggedFrac > (1.0+1.0e-8)) ) { std::cerr<<"WARNING in LauTimeDepNonFlavModel::checkSignalTagCatFractions : Tagging category fractions add up to "<second; Double_t newVal = par.value() / totalTaggedFrac; par.value(newVal); par.initValue(newVal); par.genValue(newVal); } } else if (useUntaggedEvents_) { Double_t tagCatFrac = 1.0 - totalTaggedFrac; TString tagCatFracName("signalTagCatFrac0"); signalTagCatFrac_[0].name(tagCatFracName); signalTagCatFrac_[0].range(0.0,1.0); signalTagCatFrac_[0].value(tagCatFrac); signalTagCatFrac_[0].initValue(tagCatFrac); signalTagCatFrac_[0].genValue(tagCatFrac); signalTagCatFrac_[0].fixed(kTRUE); TString dilutionName("dilution0"); dilution_[0].name(dilutionName); dilution_[0].range(0.0,1.0); dilution_[0].value(0.0); dilution_[0].initValue(0.0); dilution_[0].genValue(0.0); TString deltaDilutionName("deltaDilution0"); deltaDilution_[0].name(deltaDilutionName); deltaDilution_[0].range(-2.0,2.0); deltaDilution_[0].value(0.0); deltaDilution_[0].initValue(0.0); deltaDilution_[0].genValue(0.0); } for (LauTagCatParamMap::const_iterator iter=dilution_.begin(); iter!=dilution_.end(); ++iter) { std::cout<<"INFO in LauTimeDepNonFlavModel::checkSignalTagCatFractions : Setting dilution for tagging category "<<(*iter).first<<" to "<<(*iter).second<validTagCat(tagCat)) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::setSignalDtPdf : Tagging category \""<validTagCat(tagCat)) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::setSignalPdfs : Tagging category \""<updateCoeffs(); // Initialisation if (this->useDP() == kTRUE) { this->initialiseDPModels(); } if (!this->useDP() && sigExtraPdf_.empty()) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::initialise : Signal model doesn't exist for any variable."<Exit(EXIT_FAILURE); } if (this->useDP() == kTRUE) { // Check that we have all the Dalitz-plot models if ((sigModelB0bar_f_ == 0) || (sigModelB0_f_ == 0) || (sigModelB0bar_fbar_ == 0) || (sigModelB0bar_fbar_ == 0)) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::initialise : the pointer to one (particle or anti-particle) of the signal DP models is null."<Exit(EXIT_FAILURE); } } // Check here that the tagging category fractions add up to 1, otherwise "normalise". Also set up the untagged cat. // NB this has to be done early in the initialization as other methods access the tagCats map. this->checkSignalTagCatFractions(); // Clear the vectors of parameter information so we can start from scratch this->clearFitParVectors(); // Set the fit parameters for signal and background models this->setSignalDPParameters(); // Set the fit parameters for the decay time models this->setDecayTimeParameters(); // Set the fit parameters for the extra PDFs this->setExtraPdfParameters(); // Set the initial bg and signal events this->setFitNEvents(); // Check that we have the expected number of fit variables const LauParameterPList& fitVars = this->fitPars(); if (fitVars.size() != (nSigDPPar_ + nDecayTimePar_ + nExtraPdfPar_ + nNormPar_)) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::initialise : Number of fit parameters not of expected size."<Exit(EXIT_FAILURE); } this->setExtraNtupleVars(); } void LauTimeDepNonFlavModel::recalculateNormalisation() { sigModelB0bar_f_->recalculateNormalisation(); sigModelB0_f_->recalculateNormalisation(); sigModelB0bar_fbar_->recalculateNormalisation(); sigModelB0_fbar_->recalculateNormalisation(); sigModelB0bar_f_->modifyDataTree(); sigModelB0_f_->modifyDataTree(); sigModelB0bar_fbar_->modifyDataTree(); sigModelB0_fbar_->modifyDataTree(); this->calcInterferenceTermIntegrals(); } void LauTimeDepNonFlavModel::initialiseDPModels() { if (sigModelB0bar_f_ == 0) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::initialiseDPModels : B0bar -> f signal DP model doesn't exist"<Exit(EXIT_FAILURE); } if (sigModelB0_f_ == 0) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::initialiseDPModels : B0 -> f signal DP model doesn't exist"<Exit(EXIT_FAILURE); } if (sigModelB0bar_fbar_ == 0) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::initialiseDPModels : B0bar -> fbar signal DP model doesn't exist"<Exit(EXIT_FAILURE); } if (sigModelB0_fbar_ == 0) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::initialiseDPModels : B0 -> fbar signal DP model doesn't exist"<Exit(EXIT_FAILURE); } // Need to check that the number of components we have and that the dynamics has matches up //const UInt_t nAmpB0bar_f = sigModelB0bar_f_->getnAmp(); //const UInt_t nAmpB0_f = sigModelB0_f_->getnAmp(); //const UInt_t nAmpB0bar_fbar = sigModelB0bar_fbar_->getnAmp(); //const UInt_t nAmpB0_fbar = sigModelB0_fbar_->getnAmp(); const UInt_t nAmpB0bar_f = sigModelB0bar_f_->getnTotAmp(); const UInt_t nAmpB0_f = sigModelB0_f_->getnTotAmp(); const UInt_t nAmpB0bar_fbar = sigModelB0bar_fbar_->getnTotAmp(); const UInt_t nAmpB0_fbar = sigModelB0_fbar_->getnTotAmp(); if ( nAmpB0bar_f != nAmpB0_f ){ std::cerr << "ERROR in LauTimeDepNonFlavModel::initialiseDPModels : Unequal number of signal DP components in the particle and anti-particle models: " << nAmpB0bar_f << " != " << nAmpB0_f << std::endl; gSystem->Exit(EXIT_FAILURE); } else if ( nAmpB0bar_fbar != nAmpB0_fbar ) { std::cerr << "ERROR in LauTimeDepNonFlavModel::initialiseDPModels : Unequal number of signal DP components in the particle and anti-particle models: " << nAmpB0bar_fbar << " != " << nAmpB0_fbar << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( nAmpB0bar_f != nSigComp_ ) { std::cerr << "ERROR in LauTimeDepNonFlavModel::initialiseDPModels : Number of signal DP components in the model (" << nAmpB0bar_f << ") not equal to number of coefficients supplied (" << nSigComp_ << ")." << std::endl; gSystem->Exit(EXIT_FAILURE); } std::cout<<"INFO in LauTimeDepNonFlavModel::initialiseDPModels : Initialising signal DP model"<initialise(coeffsB0bar_f_); sigModelB0_f_->initialise(coeffsB0_f_); sigModelB0bar_fbar_->initialise(coeffsB0bar_fbar_); sigModelB0_fbar_->initialise(coeffsB0_fbar_); fifjEffSum_f_.clear(); fifjEffSum_fbar_.clear(); fifjEffSum_f_.resize(nSigComp_); fifjEffSum_fbar_.resize(nSigComp_); for (UInt_t iAmp = 0; iAmp < nSigComp_; ++iAmp) { fifjEffSum_f_[iAmp].resize(nSigComp_); fifjEffSum_fbar_[iAmp].resize(nSigComp_); } // calculate the integrals of the A*Abar terms this->calcInterferenceTermIntegrals(); this->calcInterTermNorm(); } void LauTimeDepNonFlavModel::calcInterferenceTermIntegrals() { const std::vector& integralInfoListB0bar_f = sigModelB0bar_f_->getIntegralInfos(); const std::vector& integralInfoListB0_f = sigModelB0_f_->getIntegralInfos(); const std::vector& integralInfoListB0bar_fbar = sigModelB0bar_fbar_->getIntegralInfos(); const std::vector& integralInfoListB0_fbar = sigModelB0_fbar_->getIntegralInfos(); LauComplex A_f, Abar_f, A_fbar, Abar_fbar, fifjEffSumTerm_f, fifjEffSumTerm_fbar; for (UInt_t iAmp = 0; iAmp < nSigComp_; ++iAmp) { for (UInt_t jAmp = 0; jAmp < nSigComp_; ++jAmp) { fifjEffSum_f_[iAmp][jAmp].zero(); fifjEffSum_fbar_[iAmp][jAmp].zero(); } } const UInt_t nIntegralRegions_f = integralInfoListB0bar_f.size(); for ( UInt_t iRegion(0); iRegion < nIntegralRegions_f; ++iRegion ) { const LauDPPartialIntegralInfo* integralInfoB0bar_f = integralInfoListB0bar_f[iRegion]; const LauDPPartialIntegralInfo* integralInfoB0_f = integralInfoListB0_f[iRegion]; const UInt_t nm13Points = integralInfoB0bar_f->getnm13Points(); const UInt_t nm23Points = integralInfoB0bar_f->getnm23Points(); for (UInt_t m13 = 0; m13 < nm13Points; ++m13) { for (UInt_t m23 = 0; m23 < nm23Points; ++m23) { const Double_t weight_f = integralInfoB0bar_f->getWeight(m13,m23); const Double_t eff_f = integralInfoB0bar_f->getEfficiency(m13,m23); const Double_t effWeight_f = eff_f*weight_f; for (UInt_t iAmp = 0; iAmp < nSigComp_; ++iAmp) { A_f = integralInfoB0_f->getAmplitude(m13, m23, iAmp); for (UInt_t jAmp = 0; jAmp < nSigComp_; ++jAmp) { Abar_f = integralInfoB0bar_f->getAmplitude(m13, m23, jAmp); fifjEffSumTerm_f = Abar_f*A_f.conj(); fifjEffSumTerm_f.rescale(effWeight_f); fifjEffSum_f_[iAmp][jAmp] += fifjEffSumTerm_f; } } } } } const UInt_t nIntegralRegions_fbar = integralInfoListB0bar_fbar.size(); for ( UInt_t iRegion(0); iRegion < nIntegralRegions_fbar; ++iRegion ) { const LauDPPartialIntegralInfo* integralInfoB0bar_fbar = integralInfoListB0bar_fbar[iRegion]; const LauDPPartialIntegralInfo* integralInfoB0_fbar = integralInfoListB0_fbar[iRegion]; const UInt_t nm13Points = integralInfoB0bar_fbar->getnm13Points(); const UInt_t nm23Points = integralInfoB0bar_fbar->getnm23Points(); for (UInt_t m13 = 0; m13 < nm13Points; ++m13) { for (UInt_t m23 = 0; m23 < nm23Points; ++m23) { const Double_t weight_fbar = integralInfoB0bar_fbar->getWeight(m13,m23); const Double_t eff_fbar = integralInfoB0bar_fbar->getEfficiency(m13,m23); const Double_t effWeight_fbar = eff_fbar*weight_fbar; for (UInt_t iAmp = 0; iAmp < nSigComp_; ++iAmp) { A_fbar = integralInfoB0_fbar->getAmplitude(m13, m23, iAmp); for (UInt_t jAmp = 0; jAmp < nSigComp_; ++jAmp) { Abar_fbar = integralInfoB0bar_fbar->getAmplitude(m13, m23, jAmp); fifjEffSumTerm_fbar = Abar_fbar*A_fbar.conj(); fifjEffSumTerm_fbar.rescale(effWeight_fbar); fifjEffSum_fbar_[iAmp][jAmp] += fifjEffSumTerm_fbar; } } } } } } void LauTimeDepNonFlavModel::calcInterTermNorm() { const std::vector fNormB0bar_f = sigModelB0bar_f_->getFNorm(); const std::vector fNormB0_f = sigModelB0_f_->getFNorm(); const std::vector fNormB0bar_fbar = sigModelB0bar_fbar_->getFNorm(); const std::vector fNormB0_fbar = sigModelB0_fbar_->getFNorm(); LauComplex norm_f; LauComplex norm_fbar; for (UInt_t iAmp = 0; iAmp < nSigComp_; ++iAmp) { for (UInt_t jAmp = 0; jAmp < nSigComp_; ++jAmp) { LauComplex coeffTerm_f = coeffsB0bar_f_[jAmp]*coeffsB0_f_[iAmp].conj(); LauComplex coeffTerm_fbar = coeffsB0bar_fbar_[jAmp]*coeffsB0_fbar_[iAmp].conj(); coeffTerm_f *= fifjEffSum_f_[iAmp][jAmp]; coeffTerm_fbar *= fifjEffSum_fbar_[iAmp][jAmp]; coeffTerm_f.rescale(fNormB0bar_f[jAmp] * fNormB0_f[iAmp]); coeffTerm_fbar.rescale(fNormB0bar_fbar[jAmp] * fNormB0_fbar[iAmp]); norm_f += coeffTerm_f; norm_fbar += coeffTerm_fbar; } } norm_f *= phiMixComplex_; norm_fbar *= phiMixComplex_; interTermReNorm_f_ = 2.0*norm_f.re(); interTermImNorm_f_ = 2.0*norm_f.im(); interTermReNorm_fbar_ = 2.0*norm_fbar.re(); interTermImNorm_fbar_ = 2.0*norm_fbar.im(); } void LauTimeDepNonFlavModel::setAmpCoeffSet(LauAbsCoeffSet* coeffSet) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::setAmpCoeffSet : Set of coefficients for B0/B0bar -> f,fbar contains only component for f final state \""<name()<<"\"."<name(); TString compName_B0fbar_B0barf = coeffSet_B0fbar_B0barf->name(); TString conjName_B0f_B0barfbar = sigModelB0bar_fbar_->getConjResName(compName_B0f_B0barfbar); TString conjName_B0fbar_B0barf = sigModelB0bar_f_->getConjResName(compName_B0fbar_B0barf); std::cout << "Values are: " << std::endl; std::cout << "CompName: " << compName_B0f_B0barfbar << " " << compName_B0fbar_B0barf << std::endl; std::cout << "ComjName: " << conjName_B0f_B0barfbar << " " << conjName_B0fbar_B0barf << std::endl; // Define each daughter configuration const LauDaughters* daughtersB0bar_f = sigModelB0bar_f_->getDaughters(); const LauDaughters* daughtersB0_f = sigModelB0_f_->getDaughters(); const LauDaughters* daughtersB0bar_fbar = sigModelB0bar_fbar_->getDaughters(); const LauDaughters* daughtersB0_fbar = sigModelB0_fbar_->getDaughters(); const Bool_t conjugateB0_f = daughtersB0_f->isConjugate( daughtersB0bar_fbar ); const Bool_t conjugateB0_fbar = daughtersB0_fbar->isConjugate( daughtersB0bar_f ); std::cout << "I am here 1 " << std::endl; if ( ! sigModelB0_f_->hasResonance(compName_B0f_B0barfbar) ) { if ( ! sigModelB0_f_->hasResonance(conjName_B0f_B0barfbar) ) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::setAmpCoeffSet : B0 -> f signal DP model doesn't contain component \""<< compName_B0f_B0barfbar <<"\"."<hasResonance(compName_B0fbar_B0barf) ) { std::cout << "Checked: " << compName_B0fbar_B0barf << std::endl; if ( ! sigModelB0_fbar_->hasResonance(conjName_B0fbar_B0barf) ) { std::cout << "Checked: " << conjName_B0fbar_B0barf << std::endl; std::cerr<<"ERROR in LauTimeDepNonFlavModel::setAmpCoeffSet : B0 -> fbar signal DP model doesn't contain component \""<< compName_B0fbar_B0barf<<"\"."<hasResonance(conjName_B0f_B0barfbar) ) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::setAmpCoeffSet : signal DP model doesn't contain component \""<hasResonance(conjName_B0fbar_B0barf) ) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::setAmpCoeffSet : signal DP model doesn't contain component \""<hasResonance(compName_B0f_B0barfbar) ) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::setAmpCoeffSet : signal DP model doesn't contain component \""<hasResonance(compName_B0fbar_B0barf) ) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::setAmpCoeffSet : signal DP model doesn't contain component \""<::const_iterator iter_B0f_B0barfbar=coeffPars_B0f_B0barfbar_.begin(); iter_B0f_B0barfbar!=coeffPars_B0f_B0barfbar_.end(); ++iter_B0f_B0barfbar) { if ((*iter_B0f_B0barfbar)->name() == compName_B0f_B0barfbar) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::setAmpCoeffSet : Have already set coefficients for \""<::const_iterator iter_B0fbar_B0barf=coeffPars_B0fbar_B0barf_.begin(); iter_B0fbar_B0barf!=coeffPars_B0fbar_B0barf_.end(); ++iter_B0fbar_B0barf) { if ((*iter_B0fbar_B0barf)->name() == compName_B0fbar_B0barf) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::setAmpCoeffSet : Have already set coefficients for \""<index(nSigComp_); coeffSet_B0fbar_B0barf->index(nSigComp_); coeffPars_B0f_B0barfbar_.push_back(coeffSet_B0f_B0barfbar); coeffPars_B0fbar_B0barf_.push_back(coeffSet_B0fbar_B0barf); TString parName_B0f_B0barfbar = coeffSet_B0f_B0barfbar->baseName(); parName_B0f_B0barfbar += "FitFracAsym"; TString parName_B0fbar_B0barf = coeffSet_B0fbar_B0barf->baseName(); parName_B0fbar_B0barf += "FitFracAsym"; fitFracAsymm_B0f_B0barfbar_.push_back(LauParameter(parName_B0f_B0barfbar, 0.0, -1.0, 1.0)); fitFracAsymm_B0fbar_B0barf_.push_back(LauParameter(parName_B0fbar_B0barf, 0.0, -1.0, 1.0)); acp_B0f_B0barfbar_.push_back(coeffSet_B0f_B0barfbar->acp()); acp_B0fbar_B0barf_.push_back(coeffSet_B0fbar_B0barf->acp()); ++nSigComp_; std::cout<<"INFO in LauTimeDepNonFlavModel::setAmpCoeffSet : Added coefficients for components \""<f, B0bar->fbar) and \""<fbar, B0bar->f)"<acp(); acp_B0fbar_B0barf_[i] = coeffPars_B0fbar_B0barf_[i]->acp(); LauAsymmCalc asymmCalc_B0f_B0barfbar(fitFracB0bar_fbar_[i][i].value(), fitFracB0_f_[i][i].value()); LauAsymmCalc asymmCalc_B0fbar_B0barf(fitFracB0bar_f_[i][i].value(), fitFracB0_fbar_[i][i].value()); Double_t asym_B0f_B0barfbar = asymmCalc_B0f_B0barfbar.getAsymmetry(); Double_t asym_B0fbar_B0barf = asymmCalc_B0fbar_B0barf.getAsymmetry(); fitFracAsymm_B0f_B0barfbar_[i].value(asym_B0f_B0barfbar); fitFracAsymm_B0fbar_B0barf_[i].value(asym_B0fbar_B0barf); if (initValues) { fitFracAsymm_B0f_B0barfbar_[i].genValue(asym_B0f_B0barfbar); fitFracAsymm_B0fbar_B0barf_[i].genValue(asym_B0fbar_B0barf); fitFracAsymm_B0f_B0barfbar_[i].initValue(asym_B0f_B0barfbar); fitFracAsymm_B0fbar_B0barf_[i].initValue(asym_B0fbar_B0barf); } } } void LauTimeDepNonFlavModel::setSignalDPParameters() { // Set the fit parameters for the signal model. nSigDPPar_ = 0; if ( ! this->useDP() ) { return; } std::cout << "INFO in LauTimeDepNonFlavModel::setSignalDPParameters : Setting the initial fit parameters for the signal DP model." << std::endl; // Place isobar coefficient parameters in vector of fit variables LauParameterPList& fitVars = this->fitPars(); for (UInt_t i = 0; i < nSigComp_; i++) { LauParameterPList pars_B0f_B0barfbar = coeffPars_B0f_B0barfbar_[i]->getParameters(); LauParameterPList pars_B0fbar_B0barf = coeffPars_B0fbar_B0barf_[i]->getParameters(); for (LauParameterPList::iterator iter_B0f_B0barfbar = pars_B0f_B0barfbar.begin(); iter_B0f_B0barfbar != pars_B0f_B0barfbar.end(); ++iter_B0f_B0barfbar) { if ( !(*iter_B0f_B0barfbar)->clone() ) { fitVars.push_back(*iter_B0f_B0barfbar); ++nSigDPPar_; } } for (LauParameterPList::iterator iter_B0fbar_B0barf = pars_B0fbar_B0barf.begin(); iter_B0fbar_B0barf != pars_B0fbar_B0barf.end(); ++iter_B0fbar_B0barf) { if ( !(*iter_B0fbar_B0barf)->clone() ) { fitVars.push_back(*iter_B0fbar_B0barf); ++nSigDPPar_; } } } // Obtain the resonance parameters and place them in the vector of fit variables and in a separate vector // Need to make sure that they are unique because some might appear in both DP models LauParameterPSet& resVars = this->resPars(); resVars.clear(); LauParameterPList& sigDPParsB0bar_f = sigModelB0bar_f_->getFloatingParameters(); LauParameterPList& sigDPParsB0_f = sigModelB0_f_->getFloatingParameters(); LauParameterPList& sigDPParsB0bar_fbar = sigModelB0bar_fbar_->getFloatingParameters(); LauParameterPList& sigDPParsB0_fbar = sigModelB0_fbar_->getFloatingParameters(); for ( LauParameterPList::iterator iter = sigDPParsB0bar_f.begin(); iter != sigDPParsB0bar_f.end(); ++iter ) { if ( resVars.insert(*iter).second ) { fitVars.push_back(*iter); ++nSigDPPar_; } } for ( LauParameterPList::iterator iter = sigDPParsB0_f.begin(); iter != sigDPParsB0_f.end(); ++iter ) { if ( resVars.insert(*iter).second ) { fitVars.push_back(*iter); ++nSigDPPar_; } } for ( LauParameterPList::iterator iter = sigDPParsB0bar_fbar.begin(); iter != sigDPParsB0bar_fbar.end(); ++iter ) { if ( resVars.insert(*iter).second ) { fitVars.push_back(*iter); ++nSigDPPar_; } } for ( LauParameterPList::iterator iter = sigDPParsB0_fbar.begin(); iter != sigDPParsB0_fbar.end(); ++iter ) { if ( resVars.insert(*iter).second ) { fitVars.push_back(*iter); ++nSigDPPar_; } } } UInt_t LauTimeDepNonFlavModel::addParametersToFitList(LauTagCatDtPdfMap& theMap) { UInt_t counter(0); LauParameterPList& fitVars = this->fitPars(); // loop through the map for (LauTagCatDtPdfMap::iterator iter = theMap.begin(); iter != theMap.end(); ++iter) { // grab the pdf and then its parameters LauDecayTimePdf* thePdf = (*iter).second; // The first one is the tagging category LauAbsRValuePList& rvalues = thePdf->getParameters(); // loop through the parameters for (LauAbsRValuePList::iterator pars_iter = rvalues.begin(); pars_iter != rvalues.end(); ++pars_iter) { LauParameterPList params = (*pars_iter)->getPars(); for (LauParameterPList::iterator params_iter = params.begin(); params_iter != params.end(); ++params_iter) { // for each "original" parameter add it to the list of fit parameters and increment the counter if ( !(*params_iter)->clone() && ( !(*params_iter)->fixed() || (this->twoStageFit() && (*params_iter)->secondStage()) ) ) { fitVars.push_back(*params_iter); ++counter; } } } } return counter; } UInt_t LauTimeDepNonFlavModel::addParametersToFitList(LauTagCatPdfMap& theMap) { UInt_t counter(0); // loop through the map for (LauTagCatPdfMap::iterator iter = theMap.begin(); iter != theMap.end(); ++iter) { counter += this->addFitParameters(iter->second); // first is the tagging category } return counter; } void LauTimeDepNonFlavModel::setDecayTimeParameters() { nDecayTimePar_ = 0; // Loop over the Dt PDFs nDecayTimePar_ += this->addParametersToFitList(signalDecayTimePdfs_); LauParameterPList& fitVars = this->fitPars(); if (useSinCos_) { fitVars.push_back(&sinPhiMix_); fitVars.push_back(&cosPhiMix_); nDecayTimePar_ += 2; } else { fitVars.push_back(&phiMix_); ++nDecayTimePar_; } } void LauTimeDepNonFlavModel::setExtraPdfParameters() { // Include the parameters of the PDF for each tagging category in the fit // NB all of them are passed to the fit, even though some have been fixed through parameter.fixed(kTRUE) // With the new "cloned parameter" scheme only "original" parameters are passed to the fit. // Their clones are updated automatically when the originals are updated. nExtraPdfPar_ = 0; nExtraPdfPar_ += this->addParametersToFitList(sigExtraPdf_); } void LauTimeDepNonFlavModel::setFitNEvents() { nNormPar_ = 0; // Initialise the total number of events to be the sum of all the hypotheses Double_t nTotEvts = signalEvents_->value(); this->eventsPerExpt(TMath::FloorNint(nTotEvts)); LauParameterPList& fitVars = this->fitPars(); // if doing an extended ML fit add the signal fraction into the fit parameters if (this->doEMLFit()) { std::cout<<"INFO in LauTimeDepNonFlavModel::setFitNEvents : Initialising number of events for signal and background components..."<useDP() == kFALSE) { fitVars.push_back(signalAsym_); ++nNormPar_; } // tagging-category fractions for signal events for (LauTagCatParamMap::iterator iter = signalTagCatFrac_.begin(); iter != signalTagCatFrac_.end(); ++iter) { if (iter == signalTagCatFrac_.begin()) { continue; } LauParameter* par = &((*iter).second); fitVars.push_back(par); ++nNormPar_; } } void LauTimeDepNonFlavModel::setExtraNtupleVars() { // Set-up other parameters derived from the fit results, e.g. fit fractions. if (this->useDP() != kTRUE) { return; } // First clear the vectors so we start from scratch this->clearExtraVarVectors(); LauParameterList& extraVars = this->extraPars(); // Add the B0 (f/fbar) and B0bar (f/fbar) fit fractions for each signal component fitFracB0bar_f_ = sigModelB0bar_f_->getFitFractions(); if (fitFracB0bar_f_.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::setExtraNtupleVars : Initial Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } for (UInt_t i(0); igetFitFractions(); if (fitFracB0_f_.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::setExtraNtupleVars : Initial Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } for (UInt_t i(0); igetFitFractions(); if (fitFracB0bar_fbar_.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::setExtraNtupleVars : Initial Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } for (UInt_t i(0); igetFitFractions(); if (fitFracB0_fbar_.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::setExtraNtupleVars : Initial Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } for (UInt_t i(0); icalcAsymmetries(kTRUE); // Add the Fit Fraction asymmetry for each signal component for (UInt_t i = 0; i < nSigComp_; i++) { extraVars.push_back(fitFracAsymm_B0f_B0barfbar_[i]); extraVars.push_back(fitFracAsymm_B0fbar_B0barf_[i]); } // Add the calculated CP asymmetry for each signal component for (UInt_t i = 0; i < nSigComp_; i++) { extraVars.push_back(acp_B0f_B0barfbar_[i]); extraVars.push_back(acp_B0fbar_B0barf_[i]); } // Now add in the DP efficiency values Double_t initMeanEffB0bar_f = sigModelB0bar_f_->getMeanEff().initValue(); meanEffB0bar_f_.value(initMeanEffB0bar_f); meanEffB0bar_f_.initValue(initMeanEffB0bar_f); meanEffB0bar_f_.genValue(initMeanEffB0bar_f); extraVars.push_back(meanEffB0bar_f_); Double_t initMeanEffB0_f = sigModelB0_f_->getMeanEff().initValue(); meanEffB0_f_.value(initMeanEffB0_f); meanEffB0_f_.initValue(initMeanEffB0_f); meanEffB0_f_.genValue(initMeanEffB0_f); extraVars.push_back(meanEffB0_f_); Double_t initMeanEffB0bar_fbar = sigModelB0bar_fbar_->getMeanEff().initValue(); meanEffB0bar_fbar_.value(initMeanEffB0bar_fbar); meanEffB0bar_fbar_.initValue(initMeanEffB0bar_fbar); meanEffB0bar_fbar_.genValue(initMeanEffB0bar_fbar); extraVars.push_back(meanEffB0bar_fbar_); Double_t initMeanEffB0_fbar = sigModelB0_fbar_->getMeanEff().initValue(); meanEffB0_fbar_.value(initMeanEffB0_fbar); meanEffB0_fbar_.initValue(initMeanEffB0_fbar); meanEffB0_fbar_.genValue(initMeanEffB0_fbar); extraVars.push_back(meanEffB0_fbar_); // Also add in the DP rates Double_t initDPRateB0bar_f = sigModelB0bar_f_->getDPRate().initValue(); DPRateB0bar_f_.value(initDPRateB0bar_f); DPRateB0bar_f_.initValue(initDPRateB0bar_f); DPRateB0bar_f_.genValue(initDPRateB0bar_f); extraVars.push_back(DPRateB0bar_f_); Double_t initDPRateB0_f = sigModelB0_f_->getDPRate().initValue(); DPRateB0_f_.value(initDPRateB0_f); DPRateB0_f_.initValue(initDPRateB0_f); DPRateB0_f_.genValue(initDPRateB0_f); extraVars.push_back(DPRateB0_f_); Double_t initDPRateB0bar_fbar = sigModelB0bar_fbar_->getDPRate().initValue(); DPRateB0bar_fbar_.value(initDPRateB0bar_fbar); DPRateB0bar_fbar_.initValue(initDPRateB0bar_fbar); DPRateB0bar_fbar_.genValue(initDPRateB0bar_fbar); extraVars.push_back(DPRateB0bar_fbar_); Double_t initDPRateB0_fbar = sigModelB0_fbar_->getDPRate().initValue(); DPRateB0_fbar_.value(initDPRateB0_fbar); DPRateB0_fbar_.initValue(initDPRateB0_fbar); DPRateB0_fbar_.genValue(initDPRateB0_fbar); extraVars.push_back(DPRateB0_fbar_); } void LauTimeDepNonFlavModel::finaliseFitResults(const TString& tablePrefixName) { // Retrieve parameters from the fit results for calculations and toy generation // and eventually store these in output root ntuples/text files // Now take the fit parameters and update them as necessary // i.e. to make mag > 0.0, phase in the right range. // This function will also calculate any other values, such as the // fit fractions, using any errors provided by fitParErrors as appropriate. // Also obtain the pull values: (measured - generated)/(average error) if (this->useDP() == kTRUE) { for (UInt_t i = 0; i < nSigComp_; ++i) { // Check whether we have "a > 0.0", and phases in the right range coeffPars_B0f_B0barfbar_[i]->finaliseValues(); coeffPars_B0fbar_B0barf_[i]->finaliseValues(); } } // update the pulls on the event fractions and asymmetries if (this->doEMLFit()) { signalEvents_->updatePull(); } if (this->useDP() == kFALSE) { signalAsym_->updatePull(); } // Finalise the pulls on the decay time parameters for (LauTagCatDtPdfMap::iterator iter = signalDecayTimePdfs_.begin(); iter != signalDecayTimePdfs_.end(); ++iter) { LauDecayTimePdf* pdf = (*iter).second; pdf->updatePulls(); } if (useSinCos_) { cosPhiMix_.updatePull(); sinPhiMix_.updatePull(); } else { this->checkMixingPhase(); } // Update the pulls on all the extra PDFs' parameters for (LauTagCatPdfMap::iterator iter = sigExtraPdf_.begin(); iter != sigExtraPdf_.end(); ++iter) { this->updateFitParameters(iter->second); } // Tagging-category fractions for signal and background events Double_t firstCatFrac(1.0); Int_t firstCat(0); for (LauTagCatParamMap::iterator iter = signalTagCatFrac_.begin(); iter != signalTagCatFrac_.end(); ++iter) { if (iter == signalTagCatFrac_.begin()) { firstCat = iter->first; continue; } LauParameter& par = (*iter).second; firstCatFrac -= par.value(); // update the parameter pull par.updatePull(); } signalTagCatFrac_[firstCat].value(firstCatFrac); signalTagCatFrac_[firstCat].updatePull(); // Fill the fit results to the ntuple // update the coefficients and then calculate the fit fractions and ACP's if (this->useDP() == kTRUE) { this->updateCoeffs(); sigModelB0bar_f_->updateCoeffs(coeffsB0bar_f_); sigModelB0bar_f_->calcExtraInfo(); sigModelB0_f_->updateCoeffs(coeffsB0_f_); sigModelB0_f_->calcExtraInfo(); sigModelB0bar_fbar_->updateCoeffs(coeffsB0bar_fbar_); sigModelB0bar_fbar_->calcExtraInfo(); sigModelB0_fbar_->updateCoeffs(coeffsB0_fbar_); sigModelB0_fbar_->calcExtraInfo(); LauParArray fitFracB0bar_f = sigModelB0bar_f_->getFitFractions(); if (fitFracB0bar_f.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::finaliseFitResults : Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } LauParArray fitFracB0_f = sigModelB0_f_->getFitFractions(); if (fitFracB0_f.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::finaliseFitResults : Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } LauParArray fitFracB0bar_fbar = sigModelB0bar_fbar_->getFitFractions(); if (fitFracB0bar_fbar.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::finaliseFitResults : Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } LauParArray fitFracB0_fbar = sigModelB0_fbar_->getFitFractions(); if (fitFracB0_fbar.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::finaliseFitResults : Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } for (UInt_t i(0); igetMeanEff().value()); meanEffB0_f_.value(sigModelB0_f_->getMeanEff().value()); meanEffB0bar_fbar_.value(sigModelB0bar_fbar_->getMeanEff().value()); meanEffB0_fbar_.value(sigModelB0_fbar_->getMeanEff().value()); DPRateB0bar_f_.value(sigModelB0bar_f_->getDPRate().value()); DPRateB0_f_.value(sigModelB0_f_->getDPRate().value()); DPRateB0bar_fbar_.value(sigModelB0bar_fbar_->getDPRate().value()); DPRateB0_fbar_.value(sigModelB0_fbar_->getDPRate().value()); this->calcAsymmetries(); // Then store the final fit parameters, and any extra parameters for // the signal model (e.g. fit fractions, FF asymmetries, ACPs, mean efficiency and DP rate) this->clearExtraVarVectors(); LauParameterList& extraVars = this->extraPars(); for (UInt_t i(0); iprintFitFractions(std::cout); this->printAsymmetries(std::cout); } const LauParameterPList& fitVars = this->fitPars(); const LauParameterList& extraVars = this->extraPars(); LauFitNtuple* ntuple = this->fitNtuple(); ntuple->storeParsAndErrors(fitVars, extraVars); // find out the correlation matrix for the parameters ntuple->storeCorrMatrix(this->iExpt(), this->fitStatus(), this->covarianceMatrix()); // Fill the data into ntuple ntuple->updateFitNtuple(); // Print out the partial fit fractions, phases and the // averaged efficiency, reweighted by the dynamics (and anything else) if (this->writeLatexTable()) { TString sigOutFileName(tablePrefixName); sigOutFileName += "_"; sigOutFileName += this->iExpt(); sigOutFileName += "Expt.tex"; this->writeOutTable(sigOutFileName); } } void LauTimeDepNonFlavModel::printFitFractions(std::ostream& output) { // Print out Fit Fractions, total DP rate and mean efficiency // B0 -> f events for (UInt_t i = 0; i < nSigComp_; i++) { const TString compName(coeffPars_B0f_B0barfbar_[i]->name()); output<<"B0bar FitFraction for component "< f overall DP rate (integral of matrix element squared) = "< f average efficiency weighted by whole DP dynamics = "< fbar sample for (UInt_t i = 0; i < nSigComp_; i++) { const TString compName(coeffPars_B0f_B0barfbar_[i]->name()); const TString conjName(sigModelB0_f_->getConjResName(compName)); output<<"B0 FitFraction for component "< fbar overall DP rate (integral of matrix element squared) = "< fbar average efficiency weighted by whole DP dynamics = "< fbar events for (UInt_t i = 0; i < nSigComp_; i++) { const TString compName(coeffPars_B0fbar_B0barf_[i]->name()); output<<"B0bar FitFraction for component "< fbar overall DP rate (integral of matrix element squared) = "< fbar average efficiency weighted by whole DP dynamics = "< f sample for (UInt_t i = 0; i < nSigComp_; i++) { const TString compName(coeffPars_B0fbar_B0barf_[i]->name()); const TString conjName(sigModelB0_fbar_->getConjResName(compName)); output<<"B0 FitFraction for component "< f overall DP rate (integral of matrix element squared) = "< f average efficiency weighted by whole DP dynamics = "<name()); output<<"Fit Fraction for B0(B0bar) -> f(fbar) asymmetry for component "< fbar(f) asymmetry for component "< f(fbar) component "<name()); output<<"ACP for B0(B0bar) -> fbar(f) component "<useDP() == kTRUE) { // print the fit coefficients in one table coeffPars_B0f_B0barfbar_.front()->printTableHeading(fout); for (UInt_t i = 0; i < nSigComp_; i++) { coeffPars_B0f_B0barfbar_[i]->printTableRow(fout); } fout<<"\\hline"<printTableHeading(fout); for (UInt_t i = 0; i < nSigComp_; i++) { coeffPars_B0fbar_B0barf_[i]->printTableRow(fout); } fout<<"\\hline"< f(fbar) fout<<"\\begin{tabular}{|l|c|c|c|c|}"< fbar \\ Fit Fraction & \\Bz ->f \\ Fit Fraction & Fit Fraction Asymmetry & $A_{\\CP}$ \\\\"<name(); resName = resName.ReplaceAll("_", "\\_"); fout< =$ & $"; print.printFormat(fout, meanEffB0bar_fbar_.value()); fout << "$ & $"; print.printFormat(fout, meanEffB0_f_.value()); fout << "$ & & \\\\" << std::endl; fout << "$ & & & & & & & \\\\" << std::endl; if (useSinCos_) { fout << "$\\sinPhiMix =$ & $"; print.printFormat(fout, sinPhiMix_.value()); fout << " \\pm "; print.printFormat(fout, sinPhiMix_.error()); fout << "$ & & & & & & & \\\\" << std::endl; fout << "$\\cosPhiMix =$ & $"; print.printFormat(fout, cosPhiMix_.value()); fout << " \\pm "; print.printFormat(fout, cosPhiMix_.error()); fout << "$ & & & & & & & \\\\" << std::endl; } else { fout << "$\\phiMix =$ & $"; print.printFormat(fout, phiMix_.value()); fout << " \\pm "; print.printFormat(fout, phiMix_.error()); fout << "$ & & & & & & & \\\\" << std::endl; } fout << "\\hline \n\\end{tabular}" << std::endl; // Another combination for B0(B0bar) -> fbar(f) fout<<"\\begin{tabular}{|l|c|c|c|c|}"< f \\ Fit Fraction & \\Bz ->fbar \\ Fit Fraction & Fit Fraction Asymmetry & $A_{\\CP}$ \\\\"<name(); resName = resName.ReplaceAll("_", "\\_"); fout< =$ & $"; print.printFormat(fout, meanEffB0bar_f_.value()); fout << "$ & $"; print.printFormat(fout, meanEffB0_fbar_.value()); fout << "$ & & \\\\" << std::endl; fout << "$ & & & & & & & \\\\" << std::endl; if (useSinCos_) { fout << "$\\sinPhiMix =$ & $"; print.printFormat(fout, sinPhiMix_.value()); fout << " \\pm "; print.printFormat(fout, sinPhiMix_.error()); fout << "$ & & & & & & & \\\\" << std::endl; fout << "$\\cosPhiMix =$ & $"; print.printFormat(fout, cosPhiMix_.value()); fout << " \\pm "; print.printFormat(fout, cosPhiMix_.error()); fout << "$ & & & & & & & \\\\" << std::endl; } else { fout << "$\\phiMix =$ & $"; print.printFormat(fout, phiMix_.value()); fout << " \\pm "; print.printFormat(fout, phiMix_.error()); fout << "$ & & & & & & & \\\\" << std::endl; } fout << "\\hline \n\\end{tabular}" << std::endl; } if (!sigExtraPdf_.empty()) { fout<<"\\begin{tabular}{|l|c|}"<printFitParameters(iter->second, fout); } fout<<"\\hline \n\\end{tabular}"<updateSigEvents(); // Check whether we want to have randomised initial fit parameters for the signal model if (this->useRandomInitFitPars() == kTRUE) { this->randomiseInitFitPars(); } } void LauTimeDepNonFlavModel::randomiseInitFitPars() { // Only randomise those parameters that are not fixed! std::cout<<"INFO in LauTimeDepNonFlavModel::randomiseInitFitPars : Randomising the initial values of the coefficients of the DP components (and phiMix)..."<randomiseInitValues(); coeffPars_B0fbar_B0barf_[i]->randomiseInitValues(); } phiMix_.randomiseValue(-LauConstants::pi, LauConstants::pi); if (useSinCos_) { sinPhiMix_.initValue(TMath::Sin(phiMix_.initValue())); cosPhiMix_.initValue(TMath::Cos(phiMix_.initValue())); } } LauTimeDepNonFlavModel::LauGenInfo LauTimeDepNonFlavModel::eventsToGenerate() { // TODO : Check whether in this bit we keep the same procedure or not // Determine the number of events to generate for each hypothesis // If we're smearing then smear each one individually // NB this individual smearing has to be done individually per tagging category as well LauGenInfo nEvtsGen; LauTagCatGenInfo eventsB0, eventsB0bar; // Signal // If we're including the DP and decay time we can't decide on the tag // yet, since it depends on the whole DP+dt PDF, however, if // we're not then we need to decide. Double_t evtWeight(1.0); Double_t nEvts = signalEvents_->genValue(); if ( nEvts < 0.0 ) { evtWeight = -1.0; nEvts = TMath::Abs( nEvts ); } Double_t sigAsym(0.0); if (this->useDP() == kFALSE) { sigAsym = signalAsym_->genValue(); for (LauTagCatParamMap::const_iterator iter = signalTagCatFrac_.begin(); iter != signalTagCatFrac_.end(); ++iter) { const LauParameter& par = iter->second; Double_t eventsbyTagCat = par.value() * nEvts; Double_t eventsB0byTagCat = TMath::Nint(eventsbyTagCat/2.0 * (1.0 - sigAsym)); Double_t eventsB0barbyTagCat = TMath::Nint(eventsbyTagCat/2.0 * (1.0 + sigAsym)); if (this->doPoissonSmearing()) { eventsB0byTagCat = LauRandom::randomFun()->Poisson(eventsB0byTagCat); eventsB0barbyTagCat = LauRandom::randomFun()->Poisson(eventsB0barbyTagCat); } eventsB0[iter->first] = std::make_pair( TMath::Nint(eventsB0byTagCat), evtWeight ); eventsB0bar[iter->first] = std::make_pair( TMath::Nint(eventsB0barbyTagCat), evtWeight ); } nEvtsGen[std::make_pair("signal",-1)] = eventsB0; nEvtsGen[std::make_pair("signal",+1)] = eventsB0bar; } else { Double_t rateB0bar = sigModelB0bar_f_->getDPRate().value(); Double_t rateB0 = sigModelB0_f_->getDPRate().value(); if ( rateB0bar+rateB0 > 1e-30) { sigAsym = (rateB0bar-rateB0)/(rateB0bar+rateB0); } for (LauTagCatParamMap::const_iterator iter = signalTagCatFrac_.begin(); iter != signalTagCatFrac_.end(); ++iter) { const LauParameter& par = iter->second; Double_t eventsbyTagCat = par.value() * nEvts; if (this->doPoissonSmearing()) { eventsbyTagCat = LauRandom::randomFun()->Poisson(eventsbyTagCat); } eventsB0[iter->first] = std::make_pair( TMath::Nint(eventsbyTagCat), evtWeight ); } nEvtsGen[std::make_pair("signal",0)] = eventsB0; // generate signal event, decide tag later. } std::cout<<"INFO in LauTimeDepNonFlavModel::eventsToGenerate : Generating toy MC with:"<setGenNtupleIntegerBranchValue("genSig",1); // All the generate*Event() methods have to fill in curEvtDecayTime_ and curEvtDecayTimeErr_ // In addition, generateSignalEvent has to decide on the tag and fill in curEvtTagFlv_ genOK = this->generateSignalEvent(); } else { genOK = kFALSE; } if (!genOK) { // If there was a problem with the generation then break out and return. // The problem model will have adjusted itself so that all should be OK next time. break; } if (this->useDP() == kTRUE) { this->setDPDtBranchValues(); // store DP, decay time and tagging variables in the ntuple } // Store the event's tag and tagging category this->setGenNtupleIntegerBranchValue("cpEigenvalue", cpEigenValue_); this->setGenNtupleIntegerBranchValue("tagCat",curEvtTagCat_); this->setGenNtupleIntegerBranchValue("tagFlv",curEvtTagFlv_); // Store the event number (within this experiment) // and then increment it this->setGenNtupleIntegerBranchValue("iEvtWithinExpt",evtNum); ++evtNum; // Write the values into the tree this->fillGenNtupleBranches(); // Print an occasional progress message if (iEvt%1000 == 0) {std::cout<<"INFO in LauTimeDepNonFlavModel::genExpt : Generated event number "<useDP() && genOK) { sigModelB0bar_f_->checkToyMC(kTRUE); sigModelB0_f_->checkToyMC(kTRUE); sigModelB0bar_fbar_->checkToyMC(kTRUE); sigModelB0_fbar_->checkToyMC(kTRUE); std::cout<<"aSqMaxSet = "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } LauParArray fitFracB0_f = sigModelB0_f_->getFitFractions(); if (fitFracB0_f.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::generate : Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } LauParArray fitFracB0bar_fbar = sigModelB0bar_fbar_->getFitFractions(); if (fitFracB0bar_fbar.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::generate : Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } LauParArray fitFracB0_fbar = sigModelB0_fbar_->getFitFractions(); if (fitFracB0_fbar.size() != nSigComp_) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::generate : Fit Fraction array of unexpected dimension: "<Exit(EXIT_FAILURE); } for (UInt_t i(0); iExit(EXIT_FAILURE); } } for (UInt_t i(0); igetMeanEff().value()); meanEffB0_f_.value(sigModelB0_f_->getMeanEff().value()); meanEffB0bar_fbar_.value(sigModelB0bar_fbar_->getMeanEff().value()); meanEffB0_fbar_.value(sigModelB0_fbar_->getMeanEff().value()); DPRateB0bar_f_.value(sigModelB0bar_f_->getDPRate().value()); DPRateB0_f_.value(sigModelB0_f_->getDPRate().value()); DPRateB0bar_fbar_.value(sigModelB0bar_fbar_->getDPRate().value()); DPRateB0_fbar_.value(sigModelB0_fbar_->getDPRate().value()); } } // If we're reusing embedded events or if the generation is being // reset then clear the lists of used events //if (!signalTree_.empty() && (reuseSignal_ || !genOK)) { if (reuseSignal_ || !genOK) { for(LauTagCatEmbDataMap::const_iterator iter = signalTree_.begin(); iter != signalTree_.end(); ++iter) { (iter->second)->clearUsedList(); } } return genOK; } Bool_t LauTimeDepNonFlavModel::generateSignalEvent() { // Generate signal event, including SCF if necessary. // DP:DecayTime generation follows. // If it's ok, we then generate mES, DeltaE, Fisher/NN... Bool_t genOK(kTRUE); Bool_t generatedEvent(kFALSE); Bool_t doSquareDP = kinematicsB0bar_f_->squareDP(); doSquareDP &= kinematicsB0_f_->squareDP(); doSquareDP &= kinematicsB0bar_fbar_->squareDP(); doSquareDP &= kinematicsB0_fbar_->squareDP(); LauKinematics* kinematics = 0; //(kinematicsB0bar_); // find the right decay time PDF for the current tagging category LauTagCatDtPdfMap::const_iterator dt_iter = signalDecayTimePdfs_.find(curEvtTagCat_); LauDecayTimePdf* decayTimePdf = (dt_iter != signalDecayTimePdfs_.end()) ? dt_iter->second : 0; // find the right embedded data for the current tagging category LauTagCatEmbDataMap::const_iterator emb_iter = signalTree_.find(curEvtTagCat_); LauEmbeddedData* embeddedData = (emb_iter != signalTree_.end()) ? emb_iter->second : 0; // find the right extra PDFs for the current tagging category LauTagCatPdfMap::iterator extra_iter = sigExtraPdf_.find(curEvtTagCat_); LauPdfList* extraPdfs = (extra_iter != sigExtraPdf_.end()) ? &(extra_iter->second) : 0; if (this->useDP()) { if (embeddedData) { // TODO : correct the kinematic term to the two possible final state // This option is not allowed in the moment kinematics = kinematicsB0bar_f_; embeddedData->getEmbeddedEvent(kinematics); curEvtTagFlv_ = TMath::Nint(embeddedData->getValue("tagFlv")); curEvtDecayTimeErr_ = embeddedData->getValue(decayTimePdf->varErrName()); curEvtDecayTime_ = embeddedData->getValue(decayTimePdf->varName()); if (embeddedData->haveBranch("mcMatch")) { Int_t match = TMath::Nint(embeddedData->getValue("mcMatch")); if (match) { this->setGenNtupleIntegerBranchValue("genTMSig",1); this->setGenNtupleIntegerBranchValue("genSCFSig",0); } else { this->setGenNtupleIntegerBranchValue("genTMSig",0); this->setGenNtupleIntegerBranchValue("genSCFSig",1); } } } else { nGenLoop_ = 0; // generate the decay time error (NB the kTRUE forces the generation of a new value) curEvtDecayTimeErr_ = decayTimePdf->generateError(kTRUE); while (generatedEvent == kFALSE && nGenLoop_ < iterationsMax_) { // Calculate the unnormalised truth-matched signal likelihood // First let define the tag flavour Double_t randNo = LauRandom::randomFun()->Rndm(); if (randNo < 0.5) { curEvtTagFlv_ = +1; // B0 tag } else { curEvtTagFlv_ = -1; // B0bar tag } // Calculate event quantities that depend only on the tagCat and tagFlv qD_ = curEvtTagFlv_*dilution_[curEvtTagCat_].unblindValue(); qDDo2_ = curEvtTagFlv_*0.5*deltaDilution_[curEvtTagCat_].unblindValue(); // Generate decay time const Double_t tMin = decayTimePdf->minAbscissa(); const Double_t tMax = decayTimePdf->maxAbscissa(); curEvtDecayTime_ = LauRandom::randomFun()->Rndm()*(tMax-tMin) + tMin; // Calculate all the decay time info decayTimePdf->calcLikelihoodInfo(curEvtDecayTime_, curEvtDecayTimeErr_); // ...and check that the calculation went ok, otherwise loop again if (decayTimePdf->state() != LauDecayTimePdf::Good) { ++nGenLoop_; continue; } // Calculate the relevant amplitude normalisation for the two DP's this->calculateAmplitudeNorm(decayTimePdf); // DP variables Double_t m13Sq(0.0), m23Sq(0.0); Double_t randNo_finalState = LauRandom::randomFun()->Rndm(); if (randNo_finalState < normTimeDP_f_/(normTimeDP_f_+normTimeDP_fbar_)) { finalState_ = +1; // A(Abar) -> f // Generate DP position kinematicsB0bar_f_->genFlatPhaseSpace(m13Sq, m23Sq); kinematicsB0_f_->updateKinematics(kinematicsB0bar_f_->getm13Sq(), kinematicsB0bar_f_->getm23Sq() ); // Calculate the total A and Abar for the given DP position sigModelB0_f_->calcLikelihoodInfo(m13Sq, m23Sq); sigModelB0bar_f_->calcLikelihoodInfo(m13Sq, m23Sq); // Calculate DP terms this->calculateDPterms(decayTimePdf, sigModelB0bar_f_, sigModelB0_f_); } else { finalState_ = -1; // A(Abar) -> fbar // Generate DP position kinematicsB0bar_fbar_->genFlatPhaseSpace(m13Sq, m23Sq); kinematicsB0_fbar_->updateKinematics(kinematicsB0bar_fbar_->getm13Sq(), kinematicsB0bar_fbar_->getm23Sq() ); // Calculate the total A and Abar for the given DP position sigModelB0_fbar_->calcLikelihoodInfo(m13Sq, m23Sq); sigModelB0bar_fbar_->calcLikelihoodInfo(m13Sq, m23Sq); // Calculate DP terms this->calculateDPterms(decayTimePdf, sigModelB0bar_fbar_, sigModelB0_fbar_); } //Finally we throw the dice to see whether this event should be generated //We make a distinction between the likelihood of TM and SCF to tag the SCF events as such randNo = LauRandom::randomFun()->Rndm(); if (randNo <= ASq_/aSqMaxSet_ ) { generatedEvent = kTRUE; nGenLoop_ = 0; if (ASq_ > aSqMaxVar_) {aSqMaxVar_ = ASq_;} } else { nGenLoop_++; } } // end of while !generatedEvent loop } // end of if (embeddedData) else control } else { if ( embeddedData ) { embeddedData->getEmbeddedEvent(0); curEvtTagFlv_ = TMath::Nint(embeddedData->getValue("tagFlv")); curEvtDecayTimeErr_ = embeddedData->getValue(decayTimePdf->varErrName()); curEvtDecayTime_ = embeddedData->getValue(decayTimePdf->varName()); } } // Check whether we have generated the toy MC OK. if (nGenLoop_ >= iterationsMax_) { aSqMaxSet_ = 1.01 * aSqMaxVar_; genOK = kFALSE; std::cerr<<"WARNING in LauTimeDepNonFlavModel::generateSignalEvent : Hit max iterations: setting aSqMaxSet_ to "< aSqMaxSet_) { aSqMaxSet_ = 1.01 * aSqMaxVar_; genOK = kFALSE; std::cerr<<"WARNING in LauTimeDepNonFlavModel::generateSignalEvent : Found a larger ASq value: setting aSqMaxSet_ to "<generateExtraPdfValues(extraPdfs, embeddedData); } // Check for problems with the embedding if (embeddedData && (embeddedData->nEvents() == embeddedData->nUsedEvents())) { std::cerr<<"WARNING in LauTimeDepNonFlavModel::generateSignalEvent : Source of embedded signal events used up, clearing the list of used events."<clearUsedList(); } return genOK; } void LauTimeDepNonFlavModel::calculateDPterms(LauDecayTimePdf* decayTimePdf, LauIsobarDynamics* sigModelB0bar, LauIsobarDynamics* sigModelB0) { // Retrieve the amplitudes and efficiency from the dynamics const LauComplex& Abar = sigModelB0bar->getEvtDPAmp(); const LauComplex& A = sigModelB0->getEvtDPAmp(); Double_t eff = sigModelB0bar->getEvtEff(); // Calculate the DP terms Double_t aSqSum = A.abs2() + Abar.abs2(); Double_t aSqDif = A.abs2() - Abar.abs2(); LauComplex inter = Abar * A.conj() * phiMixComplex_; Double_t interTermIm = 2.0 * inter.im(); Double_t interTermRe = 2.0 * inter.re(); // Decay time pdf terms Double_t dtCos = decayTimePdf->getCosTerm(); Double_t dtSin = decayTimePdf->getSinTerm(); Double_t dtCosh = decayTimePdf->getCoshTerm(); Double_t dtSinh = decayTimePdf->getSinhTerm(); // Combine all terms Double_t cosTerm = dtCos * qD_ * aSqDif; Double_t sinTerm = dtSin * qD_ * interTermIm; Double_t coshTerm = dtCosh * (1.0 + qDDo2_) * aSqSum; Double_t sinhTerm = dtSinh * (1.0 + qDDo2_) * interTermRe; if ( cpEigenValue_ == CPOdd ) { sinTerm *= -1.0; sinhTerm *= -1.0; } // Total amplitude and multiply by the efficiency ASq_ = coshTerm + cosTerm - sinTerm + sinhTerm; ASq_ *= eff; } void LauTimeDepNonFlavModel::calculateAmplitudeNorm(LauDecayTimePdf* decayTimePdf) { // Integrals of the sum of the ampltudes to the f(fbar) integral( |A|^2 + |Abar|^2 ) dP Double_t normTermNonDep_f = sigModelB0bar_f_->getDPNorm() + sigModelB0_f_->getDPNorm(); Double_t normTermNonDep_fbar = sigModelB0bar_fbar_->getDPNorm() + sigModelB0_fbar_->getDPNorm(); // Integrals of cross terms |Abar|*|Aconj| Double_t normTermDep_f = interTermReNorm_f_; Double_t normTermDep_fbar = interTermReNorm_fbar_; // Decay time constant integrals Double_t normTermCosh = decayTimePdf->getNormTermCosh(); Double_t normTermSinh = decayTimePdf->getNormTermSinh(); // Time-dependent DP normalisation terms normTimeDP_f_ = normTermNonDep_f*normTermCosh + normTermDep_f*normTermSinh; normTimeDP_fbar_ = normTermNonDep_fbar*normTermCosh + normTermDep_fbar*normTermSinh; } void LauTimeDepNonFlavModel::setupGenNtupleBranches() { // Setup the required ntuple branches this->addGenNtupleDoubleBranch("evtWeight"); this->addGenNtupleIntegerBranch("genSig"); this->addGenNtupleIntegerBranch("cpEigenvalue"); this->addGenNtupleIntegerBranch("tagFlv"); this->addGenNtupleIntegerBranch("tagCat"); if (this->useDP() == kTRUE) { // Let's add the decay time variables. if (signalDecayTimePdfs_.begin() != signalDecayTimePdfs_.end()) { LauDecayTimePdf* pdf = signalDecayTimePdfs_.begin()->second; this->addGenNtupleDoubleBranch(pdf->varName()); this->addGenNtupleDoubleBranch(pdf->varErrName()); } this->addGenNtupleDoubleBranch("m12_f"); this->addGenNtupleDoubleBranch("m23_f"); this->addGenNtupleDoubleBranch("m13_f"); this->addGenNtupleDoubleBranch("m12Sq_f"); this->addGenNtupleDoubleBranch("m23Sq_f"); this->addGenNtupleDoubleBranch("m13Sq_f"); this->addGenNtupleDoubleBranch("cosHel12_f"); this->addGenNtupleDoubleBranch("cosHel23_f"); this->addGenNtupleDoubleBranch("cosHel13_f"); if (kinematicsB0bar_f_->squareDP() && kinematicsB0_f_->squareDP()) { this->addGenNtupleDoubleBranch("mPrime_f"); this->addGenNtupleDoubleBranch("thPrime_f"); } this->addGenNtupleDoubleBranch("m12_fbar"); this->addGenNtupleDoubleBranch("m23_fbar"); this->addGenNtupleDoubleBranch("m13_fbar"); this->addGenNtupleDoubleBranch("m12Sq_fbar"); this->addGenNtupleDoubleBranch("m23Sq_fbar"); this->addGenNtupleDoubleBranch("m13Sq_fbar"); this->addGenNtupleDoubleBranch("cosHel12_fbar"); this->addGenNtupleDoubleBranch("cosHel23_fbar"); this->addGenNtupleDoubleBranch("cosHel13_fbar"); if (kinematicsB0bar_fbar_->squareDP() && kinematicsB0_fbar_->squareDP()) { this->addGenNtupleDoubleBranch("mPrime_fbar"); this->addGenNtupleDoubleBranch("thPrime_fbar"); } // Can add the real and imaginary parts of the B0 and B0bar total // amplitudes seen in the generation (restrict this with a flag // that defaults to false) if ( storeGenAmpInfo_ ) { this->addGenNtupleDoubleBranch("reB0fAmp"); this->addGenNtupleDoubleBranch("imB0fAmp"); this->addGenNtupleDoubleBranch("reB0barfAmp"); this->addGenNtupleDoubleBranch("imB0barfAmp"); this->addGenNtupleDoubleBranch("reB0fbarAmp"); this->addGenNtupleDoubleBranch("imB0fbarAmp"); this->addGenNtupleDoubleBranch("reB0barfbarAmp"); this->addGenNtupleDoubleBranch("imB0barfbarAmp"); } } // Let's look at the extra variables for signal in one of the tagging categories if ( ! sigExtraPdf_.empty() ) { LauPdfList oneTagCatPdfList = sigExtraPdf_.begin()->second; for (LauPdfList::const_iterator pdf_iter = oneTagCatPdfList.begin(); pdf_iter != oneTagCatPdfList.end(); ++pdf_iter) { for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { this->addGenNtupleDoubleBranch( (*var_iter) ); } } } } } void LauTimeDepNonFlavModel::setDPDtBranchValues() { // Store the decay time variables. if (signalDecayTimePdfs_.begin() != signalDecayTimePdfs_.end()) { LauDecayTimePdf* pdf = signalDecayTimePdfs_.begin()->second; this->setGenNtupleDoubleBranchValue(pdf->varName(),curEvtDecayTime_); this->setGenNtupleDoubleBranchValue(pdf->varErrName(),curEvtDecayTimeErr_); } LauKinematics* kinematics_f(0); LauKinematics* kinematics_fbar(0); if (curEvtTagFlv_<0) { kinematics_f = kinematicsB0_f_; kinematics_fbar = kinematicsB0_fbar_; } else { kinematics_f = kinematicsB0bar_f_; kinematics_fbar = kinematicsB0bar_fbar_; } // Store all the DP information this->setGenNtupleDoubleBranchValue("m12_f", kinematics_f->getm12()); this->setGenNtupleDoubleBranchValue("m23_f", kinematics_f->getm23()); this->setGenNtupleDoubleBranchValue("m13_f", kinematics_f->getm13()); this->setGenNtupleDoubleBranchValue("m12Sq_f", kinematics_f->getm12Sq()); this->setGenNtupleDoubleBranchValue("m23Sq_f", kinematics_f->getm23Sq()); this->setGenNtupleDoubleBranchValue("m13Sq_f", kinematics_f->getm13Sq()); this->setGenNtupleDoubleBranchValue("cosHel12_f", kinematics_f->getc12()); this->setGenNtupleDoubleBranchValue("cosHel23_f", kinematics_f->getc23()); this->setGenNtupleDoubleBranchValue("cosHel13_f", kinematics_f->getc13()); if (kinematics_f->squareDP()) { this->setGenNtupleDoubleBranchValue("mPrime_f", kinematics_f->getmPrime()); this->setGenNtupleDoubleBranchValue("thPrime_f", kinematics_f->getThetaPrime()); } this->setGenNtupleDoubleBranchValue("m12_fbar", kinematics_fbar->getm12()); this->setGenNtupleDoubleBranchValue("m23_fbar", kinematics_fbar->getm23()); this->setGenNtupleDoubleBranchValue("m13_fbar", kinematics_fbar->getm13()); this->setGenNtupleDoubleBranchValue("m12Sq_fbar", kinematics_fbar->getm12Sq()); this->setGenNtupleDoubleBranchValue("m23Sq_fbar", kinematics_fbar->getm23Sq()); this->setGenNtupleDoubleBranchValue("m13Sq_fbar", kinematics_fbar->getm13Sq()); this->setGenNtupleDoubleBranchValue("cosHel12_fbar", kinematics_fbar->getc12()); this->setGenNtupleDoubleBranchValue("cosHel23_fbar", kinematics_fbar->getc23()); this->setGenNtupleDoubleBranchValue("cosHel13_fbar", kinematics_fbar->getc13()); if (kinematics_fbar->squareDP()) { this->setGenNtupleDoubleBranchValue("mPrime_fbar", kinematics_fbar->getmPrime()); this->setGenNtupleDoubleBranchValue("thPrime_fbar", kinematics_fbar->getThetaPrime()); } // Can add the real and imaginary parts of the B0 and B0bar total // amplitudes seen in the generation (restrict this with a flag // that defaults to false) if ( storeGenAmpInfo_ ) { if ( this->getGenNtupleIntegerBranchValue("genSig")==1 ) { LauComplex Abar_f = sigModelB0bar_f_->getEvtDPAmp(); LauComplex A_f = sigModelB0_f_->getEvtDPAmp(); LauComplex Abar_fbar = sigModelB0bar_fbar_->getEvtDPAmp(); LauComplex A_fbar = sigModelB0_fbar_->getEvtDPAmp(); this->setGenNtupleDoubleBranchValue("reB0fAmp", A_f.re()); this->setGenNtupleDoubleBranchValue("imB0fAmp", A_f.im()); this->setGenNtupleDoubleBranchValue("reB0barfAmp", Abar_f.re()); this->setGenNtupleDoubleBranchValue("imB0barfAmp", Abar_f.im()); this->setGenNtupleDoubleBranchValue("reB0fbarAmp", A_fbar.re()); this->setGenNtupleDoubleBranchValue("imB0fbarAmp", A_fbar.im()); this->setGenNtupleDoubleBranchValue("reB0barfbarAmp", Abar_fbar.re()); this->setGenNtupleDoubleBranchValue("imB0barfbarAmp", Abar_fbar.im()); } else { this->setGenNtupleDoubleBranchValue("reB0fAmp", 0.0); this->setGenNtupleDoubleBranchValue("imB0fAmp", 0.0); this->setGenNtupleDoubleBranchValue("reB0barfAmp", 0.0); this->setGenNtupleDoubleBranchValue("imB0barfAmp", 0.0); this->setGenNtupleDoubleBranchValue("reB0fbarAmp", 0.0); this->setGenNtupleDoubleBranchValue("imB0fbarAmp", 0.0); this->setGenNtupleDoubleBranchValue("reB0barfbarAmp", 0.0); this->setGenNtupleDoubleBranchValue("imB0barfbarAmp", 0.0); } } } void LauTimeDepNonFlavModel::generateExtraPdfValues(LauPdfList* extraPdfs, LauEmbeddedData* embeddedData) { // TODO : need to add the additional DP LauKinematics* kinematics_f(0); //LauKinematics* kinematics_fbar(0); if (curEvtTagFlv_<0) { kinematics_f = kinematicsB0_f_; //kinematics_fbar = kinematicsB0_fbar_; } else { kinematics_f = kinematicsB0bar_f_; //kinematics_fbar = kinematicsB0bar_fbar_; } // Generate from the extra PDFs if (extraPdfs) { for (LauPdfList::iterator pdf_iter = extraPdfs->begin(); pdf_iter != extraPdfs->end(); ++pdf_iter) { LauFitData genValues; if (embeddedData) { genValues = embeddedData->getValues( (*pdf_iter)->varNames() ); } else { genValues = (*pdf_iter)->generate(kinematics_f); } for ( LauFitData::const_iterator var_iter = genValues.begin(); var_iter != genValues.end(); ++var_iter ) { TString varName = var_iter->first; if ( varName != "m13Sq" && varName != "m23Sq" ) { Double_t value = var_iter->second; this->setGenNtupleDoubleBranchValue(varName,value); } } } } } void LauTimeDepNonFlavModel::propagateParUpdates() { // Update the complex mixing phase if (useSinCos_) { phiMixComplex_.setRealPart(cosPhiMix_.unblindValue()); phiMixComplex_.setImagPart(-1.0*sinPhiMix_.unblindValue()); } else { phiMixComplex_.setRealPart(TMath::Cos(-1.0*phiMix_.unblindValue())); phiMixComplex_.setImagPart(TMath::Sin(-1.0*phiMix_.unblindValue())); } // Update the total normalisation for the signal likelihood if (this->useDP() == kTRUE) { this->updateCoeffs(); sigModelB0bar_f_->updateCoeffs(coeffsB0bar_f_); sigModelB0_f_->updateCoeffs(coeffsB0_f_); sigModelB0bar_fbar_->updateCoeffs(coeffsB0bar_fbar_); sigModelB0_fbar_->updateCoeffs(coeffsB0_fbar_); this->calcInterTermNorm(); } // Update the signal events from the background numbers if not doing an extended fit if (!this->doEMLFit()) { this->updateSigEvents(); } } void LauTimeDepNonFlavModel::updateSigEvents() { // The background parameters will have been set from Minuit. // We need to update the signal events using these. Double_t nTotEvts = this->eventsPerExpt(); Double_t signalEvents = nTotEvts; // tagging-category fractions for signal events this->setFirstTagCatFrac(signalTagCatFrac_); signalEvents_->range(-2.0*nTotEvts,2.0*nTotEvts); if ( ! signalEvents_->fixed() ) { signalEvents_->value(signalEvents); } } void LauTimeDepNonFlavModel::setFirstTagCatFrac(LauTagCatParamMap& theMap) { Double_t firstCatFrac = 1.0; Int_t firstCat(0); for (LauTagCatParamMap::iterator iter = theMap.begin(); iter != theMap.end(); ++iter) { if (iter == theMap.begin()) { firstCat = iter->first; continue; } LauParameter& par = iter->second; firstCatFrac -= par.unblindValue(); } theMap[firstCat].value(firstCatFrac); } void LauTimeDepNonFlavModel::cacheInputFitVars() { // Fill the internal data trees of the signal and background models. // Note that we store the events of both charges in both the // negative and the positive models. It's only later, at the stage // when the likelihood is being calculated, that we separate them. LauFitDataTree* inputFitData = this->fitData(); // Start by caching the tagging and CP-eigenstate information evtTagCatVals_.clear(); evtTagFlvVals_.clear(); evtCPEigenVals_.clear(); if ( ! inputFitData->haveBranch( tagCatVarName_ ) ) { std::cerr << "ERROR in LauTimeDepNonFlavModel::cacheInputFitVars : Input data does not contain branch \"" << tagCatVarName_ << "\"." << std::endl; gSystem->Exit(EXIT_FAILURE); } if ( ! inputFitData->haveBranch( tagVarName_ ) ) { std::cerr << "ERROR in LauTimeDepNonFlavModel::cacheInputFitVars : Input data does not contain branch \"" << tagVarName_ << "\"." << std::endl; gSystem->Exit(EXIT_FAILURE); } const Bool_t hasCPEV = ( (cpevVarName_ != "") && inputFitData->haveBranch( cpevVarName_ ) ); UInt_t nEvents = inputFitData->nEvents(); evtTagCatVals_.reserve( nEvents ); evtTagFlvVals_.reserve( nEvents ); evtCPEigenVals_.reserve( nEvents ); LauFitData::const_iterator fitdata_iter; for (UInt_t iEvt = 0; iEvt < nEvents; iEvt++) { const LauFitData& dataValues = inputFitData->getData(iEvt); fitdata_iter = dataValues.find( tagCatVarName_ ); curEvtTagCat_ = static_cast( fitdata_iter->second ); if ( ! this->validTagCat( curEvtTagCat_ ) ) { std::cerr << "WARNING in LauTimeDepNonFlavModel::cacheInputFitVars : Invalid tagging category " << curEvtTagCat_ << " for event " << iEvt << ", setting it to untagged" << std::endl; curEvtTagCat_ = 0; } evtTagCatVals_.push_back( curEvtTagCat_ ); fitdata_iter = dataValues.find( tagVarName_ ); curEvtTagFlv_ = static_cast( fitdata_iter->second ); if ( TMath::Abs( curEvtTagFlv_ ) != 1 ) { if ( curEvtTagFlv_ > 0 ) { std::cerr << "WARNING in LauTimeDepNonFlavModel::cacheInputFitVars : Invalid tagging output " << curEvtTagFlv_ << " for event " << iEvt << ", setting it to +1" << std::endl; curEvtTagFlv_ = +1; } else { std::cerr << "WARNING in LauTimeDepNonFlavModel::cacheInputFitVars : Invalid tagging output " << curEvtTagFlv_ << " for event " << iEvt << ", setting it to -1" << std::endl; curEvtTagFlv_ = -1; } } evtTagFlvVals_.push_back( curEvtTagFlv_ ); // if the CP-eigenvalue is in the data use those, otherwise use the default if ( hasCPEV ) { fitdata_iter = dataValues.find( cpevVarName_ ); const Int_t cpEV = static_cast( fitdata_iter->second ); if ( cpEV == 1 ) { cpEigenValue_ = CPEven; } else if ( cpEV == -1 ) { cpEigenValue_ = CPOdd; } else { std::cerr<<"WARNING in LauTimeDepNonFlavModel::cacheInputFitVars : Unknown value: "<useDP() == kTRUE) { // DecayTime and SigmaDecayTime for (LauTagCatDtPdfMap::iterator dt_iter = signalDecayTimePdfs_.begin(); dt_iter != signalDecayTimePdfs_.end(); ++dt_iter) { (*dt_iter).second->cacheInfo(*inputFitData); } } // ...and then the extra PDFs for (LauTagCatPdfMap::iterator pdf_iter = sigExtraPdf_.begin(); pdf_iter != sigExtraPdf_.end(); ++pdf_iter) { this->cacheInfo(pdf_iter->second, *inputFitData); } if (this->useDP() == kTRUE) { sigModelB0bar_f_->fillDataTree(*inputFitData); sigModelB0_f_->fillDataTree(*inputFitData); sigModelB0bar_fbar_->fillDataTree(*inputFitData); sigModelB0_fbar_->fillDataTree(*inputFitData); } } Double_t LauTimeDepNonFlavModel::getTotEvtLikelihood(const UInt_t iEvt) { // Find out whether the tag-side B was a B0 or a B0bar. curEvtTagFlv_ = evtTagFlvVals_[iEvt]; // Also get the tagging category. curEvtTagCat_ = evtTagCatVals_[iEvt]; // Get the CP eigenvalue of the current event cpEigenValue_ = evtCPEigenVals_[iEvt]; // Get the DP and DecayTime likelihood for signal this->getEvtDPDtLikelihood(iEvt); // Get the combined extra PDFs likelihood for signal this->getEvtExtraLikelihoods(iEvt); // Construct the total likelihood for signal, qqbar and BBbar backgrounds Double_t sigLike = sigDPLike_ * sigExtraLike_; Double_t signalEvents = signalEvents_->unblindValue(); if (this->useDP() == kFALSE) { signalEvents *= 0.5 * (1.0 + curEvtTagFlv_ * signalAsym_->unblindValue()); } // Construct the total event likelihood Double_t likelihood(sigLike*signalTagCatFrac_[curEvtTagCat_].unblindValue()); if ( ! signalEvents_->fixed() ) { likelihood *= signalEvents; } return likelihood; } Double_t LauTimeDepNonFlavModel::getEventSum() const { Double_t eventSum(0.0); eventSum += signalEvents_->unblindValue(); return eventSum; } void LauTimeDepNonFlavModel::getEvtDPDtLikelihood(const UInt_t iEvt) { // Function to return the signal and background likelihoods for the // Dalitz plot for the given event evtNo. sigDPLike_ = 1.0; //There's always a likelihood term for signal, so we better not zero it. if ( this->useDP() == kFALSE ) { return; } // Mistag probabilities. Defined as: omega = prob of the tagging B0 being reported as B0bar // Whether we want omega or omegaBar depends on q_tag, hence curEvtTagFlv_*... in the previous lines //Double_t misTagFrac = 0.5 * (1.0 - dilution_[curEvtTagCat_] - qDDo2); //Double_t misTagFracBar = 0.5 * (1.0 - dilution_[curEvtTagCat_] + qDDo2); // Calculate event quantities qD_ = curEvtTagFlv_*dilution_[curEvtTagCat_].unblindValue(); qDDo2_ = curEvtTagFlv_*0.5*deltaDilution_[curEvtTagCat_].unblindValue(); //LauDecayTimePdf* signalDtPdf = signalDecayTimePdfs_[curEvtTagCat_]; LauDecayTimePdf* decayTimePdf = signalDecayTimePdfs_[curEvtTagCat_]; decayTimePdf->calcLikelihoodInfo(iEvt); // Calculate the relevant amplitude normalisation for the two DP's this->calculateAmplitudeNorm(decayTimePdf); Double_t randNo = LauRandom::randomFun()->Rndm(); if (randNo < normTimeDP_f_/(normTimeDP_f_+normTimeDP_fbar_)) { finalState_ = +1; // A(Abar) -> f // Calculate the likelihood for the f final state sigModelB0bar_f_->calcLikelihoodInfo(iEvt); sigModelB0_f_->calcLikelihoodInfo(iEvt); // Calculate DP terms this->calculateDPterms(decayTimePdf, sigModelB0bar_f_, sigModelB0_f_); } else { finalState_ = -1; // A(Abar) -> fbar // Calculate the likelihood for the fbar final state sigModelB0bar_fbar_->calcLikelihoodInfo(iEvt); sigModelB0_fbar_->calcLikelihoodInfo(iEvt); // Calculate DP terms this->calculateDPterms(decayTimePdf, sigModelB0bar_fbar_, sigModelB0_fbar_); } // Calculate the normalised signal likelihood sigDPLike_ = ASq_ / (normTimeDP_f_+normTimeDP_fbar_); } void LauTimeDepNonFlavModel::getEvtExtraLikelihoods(const UInt_t iEvt) { // Function to return the signal and background likelihoods for the // extra variables for the given event evtNo. sigExtraLike_ = 1.0; //There's always a likelihood term for signal, so we better not zero it. // First, those independent of the tagging of the event: // signal LauTagCatPdfMap::iterator sig_iter = sigExtraPdf_.find(curEvtTagCat_); LauPdfList* pdfList = (sig_iter != sigExtraPdf_.end())? &(sig_iter->second) : 0; if (pdfList) { sigExtraLike_ = this->prodPdfValue( *pdfList, iEvt ); } } void LauTimeDepNonFlavModel::updateCoeffs() { coeffsB0bar_f_.clear(); coeffsB0_f_.clear(); coeffsB0bar_fbar_.clear(); coeffsB0_fbar_.clear(); coeffsB0bar_f_.reserve(nSigComp_); coeffsB0_f_.reserve(nSigComp_); coeffsB0bar_fbar_.reserve(nSigComp_); coeffsB0_fbar_.reserve(nSigComp_); for (UInt_t i = 0; i < nSigComp_; ++i) { coeffsB0bar_f_.push_back(coeffPars_B0fbar_B0barf_[i]->antiparticleCoeff()); coeffsB0_f_.push_back(coeffPars_B0f_B0barfbar_[i]->particleCoeff()); coeffsB0bar_fbar_.push_back(coeffPars_B0f_B0barfbar_[i]->antiparticleCoeff()); coeffsB0_fbar_.push_back(coeffPars_B0fbar_B0barf_[i]->particleCoeff()); } } Bool_t LauTimeDepNonFlavModel::validTagCat(Int_t tagCat) const { return (validTagCats_.find(tagCat) != validTagCats_.end()); } Bool_t LauTimeDepNonFlavModel::checkTagCatFracMap(const LauTagCatParamMap& theMap) const { // First check that there is an entry for each tagging category. // NB an entry won't have been added if it isn't a valid category // so don't need to check for that here. if (theMap.size() != signalTagCatFrac_.size()) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::checkTagCatFracMap : Not all tagging categories present."< 1E-10) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::checkTagCatFracMap : Tagging category event fractions do not sum to unity."< -LauConstants::pi && phase < LauConstants::pi) { withinRange = kTRUE; } else { // Not within the specified range if (phase > LauConstants::pi) { phase -= LauConstants::twoPi; } else if (phase < -LauConstants::pi) { phase += LauConstants::twoPi; } } } // A further problem can occur when the generated phase is close to -pi or pi. // The phase can wrap over to the other end of the scale - // this leads to artificially large pulls so we wrap it back. Double_t diff = phase - genPhase; if (diff > LauConstants::pi) { phase -= LauConstants::twoPi; } else if (diff < -LauConstants::pi) { phase += LauConstants::twoPi; } // finally store the new value in the parameter // and update the pull phiMix_.value(phase); phiMix_.updatePull(); } void LauTimeDepNonFlavModel::embedSignal(Int_t tagCat, const TString& fileName, const TString& treeName, Bool_t reuseEventsWithinEnsemble, Bool_t reuseEventsWithinExperiment) { if (signalTree_[tagCat]) { std::cerr<<"ERROR in LauTimeDepNonFlavModel::embedSignal : Already embedding signal from file for tagging category "<findBranches(); if (!dataOK) { delete signalTree_[tagCat]; signalTree_[tagCat] = 0; std::cerr<<"ERROR in LauTimeDepNonFlavModel::embedSignal : Problem creating data tree for embedding."<addSPlotNtupleIntegerBranch("iExpt"); this->addSPlotNtupleIntegerBranch("iEvtWithinExpt"); // Store the efficiency of the event (for inclusive BF calculations). if (this->storeDPEff()) { this->addSPlotNtupleDoubleBranch("efficiency"); } // Store the total event likelihood for each species. this->addSPlotNtupleDoubleBranch("sigTotalLike"); // Store the DP likelihoods if (this->useDP()) { this->addSPlotNtupleDoubleBranch("sigDPLike"); } // Store the likelihoods for each extra PDF const LauPdfList* pdfList( &(sigExtraPdf_.begin()->second) ); this->addSPlotNtupleBranches(pdfList, "sig"); } void LauTimeDepNonFlavModel::addSPlotNtupleBranches(const LauPdfList* extraPdfs, const TString& prefix) { if (!extraPdfs) { return; } // Loop through each of the PDFs for (LauPdfList::const_iterator pdf_iter = extraPdfs->begin(); pdf_iter != extraPdfs->end(); ++pdf_iter) { // Count the number of input variables that are not // DP variables (used in the case where there is DP // dependence for e.g. MVA) UInt_t nVars(0); for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { ++nVars; } } if ( nVars == 1 ) { // If the PDF only has one variable then // simply add one branch for that variable TString varName = (*pdf_iter)->varName(); TString name(prefix); name += varName; name += "Like"; this->addSPlotNtupleDoubleBranch(name); } else if ( nVars == 2 ) { // If the PDF has two variables then we // need a branch for them both together and // branches for each TString allVars(""); for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { allVars += (*var_iter); TString name(prefix); name += (*var_iter); name += "Like"; this->addSPlotNtupleDoubleBranch(name); } TString name(prefix); name += allVars; name += "Like"; this->addSPlotNtupleDoubleBranch(name); } else { std::cerr<<"WARNING in LauTimeDepNonFlavModel::addSPlotNtupleBranches : Can't yet deal with 3D PDFs."<begin(); pdf_iter != extraPdfs->end(); ++pdf_iter) { // calculate the likelihood for this event (*pdf_iter)->calcLikelihoodInfo(iEvt); extraLike = (*pdf_iter)->getLikelihood(); totalLike *= extraLike; // Count the number of input variables that are not // DP variables (used in the case where there is DP // dependence for e.g. MVA) UInt_t nVars(0); for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { ++nVars; } } if ( nVars == 1 ) { // If the PDF only has one variable then // simply store the value for that variable TString varName = (*pdf_iter)->varName(); TString name(prefix); name += varName; name += "Like"; this->setSPlotNtupleDoubleBranchValue(name, extraLike); } else if ( nVars == 2 ) { // If the PDF has two variables then we // store the value for them both together // and for each on their own TString allVars(""); for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { allVars += (*var_iter); TString name(prefix); name += (*var_iter); name += "Like"; Double_t indivLike = (*pdf_iter)->getLikelihood( (*var_iter) ); this->setSPlotNtupleDoubleBranchValue(name, indivLike); } TString name(prefix); name += allVars; name += "Like"; this->setSPlotNtupleDoubleBranchValue(name, extraLike); } else { std::cerr<<"WARNING in LauAllFitModel::setSPlotNtupleBranchValues : Can't yet deal with 3D PDFs."<useDP()) { nameSet.insert("DP"); } LauPdfList pdfList( (sigExtraPdf_.begin()->second) ); for (LauPdfList::const_iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) { // Loop over the variables involved in each PDF for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { // If they are not DP coordinates then add them if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { nameSet.insert( (*var_iter) ); } } } return nameSet; } LauSPlot::NumbMap LauTimeDepNonFlavModel::freeSpeciesNames() const { LauSPlot::NumbMap numbMap; if (!signalEvents_->fixed() && this->doEMLFit()) { numbMap["sig"] = signalEvents_->genValue(); } return numbMap; } LauSPlot::NumbMap LauTimeDepNonFlavModel::fixdSpeciesNames() const { LauSPlot::NumbMap numbMap; if (signalEvents_->fixed() && this->doEMLFit()) { numbMap["sig"] = signalEvents_->genValue(); } return numbMap; } LauSPlot::TwoDMap LauTimeDepNonFlavModel::twodimPDFs() const { LauSPlot::TwoDMap twodimMap; const LauPdfList* pdfList = &(sigExtraPdf_.begin()->second); for (LauPdfList::const_iterator pdf_iter = pdfList->begin(); pdf_iter != pdfList->end(); ++pdf_iter) { // Count the number of input variables that are not DP variables UInt_t nVars(0); for ( std::vector::const_iterator var_iter = (*pdf_iter)->varNames().begin(); var_iter != (*pdf_iter)->varNames().end(); ++var_iter ) { if ( (*var_iter) != "m13Sq" && (*var_iter) != "m23Sq" ) { ++nVars; } } if ( nVars == 2 ) { twodimMap.insert( std::make_pair( "sig", std::make_pair( (*pdf_iter)->varNames()[0], (*pdf_iter)->varNames()[1] ) ) ); } } return twodimMap; } void LauTimeDepNonFlavModel::storePerEvtLlhds() { std::cout<<"INFO in LauTimeDepNonFlavModel::storePerEvtLlhds : Storing per-event likelihood values..."<fitData(); // if we've not been using the DP model then we need to cache all // the info here so that we can get the efficiency from it if (!this->useDP() && this->storeDPEff()) { sigModelB0bar_f_->initialise(coeffsB0bar_f_); sigModelB0_f_->initialise(coeffsB0_f_); sigModelB0bar_fbar_->initialise(coeffsB0bar_fbar_); sigModelB0_fbar_->initialise(coeffsB0_fbar_); sigModelB0bar_f_->fillDataTree(*inputFitData); sigModelB0_f_->fillDataTree(*inputFitData); sigModelB0bar_fbar_->fillDataTree(*inputFitData); sigModelB0_fbar_->fillDataTree(*inputFitData); } UInt_t evtsPerExpt(this->eventsPerExpt()); LauIsobarDynamics* sigModel(sigModelB0bar_f_); for (UInt_t iEvt = 0; iEvt < evtsPerExpt; ++iEvt) { // Find out whether we have B0bar or B0 curEvtTagFlv_ = evtTagFlvVals_[iEvt]; curEvtTagCat_ = evtTagCatVals_[iEvt]; LauTagCatPdfMap::iterator sig_iter = sigExtraPdf_.find(curEvtTagCat_); LauPdfList* sigPdfs = (sig_iter != sigExtraPdf_.end())? &(sig_iter->second) : 0; // the DP information this->getEvtDPDtLikelihood(iEvt); if (this->storeDPEff()) { if (!this->useDP()) { sigModel->calcLikelihoodInfo(iEvt); } this->setSPlotNtupleDoubleBranchValue("efficiency",sigModel->getEvtEff()); } if (this->useDP()) { sigTotalLike_ = sigDPLike_; this->setSPlotNtupleDoubleBranchValue("sigDPLike",sigDPLike_); } else { sigTotalLike_ = 1.0; } // the signal PDF values sigTotalLike_ *= this->setSPlotNtupleBranchValues(sigPdfs, "sig", iEvt); // the total likelihoods this->setSPlotNtupleDoubleBranchValue("sigTotalLike",sigTotalLike_); // fill the tree this->fillSPlotNtupleBranches(); } std::cout<<"INFO in LauTimeDepNonFlavModel::storePerEvtLlhds : Finished storing per-event likelihood values."<