Belle II Software development
BeamBackground.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <analysis/variables/BeamBackground.h>
10
11#include <analysis/VariableManager/Manager.h>
12#include <framework/dataobjects/BackgroundInfo.h>
13#include <framework/dataobjects/BackgroundMetaData.h>
14#include <framework/datastore/DataStore.h>
15#include <framework/datastore/StoreObjPtr.h>
16
17#include <algorithm>
18
19namespace Belle2::Variable {
20
21 namespace {
22 const BackgroundInfo::BackgroundDescr* getBackgroundDescription()
23 {
24 StoreObjPtr<BackgroundInfo> bkgInfo{"", DataStore::c_Persistent};
25 // Sanity check
26 if (bkgInfo->getMethod() != BackgroundInfo::c_Overlay)
27 return nullptr;
28 const auto bkgDescriptions = bkgInfo->getBackgrounds();
29 // In mdsts we are supposed to have only the "default" type.
30 // Also: we should have only one type, but let's be safe here.
31 auto bkgDescription = std::find_if(bkgDescriptions.begin(), bkgDescriptions.end(), [](const auto & d) { return d.type == BackgroundMetaData::getDefaultBackgroundOverlayType(); });
32 if (bkgDescription != bkgDescriptions.end())
33 return &(*bkgDescription);
34 else
35 return nullptr;
36 }
37 }
38
39 int beamBackgroundReuseRate(const Particle*)
40 {
41 const auto* bkgDescription = getBackgroundDescription();
42 if (not bkgDescription)
43 return 0;
44 return bkgDescription->reused;
45 }
46
47 int beamBackgroundEvents(const Particle*)
48 {
49 const auto* bkgDescription = getBackgroundDescription();
50 if (not bkgDescription)
51 return 0;
52 return bkgDescription->numEvents;
53 }
54
55 VARIABLE_GROUP("BeamBackgroundOverlay");
56 REGISTER_VARIABLE("beamBackgroundReuseRate", beamBackgroundReuseRate,
57 "[Eventbased] Reuse rate of the background overlay events used for producing the file.", "");
58 REGISTER_VARIABLE("beamBackgroundEvents", beamBackgroundEvents,
59 "[Eventbased] Total number of the background overlay events used for producing the file.", "");
60}
@ c_Persistent
Object is available during entire execution time.
Definition DataStore.h:60