#include "TH1D.h" #include "TH2D.h" #include "THStack.h" #include "TGraph.h" #include "TTree.h" #include "TChain.h" #include "TFile.h" #include "TCanvas.h" #include "TROOT.h" #include "TStyle.h" #include "TColor.h" #include "TLorentzVector.h" #include "TRandom3.h" #include "TLorentzVector.h" #include "TString.h" #include "RooDataHist.h" #include "RooRealVar.h" #include "RooPlot.h" #include "RooGaussian.h" #include "RooExponential.h" #include "RooRealConstant.h" #include "RooAddPdf.h" #include "RooFitResult.h" #include "RooProduct.h" #include "RooCrystalBall.h" #include "RooBreitWigner.h" #include "RooArgSet.h" #include "RooFFTConvPdf.h" #include "RooNovosibirsk.h" #include #include #include #include template class Cut { public: virtual bool Check(T y) = 0; virtual std::string ToString() = 0; }; template class LT : public Cut { private: T value; public: LT(T val) : value{val} { } bool Check(T y) { return y < value; } std::string ToString() { return TString::Format("(x < %s)", std::to_string(value).c_str()).Data(); } }; template class GT : public Cut { private: T value; public: GT(T val) : value{val} {} bool Check(T y) { return y > value; } std::string ToString() { return TString::Format("(x > %s)", std::to_string(value).c_str()).Data(); } }; template class EQ : public Cut { private: T value; public: EQ(T val) : value{val} {} bool Check(T y) { return y == value; } std::string ToString() { return TString::Format("(x == %s)", std::to_string(value).c_str()).Data(); } }; template class BT : public Cut { private: T low; T up; public: BT(T lower, T upper) : low{lower}, up{upper} {} bool Check(T y) { return low < y && y < up; } std::string ToString() { return TString::Format("(x in [%s, %s])", std::to_string(low).c_str(), std::to_string(up).c_str()).Data(); } }; template class Variable { private: const char* name; std::vector*> cuts; T value; public: Variable() { } Variable(const char* name, std::vector*> cuts) { this->name = name; this->cuts = cuts; } T* GetValuePtr() { return &value; } T GetValue() const { return value; } }; class VariableCollection { private: std::map> doubles; std::map> floats; std::map> ints; std::map> bools; public: VariableCollection() { doubles = std::map>{}; floats = std::map>{}; ints = std::map>{}; bools = std::map>{}; } void Connect(TChain *chain) { for (auto& [key, var] : doubles) { chain->SetBranchAddress(key.c_str(), var.GetValuePtr()); } for (auto& [key, var] : floats) { chain->SetBranchAddress(key.c_str(), var.GetValuePtr()); } for (auto& [key, var] : ints) { chain->SetBranchAddress(key.c_str(), var.GetValuePtr()); } for (auto& [key, var] : bools) { chain->SetBranchAddress(key.c_str(), var.GetValuePtr()); } } void AddDouble(const char* name, const std::vector*>& cuts) { doubles[name] = Variable(name, cuts); } void AddFloat(const char* name, const std::vector*>& cuts) { floats[name] = Variable(name, cuts); } void AddInt(const char* name, const std::vector*>& cuts) { ints[name] = Variable(name, cuts); } void AddBool(const char* name, const std::vector*>& cuts) { bools[name] = Variable(name, cuts); } void PrintValues() { for (const auto& [key, var] : doubles) { std::cout << key << ": " << var.GetValue() << std::endl; } for (const auto& [key, var] : floats) { std::cout << key << ": " << var.GetValue() << std::endl; } for (const auto& [key, var] : ints) { std::cout << key << ": " << var.GetValue() << std::endl; } for (const auto& [key, var] : bools) { std::cout << key << ": " << var.GetValue() << std::endl; } } }; int do_all() { VariableCollection col{}; col.AddDouble("B_M", {}); col.AddDouble("Jpsi_M", {}); col.AddFloat("Kplus_PT", {}); col.AddBool("muminus_ISMUON", {}); col.AddInt("muplus_Q", {}); TChain *data_chain = new TChain(TString::Format("%s/DecayTree", "Hlt2RD_BuToKpMuMu").Data()); data_chain->Add("/auto/data/pfeiffer/inclusive_detached_dilepton/data_samples/Collision23_Beam6800GeV-VeloClosed-MagDown-Excl-UT_RealData_SprucingPass23r1_94000000_RD.root"); col.Connect(data_chain); data_chain->GetEntry(1); col.PrintValues(); data_chain->GetEntry(2); col.PrintValues(); return 0; }