ATLAS Offline Software
Loading...
Searching...
No Matches
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
29 if(msgLvl (MSG::DEBUG)) m_data->PrintData();
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
48StatusCode 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);
138 m_data->addHadDMCoeff(pars);
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}
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
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
bool msgLvl(const MSG::Level lvl) const
std::vector< float > HadDMCoeff
LArReadHadDMCoeffFile(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initDataFromFile(const std::string &hadDMCoeffFileName)
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
std::vector< float > m_FracBins
std::vector< float > m_EnerBins
std::vector< float > m_EtaBins
TFile * file