Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-02 03:39:12

0001 /****************************************************************************
0002 *
0003 * This is a part of CTPPSDQM software.
0004 * Authors:
0005 *   Jan Kašpar (jan.kaspar@gmail.com)
0006 *   Nicola Minafra
0007 *   Laurent Forthomme
0008 *   Christopher Misan
0009 *
0010 ****************************************************************************/
0011 
0012 #include "FWCore/Framework/interface/ESHandle.h"
0013 #include "FWCore/Framework/interface/MakerMacros.h"
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/EventSetup.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "FWCore/Utilities/interface/ESGetToken.h"
0018 #include "FWCore/Utilities/interface/InputTag.h"
0019 #include "FWCore/Utilities/interface/Transition.h"
0020 #include "FWCore/Framework/interface/Run.h"
0021 
0022 #include "DQMServices/Core/interface/DQMOneEDAnalyzer.h"
0023 #include "DQMServices/Core/interface/DQMStore.h"
0024 
0025 #include "DataFormats/Provenance/interface/EventRange.h"
0026 #include "DataFormats/CTPPSDigi/interface/TotemVFATStatus.h"
0027 #include "DataFormats/CTPPSDigi/interface/TotemFEDInfo.h"
0028 #include "DataFormats/Common/interface/DetSetVector.h"
0029 
0030 #include "DataFormats/CTPPSDetId/interface/CTPPSDiamondDetId.h"
0031 #include "DataFormats/CTPPSDigi/interface/CTPPSDiamondDigi.h"
0032 
0033 #include "DataFormats/CTPPSReco/interface/CTPPSPixelLocalTrack.h"
0034 #include "DataFormats/CTPPSDetId/interface/CTPPSPixelDetId.h"
0035 
0036 #include "DataFormats/CTPPSReco/interface/CTPPSDiamondRecHit.h"
0037 #include "DataFormats/CTPPSReco/interface/CTPPSDiamondLocalTrack.h"
0038 #include "Geometry/VeryForwardGeometryBuilder/interface/CTPPSGeometry.h"
0039 #include "Geometry/Records/interface/VeryForwardRealGeometryRecord.h"
0040 
0041 // #include "CondFormats/RunInfo/interface/LHCInfo.h"
0042 // #include "CondFormats/DataRecord/interface/LHCInfoRcd.h"
0043 
0044 #include <string>
0045 
0046 //----------------------------------------------------------------------------------------------------
0047 
0048 // Utility for efficiency computations
0049 bool channelAlignedWithTrack(const CTPPSGeometry* geom,
0050                              const CTPPSDiamondDetId& detid,
0051                              const CTPPSDiamondLocalTrack& localTrack,
0052                              const float tolerance = 1) {
0053   const DetGeomDesc* det = geom->sensor(detid);
0054   const float x_pos = det->translation().x(),
0055               x_width = 2.0 * det->getDiamondDimensions().xHalfWidth;  // parameters stand for half the size
0056   return ((x_pos + 0.5 * x_width > localTrack.x0() - localTrack.x0Sigma() - tolerance &&
0057            x_pos + 0.5 * x_width < localTrack.x0() + localTrack.x0Sigma() + tolerance) ||
0058           (x_pos - 0.5 * x_width > localTrack.x0() - localTrack.x0Sigma() - tolerance &&
0059            x_pos - 0.5 * x_width < localTrack.x0() + localTrack.x0Sigma() + tolerance) ||
0060           (x_pos - 0.5 * x_width < localTrack.x0() - localTrack.x0Sigma() - tolerance &&
0061            x_pos + 0.5 * x_width > localTrack.x0() + localTrack.x0Sigma() + tolerance));
0062 }
0063 
0064 namespace dds {
0065   struct Cache {
0066     std::unordered_map<unsigned int, std::unique_ptr<TH2F>> hitDistribution2dMap;
0067 
0068     std::unordered_map<unsigned int, unsigned long> hitsCounterMap;
0069   };
0070 }  // namespace dds
0071 
0072 class CTPPSDiamondDQMSource : public DQMOneEDAnalyzer<edm::LuminosityBlockCache<dds::Cache>> {
0073 public:
0074   CTPPSDiamondDQMSource(const edm::ParameterSet&);
0075 
0076 protected:
0077   void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
0078   void dqmEndRun(edm::Run const&, edm::EventSetup const&) override;
0079   void bookHistograms(DQMStore::IBooker&, const edm::Run&, const edm::EventSetup&) override;
0080   void analyze(const edm::Event&, const edm::EventSetup&) override;
0081   std::shared_ptr<dds::Cache> globalBeginLuminosityBlock(const edm::LuminosityBlock&,
0082                                                          const edm::EventSetup&) const override;
0083   void globalEndLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup&) override;
0084 
0085 private:
0086   // Constants
0087   /// Number of seconds per lumisection: used to compute hit rates in Hz
0088   static constexpr double SEC_PER_LUMI_SECTION = 23.31;
0089   /// Channel ID of the VFAT that contains clock data
0090   static constexpr unsigned short CHANNEL_OF_VFAT_CLOCK = 30;
0091   /// Bin width of histograms showing hits and tracks (in mm)
0092   static constexpr double DISPLAY_RESOLUTION_FOR_HITS_MM = 0.1;
0093   static constexpr double INV_DISPLAY_RESOLUTION_FOR_HITS_MM = 1. / DISPLAY_RESOLUTION_FOR_HITS_MM;
0094   /// ns per HPTDC bin
0095   static constexpr double HPTDC_BIN_WIDTH_NS = 25. / 1024;
0096   static constexpr unsigned short CTPPS_PIXEL_STATION_ID = 2;
0097   static constexpr unsigned short CTPPS_FAR_RP_ID = 3;
0098   static constexpr unsigned short CTPPS_DIAMOND_NUM_OF_CHANNELS = 12;
0099   static constexpr unsigned short CTPPS_FED_ID_45 = 583;
0100   static constexpr unsigned short CTPPS_FED_ID_56 = 582;
0101   static constexpr unsigned short HPTDC_0_CHANNEL = 6;
0102   static constexpr unsigned short HPTDC_1_CHANNEL = 7;
0103   /// Number of OOT indices monitored
0104   static constexpr unsigned int FIRST_RUN_W_PIXELS = 300000;
0105 
0106   bool perLSsaving_;  //to avoid nanoDQMIO crashing, driven by  DQMServices/Core/python/DQMStore_cfi.py
0107 
0108   /// plots related to the whole system
0109   struct GlobalPlots {
0110     GlobalPlots() = default;
0111     GlobalPlots(DQMStore::IBooker& ibooker);
0112   };
0113   /// plots related to one sector
0114   struct SectorPlots {
0115     // Tracks
0116     MonitorElement* trackCorrelation = nullptr;
0117     MonitorElement* trackCorrelationLowMultiplicity = nullptr;
0118     MonitorElement* digiSentPercentage = nullptr;
0119     SectorPlots(){};
0120     SectorPlots(DQMStore::IBooker& ibooker, unsigned int id, bool plotOnline);
0121   };
0122   /// plots related to one Diamond detector package
0123   struct PotPlots {
0124     std::unordered_map<unsigned int, MonitorElement*> activity_per_bx;
0125 
0126     MonitorElement* hitDistribution2d = nullptr;
0127     MonitorElement* hitDistribution2d_lumisection = nullptr;
0128     MonitorElement* hitDistribution2dOOT = nullptr;
0129     MonitorElement* hitDistribution2dOOT_le = nullptr;
0130     MonitorElement *activePlanes = nullptr, *activePlanesInclusive = nullptr;
0131 
0132     MonitorElement* trackDistribution = nullptr;
0133     MonitorElement* trackDistributionOOT = nullptr;
0134 
0135     std::unordered_map<unsigned int, MonitorElement*> pixelTomographyAll;
0136 
0137     MonitorElement *leadingEdgeCumulative_both = nullptr, *leadingEdgeCumulative_all = nullptr,
0138                    *leadingEdgeCumulative_le = nullptr, *trailingEdgeCumulative_te = nullptr;
0139     MonitorElement* timeOverThresholdCumulativePot = nullptr;  //, *leadingTrailingCorrelationPot = nullptr;
0140     MonitorElement* leadingWithoutTrailingCumulativePot = nullptr;
0141 
0142     MonitorElement* ECCheck = nullptr;
0143 
0144     MonitorElement* HPTDCErrorFlags_2D = nullptr;
0145     MonitorElement* MHComprensive = nullptr;
0146 
0147     MonitorElement* recHitTime = nullptr;
0148 
0149     // MonitorElement* clock_Digi1_le = nullptr;
0150     // MonitorElement* clock_Digi1_te = nullptr;
0151     // MonitorElement* clock_Digi3_le = nullptr;
0152     // MonitorElement* clock_Digi3_te = nullptr;
0153 
0154     unsigned int HitCounter, MHCounter, LeadingOnlyCounter, TrailingOnlyCounter, CompleteCounter;
0155 
0156     std::map<int, int> effTriplecountingChMap;
0157     std::map<int, int> effDoublecountingChMap;
0158     MonitorElement* EfficiencyOfChannelsInPot = nullptr;
0159     TH2F pixelTracksMap;
0160 
0161     // MonitorElement* TOTVsLS = nullptr;
0162     // MonitorElement* trackTimeVsLS = nullptr;
0163     MonitorElement* trackTimeVsBX = nullptr;
0164     // MonitorElement* trackTimeVsXAngle = nullptr;
0165 
0166     // MonitorElement* TOTVsLSProfile = nullptr;
0167     // MonitorElement* trackTimeVsLSProfile = nullptr;
0168     MonitorElement* trackTimeVsBXProfile = nullptr;
0169     // MonitorElement* trackTimeVsXAngleProfile = nullptr;
0170 
0171     PotPlots() = default;
0172     PotPlots(DQMStore::IBooker& ibooker,
0173              unsigned int id,
0174              unsigned int windowsNum,
0175              bool plotOnline,
0176              bool plotOffline,
0177              bool perLSsaving);
0178   };
0179   /// plots related to one Diamond plane
0180   struct PlanePlots {
0181     MonitorElement* digiProfileCumulativePerPlane = nullptr;
0182     MonitorElement* hitProfile = nullptr;
0183     MonitorElement* hit_multiplicity = nullptr;
0184 
0185     MonitorElement* pixelTomography_far = nullptr;
0186     MonitorElement* EfficiencyWRTPixelsInPlane = nullptr;
0187 
0188     TH2F pixelTracksMapWithDiamonds;
0189 
0190     PlanePlots() = default;
0191     PlanePlots(DQMStore::IBooker& ibooker, unsigned int id, unsigned int windowsNum);
0192   };
0193   /// plots related to one Diamond channel
0194   struct ChannelPlots {
0195     std::unordered_map<unsigned int, MonitorElement*> activity_per_bx;
0196 
0197     MonitorElement* HPTDCErrorFlags = nullptr;
0198     MonitorElement *leadingEdgeCumulative_both = nullptr, *leadingEdgeCumulative_le = nullptr,
0199                    *trailingEdgeCumulative_te = nullptr;
0200     MonitorElement* TimeOverThresholdCumulativePerChannel = nullptr;
0201     //MonitorElement* LeadingTrailingCorrelationPerChannel = nullptr;
0202     MonitorElement* leadingWithoutTrailing = nullptr;
0203     MonitorElement* pixelTomography_far = nullptr;
0204     MonitorElement* hit_rate = nullptr;
0205     MonitorElement* recHitTime = nullptr;
0206 
0207     unsigned int HitCounter, MHCounter, LeadingOnlyCounter, TrailingOnlyCounter, CompleteCounter;
0208 
0209     ChannelPlots() = default;
0210     ChannelPlots(DQMStore::IBooker& ibooker, unsigned int id, unsigned int windowsNum);
0211   };
0212 
0213   void checkEventNumber(const CTPPSDiamondDetId&, const TotemFEDInfo&, const TotemVFATStatus&, PotPlots&, int&) const;
0214 
0215   edm::EDGetTokenT<edm::DetSetVector<TotemVFATStatus>> tokenStatus_;
0216   edm::EDGetTokenT<edm::DetSetVector<CTPPSPixelLocalTrack>> tokenPixelTrack_;
0217   edm::EDGetTokenT<edm::DetSetVector<CTPPSDiamondDigi>> tokenDigi_;
0218   edm::EDGetTokenT<edm::DetSetVector<CTPPSDiamondRecHit>> tokenDiamondHit_;
0219   edm::EDGetTokenT<edm::DetSetVector<CTPPSDiamondLocalTrack>> tokenDiamondTrack_;
0220   edm::EDGetTokenT<std::vector<TotemFEDInfo>> tokenFEDInfo_;
0221 
0222   edm::ESGetToken<CTPPSGeometry, VeryForwardRealGeometryRecord> ctppsGeometryRunToken_;
0223   edm::ESGetToken<CTPPSGeometry, VeryForwardRealGeometryRecord> ctppsGeometryEventToken_;
0224   // edm::ESGetToken<LHCInfo, LHCInfoRcd> ctppsLhcInfoToken_;
0225 
0226   bool excludeMultipleHits_;
0227   const bool extract_digi_info_;
0228   struct DiamondShifts {
0229     double global, withPixels;
0230   };
0231   std::unordered_map<CTPPSDetId, DiamondShifts> diamShifts_;
0232   std::vector<std::pair<edm::EventRange, int>> runParameters_;
0233   int centralOOT_;
0234   unsigned int verbosity_;
0235   const bool plotOnline_;
0236   const bool plotOffline_;
0237   unsigned int windowsNum_;
0238   unsigned int trackCorrelationThreshold_;
0239 
0240   GlobalPlots globalPlot_;
0241   std::unordered_map<unsigned int, PotPlots> potPlots_;
0242   std::unordered_map<unsigned int, SectorPlots> sectorPlots_;
0243   std::unordered_map<unsigned int, PlanePlots> planePlots_;
0244   std::unordered_map<unsigned int, ChannelPlots> channelPlots_;
0245 
0246   int EC_difference_56_, EC_difference_45_;
0247 };
0248 
0249 //----------------------------------------------------------------------------------------------------
0250 
0251 CTPPSDiamondDQMSource::GlobalPlots::GlobalPlots(DQMStore::IBooker& ibooker) { ibooker.setCurrentFolder("CTPPS"); }
0252 
0253 //----------------------------------------------------------------------------------------------------
0254 
0255 CTPPSDiamondDQMSource::SectorPlots::SectorPlots(DQMStore::IBooker& ibooker, unsigned int id, bool plotOnline) {
0256   std::string path, title;
0257   CTPPSDiamondDetId(id).armName(path, CTPPSDiamondDetId::nPath);
0258   ibooker.setCurrentFolder(path);
0259 
0260   CTPPSDiamondDetId(id).armName(title, CTPPSDiamondDetId::nFull);
0261 
0262   trackCorrelation = ibooker.book2D("tracks correlation near-far",
0263                                     title + " tracks correlation near-far;x (mm);x (mm)",
0264                                     19. * INV_DISPLAY_RESOLUTION_FOR_HITS_MM,
0265                                     -1,
0266                                     18,
0267                                     19. * INV_DISPLAY_RESOLUTION_FOR_HITS_MM,
0268                                     -1,
0269                                     18);
0270   trackCorrelationLowMultiplicity =
0271       ibooker.book2D("tracks correlation with low multiplicity near-far",
0272                      title + " tracks correlation with low multiplicity near-far;x (mm);x (mm)",
0273                      19. * INV_DISPLAY_RESOLUTION_FOR_HITS_MM,
0274                      -1,
0275                      18,
0276                      19. * INV_DISPLAY_RESOLUTION_FOR_HITS_MM,
0277                      -1,
0278                      18);
0279 }
0280 
0281 //----------------------------------------------------------------------------------------------------
0282 CTPPSDiamondDQMSource::PotPlots::PotPlots(DQMStore::IBooker& ibooker,
0283                                           unsigned int id,
0284                                           unsigned int windowsNum,
0285                                           bool plotOnline,
0286                                           bool plotOffline,
0287                                           bool perLSsaving)
0288     : HitCounter(0),
0289       MHCounter(0),
0290       LeadingOnlyCounter(0),
0291       TrailingOnlyCounter(0),
0292       CompleteCounter(0),
0293       pixelTracksMap("Pixel track maps for efficiency", "Pixel track maps for efficiency", 25, 0, 25, 12, -2, 10) {
0294   std::string path, title;
0295   CTPPSDiamondDetId(id).rpName(path, CTPPSDiamondDetId::nPath);
0296   ibooker.setCurrentFolder(path);
0297 
0298   CTPPSDiamondDetId(id).rpName(title, CTPPSDiamondDetId::nFull);
0299 
0300   if (plotOnline) {
0301     hitDistribution2d_lumisection =
0302         ibooker.book2D("hits in planes lumisection",
0303                        title + " hits in planes in the last lumisection;plane number;x (mm)",
0304                        10,
0305                        -0.5,
0306                        4.5,
0307                        19. * INV_DISPLAY_RESOLUTION_FOR_HITS_MM,
0308                        -0.5,
0309                        18.5);
0310 
0311     hitDistribution2dOOT_le =
0312         ibooker.book2D("hits with OOT in planes (le only)",
0313                        title + " hits with OOT in planes (le only);plane number, OOT index;x (mm)",
0314                        1 + windowsNum * 4,
0315                        -1. / windowsNum,
0316                        4,
0317                        19. * INV_DISPLAY_RESOLUTION_FOR_HITS_MM,
0318                        -0.5,
0319                        18.5);
0320 
0321     activePlanesInclusive =
0322         ibooker.book1D("active planes inclusive",
0323                        title + " active planes, MH and le only included (per event);number of active planes",
0324                        6,
0325                        -0.5,
0326                        5.5);
0327 
0328     ECCheck = ibooker.book1D("optorxEC(8bit) - vfatEC", title + " EC Error;optorxEC-vfatEC", 50, -25, 25);
0329 
0330     EfficiencyOfChannelsInPot =
0331         ibooker.book2D("Efficiency in channels",
0332                        title + " Efficiency (%) in channels (diamonds only);plane number;ch number",
0333                        10,
0334                        -0.5,
0335                        4.5,
0336                        14,
0337                        -1,
0338                        13);
0339   }
0340 
0341   if (plotOffline && !perLSsaving) {
0342     ibooker.setCurrentFolder(path + "/timing_profiles");
0343     // TOTVsLS=ibooker.book2D("ToT vs LS",title +" ToT vs LS;LS;ToT(ns)",4000,0,4000, 200,5,25);
0344     // trackTimeVsLS=ibooker.book2D("track time vs LS",title+" track time vs LS;LS;track_time(ns)",4000,0,4000, 500, -25, 25);
0345     trackTimeVsBX =
0346         ibooker.book2D("track time vs BX", title + " track time vs BX;BX;track_time(ns)", 4000, 0, 4000, 500, -25, 25);
0347     // trackTimeVsXAngle = ibooker.book2D(
0348     //     "track time vs xangle", title + " track time vs xangle;xangle;track_time(ns)", 60, 120, 180, 500, -25, 25);
0349 
0350     // TOTVsLSProfile=ibooker.bookProfile("ToT vs LS profile",title+" ToT vs LS profile;LS;track_time(ns)", 500, -25, 25,4000,0,4000);
0351     // trackTimeVsLSProfile=ibooker.bookProfile("track time vs LS profile",title+" track time vs LS profile;LS;track_time(ns)", 500, -25, 25,4000,0,4000);
0352     trackTimeVsBXProfile = ibooker.bookProfile(
0353         "track time vs BX profile", title + " track time vs BX profile;BX;track_time(ns)", 500, -25, 25, 4000, 0, 4000);
0354     // trackTimeVsXAngleProfile = ibooker.bookProfile("track time vs xangle profile",
0355     //                                                title + " track time vs xangle profile;xangle;track_time(ns)",
0356     //                                                500,
0357     //                                                -25,
0358     //                                                25,
0359     //                                                60,
0360     //                                                120,
0361     //                                                180);
0362     ibooker.setCurrentFolder(path);
0363   }
0364 
0365   for (unsigned int i = 0; i < windowsNum; i++) {
0366     std::string window = std::to_string(i * 25) + "-" + std::to_string((i + 1) * 25);
0367     activity_per_bx[i] = ibooker.book1D(
0368         "activity per BX " + window, title + " Activity per BX " + window + " ns;Event.BX", 3600, -1.5, 3598. + 0.5);
0369     pixelTomographyAll[i] =
0370         ibooker.book2D("tomography pixel " + window,
0371                        title + " tomography with pixel " + window + " ns (all planes);x + 25*plane(mm);y (mm)",
0372                        100,
0373                        0,
0374                        100,
0375                        10,
0376                        -5,
0377                        5);
0378   }
0379 
0380   hitDistribution2d = ibooker.book2D("hits in planes",
0381                                      title + " hits in planes;plane number;x (mm)",
0382                                      10,
0383                                      -0.5,
0384                                      4.5,
0385                                      19. * INV_DISPLAY_RESOLUTION_FOR_HITS_MM,
0386                                      -0.5,
0387                                      18.5);
0388 
0389   hitDistribution2dOOT = ibooker.book2D("hits with OOT in planes",
0390                                         title + " hits with OOT in planes;plane number, OOT index;x (mm)",
0391                                         1 + windowsNum * 4,
0392                                         -1. / windowsNum,
0393                                         4,
0394                                         19. * INV_DISPLAY_RESOLUTION_FOR_HITS_MM,
0395                                         -0.5,
0396                                         18.5);
0397 
0398   {               // bin labelling (for clarity)
0399     int idx = 2;  // start counting at 1, first bin is empty
0400     for (int pl = 0; pl < 4; ++pl)
0401       for (unsigned int oot = 0; oot < windowsNum; ++oot) {
0402         const std::string bin_label =
0403             (oot == 0 ? "Plane " + std::to_string(pl) + ", " : "") + "OOT" + std::to_string(oot);
0404         hitDistribution2dOOT->setBinLabel(idx, bin_label);
0405         if (plotOnline)
0406           hitDistribution2dOOT_le->setBinLabel(idx, bin_label);
0407         ++idx;
0408       }
0409   }
0410 
0411   recHitTime = ibooker.book1D("recHit time", title + " recHit time; t (ns)", 500, -25, 25);
0412 
0413   activePlanes =
0414       ibooker.book1D("active planes", title + " active planes (per event);number of active planes", 6, -0.5, 5.5);
0415 
0416   trackDistribution =
0417       ibooker.book1D("tracks", title + " tracks;x (mm)", 19. * INV_DISPLAY_RESOLUTION_FOR_HITS_MM, -0.5, 18.5);
0418   trackDistributionOOT = ibooker.book2D("tracks with OOT",
0419                                         title + " tracks with OOT;plane number;x (mm)",
0420                                         9,
0421                                         -0.5,
0422                                         4,
0423                                         19. * INV_DISPLAY_RESOLUTION_FOR_HITS_MM,
0424                                         -0.5,
0425                                         18.5);
0426 
0427   leadingEdgeCumulative_both = ibooker.book1D("leading edge (le and te)",
0428                                               title + " leading edge (le and te) (recHits); leading edge (ns)",
0429                                               25 * windowsNum,
0430                                               0,
0431                                               25 * windowsNum);
0432   leadingEdgeCumulative_all = ibooker.book1D("leading edge (all)",
0433                                              title + " leading edge (with or without te) (DIGIs); leading edge (ns)",
0434                                              25 * windowsNum,
0435                                              0,
0436                                              25 * windowsNum);
0437   leadingEdgeCumulative_le = ibooker.book1D("leading edge (le only)",
0438                                             title + " leading edge (le only) (DIGIs); leading edge (ns)",
0439                                             25 * windowsNum,
0440                                             0,
0441                                             25 * windowsNum);
0442   trailingEdgeCumulative_te = ibooker.book1D("trailing edge (te only)",
0443                                              title + " trailing edge (te only) (DIGIs); trailing edge (ns)",
0444                                              25 * windowsNum,
0445                                              0,
0446                                              25 * windowsNum);
0447   timeOverThresholdCumulativePot =
0448       ibooker.book1D("time over threshold", title + " time over threshold;time over threshold (ns)", 250, -25, 100);
0449   // leadingTrailingCorrelationPot =
0450   //     ibooker.book2D("leading trailing correlation",
0451   //                    title + " leading trailing correlation;leading edge (ns);trailing edge (ns)",
0452   //                    75,
0453   //                    0,
0454   //                    75,
0455   //                    75,
0456   //                    0,
0457   //                    75);
0458 
0459   leadingWithoutTrailingCumulativePot =
0460       ibooker.book1D("event category", title + " leading edges without trailing;;%", 3, 0.5, 3.5);
0461   leadingWithoutTrailingCumulativePot->setBinLabel(1, "Leading only");
0462   leadingWithoutTrailingCumulativePot->setBinLabel(2, "Trailing only");
0463   leadingWithoutTrailingCumulativePot->setBinLabel(3, "Both");
0464 
0465   HPTDCErrorFlags_2D = ibooker.book2D("HPTDC Errors", title + " HPTDC Errors", 16, -0.5, 16.5, 9, -0.5, 8.5);
0466   for (unsigned short error_index = 1; error_index < 16; ++error_index)
0467     HPTDCErrorFlags_2D->setBinLabel(error_index, HPTDCErrorFlags::hptdcErrorName(error_index - 1));
0468   HPTDCErrorFlags_2D->setBinLabel(16, "Wrong EC");
0469 
0470   int tmpIndex = 0;
0471   HPTDCErrorFlags_2D->setBinLabel(++tmpIndex, "DB 0 TDC 18", /* axis */ 2);
0472   HPTDCErrorFlags_2D->setBinLabel(++tmpIndex, "DB 0 TDC 17", /* axis */ 2);
0473   HPTDCErrorFlags_2D->setBinLabel(++tmpIndex, "DB 0 TDC 16", /* axis */ 2);
0474   HPTDCErrorFlags_2D->setBinLabel(++tmpIndex, "DB 0 TDC 15", /* axis */ 2);
0475   HPTDCErrorFlags_2D->setBinLabel(++tmpIndex, "DB 1 TDC 18", /* axis */ 2);
0476   HPTDCErrorFlags_2D->setBinLabel(++tmpIndex, "DB 1 TDC 17", /* axis */ 2);
0477   HPTDCErrorFlags_2D->setBinLabel(++tmpIndex, "DB 1 TDC 16", /* axis */ 2);
0478   HPTDCErrorFlags_2D->setBinLabel(++tmpIndex, "DB 1 TDC 15", /* axis */ 2);
0479 
0480   MHComprensive =
0481       ibooker.book2D("MH in channels", title + " MH (%) in channels;plane number;ch number", 10, -0.5, 4.5, 14, -1, 13);
0482 
0483   // ibooker.setCurrentFolder( path+"/clock/" );
0484   // clock_Digi1_le = ibooker.book1D( "clock1 leading edge", title+" clock1;leading edge (ns)", 250, 0, 25 );
0485   // clock_Digi1_te = ibooker.book1D( "clock1 trailing edge", title+" clock1;trailing edge (ns)", 75, 0, 75 );
0486   // clock_Digi3_le = ibooker.book1D( "clock3 leading edge", title+" clock3;leading edge (ns)", 250, 0, 25 );
0487   // clock_Digi3_te = ibooker.book1D( "clock3 trailing edge", title+" clock3;trailing edge (ns)", 75, 0, 75 );
0488 }
0489 
0490 //----------------------------------------------------------------------------------------------------
0491 
0492 CTPPSDiamondDQMSource::PlanePlots::PlanePlots(DQMStore::IBooker& ibooker, unsigned int id, unsigned int windowsNum)
0493     : pixelTracksMapWithDiamonds("Pixel track maps for efficiency with coincidence",
0494                                  "Pixel track maps for efficiency with coincidence",
0495                                  25,
0496                                  0,
0497                                  25,
0498                                  12,
0499                                  -2,
0500                                  10) {
0501   std::string path, title;
0502   CTPPSDiamondDetId(id).planeName(path, CTPPSDiamondDetId::nPath);
0503   ibooker.setCurrentFolder(path);
0504 
0505   CTPPSDiamondDetId(id).planeName(title, CTPPSDiamondDetId::nFull);
0506 
0507   digiProfileCumulativePerPlane = ibooker.book1D("digi profile",
0508                                                  title + " digi profile; ch number",
0509                                                  CTPPS_DIAMOND_NUM_OF_CHANNELS,
0510                                                  -0.5,
0511                                                  CTPPS_DIAMOND_NUM_OF_CHANNELS - 0.5);
0512   hitProfile = ibooker.book1D(
0513       "hit profile", title + " hit profile;x (mm)", 19. * INV_DISPLAY_RESOLUTION_FOR_HITS_MM, -0.5, 18.5);
0514   hit_multiplicity = ibooker.book1D("channels per plane", title + " channels per plane; ch per plane", 13, -0.5, 12.5);
0515 
0516   pixelTomography_far = ibooker.book2D("tomography pixel",
0517                                        title + " tomography with pixel;x + 25 OOT (mm);y (mm)",
0518                                        25 * windowsNum,
0519                                        0,
0520                                        25 * windowsNum,
0521                                        8,
0522                                        0,
0523                                        8);
0524   EfficiencyWRTPixelsInPlane =
0525       ibooker.book2D("Efficiency wrt pixels", title + " Efficiency wrt pixels;x (mm);y (mm)", 25, 0, 25, 12, -2, 10);
0526 }
0527 
0528 //----------------------------------------------------------------------------------------------------
0529 
0530 CTPPSDiamondDQMSource::ChannelPlots::ChannelPlots(DQMStore::IBooker& ibooker, unsigned int id, unsigned int windowsNum)
0531     : HitCounter(0), MHCounter(0), LeadingOnlyCounter(0), TrailingOnlyCounter(0), CompleteCounter(0) {
0532   std::string path, title;
0533   CTPPSDiamondDetId(id).channelName(path, CTPPSDiamondDetId::nPath);
0534   ibooker.setCurrentFolder(path);
0535 
0536   CTPPSDiamondDetId(id).channelName(title, CTPPSDiamondDetId::nFull);
0537 
0538   leadingWithoutTrailing = ibooker.book1D("event category", title + " Event Category;;%", 3, 0.5, 3.5);
0539   leadingWithoutTrailing->setBinLabel(1, "Leading only");
0540   leadingWithoutTrailing->setBinLabel(2, "Trailing only");
0541   leadingWithoutTrailing->setBinLabel(3, "Full");
0542 
0543   for (unsigned int i = 0; i < windowsNum; i++) {
0544     std::string window = std::to_string(i * 25) + "-" + std::to_string((i + 1) * 25);
0545     activity_per_bx[i] = ibooker.book1D(
0546         "activity per BX " + window, title + " Activity per BX " + window + " ns;Event.BX", 3600, -1.5, 3598. + 0.5);
0547   }
0548 
0549   HPTDCErrorFlags = ibooker.book1D("hptdc_Errors", title + " HPTDC Errors", 16, -0.5, 16.5);
0550   for (unsigned short error_index = 1; error_index < 16; ++error_index)
0551     HPTDCErrorFlags->setBinLabel(error_index, HPTDCErrorFlags::hptdcErrorName(error_index - 1));
0552   HPTDCErrorFlags->setBinLabel(16, "MH  (%)");
0553 
0554   leadingEdgeCumulative_both = ibooker.book1D("leading edge (le and te)",
0555                                               title + " leading edge (recHits); leading edge (ns)",
0556                                               25 * windowsNum,
0557                                               0,
0558                                               25 * windowsNum);
0559   leadingEdgeCumulative_le = ibooker.book1D(
0560       "leading edge (le only)", title + " leading edge (DIGIs); leading edge (ns)", 25 * windowsNum, 0, 25 * windowsNum);
0561   trailingEdgeCumulative_te = ibooker.book1D("trailing edge (te only)",
0562                                              title + " trailing edge (te only) (DIGIs); trailing edge (ns)",
0563                                              25 * windowsNum,
0564                                              0,
0565                                              25 * windowsNum);
0566   TimeOverThresholdCumulativePerChannel =
0567       ibooker.book1D("time over threshold", title + " time over threshold;time over threshold (ns)", 75, -25, 50);
0568   // LeadingTrailingCorrelationPerChannel =
0569   //     ibooker.book2D("leading trailing correlation",
0570   //                    title + " leading trailing correlation;leading edge (ns);trailing edge (ns)",
0571   //                    75,
0572   //                    0,
0573   //                    75,
0574   //                    75,
0575   //                    0,
0576   //                    75);
0577 
0578   pixelTomography_far = ibooker.book2D(
0579       "tomography pixel", "tomography with pixel;x + 25 OOT (mm);y (mm)", 25 * windowsNum, 0, 25 * windowsNum, 8, 0, 8);
0580 
0581   hit_rate = ibooker.book1D("hit rate", title + "hit rate;rate (Hz)", 40, 0, 20);
0582 
0583   recHitTime = ibooker.book1D("recHit Time", title + " recHit Time; t (ns)", 500, -25, 25);
0584 }
0585 
0586 //----------------------------------------------------------------------------------------------------
0587 
0588 CTPPSDiamondDQMSource::CTPPSDiamondDQMSource(const edm::ParameterSet& ps)
0589     : perLSsaving_(ps.getUntrackedParameter<bool>("perLSsaving", false)),
0590       tokenPixelTrack_(
0591           consumes<edm::DetSetVector<CTPPSPixelLocalTrack>>(ps.getParameter<edm::InputTag>("tagPixelLocalTracks"))),
0592       tokenDiamondHit_(
0593           consumes<edm::DetSetVector<CTPPSDiamondRecHit>>(ps.getParameter<edm::InputTag>("tagDiamondRecHits"))),
0594       tokenDiamondTrack_(
0595           consumes<edm::DetSetVector<CTPPSDiamondLocalTrack>>(ps.getParameter<edm::InputTag>("tagDiamondLocalTracks"))),
0596       ctppsGeometryRunToken_(esConsumes<CTPPSGeometry, VeryForwardRealGeometryRecord, edm::Transition::BeginRun>()),
0597       ctppsGeometryEventToken_(esConsumes<CTPPSGeometry, VeryForwardRealGeometryRecord>()),
0598       // ctppsLhcInfoToken_(esConsumes<LHCInfo, LHCInfoRcd>()),
0599       excludeMultipleHits_(ps.getParameter<bool>("excludeMultipleHits")),
0600       extract_digi_info_(ps.getParameter<bool>("extractDigiInfo")),
0601       centralOOT_(-999),
0602       verbosity_(ps.getUntrackedParameter<unsigned int>("verbosity", 0)),
0603       plotOnline_(ps.getUntrackedParameter<bool>("plotOnline", true)),
0604       plotOffline_(ps.getUntrackedParameter<bool>("plotOffline", false)),
0605       windowsNum_(ps.getUntrackedParameter<unsigned int>("windowsNum", 3)),
0606       trackCorrelationThreshold_(ps.getUntrackedParameter<unsigned int>("trackCorrelationThreshold", 3)),
0607       EC_difference_56_(-500),
0608       EC_difference_45_(-500) {
0609   if (extract_digi_info_) {
0610     tokenStatus_ = consumes<edm::DetSetVector<TotemVFATStatus>>(ps.getParameter<edm::InputTag>("tagStatus"));
0611     tokenFEDInfo_ = consumes<std::vector<TotemFEDInfo>>(ps.getParameter<edm::InputTag>("tagFEDInfo"));
0612     tokenDigi_ = consumes<edm::DetSetVector<CTPPSDiamondDigi>>(ps.getParameter<edm::InputTag>("tagDigi"));
0613   }
0614   for (const auto& pset : ps.getParameter<std::vector<edm::ParameterSet>>("offsetsOOT")) {
0615     runParameters_.emplace_back(
0616         std::make_pair(pset.getParameter<edm::EventRange>("validityRange"), pset.getParameter<int>("centralOOT")));
0617   }
0618 }
0619 
0620 //----------------------------------------------------------------------------------------------------
0621 
0622 void CTPPSDiamondDQMSource::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0623   centralOOT_ = -999;
0624   for (const auto& oot : runParameters_) {
0625     if (edm::contains(oot.first, edm::EventID(iRun.run(), 0, 1))) {
0626       centralOOT_ = oot.second;
0627       break;
0628     }
0629   }
0630 
0631   // Get detector shifts from the geometry
0632   const CTPPSGeometry& geom = iSetup.getData(ctppsGeometryRunToken_);
0633   for (auto it = geom.beginRP(); it != geom.endRP(); ++it)
0634     if (CTPPSDiamondDetId::check(it->first)) {
0635       const CTPPSDiamondDetId diam_id(it->first);
0636       const auto diam = geom.sensor(it->first);
0637       diamShifts_[diam_id].global = diam->translation().x() - diam->getDiamondDimensions().xHalfWidth;
0638       if (iRun.run() > FIRST_RUN_W_PIXELS) {  // pixel installed
0639         const CTPPSPixelDetId pixid(diam_id.arm(), CTPPS_PIXEL_STATION_ID, CTPPS_FAR_RP_ID);
0640         auto pix = geom.sensor(pixid);
0641         // Rough alignement of pixel detector for diamond tomography
0642         diamShifts_[diam_id].withPixels =
0643             pix->translation().x() - pix->getDiamondDimensions().xHalfWidth - diamShifts_[diam_id].global - 1.;
0644       }
0645     }
0646 }
0647 
0648 //----------------------------------------------------------------------------------------------------
0649 
0650 void CTPPSDiamondDQMSource::bookHistograms(DQMStore::IBooker& ibooker, const edm::Run&, const edm::EventSetup& iSetup) {
0651   ibooker.cd();
0652   ibooker.setCurrentFolder("CTPPS");
0653 
0654   globalPlot_ = GlobalPlots(ibooker);
0655 
0656   // book plots from the geometry
0657   const CTPPSGeometry& geom = iSetup.getData(ctppsGeometryRunToken_);
0658   for (auto it = geom.beginSensor(); it != geom.endSensor(); ++it) {
0659     if (!CTPPSDiamondDetId::check(it->first))
0660       continue;
0661     // per-channel plots
0662     const CTPPSDiamondDetId chId(it->first);
0663     if (plotOnline_ && channelPlots_.count(chId) == 0)
0664       channelPlots_[chId] = ChannelPlots(ibooker, chId, windowsNum_);
0665 
0666     // per-plane plots
0667     const CTPPSDiamondDetId plId(chId.planeId());
0668     if (planePlots_.count(plId) == 0)
0669       planePlots_[plId] = PlanePlots(ibooker, plId, windowsNum_);
0670     // per-pot plots
0671     const CTPPSDiamondDetId rpId(chId.rpId());
0672     if (potPlots_.count(rpId) == 0)
0673       potPlots_[rpId] = PotPlots(ibooker, rpId, windowsNum_, plotOnline_, plotOffline_, perLSsaving_);
0674 
0675     // per-sector plots
0676     const CTPPSDiamondDetId secId(chId.armId());
0677     if (plotOffline_ && sectorPlots_.count(secId) == 0)
0678       sectorPlots_[secId] = SectorPlots(ibooker, secId, plotOnline_);
0679   }
0680 }
0681 
0682 //----------------------------------------------------------------------------------------------------
0683 
0684 std::shared_ptr<dds::Cache> CTPPSDiamondDQMSource::globalBeginLuminosityBlock(const edm::LuminosityBlock&,
0685                                                                               const edm::EventSetup&) const {
0686   auto d = std::make_shared<dds::Cache>();
0687   d->hitDistribution2dMap.reserve(potPlots_.size());
0688   if (!perLSsaving_ && plotOnline_) {
0689     for (auto& plot : potPlots_)
0690       d->hitDistribution2dMap[plot.first] =
0691           std::unique_ptr<TH2F>(static_cast<TH2F*>(plot.second.hitDistribution2d_lumisection->getTH2F()->Clone()));
0692   }
0693   return d;
0694 }
0695 
0696 //----------------------------------------------------------------------------------------------------
0697 
0698 void CTPPSDiamondDQMSource::analyze(const edm::Event& event, const edm::EventSetup& iSetup) {
0699   // get event data
0700 
0701   edm::Handle<edm::DetSetVector<TotemVFATStatus>> diamondVFATStatus;
0702   edm::Handle<edm::DetSetVector<CTPPSDiamondDigi>> diamondDigis;
0703   edm::Handle<std::vector<TotemFEDInfo>> fedInfo;
0704   if (extract_digi_info_) {
0705     event.getByToken(tokenStatus_, diamondVFATStatus);
0706     event.getByToken(tokenDigi_, diamondDigis);
0707     event.getByToken(tokenFEDInfo_, fedInfo);
0708   }
0709 
0710   edm::Handle<edm::DetSetVector<CTPPSPixelLocalTrack>> pixelTracks;
0711   event.getByToken(tokenPixelTrack_, pixelTracks);
0712 
0713   edm::Handle<edm::DetSetVector<CTPPSDiamondRecHit>> diamondRecHits;
0714   event.getByToken(tokenDiamondHit_, diamondRecHits);
0715 
0716   edm::Handle<edm::DetSetVector<CTPPSDiamondLocalTrack>> diamondLocalTracks;
0717   event.getByToken(tokenDiamondTrack_, diamondLocalTracks);
0718 
0719   const CTPPSGeometry* ctppsGeometry = &iSetup.getData(ctppsGeometryEventToken_);
0720   // const LHCInfo* hLhcInfo = &iSetup.getData(ctppsLhcInfoToken_);
0721 
0722   // check validity
0723   bool valid = true;
0724   if (extract_digi_info_) {  // drop DIGI-level validity checks if not monitored
0725     valid &= diamondVFATStatus.isValid();
0726     valid &= diamondDigis.isValid();
0727     valid &= fedInfo.isValid();
0728   }
0729   valid &= pixelTracks.isValid();
0730   valid &= diamondRecHits.isValid();
0731   valid &= diamondLocalTracks.isValid();
0732 
0733   if (!valid) {
0734     if (verbosity_)
0735       edm::LogProblem("CTPPSDiamondDQMSource")
0736           << "ERROR in CTPPSDiamondDQMSource::analyze > some of the required inputs are not valid. Skipping this "
0737              "event.\n"
0738           << "  DIGI-level: (checked? " << std::boolalpha << extract_digi_info_ << ")\n"
0739           << "    diamondVFATStatus.isValid = " << diamondVFATStatus.isValid() << "\n"
0740           << "    diamondDigis.isValid = " << diamondDigis.isValid() << "\n"
0741           << "    fedInfo.isValid = " << fedInfo.isValid() << "\n"
0742           << "  RECO-level:\n"
0743           << "    pixelTracks.isValid = " << pixelTracks.isValid() << "\n"
0744           << "    diamondRecHits.isValid = " << diamondRecHits.isValid() << "\n"
0745           << "    diamondLocalTracks.isValid = " << diamondLocalTracks.isValid();
0746     return;
0747   }
0748 
0749   //------------------------------
0750   // Sector Plots
0751   //------------------------------
0752   // Using CTPPSDiamondLocalTrack
0753   if (plotOffline_)
0754     for (const auto& tracks : *diamondLocalTracks) {
0755       const CTPPSDiamondDetId detId_near(tracks.detId());
0756 
0757       for (const auto& track : tracks) {
0758         if (!track.isValid())
0759           continue;
0760         if (potPlots_.count(detId_near.rpId()) == 0)
0761           continue;
0762         TH1F* trackHistoInTimeTmp = potPlots_[detId_near.rpId()].trackDistribution->getTH1F();
0763         int startBin_near =
0764             trackHistoInTimeTmp->FindBin(track.x0() - diamShifts_[detId_near.rpId()].global - track.x0Sigma());
0765         int numOfBins_near = 2 * track.x0Sigma() * INV_DISPLAY_RESOLUTION_FOR_HITS_MM;
0766 
0767         for (const auto& tracks_far : *diamondLocalTracks) {
0768           CTPPSDiamondDetId detId_far(tracks_far.detId());
0769           if (detId_near.arm() != detId_far.arm() || detId_near.station() == detId_far.station())
0770             continue;
0771           for (const auto& track_far : tracks_far) {
0772             if (!track.isValid())
0773               continue;
0774             if (sectorPlots_.count(detId_far.armId()) == 0)
0775               continue;
0776             TH2F* trackHistoTmp = sectorPlots_[detId_far.armId()].trackCorrelation->getTH2F();
0777             TAxis* trackHistoTmpXAxis = trackHistoTmp->GetXaxis();
0778             TAxis* trackHistoTmpYAxis = trackHistoTmp->GetYaxis();
0779             int startBin_far = trackHistoTmpYAxis->FindBin(track_far.x0() - diamShifts_[detId_far.rpId()].global -
0780                                                            track_far.x0Sigma());
0781             int numOfBins_far = 2 * track_far.x0Sigma() * INV_DISPLAY_RESOLUTION_FOR_HITS_MM;
0782             for (int i = 0; i < numOfBins_near; ++i)
0783               for (int y = 0; y < numOfBins_far; ++y) {
0784                 trackHistoTmp->Fill(trackHistoTmpXAxis->GetBinCenter(startBin_near + i),
0785                                     trackHistoTmpYAxis->GetBinCenter(startBin_far + y));
0786                 if (tracks.size() < 3 && tracks_far.size() < trackCorrelationThreshold_)
0787                   sectorPlots_[detId_far.armId()].trackCorrelationLowMultiplicity->Fill(
0788                       trackHistoTmpXAxis->GetBinCenter(startBin_near + i),
0789                       trackHistoTmpYAxis->GetBinCenter(startBin_far + y));
0790               }
0791           }
0792         }
0793       }
0794     }
0795 
0796   //------------------------------
0797   // RP Plots
0798   //------------------------------
0799 
0800   //------------------------------
0801   // Correlation Plots
0802   //------------------------------
0803 
0804   if (extract_digi_info_) {
0805     // Using CTPPSDiamondDigi
0806     for (const auto& digis : *diamondDigis) {
0807       const CTPPSDiamondDetId detId(digis.detId()), detId_pot(detId.rpId());
0808       for (const auto& digi : digis) {
0809         if (detId.channel() == CHANNEL_OF_VFAT_CLOCK)
0810           continue;
0811         if (potPlots_.count(detId_pot) == 0)
0812           continue;
0813         //Leading without trailing investigation
0814         if (digi.leadingEdge() != 0 || digi.trailingEdge() != 0) {
0815           ++potPlots_[detId_pot].HitCounter;
0816           if (digi.leadingEdge() != 0) {
0817             potPlots_[detId_pot].leadingEdgeCumulative_all->Fill(HPTDC_BIN_WIDTH_NS * digi.leadingEdge());
0818           }
0819           if (digi.leadingEdge() != 0 && digi.trailingEdge() == 0) {
0820             ++potPlots_[detId_pot].LeadingOnlyCounter;
0821             potPlots_[detId_pot].leadingEdgeCumulative_le->Fill(HPTDC_BIN_WIDTH_NS * digi.leadingEdge());
0822           }
0823           if (digi.leadingEdge() == 0 && digi.trailingEdge() != 0) {
0824             ++potPlots_[detId_pot].TrailingOnlyCounter;
0825             potPlots_[detId_pot].trailingEdgeCumulative_te->Fill(HPTDC_BIN_WIDTH_NS * digi.trailingEdge());
0826           }
0827           if (digi.leadingEdge() != 0 && digi.trailingEdge() != 0) {
0828             ++potPlots_[detId_pot].CompleteCounter;
0829             // potPlots_[detId_pot].leadingTrailingCorrelationPot->Fill(HPTDC_BIN_WIDTH_NS * digi.leadingEdge(),
0830             //                                                          HPTDC_BIN_WIDTH_NS * digi.trailingEdge());
0831           }
0832         }
0833 
0834         // HPTDC Errors
0835         const HPTDCErrorFlags hptdcErrors = digi.hptdcErrorFlags();
0836         if (detId.channel() == HPTDC_0_CHANNEL ||
0837             detId.channel() == HPTDC_1_CHANNEL) {  // ch6 for HPTDC 0 and ch7 for HPTDC 1
0838           int verticalIndex = 2 * detId.plane() + (detId.channel() - HPTDC_0_CHANNEL);
0839           for (unsigned short hptdcErrorIndex = 1; hptdcErrorIndex < 16; ++hptdcErrorIndex)
0840             if (hptdcErrors.errorId(hptdcErrorIndex - 1))
0841               potPlots_[detId_pot].HPTDCErrorFlags_2D->Fill(hptdcErrorIndex, verticalIndex);
0842         }
0843         if (digi.multipleHit())
0844           ++potPlots_[detId_pot].MHCounter;
0845       }
0846     }
0847   }
0848 
0849   // EC Errors
0850   if (extract_digi_info_) {
0851     for (const auto& vfat_status : *diamondVFATStatus) {
0852       const CTPPSDiamondDetId detId(vfat_status.detId());
0853       for (const auto& status : vfat_status) {
0854         if (!status.isOK())
0855           continue;
0856         if (potPlots_.count(detId.rpId()) == 0)
0857           continue;
0858         if (channelPlots_.count(detId) == 0)
0859           continue;
0860 
0861         // Check Event Number
0862         for (const auto& optorx : *fedInfo) {
0863           if (detId.arm() == 1 && optorx.fedId() == CTPPS_FED_ID_56)
0864             checkEventNumber(detId, optorx, status, potPlots_[detId.rpId()], EC_difference_56_);
0865           else if (detId.arm() == 0 && optorx.fedId() == CTPPS_FED_ID_45)
0866             checkEventNumber(detId, optorx, status, potPlots_[detId.rpId()], EC_difference_45_);
0867         }
0868       }
0869     }
0870   }
0871 
0872   // Using CTPPSDiamondRecHit
0873   std::unordered_map<unsigned int, std::set<unsigned int>> planes;
0874   std::unordered_map<unsigned int, std::set<unsigned int>> planes_inclusive;
0875 
0876   auto lumiCache = luminosityBlockCache(event.getLuminosityBlock().index());
0877   for (const auto& rechits : *diamondRecHits) {
0878     const CTPPSDiamondDetId detId(rechits.detId()), detId_pot(detId.rpId());
0879     const auto& x_shift = diamShifts_.at(detId_pot);
0880 
0881     for (const auto& rechit : rechits) {
0882       planes_inclusive[detId_pot].insert(detId.plane());
0883       if (excludeMultipleHits_ && rechit.multipleHits() > 0)
0884         continue;
0885       if (rechit.toT() != 0 && centralOOT_ != -999 && rechit.ootIndex() == centralOOT_)
0886         planes[detId_pot].insert(detId.plane());
0887 
0888       if (potPlots_.count(detId_pot) == 0)
0889         continue;
0890 
0891       potPlots_[detId_pot].recHitTime->Fill(rechit.time());
0892 
0893       float UFSDShift = 0.0;
0894       if (rechit.yWidth() < 3)
0895         UFSDShift = 0.5;  // Display trick for UFSD that have 2 pixels with same X
0896 
0897       if (rechit.toT() != 0 && centralOOT_ != -999 && rechit.ootIndex() == centralOOT_) {
0898         TH2F* hitHistoTmp = potPlots_[detId_pot].hitDistribution2d->getTH2F();
0899         TAxis* hitHistoTmpYAxis = hitHistoTmp->GetYaxis();
0900         int startBin = hitHistoTmpYAxis->FindBin(rechit.x() - x_shift.global - 0.5 * rechit.xWidth());
0901         int numOfBins = rechit.xWidth() * INV_DISPLAY_RESOLUTION_FOR_HITS_MM;
0902         for (int i = 0; i < numOfBins; ++i)
0903           hitHistoTmp->Fill(detId.plane() + UFSDShift, hitHistoTmpYAxis->GetBinCenter(startBin + i));
0904 
0905         if (!perLSsaving_ && plotOnline_) {
0906           hitHistoTmp = lumiCache->hitDistribution2dMap[detId_pot].get();
0907           hitHistoTmpYAxis = hitHistoTmp->GetYaxis();
0908           startBin = hitHistoTmpYAxis->FindBin(rechit.x() - x_shift.global - 0.5 * rechit.xWidth());
0909           numOfBins = rechit.xWidth() * INV_DISPLAY_RESOLUTION_FOR_HITS_MM;
0910           for (int i = 0; i < numOfBins; ++i)
0911             hitHistoTmp->Fill(detId.plane() + UFSDShift, hitHistoTmpYAxis->GetBinCenter(startBin + i));
0912         }
0913       }
0914 
0915       if (rechit.toT() != 0) {
0916         // Both
0917         potPlots_[detId_pot].leadingEdgeCumulative_both->Fill(rechit.time() + 25 * rechit.ootIndex());
0918         potPlots_[detId_pot].timeOverThresholdCumulativePot->Fill(rechit.toT());
0919 
0920         TH2F* hitHistoOOTTmp = potPlots_[detId_pot].hitDistribution2dOOT->getTH2F();
0921         TAxis* hitHistoOOTTmpYAxis = hitHistoOOTTmp->GetYaxis();
0922         int startBin = hitHistoOOTTmpYAxis->FindBin(rechit.x() - x_shift.global - 0.5 * rechit.xWidth());
0923         int numOfBins = rechit.xWidth() * INV_DISPLAY_RESOLUTION_FOR_HITS_MM;
0924         for (int i = 0; i < numOfBins; ++i)
0925           hitHistoOOTTmp->Fill(detId.plane() + 0.25 * rechit.ootIndex(),
0926                                hitHistoOOTTmpYAxis->GetBinCenter(startBin + i));
0927       } else if (rechit.ootIndex() != CTPPSDiamondRecHit::TIMESLICE_WITHOUT_LEADING && plotOnline_) {
0928         // Only leading
0929         TH2F* hitHistoOOTTmp = potPlots_[detId_pot].hitDistribution2dOOT_le->getTH2F();
0930         TAxis* hitHistoOOTTmpYAxis = hitHistoOOTTmp->GetYaxis();
0931         int startBin = hitHistoOOTTmpYAxis->FindBin(rechit.x() - x_shift.global - 0.5 * rechit.xWidth());
0932         int numOfBins = rechit.xWidth() * INV_DISPLAY_RESOLUTION_FOR_HITS_MM;
0933         for (int i = 0; i < numOfBins; ++i) {
0934           hitHistoOOTTmp->Fill(detId.plane() + 0.25 * rechit.ootIndex(),
0935                                hitHistoOOTTmpYAxis->GetBinCenter(startBin + i));
0936         }
0937       }
0938       if (rechit.ootIndex() != CTPPSDiamondRecHit::TIMESLICE_WITHOUT_LEADING &&
0939           potPlots_[detId_pot].activity_per_bx.count(rechit.ootIndex()) > 0)
0940         potPlots_[detId_pot].activity_per_bx.at(rechit.ootIndex())->Fill(event.bunchCrossing());
0941 
0942       // if(plotOffline_)
0943       //   potPlots_[detId_pot].TOTVsLS->Fill(event.luminosityBlock(),rechit.toT());
0944     }
0945   }
0946 
0947   for (const auto& plt : potPlots_) {
0948     plt.second.activePlanes->Fill(planes[plt.first].size());
0949     if (plotOnline_)
0950       plt.second.activePlanesInclusive->Fill(planes_inclusive[plt.first].size());
0951   }
0952 
0953   // Using CTPPSDiamondLocalTrack
0954   for (const auto& tracks : *diamondLocalTracks) {
0955     const CTPPSDiamondDetId detId(tracks.detId()), detId_pot(detId.rpId());
0956     const auto& x_shift = diamShifts_.at(detId_pot);
0957 
0958     for (const auto& track : tracks) {
0959       if (!track.isValid())
0960         continue;
0961       if (track.ootIndex() == CTPPSDiamondRecHit::TIMESLICE_WITHOUT_LEADING)
0962         continue;
0963       if (excludeMultipleHits_ && track.multipleHits() > 0)
0964         continue;
0965       if (potPlots_.count(detId_pot) == 0)
0966         continue;
0967 
0968       TH2F* trackHistoOOTTmp = potPlots_[detId_pot].trackDistributionOOT->getTH2F();
0969       TAxis* trackHistoOOTTmpYAxis = trackHistoOOTTmp->GetYaxis();
0970       int startBin = trackHistoOOTTmpYAxis->FindBin(track.x0() - x_shift.global - track.x0Sigma());
0971       int numOfBins = 2 * track.x0Sigma() * INV_DISPLAY_RESOLUTION_FOR_HITS_MM;
0972       for (int i = 0; i < numOfBins; ++i)
0973         trackHistoOOTTmp->Fill(track.ootIndex(), trackHistoOOTTmpYAxis->GetBinCenter(startBin + i));
0974 
0975       if (centralOOT_ != -999 && track.ootIndex() == centralOOT_) {
0976         TH1F* trackHistoInTimeTmp = potPlots_[detId_pot].trackDistribution->getTH1F();
0977         int startBin = trackHistoInTimeTmp->FindBin(track.x0() - x_shift.global - track.x0Sigma());
0978         int numOfBins = 2 * track.x0Sigma() * INV_DISPLAY_RESOLUTION_FOR_HITS_MM;
0979         for (int i = 0; i < numOfBins; ++i)
0980           trackHistoInTimeTmp->Fill(trackHistoInTimeTmp->GetBinCenter(startBin + i));
0981       }
0982       if (plotOffline_ && !perLSsaving_) {
0983         // potPlots_[detId_pot].trackTimeVsLS->Fill(event.luminosityBlock(),track.time());
0984         potPlots_[detId_pot].trackTimeVsBX->Fill(event.bunchCrossing(), track.time());
0985         //potPlots_[detId_pot].trackTimeVsXAngle->Fill(hLhcInfo->crossingAngle(), track.time());
0986       }
0987     }
0988   }
0989 
0990   // Channel efficiency using CTPPSDiamondLocalTrack
0991   for (const auto& tracks : *diamondLocalTracks) {
0992     const CTPPSDiamondDetId detId(tracks.detId()), detId_pot(detId.rpId());
0993     for (const auto& track : tracks) {
0994       // Find hits and planes in the track
0995       int numOfHits = 0;
0996       std::set<int> planesInTrackSet;
0997       for (const auto& vec : *diamondRecHits) {
0998         const CTPPSDiamondDetId detid(vec.detId());
0999         if (detid.arm() != detId_pot.arm())
1000           continue;
1001 
1002         for (const auto& hit : vec) {
1003           // first check if the hit contributes to the track
1004           if (track.containsHit(hit)) {
1005             ++numOfHits;
1006             planesInTrackSet.insert(detid.plane());
1007           }
1008         }
1009       }
1010 
1011       if (numOfHits > 0 && numOfHits <= 10 && planesInTrackSet.size() > 2) {
1012         for (const auto& plt_vs_ch : channelPlots_) {  // loop over all channels registered in geometry
1013           const CTPPSDiamondDetId detId(plt_vs_ch.first);
1014           if (detId.rpId() != detId_pot)
1015             continue;
1016           const unsigned short map_index = detId.plane() * 100 + detId.channel();
1017           if (potPlots_[detId_pot].effDoublecountingChMap.count(map_index) == 0) {
1018             potPlots_[detId_pot].effTriplecountingChMap[map_index] = 0;
1019             potPlots_[detId_pot].effDoublecountingChMap[map_index] = 0;
1020           }
1021           if (channelAlignedWithTrack(ctppsGeometry, detId, track, 0.2)) {
1022             // Channel should fire
1023             ++potPlots_[detId_pot].effDoublecountingChMap[map_index];
1024             for (const auto& rechits : *diamondRecHits) {
1025               const CTPPSDiamondDetId detId_hit(rechits.detId());
1026               if (detId_hit == detId)
1027                 for (const auto& rechit : rechits)
1028                   if (track.containsHit(rechit, 1))  // Channel fired
1029                     ++potPlots_[detId_pot].effTriplecountingChMap[map_index];
1030             }
1031           }
1032         }
1033       }
1034     }
1035   }
1036 
1037   // Tomography of diamonds using pixel
1038   for (const auto& rechits : *diamondRecHits) {
1039     const CTPPSDiamondDetId detId(rechits.detId()), detId_pot(detId.rpId());
1040     const auto pix_shift = diamShifts_.at(detId_pot).withPixels;
1041     for (const auto& rechit : rechits) {
1042       if (excludeMultipleHits_ && rechit.multipleHits() > 0)
1043         continue;
1044       if (rechit.toT() == 0)
1045         continue;
1046       if (!pixelTracks.isValid())
1047         continue;
1048       if (potPlots_.count(detId_pot) == 0)
1049         continue;
1050 
1051       for (const auto& ds : *pixelTracks) {
1052         if (ds.size() > 1)
1053           continue;
1054         const CTPPSPixelDetId pixId(ds.detId());
1055         if (pixId.station() != CTPPS_PIXEL_STATION_ID || pixId.rp() != CTPPS_FAR_RP_ID)
1056           continue;
1057         for (const auto& lt : ds) {
1058           if (lt.isValid() && pixId.arm() == detId_pot.arm()) {
1059             if (rechit.ootIndex() != CTPPSDiamondRecHit::TIMESLICE_WITHOUT_LEADING && rechit.ootIndex() >= 0 &&
1060                 potPlots_[detId_pot].pixelTomographyAll.count(rechit.ootIndex()) > 0 && lt.x0() - pix_shift < 24)
1061               potPlots_[detId_pot]
1062                   .pixelTomographyAll.at(rechit.ootIndex())
1063                   ->Fill(lt.x0() - pix_shift + 25 * detId.plane(), lt.y0());
1064           }
1065         }
1066       }
1067     }
1068   }
1069 
1070   //------------------------------
1071   // Clock Plots
1072   //------------------------------
1073   // Commented out to save space in the DQM files, but code should be kept
1074   // for ( const auto& digis : *diamondDigis ) {
1075   //   const CTPPSDiamondDetId detId(digis.detId()), detId_pot(detId.rpId());
1076   //   if ( detId.channel() == CHANNEL_OF_VFAT_CLOCK ) {
1077   //     for ( const auto& digi : digis ) {
1078   //       if ( digi.leadingEdge() != 0 )  {
1079   //         if ( detId.plane() == 1 ) {
1080   //           potPlots_[detId_pot].clock_Digi1_le->Fill( HPTDC_BIN_WIDTH_NS * digi.leadingEdge() );
1081   //           potPlots_[detId_pot].clock_Digi1_te->Fill( HPTDC_BIN_WIDTH_NS * digi.trailingEdge() );
1082   //         }
1083   //         if ( detId.plane() == 3 ) {
1084   //           potPlots_[detId_pot].clock_Digi3_le->Fill( HPTDC_BIN_WIDTH_NS * digi.leadingEdge() );
1085   //           potPlots_[detId_pot].clock_Digi3_te->Fill( HPTDC_BIN_WIDTH_NS * digi.trailingEdge() );
1086   //         }
1087   //       }
1088   //     }
1089   //   }
1090   // }
1091 
1092   //------------------------------
1093   // Plane Plots
1094   //------------------------------
1095 
1096   // Using CTPPSDiamondDigi
1097   std::unordered_map<unsigned int, unsigned int> channelsPerPlane;
1098   if (extract_digi_info_) {
1099     for (const auto& digis : *diamondDigis) {
1100       const CTPPSDiamondDetId detId(digis.detId()), detId_plane(detId.planeId());
1101       for (const auto& digi : digis) {
1102         if (detId.channel() == CHANNEL_OF_VFAT_CLOCK)
1103           continue;
1104         if (planePlots_.count(detId_plane) == 0)
1105           continue;
1106 
1107         if (digi.leadingEdge() != 0) {
1108           planePlots_[detId_plane].digiProfileCumulativePerPlane->Fill(detId.channel());
1109           channelsPerPlane[detId_plane]++;
1110         }
1111       }
1112     }
1113   }
1114 
1115   for (const auto& plt : channelsPerPlane)
1116     planePlots_[plt.first].hit_multiplicity->Fill(plt.second);
1117 
1118   // Using CTPPSDiamondRecHit
1119   for (const auto& rechits : *diamondRecHits) {
1120     const CTPPSDiamondDetId detId(rechits.detId()), detId_plane(detId.planeId()), detId_pot(detId.rpId());
1121     for (const auto& rechit : rechits) {
1122       if (excludeMultipleHits_ && rechit.multipleHits() > 0)
1123         continue;
1124       if (rechit.toT() == 0)
1125         continue;
1126       if (planePlots_.count(detId_plane) != 0) {
1127         if (centralOOT_ != -999 && rechit.ootIndex() == centralOOT_) {
1128           TH1F* hitHistoTmp = planePlots_[detId_plane].hitProfile->getTH1F();
1129           int startBin = hitHistoTmp->FindBin(rechit.x() - diamShifts_.at(detId_pot).global - 0.5 * rechit.xWidth());
1130           int numOfBins = rechit.xWidth() * INV_DISPLAY_RESOLUTION_FOR_HITS_MM;
1131           for (int i = 0; i < numOfBins; ++i)
1132             hitHistoTmp->Fill(hitHistoTmp->GetBinCenter(startBin + i));
1133         }
1134       }
1135     }
1136   }
1137 
1138   //Tomography of diamonds using pixel and Efficiency WRT Pixels
1139   for (const auto& ds : *pixelTracks) {
1140     const CTPPSPixelDetId pixId(ds.detId());
1141     if (pixId.station() != CTPPS_PIXEL_STATION_ID || pixId.rp() != CTPPS_FAR_RP_ID)
1142       continue;
1143     if (ds.size() > 1)
1144       continue;
1145     for (const auto& lt : ds) {
1146       if (lt.isValid()) {
1147         for (const auto& sh_vs_id : diamShifts_) {
1148           const CTPPSDiamondDetId& detId_pot = sh_vs_id.first;
1149           const auto& shift = sh_vs_id.second;
1150           if (detId_pot.arm() == pixId.arm())
1151             // For efficieny
1152             potPlots_[detId_pot].pixelTracksMap.Fill(lt.x0() - shift.withPixels, lt.y0());
1153         }
1154 
1155         std::set<CTPPSDiamondDetId> planesWitHits_set;
1156         for (const auto& rechits : *diamondRecHits) {
1157           const CTPPSDiamondDetId detId(rechits.detId()), detId_plane(detId.planeId()), detId_pot(detId.rpId());
1158           const auto pix_shift = diamShifts_.at(detId_pot).withPixels;
1159           for (const auto& rechit : rechits) {
1160             if (excludeMultipleHits_ && rechit.multipleHits() > 0)
1161               continue;
1162             if (rechit.ootIndex() == CTPPSDiamondRecHit::TIMESLICE_WITHOUT_LEADING || rechit.toT() == 0)
1163               continue;
1164             if (planePlots_.count(detId_plane) == 0)
1165               continue;
1166             if (pixId.arm() == detId_plane.arm() && lt.x0() - pix_shift < 24) {
1167               planePlots_[detId_plane].pixelTomography_far->Fill(lt.x0() - pix_shift + 25 * rechit.ootIndex(), lt.y0());
1168               if (centralOOT_ != -999 && rechit.ootIndex() == centralOOT_)
1169                 planesWitHits_set.insert(detId_plane);
1170             }
1171           }
1172         }
1173 
1174         for (auto& planeId : planesWitHits_set)
1175           planePlots_[planeId].pixelTracksMapWithDiamonds.Fill(lt.x0() - diamShifts_.at(planeId.rpId()).withPixels,
1176                                                                lt.y0());
1177       }
1178     }
1179   }
1180 
1181   //------------------------------
1182   // Channel Plots
1183   //------------------------------
1184 
1185   // digi profile cumulative
1186   if (extract_digi_info_) {
1187     for (const auto& digis : *diamondDigis) {
1188       const CTPPSDiamondDetId detId(digis.detId());
1189       for (const auto& digi : digis) {
1190         if (detId.channel() == CHANNEL_OF_VFAT_CLOCK)
1191           continue;
1192         if (channelPlots_.count(detId) != 0) {
1193           // HPTDC Errors
1194           const HPTDCErrorFlags hptdcErrors = digi.hptdcErrorFlags();
1195           for (unsigned short hptdcErrorIndex = 1; hptdcErrorIndex < 16; ++hptdcErrorIndex)
1196             if (hptdcErrors.errorId(hptdcErrorIndex - 1))
1197               channelPlots_[detId].HPTDCErrorFlags->Fill(hptdcErrorIndex);
1198           if (digi.multipleHit())
1199             ++channelPlots_[detId].MHCounter;
1200 
1201           // Check dropped trailing edges
1202           if (digi.leadingEdge() != 0 || digi.trailingEdge() != 0) {
1203             ++channelPlots_[detId].HitCounter;
1204             if (digi.trailingEdge() == 0) {
1205               ++channelPlots_[detId].LeadingOnlyCounter;
1206               channelPlots_[detId].leadingEdgeCumulative_le->Fill(HPTDC_BIN_WIDTH_NS * digi.leadingEdge());
1207             } else if (digi.leadingEdge() == 0) {
1208               ++channelPlots_[detId].TrailingOnlyCounter;
1209               channelPlots_[detId].trailingEdgeCumulative_te->Fill(HPTDC_BIN_WIDTH_NS * digi.trailingEdge());
1210             } else {
1211               ++channelPlots_[detId].CompleteCounter;
1212               // channelPlots_[detId].LeadingTrailingCorrelationPerChannel->Fill(HPTDC_BIN_WIDTH_NS * digi.leadingEdge(),
1213               //                                                                 HPTDC_BIN_WIDTH_NS * digi.trailingEdge());
1214             }
1215           }
1216         }
1217       }
1218     }
1219   }
1220 
1221   // Using CTPPSDiamondRecHit
1222 
1223   for (const auto& rechits : *diamondRecHits) {
1224     CTPPSDiamondDetId detId(rechits.detId());
1225     for (const auto& rechit : rechits) {
1226       if (excludeMultipleHits_ && rechit.multipleHits() > 0)
1227         continue;
1228       if (channelPlots_.count(detId) != 0) {
1229         channelPlots_[detId].recHitTime->Fill(rechit.time());
1230         if (rechit.ootIndex() != CTPPSDiamondRecHit::TIMESLICE_WITHOUT_LEADING && rechit.toT() != 0) {
1231           channelPlots_[detId].leadingEdgeCumulative_both->Fill(rechit.time() + 25 * rechit.ootIndex());
1232           channelPlots_[detId].TimeOverThresholdCumulativePerChannel->Fill(rechit.toT());
1233         }
1234         ++lumiCache->hitsCounterMap[detId];
1235 
1236         if (rechit.ootIndex() != CTPPSDiamondRecHit::TIMESLICE_WITHOUT_LEADING &&
1237             channelPlots_[detId].activity_per_bx.count(rechit.ootIndex()) > 0)
1238           channelPlots_[detId].activity_per_bx.at(rechit.ootIndex())->Fill(event.bunchCrossing());
1239       }
1240     }
1241   }
1242 
1243   // Tomography of diamonds using pixel
1244   for (const auto& rechits : *diamondRecHits) {
1245     const CTPPSDiamondDetId detId(rechits.detId()), detId_pot(detId.rpId());
1246     const auto shift_pix = diamShifts_.at(detId_pot).withPixels;
1247     for (const auto& rechit : rechits) {
1248       if (excludeMultipleHits_ && rechit.multipleHits() > 0)
1249         continue;
1250       if (rechit.ootIndex() == CTPPSDiamondRecHit::TIMESLICE_WITHOUT_LEADING || rechit.toT() == 0)
1251         continue;
1252       if (!pixelTracks.isValid())
1253         continue;
1254       if (channelPlots_.count(detId) == 0)
1255         continue;
1256 
1257       for (const auto& ds : *pixelTracks) {
1258         const CTPPSPixelDetId pixId(ds.detId());
1259         if (pixId.station() != CTPPS_PIXEL_STATION_ID || pixId.rp() != CTPPS_FAR_RP_ID)
1260           continue;
1261         if (ds.size() > 1)
1262           continue;
1263         for (const auto& lt : ds) {
1264           if (lt.isValid() && pixId.arm() == detId.arm() && lt.x0() - shift_pix < 24)
1265             channelPlots_[detId].pixelTomography_far->Fill(lt.x0() - shift_pix + 25 * rechit.ootIndex(), lt.y0());
1266         }
1267       }
1268     }
1269   }
1270 }
1271 
1272 //----------------------------------------------------------------------------------------------------
1273 
1274 void CTPPSDiamondDQMSource::globalEndLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup&) {
1275   auto lumiCache = luminosityBlockCache(iLumi.index());
1276   if (!perLSsaving_) {
1277     if (plotOnline_)
1278       for (auto& plot : potPlots_) {
1279         *(plot.second.hitDistribution2d_lumisection->getTH2F()) = *(lumiCache->hitDistribution2dMap[plot.first]);
1280       }
1281 
1282     for (auto& plot : channelPlots_) {
1283       auto hitsCounterPerLumisection = lumiCache->hitsCounterMap[plot.first];
1284       if (hitsCounterPerLumisection != 0) {
1285         plot.second.hit_rate->Fill((double)hitsCounterPerLumisection / SEC_PER_LUMI_SECTION);
1286       }
1287 
1288       double HundredOverHitCounter = .0;
1289       if (plot.second.HitCounter != 0)
1290         HundredOverHitCounter = 100. / plot.second.HitCounter;
1291       plot.second.HPTDCErrorFlags->setBinContent(16, HundredOverHitCounter * plot.second.MHCounter);
1292       plot.second.leadingWithoutTrailing->setBinContent(1, HundredOverHitCounter * plot.second.LeadingOnlyCounter);
1293       plot.second.leadingWithoutTrailing->setBinContent(2, HundredOverHitCounter * plot.second.TrailingOnlyCounter);
1294       plot.second.leadingWithoutTrailing->setBinContent(3, HundredOverHitCounter * plot.second.CompleteCounter);
1295     }
1296 
1297     for (auto& plot : potPlots_) {
1298       double HundredOverHitCounterPot = 0.;
1299       if (plot.second.HitCounter != 0)
1300         HundredOverHitCounterPot = 100. / plot.second.HitCounter;
1301       plot.second.leadingWithoutTrailingCumulativePot->setBinContent(
1302           1, HundredOverHitCounterPot * plot.second.LeadingOnlyCounter);
1303       plot.second.leadingWithoutTrailingCumulativePot->setBinContent(
1304           2, HundredOverHitCounterPot * plot.second.TrailingOnlyCounter);
1305       plot.second.leadingWithoutTrailingCumulativePot->setBinContent(
1306           3, HundredOverHitCounterPot * plot.second.CompleteCounter);
1307 
1308       plot.second.MHComprensive->Reset();
1309       const CTPPSDiamondDetId rpId(plot.first);
1310       for (auto& chPlot : channelPlots_) {
1311         const CTPPSDiamondDetId chId(chPlot.first);
1312         if (chId.arm() == rpId.arm() && chId.rp() == rpId.rp()) {
1313           plot.second.MHComprensive->Fill(
1314               chId.plane(), chId.channel(), chPlot.second.HPTDCErrorFlags->getBinContent(16));
1315         }
1316       }
1317     }
1318     // Efficiencies of single channels
1319     if (plotOnline_)
1320       for (auto& plot : potPlots_) {
1321         plot.second.EfficiencyOfChannelsInPot->Reset();
1322         for (auto& element : plot.second.effTriplecountingChMap) {
1323           if (plot.second.effDoublecountingChMap[element.first] > 0) {
1324             int plane = element.first / 100;
1325             int channel = element.first % 100;
1326             double counted = element.second;
1327             double total = plot.second.effDoublecountingChMap[element.first];
1328             double efficiency = counted / total;
1329             //         double error = std::sqrt( efficiency * ( 1 - efficiency ) / total );
1330 
1331             plot.second.EfficiencyOfChannelsInPot->Fill(plane, channel, 100 * efficiency);
1332           }
1333         }
1334       }
1335 
1336     // Efficeincy wrt pixels  //TODO
1337     for (auto& plot : planePlots_) {
1338       TH2F* hitHistoTmp = plot.second.EfficiencyWRTPixelsInPlane->getTH2F();
1339 
1340       const CTPPSDiamondDetId detId(plot.first), detId_pot(detId.rpId());
1341       hitHistoTmp->Divide(&(plot.second.pixelTracksMapWithDiamonds), &(potPlots_[detId_pot].pixelTracksMap));
1342     }
1343   }  //perLSsaving
1344 }
1345 
1346 //----------------------------------------------------------------------------------------------------
1347 
1348 void CTPPSDiamondDQMSource::checkEventNumber(const CTPPSDiamondDetId& detId,
1349                                              const TotemFEDInfo& optorx,
1350                                              const TotemVFATStatus& status,
1351                                              CTPPSDiamondDQMSource::PotPlots& plots,
1352                                              int& EC_difference) const {
1353   const CTPPSDiamondDetId detId_pot(detId.rpId());
1354   if (plotOnline_)
1355     plots.ECCheck->Fill((int)((optorx.lv1() & 0xFF) - ((unsigned int)status.ec() & 0xFF)) & 0xFF);
1356   if ((static_cast<int>((optorx.lv1() & 0xFF) - status.ec()) != EC_difference) &&
1357       (static_cast<uint8_t>((optorx.lv1() & 0xFF) - status.ec()) < 128))
1358     EC_difference = static_cast<int>(optorx.lv1() & 0xFF) - (static_cast<unsigned int>(status.ec()) & 0xFF);
1359   if (EC_difference != 1 && EC_difference != -500 && std::abs(EC_difference) < 127) {
1360     if (detId.channel() == HPTDC_0_CHANNEL || detId.channel() == HPTDC_1_CHANNEL)
1361       plots.HPTDCErrorFlags_2D->Fill(16, 2 * detId.plane() + (detId.channel() - HPTDC_0_CHANNEL));
1362     if (verbosity_)
1363       edm::LogProblem("CTPPSDiamondDQMSource")
1364           << "FED " << optorx.fedId() << ": ECError at EV: 0x" << std::hex << optorx.lv1() << "\t\tVFAT EC: 0x"
1365           << static_cast<unsigned int>(status.ec()) << "\twith ID: " << std::dec << detId
1366           << "\tdiff: " << EC_difference;
1367   }
1368 }
1369 
1370 //----------------------------------------------------------------------------------------------------
1371 
1372 void CTPPSDiamondDQMSource::dqmEndRun(edm::Run const&, edm::EventSetup const&) {
1373   if (plotOffline_ && !perLSsaving_)
1374     for (const auto& rpPlots : potPlots_) {
1375       auto plots = rpPlots.second;
1376       // *(plots.TOTVsLSProfile->getTProfile())=*plots.TOTVsLS->getTH2F()->ProfileX();
1377       // *(plots.trackTimeVsLSProfile->getTProfile())=*plots.trackTimeVsLS->getTH2F()->ProfileX();
1378       *(plots.trackTimeVsBXProfile->getTProfile()) = *plots.trackTimeVsBX->getTH2F()->ProfileX();
1379       // *(plots.trackTimeVsXAngleProfile->getTProfile()) = *plots.trackTimeVsXAngle->getTH2F()->ProfileX();
1380     }
1381 }
1382 
1383 //----------------------------------------------------------------------------------------------------
1384 DEFINE_FWK_MODULE(CTPPSDiamondDQMSource);