DAS  3.0
Das Analysis System
Flattener.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPLv3-or-later
2 //
3 // SPDX-FileCopyrightText: Patrick L.S. Connor <patrick.connor@cern.ch>
4 
5 #pragma once
6 
7 #include <Flow.h>
8 #include <GenericObject.h>
9 #include <GenericPlugin.h>
10 #include <MetaInfo.h>
11 #include <SelfAwareBranch.h>
12 #include <Variation.h>
13 
14 #include <list>
15 #include <memory>
16 #include <ranges>
17 #include <set>
18 #include <string>
19 #include <type_traits>
20 
21 namespace pt = boost::property_tree;
22 namespace DT = Darwin::Tools;
23 
24 namespace Darwin::Physics {
25 
41 protected:
43  BranchFlattener (const Variation& v) : v(v) { }
44 public:
45  virtual ~BranchFlattener () = default;
46  virtual void Fill () = 0;
47  virtual void Clear () = 0;
48 };
49 
55 template<typename T> class ScaledObjectBranchFlattener : public BranchFlattener {
56 
57  std::vector<T> * branchIn;
58  std::list<std::unique_ptr<DT::SelfAwareBranch<const T&>>>
60  std::unique_ptr<DT::SelfAwareBranch<const std::vector<T>&>> multiplicity;
61 
62 public:
63 
66  template<typename Ret> void Add (Tools::Flow& flow,
67  const std::string& name,
68  const std::function<Ret(const T&)>& f)
69  {
70  branchesOut.emplace_back(std::make_unique<DT::SelfAwareVectorBranch<Ret, const T&>>(flow, name, f));
71  }
72 
76  const std::string& nameIn,
77  const std::string& nameOut
78  )
79  : BranchFlattener(v), branchIn(nullptr)
80  {
81  using namespace std;
82 
83  branchIn = flow.GetBranchReadOnly<vector<T>>(nameIn, DT::facultative);
84  if (!branchIn) return;
85 
86  Add<float>(flow, nameOut + "_pt" , [this](const T& el) { return el.CorrP4(this->v).pt (); });
87  Add<float>(flow, nameOut + "_eta" , [this](const T& el) { return el.CorrP4(this->v).eta (); });
88  Add<float>(flow, nameOut + "_phi" , [this](const T& el) { return el.CorrP4(this->v).phi (); });
89  Add<float>(flow, nameOut + "_mass", [this](const T& el) { return el.CorrP4(this->v).mass(); });
90 
91  auto getMult = [](const vector<T>& branchIn) { return branchIn.size(); };
92  multiplicity = make_unique<DT::SelfAwarePlainBranch<int, const vector<T>&>>(flow, "n" + nameOut, getMult);
93  }
94 
97  void Fill () override
98  {
99  if (!branchIn) return;
100 
101  for (const auto& br: branchesOut)
102  for (const auto& el: *branchIn)
103  br->Fill(el);
104 
105  multiplicity->Fill(*branchIn);
106  }
107 
110  void Clear () override
111  {
112  if (!branchIn) return;
113 
114  for (const auto& br: branchesOut)
115  br->Clear();
116 
117  multiplicity->Clear();
118  }
119 
120  virtual ~ScaledObjectBranchFlattener () = default;
121 };
122 
136 template<typename GenObject, typename RecObject>
138 
139 protected:
140 
141  std::list<std::unique_ptr<BranchFlattener>> branch_flatteners;
142 
143  virtual int GetParamsVeto () noexcept override { return DT::syst; }
144 
145 public:
146 
148  virtual ~PhysicsObjectFlattener () = default;
149 
154  virtual void ExecuteAtBegin (const std::set<Variation>& = {nominal}) override
155  {
156  for (const auto& br: branch_flatteners)
157  br->Clear();
158  }
159 
164  virtual void ExecuteAtEnd (const std::set<Variation>& = {nominal}) override
165  {
166  for (const auto& br: branch_flatteners)
167  br->Fill();
168  }
169 };
170 
171 } // end of Darwin::Physics namespace
DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.name
name
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:48
Darwin::Physics::ScaledObjectBranchFlattener::branchesOut
std::list< std::unique_ptr< DT::SelfAwareBranch< const T & > > > branchesOut
container for output branches
Definition: Flattener.h:59
Darwin::Physics::PhysicsObjectFlattener::~PhysicsObjectFlattener
virtual ~PhysicsObjectFlattener()=default
Darwin::Physics::PhysicsObjectFlattener::PhysicsObjectFlattener
PhysicsObjectFlattener()=default
jmarExample.pt
pt
Definition: jmarExample.py:19
Darwin::Tools::Flow
User-friendly handling of input and output n-tuples.
Definition: Flow.h:80
Darwin::Tools::GenericPlugin
Generic plugin class.
Definition: GenericPlugin.h:42
MetaInfo.h
Darwin::Physics::ScaledObjectBranchFlattener::ScaledObjectBranchFlattener
ScaledObjectBranchFlattener(Tools::Flow &flow, const Variation &v, const std::string &nameIn, const std::string &nameOut)
Generic class to project vectors of a given scaled object.
Definition: Flattener.h:75
Darwin::Physics::PhysicsObjectFlattener::ExecuteAtBegin
virtual void ExecuteAtBegin(const std::set< Variation > &={nominal}) override
Clear output branches.
Definition: Flattener.h:154
Darwin::Physics::PhysicsObjectFlattener::ExecuteAtEnd
virtual void ExecuteAtEnd(const std::set< Variation > &={nominal}) override
Fill output branches.
Definition: Flattener.h:164
Ntupliser_cfg.f
f
Definition: Ntupliser_cfg.py:322
Darwin::Tools::syst
@ syst
activate -s to systematic uncertainties
Definition: Options.h:34
Darwin::Tools::SelfAwareVectorBranch
Type for a vector branch that knows how to fill itself.
Definition: SelfAwareBranch.h:74
Darwin::Physics::ScaledObjectBranchFlattener::Clear
void Clear() override
Clear output branches.
Definition: Flattener.h:110
Darwin::Physics::Variation
Definition: Variation.h:26
Darwin::Physics::ScaledObjectBranchFlattener::~ScaledObjectBranchFlattener
virtual ~ScaledObjectBranchFlattener()=default
Variation.h
Darwin::Physics::BranchFlattener::v
Variation v
Definition: Flattener.h:42
Flow.h
Darwin::Physics::ScaledObjectBranchFlattener::branchIn
std::vector< T > * branchIn
input structured branch (e.g. in Darwin format)
Definition: Flattener.h:57
Darwin::Physics::ScaledObjectBranchFlattener
Wrapper for flat branches for gen- or rec-level final-state objects.
Definition: Flattener.h:55
Darwin::Physics::nominal
const Variation nominal("", "nominal")
SelfAwareBranch.h
Darwin::Physics::PhysicsObjectFlattener::GetParamsVeto
virtual int GetParamsVeto() noexcept override
Plugin's forbidden modes.
Definition: Flattener.h:143
Darwin::Physics::BranchFlattener::~BranchFlattener
virtual ~BranchFlattener()=default
Darwin::Physics::ScaledObjectBranchFlattener::multiplicity
std::unique_ptr< DT::SelfAwareBranch< const std::vector< T > & > > multiplicity
Definition: Flattener.h:60
Darwin::Tools
Classes and functions related to the framework.
Definition: Darwin_dict.cxx:1144
Darwin::Physics::BranchFlattener::Fill
virtual void Fill()=0
Darwin::Tools::Flow::GetBranchReadOnly
T * GetBranchReadOnly(const std::string &name, BranchMode mode=mandatory)
Wrapper to initialise read-only branches.
Definition: Flow.h:301
Darwin::Physics::PhysicsObjectFlattener::branch_flatteners
std::list< std::unique_ptr< BranchFlattener > > branch_flatteners
Definition: Flattener.h:141
Darwin::Physics::PhysicsObjectFlattener
Plugin template to produce flat branches for physics objects.
Definition: Flattener.h:137
GenericObject.h
Darwin::Physics::BranchFlattener::Clear
virtual void Clear()=0
Darwin::Physics::BranchFlattener::BranchFlattener
BranchFlattener(const Variation &v)
Definition: Flattener.h:43
Darwin::Physics
Everything what concerns physics analysis directly.
Definition: darwin.h:25
Darwin::Physics::ScaledObjectBranchFlattener::Fill
void Fill() override
Fill output branches.
Definition: Flattener.h:97
Darwin::Physics::ScaledObjectBranchFlattener::Add
void Add(Tools::Flow &flow, const std::string &name, const std::function< Ret(const T &)> &f)
Helper to add a new self-aware input branch.
Definition: Flattener.h:66
jmarExample.eta
eta
DeepAK8/ParticleNet tagging.
Definition: jmarExample.py:19
Darwin::Tools::facultative
@ facultative
mounting branch is facultative
Definition: Flow.h:33
Darwin::Physics::BranchFlattener
Abstract class to produce flat branch(es) onto one or a set of ouput branches.
Definition: Flattener.h:40
GenericPlugin.h