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