11 #include <boost/bind.hpp>
13 #include <xercesc/dom/DOM.hpp>
14 #include <xercesc/parsers/XercesDOMParser.hpp>
15 #include <xercesc/sax/HandlerBase.hpp>
26 XERCES_CPP_NAMESPACE_USE
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));
99 heprup(product.heprup())
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 > 1
e-6? npass/ntotal: -1;
228 fracAcc =
proc->selected().sum() > 1
e-6?
proc->killed().sum() /
proc->selected().sum():-1;
232 if(fracAcc<1
e-6)
continue;
234 double fracBr =
proc->accepted().sum() > 0.0 ?
235 proc->acceptedBr().sum() /
proc->accepted().sum() : 1;
236 double sigmaFin = sigmaAvg * fracAcc * fracBr;
237 double sigmaFinBr = sigmaFin * fracBr;
240 if (
proc->killed().n() > 1) {
246 double ntotal_pos =
proc->nTotalPos();
247 double effp = ntotal_pos > 1
e-6?
248 (double)
proc->nPassPos()/ntotal_pos:0;
249 double effp_err2 = ntotal_pos > 1
e-6?
250 (1-effp)*effp/ntotal_pos: 0;
252 double ntotal_neg =
proc->nTotalNeg();
253 double effn = ntotal_neg > 1
e-6?
254 (double)
proc->nPassNeg()/ntotal_neg:0;
255 double effn_err2 = ntotal_neg > 1
e-6?
256 (1-effn)*effn/ntotal_neg: 0;
258 efferr2 = ntotal > 0 ?
259 (ntotal_pos*ntotal_pos*effp_err2 +
260 ntotal_neg*ntotal_neg*effn_err2)/ntotal/ntotal:0;
266 double passw =
proc->killed().sum();
267 double passw2 =
proc->killed().sum2();
268 double failw =
proc->selected().sum() - passw;
269 double failw2 =
proc->selected().sum2() - passw2;
270 double numerator = (passw2*failw*failw + failw2*passw*passw);
272 efferr2 = denominator>1
e-6?
273 numerator/denominator:0;
277 double delta2Veto = efferr2/fracAcc/fracAcc;
278 double delta2Sum = delta2Veto
279 + sigma2Err / sigma2Sum;
280 relErr = (delta2Sum > 0.0 ?
283 double deltaFin = sigmaFin * relErr;
284 double deltaFinBr = sigmaFinBr * relErr;
286 sigSelSum += sigmaAvg;
288 sigBrSum += sigmaFinBr;
289 err2Sum += deltaFin * deltaFin;
290 errBr2Sum += deltaFinBr * deltaFinBr;
300 double sigSelSum = 0.0;
302 double sigBrSum = 0.0;
303 double errSel2Sum = 0.0;
304 double err2Sum = 0.0;
305 double errBr2Sum = 0.0;
306 double errMatch2Sum = 0.0;
307 unsigned long nAccepted = 0;
308 unsigned long nTried = 0;
309 unsigned long nAccepted_pos = 0;
310 unsigned long nTried_pos = 0;
311 unsigned long nAccepted_neg = 0;
312 unsigned long nTried_neg = 0;
316 std::cout <<
"Process and cross-section statistics" << std::endl;
317 std::cout <<
"------------------------------------" << std::endl;
318 std::cout <<
"Process\t\txsec_before [pb]\t\tpassed\tnposw\tnnegw\ttried\tnposw\tnnegw \txsec_match [pb]\t\t\taccepted [%]\t event_eff [%]"
321 for(std::vector<Process>::const_iterator
proc =
processes.begin();
323 unsigned int idx =
proc->heprupIndex();
325 if (!
proc->selected().n()) {
331 double sigma2Sum, sigma2Err;
339 double npass =
proc->nPassPos() -
proc->nPassNeg();
342 fracAcc = ntotal > 1
e-6? npass/ntotal: -1;
345 fracAcc =
proc->selected().sum() > 1
e-6?
proc->killed().sum() /
proc->selected().sum():-1;
349 if(fracAcc<1
e-6)
continue;
351 double fracBr =
proc->accepted().sum() > 0.0 ?
352 proc->acceptedBr().sum() /
proc->accepted().sum() : 1;
353 double sigmaFin = sigmaAvg * fracAcc;
354 double sigmaFinBr = sigmaFin * fracBr;
357 double relAccErr = 1.0;
360 if (
proc->killed().n() > 1) {
364 double ntotal_pos =
proc->nTotalPos();
365 double effp = ntotal_pos > 1
e-6?
366 (double)
proc->nPassPos()/ntotal_pos:0;
367 double effp_err2 = ntotal_pos > 1
e-6?
368 (1-effp)*effp/ntotal_pos: 0;
370 double ntotal_neg =
proc->nTotalNeg();
371 double effn = ntotal_neg > 1
e-6?
372 (double)
proc->nPassNeg()/ntotal_neg:0;
373 double effn_err2 = ntotal_neg > 1
e-6?
374 (1-effn)*effn/ntotal_neg: 0;
376 efferr2 = ntotal > 0 ?
377 (ntotal_pos*ntotal_pos*effp_err2 +
378 ntotal_neg*ntotal_neg*effn_err2)/ntotal/ntotal:0;
384 double passw =
proc->killed().sum();
385 double passw2 =
proc->killed().sum2();
386 double failw =
proc->selected().sum() - passw;
387 double failw2 =
proc->selected().sum2() - passw2;
388 double numerator = (passw2*failw*failw + failw2*passw*passw);
390 efferr2 = denominator>1
e-6?
391 numerator/denominator:0;
395 double delta2Veto = efferr2/fracAcc/fracAcc;
396 double delta2Sum = delta2Veto
397 + sigma2Err / sigma2Sum;
398 relErr = (delta2Sum > 0.0 ?
400 relAccErr = (delta2Veto > 0.0 ?
403 double deltaFin = sigmaFin * relErr;
404 double deltaFinBr = sigmaFinBr * relErr;
406 double ntotal_proc =
proc->nTotalPos()+
proc->nTotalNeg();
407 double event_eff_proc = ntotal_proc>1
e-6? (double)(
proc->nPassPos()+
proc->nPassNeg())/ntotal_proc: -1;
408 double event_eff_err_proc = ntotal_proc>1
e-6?
std::sqrt((1-event_eff_proc)*event_eff_proc/ntotal_proc): -1;
411 << std::scientific << std::setprecision(3)
414 <<
proc->accepted().n() <<
"\t"
415 <<
proc->nPassPos() <<
"\t"
416 <<
proc->nPassNeg() <<
"\t"
417 <<
proc->tried().n() <<
"\t"
418 <<
proc->nTotalPos() <<
"\t"
419 <<
proc->nTotalNeg() <<
"\t"
420 << std::scientific << std::setprecision(3)
421 << sigmaFinBr <<
" +/- "
422 << deltaFinBr <<
"\t\t"
423 << std::fixed << std::setprecision(1)
424 << (fracAcc * 100) <<
" +/- " << ( std::sqrt(efferr2) * 100) <<
"\t"
425 << std::fixed << std::setprecision(1)
426 << (event_eff_proc * 100) <<
" +/- " << ( event_eff_err_proc * 100)
429 nAccepted +=
proc->accepted().n();
430 nTried +=
proc->tried().n();
431 nAccepted_pos +=
proc->nPassPos();
432 nTried_pos +=
proc->nTotalPos();
433 nAccepted_neg +=
proc->nPassNeg();
434 nTried_neg +=
proc->nTotalNeg();
435 sigSelSum += sigmaAvg;
437 sigBrSum += sigmaFinBr;
438 errSel2Sum += sigma2Err;
439 err2Sum += deltaFin * deltaFin;
440 errBr2Sum += deltaFinBr * deltaFinBr;
441 errMatch2Sum += sigmaFin*relAccErr*sigmaFin*relAccErr;
444 double ntotal_all = (nTried_pos+nTried_neg);
445 double event_eff_all = ntotal_all>1
e-6? (double)(nAccepted_pos+nAccepted_neg)/ntotal_all: -1;
446 double event_eff_err_all = ntotal_all>1
e-6?
std::sqrt((1-event_eff_all)*event_eff_all/ntotal_all): -1;
449 << std::scientific << std::setprecision(3)
450 << sigSelSum <<
" +/- " <<
std::sqrt(errSel2Sum) <<
"\t\t"
452 << nAccepted_pos <<
"\t"
453 << nAccepted_neg <<
"\t"
455 << nTried_pos <<
"\t"
456 << nTried_neg <<
"\t"
457 << std::scientific << std::setprecision(3)
458 << sigBrSum <<
" +/- "
460 << std::fixed << std::setprecision(1)
461 << (sigSum / sigSelSum * 100) <<
" +/- " << (std::sqrt(errMatch2Sum)/sigSelSum * 100) <<
"\t"
462 << std::fixed << std::setprecision(1)
463 << (event_eff_all * 100) <<
" +/- " << (event_eff_err_all * 100)
496 const char *
end = len >= 0 ? (data + len) : 0;
497 while(*data && (!end || data < end)) {
498 std::size_t len = std::strcspn(data,
"\r\n");
499 if (end && data + len > end)
501 if (data[len] ==
'\r' && data[len + 1] ==
'\n')
512 std::vector<std::string>
result;
513 DOMImplementation *impl =
514 DOMImplementationRegistry::getDOMImplementation(
516 std::auto_ptr<DOMWriter> writer(
517 static_cast<DOMImplementationLS*>(impl)->createDOMWriter());
522 const char *
p = std::strchr((
const char*)buffer,
'>') + 1;
523 const char *
q = std::strrchr(p,
'<');
532 for(std::vector<Header>::const_iterator
iter =
headers.begin();
535 return std::vector<std::string>(
iter->begin(),
537 if (
iter->tag() ==
"header")
542 return std::vector<std::string>();
544 const DOMNode *
root = header->getXMLNode();
546 return std::vector<std::string>();
548 for(
const DOMNode *
iter = root->getFirstChild();
550 if (
iter->getNodeType() != DOMNode::ELEMENT_NODE)
556 return std::vector<std::string>();
563 header(header),
mode(kHeader),
572 tmp =
"<" + header->tag() +
">";
576 if (
iter != header->end())
578 tmp =
"</" + header->tag() +
">";
595 const LHERunInfo::Header *header;
602 const DOMNode *LHERunInfo::Header::getXMLNode()
const
609 parser.setValidationScheme(XercesDOMParser::Val_Auto);
610 parser.setDoNamespaces(
false);
611 parser.setDoSchema(
false);
612 parser.setValidationSchemaFullChecking(
false);
614 HandlerBase errHandler;
615 parser.setErrorHandler(&errHandler);
616 parser.setCreateEntityReferenceNodes(
false);
619 std::auto_ptr<CBInputStream::Reader>
reader(
620 new HeaderReader(
this));
623 xmlDoc = parser.adoptDocument();
624 }
catch(
const XMLException &
e) {
626 <<
"XML parser reported DOM error no. "
627 << (
unsigned long)e.getCode()
630 }
catch(
const SAXException &e) {
632 <<
"XML parser reported: "
638 return xmlDoc->getDocumentElement();
643 int pdfA = -1, pdfB = -1;
653 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
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)
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
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)
string root
initialization