DAS  3.0
Das Analysis System
testGenericSFApplier.cc File Reference
#include "Core/CommonTools/interface/GenericSFApplier.h"
#include <boost/test/included/unit_test.hpp>
#include <TFile.h>
#include <TH1D.h>
#include <filesystem>
#include <stdexcept>
#include <vector>
+ Include dependency graph for testGenericSFApplier.cc:

Classes

struct  HistogramFileFixture
 
struct  SimpleObject
 
struct  SimpleObjectApplier
 
struct  ContextApplier
 

Macros

#define BOOST_TEST_MODULE   testGenericSFApplier
 
#define FILE_NAME   "scaleFactors.root"
 
#define HIST_PREFIX   "H"
 
#define BIN_WISE_NAME   "stat"
 
#define GLOBAL_NAME   "syst"
 

Functions

 BOOST_AUTO_TEST_CASE (SimpleObjectNoSF)
 
 BOOST_AUTO_TEST_CASE (Vector)
 
 BOOST_AUTO_TEST_CASE (SimpleObjectApplySF)
 
 BOOST_AUTO_TEST_CASE (SimpleObjectApplySFAndUnc)
 
 BOOST_AUTO_TEST_CASE (Context)
 

Variables

const double BIN1_SF = 2
 
const double BIN2_SF = 3
 
const double BIN1_BW = 0.2
 
const double BIN2_BW = 0.3
 
const double BIN1_GB = 0.5
 
const double BIN2_GB = 0.6
 

Macro Definition Documentation

◆ BIN_WISE_NAME

#define BIN_WISE_NAME   "stat"

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   testGenericSFApplier

◆ FILE_NAME

#define FILE_NAME   "scaleFactors.root"

◆ GLOBAL_NAME

#define GLOBAL_NAME   "syst"

◆ HIST_PREFIX

#define HIST_PREFIX   "H"

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/5]

BOOST_AUTO_TEST_CASE ( Context  )
298  {
299  // This applier must not even try to open the file, so passing a dummy
300  // file name must be fine
301  const ContextApplier applier("/nowhere", false, false);
302 
303  SimpleObject obj = {2, {}};
304  applier(obj, applier.expectedContext);
305  }

◆ BOOST_AUTO_TEST_CASE() [2/5]

BOOST_AUTO_TEST_CASE ( SimpleObjectApplySF  )
196  {
197  // Check error condition
198  BOOST_CHECK_THROW( SimpleObjectApplier("/nowhere", true, false),
199  fs::filesystem_error );
200 
202  // This applier must apply the SF without doing systematics
203  const SimpleObjectApplier applier(f.path, true, false);
204 
205  // Must only return systematics that are actually applied
206  BOOST_TEST( applier.weightNames().empty() );
207 
208  // Selected object
209  SimpleObject obj = {2, {}};
210  applier(obj);
211  BOOST_TEST( obj.weights.size() == 1 );
212  BOOST_TEST( obj.weights.at(0).v == BIN2_SF );
213  BOOST_TEST( obj.weights.at(0).i == 0 );
214 
215  // Selected object with existing weights
216  obj = {2, {Weight{1, 0}, Weight{2, 1}}};
217  applier(obj);
218  BOOST_TEST( obj.weights.size() == 2 );
219  BOOST_TEST( obj.weights.at(0).v == 1 * BIN2_SF );
220  BOOST_TEST( obj.weights.at(0).i == 0 );
221  BOOST_TEST( obj.weights.at(1).v == 2 * BIN2_SF );
222  BOOST_TEST( obj.weights.at(1).i == 1 );
223 
224  // Selected object outside histogram bounds
225  obj = {10, {}};
226  applier(obj);
227  BOOST_TEST( obj.weights.size() == 1 );
228  BOOST_TEST( obj.weights.at(0).v == 0 );
229  BOOST_TEST( obj.weights.at(0).i == 0 );
230 
231  // Selected object outside histogram bounds, existing weights
232  obj = {10, {Weight{1, 0}, Weight{2, 1}}};
233  applier(obj);
234  BOOST_TEST( obj.weights.size() == 2 );
235  BOOST_TEST( obj.weights.at(0).v == 0 );
236  BOOST_TEST( obj.weights.at(0).i == 0 );
237  BOOST_TEST( obj.weights.at(1).v == 0 );
238  BOOST_TEST( obj.weights.at(1).i == 1 );
239 
240  // Object not selected
241  obj = {1, {}};
242  applier(obj);
243  BOOST_TEST( obj.weights.size() == 1 );
244  BOOST_TEST( obj.weights.at(0).v == 0 );
245  BOOST_TEST( obj.weights.at(0).i == 0 );
246  }

