ATLAS Offline Software
LArReadHadDMCoeffFile.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "GaudiKernel/MsgStream.h"
10 
11 
13  ISvcLocator * pSvcLocator) :
14  AthAlgorithm(name,pSvcLocator) {
15  declareProperty("HadDMCoeffFileName",m_hadDMCoeffFileName);
16  declareProperty("CorrectionKey",m_key="HadDMCoeff");
17 
18  m_data = 0;
19 }
20 
21 
23 
24 
26  ATH_MSG_INFO ( "=== LArReadHadDMCoeffFile::initialize() ===" );
28 
30 
31  ATH_CHECK( detStore()->record(m_data,m_key) );
32  ATH_CHECK( detStore()->setConst(m_data) );
33  return StatusCode::SUCCESS;
34 }
35 
36 
38 {
39  return StatusCode::SUCCESS;
40 }
41 
43 {
44  return StatusCode::SUCCESS;
45 }
46 
47 
48 StatusCode LArReadHadDMCoeffFile::initDataFromFile(const std::string& hadDMCoeffFileName)
49 {
50  m_data = new CaloHadDMCoeff();
51 
52  // Find the full path to filename
53  std::string file = PathResolver::find_file (hadDMCoeffFileName, "DATAPATH");
54  ATH_MSG_INFO ( "Reading file " << file );
55 
56  FILE *fin = fopen(file.c_str(),"r");
57  if ( fin == NULL) {
58  ATH_MSG_ERROR ( "Can't open file " << file );
59  return StatusCode::FAILURE;
60  }
61 
62  char line[1024], title[128];
63  int offset = 0;
64  int indx_zone = 0;
65  int nFrac, nEner, nEta, nPars;
66  while(fgets(line,1024,fin)) {
67  if(line[0] == '#' || line[0] == '\n' ) continue;
68  int izone, is_on;
69  if(sscanf(line,"%80d %80d %127s\n",&izone, &is_on, title)!=3 || indx_zone != izone) {
70  ATH_MSG_ERROR ( "Format error #1." );
71  fclose (fin);
72  return StatusCode::FAILURE;
73  }
75  dmArea.m_is_on = is_on;
76  dmArea.m_indx = indx_zone;
77  dmArea.m_title = title;
78 
79  fgets(line,1024,fin);
80  if(sscanf(line,"%80d %80f %80f\n", &nFrac, &dmArea.m_MinFrac, &dmArea.m_MaxFrac)!=3 ||
81  nFrac<0 || nFrac>1000)
82  {
83  ATH_MSG_ERROR ( "Format error #2." );
84  fclose (fin);
85  return StatusCode::FAILURE;
86  }
87  fgets(line,1024,fin);
88  if(sscanf(line,"%80d %80f %80f\n", &nEner, &dmArea.m_MinEner, &dmArea.m_MaxEner)!=3 ||
89  nEner < 0 || nEner > 1000)
90  {
91  ATH_MSG_ERROR ( "Format error #3." );
92  fclose (fin);
93  return StatusCode::FAILURE;
94  }
95  fgets(line,1024,fin);
96  if(sscanf(line,"%80d %80f %80f\n", &nEta, &dmArea.m_MinEta, &dmArea.m_MaxEta)!=3 ||
97  nEta < 0 || nEta > 1000)
98  {
99  ATH_MSG_ERROR ( "Format error #4." );
100  fclose (fin);
101  return StatusCode::FAILURE;
102  }
103  fgets(line,1024,fin);
104  if(sscanf(line,"%80d \n", &nPars)!=1 || nPars < 0 || nPars> 1000) {
105  ATH_MSG_ERROR ( "Format error #5." );
106  fclose (fin);
107  return StatusCode::FAILURE;
108  }
109  dmArea.m_nPars = nPars;
110 
111  for(int i_frac=0; i_frac<nFrac; i_frac++){
112  int iparset = 0, ifrac = 0, iener = 0, ieta = 0;
113  float frac = 0, ener = 0, eta = 0;
114  for(int i_ener=0; i_ener<nEner; i_ener++){
115  for(int i_eta=0; i_eta<nEta; i_eta++){
116  fgets(line,1024,fin);
117  std::string sLine;
118  sLine = std::string(line);
119  std::istringstream es( sLine.c_str() );
120 
121  if ( es >> iparset >> ifrac >> iener >> ieta >> frac >> ener >> eta) {
123  pars.resize(nPars);
124  for(int i=0; i<nPars; i++) {
125  if(!(es >> pars[i]) ) {
126  ATH_MSG_ERROR ( "Format error #6." );
127  fclose (fin);
128  return StatusCode::FAILURE;
129  }
130  }
131  if(ifrac != i_frac || iener != i_ener || ieta != i_eta || (int)pars.size() != nPars){
132  ATH_MSG_ERROR ( "Format error #7." );
133  fclose (fin);
134  return StatusCode::FAILURE;
135  }
136 
137  if(i_frac==0 && i_ener==0) dmArea.m_EtaBins.push_back(eta);
139  pars.clear();
140  } else {
141  ATH_MSG_ERROR ( "Format error #8." );
142  }
143  } // i_eta
144  if(i_frac == 0) dmArea.m_EnerBins.push_back(ener);
145  } // i_ener
146  dmArea.m_FracBins.push_back(frac);
147  }
148  dmArea.m_offset = offset;
149 // std::cout << "indx_zone: " << indx_zone << " offset:" << offset << std::endl;
150  m_data->addHadDMArea(dmArea);
151  offset += nFrac*nEner*nEta; // ofset for next DM area
152  indx_zone++;
153  }
154  fclose(fin);
155 
156  return StatusCode::SUCCESS;
157 }
CaloHadDMCoeff::HadDMArea::m_MaxEta
float m_MaxEta
Definition: CaloHadDMCoeff.h:36
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
LArReadHadDMCoeffFile::initDataFromFile
StatusCode initDataFromFile(const std::string &hadDMCoeffFileName)
Definition: LArReadHadDMCoeffFile.cxx:48
CaloHadDMCoeff::addHadDMArea
void addHadDMArea(const HadDMArea &theArea)
Definition: CaloHadDMCoeff.cxx:58
checkFileSG.line
line
Definition: checkFileSG.py:75
LArReadHadDMCoeffFile::initialize
StatusCode initialize()
Definition: LArReadHadDMCoeffFile.cxx:25
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
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
CaloHadDMCoeff::HadDMArea::m_FracBins
std::vector< float > m_FracBins
Definition: CaloHadDMCoeff.h:31
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArReadHadDMCoeffFile::m_data
CaloHadDMCoeff * m_data
Definition: LArReadHadDMCoeffFile.h:30
CaloHadDMCoeff::HadDMArea::m_MaxEner
float m_MaxEner
Definition: CaloHadDMCoeff.h:33
CaloHadDMCoeff::HadDMArea::m_is_on
int m_is_on
Definition: CaloHadDMCoeff.h:28
CaloHadDMCoeff::HadDMCoeff
std::vector< float > HadDMCoeff
Definition: CaloHadDMCoeff.h:44
LArReadHadDMCoeffFile::m_key
std::string m_key
Definition: LArReadHadDMCoeffFile.h:27
CaloHadDMCoeff::HadDMArea::m_EnerBins
std::vector< float > m_EnerBins
Definition: CaloHadDMCoeff.h:34
AthCommonMsg< Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
CaloHadDMCoeff::HadDMArea::m_MinEta
float m_MinEta
Definition: CaloHadDMCoeff.h:35
LArReadHadDMCoeffFile::execute
StatusCode execute()
Definition: LArReadHadDMCoeffFile.cxx:37
LArReadHadDMCoeffFile::~LArReadHadDMCoeffFile
~LArReadHadDMCoeffFile()
Definition: LArReadHadDMCoeffFile.cxx:22
CaloHadDMCoeff::HadDMArea::m_title
std::string m_title
Definition: CaloHadDMCoeff.h: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
CaloHadDMCoeff::addHadDMCoeff
void addHadDMCoeff(const HadDMCoeff &theData)
Definition: CaloHadDMCoeff.cxx:46
CaloHadDMCoeff::HadDMArea::m_offset
int m_offset
Definition: CaloHadDMCoeff.h:39
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
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:259
CaloHadDMCoeff::HadDMArea::m_EtaBins
std::vector< float > m_EtaBins
Definition: CaloHadDMCoeff.h:37
LArReadHadDMCoeffFile::m_hadDMCoeffFileName
std::string m_hadDMCoeffFileName
Definition: LArReadHadDMCoeffFile.h:28
covarianceTool.title
title
Definition: covarianceTool.py:542
CaloHadDMCoeff::HadDMArea
Definition: CaloHadDMCoeff.h:25
file
TFile * file
Definition: tile_monitor.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloHadDMCoeff::HadDMArea::m_nPars
int m_nPars
Definition: CaloHadDMCoeff.h:38
LArReadHadDMCoeffFile::finalize
StatusCode finalize()
Definition: LArReadHadDMCoeffFile.cxx:42
AthAlgorithm
Definition: AthAlgorithm.h:47
CaloHadDMCoeff::HadDMArea::m_MinFrac
float m_MinFrac
Definition: CaloHadDMCoeff.h:29
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
CaloHadDMCoeff
Definition: CaloHadDMCoeff.h:23
CaloHadDMCoeff::PrintData
void PrintData(FILE *fout=stdout) const
Definition: CaloHadDMCoeff.cxx:145
LArReadHadDMCoeffFile.h
LArReadHadDMCoeffFile::LArReadHadDMCoeffFile
LArReadHadDMCoeffFile(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArReadHadDMCoeffFile.cxx:12
CaloHadDMCoeff::HadDMArea::m_indx
int m_indx
Definition: CaloHadDMCoeff.h:27
DEBUG
#define DEBUG
Definition: page_access.h:11
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
compute_lumi.fin
fin
Definition: compute_lumi.py:19
TrigVSI::AlgConsts::nEta
constexpr int nEta
Default bin number of eta for vertex map.
Definition: Trigger/TrigTools/TrigVrtSecInclusive/TrigVrtSecInclusive/Constants.h:26
StoreGateSvc.h
CaloHadDMCoeff::HadDMArea::m_MaxFrac
float m_MaxFrac
Definition: CaloHadDMCoeff.h:30
CaloHadDMCoeff::HadDMArea::m_MinEner
float m_MinEner
Definition: CaloHadDMCoeff.h:32