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