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())
50 throw cms::Exception(
"InvalidFormat") <<
"Les Houches file contained invalid" 51 " header in init section." 59 throw cms::Exception(
"InvalidFormat") <<
"Les Houches file contained invalid data" 60 " in header payload line " 61 << (
i + 1) <<
"." << std::endl;
72 <<
"Les Houches file contained spurious" 73 " content after the regular data (this is normal for LHEv3 files for now)." 82 const std::vector<LHERunInfoProduct::Header> &
headers,
83 const std::vector<std::string> &comments)
104 proc.setHepRupIndex((
unsigned int)
i);
116 proc.setHepRupIndex((
unsigned int)
i);
137 proc->addAcceptedBr(eventWeight * brWeight * matchWeight);
138 proc->addAccepted(eventWeight * matchWeight);
139 procLumi->addAcceptedBr(eventWeight * brWeight * matchWeight);
140 procLumi->addAccepted(eventWeight * matchWeight);
143 proc->addKilled(eventWeight * matchWeight);
144 procLumi->addKilled(eventWeight * matchWeight);
145 if (eventWeight > 0) {
147 procLumi->addNPassPos();
150 procLumi->addNPassNeg();
154 proc->addSelected(eventWeight);
155 procLumi->addSelected(eventWeight);
156 if (eventWeight > 0) {
157 proc->addNTotalPos();
158 procLumi->addNTotalPos();
160 proc->addNTotalNeg();
161 procLumi->addNTotalNeg();
165 proc->addTried(eventWeight);
166 procLumi->addTried(eventWeight);
171 double sigBrSum = 0.0;
172 double errBr2Sum = 0.0;
175 unsigned int idx =
proc->heprupIndex();
177 if (!
proc->killed().n())
180 double sigma2Sum, sigma2Err;
188 double npass =
proc->nPassPos() -
proc->nPassNeg();
195 fracAcc =
proc->selected().sum() > 0 ?
proc->killed().sum() /
proc->selected().sum() : -1;
202 double fracBr =
proc->accepted().sum() > 0.0 ?
proc->acceptedBr().sum() /
proc->accepted().sum() : 1;
203 double sigmaFin = sigmaAvg * fracAcc;
204 double sigmaFinBr = sigmaFin * fracBr;
212 double ntotal_pos =
proc->nTotalPos();
213 double effp = ntotal_pos > 0 ? (double)
proc->nPassPos() / ntotal_pos : 0;
214 double effp_err2 = ntotal_pos > 0 ? (1 - effp) * effp / ntotal_pos : 0;
216 double ntotal_neg =
proc->nTotalNeg();
217 double effn = ntotal_neg > 0 ? (double)
proc->nPassNeg() / ntotal_neg : 0;
218 double effn_err2 = ntotal_neg > 0 ? (1 - effn) * effn / ntotal_neg : 0;
221 ? (ntotal_pos * ntotal_pos * effp_err2 + ntotal_neg * ntotal_neg * effn_err2) /
ntotal /
ntotal 227 double passw =
proc->killed().sum();
228 double passw2 =
proc->killed().sum2();
229 double failw =
proc->selected().sum() - passw;
230 double failw2 =
proc->selected().sum2() - passw2;
231 double numerator = (passw2 * failw * failw + failw2 * passw * passw);
237 double delta2Veto = efferr2 / fracAcc / fracAcc;
238 double delta2Sum = delta2Veto + sigma2Err / sigma2Sum;
239 relErr = (delta2Sum > 0.0 ?
std::sqrt(delta2Sum) : 0.0);
241 double deltaFinBr = sigmaFinBr * relErr;
243 sigBrSum += sigmaFinBr;
244 errBr2Sum += deltaFinBr * deltaFinBr;
253 double sigSelSum = 0.0;
255 double sigBrSum = 0.0;
256 double errSel2Sum = 0.0;
257 double errBr2Sum = 0.0;
258 double errMatch2Sum = 0.0;
259 unsigned long nAccepted = 0;
260 unsigned long nTried = 0;
261 unsigned long nAccepted_pos = 0;
262 unsigned long nTried_pos = 0;
263 unsigned long nAccepted_neg = 0;
264 unsigned long nTried_neg = 0;
267 LogDebug(
"LHERunInfo") <<
" statistics";
268 LogDebug(
"LHERunInfo") <<
"Process and cross-section statistics";
269 LogDebug(
"LHERunInfo") <<
"------------------------------------";
270 LogDebug(
"LHERunInfo") <<
"Process\t\txsec_before [pb]\t\tpassed\tnposw\tnnegw\ttried\tnposw\tnnegw \txsec_match " 271 "[pb]\t\t\taccepted [%]\t event_eff [%]";
274 unsigned int idx =
proc->heprupIndex();
276 if (!
proc->selected().n()) {
277 LogDebug(
"LHERunInfo") <<
proc->process() <<
"\t0\t0\tn/a\t\t\tn/a";
281 double sigma2Sum, sigma2Err;
289 double npass =
proc->nPassPos() -
proc->nPassNeg();
296 fracAcc =
proc->selected().sum() > 0 ?
proc->killed().sum() /
proc->selected().sum() : -1;
300 double fracBr =
proc->accepted().sum() > 0.0 ?
proc->acceptedBr().sum() /
proc->accepted().sum() : 1;
301 double sigmaFin = fracAcc > 0 ? sigmaAvg * fracAcc : 0;
302 double sigmaFinBr = sigmaFin * fracBr;
305 double relAccErr = 1.0;
308 if (
proc->killed().n() > 0 && fracAcc > 0) {
312 double ntotal_pos =
proc->nTotalPos();
313 double effp = ntotal_pos > 0 ? (double)
proc->nPassPos() / ntotal_pos : 0;
314 double effp_err2 = ntotal_pos > 0 ? (1 - effp) * effp / ntotal_pos : 0;
316 double ntotal_neg =
proc->nTotalNeg();
317 double effn = ntotal_neg > 0 ? (double)
proc->nPassNeg() / ntotal_neg : 0;
318 double effn_err2 = ntotal_neg > 0 ? (1 - effn) * effn / ntotal_neg : 0;
320 efferr2 =
ntotal > 0 ? (ntotal_pos * ntotal_pos * effp_err2 + ntotal_neg * ntotal_neg * effn_err2) /
327 double passw =
proc->killed().sum();
328 double passw2 =
proc->killed().sum2();
329 double failw =
proc->selected().sum() - passw;
330 double failw2 =
proc->selected().sum2() - passw2;
331 double numerator = (passw2 * failw * failw + failw2 * passw * passw);
337 double delta2Veto = efferr2 / fracAcc / fracAcc;
338 double delta2Sum = delta2Veto + sigma2Err / sigma2Sum;
339 relErr = (delta2Sum > 0.0 ?
std::sqrt(delta2Sum) : 0.0);
340 relAccErr = (delta2Veto > 0.0 ?
std::sqrt(delta2Veto) : 0.0);
342 double deltaFinBr = sigmaFinBr * relErr;
344 double ntotal_proc =
proc->nTotalPos() +
proc->nTotalNeg();
345 double event_eff_proc = ntotal_proc > 0 ? (double)(
proc->nPassPos() +
proc->nPassNeg()) / ntotal_proc : -1;
346 double event_eff_err_proc = ntotal_proc > 0 ?
std::sqrt((1 - event_eff_proc) * event_eff_proc / ntotal_proc) : -1;
348 LogDebug(
"LHERunInfo") <<
proc->process() <<
"\t\t" << std::scientific << std::setprecision(3)
350 <<
"\t\t" <<
proc->accepted().n() <<
"\t" <<
proc->nPassPos() <<
"\t" <<
proc->nPassNeg()
351 <<
"\t" <<
proc->tried().n() <<
"\t" <<
proc->nTotalPos() <<
"\t" <<
proc->nTotalNeg()
352 <<
"\t" << std::scientific << std::setprecision(3) << sigmaFinBr <<
" +/- " << deltaFinBr
353 <<
"\t\t" <<
std::fixed << std::setprecision(1) << (fracAcc * 100) <<
" +/- " 355 << (event_eff_proc * 100) <<
" +/- " << (event_eff_err_proc * 100);
357 nAccepted +=
proc->accepted().n();
358 nTried +=
proc->tried().n();
359 nAccepted_pos +=
proc->nPassPos();
360 nTried_pos +=
proc->nTotalPos();
361 nAccepted_neg +=
proc->nPassNeg();
362 nTried_neg +=
proc->nTotalNeg();
363 sigSelSum += sigmaAvg;
365 sigBrSum += sigmaFinBr;
366 errSel2Sum += sigma2Err;
367 errBr2Sum += deltaFinBr * deltaFinBr;
368 errMatch2Sum += sigmaFin * relAccErr * sigmaFin * relAccErr;
371 double ntotal_all = (nTried_pos + nTried_neg);
372 double event_eff_all = ntotal_all > 0 ? (double)(nAccepted_pos + nAccepted_neg) / ntotal_all : -1;
373 double event_eff_err_all = ntotal_all > 0 ?
std::sqrt((1 - event_eff_all) * event_eff_all / ntotal_all) : -1;
375 LogDebug(
"LHERunInfo") <<
"Total\t\t" << std::scientific << std::setprecision(3) << sigSelSum <<
" +/- " 376 <<
std::sqrt(errSel2Sum) <<
"\t\t" << nAccepted <<
"\t" << nAccepted_pos <<
"\t" 377 << nAccepted_neg <<
"\t" << nTried <<
"\t" << nTried_pos <<
"\t" << nTried_neg <<
"\t" 378 << std::scientific << std::setprecision(3) << sigBrSum <<
" +/- " <<
std::sqrt(errBr2Sum)
379 <<
"\t\t" <<
std::fixed << std::setprecision(1) << (sigSum / sigSelSum * 100) <<
" +/- " 380 << (
std::sqrt(errMatch2Sum) / sigSelSum * 100) <<
"\t" <<
std::fixed << std::setprecision(1)
381 << (event_eff_all * 100) <<
" +/- " << (event_eff_err_all * 100);
399 const char *end = len >= 0 ? (
data + len) :
nullptr;
400 while (*
data && (!end ||
data < end)) {
401 std::size_t len = std::strcspn(
data,
"\r\n");
402 if (end &&
data + len > end)
404 if (
data[len] ==
'\r' &&
data[len + 1] ==
'\n')
413 static std::vector<std::string>
domToLines(
const DOMNode *node) {
414 std::vector<std::string>
result;
415 DOMImplementation *
impl = DOMImplementationRegistry::getDOMImplementation(
XMLUniStr(
"Core"));
416 std::unique_ptr<DOMLSSerializer>
writer(((DOMImplementationLS *)(
impl))->createLSSerializer());
418 std::unique_ptr<DOMLSOutput> outputDesc(((DOMImplementationLS *)
impl)->createLSOutput());
420 outputDesc->setEncoding(
XMLUniStr(
"UTF-8"));
424 const char *
p = std::strchr((
const char *)
buffer,
'>') + 1;
425 const char *
q = std::strrchr(
p,
'<');
433 for (std::vector<Header>::const_iterator iter =
headers.begin(); iter !=
headers.end(); ++iter) {
434 if (iter->tag() ==
tag)
435 return std::vector<std::string>(iter->begin(), iter->end());
436 if (iter->tag() ==
"header")
441 return std::vector<std::string>();
445 return std::vector<std::string>();
447 for (
const DOMNode *iter =
root->getFirstChild(); iter; iter = iter->getNextSibling()) {
448 if (iter->getNodeType() != DOMNode::ELEMENT_NODE)
454 return std::vector<std::string>();
469 if (iter !=
header->end())
482 enum Mode { kHeader, kBody, kFooter };
484 const LHERunInfo::Header *
header;
491 const DOMNode *LHERunInfo::Header::getXMLNode()
const {
497 parser.setValidationScheme(XercesDOMParser::Val_Auto);
498 parser.setDoNamespaces(
false);
499 parser.setDoSchema(
false);
500 parser.setValidationSchemaFullChecking(
false);
502 HandlerBase errHandler;
503 parser.setErrorHandler(&errHandler);
504 parser.setCreateEntityReferenceNodes(
false);
507 std::unique_ptr<CBInputStream::Reader>
reader(
new HeaderReader(
this));
510 xmlDoc =
parser.adoptDocument();
511 }
catch (
const XMLException &
e) {
513 <<
"XML parser reported DOM error no. " << (
unsigned long)
e.getCode() <<
": " 514 << XMLSimpleStr(
e.getMessage()) <<
"." << std::endl;
515 }
catch (
const SAXException &
e) {
517 <<
"XML parser reported: " << XMLSimpleStr(
e.getMessage()) <<
"." << std::endl;
521 return xmlDoc->getDocumentElement();
525 int pdfA = -1, pdfB = -1;
535 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)
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)