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 "HFMsgService.h"
24
25#include <TXMLAttr.h>
26#include <TXMLNode.h>
27
28
29#include <sstream>
30
31using namespace RooStats;
32using namespace HistFactory;
33
34using std::string, std::cerr, std::cout, std::endl, std::vector;
35
36namespace {
37
38 void AddSubStrings( vector<std::string> & vs, std::string s){
39 const std::string delims("\\ ");
40 std::string::size_type begIdx;
41 std::string::size_type endIdx;
42 begIdx=s.find_first_not_of(delims);
43 while(begIdx!=string::npos){
44 endIdx=s.find_first_of(delims, begIdx);
45 if(endIdx==string::npos) endIdx=s.length();
46 vs.push_back(s.substr(begIdx,endIdx-begIdx));
47 begIdx=s.find_first_not_of(delims, endIdx);
48 }
49 }
50
51 // Turn a std::string of "children" (space separated items)
52 // into a vector of std::strings
53 std::vector<std::string> GetChildrenFromString( std::string str ) {
54
55 std::vector<std::string> child_vec;
56
57 const std::string delims("\\ ");
58 std::string::size_type begIdx;
59 std::string::size_type endIdx;
60 begIdx=str.find_first_not_of(delims);
61 while(begIdx!=string::npos){
62 endIdx=str.find_first_of(delims, begIdx);
63 if(endIdx==string::npos) endIdx=str.length();
64 std::string child_name = str.substr(begIdx,endIdx-begIdx);
65 child_vec.push_back(child_name);
66 begIdx=str.find_first_not_of(delims, endIdx);
67 }
68
69 return child_vec;
70 }
71
72 // Turn a std::string of "children" (space separated items)
73 // into a vector of std::strings
74 void AddParamsToAsimov( RooStats::HistFactory::Asimov& asimov, std::string str ) {
75
76 // First, split the string into a list
77 // each describing a parameter
78 std::vector<std::string> string_list = GetChildrenFromString( str );
79
80 // Next, go through each one and split based
81 // on the '=' to separate the name from the val
82 // and fill the map
83 std::map<std::string, double> param_map;
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 = atof( param.substr(eql_location+1, param.size()).c_str() );
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 << 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, Val of this node
157 TString attrName = curAttr->GetName();
158 std::string attrVal = curAttr->GetValue();
159
160 if( attrName == TString( "" ) ) {
161 cxcoutEHF << " Error: Attribute for 'Combination' with no name found" << std::endl;
162 throw hf_exc();
163 }
164
165 else if( attrName == TString( "OutputFilePrefix" ) ) {
166 OutputFilePrefix = string(curAttr->GetValue());
167 cxcoutIHF << "output file prefix is : " << OutputFilePrefix << endl;
168 }
169
170 /*
171 else if( attrName == TString( "InputFile" ) ) {
172 channel.InputFile = attrVal ;
173 }
174 */
175
176 else {
177 cxcoutEHF << " Error: Unknown attribute for 'Combination' encountered: "
178 << attrName << std::endl;
179 throw hf_exc();
180 }
181
182 // node = node->GetNextNode();
183
184 }
185
186 TXMLNode* node = nullptr;
187
188 // Get the list of channel XML files to combine
189 // Do this first so we can quickly exit
190 // if no channels are found
191 std::vector< std::string > xml_channel_files;
192 node = rootNode->GetChildren();
193 while( node != nullptr ) {
194 if( node->GetNodeName() == TString( "Input" ) ) {
195 if( node->GetText() == nullptr ) {
196 cxcoutEHF << "Error: node: " << node->GetName()
197 << " has no text." << std::endl;
198 throw hf_exc();
199 }
200 xml_channel_files.push_back(node->GetText());
201 }
202 node = node->GetNextNode();
203 }
204
205 // If no channel xml files are found, exit
206 if(xml_channel_files.empty()){
207 cerr << "no input channels found" << endl;
208 throw hf_exc();
209 //return measurement_list;
210 }
211 else {
212 std::ostringstream msg;
213 msg << "Found Channels: ";
214 for( unsigned int i=0; i < xml_channel_files.size(); ++i ) msg << " " << xml_channel_files.at(i);
215 cxcoutIHF << msg.str();
216 }
217
218 // Get the list of functions
219 // These apply to all measurements, so we
220 // first create the list of preprocess functions
221 // (before we create the list of measurements)
222 // and then we add them to all measurements
223
224 // For now, we create this list twice
225 // simply for compatibility
226 // std::vector< std::string > preprocessFunctions;
227 std::vector< RooStats::HistFactory::PreprocessFunction > functionObjects;
228
229 node = rootNode->GetChildren();
230 while( node != nullptr ) {
231 if( node->GetNodeName() == TString( "Function" ) ) {
232
233 // For now, add both the objects itself and
234 // it's command string (for easy compatibility)
236 // preprocessFunctions.push_back( Func.GetCommand() );
237 functionObjects.push_back( Func );
238 }
239 node = node->GetNextNode();
240 }
241
242 std::cout << std::endl;
243
244
245 // Fill the list of measurements
246 node = rootNode->GetChildren();
247 while( node != nullptr ) {
248
249 if( node->GetNodeName() == TString( "" ) ) {
250 cxcoutEHF << "Error: Node found in Measurement Driver XML with no name" << std::endl;
251 throw hf_exc();
252 }
253
254 else if( node->GetNodeName() == TString( "Measurement" ) ) {
256 // Set the prefix (obtained above)
257 measurement.SetOutputFilePrefix( OutputFilePrefix );
258 measurement_list.push_back( measurement );
259 }
260
261 else if( node->GetNodeName() == TString( "Function" ) ) {
262 // Already processed these (directly above)
263 ;
264 }
265
266 else if( node->GetNodeName() == TString( "Input" ) ) {
267 // Already processed these (directly above)
268 ;
269 }
270
271 else if( IsAcceptableNode( node ) ) { ; }
272
273 else {
274 cxcoutEHF << "Error: Unknown node found in Measurement Driver XML: "
275 << node->GetNodeName() << std::endl;
276 throw hf_exc();
277 }
278
279 node = node->GetNextNode();
280 }
281
282 cxcoutIHF << "Done Processing Measurements" << std::endl;
283
284 if( measurement_list.empty() ) {
285 cxcoutEHF << "Error: No Measurements found in XML Driver File" << std::endl;
286 throw hf_exc();
287 }
288 else {
289 std::ostringstream msg;
290 msg << "Found Measurements: ";
291 for( unsigned int i=0; i < measurement_list.size(); ++i ) msg << " " << measurement_list.at(i).GetName();
292 msg << std::endl;
293 cxcoutIHF << msg.str();
294 }
295
296 // Add the preprocessed functions to each measurement
297 // for( unsigned int i = 0; i < measurement_list.size(); ++i) {
298 // measurement_list.at(i).SetPreprocessFunctions( preprocessFunctions );
299 // }
300 // Add the preprocessed functions to each measurement
301 for( unsigned int i = 0; i < measurement_list.size(); ++i) {
302 measurement_list.at(i).SetFunctionObjects( functionObjects );
303 }
304
305 // Create an instance of the class
306 // that collects histograms
307 //HistCollector collector;
308
309 // Create the list of channels
310 // (Each of these will be added
311 // to every measurement)
312 std::vector< HistFactory::Channel > channel_list;
313
314 // Fill the list of channels
315 for( unsigned int i = 0; i < xml_channel_files.size(); ++i ) {
316 std::string channel_xml = xml_channel_files.at(i);
317 cxcoutIHF << "Parsing Channel: " << channel_xml << std::endl;
318 HistFactory::Channel channel = ParseChannelXMLFile( channel_xml );
319
320 // Get the histograms for the channel
321 //collector.CollectHistograms( channel );
322 //channel.CollectHistograms();
323 channel_list.push_back( channel );
324 }
325
326 // Finally, add the channels to the measurements:
327 for( unsigned int i = 0; i < measurement_list.size(); ++i) {
328
329 HistFactory::Measurement& measurement = measurement_list.at(i);
330
331 for( unsigned int j = 0; j < channel_list.size(); ++j ) {
332 measurement.GetChannels().push_back( channel_list.at(j) );
333 }
334 }
335
336 return measurement_list;
337}
338
339
341{
342 // construct and return at bottom
343 HistFactory::Measurement measurement;
344
345 // safety for public functions
346 if (node == nullptr) {
347 cxcoutWHF << "Input driver node is undefined, ignoring\n";
348 return measurement;
349 }
350
351 // Set the default values:
352 measurement.SetLumi(1.0);
353 measurement.SetLumiRelErr(.10);
354 measurement.SetBinLow(0);
355 measurement.SetBinHigh(1);
356
357 cxcoutIHF << "Creating new measurement:\n";
358
359 // First, get the attributes of the node
360 TListIter attribIt = node->GetAttributes();
361 TXMLAttr *curAttr = nullptr;
362 while ((/**/ curAttr = dynamic_cast<TXMLAttr *>(attribIt()) /**/) != nullptr) {
363 // curAttr is guaranteed non-null above
364 const std::string curAttrName(curAttr->GetName() ? curAttr->GetName() : "");
365 const std::string curAttrValue(curAttr->GetValue() ? curAttr->GetValue() : "");
366 if (curAttrName.empty()) {
367 cxcoutEHF << "Found XML attribute in Measurement with no name.\n";
368 // ADD Output Here
369 throw hf_exc();
370 } else if (curAttrName == "Name") {
371 measurement.SetName(curAttrValue.c_str());
372 } else if (curAttrName == "Lumi") {
373 measurement.SetLumi(std::stof(curAttrValue));
374 } else if (curAttrName == "LumiRelErr") {
375 measurement.SetLumiRelErr(std::stof(curAttrValue));
376 } else if (curAttrName == "BinLow") {
377 measurement.SetBinLow(std::stoi(curAttrValue));
378 } else if (curAttrName == "BinHigh") {
379 measurement.SetBinHigh(std::stoi(curAttrValue));
380 } else if (curAttrName == "Mode") {
381 cout << "\n INFO: Mode attribute is deprecated and no longer supported, will ignore\n";
382 } else if (curAttrName == "ExportOnly") {
383 measurement.SetExportOnly(CheckTrueFalse(curAttrValue, "Measurement"));
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 = atof(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 = std::stof(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( atof(attrVal.c_str()) );
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 cout << "Invalid Stat Constraint Type: " << curAttr->GetValue() << 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
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" ) ) {
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( atof(attrVal.c_str()) );
1013 }
1014 else if( curAttr->GetName() == TString( "Low" ) ) {
1015 norm.SetLow( atof(attrVal.c_str()) );
1016 }
1017 else if( curAttr->GetName() == TString( "High" ) ) {
1018 norm.SetHigh( atof(attrVal.c_str()) );
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
1086
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( atof(attrVal.c_str()) );
1197 }
1198 else if( attrName == TString( "Low" ) ) {
1199 overallSys.SetLow( atof(attrVal.c_str()) );
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 }
1253 else if( attrName == TString( "Const" ) ) {
1254 shapeFactor.SetConstant( CheckTrueFalse(attrVal, "ShapeFactor" ) );
1255 }
1256
1257 else if( attrName == TString( "HistoName" ) ) {
1258 shapeFactor.SetHistoName( attrVal );
1259 }
1260
1261 else if( attrName == TString( "InputFile" ) ) {
1262 ShapeInputFile = attrVal;
1263 }
1264
1265 else if( attrName == TString( "HistoPath" ) ) {
1266 ShapeInputPath = attrVal;
1267 }
1268
1269 else {
1270 cxcoutEHF << "Error: Encountered Element in ShapeFactor with unknown name: "
1271 << attrName << std::endl;
1272 throw hf_exc();
1273 }
1274
1275 }
1276
1277 if( shapeFactor.GetName().empty() ) {
1278 cxcoutEHF << "Error: Encountered ShapeFactor with no name" << std::endl;
1279 throw hf_exc();
1280 }
1281
1282 // Set the Histogram name, path, and file
1283 // if an InitialHist is set
1284 if( shapeFactor.HasInitialShape() ) {
1285 if( shapeFactor.GetHistoName().empty() ) {
1286 cxcoutEHF << "Error: ShapeFactor: " << shapeFactor.GetName()
1287 << " is configured to have an initial shape, but "
1288 << "its histogram doesn't have a name"
1289 << std::endl;
1290 throw hf_exc();
1291 }
1292 shapeFactor.SetHistoPath( ShapeInputPath );
1293 shapeFactor.SetInputFile( ShapeInputFile );
1294 }
1295
1296 shapeFactor.Print(oocoutI(nullptr, HistFactory));
1297
1298 return shapeFactor;
1299
1300}
1301
1302
1304
1305 cxcoutIHF << "Making ShapeSys" << std::endl;
1306
1307 HistFactory::ShapeSys shapeSys;
1308
1309 // Set the default values
1311 shapeSys.SetInputFile( m_currentInputFile );
1312 shapeSys.SetHistoPath( m_currentHistoPath );
1313
1314
1315 TListIter attribIt = node->GetAttributes();
1316 TXMLAttr* curAttr = nullptr;
1317 //EstimateSummary::ConstraintType ConstraintType = EstimateSummary::Gaussian; //"Gaussian";
1318
1319 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
1320
1321
1322 // Get the Name, Val of this node
1323 TString attrName = curAttr->GetName();
1324 std::string attrVal = curAttr->GetValue();
1325
1326 if( attrName == TString( "" ) ){
1327 cxcoutEHF << "Error: Encountered Element in ShapeSys with no name" << std::endl;
1328 throw hf_exc();
1329 }
1330
1331 else if( attrName == TString( "Name" ) ) {
1332 shapeSys.SetName( attrVal );
1333 }
1334
1335 else if( attrName == TString( "HistoName" ) ) {
1336 shapeSys.SetHistoName( attrVal );
1337 }
1338
1339 else if( attrName == TString( "HistoPath" ) ) {
1340 shapeSys.SetHistoPath( attrVal );
1341 }
1342
1343 else if( attrName == TString( "InputFile" ) ) {
1344 shapeSys.SetInputFile( attrVal );
1345 }
1346
1347 else if( attrName == TString( "ConstraintType" ) ) {
1348 if( attrVal.empty() ) {
1349 cxcoutEHF << "Error: ShapeSys Constraint type is empty" << std::endl;
1350 throw hf_exc();
1351 }
1352 else if( attrVal=="Gaussian" || attrVal=="Gauss" ) {
1354 }
1355 else if( attrVal=="Poisson" || attrVal=="Pois" ) {
1357 }
1358 else {
1359 cout << "Error: Encountered unknown ShapeSys Constraint type: " << attrVal << endl;
1360 throw hf_exc();
1361 }
1362 }
1363
1364 else {
1365 cxcoutEHF << "Error: Encountered Element in ShapeSys with unknown name: "
1366 << attrName << std::endl;
1367 throw hf_exc();
1368 }
1369
1370 } // End loop over attributes
1371
1372
1373 if( shapeSys.GetName().empty() ) {
1374 cxcoutEHF << "Error: Encountered ShapeSys with no Name" << std::endl;
1375 throw hf_exc();
1376 }
1377 if( shapeSys.GetInputFile().empty() ) {
1378 cxcoutEHF << "Error: Encountered ShapeSys with no InputFile" << std::endl;
1379 throw hf_exc();
1380 }
1381 if( shapeSys.GetHistoName().empty() ) {
1382 cxcoutEHF << "Error: Encountered ShapeSys with no HistoName" << std::endl;
1383 throw hf_exc();
1384 }
1385
1386 shapeSys.Print(oocoutI(nullptr, HistFactory));
1387
1388 return shapeSys;
1389
1390}
1391
1392
1394
1395 cxcoutIHF << "Activating StatError" << std::endl;
1396
1397 // Set default values
1398 HistFactory::StatError statError;
1399 statError.Activate( false );
1400 statError.SetUseHisto( false );
1401 statError.SetHistoName( "" );
1402
1403 // Loop over the node's attributes
1404 TListIter attribIt = node->GetAttributes();
1405 TXMLAttr* curAttr = nullptr;
1406 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
1407
1408 // Get the Name, Val of this node
1409 TString attrName = curAttr->GetName();
1410 std::string attrVal = curAttr->GetValue();
1411
1412 if( attrName == TString( "" ) ){
1413 cxcoutEHF << "Error: Encountered Element in ActivateStatError with no name" << std::endl;
1414 throw hf_exc();
1415 }
1416
1417 else if( attrName == TString( "Activate" ) ) {
1418 statError.Activate( CheckTrueFalse(attrVal,"ActivateStatError") );
1419 }
1420
1421 else if( attrName == TString( "HistoName" ) ) {
1422 statError.SetHistoName( attrVal );
1423 }
1424
1425 else if( attrName == TString( "HistoPath" ) ) {
1426 statError.SetHistoPath( attrVal );
1427 }
1428
1429 else if( attrName == TString( "InputFile" ) ) {
1430 statError.SetInputFile( attrVal );
1431 }
1432
1433 else {
1434 cxcoutEHF << "Error: Encountered Element in ActivateStatError with unknown name: "
1435 << attrName << std::endl;
1436 throw hf_exc();
1437 }
1438
1439 } // End: Loop Over Attributes
1440
1441 // Based on the input, determine
1442 // if we should use a histogram or not:
1443 // Logic: One turns on using a histogram
1444 // by setting the attribute "HistoName"
1445 // If this is set AND the InputFile or
1446 // HistoPath aren't set, we set those
1447 // to the current default values
1448 if( !statError.GetHistoName().empty() ) {
1449 statError.SetUseHisto( true );
1450
1451 // Check that a file has been set
1452 // (Possibly using the default)
1453 if( statError.GetInputFile().empty() ) {
1454 statError.SetInputFile( m_currentInputFile );
1455 }
1456 if( statError.GetHistoPath().empty() ) {
1457 statError.SetHistoPath( m_currentHistoPath );
1458 }
1459
1460 }
1461
1462 /*
1463 if( statError.Activate ) {
1464 if( statError.UseHisto ) {
1465 }
1466 else {
1467 statError.InputFile = "";
1468 statError.HistoName = "";
1469 statError.HistoPath = "";
1470 }
1471 }
1472 */
1473
1474 statError.Print(oocoutI(nullptr, HistFactory));
1475
1476 return statError;
1477
1478}
1479
1480
1482
1483 cxcoutIHF << "Parsing FunctionConfig" << std::endl;
1484
1485 //std::string name, expression, dependents;
1486 TListIter attribIt = functionNode->GetAttributes();
1487 TXMLAttr* curAttr = nullptr;
1488
1489 std::string Name;
1490 std::string Expression;
1491 std::string Dependents;
1492
1493 // Add protection to ensure that all parts are there
1494 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
1495 if( curAttr->GetName() == TString( "Name" ) ) {
1496 Name = curAttr->GetValue();
1497 //func.SetName( curAttr->GetValue() );
1498 //name = curAttr->GetValue() ;
1499 }
1500 if( curAttr->GetName() == TString( "Expression" ) ) {
1501 Expression = curAttr->GetValue();
1502 //func.SetExpression( curAttr->GetValue() );
1503 }
1504 if( curAttr->GetName() == TString( "Dependents" ) ) {
1505 Dependents = curAttr->GetValue();
1506 //func.SetDependents( curAttr->GetValue() );
1507 }
1508 }
1509
1510 if( Name.empty() ){
1511 cxcoutEHF << "Error processing PreprocessFunction: Name attribute is empty" << std::endl;
1512 throw hf_exc();
1513 }
1514 if( Expression.empty() ){
1515 cxcoutEHF << "Error processing PreprocessFunction: Expression attribute is empty" << std::endl;
1516 throw hf_exc();
1517 }
1518 if( Dependents.empty() ){
1519 cxcoutEHF << "Error processing PreprocessFunction: Dependents attribute is empty" << std::endl;
1520 throw hf_exc();
1521 }
1522
1523 RooStats::HistFactory::PreprocessFunction func(Name, Expression, Dependents);
1524
1525 cxcoutIHF << "Created Preprocess Function: " << func.GetCommand() << std::endl;
1526
1527 //std::string command = "expr::"+func.GetName()+"('"+func.GetExpression()+"',{"+func.GetDependents()+"})";
1528 //func.SetCommand( command );
1529 // // cout << "will pre-process this line " << ret <<endl;
1530 return func;
1531
1532}
1533
1534
1536
1537 if( node->GetNodeName() == TString( "text" ) ) {
1538 return true;
1539 }
1540
1541 if( node->GetNodeName() == TString( "comment" ) ) {
1542 return true;
1543 }
1544
1545 return false;
1546
1547}
1548
1549
1550bool ConfigParser::CheckTrueFalse( std::string attrVal, std::string NodeTitle ) {
1551
1552 if( attrVal.empty() ) {
1553 cxcoutEHF << "Error: In " << NodeTitle
1554 << " Expected either 'True' or 'False' but found empty" << std::endl;
1555 throw hf_exc();
1556 }
1557 else if ( attrVal == "True" || attrVal == "true" ) return true;
1558 else if ( attrVal == "False" || attrVal == "false" ) return false;
1559 else {
1560 cxcoutEHF << "Error: In " << NodeTitle
1561 << " Expected either 'True' or 'False' but found: " << attrVal << std::endl;
1562 throw hf_exc();
1563 }
1564
1565 return false;
1566
1567}
1568
1569//ConfigParser
#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.
Definition Asimov.h:22
void SetName(const std::string &name)
Definition Asimov.h:32
void SetParamValue(const std::string &param, double value)
Definition Asimov.h:35
void SetFixedParam(const std::string &param, bool constant=true)
Definition Asimov.h:34
This class encapsulates all information for the statistical interpretation of one experiment.
Definition Channel.h:30
void SetName(const std::string &Name)
set name of channel
Definition Channel.h:40
void Print(std::ostream &=std::cout)
Definition Channel.cxx:58
void AddAdditionalData(const RooStats::HistFactory::Data &data)
add additional data object
Definition Channel.h:62
std::string GetInputFile() const
get name of input file
Definition Channel.h:46
std::string GetHistoPath() const
get path to histograms in input file
Definition Channel.h:50
void SetData(const RooStats::HistFactory::Data &data)
set data object
Definition Channel.h:53
void SetInputFile(const std::string &file)
set name of input file containing histograms
Definition Channel.h:44
void SetStatErrorConfig(double RelErrorThreshold, Constraint::Type ConstraintType)
Definition Channel.cxx:182
std::vector< RooStats::HistFactory::Sample > & GetSamples()
get vector of samples for this channel
Definition Channel.h:76
void SetHistoPath(const std::string &file)
set path for histograms in input file
Definition Channel.h:48
std::string GetName() const
get name of channel
Definition Channel.h:42
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)
bool CheckTrueFalse(std::string val, std::string Name)
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)
const std::string & GetHistoNameHigh() const
const std::string & GetHistoNameLow() const
void SetHistoNameHigh(const std::string &HistoNameHigh)
void SetHistoNameLow(const std::string &HistoNameLow)
virtual void Print(std::ostream &=std::cout) const
const std::string & GetInputFileHigh() const
const std::string & GetInputFileLow() const
void SetHistoPathLow(const std::string &HistoPathLow)
The RooStats::HistFactory::Measurement class can be used to construct a model by combining multiple R...
Definition Measurement.h:33
std::vector< std::string > & GetPOIList()
get vector of PoI names
Definition Measurement.h:53
void SetLumi(double Lumi)
set integrated luminosity used to normalise histograms (if NormalizeByTheory is true for this sample)
Definition Measurement.h:87
void SetParamValue(const std::string &param, double value)
Set a parameter to a specific value (And optionally fix it)
void SetExportOnly(bool ExportOnly) R__DEPRECATED(6
Do not produce any plots or tables, just save the model.
std::vector< std::string > & GetConstantParams()
get vector of all constant parameters
Definition Measurement.h:62
void SetOutputFilePrefix(const std::string &prefix)
set output prefix
Definition Measurement.h:42
void SetLumiRelErr(double RelErr)
set relative uncertainty on luminosity
Definition Measurement.h:89
void AddAsimovDataset(RooStats::HistFactory::Asimov dataset)
add an Asimov Dataset
Definition Measurement.h:84
Configuration for an un- constrained overall systematic to scale sample normalisations.
Definition Systematics.h:62
void Print(std::ostream &=std::cout) const
void SetName(const std::string &Name)
Definition Systematics.h:68
Configuration for a constrained overall systematic to scale sample normalisations.
Definition Systematics.h:34
void SetName(const std::string &Name)
Definition Systematics.h:40
const std::string & GetName() const
Definition Systematics.h:41
void Print(std::ostream &=std::cout) const
std::vector< RooStats::HistFactory::OverallSys > & GetOverallSysList()
Definition Sample.h:108
std::string GetHistoName() const
get histogram name
Definition Sample.h:92
void SetStatError(RooStats::HistFactory::StatError Error)
Definition Sample.h:126
std::string GetName() const
get name of sample
Definition Sample.h:82
void SetInputFile(const std::string &InputFile)
set input ROOT file
Definition Sample.h:89
void SetChannelName(const std::string &ChannelName)
set name of associated channel
Definition Sample.h:104
void SetHistoName(const std::string &HistoName)
set histogram name
Definition Sample.h:94
std::string GetHistoPath() const
get histogram path
Definition Sample.h:97
void SetNormalizeByTheory(bool norm)
defines whether the normalization scale with luminosity
Definition Sample.h:76
std::vector< RooStats::HistFactory::ShapeFactor > & GetShapeFactorList()
Definition Sample.h:113
void SetName(const std::string &Name)
set name of sample
Definition Sample.h:84
void SetHistoPath(const std::string &HistoPath)
set histogram path
Definition Sample.h:99
std::vector< RooStats::HistFactory::NormFactor > & GetNormFactorList()
Definition Sample.h:109
std::string GetInputFile() const
get input ROOT file
Definition Sample.h:87
std::vector< RooStats::HistFactory::HistoSys > & GetHistoSysList()
Definition Sample.h:110
std::vector< RooStats::HistFactory::ShapeSys > & GetShapeSysList()
Definition Sample.h:112
*Un*constrained bin-by-bin variation of affected histogram.
void SetInputFile(const std::string &InputFile)
void SetHistoName(const std::string &HistoName)
void Print(std::ostream &=std::cout) const override
void SetHistoPath(const std::string &HistoPath)
const std::string & GetHistoName() const
Constrained bin-by-bin variation of affected histogram.
std::string GetHistoName() const
void SetInputFile(const std::string &InputFile)
void Print(std::ostream &=std::cout) const override
void SetHistoName(const std::string &HistoName)
void SetConstraintType(Constraint::Type ConstrType)
std::string GetInputFile() const
void SetHistoPath(const std::string &HistoPath)
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
virtual TXMLDocument * GetXMLDocument() const
Returns the TXMLDocument.
Int_t ParseFile(const char *filename) override
Parse the XML file where filename is the XML file name.
Iterator of linked list.
Definition TList.h:191
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:444
Basic string class.
Definition TString.h:139
TXMLAttribute is the attribute of an Element.
Definition TXMLAttr.h:18
const char * GetValue() const
Definition TXMLAttr.h:33
const char * GetName() const override
Returns name of object.
Definition TXMLAttr.h:31
TXMLDocument contains a pointer to an xmlDoc structure, after the parser returns a tree built during ...
TXMLNode * GetRootNode() const
Returns the root element node.
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:108
const char * GetText() const
Returns the content of a Text node if node is a TextNode, 0 otherwise.
Definition TXMLNode.cxx:154
TXMLNode * GetNextNode()
Returns the next sibling XMLNode in the DOM tree, if any return 0 if no next node.
Definition TXMLNode.cxx:130
TXMLNode * GetChildren()
Returns the node's child if any, returns 0 if no child.
Definition TXMLNode.cxx:74
const char * GetNodeName() const
Returns the node's name.
Definition TXMLNode.cxx:66
Namespace for the RooStats classes.
Definition Asimov.h:19