diff --git a/inc/LauFlavTag.hh b/inc/LauFlavTag.hh index 5e03dac..96664a0 100644 --- a/inc/LauFlavTag.hh +++ b/inc/LauFlavTag.hh @@ -1,539 +1,540 @@ /* Copyright 2017 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 LauFlavTag.hh \brief File containing declaration of LauFlavTag class. */ /*! \class LauFlavTag \brief Class for defining the flavour tagging approach. Define the flavour tagging categories and all associated parameters to be passed to the relevant fit models. */ #ifndef LAU_FLAVTAG #define LAU_FLAVTAG #include #include #include "TString.h" #include "LauParameter.hh" class LauAbsPdf; class LauFitDataTree; class LauFlavTag final { public: //! Define sign convention for B and Bbar flavours enum Flavour { Bbar = -1, //< Bbar flavour Unknown = 0, //< Unknown flavour B = +1 //< B flavour }; //! Define different types of background to control the behaviour for each source // TODO Might want to move this somewhere more general later enum class BkgndType { Combinatorial, //< combinatorial background FlavourSpecific, //< flavour-specific decay (i.e. the flavour of the parent can be determined from the decay products), e.g. B0 -> K+ pi- pi0 SelfConjugate, //< decays where both B and Bbar can decay to a single self-conjugate final state, e.g. B0 -> pi+ pi- K_S0 NonSelfConjugate //< decays where both B and Bbar can decay to either of two final states that are conjugates of each other, e.g. B0 -> K+ pi- K_S0 and B0 -> K- pi+ K_S0 }; //! Constructor /*! \param [in] useAveDelta use average and delta variables for tagging calibration and efficiency \param [in] useEtaPrime use eta prime rather the eta as the mistag throughout \param [in] bkgndInfo map containing names and types of the background sources (if applicable) */ LauFlavTag(const Bool_t useAveDelta = kFALSE, const Bool_t useEtaPrime = kFALSE, const std::map bkgndInfo={}); //! Initialise // TODO is this needed? Commented for the moment (here and where called in LauTimeDepFitModel) //void initialise(); // TODO - need to decide which functions need to be public (interface) and which should be private (implementation details) // - improve/extend Doxygen comments //! Change the dilutions, delta dilutions and tagCatFrac for signal if needed /*! \param [in] name the name of the tagger \param [in] tagVarName the tagging variable name of the tagger in the ntuple \param [in] mistagVarName the associated mistag variable name of the same tagger in the ntuple \param [in] etapdf the mistag distribution for the tagger \param [in] tagEff tagging efficiency - (particle, antiparticle) or (average, delta) depending on useAveDelta_ flag \param [in] calib_p0 calibration parameter p0 - (particle, antiparticle) or (average, delta) depending on useAveDelta_ flag \param [in] calib_p1 calibration parameter p1 - (particle, antiparticle) or (average, delta) depending on useAveDelta_ flag */ void addTagger(const TString& name, const TString& tagVarName, const TString& mistagVarName, LauAbsPdf* etapdf, const std::pair tagEff, const std::pair calib_p0, const std::pair calib_p1); //! Change the dilutions, delta dilutions and tagCatFrac for signal if needed /*! \param [in] name the name of the tagger \param [in] tagVarName the tagging variable name of the tagger in the ntuple \param [in] mistagVarName the associated mistag variable name of the same tagger in the ntuple \param [in] etapdf the mistag distribution for the tagger \param [in] tagEff tagging efficiency histograms - (particle, antiparticle) or (average, delta) depending on useAveDelta_ flag \param [in] calib_p0 calibration parameter p0 - (particle, antiparticle) or (average, delta) depending on useAveDelta_ flag \param [in] calib_p1 calibration parameter p1 - (particle, antiparticle) or (average, delta) depending on useAveDelta_ flag */ void addTagger(const TString& name, const TString& tagVarName, const TString& mistagVarName, LauAbsPdf* etapdf, const std::pair tagEff, const std::pair calib_p0, const std::pair calib_p1); //! Read in the input fit data variables /*! \param [in] inputFitData the data source \param [in] decayTimeVarName the name of the decay time variable within the input data (used if the tagging efficiencies depend on decay time) */ void cacheInputFitVars(LauFitDataTree* inputFitData, const TString& decayTimeVarName=""); //! Generate values for the signal tag decisions and mis-tag probabilities /*! \param [in] trueTagFlv the true tag flavour \param [in] curEvtDecayTime the generated decay time value (used if the tagging efficiencies depend on decay time) */ void generateEventInfo(const Flavour trueTagFlv, const Double_t curEvtDecayTime); //! Generate values for the background tag decisions and mis-tag probabilities /*! \param [in] bkgndID the background category ID for which to generate \param [in] trueTagFlv the true tag flavour \param [in] trueDecayFlv the true decay flavour (if known) \param [in] curEvtDecayTime the generated decay time value (used if the tagging efficiencies depend on decay time) */ void generateBkgndEventInfo(const std::size_t bkgndID, const Flavour trueTagFlv, const Flavour trueDecayFlv, const Double_t curEvtDecayTime); //! Retrieve the cached info for a given event /*! \param [in] iEvt the event to retrieve */ void updateEventInfo(const std::size_t iEvt); //! Retrieve the name of the true tag variable const TString& getTrueTagVarName() const {return trueTagVarName_;}; //! Retrieve the name of the decay flavour variable const TString& getDecayFlvVarName() const {return decayFlvVarName_;}; //! Retrieve the names of the tag decision variables for each tagger const std::vector& getTagVarNames() const {return tagVarNames_;}; //! Retrieve the names of the mis-tag probability variables for each tagger const std::vector& getMistagVarNames() const {return mistagVarNames_;}; //! Retrieve the current value of the true tag variable Flavour getCurEvtTrueTagFlv() const {return curEvtTrueTagFlv_;}; //! Retrieve the current value of the decay flavour variable Flavour getCurEvtDecayFlv() const {return curEvtDecayFlv_;}; //! Retrieve the current values of the tag decision variables for each tagger const std::vector& getCurEvtTagFlv() const {return curEvtTagFlv_;}; //! Retrieve the current values of the mis-tag probability variables for each tagger const std::vector& getCurEvtMistag() const {return curEvtMistag_;}; //! Retrieve the number of taggers std::size_t getNTaggers() const {return tagVarNames_.size();} //! Get vector of calibration p0 for B0 parameters for each tagger std::vector getCalibP0B0(){return calib_p0_B0_;}; //! Get vector of calibration p0 for B0bar parameters for each tagger std::vector getCalibP0B0bar(){return calib_p0_B0bar_;}; //! Get vector of calibration p1 for B0 parameters for each tagger std::vector getCalibP1B0(){return calib_p1_B0_;}; //! Get vector of calibration p1 for B0bar parameters for each tagger std::vector getCalibP1B0bar(){return calib_p1_B0bar_;}; //! Get vector of calibration p0 average parameters for each tagging category std::vector getCalibP0Ave(){return calib_p0_ave_;}; //! Get vector of calibration p0 difference parameters for each tagging category std::vector getCalibP0Delta(){return calib_p0_delta_;}; //! Get vector of calibration p1 average parameters for each tagging category std::vector getCalibP1Ave(){return calib_p1_ave_;}; //! Get vector of calibration p1 difference parameters for each tagging category std::vector getCalibP1Delta(){return calib_p1_delta_;}; //! Get vector of tagging efficiency for B0 parameters for each tagging category std::vector getTagEffB0(){return tagEff_B0_;}; //! Get vector of tagging efficiency for B0bar parameters for each tagging category std::vector getTagEffB0bar(){return tagEff_B0bar_;}; //! Get vector of tagging efficiency average parameters for each tagging category std::vector getTagEffAve(){return tagEff_ave_;}; //! Get vector of tagging efficiency difference parameters for each tagging category std::vector getTagEffDelta(){return tagEff_delta_;}; //! Get 2D vector of background tagging efficiency for B0 parameters for each tagger (inner vec) and background source (outer vec) auto getTagEffBkgndB0(){return tagEffBkgnd_B0_;}; //! Get 2D vector of background tagging efficiency for B0bar parameters for each tagger (inner vec) and background source (outer vec) auto getTagEffBkgndB0bar(){return tagEffBkgnd_B0bar_;}; //! Get 2D vector of background tagging efficiency average parameters for each tagger (inner vec) and background source (outer vec) auto getTagEffBkgndAve(){return tagEffBkgnd_ave_;}; //! Get 2D vector of background tagging efficiency difference parameters for each tagger (inner vec) and background source (outer vec) auto getTagEffBkgndDelta(){return tagEffBkgnd_delta_;}; //! Set background parameters for a given background and given tagger /*! Set the eta (mis-tag probability) distribution and tagging efficiency constants for B and Bbar \param [in] bkgndName background category name \param [in] taggerName name of the tagger \param [in] etaPdf the eta PDF itself \param [in] tagEff the tagging efficiency parameters */ void setBkgndParams(const TString& bkgndName, const TString& taggerName, LauAbsPdf* etaPdf, std::pair tagEff); //! Set background parameters for a given background and given tagger /*! Set the eta (mis-tag probability) distribution and tagging efficiencies (as a function of decay time) for B and Bbar \param [in] bkgndName background category name \param [in] taggerName name of the tagger \param [in] etaPdf the eta PDF itself \param [in] tagEff the tagging efficiency histograms */ void setBkgndParams(const TString& bkgndName, const TString& taggerName, LauAbsPdf* etaPdf, std::pair tagEff); //! Set background parameters for a given background and given tagger /*! Set the eta (mis-tag probability) distribution and tagging efficiency constants for B and Bbar This version provides different parameters for each decay flavour (used for Combinatorial background in QFS modes) \param [in] bkgndName background category name \param [in] taggerName name of the tagger \param [in] etaPdfB the eta PDF for decay flavour = B \param [in] tagEffB the tagging efficiency parameters for decay flavour = B \param [in] etaPdfBbar the eta PDF for decay flavour = Bbar \param [in] tagEffBbar the tagging efficiency parameters for decay flavour = Bbar */ void setBkgndParams(const TString& bkgndName, const TString& taggerName, LauAbsPdf* etaPdfB, std::pair tagEffB, LauAbsPdf* etaPdfBbar, std::pair tagEffBbar); //! Set background parameters for a given background and given tagger /*! Set the eta (mis-tag probability) distribution and tagging efficiencies (as a function of decay time) for B and Bbar This version provides different parameters for each decay flavour (used for Combinatorial background in QFS modes) \param [in] bkgndName background category name \param [in] taggerName name of the tagger \param [in] etaPdfB the eta PDF for decay flavour = B \param [in] tagEffB the tagging efficiency histograms for decay flavour = B \param [in] etaPdfBbar the eta PDF for decay flavour = Bbar \param [in] tagEffBbar the tagging efficiency histograms for decay flavour = Bbar */ void setBkgndParams(const TString& bkgndName, const TString& taggerName, LauAbsPdf* etaPdfB, std::pair tagEffB, LauAbsPdf* etaPdfBbar, std::pair tagEffBbar); //! Returns little omega (calibrated mistag) /*! \param [in] taggerID index of the tagger in the taggers vectors \param [in] flag choose to calculate omega or omegabar (corrsonding to B or Bbar) */ Double_t getLittleOmega(const std::size_t taggerID, const Flavour flag) const; //! Capital Omega for signal decays /*! \param [in] taggerID index of the tagger in the taggers vectors \param [in] flag choose to calculate Omega or Omegabar (corrsonding to B or Bbar) */ Double_t getCapitalOmega(const std::size_t taggerID, const Flavour flag) const; //! Returns little omega (calibrated mistag) for backgrounds /*! \param [in] bkgndID index of the background vector \param [in] taggerID index of the tagger in the taggers vectors \param [in] flag choose to calculate omega or omegabar (corrsonding to B or Bbar) \param [in] decayFlv the decay flavour of the B */ Double_t getLittleOmegaBkgnd(const std::size_t bkgndID, const std::size_t taggerID, const Flavour flag, const Flavour decayFlv) const; //! Capital Omega for backgrounds /*! \param [in] bkgndID index of the background vector \param [in] taggerID index of the tagger in the taggers vectors \param [in] flag choose to calculate Omega or Omegabar (corrsonding to B or Bbar) \param [in] decayFlv the decay flavour of the B */ Double_t getCapitalOmegaBkgnd(const std::size_t bkgndID, const std::size_t taggerID, const Flavour flag, const Flavour decayFlv) const; //! Get the generated value of signal eta for the given tagger /*! \param [in] taggerID index of the tagger in the taggers vectors */ Double_t getEtaGen(const std::size_t taggerID); //! Get the generated value of background eta for the given tagger and background category /*! \param [in] taggerID index of the tagger in the taggers vectors \param [in] bkgndID index of the background in the backgrounds vectors + \param [in] decayFlv the decay flavour of the B */ Double_t getEtaGenBkgnd(const std::size_t taggerID, const std::size_t bkgndID, const Flavour decayFlv); //! Return the Boolean controlling if we use the alternative tagging calibration and efficiency parameters Bool_t getUseAveDelta() const {return useAveDelta_;}; //! Specify the name of the true tag variable /*! \param [in] trueTagVarName the name of the true tag variable */ void setTrueTagVarName(TString trueTagVarName); //! Specify the name of the decay flavour variable /*! \param [in] decayFlvVarName the name of the decay flavour variable */ void setDecayFlvVarName(TString decayFlvVarName); //! Gaussian constraints for P0 parameters for a given tagger /*! \param [in] taggerName name of the tagger \param [in] constraint1 the (mean, sigma) for the particle or average parameter \param [in] constraint2 the (mean, sigma) for the antiparticle or delta parameter */ void addP0GaussianConstraints(const TString& taggerName, const std::pair constraint1, const std::pair constraint2); //! Gaussian constraints for P1 parameters for a given tagger /*! \param [in] taggerName name of the tagger \param [in] constraint1 the (mean, sigma) for the particle or average parameter \param [in] constraint2 the (mean, sigma) for the antiparticle or delta parameter */ void addP1GaussianConstraints(const TString& taggerName, const std::pair constraint1, const std::pair constraint2); //! Gaussian constraints for tagging efficiency parameters for a given tagger /*! \param [in] taggerName name of the tagger \param [in] constraint1 the (mean, sigma) for the particle or average parameter \param [in] constraint2 the (mean, sigma) for the antiparticle or delta parameter */ void addTagEffGaussianConstraints(const TString& taggerName, const std::pair constraint1, const std::pair constraint2); //! Retrieve the names of the background categories std::vector getBkgndNames(); //! Retrieve the types of the background categories std::vector getBkgndTypes(){return bkgndTypes_;} //! Float the P0 calibration parameters for B tags /*! \param [in] taggerName name of the tagger, defaults to empty to float for all taggers */ void floatCalibParP0B0(const TString& taggerName = ""); //! Float the P1 calibration parameters for B tags /*! \param [in] taggerName name of the tagger, defaults to empty to float for all taggers */ void floatCalibParP1B0(const TString& taggerName = ""); //! Float the P0 calibration parameters for Bbar tags /*! \param [in] taggerName name of the tagger, defaults to empty to float for all taggers */ void floatCalibParP0B0bar(const TString& taggerName = ""); //! Float the P1 calibration parameters for Bbar tags /*! \param [in] taggerName name of the tagger, defaults to empty to float for all taggers */ void floatCalibParP1B0bar(const TString& taggerName = ""); //! Float the P0 average calibration parameters /*! \param [in] taggerName name of the tagger, defaults to empty to float for all taggers */ void floatCalibParP0Ave(const TString& taggerName = ""); //! Float the P0 delta calibration parameters /*! \param [in] taggerName name of the tagger, defaults to empty to float for all taggers */ void floatCalibParP0Delta(const TString& taggerName = ""); //! Float the P1 average calibration parameters /*! \param [in] taggerName name of the tagger, defaults to empty to float for all taggers */ void floatCalibParP1Ave(const TString& taggerName = ""); //! Float the P1 delta calibration parameters /*! \param [in] taggerName name of the tagger, defaults to empty to float for all taggers */ void floatCalibParP1Delta(const TString& taggerName = ""); //! Float all calibration parameters void floatAllCalibPars(); //! Update pulls on all floating parameters void updatePulls(); private: //! Internal function to extend vectors void extendVectors(const TString& tagVarName, const TString& mistagVarName); //! Internal function to setup Calib parameters void setupCalibParams(const TString& taggerName, const std::pair calib_p0, const std::pair calib_p1); //! Internal function to find parameters in per-tagger vectors LauParameter* findParameter( const TString& taggerName, std::vector& parameters ); //! Flag to use alternative calibration parameters const Bool_t useAveDelta_; //! Flag to use eta prime not eta for the mistag const Bool_t useEtaPrime_; //! Map to link tagger names to their index in all the vectors std::map taggerIndex_; //! Map to link background names to their index in all the vectors std::map bkgndIndex_; //! Flavour tagging variable name std::vector tagVarNames_; //! Per event mistag variable name std::vector mistagVarNames_; //! True tag variable name for normalisation decays TString trueTagVarName_; //! Decay flavour tag variable name for normalisation decays TString decayFlvVarName_; //! Vector of background types std::vector bkgndTypes_; //! Vector of flags indicating if the background parameters depend on the decay flavour std::vector bkgndDecayFlvDep_; //! Vector of flavour tags for each event std::vector> evtTagFlv_; //! Flavour tag for current event std::vector curEvtTagFlv_; //! Vector of mistags for each event std::vector> evtMistag_; //! Per event mistag for current event std::vector curEvtMistag_; //! Vector of true tags for each event std::vector evtTrueTagFlv_; //! Vector of decay tags for each event std::vector evtDecayFlv_; //! True tag from normalisation mode for current event Flavour curEvtTrueTagFlv_{Flavour::Unknown}; //! True tag from normalisation mode for current event Flavour curEvtDecayFlv_{Flavour::Unknown}; //! Average background mistag value (eta hat) std::vector>> avgMistagBkgnd_; //! Per-event average mistag value (eta hat) std::vector perEvtAvgMistag_; //! Decay time values for each event std::vector evtDecayTime_; //! Decay time value of the current event Double_t curEvtDecayTime_; //! Calibration parameters p0 for B0 std::vector calib_p0_B0_; //! Calibration parameters p0 for B0bar std::vector calib_p0_B0bar_; //! Calibration parameters p1 for B0 std::vector calib_p1_B0_; //! Calibration parameters p1 for B0bar std::vector calib_p1_B0bar_; //! Alternative calibration parameters p0 average std::vector calib_p0_ave_; //! Alternative calibration parameters p0 difference std::vector calib_p0_delta_; //! Alternative calibration parameters p1 average std::vector calib_p1_ave_; //! Alternative calibration parameters p1 difference std::vector calib_p1_delta_; //! Tagging efficiency parameters for B0 std::vector tagEff_B0_; //! Tagging efficiency parameters for B0bar std::vector tagEff_B0bar_; //! Tagging efficiency parameters average of B0 and B0bar std::vector tagEff_ave_; //! Tagging efficiency parameters difference between B0 and B0bar std::vector tagEff_delta_; //! Tagging efficiency histograms for B0 std::vector tagEff_hist_B0_; //! Tagging efficiency histograms for B0bar std::vector tagEff_hist_B0bar_; //! Tagging efficiency histograms average of B0 and B0bar std::vector tagEff_hist_ave_; //! Tagging efficiency histograms difference between B0 and B0bar std::vector tagEff_hist_delta_; //! Background tagging efficiency parameters for B0 std::vector>> tagEffBkgnd_B0_; //! Background tagging efficiency parameters for B0bar std::vector>> tagEffBkgnd_B0bar_; //! Background tagging efficiency parameters average of B0 and B0bar std::vector>> tagEffBkgnd_ave_; //! Background tagging efficiency parameters difference between B0 and B0bar std::vector>> tagEffBkgnd_delta_; //! Background tagging efficiency histograms for B0 std::vector>> tagEffBkgnd_hist_B0_; //! Background tagging efficiency histograms for B0bar std::vector>> tagEffBkgnd_hist_B0bar_; //! Background tagging efficiency histograms average of B0 and B0bar std::vector>> tagEffBkgnd_hist_ave_; //! Background tagging efficiency histograms difference between B0 and B0bar std::vector>> tagEffBkgnd_hist_delta_; //! Eta PDFs std::vector etaPdfs_; //! Eta PDFs for backgrounds per tagger (inner vec) and per background source (outer vec) std::vector>> etaBkgndPdfs_; ClassDef(LauFlavTag,0) // Flavour tagging set up }; //! output stream operator /*! \param [in,out] stream the output stream to which the background type is to be printed \param [in] bkgndType the type to be written out return the output stream */ std::ostream& operator<<( std::ostream& stream, const LauFlavTag::BkgndType bkgndType ); #endif