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 <utility>
#include <stdexcept>
#include <vector>
+ Include dependency graph for testGenericSFApplier.cc:

Classes

struct  HistogramFileFixture
 
struct  SimpleObject
 
struct  SimpleObjectApplier
 
struct  ContextApplier
 
struct  SpecialObject
 
struct  SpecialObjectApplier
 

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)
 
 BOOST_AUTO_TEST_CASE (SpecialObjectCanary)
 

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/6]

BOOST_AUTO_TEST_CASE ( Context  )
333  {
334  // This applier must not even try to open the file, so passing a dummy
335  // file name must be fine
336  const ContextApplier applier("/nowhere", false, false);
337 
338  SimpleObject obj = {2, {}};
339  applier(obj, applier.expectedContext);
340  }

◆ BOOST_AUTO_TEST_CASE() [2/6]

BOOST_AUTO_TEST_CASE ( SimpleObjectApplySF  )
230  {
231  // Check error condition
232  BOOST_CHECK_THROW( SimpleObjectApplier("/nowhere", true, false),
233  fs::filesystem_error );
234 
236  // This applier must apply the SF without doing systematics
237  const SimpleObjectApplier applier(f.path, true, false);
238 
239  // Must only return systematics that are actually applied
240  BOOST_TEST( applier.weightNames().empty() );
241 
242  // Selected object
243  SimpleObject obj = {2, {}};
244  applier(obj);
245  BOOST_TEST( obj.weights.size() == 1 );
246  BOOST_TEST( obj.weights.at(0).v == BIN2_SF );
247  BOOST_TEST( obj.weights.at(0).i == 0 );
248 
249  // Selected object with existing weights
250  obj = {2, {Weight{1, 0}, Weight{2, 1}}};
251  applier(obj);
252  BOOST_TEST( obj.weights.size() == 2 );
253  BOOST_TEST( obj.weights.at(0).v == 1 * BIN2_SF );
254  BOOST_TEST( obj.weights.at(0).i == 0 );
255  BOOST_TEST( obj.weights.at(1).v == 2 * BIN2_SF );
256  BOOST_TEST( obj.weights.at(1).i == 1 );
257 
258  // Selected object outside histogram bounds
259  obj = {10, {}};
260  applier(obj);
261  BOOST_TEST( obj.weights.size() == 1 );
262  BOOST_TEST( obj.weights.at(0).v == 0 );
263  BOOST_TEST( obj.weights.at(0).i == 0 );
264 
265  // Selected object outside histogram bounds, existing weights
266  obj = {10, {Weight{1, 0}, Weight{2, 1}}};
267  applier(obj);
268  BOOST_TEST( obj.weights.size() == 2 );
269  BOOST_TEST( obj.weights.at(0).v == 0 );
270  BOOST_TEST( obj.weights.at(0).i == 0 );
271  BOOST_TEST( obj.weights.at(1).v == 0 );
272  BOOST_TEST( obj.weights.at(1).i == 1 );
273 
274  // Object not selected
275  obj = {1, {}};
276  applier(obj);
277  BOOST_TEST( obj.weights.size() == 1 );
278  BOOST_TEST( obj.weights.at(0).v == 0 );
279  BOOST_TEST( obj.weights.at(0).i == 0 );
280  }

◆ BOOST_AUTO_TEST_CASE() [3/6]

