Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:25

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   GeometryInterface& geometryInterface;
0063 
0064   std::vector<SummationSpecification> specs;
0065   std::vector<Table> tables;
0066   std::vector<Table> counters;
0067 
0068   std::pair<std::string, std::string> makePathName(SummationSpecification const& s,
0069                                                    GeometryInterface::Values const&,
0070                                                    SummationStep const* upto);
0071 
0072   void fillInternal(double x,
0073                     double y,
0074                     int n_parameters,
0075                     GeometryInterface::InterestingQuantities const& iq,
0076                     std::vector<SummationStep>::iterator first,
0077                     std::vector<SummationStep>::iterator last,
0078                     AbstractHistogram& dest);
0079 
0080   void loadFromDQMStore(SummationSpecification& s, Table& t, DQMStore::IGetter& iGetter);
0081   void executeGroupBy(SummationStep const& step, Table& t, DQMStore::IBooker& iBooker, SummationSpecification const& s);
0082   void executeExtend(SummationStep const& step,
0083                      Table& t,
0084                      std::string const& reduction,
0085                      DQMStore::IBooker& iBooker,
0086                      SummationSpecification const& s);
0087 
0088 public:  // these are available in config as is, and may be used in harvesting.
0089   bool enabled;
0090   bool perLumiHarvesting;
0091   bool bookUndefined;
0092   std::string top_folder_name;
0093 
0094   std::string name;
0095   std::string title;
0096   std::string xlabel;
0097   std::string ylabel;
0098   int dimensions;
0099   int range_x_nbins;
0100   double range_x_min;
0101   double range_x_max;
0102   int range_y_nbins;
0103   double range_y_min;
0104   double range_y_max;
0105   bool statsOverflows;
0106 
0107   // can be used in "custom" harvesting in online.
0108   edm::LuminosityBlock const* lumisection = nullptr;
0109 
0110 private:
0111   // These are actually more like local variables, and they might be shadowed
0112   // by locals now and then. The point is to avoid reallocating the heap buffer
0113   // of the Values on every call.
0114   // iq/significantvalues are also used to cache the last set of columns
0115   // per-spec, to avoid unnecessary extractions.
0116   GeometryInterface::InterestingQuantities iq;
0117   // "immutable" cache
0118   std::vector<GeometryInterface::Values> significantvalues;
0119   // Direct links to the Histogram if the caching above succeeds.
0120   std::vector<AbstractHistogram*> fastpath;
0121 };
0122 
0123 #endif