Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:11:23

0001 #ifndef SiPixel_HistogramManager_h
0002 #define SiPixel_HistogramManager_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     SiPixelPhase1Common
0006 // Class  :     HistogramManager
0007 //
0008 // This helper is used by the DQM plugins to create histograms for different
0009 // sub-partitions of the detector. It records all the samples that go into
0010 // histograms and takes a SummationSpecification. From these, it generates all
0011 // the histograms in the right places and with consistent labels.
0012 //
0013 // One HistogramManager records one quantity, which may be multidimensional.
0014 // A plugin can use more than one HistogramManager, which can be held in a
0015 // HistogramManagerHolder (SiPixelPhase1Base.h)
0016 //
0017 
0018 // CMSSW
0019 #include "DataFormats/DetId/interface/DetId.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 #include "FWCore/Framework/interface/Event.h"
0022 
0023 // DQM stuff
0024 #include "DQMServices/Core/interface/DQMStore.h"
0025 
0026 // Own Stuff
0027 #include "DQM/SiPixelPhase1Common/interface/SummationSpecification.h"
0028 #include "DQM/SiPixelPhase1Common/interface/GeometryInterface.h"
0029 #include "DQM/SiPixelPhase1Common/interface/AbstractHistogram.h"
0030 
0031 class HistogramManager {
0032 public:
0033   typedef dqm::legacy::DQMStore DQMStore;
0034   typedef dqm::legacy::MonitorElement MonitorElement;
0035 
0036   explicit HistogramManager(const edm::ParameterSet& iConfig, GeometryInterface& geo);
0037 
0038   void addSpec(SummationSpecification spec);
0039 
0040   // Event is only needed for time-based quantities; row, col only if strcture within module is interesting.
0041   void fill(DetId sourceModule, const edm::Event* sourceEvent = nullptr, int col = 0, int row = 0);
0042   void fill(double value, DetId sourceModule, const edm::Event* sourceEvent = nullptr, int col = 0, int row = 0);
0043   void fill(double x, double y, DetId sourceModule, const edm::Event* sourceEvent = nullptr, int col = 0, int row = 0);
0044 
0045   // This needs to be called after each event (in the analyzer) for per-event counting, like ndigis.
0046   void executePerEventHarvesting(edm::Event const* ev);
0047 
0048   // Initiate the geometry extraction and book all required frames. Requires the specs to be set.
0049   void book(DQMStore::IBooker& iBooker, edm::EventSetup const& iSetup);
0050 
0051   // These functions perform step2, for online (per lumisection) or offline (endRun) respectively.
0052   // Note that the EventSetup from PerLumi is used in offline as well, so PerLumi always has to be called first.
0053   void executePerLumiHarvesting(DQMStore::IBooker& iBooker,
0054                                 DQMStore::IGetter& iGetter,
0055                                 edm::LuminosityBlock const& lumiBlock,
0056                                 edm::EventSetup const& iSetup);
0057   void executeHarvesting(DQMStore::IBooker& iBooker, DQMStore::IGetter& iGetter);
0058 
0059   typedef std::map<GeometryInterface::Values, AbstractHistogram> Table;
0060 
0061 private:
0062   const edm::ParameterSet& iConfig;
0063   GeometryInterface& geometryInterface;
0064 
0065   std::vector<SummationSpecification> specs;
0066   std::vector<Table> tables;
0067   std::vector<Table> counters;
0068 
0069   std::pair<std::string, std::string> makePathName(SummationSpecification const& s,
0070                                                    GeometryInterface::Values const&,
0071                                                    SummationStep const* upto);
0072 
0073   void fillInternal(double x,
0074                     double y,
0075                     int n_parameters,
0076                     GeometryInterface::InterestingQuantities const& iq,
0077                     std::vector<SummationStep>::iterator first,
0078                     std::vector<SummationStep>::iterator last,
0079                     AbstractHistogram& dest);
0080 
0081   void loadFromDQMStore(SummationSpecification& s, Table& t, DQMStore::IGetter& iGetter);
0082   void executeGroupBy(SummationStep const& step, Table& t, DQMStore::IBooker& iBooker, SummationSpecification const& s);
0083   void executeExtend(SummationStep const& step,
0084                      Table& t,
0085                      std::string const& reduction,
0086                      DQMStore::IBooker& iBooker,
0087                      SummationSpecification const& s);
0088 
0089 public:  // these are available in config as is, and may be used in harvesting.
0090   bool enabled;
0091   bool perLumiHarvesting;
0092   bool bookUndefined;
0093   std::string top_folder_name;
0094 
0095   std::string name;
0096   std::string title;
0097   std::string xlabel;
0098   std::string ylabel;
0099   int dimensions;
0100   int range_x_nbins;
0101   double range_x_min;
0102   double range_x_max;
0103   int range_y_nbins;
0104   double range_y_min;
0105   double range_y_max;
0106   bool statsOverflows;
0107 
0108   // can be used in "custom" harvesting in online.
0109   edm::LuminosityBlock const* lumisection = nullptr;
0110 
0111 private:
0112   // These are actually more like local variables, and they might be shadowed
0113   // by locals now and then. The point is to avoid reallocating the heap buffer
0114   // of the Values on every call.
0115   // iq/significantvalues are also used to cache the last set of columns
0116   // per-spec, to avoid unnecessary extractions.
0117   GeometryInterface::InterestingQuantities iq;
0118   // "immutable" cache
0119   std::vector<GeometryInterface::Values> significantvalues;
0120   // Direct links to the Histogram if the caching above succeeds.
0121   std::vector<AbstractHistogram*> fastpath;
0122 };
0123 
0124 #endif