BOOST_AUTO_TEST_CASE ( SimpleObjectApplySFAndUnc  )
283  {
284  // Check error condition
285  BOOST_CHECK_THROW( SimpleObjectApplier("/nowhere", true, true),
286  fs::filesystem_error );
287 
289  // This applier must apply the SF and do systematics
290  const SimpleObjectApplier applier(f.path, true, true);
291 
292  // Must only return systematics that are actually applied
293  const vector<string> expected_names{
296  BOOST_TEST( applier.weightNames() == expected_names );
297 
298  // Selected object
299  SimpleObject obj = {2, {}};
300  applier(obj);
301  BOOST_TEST( obj.weights.size() == 5 );
302  BOOST_TEST( obj.weights.at(0).v == BIN2_SF );
303  BOOST_TEST( obj.weights.at(0).i == 0 );
304  BOOST_TEST( obj.weights.at(1).v == BIN2_SF + BIN2_BW );
305  BOOST_TEST( obj.weights.at(1).i == 2 );
306  BOOST_TEST( obj.weights.at(2).v == BIN2_SF - BIN2_BW );
307  BOOST_TEST( obj.weights.at(2).i == 2 );
308  BOOST_TEST( obj.weights.at(3).v == BIN2_SF + BIN2_GB );
309  BOOST_TEST( obj.weights.at(3).i == 0 );
310  BOOST_TEST( obj.weights.at(4).v == BIN2_SF - BIN2_GB );
311  BOOST_TEST( obj.weights.at(4).i == 0 );
312 
313  // Selected object with existing weights
314  // Check that existing weights are modified as expected
315  obj = {2, {Weight{1, 0}, Weight{2, 1}}};
316  applier(obj);
317  BOOST_TEST( obj.weights.size() == 6 );
318  BOOST_TEST( obj.weights.at(0).v == 1 * BIN2_SF );
319  BOOST_TEST( obj.weights.at(0).i == 0 );
320  BOOST_TEST( obj.weights.at(1).v == 2 * BIN2_SF );
321  BOOST_TEST( obj.weights.at(1).i == 1 );
322 
323  // Object not selected
324  // Check that systematics are not recorded
325  obj = {1, {}};
326  applier(obj);
327  BOOST_TEST( obj.weights.size() == 1 );
328  BOOST_TEST( obj.weights.at(0).v == 0 );
329  BOOST_TEST( obj.weights.at(0).i == 0 );
330  }

◆ BOOST_AUTO_TEST_CASE() [4/6]

BOOST_AUTO_TEST_CASE ( SimpleObjectNoSF  )
172  {
173  // This applier must not even try to open the file, so passing a dummy
174  // file name must be fine
175  const SimpleObjectApplier applier("/nowhere", false, false);
176 
177  // Must only return systematics that are actually applied
178  BOOST_TEST( applier.weightNames().empty() );
179 
180  // Selected object
181  SimpleObject obj = {2, {}};
182  applier(obj);
183  BOOST_TEST( obj.weights.size() == 1 );
184  BOOST_TEST( obj.weights.at(0).v == 1 );
185  BOOST_TEST( obj.weights.at(0).i == 0 );
186 
187  // Selected object with existing weights
188  obj = {2, {Weight{1, 0}, Weight{2, 1}}};
189  applier(obj);
190  BOOST_TEST( obj.weights.size() == 2 );
191  BOOST_TEST( obj.weights.at(0).v == 1 );
192  BOOST_TEST( obj.weights.at(0).i == 0 );
193  BOOST_TEST( obj.weights.at(1).v == 2 );
194  BOOST_TEST( obj.weights.at(1).i == 1 );
195 
196  // Object not selected
197  obj = {1, {}};
198  applier(obj);
199  BOOST_TEST( obj.weights.size() == 1 );
200  BOOST_TEST( obj.weights.at(0).v == 0 );
201  BOOST_TEST( obj.weights.at(0).i == 0 );
202 
203  // Object not selected with existing weights
204  obj = {1, {Weight{1, 0}, Weight{2, 1}, Weight{3, -1}}};
205  applier(obj);
206  BOOST_TEST( obj.weights.size() == 1 );
207  BOOST_TEST( obj.weights.at(0).v == 0 );
208  BOOST_TEST( obj.weights.at(0).i == 0 );
209  }

◆ BOOST_AUTO_TEST_CASE() [5/6]

BOOST_AUTO_TEST_CASE ( SpecialObjectCanary  )
343  {
344  // This applier must not even try to open the file, so passing a dummy
345  // file name must be fine
346  const SpecialObjectApplier applier;
347 
348  SpecialObject obj = {0, {}};
349  applier(obj);
350  // This checks that the appropriate weightsRef() was called
351  BOOST_TEST( obj.canary == 42 );
352  }

◆ BOOST_AUTO_TEST_CASE() [6/6]

BOOST_AUTO_TEST_CASE ( Vector  )
212  {
213  // This applier must not even try to open the file, so passing a dummy
214  // file name must be fine
215  const SimpleObjectApplier applier("/nowhere", false, false);
216 
217  // First object not selected, second selected
218  vector<SimpleObject> objs = {{1, {}}, {2, {}}};
219  applier(objs);
220  BOOST_TEST( objs.size() == 2 );
221  BOOST_TEST( objs.at(0).weights.size() == 1 );
222  BOOST_TEST( objs.at(0).weights.at(0).v == 0 );
223  BOOST_TEST( objs.at(0).weights.at(0).i == 0 );
224  BOOST_TEST( objs.at(1).weights.size() == 1 );
225  BOOST_TEST( objs.at(1).weights.at(0).v == 1 );
226  BOOST_TEST( objs.at(1).weights.at(0).i == 0 );
227  }

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
SpecialObjectApplier
Definition: testGenericSFApplier.cc:158
BOOST_TEST
BOOST_TEST(gendijet.Rapidity()==1.3573785791881385)
SimpleObjectApplier
Definition: testGenericSFApplier.cc:88
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:22
SpecialObject
Definition: testGenericSFApplier.cc:139
SimpleObject
Definition: testGenericSFApplier.cc:79
Ntupliser_cfg.f
f
Definition: Ntupliser_cfg.py:289
HistogramFileFixture
Fixture that creates a temporary ROOT file with "scale factor" histograms inside.
Definition: testGenericSFApplier.cc:34
GLOBAL_NAME
#define GLOBAL_NAME
Definition: testGenericSFApplier.cc:23
BIN2_GB
const double BIN2_GB
Definition: testGenericSFApplier.cc:27
ContextApplier
Definition: testGenericSFApplier.cc:110
SimpleObject::weights
vector< Weight > weights
Definition: testGenericSFApplier.cc:81
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:26
BIN2_SF
const double BIN2_SF
Definition: testGenericSFApplier.cc:25
SpecialObject::canary
int canary
Definition: testGenericSFApplier.cc:140