ATLAS Offline Software
Loading...
Searching...
No Matches
LArReadHadDMCoeffFile2.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "GaudiKernel/MsgStream.h"
10
11#define MAX_BUFFER_LEN 1024
12
13
14/* ***************************************************************************
15c-tor
16*************************************************************************** */
18 ISvcLocator * pSvcLocator) : AthAlgorithm(name,pSvcLocator) {
19 declareProperty("HadDMCoeffFileName",m_hadDMCoeffFileName);
20 declareProperty("CorrectionKey",m_key="HadDMCoeff");
21
22 m_data = 0;
23}
24
26
27
28/* ***************************************************************************
29initialize
30*************************************************************************** */
32 ATH_MSG_INFO ( "=== LArReadHadDMCoeffFile2::initialize() === m_key:" << m_key );
34
35 if(msgLvl(MSG::DEBUG)) m_data->PrintData(std::cout);
36
37 ATH_CHECK( detStore()->record(m_data,m_key) );
38 ATH_CHECK( detStore()->setConst(m_data) );
39 return StatusCode::SUCCESS;
40}
41
42
44{
45 return StatusCode::SUCCESS;
46}
47
49{
50 return StatusCode::SUCCESS;
51}
52
53
54/* ***************************************************************************
55reading text file
56*************************************************************************** */
57StatusCode LArReadHadDMCoeffFile2::initDataFromFile(const std::string& hadDMCoeffFileName)
58{
59 char cLine[MAX_BUFFER_LEN];
60
61 m_data = new CaloHadDMCoeff2();
62
63 // Find the full path to filename
64 std::string file = hadDMCoeffFileName;
65 ATH_MSG_INFO ( "Reading file " << file );
66
67 std::ifstream fin(file.c_str());
68 if ( !fin ) {
69 ATH_MSG_ERROR ( "LArReadHadDMCoeffFile2::initDataFromFile() - Can't open file " << file );
70 return StatusCode::FAILURE;
71 }
72
73 int offset = 0;
74
75 std::string sLine;
76 std::string sdummy;
77 std::istringstream ist;
78 while(fin.getline(cLine,sizeof(cLine)-1)) {
79 if( strlen(cLine)==0 || cLine[0] == '#' || cLine[0] == '\n') continue;
80
81 // creating new dead material area
83 // parsing zone line
84 sLine = cLine;
85 ist.clear(); ist.str(sLine);
86 if( !(ist >> sdummy >> dmArea.m_indx >> dmArea.m_is_on >> dmArea.m_title) && sdummy.find("zone")==std::string::npos ) {
87 ATH_MSG_ERROR ( "LArReadHadDMCoeffFile2::initDataFromFile() -> Error! Could not parse line '" << cLine << "' at p1." );
88 return StatusCode::FAILURE;
89 }
91 if(dmArea.m_title.find("LOOKUP") != std::string::npos) dmArea.m_type = CaloHadDMCoeff2::kAREA_LOOKUP;
92 // loop over dimensions of this zones
93 std::vector<CaloHadDMCoeff2::HadDMDimension > v_dims;
94 while(fin.getline(cLine,sizeof(cLine)-1)){
95 if( cLine[0] == '#') continue;
96 sLine = cLine;
97 // reading number of parameters
98 if(sLine.find("npars") != std::string::npos){
99 ist.clear(); ist.str(sLine);
100 if( !(ist >> sdummy >> dmArea.m_nPars) || dmArea.m_nPars < 0 || dmArea.m_nPars > 1000 ){
101 ATH_MSG_ERROR ( "LArReadHadDMCoeffFile2::initDataFromFile() ->Error! Could not parse line '" << cLine << "' at p2." );
102 return StatusCode::FAILURE;
103 }
104 // this is the end of zone
105 break;
106 }
108 if( !parse_dim(sLine, dim) ) {
109 ATH_MSG_ERROR ( "LArReadHadDMCoeffFile2::initDataFromFile() ->Error! Could not parse line '" << sLine << "' at p2a." );
110 return StatusCode::FAILURE;
111 }
112 v_dims.push_back(std::move(dim));
113 }
114 // calculation offset for this area
115 int ndim = (int) v_dims.size();
116 int length = 1;
117 for(int i=0; i<ndim; i++){
118 length = length*v_dims[i].m_vBins.size();
119 }
120 dmArea.m_offset = offset;
121 dmArea.m_length = length;
122 // calculation of dimension locator coefficient
123 for(int i_dim=0; i_dim<ndim; i_dim++){
124 int xloc = 1;
125 for(int j=i_dim+1; j<ndim; j++){
126 xloc = xloc*v_dims[j].m_vBins.size();
127 }
128 v_dims[i_dim].xloc = xloc;
129 }
130 if( v_dims.size() != 4 ){
131 ATH_MSG_ERROR ( "LArReadHadDMCoeffFile2::initDataFromFile() ->Error! Wrong number of dimensions for area'" << dmArea.m_title << "' at p3." );
132 return StatusCode::FAILURE;
133 }
134 dmArea.m_dimFrac = v_dims[0];
135 dmArea.m_dimEner = v_dims[1];
136 dmArea.m_dimLambda = v_dims[2];
137 dmArea.m_dimEta = v_dims[3];
138
139 m_data->addHadDMArea(dmArea);
140 offset += length; // ofset for next DM area
141 // putting zero parameters
143 pars.resize(dmArea.m_nPars, 0.0);
144 for(int i_len=0; i_len<dmArea.m_length; i_len++) m_data->addHadDMCoeff(pars);
145 // now reading parameters
146 for(int i_len=0; i_len<dmArea.m_length; i_len++){
147 if(!fin.getline(cLine,sizeof(cLine)-1)) {
148 ATH_MSG_ERROR ( "panic " );
149 return StatusCode::FAILURE;
150 }
151 sLine = cLine;
152 ist.clear(); ist.str(sLine);
153 int idummy;
154 if( !(ist >> idummy) ) {
155 ATH_MSG_ERROR ( "LArReadHadDMCoeffFile2::initDataFromFile() -> Warning! Area " << dmArea.m_title << " doesn't have parameters." );
156 break;
157 }
158 if(idummy != dmArea.m_offset+i_len){
159 ATH_MSG_ERROR ( "LArReadHadDMCoeffFile2::initDataFromFile() ->Error! Could not parse line '" << cLine << "' at p3." );
160 return StatusCode::FAILURE;
161 }
162 for(int j=0; j<(int)v_dims.size(); j++) {
163 if(!(ist >> idummy)) {
164 ATH_MSG_ERROR ( "LArReadHadDMCoeffFile2::initDataFromFile() -> panic!" );
165 return StatusCode::FAILURE;
166 }
167 }
169 pars.resize(dmArea.m_nPars,0.0);
170 for(int j=0; j<dmArea.m_nPars; j++) {
171 if( !(ist >> pars[j]) ) {
172 ATH_MSG_ERROR ( "LArReadHadDMCoeffFile2::initDataFromFile() ->Error! Could not parse line '" << cLine << "' at p4." );
173 ATH_MSG_ERROR ( " dmArea.m_title" << dmArea.m_title );
174 return StatusCode::FAILURE;
175 }
176 }
177 m_data->setHadDMCoeff(dmArea.m_offset+i_len,pars);
178 }
179 }
180 fin.close();
181 return StatusCode::SUCCESS;
182}
183
184
185/* **************************************************************************
186parsing dimension string
187*************************************************************************** */
189{
190 std::string dummy;
191 std::string stype;
192 std::istringstream ist(sLine.c_str());
193
194 if( !(ist >> dim.m_title >> dim.m_nbins >> dim.m_vMin >> dim.m_vMax >> stype) || dim.m_nbins <= 0 || dim.m_nbins > 1000){
195 std::cout << "LArReadHadDMCoeffFile2::parse_dim() -> Error! Could not parse line '" << sLine << "' at pp1." << std::endl;
196 return 0;
197 }
198 // bins according to flat scale
199 if(stype.find("flat") != std::string::npos) {
200 dim.m_type = CaloHadDMCoeff2::kDIM_FLAT;
201 dim.m_bin_size = (dim.m_vMax - dim.m_vMin)/float(dim.m_nbins);
202 for(int i=0; i<dim.m_nbins; i++) dim.m_vBins.push_back(dim.m_vMin + i*(dim.m_vMax - dim.m_vMin)/float(dim.m_nbins));
203 // bins are setted in the string
204 }else if(stype.find("hand") != std::string::npos) {
205 dim.m_type = CaloHadDMCoeff2::kDIM_HAND;
206 float e;
207 for(int i=0; i<dim.m_nbins; i++) if( ist >> e ) dim.m_vBins.push_back(e);
208 }else{
209 std::cout << "LArReadHadDMCoeffFile2::parse_dim() -> Error! Could not parse line '" << sLine << "' at pp3." << std::endl;
210 return 0;
211 }
212 if((int)dim.m_vBins.size() != dim.m_nbins){
213 std::cout << "LArReadHadDMCoeffFile2::parse_dim() -> Error! Could not parse line '" << sLine << "' at pp4." << std::endl;
214 return 0;
215 }
216 return (int) dim.m_vBins.size();
217}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define MAX_BUFFER_LEN
double length(const pvec &v)
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
Dead material correction coefficients.
std::vector< float > HadDMCoeff
LArReadHadDMCoeffFile2(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initDataFromFile(const std::string &hadDMCoeffFileName)
int parse_dim(std::string &sLine, CaloHadDMCoeff2::HadDMDimension &dim)
TFile * file