CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/HLTriggerOffline/HeavyFlavor/src/PlotCombiner.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/Frameworkfwd.h"
00002 #include "FWCore/Framework/interface/EDAnalyzer.h"
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/MakerMacros.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "FWCore/ServiceRegistry/interface/Service.h"
00007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00008 #include "FWCore/Utilities/interface/InputTag.h"
00009 #include "DQMServices/Core/interface/DQMStore.h"
00010 #include "DQMServices/Core/interface/MonitorElement.h"
00011 
00012 #include "TH1F.h"
00013 #include "TH2F.h"
00014 
00015 using namespace edm;
00016 using namespace std;
00017 
00018 class PlotCombiner : public edm::EDAnalyzer{
00019   public:
00020     PlotCombiner(const edm::ParameterSet& pset);
00021     virtual ~PlotCombiner();
00022     virtual void analyze(const edm::Event& event, const edm::EventSetup& eventSetup) {};
00023     virtual void endRun(const edm::Run &, const edm::EventSetup &);
00024   private:
00025     void makePlot(const ParameterSet& pset);
00026     DQMStore * dqmStore;
00027     string myDQMrootFolder;
00028     const VParameterSet plots;
00029 };
00030 
00031 PlotCombiner::PlotCombiner(const edm::ParameterSet& pset):
00032   myDQMrootFolder( pset.getUntrackedParameter<string>("MyDQMrootFolder") ),
00033   plots( pset.getUntrackedParameter<VParameterSet>("Plots") )
00034 {
00035 }
00036 
00037 void PlotCombiner::endRun(const edm::Run &, const edm::EventSetup &){
00038   dqmStore = Service<DQMStore>().operator->();
00039   if( !dqmStore ){
00040     LogError("HLTriggerOfflineHeavyFlavor") << "Could not find DQMStore service\n";
00041     return;
00042   }
00043   for(VParameterSet::const_iterator pset = plots.begin(); pset!=plots.end(); pset++){
00044     makePlot(*pset);
00045   }
00046 }
00047   
00048 void PlotCombiner::makePlot(const ParameterSet& pset){
00049 //get hold of MEs
00050   vector<string> inputMEnames = pset.getUntrackedParameter<vector<string> >("InputMEnames");
00051   vector<string> inputLabels = pset.getUntrackedParameter<vector<string> >("InputLabels");
00052   if( inputMEnames.size() != inputLabels.size() ){
00053     LogDebug("HLTriggerOfflineHeavyFlavor") << "Number of labels must match the histos[0]ber of InputMEnames"<<endl;
00054     return;
00055   }
00056   vector<TH1*> histos;
00057   vector<TString> labels;
00058   for(size_t i=0; i<inputMEnames.size(); i++){
00059     string MEname = myDQMrootFolder+"/"+inputMEnames[i];
00060     MonitorElement *ME = dqmStore->get(MEname);
00061     if(ME==0){
00062       LogDebug("HLTriggerOfflineHeavyFlavor") << "Could not find ME: "<<MEname<<endl;
00063       continue;
00064     }
00065     histos.push_back( ME->getTH1() );
00066     labels.push_back( inputLabels[i] );
00067   }
00068   if(histos.size()==0){
00069     return;
00070   }
00071   //figure out the output directory name
00072   string outputMEname = pset.getUntrackedParameter<string>("OutputMEname");;
00073   string outputDir = myDQMrootFolder;
00074   string::size_type slashPos = outputMEname.rfind('/');
00075   if ( string::npos != slashPos ) {
00076     outputDir += "/"+outputMEname.substr(0, slashPos);
00077     outputMEname.erase(0, slashPos+1);
00078   }
00079   dqmStore->setCurrentFolder(outputDir);
00080   //create output ME
00081   TH2F * output;
00082   if(histos[0]->GetXaxis()->GetXbins()->GetSize()==0){
00083     output = new TH2F(outputMEname.c_str(),outputMEname.c_str(),histos[0]->GetXaxis()->GetNbins(),histos[0]->GetXaxis()->GetXmin(),histos[0]->GetXaxis()->GetXmax(),histos.size(),0,histos.size());
00084   }else{
00085     output = new TH2F(outputMEname.c_str(),outputMEname.c_str(),histos[0]->GetXaxis()->GetNbins(),histos[0]->GetXaxis()->GetXbins()->GetArray(),histos.size(),0,histos.size());
00086   }
00087   output->SetTitle(outputMEname.c_str());
00088   output->SetXTitle( histos[0]->GetXaxis()->GetTitle() );
00089   output->SetStats(kFALSE);
00090   output->SetOption("colztexte");
00091   for(size_t i=0; i<histos.size(); i++){
00092     for(int j=1; j<=histos[0]->GetNbinsX(); j++){
00093       output->SetBinContent(j,i+1,histos[i]->GetBinContent(j));
00094       output->SetBinError(j,i+1,histos[i]->GetBinError(j));
00095     }
00096     output->GetYaxis()->SetBinLabel(i+1,labels[i]);
00097   }
00098   dqmStore->book2D(outputMEname,output);
00099   delete output;
00100 }
00101 
00102 PlotCombiner::~PlotCombiner(){
00103 }
00104 
00105 //define this as a plug-in
00106 DEFINE_FWK_MODULE(PlotCombiner);