Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:06:34

0001 // -*- C++ -*-
0002 //
0003 // Package:    BigEventsDebugger
0004 // Class:      BigEventsDebugger
0005 //
0006 /**\class BigEventsDebugger BigEventsDebugger.cc myTKAnalyses/BigEventsDebugger/src/BigEventsDebugger.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Andrea Venturi
0015 //         Created:  Sun Nov 16 16:04:44 CET 2008
0016 // $Id: BigEventsDebugger.cc,v 1.2 2012/12/05 21:51:54 venturia Exp $
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/Run.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030 
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032 
0033 #include <vector>
0034 #include "TH1F.h"
0035 #include "TH2F.h"
0036 #include "TProfile.h"
0037 
0038 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0039 
0040 #include "FWCore/ServiceRegistry/interface/Service.h"
0041 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0042 
0043 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
0044 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
0045 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0046 #include "DataFormats/Common/interface/DetSetVector.h"
0047 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0048 
0049 #include "DPGAnalysis/SiStripTools/interface/DigiCollectionProfiler.h"
0050 
0051 //
0052 // class decleration
0053 //
0054 
0055 template <class T>
0056 class BigEventsDebugger : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0057 public:
0058   explicit BigEventsDebugger(const edm::ParameterSet&);
0059   ~BigEventsDebugger() override;
0060 
0061 private:
0062   void analyze(const edm::Event&, const edm::EventSetup&) override;
0063 
0064   // ----------member data ---------------------------
0065 
0066   DigiCollectionProfiler<T> m_digiprofiler;
0067   edm::EDGetTokenT<T> m_collectionToken;
0068   bool m_singleevents;
0069   bool m_folded;
0070   bool m_want1dHisto;
0071   bool m_wantProfile;
0072   bool m_want2dHisto;
0073 
0074   std::vector<std::string> m_labels;
0075   std::vector<TH1F*> m_hist;
0076   std::vector<TProfile*> m_hprof;
0077   std::vector<TH2F*> m_hist2d;
0078 };
0079 
0080 //
0081 // constants, enums and typedefs
0082 //
0083 
0084 //
0085 // static data member definitions
0086 //
0087 
0088 //
0089 // constructors and destructor
0090 //
0091 template <class T>
0092 BigEventsDebugger<T>::BigEventsDebugger(const edm::ParameterSet& iConfig)
0093     : m_digiprofiler(iConfig),
0094       m_collectionToken(consumes<T>(iConfig.getParameter<edm::InputTag>("collection"))),
0095       m_singleevents(iConfig.getParameter<bool>("singleEvents")),
0096       m_folded(iConfig.getUntrackedParameter<bool>("foldedStrips", false)),
0097       m_want1dHisto(iConfig.getUntrackedParameter<bool>("want1dHisto", true)),
0098       m_wantProfile(iConfig.getUntrackedParameter<bool>("wantProfile", true)),
0099       m_want2dHisto(iConfig.getUntrackedParameter<bool>("want2dHisto", false))
0100 
0101 {
0102   //now do what ever initialization is needed
0103   usesResource(TFileService::kSharedResource);
0104 
0105   std::vector<edm::ParameterSet> selconfigs = iConfig.getParameter<std::vector<edm::ParameterSet> >("selections");
0106 
0107   for (std::vector<edm::ParameterSet>::const_iterator selconfig = selconfigs.begin(); selconfig != selconfigs.end();
0108        ++selconfig) {
0109     m_labels.push_back(selconfig->getParameter<std::string>("label"));
0110   }
0111 
0112   edm::Service<TFileService> tfserv;
0113 
0114   if (!m_singleevents) {
0115     char dirname[500];
0116     sprintf(dirname, "Summary");
0117     TFileDirectory subd = tfserv->mkdir(dirname);
0118 
0119     //book histos
0120 
0121     unsigned int nbins = 768;
0122     if (m_folded)
0123       nbins = 256;
0124 
0125     for (std::vector<std::string>::const_iterator label = m_labels.begin(); label != m_labels.end(); ++label) {
0126       if (m_want1dHisto) {
0127         std::string hname = *label + "hist";
0128         std::string htitle = *label + " occupancy";
0129         m_hist.push_back(subd.make<TH1F>(hname.c_str(), htitle.c_str(), nbins, -0.5, nbins - 0.5));
0130       }
0131       if (m_wantProfile) {
0132         std::string hname = *label + "prof";
0133         std::string htitle = *label + " charge profile";
0134         m_hprof.push_back(subd.make<TProfile>(hname.c_str(), htitle.c_str(), nbins, -0.5, nbins - 0.5));
0135       }
0136       if (m_want2dHisto) {
0137         std::string hname = *label + "hist2d";
0138         std::string htitle = *label + " charge distribution";
0139         m_hist2d.push_back(subd.make<TH2F>(hname.c_str(), htitle.c_str(), nbins, -0.5, nbins - 0.5, 257, -0.5, 256.5));
0140       }
0141     }
0142   }
0143 }
0144 
0145 template <class T>
0146 BigEventsDebugger<T>::~BigEventsDebugger() {
0147   // do anything here that needs to be done at desctruction time
0148   // (e.g. close files, deallocate resources etc.)
0149 }
0150 
0151 //
0152 // member functions
0153 //
0154 
0155 // ------------ method called to for each event  ------------
0156 template <class T>
0157 void BigEventsDebugger<T>::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0158   using namespace edm;
0159 
0160   edm::Service<TFileService> tfserv;
0161 
0162   // create a folder for each event
0163 
0164   if (m_singleevents) {
0165     m_hist.clear();
0166     m_hprof.clear();
0167     m_hist2d.clear();
0168 
0169     char dirname[500];
0170     sprintf(dirname, "event_%u_%llu", iEvent.run(), iEvent.id().event());
0171     TFileDirectory subd = tfserv->mkdir(dirname);
0172 
0173     //book histos
0174 
0175     unsigned int nbins = 768;
0176     if (m_folded)
0177       nbins = 256;
0178 
0179     for (std::vector<std::string>::const_iterator label = m_labels.begin(); label != m_labels.end(); ++label) {
0180       if (m_want1dHisto) {
0181         std::string hname = *label + "hist";
0182         std::string htitle = *label + " occupancy";
0183         m_hist.push_back(subd.make<TH1F>(hname.c_str(), htitle.c_str(), nbins, -0.5, nbins - 0.5));
0184       }
0185       if (m_wantProfile) {
0186         std::string hname = *label + "prof";
0187         std::string htitle = *label + " charge profile";
0188         m_hprof.push_back(subd.make<TProfile>(hname.c_str(), htitle.c_str(), nbins, -0.5, nbins - 0.5));
0189       }
0190       if (m_want2dHisto) {
0191         std::string hname = *label + "hist2d";
0192         std::string htitle = *label + " charge distribution";
0193         m_hist2d.push_back(subd.make<TH2F>(hname.c_str(), htitle.c_str(), nbins, -0.5, nbins - 0.5, 257, -0.5, 256.5));
0194       }
0195     }
0196   }
0197 
0198   //analyze event
0199 
0200   Handle<T> digis;
0201   iEvent.getByToken(m_collectionToken, digis);
0202   m_digiprofiler.fill(digis, m_hist, m_hprof, m_hist2d);
0203 }
0204 
0205 typedef BigEventsDebugger<edmNew::DetSetVector<SiStripCluster> > ClusterBigEventsDebugger;
0206 typedef BigEventsDebugger<edm::DetSetVector<SiStripDigi> > DigiBigEventsDebugger;
0207 typedef BigEventsDebugger<edm::DetSetVector<SiStripRawDigi> > RawDigiBigEventsDebugger;
0208 
0209 //define this as a plug-in
0210 DEFINE_FWK_MODULE(ClusterBigEventsDebugger);
0211 DEFINE_FWK_MODULE(DigiBigEventsDebugger);
0212 DEFINE_FWK_MODULE(RawDigiBigEventsDebugger);