CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CombDataSetFactory.cc
Go to the documentation of this file.
1 #include "../interface/CombDataSetFactory.h"
2 #include "../interface/utils.h"
3 
4 #include <cmath>
5 
6 CombDataSetFactory::CombDataSetFactory(const RooArgSet &vars, RooCategory &cat) :
7  vars_(vars), cat_(&cat), weight_(0)
8 {
9  if (vars_.contains(cat)) vars_.remove(cat);
10 }
11 
13 
14 void CombDataSetFactory::addSetBin(const char *label, RooDataHist *set) {
15  map_[label] = set;
16 }
17 
18 void CombDataSetFactory::addSetAny(const char *label, RooDataHist *set) {
19  if (weight_ == 0) weight_ = new RooRealVar("_weight_","",1);
20  RooDataSet *data = new RooDataSet(TString(set->GetName())+"_unbin", "", RooArgSet(*set->get(), *weight_), "_weight_");
21  for (int i = 0, n = set->numEntries(); i < n; ++i) {
22  const RooArgSet *entry = set->get(i);
23  data->add(*entry, set->weight());
24  }
25  mapUB_[label] = data;
26 }
27 
28 
29 void CombDataSetFactory::addSetAny(const char *label, RooDataSet *set) {
30  mapUB_[label] = set;
31 }
32 
33 
34 RooDataHist *CombDataSetFactory::done(const char *name, const char *title) {
35  return new RooDataHist(name,title,vars_,*cat_,map_);
36  map_.clear();
37 }
38 
39 RooDataSet *CombDataSetFactory::doneUnbinned(const char *name, const char *title) {
40  using namespace RooFit;
41  RooDataSet *ret = 0;
42  if (weight_) {
43 #if 0 // This works most of the time, but sometimes weights end up wrong.
44  // I don't knopw why the @$^#&^# this happens, but it nevertheless
45  // means that I can't use the constructor with the map directly
46  //
47  for (std::map<std::string, RooDataSet *>::iterator it = mapUB_.begin(), ed = mapUB_.end(); it != ed; ++it) {
48  RooDataSet *data = it->second;
49  if (!data->isWeighted()) {
50  weight_->setVal(1.0);
51  data->addColumn(*weight_);
52  it->second = new RooDataSet(data->GetName(), data->GetTitle(), data, *data->get(), /*cut=*/(char*)0, weight_->GetName());
53  }
54  //std::cout << "\n\n\n========== DATASET " << it->first << " =============" << std::endl;
55  //utils::printRDH(it->second);
56  }
57  RooArgSet varsPlusWeight(vars_); varsPlusWeight.add(*weight_);
58  ret = new RooDataSet(name,title,varsPlusWeight,Index(*cat_),Import(mapUB_),WeightVar(*weight_));
59  //std::cout << "\n\n\n========== COMBINED DATASET =============" << std::endl;
60  //utils::printRDH(ret);
61 #else
62  RooArgSet varsPlusCat(vars_); varsPlusCat.add(*cat_);
63  RooArgSet varsPlusWeight(varsPlusCat); varsPlusWeight.add(*weight_);
64  ret = new RooDataSet(name,title,varsPlusWeight,WeightVar(*weight_));
65  for (std::map<std::string, RooDataSet *>::iterator it = mapUB_.begin(), ed = mapUB_.end(); it != ed; ++it) {
66  //std::cout << "\n\n\n========== DATASET " << it->first << " =============" << std::endl;
67  //utils::printRDH(it->second);
68  cat_->setLabel(it->first.c_str());
69  RooDataSet *data = it->second;
70  for (unsigned int i = 0, n = data->numEntries(); i < n; ++i) {
71  varsPlusCat = *data->get(i);
72  ret->add(varsPlusCat, data->weight());
73  }
74  }
75  //std::cout << "\n\n\n========== COMBINED DATASET =============" << std::endl;
76  //utils::printRDH(ret);
77 #endif
78  } else {
79  ret = new RooDataSet(name,title,vars_,Index(*cat_),Import(mapUB_));
80  }
81  mapUB_.clear();
82  return ret;
83 }
84 
85 
86 ClassImp(CombDataSetFactory)
int i
Definition: DBlmapReader.cc:9
std::map< std::string, RooDataHist * > map_
std::map< std::string, RooDataSet * > mapUB_
void addSetBin(const char *label, RooDataHist *set)
ClassDef(CombDataSetFactory, 1) private RooCategory * cat_
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
RooDataSet * doneUnbinned(const char *name, const char *title)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void addSetAny(const char *label, RooDataSet *set)
RooDataHist * done(const char *name, const char *title)
void set(const std::string &name, int value)
set the flag, with a run-time name