Page MenuHomeHEPForge

No OneTemporary

diff --git a/inc/LauFlavTag.hh b/inc/LauFlavTag.hh
index 677eb6c..23f354e 100644
--- a/inc/LauFlavTag.hh
+++ b/inc/LauFlavTag.hh
@@ -1,188 +1,188 @@
// Copyright University of Warwick 2006 - 2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// Authors:
// Thomas Latham
// John Back
// Paul Harrison
/*! \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 <vector>
#include <map>
#include <set>
#include <iostream>
#include "TString.h"
#include "TStopwatch.h"
#include "TSystem.h"
#include "LauConstants.hh"
#include "LauParameter.hh"
#include "LauFitDataTree.hh"
#include "LauAbsFitModel.hh"
class LauFlavTag {
public:
//! 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
*/
LauFlavTag(const std::vector<LauAbsRValue*>& params, const Bool_t useUntaggedEvents = kTRUE, const TString& tagVarName = "tagFlv", const TString& tagCatVarName = "tagCat");
//! Destructor
virtual ~LauFlavTag();
//! 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<Int_t>& tagCats);
//! Check the validity of the given tagging category
/*!
\param [in] tagCat the tagging category ID
*/
Bool_t validTagCat(const Int_t tagCat) const;
//! 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
\param [in] usePerEvtMistag whether to use per event mistag information or not
\param [in] mistagVarName the name of the branch in the tree containing per event mistag information
*/
void setSignalTagCatPars(const Int_t tagCat, const Double_t tagCatFrac, const Double_t dilution, const Double_t deltaDilution,
const Bool_t fixTCFrac = kTRUE, const Bool_t usePerEvtMistag = kFALSE, const TString& mistagVarName = "tagMistag");
//! Read in the input fit data variables, e.g. m13Sq and m23Sq
void cacheInputFitVars(LauFitDataTree* inputFitData);
Bool_t getUsePerEvtMistag(){return usePerEvtMistag_;};
typedef std::map< Int_t, LauParameter> LauTagCatParamMap;
LauTagCatParamMap getDilution(){return dilution_;};
LauTagCatParamMap getDeltaDilution(){return deltaDilution_;};
LauTagCatParamMap& getSignalTagCatFrac(){return signalTagCatFrac_;};
//! 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);
std::vector<Int_t> getEvtTagFlvVals(){return evtTagFlvVals_;};
std::vector<Int_t> getEvtTagCatVals(){return evtTagCatVals_;};
std::vector<Double_t> getEvtMistagVals(){return evtMistagVals_;};
TString getMistagVarName(){return mistagVarName_;};
LauAbsRValue* findParameter(const TString& parName);
- std::vector<LauParameter*> getFitParameters();
+ std::vector<LauParameter*> getCalibParameters();
Double_t getPerEvtAvgMistag(){return perEvtAvgMistag_;};
protected:
//! 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();
private:
//! Whether or not to use untagged events
const Bool_t useUntaggedEvents_;
//! Signal tagging category fractions
LauTagCatParamMap signalTagCatFrac_;
//! Flavour tagging variable name
TString tagVarName_;
//! Tagging category variable name
TString tagCatVarName_;
//! Per event mistag variable name
TString mistagVarName_;
//! The allowed tagging categories
std::set<Int_t> validTagCats_;
//! 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_;
//! Vector to store event flavour tags
std::vector<Int_t> evtTagFlvVals_;
//! Vector to store event tagging categories
std::vector<Int_t> evtTagCatVals_;
//! Vector to store event mistag values
std::vector<Double_t> evtMistagVals_;
//! Average dilutions
LauTagCatParamMap dilution_;
//! Dilution differences
LauTagCatParamMap deltaDilution_;
//! Use per event mistag
Bool_t usePerEvtMistag_;
//! Per-event average mistag value (eta hat)
Double_t perEvtAvgMistag_;
//! Calibration parameters
LauParameter* calib_p0_;
LauParameter* calib_p1_;
//! Input parameters
std::vector<LauAbsRValue*> params_;
ClassDef(LauFlavTag,0) // Flaour tagging set up
};
#endif
diff --git a/src/LauFlavTag.cc b/src/LauFlavTag.cc
index dfd1d77..4b433ab 100644
--- a/src/LauFlavTag.cc
+++ b/src/LauFlavTag.cc
@@ -1,319 +1,319 @@
// Copyright University of Warwick 2006 - 2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// Authors:
// Thomas Latham
// John Back
// Paul Harrison
/*! \file LauFlavTag.cc
\brief File containing implementation of LauFlavTag class.
*/
#include <iostream>
#include <iomanip>
#include <fstream>
#include <map>
#include <vector>
#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 "LauFlavTag.hh"
ClassImp(LauFlavTag)
LauFlavTag::LauFlavTag(const std::vector<LauAbsRValue*>& params, const Bool_t useUntaggedEvents, const TString& tagVarName, const TString& tagCatVarName) :
useUntaggedEvents_(useUntaggedEvents),
signalTagCatFrac_(),
tagVarName_(tagVarName),
tagCatVarName_(tagCatVarName),
mistagVarName_("tagMistag"),
validTagCats_(),
curEvtTagFlv_(0),
curEvtTagCat_(0),
curEvtMistag_(0.),
evtTagFlvVals_(0),
evtTagCatVals_(0),
evtMistagVals_(0),
dilution_(),
deltaDilution_(),
usePerEvtMistag_(kFALSE),
perEvtAvgMistag_(),
calib_p0_(),
calib_p1_(),
params_(params)
{
// 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);
}
LauFlavTag::~LauFlavTag()
{
}
void LauFlavTag::addValidTagCats(const std::vector<Int_t>& tagCats)
{
for (std::vector<Int_t>::const_iterator iter = tagCats.begin(); iter != tagCats.end(); ++iter) {
this->addValidTagCat(*iter);
}
}
void LauFlavTag::addValidTagCat(const Int_t tagCat)
{
validTagCats_.insert(tagCat);
}
void LauFlavTag::setSignalTagCatPars(const Int_t tagCat, const Double_t tagCatFrac, const Double_t dilution, const Double_t deltaDilution, const Bool_t fixTCFrac, const Bool_t usePerEvtMistag, const TString& mistagVarName)
{
if (!this->validTagCat(tagCat)) {
std::cerr<<"ERROR in LauFlavTag::setSignalTagCatPars : Tagging category \""<<tagCat<<"\" not valid, not changing the parameters."<<std::endl;
return;
}
TString tagCatFracName("signalTagCatFrac");
tagCatFracName += tagCat;
signalTagCatFrac_[tagCat].name(tagCatFracName);
signalTagCatFrac_[tagCat].range(0.0,1.0);
signalTagCatFrac_[tagCat].value(tagCatFrac); signalTagCatFrac_[tagCat].initValue(tagCatFrac); signalTagCatFrac_[tagCat].genValue(tagCatFrac);
signalTagCatFrac_[tagCat].fixed(fixTCFrac);
TString dilutionName("dilution");
dilutionName += tagCat;
dilution_[tagCat].name(dilutionName);
dilution_[tagCat].range(0.0,1.0);
dilution_[tagCat].value(dilution); dilution_[tagCat].initValue(dilution); dilution_[tagCat].genValue(dilution);
dilution_[tagCat].fixed(kTRUE);
TString deltaDilutionName("deltaDilution");
deltaDilutionName += tagCat;
deltaDilution_[tagCat].name(deltaDilutionName);
deltaDilution_[tagCat].range(-2.0,2.0);
deltaDilution_[tagCat].value(deltaDilution); deltaDilution_[tagCat].initValue(deltaDilution); deltaDilution_[tagCat].genValue(deltaDilution);
deltaDilution_[tagCat].fixed(kTRUE);
if (usePerEvtMistag){
usePerEvtMistag_ = kTRUE;
mistagVarName_ = mistagVarName;
std::cout<<"INFO in LauFlavTag::setSignalTagCatPars : Using per event mistag information from branch "<<mistagVarName_<<" ."<<std::endl;
}
// We check they're set up correctly with checkSignalTagCatFractions()
// only when the user has set them all up, see initialise()
}
void LauFlavTag::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 LauFlavTag::checkSignalTagCatFractions : Tagging category fractions add up to "<<totalTaggedFrac<<", not 1.0; normalizing them."<<std::endl;
for (LauTagCatParamMap::iterator iter=signalTagCatFrac_.begin(); iter!=signalTagCatFrac_.end(); ++iter) {
LauParameter& par = iter->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);
dilution_[0].fixed(kTRUE);
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);
deltaDilution_[0].fixed(kTRUE);
}
for (LauTagCatParamMap::const_iterator iter=dilution_.begin(); iter!=dilution_.end(); ++iter) {
std::cout<<"INFO in LauFlavTag::checkSignalTagCatFractions : Setting dilution for tagging category "<<(*iter).first<<" to "<<(*iter).second<<std::endl;
}
for (LauTagCatParamMap::const_iterator iter=deltaDilution_.begin(); iter!=deltaDilution_.end(); ++iter) {
std::cout<<"INFO in LauFlavTag::checkSignalTagCatFractions : Setting Delta(dilution) for tagging category "<<(*iter).first<<" to "<<(*iter).second<<std::endl;
}
for (LauTagCatParamMap::const_iterator iter=signalTagCatFrac_.begin(); iter!=signalTagCatFrac_.end(); ++iter) {
std::cout<<"INFO in LauFlavTag::checkSignalTagCatFractions : Setting (signal) fraction for tagging category "<<(*iter).first<<" to "<<(*iter).second<<std::endl;
}
}
void LauFlavTag::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);
}
Bool_t LauFlavTag::validTagCat(Int_t tagCat) const
{
return (validTagCats_.find(tagCat) != validTagCats_.end());
}
Bool_t LauFlavTag::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 LauFlavTag::checkTagCatFracMap : Not all tagging categories present."<<std::endl;
return kFALSE;
}
// Now check that the fractions sum up to unity.
Double_t tagCatFracSum(0.0);
for (LauTagCatParamMap::const_iterator iter = theMap.begin(); iter != theMap.end(); ++iter) {
const LauParameter& par = (*iter).second;
tagCatFracSum += par.unblindValue();
}
if ((tagCatFracSum - 1.0) > 1E-10) {
std::cerr<<"ERROR in LauFlavTag::checkTagCatFracMap : Tagging category event fractions do not sum to unity."<<std::endl;
return kFALSE;
}
// If we've got to here then all is OK.
return kTRUE;
}
void LauFlavTag::cacheInputFitVars(LauFitDataTree* inputFitData)
{
// Fill event by event data
// Start by caching the tagging information
evtTagCatVals_.clear();
evtTagFlvVals_.clear();
evtMistagVals_.clear();
if ( ! inputFitData->haveBranch( tagCatVarName_ ) ) {
std::cerr << "ERROR in LauFlavTag::cacheInputFitVars : Input data does not contain branch \"" << tagCatVarName_ << "\"." << std::endl;
gSystem->Exit(EXIT_FAILURE);
}
if ( ! inputFitData->haveBranch( tagVarName_ ) ) {
std::cerr << "ERROR in LauFlavTag::cacheInputFitVars : Input data does not contain branch \"" << tagVarName_ << "\"." << std::endl;
gSystem->Exit(EXIT_FAILURE);
}
if ( ! inputFitData->haveBranch( mistagVarName_ ) ) {
std::cerr << "ERROR in LauFlavTag::cacheInputFitVars : Input data does not contain branch \"" << mistagVarName_ << "\"." << std::endl;
gSystem->Exit(EXIT_FAILURE);
}
UInt_t nEvents = inputFitData->nEvents();
evtTagCatVals_.reserve( nEvents );
evtTagFlvVals_.reserve( nEvents );
evtMistagVals_.reserve( nEvents );
//Running total to calc average mistag
Double_t tot_mistag(0.);
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<Int_t>( fitdata_iter->second );
if ( ! this->validTagCat( curEvtTagCat_ ) ) {
std::cerr << "WARNING in LauFlavTag::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<Int_t>( fitdata_iter->second );
if ( TMath::Abs( curEvtTagFlv_ ) != 1 ) {
if ( curEvtTagFlv_ > 0 ) {
std::cerr << "WARNING in LauFlavTag::cacheInputFitVars : Invalid tagging output " << curEvtTagFlv_ << " for event " << iEvt << ", setting it to +1" << std::endl;
curEvtTagFlv_ = +1;
} else {
std::cerr << "WARNING in LauFlavTag::cacheInputFitVars : Invalid tagging output " << curEvtTagFlv_ << " for event " << iEvt << ", setting it to -1" << std::endl;
curEvtTagFlv_ = -1;
}
}
evtTagFlvVals_.push_back( curEvtTagFlv_ );
fitdata_iter = dataValues.find( mistagVarName_);
curEvtMistag_ = static_cast<Double_t>( fitdata_iter->second );
if (curEvtMistag_ > 0.5){
std::cerr<<"WARNING in LauFlavTag::cacheInputFitVars : Mistag value "<<curEvtMistag_<<" is larger than 0.5, setting to 0.5"<<std::endl;
curEvtMistag_ = 0.5;
}
if (curEvtMistag_ < 0.0){
std::cerr<<"WARNING in LauFlavTag::cacheInputFitVars : Mistag value "<<curEvtMistag_<<" is less than 0.0, setting to 0.0"<<std::endl;
curEvtMistag_ = 0.0;
}
tot_mistag += curEvtMistag_;
evtMistagVals_.push_back( curEvtMistag_ );
}
// Store average per event mistag for calibration
perEvtAvgMistag_ = tot_mistag/nEvents;
// 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();
}
LauAbsRValue* LauFlavTag::findParameter(const TString& parName)
{
for ( std::vector<LauAbsRValue*>::iterator iter = params_.begin(); iter != params_.end(); ++iter ) {
if ((*iter)->name().Contains(parName)) {
return (*iter);
}
}
std::cerr << "ERROR in LauFlavTag::findParameter : Parameter \"" << parName << "\" not found." << std::endl;
return 0;
}
-std::vector<LauParameter*> LauFlavTag::getFitParameters()
+std::vector<LauParameter*> LauFlavTag::getCalibParameters()
{
this->findParameter("calib_p0");
this->findParameter("calib_p1");
std::vector<LauParameter*> param_list;
param_list.push_back( calib_p0_ );
param_list.push_back( calib_p1_ );
return param_list;
}

File Metadata

Mime Type
text/x-diff
Expires
Tue, Nov 19, 6:07 PM (1 d, 17 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3805508
Default Alt Text
(18 KB)

Event Timeline