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#include <limits>
19
20namespace Belle2::Variable {
21
22 namespace {
23 const BackgroundInfo::BackgroundDescr* getBackgroundDescription()
24 {
25 StoreObjPtr<BackgroundInfo> bkgInfo{"", DataStore::c_Persistent};
26 // Sanity check
27 if (bkgInfo->getMethod() != BackgroundInfo::c_Overlay)
28 return nullptr;
29 const auto bkgDescriptions = bkgInfo->getBackgrounds();
30 // In mdsts we are supposed to have only the "default" type.
31 // Also: we should have only one type, but let's be safe here.
32 auto bkgDescription = std::find_if(bkgDescriptions.begin(), bkgDescriptions.end(), [](const auto & d) { return d.type == BackgroundMetaData::getDefaultBackgroundOverlayType(); });
33 if (bkgDescription != bkgDescriptions.end())
34 return &(*bkgDescription);
35 else
36 return nullptr;
37 }
38 }
39
40 int beamBackgroundReuseRate(const Particle*)
41 {
42 const auto* bkgDescription = getBackgroundDescription();
43 if (not bkgDescription)
44 return std::numeric_limits<int>::quiet_NaN();
45 return bkgDescription->reused;
46 }
47
48 int beamBackgroundEvents(const Particle*)
49 {
50 const auto* bkgDescription = getBackgroundDescription();
51 if (not bkgDescription)
52 return std::numeric_limits<int>::quiet_NaN();
53 return bkgDescription->numEvents;
54 }
55
56 VARIABLE_GROUP("BeamBackgroundOverlay");
57 REGISTER_VARIABLE("beamBackgroundReuseRate", beamBackgroundReuseRate,
58 "[Eventbased] Reuse rate of the background overlay events used for producing the file.", "");
59 REGISTER_VARIABLE("beamBackgroundEvents", beamBackgroundEvents,
60 "[Eventbased] Total number of the background overlay events used for producing the file.", "");
61}
@ c_Persistent
Object is available during entire execution time.
Definition: DataStore.h:60