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  if (pathToGet == "" && calibArea != "")
112  pathToGet = TString(PathResolverFindCalibFile(Form("JetUncertainties/%s/%s",calibArea.Data(),fileName.Data())).c_str());
113  // PathResolver #2: unversioned CalibArea (legacy support)
114  if (pathToGet == "" && calibArea == "")
115  pathToGet = TString(PathResolverFindCalibFile(Form("JetUncertainties/%s",fileName.Data())).c_str());
116  // PathResolver #3: general search in case of files residing in other packages (request from a Higgs group)
117  if (pathToGet == "")
118  pathToGet = TString(PathResolverFindCalibFile(fileName.Data()).c_str());
119 
120  // Try backup locations now (legacy support)
121  if (pathToGet == "")
122  {
123  // Try ROOTCOREBIN
124  if (TString(gSystem->Getenv("ROOTCOREBIN")) != "" && fileExists(TString(gSystem->Getenv("ROOTCOREBIN"))+"/data/JetUncertainties/"+fileName))
125  pathToGet = TString(gSystem->Getenv("ROOTCOREBIN"))+"/data/JetUncertainties/"+fileName;
126  // Try ROOTCOREDIR
127  else if (TString(gSystem->Getenv("ROOTCOREDIR")) != "" && fileExists(TString(gSystem->Getenv("ROOTCOREDIR"))+"/data/JetUncertainties/"+fileName))
128  pathToGet = TString(gSystem->Getenv("ROOTCOREDIR"))+"/data/JetUncertainties/"+fileName;
129  // Try standard athena location
130  else if (TString(gSystem->Getenv("TestArea")) != "" && fileExists(TString(gSystem->Getenv("TestArea"))+"/Reconstruction/Jet/JetUncertainties/share/"+fileName))
131  pathToGet = TString(gSystem->Getenv("TestArea"))+"/Reconstruction/Jet/JetUncertainties/share/"+fileName;
132  }
133 
134  // Give up, hopefully sucessfully
135  // User must check if return is "" (failed) or an actual path (success)
136  return pathToGet;
137 }

◆ getLogBins()

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

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

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

◆ 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 164 of file Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx.

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

◆ 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 139 of file Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx.

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

◆ scaleHistoAxes()

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

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

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

◆ 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 }
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:126
python.App.bins
bins
Definition: App.py:410
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:122
beamspotman.tokens
tokens
Definition: beamspotman.py:1284
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
ChangeHistoRange.binsY
list binsY
Definition: ChangeHistoRange.py:59
makeComparison.rootFile
rootFile
Definition: makeComparison.py:27
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
grepfile.sep
sep
Definition: grepfile.py:38
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
jet::utils::findFilePath
TString findFilePath(const TString &fileName, const TString &path="", const TString &calibArea="")
Definition: Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx:99
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
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
python.PyAthena.obj
obj
Definition: PyAthena.py:135
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
beamspotman.fail
def fail(message)
Definition: beamspotman.py:201
fileExists
bool fileExists(const std::string &filename)
Definition: main_comphistfiles.cxx:57