Go to the documentation of this file.00001 #ifndef ConfigurableAnalysis_Plotter_H
00002 #define ConfigurableAnalysis_Plotter_H
00003
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005
00006 #include "TH1.h"
00007 #include "TH1F.h"
00008 #include "TH2F.h"
00009 #include "TProfile.h"
00010
00011 #include "PhysicsTools/UtilAlgos/interface/VariableHelper.h"
00012 #include "PhysicsTools/UtilAlgos/interface/CachingVariable.h"
00013 #include "PhysicsTools/UtilAlgos/interface/ConfigurableHisto.h"
00014 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00015 #include "CommonTools/Utils/interface/TFileDirectory.h"
00016 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00017
00018
00019 class Plotter {
00020 public:
00021 Plotter(){}
00022 Plotter(edm::ParameterSet iConfig){}
00023 virtual ~Plotter(){}
00024
00025 virtual void setDir(std::string dir) =0;
00026 virtual void fill(std::string subDir,const edm::Event& iEvent) =0;
00027 virtual void complete() =0;
00028 };
00029
00030
00031 class VariablePlotter : public Plotter {
00032 public:
00033 VariablePlotter(edm::ParameterSet iConfig) : currentDir_("youDidNotSetDirectoryFirst") {
00034
00035
00036
00037 edm::ParameterSet th1=iConfig.getParameter<edm::ParameterSet>("TH1s");
00038 std::vector<std::string> th1Names;
00039 th1.getParameterSetNames(th1Names);
00040 for (unsigned int iH=0;iH!=th1Names.size();++iH){
00041 std::string hname = th1Names[iH];
00042 edm::ParameterSet hPset=th1.getParameter<edm::ParameterSet>(hname);
00043 bool split=hPset.exists("splitter") || hPset.exists("splitters");
00044 if (split)
00045 master_[hname]=new SplittingConfigurableHisto(ConfigurableHisto::h1, hname, hPset);
00046 else
00047 master_[hname]=new ConfigurableHisto(ConfigurableHisto::h1, hname, hPset);
00048 }
00049
00050
00051 edm::ParameterSet tprof=iConfig.getParameter<edm::ParameterSet>("TProfiles");
00052 std::vector<std::string> tprofNames;
00053 tprof.getParameterSetNames(tprofNames);
00054 for (unsigned int iH=0;iH!=tprofNames.size();++iH){
00055 std::string hname = tprofNames[iH];
00056 edm::ParameterSet hPset=tprof.getParameter<edm::ParameterSet>(hname);
00057 bool split=hPset.exists("splitter") || hPset.exists("splitters");
00058 if (split)
00059 master_[hname]=new SplittingConfigurableHisto(ConfigurableHisto::prof, hname, hPset);
00060 else
00061 master_[hname]=new ConfigurableHisto(ConfigurableHisto::prof, hname, hPset);
00062 }
00063
00064
00065 edm::ParameterSet th2=iConfig.getParameter<edm::ParameterSet>("TH2s");
00066 std::vector<std::string> th2Names;
00067 th2.getParameterSetNames(th2Names);
00068 for (unsigned int iH=0;iH!=th2Names.size();++iH){
00069 std::string hname = th2Names[iH];
00070 edm::ParameterSet hPset=th2.getParameter<edm::ParameterSet>(hname);
00071 bool split=hPset.exists("splitter") || hPset.exists("splitters");
00072 if (split)
00073 master_[hname]=new SplittingConfigurableHisto(ConfigurableHisto::h2, hname, hPset);
00074 else
00075 master_[hname]=new ConfigurableHisto(ConfigurableHisto::h2, hname, hPset);
00076 }
00077 }
00078
00079 void setDir(std::string dir){
00080
00081 Directory & insertedDirectory = directories_[dir];
00082
00083
00084 if (!insertedDirectory.dir){
00085 insertedDirectory.dir=new TFileDirectory(edm::Service<TFileService>()->mkdir(dir));
00086 insertedDirectory.dirName=dir;
00087 }
00088
00089
00090 currentDir_=dir;
00091 }
00092
00093 void fill(std::string subDir,const edm::Event& iEvent){
00094
00095 Directory & currentDirectory= directories_[currentDir_];
00096
00097
00098 SubDirectories & currentSetOfSubDirectories=currentDirectory.subDir;
00099
00100
00101 SubDirectory * subDirectoryToUse=0;
00102 SubDirectories::iterator subDirectoryFindIterator=currentSetOfSubDirectories.find(subDir);
00103
00104
00105 if (subDirectoryFindIterator==currentSetOfSubDirectories.end()){
00106 edm::LogInfo("VariablePlotter")<<" gonna clone histograms for :"<<subDir<<" in "<<currentDir_;
00107 SubDirectory & insertedDir = currentSetOfSubDirectories[subDir];
00108 subDirectoryToUse = &insertedDir;
00109 if (!insertedDir.dir){
00110 insertedDir.dir=new TFileDirectory(currentDirectory.dir->mkdir(subDir));
00111 insertedDir.dirName=subDir;
00112 }
00113
00114
00115 DirectoryHistos::iterator masterHistogramIterator=master_.begin();
00116 DirectoryHistos::iterator masterHistogramIterator_end=master_.end();
00117 for (; masterHistogramIterator!=masterHistogramIterator_end;++masterHistogramIterator)
00118 {
00119
00120 insertedDir.histos[masterHistogramIterator->first]=masterHistogramIterator->second->clone();
00121 }
00122
00123
00124 DirectoryHistos::iterator clonedHistogramIterator=insertedDir.histos.begin();
00125 DirectoryHistos::iterator clonedHistogramIterator_end=insertedDir.histos.end();
00126 for (; clonedHistogramIterator!=clonedHistogramIterator_end;++clonedHistogramIterator)
00127 {
00128 clonedHistogramIterator->second->book(insertedDir.dir);
00129 }
00130 }
00131 else{
00132 subDirectoryToUse=&subDirectoryFindIterator->second;
00133 }
00134
00135
00136 DirectoryHistos::iterator histogramIterator=subDirectoryToUse->histos.begin();
00137 DirectoryHistos::iterator histogramIterator_end=subDirectoryToUse->histos.end();
00138 for(; histogramIterator!=histogramIterator_end;++histogramIterator)
00139 { histogramIterator->second->fill(iEvent); }
00140 }
00141
00142 ~VariablePlotter(){
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 }
00166 void complete(){
00167
00168
00169
00170 Directories::iterator dir_It = directories_.begin();
00171 Directories::iterator dir_It_end = directories_.end();
00172
00173 for (;dir_It!=dir_It_end;++dir_It){
00174 Directory & currentDirectory=dir_It->second;
00175 SubDirectories & currentSetOfSubDirectories=currentDirectory.subDir;
00176 SubDirectories::iterator subDir_It = currentSetOfSubDirectories.begin();
00177 SubDirectories::iterator subDir_It_end = currentSetOfSubDirectories.end();
00178
00179 for (;subDir_It!=subDir_It_end;++subDir_It){
00180 DirectoryHistos::iterator histogramIterator=subDir_It->second.histos.begin();
00181 DirectoryHistos::iterator histogramIterator_end=subDir_It->second.histos.end();
00182
00183 for(; histogramIterator!=histogramIterator_end;++histogramIterator)
00184 { histogramIterator->second->complete(); }
00185 }
00186 }
00187 }
00188
00189 private:
00190 typedef std::map<std::string, ConfigurableHisto *> DirectoryHistos;
00191 DirectoryHistos master_;
00192
00193 class SubDirectory {
00194 public:
00195 SubDirectory() : dirName(""),dir(0){}
00196 std::string dirName;
00197 DirectoryHistos histos;
00198 TFileDirectory * dir;
00199 };
00200 typedef std::map<std::string, SubDirectory> SubDirectories;
00201
00202 class Directory {
00203 public:
00204 Directory() : dirName(""),dir(0){}
00205 std::string dirName;
00206 SubDirectories subDir;
00207 TFileDirectory * dir;
00208 };
00209 typedef std::map<std::string, Directory> Directories;
00210
00211 std::string currentDir_;
00212 Directories directories_;
00213 };
00214
00215
00216 #include "FWCore/PluginManager/interface/PluginFactory.h"
00217 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00218
00219 typedef edmplugin::PluginFactory< Plotter* (const edm::ParameterSet&) > PlotterFactory;
00220
00221 #endif