CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/DPGAnalysis/SiStripTools/plugins/BigEventsDebugger.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    BigEventsDebugger
00004 // Class:      BigEventsDebugger
00005 // 
00013 //
00014 // Original Author:  Andrea Venturi
00015 //         Created:  Sun Nov 16 16:04:44 CET 2008
00016 // $Id: BigEventsDebugger.cc,v 1.2 2012/12/05 21:51:54 venturia Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDAnalyzer.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/Run.h"
00030 #include "FWCore/Framework/interface/MakerMacros.h"
00031 
00032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00033 
00034 #include <vector>
00035 #include "TH1F.h"
00036 #include "TH2F.h"
00037 #include "TProfile.h"
00038 
00039 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00040 
00041 #include "FWCore/ServiceRegistry/interface/Service.h"
00042 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00043 
00044 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
00045 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
00046 #include "DataFormats/Common/interface/DetSetVector.h"
00047 #include "DataFormats/Common/interface/DetSetVectorNew.h"
00048 
00049 #include "DPGAnalysis/SiStripTools/interface/DigiCollectionProfiler.h"
00050 
00051 //
00052 // class decleration
00053 //
00054 
00055 template <class T>
00056 class BigEventsDebugger : public edm::EDAnalyzer {
00057    public:
00058       explicit BigEventsDebugger(const edm::ParameterSet&);
00059       ~BigEventsDebugger();
00060 
00061 
00062    private:
00063       virtual void beginJob(const edm::EventSetup&) ;
00064       virtual void analyze(const edm::Event&, const edm::EventSetup&);
00065       virtual void endJob() ;
00066 
00067       // ----------member data ---------------------------
00068 
00069   DigiCollectionProfiler<T> m_digiprofiler;
00070   edm::InputTag m_collection;
00071   bool m_singleevents;
00072   bool m_folded;
00073   bool m_want1dHisto;
00074   bool m_wantProfile;
00075   bool m_want2dHisto;
00076 
00077   std::vector<std::string> m_labels;
00078   std::vector<TH1F*> m_hist;
00079   std::vector<TProfile*> m_hprof;
00080   std::vector<TH2F*> m_hist2d;
00081 
00082 };
00083 
00084 //
00085 // constants, enums and typedefs
00086 //
00087 
00088 //
00089 // static data member definitions
00090 //
00091 
00092 //
00093 // constructors and destructor
00094 //
00095 template <class T>
00096 BigEventsDebugger<T>::BigEventsDebugger(const edm::ParameterSet& iConfig):
00097   m_digiprofiler(iConfig),
00098   m_collection(iConfig.getParameter<edm::InputTag>("collection")),
00099   m_singleevents(iConfig.getParameter<bool>("singleEvents")),
00100   m_folded(iConfig.getUntrackedParameter<bool>("foldedStrips",false)),
00101   m_want1dHisto(iConfig.getUntrackedParameter<bool>("want1dHisto",true)),
00102   m_wantProfile(iConfig.getUntrackedParameter<bool>("wantProfile",true)),
00103   m_want2dHisto(iConfig.getUntrackedParameter<bool>("want2dHisto",false))
00104 
00105 {
00106    //now do what ever initialization is needed
00107 
00108   std::vector<edm::ParameterSet> selconfigs = iConfig.getParameter<std::vector<edm::ParameterSet> >("selections");
00109   
00110   for(std::vector<edm::ParameterSet>::const_iterator selconfig=selconfigs.begin();selconfig!=selconfigs.end();++selconfig) {
00111     m_labels.push_back(selconfig->getParameter<std::string>("label"));
00112   }
00113 
00114 
00115   edm::Service<TFileService> tfserv;
00116 
00117   if(!m_singleevents) {
00118     char dirname[500];
00119     sprintf(dirname,"Summary");
00120     TFileDirectory subd = tfserv->mkdir(dirname);
00121     
00122     //book histos
00123     
00124     unsigned int nbins =768;
00125     if(m_folded) nbins=256;
00126     
00127     for(std::vector<std::string>::const_iterator label=m_labels.begin(); label!=m_labels.end(); ++label) {
00128       if(m_want1dHisto) {
00129         std::string hname = *label + "hist";
00130         std::string htitle = *label + " occupancy";
00131         m_hist.push_back(subd.make<TH1F>(hname.c_str(),htitle.c_str(),nbins,-0.5,nbins-0.5));
00132       }
00133       if(m_wantProfile) {
00134         std::string hname = *label + "prof";
00135         std::string htitle = *label + " charge profile";
00136         m_hprof.push_back(subd.make<TProfile>(hname.c_str(),htitle.c_str(),nbins,-0.5,nbins-0.5));
00137       }
00138       if(m_want2dHisto) {
00139         std::string hname = *label + "hist2d";
00140         std::string htitle = *label + " charge distribution";
00141         m_hist2d.push_back(subd.make<TH2F>(hname.c_str(),htitle.c_str(),nbins,-0.5,nbins-0.5,257,-0.5,256.5));
00142       }
00143     }
00144   }
00145 }
00146 
00147 template <class T>
00148 BigEventsDebugger<T>::~BigEventsDebugger()
00149 {
00150 
00151  
00152    // do anything here that needs to be done at desctruction time
00153    // (e.g. close files, deallocate resources etc.)
00154 
00155 }
00156 
00157 
00158 //
00159 // member functions
00160 //
00161 
00162 // ------------ method called to for each event  ------------
00163 template <class T>
00164 void
00165 BigEventsDebugger<T>::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00166 {
00167    using namespace edm;
00168 
00169    edm::Service<TFileService> tfserv;
00170 
00171    // create a folder for each event
00172 
00173    if(m_singleevents) {
00174 
00175      m_hist.clear();     m_hprof.clear();     m_hist2d.clear();
00176      
00177      char dirname[500];
00178      sprintf(dirname,"event_%u_%u",iEvent.run(),iEvent.id().event());
00179      TFileDirectory subd = tfserv->mkdir(dirname);
00180      
00181      //book histos
00182      
00183      unsigned int nbins =768;
00184      if(m_folded) nbins=256;
00185      
00186      for(std::vector<std::string>::const_iterator label=m_labels.begin(); label!=m_labels.end(); ++label) {
00187        if(m_want1dHisto) {
00188          std::string hname = *label + "hist";
00189          std::string htitle = *label + " occupancy";
00190          m_hist.push_back(subd.make<TH1F>(hname.c_str(),htitle.c_str(),nbins,-0.5,nbins-0.5));
00191        }
00192        if(m_wantProfile) {
00193          std::string hname = *label + "prof";
00194          std::string htitle = *label + " charge profile";
00195          m_hprof.push_back(subd.make<TProfile>(hname.c_str(),htitle.c_str(),nbins,-0.5,nbins-0.5));
00196        }
00197        if(m_want2dHisto) {
00198          std::string hname = *label + "hist2d";
00199          std::string htitle = *label + " charge distribution";
00200          m_hist2d.push_back(subd.make<TH2F>(hname.c_str(),htitle.c_str(),nbins,-0.5,nbins-0.5,257,-0.5,256.5));
00201        }
00202      }
00203      
00204    }
00205 
00206    //analyze event
00207 
00208    Handle<T> digis;
00209    iEvent.getByLabel(m_collection,digis);
00210    m_digiprofiler.fill(digis,m_hist,m_hprof,m_hist2d);
00211 
00212 }
00213 
00214 
00215 // ------------ method called once each job just before starting event loop  ------------
00216 template <class T>
00217 void 
00218 BigEventsDebugger<T>::beginJob(const edm::EventSetup&)
00219 {
00220 }
00221 
00222 // ------------ method called once each job just after ending the event loop  ------------
00223 template <class T>
00224 void 
00225 BigEventsDebugger<T>::endJob() {
00226 }
00227 
00228 typedef BigEventsDebugger<edmNew::DetSetVector<SiStripCluster> > ClusterBigEventsDebugger;
00229 typedef BigEventsDebugger<edm::DetSetVector<SiStripDigi> > DigiBigEventsDebugger;
00230 
00231 //define this as a plug-in
00232 DEFINE_FWK_MODULE(ClusterBigEventsDebugger);
00233 DEFINE_FWK_MODULE(DigiBigEventsDebugger);