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