00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "TDOMParser.h"
00021
00022 #include "ConfigParser.h"
00023 #include "Helper.h"
00024
00025 using namespace RooStats;
00026 using namespace HistFactory;
00027
00028 void HistFactory::ReadXmlConfig( string filen, vector<EstimateSummary> & summary, Double_t lumi ){
00029
00030 TString lumiStr;
00031 lumiStr+=lumi;
00032 lumiStr.ReplaceAll(' ', TString());
00033
00034 std::cout << "Parsing file: " << filen ;
00035
00036 TDOMParser xmlparser;
00037 string channelName;
00038 string inputFileName;
00039 string histoName;
00040 string histoPathName;
00041
00042
00043 Int_t parseError = xmlparser.ParseFile( filen.c_str() );
00044 if( parseError ) {
00045 std::cout << "Loading of xml document \"" << filen
00046 << "\" failed" << std::endl;
00047 }
00048
00049 TXMLDocument* xmldoc = xmlparser.GetXMLDocument();
00050 TXMLNode* rootNode = xmldoc->GetRootNode();
00051
00052
00053
00054 if( rootNode->GetNodeName() == TString( "Channel" ) ){
00055
00056
00057 TListIter attribIt = rootNode->GetAttributes();
00058 TXMLAttr* curAttr = 0;
00059 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
00060 if( curAttr->GetName() == TString( "Name" ) ) {
00061
00062 channelName = curAttr->GetValue() ;
00063 std::cout << " : creating a channel named " << channelName<< std::endl;
00064 }
00065 if( curAttr->GetName() == TString( "InputFile" ) ) {
00066 inputFileName = curAttr->GetValue() ;
00067 }
00068 if( curAttr->GetName() == TString( "HistoName" ) ) {
00069 histoName = curAttr->GetValue() ;
00070 }
00071 if( curAttr->GetName() == TString( "HistoPath" ) ) {
00072 histoPathName = curAttr->GetValue() ;
00073 }
00074 }
00075
00076 string inputFileName_cache, histoName_cache, histoPathName_cache;
00077 TXMLNode* node = rootNode->GetChildren();
00078 while( node != 0 ) {
00079 if( node->GetNodeName() == TString( "Data" ) ) {
00080 inputFileName_cache=inputFileName;
00081 histoName_cache=histoName;
00082 histoPathName_cache=histoPathName;
00083 EstimateSummary data_channel;
00084 data_channel.channel=channelName;
00085 data_channel.name="Data";
00086
00087 attribIt = node->GetAttributes();
00088 curAttr = 0;
00089 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
00090 if( curAttr->GetName() == TString( "InputFile" ) ) {
00091 inputFileName = curAttr->GetValue() ;
00092 }
00093 if( curAttr->GetName() == TString( "HistoName" ) ) {
00094 histoName = curAttr->GetValue() ;
00095 }
00096 if( curAttr->GetName() == TString( "HistoPath" ) ) {
00097 histoPathName=curAttr->GetValue();
00098 }
00099 }
00100 data_channel.nominal = (TH1F*) GetHisto(inputFileName, histoPathName, histoName);
00101 summary.push_back(data_channel);
00102 inputFileName=inputFileName_cache;
00103 histoName=histoName_cache;
00104 histoPathName=histoPathName_cache;
00105
00106 }
00107 node = node->GetNextNode();
00108 }
00109 node = rootNode->GetChildren();
00110 while( node != 0 ) {
00111 if( node->GetNodeName() == TString( "Sample" ) ) {
00112 inputFileName_cache=inputFileName;
00113 histoName_cache=histoName;
00114 histoPathName_cache=histoPathName;
00115 EstimateSummary sample_channel;
00116 sample_channel.channel=channelName;
00117
00118 attribIt = node->GetAttributes();
00119 curAttr = 0;
00120 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
00121 if( curAttr->GetName() == TString( "Name" ) ) {
00122
00123 sample_channel.name=curAttr->GetValue();
00124 }
00125 if( curAttr->GetName() == TString( "InputFile" ) ) {
00126 inputFileName = curAttr->GetValue() ;
00127 }
00128 if( curAttr->GetName() == TString( "HistoName" ) ) {
00129 histoName = curAttr->GetValue() ;
00130 }
00131 if( curAttr->GetName() == TString( "HistoPath" ) ) {
00132 histoPathName=curAttr->GetValue();
00133 }
00134 if( curAttr->GetName() == TString( "NormalizeByTheory" ) ) {
00135 if((curAttr->GetValue()==TString("False"))){
00136 sample_channel.normName=lumiStr;
00137 }
00138 }
00139 }
00140 sample_channel.nominal = (TH1F*) GetHisto(inputFileName, histoPathName, histoName);
00141 TXMLNode* sys = node->GetChildren();
00142 AddSystematic(sample_channel, sys, inputFileName, histoPathName, histoName);
00143 summary.push_back(sample_channel);
00144 inputFileName=inputFileName_cache;
00145 histoName=histoName_cache;
00146 histoPathName=histoPathName_cache;
00147
00148 }
00149 node = node->GetNextNode();
00150 }
00151 }
00152
00153 else {
00154 std::cout << "Did not find 'Channel' at the root level"
00155 << std::endl;
00156 }
00157 }
00158
00159
00160 void HistFactory::AddSystematic( EstimateSummary & sample_channel, TXMLNode* node, string inputFileName, string histoPathName, string histoName){
00161
00162 while( node != 0 ) {
00163 if( node->GetNodeName() == TString( "NormFactor" ) ){
00164 TListIter attribIt = node->GetAttributes();
00165 EstimateSummary::NormFactor norm;
00166 TXMLAttr* curAttr = 0;
00167 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
00168 if( curAttr->GetName() == TString( "Name" ) ) {
00169 norm.name = curAttr->GetValue() ;
00170 }
00171 if( curAttr->GetName() == TString( "Val" ) ) {
00172 norm.val = atof(curAttr->GetValue()) ;
00173 }
00174 if( curAttr->GetName() == TString( "Low" ) ) {
00175 norm.low = atof(curAttr->GetValue()) ;
00176 }
00177 if( curAttr->GetName() == TString( "High" ) ) {
00178 norm.high = atof(curAttr->GetValue()) ;
00179 }
00180 if( curAttr->GetName() == TString( "Const" ) ) {
00181 norm.constant = (curAttr->GetValue()==TString("True"));
00182 }
00183 }
00184 sample_channel.normFactor.push_back(norm);
00185 }
00186
00187 if( node->GetNodeName() == TString( "HistoSys" ) ){
00188 TListIter attribIt = node->GetAttributes();
00189 TXMLAttr* curAttr = 0;
00190 string Name, histoPathHigh, histoPathLow,
00191 histoNameLow, histoNameHigh, inputFileHigh, inputFileLow;
00192 inputFileLow=inputFileName; inputFileHigh=inputFileName;
00193 histoPathLow=histoPathName; histoPathHigh=histoPathName;
00194 histoNameLow=histoName; histoNameHigh=histoName;
00195 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
00196 if( curAttr->GetName() == TString( "Name" ) ) {
00197 Name = curAttr->GetValue() ;
00198 }
00199 if( curAttr->GetName() == TString( "InputFileHigh" ) ) {
00200 inputFileHigh = curAttr->GetValue() ;
00201 }
00202 if( curAttr->GetName() == TString( "HistoPathHigh" ) ) {
00203 histoPathHigh = curAttr->GetValue() ;
00204 }
00205 if( curAttr->GetName() == TString( "HistoNameHigh" ) ) {
00206 histoNameHigh = curAttr->GetValue() ;
00207 }
00208 if( curAttr->GetName() == TString( "InputFileLow" ) ) {
00209 inputFileLow = curAttr->GetValue() ;
00210 }
00211 if( curAttr->GetName() == TString( "HistoPathLow" ) ) {
00212 histoPathLow = curAttr->GetValue() ;
00213 }
00214 if( curAttr->GetName() == TString( "HistoNameLow" ) ) {
00215 histoNameLow = curAttr->GetValue() ;
00216 }
00217 }
00218 sample_channel.AddSyst(Name,
00219 (TH1F*) GetHisto( inputFileLow, histoPathLow, histoNameLow),
00220 (TH1F*) GetHisto( inputFileHigh, histoPathHigh, histoNameHigh));
00221 }
00222 if( node->GetNodeName() == TString( "OverallSys" ) ){
00223 TListIter attribIt = node->GetAttributes();
00224 TXMLAttr* curAttr = 0;
00225 string Name;
00226 Double_t Low=0, High=0;
00227 while( ( curAttr = dynamic_cast< TXMLAttr* >( attribIt() ) ) != 0 ) {
00228 if( curAttr->GetName() == TString( "Name" ) ) {
00229 Name = curAttr->GetValue() ;
00230 }
00231 if( curAttr->GetName() == TString( "High" ) ) {
00232 High = atof(curAttr->GetValue()) ;
00233 }
00234 if( curAttr->GetName() == TString( "Low" ) ) {
00235 Low = atof(curAttr->GetValue()) ;
00236 }
00237 }
00238 sample_channel.overallSyst[Name] = UncertPair(Low, High);
00239 }
00240 node=node->GetNextNode();
00241 }
00242 }
00243