ATLAS Offline Software
Functions
jet::utils Namespace Reference

Functions

template<typename T >
bool isTypeObjFromString (const std::string &str)
 
template<typename T >
bool isTypeObjFromString (const TString &str)
 
template<typename T >
bool getTypeObjFromString (const std::string &str, T &obj)
 
template<typename T >
getTypeObjFromString (const std::string &str)
 
template<typename T >
bool getTypeObjFromString (const TString &str, T &obj)
 
template<typename T >
getTypeObjFromString (const TString &str)
 
template<>
bool getTypeObjFromString< std::string > (const std::string &str, std::string &obj)
 
template<>
bool getTypeObjFromString< TString > (const std::string &str, TString &obj)
 
template<>
bool getTypeObjFromString< bool > (const std::string &str, bool &obj)
 
template<>
bool getTypeObjFromString< std::string > (const TString &str, std::string &obj)
 
template<>
bool getTypeObjFromString< TString > (const TString &str, TString &obj)
 
template<>
bool getTypeObjFromString< bool > (const TString &str, bool &obj)
 
template<typename T >
bool vectorize (const TString &str, const TString &sep, std::vector< T > &result)
 
template<typename T >
std::vector< T > vectorize (const TString &str, const TString &sep)
 
bool fileExists (const TString &fileName)
 
TString findFilePath (const TString &fileName, const TString &path="", const TString &calibArea="")
 
TFile * readRootFile (const TString &fileName, const TString &path="", const TString &calibArea="")
 
std::vector< double > getLogBins (const size_t numBins, const double minVal, const double maxVal)
 
std::vector< double > getUniformBins (const size_t numBins, const double minVal, const double maxVal)
 
void scaleHistoAxes (TH1 *toScale, const double factorX=1, const double factorY=1, const double factorZ=1)
 

Function Documentation

◆ fileExists()

bool jet::utils::fileExists ( const TString &  fileName)

Definition at line 94 of file Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx.

95 {
96  return !gSystem->AccessPathName(fileName);
97 }

◆ findFilePath()

TString jet::utils::findFilePath ( const TString &  fileName,
const TString &  path = "",
const TString &  calibArea = "" 
)

Definition at line 99 of file Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx.

100 {
101  TString pathToGet = "";
102 
103  // First, try the raw filename plus path (user-specified), then raw filename (local or full path)
104  if (path != "" && fileExists(path+(path.EndsWith("/")?"":"/")+fileName))
105  pathToGet = path+(path.EndsWith("/")?"":"/")+fileName;
106  else if (fileExists(fileName))
107  pathToGet = fileName;
108 
109  // Next, try PathResolver in a few configurations
110  // PathResolver #1: versioned CalibArea (most users should be in this case)
111  //coverity[copy_paste_error]
112  if (pathToGet == "" && calibArea != "")
113  pathToGet = TString(PathResolverFindCalibFile(Form("JetUncertainties/%s/%s",calibArea.Data(),fileName.Data())).c_str());
114  // PathResolver #2: unversioned CalibArea (legacy support)
115  if (pathToGet == "" && calibArea == "")
116  pathToGet = TString(PathResolverFindCalibFile(Form("JetUncertainties/%s",fileName.Data())).c_str());
117  // PathResolver #3: general search in case of files residing in other packages (request from a Higgs group)
118  if (pathToGet == "")
119  pathToGet = TString(PathResolverFindCalibFile(fileName.Data()).c_str());
120 
121  // Try backup locations now (legacy support)
122  if (pathToGet == "")
123  {
124  // Try ROOTCOREBIN
125  if (TString(gSystem->Getenv("ROOTCOREBIN")) != "" && fileExists(TString(gSystem->Getenv("ROOTCOREBIN"))+"/data/JetUncertainties/"+fileName))
126  pathToGet = TString(gSystem->Getenv("ROOTCOREBIN"))+"/data/JetUncertainties/"+fileName;
127  // Try ROOTCOREDIR
128  else if (TString(gSystem->Getenv("ROOTCOREDIR")) != "" && fileExists(TString(gSystem->Getenv("ROOTCOREDIR"))+"/data/JetUncertainties/"+fileName))
129  pathToGet = TString(gSystem->Getenv("ROOTCOREDIR"))+"/data/JetUncertainties/"+fileName;
130  // Try standard athena location
131  else if (TString(gSystem->Getenv("TestArea")) != "" && fileExists(TString(gSystem->Getenv("TestArea"))+"/Reconstruction/Jet/JetUncertainties/share/"+fileName))
132  pathToGet = TString(gSystem->Getenv("TestArea"))+"/Reconstruction/Jet/JetUncertainties/share/"+fileName;
133  }
134 
135  // Give up, hopefully sucessfully
136  // User must check if return is "" (failed) or an actual path (success)
137  return pathToGet;
138 }