◆ BOOST_AUTO_TEST_CASE() [3/5]

BOOST_AUTO_TEST_CASE ( SimpleObjectApplySFAndUnc  )
249  {
250  // Check error condition
251  BOOST_CHECK_THROW( SimpleObjectApplier("/nowhere", true, true),
252  fs::filesystem_error );
253 
255  // This applier must apply the SF and do systematics
256  const SimpleObjectApplier applier(f.path, true, true);
257 
258  // Must only return systematics that are actually applied
259  const vector<string> expected_names{
262  BOOST_TEST( applier.weightNames() == expected_names );
263 
264  // Selected object
265  SimpleObject obj = {2, {}};
266  applier(obj);
267  BOOST_TEST( obj.weights.size() == 5 );
268  BOOST_TEST( obj.weights.at(0).v == BIN2_SF );
269  BOOST_TEST( obj.weights.at(0).i == 0 );
270  BOOST_TEST( obj.weights.at(1).v == BIN2_SF + BIN2_BW );
271  BOOST_TEST( obj.weights.at(1).i == 2 );
272  BOOST_TEST( obj.weights.at(2).v == BIN2_SF - BIN2_BW );
273  BOOST_TEST( obj.weights.at(2).i == 2 );
274  BOOST_TEST( obj.weights.at(3).v == BIN2_SF + BIN2_GB );
275  BOOST_TEST( obj.weights.at(3).i == 0 );
276  BOOST_TEST( obj.weights.at(4).v == BIN2_SF - BIN2_GB );
277  BOOST_TEST( obj.weights.at(4).i == 0 );
278 
279  // Selected object with existing weights
280  // Check that existing weights are modified as expected
281  obj = {2, {Weight{1, 0}, Weight{2, 1}}};
282  applier(obj);
283  BOOST_TEST( obj.weights.size() == 6 );
284  BOOST_TEST( obj.weights.at(0).v == 1 * BIN2_SF );
285  BOOST_TEST( obj.weights.at(0).i == 0 );
286  BOOST_TEST( obj.weights.at(1).v == 2 * BIN2_SF );
287  BOOST_TEST( obj.weights.at(1).i == 1 );
288 
289  // Object not selected
290  obj = {1, {}};
291  applier(obj);
292  BOOST_TEST( obj.weights.size() == 1 );
293  BOOST_TEST( obj.weights.at(0).v == 0 );
294  BOOST_TEST( obj.weights.at(0).i == 0 );
295  }

◆ BOOST_AUTO_TEST_CASE() [4/5]

BOOST_AUTO_TEST_CASE ( SimpleObjectNoSF  )
137  {
138  // This applier must not even try to open the file, so passing a dummy
139  // file name must be fine
140  const SimpleObjectApplier applier("/nowhere", false, false);
141 
142  // Must only return systematics that are actually applied
143  BOOST_TEST( applier.weightNames().empty() );
144 
145  // Selected object
146  SimpleObject obj = {2, {}};
147  applier(obj);
148  BOOST_TEST( obj.weights.size() == 1 );
149  BOOST_TEST( obj.weights.at(0).v == 1 );
150  BOOST_TEST( obj.weights.at(0).i == 0 );
151 
152  // Selected object with existing weights
153  obj = {2, {Weight{1, 0}, Weight{2, 1}}};
154  applier(obj);
155  BOOST_TEST( obj.weights.size() == 2 );
156  BOOST_TEST( obj.weights.at(0).v == 1 );
157  BOOST_TEST( obj.weights.at(0).i == 0 );
158  BOOST_TEST( obj.weights.at(1).v == 2 );
159  BOOST_TEST( obj.weights.at(1).i == 1 );
160 
161  // Object not selected
162  obj = {1, {}};
163  applier(obj);
164  BOOST_TEST( obj.weights.size() == 1 );
165  BOOST_TEST( obj.weights.at(0).v == 0 );
166  BOOST_TEST( obj.weights.at(0).i == 0 );
167 
168  // Object not selected with existing weights
169  obj = {1, {Weight{1, 0}, Weight{2, 1}, Weight{3, -1}}};
170  applier(obj);
171  BOOST_TEST( obj.weights.size() == 3 );
172  for (int i = 0; i < obj.weights.size(); ++i) {
173  BOOST_TEST( obj.weights.at(i).v == 0 );
174  }
175  }

◆ BOOST_AUTO_TEST_CASE() [5/5]

BOOST_AUTO_TEST_CASE ( Vector  )
178  {
179  // This applier must not even try to open the file, so passing a dummy
180  // file name must be fine
181  const SimpleObjectApplier applier("/nowhere", false, false);
182 
183  // First object not selected, second selected
184  vector<SimpleObject> objs = {{1, {}}, {2, {}}};
185  applier(objs);
186  BOOST_TEST( objs.size() == 2 );
187  BOOST_TEST( objs.at(0).weights.size() == 1 );
188  BOOST_TEST( objs.at(0).weights.at(0).v == 0 );
189  BOOST_TEST( objs.at(0).weights.at(0).i == 0 );
190  BOOST_TEST( objs.at(1).weights.size() == 1 );
191  BOOST_TEST( objs.at(1).weights.at(0).v == 1 );
192  BOOST_TEST( objs.at(1).weights.at(0).i == 0 );
193  }

Variable Documentation

◆ BIN1_BW

const double BIN1_BW = 0.2

◆ BIN1_GB

const double BIN1_GB = 0.5

◆ BIN1_SF

const double BIN1_SF = 2

◆ BIN2_BW

const double BIN2_BW = 0.3

◆ BIN2_GB

const double BIN2_GB = 0.6

◆ BIN2_SF

const double BIN2_SF = 3
BOOST_TEST
BOOST_TEST(gendijet.Rapidity()==1.3573785791881385)
SimpleObjectApplier
Definition: testGenericSFApplier.cc:87
DAS::SysUp
const std::string SysUp
Suffix used for "up" uncertainties. Follows the Combine convention.
Definition: Format.h:8
BIN_WISE_NAME
#define BIN_WISE_NAME
Definition: testGenericSFApplier.cc:21
SimpleObject
Definition: testGenericSFApplier.cc:78
Ntupliser_cfg.f
f
Definition: Ntupliser_cfg.py:324
HistogramFileFixture
Fixture that creates a temporary ROOT file with "scale factor" histograms inside.
Definition: testGenericSFApplier.cc:33
GLOBAL_NAME
#define GLOBAL_NAME
Definition: testGenericSFApplier.cc:22
BIN2_GB
const double BIN2_GB
Definition: testGenericSFApplier.cc:26
ContextApplier
Definition: testGenericSFApplier.cc:109
SimpleObject::weights
vector< Weight > weights
Definition: testGenericSFApplier.cc:80
DAS::Weight
Definition: Weight.h:16
DAS::SysDown
const std::string SysDown
Suffix used for "down" uncertainties. Follows the Combine convention.
Definition: Format.h:10
BIN2_BW
const double BIN2_BW
Definition: testGenericSFApplier.cc:25
BIN2_SF
const double BIN2_SF
Definition: testGenericSFApplier.cc:24