DAS  3.0
Das Analysis System
toy.cc File Reference
#include <boost/test/included/unit_test.hpp>
#include "Core/Uncertainties/bin/getToyCalculation.cc"
#include "Core/Unfolding/interface/Observable.h"
#include <darwin.h>
#include <filesystem>
#include <vector>
#include <TH1.h>
#include <TH2.h>
+ Include dependency graph for toy.cc:

Classes

class  TestTransformer
 

Macros

#define DOXYGEN_SHOULD_SKIP_THIS
 
#define BOOST_TEST_MODULE   testToy
 

Functions

 BOOST_AUTO_TEST_CASE (single_distribution)
 
 BOOST_AUTO_TEST_CASE (double_distribution)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   testToy

◆ DOXYGEN_SHOULD_SKIP_THIS

#define DOXYGEN_SHOULD_SKIP_THIS

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/2]

BOOST_AUTO_TEST_CASE ( double_distribution  )
96  {
97  // pre distribution
98  auto preBng = new TUnfoldBinning("pre");
99 
100  auto firstPreBng = new TUnfoldBinning("first_dist");
101  firstPreBng->AddAxis("first_axis", 4, 0.5, 4.5, false, false);
102  preBng->AddBinning(firstPreBng);
103 
104  auto secondPreBng = new TUnfoldBinning("second_dist");
105  secondPreBng->AddAxis("second_axis", 4, 4.5, 8.5, false, false);
106  preBng->AddBinning(secondPreBng);
107 
108  auto hIn = unique_ptr<TH1D>((TH1D*)preBng->CreateHistogram("hIn", false, nullptr, "input"));
109  auto covIn = unique_ptr<TH2D>(preBng->CreateErrorMatrixHistogram("covIn", false, nullptr, "input"));
110 
111  hIn->SetBinContent(1, 1); hIn->SetBinContent(5, 3);
112  hIn->SetBinContent(2, 2); hIn->SetBinContent(6, 4);
113  hIn->SetBinContent(3, 5); hIn->SetBinContent(7, 7);
114  hIn->SetBinContent(4, 0); hIn->SetBinContent(8, 10);
115 
116  for (int i = 1; i <= 8; ++i)
117  covIn->SetBinContent(i,i,hIn->GetBinContent(i));
118 
120 
121  using namespace DAS;
122  using namespace Unfolding;
123 
124  // post distribution
125  auto postBng = new TUnfoldBinning("post");
126  vector<unique_ptr<Transformer>> transformers;
127  transformers.emplace_back(make_unique<Transformer>(firstPreBng));
128  transformers.emplace_back(make_unique<TestTransformer>(secondPreBng));
129  postBng->AddBinning(transformers[0]->postBinning);
130  postBng->AddBinning(transformers[1]->postBinning);
131 
132  function<VectorXd(const VectorXd &)> transformation =
133  [&transformers](const VectorXd& x) {
134  Transformer::y = VectorXd::Zero(9);
135  for (const auto& t: transformers)
136  t->Transform(x);
137  return Transformer::y;
138  };
139 
140  for (auto& t: transformers)
141  t->RemoveBadInputBins(hIn.get(), covIn.get());
142 
144 
145  Teddy toy(hIn, covIn, transformation);
146  for (int i = 0; i < 1e6; ++i)
147  toy.play();
148  auto [x,cov] = toy.buy();
149 
150  cout << "x:\n" << x << "\n\n"
151  << "cov:\n" << cov << endl;
152 
153  VectorXd xTruth(9);
154  xTruth << 1, 2, 5, 0, 0, 0, 4, 10, 0;
155  for (int i = 0; i < 9; ++i) {
156  cout << i << ' ' << xTruth(i) << ' ' << x(i) << endl;
157  BOOST_TEST( x(i) == xTruth(i) );
158  }
159  }

◆ BOOST_AUTO_TEST_CASE() [2/2]

BOOST_AUTO_TEST_CASE ( single_distribution  )
46  {
48 
49  auto hIn = make_unique<TH1D>( "hIn", "hIn", 3, 0.5, 3.5);
50  auto covIn = make_unique<TH2D>("covIn", "covIn", 3, 0.5, 3.5,
51  3, 0.5, 3.5);
52 
53  cout << "\nInput\n" << endl;
54  hIn->SetBinContent(1, 1);
55  hIn->SetBinContent(2, 2);
56  hIn->SetBinContent(3, 1);
57  hIn->Print("all");
58 
59  covIn->SetBinContent(1, 1, 1);
60  covIn->SetBinContent(1, 2, 1);
61  covIn->SetBinContent(1, 3, 0);
62  covIn->SetBinContent(2, 1, 1);
63  covIn->SetBinContent(2, 2, 4);
64  covIn->SetBinContent(2, 3, 0);
65  covIn->SetBinContent(3, 1, 0);
66  covIn->SetBinContent(3, 2, 0);
67  covIn->SetBinContent(3, 3, 1);
68  covIn->Print("all");
69 
70  auto func = [](const VectorXd& x) {
71  VectorXd y(2);
72  y(0) = x(0) + x(1);
73  y(1) = x(2);
74  return y;
75  };
76 
77  using namespace DAS;
78  Teddy toy(hIn, covIn, func);
79  for (int i = 0; i < 1e6; ++i)
80  toy.play();
81  auto [x,cov] = toy.buy();
82 
83  cout << "x:\n" << x << "\n\n"
84  << "cov:\n" << cov << endl;
85 
86  BOOST_TEST( x(0) == 3 );
87  BOOST_TEST( x(1) == 1 );
88 
89  BOOST_TEST( cov(0,0) == 7);
90  BOOST_TEST( cov(0,1) == 0);
91  BOOST_TEST( cov(1,0) == 0);
92  BOOST_TEST( cov(1,1) == 1);
93  }
DAS
Definition: applyBTagSF.cc:31
BOOST_TEST
BOOST_TEST(gendijet.Rapidity()==1.3573785791881385)
Darwin::Tools::StandardInit
void StandardInit()
Definition: FileUtils.cc:29
DAS::Unfolding::Transformer::y
static Eigen::VectorXd y
output vector
Definition: Observable.h:100
DAS::Teddy
Definition: Teddy.h:40