11 #include <boost/bind.hpp>
13 #include <xercesc/dom/DOM.hpp>
14 #include <xercesc/parsers/XercesDOMParser.hpp>
15 #include <xercesc/sax/HandlerBase.hpp>
32 }
while (std::isspace(ch));
33 if (ch != std::istream::traits_type::eof())
45 throw cms::Exception(
"InvalidFormat") <<
"Les Houches file contained invalid"
46 " header in init section."
54 throw cms::Exception(
"InvalidFormat") <<
"Les Houches file contained invalid data"
55 " in header payload line "
56 << (
i + 1) <<
"." << std::endl;
67 <<
"Les Houches file contained spurious"
68 " content after the regular data (this is normal for LHEv3 files for now)."
77 const std::vector<LHERunInfoProduct::Header> &
headers,
78 const std::vector<std::string> &
comments)
99 proc.setHepRupIndex((
unsigned int)
i);
111 proc.setHepRupIndex((
unsigned int)
i);
132 proc->addAcceptedBr(eventWeight * brWeight * matchWeight);
133 proc->addAccepted(eventWeight * matchWeight);
134 procLumi->addAcceptedBr(eventWeight * brWeight * matchWeight);
135 procLumi->addAccepted(eventWeight * matchWeight);
138 proc->addKilled(eventWeight * matchWeight);
139 procLumi->addKilled(eventWeight * matchWeight);
140 if (eventWeight > 0) {
142 procLumi->addNPassPos();
145 procLumi->addNPassNeg();
149 proc->addSelected(eventWeight);
150 procLumi->addSelected(eventWeight);
151 if (eventWeight > 0) {
152 proc->addNTotalPos();
153 procLumi->addNTotalPos();
155 proc->addNTotalNeg();
156 procLumi->addNTotalNeg();
160 proc->addTried(eventWeight);
161 procLumi->addTried(eventWeight);
166 double sigSelSum = 0.0;
168 double sigBrSum = 0.0;
169 double err2Sum = 0.0;
170 double errBr2Sum = 0.0;
173 unsigned int idx =
proc->heprupIndex();
175 if (!
proc->killed().n())
178 double sigma2Sum, sigma2Err;
186 double npass =
proc->nPassPos() -
proc->nPassNeg();
193 fracAcc =
proc->selected().sum() > 0 ?
proc->killed().sum() /
proc->selected().sum() : -1;
200 double fracBr =
proc->accepted().sum() > 0.0 ?
proc->acceptedBr().sum() /
proc->accepted().sum() : 1;
201 double sigmaFin = sigmaAvg * fracAcc;
202 double sigmaFinBr = sigmaFin * fracBr;
210 double ntotal_pos =
proc->nTotalPos();
211 double effp = ntotal_pos > 0 ? (double)
proc->nPassPos() / ntotal_pos : 0;
212 double effp_err2 = ntotal_pos > 0 ? (1 - effp) * effp / ntotal_pos : 0;
214 double ntotal_neg =
proc->nTotalNeg();
215 double effn = ntotal_neg > 0 ? (double)
proc->nPassNeg() / ntotal_neg : 0;
216 double effn_err2 = ntotal_neg > 0 ? (1 - effn) * effn / ntotal_neg : 0;
219 ? (ntotal_pos * ntotal_pos * effp_err2 + ntotal_neg * ntotal_neg * effn_err2) /
ntotal /
ntotal
225 double passw =
proc->killed().sum();
226 double passw2 =
proc->killed().sum2();
227 double failw =
proc->selected().sum() - passw;
228 double failw2 =
proc->selected().sum2() - passw2;
229 double numerator = (passw2 * failw * failw + failw2 * passw * passw);
235 double delta2Veto = efferr2 / fracAcc / fracAcc;
236 double delta2Sum = delta2Veto + sigma2Err / sigma2Sum;
237 relErr = (delta2Sum > 0.0 ?
std::sqrt(delta2Sum) : 0.0);
239 double deltaFin = sigmaFin * relErr;
240 double deltaFinBr = sigmaFinBr * relErr;
242 sigSelSum += sigmaAvg;
244 sigBrSum += sigmaFinBr;
245 err2Sum += deltaFin * deltaFin;
246 errBr2Sum += deltaFinBr * deltaFinBr;
255 double sigSelSum = 0.0;
257 double sigBrSum = 0.0;
258 double errSel2Sum = 0.0;
259 double err2Sum = 0.0;
260 double errBr2Sum = 0.0;
261 double errMatch2Sum = 0.0;
262 unsigned long nAccepted = 0;
263 unsigned long nTried = 0;
264 unsigned long nAccepted_pos = 0;
265 unsigned long nTried_pos = 0;
266 unsigned long nAccepted_neg = 0;
267 unsigned long nTried_neg = 0;
270 LogDebug(
"LHERunInfo") <<
" statistics";
271 LogDebug(
"LHERunInfo") <<
"Process and cross-section statistics";
272 LogDebug(
"LHERunInfo") <<
"------------------------------------";
273 LogDebug(
"LHERunInfo") <<
"Process\t\txsec_before [pb]\t\tpassed\tnposw\tnnegw\ttried\tnposw\tnnegw \txsec_match "
274 "[pb]\t\t\taccepted [%]\t event_eff [%]";
277 unsigned int idx =
proc->heprupIndex();
279 if (!
proc->selected().n()) {
280 LogDebug(
"LHERunInfo") <<
proc->process() <<
"\t0\t0\tn/a\t\t\tn/a";
284 double sigma2Sum, sigma2Err;
292 double npass =
proc->nPassPos() -
proc->nPassNeg();
299 fracAcc =
proc->selected().sum() > 0 ?
proc->killed().sum() /
proc->selected().sum() : -1;
303 double fracBr =
proc->accepted().sum() > 0.0 ?
proc->acceptedBr().sum() /
proc->accepted().sum() : 1;
304 double sigmaFin = fracAcc > 0 ? sigmaAvg * fracAcc : 0;
305 double sigmaFinBr = sigmaFin * fracBr;
308 double relAccErr = 1.0;
311 if (
proc->killed().n() > 0 && fracAcc > 0) {
315 double ntotal_pos =
proc->nTotalPos();
316 double effp = ntotal_pos > 0 ? (double)
proc->nPassPos() / ntotal_pos : 0;
317 double effp_err2 = ntotal_pos > 0 ? (1 - effp) * effp / ntotal_pos : 0;
319 double ntotal_neg =
proc->nTotalNeg();
320 double effn = ntotal_neg > 0 ? (double)
proc->nPassNeg() / ntotal_neg : 0;
321 double effn_err2 = ntotal_neg > 0 ? (1 - effn) * effn / ntotal_neg : 0;
323 efferr2 =
ntotal > 0 ? (ntotal_pos * ntotal_pos * effp_err2 + ntotal_neg * ntotal_neg * effn_err2) /
330 double passw =
proc->killed().sum();
331 double passw2 =
proc->killed().sum2();
332 double failw =
proc->selected().sum() - passw;
333 double failw2 =
proc->selected().sum2() - passw2;
334 double numerator = (passw2 * failw * failw + failw2 * passw * passw);
340 double delta2Veto = efferr2 / fracAcc / fracAcc;
341 double delta2Sum = delta2Veto + sigma2Err / sigma2Sum;
342 relErr = (delta2Sum > 0.0 ?
std::sqrt(delta2Sum) : 0.0);
343 relAccErr = (delta2Veto > 0.0 ?
std::sqrt(delta2Veto) : 0.0);
345 double deltaFin = sigmaFin * relErr;
346 double deltaFinBr = sigmaFinBr * relErr;
348 double ntotal_proc =
proc->nTotalPos() +
proc->nTotalNeg();
349 double event_eff_proc = ntotal_proc > 0 ? (double)(
proc->nPassPos() +
proc->nPassNeg()) / ntotal_proc : -1;
350 double event_eff_err_proc = ntotal_proc > 0 ?
std::sqrt((1 - event_eff_proc) * event_eff_proc / ntotal_proc) : -1;
352 LogDebug(
"LHERunInfo") <<
proc->process() <<
"\t\t" << std::scientific << std::setprecision(3)
354 <<
"\t\t" <<
proc->accepted().n() <<
"\t" <<
proc->nPassPos() <<
"\t" <<
proc->nPassNeg()
355 <<
"\t" <<
proc->tried().n() <<
"\t" <<
proc->nTotalPos() <<
"\t" <<
proc->nTotalNeg()
356 <<
"\t" << std::scientific << std::setprecision(3) << sigmaFinBr <<
" +/- " << deltaFinBr
357 <<
"\t\t" <<
std::fixed << std::setprecision(1) << (fracAcc * 100) <<
" +/- "
359 << (event_eff_proc * 100) <<
" +/- " << (event_eff_err_proc * 100);
361 nAccepted +=
proc->accepted().n();
362 nTried +=
proc->tried().n();
363 nAccepted_pos +=
proc->nPassPos();
364 nTried_pos +=
proc->nTotalPos();
365 nAccepted_neg +=
proc->nPassNeg();
366 nTried_neg +=
proc->nTotalNeg();
367 sigSelSum += sigmaAvg;
369 sigBrSum += sigmaFinBr;
370 errSel2Sum += sigma2Err;
371 err2Sum += deltaFin * deltaFin;
372 errBr2Sum += deltaFinBr * deltaFinBr;
373 errMatch2Sum += sigmaFin * relAccErr * sigmaFin * relAccErr;
376 double ntotal_all = (nTried_pos + nTried_neg);
377 double event_eff_all = ntotal_all > 0 ? (double)(nAccepted_pos + nAccepted_neg) / ntotal_all : -1;
378 double event_eff_err_all = ntotal_all > 0 ?
std::sqrt((1 - event_eff_all) * event_eff_all / ntotal_all) : -1;
380 LogDebug(
"LHERunInfo") <<
"Total\t\t" << std::scientific << std::setprecision(3) << sigSelSum <<
" +/- "
381 <<
std::sqrt(errSel2Sum) <<
"\t\t" << nAccepted <<
"\t" << nAccepted_pos <<
"\t"
382 << nAccepted_neg <<
"\t" << nTried <<
"\t" << nTried_pos <<
"\t" << nTried_neg <<
"\t"
383 << std::scientific << std::setprecision(3) << sigBrSum <<
" +/- " <<
std::sqrt(errBr2Sum)
384 <<
"\t\t" <<
std::fixed << std::setprecision(1) << (sigSum / sigSelSum * 100) <<
" +/- "
385 << (
std::sqrt(errMatch2Sum) / sigSelSum * 100) <<
"\t" <<
std::fixed << std::setprecision(1)
386 << (event_eff_all * 100) <<
" +/- " << (event_eff_err_all * 100);
404 const char *
end = len >= 0 ? (
data + len) :
nullptr;
406 std::size_t len = std::strcspn(
data,
"\r\n");
409 if (
data[len] ==
'\r' &&
data[len + 1] ==
'\n')
418 static std::vector<std::string>
domToLines(
const DOMNode *node) {
419 std::vector<std::string>
result;
420 DOMImplementation *
impl = DOMImplementationRegistry::getDOMImplementation(
XMLUniStr(
"Core"));
421 std::unique_ptr<DOMLSSerializer>
writer(((DOMImplementationLS *)(
impl))->createLSSerializer());
423 std::unique_ptr<DOMLSOutput> outputDesc(((DOMImplementationLS *)
impl)->createLSOutput());
425 outputDesc->setEncoding(
XMLUniStr(
"UTF-8"));
429 const char *
p = std::strchr((
const char *)
buffer,
'>') + 1;
430 const char *
q = std::strrchr(
p,
'<');
438 for (std::vector<Header>::const_iterator iter =
headers.begin(); iter !=
headers.end(); ++iter) {
439 if (iter->tag() ==
tag)
440 return std::vector<std::string>(iter->begin(), iter->end());
441 if (iter->tag() ==
"header")
446 return std::vector<std::string>();
450 return std::vector<std::string>();
452 for (
const DOMNode *iter =
root->getFirstChild(); iter; iter = iter->getNextSibling()) {
453 if (iter->getNodeType() != DOMNode::ELEMENT_NODE)
459 return std::vector<std::string>();
474 if (iter !=
header->end())
487 enum Mode { kHeader, kBody, kFooter };
489 const LHERunInfo::Header *
header;
496 const DOMNode *LHERunInfo::Header::getXMLNode()
const {
502 parser.setValidationScheme(XercesDOMParser::Val_Auto);
503 parser.setDoNamespaces(
false);
504 parser.setDoSchema(
false);
505 parser.setValidationSchemaFullChecking(
false);
507 HandlerBase errHandler;
508 parser.setErrorHandler(&errHandler);
509 parser.setCreateEntityReferenceNodes(
false);
512 std::unique_ptr<CBInputStream::Reader>
reader(
new HeaderReader(
this));
515 xmlDoc =
parser.adoptDocument();
516 }
catch (
const XMLException &
e) {
518 <<
"XML parser reported DOM error no. " << (
unsigned long)
e.getCode() <<
": "
519 << XMLSimpleStr(
e.getMessage()) <<
"." << std::endl;
520 }
catch (
const SAXException &
e) {
522 <<
"XML parser reported: " << XMLSimpleStr(
e.getMessage()) <<
"." << std::endl;
526 return xmlDoc->getDocumentElement();
530 int pdfA = -1, pdfB = -1;
540 return std::make_pair(pdfA, pdfB);