11 #include <boost/bind.hpp> 13 #include <xercesc/dom/DOM.hpp> 14 #include <xercesc/parsers/XercesDOMParser.hpp> 15 #include <xercesc/sax/HandlerBase.hpp> 33 }
while(std::isspace(ch));
34 if (ch != std::istream::traits_type::eof())
50 <<
"Les Houches file contained invalid" 51 " header in init section." << std::endl;
60 <<
"Les Houches file contained invalid data" 61 " in header payload line " << (
i + 1)
67 std::getline(in, line);
73 <<
"Les Houches file contained spurious" 74 " content after the regular data (this is normal for LHEv3 files for now)." << std::endl;
86 const std::vector<LHERunInfoProduct::Header> &
headers,
87 const std::vector<std::string> &
comments) :
91 std::back_inserter(this->headers));
92 std::copy(comments.begin(), comments.end(),
93 std::back_inserter(this->comments));
148 double brWeight,
double matchWeight)
150 std::vector<Process>::iterator
proc =
155 std::vector<Process>::iterator procLumi =
162 proc->addAcceptedBr(eventWeight * brWeight * matchWeight);
163 proc->addAccepted(eventWeight * matchWeight);
164 procLumi->addAcceptedBr(eventWeight * brWeight * matchWeight);
165 procLumi->addAccepted(eventWeight * matchWeight);
167 proc->addKilled(eventWeight * matchWeight);
168 procLumi->addKilled(eventWeight * matchWeight);
172 procLumi->addNPassPos();
177 procLumi->addNPassNeg();
180 proc->addSelected(eventWeight);
181 procLumi->addSelected(eventWeight);
184 proc->addNTotalPos();
185 procLumi->addNTotalPos();
189 proc->addNTotalNeg();
190 procLumi->addNTotalNeg();
193 proc->addTried(eventWeight);
194 procLumi->addTried(eventWeight);
201 double sigSelSum = 0.0;
203 double sigBrSum = 0.0;
204 double err2Sum = 0.0;
205 double errBr2Sum = 0.0;
207 for(std::vector<Process>::const_iterator
proc =
processes.begin();
209 unsigned int idx =
proc->heprupIndex();
211 if (!
proc->killed().n())
214 double sigma2Sum, sigma2Err;
222 double npass =
proc->nPassPos() -
proc->nPassNeg();
225 fracAcc = ntotal > 0? npass/ntotal: -1;
228 fracAcc =
proc->selected().sum() > 0?
proc->killed().sum() /
proc->selected().sum():-1;
232 if(fracAcc<=0)
continue;
234 double fracBr =
proc->accepted().sum() > 0.0 ?
235 proc->acceptedBr().sum() /
proc->accepted().sum() : 1;
236 double sigmaFin = sigmaAvg * fracAcc ;
237 double sigmaFinBr = sigmaFin * fracBr;
245 double ntotal_pos =
proc->nTotalPos();
246 double effp = ntotal_pos > 0?
247 (double)
proc->nPassPos()/ntotal_pos:0;
248 double effp_err2 = ntotal_pos > 0?
249 (1-effp)*effp/ntotal_pos: 0;
251 double ntotal_neg =
proc->nTotalNeg();
252 double effn = ntotal_neg > 0?
253 (double)
proc->nPassNeg()/ntotal_neg:0;
254 double effn_err2 = ntotal_neg > 0?
255 (1-effn)*effn/ntotal_neg: 0;
257 efferr2 = ntotal > 0 ?
258 (ntotal_pos*ntotal_pos*effp_err2 +
259 ntotal_neg*ntotal_neg*effn_err2)/ntotal/ntotal:0;
265 double passw =
proc->killed().sum();
266 double passw2 =
proc->killed().sum2();
267 double failw =
proc->selected().sum() - passw;
268 double failw2 =
proc->selected().sum2() - passw2;
269 double numerator = (passw2*failw*failw + failw2*passw*passw);
271 efferr2 = denominator > 0?
272 numerator/denominator:0;
276 double delta2Veto = efferr2/fracAcc/fracAcc;
277 double delta2Sum = delta2Veto
278 + sigma2Err / sigma2Sum;
279 relErr = (delta2Sum > 0.0 ?
282 double deltaFin = sigmaFin * relErr;
283 double deltaFinBr = sigmaFinBr * relErr;
285 sigSelSum += sigmaAvg;
287 sigBrSum += sigmaFinBr;
288 err2Sum += deltaFin * deltaFin;
289 errBr2Sum += deltaFinBr * deltaFinBr;
299 double sigSelSum = 0.0;
301 double sigBrSum = 0.0;
302 double errSel2Sum = 0.0;
303 double err2Sum = 0.0;
304 double errBr2Sum = 0.0;
305 double errMatch2Sum = 0.0;
306 unsigned long nAccepted = 0;
307 unsigned long nTried = 0;
308 unsigned long nAccepted_pos = 0;
309 unsigned long nTried_pos = 0;
310 unsigned long nAccepted_neg = 0;
311 unsigned long nTried_neg = 0;
314 LogDebug(
"LHERunInfo") <<
" statistics";
315 LogDebug(
"LHERunInfo") <<
"Process and cross-section statistics";
316 LogDebug(
"LHERunInfo") <<
"------------------------------------";
317 LogDebug(
"LHERunInfo") <<
"Process\t\txsec_before [pb]\t\tpassed\tnposw\tnnegw\ttried\tnposw\tnnegw \txsec_match [pb]\t\t\taccepted [%]\t event_eff [%]";
319 for(std::vector<Process>::const_iterator
proc =
processes.begin();
321 unsigned int idx =
proc->heprupIndex();
323 if (!
proc->selected().n()) {
324 LogDebug(
"LHERunInfo") <<
proc->process() <<
"\t0\t0\tn/a\t\t\tn/a";
328 double sigma2Sum, sigma2Err;
336 double npass =
proc->nPassPos() -
proc->nPassNeg();
339 fracAcc = ntotal > 0? npass/ntotal: -1;
342 fracAcc =
proc->selected().sum() > 0?
proc->killed().sum() /
proc->selected().sum():-1;
347 double fracBr =
proc->accepted().sum() > 0.0 ?
348 proc->acceptedBr().sum() /
proc->accepted().sum() : 1;
349 double sigmaFin = fracAcc >0? sigmaAvg * fracAcc : 0;
350 double sigmaFinBr = sigmaFin * fracBr;
353 double relAccErr = 1.0;
356 if (
proc->killed().n() > 0 && fracAcc > 0) {
360 double ntotal_pos =
proc->nTotalPos();
361 double effp = ntotal_pos > 0?
362 (double)
proc->nPassPos()/ntotal_pos:0;
363 double effp_err2 = ntotal_pos > 0?
364 (1-effp)*effp/ntotal_pos: 0;
366 double ntotal_neg =
proc->nTotalNeg();
367 double effn = ntotal_neg > 0?
368 (double)
proc->nPassNeg()/ntotal_neg:0;
369 double effn_err2 = ntotal_neg > 0?
370 (1-effn)*effn/ntotal_neg: 0;
372 efferr2 = ntotal > 0 ?
373 (ntotal_pos*ntotal_pos*effp_err2 +
374 ntotal_neg*ntotal_neg*effn_err2)/ntotal/ntotal:0;
380 double passw =
proc->killed().sum();
381 double passw2 =
proc->killed().sum2();
382 double failw =
proc->selected().sum() - passw;
383 double failw2 =
proc->selected().sum2() - passw2;
384 double numerator = (passw2*failw*failw + failw2*passw*passw);
386 efferr2 = denominator>0?
387 numerator/denominator:0;
391 double delta2Veto = efferr2/fracAcc/fracAcc;
392 double delta2Sum = delta2Veto
393 + sigma2Err / sigma2Sum;
394 relErr = (delta2Sum > 0.0 ?
396 relAccErr = (delta2Veto > 0.0 ?
399 double deltaFin = sigmaFin * relErr;
400 double deltaFinBr = sigmaFinBr * relErr;
402 double ntotal_proc =
proc->nTotalPos()+
proc->nTotalNeg();
403 double event_eff_proc = ntotal_proc>0? (double)(
proc->nPassPos()+
proc->nPassNeg())/ntotal_proc: -1;
404 double event_eff_err_proc = ntotal_proc>0?
std::sqrt((1-event_eff_proc)*event_eff_proc/ntotal_proc): -1;
407 << std::scientific << std::setprecision(3)
410 <<
proc->accepted().n() <<
"\t" 411 <<
proc->nPassPos() <<
"\t" 412 <<
proc->nPassNeg() <<
"\t" 413 <<
proc->tried().n() <<
"\t" 414 <<
proc->nTotalPos() <<
"\t" 415 <<
proc->nTotalNeg() <<
"\t" 416 << std::scientific << std::setprecision(3)
417 << sigmaFinBr <<
" +/- " 418 << deltaFinBr <<
"\t\t" 420 << (fracAcc * 100) <<
" +/- " << ( std::sqrt(efferr2) * 100) <<
"\t" 422 << (event_eff_proc * 100) <<
" +/- " << ( event_eff_err_proc * 100);
424 nAccepted +=
proc->accepted().n();
425 nTried +=
proc->tried().n();
426 nAccepted_pos +=
proc->nPassPos();
427 nTried_pos +=
proc->nTotalPos();
428 nAccepted_neg +=
proc->nPassNeg();
429 nTried_neg +=
proc->nTotalNeg();
430 sigSelSum += sigmaAvg;
432 sigBrSum += sigmaFinBr;
433 errSel2Sum += sigma2Err;
434 err2Sum += deltaFin * deltaFin;
435 errBr2Sum += deltaFinBr * deltaFinBr;
436 errMatch2Sum += sigmaFin*relAccErr*sigmaFin*relAccErr;
439 double ntotal_all = (nTried_pos+nTried_neg);
440 double event_eff_all = ntotal_all>0? (double)(nAccepted_pos+nAccepted_neg)/ntotal_all: -1;
441 double event_eff_err_all = ntotal_all>0?
std::sqrt((1-event_eff_all)*event_eff_all/ntotal_all): -1;
443 LogDebug(
"LHERunInfo") <<
"Total\t\t" 444 << std::scientific << std::setprecision(3)
445 << sigSelSum <<
" +/- " <<
std::sqrt(errSel2Sum) <<
"\t\t" 447 << nAccepted_pos <<
"\t" 448 << nAccepted_neg <<
"\t" 450 << nTried_pos <<
"\t" 451 << nTried_neg <<
"\t" 452 << std::scientific << std::setprecision(3)
453 << sigBrSum <<
" +/- " 456 << (sigSum / sigSelSum * 100) <<
" +/- " << (std::sqrt(errMatch2Sum)/sigSelSum * 100) <<
"\t" 458 << (event_eff_all * 100) <<
" +/- " << (event_eff_err_all * 100);
490 const char *
end = len >= 0 ? (data + len) : 0;
491 while(*data && (!end || data < end)) {
492 std::size_t len = std::strcspn(data,
"\r\n");
493 if (end && data + len > end)
495 if (data[len] ==
'\r' && data[len + 1] ==
'\n')
504 static std::vector<std::string>
domToLines(
const DOMNode *node)
506 std::vector<std::string>
result;
507 DOMImplementation *
impl =
508 DOMImplementationRegistry::getDOMImplementation(
510 std::auto_ptr<DOMLSSerializer>
writer(((DOMImplementationLS*)(impl))->createLSSerializer());
512 std::auto_ptr<DOMLSOutput> outputDesc(((DOMImplementationLS*)impl)->createLSOutput());
513 assert(outputDesc.get());
514 outputDesc->setEncoding(
XMLUniStr(
"UTF-8"));
518 const char *
p = std::strchr((
const char*)
buffer,
'>') + 1;
519 const char *
q = std::strrchr(p,
'<');
528 for(std::vector<Header>::const_iterator iter =
headers.begin();
529 iter !=
headers.end(); ++iter) {
530 if (iter->tag() ==
tag)
531 return std::vector<std::string>(iter->begin(),
533 if (iter->tag() ==
"header")
538 return std::vector<std::string>();
540 const DOMNode *
root = header->getXMLNode();
542 return std::vector<std::string>();
544 for(
const DOMNode *iter = root->getFirstChild();
545 iter; iter = iter->getNextSibling()) {
546 if (iter->getNodeType() != DOMNode::ELEMENT_NODE)
548 if (tag == (
const char*)
XMLSimpleStr(iter->getNodeName()))
552 return std::vector<std::string>();
560 iter(header->
begin())
568 tmp =
"<" + header->
tag() +
">";
572 if (iter != header->
end())
574 tmp =
"</" + header->
tag() +
">";
598 const DOMNode *LHERunInfo::Header::getXMLNode()
const 605 parser.setValidationScheme(XercesDOMParser::Val_Auto);
606 parser.setDoNamespaces(
false);
607 parser.setDoSchema(
false);
608 parser.setValidationSchemaFullChecking(
false);
610 HandlerBase errHandler;
611 parser.setErrorHandler(&errHandler);
612 parser.setCreateEntityReferenceNodes(
false);
615 std::auto_ptr<CBInputStream::Reader>
reader(
616 new HeaderReader(
this));
618 parser.parse(source);
619 xmlDoc = parser.adoptDocument();
620 }
catch(
const XMLException &
e) {
622 <<
"XML parser reported DOM error no. " 623 << (
unsigned long)e.getCode()
626 }
catch(
const SAXException &e) {
628 <<
"XML parser reported: " 634 return xmlDoc->getDocumentElement();
639 int pdfA = -1, pdfB = -1;
649 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)
TrainProcessor *const proc
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
std::vector< std::vector< double > > tmp
char data[epos_bytes_allocation]
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)