◆ getLogBins()

std::vector< double > jet::utils::getLogBins ( const size_t  numBins,
const double  minVal,
const double  maxVal 
)

Definition at line 153 of file Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx.

154 {
155  std::vector<double> bins;
156  bins.resize(numBins+1);
157 
158  const double dx = (log(maxVal)-log(minVal))/numBins;
159  for (size_t iBin = 0; iBin <= numBins; ++iBin)
160  bins[iBin] = exp(log(minVal)+iBin*dx);
161 
162  return bins;
163 }

◆ getTypeObjFromString() [1/4]

template<typename T >
T jet::utils::getTypeObjFromString ( const std::string &  str)

Definition at line 122 of file Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h.

123 {
124  T toReturn;
125  if (!getTypeObjFromString(str,toReturn))
126  printf("Failed to convert object: %s\n",str.c_str());
127 
128  return toReturn;
129 }

◆ getTypeObjFromString() [2/4]

template<typename T >
bool jet::utils::getTypeObjFromString ( const std::string &  str,
T &  obj 
)

Definition at line 116 of file Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h.

117 {
118  std::istringstream iss(str);
119  return !(iss >> obj).fail();
120 }

◆ getTypeObjFromString() [3/4]

template<typename T >
T jet::utils::getTypeObjFromString ( const TString &  str)

Definition at line 137 of file Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h.

138 {
139  T toReturn;
140  if (!getTypeObjFromString(str,toReturn))
141  printf("ERROR: Failed to convert object: %s\n",str.Data());
142 
143  return toReturn;
144 }

◆ getTypeObjFromString() [4/4]

template<typename T >
bool jet::utils::getTypeObjFromString ( const TString &  str,
T &  obj 
)

Definition at line 131 of file Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h.

132 {
133  std::string stdstr = str.Data();
134  return getTypeObjFromString(stdstr,obj);
135 }

◆ getTypeObjFromString< bool >() [1/2]

template<>
bool jet::utils::getTypeObjFromString< bool > ( const std::string &  str,
bool &  obj 
)

Definition at line 33 of file Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx.

34 {
35  bool toReturn = false;
36  if (str == "true" || str == "True" || str == "TRUE")
37  {
38  obj = true;
39  toReturn = true;
40  }
41  else if (str == "false" || str == "False" || str == "FALSE")
42  {
43  obj = false;
44  toReturn = true;
45  }
46  else
47  {
48  int value;
49  toReturn = getTypeObjFromString<int>(str,value);
50  if (toReturn)
51  obj = static_cast<bool>(value);
52  }
53  return toReturn;
54 }

◆ getTypeObjFromString< bool >() [2/2]

template<>
bool jet::utils::getTypeObjFromString< bool > ( const TString &  str,
bool &  obj 
)

Definition at line 71 of file Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx.

72 {
73  bool toReturn = false;
74  if (str.EqualTo("true",TString::kIgnoreCase))
75  {
76  obj = true;
77  toReturn = true;
78  }
79  else if (str.EqualTo("false",TString::kIgnoreCase))
80  {
81  obj = false;
82  toReturn = true;
83  }
84  else
85  {
86  int value;
87  toReturn = getTypeObjFromString<int>(str,value);
88  if (toReturn)
89  obj = static_cast<bool>(value);
90  }
91  return toReturn;
92 }

◆ getTypeObjFromString< std::string >() [1/2]

template<>
bool jet::utils::getTypeObjFromString< std::string > ( const std::string &  str,
std::string &  obj 
)

