26 using namespace RooStats;
27 using namespace HistFactory;
31 std::vector< RooStats::HistFactory::Measurement > ConfigParser::GetMeasurementsFromXML(
string input ) {
41 std::vector< HistFactory::Measurement > measurement_list;
47 Int_t parseError = xmlparser.ParseFile( input.c_str() );
49 std::cerr <<
"Loading of xml document \"" << input
50 <<
"\" failed" << std::endl;
56 cout <<
"reading input : " << input << endl;
57 TXMLDocument* xmldoc = xmlparser.GetXMLDocument();
58 TXMLNode* rootNode = xmldoc->GetRootNode();
62 if( rootNode->GetNodeName() != TString(
"Combination" ) ){
63 std::cout <<
"Error: Driver DOCTYPE not equal to 'Combination'" << std::endl;
68 std::string OutputFilePrefix;
70 TListIter attribIt = rootNode->GetAttributes();
71 TXMLAttr* curAttr = 0;
72 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
75 TString attrName = curAttr->GetName();
76 std::string attrVal = curAttr->GetValue();
78 if( attrName == TString(
"" ) ) {
79 std::cout <<
" Error: Attribute for 'Combination' with no name found" << std::endl;
83 else if( attrName == TString(
"OutputFilePrefix" ) ) {
84 OutputFilePrefix = string(curAttr->GetValue());
85 std::cout <<
"output file prefix is : " << OutputFilePrefix << endl;
95 std::cout <<
" Error: Unknown attribute for 'Combination' encountered: "
96 << attrName << std::endl;
104 TXMLNode* node = NULL;
109 std::vector< std::string > xml_channel_files;
110 node = rootNode->GetChildren();
112 if( node->GetNodeName() == TString(
"Input" ) ) {
113 if( node->GetText() == NULL ) {
114 std::cout <<
"Error: node: " << node->GetName()
115 <<
" has no text." << std::endl;
118 xml_channel_files.push_back(node->GetText());
120 node = node->GetNextNode();
124 if(xml_channel_files.empty()){
125 cerr <<
"no input channels found" << endl;
130 std::cout <<
"Found Channels: ";
131 for(
unsigned int i=0; i < xml_channel_files.size(); ++i ) std::cout <<
" " << xml_channel_files.at(i);
132 std::cout << std::endl;
144 std::vector< RooStats::HistFactory::PreprocessFunction > functionObjects;
146 node = rootNode->GetChildren();
148 if( node->GetNodeName() == TString(
"Function" ) ) {
152 RooStats::HistFactory::PreprocessFunction Func = ParseFunctionConfig( node );
154 functionObjects.push_back( Func );
156 node = node->GetNextNode();
159 std::cout << std::endl;
163 node = rootNode->GetChildren();
166 if( node->GetNodeName() == TString(
"" ) ) {
167 std::cout <<
"Error: Node found in Measurement Driver XML with no name" << std::endl;
171 else if( node->GetNodeName() == TString(
"Measurement" ) ) {
172 HistFactory::Measurement measurement = CreateMeasurementFromDriverNode( node );
174 measurement.SetOutputFilePrefix( OutputFilePrefix );
175 measurement_list.push_back( measurement );
178 else if( node->GetNodeName() == TString(
"Function" ) ) {
183 else if( node->GetNodeName() == TString(
"Input" ) ) {
188 else if( IsAcceptableNode( node ) ) { ; }
191 std::cout <<
"Error: Unknown node found in Measurement Driver XML: "
192 << node->GetNodeName() << std::endl;
196 node = node->GetNextNode();
199 std::cout <<
"Done Processing Measurements" << std::endl;
201 if( measurement_list.size() == 0 ) {
202 std::cout <<
"Error: No Measurements found in XML Driver File" << std::endl;
206 std::cout <<
"Found Measurements: ";
207 for(
unsigned int i=0; i < measurement_list.size(); ++i ) std::cout <<
" " << measurement_list.at(i).GetName();
208 std::cout << std::endl;
216 for(
unsigned int i = 0; i < measurement_list.size(); ++i) {
217 measurement_list.at(i).SetFunctionObjects( functionObjects );
227 std::vector< HistFactory::Channel > channel_list;
230 for(
unsigned int i = 0; i < xml_channel_files.size(); ++i ) {
231 std::string channel_xml = xml_channel_files.at(i);
232 std::cout <<
"Parsing Channel: " << channel_xml << std::endl;
233 HistFactory::Channel channel = ParseChannelXMLFile( channel_xml );
238 channel_list.push_back( channel );
242 for(
unsigned int i = 0; i < measurement_list.size(); ++i) {
244 HistFactory::Measurement& measurement = measurement_list.at(i);
246 for(
unsigned int j = 0; j < channel_list.size(); ++j ) {
247 measurement.GetChannels().push_back( channel_list.at(j) );
251 catch(std::exception& e)
253 std::cout << e.what() << std::endl;
257 return measurement_list;
262 HistFactory::Measurement ConfigParser::CreateMeasurementFromDriverNode( TXMLNode* node ) {
265 HistFactory::Measurement measurement;
268 measurement.SetLumi( 1.0 );
269 measurement.SetLumiRelErr( .10 );
270 measurement.SetBinLow( 0 );
271 measurement.SetBinHigh( 1 );
272 measurement.SetExportOnly(
false );
274 std::cout <<
"Creating new measurement: " << std::endl;
277 TListIter attribIt = node->GetAttributes();
278 TXMLAttr* curAttr = 0;
279 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
281 if( curAttr->GetName() == TString(
"" ) ) {
282 std::cout <<
"Found XML attribute in Measurement with no name" << std::endl;
286 else if( curAttr->GetName() == TString(
"Name" ) ) {
288 measurement.SetName( curAttr->GetValue() );
291 else if( curAttr->GetName() == TString(
"Lumi" ) ) {
292 measurement.SetLumi( atof(curAttr->GetValue()) );
294 else if( curAttr->GetName() == TString(
"LumiRelErr" ) ) {
295 measurement.SetLumiRelErr( atof(curAttr->GetValue()) );
297 else if( curAttr->GetName() == TString(
"BinLow" ) ) {
298 measurement.SetBinLow( atoi(curAttr->GetValue()) );
300 else if( curAttr->GetName() == TString(
"BinHigh" ) ) {
301 measurement.SetBinHigh( atoi(curAttr->GetValue()) );
303 else if( curAttr->GetName() == TString(
"Mode" ) ) {
304 cout <<
"\n INFO: Mode attribute is deprecated, will ignore\n"<<endl;
306 else if( curAttr->GetName() == TString(
"ExportOnly" ) ) {
307 measurement.SetExportOnly( CheckTrueFalse(curAttr->GetValue(),
"Measurement") );
311 std::cout <<
"Found unknown XML attribute in Measurement: " << curAttr->GetName()
320 TXMLNode* child = node->GetChildren();
321 while( child != 0 ) {
323 if( child->GetNodeName() == TString(
"" ) ) {
324 std::cout <<
"Found XML child node of Measurement with no name" << std::endl;
328 else if( child->GetNodeName() == TString(
"POI" ) ) {
329 if( child->GetText() == NULL ) {
330 std::cout <<
"Error: node: " << child->GetName()
331 <<
" has no text." << std::endl;
335 AddSubStrings( measurement.GetPOIList(), child->GetText() );
338 else if( child->GetNodeName() == TString(
"ParamSetting" ) ) {
339 TListIter paramIt = child->GetAttributes();
340 TXMLAttr* curParam = 0;
341 while( ( curParam = dynamic_cast< TXMLAttr* >( paramIt() ) ) != 0 ) {
343 if( curParam->GetName() == TString(
"" ) ) {
344 std::cout <<
"Error: Found tag attribute with no name in ParamSetting" << std::endl;
347 else if( curParam->GetName() == TString(
"Const" ) ) {
348 if(curParam->GetValue()==TString(
"True")){
350 if( child->GetText() == NULL ) {
351 std::cout <<
"Error: node: " << child->GetName()
352 <<
" has no text." << std::endl;
355 AddSubStrings( measurement.GetConstantParams(), child->GetText() );
358 else if( curParam->GetName() == TString(
"Val" ) ) {
359 double val = atof(curParam->GetValue());
360 if( child->GetText() == NULL ) {
361 std::cout <<
"Error: node: " << child->GetName()
362 <<
" has no text." << std::endl;
365 std::vector<std::string> child_nodes = GetChildrenFromString(child->GetText());
366 for(
unsigned int i = 0; i < child_nodes.size(); ++i) {
367 measurement.SetParamValue( child_nodes.at(i), val);
372 std::cout <<
"Found tag attribute with unknown name in ParamSetting: "
373 << curAttr->GetName() << std::endl;
379 else if( child->GetNodeName() == TString(
"Asimov" ) ) {
386 RooStats::HistFactory::Asimov asimov;
387 std::string ParamFixString;
390 attribIt = child->GetAttributes();
392 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
394 if( curAttr->GetName() == TString(
"" ) ) {
395 std::cout <<
"Error: Found tag attribute with no name in ConstraintTerm" << std::endl;
399 else if( curAttr->GetName() == TString(
"Name" ) ) {
400 std::string name = curAttr->GetValue();
401 asimov.SetName( name );
404 else if( curAttr->GetName() == TString(
"FixParams" ) ) {
405 ParamFixString = curAttr->GetValue();
411 std::cout <<
"Found tag attribute with unknown name in ConstraintTerm: "
412 << curAttr->GetName() << std::endl;
420 if( ParamFixString==
"" ) {
421 std::cout <<
"Warning: Asimov Dataset with name: " << asimov.GetName()
422 <<
" added, but no parameters are set to be fixed" << std::endl;
425 AddParamsToAsimov( asimov, ParamFixString );
428 measurement.AddAsimovDataset( asimov );
432 else if( child->GetNodeName() == TString(
"ConstraintTerm" ) ) {
437 map<string,double> gammaSyst;
438 map<string,double> uniformSyst;
439 map<string,double> logNormSyst;
442 if( child->GetText() == NULL ) {
443 std::cout <<
"Error: node: " << child->GetName()
444 <<
" has no text." << std::endl;
447 AddSubStrings(syst, child->GetText());
450 attribIt = child->GetAttributes();
452 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
454 if( curAttr->GetName() == TString(
"" ) ) {
455 std::cout <<
"Error: Found tag attribute with no name in ConstraintTerm" << std::endl;
459 else if( curAttr->GetName() == TString(
"Type" ) ) {
460 type = curAttr->GetValue();
463 else if( curAttr->GetName() == TString(
"RelativeUncertainty" ) ) {
464 rel = atof(curAttr->GetValue());
468 std::cout <<
"Found tag attribute with unknown name in ConstraintTerm: "
469 << curAttr->GetName() << std::endl;
479 if( ! (type==
"Gamma" || type==
"Uniform" ||
480 type==
"LogNormal" || type==
"NoConstraint") ) {
481 std::cout <<
"Error: Encountered unknown type for ConstraintTerm: " << type << std::endl;
485 if (type==
"Gamma" && rel!=0) {
486 for (vector<string>::const_iterator it=syst.begin(); it!=syst.end(); ++it) {
488 measurement.GetGammaSyst()[(*it).c_str()] = rel;
492 if (type==
"Uniform" && rel!=0) {
493 for (vector<string>::const_iterator it=syst.begin(); it!=syst.end(); ++it) {
495 measurement.GetUniformSyst()[(*it).c_str()] = rel;
499 if (type==
"LogNormal" && rel!=0) {
500 for (vector<string>::const_iterator it=syst.begin(); it!=syst.end(); ++it) {
502 measurement.GetLogNormSyst()[(*it).c_str()] = rel;
506 if (type==
"NoConstraint") {
507 for (vector<string>::const_iterator it=syst.begin(); it!=syst.end(); ++it) {
509 measurement.GetNoSyst()[(*it).c_str()] = 1.0;
515 else if( IsAcceptableNode( child ) ) { ; }
518 std::cout <<
"Found XML child of Measurement with unknown name: " << child->GetNodeName()
523 child = child->GetNextNode();
526 measurement.PrintTree();
527 std::cout << std::endl;
535 HistFactory::Channel ConfigParser::ParseChannelXMLFile(
string filen ) {
543 std::cout <<
"Parsing file: " << filen ;
545 TDOMParser xmlparser;
548 Int_t parseError = xmlparser.ParseFile( filen.c_str() );
550 std::cout <<
"Loading of xml document \"" << filen
551 <<
"\" failed" << std::endl;
555 TXMLDocument* xmldoc = xmlparser.GetXMLDocument();
556 TXMLNode* rootNode = xmldoc->GetRootNode();
560 if( rootNode->GetNodeName() != TString(
"Channel" ) ){
561 std::cout <<
"Error: In parsing a Channel XML, "
562 <<
"Encounterd XML with DOCTYPE: " << rootNode->GetNodeName()
564 std::cout <<
" DOCTYPE for channels must be 'Channel' "
565 <<
" Check that your XML is properly written" << std::endl;
573 HistFactory::Channel channel;
576 channel.SetInputFile(
"" );
577 channel.SetHistoPath(
"" );
581 TListIter attribIt = rootNode->GetAttributes();
582 TXMLAttr* curAttr = 0;
583 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
586 TString attrName = curAttr->GetName();
587 std::string attrVal = curAttr->GetValue();
589 if( attrName == TString(
"" ) ) {
590 std::cout <<
" Error: Attribute for 'Channel' with no name found" << std::endl;
594 else if( attrName == TString(
"Name" ) ) {
595 channel.SetName( attrVal );
596 std::cout <<
" : creating a channel named " << channel.GetName() << std::endl;
599 else if( attrName == TString(
"InputFile" ) ) {
600 std::cout <<
"Setting InputFile for this channel: " << attrVal << std::endl;
601 channel.SetInputFile( attrVal );
603 m_currentInputFile = attrVal;
606 else if( curAttr->GetName() == TString(
"HistoPath" ) ) {
607 std::cout <<
"Setting HistoPath for this channel: " << attrVal << std::endl;
609 channel.SetHistoPath( attrVal );
610 m_currentHistoPath = attrVal;
613 else if( curAttr->GetName() == TString(
"HistoName" ) ) {
615 std::cout <<
"Use of HistoName in Channel is deprecated" << std::endl;
616 std::cout <<
"This will be ignored" << std::endl;
620 std::cout <<
" Error: Unknown attribute for 'Channel' encountered: "
621 << attrName << std::endl;
629 if( channel.GetName() ==
"" ) {
630 std::cout <<
"Error: Channel created with no name" << std::endl;
634 m_currentChannel = channel.GetName();
639 TXMLNode* node = rootNode->GetChildren();
646 m_currentInputFile = channel.GetInputFile();
647 m_currentHistoPath = channel.GetHistoPath();
649 if( node->GetNodeName() == TString(
"" ) ) {
650 std::cout <<
"Error: Encountered node in Channel with no name" << std::endl;
654 else if( node->GetNodeName() == TString(
"Data" ) ) {
656 RooStats::HistFactory::Data data = CreateDataElement(node);
657 if( data.GetName() !=
"" ) {
658 std::cout <<
"Error: You can only rename the datasets of additional data sets. "
659 <<
" Remove the 'Name=" << data.GetName() <<
"' tag"
660 <<
" from channel: " << channel.GetName() << std::endl;
663 channel.SetData( data );
667 channel.AddAdditionalData( CreateDataElement(node) );
671 else if( node->GetNodeName() == TString(
"StatErrorConfig" ) ) {
672 channel.SetStatErrorConfig( CreateStatErrorConfigElement(node) );
675 else if( node->GetNodeName() == TString(
"Sample" ) ) {
676 channel.GetSamples().push_back( CreateSampleElement(node) );
679 else if( IsAcceptableNode( node ) ) { ; }
682 std::cout <<
"Error: Encountered node in Channel with unknown name: " << node->GetNodeName() << std::endl;
686 node = node->GetNextNode();
690 std::cout <<
"Created Channel: " << std::endl;
699 HistFactory::Data ConfigParser::CreateDataElement( TXMLNode* node ) {
701 std::cout <<
"Creating Data Element" << std::endl;
703 HistFactory::Data data;
706 data.SetInputFile( m_currentInputFile );
707 data.SetHistoPath( m_currentHistoPath );
711 TListIter attribIt = node->GetAttributes();
712 TXMLAttr* curAttr = 0;
713 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
716 TString attrName = curAttr->GetName();
717 std::string attrVal = curAttr->GetValue();
719 if( attrName == TString(
"" ) ) {
720 std::cout <<
" Error: Attribute for 'Data' with no name found" << std::endl;
724 else if( attrName == TString(
"Name" ) ) {
725 data.SetName( attrVal );
728 else if( attrName == TString(
"InputFile" ) ) {
729 data.SetInputFile( attrVal );
732 else if( attrName == TString(
"HistoName" ) ) {
733 data.SetHistoName( attrVal );
736 else if( attrName == TString(
"HistoPath" ) ) {
737 data.SetHistoPath( attrVal );
740 else if( IsAcceptableNode( node ) ) { ; }
743 std::cout <<
" Error: Unknown attribute for 'Data' encountered: " << attrName << std::endl;
750 if( data.GetInputFile() ==
"" ) {
751 std::cout <<
"Error: Data Node has no InputFile" << std::endl;
754 if( data.GetHistoName() ==
"" ) {
755 std::cout <<
"Error: Data Node has no HistoName" << std::endl;
759 std::cout <<
"Created Data Node with"
760 <<
" InputFile: " << data.GetInputFile()
761 <<
" HistoName: " << data.GetHistoName()
762 <<
" HistoPath: " << data.GetHistoPath();
763 if( data.GetName() !=
"") std::cout <<
" Name: " << data.GetName();
764 std::cout << std::endl;
773 HistFactory::StatErrorConfig ConfigParser::CreateStatErrorConfigElement( TXMLNode* node ) {
775 std::cout <<
"Creating StatErrorConfig Element" << std::endl;
777 HistFactory::StatErrorConfig config;
780 config.SetConstraintType( Constraint::Gaussian );
781 config.SetRelErrorThreshold( 0.05 );
784 TListIter attribIt = node->GetAttributes();
785 TXMLAttr* curAttr = 0;
786 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
789 TString attrName = curAttr->GetName();
790 std::string attrVal = curAttr->GetValue();
792 if( attrName == TString(
"RelErrorThreshold" ) ) {
793 config.SetRelErrorThreshold( atof(attrVal.c_str()) );
796 if( attrName == TString(
"ConstraintType" ) ) {
799 if( attrVal ==
"" ) {
800 std::cout <<
"Error: Bad Value for StatErrorConfig Constraint Type Found" << std::endl;
804 else if( attrVal==
"Gaussian" || attrVal==
"Gauss" ) {
805 config.SetConstraintType( Constraint::Gaussian );
808 else if( attrVal==
"Poisson" || attrVal==
"Pois" ) {
809 config.SetConstraintType( Constraint::Poisson );
812 else if( IsAcceptableNode( node ) ) { ; }
815 cout <<
"Invalid Stat Constraint Type: " << curAttr->GetValue() << endl;
821 std::cout <<
"Created StatErrorConfig Element with"
822 <<
" Constraint type: " << config.GetConstraintType()
823 <<
" RelError Threshold: " << config.GetRelErrorThreshold()
831 HistFactory::Sample ConfigParser::CreateSampleElement( TXMLNode* node ) {
833 std::cout <<
"Creating Sample Element" << std::endl;
835 HistFactory::Sample sample;
838 sample.SetInputFile( m_currentInputFile );
839 sample.SetHistoPath( m_currentHistoPath );
840 sample.SetChannelName( m_currentChannel );
841 sample.SetNormalizeByTheory(
true );
846 TListIter attribIt = node->GetAttributes();
847 TXMLAttr* curAttr = 0;
848 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
851 TString attrName = curAttr->GetName();
852 std::string attrVal = curAttr->GetValue();
854 if( attrName == TString(
"" ) ) {
855 std::cout <<
" Error: Attribute for 'Sample' with no name found" << std::endl;
859 else if( attrName == TString(
"Name" ) ) {
860 sample.SetName( attrVal );
863 else if( attrName == TString(
"InputFile" ) ) {
864 sample.SetInputFile( attrVal );
865 m_currentInputFile = attrVal;
868 else if( attrName == TString(
"HistoName" ) ) {
869 sample.SetHistoName( attrVal );
872 else if( attrName == TString(
"HistoPath" ) ) {
873 sample.SetHistoPath( attrVal );
874 m_currentHistoPath = attrVal;
877 else if( attrName == TString(
"NormalizeByTheory" ) ) {
878 sample.SetNormalizeByTheory( CheckTrueFalse(attrVal,
"Sample") );
895 std::cout <<
" Error: Unknown attribute for 'Sample' encountered: " << attrName << std::endl;
901 if( sample.GetName() ==
"" ) {
902 std::cout <<
"Error: Sample Node has no Name" << std::endl;
905 if( sample.GetInputFile() ==
"" ) {
906 std::cout <<
"Error: Sample Node has no InputFile" << std::endl;
909 if( sample.GetHistoName() ==
"" ) {
910 std::cout <<
"Error: Sample Node has no HistoName" << std::endl;
917 TXMLNode* child = node->GetChildren();
919 while( child != 0 ) {
921 if( child->GetNodeName() == TString(
"" ) ) {
922 std::cout <<
"Error: Encountered node in Sample with no name" << std::endl;
926 else if( child->GetNodeName() == TString(
"NormFactor" ) ) {
927 sample.GetNormFactorList().push_back( MakeNormFactor( child ) );
930 else if( child->GetNodeName() == TString(
"OverallSys" ) ) {
931 sample.GetOverallSysList().push_back( MakeOverallSys( child ) );
934 else if( child->GetNodeName() == TString(
"HistoSys" ) ) {
935 sample.GetHistoSysList().push_back( MakeHistoSys( child ) );
938 else if( child->GetNodeName() == TString(
"HistoFactor" ) ) {
939 std::cout <<
"WARNING: HistoFactor not yet supported" << std::endl;
943 else if( child->GetNodeName() == TString(
"ShapeSys" ) ) {
944 sample.GetShapeSysList().push_back( MakeShapeSys( child ) );
947 else if( child->GetNodeName() == TString(
"ShapeFactor" ) ) {
948 sample.GetShapeFactorList().push_back( MakeShapeFactor( child ) );
951 else if( child->GetNodeName() == TString(
"StatError" ) ) {
952 sample.SetStatError( ActivateStatError(child) );
955 else if( IsAcceptableNode( child ) ) { ; }
958 std::cout <<
"Error: Encountered node in Sample with unknown name: " << child->GetNodeName() << std::endl;
962 child=child->GetNextNode();
965 std::cout <<
"Created Sample Node with"
966 <<
" Name: " << sample.GetName()
967 <<
" InputFile: " << sample.GetInputFile()
968 <<
" HistoName: " << sample.GetHistoName()
969 <<
" HistoPath: " << sample.GetHistoPath()
978 HistFactory::NormFactor ConfigParser::MakeNormFactor( TXMLNode* node ) {
980 std::cout <<
"Making NormFactor:" << std::endl;
982 HistFactory::NormFactor norm;
984 TListIter attribIt = node->GetAttributes();
985 TXMLAttr* curAttr = 0;
986 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
989 TString attrName = curAttr->GetName();
990 std::string attrVal = curAttr->GetValue();
992 if( attrName == TString(
"" ) ){
993 std::cout <<
"Error: Encountered Element in NormFactor with no name" << std::endl;
997 else if( curAttr->GetName() == TString(
"Name" ) ) {
998 norm.SetName( attrVal );
1000 else if( curAttr->GetName() == TString(
"Val" ) ) {
1001 norm.SetVal( atof(attrVal.c_str()) );
1003 else if( curAttr->GetName() == TString(
"Low" ) ) {
1004 norm.SetLow( atof(attrVal.c_str()) );
1006 else if( curAttr->GetName() == TString(
"High" ) ) {
1007 norm.SetHigh( atof(attrVal.c_str()) );
1009 else if( curAttr->GetName() == TString(
"Const" ) ) {
1010 norm.SetConst( CheckTrueFalse(attrVal,
"NormFactor") );
1014 std::cout <<
"Error: Encountered Element in NormFactor with unknown name: "
1015 << attrName << std::endl;
1021 if( norm.GetName() ==
"" ) {
1022 std::cout <<
"Error: NormFactor Node has no Name" << std::endl;
1026 if( norm.GetLow() >= norm.GetHigh() ) {
1027 std::cout <<
"Error: NormFactor: " << norm.GetName()
1028 <<
" has lower limit >= its upper limit: "
1029 <<
" Lower: " << norm.GetLow()
1030 <<
" Upper: " << norm.GetHigh()
1031 <<
". Please Fix" << std::endl;
1034 if( norm.GetVal() > norm.GetHigh() || norm.GetVal() < norm.GetLow() ) {
1035 std::cout <<
"Error: NormFactor: " << norm.GetName()
1036 <<
" has initial value not within its range: "
1037 <<
" Val: " << norm.GetVal()
1038 <<
" Lower: " << norm.GetLow()
1039 <<
" Upper: " << norm.GetHigh()
1040 <<
". Please Fix" << std::endl;
1050 HistFactory::HistoFactor ConfigParser::MakeHistoFactor( TXMLNode* ) {
1052 std::cout <<
"Making HistoFactor" << std::endl;
1054 HistFactory::HistoFactor dummy;
1056 dummy.SetInputFileLow( m_currentInputFile );
1057 dummy.SetHistoPathLow( m_currentHistoPath );
1059 dummy.SetInputFileHigh( m_currentInputFile );
1060 dummy.SetHistoPathHigh( m_currentHistoPath );
1062 std::cout <<
"Made HistoFactor" << std::endl;
1069 HistFactory::HistoSys ConfigParser::MakeHistoSys( TXMLNode* node ) {
1071 std::cout <<
"Making HistoSys:" << std::endl;
1073 HistFactory::HistoSys histoSys;
1076 histoSys.SetInputFileLow( m_currentInputFile );
1077 histoSys.SetHistoPathLow( m_currentHistoPath );
1079 histoSys.SetInputFileHigh( m_currentInputFile );
1080 histoSys.SetHistoPathHigh( m_currentHistoPath );
1082 TListIter attribIt = node->GetAttributes();
1083 TXMLAttr* curAttr = 0;
1092 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
1095 TString attrName = curAttr->GetName();
1096 std::string attrVal = curAttr->GetValue();
1098 if( attrName == TString(
"" ) ){
1099 std::cout <<
"Error: Encountered Element in HistoSys with no name" << std::endl;
1103 else if( curAttr->GetName() == TString(
"Name" ) ) {
1104 histoSys.SetName( attrVal );
1107 else if( curAttr->GetName() == TString(
"HistoFileHigh" ) ) {
1108 histoSys.SetInputFileHigh( attrVal );
1110 else if( curAttr->GetName() == TString(
"HistoPathHigh" ) ) {
1111 histoSys.SetHistoPathHigh( attrVal );
1113 else if( curAttr->GetName() == TString(
"HistoNameHigh" ) ) {
1114 histoSys.SetHistoNameHigh( attrVal );
1117 else if( curAttr->GetName() == TString(
"HistoFileLow" ) ) {
1118 histoSys.SetInputFileLow( attrVal );
1120 else if( curAttr->GetName() == TString(
"HistoPathLow" ) ) {
1121 histoSys.SetHistoPathLow( attrVal );
1123 else if( curAttr->GetName() == TString(
"HistoNameLow" ) ) {
1124 histoSys.SetHistoNameLow( attrVal );
1128 std::cout <<
"Error: Encountered Element in HistoSys with unknown name: "
1129 << attrName << std::endl;
1136 if( histoSys.GetName() ==
"" ) {
1137 std::cout <<
"Error: HistoSys Node has no Name" << std::endl;
1140 if( histoSys.GetInputFileHigh() ==
"" ) {
1141 std::cout <<
"Error: HistoSysSample Node has no InputFileHigh" << std::endl;
1144 if( histoSys.GetInputFileLow() ==
"" ) {
1145 std::cout <<
"Error: HistoSysSample Node has no InputFileLow" << std::endl;
1148 if( histoSys.GetHistoNameHigh() ==
"" ) {
1149 std::cout <<
"Error: HistoSysSample Node has no HistoNameHigh" << std::endl;
1152 if( histoSys.GetHistoNameLow() ==
"" ) {
1153 std::cout <<
"Error: HistoSysSample Node has no HistoNameLow" << std::endl;
1165 HistFactory::OverallSys ConfigParser::MakeOverallSys( TXMLNode* node ) {
1167 std::cout <<
"Making OverallSys:" << std::endl;
1169 HistFactory::OverallSys overallSys;
1171 TListIter attribIt = node->GetAttributes();
1172 TXMLAttr* curAttr = 0;
1173 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
1176 TString attrName = curAttr->GetName();
1177 std::string attrVal = curAttr->GetValue();
1179 if( attrName == TString(
"" ) ){
1180 std::cout <<
"Error: Encountered Element in OverallSys with no name" << std::endl;
1184 else if( attrName == TString(
"Name" ) ) {
1185 overallSys.SetName( attrVal );
1187 else if( attrName == TString(
"High" ) ) {
1188 overallSys.SetHigh( atof(attrVal.c_str()) );
1190 else if( attrName == TString(
"Low" ) ) {
1191 overallSys.SetLow( atof(attrVal.c_str()) );
1195 std::cout <<
"Error: Encountered Element in OverallSys with unknown name: "
1196 << attrName << std::endl;
1202 if( overallSys.GetName() ==
"" ) {
1203 std::cout <<
"Error: Encountered OverallSys with no name" << std::endl;
1215 HistFactory::ShapeFactor ConfigParser::MakeShapeFactor( TXMLNode* node ) {
1217 std::cout <<
"Making ShapeFactor" << std::endl;
1219 HistFactory::ShapeFactor shapeFactor;
1221 TListIter attribIt = node->GetAttributes();
1222 TXMLAttr* curAttr = 0;
1228 std::string ShapeInputFile = m_currentInputFile;
1229 std::string ShapeInputPath = m_currentHistoPath;
1231 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
1234 TString attrName = curAttr->GetName();
1235 std::string attrVal = curAttr->GetValue();
1237 if( attrName == TString(
"" ) ){
1238 std::cout <<
"Error: Encountered Element in ShapeFactor with no name" << std::endl;
1242 else if( attrName == TString(
"Name" ) ) {
1243 shapeFactor.SetName( attrVal );
1245 else if( attrName == TString(
"Const" ) ) {
1246 shapeFactor.SetConstant( CheckTrueFalse(attrVal,
"ShapeFactor" ) );
1249 else if( attrName == TString(
"HistoName" ) ) {
1250 shapeFactor.SetHistoName( attrVal );
1253 else if( attrName == TString(
"InputFile" ) ) {
1254 ShapeInputFile = attrVal;
1257 else if( attrName == TString(
"HistoPath" ) ) {
1258 ShapeInputPath = attrVal;
1262 std::cout <<
"Error: Encountered Element in ShapeFactor with unknown name: "
1263 << attrName << std::endl;
1269 if( shapeFactor.GetName() ==
"" ) {
1270 std::cout <<
"Error: Encountered ShapeFactor with no name" << std::endl;
1276 if( shapeFactor.HasInitialShape() ) {
1277 if( shapeFactor.GetHistoName() ==
"" ) {
1278 std::cout <<
"Error: ShapeFactor: " << shapeFactor.GetName()
1279 <<
" is configured to have an initial shape, but "
1280 <<
"its histogram doesn't have a name"
1284 shapeFactor.SetHistoPath( ShapeInputPath );
1285 shapeFactor.SetInputFile( ShapeInputFile );
1288 shapeFactor.Print();
1295 HistFactory::ShapeSys ConfigParser::MakeShapeSys( TXMLNode* node ) {
1297 std::cout <<
"Making ShapeSys" << std::endl;
1299 HistFactory::ShapeSys shapeSys;
1302 shapeSys.SetConstraintType( Constraint::Gaussian );
1303 shapeSys.SetInputFile( m_currentInputFile );
1304 shapeSys.SetHistoPath( m_currentHistoPath );
1307 TListIter attribIt = node->GetAttributes();
1308 TXMLAttr* curAttr = 0;
1311 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
1315 TString attrName = curAttr->GetName();
1316 std::string attrVal = curAttr->GetValue();
1318 if( attrName == TString(
"" ) ){
1319 std::cout <<
"Error: Encountered Element in ShapeSys with no name" << std::endl;
1323 else if( attrName == TString(
"Name" ) ) {
1324 shapeSys.SetName( attrVal );
1327 else if( attrName == TString(
"HistoName" ) ) {
1328 shapeSys.SetHistoName( attrVal );
1331 else if( attrName == TString(
"HistoPath" ) ) {
1332 shapeSys.SetHistoPath( attrVal );
1335 else if( attrName == TString(
"InputFile" ) ) {
1336 shapeSys.SetInputFile( attrVal );
1339 else if( attrName == TString(
"ConstraintType" ) ) {
1341 std::cout <<
"Error: ShapeSys Constraint type is empty" << std::endl;
1344 else if( attrVal==
"Gaussian" || attrVal==
"Gauss" ) {
1345 shapeSys.SetConstraintType( Constraint::Gaussian );
1347 else if( attrVal==
"Poisson" || attrVal==
"Pois" ) {
1348 shapeSys.SetConstraintType( Constraint::Poisson );
1351 cout <<
"Error: Encountered unknown ShapeSys Constraint type: " << attrVal << endl;
1357 std::cout <<
"Error: Encountered Element in ShapeSys with unknown name: "
1358 << attrName << std::endl;
1365 if( shapeSys.GetName() ==
"" ) {
1366 std::cout <<
"Error: Encountered ShapeSys with no Name" << std::endl;
1369 if( shapeSys.GetInputFile() ==
"" ) {
1370 std::cout <<
"Error: Encountered ShapeSys with no InputFile" << std::endl;
1373 if( shapeSys.GetHistoName() ==
"" ) {
1374 std::cout <<
"Error: Encountered ShapeSys with no HistoName" << std::endl;
1385 HistFactory::StatError ConfigParser::ActivateStatError( TXMLNode* node ) {
1387 std::cout <<
"Activating StatError" << std::endl;
1390 HistFactory::StatError statError;
1391 statError.Activate(
false );
1392 statError.SetUseHisto(
false );
1393 statError.SetHistoName(
"" );
1396 TListIter attribIt = node->GetAttributes();
1397 TXMLAttr* curAttr = 0;
1398 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
1401 TString attrName = curAttr->GetName();
1402 std::string attrVal = curAttr->GetValue();
1404 if( attrName == TString(
"" ) ){
1405 std::cout <<
"Error: Encountered Element in ActivateStatError with no name" << std::endl;
1409 else if( attrName == TString(
"Activate" ) ) {
1410 statError.Activate( CheckTrueFalse(attrVal,
"ActivateStatError") );
1413 else if( attrName == TString(
"HistoName" ) ) {
1414 statError.SetHistoName( attrVal );
1417 else if( attrName == TString(
"HistoPath" ) ) {
1418 statError.SetHistoPath( attrVal );
1421 else if( attrName == TString(
"InputFile" ) ) {
1422 statError.SetInputFile( attrVal );
1426 std::cout <<
"Error: Encountered Element in ActivateStatError with unknown name: "
1427 << attrName << std::endl;
1440 if( statError.GetHistoName() !=
"" ) {
1441 statError.SetUseHisto(
true );
1445 if( statError.GetInputFile() ==
"" ) {
1446 statError.SetInputFile( m_currentInputFile );
1448 if( statError.GetHistoPath() ==
"" ) {
1449 statError.SetHistoPath( m_currentHistoPath );
1473 RooStats::HistFactory::PreprocessFunction ConfigParser::ParseFunctionConfig( TXMLNode* functionNode ){
1475 std::cout <<
"Parsing FunctionConfig" << std::endl;
1478 TListIter attribIt = functionNode->GetAttributes();
1479 TXMLAttr* curAttr = 0;
1481 std::string Name =
"";
1482 std::string Expression =
"";
1483 std::string Dependents =
"";
1486 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
1487 if( curAttr->GetName() == TString(
"Name" ) ) {
1488 Name = curAttr->GetValue();
1492 if( curAttr->GetName() == TString(
"Expression" ) ) {
1493 Expression = curAttr->GetValue();
1496 if( curAttr->GetName() == TString(
"Dependents" ) ) {
1497 Dependents = curAttr->GetValue();
1503 std::cout <<
"Error processing PreprocessFunction: Name attribute is empty" << std::endl;
1506 if( Expression==
"" ){
1507 std::cout <<
"Error processing PreprocessFunction: Expression attribute is empty" << std::endl;
1510 if( Dependents==
"" ){
1511 std::cout <<
"Error processing PreprocessFunction: Dependents attribute is empty" << std::endl;
1515 RooStats::HistFactory::PreprocessFunction func(Name, Expression, Dependents);
1517 std::cout <<
"Created Preprocess Function: " << func.GetCommand() << std::endl;
1527 bool ConfigParser::IsAcceptableNode( TXMLNode* node ) {
1529 if( node->GetNodeName() == TString(
"text" ) ) {
1533 if( node->GetNodeName() == TString(
"comment" ) ) {
1542 bool ConfigParser::CheckTrueFalse( std::string attrVal, std::string NodeTitle ) {
1544 if( attrVal ==
"" ) {
1545 std::cout <<
"Error: In " << NodeTitle
1546 <<
" Expected either 'True' or 'False' but found empty" << std::endl;
1549 else if ( attrVal ==
"True" || attrVal ==
"true" )
return true;
1550 else if ( attrVal ==
"False" || attrVal ==
"false" )
return false;
1552 std::cout <<
"Error: In " << NodeTitle
1553 <<
" Expected either 'True' or 'False' but found: " << attrVal << std::endl;