Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*!
0002   \file AlignPCLThresholds_PayloadInspector
0003   \Payload Inspector Plugin for Alignment PCL thresholds
0004   \author M. Musich
0005   \version $Revision: 1.0 $
0006   \date $Date: 2017/10/19 12:51:00 $
0007 */
0008 
0009 #include "CondCore/Utilities/interface/PayloadInspectorModule.h"
0010 #include "CondCore/Utilities/interface/PayloadInspector.h"
0011 #include "CondCore/CondDB/interface/Time.h"
0012 
0013 // the data format of the condition to be inspected
0014 #include "CondFormats/PCLConfig/interface/AlignPCLThresholds.h"
0015 
0016 #include <memory>
0017 #include <sstream>
0018 #include <iostream>
0019 #include <functional>
0020 
0021 // include ROOT
0022 #include "TH2F.h"
0023 #include "TLegend.h"
0024 #include "TCanvas.h"
0025 #include "TLine.h"
0026 #include "TStyle.h"
0027 
0028 namespace {
0029 
0030   enum types { DELTA, SIG, MAXMOVE, MAXERR, END_OF_TYPES };
0031 
0032   /************************************************
0033     Display of AlignPCLThresholds
0034   *************************************************/
0035   class AlignPCLThresholds_Display : public cond::payloadInspector::PlotImage<AlignPCLThresholds> {
0036   public:
0037     AlignPCLThresholds_Display()
0038         : cond::payloadInspector::PlotImage<AlignPCLThresholds>("Display of threshold parameters for SiPixelAli PCL") {
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<AlignPCLThresholds> payload = fetchPayload(std::get<1>(iov));
0045       auto alignables = payload->getAlignableList();
0046 
0047       TCanvas canvas("Alignment PCL thresholds summary", "Alignment PCL thresholds summary", 1500, 800);
0048       canvas.cd();
0049 
0050       canvas.SetTopMargin(0.07);
0051       canvas.SetBottomMargin(0.06);
0052       canvas.SetLeftMargin(0.11);
0053       canvas.SetRightMargin(0.05);
0054       canvas.Modified();
0055       canvas.SetGrid();
0056 
0057       auto Thresholds = std::make_unique<TH2F>(
0058           "Thresholds", "Alignment parameter thresholds", alignables.size(), 0, alignables.size(), 24, 0, 24);
0059       Thresholds->SetStats(false);
0060 
0061       std::function<float(types, std::string, AlignPCLThresholds::coordType)> cutFunctor =
0062           [&payload](types my_type, std::string alignable, AlignPCLThresholds::coordType coord) {
0063             float ret(-999.);
0064             switch (my_type) {
0065               case DELTA:
0066                 return payload->getCut(alignable, coord);
0067               case SIG:
0068                 return payload->getSigCut(alignable, coord);
0069               case MAXMOVE:
0070                 return payload->getMaxMoveCut(alignable, coord);
0071               case MAXERR:
0072                 return payload->getMaxErrorCut(alignable, coord);
0073               case END_OF_TYPES:
0074                 return ret;
0075               default:
0076                 return ret;
0077             }
0078           };
0079 
0080       unsigned int xBin = 0;
0081       for (const auto& alignable : alignables) {
0082         xBin++;
0083 
0084         auto xLabel = replaceAll(replaceAll(alignable, "minus", "(-)"), "plus", "(+)");
0085         Thresholds->GetXaxis()->SetBinLabel(xBin, (xLabel).c_str());
0086         unsigned int yBin = 24;
0087         for (int foo = AlignPCLThresholds::X; foo != AlignPCLThresholds::extra_DOF; foo++) {
0088           AlignPCLThresholds::coordType coord = static_cast<AlignPCLThresholds::coordType>(foo);
0089           for (int bar = types::DELTA; bar != types::END_OF_TYPES; bar++) {
0090             types type = static_cast<types>(bar);
0091             std::string theLabel = getStringFromTypeEnum(type) + getStringFromCoordEnum(coord);
0092             if (xBin == 1) {
0093               Thresholds->GetYaxis()->SetBinLabel(yBin, theLabel.c_str());
0094             }
0095 
0096             Thresholds->SetBinContent(xBin, yBin, cutFunctor(type, alignable, coord));
0097 
0098             yBin--;
0099           }  // loop on types
0100         }    // loop on coordinates
0101       }      // loop on alignables
0102 
0103       Thresholds->GetXaxis()->LabelsOption("h");
0104       Thresholds->Draw("TEXT");
0105 
0106       std::string fileName(m_imageFileName);
0107       canvas.SaveAs(fileName.c_str());
0108 
0109       return true;
0110     }
0111 
0112     /************************************************/
0113     std::string getStringFromCoordEnum(const AlignPCLThresholds::coordType& coord) {
0114       switch (coord) {
0115         case AlignPCLThresholds::X:
0116           return "X";
0117         case AlignPCLThresholds::Y:
0118           return "Y";
0119         case AlignPCLThresholds::Z:
0120           return "Z";
0121         case AlignPCLThresholds::theta_X:
0122           return "#theta_{X}";
0123         case AlignPCLThresholds::theta_Y:
0124           return "#theta_{Y}";
0125         case AlignPCLThresholds::theta_Z:
0126           return "#theta_{Z}";
0127         default:
0128           return "should never be here";
0129       }
0130     }
0131 
0132     /************************************************/
0133     std::string getStringFromTypeEnum(const types& type) {
0134       switch (type) {
0135         case types::DELTA:
0136           return "#Delta";
0137         case types::SIG:
0138           return "#Delta/#sigma ";
0139         case types::MAXMOVE:
0140           return "max. move ";
0141         case types::MAXERR:
0142           return "max. err ";
0143         default:
0144           return "should never be here";
0145       }
0146     }
0147 
0148     /************************************************/
0149     std::string replaceAll(const std::string& str, const std::string& from, const std::string& to) {
0150       std::string out(str);
0151 
0152       if (from.empty())
0153         return out;
0154       size_t start_pos = 0;
0155       while ((start_pos = out.find(from, start_pos)) != std::string::npos) {
0156         out.replace(start_pos, from.length(), to);
0157         start_pos += to.length();  // In case 'to' contains 'from', like replacing 'x' with 'yx'
0158       }
0159       return out;
0160     }
0161   };
0162 }  // namespace
0163 
0164 // Register the classes as boost python plugin
0165 PAYLOAD_INSPECTOR_MODULE(AlignPCLThresholds) { PAYLOAD_INSPECTOR_CLASS(AlignPCLThresholds_Display); }