ATLAS Offline Software
PMGCrossSectionTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id: PMGCrossSectionTool.cxx 764400 2016-07-26 17:47:39Z tripiana $
6 
7 #include <fstream>
8 #include <sstream>
9 #include <string>
10 #include <TSystem.h>
11 #include <TString.h>
12 #include <stdlib.h>
13 #include <limits>
14 
15 // Local include(s):
17 
18 namespace PMGTools {
19 
21 PMGCrossSectionTool(const std::string& name) : asg::AsgTool(name) { }
22 
23 
25 
26  // Tell the user what's happening:
27  ATH_MSG_INFO( "Initializing " << name() << "..." );
28  //ATH_MSG_INFO( "Read in all Xsec Info ..." );
29 
30  //readInfosFromDir(inputDir.c_str());
31 
32  // Return gracefully:
33  return StatusCode::SUCCESS;
34 }
35 
36 
37 bool PMGCrossSectionTool::readInfosFromFiles(std::vector<std::string> InputFiles)
38 {
39 
40  for (const auto& currentFileName : InputFiles) {
41 
42  std::ifstream currentFile(currentFileName);
43  if (not currentFile.is_open()) {
44  ATH_MSG_WARNING("cannot open file " << currentFileName);
45  continue;
46  }
47 
48  // skip first line
49  currentFile.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
50 
51  int nfound = 0; // for this file
52  for (std::string line; std::getline(currentFile, line); ) {
53  std::stringstream input_line(line);
55 
56  input_line >> help.dsid;
57  input_line >> help.containerName;
58  input_line >> help.amiXSec;
59  input_line >> help.filterEff;
60  input_line >> help.kFactor;
61  input_line >> help.XSecUncUP;
62  input_line >> help.XSecUncDOWN;
63  // :: below is for future use?
64  //input_line >> help.br;
65  //input_line >> help.higherOrderXsecTotal;
66  //input_line >> help.higherOrderXsecSample; // this is hoXsec * filter eff
67 
68  if (input_line.fail()) { ATH_MSG_ERROR("cannot parse line '" << line << "' from file " << currentFileName); continue; }
69 
71  ++nfound;
72  }
73 
74  if (nfound == 0) { ATH_MSG_WARNING("no sample read from file " << currentFileName); }
75  }
76 
77  if (m_fStoreSampleInfo.empty()) {
78  ATH_MSG_ERROR("list of sample is empty");
79  return false;
80  }
81 
82  return true;
83 }
84 
85 
87 {
88 
89  TString mydir = inputDir;
90  gSystem->ExpandPathName (mydir);
91  void *dirp = 0;
92 
93  std::vector<std::string> inFiles = {};
94 
95  try
96  {
97  dirp = gSystem->OpenDirectory (mydir.Data());
98  const char *file = 0;
99  while ((file = gSystem->GetDirEntry (dirp)))
100  {
101  std::string myfile = inputDir + "/" + file;
102  if (myfile.size() > 4 && myfile.substr (myfile.size() - 4) == ".txt")
103  inFiles.push_back(myfile);
104  }
105  gSystem->FreeDirectory (dirp);
106  }
107  catch (...)
108  {
109  gSystem->FreeDirectory (dirp);
110  //throw;
111  return false;
112  }
113 
115  return true;
116 }
117 
118 
120 {
121  const auto it = m_fStoreSampleInfo.find(dsid);
122  if (it != m_fStoreSampleInfo.end()) { return it->second.filterEff; }
123 
124  ATH_MSG_ERROR("Sample with DSID " << dsid << " has no info stored!!!");
125  return -1;
126 }
127 
128 
129 std::string PMGCrossSectionTool::getSampleName(const int dsid) const
130 {
131  const auto it = m_fStoreSampleInfo.find(dsid);
132  if (it != m_fStoreSampleInfo.end()) { return it->second.containerName; }
133 
134  ATH_MSG_ERROR("Sample with DSID " << dsid << " has no info stored!!!");
135  return std::string("");
136 }
137 
138 
140 {
141  const auto it = m_fStoreSampleInfo.find(dsid);
142  if (it != m_fStoreSampleInfo.end()) { return it->second.amiXSec; }
143 
144  ATH_MSG_ERROR("Sample with DSID " << dsid << " has no info stored!!!");
145  return -1;
146 }
147 
148 
149 // :: below is for future use?
150 /*double PMGCrossSectionTool::getBR(const int dsid) const
151 {
152  const auto it = m_fStoreSampleInfo.find(dsid);
153  if (it != m_fStoreSampleInfo.end()) { return it->second.br; }
154 
155  ATH_MSG_ERROR("Sample with DSID " << dsid << " has no info stored!!!");
156  return -1;
157 
158 }*/
159 
160 
162 {
163  const auto it = m_fStoreSampleInfo.find(dsid);
164  if (it != m_fStoreSampleInfo.end()) { return it->second.XSecUncUP; }
165 
166  ATH_MSG_ERROR("Sample with DSID " << dsid << " has no info stored!!!");
167  return -1;
168 }
169 
171 {
172  const auto it = m_fStoreSampleInfo.find(dsid);
173  if (it != m_fStoreSampleInfo.end()) { return it->second.XSecUncDOWN; }
174 
175  ATH_MSG_ERROR("Sample with DSID " << dsid << " has no info stored!!!");
176  return -1;
177 }
178 
180 {
181  //symmetrize the up and down variations
182  return 0.5*( fabs(getXsectionUncertaintyDOWN(dsid)) + fabs(getXsectionUncertaintyUP(dsid)) );
183 }
184 
185 double PMGCrossSectionTool::getKfactor(const int dsid) const
186 {
187  const auto it = m_fStoreSampleInfo.find(dsid);
188  if (it != m_fStoreSampleInfo.end()) { return it->second.kFactor; }
189 
190  ATH_MSG_ERROR("Sample with DSID " << dsid << " has no info stored!!!");
191  return -1;
192 }
193 
194 
195 // :: below is for future use?
197 {
198  const auto it = m_fStoreSampleInfo.find(dsid);
199  if (it != m_fStoreSampleInfo.end()) { return it->second.amiXSec * it->second.kFactor * it->second.filterEff; }
200  // :: below is for future use?
201  //return info.higherOrderXsecSample;
202 
203  ATH_MSG_ERROR("Sample with DSID " << dsid << " has no info stored!!!");
204  return -1;
205 }
206 
207 
208 std::vector<int> PMGCrossSectionTool::getLoadedDSIDs() const {
209  std::vector<int> dsids;
210  dsids.reserve(m_fStoreSampleInfo.size());
211  for (const auto& key_info : m_fStoreSampleInfo) {
212  dsids.push_back(key_info.second.dsid);
213  }
214  return dsids;
215 }
216 
217 } // end namespace
PMGTools::PMGCrossSectionTool::getAMIXsection
double getAMIXsection(const int dsid) const
return the AMI cross-section for DSID
Definition: PMGCrossSectionTool.cxx:139
checkFileSG.line
line
Definition: checkFileSG.py:75
PMGTools::PMGCrossSectionTool::PMGCrossSectionTool
PMGCrossSectionTool(const std::string &name="PMGCrossSectionTool")
Standard tool constructor, with name.
Definition: PMGCrossSectionTool.cxx:21
max
#define max(a, b)
Definition: cfImp.cxx:41
PMGCrossSectionTool.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PMGTools::PMGCrossSectionTool::getXsectionUncertaintyDOWN
double getXsectionUncertaintyDOWN(const int dsid) const
return the cross-section uncertainty for DSID
Definition: PMGCrossSectionTool.cxx:170
PMGTools::PMGCrossSectionTool::getSampleName
std::string getSampleName(const int dsid) const
return the sample name for DSID
Definition: PMGCrossSectionTool.cxx:129
Make4DCorrelationMatrix.inFiles
list inFiles
Definition: Make4DCorrelationMatrix.py:59
skel.it
it
Definition: skel.GENtoEVGEN.py:396
asg
Definition: DataHandleTestTool.h:28
PMGTools::PMGCrossSectionTool::getFilterEff
double getFilterEff(const int dsid) const
return filter efficiency for DSID
Definition: PMGCrossSectionTool.cxx:119
grl_maker.mydir
mydir
Definition: grl_maker.py:4
PMGTools::PMGCrossSectionTool::getLoadedDSIDs
std::vector< int > getLoadedDSIDs() const
get a list of the DSID for the loaded samples
Definition: PMGCrossSectionTool.cxx:208
PMGTools::PMGCrossSectionTool::initialize
StatusCode initialize()
initialize() is required by AsgTool base class
Definition: PMGCrossSectionTool.cxx:24
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
python.CaloScaleNoiseConfig.help
help
Definition: CaloScaleNoiseConfig.py:76
Generate_dsid_ranseed.dsid
dsid
Definition: Generate_dsid_ranseed.py:6
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
PMGTools::PMGCrossSectionTool::m_fStoreSampleInfo
std::map< unsigned, PMGTools::AllSampleInfo > m_fStoreSampleInfo
Definition: PMGCrossSectionTool.h:82
PMGTools::AllSampleInfo
Definition: AnalysisCommon/PMGTools/PMGTools/IPMGCrossSectionTool.h:18
PMGTools
Tool providing sample cross-sections and k-factors etc.
Definition: AnalysisCommon/PMGTools/PMGTools/IPMGCrossSectionTool.h:15
PMGTools::PMGCrossSectionTool::getSampleXsection
double getSampleXsection(const int dsid) const
return the sample cross-section for DSID
Definition: PMGCrossSectionTool.cxx:196
PMGTools::PMGCrossSectionTool::getXsectionUncertainty
double getXsectionUncertainty(const int dsid) const
return the cross-section uncertainty for DSID
Definition: PMGCrossSectionTool.cxx:179
file
TFile * file
Definition: tile_monitor.h:29
TestSUSYToolsAlg.inputDir
string inputDir
Definition: TestSUSYToolsAlg.py:74
PMGTools::PMGCrossSectionTool::getKfactor
double getKfactor(const int dsid) const
return the branching ratio for DSID
Definition: PMGCrossSectionTool.cxx:185
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
PMGTools::PMGCrossSectionTool::readInfosFromFiles
bool readInfosFromFiles(std::vector< std::string >)
read infos from file, store them in the structure and make a vector that keeps all of them
Definition: PMGCrossSectionTool.cxx:37
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
PMGTools::PMGCrossSectionTool::getXsectionUncertaintyUP
double getXsectionUncertaintyUP(const int dsid) const
return the cross-section uncertainty for DSID
Definition: PMGCrossSectionTool.cxx:161
PMGTools::PMGCrossSectionTool::readInfosFromDir
bool readInfosFromDir(const std::string &inputDir)
read infos from all files in dir
Definition: PMGCrossSectionTool.cxx:86