Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:37

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/HcalPedestalWidths.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 HcalPedestalWidthContainer : public HcalObjRepresent::HcalDataContainer<HcalPedestalWidths, HcalPedestalWidth> {
0024   public:
0025     HcalPedestalWidthContainer(std::shared_ptr<HcalPedestalWidths> payload, unsigned int run)
0026         : HcalObjRepresent::HcalDataContainer<HcalPedestalWidths, HcalPedestalWidth>(payload, run) {}
0027     float getValue(HcalPedestalWidth* ped) override {
0028       return (ped->getWidth(0) + ped->getWidth(1) + ped->getWidth(2) + ped->getWidth(3)) / 4;
0029     }
0030   };
0031 
0032   /******************************************
0033      2d plot of HCAL PedestalWidth of 1 IOV
0034   ******************************************/
0035   class HcalPedestalWidthsPlot : public cond::payloadInspector::PlotImage<HcalPedestalWidths> {
0036   public:
0037     HcalPedestalWidthsPlot()
0038         : cond::payloadInspector::PlotImage<HcalPedestalWidths>("HCAL PedestalWidth Ratios - map ") {
0039       setSingleIov(true);
0040     }
0041 
0042     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0043       auto iov = iovs.front();
0044       std::shared_ptr<HcalPedestalWidths> payload = fetchPayload(std::get<1>(iov));
0045       if (payload.get()) {
0046         HcalPedestalWidthContainer* objContainer = new HcalPedestalWidthContainer(payload, std::get<0>(iov));
0047         std::string ImageName(m_imageFileName);
0048         objContainer->getCanvasAll()->SaveAs(ImageName.c_str());
0049         return true;
0050       } else
0051         return false;
0052     }  // fill method
0053   };
0054 
0055   /**********************************************************
0056      2d plot of HCAL PedestalWidth difference between 2 IOVs
0057   **********************************************************/
0058   class HcalPedestalWidthsDiff : public cond::payloadInspector::PlotImage<HcalPedestalWidths> {
0059   public:
0060     HcalPedestalWidthsDiff()
0061         : cond::payloadInspector::PlotImage<HcalPedestalWidths>("HCAL PedestalWidth Ratios difference") {
0062       setSingleIov(false);
0063     }
0064 
0065     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0066       auto iov1 = iovs.front();
0067       auto iov2 = iovs.back();
0068 
0069       std::shared_ptr<HcalPedestalWidths> payload1 = fetchPayload(std::get<1>(iov1));
0070       std::shared_ptr<HcalPedestalWidths> payload2 = fetchPayload(std::get<1>(iov2));
0071 
0072       if (payload1.get() && payload2.get()) {
0073         HcalPedestalWidthContainer* objContainer1 = new HcalPedestalWidthContainer(payload1, std::get<0>(iov1));
0074         HcalPedestalWidthContainer* objContainer2 = new HcalPedestalWidthContainer(payload2, std::get<0>(iov2));
0075         objContainer2->Subtract(objContainer1);
0076         std::string ImageName(m_imageFileName);
0077         objContainer2->getCanvasAll()->SaveAs(ImageName.c_str());
0078         return true;
0079       } else
0080         return false;
0081     }  // fill method
0082   };
0083   /******************************************
0084      2d plot of HCAL PedestalWidth of 1 IOV
0085   ******************************************/
0086   class HcalPedestalWidthsEtaPlot : public cond::payloadInspector::PlotImage<HcalPedestalWidths> {
0087   public:
0088     HcalPedestalWidthsEtaPlot()
0089         : cond::payloadInspector::PlotImage<HcalPedestalWidths>("HCAL PedestalWidth Ratios - map ") {
0090       setSingleIov(true);
0091     }
0092 
0093     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0094       auto iov = iovs.front();
0095       std::shared_ptr<HcalPedestalWidths> payload = fetchPayload(std::get<1>(iov));
0096       if (payload.get()) {
0097         HcalPedestalWidthContainer* objContainer = new HcalPedestalWidthContainer(payload, std::get<0>(iov));
0098         std::string ImageName(m_imageFileName);
0099         objContainer->getCanvasAll("EtaProfile")->SaveAs(ImageName.c_str());
0100         return true;
0101       } else
0102         return false;
0103     }  // fill method
0104   };
0105 
0106   /**********************************************************
0107      2d plot of HCAL PedestalWidth difference between 2 IOVs
0108   **********************************************************/
0109   class HcalPedestalWidthsEtaDiff : public cond::payloadInspector::PlotImage<HcalPedestalWidths> {
0110   public:
0111     HcalPedestalWidthsEtaDiff()
0112         : cond::payloadInspector::PlotImage<HcalPedestalWidths>("HCAL PedestalWidth Ratios difference") {
0113       setSingleIov(false);
0114     }
0115 
0116     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0117       auto iov1 = iovs.front();
0118       auto iov2 = iovs.back();
0119 
0120       std::shared_ptr<HcalPedestalWidths> payload1 = fetchPayload(std::get<1>(iov1));
0121       std::shared_ptr<HcalPedestalWidths> payload2 = fetchPayload(std::get<1>(iov2));
0122 
0123       if (payload1.get() && payload2.get()) {
0124         HcalPedestalWidthContainer* objContainer1 = new HcalPedestalWidthContainer(payload1, std::get<0>(iov1));
0125         HcalPedestalWidthContainer* objContainer2 = new HcalPedestalWidthContainer(payload2, std::get<0>(iov2));
0126         objContainer2->Subtract(objContainer1);
0127         std::string ImageName(m_imageFileName);
0128         objContainer2->getCanvasAll("EtaProfile")->SaveAs(ImageName.c_str());
0129         return true;
0130       } else
0131         return false;
0132     }  // fill method
0133   };
0134   /******************************************
0135      2d plot of HCAL PedestalWidth of 1 IOV
0136   ******************************************/
0137   class HcalPedestalWidthsPhiPlot : public cond::payloadInspector::PlotImage<HcalPedestalWidths> {
0138   public:
0139     HcalPedestalWidthsPhiPlot()
0140         : cond::payloadInspector::PlotImage<HcalPedestalWidths>("HCAL PedestalWidth Ratios - map ") {
0141       setSingleIov(true);
0142     }
0143 
0144     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0145       auto iov = iovs.front();
0146       std::shared_ptr<HcalPedestalWidths> payload = fetchPayload(std::get<1>(iov));
0147       if (payload.get()) {
0148         HcalPedestalWidthContainer* objContainer = new HcalPedestalWidthContainer(payload, std::get<0>(iov));
0149         std::string ImageName(m_imageFileName);
0150         objContainer->getCanvasAll("PhiProfile")->SaveAs(ImageName.c_str());
0151         return true;
0152       } else
0153         return false;
0154     }  // fill method
0155   };
0156 
0157   /**********************************************************
0158      2d plot of HCAL PedestalWidth difference between 2 IOVs
0159   **********************************************************/
0160   class HcalPedestalWidthsPhiDiff : public cond::payloadInspector::PlotImage<HcalPedestalWidths> {
0161   public:
0162     HcalPedestalWidthsPhiDiff()
0163         : cond::payloadInspector::PlotImage<HcalPedestalWidths>("HCAL PedestalWidth Ratios difference") {
0164       setSingleIov(false);
0165     }
0166 
0167     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0168       auto iov1 = iovs.front();
0169       auto iov2 = iovs.back();
0170 
0171       std::shared_ptr<HcalPedestalWidths> payload1 = fetchPayload(std::get<1>(iov1));
0172       std::shared_ptr<HcalPedestalWidths> payload2 = fetchPayload(std::get<1>(iov2));
0173 
0174       if (payload1.get() && payload2.get()) {
0175         HcalPedestalWidthContainer* objContainer1 = new HcalPedestalWidthContainer(payload1, std::get<0>(iov1));
0176         HcalPedestalWidthContainer* objContainer2 = new HcalPedestalWidthContainer(payload2, std::get<0>(iov2));
0177         objContainer2->Subtract(objContainer1);
0178         std::string ImageName(m_imageFileName);
0179         objContainer2->getCanvasAll("PhiProfile")->SaveAs(ImageName.c_str());
0180         return true;
0181       } else
0182         return false;
0183     }  // fill method
0184   };
0185 }  // namespace
0186 
0187 // Register the classes as boost python plugin
0188 PAYLOAD_INSPECTOR_MODULE(HcalPedestalWidths) {
0189   PAYLOAD_INSPECTOR_CLASS(HcalPedestalWidthsPlot);
0190   PAYLOAD_INSPECTOR_CLASS(HcalPedestalWidthsDiff);
0191   PAYLOAD_INSPECTOR_CLASS(HcalPedestalWidthsPhiPlot);
0192   PAYLOAD_INSPECTOR_CLASS(HcalPedestalWidthsPhiDiff);
0193   PAYLOAD_INSPECTOR_CLASS(HcalPedestalWidthsEtaPlot);
0194   PAYLOAD_INSPECTOR_CLASS(HcalPedestalWidthsEtaDiff);
0195 }