ATLAS Offline Software
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 
29 CaloReadLCClassificationFile::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;
64  types.push_back(CaloLocalHadDefs::DIM_EQUI);
65  types.push_back(CaloLocalHadDefs::DIM_EQUI);
66  types.push_back(CaloLocalHadDefs::DIM_EQUI);
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 }
CaloLocalHadCoeff::LocalHadDimension
Class defines binning for user dimension.
Definition: CaloLocalHadCoeff.h:47
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
CaloReadLCClassificationFile::finalize
StatusCode finalize()
Definition: CaloReadLCClassificationFile.cxx:153
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
CaloLocalHadDefs.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloReadLCClassificationFile::execute
StatusCode execute()
Definition: CaloReadLCClassificationFile.cxx:148
CaloReadLCClassificationFile::m_LCClassificationFileName
std::string m_LCClassificationFileName
Definition: CaloReadLCClassificationFile.h:28
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
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
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
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
CaloReadLCClassificationFile::initialize
StatusCode initialize()
Definition: CaloReadLCClassificationFile.cxx:140
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:228
CaloReadLCClassificationFile::initDataFromFile
StatusCode initDataFromFile(const std::string &theLCClassificationFileName, CaloLocalHadCoeff &data)
Definition: CaloReadLCClassificationFile.cxx:29
CaloReadLCClassificationFile::~CaloReadLCClassificationFile
~CaloReadLCClassificationFile()
Definition: CaloReadLCClassificationFile.cxx:25
CaloReadLCClassificationFile::m_key
std::string m_key
Definition: CaloReadLCClassificationFile.h:27
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
CaloLocalHadCoeff::LocalHadArea
Definition of correction area.
Definition: CaloLocalHadCoeff.h:145
CaloReadLCClassificationFile.h
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
CaloLocalHadDefs::BIN_WEIGHT
@ BIN_WEIGHT
Definition: CaloLocalHadDefs.h:28
python.compressB64.c
def c
Definition: compressB64.py:93
CaloReadLCClassificationFile::CaloReadLCClassificationFile
CaloReadLCClassificationFile(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CaloReadLCClassificationFile.cxx:17