11 #include <xercesc/dom/DOM.hpp> 12 #include <xercesc/parsers/XercesDOMParser.hpp> 13 #include <xercesc/sax/HandlerBase.hpp> 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;
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)
97 proc.setHepRupIndex((
unsigned int)
i);
109 proc.setHepRupIndex((
unsigned int)
i);
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 sigBrSum = 0.0;
165 double errBr2Sum = 0.0;
168 unsigned int idx =
proc->heprupIndex();
170 if (!
proc->killed().n())
173 double sigma2Sum, sigma2Err;
181 double npass =
proc->nPassPos() -
proc->nPassNeg();
188 fracAcc =
proc->selected().sum() > 0 ?
proc->killed().sum() /
proc->selected().sum() : -1;
195 double fracBr =
proc->accepted().sum() > 0.0 ?
proc->acceptedBr().sum() /
proc->accepted().sum() : 1;
196 double sigmaFin = sigmaAvg * fracAcc;
197 double sigmaFinBr = sigmaFin * fracBr;
205 double ntotal_pos =
proc->nTotalPos();
206 double effp = ntotal_pos > 0 ? (double)
proc->nPassPos() / ntotal_pos : 0;
207 double effp_err2 = ntotal_pos > 0 ? (1 - effp) * effp / ntotal_pos : 0;
209 double ntotal_neg =
proc->nTotalNeg();
210 double effn = ntotal_neg > 0 ? (double)
proc->nPassNeg() / ntotal_neg : 0;
211 double effn_err2 = ntotal_neg > 0 ? (1 - effn) * effn / ntotal_neg : 0;
214 ? (ntotal_pos * ntotal_pos * effp_err2 + ntotal_neg * ntotal_neg * effn_err2) /
ntotal /
ntotal 220 double passw =
proc->killed().sum();
221 double passw2 =
proc->killed().sum2();
222 double failw =
proc->selected().sum() - passw;
223 double failw2 =
proc->selected().sum2() - passw2;
224 double numerator = (passw2 * failw * failw + failw2 * passw * passw);
230 double delta2Veto = efferr2 / fracAcc / fracAcc;
231 double delta2Sum = delta2Veto + sigma2Err / sigma2Sum;
232 relErr = (delta2Sum > 0.0 ?
std::sqrt(delta2Sum) : 0.0);
234 double deltaFinBr = sigmaFinBr * relErr;
236 sigBrSum += sigmaFinBr;
237 errBr2Sum += deltaFinBr * deltaFinBr;
246 double sigSelSum = 0.0;
248 double sigBrSum = 0.0;
249 double errSel2Sum = 0.0;
250 double errBr2Sum = 0.0;
251 double errMatch2Sum = 0.0;
252 unsigned long nAccepted = 0;
253 unsigned long nTried = 0;
254 unsigned long nAccepted_pos = 0;
255 unsigned long nTried_pos = 0;
256 unsigned long nAccepted_neg = 0;
257 unsigned long nTried_neg = 0;
260 LogDebug(
"LHERunInfo") <<
" statistics";
261 LogDebug(
"LHERunInfo") <<
"Process and cross-section statistics";
262 LogDebug(
"LHERunInfo") <<
"------------------------------------";
263 LogDebug(
"LHERunInfo") <<
"Process\t\txsec_before [pb]\t\tpassed\tnposw\tnnegw\ttried\tnposw\tnnegw \txsec_match " 264 "[pb]\t\t\taccepted [%]\t event_eff [%]";
267 unsigned int idx =
proc->heprupIndex();
269 if (!
proc->selected().n()) {
270 LogDebug(
"LHERunInfo") <<
proc->process() <<
"\t0\t0\tn/a\t\t\tn/a";
274 double sigma2Sum, sigma2Err;
282 double npass =
proc->nPassPos() -
proc->nPassNeg();
289 fracAcc =
proc->selected().sum() > 0 ?
proc->killed().sum() /
proc->selected().sum() : -1;
293 double fracBr =
proc->accepted().sum() > 0.0 ?
proc->acceptedBr().sum() /
proc->accepted().sum() : 1;
294 double sigmaFin = fracAcc > 0 ? sigmaAvg * fracAcc : 0;
295 double sigmaFinBr = sigmaFin * fracBr;
298 double relAccErr = 1.0;
301 if (
proc->killed().n() > 0 && fracAcc > 0) {
305 double ntotal_pos =
proc->nTotalPos();
306 double effp = ntotal_pos > 0 ? (double)
proc->nPassPos() / ntotal_pos : 0;
307 double effp_err2 = ntotal_pos > 0 ? (1 - effp) * effp / ntotal_pos : 0;
309 double ntotal_neg =
proc->nTotalNeg();
310 double effn = ntotal_neg > 0 ? (double)
proc->nPassNeg() / ntotal_neg : 0;
311 double effn_err2 = ntotal_neg > 0 ? (1 - effn) * effn / ntotal_neg : 0;
313 efferr2 =
ntotal > 0 ? (ntotal_pos * ntotal_pos * effp_err2 + ntotal_neg * ntotal_neg * effn_err2) /
320 double passw =
proc->killed().sum();
321 double passw2 =
proc->killed().sum2();
322 double failw =
proc->selected().sum() - passw;
323 double failw2 =
proc->selected().sum2() - passw2;
324 double numerator = (passw2 * failw * failw + failw2 * passw * passw);
330 double delta2Veto = efferr2 / fracAcc / fracAcc;
331 double delta2Sum = delta2Veto + sigma2Err / sigma2Sum;
332 relErr = (delta2Sum > 0.0 ?
std::sqrt(delta2Sum) : 0.0);
333 relAccErr = (delta2Veto > 0.0 ?
std::sqrt(delta2Veto) : 0.0);
335 double deltaFinBr = sigmaFinBr * relErr;
337 double ntotal_proc =
proc->nTotalPos() +
proc->nTotalNeg();
338 double event_eff_proc = ntotal_proc > 0 ? (double)(
proc->nPassPos() +
proc->nPassNeg()) / ntotal_proc : -1;
339 double event_eff_err_proc = ntotal_proc > 0 ?
std::sqrt((1 - event_eff_proc) * event_eff_proc / ntotal_proc) : -1;
341 LogDebug(
"LHERunInfo") <<
proc->process() <<
"\t\t" << std::scientific << std::setprecision(3)
343 <<
"\t\t" <<
proc->accepted().n() <<
"\t" <<
proc->nPassPos() <<
"\t" <<
proc->nPassNeg()
344 <<
"\t" <<
proc->tried().n() <<
"\t" <<
proc->nTotalPos() <<
"\t" <<
proc->nTotalNeg()
345 <<
"\t" << std::scientific << std::setprecision(3) << sigmaFinBr <<
" +/- " << deltaFinBr
346 <<
"\t\t" <<
std::fixed << std::setprecision(1) << (fracAcc * 100) <<
" +/- " 348 << (event_eff_proc * 100) <<
" +/- " << (event_eff_err_proc * 100);
350 nAccepted +=
proc->accepted().n();
351 nTried +=
proc->tried().n();
352 nAccepted_pos +=
proc->nPassPos();
353 nTried_pos +=
proc->nTotalPos();
354 nAccepted_neg +=
proc->nPassNeg();
355 nTried_neg +=
proc->nTotalNeg();
356 sigSelSum += sigmaAvg;
358 sigBrSum += sigmaFinBr;
359 errSel2Sum += sigma2Err;
360 errBr2Sum += deltaFinBr * deltaFinBr;
361 errMatch2Sum += sigmaFin * relAccErr * sigmaFin * relAccErr;
364 double ntotal_all = (nTried_pos + nTried_neg);
365 double event_eff_all = ntotal_all > 0 ? (double)(nAccepted_pos + nAccepted_neg) / ntotal_all : -1;
366 double event_eff_err_all = ntotal_all > 0 ?
std::sqrt((1 - event_eff_all) * event_eff_all / ntotal_all) : -1;
368 LogDebug(
"LHERunInfo") <<
"Total\t\t" << std::scientific << std::setprecision(3) << sigSelSum <<
" +/- " 369 <<
std::sqrt(errSel2Sum) <<
"\t\t" << nAccepted <<
"\t" << nAccepted_pos <<
"\t" 370 << nAccepted_neg <<
"\t" << nTried <<
"\t" << nTried_pos <<
"\t" << nTried_neg <<
"\t" 371 << std::scientific << std::setprecision(3) << sigBrSum <<
" +/- " <<
std::sqrt(errBr2Sum)
372 <<
"\t\t" <<
std::fixed << std::setprecision(1) << (sigSum / sigSelSum * 100) <<
" +/- " 373 << (
std::sqrt(errMatch2Sum) / sigSelSum * 100) <<
"\t" <<
std::fixed << std::setprecision(1)
374 << (event_eff_all * 100) <<
" +/- " << (event_eff_err_all * 100);
392 const char *end = len >= 0 ? (
data + len) :
nullptr;
393 while (*
data && (!end ||
data < end)) {
394 std::size_t len = std::strcspn(
data,
"\r\n");
395 if (end &&
data + len > end)
397 if (
data[len] ==
'\r' &&
data[len + 1] ==
'\n')
406 static std::vector<std::string>
domToLines(
const DOMNode *node) {
407 std::vector<std::string>
result;
408 DOMImplementation *
impl = DOMImplementationRegistry::getDOMImplementation(
XMLUniStr(
"Core"));
409 std::unique_ptr<DOMLSSerializer>
writer(((DOMImplementationLS *)(
impl))->createLSSerializer());
411 std::unique_ptr<DOMLSOutput> outputDesc(((DOMImplementationLS *)
impl)->createLSOutput());
413 outputDesc->setEncoding(
XMLUniStr(
"UTF-8"));
417 const char *
p = std::strchr((
const char *)
buffer,
'>') + 1;
418 const char *
q = std::strrchr(
p,
'<');
426 for (std::vector<Header>::const_iterator iter =
headers.begin(); iter !=
headers.end(); ++iter) {
427 if (iter->tag() ==
tag)
428 return std::vector<std::string>(iter->begin(), iter->end());
429 if (iter->tag() ==
"header")
434 return std::vector<std::string>();
438 return std::vector<std::string>();
440 for (
const DOMNode *iter =
root->getFirstChild(); iter; iter = iter->getNextSibling()) {
441 if (iter->getNodeType() != DOMNode::ELEMENT_NODE)
447 return std::vector<std::string>();
462 if (iter !=
header->end())
475 enum Mode { kHeader, kBody, kFooter };
477 const LHERunInfo::Header *
header;
484 const DOMNode *LHERunInfo::Header::getXMLNode()
const {
490 parser.setValidationScheme(XercesDOMParser::Val_Auto);
491 parser.setDoNamespaces(
false);
492 parser.setDoSchema(
false);
493 parser.setValidationSchemaFullChecking(
false);
495 HandlerBase errHandler;
496 parser.setErrorHandler(&errHandler);
497 parser.setCreateEntityReferenceNodes(
false);
500 std::unique_ptr<CBInputStream::Reader>
reader(
new HeaderReader(
this));
503 xmlDoc =
parser.adoptDocument();
504 }
catch (
const XMLException &
e) {
506 <<
"XML parser reported DOM error no. " << (
unsigned long)
e.getCode() <<
": " 507 << XMLSimpleStr(
e.getMessage()) <<
"." << std::endl;
508 }
catch (
const SAXException &
e) {
510 <<
"XML parser reported: " << XMLSimpleStr(
e.getMessage()) <<
"." << std::endl;
514 return xmlDoc->getDocumentElement();
518 int pdfA = -1, pdfB = -1;
528 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)
XMLInputSourceWrapper< CBInputStream > CBInputSource
std::pair< double, double > EBMUP
headers_const_iterator headers_begin() const
static std::vector< std::string > domToLines(const DOMNode *node)
std::pair< int, int > IDBMUP
std::vector< Process > processes
std::pair< int, int > pdfSetTranslation() const
comments_const_iterator comments_end() const
std::pair< int, int > PDFGUP
headers_const_iterator headers_end() const
std::vector< std::string > findHeader(const std::string &tag) const
LHERunInfo(std::istream &in)
std::vector< double > XERRUP
bool operator==(const LHERunInfo &other) const
std::vector< double > XMAXUP
std::vector< Process > processesLumi
std::pair< int, int > PDFSUP
std::vector< std::string > comments
char data[epos_bytes_allocation]
std::vector< Header > headers
comments_const_iterator comments_begin() const
void count(int process, CountMode count, double eventWeight=1.0, double brWeight=1.0, double matchWeight=1.0)
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)