23 #include "boost/io/ios_state.hpp"
26 #define MAX_BUFFER_LEN 1024
44 for(
int i_area=0; i_area<
coeff->getSizeAreaSet(); i_area++) {
45 if(sname ==
coeff->getArea(i_area)->getTitle()) {
47 return coeff->getArea(i_area);
50 std::cout <<
"CaloLocalHadCoeffHelper::getAreaFromName() -> Error! No such area '" << sname <<
"'" << std::endl;
66 std::cout <<
"CaloLocalHadCoeffHelper::InitDataFromFile - Reading file '" <<
filename <<
"'." << std::endl;
70 std::cout <<
"CaloLocalHadCoeffHelper::InitDataFromFile - Can't open file '" <<
filename <<
"'." << std::endl;
71 delete data;
return nullptr;
75 std::istringstream ist;
76 while(
fin.getline(cLine,
sizeof(cLine)-1)) {
77 if( strlen(cLine)==0 || cLine[0] ==
'#' || cLine[0] ==
'\n')
continue;
81 ist.clear(); ist.str(sLine);
82 std::string sdummy, area_title;
83 int area_indx(0), area_type(0), area_npars(0);
84 if( !(ist >> sdummy >> area_indx >> area_title >> area_type >> area_npars) ) {
85 std::cout <<
"CaloLocalHadCoeffHelper::initDataFromFile() -> Error! Could not parse line '" << cLine <<
"' at p1." << std::endl;
86 delete data;
return nullptr;
92 while(
fin.getline(cLine,
sizeof(cLine)-1)){
93 if( cLine[0] ==
'#')
continue;
95 if(sLine.find(
"break") != std::string::npos) {
100 std::cout <<
"CaloLocalHadCoeffHelper::initDataFromFile() ->Error! Could not parse line '" << sLine <<
"' at p2a." << std::endl;
101 delete data;
return nullptr;
107 data->addArea(theArea);
110 for(
int i_len=0; i_len<theArea.
getLength(); i_len++){
111 if(!
fin.getline(cLine,
sizeof(cLine)-1)) {
112 std::cout <<
"panic " << std::endl;
113 delete data;
return nullptr;
116 ist.clear(); ist.str(sLine);
118 if( !(ist >> idummy) ) {
119 std::cout <<
"CaloLocalHadCoeffHelper::initDataFromFile() -> Warning! Area " << theArea.
getTitle() <<
" doesn't have parameters." << std::endl;
123 std::cout <<
"CaloLocalHadCoeffHelper::initDataFromFile() ->Error! Could not parse line '" << cLine <<
"' at p3." << std::endl;
124 delete data;
return nullptr;
126 for(
int j=0; j<theArea.
getNdim(); j++) {
127 if(!(ist >> idummy)) {
128 std::cout <<
"CaloLocalHadCoeffHelper::initDataFromFile() -> panic!" << std::endl;
129 delete data;
return nullptr;
134 for(
int j=0; j<theArea.
getNpars(); j++) {
135 if( !(ist >>
pars[j]) ) {
136 std::cout <<
"CaloLocalHadCoeffHelper::initDataFromFile() ->Error! Could not parse line '" << cLine <<
"' at p4." << std::endl;
137 std::cout <<
" dmArea.m_title" << theArea.
getTitle() << std::endl;
138 delete data;
return nullptr;
171 "# Coefficients for local hadronic calibration .\n\n"
177 for(
int i_area=0; i_area <
data->getSizeAreaSet(); i_area++){
179 fout <<
"area " << i_area <<
" " <<
area->getTitle() <<
" " <<
area->getType() <<
" " <<
area->getNpars() << std::endl;
180 for(
int i_dim=0; i_dim<
area->getNdim(); i_dim++){
182 sprintf(
line,
"%-6s %2d %6.3f %12.3f ",
dim->getTitle().c_str(),
dim->getNbins(),
dim->getXmin(),
dim->getXmax() );
183 std::string sline(
line);
198 fout <<
"break" << std::endl;
201 for(
int i_data=0; i_data<
area->getLength(); i_data++) {
202 int indx =
area->getOffset() + i_data;
205 std::cout <<
"CaloLocalHadCoeffHelper::PrintData() -> Error! Wrong bin number" << std::endl;
208 boost::io::ios_base_all_saver foutsave (
fout);
209 fout << std::setw(5) << indx <<
" ";
210 std::vector<int > v_dim_indexes;
211 data->bin2indexes(indx, v_dim_indexes);
212 for(
unsigned int i_dim=0; i_dim<v_dim_indexes.size(); i_dim++){
213 fout << std::setw(4) << v_dim_indexes[i_dim] <<
" ";
216 for(
unsigned int i_par=0; i_par<(*pars).size(); i_par++) {
217 fout << std::fixed << std::setprecision(6) << std::setw(12) << (*pars)[i_par] <<
" ";
236 std::istringstream ist(sLine.c_str());
238 std::string dim_title;
240 int dim_nbins(0), dim_type(0);
241 float dim_xmax(0), dim_xmin(0);
243 if( !(ist >> dim_title >> dim_nbins >> dim_xmin >> dim_xmax >> stype) ||
247 std::cout <<
"CaloHadDMCoeffHelper::parse_dim() -> Error! Could not parse line '" << sLine <<
"' at p1." << std::endl;
251 if(stype.find(
"flat") != std::string::npos) {
254 }
else if(stype.find(
"hand") != std::string::npos) {
256 std::vector<float> x_bins;
258 for(
int i=0;
i<dim_nbins+1;
i++) {
260 std::cout <<
"CaloHadDMCoeffHelper::parse_dim() -> Error! Could not parse line '" << sLine <<
"' at p2." << std::endl;
268 std::cout <<
"CaloHadDMCoeffHelper::parse_dim() -> Error! Could not parse line '" << sLine <<
"' at p3." << std::endl;