10 #include "TXMLEngine.h"
11 #include "TObjString.h"
12 #include "TDOMParser.h"
14 #include "TXMLDocument.h"
22 T stringToNum(
const std::string&
i) {
24 std::istringstream(
i ) >> ret;
33 m_mcModifiedCrossSection(0.)
44 ATH_MSG_FATAL(
"For MC rates, a cross section and filter efficiency must be supplied.");
45 return StatusCode::FAILURE;
56 ATH_MSG_FATAL(
"calculateWeightingData is TRUE, but the RunNumber property has not been set. This must be set such that we can read in the correct data.");
57 return StatusCode::FAILURE;
59 ATH_MSG_INFO (
"calculateWeightingData is TRUE. This job will read in EnhancedBias weighting data from CVMFS and COOL.");
66 return StatusCode::SUCCESS;
72 return StatusCode::SUCCESS;
85 if (weightingFile ==
"") {
90 std::unique_ptr<TXMLEngine>
xml(
new TXMLEngine() );
91 XMLDocPointer_t xmlDoc =
xml->ParseFile( weightingFile.c_str() );
93 if (xmlDoc ==
nullptr) {
95 return StatusCode::FAILURE;
99 const XMLNodePointer_t mainNode =
xml->DocGetRootElement(xmlDoc);
100 if (
xml->GetNodeName(mainNode) != std::string(
"run") ) {
101 ATH_MSG_ERROR (
"Canot parse XML. Expected 'run' node, got " <<
xml->GetNodeName(mainNode));
102 return StatusCode::FAILURE;
104 const XMLNodePointer_t weightsNode =
xml->GetChild( mainNode );
105 const XMLNodePointer_t eventsNode =
xml->GetNext( weightsNode );
107 XMLNodePointer_t weightNode =
xml->GetChild( weightsNode );
108 XMLNodePointer_t eventNode =
xml->GetChild( eventsNode );
110 while ( weightNode != 0 ) {
111 if (
xml->GetNodeName(weightNode) != std::string(
"weight") ) {
112 ATH_MSG_ERROR (
"Canot parse XML. Expected 'weight' node, got " <<
xml->GetNodeName(weightNode));
113 return StatusCode::FAILURE;
116 const int32_t
id =
std::atoi(
xml->GetAttr(weightNode,
"id") );
118 int32_t unbiased = 0;
119 if (
xml->HasAttr(weightNode,
"unbiased") ==
true ) {
120 unbiased =
std::atoi(
xml->GetAttr(weightNode,
"unbiased"));
126 weightNode =
xml->GetNext(weightNode);
129 while ( eventNode != 0 ) {
130 if (
xml->GetNodeName(eventNode) != std::string(
"e") ) {
131 ATH_MSG_ERROR (
"Canot parse XML. Expected 'e' (event) node, got " <<
xml->GetNodeName(eventNode));
132 return StatusCode::FAILURE;
135 const int32_t eventWeightID = std::stoi(
xml->GetAttr(eventNode,
"w") );
139 eventNode =
xml->GetNext(eventNode);
143 return StatusCode::SUCCESS;
151 ATH_MSG_FATAL(
"Unable to load this runs luminosity values from COOL.");
152 return StatusCode::FAILURE;
167 std::unique_ptr<TXMLEngine>
xml(
new TXMLEngine());
168 const XMLDocPointer_t xmlDoc =
xml->ParseFile( runFile.c_str() );
170 if (xmlDoc ==
nullptr) {
172 return StatusCode::FAILURE;
175 const XMLNodePointer_t mainNode =
xml->DocGetRootElement(xmlDoc);
176 if (
xml->GetNodeName(mainNode) != std::string(
"trigger") ) {
177 ATH_MSG_ERROR (
"Canot parse XML. Expected 'trigger' node, got " <<
xml->GetNodeName(mainNode));
178 return StatusCode::FAILURE;
180 XMLNodePointer_t listNode =
xml->GetChild( mainNode );
182 while ( listNode != 0 ) {
183 const std::string listName =
xml->GetNodeName(listNode);
185 if (listName ==
"lb_list") {
187 XMLNodePointer_t
node =
xml->GetChild( listNode );
189 if (
xml->GetNodeName(
node) != std::string(
"lb") ) {
191 return StatusCode::FAILURE;
196 const std::string
flag =
xml->HasAttr(
node,
"flag") ?
xml->GetAttr(
node,
"flag") :
"";
202 if (
xml->HasAttr(
node,
"deadtime")) {
210 }
else if (listName ==
"lumivalues") {
212 XMLNodePointer_t
node =
xml->GetChild( listNode );
214 if (
xml->GetNodeName(
node) == std::string(
"deadtime") ) {
220 }
else if (listName ==
"bunchgroups") {
222 XMLNodePointer_t
node =
xml->GetChild( listNode );
225 if (
xml->GetNodeName(
node) == std::string(
"bunchgroup") &&
xml->HasAttr(
node,
"name") &&
226 (std::string(
xml->GetAttr(
node,
"name")) ==
"Paired" || std::string(
xml->GetAttr(
node,
"name")) ==
"Filled")) {
232 }
else if (listName ==
"filters") {
234 ATH_MSG_DEBUG(
"Found filters section of enhanced bias XML. Unused by this application.");
238 ATH_MSG_INFO(
"Encountered unknown element in enhanced bias XML: " << listName <<
" ignoring it.");
242 listNode =
xml->GetNext(listNode);
246 return StatusCode::SUCCESS;
250 std::unordered_map<std::string, ChainDetail>
result;
254 ATH_MSG_ERROR (
"Could not retrieve " << prescaleXML <<
", place it somewhere PathResolver can find it (such as the current directory).");
258 std::unique_ptr<TXMLEngine>
xml(
new TXMLEngine());
259 const XMLDocPointer_t xmlDoc =
xml->ParseFile( xmlFile.c_str() );
261 if (xmlDoc ==
nullptr) {
262 ATH_MSG_WARNING (
"Could not parse " << prescaleXML <<
", please check that it is valid XML.");
267 XMLNodePointer_t mainNode =
xml->DocGetRootElement(xmlDoc);
268 if (
xml->GetNodeName(mainNode) != std::string(
"trigger") ) {
269 ATH_MSG_ERROR (
"Canot parse XML. Expected 'trigger' node, got " <<
xml->GetNodeName(mainNode));
272 XMLNodePointer_t listNode =
xml->GetChild( mainNode );
275 while ( listNode !=
nullptr) {
276 const std::string listName =
xml->GetNodeName(listNode);
281 if (listName !=
"level") {
282 listNode =
xml->GetNext(listNode);
286 XMLNodePointer_t sigNode =
xml->GetChild( listNode );
287 while( sigNode !=
nullptr) {
288 if (
xml->GetNodeName(sigNode) != std::string(
"signature")) {
289 sigNode =
xml->GetNext(sigNode);
293 XMLNodePointer_t sigDetailsNode =
xml->GetChild( sigNode );
295 while( sigDetailsNode !=
nullptr) {
297 if (
xml->GetNodeContent(sigDetailsNode) ==
nullptr) {
298 sigDetailsNode =
xml->GetNext(sigDetailsNode);
302 const std::string
detail =
xml->GetNodeName(sigDetailsNode);
303 if (
detail ==
"sig_name") {
306 }
else if (
detail ==
"sig_counter") {
308 }
else if (
detail ==
"prescale" ||
detail ==
"chain_prescale") {
310 }
else if (
detail ==
"lower_chain_name") {
312 std::string lower =
xml->GetNodeContent(sigDetailsNode);
313 while (lower.find(
" ") != std::string::npos) lower.replace( lower.find(
" "), 1,
"");
315 }
else if (
detail ==
"evts_passed") {
317 }
else if (
detail ==
"evts_passed_weighted") {
318 result[
chainName].m_eventsPassedWeighted = std::stod(
xml->GetNodeContent(sigDetailsNode) );
319 }
else if (
detail ==
"rate") {
321 }
else if (
detail ==
"rate_err") {
323 }
else if (
detail ==
"passthrough") {
324 result[
chainName].m_passthroughPrescale = std::stod(
xml->GetNodeContent(sigDetailsNode) );
325 }
else if (
detail ==
"rerun_prescale") {
327 }
else if (
detail ==
"express_prescale") {
328 result[
chainName].m_expressPrescale = std::stod(
xml->GetNodeContent(sigDetailsNode) );
329 }
else if (
detail ==
"efficiency") {
331 }
else if (
detail ==
"efficiency_err") {
333 }
else if (
detail ==
"prescaled_efficiency") {
334 result[
chainName].m_prescaledEfficiency = std::stod(
xml->GetNodeContent(sigDetailsNode) );
335 }
else if (
detail ==
"prescaled_efficiency_error") {
336 result[
chainName].m_prescaledEfficiencyErr = std::stod(
xml->GetNodeContent(sigDetailsNode) );
337 }
else if (
detail ==
"comment") {
340 ATH_MSG_DEBUG(
"Input prescales XML contains additional data which cannot be parsed at present:" <<
detail);
343 sigDetailsNode =
xml->GetNext(sigDetailsNode);
345 sigNode =
xml->GetNext(sigNode);
347 listNode =
xml->GetNext(listNode);
359 return mapIterator->second;
362 const int32_t eventNumber32 =
static_cast<int32_t
>(
eventNumber);
365 return mapIterator32->second;
378 return mapIterator->second;
381 const int32_t eventNumber32 =
static_cast<int32_t
>(
eventNumber);
384 return mapIterator32->second;
419 ATH_MSG_ERROR(
"Couldn't find enhanced bias weight for event with ID " << ebID);
422 return mapIterator->second;
439 ATH_MSG_ERROR(
"Cannot use EventContext based getEBWeight with MC. Needs full EventInfo.");
447 ATH_MSG_ERROR(
"Couldn't find enhanced bias weight for event with ID " << ebID);
450 return mapIterator->second;
459 return StatusCode::SUCCESS;
467 return StatusCode::SUCCESS;
483 ATH_MSG_DEBUG(
"MC livetime debug: probOfProcess:" << probOfProcess <<
" probOfBunchCrossing:" << probOfBunchCrossing <<
" bunchCrossingRate:" << bunchCrossingRate <<
" time:" << (1. / (probOfBunchCrossing * bunchCrossingRate)));
484 return 1. / (probOfBunchCrossing * bunchCrossingRate);
489 std::lock_guard<std::mutex> scopeLock(
m_mutex);
492 const auto inCacheIterator = m_eventLivetime.find(
lumiBlock );
493 if (inCacheIterator != m_eventLivetime.end())
return inCacheIterator->second;
503 const int32_t eventsInThisLB = mapIterator->second;
506 double eventLivetime = 0;
507 if (eventsInThisLB > 0 && fabs(lbLength) > 1
e-10) eventLivetime = (1. /
static_cast<double>(eventsInThisLB)) * lbLength;
509 m_eventLivetime[
lumiBlock] = eventLivetime;
510 return eventLivetime;
519 ATH_MSG_ERROR(
"Cannot use EventContext based getEBLiveTime with MC. Needs full EventInfo.");
525 std::lock_guard<std::mutex> scopeLock(
m_mutex);
528 const auto inCacheIterator = m_eventLivetime.find(
lumiBlock );
529 if (inCacheIterator != m_eventLivetime.end())
return inCacheIterator->second;
539 const int32_t eventsInThisLB = mapIterator->second;
542 double eventLivetime = 0;
543 if (eventsInThisLB > 0 && fabs(lbLength) > 1
e-10) eventLivetime = (1. /
static_cast<double>(eventsInThisLB)) * lbLength;
545 m_eventLivetime[
lumiBlock] = eventLivetime;
546 return eventLivetime;
588 ATH_MSG_ERROR(
"Couldn't find isUnbiased information for event with ID " << ebID);
591 return mapIterator->second;
607 if (mapIterator ==
m_goodLB.end() ) {
611 return static_cast<bool>(mapIterator->second);
627 if (mapIterator ==
m_goodLB.end() ) {
631 return static_cast<bool>(mapIterator->second);
659 return mapIterator->second;
668 ATH_MSG_ERROR(
"Cannot use EventContext based getLBLumi with MC. Needs full EventInfo.");
679 return mapIterator->second;
704 const EventContext& context = Gaudi::Hive::currentContext();
709 return StatusCode::SUCCESS;
714 return m_lumiAverage.mean();
719 return m_muAverage.mean();
739 decoratorEBWeight(*eventInfo) =
getEBWeight(eventInfo);
741 decoratorLBLumi(*eventInfo) =
getLBLumi(eventInfo);
743 decoratorGoodLBFlag(*eventInfo) =
isGoodLB(eventInfo);
745 decoratorBCIDDistanceFromFront(*eventInfo) =
distance;
747 return StatusCode::SUCCESS;