ATLAS Offline Software
get_MaterialResolutionEffect.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 #include "TArrayD.h"
9 #include "TFile.h"
10 #include "TH1.h"
11 #include "TH2.h"
12 
13 namespace {
14 template <typename TargetPtr, typename SourcePtr>
15 TargetPtr checked_cast(SourcePtr ptr) {
17  "attempt to cast to no ptr object");
19  "attempt to cast from no ptr object");
20  if (!ptr) {
21  throw std::runtime_error(
22  "Attempt to cast from nullptr in get_MaterialResolutionEffect");
23  }
24  TargetPtr obj = dynamic_cast<TargetPtr>(ptr);
25  if (not obj) {
26  throw std::runtime_error("failed dynamic cast for " +
27  std::string(ptr->GetName()) +
28  " get_MaterialResolutionEffect");
29  }
30  return obj;
31 }
32 } // namespace
33 
35  : asg::AsgMessaging("get_MaterialResolutionEffect") {
36 
37  const std::string pType[3] = {"Elec", "Unconv", "Conv"};
38  const std::string sType[s_nSys] = {"A", "CD", "EL", "FMX"};
39 
40  const std::string filename = PathResolverFindCalibFile(
41  "ElectronPhotonFourMomentumCorrection/v8/"
42  "histos-systematics-material.root");
43 
44  std::unique_ptr<TFile> file0(TFile::Open(filename.c_str(), "READ"));
45 
46  for (Int_t isys = 0; isys < s_nSys; isys++) { // 0=A, 1=CD, 2=EL, 3=FMX
47  for (Int_t ieta = 0; ieta < s_nEtaBins; ieta++) {
48  for (Int_t iconv = 0; iconv < 3;
49  iconv++) { // 0=electron, 1=unconverted, 2=converted
50  char name[31];
51  sprintf(name, "syst%s_%s_etaBin_%d", pType[iconv].c_str(),
52  sType[isys].c_str(), ieta);
53  m_hSystPeak.at(isys).at(ieta).at(iconv).reset(
54  checked_cast<TH1*>(file0->Get(name)));
55  m_hSystPeak.at(isys).at(ieta).at(iconv)->SetDirectory(nullptr);
56 
57  sprintf(name, "syst%s_sigmaG_%s_etaBin_%d", pType[iconv].c_str(),
58  sType[isys].c_str(), ieta);
59  m_hSystResol.at(isys).at(ieta).at(iconv).reset(
60  checked_cast<TH1*>(file0->Get(name)));
61  m_hSystResol.at(isys).at(ieta).at(iconv)->SetDirectory(nullptr);
62  }
63  }
64  }
65 
66  // IBL+PP0 material systematics stored in 2D histograms
67  m_hsyst_IBL_PP0.at(0).reset(
68  checked_cast<TH2*>(file0->Get("systElec_IBLPP0")));
69  m_hsyst_IBL_PP0.at(0)->SetDirectory(nullptr);
70 
71  m_hsyst_IBL_PP0.at(1).reset(
72  checked_cast<TH2*>(file0->Get("systUnconv_IBLPP0")));
73  m_hsyst_IBL_PP0.at(1)->SetDirectory(nullptr);
74 
75  m_hsyst_IBL_PP0.at(2).reset(
76  checked_cast<TH2*>(file0->Get("systConv_IBLPP0")));
77  m_hsyst_IBL_PP0.at(2)->SetDirectory(nullptr);
78 
79  m_etBins = m_hSystResol.at(0).at(0).at(1)->GetXaxis()->GetXbins();
80 }
81 
82 //============================================================================
83 // inputs are particle_type (0=elec, 1=reco unconv photon, 2=reco conv photon,
84 // 3=true unconv photon)
85 // energy in MeV
86 // eta
87 // response_type (0=gaussian core fit, 1=sigmaeff 80%, 2=sigma eff
88 // 90%)
89 //
90 // returned value is sigmaE/E change in quadrature to resolution
91 //
93  double eta, int response_type,
94  int isyst) const {
95 
96  // cout << " in getDelta " << endl;
97  if (particle_type < 0 || particle_type > 2)
98  return -999;
99  if (response_type < 0 || response_type > 1)
100  return -999;
101 
102  float aeta = std::fabs(eta);
103  double energyGeV = energy * 0.001;
104  double et = energyGeV / cosh(eta);
105 
106  // IBL+PP0
107  if (isyst == 5) {
108  double et2 = et;
109  if (et < 5.) {
110  et2 = 5.1;
111  }
112  if (et > 2000) {
113  et2 = 1999.;
114  }
115  return 0.01 *
117  ->GetBinContent(
118  m_hsyst_IBL_PP0.at(particle_type)->GetXaxis()->FindBin(aeta),
119  m_hsyst_IBL_PP0.at(particle_type)->GetYaxis()->FindBin(et2));
120  }
121 
122  int ieta = 0;
123  if (aeta < 0.4) {
124  ieta = 0;
125  } else if (aeta < 0.8) {
126  ieta = 1;
127  } else if (aeta < 1.1) {
128  ieta = 2;
129  } else if (aeta < 1.37) {
130  ieta = 3;
131  } else if (aeta < 1.52) {
132  ieta = 4;
133  } else if (aeta < 1.80) {
134  ieta = 5;
135  } else if (aeta < 2.10) {
136  ieta = 6;
137  } else {
138  ieta = 7;
139  }
140 
141  int ibinEt = m_etBins->GetSize() - 2;
142  for (int i = 1; i < m_etBins->GetSize(); i++) {
143  if (et < m_etBins->GetAt(i)) {
144  ibinEt = i - 1;
145  break;
146  }
147  }
148 
149  if (response_type == 0) {
150  return 0.01 * m_hSystPeak.at(isyst)
151  .at(ieta)
152  .at(particle_type)
153  ->GetBinContent(ibinEt + 1);
154  } else {
155  return 0.01 * m_hSystResol.at(isyst)
156  .at(ieta)
157  .at(particle_type)
158  ->GetBinContent(ibinEt + 1);
159  }
160 }
et
Extra patterns decribing particle interation process.
xAOD::et
et
Definition: TrigEMCluster_v1.cxx:25
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
asg
Definition: DataHandleTestTool.h:28
EgammaARTmonitoring_plotsMaker.particle_type
particle_type
Definition: EgammaARTmonitoring_plotsMaker.py:633
athena.value
value
Definition: athena.py:122
get_MaterialResolutionEffect::getDelta
double getDelta(int particle_type, double energy, double eta, int response_type, int isyst) const
get material effect on resolution from distorted geometry as difference to 40 GeV Et electrons smeari...
Definition: get_MaterialResolutionEffect.cxx:92
get_MaterialResolutionEffect::s_nSys
static const int s_nSys
Definition: get_MaterialResolutionEffect.h:52
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
lumiFormat.i
int i
Definition: lumiFormat.py:92
get_MaterialResolutionEffect::get_MaterialResolutionEffect
get_MaterialResolutionEffect()
constructor (initialization done there reading root files with resolution fit parameters
Definition: get_MaterialResolutionEffect.cxx:34
get_MaterialResolutionEffect.h
get_MaterialResolutionEffect::m_etBins
const TArrayD * m_etBins
Definition: get_MaterialResolutionEffect.h:60
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
get_MaterialResolutionEffect::m_hSystPeak
std::array< std::array< std::array< std::unique_ptr< TH1 >, 3 >, s_nEtaBins >, s_nSys > m_hSystPeak
Definition: get_MaterialResolutionEffect.h:55
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
get_MaterialResolutionEffect::m_hSystResol
std::array< std::array< std::array< std::unique_ptr< TH1 >, 3 >, s_nEtaBins >, s_nSys > m_hSystResol
Definition: get_MaterialResolutionEffect.h:58
get_MaterialResolutionEffect::m_hsyst_IBL_PP0
std::array< std::unique_ptr< TH2 >, 3 > m_hsyst_IBL_PP0
Definition: get_MaterialResolutionEffect.h:59
get_MaterialResolutionEffect::s_nEtaBins
static const int s_nEtaBins
Definition: get_MaterialResolutionEffect.h:51
python.PyAthena.obj
obj
Definition: PyAthena.py:135