ATLAS Offline Software
Loading...
Searching...
No Matches
CaloReadLCClassificationFile.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("LCClassificationFileName",m_LCClassificationFileName);
21 declareProperty("ClassificationKey",m_key="EMFrac");
22}
23
24
26
27
28StatusCode
29CaloReadLCClassificationFile::initDataFromFile(const std::string& theLCClassificationFileName,
31{
32 // Find the full path to filename:
33 std::string file = PathResolver::find_file (theLCClassificationFileName, "DATAPATH");
34 ATH_MSG_INFO ("Reading file " << file);
35 TFile* theLCClassificationFile = new TFile(file.c_str());
36 if ( !theLCClassificationFile ) {
37 return StatusCode::FAILURE;
38 }
39
40 CaloLocalHadCoeff::LocalHadArea theArea("Classification",0,3);
41
42 TList * theKeyList = theLCClassificationFile->GetListOfKeys();
43 while ( theKeyList->GetEntries() ) {
44 TProfile2D * prof = (TProfile2D *)theLCClassificationFile->Get(theKeyList->First()->GetTitle());
45 // parse histogram title to find all dimensions and bins
46 std::string sTitle(prof->GetTitle());
47 bool allValid(true);
48
49 std::vector<std::string> keys;
50 keys.emplace_back("_iside_");
51 keys.emplace_back("_ieta_");
52 keys.emplace_back("_iphi_");
53 keys.emplace_back("_ilogE_");
54
55 std::vector<std::string> names;
56 names.emplace_back("side");
57 names.emplace_back("|eta|");
58 names.emplace_back("phi");
59 names.emplace_back("log10(E_clus (MeV))");
60 names.emplace_back(prof->GetXaxis()->GetTitle());
61 names.emplace_back(prof->GetYaxis()->GetTitle());
62
63 std::vector<int> types;
70
71 std::vector<int> ibin(names.size(),-1);
72 std::vector<double> rmin(names.size(),-1);
73 std::vector<double> rmax(names.size(),-1);
74 std::vector<int> nbin(names.size(),-1);
75 unsigned int idim;
76
77 for (idim=0;idim<keys.size();idim++) {
78 size_t found = sTitle.find(keys[idim]);
79 if ( found == std::string::npos ) {
80 ATH_MSG_ERROR ("Could not find key " << keys[idim] << " in current histogram.");
81 allValid = false;
82 }
83 else {
84 char c;
85 std::istringstream tstr(sTitle.substr(found+keys[idim].length()));
86 tstr >> ibin[idim] >> c >> c >> rmin[idim] >> c >> rmax[idim] >> c >> nbin[idim];
87 if ( ibin[idim] < 0 || ibin[idim] >= nbin[idim] ) {
88 ATH_MSG_ERROR ("Found invalid bin number " << ibin[idim] << " not in valid range [0," << nbin[idim] << " in current histogram.");
89 allValid = false;
90 }
91 }
92 }
93 if ( allValid ) {
94 // final 2 dimensions are from TProfile2D itself
95 nbin[names.size()-2] = prof->GetNbinsX();
96 rmin[names.size()-2] = prof->GetXaxis()->GetXmin();
97 rmax[names.size()-2] = prof->GetXaxis()->GetXmax();
98 nbin[names.size()-1] = prof->GetNbinsY();
99 rmin[names.size()-1] = prof->GetYaxis()->GetXmin();
100 rmax[names.size()-1] = prof->GetYaxis()->GetXmax();
101 // book new area from the first histo found
102 if ( theArea.getNdim() == 0 ) {
103 for (idim = 0;idim<names.size();idim++) {
104 CaloLocalHadCoeff::LocalHadDimension theDim(names[idim].c_str(),types[idim],nbin[idim],rmin[idim],rmax[idim]);
105 theArea.addDimension(theDim);
106 }
107 ATH_MSG_INFO ("adding Area with nDim = " << theArea.getNdim());
108 data.addArea(theArea);
109 }
110 // now fill all data for current histogram
111 TAxis * xax = prof->GetXaxis();
112 TAxis * yax = prof->GetYaxis();
113 for (ibin[names.size()-2]=0;ibin[names.size()-2]<prof->GetNbinsX();ibin[names.size()-2]++) {
114 for (ibin[names.size()-1]=0;ibin[names.size()-1]<prof->GetNbinsY();ibin[names.size()-1]++) {
115 float logEDens = xax->GetBinCenter(ibin[names.size()-2]+1);
116 float loglambda = yax->GetBinCenter(ibin[names.size()-1]+1);
117 int iBin = prof->FindBin(logEDens,loglambda);
118
120 theData[CaloLocalHadDefs::BIN_WEIGHT] = prof->GetBinContent(iBin);
121 theData[CaloLocalHadDefs::BIN_ENTRIES] = prof->GetBinEntries(iBin);
122 theData[CaloLocalHadDefs::BIN_ERROR] = prof->GetBinError(iBin);
123
124 msg() << MSG::INFO << "Now set data for bins: ";
125 for(unsigned int ii=0;ii<ibin.size();ii++)
126 msg() << ibin[ii] << " ";
127 msg() << endmsg;
128 int dbin = data.getBin(0,ibin);
129 if (dbin >= 0)
130 data.setCoeff(dbin,theData);
131 }
132 }
133 }
134 theKeyList->RemoveFirst();
135 }
136
137 return StatusCode::SUCCESS;
138}
139
141 ATH_MSG_INFO (" Building CaloLocalHadCoeff object ");
142 auto data = std::make_unique<CaloLocalHadCoeff>();
144 ATH_CHECK( detStore()->record(std::move(data), m_key, false) );
145 return StatusCode::SUCCESS;
146}
147
149{
150 return StatusCode::SUCCESS;
151}
152
154{
155 return StatusCode::SUCCESS;
156}
#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.
CaloReadLCClassificationFile(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initDataFromFile(const std::string &theLCClassificationFileName, CaloLocalHadCoeff &data)
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
TFile * file