ATLAS Offline Software
Loading...
Searching...
No Matches
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
16namespace 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
24 auto fileName = PathResolverFindCalibFile(inFileName);
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 if (histName.find("ptExtra") != std::string::npos) {
36 // exceptional condition, to make it compatible with old recommendations
37 m_calibConstantHist.reset(nullptr);
38 } else {
39 throw std::invalid_argument("Cannot find hist ("+histName+") in file " + fileName);
40 }
41 } else {
42 hist->SetDirectory(nullptr);
43 m_calibConstantHist.reset(hist);
44
45 // Store to check later if the input ranges are within the range of the hist
46 // subtract epsilon so that it doesn't go into the overflow bin at the highest edge
47 m_maxX = m_calibConstantHist->GetXaxis()->GetXmax() - std::numeric_limits<double>::epsilon();
48 m_minX = m_calibConstantHist->GetXaxis()->GetXmin() + std::numeric_limits<double>::epsilon();
49 m_maxY = m_calibConstantHist->GetYaxis()->GetXmax() - std::numeric_limits<double>::epsilon();
50 m_minY = m_calibConstantHist->GetYaxis()->GetXmin() + std::numeric_limits<double>::epsilon();
51 }
52 }
53
55 {
56 // If outside the range, use the last bin in either direction
57 const int binEta = m_calibConstantHist->GetXaxis()->FindFixBin(std::max(std::min(trk.eta,m_maxX),m_minX));
58 const int binPhi = m_calibConstantHist->GetYaxis()->FindFixBin(std::max(std::min(trk.phi,m_maxY),m_minY));
59
60 int gbin = m_calibConstantHist->GetBin(binEta, binPhi);
61
62 return m_calibConstantHist->GetBinContent(gbin);
63 }
64
65}
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
double getCalibConstant(const TrackCalibObj &trk) const
std::unique_ptr< const TH1 > m_calibConstantHist
CalibContainer(const std::string &fileName, const std::string &histName)
Basic object to cache all relevant information from the track.
Definition MuonObj.h:74
const double eta
Value of the track-eta.
Definition MuonObj.h:157
const double phi
Value of the track-phi.
Definition MuonObj.h:159