Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ConfigParser.cxx
Go to the documentation of this file.
1// @(#)root/roostats:$Id: cranmer $
2// Author: Kyle Cranmer, Akira Shibata
3/*************************************************************************
4 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11////////////////////////////////////////////////////////////////////////////////
12/** \class RooStats::HistFactory::ConfigParser
13 * \ingroup HistFactory
14 * TODO Add documentation.
15*/
16
17#include "TDOMParser.h"
18
22
23#include "RooFitImplHelpers.h"
24
25#include "HFMsgService.h"
26
27#include <TXMLAttr.h>
28#include <TXMLNode.h>
29
30
31#include <sstream>
32
33using namespace RooStats;
34using namespace HistFactory;
35
36using std::string, std::vector;
37
38namespace {
39
40 void AddSubStrings( vector<std::string> & vs, std::string s){
41 const std::string delims("\\ ");
42 std::string::size_type begIdx;
43 std::string::size_type endIdx;
44 begIdx=s.find_first_not_of(delims);
45 while(begIdx!=string::npos){
46 endIdx=s.find_first_of(delims, begIdx);
47 if(endIdx==string::npos) endIdx=s.length();
48 vs.push_back(s.substr(begIdx,endIdx-begIdx));
49 begIdx=s.find_first_not_of(delims, endIdx);
50 }
51 }
52
53 // Turn a std::string of "children" (space separated items)
54 // into a vector of std::strings
55 std::vector<std::string> GetChildrenFromString( std::string str ) {
56
57 std::vector<std::string> child_vec;
58
59 const std::string delims("\\ ");
60 std::string::size_type begIdx;
61 std::string::size_type endIdx;
62 begIdx=str.find_first_not_of(delims);
63 while(begIdx!=string::npos){
64 endIdx=str.find_first_of(delims, begIdx);
65 if(endIdx==string::npos) endIdx=str.length();
66 std::string child_name = str.substr(begIdx,endIdx-begIdx);
67 child_vec.push_back(child_name);
68 begIdx=str.find_first_not_of(delims, endIdx);
69 }
70
71 return child_vec;
72 }
73
74 // Turn a std::string of "children" (space separated items)
75 // into a vector of std::strings
76 void AddParamsToAsimov( RooStats::HistFactory::Asimov& asimov, std::string str ) {
77
78 // First, split the string into a list
79 // each describing a parameter
80 std::vector<std::string> string_list = GetChildrenFromString( str );
81
82 // Next, go through each one and split based
83 // on the '=' to separate the name from the val
84
85 for( unsigned int i=0; i < string_list.size(); ++i) {
86
87 std::string param = string_list.at(i);
88 // Split the string
89 size_t eql_location = param.find('=');
90
91 // If there is no '=' deliminator, we only
92 // set the variable constant
93 if( eql_location==string::npos ) {
94 asimov.SetFixedParam(param);
95 }
96 else {
97
98 std::string param_name = param.substr(0,eql_location);
99 double param_val = toDouble(param.substr(eql_location + 1, param.size()));
100
101 std::cout << "ASIMOV - Param Name: " << param_name
102 << " Param Val: " << param_val << std::endl;
103 // Give the params a value AND set them constant
104 asimov.SetParamValue(param_name, param_val);
105 asimov.SetFixedParam(param_name);
106 }
107
108 }
109
110 return;
111
112 }
113}
114
115std::vector< RooStats::HistFactory::Measurement > ConfigParser::GetMeasurementsFromXML( string input ) {
116
117 // Open an input "Driver" XML file (input),
118 // Parse that file and its channel files
119 // and return a vector filled with
120 // the listed measurements
121
122
123 // Create the list of measurements
124 // (This is what will be returned)
125 std::vector< HistFactory::Measurement > measurement_list;
126
127 // Open the Driver XML File
128 TDOMParser xmlparser;
129 Int_t parseError = xmlparser.ParseFile( input.c_str() );
130 if( parseError ) {
131 std::cerr << "Loading of xml document \"" << input
132 << "\" failed" << std::endl;
133 throw hf_exc();
134 }
135
136
137 // Read the Driver XML File
138 cxcoutIHF << "reading input : " << input << std::endl;
139 TXMLDocument* xmldoc = xmlparser.GetXMLDocument();
140 TXMLNode* rootNode = xmldoc->GetRootNode();
141
142
143 // Check that it is the proper DOCTYPE
144 if( rootNode->GetNodeName() != TString( "Combination" ) ){
145 cxcoutEHF << "Error: Driver DOCTYPE not equal to 'Combination'" << std::endl;
146 throw hf_exc();
147 }
148
149 // Loop over the Combination's attributes
150 std::string OutputFilePrefix;
151
152 TListIter attribIt = rootNode->GetAttributes();
153 TXMLAttr* curAttr = nullptr;
154 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
155
156 // Get the Name of this node
157 TString attrName = curAttr->GetName();
158
159 if( attrName == TString( "" ) ) {
160 cxcoutEHF << " Error: Attribute for 'Combination' with no name found" << std::endl;
161 throw hf_exc();
162 }
163
164 else if( attrName == TString( "OutputFilePrefix" ) ) {
165 OutputFilePrefix = string(curAttr->GetValue());
166 cxcoutIHF << "output file prefix is : " << OutputFilePrefix << std::endl;
167 }
168
169 /*
170 else if( attrName == TString( "InputFile" ) ) {
171 channel.InputFile = attrVal ;
172 }
173 */
174
175 else {
176 cxcoutEHF << " Error: Unknown attribute for 'Combination' encountered: "
177 << attrName << std::endl;
178 throw hf_exc();
179 }
180
181 // node = node->GetNextNode();
182
183 }
184
185 TXMLNode* node = nullptr;
186
187 // Get the list of channel XML files to combine
188 // Do this first so we can quickly exit
189 // if no channels are found
190 std::vector< std::string > xml_channel_files;
191 node = rootNode->GetChildren();
192 while( node != nullptr ) {
193 if( node->GetNodeName() == TString( "Input" ) ) {
194 if( node->GetText() == nullptr ) {
195 cxcoutEHF << "Error: node: " << node->GetName()
196 << " has no text." << std::endl;
197 throw hf_exc();
198 }
199 xml_channel_files.push_back(node->GetText());
200 }
201 node = node->GetNextNode();
202 }
203
204 // If no channel xml files are found, exit
205 if(xml_channel_files.empty()){
206 std::cerr << "no input channels found" << std::endl;
207 throw hf_exc();
208 //return measurement_list;
209 }
210 else {
211 std::ostringstream msg;
212 msg << "Found Channels: ";
213 for( unsigned int i=0; i < xml_channel_files.size(); ++i ) msg << " " << xml_channel_files.at(i);
214 cxcoutIHF << msg.str();
215 }
216
217 // Get the list of functions
218 // These apply to all measurements, so we
219 // first create the list of preprocess functions
220 // (before we create the list of measurements)
221 // and then we add them to all measurements
222
223 // For now, we create this list twice
224 // simply for compatibility
225 // std::vector< std::string > preprocessFunctions;
226 std::vector< RooStats::HistFactory::PreprocessFunction > functionObjects;
227
228 node = rootNode->GetChildren();
229 while( node != nullptr ) {
230 if( node->GetNodeName() == TString( "Function" ) ) {
231
232 // For now, add both the objects itself and
233 // it's command string (for easy compatibility)
235 // preprocessFunctions.push_back( Func.GetCommand() );
236 functionObjects.push_back( Func );
237 }
238 node = node->GetNextNode();
239 }
240
241 std::cout << std::endl;
242
243
244 // Fill the list of measurements
245 node = rootNode->GetChildren();
246 while( node != nullptr ) {
247
248 if( node->GetNodeName() == TString( "" ) ) {
249 cxcoutEHF << "Error: Node found in Measurement Driver XML with no name" << std::endl;
250 throw hf_exc();
251 }
252
253 else if( node->GetNodeName() == TString( "Measurement" ) ) {
255 // Set the prefix (obtained above)
256 measurement.SetOutputFilePrefix( OutputFilePrefix );
257 measurement_list.push_back( measurement );
258 }
259
260 else if( node->GetNodeName() == TString( "Function" ) ) {
261 // Already processed these (directly above)
262 ;
263 }
264
265 else if( node->GetNodeName() == TString( "Input" ) ) {
266 // Already processed these (directly above)
267 ;
268 }
269
270 else if( IsAcceptableNode( node ) ) { ; }
271
272 else {
273 cxcoutEHF << "Error: Unknown node found in Measurement Driver XML: "
274 << node->GetNodeName() << std::endl;
275 throw hf_exc();
276 }
277
278 node = node->GetNextNode();
279 }
280
281 cxcoutIHF << "Done Processing Measurements" << std::endl;
282
283 if( measurement_list.empty() ) {
284 cxcoutEHF << "Error: No Measurements found in XML Driver File" << std::endl;
285 throw hf_exc();
286 }
287 else {
288 std::ostringstream msg;
289 msg << "Found Measurements: ";
290 for( unsigned int i=0; i < measurement_list.size(); ++i ) msg << " " << measurement_list.at(i).GetName();
291 msg << std::endl;
292 cxcoutIHF << msg.str();
293 }
294
295 // Add the preprocessed functions to each measurement
296 // for( unsigned int i = 0; i < measurement_list.size(); ++i) {
297 // measurement_list.at(i).SetPreprocessFunctions( preprocessFunctions );
298 // }
299 // Add the preprocessed functions to each measurement
300 for( unsigned int i = 0; i < measurement_list.size(); ++i) {
301 measurement_list.at(i).SetFunctionObjects( functionObjects );
302 }
303
304 // Create an instance of the class
305 // that collects histograms
306 //HistCollector collector;
307
308 // Create the list of channels
309 // (Each of these will be added
310 // to every measurement)
311 std::vector< HistFactory::Channel > channel_list;
312
313 // Fill the list of channels
314 for( unsigned int i = 0; i < xml_channel_files.size(); ++i ) {
315 std::string channel_xml = xml_channel_files.at(i);
316 cxcoutIHF << "Parsing Channel: " << channel_xml << std::endl;
317 HistFactory::Channel channel = ParseChannelXMLFile( channel_xml );
318
319 // Get the histograms for the channel
320 //collector.CollectHistograms( channel );
321 //channel.CollectHistograms();
322 channel_list.push_back( channel );
323 }
324
325 // Finally, add the channels to the measurements:
326 for( unsigned int i = 0; i < measurement_list.size(); ++i) {
327
328 HistFactory::Measurement& measurement = measurement_list.at(i);
329
330 for( unsigned int j = 0; j < channel_list.size(); ++j ) {
331 measurement.GetChannels().push_back( channel_list.at(j) );
332 }
333 }
334
335 return measurement_list;
336}
337
338
340{
341 // construct and return at bottom
342 HistFactory::Measurement measurement;
343
344 // safety for public functions
345 if (node == nullptr) {
346 cxcoutWHF << "Input driver node is undefined, ignoring\n";
347 return measurement;
348 }
349
350 // Set the default values:
351 measurement.SetLumi(1.0);
352 measurement.SetLumiRelErr(.10);
353 measurement.SetBinLow(0);
354 measurement.SetBinHigh(1);
355
356 cxcoutIHF << "Creating new measurement:\n";
357
358 // First, get the attributes of the node
359 TListIter attribIt = node->GetAttributes();
360 TXMLAttr *curAttr = nullptr;
361 while ((/**/ curAttr = dynamic_cast<TXMLAttr *>(attribIt()) /**/) != nullptr) {
362 // curAttr is guaranteed non-null above
363 const std::string curAttrName(curAttr->GetName() ? curAttr->GetName() : "");
364 const std::string curAttrValue(curAttr->GetValue() ? curAttr->GetValue() : "");
365 if (curAttrName.empty()) {
366 cxcoutEHF << "Found XML attribute in Measurement with no name.\n";
367 // ADD Output Here
368 throw hf_exc();
369 } else if (curAttrName == "Name") {
370 measurement.SetName(curAttrValue.c_str());
371 } else if (curAttrName == "Lumi") {
372 measurement.SetLumi(toDouble(curAttrValue));
373 } else if (curAttrName == "LumiRelErr") {
374 measurement.SetLumiRelErr(toDouble(curAttrValue));
375 } else if (curAttrName == "BinLow") {
376 measurement.SetBinLow(std::stoi(curAttrValue));
377 } else if (curAttrName == "BinHigh") {
378 measurement.SetBinHigh(std::stoi(curAttrValue));
379 } else if (curAttrName == "Mode") {
380 std::cout << "\n INFO: Mode attribute is deprecated and no longer supported, will ignore\n";
381 } else if (curAttrName == "ExportOnly") {
382 // ignored
383 cxcoutIHF << "The \"ExportOnly\" attribute is ignored it is always \"true\" for any Measurement." << std::endl;
384 } else {
385 cxcoutEHF << "Found unknown XML attribute in Measurement: " << curAttrName << "\n";
386 throw hf_exc();
387 }
388 } // End Loop over attributes
389
390 // Then, get the properties of the children nodes
391 TXMLNode *child = node->GetChildren();
392 while (child != nullptr) {
393 const std::string childName(child->GetName() ? child->GetName() : "");
394 const std::string childNodeName(child->GetNodeName() ? child->GetNodeName() : "");
395 const std::string childText(child->GetText() ? child->GetText() : "");
396 if (childNodeName.empty()) {
397 cxcoutEHF << "Found XML child node of Measurement with no name\n";
398 throw hf_exc();
399 } else if (childNodeName == "POI") {
400 if (childText.empty()) {
401 cxcoutEHF << "Error: node: " << childName << " has no text.\n";
402 throw hf_exc();
403 }
404 // poi // measurement.SetPOI(childText);
405 AddSubStrings(measurement.GetPOIList(), childText);
406 } else if (childNodeName == "ParamSetting") {
407 TListIter paramIt = child->GetAttributes();
408 TXMLAttr *curParam = nullptr;
409 while ((/**/ curParam = dynamic_cast<TXMLAttr *>(paramIt()) /**/) != nullptr) {
410 // curParam is guaranteed non-null above
411 const std::string curParamName(curParam->GetName() ? curParam->GetName() : "");
412 if (curParamName.empty()) {
413 cxcoutEHF << "Error: Found tag attribute with no name in ParamSetting\n";
414 throw hf_exc();
415 } else if (curParamName == "Const") {
416 if (curParam->GetValue() == TString("True")) {
417 // Fix here...?
418 if (childText.empty()) {
419 cxcoutEHF << "Error: node: " << childName << " has no text.\n";
420 throw hf_exc();
421 }
422 AddSubStrings(measurement.GetConstantParams(), childText);
423 }
424 } else if (curParamName == "Val") {
425 double val = toDouble(curParam->GetValue());
426 if (childText.empty()) {
427 cxcoutEHF << "Error: node: " << childName << " has no text.\n";
428 throw hf_exc();
429 }
430 std::vector<std::string> child_nodes = GetChildrenFromString(childText);
431 for (size_t i = 0; i < child_nodes.size(); ++i) {
432 measurement.SetParamValue(child_nodes.at(i), val);
433 }
434 } else {
435 cxcoutEHF << "Found tag attribute with unknown name in ParamSetting: " << curParamName << "\n";
436 throw hf_exc();
437 }
438 }
439 } else if (childNodeName == "Asimov") {
440 // Now, create and configure an asimov object
441 // and add it to the measurement
443 std::string ParamFixString;
444
445 // Loop over attributes
446 attribIt = child->GetAttributes();
447 curAttr = nullptr;
448 while ((/**/ curAttr = dynamic_cast<TXMLAttr *>(attribIt()) /**/) != nullptr) {
449 const std::string curAttrName(curAttr->GetName() ? curAttr->GetName() : "");
450 const std::string curAttrValue(curAttr->GetValue() ? curAttr->GetValue() : "");
451 if (curAttrName.empty()) {
452 cxcoutEHF << "Error: Found tag attribute with no name in ConstraintTerm\n";
453 throw hf_exc();
454 } else if (curAttrName == "Name") {
455 asimov.SetName(curAttrValue);
456 } else if (curAttrName == "FixParams") {
457 ParamFixString = curAttrValue;
458 } else {
459 cxcoutEHF << "Found tag attribute with unknown name in ConstraintTerm: " << curAttrName << "\n";
460 throw hf_exc();
461 }
462 }
463
464 // Add any parameters to the asimov dataset
465 // to be fixed during the fitting and dataset generation
466 if (ParamFixString.empty()) {
467 cxcoutWHF << "Warning: Asimov Dataset with name: " << asimov.GetName()
468 << " added, but no parameters are set to be fixed\n";
469 } else {
470 AddParamsToAsimov(asimov, ParamFixString);
471 }
472 measurement.AddAsimovDataset(asimov);
473 } else if (childNodeName == "ConstraintTerm") {
474 std::vector<string> syst;
475 std::string type;
476 double rel = 0;
477
478 // Get the list of parameters in this tag:
479 if (childText.empty()) {
480 cxcoutEHF << "Error: node: " << childName << " has no text\n";
481 throw hf_exc();
482 }
483 AddSubStrings(syst, childText);
484
485 // Now, loop over this tag's attributes
486 attribIt = child->GetAttributes();
487 curAttr = nullptr;
488 while ((/**/ curAttr = dynamic_cast<TXMLAttr *>(attribIt()) /**/) != nullptr) {
489 const std::string curAttrName(curAttr->GetName() ? curAttr->GetName() : "");
490 const std::string curAttrValue(curAttr->GetValue() ? curAttr->GetValue() : "");
491 if (curAttrName.empty()) {
492 cxcoutEHF << "Error: Found tag attribute with no name in ConstraintTerm\n";
493 throw hf_exc();
494 } else if (curAttrName == "Type") {
495 type = curAttrValue;
496 } else if (curAttrName == "RelativeUncertainty") {
497 rel = toDouble(curAttrValue);
498 } else {
499 cxcoutEHF << "Found tag attribute with unknown name in ConstraintTerm: " << curAttrName << "\n";
500 throw hf_exc();
501 }
502 } // End Loop over tag attributes
503
504 // Now, fill the maps, depending on the type:
505 if (rel != 0) {
506 if (type == "Gamma") {
507 for (const auto &isyst : syst) {
508 // Fix Here...?
509 measurement.GetGammaSyst()[isyst] = rel;
510 }
511 } else if (type == "Uniform") {
512 for (const auto &isyst : syst) {
513 // Fix Here...?
514 measurement.GetUniformSyst()[isyst] = rel;
515 }
516 } else if (type == "LogNormal") {
517 for (const auto &isyst : syst) {
518 // Fix Here...?
519 measurement.GetLogNormSyst()[isyst] = rel;
520 }
521 }
522 } else if (type == "NoConstraint") {
523 for (const auto &isyst : syst) {
524 // Fix Here...?
525 measurement.GetNoSyst()[isyst] = 1.0; // MB : dummy value
526 }
527 } else {
528 // only Gamma, Uniform, LogNormal and NoConstraint are valid types
529 cxcoutEHF << "Error: Encountered unknown type for ConstraintTerm: " << type << "\n";
530 throw hf_exc();
531 }
532 // End adding of Constraint terms
533 } else if (IsAcceptableNode(child)) {
534 /* do nothing */
535 } else {
536 cxcoutEHF << "Found XML child of Measurement with unknown name: " << childNodeName << "\n";
537 throw hf_exc();
538 }
539 child = child->GetNextNode();
540 }
541
542 measurement.PrintTree(oocoutI(nullptr, HistFactory));
543
544 return measurement;
545}
546
548
549 /*
550 TString lumiStr;
551 lumiStr+=lumi;
552 lumiStr.ReplaceAll(' ', TString());
553 */
554
555 cxcoutIHF << "Parsing file: " << filen << std::endl;
556
557 TDOMParser xmlparser;
558
559 // reading in the file and parse by DOM
560 Int_t parseError = xmlparser.ParseFile( filen.c_str() );
561 if( parseError ) {
562 cxcoutEHF << "Loading of xml document \"" << filen
563 << "\" failed" << std::endl;
564 throw hf_exc();
565 }
566
567 TXMLDocument* xmldoc = xmlparser.GetXMLDocument();
568 TXMLNode* rootNode = xmldoc->GetRootNode();
569
570 // Check that is is a CHANNEL based on the DOCTYPE
571
572 if( rootNode->GetNodeName() != TString( "Channel" ) ){
573 cxcoutEHF << "Error: In parsing a Channel XML, "
574 << "Encountered XML with DOCTYPE: " << rootNode->GetNodeName()
575 << std::endl;
576 cxcoutEHF << " DOCTYPE for channels must be 'Channel' "
577 << " Check that your XML is properly written" << std::endl;
578 throw hf_exc();
579 }
580
581 // Now, create the channel,
582 // configure it based on the XML
583 // and return it
584
585 HistFactory::Channel channel;
586
587 // Set the default values:
588 channel.SetInputFile( "" );
589 channel.SetHistoPath( "" );
590
591 // Walk through the root node and
592 // get its attributes
593 TListIter attribIt = rootNode->GetAttributes();
594 TXMLAttr* curAttr = nullptr;
595 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
596
597 // Get the Name, Val of this node
598 TString attrName = curAttr->GetName();
599 std::string attrVal = curAttr->GetValue();
600
601 if( attrName == TString( "" ) ) {
602 cxcoutEHF << " Error: Attribute for 'Channel' with no name found" << std::endl;
603 throw hf_exc();
604 }
605
606 else if( attrName == TString( "Name" ) ) {
607 channel.SetName( attrVal );
608 cxcoutIHF << " : creating a channel named " << channel.GetName() << std::endl;
609 }
610
611 else if( attrName == TString( "InputFile" ) ) {
612 cxcoutIHF << "Setting InputFile for this channel: " << attrVal << std::endl;
613 channel.SetInputFile( attrVal );
614 // Set the current (cached) value
615 m_currentInputFile = attrVal;
616 }
617
618 else if( curAttr->GetName() == TString( "HistoPath" ) ) {
619 cxcoutIHF << "Setting HistoPath for this channel: " << attrVal << std::endl;
620 // Set the current (cached) value
621 channel.SetHistoPath( attrVal );
622 m_currentHistoPath = attrVal;
623 }
624
625 else if( curAttr->GetName() == TString( "HistoName" ) ) {
626 // Changed This:
627 cxcoutEHF << "Use of HistoName in Channel is deprecated" << std::endl;
628 cxcoutEHF << "This will be ignored" << std::endl;
629 }
630
631 else {
632 cxcoutEHF << " Error: Unknown attribute for 'Channel' encountered: "
633 << attrName << std::endl;
634 throw hf_exc();
635 }
636
637 } // End loop over the channel tag's attributes
638
639 // Check that the channel was properly initiated:
640
641 if( channel.GetName().empty() ) {
642 cxcoutEHF << "Error: Channel created with no name" << std::endl;
643 throw hf_exc();
644 }
645
646 m_currentChannel = channel.GetName();
647
648 // Loop over the children nodes in the XML file
649 // and configure the channel based on them
650
651 TXMLNode* node = rootNode->GetChildren();
652
653 bool firstData=true;
654
655 while( node != nullptr ) {
656
657 // Restore the Channel-Wide Defaults
660
661 if( node->GetNodeName() == TString( "" ) ) {
662 cxcoutEHF << "Error: Encountered node in Channel with no name" << std::endl;
663 throw hf_exc();
664 }
665
666 else if( node->GetNodeName() == TString( "Data" ) ) {
667 if( firstData ) {
669 if( !data.GetName().empty() ) {
670 cxcoutEHF << "Error: You can only rename the datasets of additional data sets. "
671 << " Remove the 'Name=" << data.GetName() << "' tag"
672 << " from channel: " << channel.GetName() << std::endl;
673 throw hf_exc();
674 }
675 channel.SetData( data );
676 firstData=false;
677 }
678 else {
679 channel.AddAdditionalData( CreateDataElement(node) );
680 }
681 }
682
683 else if( node->GetNodeName() == TString( "StatErrorConfig" ) ) {
685 }
686
687 else if( node->GetNodeName() == TString( "Sample" ) ) {
688 channel.GetSamples().push_back( CreateSampleElement(node) );
689 }
690
691 else if( IsAcceptableNode( node ) ) { ; }
692
693 else {
694 cxcoutEHF << "Error: Encountered node in Channel with unknown name: " << node->GetNodeName() << std::endl;
695 throw hf_exc();
696 }
697
698 node = node->GetNextNode();
699
700 } // End loop over tags in this channel
701
702 cxcoutIHF << "Created Channel: " << std::endl;
703 channel.Print(oocoutI(nullptr, HistFactory));
704
705 return channel;
706
707}
708
709
710
712
713 cxcoutIHF << "Creating Data Element" << std::endl;
714
716
717 // Set the default values
718 data.SetInputFile( m_currentInputFile );
719 data.SetHistoPath( m_currentHistoPath );
720 //data.HistoName = m_currentHistoName;
721
722 // Now, set the attributes
723 TListIter attribIt = node->GetAttributes();
724 TXMLAttr* curAttr = nullptr;
725 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
726
727 // Get the Name, Val of this node
728 TString attrName = curAttr->GetName();
729 std::string attrVal = curAttr->GetValue();
730
731 if( attrName == TString( "" ) ) {
732 cxcoutEHF << " Error: Attribute for 'Data' with no name found" << std::endl;
733 throw hf_exc();
734 }
735
736 else if( attrName == TString( "Name" ) ) {
737 data.SetName( attrVal );
738 }
739
740 else if( attrName == TString( "InputFile" ) ) {
741 data.SetInputFile( attrVal );
742 }
743
744 else if( attrName == TString( "HistoName" ) ) {
745 data.SetHistoName( attrVal );
746 }
747
748 else if( attrName == TString( "HistoPath" ) ) {
749 data.SetHistoPath( attrVal );
750 }
751
752 else if( IsAcceptableNode( node ) ) { ; }
753
754 else {
755 cxcoutEHF << " Error: Unknown attribute for 'Data' encountered: " << attrName << std::endl;
756 throw hf_exc();
757 }
758
759 }
760
761 // Check the properties of the data node:
762 if( data.GetInputFile().empty() ) {
763 cxcoutEHF << "Error: Data Node has no InputFile" << std::endl;
764 throw hf_exc();
765 }
766 if( data.GetHistoName().empty() ) {
767 cxcoutEHF << "Error: Data Node has no HistoName" << std::endl;
768 throw hf_exc();
769 }
770
771 cxcoutIHF << "Created Data Node with"
772 << " InputFile: " << data.GetInputFile()
773 << " HistoName: " << data.GetHistoName()
774 << " HistoPath: " << data.GetHistoPath()
775 << (!data.GetName().empty() ? " Name: " : "") << data.GetName() << std::endl;
776
777 // data.hist = GetHisto(data.FileName, data.HistoPath, data.HistoName);
778
779 return data;
780}
781
782
783
785
786 cxcoutIHF << "Creating StatErrorConfig Element" << std::endl;
787
789
790 // Setup default values:
792 config.SetRelErrorThreshold( 0.05 ); // 5%
793
794 // Loop over the node's attributes
795 TListIter attribIt = node->GetAttributes();
796 TXMLAttr* curAttr = nullptr;
797 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
798
799 // Get the Name, Val of this node
800 TString attrName = curAttr->GetName();
801 std::string attrVal = curAttr->GetValue();
802
803 if( attrName == TString( "RelErrorThreshold" ) ) {
804 config.SetRelErrorThreshold(toDouble(attrVal));
805 }
806
807 if( attrName == TString( "ConstraintType" ) ) {
808 // Allowable Values: Gaussian
809
810 if( attrVal.empty() ) {
811 cxcoutEHF << "Error: Bad Value for StatErrorConfig Constraint Type Found" << std::endl;
812 throw hf_exc();
813 }
814
815 else if( attrVal=="Gaussian" || attrVal=="Gauss" ) {
817 }
818
819 else if( attrVal=="Poisson" || attrVal=="Pois" ) {
821 }
822
823 else if( IsAcceptableNode( node ) ) { ; }
824
825 else {
826 std::cout << "Invalid Stat Constraint Type: " << curAttr->GetValue() << std::endl;
827 throw hf_exc();
828 }
829 }
830 } // End: Loop Over Attributes
831
832 cxcoutIHF << "Created StatErrorConfig Element with"
833 << " Constraint type: " << config.GetConstraintType()
834 << " RelError Threshold: " << config.GetRelErrorThreshold()
835 << std::endl;
836
837 return config;
838
839}
840
841
843
844 cxcoutIHF << "Creating Sample Element" << std::endl;
845
846 HistFactory::Sample sample;
847
848 // Set the default values
850 sample.SetHistoPath( m_currentHistoPath );
851 sample.SetChannelName( m_currentChannel );
852 sample.SetNormalizeByTheory( true );
853 //sample.HistoName = m_currentHistoName;
854
855 // Now, set the attributes
856
857 TListIter attribIt = node->GetAttributes();
858 TXMLAttr* curAttr = nullptr;
859 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
860
861 // Get the Name, Val of this node
862 TString attrName = curAttr->GetName();
863 std::string attrVal = curAttr->GetValue();
864
865 if( attrName == TString( "" ) ) {
866 cxcoutEHF << " Error: Attribute for 'Sample' with no name found" << std::endl;
867 throw hf_exc();
868 }
869
870 else if( attrName == TString( "Name" ) ) {
871 sample.SetName( attrVal );
872 }
873
874 else if( attrName == TString( "InputFile" ) ) {
875 sample.SetInputFile( attrVal );
876 m_currentInputFile = attrVal;
877 }
878
879 else if( attrName == TString( "HistoName" ) ) {
880 sample.SetHistoName( attrVal );
881 }
882
883 else if( attrName == TString( "HistoPath" ) ) {
884 sample.SetHistoPath( attrVal );
885 m_currentHistoPath = attrVal;
886 }
887
888 else if( attrName == TString( "NormalizeByTheory" ) ) {
889 sample.SetNormalizeByTheory( CheckTrueFalse(attrVal,"Sample") );
890 /*
891 if( attrVal == "" ) {
892 cxcoutEHF << "Error: Attribute 'NormalizeByTheory' in Sample has no value" << std::endl;
893 throw hf_exc();
894 }
895 else if ( attrVal == "True" || attrVal == "true" ) sample.NormalizeByTheory = true;
896 else if ( attrVal == "False" || attrVal == "false" ) sample.NormalizeByTheory = false;
897 else {
898 cxcoutEHF << "Error: Attribute 'NormalizeByTheory' in Sample has unknown value: " << attrVal << std::endl;
899 std::cout << "Value must be 'True' or 'False' " << std::endl;
900 throw hf_exc();
901 }
902 */
903 }
904
905 else {
906 cxcoutEHF << " Error: Unknown attribute for 'Sample' encountered: " << attrName << std::endl;
907 throw hf_exc();
908 }
909 }
910
911 // Quickly check the properties of the Sample Node
912 if( sample.GetName().empty() ) {
913 cxcoutEHF << "Error: Sample Node has no Name" << std::endl;
914 throw hf_exc();
915 }
916 if( sample.GetInputFile().empty() ) {
917 cxcoutEHF << "Error: Sample Node has no InputFile" << std::endl;
918 throw hf_exc();
919 }
920 if( sample.GetHistoName().empty() ) {
921 cxcoutEHF << "Error: Sample Node has no HistoName" << std::endl;
922 throw hf_exc();
923 }
924
925
926 // Now, loop over the children and add the systematics
927
928 TXMLNode* child = node->GetChildren();
929
930 while( child != nullptr ) {
931
932 if( child->GetNodeName() == TString( "" ) ) {
933 cxcoutEHF << "Error: Encountered node in Sample with no name" << std::endl;
934 throw hf_exc();
935 }
936
937 else if( child->GetNodeName() == TString( "NormFactor" ) ) {
938 sample.GetNormFactorList().push_back( MakeNormFactor( child ) );
939 }
940
941 else if( child->GetNodeName() == TString( "OverallSys" ) ) {
942 sample.GetOverallSysList().push_back( MakeOverallSys( child ) );
943 }
944
945 else if( child->GetNodeName() == TString( "HistoSys" ) ) {
946 sample.GetHistoSysList().push_back( MakeHistoSys( child ) );
947 }
948
949 else if( child->GetNodeName() == TString( "HistoFactor" ) ) {
950 cxcoutEHF << "WARNING: HistoFactor not yet supported" << std::endl;
951 //sample.GetHistoFactorList().push_back( MakeHistoFactor( child ) );
952 }
953
954 else if( child->GetNodeName() == TString( "ShapeSys" ) ) {
955 sample.GetShapeSysList().push_back( MakeShapeSys( child ) );
956 }
957
958 else if( child->GetNodeName() == TString( "ShapeFactor" ) ) {
959 sample.GetShapeFactorList().push_back( MakeShapeFactor( child ) );
960 }
961
962 else if( child->GetNodeName() == TString( "StatError" ) ) {
963 sample.SetStatError( ActivateStatError(child) );
964 }
965
966 else if( IsAcceptableNode( child ) ) { ; }
967
968 else {
969 cxcoutEHF << "Error: Encountered node in Sample with unknown name: " << child->GetNodeName() << std::endl;
970 throw hf_exc();
971 }
972
973 child=child->GetNextNode();
974 }
975
976 cxcoutIHF << "Created Sample Node with"
977 << " Name: " << sample.GetName()
978 << " InputFile: " << sample.GetInputFile()
979 << " HistoName: " << sample.GetHistoName()
980 << " HistoPath: " << sample.GetHistoPath()
981 << std::endl;
982
983 // sample.hist = GetHisto(sample.FileName, sample.HistoPath, sample.HistoName);
984
985 return sample;
986}
987
988
990
991 cxcoutIHF << "Making NormFactor:" << std::endl;
992
994
995 TListIter attribIt = node->GetAttributes();
996 TXMLAttr* curAttr = nullptr;
997 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
998
999 // Get the Name, Val of this node
1000 TString attrName = curAttr->GetName();
1001 std::string attrVal = curAttr->GetValue();
1002
1003 if( attrName == TString( "" ) ){
1004 cxcoutEHF << "Error: Encountered Element in NormFactor with no name" << std::endl;
1005 throw hf_exc();
1006 }
1007
1008 else if( curAttr->GetName() == TString( "Name" ) ) {
1009 norm.SetName( attrVal );
1010 }
1011 else if( curAttr->GetName() == TString( "Val" ) ) {
1012 norm.SetVal(toDouble(attrVal));
1013 }
1014 else if( curAttr->GetName() == TString( "Low" ) ) {
1015 norm.SetLow(toDouble(attrVal));
1016 }
1017 else if( curAttr->GetName() == TString( "High" ) ) {
1018 norm.SetHigh(toDouble(attrVal));
1019 }
1020
1021 else {
1022 cxcoutEHF << "Error: Encountered Element in NormFactor with unknown name: "
1023 << attrName << std::endl;
1024 throw hf_exc();
1025 }
1026
1027 } // End loop over properties
1028
1029 if( norm.GetName().empty() ) {
1030 cxcoutEHF << "Error: NormFactor Node has no Name" << std::endl;
1031 throw hf_exc();
1032 }
1033
1034 if( norm.GetLow() >= norm.GetHigh() ) {
1035 cxcoutEHF << "Error: NormFactor: " << norm.GetName()
1036 << " has lower limit >= its upper limit: "
1037 << " Lower: " << norm.GetLow()
1038 << " Upper: " << norm.GetHigh()
1039 << ". Please Fix" << std::endl;
1040 throw hf_exc();
1041 }
1042 if( norm.GetVal() > norm.GetHigh() || norm.GetVal() < norm.GetLow() ) {
1043 cxcoutEHF << "Error: NormFactor: " << norm.GetName()
1044 << " has initial value not within its range: "
1045 << " Val: " << norm.GetVal()
1046 << " Lower: " << norm.GetLow()
1047 << " Upper: " << norm.GetHigh()
1048 << ". Please Fix" << std::endl;
1049 throw hf_exc();
1050 }
1051
1052 norm.Print(oocoutI(nullptr, HistFactory));
1053
1054 return norm;
1055
1056}
1057
1059
1060 cxcoutIHF << "Making HistoFactor" << std::endl;
1061
1063
1066
1069
1070 cxcoutIHF << "Made HistoFactor" << std::endl;
1071
1072 return dummy;
1073
1074}
1075
1076
1078
1079 cxcoutIHF << "Making HistoSys:" << std::endl;
1080
1081 HistFactory::HistoSys histoSys;
1082
1083 // Set Default values
1085 histoSys.SetHistoPathLow( m_currentHistoPath );
1086
1087 histoSys.SetInputFileHigh( m_currentInputFile );
1088 histoSys.SetHistoPathHigh( m_currentHistoPath );
1089
1090 TListIter attribIt = node->GetAttributes();
1091 TXMLAttr* curAttr = nullptr;
1092 /*
1093 string Name, histoPathHigh, histoPathLow,
1094 histoNameLow, histoNameHigh, inputFileHigh, inputFileLow;
1095 inputFileLow=inputFileName; inputFileHigh=inputFileName;
1096 histoPathLow=histoPathName; histoPathHigh=histoPathName;
1097 histoNameLow=histoName; histoNameHigh=histoName;
1098 */
1099
1100 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
1101
1102 // Get the Name, Val of this node
1103 TString attrName = curAttr->GetName();
1104 std::string attrVal = curAttr->GetValue();
1105
1106 if( attrName == TString( "" ) ){
1107 cxcoutEHF << "Error: Encountered Element in HistoSys with no name" << std::endl;
1108 throw hf_exc();
1109 }
1110
1111 else if( curAttr->GetName() == TString( "Name" ) ) {
1112 histoSys.SetName( attrVal );
1113 }
1114
1115 else if( curAttr->GetName() == TString( "HistoFileHigh" ) ) {
1116 histoSys.SetInputFileHigh( attrVal );
1117 }
1118 else if( curAttr->GetName() == TString( "HistoPathHigh" ) ) {
1119 histoSys.SetHistoPathHigh( attrVal );
1120 }
1121 else if( curAttr->GetName() == TString( "HistoNameHigh" ) ) {
1122 histoSys.SetHistoNameHigh( attrVal );
1123 }
1124
1125 else if( curAttr->GetName() == TString( "HistoFileLow" ) ) {
1126 histoSys.SetInputFileLow( attrVal );
1127 }
1128 else if( curAttr->GetName() == TString( "HistoPathLow" ) ) {
1129 histoSys.SetHistoPathLow( attrVal );
1130 }
1131 else if( curAttr->GetName() == TString( "HistoNameLow" ) ) {
1132 histoSys.SetHistoNameLow( attrVal );
1133 }
1134
1135 else {
1136 cxcoutEHF << "Error: Encountered Element in HistoSys with unknown name: "
1137 << attrName << std::endl;
1138 throw hf_exc();
1139 }
1140
1141 } // End loop over properties
1142
1143
1144 if( histoSys.GetName().empty() ) {
1145 cxcoutEHF << "Error: HistoSys Node has no Name" << std::endl;
1146 throw hf_exc();
1147 }
1148 if( histoSys.GetInputFileHigh().empty() ) {
1149 cxcoutEHF << "Error: HistoSysSample Node has no InputFileHigh" << std::endl;
1150 throw hf_exc();
1151 }
1152 if( histoSys.GetInputFileLow().empty() ) {
1153 cxcoutEHF << "Error: HistoSysSample Node has no InputFileLow" << std::endl;
1154 throw hf_exc();
1155 }
1156 if( histoSys.GetHistoNameHigh().empty() ) {
1157 cxcoutEHF << "Error: HistoSysSample Node has no HistoNameHigh" << std::endl;
1158 throw hf_exc();
1159 }
1160 if( histoSys.GetHistoNameLow().empty() ) {
1161 cxcoutEHF << "Error: HistoSysSample Node has no HistoNameLow" << std::endl;
1162 throw hf_exc();
1163 }
1164
1165
1166 histoSys.Print(oocoutI(nullptr, HistFactory));
1167
1168 return histoSys;
1169
1170}
1171
1172
1174
1175 cxcoutIHF << "Making OverallSys:" << std::endl;
1176
1177 HistFactory::OverallSys overallSys;
1178
1179 TListIter attribIt = node->GetAttributes();
1180 TXMLAttr* curAttr = nullptr;
1181 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
1182
1183 // Get the Name, Val of this node
1184 TString attrName = curAttr->GetName();
1185 std::string attrVal = curAttr->GetValue();
1186
1187 if( attrName == TString( "" ) ){
1188 cxcoutEHF << "Error: Encountered Element in OverallSys with no name" << std::endl;
1189 throw hf_exc();
1190 }
1191
1192 else if( attrName == TString( "Name" ) ) {
1193 overallSys.SetName( attrVal );
1194 }
1195 else if( attrName == TString( "High" ) ) {
1196 overallSys.SetHigh(toDouble(attrVal));
1197 }
1198 else if( attrName == TString( "Low" ) ) {
1199 overallSys.SetLow(toDouble(attrVal));
1200 }
1201
1202 else {
1203 cxcoutEHF << "Error: Encountered Element in OverallSys with unknown name: "
1204 << attrName << std::endl;
1205 throw hf_exc();
1206 }
1207
1208 }
1209
1210 if( overallSys.GetName().empty() ) {
1211 cxcoutEHF << "Error: Encountered OverallSys with no name" << std::endl;
1212 throw hf_exc();
1213 }
1214
1215
1216 overallSys.Print(oocoutI(nullptr, HistFactory));
1217
1218 return overallSys;
1219
1220}
1221
1222
1224
1225 cxcoutIHF << "Making ShapeFactor" << std::endl;
1226
1227 HistFactory::ShapeFactor shapeFactor;
1228
1229 TListIter attribIt = node->GetAttributes();
1230 TXMLAttr* curAttr = nullptr;
1231
1232 // A Shape Factor may or may not include an initial shape
1233 // This will be set by strings pointing to a histogram
1234 // If we don't see a 'HistoName' attribute, we assume
1235 // that an initial shape is not being set
1236 std::string ShapeInputFile = m_currentInputFile;
1237 std::string ShapeInputPath = m_currentHistoPath;
1238
1239 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
1240
1241 // Get the Name, Val of this node
1242 TString attrName = curAttr->GetName();
1243 std::string attrVal = curAttr->GetValue();
1244
1245 if( attrName == TString( "" ) ){
1246 cxcoutEHF << "Error: Encountered Element in ShapeFactor with no name" << std::endl;
1247 throw hf_exc();
1248 }
1249
1250 else if( attrName == TString( "Name" ) ) {
1251 shapeFactor.SetName( attrVal );
1252 } else if (attrName == TString("Val")) {
1253 shapeFactor.SetVal(toDouble(attrVal));
1254 } else if (attrName == TString("Low")) {
1255 shapeFactor.SetLow(toDouble(attrVal));
1256 } else if (attrName == TString("High")) {
1257 shapeFactor.SetHigh(toDouble(attrVal));
1258 } else if (attrName == TString("Const")) {
1259 shapeFactor.SetConstant(CheckTrueFalse(attrVal, "ShapeFactor"));
1260 }
1261
1262 else if (attrName == TString("HistoName")) {
1263 shapeFactor.SetHistoName(attrVal);
1264 }
1265
1266 else if (attrName == TString("InputFile")) {
1267 ShapeInputFile = attrVal;
1268 }
1269
1270 else if (attrName == TString("HistoPath")) {
1271 ShapeInputPath = attrVal;
1272 }
1273
1274 else {
1275 cxcoutEHF << "Error: Encountered Element in ShapeFactor with unknown name: " << attrName << std::endl;
1276 throw hf_exc();
1277 }
1278 }
1279
1280 if( shapeFactor.GetName().empty() ) {
1281 cxcoutEHF << "Error: Encountered ShapeFactor with no name" << std::endl;
1282 throw hf_exc();
1283 }
1284
1285 // Set the Histogram name, path, and file
1286 // if an InitialHist is set
1287 if( shapeFactor.HasInitialShape() ) {
1288 if( shapeFactor.GetHistoName().empty() ) {
1289 cxcoutEHF << "Error: ShapeFactor: " << shapeFactor.GetName()
1290 << " is configured to have an initial shape, but "
1291 << "its histogram doesn't have a name"
1292 << std::endl;
1293 throw hf_exc();
1294 }
1295 shapeFactor.SetHistoPath( ShapeInputPath );
1296 shapeFactor.SetInputFile( ShapeInputFile );
1297 }
1298
1299 shapeFactor.Print(oocoutI(nullptr, HistFactory));
1300
1301 return shapeFactor;
1302
1303}
1304
1305
1307
1308 cxcoutIHF << "Making ShapeSys" << std::endl;
1309
1310 HistFactory::ShapeSys shapeSys;
1311
1312 // Set the default values
1314 shapeSys.SetInputFile( m_currentInputFile );
1315 shapeSys.SetHistoPath( m_currentHistoPath );
1316
1317
1318 TListIter attribIt = node->GetAttributes();
1319 TXMLAttr* curAttr = nullptr;
1320 //EstimateSummary::ConstraintType ConstraintType = EstimateSummary::Gaussian; //"Gaussian";
1321
1322 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
1323
1324
1325 // Get the Name, Val of this node
1326 TString attrName = curAttr->GetName();
1327 std::string attrVal = curAttr->GetValue();
1328
1329 if( attrName == TString( "" ) ){
1330 cxcoutEHF << "Error: Encountered Element in ShapeSys with no name" << std::endl;
1331 throw hf_exc();
1332 }
1333
1334 else if( attrName == TString( "Name" ) ) {
1335 shapeSys.SetName( attrVal );
1336 }
1337
1338 else if( attrName == TString( "HistoName" ) ) {
1339 shapeSys.SetHistoName( attrVal );
1340 }
1341
1342 else if( attrName == TString( "HistoPath" ) ) {
1343 shapeSys.SetHistoPath( attrVal );
1344 }
1345
1346 else if( attrName == TString( "InputFile" ) ) {
1347 shapeSys.SetInputFile( attrVal );
1348 }
1349
1350 else if( attrName == TString( "ConstraintType" ) ) {
1351 if( attrVal.empty() ) {
1352 cxcoutEHF << "Error: ShapeSys Constraint type is empty" << std::endl;
1353 throw hf_exc();
1354 }
1355 else if( attrVal=="Gaussian" || attrVal=="Gauss" ) {
1356 shapeSys.SetConstraintType( Constraint::Gaussian );
1357 }
1358 else if( attrVal=="Poisson" || attrVal=="Pois" ) {
1359 shapeSys.SetConstraintType( Constraint::Poisson );
1360 }
1361 else {
1362 std::cout << "Error: Encountered unknown ShapeSys Constraint type: " << attrVal << std::endl;
1363 throw hf_exc();
1364 }
1365 }
1366
1367 else {
1368 cxcoutEHF << "Error: Encountered Element in ShapeSys with unknown name: "
1369 << attrName << std::endl;
1370 throw hf_exc();
1371 }
1372
1373 } // End loop over attributes
1374
1375
1376 if( shapeSys.GetName().empty() ) {
1377 cxcoutEHF << "Error: Encountered ShapeSys with no Name" << std::endl;
1378 throw hf_exc();
1379 }
1380 if( shapeSys.GetInputFile().empty() ) {
1381 cxcoutEHF << "Error: Encountered ShapeSys with no InputFile" << std::endl;
1382 throw hf_exc();
1383 }
1384 if( shapeSys.GetHistoName().empty() ) {
1385 cxcoutEHF << "Error: Encountered ShapeSys with no HistoName" << std::endl;
1386 throw hf_exc();
1387 }
1388
1389 shapeSys.Print(oocoutI(nullptr, HistFactory));
1390
1391 return shapeSys;
1392
1393}
1394
1395
1397
1398 cxcoutIHF << "Activating StatError" << std::endl;
1399
1400 // Set default values
1401 HistFactory::StatError statError;
1402 statError.Activate( false );
1403 statError.SetUseHisto( false );
1404 statError.SetHistoName( "" );
1405
1406 // Loop over the node's attributes
1407 TListIter attribIt = node->GetAttributes();
1408 TXMLAttr* curAttr = nullptr;
1409 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
1410
1411 // Get the Name, Val of this node
1412 TString attrName = curAttr->GetName();
1413 std::string attrVal = curAttr->GetValue();
1414
1415 if( attrName == TString( "" ) ){
1416 cxcoutEHF << "Error: Encountered Element in ActivateStatError with no name" << std::endl;
1417 throw hf_exc();
1418 }
1419
1420 else if( attrName == TString( "Activate" ) ) {
1421 statError.Activate( CheckTrueFalse(attrVal,"ActivateStatError") );
1422 }
1423
1424 else if( attrName == TString( "HistoName" ) ) {
1425 statError.SetHistoName( attrVal );
1426 }
1427
1428 else if( attrName == TString( "HistoPath" ) ) {
1429 statError.SetHistoPath( attrVal );
1430 }
1431
1432 else if( attrName == TString( "InputFile" ) ) {
1433 statError.SetInputFile( attrVal );
1434 }
1435
1436 else {
1437 cxcoutEHF << "Error: Encountered Element in ActivateStatError with unknown name: "
1438 << attrName << std::endl;
1439 throw hf_exc();
1440 }
1441
1442 } // End: Loop Over Attributes
1443
1444 // Based on the input, determine
1445 // if we should use a histogram or not:
1446 // Logic: One turns on using a histogram
1447 // by setting the attribute "HistoName"
1448 // If this is set AND the InputFile or
1449 // HistoPath aren't set, we set those
1450 // to the current default values
1451 if( !statError.GetHistoName().empty() ) {
1452 statError.SetUseHisto( true );
1453
1454 // Check that a file has been set
1455 // (Possibly using the default)
1456 if( statError.GetInputFile().empty() ) {
1457 statError.SetInputFile( m_currentInputFile );
1458 }
1459 if( statError.GetHistoPath().empty() ) {
1460 statError.SetHistoPath( m_currentHistoPath );
1461 }
1462
1463 }
1464
1465 /*
1466 if( statError.Activate ) {
1467 if( statError.UseHisto ) {
1468 }
1469 else {
1470 statError.InputFile = "";
1471 statError.HistoName = "";
1472 statError.HistoPath = "";
1473 }
1474 }
1475 */
1476
1477 statError.Print(oocoutI(nullptr, HistFactory));
1478
1479 return statError;
1480
1481}
1482
1483
1485
1486 cxcoutIHF << "Parsing FunctionConfig" << std::endl;
1487
1488 //std::string name, expression, dependents;
1489 TListIter attribIt = functionNode->GetAttributes();
1490 TXMLAttr* curAttr = nullptr;
1491
1492 std::string Name;
1493 std::string Expression;
1494 std::string Dependents;
1495
1496 // Add protection to ensure that all parts are there
1497 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
1498 if( curAttr->GetName() == TString( "Name" ) ) {
1499 Name = curAttr->GetValue();
1500 //func.SetName( curAttr->GetValue() );
1501 //name = curAttr->GetValue() ;
1502 }
1503 if( curAttr->GetName() == TString( "Expression" ) ) {
1504 Expression = curAttr->GetValue();
1505 //func.SetExpression( curAttr->GetValue() );
1506 }
1507 if( curAttr->GetName() == TString( "Dependents" ) ) {
1508 Dependents = curAttr->GetValue();
1509 //func.SetDependents( curAttr->GetValue() );
1510 }
1511 }
1512
1513 if( Name.empty() ){
1514 cxcoutEHF << "Error processing PreprocessFunction: Name attribute is empty" << std::endl;
1515 throw hf_exc();
1516 }
1517 if( Expression.empty() ){
1518 cxcoutEHF << "Error processing PreprocessFunction: Expression attribute is empty" << std::endl;
1519 throw hf_exc();
1520 }
1521 if( Dependents.empty() ){
1522 cxcoutEHF << "Error processing PreprocessFunction: Dependents attribute is empty" << std::endl;
1523 throw hf_exc();
1524 }
1525
1526 RooStats::HistFactory::PreprocessFunction func(Name, Expression, Dependents);
1527
1528 cxcoutIHF << "Created Preprocess Function: " << func.GetCommand() << std::endl;
1529
1530 //std::string command = "expr::"+func.GetName()+"('"+func.GetExpression()+"',{"+func.GetDependents()+"})";
1531 //func.SetCommand( command );
1532 // // std::cout << "will pre-process this line " << ret << std::endl;
1533 return func;
1534
1535}
1536
1537
1539
1540 if( node->GetNodeName() == TString( "text" ) ) {
1541 return true;
1542 }
1543
1544 if( node->GetNodeName() == TString( "comment" ) ) {
1545 return true;
1546 }
1547
1548 return false;
1549
1550}
1551
1552
1553bool ConfigParser::CheckTrueFalse( std::string attrVal, std::string NodeTitle ) {
1554
1555 if( attrVal.empty() ) {
1556 cxcoutEHF << "Error: In " << NodeTitle
1557 << " Expected either 'True' or 'False' but found empty" << std::endl;
1558 throw hf_exc();
1559 } else if (attrVal == "True" || attrVal == "true") {
1560 return true;
1561 } else if (attrVal == "False" || attrVal == "false") {
1562 return false;
1563 } else {
1564 cxcoutEHF << "Error: In " << NodeTitle << " Expected either 'True' or 'False' but found: " << attrVal << std::endl;
1565 throw hf_exc();
1566 }
1567
1568 return false;
1569
1570}
1571
1572//ConfigParser
#define cxcoutIHF
#define cxcoutWHF
#define cxcoutEHF
double toDouble(const char *s)
#define oocoutI(o, a)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t child
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
TODO Here, we are missing some documentation.
void SetName(const std::string &name)
void SetParamValue(const std::string &param, double value)
void SetFixedParam(const std::string &param, bool constant=true)
This class encapsulates all information for the statistical interpretation of one experiment.
void SetName(const std::string &Name)
set name of channel
void Print(std::ostream &=std::cout)
void AddAdditionalData(const RooStats::HistFactory::Data &data)
add additional data object
std::string GetInputFile() const
get name of input file
std::string GetHistoPath() const
get path to histograms in input file
void SetData(const RooStats::HistFactory::Data &data)
set data object
void SetInputFile(const std::string &file)
set name of input file containing histograms
void SetStatErrorConfig(double RelErrorThreshold, Constraint::Type ConstraintType)
std::vector< RooStats::HistFactory::Sample > & GetSamples()
get vector of samples for this channel
void SetHistoPath(const std::string &file)
set path for histograms in input file
std::string GetName() const
get name of channel
bool CheckTrueFalse(std::string val, std::string NodeTitle)
bool IsAcceptableNode(TXMLNode *functionNode)
std::vector< RooStats::HistFactory::Measurement > GetMeasurementsFromXML(std::string input)
The "main" method.
HistFactory::StatErrorConfig CreateStatErrorConfigElement(TXMLNode *node)
HistFactory::StatError ActivateStatError(TXMLNode *node)
HistFactory::OverallSys MakeOverallSys(TXMLNode *node)
HistFactory::Sample CreateSampleElement(TXMLNode *node)
HistFactory::HistoSys MakeHistoSys(TXMLNode *node)
std::string m_currentInputFile
To facilitate writing xml, when not specified, files and paths default to these cached values.
HistFactory::ShapeFactor MakeShapeFactor(TXMLNode *node)
RooStats::HistFactory::Measurement CreateMeasurementFromDriverNode(TXMLNode *node)
HistFactory::PreprocessFunction ParseFunctionConfig(TXMLNode *functionNode)
HistFactory::Data CreateDataElement(TXMLNode *node)
Helpers used to process a channel.
HistFactory::HistoFactor MakeHistoFactor(TXMLNode *node)
RooStats::HistFactory::Channel ParseChannelXMLFile(std::string filen)
HistFactory::ShapeSys MakeShapeSys(TXMLNode *node)
HistFactory::NormFactor MakeNormFactor(TXMLNode *node)
Helpers used when processing a Sample.
Configuration for an *un*constrained, coherent shape variation of affected samples.
Configuration for a constrained, coherent shape variation of affected samples.
void SetInputFileHigh(const std::string &InputFileHigh)
void SetHistoPathHigh(const std::string &HistoPathHigh)
void SetInputFileLow(const std::string &InputFileLow)
void SetHistoPathLow(const std::string &HistoPathLow)
The RooStats::HistFactory::Measurement class can be used to construct a model by combining multiple R...
void SetLumi(double Lumi)
set integrated luminosity used to normalise histograms (if NormalizeByTheory is true for this sample)
std::vector< RooStats::HistFactory::Channel > & GetChannels()
Configuration for an un- constrained overall systematic to scale sample normalisations.
Definition Measurement.h:60
Configuration for a constrained overall systematic to scale sample normalisations.
Definition Measurement.h:36
void SetInputFile(const std::string &InputFile)
set input ROOT file
*Un*constrained bin-by-bin variation of affected histogram.
Constrained bin-by-bin variation of affected histogram.
void SetConstraintType(Constraint::Type ConstrType)
Configuration to automatically assign nuisance parameters for the statistical error of the Monte Carl...
void SetConstraintType(Constraint::Type ConstrType)
void SetRelErrorThreshold(double Threshold)
Constraint::Type GetConstraintType() const
Statistical error of Monte Carlo predictions.
const std::string & GetHistoPath() const
void Activate(bool IsActive=true)
void SetHistoPath(const std::string &HistoPath)
void SetInputFile(const std::string &InputFile)
const std::string & GetInputFile() const
void SetHistoName(const std::string &HistoName)
const std::string & GetHistoName() const
void SetUseHisto(bool UseHisto=true)
void Print(std::ostream &=std::cout) const override
Iterator of linked list.
Definition TList.h:196
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:461
Basic string class.
Definition TString.h:137
TXMLAttribute is the attribute of an Element.
Definition TXMLAttr.h:18
TXMLDocument contains a pointer to an xmlDoc structure, after the parser returns a tree built during ...
TXMLNode contains a pointer to xmlNode, which is a node under the DOM tree.
Definition TXMLNode.h:20
TList * GetAttributes()
Returns a list of node's attribute if any, returns 0 if no attribute.
Definition TXMLNode.cxx:107
const char * GetText() const
Returns the content of a Text node if node is a TextNode, 0 otherwise.
Definition TXMLNode.cxx:153
TXMLNode * GetNextNode()
Returns the next sibling XMLNode in the DOM tree, if any return 0 if no next node.
Definition TXMLNode.cxx:129
TXMLNode * GetChildren()
Returns the node's child if any, returns 0 if no child.
Definition TXMLNode.cxx:73
const char * GetNodeName() const
Returns the node's name.
Definition TXMLNode.cxx:65
Namespace for the RooStats classes.
Definition CodegenImpl.h:67