Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-02 00:53:27

0001 #include "CondCore/Utilities/interface/PayloadInspectorModule.h"
0002 #include "CondCore/Utilities/interface/PayloadInspector.h"
0003 #include "CondCore/CondDB/interface/Time.h"
0004 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0005 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0006 #include "CondCore/HcalPlugins/interface/HcalObjRepresent.h"
0007 
0008 // the data format of the condition to be inspected
0009 #include "CondFormats/HcalObjects/interface/HcalPedestals.h"
0010 
0011 #include "TH2F.h"
0012 #include "TCanvas.h"
0013 #include "TLine.h"
0014 #include "TStyle.h"
0015 #include "TLatex.h"
0016 #include "TPave.h"
0017 #include "TPaveStats.h"
0018 #include <string>
0019 #include <fstream>
0020 
0021 namespace {
0022 
0023   class HcalPedestalContainer : public HcalObjRepresent::HcalDataContainer<HcalPedestals, HcalPedestal> {
0024   public:
0025     HcalPedestalContainer(std::shared_ptr<HcalPedestals> payload, unsigned int run)
0026         : HcalObjRepresent::HcalDataContainer<HcalPedestals, HcalPedestal>(payload, run) {}
0027     float getValue(const HcalPedestal* ped) override {
0028       return (ped->getValue(0) + ped->getValue(1) + ped->getValue(2) + ped->getValue(3)) / 4;
0029     }
0030   };
0031 
0032   /******************************************
0033      2d plot of HCAL Pedestal of 1 IOV
0034   ******************************************/
0035   class HcalPedestalsPlot : public cond::payloadInspector::PlotImage<HcalPedestals> {
0036   public:
0037     HcalPedestalsPlot() : cond::payloadInspector::PlotImage<HcalPedestals>("HCAL Pedestal Ratios - map ") {
0038       setSingleIov(true);
0039     }
0040 
0041     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0042       auto iov = iovs.front();
0043       std::shared_ptr<HcalPedestals> payload = fetchPayload(std::get<1>(iov));
0044       if (payload.get()) {
0045         HcalPedestalContainer* objContainer = new HcalPedestalContainer(payload, std::get<0>(iov));
0046         std::string ImageName(m_imageFileName);
0047         objContainer->getCanvasAll()->SaveAs(ImageName.c_str());
0048         return true;
0049       } else
0050         return false;
0051     }  // fill method
0052   };
0053 
0054   /**********************************************************
0055      2d plot of HCAL Pedestal difference between 2 IOVs
0056   **********************************************************/
0057   class HcalPedestalsDiff : public cond::payloadInspector::PlotImage<HcalPedestals> {
0058   public:
0059     HcalPedestalsDiff() : cond::payloadInspector::PlotImage<HcalPedestals>("HCAL Pedestal Ratios difference") {
0060       setSingleIov(false);
0061     }
0062 
0063     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0064       auto iov1 = iovs.front();
0065       auto iov2 = iovs.back();
0066 
0067       std::shared_ptr<HcalPedestals> payload1 = fetchPayload(std::get<1>(iov1));
0068       std::shared_ptr<HcalPedestals> payload2 = fetchPayload(std::get<1>(iov2));
0069 
0070       if (payload1.get() && payload2.get()) {
0071         HcalPedestalContainer* objContainer1 = new HcalPedestalContainer(payload1, std::get<0>(iov1));
0072         HcalPedestalContainer* objContainer2 = new HcalPedestalContainer(payload2, std::get<0>(iov2));
0073         objContainer2->Subtract(objContainer1);
0074         std::string ImageName(m_imageFileName);
0075         objContainer2->getCanvasAll()->SaveAs(ImageName.c_str());
0076         return true;
0077       } else
0078         return false;
0079     }  // fill method
0080   };
0081   /******************************************
0082      2d plot of HCAL Pedestal of 1 IOV
0083   ******************************************/
0084   class HcalPedestalsEtaPlot : public cond::payloadInspector::PlotImage<HcalPedestals> {
0085   public:
0086     HcalPedestalsEtaPlot() : cond::payloadInspector::PlotImage<HcalPedestals>("HCAL Pedestal Ratios - map ") {
0087       setSingleIov(true);
0088     }
0089 
0090     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0091       auto iov = iovs.front();
0092       std::shared_ptr<HcalPedestals> payload = fetchPayload(std::get<1>(iov));
0093       if (payload.get()) {
0094         HcalPedestalContainer* objContainer = new HcalPedestalContainer(payload, std::get<0>(iov));
0095         std::string ImageName(m_imageFileName);
0096         objContainer->getCanvasAll("EtaProfile")->SaveAs(ImageName.c_str());
0097         return true;
0098       } else
0099         return false;
0100     }  // fill method
0101   };
0102 
0103   /**********************************************************
0104      2d plot of HCAL Pedestal difference between 2 IOVs
0105   **********************************************************/
0106   class HcalPedestalsEtaDiff : public cond::payloadInspector::PlotImage<HcalPedestals> {
0107   public:
0108     HcalPedestalsEtaDiff() : cond::payloadInspector::PlotImage<HcalPedestals>("HCAL Pedestal Ratios difference") {
0109       setSingleIov(false);
0110     }
0111 
0112     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0113       auto iov1 = iovs.front();
0114       auto iov2 = iovs.back();
0115 
0116       std::shared_ptr<HcalPedestals> payload1 = fetchPayload(std::get<1>(iov1));
0117       std::shared_ptr<HcalPedestals> payload2 = fetchPayload(std::get<1>(iov2));
0118 
0119       if (payload1.get() && payload2.get()) {
0120         HcalPedestalContainer* objContainer1 = new HcalPedestalContainer(payload1, std::get<0>(iov1));
0121         HcalPedestalContainer* objContainer2 = new HcalPedestalContainer(payload2, std::get<0>(iov2));
0122         objContainer2->Subtract(objContainer1);
0123         std::string ImageName(m_imageFileName);
0124         objContainer2->getCanvasAll("EtaProfile")->SaveAs(ImageName.c_str());
0125         return true;
0126       } else
0127         return false;
0128     }  // fill method
0129   };
0130   /******************************************
0131      2d plot of HCAL Pedestal of 1 IOV
0132   ******************************************/
0133   class HcalPedestalsPhiPlot : public cond::payloadInspector::PlotImage<HcalPedestals> {
0134   public:
0135     HcalPedestalsPhiPlot() : cond::payloadInspector::PlotImage<HcalPedestals>("HCAL Pedestal Ratios - map ") {
0136       setSingleIov(true);
0137     }
0138 
0139     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0140       auto iov = iovs.front();
0141       std::shared_ptr<HcalPedestals> payload = fetchPayload(std::get<1>(iov));
0142       if (payload.get()) {
0143         HcalPedestalContainer* objContainer = new HcalPedestalContainer(payload, std::get<0>(iov));
0144         std::string ImageName(m_imageFileName);
0145         objContainer->getCanvasAll("PhiProfile")->SaveAs(ImageName.c_str());
0146         return true;
0147       } else
0148         return false;
0149     }  // fill method
0150   };
0151 
0152   /**********************************************************
0153      2d plot of HCAL Pedestal difference between 2 IOVs
0154   **********************************************************/
0155   class HcalPedestalsPhiDiff : public cond::payloadInspector::PlotImage<HcalPedestals> {
0156   public:
0157     HcalPedestalsPhiDiff() : cond::payloadInspector::PlotImage<HcalPedestals>("HCAL Pedestal Ratios difference") {
0158       setSingleIov(false);
0159     }
0160 
0161     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0162       auto iov1 = iovs.front();
0163       auto iov2 = iovs.back();
0164 
0165       std::shared_ptr<HcalPedestals> payload1 = fetchPayload(std::get<1>(iov1));
0166       std::shared_ptr<HcalPedestals> payload2 = fetchPayload(std::get<1>(iov2));
0167 
0168       if (payload1.get() && payload2.get()) {
0169         HcalPedestalContainer* objContainer1 = new HcalPedestalContainer(payload1, std::get<0>(iov1));
0170         HcalPedestalContainer* objContainer2 = new HcalPedestalContainer(payload2, std::get<0>(iov2));
0171         objContainer2->Subtract(objContainer1);
0172         std::string ImageName(m_imageFileName);
0173         objContainer2->getCanvasAll("PhiProfile")->SaveAs(ImageName.c_str());
0174         return true;
0175       } else
0176         return false;
0177     }  // fill method
0178   };
0179 }  // namespace
0180 
0181 // Register the classes as boost python plugin
0182 PAYLOAD_INSPECTOR_MODULE(HcalPedestals) {
0183   PAYLOAD_INSPECTOR_CLASS(HcalPedestalsPlot);
0184   PAYLOAD_INSPECTOR_CLASS(HcalPedestalsDiff);
0185   PAYLOAD_INSPECTOR_CLASS(HcalPedestalsPhiPlot);
0186   PAYLOAD_INSPECTOR_CLASS(HcalPedestalsEtaPlot);
0187   PAYLOAD_INSPECTOR_CLASS(HcalPedestalsEtaDiff);
0188   PAYLOAD_INSPECTOR_CLASS(HcalPedestalsPhiDiff);
0189 }