ATLAS Offline Software
Loading...
Searching...
No Matches
CaloReadLCJetEnergyScaleFile.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
8
10#include "TFile.h"
11#include "TAxis.h"
12#include "TProfile2D.h"
13#include <iostream>
14#include <sstream>
15
16
18 ISvcLocator * pSvcLocator) :
19 AthAlgorithm(name,pSvcLocator) {
20 declareProperty("LCJetEnergyScaleFileNames",m_LCJetEnergyScaleFileNames);
21 declareProperty("LCJetEnergyScaleJetCollectionNames",m_LCJetEnergyScaleJetCollectionNames);
22 declareProperty("CorrectionKey",m_key="JESCorrection");
23}
24
25
27
28
29StatusCode CaloReadLCJetEnergyScaleFile::initDataFromFile(std::vector<std::string> &theLCJetEnergyScaleFileNames, std::vector<std::string> &theLCJetEnergyScaleJetCollectionNames,
31{
32 for (unsigned int iFile=0;iFile<theLCJetEnergyScaleFileNames.size();iFile++) {
33 // Find the full path to filename:
34 std::string file = PathResolver::find_file (theLCJetEnergyScaleFileNames[iFile], "DATAPATH");
35 ATH_MSG_INFO( "Reading file " << file );
36 TFile* theLCJetEnergyScaleFile = new TFile(file.c_str());
37 if ( !theLCJetEnergyScaleFile ) {
38 return StatusCode::FAILURE;
39 }
40
41 CaloLocalHadCoeff::LocalHadArea theArea(theLCJetEnergyScaleJetCollectionNames[iFile].c_str(),0,3);
42
43 TList * theKeyList = theLCJetEnergyScaleFile->GetListOfKeys();
44 while ( theKeyList->GetEntries() ) {
45 TProfile2D * prof = (TProfile2D *)theLCJetEnergyScaleFile->Get(theKeyList->First()->GetTitle());
46 // parse histogram title to find all dimensions and bins
47 std::string sTitle(prof->GetTitle());
48 bool allValid(true);
49
50 std::vector<std::string> keys;
51 keys.emplace_back("ieta_inv_");
52
53 std::vector<std::string> names;
54 names.emplace_back("|eta|");
55 names.emplace_back("side");
56 names.emplace_back("phi");
57 // the next two should actually come from the histograms
58 names.emplace_back("log10(E_jet (MeV))");
59 names.emplace_back("frac_low_E_clus");
60 // names.push_back(std::string(prof->GetXaxis()->GetTitle()));
61 // names.push_back(std::string(prof->GetYaxis()->GetTitle()));
62
63 std::vector<int> types;
69
70 std::vector<int> ibin(names.size(),-1);
71 std::vector<double> rmin(names.size(),-1);
72 std::vector<double> rmax(names.size(),-1);
73 std::vector<int> nbin(names.size(),-1);
74 unsigned int idim;
75
76 for (idim=0;idim<keys.size();idim++) {
77 size_t found = sTitle.find(keys[idim]);
78 if ( found == std::string::npos ) {
79 ATH_MSG_ERROR( "Could not find key " << keys[idim] << " in current histogram." );
80 allValid = false;
81 }
82 else {
83 std::istringstream tstr(sTitle.substr(found+keys[idim].length()));
84 tstr >> ibin[idim];
85
86 // these should come from the histogram title eventually ...
87 nbin[idim] = 25;
88 rmin[idim] = 0.; // |eta| min
89 rmax[idim] = 5.; // |eta| max
90
91 if ( ibin[idim] < 0 || ibin[idim] >= nbin[idim] ) {
92 ATH_MSG_ERROR( "Found invalid bin number " << ibin[idim] << " not in valid range [0," << nbin[idim] << " in current histogram." );
93 allValid = false;
94 }
95 }
96 }
97 if ( allValid ) {
98 // next 2 are side and phi
99 ibin[1] = 0;
100 nbin[1] = 1;
101 rmin[1] = -1.5; // side min
102 rmax[1] = 1.5; // side max
103
104 ibin[2] = 0;
105 nbin[2] = 1;
106 rmin[2] = -M_PI; // phi min
107 rmax[2] = M_PI; // phi max
108
109 // final 2 dimensions are from TProfile2D itself
110 nbin[names.size()-2] = prof->GetNbinsX();
111 rmin[names.size()-2] = prof->GetXaxis()->GetXmin();
112 rmax[names.size()-2] = prof->GetXaxis()->GetXmax();
113 nbin[names.size()-1] = prof->GetNbinsY();
114 rmin[names.size()-1] = prof->GetYaxis()->GetXmin();
115 rmax[names.size()-1] = prof->GetYaxis()->GetXmax();
116 // book new area from the first histo found
117 if ( theArea.getNdim() == 0 ) {
118 for (idim = 0;idim<names.size();idim++) {
119 CaloLocalHadCoeff::LocalHadDimension theDim(names[idim].c_str(),types[idim],nbin[idim],rmin[idim],rmax[idim]);
120 theArea.addDimension(theDim);
121 }
122 ATH_MSG_INFO( "adding Area with nDim = " << theArea.getNdim() );
123 data.addArea(theArea);
124 }
125 // now fill all data for current histogram
126 TAxis * xax = prof->GetXaxis();
127 TAxis * yax = prof->GetYaxis();
128 for (ibin[names.size()-2]=0;ibin[names.size()-2]<prof->GetNbinsX();ibin[names.size()-2]++) {
129 for (ibin[names.size()-1]=0;ibin[names.size()-1]<prof->GetNbinsY();ibin[names.size()-1]++) {
130 float logE = xax->GetBinCenter(ibin[names.size()-2]+1);
131 float frac = yax->GetBinCenter(ibin[names.size()-1]+1);
132 int iBin = prof->FindBin(logE,frac);
133
135 theData[CaloLocalHadDefs::BIN_WEIGHT] = prof->GetBinContent(iBin);
136 theData[CaloLocalHadDefs::BIN_ENTRIES] = prof->GetBinEntries(iBin);
137 theData[CaloLocalHadDefs::BIN_ERROR] = prof->GetBinError(iBin);
138
139 msg() << MSG::INFO << "Now set data for bins: ";
140 for(unsigned int ii=0;ii<ibin.size();ii++)
141 msg() << ibin[ii] << " ";
142 msg() << endmsg;
143 int dbin = data.getBin(iFile,ibin);
144 if (dbin >= 0)
145 data.setCoeff(dbin,theData);
146 }
147 }
148 }
149 theKeyList->RemoveFirst();
150 }
151 }
152 return StatusCode::SUCCESS;
153}
154
156 ATH_MSG_INFO( " Building CaloLocalHadCoeff object " );
157 auto data = std::make_unique<CaloLocalHadCoeff>();
159 ATH_CHECK( detStore()->record(std::move(data), m_key, false) );
160 return StatusCode::SUCCESS;
161}
162
164{
165 return StatusCode::SUCCESS;
166}
167
169{
170 return StatusCode::SUCCESS;
171}
#define M_PI
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static const std::vector< std::string > types
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
MsgStream & msg() const
Definition of correction area.
int getNdim() const
get number of dimensions
void addDimension(LocalHadDimension &dim)
to add new dimension
Class defines binning for user dimension.
Hold binned correction data for local hadronic calibration procedure.
std::vector< float > LocalHadCoeff
Correction parameters for one general bin.
CaloReadLCJetEnergyScaleFile(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initDataFromFile(std::vector< std::string > &theLCJetEnergyScaleFileNames, std::vector< std::string > &theLCJetEnergyScaleJetCollectionNames, CaloLocalHadCoeff &data)
std::vector< std::string > m_LCJetEnergyScaleJetCollectionNames
std::vector< std::string > m_LCJetEnergyScaleFileNames
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
TFile * file