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." << 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())
133 double brWeight,
double matchWeight)
135 std::vector<Process>::iterator
proc =
142 proc->acceptedBr.add(eventWeight * brWeight * matchWeight);
143 proc->accepted.add(eventWeight * matchWeight);
145 proc->killed.add(eventWeight * matchWeight);
147 proc->selected.add(eventWeight);
149 proc->tried.add(eventWeight);
155 double sigSelSum = 0.0;
157 double sigBrSum = 0.0;
158 double err2Sum = 0.0;
159 double errBr2Sum = 0.0;
161 for(std::vector<Process>::const_iterator
proc =
processes.begin();
163 unsigned int idx =
proc->heprupIndex;
165 double sigmaSum, sigma2Sum, sigma2Err,
xsec;
181 xsec =
proc->tried.sum /
proc->tried.n;
183 sigma2Sum =
proc->tried.sum2 * xsec *
xsec;
190 double sigmaAvg = sigmaSum /
proc->tried.sum;
191 double fracAcc =
proc->killed.sum /
proc->selected.sum;
192 double fracBr =
proc->accepted.sum > 0.0 ?
193 proc->acceptedBr.sum /
proc->accepted.sum : 1;
194 double sigmaFin = sigmaAvg * fracAcc * fracBr;
195 double sigmaFinBr = sigmaFin * fracBr;
198 if (
proc->killed.n > 1) {
199 double sigmaAvg2 = sigmaAvg * sigmaAvg;
201 (sigma2Sum /
proc->tried.n - sigmaAvg2) /
202 (
proc->tried.n * sigmaAvg2);
204 ((double)
proc->selected.n -
proc->killed.n) /
205 ((double)
proc->selected.n *
proc->killed.n);
206 double delta2Sum = delta2Sig + delta2Veto
207 + sigma2Err / sigma2Sum;
208 relErr = (delta2Sum > 0.0 ?
211 double deltaFin = sigmaFin * relErr;
212 double deltaFinBr = sigmaFinBr * relErr;
214 sigSelSum += sigmaAvg;
216 sigBrSum += sigmaFinBr;
217 err2Sum += deltaFin * deltaFin;
218 errBr2Sum += deltaFinBr * deltaFinBr;
222 result.
value = sigBrSum;
230 double sigSelSum = 0.0;
232 double sigBrSum = 0.0;
233 double err2Sum = 0.0;
234 double errBr2Sum = 0.0;
235 unsigned long nAccepted = 0;
236 unsigned long nTried = 0;
239 std::cout <<
"Process and cross-section statistics" << std::endl;
240 std::cout <<
"------------------------------------" << std::endl;
241 std::cout <<
"Process\tevents\ttried\txsec [pb]\t\taccepted [%]"
244 for(std::vector<Process>::const_iterator
proc =
processes.begin();
246 unsigned int idx =
proc->heprupIndex;
248 double sigmaSum, sigma2Sum, sigma2Err,
xsec;
264 xsec =
proc->tried.sum /
proc->tried.n;
266 sigma2Sum =
proc->tried.sum2 * xsec *
xsec;
270 if (!
proc->selected.n) {
276 double sigmaAvg = sigmaSum /
proc->tried.sum;
277 double fracAcc =
proc->killed.sum /
proc->selected.sum;
278 double fracBr =
proc->accepted.sum > 0.0 ?
279 proc->acceptedBr.sum /
proc->accepted.sum : 1;
280 double sigmaFin = sigmaAvg * fracAcc;
281 double sigmaFinBr = sigmaFin * fracBr;
284 if (
proc->killed.n > 1) {
285 double sigmaAvg2 = sigmaAvg * sigmaAvg;
287 (sigma2Sum /
proc->tried.n - sigmaAvg2) /
288 (
proc->tried.n * sigmaAvg2);
290 ((double)
proc->selected.n -
proc->killed.n) /
291 ((double)
proc->selected.n *
proc->killed.n);
292 double delta2Sum = delta2Sig + delta2Veto
293 + sigma2Err / sigma2Sum;
294 relErr = (delta2Sum > 0.0 ?
297 double deltaFin = sigmaFin * relErr;
298 double deltaFinBr = sigmaFinBr * relErr;
301 <<
proc->accepted.n <<
"\t"
302 <<
proc->tried.n <<
"\t"
303 << std::scientific << std::setprecision(3)
304 << sigmaFinBr <<
" +/- "
305 << deltaFinBr <<
"\t"
306 << std::fixed << std::setprecision(1)
307 << (fracAcc * 100) << std::endl;
309 nAccepted +=
proc->accepted.n;
310 nTried +=
proc->tried.n;
311 sigSelSum += sigmaAvg;
313 sigBrSum += sigmaFinBr;
314 err2Sum += deltaFin * deltaFin;
315 errBr2Sum += deltaFinBr * deltaFinBr;
321 << std::scientific << std::setprecision(3)
322 << sigBrSum <<
" +/- "
324 << std::fixed << std::setprecision(1)
325 << (sigSum / sigSelSum * 100) << std::endl;
357 const char *
end = len >= 0 ? (data + len) : 0;
358 while(*data && (!end || data < end)) {
359 std::size_t len = std::strcspn(data,
"\r\n");
360 if (end && data + len > end)
362 if (data[len] ==
'\r' && data[len + 1] ==
'\n')
373 std::vector<std::string>
result;
374 DOMImplementation *impl =
375 DOMImplementationRegistry::getDOMImplementation(
377 std::auto_ptr<DOMWriter> writer(
378 static_cast<DOMImplementationLS*>(impl)->createDOMWriter());
383 const char *
p = std::strchr((
const char*)buffer,
'>') + 1;
384 const char *
q = std::strrchr(p,
'<');
393 for(std::vector<Header>::const_iterator iter =
headers.begin();
394 iter !=
headers.end(); ++iter) {
395 if (iter->tag() ==
tag)
396 return std::vector<std::string>(iter->begin(),
398 if (iter->tag() ==
"header")
403 return std::vector<std::string>();
405 const DOMNode *
root = header->getXMLNode();
407 return std::vector<std::string>();
409 for(
const DOMNode *iter = root->getFirstChild();
410 iter; iter = iter->getNextSibling()) {
411 if (iter->getNodeType() != DOMNode::ELEMENT_NODE)
413 if (tag == (
const char*)
XMLSimpleStr(iter->getNodeName()))
417 return std::vector<std::string>();
424 header(header),
mode(kHeader),
425 iter(header->
begin())
433 tmp =
"<" + header->tag() +
">";
437 if (iter != header->end())
439 tmp =
"</" + header->tag() +
">";
456 const LHERunInfo::Header *header;
463 const DOMNode *LHERunInfo::Header::getXMLNode()
const
470 parser.setValidationScheme(XercesDOMParser::Val_Auto);
471 parser.setDoNamespaces(
false);
472 parser.setDoSchema(
false);
473 parser.setValidationSchemaFullChecking(
false);
475 HandlerBase errHandler;
476 parser.setErrorHandler(&errHandler);
477 parser.setCreateEntityReferenceNodes(
false);
480 std::auto_ptr<CBInputStream::Reader>
reader(
481 new HeaderReader(
this));
484 xmlDoc = parser.adoptDocument();
485 }
catch(
const XMLException &
e) {
487 <<
"XML parser reported DOM error no. "
488 << (
unsigned long)e.getCode()
491 }
catch(
const SAXException &e) {
493 <<
"XML parser reported: "
499 return xmlDoc->getDocumentElement();
504 int pdfA = -1, pdfB = -1;
514 return std::make_pair(pdfA, pdfB);
static XERCES_CPP_NAMESPACE_USE int skipWhitespace(std::istream &in)
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
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
comments_const_iterator comments_begin() const
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)
string root
initialization