CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/HiggsAnalysis/CombinedLimit/src/CombDataSetFactory.cc

Go to the documentation of this file.
00001 #include "../interface/CombDataSetFactory.h"
00002 #include "../interface/utils.h"
00003 
00004 #include <cmath>
00005 
00006 CombDataSetFactory::CombDataSetFactory(const RooArgSet &vars, RooCategory &cat) :
00007     vars_(vars), cat_(&cat), weight_(0)
00008 {
00009     if (vars_.contains(cat)) vars_.remove(cat);
00010 }
00011 
00012 CombDataSetFactory::~CombDataSetFactory() {}
00013 
00014 void CombDataSetFactory::addSetBin(const char *label, RooDataHist *set) {
00015     map_[label] = set;
00016 }
00017 
00018 void CombDataSetFactory::addSetAny(const char *label, RooDataHist *set) {
00019     if (weight_ == 0) weight_ = new RooRealVar("_weight_","",1);
00020     RooDataSet *data = new RooDataSet(TString(set->GetName())+"_unbin", "", RooArgSet(*set->get(), *weight_), "_weight_");
00021     for (int i = 0, n = set->numEntries(); i < n; ++i) {
00022         const RooArgSet *entry = set->get(i);
00023         data->add(*entry, set->weight());
00024     }
00025     mapUB_[label] = data;
00026 }
00027 
00028 
00029 void CombDataSetFactory::addSetAny(const char *label, RooDataSet *set) {
00030     mapUB_[label] = set;
00031 }
00032 
00033 
00034 RooDataHist *CombDataSetFactory::done(const char *name, const char *title) {
00035     return new RooDataHist(name,title,vars_,*cat_,map_);
00036     map_.clear();
00037 }
00038 
00039 RooDataSet *CombDataSetFactory::doneUnbinned(const char *name, const char *title) {
00040     using namespace RooFit; 
00041     RooDataSet *ret = 0;
00042     if (weight_) {
00043 #if 0   // This works most of the time, but sometimes weights end up wrong.
00044         // I don't knopw why the @$^#&^# this happens, but it nevertheless 
00045         // means that I can't use the constructor with the map directly
00046         //
00047         for (std::map<std::string, RooDataSet *>::iterator it = mapUB_.begin(), ed = mapUB_.end(); it != ed; ++it) {
00048             RooDataSet *data = it->second;
00049             if (!data->isWeighted()) {
00050                 weight_->setVal(1.0);
00051                 data->addColumn(*weight_);
00052                 it->second = new RooDataSet(data->GetName(), data->GetTitle(), data, *data->get(), /*cut=*/(char*)0, weight_->GetName());
00053             }
00054             //std::cout << "\n\n\n========== DATASET " << it->first << " =============" << std::endl;
00055             //utils::printRDH(it->second);
00056         }
00057         RooArgSet varsPlusWeight(vars_); varsPlusWeight.add(*weight_);
00058         ret = new RooDataSet(name,title,varsPlusWeight,Index(*cat_),Import(mapUB_),WeightVar(*weight_));
00059         //std::cout << "\n\n\n========== COMBINED DATASET =============" << std::endl;
00060         //utils::printRDH(ret);
00061 #else
00062         RooArgSet varsPlusCat(vars_); varsPlusCat.add(*cat_);
00063         RooArgSet varsPlusWeight(varsPlusCat); varsPlusWeight.add(*weight_);
00064         ret = new RooDataSet(name,title,varsPlusWeight,WeightVar(*weight_));
00065         for (std::map<std::string, RooDataSet *>::iterator it = mapUB_.begin(), ed = mapUB_.end(); it != ed; ++it) {
00066             //std::cout << "\n\n\n========== DATASET " << it->first << " =============" << std::endl;
00067             //utils::printRDH(it->second);
00068             cat_->setLabel(it->first.c_str());
00069             RooDataSet *data = it->second;
00070             for (unsigned int i = 0, n = data->numEntries(); i < n; ++i) {
00071                 varsPlusCat = *data->get(i);
00072                 ret->add(varsPlusCat, data->weight());
00073             }
00074         }
00075         //std::cout << "\n\n\n========== COMBINED DATASET =============" << std::endl;
00076         //utils::printRDH(ret);
00077 #endif
00078     } else {
00079         ret = new RooDataSet(name,title,vars_,Index(*cat_),Import(mapUB_));
00080     }
00081     mapUB_.clear();
00082     return ret;
00083 }
00084 
00085 
00086 ClassImp(CombDataSetFactory)