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