CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ProcessNormalization.cc
Go to the documentation of this file.
1 #include "../interface/ProcessNormalization.h"
2 
3 #include <cmath>
4 #include <cassert>
5 #include <cstdio>
6 
7 ProcessNormalization::ProcessNormalization(const char *name, const char *title, double nominal) :
8  RooAbsReal(name,title),
9  nominalValue_(nominal),
10  thetaList_("thetaList","List of nuisances for symmetric kappas", this),
11  asymmThetaList_("asymmThetaList","List of nuisances for asymmetric kappas", this),
12  otherFactorList_("otherFactorList","Other multiplicative terms", this)
13 {
14 }
15 
16 ProcessNormalization::ProcessNormalization(const char *name, const char *title, RooAbsReal &nominal) :
17  RooAbsReal(name,title),
18  nominalValue_(1.0),
19  thetaList_("thetaList", "List of nuisances for symmetric kappas", this),
20  asymmThetaList_("asymmThetaList", "List of nuisances for asymmetric kappas", this),
21  otherFactorList_("otherFactorList", "Other multiplicative terms", this)
22 {
23  otherFactorList_.add(nominal);
24 }
25 
27  RooAbsReal(other, newname ? newname : other.GetName()),
28  nominalValue_(other.nominalValue_),
29  logKappa_(other.logKappa_),
30  thetaList_("thetaList", this, other.thetaList_),
31  logAsymmKappa_(other.logAsymmKappa_),
32  asymmThetaList_("asymmThetaList", this, other.asymmThetaList_),
33  otherFactorList_("otherFactorList", this, other.otherFactorList_)
34 {
35 }
36 
38 
39 void ProcessNormalization::addLogNormal(double kappa, RooAbsReal &theta) {
40  if (kappa != 0.0 && kappa != 1.0) {
41  logKappa_.push_back(std::log(kappa));
42  thetaList_.add(theta);
43  }
44 }
45 
46 void ProcessNormalization::addAsymmLogNormal(double kappaLo, double kappaHi, RooAbsReal &theta) {
47  if (fabs(kappaLo*kappaHi - 1) < 1e-5) {
48  addLogNormal(kappaHi, theta);
49  } else {
50  logAsymmKappa_.push_back(std::make_pair(std::log(kappaLo), std::log(kappaHi)));
51  asymmThetaList_.add(theta);
52  }
53 }
54 
55 void ProcessNormalization::addOtherFactor(RooAbsReal &factor) {
56  otherFactorList_.add(factor);
57 }
58 
60  double logVal = 0.0;
61  if (!logKappa_.empty()) {
62  RooLinkedListIter iterTheta = thetaList_.iterator();
63  std::vector<double>::const_iterator logKappa = logKappa_.begin();
64  for (RooAbsReal *theta = (RooAbsReal*) iterTheta.Next(); theta != 0; theta = (RooAbsReal*) iterTheta.Next(), ++logKappa) {
65  logVal += theta->getVal() * (*logKappa);
66  }
67  }
68  if (!logAsymmKappa_.empty()) {
69  RooLinkedListIter iterTheta = asymmThetaList_.iterator();
70  std::vector<std::pair<double,double> >::const_iterator logKappas = logAsymmKappa_.begin();
71  for (RooAbsReal *theta = (RooAbsReal*) iterTheta.Next(); theta != 0; theta = (RooAbsReal*) iterTheta.Next(), ++logKappas) {
72  double x = theta->getVal();
73  logVal += x * logKappaForX(x, *logKappas);
74  }
75  }
76  double norm = nominalValue_;
77  if (logVal) norm *= std::exp(logVal);
78  if (otherFactorList_.getSize()) {
79  RooLinkedListIter iterOther = otherFactorList_.iterator();
80  for (RooAbsReal *fact = (RooAbsReal*) iterOther.Next(); fact != 0; fact = (RooAbsReal*) iterOther.Next()) {
81  norm *= fact->getVal();
82  }
83  }
84  return norm;
85 }
86 
87 Double_t ProcessNormalization::logKappaForX(double x, const std::pair<double,double> &logKappas) const {
88  if (fabs(x) >= 0.5) return (x >= 0 ? logKappas.second : -logKappas.first);
89  // interpolate between log(kappaHigh) and -log(kappaLow)
90  // logKappa(x) = avg + halfdiff * h(2x)
91  // where h(x) is the 3th order polynomial
92  // h(x) = (3 x^5 - 10 x^3 + 15 x)/8;
93  // chosen so that h(x) satisfies the following:
94  // h (+/-1) = +/-1
95  // h'(+/-1) = 0
96  // h"(+/-1) = 0
97  double logKhi = logKappas.second;
98  double logKlo = -logKappas.first;
99  double avg = 0.5*(logKhi + logKlo), halfdiff = 0.5*(logKhi - logKlo);
100  double twox = x+x, twox2 = twox*twox;
101  double alpha = 0.125 * twox * (twox2 * (3*twox2 - 10.) + 15.);
102  double ret = avg + alpha*halfdiff;
103  return ret;
104 }
105 
107  std::cout << "Dumping ProcessNormalization " << GetName() << " @ " << (void*)this << std::endl;
108  std::cout << "\tnominal value: " << nominalValue_ << std::endl;
109  std::cout << "\tlog-normals (" << logKappa_.size() << "):" << std::endl;
110  for (unsigned int i = 0; i < logKappa_.size(); ++i) {
111  std::cout << "\t\t kappa = " << exp(logKappa_[i]) << ", logKappa = " << logKappa_[i] <<
112  ", theta = " << thetaList_.at(i)->GetName() << " = " << ((RooAbsReal*)thetaList_.at(i))->getVal() << std::endl;
113  }
114  std::cout << "\tasymm log-normals (" << logAsymmKappa_.size() << "):" << std::endl;
115  for (unsigned int i = 0; i < logAsymmKappa_.size(); ++i) {
116  std::cout << "\t\t kappaLo = " << exp(logAsymmKappa_[i].first) << ", logKappaLo = " << logAsymmKappa_[i].first <<
117  ", kappaHi = " << exp(logAsymmKappa_[i].second) << ", logKappaHi = " << logAsymmKappa_[i].second <<
118  ", theta = " << thetaList_.at(i)->GetName() << " = " << ((RooAbsReal*)thetaList_.at(i))->getVal() << std::endl;
119  }
120  std::cout << "\tother terms (" << otherFactorList_.getSize() << "):" << std::endl;
121  for (int i = 0; i < otherFactorList_.getSize(); ++i) {
122  std::cout << "\t\t term " << otherFactorList_.at(i)->GetName() <<
123  " (class " << otherFactorList_.at(i)->ClassName() <<
124  "), value = " << ((RooAbsReal*)otherFactorList_.at(i))->getVal() << std::endl;
125  }
126  std::cout << std::endl;
127 }
128 ClassImp(ProcessNormalization)
int i
Definition: DBlmapReader.cc:9
float alpha
Definition: AMPTWrapper.h:95
void addLogNormal(double kappa, RooAbsReal &theta)
Double_t logKappaForX(double x, const std::pair< double, double > &logKappas) const
Geom::Theta< T > theta() const
U second(std::pair< T, U > const &p)
std::vector< double > logKappa_
Double_t evaluate() const
bool first
Definition: L1TdeRCT.cc:94
std::vector< std::pair< double, double > > logAsymmKappa_
void addOtherFactor(RooAbsReal &factor)
void addAsymmLogNormal(double kappaLo, double kappaHi, RooAbsReal &theta)
tuple cout
Definition: gather_cfg.py:121
x
Definition: VDTMath.h:216