Definition at line 19 of file Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx.

20 {
21  obj = str;
22  return true;
23 }

◆ getTypeObjFromString< std::string >() [2/2]

template<>
bool jet::utils::getTypeObjFromString< std::string > ( const TString &  str,
std::string &  obj 
)

Definition at line 57 of file Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx.

58 {
59  obj = str.Data();
60  return true;
61 }

◆ getTypeObjFromString< TString >() [1/2]

template<>
bool jet::utils::getTypeObjFromString< TString > ( const std::string &  str,
TString &  obj 
)

Definition at line 26 of file Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx.

27 {
28  obj = str.c_str();
29  return true;
30 }

◆ getTypeObjFromString< TString >() [2/2]

template<>
bool jet::utils::getTypeObjFromString< TString > ( const TString &  str,
TString &  obj 
)

Definition at line 64 of file Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx.

65 {
66  obj = str;
67  return true;
68 }

◆ getUniformBins()

std::vector< double > jet::utils::getUniformBins ( const size_t  numBins,
const double  minVal,
const double  maxVal 
)

Definition at line 165 of file Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx.

166 {
167  std::vector<double> bins;
168  bins.resize(numBins+1);
169 
170  const double dx = (maxVal-minVal)/numBins;
171  for (size_t iBin = 0; iBin <= numBins; ++iBin)
172  bins[iBin] = minVal+iBin*dx;
173 
174  return bins;
175 }

◆ isTypeObjFromString() [1/2]

template<typename T >
bool jet::utils::isTypeObjFromString ( const std::string &  str)

Definition at line 101 of file Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h.

102 {
103  std::istringstream iss(str);
104  T obj;
105  return !(iss >> obj).fail();
106 }

◆ isTypeObjFromString() [2/2]

template<typename T >
bool jet::utils::isTypeObjFromString ( const TString &  str)

Definition at line 109 of file Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h.

110 {
111  std::string stdstr = str.Data();
112  return isTypeObjFromString<T>(stdstr);
113 }

◆ readRootFile()

TFile * jet::utils::readRootFile ( const TString &  fileName,
const TString &  path = "",
const TString &  calibArea = "" 
)

Definition at line 140 of file Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx.

141 {
142  TFile* rootFile = nullptr;
143 
144  TString pathToGet = findFilePath(fileName,path,calibArea);
145  //std::cout << "Looking for file " << fileName << " in path " << path << std::endl;
146 
147  if (pathToGet != "")
148  rootFile = new TFile(pathToGet,"READ");
149  return rootFile;
150 }

◆ scaleHistoAxes()

void jet::utils::scaleHistoAxes ( TH1 *  toScale,
const double  factorX = 1,
const double  factorY = 1,
const double  factorZ = 1 
)

Definition at line 178 of file Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx.

179 {
180  const int dim = toScale->GetDimension();
181 
182  // Check for simple copies and sanity checks
183  bool returnDuplicate = false;
184  if ( dim == 1 && (factorX < 0 || fabs(factorX-1) < 1.e-4) )
185  returnDuplicate = true;
186  else if ( dim == 2 && (factorX < 0 || fabs(factorX-1) < 1.e-4)
187  && (factorY < 0 || fabs(factorY-1) < 1.e-4) )
188  returnDuplicate = true;
189  else if ( dim == 3 && (factorX < 0 || fabs(factorX-1) < 1.e-4)
190  && (factorY < 0 || fabs(factorY-1) < 1.e-4)
191  && (factorZ < 0 || fabs(factorZ-1) < 1.e-4) )
192  returnDuplicate = true;
193  if (returnDuplicate)
194  {
195  printf("ScaleHistoAxes: Doing nothing, as all scale factors require no changes\n");
196  return;
197  }
198 
199  // Let negative numbers mean no change
200  const double facX = factorX < 0 ? 1 : factorX;
201  const double facY = factorY < 0 ? 1 : factorY;
202  const double facZ = factorZ < 0 ? 1 : factorZ;
203 
204  // Scale the x axis if necessary
205  if (fabs(facX-1) > 1.e-4)
206  {
207  std::vector<double> binsX;
208  for (int iBin = 1; iBin <= toScale->GetNbinsX()+1; ++iBin)
209  binsX.push_back(toScale->GetXaxis()->GetBinLowEdge(iBin)*facX);
210  toScale->GetXaxis()->Set(binsX.size()-1,&binsX[0]);
211  }
212  // Scale the y axis if necessary
213  if (dim > 1 && fabs(facY-1) > 1.e-4)
214  {
215  std::vector<double> binsY;
216  for (int iBin = 1; iBin <= toScale->GetNbinsY()+1; ++iBin)
217  binsY.push_back(toScale->GetYaxis()->GetBinLowEdge(iBin)*facY);
218  toScale->GetYaxis()->Set(binsY.size()-1,&binsY[0]);
219  }
220  // Scale the z axis if necessary
221  if (dim > 2 && fabs(facZ-1) > 1.e-4)
222  {
223  std::vector<double> binsZ;
224  for (int iBin = 1; iBin <= toScale->GetNbinsZ()+1; ++iBin)
225  binsZ.push_back(toScale->GetZaxis()->GetBinLowEdge(iBin)*facZ);
226  toScale->GetZaxis()->Set(binsZ.size()-1,&binsZ[0]);
227  }
228 
229 }

