Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:41

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 "CondCore/HcalPlugins/interface/HcalObjRepresent.h"
0006 
0007 // the data format of the condition to be inspected
0008 #include "CondFormats/HcalObjects/interface/HcalSiPMParameters.h"
0009 
0010 #include "TH2F.h"
0011 #include "TCanvas.h"
0012 #include "TLine.h"
0013 #include "TStyle.h"
0014 #include "TLatex.h"
0015 #include "TPave.h"
0016 #include "TPaveStats.h"
0017 #include <string>
0018 #include <fstream>
0019 #include <boost/algorithm/string/join.hpp>
0020 
0021 namespace {
0022 
0023   /********************************************
0024      printing float values of reco paramters
0025   *********************************************/
0026   class HcalSiPMParametersSummary : public cond::payloadInspector::PlotImage<HcalSiPMParameters> {
0027   public:
0028     HcalSiPMParametersSummary() : cond::payloadInspector::PlotImage<HcalSiPMParameters>("HCAL SiPMParameter Summary") {
0029       setSingleIov(true);
0030     }
0031 
0032     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0033       auto iov = iovs.front();
0034       float fcByPE, darkCurrent1, darkCurrent2, tempVal;
0035       int type1, type2;
0036       std::shared_ptr<HcalSiPMParameters> payload = fetchPayload(std::get<1>(iov));
0037       if (payload.get()) {
0038         std::string subDetName;
0039         std::vector<HcalSiPMParameter> itemsVec;
0040 
0041         //TODO: Abstract into a function that takes valMap as the argument
0042 
0043         TLatex label, val;
0044         std::vector<float> line;
0045         TLine* ll;
0046         TLine* lr;
0047         TLine* lt;
0048         TLine* lb;
0049         TCanvas* can = new TCanvas("SiPMParametersSummary", "SiPMParametersSummary", 2000, 1680);
0050         //can->cd();
0051         //HcalObjRepresent::drawTable(2,2);
0052         can->Divide(2, 2, 0, 0);
0053         int i = 1;
0054 
0055         label.SetNDC();
0056         label.SetTextAlign(26);
0057         label.SetTextSize(0.05);
0058         label.SetTextColor(2);
0059         label.DrawLatex(0.5, 0.96, Form("Hcal SiPM Parameters"));
0060 
0061         for (std::pair<std::string, std::vector<HcalSiPMParameter> > cont : (*payload).getAllContainers()) {
0062           subDetName = std::get<0>(cont);
0063           if (subDetName[0] != 'H' || subDetName == "HT")
0064             continue;
0065           itemsVec = std::get<1>(cont);
0066           type1 = type2 = fcByPE = darkCurrent1 = darkCurrent2 = -1.0;
0067           for (HcalSiPMParameter par : itemsVec) {
0068             HcalDetId detId = HcalDetId(par.rawId());
0069             int iphi = detId.iphi();
0070             int ieta = detId.ieta();
0071             int depth = detId.depth();
0072             //std::cout << "(subDet, eta, phi, depth) : type : DarkCurrent   |   (" << subDetName << ", " << std::to_string(ieta) << ", " << std::to_string(iphi) << ", " << std::to_string(depth) << ") : " << std::to_string(par.getType()) << " : " << std::to_string(par.getDarkCurrent()) << std::endl;
0073             if (iphi == 0 && ieta == 0 && depth == 0)
0074               continue;
0075             fcByPE = par.getFCByPE();
0076             tempVal = par.getDarkCurrent();
0077             if (darkCurrent1 == -1.0) {
0078               darkCurrent1 = tempVal;
0079               type1 = par.getType();
0080             } else if (darkCurrent2 == -1.0 && par.getType() != type1) {
0081               darkCurrent2 = tempVal;
0082               type2 = par.getType();
0083               //if(fcByPE != -1) break;
0084             }
0085           }
0086           if (type1 == -1) {
0087             type1 = darkCurrent1 = 0;
0088           }
0089           if (type2 == -1) {
0090             darkCurrent2 = darkCurrent1;
0091             type2 = type1;
0092           }
0093 
0094           //Fill Grid of subsystems
0095           can->cd(i);
0096           ll = new TLine(0, 0, 0, 1);
0097           ll->SetLineWidth(4);
0098           ll->Draw();
0099           lt = new TLine(0, 1, 1, 1);
0100           lt->SetLineWidth(4);
0101           lt->Draw();
0102           lb = new TLine(0, 0, 1, 0);
0103           lb->SetLineWidth(4);
0104           lb->Draw();
0105           lr = new TLine(1, 0, 1, 1);
0106           lr->SetLineWidth(4);
0107           lr->Draw();
0108 
0109           //label subsystem
0110           label.SetNDC();
0111           label.SetTextAlign(26);
0112           label.SetTextSize(0.15);
0113           label.SetTextColor(2);
0114           label.DrawLatex(0.5, 0.85, subDetName.c_str());
0115 
0116           //table filling
0117           float startPosY = 0.75, endPosY = 0.2;
0118           float startPosX = 0.10, endPosX = 0.8;
0119           std::vector<float>::iterator linEle;
0120           std::vector<std::string>::iterator linStrEle;
0121           int j = 0;
0122           float xDiff, yDiff;
0123           // Header line
0124           std::stringstream lbl1, lbl2;
0125           lbl1 << "(Type " << std::to_string(type1) << ")";
0126           lbl2 << "(Type " << std::to_string(type2) << ")";
0127           std::vector<std::string> lblline = {"fcByPE", "Dark Current", "Dark Current"};
0128           xDiff = (endPosX - startPosX) / (lblline.size() - 1);
0129           yDiff = (startPosY - endPosY);
0130 
0131           //printing header
0132           label.SetTextAlign(12);
0133           label.SetTextSize(0.05);
0134           label.SetTextColor(1);
0135           //ll = new TLine(startPosX -0.2*xDiff, startPosY, startPosX - 0.2*xDiff, startPosY - 0.5*yDiff);
0136           //ll->Draw();
0137           for (linStrEle = lblline.begin(); linStrEle != lblline.end(); ++linStrEle) {
0138             ll = new TLine(
0139                 startPosX + (j + 0.5) * xDiff, startPosY, startPosX + (j + 0.5) * xDiff, startPosY - 0.5 * yDiff);
0140             label.DrawLatex(
0141                 startPosX + (j == 0 ? -0.1 : (j - 0.4)) * xDiff, startPosY - 0.25 * yDiff, (*linStrEle).c_str());
0142             if (j == 1)
0143               label.DrawLatex(
0144                   startPosX + (j == 0 ? -0.1 : (j - 0.31)) * xDiff, startPosY - 0.34 * yDiff, (lbl1.str()).c_str());
0145             if (j == 2)
0146               label.DrawLatex(
0147                   startPosX + (j == 0 ? -0.1 : (j - 0.31)) * xDiff, startPosY - 0.34 * yDiff, (lbl2.str()).c_str());
0148             if (j < 2)
0149               ll->Draw();
0150             j++;
0151           }
0152           ll = new TLine(0, startPosY, 1, startPosY);
0153           ll->Draw();
0154           ll = new TLine(0, startPosY - 0.5 * yDiff, 1, startPosY - 0.5 * yDiff);
0155           ll->Draw();
0156 
0157           val.SetNDC();
0158           val.SetTextAlign(26);
0159           val.SetTextSize(0.055);
0160           line = {fcByPE, darkCurrent1, darkCurrent2};
0161           //ll = new TLine(startPosX -0.2*xDiff, startPosY - 0.5*yDiff, startPosX - 0.2*xDiff, startPosY - 1.5*yDiff);
0162           //ll->Draw();
0163           j = 0;
0164 
0165           for (linEle = line.begin(); linEle != line.end(); ++linEle) {
0166             ll = new TLine(startPosX + (j + 0.5) * xDiff,
0167                            startPosY - 0.5 * yDiff,
0168                            startPosX + (j + 0.5) * xDiff,
0169                            startPosY - 1.5 * yDiff);
0170             val.DrawLatex(startPosX + j * xDiff, startPosY - yDiff, HcalObjRepresent::SciNotatStr((*linEle)).c_str());
0171             if (j < 2) {
0172               ll->Draw();
0173             }
0174             j++;
0175           }
0176 
0177           i++;
0178         }
0179 
0180         std::string ImageName(m_imageFileName);
0181         can->SaveAs(ImageName.c_str());
0182         return false;
0183       } else
0184         return false;
0185     }  // fill method
0186   };
0187   //TODO: Add a Change Summary?
0188 
0189 }  // namespace
0190 
0191 // Register the classes as boost python plugin
0192 PAYLOAD_INSPECTOR_MODULE(HcalSiPMParameters) { PAYLOAD_INSPECTOR_CLASS(HcalSiPMParametersSummary); }