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