ATLAS Offline Software
JetCalibUtils.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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 
12 namespace 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  VecD result;
28  TObjArray* tokens = str.Tokenize(sep);
29  TIter istr(tokens);
30  while (TObjString* os=(TObjString*)istr())
31  result.push_back(atof(os->GetString()));
32  delete tokens;
33  return result;
34  }
35 
36  template<class H>
37  std::unique_ptr<const H> GetHisto_impl(TFile& file, const TString& hname) {
38  std::unique_ptr<H> h(static_cast<H*>(file.Get(hname)));
39  if (h==nullptr) {
40  std::cout << "WARNING: Cannot access histogram " << hname.Data()
41  << " in file " << file.GetName() << std::endl;
42  }
43  else {
44  h->SetDirectory(nullptr); // make histogram memory-resident
45  }
46  return h;
47  }
48 
49  std::unique_ptr<const TH1> GetHisto(TFile& file, const TString& hname) {
50  return GetHisto_impl<TH1>(file, hname);
51  }
52 
53  std::unique_ptr<const TH2> GetHisto2(TFile& file, const TString& hname) {
54  return GetHisto_impl<TH2>(file, hname);
55  }
56 
57  std::unique_ptr<const TH3> GetHisto3(TFile& file, const TString& hname) {
58  return GetHisto_impl<TH3>(file, hname);
59  }
60 
61  TTree *setTree(TTree *tree) { return tree; }
62 
63 }
get_generator_info.result
result
Definition: get_generator_info.py:21
dqt_zlumi_pandas.hname
string hname
Definition: dqt_zlumi_pandas.py:279
JetCalibUtils::GetHisto2
std::unique_ptr< const TH2 > GetHisto2(TFile &file, const TString &hname)
Definition: JetCalibUtils.cxx:53
tree
TChain * tree
Definition: tile_monitor.h:30
beamspotman.tokens
tokens
Definition: beamspotman.py:1284
JetCalibUtils::Vectorize
StrV Vectorize(const TString &str, const TString &sep=" ")
Definition: JetCalibUtils.cxx:14
JetCalibUtils
Definition: JetCalibUtils.h:25
H
#define H(x, y, z)
Definition: MD5.cxx:114
JetCalibUtils::setTree
TTree * setTree(TTree *tree)
Definition: JetCalibUtils.cxx:61
extractSporadic.h
list h
Definition: extractSporadic.py:97
JetCalibUtils::GetHisto3
std::unique_ptr< const TH3 > GetHisto3(TFile &file, const TString &hname)
Definition: JetCalibUtils.cxx:57
file
TFile * file
Definition: tile_monitor.h:29
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
CxxUtils::atof
double atof(std::string_view str)
Converts a string into a double / float.
Definition: Control/CxxUtils/Root/StringUtils.cxx:91
grepfile.sep
sep
Definition: grepfile.py:38
JetCalibUtils.h
StrV
std::vector< TString > StrV
Definition: JetCalibUtils.h:22
h
str
Definition: BTagTrackIpAccessor.cxx:11
VecD
std::vector< double > VecD
Definition: JetCalibUtils.h:23
JetCalibUtils::VectorizeD
VecD VectorizeD(const TString &str, const TString &sep=" ")
Definition: JetCalibUtils.cxx:25
JetCalibUtils::GetHisto
std::unique_ptr< const TH1 > GetHisto(TFile &file, const TString &hname)
Definition: JetCalibUtils.cxx:49
JetCalibUtils::GetHisto_impl
std::unique_ptr< const H > GetHisto_impl(TFile &file, const TString &hname)
Definition: JetCalibUtils.cxx:37