ATLAS Offline Software
Loading...
Searching...
No Matches
LinearityADC.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include "TFile.h"
8
9LinearityADC::LinearityADC(const std::string& filename, const std::string& name)
10 : asg::AsgMessaging(name) {
11 ATH_MSG_INFO("Initialize LinearityADC with file " << filename);
12 std::unique_ptr<TFile> adcFile(TFile::Open(filename.c_str(), "READ"));
13 static const std::map<TString, PATCore::ParticleType::Type> pN = {
17 for (const auto & [ptclName, ptclType] : pN) {
18 m_hcorr[ptclType].reset(dynamic_cast<TProfile2D*>(
19 adcFile->Get(Form("linearity_%s", ptclName.Data()))));
20 m_hcorr[ptclType]->SetDirectory(nullptr);
21 }
22 adcFile->Close();
23}
24
25//===============================================================================
26float LinearityADC::getCorr(float etaCalo, float et,
27 PATCore::ParticleType::Type pType) const {
28 float corr = 0.;
29 float etGeV = et / 1000.;
30 if (etGeV < 6.)
31 etGeV = 6.;
32 if (etGeV > 2999.)
33 etGeV = 2999.;
34
35 auto it = m_hcorr.find(pType);
36 if (it == m_hcorr.end()) {
37 ATH_MSG_ERROR("unknown particle type " << pType);
38 return 1.;
39 }
40 TProfile2D* hh = it->second.get();
41
42 float aeta = std::abs(etaCalo);
43 if (aeta > 2.49)
44 aeta = 2.49;
45
46 int ix = hh->GetXaxis()->FindBin(aeta);
47 int iy = hh->GetYaxis()->FindBin(etGeV);
48 float y = hh->GetYaxis()->GetBinCenter(iy);
49 int iy0, iy1;
50 if (y > etGeV) {
51 iy0 = iy - 1;
52 iy1 = iy;
53 } else {
54 iy0 = iy;
55 iy1 = iy + 1;
56 }
57
58 int iyc = hh->GetYaxis()->FindBin(40.);
59
60 if (iy0 < 1)
61 corr = hh->GetBinContent(ix, iy1);
62 if (iy1 > hh->GetYaxis()->GetNbins())
63 corr = hh->GetBinContent(ix, iy0);
64
65 float y0 = hh->GetYaxis()->GetBinCenter(iy0);
66 float y1 = hh->GetYaxis()->GetBinCenter(iy1);
67 // subtract effect for 40 GeV Et electrons
69 if (it == m_hcorr.end()){
70 ATH_MSG_ERROR("Unknown particle type " << pType<<" in LinearityADC::getCorr");
71 return 1.;
72 }
73 float c0 = hh->GetBinContent(ix, iy0) - it->second->GetBinContent(ix, iyc);
74 float c1 = hh->GetBinContent(ix, iy1) - it->second->GetBinContent(ix, iyc);
75
76 corr = (c1 * (etGeV - y0) + c0 * (y1 - etGeV)) / (y1 - y0);
77 ATH_MSG_VERBOSE("correction from ADC non linearity = " << corr);
78
79 return (1. + corr);
80}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define y
std::map< PATCore::ParticleType::Type, std::unique_ptr< TProfile2D > > m_hcorr
float getCorr(float etaCalo, float et, PATCore::ParticleType::Type ptype=PATCore::ParticleType::Electron) const
get relative correction factor to apply to energy: corrected energy should be original energy * corre...
LinearityADC(const std::string &filename, const std::string &name="ADCNonLinearityCorrection")
constructor (initialization done there reading a root file for the HV maps per period
AsgMessaging(const std::string &name)
Constructor with a name.
Extra patterns decribing particle interation process.