ATLAS Offline Software
Loading...
Searching...
No Matches
JetCalibUtils.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
5
6#include <cstdlib>
7#include <iostream>
8#include "TMath.h"
9#include "TObjArray.h"
10#include "TSystem.h"
11
12namespace JetCalibUtils {
13
14 StrV Vectorize(const TString& str, const TString& sep)
15 {
16 StrV result;
17 TObjArray* tokens = str.Tokenize(sep);
18 TIter istr(tokens);
19 while (TObjString* os=(TObjString*)istr())
20 result.push_back(os->GetString());
21 delete tokens;
22 return result;
23 }
24
25 VecD VectorizeD(const TString& str, const TString& sep)
26 {
27 std::vector<double> result;
28 std::unique_ptr<TObjArray> tokens(str.Tokenize(sep));
29 std::unique_ptr<TIter> istr(new TIter(tokens.get()));
30 while (TObjString* os = dynamic_cast<TObjString*>(istr->Next())) {
31 result.push_back(atof(os->GetString()));
32 }
33
34 return result;
35 }
36
37 template<class H>
38 std::unique_ptr<const H> GetHisto_impl(TFile& file, const TString& hname) {
39 std::unique_ptr<H> h(static_cast<H*>(file.Get(hname)));
40 if (h==nullptr) {
41 std::cout << "WARNING: Cannot access histogram " << hname.Data()
42 << " in file " << file.GetName() << std::endl;
43 }
44 else {
45 h->SetDirectory(nullptr); // make histogram memory-resident
46 }
47 return h;
48 }
49
50 std::unique_ptr<const TH1> GetHisto(TFile& file, const TString& hname) {
51 return GetHisto_impl<TH1>(file, hname);
52 }
53
54 std::unique_ptr<const TH2> GetHisto2(TFile& file, const TString& hname) {
55 return GetHisto_impl<TH2>(file, hname);
56 }
57
58 std::unique_ptr<const TH3> GetHisto3(TFile& file, const TString& hname) {
59 return GetHisto_impl<TH3>(file, hname);
60 }
61
62 TTree *setTree(TTree *tree) { return tree; }
63
64}
std::vector< double > VecD
std::vector< TString > StrV
#define H(x, y, z)
Definition MD5.cxx:114
Header file for AthHistogramAlgorithm.
StrV Vectorize(const TString &str, const TString &sep=" ")
std::unique_ptr< const H > GetHisto_impl(TFile &file, const TString &hname)
std::unique_ptr< const TH2 > GetHisto2(TFile &file, const TString &hname)
VecD VectorizeD(const TString &str, const TString &sep=" ")
std::unique_ptr< const TH1 > GetHisto(TFile &file, const TString &hname)
TTree * setTree(TTree *tree)
std::unique_ptr< const TH3 > GetHisto3(TFile &file, const TString &hname)
TChain * tree
TFile * file