ATLAS Offline Software
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 
29 StatusCode 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;
64  types.push_back(CaloLocalHadDefs::DIM_EQUI);
65  types.push_back(CaloLocalHadDefs::DIM_EQUI);
66  types.push_back(CaloLocalHadDefs::DIM_EQUI);
68  types.push_back(CaloLocalHadDefs::DIM_EQUI);
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 }
CaloLocalHadCoeff::LocalHadDimension
Class defines binning for user dimension.
Definition: CaloLocalHadCoeff.h:47
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
CaloLocalHadDefs::BIN_ERROR
@ BIN_ERROR
Definition: CaloLocalHadDefs.h:30
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
CaloReadLCJetEnergyScaleFile::CaloReadLCJetEnergyScaleFile
CaloReadLCJetEnergyScaleFile(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CaloReadLCJetEnergyScaleFile.cxx:17
CaloLocalHadDefs.h
CaloReadLCJetEnergyScaleFile::initialize
StatusCode initialize()
Definition: CaloReadLCJetEnergyScaleFile.cxx:155
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloReadLCJetEnergyScaleFile::execute
StatusCode execute()
Definition: CaloReadLCJetEnergyScaleFile.cxx:163
TProfile2D
Definition: rootspy.cxx:531
M_PI
#define M_PI
Definition: ActiveFraction.h:11
CaloReadLCJetEnergyScaleFile::m_key
std::string m_key
Definition: CaloReadLCJetEnergyScaleFile.h:27
CaloReadLCJetEnergyScaleFile::m_LCJetEnergyScaleFileNames
std::vector< std::string > m_LCJetEnergyScaleFileNames
Definition: CaloReadLCJetEnergyScaleFile.h:28
CaloReadLCJetEnergyScaleFile::~CaloReadLCJetEnergyScaleFile
~CaloReadLCJetEnergyScaleFile()
Definition: CaloReadLCJetEnergyScaleFile.cxx:26
CaloCell_ID.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
CaloLocalHadCoeff::LocalHadCoeff
std::vector< float > LocalHadCoeff
Correction parameters for one general bin.
Definition: CaloLocalHadCoeff.h:220
CaloLocalHadDefs::BIN_ENTRIES
@ BIN_ENTRIES
Definition: CaloLocalHadDefs.h:29
CaloReadLCJetEnergyScaleFile::initDataFromFile
StatusCode initDataFromFile(std::vector< std::string > &theLCJetEnergyScaleFileNames, std::vector< std::string > &theLCJetEnergyScaleJetCollectionNames, CaloLocalHadCoeff &data)
Definition: CaloReadLCJetEnergyScaleFile.cxx:29
CaloLocalHadCoeff::LocalHadArea::addDimension
void addDimension(LocalHadDimension &dim)
to add new dimension
Definition: CaloLocalHadCoeff.cxx:135
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CaloReadLCJetEnergyScaleFile::finalize
StatusCode finalize()
Definition: CaloReadLCJetEnergyScaleFile.cxx:168
CaloLocalHadDefs::DIM_EQUI
@ DIM_EQUI
Definition: CaloLocalHadDefs.h:40
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
checkxAOD.frac
frac
Definition: Tools/PyUtils/bin/checkxAOD.py:256
python.subdetectors.mmg.names
names
Definition: mmg.py:8
CaloLocalHadCoeff
Hold binned correction data for local hadronic calibration procedure.
Definition: CaloLocalHadCoeff.h:41
file
TFile * file
Definition: tile_monitor.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthAlgorithm
Definition: AthAlgorithm.h:47
CaloLocalHadCoeff::LocalHadArea::getNdim
int getNdim() const
get number of dimensions
Definition: CaloLocalHadCoeff.h:179
CaloLocalHadDefs::DIM_LOG
@ DIM_LOG
Definition: CaloLocalHadDefs.h:38
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TProfile2D::GetBinContent
double GetBinContent(int) const
Definition: rootspy.cxx:546
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
CaloReadLCJetEnergyScaleFile.h
CaloReadLCJetEnergyScaleFile::m_LCJetEnergyScaleJetCollectionNames
std::vector< std::string > m_LCJetEnergyScaleJetCollectionNames
Definition: CaloReadLCJetEnergyScaleFile.h:29
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
CaloLocalHadCoeff::LocalHadArea
Definition of correction area.
Definition: CaloLocalHadCoeff.h:145
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
CaloLocalHadDefs::BIN_WEIGHT
@ BIN_WEIGHT
Definition: CaloLocalHadDefs.h:28