Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:38

0001 // -*- C++ -*-
0002 //
0003 // Package:    SiPixelOfflineCalibAnalysisBase
0004 // Class:      SiPixelOfflineCalibAnalysisBase
0005 //
0006 /**\class SiPixelOfflineCalibAnalysisBase SiPixelOfflineCalibAnalysisBase.h CalibTracker/SiPixelTools/src/SiPixelOfflineCalibAnalysisBase.h
0007 
0008  Description: Base class for Pixel calibrations
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Evan Klose Friis
0015 //    additions by:  Freya Blekman
0016 //         Created:  Tue Nov  6 17:27:19 CET 2007
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/ServiceRegistry/interface/Service.h"
0029 
0030 #include "DataFormats/Common/interface/DetSetVector.h"
0031 #include "DataFormats/DetId/interface/DetId.h"
0032 
0033 #include "DataFormats/SiPixelDigi/interface/SiPixelCalibDigifwd.h"
0034 #include "DataFormats/SiPixelDigi/interface/SiPixelCalibDigi.h"
0035 
0036 #include "CondFormats/SiPixelObjects/interface/SiPixelCalibConfiguration.h"
0037 #include "CondFormats/DataRecord/interface/SiPixelCalibConfigurationRcd.h"
0038 #include "CondFormats/DataRecord/interface/SiPixelFedCablingMapRcd.h"
0039 
0040 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0041 #include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
0042 
0043 #include "TF1.h"
0044 
0045 #include "DQMServices/Core/interface/DQMStore.h"
0046 #include "DQM/SiPixelCommon/interface/SiPixelHistogramId.h"
0047 #include "DQM/SiPixelCommon/interface/SiPixelFolderOrganizer.h"
0048 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0049 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0050 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h"
0051 
0052 #include <map>
0053 #include <vector>
0054 #include <iostream>
0055 #include <string>
0056 //
0057 // class decleration
0058 //
0059 
0060 class SiPixelOfflineCalibAnalysisBase : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0061 public:
0062   typedef dqm::legacy::MonitorElement MonitorElement;
0063   typedef dqm::legacy::DQMStore DQMStore;
0064   explicit SiPixelOfflineCalibAnalysisBase(const edm::ParameterSet&);
0065   ~SiPixelOfflineCalibAnalysisBase() override;
0066 
0067   //no argument constructor only used to throw exception in the case of derived
0068   //class constructor not calling SiPixelOfflineCalibAnalysisBase(const edm::ParameterSet&)
0069   SiPixelOfflineCalibAnalysisBase();
0070 
0071   //pure virtual function, called after each DetID loaded
0072   virtual bool doFits(uint32_t detid, std::vector<SiPixelCalibDigi>::const_iterator ipix);
0073 
0074   //translate DetID to human readable string
0075   std::string translateDetIdToString(uint32_t detid);
0076 
0077   //booking DQM histograms (for dynamic histogram creation)
0078 
0079   MonitorElement* bookDQMHistogram1D(
0080       uint32_t detid, std::string name, std::string title, int nchX, double lowX, double highX);
0081   MonitorElement* bookDQMHistogram1D(
0082       uint32_t detid, std::string name, std::string title, int nchX, float* xbinsize);  //variable size bins
0083   MonitorElement* bookDQMHistogram2D(uint32_t detid,
0084                                      std::string name,
0085                                      std::string title,
0086                                      int nchX,
0087                                      double lowX,
0088                                      double highX,
0089                                      int nchY,
0090                                      double lowY,
0091                                      double highY);
0092 
0093   MonitorElement* bookDQMHistoPlaquetteSummary2D(
0094       uint32_t detid,
0095       std::string name,
0096       std::string
0097           title);  // take the detid to determine the size of rows and columns, this saves looking up everything in the cabling map by the user.
0098   void addTF1ToDQMMonitoringElement(MonitorElement* ele, TF1* func);
0099 
0100   bool setDQMDirectory(std::string dirName);
0101   bool setDQMDirectory(uint32_t detID);  //automatically create directory hierachy based on DetID
0102   static TF1* fitFunction_;
0103   static const std::vector<short>* getVcalValues();
0104   std::vector<uint32_t>& getRunNumbers() { return runnumbers_; }
0105 
0106 protected:
0107   //calibration parameters from calib.dat/DB
0108   edm::ESHandle<SiPixelCalibConfiguration> calib_;
0109   edm::ESHandle<TrackerGeometry> geom_;
0110   edm::ESHandle<SiPixelFedCablingMap> theCablingMap_;
0111 
0112   edm::ESGetToken<SiPixelCalibConfiguration, SiPixelCalibConfigurationRcd> calibTokenBeginRun_;
0113   edm::ESGetToken<SiPixelCalibConfiguration, SiPixelCalibConfigurationRcd> calibToken_;
0114   edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> trackerGeomToken_;
0115   edm::ESGetToken<SiPixelFedCablingMap, SiPixelFedCablingMapRcd> cablingMapToken_;
0116 
0117   std::string calibrationMode_;
0118   short nTriggers_;
0119   static std::vector<short> vCalValues_;
0120   uint32_t& EventNumber() { return eventCounter_; }
0121 
0122 private:
0123   SiPixelFolderOrganizer* folderMaker_;
0124   DQMStore* daqBE_;
0125   SiPixelHistogramId* theHistogramIdWorker_;
0126   std::string outputFileName_;
0127   bool createOutputFile_;
0128 
0129   std::vector<uint32_t> runnumbers_;
0130   uint32_t eventCounter_;
0131 
0132   //store set of detIDs that have been encountered
0133   //second int argument can be a derived class result flag
0134   std::map<uint32_t, int> detIdsEntered_;
0135   std::map<uint32_t, std::string> detIdNames_;
0136 
0137   edm::InputTag siPixelCalibDigiProducer_;
0138 
0139   edm::EDGetTokenT<edm::DetSetVector<SiPixelCalibDigi> > tPixelCalibDigi;
0140 
0141   //the beginJob is used to load the calib database.  It then calls the pure
0142   //virtual calibrationSetup() function.  Derived classes should put beginJob functionality there.
0143   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0144   void endRun(const edm::Run&, const edm::EventSetup&) override;
0145   void beginJob() override;
0146 
0147   //calibrationSetup will be used by derived classes
0148   virtual void calibrationSetup(const edm::EventSetup& iSetup);
0149 
0150   // pure virtual function, checks if the calibration analyzer is of the right type wrt the calibration information in the database (as defined in the calibrationMode_ variable). Should be implemented in each analyzer, if false will not do anything in analyze loop. default returns true.
0151   virtual bool checkCorrectCalibrationType();
0152 
0153   //called when new DetID discovered
0154   virtual void newDetID(uint32_t detid);
0155 
0156   void analyze(const edm::Event&, const edm::EventSetup&) override;
0157   // the endJob method is used to save things like histograms etc.
0158   // for additional actions derived classes should use the calibrationEnd() method for endJob functionality.
0159   void endJob() override;
0160   // calibrationEnd() will be used by derived classes
0161   virtual void calibrationEnd();
0162 
0163   // checkPixel returns whether a particular pixel is to be expected during the entire run..
0164   bool checkPixel(uint32_t detid, short row, short column);
0165 };