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