11 #include <xercesc/dom/DOM.hpp>
12 #include <xercesc/parsers/XercesDOMParser.hpp>
13 #include <xercesc/sax/HandlerBase.hpp>
24 XERCES_CPP_NAMESPACE_USE
30 }
while (std::isspace(ch));
31 if (ch != std::istream::traits_type::eof())
43 throw cms::Exception(
"InvalidFormat") <<
"Les Houches file contained invalid"
44 " header in init section."
52 throw cms::Exception(
"InvalidFormat") <<
"Les Houches file contained invalid data"
53 " in header payload line "
54 << (
i + 1) <<
"." << std::endl;
59 std::getline(in, line);
65 <<
"Les Houches file contained spurious"
66 " content after the regular data (this is normal for LHEv3 files for now)."
75 const std::vector<LHERunInfoProduct::Header> &
headers,
76 const std::vector<std::string> &comments)
78 std::copy(headers.begin(), headers.end(), std::back_inserter(this->headers));
79 std::copy(comments.begin(), comments.end(), std::back_inserter(this->comments));
130 proc->addAcceptedBr(eventWeight * brWeight * matchWeight);
131 proc->addAccepted(eventWeight * matchWeight);
132 procLumi->addAcceptedBr(eventWeight * brWeight * matchWeight);
133 procLumi->addAccepted(eventWeight * matchWeight);
136 proc->addKilled(eventWeight * matchWeight);
137 procLumi->addKilled(eventWeight * matchWeight);
138 if (eventWeight > 0) {
140 procLumi->addNPassPos();
143 procLumi->addNPassNeg();
147 proc->addSelected(eventWeight);
148 procLumi->addSelected(eventWeight);
149 if (eventWeight > 0) {
150 proc->addNTotalPos();
151 procLumi->addNTotalPos();
153 proc->addNTotalNeg();
154 procLumi->addNTotalNeg();
158 proc->addTried(eventWeight);
159 procLumi->addTried(eventWeight);
164 double sigSelSum = 0.0;
166 double sigBrSum = 0.0;
167 double err2Sum = 0.0;
168 double errBr2Sum = 0.0;
171 unsigned int idx =
proc->heprupIndex();
173 if (!
proc->killed().n())
176 double sigma2Sum, sigma2Err;
184 double npass =
proc->nPassPos() -
proc->nPassNeg();
188 fracAcc = ntotal > 0 ? npass / ntotal : -1;
191 fracAcc =
proc->selected().sum() > 0 ?
proc->killed().sum() /
proc->selected().sum() : -1;
198 double fracBr =
proc->accepted().sum() > 0.0 ?
proc->acceptedBr().sum() /
proc->accepted().sum() : 1;
199 double sigmaFin = sigmaAvg * fracAcc;
200 double sigmaFinBr = sigmaFin * fracBr;
208 double ntotal_pos =
proc->nTotalPos();
209 double effp = ntotal_pos > 0 ? (double)
proc->nPassPos() / ntotal_pos : 0;
210 double effp_err2 = ntotal_pos > 0 ? (1 - effp) * effp / ntotal_pos : 0;
212 double ntotal_neg =
proc->nTotalNeg();
213 double effn = ntotal_neg > 0 ? (double)
proc->nPassNeg() / ntotal_neg : 0;
214 double effn_err2 = ntotal_neg > 0 ? (1 - effn) * effn / ntotal_neg : 0;
217 ? (ntotal_pos * ntotal_pos * effp_err2 + ntotal_neg * ntotal_neg * effn_err2) / ntotal / ntotal
223 double passw =
proc->killed().sum();
224 double passw2 =
proc->killed().sum2();
225 double failw =
proc->selected().sum() - passw;
226 double failw2 =
proc->selected().sum2() - passw2;
227 double numerator = (passw2 * failw * failw + failw2 * passw * passw);
229 efferr2 = denominator > 0 ? numerator / denominator : 0;
233 double delta2Veto = efferr2 / fracAcc / fracAcc;
234 double delta2Sum = delta2Veto + sigma2Err / sigma2Sum;
235 relErr = (delta2Sum > 0.0 ?
std::sqrt(delta2Sum) : 0.0);
237 double deltaFin = sigmaFin * relErr;
238 double deltaFinBr = sigmaFinBr * relErr;
240 sigSelSum += sigmaAvg;
242 sigBrSum += sigmaFinBr;
243 err2Sum += deltaFin * deltaFin;
244 errBr2Sum += deltaFinBr * deltaFinBr;
253 double sigSelSum = 0.0;
255 double sigBrSum = 0.0;
256 double errSel2Sum = 0.0;
257 double err2Sum = 0.0;
258 double errBr2Sum = 0.0;
259 double errMatch2Sum = 0.0;
260 unsigned long nAccepted = 0;
261 unsigned long nTried = 0;
262 unsigned long nAccepted_pos = 0;
263 unsigned long nTried_pos = 0;
264 unsigned long nAccepted_neg = 0;
265 unsigned long nTried_neg = 0;
268 LogDebug(
"LHERunInfo") <<
" statistics";
269 LogDebug(
"LHERunInfo") <<
"Process and cross-section statistics";
270 LogDebug(
"LHERunInfo") <<
"------------------------------------";
271 LogDebug(
"LHERunInfo") <<
"Process\t\txsec_before [pb]\t\tpassed\tnposw\tnnegw\ttried\tnposw\tnnegw \txsec_match "
272 "[pb]\t\t\taccepted [%]\t event_eff [%]";
275 unsigned int idx =
proc->heprupIndex();
277 if (!
proc->selected().n()) {
278 LogDebug(
"LHERunInfo") <<
proc->process() <<
"\t0\t0\tn/a\t\t\tn/a";
282 double sigma2Sum, sigma2Err;
290 double npass =
proc->nPassPos() -
proc->nPassNeg();
294 fracAcc = ntotal > 0 ? npass / ntotal : -1;
297 fracAcc =
proc->selected().sum() > 0 ?
proc->killed().sum() /
proc->selected().sum() : -1;
301 double fracBr =
proc->accepted().sum() > 0.0 ?
proc->acceptedBr().sum() /
proc->accepted().sum() : 1;
302 double sigmaFin = fracAcc > 0 ? sigmaAvg * fracAcc : 0;
303 double sigmaFinBr = sigmaFin * fracBr;
306 double relAccErr = 1.0;
309 if (
proc->killed().n() > 0 && fracAcc > 0) {
313 double ntotal_pos =
proc->nTotalPos();
314 double effp = ntotal_pos > 0 ? (double)
proc->nPassPos() / ntotal_pos : 0;
315 double effp_err2 = ntotal_pos > 0 ? (1 - effp) * effp / ntotal_pos : 0;
317 double ntotal_neg =
proc->nTotalNeg();
318 double effn = ntotal_neg > 0 ? (double)
proc->nPassNeg() / ntotal_neg : 0;
319 double effn_err2 = ntotal_neg > 0 ? (1 - effn) * effn / ntotal_neg : 0;
321 efferr2 = ntotal > 0 ? (ntotal_pos * ntotal_pos * effp_err2 + ntotal_neg * ntotal_neg * effn_err2) /
328 double passw =
proc->killed().sum();
329 double passw2 =
proc->killed().sum2();
330 double failw =
proc->selected().sum() - passw;
331 double failw2 =
proc->selected().sum2() - passw2;
332 double numerator = (passw2 * failw * failw + failw2 * passw * passw);
334 efferr2 = denominator > 0 ? numerator / denominator : 0;
338 double delta2Veto = efferr2 / fracAcc / fracAcc;
339 double delta2Sum = delta2Veto + sigma2Err / sigma2Sum;
340 relErr = (delta2Sum > 0.0 ?
std::sqrt(delta2Sum) : 0.0);
341 relAccErr = (delta2Veto > 0.0 ?
std::sqrt(delta2Veto) : 0.0);
343 double deltaFin = sigmaFin * relErr;
344 double deltaFinBr = sigmaFinBr * relErr;
346 double ntotal_proc =
proc->nTotalPos() +
proc->nTotalNeg();
347 double event_eff_proc = ntotal_proc > 0 ? (double)(
proc->nPassPos() +
proc->nPassNeg()) / ntotal_proc : -1;
348 double event_eff_err_proc = ntotal_proc > 0 ?
std::sqrt((1 - event_eff_proc) * event_eff_proc / ntotal_proc) : -1;
350 LogDebug(
"LHERunInfo") <<
proc->process() <<
"\t\t" << std::scientific << std::setprecision(3)
352 <<
"\t\t" <<
proc->accepted().n() <<
"\t" <<
proc->nPassPos() <<
"\t" <<
proc->nPassNeg()
353 <<
"\t" <<
proc->tried().n() <<
"\t" <<
proc->nTotalPos() <<
"\t" <<
proc->nTotalNeg()
354 <<
"\t" << std::scientific << std::setprecision(3) << sigmaFinBr <<
" +/- " << deltaFinBr
355 <<
"\t\t" << std::fixed << std::setprecision(1) << (fracAcc * 100) <<
" +/- "
356 << (std::sqrt(efferr2) * 100) <<
"\t" << std::fixed << std::setprecision(1)
357 << (event_eff_proc * 100) <<
" +/- " << (event_eff_err_proc * 100);
359 nAccepted +=
proc->accepted().n();
360 nTried +=
proc->tried().n();
361 nAccepted_pos +=
proc->nPassPos();
362 nTried_pos +=
proc->nTotalPos();
363 nAccepted_neg +=
proc->nPassNeg();
364 nTried_neg +=
proc->nTotalNeg();
365 sigSelSum += sigmaAvg;
367 sigBrSum += sigmaFinBr;
368 errSel2Sum += sigma2Err;
369 err2Sum += deltaFin * deltaFin;
370 errBr2Sum += deltaFinBr * deltaFinBr;
371 errMatch2Sum += sigmaFin * relAccErr * sigmaFin * relAccErr;
374 double ntotal_all = (nTried_pos + nTried_neg);
375 double event_eff_all = ntotal_all > 0 ? (double)(nAccepted_pos + nAccepted_neg) / ntotal_all : -1;
376 double event_eff_err_all = ntotal_all > 0 ?
std::sqrt((1 - event_eff_all) * event_eff_all / ntotal_all) : -1;
378 LogDebug(
"LHERunInfo") <<
"Total\t\t" << std::scientific << std::setprecision(3) << sigSelSum <<
" +/- "
379 <<
std::sqrt(errSel2Sum) <<
"\t\t" << nAccepted <<
"\t" << nAccepted_pos <<
"\t"
380 << nAccepted_neg <<
"\t" << nTried <<
"\t" << nTried_pos <<
"\t" << nTried_neg <<
"\t"
381 << std::scientific << std::setprecision(3) << sigBrSum <<
" +/- " <<
std::sqrt(errBr2Sum)
382 <<
"\t\t" << std::fixed << std::setprecision(1) << (sigSum / sigSelSum * 100) <<
" +/- "
383 << (std::sqrt(errMatch2Sum) / sigSelSum * 100) <<
"\t" << std::fixed << std::setprecision(1)
384 << (event_eff_all * 100) <<
" +/- " << (event_eff_err_all * 100);
402 const char *
end = len >= 0 ? (data + len) :
nullptr;
403 while (*data && (!end || data < end)) {
404 std::size_t len = std::strcspn(data,
"\r\n");
405 if (end && data + len > end)
407 if (data[len] ==
'\r' && data[len + 1] ==
'\n')
416 static std::vector<std::string>
domToLines(
const DOMNode *node) {
417 std::vector<std::string>
result;
418 DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(
XMLUniStr(
"Core"));
419 std::unique_ptr<DOMLSSerializer> writer(((DOMImplementationLS *)(impl))->createLSSerializer());
421 std::unique_ptr<DOMLSOutput> outputDesc(((DOMImplementationLS *)impl)->createLSOutput());
423 outputDesc->setEncoding(
XMLUniStr(
"UTF-8"));
427 const char *
p = std::strchr((
const char *)
buffer,
'>') + 1;
428 const char *
q = std::strrchr(p,
'<');
436 for (std::vector<Header>::const_iterator iter =
headers.begin(); iter !=
headers.end(); ++iter) {
437 if (iter->tag() ==
tag)
438 return std::vector<std::string>(iter->begin(), iter->end());
439 if (iter->tag() ==
"header")
444 return std::vector<std::string>();
446 const DOMNode *root = header->getXMLNode();
448 return std::vector<std::string>();
450 for (
const DOMNode *iter = root->getFirstChild(); iter; iter = iter->getNextSibling()) {
451 if (iter->getNodeType() != DOMNode::ELEMENT_NODE)
453 if (tag == (
const char *)
XMLSimpleStr(iter->getNodeName()))
457 return std::vector<std::string>();
468 tmp =
"<" + header->tag() +
">";
472 if (iter != header->end())
474 tmp =
"</" + header->tag() +
">";
485 enum Mode { kHeader, kBody, kFooter };
487 const LHERunInfo::Header *header;
494 const DOMNode *LHERunInfo::Header::getXMLNode()
const {
500 parser.setValidationScheme(XercesDOMParser::Val_Auto);
501 parser.setDoNamespaces(
false);
502 parser.setDoSchema(
false);
503 parser.setValidationSchemaFullChecking(
false);
505 HandlerBase errHandler;
506 parser.setErrorHandler(&errHandler);
507 parser.setCreateEntityReferenceNodes(
false);
510 std::unique_ptr<CBInputStream::Reader>
reader(
new HeaderReader(
this));
513 xmlDoc = parser.adoptDocument();
514 }
catch (
const XMLException &
e) {
516 <<
"XML parser reported DOM error no. " << (
unsigned long)e.getCode() <<
": "
517 << XMLSimpleStr(e.getMessage()) <<
"." << std::endl;
518 }
catch (
const SAXException &e) {
520 <<
"XML parser reported: " << XMLSimpleStr(e.getMessage()) <<
"." << std::endl;
524 return xmlDoc->getDocumentElement();
528 int pdfA = -1, pdfB = -1;
538 return std::make_pair(pdfA, pdfB);
static XERCES_CPP_NAMESPACE_USE int skipWhitespace(std::istream &in)
const bool operator<(const LHERunInfo::Process &lhs, const LHERunInfo::Process &rhs)
void setLHEXSec(double value, double error)
XMLInputSourceWrapper< CBInputStream > CBInputSource
std::pair< double, double > EBMUP
comments_const_iterator comments_end() const
static std::vector< std::string > domToLines(const DOMNode *node)
headers_const_iterator headers_end() const
std::pair< int, int > IDBMUP
std::vector< Process > processes
std::pair< int, int > PDFGUP
headers_const_iterator headers_begin() const
LHERunInfo(std::istream &in)
std::vector< double > XERRUP
std::vector< double > XMAXUP
void setHepRupIndex(int id)
comments_const_iterator comments_begin() const
std::vector< Process > processesLumi
std::pair< int, int > pdfSetTranslation() const
std::pair< int, int > PDFSUP
std::vector< std::string > comments
char data[epos_bytes_allocation]
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
std::vector< Header > headers
void count(int process, CountMode count, double eventWeight=1.0, double brWeight=1.0, double matchWeight=1.0)
std::vector< std::string > findHeader(const std::string &tag) const
bool operator==(const LHERunInfo &other) const
std::vector< double > XSECUP
static void fillLines(std::vector< std::string > &lines, const char *data, int len=-1)
static std::string const source
Power< A, B >::type pow(const A &a, const B &b)