ATLAS Offline Software
CaloReadLCOutOfClusterFile.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("LCOutOfClusterFileName",m_LCOutOfClusterFileName);
21  declareProperty("CorrectionKey",m_key="OOC");
22 }
23 
24 
26 
27 
28 StatusCode CaloReadLCOutOfClusterFile::initDataFromFile(const std::string& theLCOutOfClusterFileName,
30 {
31  // Find the full path to filename:
32  std::string file = PathResolver::find_file (theLCOutOfClusterFileName, "DATAPATH");
33  ATH_MSG_INFO( "Reading file " << file );
34  TFile* theLCOutOfClusterFile = new TFile(file.c_str());
35  if ( !theLCOutOfClusterFile ) {
36  return StatusCode::FAILURE;
37  }
38 
39  CaloLocalHadCoeff::LocalHadArea theArea("OutOfCluster",0,3);
40 
41  TList * theKeyList = theLCOutOfClusterFile->GetListOfKeys();
42  while ( theKeyList->GetEntries() ) {
43  TProfile2D * prof = (TProfile2D *)theLCOutOfClusterFile->Get(theKeyList->First()->GetTitle());
44  // parse histogram title to find all dimensions and bins
45  std::string sTitle(prof->GetTitle());
46  bool allValid(true);
47 
48  std::vector<std::string> keys;
49  keys.emplace_back("_iside_");
50  keys.emplace_back("_iphi_");
51  keys.emplace_back("_ilogE_");
52 
53  std::vector<std::string> names;
54  names.emplace_back("side");
55  names.emplace_back("phi");
56  names.emplace_back("log10(E_clus (MeV))");
57  names.emplace_back(prof->GetXaxis()->GetTitle());
58  names.emplace_back(prof->GetYaxis()->GetTitle());
59 
60  std::vector<int> types;
61  types.push_back(CaloLocalHadDefs::DIM_EQUI);
62  types.push_back(CaloLocalHadDefs::DIM_EQUI);
64  types.push_back(CaloLocalHadDefs::DIM_EQUI);
66 
67  std::vector<int> ibin(names.size(),-1);
68  std::vector<double> rmin(names.size(),-1);
69  std::vector<double> rmax(names.size(),-1);
70  std::vector<int> nbin(names.size(),-1);
71  unsigned int idim;
72 
73  for (idim=0;idim<keys.size();idim++) {
74  size_t found = sTitle.find(keys[idim]);
75  if ( found == std::string::npos ) {
76  ATH_MSG_ERROR( "Could not find key " << keys[idim] << " in current histogram." );
77  allValid = false;
78  }
79  else {
80  char c;
81  std::istringstream tstr(sTitle.substr(found+keys[idim].length()));
82  tstr >> ibin[idim] >> c >> c >> rmin[idim] >> c >> rmax[idim] >> c >> nbin[idim];
83  if ( ibin[idim] < 0 || ibin[idim] >= nbin[idim] ) {
84  ATH_MSG_ERROR( "Found invalid bin number " << ibin[idim] << " not in valid range [0," << nbin[idim] << " in current histogram." );
85  allValid = false;
86  }
87  }
88  }
89  if ( allValid ) {
90  // final 2 dimensions are from TProfile2D itself
91  nbin[names.size()-2] = prof->GetNbinsX();
92  rmin[names.size()-2] = prof->GetXaxis()->GetXmin();
93  rmax[names.size()-2] = prof->GetXaxis()->GetXmax();
94  nbin[names.size()-1] = prof->GetNbinsY();
95  rmin[names.size()-1] = prof->GetYaxis()->GetXmin();
96  rmax[names.size()-1] = prof->GetYaxis()->GetXmax();
97  // book new area from the first histo found
98  if ( theArea.getNdim() == 0 ) {
99  for (idim = 0;idim<names.size();idim++) {
100  CaloLocalHadCoeff::LocalHadDimension theDim(names[idim].c_str(),types[idim],nbin[idim],rmin[idim],rmax[idim]);
101  ATH_MSG_INFO( "adding dimension " << names[idim].c_str() << " " << types[idim]<< " " << nbin[idim]<< " " << rmin[idim]<< " " << rmax[idim] );
102  theArea.addDimension(theDim);
103  }
104  ATH_MSG_INFO( "adding Area with nDim = " << theArea.getNdim() );
105  data.addArea(theArea);
106  }
107  // now fill all data for current histogram
108  TAxis * xax = prof->GetXaxis();
109  TAxis * yax = prof->GetYaxis();
110  for (ibin[names.size()-2]=0;ibin[names.size()-2]<prof->GetNbinsX();ibin[names.size()-2]++) {
111  for (ibin[names.size()-1]=0;ibin[names.size()-1]<prof->GetNbinsY();ibin[names.size()-1]++) {
112  float abseta = xax->GetBinCenter(ibin[names.size()-2]+1);
113  float loglambda = yax->GetBinCenter(ibin[names.size()-1]+1);
114  int iBin = prof->FindBin(abseta,loglambda);
115 
117  theData[CaloLocalHadDefs::BIN_WEIGHT] = prof->GetBinContent(iBin);
118  theData[CaloLocalHadDefs::BIN_ENTRIES] = prof->GetBinEntries(iBin);
119  theData[CaloLocalHadDefs::BIN_ERROR] = prof->GetBinError(iBin);
120 
121  msg() << MSG::INFO << "Now set data for bins: ";
122  for(unsigned int ii=0;ii<ibin.size();ii++)
123  msg() << ibin[ii] << " ";
124  msg() << endmsg;
125  int dbin = data.getBin(0,ibin);
126  if (dbin >= 0)
127  data.setCoeff(dbin,theData);
128  }
129  }
130  }
131  theKeyList->RemoveFirst();
132  }
133 
134  return StatusCode::SUCCESS;
135 }
136 
138  ATH_MSG_INFO( " Building CaloLocalHadCoeff object " );
139  auto data = std::make_unique<CaloLocalHadCoeff>();
141  ATH_CHECK( detStore()->record(std::move(data), m_key, false) );
142  return StatusCode::SUCCESS;
143 }
144 
146 {
147  return StatusCode::SUCCESS;
148 }
149 
151 {
152  return StatusCode::SUCCESS;
153 }
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
CaloLocalHadDefs.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloReadLCOutOfClusterFile.h
TProfile2D
Definition: rootspy.cxx:531
CaloReadLCOutOfClusterFile::initDataFromFile
StatusCode initDataFromFile(const std::string &theLCOutOfClusterFileName, CaloLocalHadCoeff &data)
Definition: CaloReadLCOutOfClusterFile.cxx: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
CaloReadLCOutOfClusterFile::initialize
StatusCode initialize()
Definition: CaloReadLCOutOfClusterFile.cxx:137
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
AthAlgorithm
Definition: AthAlgorithm.h:47
CaloLocalHadCoeff::LocalHadArea::getNdim
int getNdim() const
get number of dimensions
Definition: CaloLocalHadCoeff.h:179
CaloReadLCOutOfClusterFile::finalize
StatusCode finalize()
Definition: CaloReadLCOutOfClusterFile.cxx:150
CaloLocalHadDefs::DIM_LOG
@ DIM_LOG
Definition: CaloLocalHadDefs.h:38
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CaloReadLCOutOfClusterFile::m_LCOutOfClusterFileName
std::string m_LCOutOfClusterFileName
Definition: CaloReadLCOutOfClusterFile.h:28
CaloReadLCOutOfClusterFile::CaloReadLCOutOfClusterFile
CaloReadLCOutOfClusterFile(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CaloReadLCOutOfClusterFile.cxx:17
TProfile2D::GetBinContent
double GetBinContent(int) const
Definition: rootspy.cxx:546
CaloReadLCOutOfClusterFile::~CaloReadLCOutOfClusterFile
~CaloReadLCOutOfClusterFile()
Definition: CaloReadLCOutOfClusterFile.cxx:25
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
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
CaloLocalHadDefs::BIN_WEIGHT
@ BIN_WEIGHT
Definition: CaloLocalHadDefs.h:28
python.compressB64.c
def c
Definition: compressB64.py:93
CaloReadLCOutOfClusterFile::m_key
std::string m_key
Definition: CaloReadLCOutOfClusterFile.h:27
CaloReadLCOutOfClusterFile::execute
StatusCode execute()
Definition: CaloReadLCOutOfClusterFile.cxx:145