ATLAS Offline Software
CalibContainer.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // c++
6 #include <iostream>
7 #include <stdexcept>
8 
9 // Local include(s):
12 
13 // Root
14 #include <TFile.h>
15 
16 namespace MCP {
17 
18  CalibContainer::CalibContainer(const std::string& inFileName, const std::string& histName)
19  {
20 
21  if (inFileName.empty()) throw std::invalid_argument("fileName arguments must be non empty");
22  if (histName.empty()) throw std::invalid_argument("histName arguments must be non empty");
23 
25 
26  std::unique_ptr<TFile> fmc{TFile::Open(fileName.c_str(), "READ")};
27  if (!fmc || !fmc->IsOpen())
28  {
29  throw std::invalid_argument("Cannot open file " + fileName);
30  }
31 
32  TH2* hist = nullptr;
33  fmc->GetObject(histName.c_str(), hist);
34  if (!hist)
35  {
36  throw std::invalid_argument("Cannot find hist ("+histName+") in file " + fileName);
37  }
38  hist->SetDirectory(nullptr);
40 
41  // Store to check later if the input ranges are within the range of the hist
42  // subtract epsilon so that it doesn't go into the overflow bin at the highest edge
43  m_maxX = m_calibConstantHist->GetXaxis()->GetXmax() - std::numeric_limits<double>::epsilon();
44  m_minX = m_calibConstantHist->GetXaxis()->GetXmin() + std::numeric_limits<double>::epsilon();
45  m_maxY = m_calibConstantHist->GetYaxis()->GetXmax() - std::numeric_limits<double>::epsilon();
46  m_minY = m_calibConstantHist->GetYaxis()->GetXmin() + std::numeric_limits<double>::epsilon();
47 
48  }
49 
51  {
52  // If outside the range, use the last bin in either direction
53  const int binEta = m_calibConstantHist->GetXaxis()->FindFixBin(std::max(std::min(trk.eta,m_maxX),m_minX));
54  const int binPhi = m_calibConstantHist->GetYaxis()->FindFixBin(std::max(std::min(trk.phi,m_maxY),m_minY));
55 
56  int gbin = m_calibConstantHist->GetBin(binEta, binPhi);
57 
58  return m_calibConstantHist->GetBinContent(gbin);
59  }
60 
61 }
AddEmptyComponent.histName
string histName
Definition: AddEmptyComponent.py:64
MCP::CalibContainer::CalibContainer
CalibContainer(const std::string &fileName, const std::string &histName)
Definition: CalibContainer.cxx:18
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
plotmaker.hist
hist
Definition: plotmaker.py:148
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
CalibContainer.h
Trk::binEta
@ binEta
Definition: BinningType.h:54
MCP::CalibContainer::m_minX
double m_minX
Definition: CalibContainer.h:30
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
IDTPMcnv.inFileName
inFileName
Definition: IDTPMcnv.py:17
MCP::TrackCalibObj::eta
const double eta
Value of the track-eta.
Definition: MuonObj.h:104
MCP::CalibContainer::m_maxY
double m_maxY
Definition: CalibContainer.h:31
MCP::CalibContainer::m_minY
double m_minY
Definition: CalibContainer.h:32
PathResolver.h
MCP::TrackCalibObj::phi
const double phi
Value of the track-phi.
Definition: MuonObj.h:106
MCP::CalibContainer::m_maxX
double m_maxX
Definition: CalibContainer.h:29
MCP
Definition: CalibContainer.h:18
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
MCP::CalibContainer::getCalibConstant
double getCalibConstant(const TrackCalibObj &trk) const
Definition: CalibContainer.cxx:50
MCP::TrackCalibObj
Basic object to cache all relevant information from the track.
Definition: MuonObj.h:21
Trk::binPhi
@ binPhi
Definition: BinningType.h:51
MCP::CalibContainer::m_calibConstantHist
std::unique_ptr< const TH1 > m_calibConstantHist
Definition: CalibContainer.h:28