ATLAS Offline Software
LArReadHadDMCoeffFile2.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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 /* ***************************************************************************
15 c-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 /* ***************************************************************************
29 initialize
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 /* ***************************************************************************
55 reading text file
56 *************************************************************************** */
57 StatusCode 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(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 /* **************************************************************************
186 parsing 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) {
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) {
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 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
yodamerge_tmp.dim
dim
Definition: yodamerge_tmp.py:239
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
CaloHadDMCoeff2::HadDMArea::m_is_on
int m_is_on
Definition: CaloHadDMCoeff2.h:42
CaloHadDMCoeff2::kDIM_HAND
@ kDIM_HAND
Definition: CaloHadDMCoeff2.h:25
CaloHadDMCoeff2::kAREA_LOOKUP
@ kAREA_LOOKUP
Definition: CaloHadDMCoeff2.h:26
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArReadHadDMCoeffFile2::execute
StatusCode execute()
Definition: LArReadHadDMCoeffFile2.cxx:43
CaloHadDMCoeff2
Dead material correction coefficients.
Definition: CaloHadDMCoeff2.h:23
CaloHadDMCoeff2::PrintData
void PrintData(std::ostream &ff) const
Definition: CaloHadDMCoeff2.cxx:199
MAX_BUFFER_LEN
#define MAX_BUFFER_LEN
Definition: LArReadHadDMCoeffFile2.cxx:11
AthCommonMsg< Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
CaloHadDMCoeff2::HadDMArea::m_offset
int m_offset
Definition: CaloHadDMCoeff2.h:45
CaloHadDMCoeff2::addHadDMCoeff
void addHadDMCoeff(const HadDMCoeff &theData)
Definition: CaloHadDMCoeff2.cxx:63
CaloHadDMCoeff2::HadDMArea::m_dimEta
HadDMDimension m_dimEta
Definition: CaloHadDMCoeff2.h:50
LArReadHadDMCoeffFile2::m_data
CaloHadDMCoeff2 * m_data
Definition: LArReadHadDMCoeffFile2.h:31
CaloHadDMCoeff2::HadDMArea
Definition: CaloHadDMCoeff2.h:39
LArReadHadDMCoeffFile2::finalize
StatusCode finalize()
Definition: LArReadHadDMCoeffFile2.cxx:48
LArReadHadDMCoeffFile2::m_key
std::string m_key
Definition: LArReadHadDMCoeffFile2.h: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
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CaloHadDMCoeff2::setHadDMCoeff
void setHadDMCoeff(const int iBin, const HadDMCoeff &theData)
Definition: CaloHadDMCoeff2.cxx:68
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
LArReadHadDMCoeffFile2::~LArReadHadDMCoeffFile2
~LArReadHadDMCoeffFile2()
Definition: LArReadHadDMCoeffFile2.cxx:25
file
TFile * file
Definition: tile_monitor.h:29
CaloHadDMCoeff2::HadDMDimension
Definition: CaloHadDMCoeff2.h:27
python.xAODType.dummy
dummy
Definition: xAODType.py:4
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LArReadHadDMCoeffFile2.h
CaloHadDMCoeff2::HadDMArea::m_type
int m_type
Definition: CaloHadDMCoeff2.h:43
AthAlgorithm
Definition: AthAlgorithm.h:47
CaloHadDMCoeff2::HadDMArea::m_indx
int m_indx
Definition: CaloHadDMCoeff2.h:41
CaloHadDMCoeff2::HadDMArea::m_title
std::string m_title
Definition: CaloHadDMCoeff2.h:40
PathResolver.h
CaloHadDMCoeff2::kAREA_PROF
@ kAREA_PROF
Definition: CaloHadDMCoeff2.h:26
LArReadHadDMCoeffFile2::initialize
StatusCode initialize()
Definition: LArReadHadDMCoeffFile2.cxx:31
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
CaloHadDMCoeff2::HadDMArea::m_dimLambda
HadDMDimension m_dimLambda
Definition: CaloHadDMCoeff2.h:49
CaloHadDMCoeff2::HadDMArea::m_dimFrac
HadDMDimension m_dimFrac
Definition: CaloHadDMCoeff2.h:47
CaloHadDMCoeff2::HadDMArea::m_dimEner
HadDMDimension m_dimEner
Definition: CaloHadDMCoeff2.h:48
CaloHadDMCoeff2::HadDMCoeff
std::vector< float > HadDMCoeff
Definition: CaloHadDMCoeff2.h:54
CaloHadDMCoeff2::addHadDMArea
void addHadDMArea(const HadDMArea &theArea)
Definition: CaloHadDMCoeff2.cxx:39
LArReadHadDMCoeffFile2::m_hadDMCoeffFileName
std::string m_hadDMCoeffFileName
Definition: LArReadHadDMCoeffFile2.h:29
LArReadHadDMCoeffFile2::LArReadHadDMCoeffFile2
LArReadHadDMCoeffFile2(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArReadHadDMCoeffFile2.cxx:17
DEBUG
#define DEBUG
Definition: page_access.h:11
CaloHadDMCoeff2::HadDMArea::m_length
int m_length
Definition: CaloHadDMCoeff2.h:46
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
LArReadHadDMCoeffFile2::parse_dim
int parse_dim(std::string &sLine, CaloHadDMCoeff2::HadDMDimension &dim)
Definition: LArReadHadDMCoeffFile2.cxx:188
compute_lumi.fin
fin
Definition: compute_lumi.py:19
CaloHadDMCoeff2::HadDMArea::m_nPars
int m_nPars
Definition: CaloHadDMCoeff2.h:44
CaloHadDMCoeff2::kDIM_FLAT
@ kDIM_FLAT
Definition: CaloHadDMCoeff2.h:25
StoreGateSvc.h
length
double length(const pvec &v)
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:26
readCCLHist.float
float
Definition: readCCLHist.py:83
LArReadHadDMCoeffFile2::initDataFromFile
StatusCode initDataFromFile(const std::string &hadDMCoeffFileName)
Definition: LArReadHadDMCoeffFile2.cxx:57