Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:35:33

0001 /*!
0002   \file SiPixelTemplateDBObject_PayloadInspector
0003   \Payload Inspector Plugin for SiPixelTemplateDBObject
0004   \author M. Musich
0005   \version $Revision: 1.0 $
0006   \date $Date: 2020/04/16 18:00:00 $
0007 */
0008 
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 
0011 #include "CondCore/Utilities/interface/PayloadInspectorModule.h"
0012 #include "CondCore/Utilities/interface/PayloadInspector.h"
0013 #include "CondCore/CondDB/interface/Time.h"
0014 #include "CondCore/SiPixelPlugins/interface/SiPixelPayloadInspectorHelper.h"
0015 #include "CondCore/SiPixelPlugins/interface/SiPixelTemplateHelper.h"
0016 #include "DQM/TrackerRemapper/interface/Phase1PixelMaps.h"
0017 #include "CalibTracker/StandaloneTrackerTopology/interface/StandaloneTrackerTopology.h"
0018 
0019 // the data format of the condition to be inspected
0020 #include "CondFormats/SiPixelObjects/interface/SiPixelTemplateDBObject.h"
0021 #include "CondFormats/SiPixelTransient/interface/SiPixelTemplate.h"
0022 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0023 #include "DataFormats/DetId/interface/DetId.h"
0024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0025 
0026 #include <memory>
0027 #include <map>
0028 #include <sstream>
0029 #include <iostream>
0030 #include <algorithm>
0031 
0032 // include ROOT
0033 #include "TH2.h"
0034 #include "TProfile2D.h"
0035 #include "TH2Poly.h"
0036 #include "TGraph.h"
0037 #include "TH2F.h"
0038 #include "TLegend.h"
0039 #include "TCanvas.h"
0040 #include "TLine.h"
0041 #include "TGraph.h"
0042 #include "TStyle.h"
0043 #include "TLatex.h"
0044 #include "TPave.h"
0045 #include "TPaveStats.h"
0046 #include "TGaxis.h"
0047 
0048 namespace {
0049 
0050   using namespace cond::payloadInspector;
0051 
0052   /************************************************
0053     test class
0054   *************************************************/
0055   class SiPixelTemplateDBObjectTest : public Histogram1D<SiPixelTemplateDBObject, SINGLE_IOV> {
0056   public:
0057     SiPixelTemplateDBObjectTest()
0058         : Histogram1D<SiPixelTemplateDBObject, SINGLE_IOV>(
0059               "SiPixelTemplateDBObject test", "SiPixelTemplateDBObject test", 10, 0.0, 100.) {}
0060 
0061     bool fill() override {
0062       auto tag = PlotBase::getTag<0>();
0063       for (auto const& iov : tag.iovs) {
0064         std::vector<SiPixelTemplateStore> thePixelTemp_;
0065         std::shared_ptr<SiPixelTemplateDBObject> payload = Base::fetchPayload(std::get<1>(iov));
0066         if (payload.get()) {
0067           if (!SiPixelTemplate::pushfile(*payload, thePixelTemp_)) {
0068             throw cms::Exception("SiPixelTemplateDBObject_PayloadInspector")
0069                 << "\nERROR: Templates not filled correctly. Check the conditions. Using "
0070                    "SiPixelTemplateDBObject version "
0071                 << payload->version() << "\n\n";
0072           }
0073 
0074           SiPixelTemplate templ(thePixelTemp_);
0075 
0076           for (const auto& theTemp : thePixelTemp_) {
0077             std::cout << "\n\n"
0078                       << "Template ID = " << theTemp.head.ID << ", Template Version " << theTemp.head.templ_version
0079                       << ", Bfield = " << theTemp.head.Bfield << ", NTy = " << theTemp.head.NTy
0080                       << ", NTyx = " << theTemp.head.NTyx << ", NTxx = " << theTemp.head.NTxx
0081                       << ", Dtype = " << theTemp.head.Dtype << ", Bias voltage " << theTemp.head.Vbias
0082                       << ", temperature " << theTemp.head.temperature << ", fluence " << theTemp.head.fluence
0083                       << ", Q-scaling factor " << theTemp.head.qscale << ", 1/2 multi dcol threshold "
0084                       << theTemp.head.s50 << ", 1/2 single dcol threshold " << theTemp.head.ss50 << ", y Lorentz Width "
0085                       << theTemp.head.lorywidth << ", y Lorentz Bias " << theTemp.head.lorybias << ", x Lorentz width "
0086                       << theTemp.head.lorxwidth << ", x Lorentz Bias " << theTemp.head.lorxbias
0087                       << ", Q/Q_avg fractions for Qbin defs " << theTemp.head.fbin[0] << ", " << theTemp.head.fbin[1]
0088                       << ", " << theTemp.head.fbin[2] << ", pixel x-size " << theTemp.head.xsize << ", y-size "
0089                       << theTemp.head.ysize << ", zsize " << theTemp.head.zsize << "\n"
0090                       << std::endl;
0091           }
0092 
0093           std::map<unsigned int, short> templMap = payload->getTemplateIDs();
0094           for (auto const& entry : templMap) {
0095             std::cout << "DetID: " << entry.first << " template ID: " << entry.second << std::endl;
0096             templ.interpolate(entry.second, 0.f, 0.f, 1.f, 1.f);
0097 
0098             std::cout << "\t lorywidth  " << templ.lorywidth() << " lorxwidth: " << templ.lorxwidth() << " lorybias "
0099                       << templ.lorybias() << " lorxbias: " << templ.lorxbias() << "\n"
0100                       << std::endl;
0101           }
0102 
0103           fillWithValue(1.);
0104 
0105         }  // payload
0106       }  // iovs
0107       return true;
0108     }  // fill
0109   };
0110 
0111   /************************************************
0112   // testing TH2Poly classes for plotting
0113   *************************************************/
0114   template <SiPixelPI::DetType myType>
0115   class SiPixelTemplateLA : public PlotImage<SiPixelTemplateDBObject, SINGLE_IOV> {
0116     struct header_info {
0117       int ID;             //!< template ID number
0118       float lorywidth;    //!< estimate of y-lorentz width for optimal resolution
0119       float lorxwidth;    //!< estimate of x-lorentz width for optimal resolution
0120       float lorybias;     //!< estimate of y-lorentz bias
0121       float lorxbias;     //!< estimate of x-lorentz bias
0122       float Vbias;        //!< detector bias potential in Volts
0123       float temperature;  //!< detector temperature in deg K
0124       int templ_version;  //!< Version number of the template to ensure code compatibility
0125       float Bfield;       //!< Bfield in Tesla
0126       float xsize;        //!< pixel size (for future use in upgraded geometry)
0127       float ysize;        //!< pixel size (for future use in upgraded geometry)
0128       float zsize;        //!< pixel size (for future use in upgraded geometry)
0129     };
0130 
0131   public:
0132     SiPixelTemplateLA() : PlotImage<SiPixelTemplateDBObject, SINGLE_IOV>("SiPixelTemplate assumed value of uH") {}
0133 
0134     bool fill() override {
0135       gStyle->SetPalette(kRainBow);
0136       TGaxis::SetMaxDigits(2);
0137 
0138       auto tag = PlotBase::getTag<0>();
0139       auto iov = tag.iovs.front();
0140       const auto& tagname = tag.name;
0141       std::vector<SiPixelTemplateStore> thePixelTemp_;
0142       std::shared_ptr<SiPixelTemplateDBObject> payload = fetchPayload(std::get<1>(iov));
0143 
0144       if (payload.get()) {
0145         if (!SiPixelTemplate::pushfile(*payload, thePixelTemp_)) {
0146           throw cms::Exception("SiPixelTemplateDBObject_PayloadInspector")
0147               << "\nERROR: Templates not filled correctly. Check the conditions. Using "
0148                  "SiPixelTemplateDBObject version "
0149               << payload->version() << "\n\n";
0150         }
0151 
0152         // store the map of ID / interesting quantities
0153         SiPixelTemplate templ(thePixelTemp_);
0154         std::map<int, header_info> theInfos;
0155         for (const auto& theTemp : thePixelTemp_) {
0156           header_info info;
0157           info.ID = theTemp.head.ID;
0158           info.lorywidth = theTemp.head.lorywidth;
0159           info.lorxwidth = theTemp.head.lorxwidth;
0160           info.lorybias = theTemp.head.lorybias;
0161           info.lorxbias = theTemp.head.lorxbias;
0162           info.Vbias = theTemp.head.Vbias;
0163           info.temperature = theTemp.head.temperature;
0164           info.templ_version = theTemp.head.templ_version;
0165           info.Bfield = theTemp.head.Bfield;
0166           info.xsize = theTemp.head.xsize;
0167           info.ysize = theTemp.head.ysize;
0168           info.zsize = theTemp.head.zsize;
0169 
0170           theInfos[theTemp.head.ID] = info;
0171         }
0172 
0173         // Book the TH2Poly
0174         Phase1PixelMaps theMaps("");
0175         if (myType == SiPixelPI::t_all) {
0176           theMaps.resetOption("COLZA L");
0177         } else {
0178           theMaps.resetOption("COLZL");
0179         }
0180 
0181         if (myType == SiPixelPI::t_barrel) {
0182           theMaps.bookBarrelHistograms("templateLABarrel", "#muH", "#mu_{H} [1/T]");
0183         } else if (myType == SiPixelPI::t_forward) {
0184           theMaps.bookForwardHistograms("templateLAForward", "#muH", "#mu_{H} [1/T]");
0185         } else if (myType == SiPixelPI::t_all) {
0186           theMaps.bookBarrelHistograms("templateLA", "#muH", "#mu_{H} [1/T]");
0187           theMaps.bookForwardHistograms("templateLA", "#muH", "#mu_{H} [1/T]");
0188         } else {
0189           edm::LogError("SiPixelTemplateDBObject_PayloadInspector")
0190               << " un-recognized detector type " << myType << std::endl;
0191           return false;
0192         }
0193 
0194         std::map<unsigned int, short> templMap = payload->getTemplateIDs();
0195         if (templMap.size() == SiPixelPI::phase0size || templMap.size() > SiPixelPI::phase1size) {
0196           edm::LogError("SiPixelTemplateDBObject_PayloadInspector")
0197               << "There are " << templMap.size()
0198               << " DetIds in this payload. SiPixelTempate Lorentz Angle maps are not supported for non-Phase1 Pixel "
0199                  "geometries !";
0200           TCanvas canvas("Canv", "Canv", 1200, 1000);
0201           SiPixelPI::displayNotSupported(canvas, templMap.size());
0202           std::string fileName(m_imageFileName);
0203           canvas.SaveAs(fileName.c_str());
0204           return false;
0205         } else {
0206           if (templMap.size() < SiPixelPI::phase1size) {
0207             edm::LogWarning("SiPixelTemplateDBObject_PayloadInspector")
0208                 << "\n ********* WARNING! ********* \n There are " << templMap.size() << " DetIds in this payload !"
0209                 << "\n **************************** \n";
0210           }
0211         }
0212 
0213         for (auto const& entry : templMap) {
0214           templ.interpolate(entry.second, 0.f, 0.f, 1.f, 1.f);
0215 
0216           //mu_H = lorentz width / sensor thickness / B field
0217           float uH = templ.lorxwidth() / theInfos[entry.second].zsize / theInfos[entry.second].Bfield;
0218           COUT << "uH: " << uH << " lor x width:" << templ.lorxwidth() << " z size: " << theInfos[entry.second].zsize
0219                << " B-field: " << theInfos[entry.second].Bfield << std::endl;
0220 
0221           auto detid = DetId(entry.first);
0222           if (myType == SiPixelPI::t_all) {
0223             if ((detid.subdetId() == PixelSubdetector::PixelBarrel)) {
0224               theMaps.fillBarrelBin("templateLA", entry.first, uH);
0225             }
0226             if ((detid.subdetId() == PixelSubdetector::PixelEndcap)) {
0227               theMaps.fillForwardBin("templateLA", entry.first, uH);
0228             }
0229           } else if ((detid.subdetId() == PixelSubdetector::PixelBarrel) && (myType == SiPixelPI::t_barrel)) {
0230             theMaps.fillBarrelBin("templateLABarrel", entry.first, uH);
0231           } else if ((detid.subdetId() == PixelSubdetector::PixelEndcap) && (myType == SiPixelPI::t_forward)) {
0232             theMaps.fillForwardBin("templateLAForward", entry.first, uH);
0233           }
0234         }
0235 
0236         theMaps.beautifyAllHistograms();
0237 
0238         TCanvas canvas("Canv", "Canv", (myType == SiPixelPI::t_barrel) ? 1200 : 1600, 1000);
0239         if (myType == SiPixelPI::t_barrel) {
0240           theMaps.drawBarrelMaps("templateLABarrel", canvas);
0241         } else if (myType == SiPixelPI::t_forward) {
0242           theMaps.drawForwardMaps("templateLAForward", canvas);
0243         } else if (myType == SiPixelPI::t_all) {
0244           theMaps.drawSummaryMaps("templateLA", canvas);
0245         }
0246 
0247         canvas.cd();
0248         TPaveText ksPt(0, 0, 0.88, 0.04, "NDC");
0249         ksPt.SetBorderSize(0);
0250         ksPt.SetFillColor(0);
0251         const char* textToAdd = Form("Template Tag: #color[2]{%s}, IOV: #color[2]{%s}. Payload hash: #color[2]{%s}",
0252                                      tagname.c_str(),
0253                                      std::to_string(std::get<0>(iov)).c_str(),
0254                                      (std::get<1>(iov)).c_str());
0255         ksPt.AddText(textToAdd);
0256         ksPt.Draw();
0257 
0258         canvas.cd();
0259         std::string fileName(m_imageFileName);
0260         canvas.SaveAs(fileName.c_str());
0261       }
0262       return true;
0263     }  // fill
0264   };
0265 
0266   using SiPixelTemplateLABPixMap = SiPixelTemplateLA<SiPixelPI::t_barrel>;
0267   using SiPixelTemplateLAFPixMap = SiPixelTemplateLA<SiPixelPI::t_forward>;
0268   using SiPixelTemplateLAMap = SiPixelTemplateLA<SiPixelPI::t_all>;
0269 
0270   using namespace templateHelper;
0271 
0272   //************************************************
0273   // Full Pixel Tracker Map of Template IDs
0274   // ***********************************************/
0275   using SiPixelTemplateIDsFullPixelMap =
0276       SiPixelFullPixelIDMap<SiPixelTemplateDBObject, SiPixelTemplateStore, SiPixelTemplate>;
0277 
0278   //************************************************
0279   // Display of Template Titles
0280   // **********************************************/
0281   using SiPixelTemplateTitles_Display =
0282       SiPixelTitles_Display<SiPixelTemplateDBObject, SiPixelTemplateStore, SiPixelTemplate>;
0283 
0284   //***********************************************
0285   // Display of Template Header
0286   // **********************************************/
0287   using SiPixelTemplateHeaderTable = SiPixelHeaderTable<SiPixelTemplateDBObject, SiPixelTemplateStore, SiPixelTemplate>;
0288 
0289   //***********************************************
0290   // TH2Poly Map of IDs
0291   //***********************************************/
0292   using SiPixelTemplateIDsBPixMap = SiPixelIDs<SiPixelTemplateDBObject, SiPixelPI::t_barrel>;
0293   using SiPixelTemplateIDsFPixMap = SiPixelIDs<SiPixelTemplateDBObject, SiPixelPI::t_forward>;
0294   using SiPixelTemplateIDsMap = SiPixelIDs<SiPixelTemplateDBObject, SiPixelPI::t_all>;
0295 
0296   //************************************************
0297   // TH2Poly Map of qScale
0298   //***********************************************/
0299   using SiPixelTemplateQScaleBPixMap = SiPixelTemplateHeaderInfo<SiPixelTemplateDBObject,
0300                                                                  SiPixelTemplateStore,
0301                                                                  SiPixelTemplate,
0302                                                                  SiPixelPI::t_barrel,
0303                                                                  headerParam::k_qscale>;
0304   using SiPixelTemplateQScaleFPixMap = SiPixelTemplateHeaderInfo<SiPixelTemplateDBObject,
0305                                                                  SiPixelTemplateStore,
0306                                                                  SiPixelTemplate,
0307                                                                  SiPixelPI::t_forward,
0308                                                                  headerParam::k_qscale>;
0309   using SiPixelTemplateQScaleMap = SiPixelTemplateHeaderInfo<SiPixelTemplateDBObject,
0310                                                              SiPixelTemplateStore,
0311                                                              SiPixelTemplate,
0312                                                              SiPixelPI::t_all,
0313                                                              headerParam::k_qscale>;
0314 
0315   //************************************************
0316   // TH2Poly Map of Vbias
0317   //***********************************************/
0318   using SiPixelTemplateVbiasBPixMap = SiPixelTemplateHeaderInfo<SiPixelTemplateDBObject,
0319                                                                 SiPixelTemplateStore,
0320                                                                 SiPixelTemplate,
0321                                                                 SiPixelPI::t_barrel,
0322                                                                 headerParam::k_Vbias>;
0323   using SiPixelTemplateVbiasFPixMap = SiPixelTemplateHeaderInfo<SiPixelTemplateDBObject,
0324                                                                 SiPixelTemplateStore,
0325                                                                 SiPixelTemplate,
0326                                                                 SiPixelPI::t_forward,
0327                                                                 headerParam::k_Vbias>;
0328   using SiPixelTemplateVbiasMap = SiPixelTemplateHeaderInfo<SiPixelTemplateDBObject,
0329                                                             SiPixelTemplateStore,
0330                                                             SiPixelTemplate,
0331                                                             SiPixelPI::t_all,
0332                                                             headerParam::k_Vbias>;
0333 }  // namespace
0334 
0335 // Register the classes as boost python plugin
0336 PAYLOAD_INSPECTOR_MODULE(SiPixelTemplateDBObject) {
0337   PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateDBObjectTest);
0338   PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateIDsFullPixelMap);
0339   PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateTitles_Display);
0340   PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateHeaderTable);
0341   PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateIDsMap);
0342   PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateIDsBPixMap);
0343   PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateIDsFPixMap);
0344   PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateLAMap);
0345   PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateLABPixMap);
0346   PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateLAFPixMap);
0347   PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateQScaleBPixMap);
0348   PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateQScaleFPixMap);
0349   PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateQScaleMap);
0350   PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateVbiasBPixMap);
0351   PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateVbiasFPixMap);
0352   PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateVbiasMap);
0353 }