DAS  3.0
Das Analysis System
toolbox.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cassert>
4 #include <vector>
5 
6 #include <TDirectory.h>
7 #include <TKey.h>
8 #include <TString.h>
9 
10 #include "Math/VectorUtil.h"
11 
13 
14 #include <boost/exception/all.hpp>
15 
16 namespace DAS {
17 
18 inline bool pt_sort (const PhysicsObject& j1, const PhysicsObject& j2)
19 {
20  return j1.CorrPt() > j2.CorrPt();
21 }
22 
27 template<typename TTreePtr>
28 [[ deprecated("Use Darwin::Tools::Flow()") ]]
29 bool branchExists (const TTreePtr& tree, TString brName)
30 {
31  auto brList = tree->GetListOfBranches();
32  bool brFound = false;
33  for (auto it = brList->begin(); it != brList->end(); ++it) {
34  TString name = (*it)->GetName();
35  if (name == brName) brFound = true;
36  }
37  return brFound;
38 }
39 
42 template<typename T> std::vector<T*> GetObjects (TDirectory * dir)
43 {
44  if (!dir)
45  BOOST_THROW_EXCEPTION( std::runtime_error("Trying to access inexistent `TDirectory`") );
46  std::vector<T*> objects;
47  for (const auto&& element: *(dir->GetListOfKeys())) {
48  auto key = dynamic_cast<TKey*>(element);
49  if (auto obj = dynamic_cast<T*>(key->ReadObj()); obj)
50  objects.push_back(obj);
51  }
52  return objects;
53 }
54 
57 inline TDirectory * GetDirectory (TDirectory * dir, const std::vector<const char *>& names)
58 {
59  for (const char * name: names) {
60  TDirectory * subdir = dir->GetDirectory(name);
61  if (!subdir)
62  BOOST_THROW_EXCEPTION( std::invalid_argument(
63  Form("`%s` could not be found in `%s`", name, dir->GetName())) );
64  dir = subdir;
65  }
66  return dir;
67 }
68 
69 using ROOT::Math::VectorUtil::DeltaPhi;
70 using ROOT::Math::VectorUtil::DeltaR;
71 
72 } // end of DAS 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
DAS
Definition: applyBTagSF.cc:31
DAS::PhysicsObject
Definition: PhysicsObject.h:41
jercExample.key
string key
Definition: jercExample.py:109
DAS::GetDirectory
TDirectory * GetDirectory(TDirectory *dir, const std::vector< const char * > &names)
Get ((...)sub)subdirectory of dir.
Definition: toolbox.h:57
DAS::pt_sort
bool pt_sort(const PhysicsObject &j1, const PhysicsObject &j2)
Definition: toolbox.h:18
PhysicsObject.h
DAS::PhysicsObject::CorrPt
float CorrPt(size_t i=0) const
corrected transverse momentum
Definition: PhysicsObject.h:55
DAS::branchExists
bool branchExists(const TTreePtr &tree, TString brName)
Definition: toolbox.h:29
DAS::GetObjects
std::vector< T * > GetObjects(TDirectory *dir)
Find all objects of type T directly in a TDirectory (i.e. not recursive)
Definition: toolbox.h:42