00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "Helper.h"
00024
00025 namespace RooStats{
00026 namespace HistFactory{
00027 vector<pair<string, string> > get_comb(vector<string> names){
00028 vector<pair<string, string> > list;
00029 for(vector<string>::iterator itr=names.begin(); itr!=names.end(); ++itr){
00030 vector<string>::iterator itr2=itr;
00031 for(itr2++; itr2!=names.end(); ++itr2){
00032 list.push_back(pair<string, string>(*itr, *itr2));
00033 }
00034 }
00035 return list;
00036 }
00037
00038 vector<EstimateSummary>* loadSavedInputs(TFile* outFile, string channel ){
00039 outFile->ShowStreamerInfo();
00040
00041 vector<EstimateSummary>* summaries = new vector<EstimateSummary>;
00042 outFile->cd(channel.c_str());
00043
00044
00045 TIter next(gDirectory->GetListOfKeys());
00046 EstimateSummary* summary;
00047 while ((summary=(EstimateSummary*) next())) {
00048
00049 summary->Print();
00050 cout << "was able to read summary with name " << summary->name << endl;
00051 cout << " nominal hist = " << summary->nominal << endl;
00052 if(summary->nominal)
00053 cout << " hist name = " << summary->nominal->GetName() <<endl;
00054 cout << "still ok" << endl;
00055
00056 summaries->push_back(*summary);
00057
00058
00059
00060
00061
00062
00063 }
00064 return summaries;
00065 }
00066
00067
00068 void saveInputs(TFile* outFile, string channel, vector<EstimateSummary> summaries){
00069 vector<EstimateSummary>::iterator it = summaries.begin();
00070 vector<EstimateSummary>::iterator end = summaries.end();
00071 vector<TH1F*>::iterator histIt;
00072 vector<TH1F*>::iterator histEnd;
00073 outFile->mkdir(channel.c_str());
00074
00075 for(; it!=end; ++it){
00076 if(channel != it->channel){
00077 cout << "channel mismatch" << endl;
00078 return;
00079 }
00080 outFile->cd(channel.c_str());
00081
00082
00083 it->Write();
00084
00085 gDirectory->mkdir(it->name.c_str());
00086 gDirectory->cd(it->name.c_str());
00087
00088 it->nominal->Write();
00089
00090 histIt = it->lowHists.begin();
00091 histEnd = it->lowHists.end();
00092 for(; histIt!=histEnd; ++histIt)
00093 (*histIt)->Write();
00094
00095 histIt = it->highHists.begin();
00096 histEnd = it->highHists.end();
00097 for(; histIt!=histEnd; ++histIt)
00098 (*histIt)->Write();
00099
00100 }
00101 }
00102
00103
00104 TH1F * GetHisto( TFile * inFile, const string name ){
00105
00106 if(!inFile || name.empty()){
00107 cerr << "Not all necessary info are set to access the input file. Check your config" << endl;
00108 cerr << "fileptr: " << inFile
00109 << "path/obj: " << name << endl;
00110 return 0;
00111 }
00112 #ifdef DEBUG
00113 cout << "Retrieving " << name ;
00114 #endif
00115 TH1F * ptr = (TH1F *) (inFile->Get( name.c_str() )->Clone());
00116 #ifdef DEBUG
00117 cout << " found at " << ptr << " with integral " << ptr->Integral() << " and mean " << ptr->GetMean() << endl;
00118 #endif
00119 if (ptr) ptr->SetDirectory(0);
00120
00121 return ptr;
00122
00123 }
00124
00125 TH1 * GetHisto( const string file, const string path, const string obj){
00126
00127 #ifdef DEBUG
00128 cout << "Retrieving " << file << ":" << path << obj ;
00129 #endif
00130 TFile inFile(file.c_str());
00131 TH1 * ptr = (TH1 *) (inFile.Get( (path+obj).c_str() )->Clone());
00132 #ifdef DEBUG
00133 cout << " found at " << ptr << " with integral " << ptr->Integral() << " and mean " << ptr->GetMean() << endl;
00134 #endif
00135
00136 if(!ptr){
00137 cerr << "Not all necessary info are set to access the input file. Check your config" << endl;
00138 cerr << "filename: " << file
00139 << "path: " << path
00140 << "obj: " << obj << endl;
00141 }
00142 else
00143 ptr->SetDirectory(0);
00144
00145 return ptr;
00146
00147 }
00148
00149 void AddSubStrings( vector<string> & vs, string s){
00150 const string delims("\\ ");
00151 string::size_type begIdx, endIdx;
00152 begIdx=s.find_first_not_of(delims);
00153 while(begIdx!=string::npos){
00154 endIdx=s.find_first_of(delims, begIdx);
00155 if(endIdx==string::npos) endIdx=s.length();
00156 vs.push_back(s.substr(begIdx,endIdx-begIdx));
00157 begIdx=s.find_first_not_of(delims, endIdx);
00158 }
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 }
00175 }