◆ vectorize() [1/2]

template<typename T >
std::vector< T > jet::utils::vectorize ( const TString &  str,
const TString &  sep 
)

Definition at line 171 of file Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h.

172 {
173  std::vector<T> result;
174  TObjArray* tokens = str.Tokenize(sep);
175  TIter istr(tokens);
176 
177  while(TObjString* os=(TObjString*)istr())
178  {
179  T obj;
180  if (!getTypeObjFromString(os->GetString(),obj))
181  printf("ERROR: String \"%s\" is not the requested type\n",os->GetString().Data());
182  result.push_back(obj);
183  }
184  delete tokens;
185 
186  return result;
187 }

◆ vectorize() [2/2]

template<typename T >
bool jet::utils::vectorize ( const TString &  str,
const TString &  sep,
std::vector< T > &  result 
)

Definition at line 147 of file Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h.

148 {
149  bool success = true;
150  result.clear();
151 
152  TObjArray* tokens = str.Tokenize(sep);
153  TIter istr(tokens);
154  while(TObjString* os=(TObjString*)istr())
155  {
156  T obj;
157  if (!getTypeObjFromString(os->GetString(),obj))
158  {
159  success = false;
160  break;
161  }
162  else
163  result.push_back(obj);
164  }
165  delete tokens;
166 
167  return success;
168 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
yodamerge_tmp.dim
dim
Definition: yodamerge_tmp.py:239
get_generator_info.result
result
Definition: get_generator_info.py:21
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
jet::utils::getTypeObjFromString
T getTypeObjFromString(const TString &str)
Definition: Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h:137
ChangeHistoRange.binsZ
list binsZ
Definition: ChangeHistoRange.py:63
athena.value
value
Definition: athena.py:124
beamspotman.tokens
tokens
Definition: beamspotman.py:1280
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
ChangeHistoRange.binsY
list binsY
Definition: ChangeHistoRange.py:59
python.CaloAddPedShiftConfig.str
str
Definition: CaloAddPedShiftConfig.py:42
makeComparison.rootFile
rootFile
Definition: makeComparison.py:27
plotting.yearwise_luminosity_vs_mu.bins
bins
Definition: yearwise_luminosity_vs_mu.py:30
CreateTrfArgs.fileExists
def fileExists(fp)
Definition: CreateTrfArgs.py:4
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:226
grepfile.sep
sep
Definition: grepfile.py:38
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:321
jet::utils::findFilePath
TString findFilePath(const TString &fileName, const TString &path="", const TString &calibArea="")
Definition: Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx:99
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
ChangeHistoRange.binsX
list binsX
Definition: ChangeHistoRange.py:56
str
Definition: BTagTrackIpAccessor.cxx:11
jobOptions.fileName
fileName
Definition: jobOptions.SuperChic_ALP2.py:39
python.PyAthena.obj
obj
Definition: PyAthena.py:132
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
beamspotman.fail
def fail(message)
Definition: beamspotman.py:197