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