ATLAS Offline Software
SampleXsection.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 #include <fstream>
6 #include <sstream>
7 #include <string>
8 
10 #include <iostream>
11 #include <stdlib.h>
12 
13 using namespace std;
14 
16  if (this != &xs) {
17  m_Xsects = xs.m_Xsects;
18  m_Uncert = xs.m_Uncert;
19  }
20  return *this;
21 }
22 
24  ifstream in(fName);
25 
26  if (!in) return false;
27 
28  for (; !in.eof(); ) {
29  string line;
30  if (!getline(in, line)) break;
31  if (!line.empty() && line[0] != '#') {
32  istringstream istr(line);
33  int dsid = -1;
34  double xSect, kFact, xSectDw, xSectUp;
35  string s_shower, s_xSectDw, s_xSectUp;
36  showering shower;
37  istr >> dsid >> xSect >> kFact >> s_shower >> s_xSectDw >> s_xSectUp;
38  if (!s_shower.empty() && s_shower[0] != '#') {
39  shower = stringToShower(s_shower);
40  if (shower == showering::unknown) {
41  cerr <<
42  "ERROR!! TopDataPreparation::SampleXsection::readFromFile: unknown showering (which is needed for btagging SF!!!) : "
43  << s_shower << " for DSID= " << dsid << endl;
44  }
45 
46  if (!s_xSectDw.empty() && s_xSectDw[0] != '#') {
47  xSectDw = atof(s_xSectDw.c_str());
48  if (!s_xSectUp.empty()) {
49  xSectUp = atof(s_xSectUp.c_str());
50  } else {
51  cerr << "ERROR!! SampleXsection::readFromFile: xSectDw of " << dsid << " is defined ( " << s_xSectDw <<
52  " ), but not xSectUp" << endl;
53  xSectUp = -1.;
54  }
55  } else {
56  xSectDw = -1.;
57  xSectUp = -1.;
58  }
59  }// !s_showering.empty()
60  else {
61  xSectDw = -1.;
62  xSectUp = -1.;
63  shower = unknown;
64  }
65  setSample(dsid, xSect, kFact, shower, xSectDw, xSectUp);
66  }
67  }
68 
69  in.close();
70  return true;
71 }
72 
73 void SampleXsection::setSample(const int dsid, const double xSect, const double kFact, const showering shower,
74  const double xSectDw, const double xSectUp) {
75  if (dsid < 0) return;
76 
77  map<int, pair<double, double> >::const_iterator it = m_Xsects.find(dsid);
78  if (it != m_Xsects.end()) {
79  cerr << "ERROR!! SampleXsection::setSample: duplicate entry ! DSID= " << dsid << endl;
80  //cerr << "ERROR!! SampleXsection::setSample: xSect=" << xSect << "\told xSect=" <<
81  // it->second.first <<endl;
82  }
83  m_Xsects[dsid] = pair<double, double>(xSect, kFact);
84  m_Uncert[dsid] = pair<double, double>(xSectDw, xSectUp);
85  m_Showering[dsid] = shower;
86 }
87 
88 double SampleXsection::getRawXsection(const int dsid) const {
89  map<int, pair<double, double> >::const_iterator it = m_Xsects.find(dsid);
90  if (it != m_Xsects.end()) return it->second.first;
91 
92  return -1;
93 }
94 
95 double SampleXsection::getKfactor(const int dsid) const {
96  map<int, pair<double, double> >::const_iterator it = m_Xsects.find(dsid);
97  if (it != m_Xsects.end()) return it->second.second;
98 
99  return -1;
100 }
101 
102 double SampleXsection::getXsection(const int dsid) const {
103  map<int, pair<double, double> >::const_iterator it = m_Xsects.find(dsid);
104  if (it != m_Xsects.end()) return (it->second.first) * (it->second.second);
105 
106  return -1;
107 }
108 
109 double SampleXsection::getXsectionDown(const int dsid) const {
110  map<int, pair<double, double> >::const_iterator it = m_Uncert.find(dsid);
111  if (it != m_Uncert.end()) return it->second.first;
112 
113  return -1;
114 }
115 
116 double SampleXsection::getXsectionUp(const int dsid) const {
117  map<int, pair<double, double> >::const_iterator it = m_Uncert.find(dsid);
118  if (it != m_Uncert.end()) return it->second.second;
119 
120  return -1;
121 }
122 
123 pair<double, double> SampleXsection::getXsectionDownUp(const int dsid) const {
124  map<int, pair<double, double> >::const_iterator it = m_Uncert.find(dsid);
125  if (it != m_Uncert.end()) return it->second;
126 
127  pair<double, double> temp = pair<double, double>(-1, -1);
128  return temp;
129 }
130 
132  map<int, showering >::const_iterator it = m_Showering.find(dsid);
133  if (it != m_Showering.end()) {
134 
135  showering shower = it->second;
136  // apply the translation of set
137  shower = applyTranslation(shower);
138 
139  return shower;
140  }
141 
142  return unknown;
143 }
144 
145 std::string SampleXsection::getShoweringString(const int dsid) const
146 {
147  return showerToString(getShowering(dsid));
148 }
149 
151  // S.Korn: labelling taken from here:
152  // https://twiki.cern.ch/twiki/bin/view/AtlasProtected/BTagRecommendationsRelease22
153 
154  showering shower = getShowering(dsid);
155 
156  if (shower == showering::pythia) return 0;
157  else if (shower == showering::herwigpp || shower == showering::herwig) // use the herwig++ maps for the few fortran
158  // herwig samples we may have
159  return 1;
160  else if (shower == showering::pythia8) return 2;
161  else if (shower == showering::sherpa) return 3;
162  else if (shower == showering::sherpa21) return 4;
163  else if (shower == showering::amcatnlopythia8) return 5;
164  else if (shower == showering::herwigpp713) return 6;
165  else if (shower == showering::sherpa228) return 7;
166  else if (shower == showering::sherpa2210) return 8;
167  else if (shower == showering::herwigpp721) return 9;
168  else if (shower == showering::sherpa2212) return 10;
169  else if (shower == showering::amcatnloherwig7) return 11;
170  else {
171  std::cout <<
172  "==========================================================================================================================================="
173  << std::endl;
174  std::cout << "ERROR:TopDataPreparation: The DSID " << dsid <<
175  " does not have a showering algorithm defined!!! This is needed for MC/MC SF!!! ---> EXIT." << std::endl;
176  std::cout << "\t" << std::endl;
177  exit(1);
178  }
179 
180  return 0;
181 }
182 
184  const std::string& stringName = showerToString(shower);
185 
186  // check the map
187  auto itr = m_translator.find(stringName);
188  if (itr == m_translator.end()) {
189  return shower;
190  } else {
191  // need to apply the translation
192  return stringToShower(itr->second);
193  }
194 }
195 
197  if (shower == showering::pythia) return "pythia";
198  else if (shower == showering::herwig) return "herwig";
199  else if (shower == showering::herwigpp) return "herwig";
200  else if (shower == showering::sherpa) return "sherpa";
201  else if (shower == showering::sherpa21) return "sherpa21";
202  else if (shower == showering::pythia8) return "pythia8";
203  else if (shower == showering::amcatnlopythia8) return "amcatnlopythia8";
204  else if (shower == showering::herwigpp713) return "herwigpp713";
205  else if (shower == showering::sherpa228) return "sherpa228";
206  else if (shower == showering::sherpa2210) return "sherpa2210";
207  else if (shower == showering::herwigpp721) return "herwigpp721";
208  else if (shower == showering::sherpa2212) return "sherpa2212";
209  else if (shower == showering::amcatnloherwig7) return "amcatnloherwig7";
210 
211  return "";
212 }
213 
215  if (name == "pythia") return showering::pythia;
216  else if (name == "herwig") return showering::herwig;
217  else if (name == "sherpa") return showering::sherpa;
218  else if (name == "sherpa21") return showering::sherpa21;
219  else if (name == "pythia8") return showering::pythia8;
220  else if (name == "herwigpp") return showering::herwigpp;
221  else if (name == "amcatnlopythia8") return showering::amcatnlopythia8;
222  else if (name == "herwigpp713") return showering::herwigpp713;
223  else if (name == "sherpa228") return showering::sherpa228;
224  else if (name == "sherpa2210") return showering::sherpa2210;
225  else if (name == "herwigpp721") return showering::herwigpp721;
226  else if (name == "sherpa2212") return showering::sherpa2212;
227  else if (name == "amcatnloherwig7") return showering::amcatnloherwig7;
228 
229  return showering::unknown;
230 }
SampleXsection::getKfactor
double getKfactor(const int dsid) const
Definition: SampleXsection.cxx:95
temp
Definition: JetEventDict.h:21
checkFileSG.line
line
Definition: checkFileSG.py:75
SampleXsection.h
rootconvert.fName
string fName
Definition: rootconvert.py:5
SampleXsection::setSample
void setSample(const int dsid, const double xSect, const double kFact, const showering shower, const double xSectDw, const double xSectUp)
Definition: SampleXsection.cxx:73
SampleXsection::operator=
SampleXsection & operator=(const SampleXsection &xs)
Definition: SampleXsection.cxx:15
skel.it
it
Definition: skel.GENtoEVGEN.py:423
SampleXsection::showering
showering
Definition: SampleXsection.h:21
SampleXsection::getXsectionDownUp
std::pair< double, double > getXsectionDownUp(const int dsid) const
Definition: SampleXsection.cxx:123
SampleXsection
Definition: SampleXsection.h:19
SampleXsection::m_Uncert
std::map< int, std::pair< double, double > > m_Uncert
Definition: SampleXsection.h:61
SampleXsection::readFromFile
bool readFromFile(const char *fName)
Definition: SampleXsection.cxx:23
SampleXsection::getShoweringString
std::string getShoweringString(const int dsid) const
Definition: SampleXsection.cxx:145
Generate_dsid_ranseed.dsid
dsid
Definition: Generate_dsid_ranseed.py:6
SampleXsection::getRawXsection
double getRawXsection(const int dsid) const
Definition: SampleXsection.cxx:88
SampleXsection::getShowering
showering getShowering(const int dsid) const
Definition: SampleXsection.cxx:131
calibdata.exit
exit
Definition: calibdata.py:236
CxxUtils::atof
double atof(std::string_view str)
Converts a string into a double / float.
Definition: Control/CxxUtils/Root/StringUtils.cxx:91
SampleXsection::m_Xsects
std::map< int, std::pair< double, double > > m_Xsects
Definition: SampleXsection.h:60
Muon::nsw::unknown
@ unknown
Definition: NSWTriggerElink.h:36
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SampleXsection::getXsection
double getXsection(const int dsid) const
Definition: SampleXsection.cxx:102
SampleXsection::applyTranslation
showering applyTranslation(const showering shower) const
Definition: SampleXsection.cxx:183
SampleXsection::getXsectionDown
double getXsectionDown(const int dsid) const
Definition: SampleXsection.cxx:109
SampleXsection::stringToShower
showering stringToShower(const std::string &name) const
Definition: SampleXsection.cxx:214
SampleXsection::getShoweringIndex
int getShoweringIndex(const int dsid) const
Definition: SampleXsection.cxx:150
SampleXsection::getXsectionUp
double getXsectionUp(const int dsid) const
Definition: SampleXsection.cxx:116
SampleXsection::showerToString
std::string showerToString(const showering shower) const
Definition: SampleXsection.cxx:196