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 // ignored
384 cxcoutIHF << "The \"ExportOnly\" attribute is ignored it is always \"true\" for any Measurement." << std::endl;
385 } else {
386 cxcoutEHF << "Found unknown XML attribute in Measurement: " << curAttrName << "\n";
387 throw hf_exc();
388 }
389 } // End Loop over attributes
390
391 // Then, get the properties of the children nodes
392 TXMLNode *child = node->GetChildren();
393 while (child != nullptr) {
394 const std::string childName(child->GetName() ? child->GetName() : "");
395 const std::string childNodeName(child->GetNodeName() ? child->GetNodeName() : "");
396 const std::string childText(child->GetText() ? child->GetText() : "");
397 if (childNodeName.empty()) {
398 cxcoutEHF << "Found XML child node of Measurement with no name\n";
399 throw hf_exc();
400 } else if (childNodeName == "POI") {
401 if (childText.empty()) {
402 cxcoutEHF << "Error: node: " << childName << " has no text.\n";
403 throw hf_exc();
404 }
405 // poi // measurement.SetPOI(childText);
406 AddSubStrings(measurement.GetPOIList(), childText);
407 } else if (childNodeName == "ParamSetting") {
408 TListIter paramIt = child->GetAttributes();
409 TXMLAttr *curParam = nullptr;
410 while ((/**/ curParam = dynamic_cast<TXMLAttr *>(paramIt()) /**/) != nullptr) {
411 // curParam is guaranteed non-null above
412 const std::string curParamName(curParam->GetName() ? curParam->GetName() : "");
413 if (curParamName.empty()) {
414 cxcoutEHF << "Error: Found tag attribute with no name in ParamSetting\n";
415 throw hf_exc();
416 } else if (curParamName == "Const") {
417 if (curParam->GetValue() == TString("True")) {
418 // Fix here...?
419 if (childText.empty()) {
420 cxcoutEHF << "Error: node: " << childName << " has no text.\n";
421 throw hf_exc();
422 }
423 AddSubStrings(measurement.GetConstantParams(), childText);
424 }
425 } else if (curParamName == "Val") {
426 double val = atof(curParam->GetValue());
427 if (childText.empty()) {
428 cxcoutEHF << "Error: node: " << childName << " has no text.\n";
429 throw hf_exc();
430 }
431 std::vector<std::string> child_nodes = GetChildrenFromString(childText);
432 for (size_t i = 0; i < child_nodes.size(); ++i) {
433 measurement.SetParamValue(child_nodes.at(i), val);
434 }
435 } else {
436 cxcoutEHF << "Found tag attribute with unknown name in ParamSetting: " << curParamName << "\n";
437 throw hf_exc();
438 }
439 }
440 } else if (childNodeName == "Asimov") {
441 // Now, create and configure an asimov object
442 // and add it to the measurement
444 std::string ParamFixString;
445
446 // Loop over attributes
447 attribIt = child->GetAttributes();
448 curAttr = nullptr;
449 while ((/**/ curAttr = dynamic_cast<TXMLAttr *>(attribIt()) /**/) != nullptr) {
450 const std::string curAttrName(curAttr->GetName() ? curAttr->GetName() : "");
451 const std::string curAttrValue(curAttr->GetValue() ? curAttr->GetValue() : "");
452 if (curAttrName.empty()) {
453 cxcoutEHF << "Error: Found tag attribute with no name in ConstraintTerm\n";
454 throw hf_exc();
455 } else if (curAttrName == "Name") {
456 asimov.SetName(curAttrValue);
457 } else if (curAttrName == "FixParams") {
458 ParamFixString = curAttrValue;
459 } else {
460 cxcoutEHF << "Found tag attribute with unknown name in ConstraintTerm: " << curAttrName << "\n";
461 throw hf_exc();
462 }
463 }
464
465 // Add any parameters to the asimov dataset
466 // to be fixed during the fitting and dataset generation
467 if (ParamFixString.empty()) {
468 cxcoutWHF << "Warning: Asimov Dataset with name: " << asimov.GetName()
469 << " added, but no parameters are set to be fixed\n";
470 } else {
471 AddParamsToAsimov(asimov, ParamFixString);
472 }
473 measurement.AddAsimovDataset(asimov);
474 } else if (childNodeName == "ConstraintTerm") {
475 std::vector<string> syst;
476 std::string type;
477 double rel = 0;
478
479 // Get the list of parameters in this tag:
480 if (childText.empty()) {
481 cxcoutEHF << "Error: node: " << childName << " has no text\n";
482 throw hf_exc();
483 }
484 AddSubStrings(syst, childText);
485
486 // Now, loop over this tag's attributes
487 attribIt = child->GetAttributes();
488 curAttr = nullptr;
489 while ((/**/ curAttr = dynamic_cast<TXMLAttr *>(attribIt()) /**/) != nullptr) {
490 const std::string curAttrName(curAttr->GetName() ? curAttr->GetName() : "");
491 const std::string curAttrValue(curAttr->GetValue() ? curAttr->GetValue() : "");
492 if (curAttrName.empty()) {
493 cxcoutEHF << "Error: Found tag attribute with no name in ConstraintTerm\n";
494 throw hf_exc();
495 } else if (curAttrName == "Type") {
496 type = curAttrValue;
497 } else if (curAttrName == "RelativeUncertainty") {
498 rel = std::stof(curAttrValue);
499 } else {
500 cxcoutEHF << "Found tag attribute with unknown name in ConstraintTerm: " << curAttrName << "\n";
501 throw hf_exc();
502 }
503 } // End Loop over tag attributes
504
505 // Now, fill the maps, depending on the type:
506 if (rel != 0) {
507 if (type == "Gamma") {
508 for (const auto &isyst : syst) {
509 // Fix Here...?
510 measurement.GetGammaSyst()[isyst] = rel;
511 }
512 } else if (type == "Uniform") {
513 for (const auto &isyst : syst) {
514 // Fix Here...?
515 measurement.GetUniformSyst()[isyst] = rel;
516 }
517 } else if (type == "LogNormal") {
518 for (const auto &isyst : syst) {
519 // Fix Here...?
520 measurement.GetLogNormSyst()[isyst] = rel;
521 }
522 }
523 } else if (type == "NoConstraint") {
524 for (const auto &isyst : syst) {
525 // Fix Here...?
526 measurement.GetNoSyst()[isyst] = 1.0; // MB : dummy value
527 }
528 } else {
529 // only Gamma, Uniform, LogNormal and NoConstraint are valid types
530 cxcoutEHF << "Error: Encountered unknown type for ConstraintTerm: " << type << "\n";
531 throw hf_exc();
532 }
533 // End adding of Constraint terms
534 } else if (IsAcceptableNode(child)) {
535 /* do nothing */
536 } else {
537 cxcoutEHF << "Found XML child of Measurement with unknown name: " << childNodeName << "\n";
538 throw hf_exc();
539 }
540 child = child->GetNextNode();
541 }
542
543 measurement.PrintTree(oocoutI(nullptr, HistFactory));
544
545 return measurement;
546}
547
549
550 /*
551 TString lumiStr;
552 lumiStr+=lumi;
553 lumiStr.ReplaceAll(' ', TString());
554 */
555
556 cxcoutIHF << "Parsing file: " << filen << std::endl;
557
558 TDOMParser xmlparser;
559
560 // reading in the file and parse by DOM
561 Int_t parseError = xmlparser.ParseFile( filen.c_str() );
562 if( parseError ) {
563 cxcoutEHF << "Loading of xml document \"" << filen
564 << "\" failed" << std::endl;
565 throw hf_exc();
566 }
567
568 TXMLDocument* xmldoc = xmlparser.GetXMLDocument();
569 TXMLNode* rootNode = xmldoc->GetRootNode();
570
571 // Check that is is a CHANNEL based on the DOCTYPE
572
573 if( rootNode->GetNodeName() != TString( "Channel" ) ){
574 cxcoutEHF << "Error: In parsing a Channel XML, "
575 << "Encountered XML with DOCTYPE: " << rootNode->GetNodeName()
576 << std::endl;
577 cxcoutEHF << " DOCTYPE for channels must be 'Channel' "
578 << " Check that your XML is properly written" << std::endl;
579 throw hf_exc();
580 }
581
582 // Now, create the channel,
583 // configure it based on the XML
584 // and return it
585
586 HistFactory::Channel channel;
587
588 // Set the default values:
589 channel.SetInputFile( "" );
590 channel.SetHistoPath( "" );
591
592 // Walk through the root node and
593 // get its attributes
594 TListIter attribIt = rootNode->GetAttributes();
595 TXMLAttr* curAttr = nullptr;
596 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
597
598 // Get the Name, Val of this node
599 TString attrName = curAttr->GetName();
600 std::string attrVal = curAttr->GetValue();
601
602 if( attrName == TString( "" ) ) {
603 cxcoutEHF << " Error: Attribute for 'Channel' with no name found" << std::endl;
604 throw hf_exc();
605 }
606
607 else if( attrName == TString( "Name" ) ) {
608 channel.SetName( attrVal );
609 cxcoutIHF << " : creating a channel named " << channel.GetName() << std::endl;
610 }
611
612 else if( attrName == TString( "InputFile" ) ) {
613 cxcoutIHF << "Setting InputFile for this channel: " << attrVal << std::endl;
614 channel.SetInputFile( attrVal );
615 // Set the current (cached) value
616 m_currentInputFile = attrVal;
617 }
618
619 else if( curAttr->GetName() == TString( "HistoPath" ) ) {
620 cxcoutIHF << "Setting HistoPath for this channel: " << attrVal << std::endl;
621 // Set the current (cached) value
622 channel.SetHistoPath( attrVal );
623 m_currentHistoPath = attrVal;
624 }
625
626 else if( curAttr->GetName() == TString( "HistoName" ) ) {
627 // Changed This:
628 cxcoutEHF << "Use of HistoName in Channel is deprecated" << std::endl;
629 cxcoutEHF << "This will be ignored" << std::endl;
630 }
631
632 else {
633 cxcoutEHF << " Error: Unknown attribute for 'Channel' encountered: "
634 << attrName << std::endl;
635 throw hf_exc();
636 }
637
638 } // End loop over the channel tag's attributes
639
640 // Check that the channel was properly initiated:
641
642 if( channel.GetName().empty() ) {
643 cxcoutEHF << "Error: Channel created with no name" << std::endl;
644 throw hf_exc();
645 }
646
647 m_currentChannel = channel.GetName();
648
649 // Loop over the children nodes in the XML file
650 // and configure the channel based on them
651
652 TXMLNode* node = rootNode->GetChildren();
653
654 bool firstData=true;
655
656 while( node != nullptr ) {
657
658 // Restore the Channel-Wide Defaults
661
662 if( node->GetNodeName() == TString( "" ) ) {
663 cxcoutEHF << "Error: Encountered node in Channel with no name" << std::endl;
664 throw hf_exc();
665 }
666
667 else if( node->GetNodeName() == TString( "Data" ) ) {
668 if( firstData ) {
670 if( !data.GetName().empty() ) {
671 cxcoutEHF << "Error: You can only rename the datasets of additional data sets. "
672 << " Remove the 'Name=" << data.GetName() << "' tag"
673 << " from channel: " << channel.GetName() << std::endl;
674 throw hf_exc();
675 }
676 channel.SetData( data );
677 firstData=false;
678 }
679 else {
680 channel.AddAdditionalData( CreateDataElement(node) );
681 }
682 }
683
684 else if( node->GetNodeName() == TString( "StatErrorConfig" ) ) {
686 }
687
688 else if( node->GetNodeName() == TString( "Sample" ) ) {
689 channel.GetSamples().push_back( CreateSampleElement(node) );
690 }
691
692 else if( IsAcceptableNode( node ) ) { ; }
693
694 else {
695 cxcoutEHF << "Error: Encountered node in Channel with unknown name: " << node->GetNodeName() << std::endl;
696 throw hf_exc();
697 }
698
699 node = node->GetNextNode();
700
701 } // End loop over tags in this channel
702
703 cxcoutIHF << "Created Channel: " << std::endl;
704 channel.Print(oocoutI(nullptr, HistFactory));
705
706 return channel;
707
708}
709
710
711
713
714 cxcoutIHF << "Creating Data Element" << std::endl;
715
717
718 // Set the default values
719 data.SetInputFile( m_currentInputFile );
720 data.SetHistoPath( m_currentHistoPath );
721 //data.HistoName = m_currentHistoName;
722
723 // Now, set the attributes
724 TListIter attribIt = node->GetAttributes();
725 TXMLAttr* curAttr = nullptr;
726 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
727
728 // Get the Name, Val of this node
729 TString attrName = curAttr->GetName();
730 std::string attrVal = curAttr->GetValue();
731
732 if( attrName == TString( "" ) ) {
733 cxcoutEHF << " Error: Attribute for 'Data' with no name found" << std::endl;
734 throw hf_exc();
735 }
736
737 else if( attrName == TString( "Name" ) ) {
738 data.SetName( attrVal );
739 }
740
741 else if( attrName == TString( "InputFile" ) ) {
742 data.SetInputFile( attrVal );
743 }
744
745 else if( attrName == TString( "HistoName" ) ) {
746 data.SetHistoName( attrVal );
747 }
748
749 else if( attrName == TString( "HistoPath" ) ) {
750 data.SetHistoPath( attrVal );
751 }
752
753 else if( IsAcceptableNode( node ) ) { ; }
754
755 else {
756 cxcoutEHF << " Error: Unknown attribute for 'Data' encountered: " << attrName << std::endl;
757 throw hf_exc();
758 }
759
760 }
761
762 // Check the properties of the data node:
763 if( data.GetInputFile().empty() ) {
764 cxcoutEHF << "Error: Data Node has no InputFile" << std::endl;
765 throw hf_exc();
766 }
767 if( data.GetHistoName().empty() ) {
768 cxcoutEHF << "Error: Data Node has no HistoName" << std::endl;
769 throw hf_exc();
770 }
771
772 cxcoutIHF << "Created Data Node with"
773 << " InputFile: " << data.GetInputFile()
774 << " HistoName: " << data.GetHistoName()
775 << " HistoPath: " << data.GetHistoPath()
776 << (!data.GetName().empty() ? " Name: " : "") << data.GetName() << std::endl;
777
778 // data.hist = GetHisto(data.FileName, data.HistoPath, data.HistoName);
779
780 return data;
781}
782
783
784
786
787 cxcoutIHF << "Creating StatErrorConfig Element" << std::endl;
788
790
791 // Setup default values:
793 config.SetRelErrorThreshold( 0.05 ); // 5%
794
795 // Loop over the node's attributes
796 TListIter attribIt = node->GetAttributes();
797 TXMLAttr* curAttr = nullptr;
798 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
799
800 // Get the Name, Val of this node
801 TString attrName = curAttr->GetName();
802 std::string attrVal = curAttr->GetValue();
803
804 if( attrName == TString( "RelErrorThreshold" ) ) {
805 config.SetRelErrorThreshold( atof(attrVal.c_str()) );
806 }
807
808 if( attrName == TString( "ConstraintType" ) ) {
809 // Allowable Values: Gaussian
810
811 if( attrVal.empty() ) {
812 cxcoutEHF << "Error: Bad Value for StatErrorConfig Constraint Type Found" << std::endl;
813 throw hf_exc();
814 }
815
816 else if( attrVal=="Gaussian" || attrVal=="Gauss" ) {
818 }
819
820 else if( attrVal=="Poisson" || attrVal=="Pois" ) {
822 }
823
824 else if( IsAcceptableNode( node ) ) { ; }
825
826 else {
827 cout << "Invalid Stat Constraint Type: " << curAttr->GetValue() << endl;
828 throw hf_exc();
829 }
830 }
831 } // End: Loop Over Attributes
832
833 cxcoutIHF << "Created StatErrorConfig Element with"
834 << " Constraint type: " << config.GetConstraintType()
835 << " RelError Threshold: " << config.GetRelErrorThreshold()
836 << std::endl;
837
838 return config;
839
840}
841
842
844
845 cxcoutIHF << "Creating Sample Element" << std::endl;
846
847 HistFactory::Sample sample;
848
849 // Set the default values
853 sample.SetNormalizeByTheory( true );
854 //sample.HistoName = m_currentHistoName;
855
856 // Now, set the attributes
857
858 TListIter attribIt = node->GetAttributes();
859 TXMLAttr* curAttr = nullptr;
860 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
861
862 // Get the Name, Val of this node
863 TString attrName = curAttr->GetName();
864 std::string attrVal = curAttr->GetValue();
865
866 if( attrName == TString( "" ) ) {
867 cxcoutEHF << " Error: Attribute for 'Sample' with no name found" << std::endl;
868 throw hf_exc();
869 }
870
871 else if( attrName == TString( "Name" ) ) {
872 sample.SetName( attrVal );
873 }
874
875 else if( attrName == TString( "InputFile" ) ) {
876 sample.SetInputFile( attrVal );
877 m_currentInputFile = attrVal;
878 }
879
880 else if( attrName == TString( "HistoName" ) ) {
881 sample.SetHistoName( attrVal );
882 }
883
884 else if( attrName == TString( "HistoPath" ) ) {
885 sample.SetHistoPath( attrVal );
886 m_currentHistoPath = attrVal;
887 }
888
889 else if( attrName == TString( "NormalizeByTheory" ) ) {
890 sample.SetNormalizeByTheory( CheckTrueFalse(attrVal,"Sample") );
891 /*
892 if( attrVal == "" ) {
893 cxcoutEHF << "Error: Attribute 'NormalizeByTheory' in Sample has no value" << std::endl;
894 throw hf_exc();
895 }
896 else if ( attrVal == "True" || attrVal == "true" ) sample.NormalizeByTheory = true;
897 else if ( attrVal == "False" || attrVal == "false" ) sample.NormalizeByTheory = false;
898 else {
899 cxcoutEHF << "Error: Attribute 'NormalizeByTheory' in Sample has unknown value: " << attrVal << std::endl;
900 std::cout << "Value must be 'True' or 'False' " << std::endl;
901 throw hf_exc();
902 }
903 */
904 }
905
906 else {
907 cxcoutEHF << " Error: Unknown attribute for 'Sample' encountered: " << attrName << std::endl;
908 throw hf_exc();
909 }
910 }
911
912 // Quickly check the properties of the Sample Node
913 if( sample.GetName().empty() ) {
914 cxcoutEHF << "Error: Sample Node has no Name" << std::endl;
915 throw hf_exc();
916 }
917 if( sample.GetInputFile().empty() ) {
918 cxcoutEHF << "Error: Sample Node has no InputFile" << std::endl;
919 throw hf_exc();
920 }
921 if( sample.GetHistoName().empty() ) {
922 cxcoutEHF << "Error: Sample Node has no HistoName" << std::endl;
923 throw hf_exc();
924 }
925
926
927 // Now, loop over the children and add the systematics
928
929 TXMLNode* child = node->GetChildren();
930
931 while( child != nullptr ) {
932
933 if( child->GetNodeName() == TString( "" ) ) {
934 cxcoutEHF << "Error: Encountered node in Sample with no name" << std::endl;
935 throw hf_exc();
936 }
937
938 else if( child->GetNodeName() == TString( "NormFactor" ) ) {
939 sample.GetNormFactorList().push_back( MakeNormFactor( child ) );
940 }
941
942 else if( child->GetNodeName() == TString( "OverallSys" ) ) {
943 sample.GetOverallSysList().push_back( MakeOverallSys( child ) );
944 }
945
946 else if( child->GetNodeName() == TString( "HistoSys" ) ) {
947 sample.GetHistoSysList().push_back( MakeHistoSys( child ) );
948 }
949
950 else if( child->GetNodeName() == TString( "HistoFactor" ) ) {
951 cxcoutEHF << "WARNING: HistoFactor not yet supported" << std::endl;
952 //sample.GetHistoFactorList().push_back( MakeHistoFactor( child ) );
953 }
954
955 else if( child->GetNodeName() == TString( "ShapeSys" ) ) {
956 sample.GetShapeSysList().push_back( MakeShapeSys( child ) );
957 }
958
959 else if( child->GetNodeName() == TString( "ShapeFactor" ) ) {
960 sample.GetShapeFactorList().push_back( MakeShapeFactor( child ) );
961 }
962
963 else if( child->GetNodeName() == TString( "StatError" ) ) {
965 }
966
967 else if( IsAcceptableNode( child ) ) { ; }
968
969 else {
970 cxcoutEHF << "Error: Encountered node in Sample with unknown name: " << child->GetNodeName() << std::endl;
971 throw hf_exc();
972 }
973
974 child=child->GetNextNode();
975 }
976
977 cxcoutIHF << "Created Sample Node with"
978 << " Name: " << sample.GetName()
979 << " InputFile: " << sample.GetInputFile()
980 << " HistoName: " << sample.GetHistoName()
981 << " HistoPath: " << sample.GetHistoPath()
982 << std::endl;
983
984 // sample.hist = GetHisto(sample.FileName, sample.HistoPath, sample.HistoName);
985
986 return sample;
987}
988
989
991
992 cxcoutIHF << "Making NormFactor:" << std::endl;
993
995
996 TListIter attribIt = node->GetAttributes();
997 TXMLAttr* curAttr = nullptr;
998 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
999
1000 // Get the Name, Val of this node
1001 TString attrName = curAttr->GetName();
1002 std::string attrVal = curAttr->GetValue();
1003
1004 if( attrName == TString( "" ) ){
1005 cxcoutEHF << "Error: Encountered Element in NormFactor with no name" << std::endl;
1006 throw hf_exc();
1007 }
1008
1009 else if( curAttr->GetName() == TString( "Name" ) ) {
1010 norm.SetName( attrVal );
1011 }
1012 else if( curAttr->GetName() == TString( "Val" ) ) {
1013 norm.SetVal( atof(attrVal.c_str()) );
1014 }
1015 else if( curAttr->GetName() == TString( "Low" ) ) {
1016 norm.SetLow( atof(attrVal.c_str()) );
1017 }
1018 else if( curAttr->GetName() == TString( "High" ) ) {
1019 norm.SetHigh( atof(attrVal.c_str()) );
1020 }
1021
1022 else {
1023 cxcoutEHF << "Error: Encountered Element in NormFactor with unknown name: "
1024 << attrName << std::endl;
1025 throw hf_exc();
1026 }
1027
1028 } // End loop over properties
1029
1030 if( norm.GetName().empty() ) {
1031 cxcoutEHF << "Error: NormFactor Node has no Name" << std::endl;
1032 throw hf_exc();
1033 }
1034
1035 if( norm.GetLow() >= norm.GetHigh() ) {
1036 cxcoutEHF << "Error: NormFactor: " << norm.GetName()
1037 << " has lower limit >= its upper limit: "
1038 << " Lower: " << norm.GetLow()
1039 << " Upper: " << norm.GetHigh()
1040 << ". Please Fix" << std::endl;
1041 throw hf_exc();
1042 }
1043 if( norm.GetVal() > norm.GetHigh() || norm.GetVal() < norm.GetLow() ) {
1044 cxcoutEHF << "Error: NormFactor: " << norm.GetName()
1045 << " has initial value not within its range: "
1046 << " Val: " << norm.GetVal()
1047 << " Lower: " << norm.GetLow()
1048 << " Upper: " << norm.GetHigh()
1049 << ". Please Fix" << std::endl;
1050 throw hf_exc();
1051 }
1052
1053 norm.Print(oocoutI(nullptr, HistFactory));
1054
1055 return norm;
1056
1057}
1058
1060
1061 cxcoutIHF << "Making HistoFactor" << std::endl;
1062
1064
1067
1070
1071 cxcoutIHF << "Made HistoFactor" << std::endl;
1072
1073 return dummy;
1074
1075}
1076
1077
1079
1080 cxcoutIHF << "Making HistoSys:" << std::endl;
1081
1082 HistFactory::HistoSys histoSys;
1083
1084 // Set Default values
1087
1090
1091 TListIter attribIt = node->GetAttributes();
1092 TXMLAttr* curAttr = nullptr;
1093 /*
1094 string Name, histoPathHigh, histoPathLow,
1095 histoNameLow, histoNameHigh, inputFileHigh, inputFileLow;
1096 inputFileLow=inputFileName; inputFileHigh=inputFileName;
1097 histoPathLow=histoPathName; histoPathHigh=histoPathName;
1098 histoNameLow=histoName; histoNameHigh=histoName;
1099 */
1100
1101 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
1102
1103 // Get the Name, Val of this node
1104 TString attrName = curAttr->GetName();
1105 std::string attrVal = curAttr->GetValue();
1106
1107 if( attrName == TString( "" ) ){
1108 cxcoutEHF << "Error: Encountered Element in HistoSys with no name" << std::endl;
1109 throw hf_exc();
1110 }
1111
1112 else if( curAttr->GetName() == TString( "Name" ) ) {
1113 histoSys.SetName( attrVal );
1114 }
1115
1116 else if( curAttr->GetName() == TString( "HistoFileHigh" ) ) {
1117 histoSys.SetInputFileHigh( attrVal );
1118 }
1119 else if( curAttr->GetName() == TString( "HistoPathHigh" ) ) {
1120 histoSys.SetHistoPathHigh( attrVal );
1121 }
1122 else if( curAttr->GetName() == TString( "HistoNameHigh" ) ) {
1123 histoSys.SetHistoNameHigh( attrVal );
1124 }
1125
1126 else if( curAttr->GetName() == TString( "HistoFileLow" ) ) {
1127 histoSys.SetInputFileLow( attrVal );
1128 }
1129 else if( curAttr->GetName() == TString( "HistoPathLow" ) ) {
1130 histoSys.SetHistoPathLow( attrVal );
1131 }
1132 else if( curAttr->GetName() == TString( "HistoNameLow" ) ) {
1133 histoSys.SetHistoNameLow( attrVal );
1134 }
1135
1136 else {
1137 cxcoutEHF << "Error: Encountered Element in HistoSys with unknown name: "
1138 << attrName << std::endl;
1139 throw hf_exc();
1140 }
1141
1142 } // End loop over properties
1143
1144
1145 if( histoSys.GetName().empty() ) {
1146 cxcoutEHF << "Error: HistoSys Node has no Name" << std::endl;
1147 throw hf_exc();
1148 }
1149 if( histoSys.GetInputFileHigh().empty() ) {
1150 cxcoutEHF << "Error: HistoSysSample Node has no InputFileHigh" << std::endl;
1151 throw hf_exc();
1152 }
1153 if( histoSys.GetInputFileLow().empty() ) {
1154 cxcoutEHF << "Error: HistoSysSample Node has no InputFileLow" << std::endl;
1155 throw hf_exc();
1156 }
1157 if( histoSys.GetHistoNameHigh().empty() ) {
1158 cxcoutEHF << "Error: HistoSysSample Node has no HistoNameHigh" << std::endl;
1159 throw hf_exc();
1160 }
1161 if( histoSys.GetHistoNameLow().empty() ) {
1162 cxcoutEHF << "Error: HistoSysSample Node has no HistoNameLow" << std::endl;
1163 throw hf_exc();
1164 }
1165
1166
1167 histoSys.Print(oocoutI(nullptr, HistFactory));
1168
1169 return histoSys;
1170
1171}
1172
1173
1175
1176 cxcoutIHF << "Making OverallSys:" << std::endl;
1177
1178 HistFactory::OverallSys overallSys;
1179
1180 TListIter attribIt = node->GetAttributes();
1181 TXMLAttr* curAttr = nullptr;
1182 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
1183
1184 // Get the Name, Val of this node
1185 TString attrName = curAttr->GetName();
1186 std::string attrVal = curAttr->GetValue();
1187
1188 if( attrName == TString( "" ) ){
1189 cxcoutEHF << "Error: Encountered Element in OverallSys with no name" << std::endl;
1190 throw hf_exc();
1191 }
1192
1193 else if( attrName == TString( "Name" ) ) {
1194 overallSys.SetName( attrVal );
1195 }
1196 else if( attrName == TString( "High" ) ) {
1197 overallSys.SetHigh( atof(attrVal.c_str()) );
1198 }
1199 else if( attrName == TString( "Low" ) ) {
1200 overallSys.SetLow( atof(attrVal.c_str()) );
1201 }
1202
1203 else {
1204 cxcoutEHF << "Error: Encountered Element in OverallSys with unknown name: "
1205 << attrName << std::endl;
1206 throw hf_exc();
1207 }
1208
1209 }
1210
1211 if( overallSys.GetName().empty() ) {
1212 cxcoutEHF << "Error: Encountered OverallSys with no name" << std::endl;
1213 throw hf_exc();
1214 }
1215
1216
1217 overallSys.Print(oocoutI(nullptr, HistFactory));
1218
1219 return overallSys;
1220
1221}
1222
1223
1225
1226 cxcoutIHF << "Making ShapeFactor" << std::endl;
1227
1228 HistFactory::ShapeFactor shapeFactor;
1229
1230 TListIter attribIt = node->GetAttributes();
1231 TXMLAttr* curAttr = nullptr;
1232
1233 // A Shape Factor may or may not include an initial shape
1234 // This will be set by strings pointing to a histogram
1235 // If we don't see a 'HistoName' attribute, we assume
1236 // that an initial shape is not being set
1237 std::string ShapeInputFile = m_currentInputFile;
1238 std::string ShapeInputPath = m_currentHistoPath;
1239
1240 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
1241
1242 // Get the Name, Val of this node
1243 TString attrName = curAttr->GetName();
1244 std::string attrVal = curAttr->GetValue();
1245
1246 if( attrName == TString( "" ) ){
1247 cxcoutEHF << "Error: Encountered Element in ShapeFactor with no name" << std::endl;
1248 throw hf_exc();
1249 }
1250
1251 else if( attrName == TString( "Name" ) ) {
1252 shapeFactor.SetName( attrVal );
1253 }
1254 else if( attrName == TString( "Const" ) ) {
1255 shapeFactor.SetConstant( CheckTrueFalse(attrVal, "ShapeFactor" ) );
1256 }
1257
1258 else if( attrName == TString( "HistoName" ) ) {
1259 shapeFactor.SetHistoName( attrVal );
1260 }
1261
1262 else if( attrName == TString( "InputFile" ) ) {
1263 ShapeInputFile = attrVal;
1264 }
1265
1266 else if( attrName == TString( "HistoPath" ) ) {
1267 ShapeInputPath = attrVal;
1268 }
1269
1270 else {
1271 cxcoutEHF << "Error: Encountered Element in ShapeFactor with unknown name: "
1272 << attrName << std::endl;
1273 throw hf_exc();
1274 }
1275
1276 }
1277
1278 if( shapeFactor.GetName().empty() ) {
1279 cxcoutEHF << "Error: Encountered ShapeFactor with no name" << std::endl;
1280 throw hf_exc();
1281 }
1282
1283 // Set the Histogram name, path, and file
1284 // if an InitialHist is set
1285 if( shapeFactor.HasInitialShape() ) {
1286 if( shapeFactor.GetHistoName().empty() ) {
1287 cxcoutEHF << "Error: ShapeFactor: " << shapeFactor.GetName()
1288 << " is configured to have an initial shape, but "
1289 << "its histogram doesn't have a name"
1290 << std::endl;
1291 throw hf_exc();
1292 }
1293 shapeFactor.SetHistoPath( ShapeInputPath );
1294 shapeFactor.SetInputFile( ShapeInputFile );
1295 }
1296
1297 shapeFactor.Print(oocoutI(nullptr, HistFactory));
1298
1299 return shapeFactor;
1300
1301}
1302
1303
1305
1306 cxcoutIHF << "Making ShapeSys" << std::endl;
1307
1308 HistFactory::ShapeSys shapeSys;
1309
1310 // Set the default values
1312 shapeSys.SetInputFile( m_currentInputFile );
1313 shapeSys.SetHistoPath( m_currentHistoPath );
1314
1315
1316 TListIter attribIt = node->GetAttributes();
1317 TXMLAttr* curAttr = nullptr;
1318 //EstimateSummary::ConstraintType ConstraintType = EstimateSummary::Gaussian; //"Gaussian";
1319
1320 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
1321
1322
1323 // Get the Name, Val of this node
1324 TString attrName = curAttr->GetName();
1325 std::string attrVal = curAttr->GetValue();
1326
1327 if( attrName == TString( "" ) ){
1328 cxcoutEHF << "Error: Encountered Element in ShapeSys with no name" << std::endl;
1329 throw hf_exc();
1330 }
1331
1332 else if( attrName == TString( "Name" ) ) {
1333 shapeSys.SetName( attrVal );
1334 }
1335
1336 else if( attrName == TString( "HistoName" ) ) {
1337 shapeSys.SetHistoName( attrVal );
1338 }
1339
1340 else if( attrName == TString( "HistoPath" ) ) {
1341 shapeSys.SetHistoPath( attrVal );
1342 }
1343
1344 else if( attrName == TString( "InputFile" ) ) {
1345 shapeSys.SetInputFile( attrVal );
1346 }
1347
1348 else if( attrName == TString( "ConstraintType" ) ) {
1349 if( attrVal.empty() ) {
1350 cxcoutEHF << "Error: ShapeSys Constraint type is empty" << std::endl;
1351 throw hf_exc();
1352 }
1353 else if( attrVal=="Gaussian" || attrVal=="Gauss" ) {
1355 }
1356 else if( attrVal=="Poisson" || attrVal=="Pois" ) {
1358 }
1359 else {
1360 cout << "Error: Encountered unknown ShapeSys Constraint type: " << attrVal << endl;
1361 throw hf_exc();
1362 }
1363 }
1364
1365 else {
1366 cxcoutEHF << "Error: Encountered Element in ShapeSys with unknown name: "
1367 << attrName << std::endl;
1368 throw hf_exc();
1369 }
1370
1371 } // End loop over attributes
1372
1373
1374 if( shapeSys.GetName().empty() ) {
1375 cxcoutEHF << "Error: Encountered ShapeSys with no Name" << std::endl;
1376 throw hf_exc();
1377 }
1378 if( shapeSys.GetInputFile().empty() ) {
1379 cxcoutEHF << "Error: Encountered ShapeSys with no InputFile" << std::endl;
1380 throw hf_exc();
1381 }
1382 if( shapeSys.GetHistoName().empty() ) {
1383 cxcoutEHF << "Error: Encountered ShapeSys with no HistoName" << std::endl;
1384 throw hf_exc();
1385 }
1386
1387 shapeSys.Print(oocoutI(nullptr, HistFactory));
1388
1389 return shapeSys;
1390
1391}
1392
1393
1395
1396 cxcoutIHF << "Activating StatError" << std::endl;
1397
1398 // Set default values
1399 HistFactory::StatError statError;
1400 statError.Activate( false );
1401 statError.SetUseHisto( false );
1402 statError.SetHistoName( "" );
1403
1404 // Loop over the node's attributes
1405 TListIter attribIt = node->GetAttributes();
1406 TXMLAttr* curAttr = nullptr;
1407 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
1408
1409 // Get the Name, Val of this node
1410 TString attrName = curAttr->GetName();
1411 std::string attrVal = curAttr->GetValue();
1412
1413 if( attrName == TString( "" ) ){
1414 cxcoutEHF << "Error: Encountered Element in ActivateStatError with no name" << std::endl;
1415 throw hf_exc();
1416 }
1417
1418 else if( attrName == TString( "Activate" ) ) {
1419 statError.Activate( CheckTrueFalse(attrVal,"ActivateStatError") );
1420 }
1421
1422 else if( attrName == TString( "HistoName" ) ) {
1423 statError.SetHistoName( attrVal );
1424 }
1425
1426 else if( attrName == TString( "HistoPath" ) ) {
1427 statError.SetHistoPath( attrVal );
1428 }
1429
1430 else if( attrName == TString( "InputFile" ) ) {
1431 statError.SetInputFile( attrVal );
1432 }
1433
1434 else {
1435 cxcoutEHF << "Error: Encountered Element in ActivateStatError with unknown name: "
1436 << attrName << std::endl;
1437 throw hf_exc();
1438 }
1439
1440 } // End: Loop Over Attributes
1441
1442 // Based on the input, determine
1443 // if we should use a histogram or not:
1444 // Logic: One turns on using a histogram
1445 // by setting the attribute "HistoName"
1446 // If this is set AND the InputFile or
1447 // HistoPath aren't set, we set those
1448 // to the current default values
1449 if( !statError.GetHistoName().empty() ) {
1450 statError.SetUseHisto( true );
1451
1452 // Check that a file has been set
1453 // (Possibly using the default)
1454 if( statError.GetInputFile().empty() ) {
1455 statError.SetInputFile( m_currentInputFile );
1456 }
1457 if( statError.GetHistoPath().empty() ) {
1458 statError.SetHistoPath( m_currentHistoPath );
1459 }
1460
1461 }
1462
1463 /*
1464 if( statError.Activate ) {
1465 if( statError.UseHisto ) {
1466 }
1467 else {
1468 statError.InputFile = "";
1469 statError.HistoName = "";
1470 statError.HistoPath = "";
1471 }
1472 }
1473 */
1474
1475 statError.Print(oocoutI(nullptr, HistFactory));
1476
1477 return statError;
1478
1479}
1480
1481
1483
1484 cxcoutIHF << "Parsing FunctionConfig" << std::endl;
1485
1486 //std::string name, expression, dependents;
1487 TListIter attribIt = functionNode->GetAttributes();
1488 TXMLAttr* curAttr = nullptr;
1489
1490 std::string Name;
1491 std::string Expression;
1492 std::string Dependents;
1493
1494 // Add protection to ensure that all parts are there
1495 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != nullptr ) {
1496 if( curAttr->GetName() == TString( "Name" ) ) {
1497 Name = curAttr->GetValue();
1498 //func.SetName( curAttr->GetValue() );
1499 //name = curAttr->GetValue() ;
1500 }
1501 if( curAttr->GetName() == TString( "Expression" ) ) {
1502 Expression = curAttr->GetValue();
1503 //func.SetExpression( curAttr->GetValue() );
1504 }
1505 if( curAttr->GetName() == TString( "Dependents" ) ) {
1506 Dependents = curAttr->GetValue();
1507 //func.SetDependents( curAttr->GetValue() );
1508 }
1509 }
1510
1511 if( Name.empty() ){
1512 cxcoutEHF << "Error processing PreprocessFunction: Name attribute is empty" << std::endl;
1513 throw hf_exc();
1514 }
1515 if( Expression.empty() ){
1516 cxcoutEHF << "Error processing PreprocessFunction: Expression attribute is empty" << std::endl;
1517 throw hf_exc();
1518 }
1519 if( Dependents.empty() ){
1520 cxcoutEHF << "Error processing PreprocessFunction: Dependents attribute is empty" << std::endl;
1521 throw hf_exc();
1522 }
1523
1524 RooStats::HistFactory::PreprocessFunction func(Name, Expression, Dependents);
1525
1526 cxcoutIHF << "Created Preprocess Function: " << func.GetCommand() << std::endl;
1527
1528 //std::string command = "expr::"+func.GetName()+"('"+func.GetExpression()+"',{"+func.GetDependents()+"})";
1529 //func.SetCommand( command );
1530 // // cout << "will pre-process this line " << ret <<endl;
1531 return func;
1532
1533}
1534
1535
1537
1538 if( node->GetNodeName() == TString( "text" ) ) {
1539 return true;
1540 }
1541
1542 if( node->GetNodeName() == TString( "comment" ) ) {
1543 return true;
1544 }
1545
1546 return false;
1547
1548}
1549
1550
1551bool ConfigParser::CheckTrueFalse( std::string attrVal, std::string NodeTitle ) {
1552
1553 if( attrVal.empty() ) {
1554 cxcoutEHF << "Error: In " << NodeTitle
1555 << " Expected either 'True' or 'False' but found empty" << std::endl;
1556 throw hf_exc();
1557 }
1558 else if ( attrVal == "True" || attrVal == "true" ) return true;
1559 else if ( attrVal == "False" || attrVal == "false" ) return false;
1560 else {
1561 cxcoutEHF << "Error: In " << NodeTitle
1562 << " Expected either 'True' or 'False' but found: " << attrVal << std::endl;
1563 throw hf_exc();
1564 }
1565
1566 return false;
1567
1568}
1569
1570//ConfigParser
#define cxcoutIHF
#define cxcoutWHF
#define cxcoutEHF
#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:31
std::map< std::string, double > & GetGammaSyst()
std::map< std::string, double > & GetLogNormSyst()
std::map< std::string, double > & GetNoSyst()
std::vector< std::string > & GetPOIList()
get vector of PoI names
Definition Measurement.h:51
void SetLumi(double Lumi)
set integrated luminosity used to normalise histograms (if NormalizeByTheory is true for this sample)
Definition Measurement.h:85
void SetParamValue(const std::string &param, double value)
Set a parameter to a specific value (And optionally fix it)
std::map< std::string, double > & GetUniformSyst()
std::vector< std::string > & GetConstantParams()
get vector of all constant parameters
Definition Measurement.h:60
void SetOutputFilePrefix(const std::string &prefix)
set output prefix
Definition Measurement.h:40
void PrintTree(std::ostream &=std::cout)
Print information about measurement object in tree-like structure to given stream.
std::vector< RooStats::HistFactory::Channel > & GetChannels()
void SetLumiRelErr(double RelErr)
set relative uncertainty on luminosity
Definition Measurement.h:87
void AddAsimovDataset(RooStats::HistFactory::Asimov dataset)
add an Asimov Dataset
Definition Measurement.h:82
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:456
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 CodegenImpl.h:58