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