Page MenuHomeHEPForge

No OneTemporary

Index: branches/timedep-branch/src/LauFlavTag.cc
===================================================================
--- branches/timedep-branch/src/LauFlavTag.cc (revision 466)
+++ branches/timedep-branch/src/LauFlavTag.cc (revision 467)
@@ -1,328 +1,328 @@
// 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<LauParameter*>& 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();
}
LauParameter* LauFlavTag::findParameter(const TString& parName)
{
for ( std::vector<LauParameter*>::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;
}
Double_t LauFlavTag::getOmega(Int_t ievt)
{
return calib_p0_->value() + calib_p1_->value()*( evtMistagVals_[ievt] - perEvtAvgMistag_);
}
std::vector<LauParameter*> LauFlavTag::getCalibParameters()
{
std::vector<LauParameter*> calibParams;
- this->findParameter("calib_p0");
- this->findParameter("calib_p1");
+ calib_p0_ = this->findParameter("calib_p0");
+ calib_p1_ = this->findParameter("calib_p1");
calibParams.push_back( calib_p0_ );
calibParams.push_back( calib_p1_ );
if (calibParams.size() != 2) {
std::cout << "FATAL in LauFlavTag::setCalibParams : Expected two calibration parameters, received " << calibParams.size() << "." << std::endl;
exit(1);
}
return calibParams;
}

File Metadata

Mime Type
text/x-diff
Expires
Tue, Nov 19, 8:50 PM (1 d, 2 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3806160
Default Alt Text
(12 KB)

Event Timeline