Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-07-22 22:43:42

0001 /*
0002  * =====================================================================================
0003  *
0004  *       Filename:  EventProcessor_processCSC.cc
0005  *
0006  *    Description:  Process Chamber
0007  *
0008  *        Version:  1.0
0009  *        Created:  10/03/2008 11:58:11 PM
0010  *       Revision:  none
0011  *       Compiler:  gcc
0012  *
0013  *         Author:  Valdas Rapsevicius, valdas.rapsevicius@cern.ch
0014  *        Company:  CERN, CH
0015  *
0016  * =====================================================================================
0017  */
0018 
0019 #include "CSCDQM_EventProcessor.h"
0020 
0021 namespace cscdqm {
0022 
0023   template <typename T>
0024   inline CSCCFEBDataWord const* const timeSample(T const& data, int nCFEB, int nSample, int nLayer, int nStrip) {
0025     return data.cfebData(nCFEB)->timeSlice(nSample)->timeSample(nLayer, nStrip, data.cfebData(nCFEB)->isDCFEB());
0026   }
0027 
0028   template <typename T>
0029   inline CSCCFEBTimeSlice const* const timeSlice(T const& data, int nCFEB, int nSample) {
0030     return data.cfebData(nCFEB)->timeSlice(nSample);
0031   }
0032 
0033   /**
0034    * @brief  Set a single bit in the 3D Histogram (aka EMU level event display). Checks if mo and x != null.
0035    * @param  eventNumber number of event
0036    * @param  mo Histogram
0037    * @param  x X bin number
0038    * @param  y Y bin number
0039    * @param  bit bit number to set
0040    */
0041   void EventProcessor::setEmuEventDisplayBit(MonitorObject*& mo,
0042                                              const unsigned int x,
0043                                              const unsigned int y,
0044                                              const unsigned int bit) {
0045     if (mo && x) {
0046       resetEmuEventDisplays();
0047       int bitset = (int)mo->GetBinContent(x, y);
0048       bitset |= 1 << bit;
0049       mo->SetBinContent(x, y, bitset);
0050     }
0051   }
0052 
0053   /**
0054    * @brief  Reset Emu level EventDisplay histograms once per event
0055    */
0056   void EventProcessor::resetEmuEventDisplays() {
0057     if (!EmuEventDisplayWasReset) {
0058       // Reseting EMU level Event displays
0059       MonitorObject* mo = nullptr;
0060       if (getEMUHisto(h::EMU_EVENT_DISPLAY_ANODE, mo)) {
0061         mo->getTH1Lock()->Reset("");
0062       }
0063 
0064       if (getEMUHisto(h::EMU_EVENT_DISPLAY_CATHODE, mo)) {
0065         mo->getTH1Lock()->Reset("");
0066       }
0067 
0068       if (getEMUHisto(h::EMU_EVENT_DISPLAY_XY, mo)) {
0069         mo->getTH1Lock()->Reset("");
0070       }
0071 
0072       EmuEventDisplayWasReset = true;
0073     }
0074   }
0075 
0076   /**
0077    * @brief  Process Chamber Data and fill MOs
0078    * @param  data Chamber data to process
0079    * @param dduID DDU identifier
0080    */
0081   void EventProcessor::processCSC(const CSCEventData& data, const int dduID, const CSCDCCExaminer& binChecker) {
0082     config->incNUnpackedCSC();
0083 
0084     int FEBunpacked = 0;
0085     int alct_unpacked = 0;
0086     int tmb_unpacked = 0;
0087     int cfeb_unpacked = 0;
0088 
0089     int alct_keywg = -1;
0090     int clct_kewdistrip = -1;
0091 
0092     bool L1A_out_of_sync = false;
0093 
0094     int nCFEBs = 5;
0095 
0096     MonitorObject* mo = nullptr;
0097 
0098     /**   DMB Found */
0099     /**   Unpacking of DMB Header and trailer */
0100     const CSCDMBHeader* dmbHeader = data.dmbHeader();
0101     const CSCDMBTrailer* dmbTrailer = data.dmbTrailer();
0102     if (!dmbHeader && !dmbTrailer) {
0103       LOG_ERROR << "Can not unpack DMB Header or/and Trailer";
0104       return;
0105     }
0106 
0107     theFormatVersion = data.getFormatVersion();
0108 
0109     /**  Unpacking of Chamber Identification number */
0110     unsigned int crateID = 0xFF;
0111     unsigned int dmbID = 0xF;
0112     unsigned int chamberID = 0xFFF;
0113 
0114     crateID = dmbHeader->crateID();
0115     dmbID = dmbHeader->dmbID();
0116     chamberID = (((crateID) << 4) + dmbID) & 0xFFF;
0117 
0118     const std::string cscTag = CSCHistoDef::getPath(crateID, dmbID);
0119 
0120     unsigned long errors = binChecker.errorsForChamber(chamberID);
0121     if ((errors & config->getBINCHECK_MASK()) > 0) {
0122       LOG_WARN << "Format Errors " << cscTag << ": 0x" << std::hex << errors << " Skipped CSC Unpacking";
0123       return;
0124     }
0125 
0126     unsigned int cscType = 0;
0127     unsigned int cscPosition = 0;
0128     if (!getCSCFromMap(crateID, dmbID, cscType, cscPosition))
0129       return;
0130 
0131     CSCDetId cid;
0132     if (!config->fnGetCSCDetId(crateID, dmbID, cid)) {
0133       return;
0134     }
0135 
0136     // Check if ME11 with PostLS1 readout (7 DCFEBs)
0137     if ((cscType == 8 || cscType == 9) && theFormatVersion >= 2013)
0138       nCFEBs = 7;
0139 
0140     // Check if in standby!
0141     if (summary.isChamberStandby(cid)) {
0142       return;
0143     }
0144 
0145     double DMBEvents = 0.0;
0146     DMBEvents = config->getChamberCounterValue(DMB_EVENTS, crateID, dmbID);
0147 
0148     // Get Event display plot number and next plot object
0149     uint32_t evDisplNo = config->getChamberCounterValue(EVENT_DISPLAY_PLOT, crateID, dmbID);
0150     evDisplNo += 1;
0151     if (evDisplNo >= 5) {
0152       config->setChamberCounterValue(EVENT_DISPLAY_PLOT, crateID, dmbID, 0);
0153     } else {
0154       config->setChamberCounterValue(EVENT_DISPLAY_PLOT, crateID, dmbID, evDisplNo);
0155     }
0156     MonitorObject* mo_EventDisplay = nullptr;
0157     if (getCSCHisto(h::CSC_EVENT_DISPLAY_NOXX, crateID, dmbID, evDisplNo, mo_EventDisplay)) {
0158       mo_EventDisplay->getTH1Lock()->Reset("");
0159     }
0160 
0161     // Receiving EMU Event displays
0162     MonitorObject *mo_Emu_EventDisplay_Anode = nullptr, *mo_Emu_EventDisplay_Cathode = nullptr,
0163                   *mo_Emu_EventDisplay_XY = nullptr;
0164     getEMUHisto(h::EMU_EVENT_DISPLAY_ANODE, mo_Emu_EventDisplay_Anode);
0165     getEMUHisto(h::EMU_EVENT_DISPLAY_CATHODE, mo_Emu_EventDisplay_Cathode);
0166     getEMUHisto(h::EMU_EVENT_DISPLAY_XY, mo_Emu_EventDisplay_XY);
0167 
0168     // Global chamber index
0169     uint32_t glChamberIndex = 0;
0170 
0171     if (mo_EventDisplay) {
0172       mo_EventDisplay->SetBinContent(1, 1, cid.endcap());
0173       mo_EventDisplay->SetBinContent(1, 2, cid.station());
0174       mo_EventDisplay->SetBinContent(1, 3, cid.ring());
0175       mo_EventDisplay->SetBinContent(1, 4, cscPosition);
0176       mo_EventDisplay->SetBinContent(1, 5, crateID);
0177       mo_EventDisplay->SetBinContent(1, 6, dmbID);
0178       mo_EventDisplay->SetBinContent(1, 7, dmbHeader->l1a24());
0179       if (mo_Emu_EventDisplay_Anode || mo_Emu_EventDisplay_Cathode || mo_Emu_EventDisplay_XY) {
0180         glChamberIndex = summary.getDetector().GlobalChamberIndex(cid.endcap(), cid.station(), cid.ring(), cscPosition);
0181       }
0182     }
0183 
0184     config->copyChamberCounterValue(DMB_EVENTS, DMB_TRIGGERS, crateID, dmbID);
0185 
0186     if (cscPosition && getEMUHisto(h::EMU_CSC_UNPACKED, mo)) {
0187       mo->Fill(cscPosition, cscType);
0188     }
0189 
0190     /**     Efficiency of the chamber */
0191     float DMBEff = float(DMBEvents) / float(config->getNEvents());
0192     if (DMBEff > 1.0) {
0193       LOG_ERROR << cscTag << " has efficiency " << DMBEff << " which is greater than 1";
0194     }
0195 
0196     /**  Unpacking L1A number from DMB header */
0197     /**  DMB L1A: 8bits (256) */
0198     /**  DDU L1A: 24bits */
0199     int dmbHeaderL1A = dmbHeader->l1a24() % 64;
0200     /**  Calculate difference between L1A numbers from DDU and DMB */
0201     int dmb_ddu_l1a_diff = (int)(dmbHeaderL1A - (int)(L1ANumber % 64));
0202     if (dmb_ddu_l1a_diff != 0)
0203       L1A_out_of_sync = true;
0204 
0205     /** LOG_DEBUG << dmbHeaderL1A << " : DMB L1A - DDU L1A = " << dmb_ddu_l1a_diff; */
0206 
0207     if (getCSCHisto(h::CSC_DMB_L1A_DISTRIB, crateID, dmbID, mo))
0208       mo->Fill(dmbHeaderL1A);
0209 
0210     if (getCSCHisto(h::CSC_DMB_DDU_L1A_DIFF, crateID, dmbID, mo)) {
0211       if (dmb_ddu_l1a_diff < -32) {
0212         mo->Fill(dmb_ddu_l1a_diff + 64);
0213       } else {
0214         if (dmb_ddu_l1a_diff >= 32)
0215           mo->Fill(dmb_ddu_l1a_diff - 64);
0216         else
0217           mo->Fill(dmb_ddu_l1a_diff);
0218       }
0219       mo->SetAxisRange(0.1, 1.1 * (1.0 + mo->GetBinContent(mo->GetMaximumBin())), "Y");
0220     }
0221 
0222     if (getCSCHisto(h::CSC_DMB_L1A_VS_DDU_L1A, crateID, dmbID, mo))
0223       mo->Fill((int)(L1ANumber & 0xFF), (int)dmbHeaderL1A);
0224 
0225     /**     Unpacking BXN number from DMB header */
0226     int dmbHeaderBXN = 0;
0227     int dmb_ddu_bxn_diff = 0;
0228 
0229     /**  == DMB BXN: 12bits (4096) call bxn12(), bxn() return 7bits value */
0230     /**  == DDU BXN: 12bits (4096)  */
0231 
0232     /**  == Use 6-bit BXN */
0233     dmbHeaderBXN = dmbHeader->bxn12();
0234     /**  Calculation difference between BXN numbers from DDU and DMB */
0235 
0236     /**   dmb_ddu_bxn_diff = (int)(dmbHeaderBXN-(int)(BXN&0x7F)); // For older DMB */
0237     dmb_ddu_bxn_diff = dmbHeaderBXN % 64 - BXN % 64;
0238     /** LOG_DEBUG << dmbHeaderBXN << " : DMB BXN - DDU BXN = " << dmb_ddu_bxn_diff; */
0239     if (getCSCHisto(h::CSC_DMB_BXN_DISTRIB, crateID, dmbID, mo))
0240       mo->Fill((int)(dmbHeader->bxn12()));
0241 
0242     if (getCSCHisto(h::CSC_DMB_DDU_BXN_DIFF, crateID, dmbID, mo)) {
0243       if (dmb_ddu_bxn_diff < -32)
0244         mo->Fill(dmb_ddu_bxn_diff + 64);
0245       else {
0246         if (dmb_ddu_bxn_diff >= 32)
0247           mo->Fill(dmb_ddu_bxn_diff - 64);
0248         else
0249           mo->Fill(dmb_ddu_bxn_diff);
0250       }
0251       mo->SetAxisRange(0.1, 1.1 * (1.0 + mo->GetBinContent(mo->GetMaximumBin())), "Y");
0252     }
0253 
0254     if (getCSCHisto(h::CSC_DMB_BXN_VS_DDU_BXN, crateID, dmbID, mo))
0255       mo->Fill(((int)(BXN)) % 256, ((int)dmbHeaderBXN) % 256);
0256 
0257     /**     Unpacking CFEB information from DMB header */
0258     int cfeb_dav = 0;
0259     int cfeb_dav_num = 0;
0260     int cfeb_movlp = 0;
0261     int dmb_cfeb_sync = 0;
0262 
0263     cfeb_dav = (int)dmbHeader->cfebAvailable();
0264     for (int i = 0; i < nCFEBs; i++)
0265       cfeb_dav_num += (cfeb_dav >> i) & 0x1;
0266     cfeb_movlp = (int)dmbHeader->cfebMovlp();
0267     dmb_cfeb_sync = (int)dmbHeader->dmbCfebSync();
0268 
0269     if (getCSCHisto(h::CSC_DMB_CFEB_DAV, crateID, dmbID, mo)) {
0270       for (int i = 0; i < nCFEBs; i++) {
0271         int cfeb_present = (cfeb_dav >> i) & 0x1;
0272         if (cfeb_present) {
0273           mo->Fill(i);
0274         }
0275       }
0276     }
0277 
0278     if (getCSCHisto(h::CSC_DMB_CFEB_DAV_MULTIPLICITY, crateID, dmbID, mo))
0279       mo->Fill(cfeb_dav_num);
0280     if (getCSCHisto(h::CSC_DMB_CFEB_MOVLP, crateID, dmbID, mo))
0281       mo->Fill(cfeb_movlp);
0282     if (getCSCHisto(h::CSC_DMB_CFEB_SYNC, crateID, dmbID, mo))
0283       mo->Fill(dmb_cfeb_sync);
0284 
0285     if (getEMUHisto(h::EMU_DMB_UNPACKED, mo)) {
0286       mo->Fill(crateID, dmbID);
0287       /**   mo->SetEntries(config->getNEvents()); */
0288     }
0289 
0290     if (getCSCHisto(h::CSC_DMB_CFEB_ACTIVE, crateID, dmbID, mo))
0291       mo->Fill(dmbHeader->cfebActive());  //KK
0292 
0293     if (getCSCHisto(h::CSC_DMB_L1_PIPE, crateID, dmbID, mo))
0294       mo->Fill(dmbTrailer->dmb_l1pipe());
0295 
0296     /**  DMB input (7 in total) FIFO stuff goes here */
0297     if (getCSCHisto(h::CSC_DMB_FIFO_STATS, crateID, dmbID, mo)) {
0298       if (dmbTrailer->tmb_empty() == 1)
0299         mo->Fill(1.0, 0.0);  //KK
0300       if (dmbTrailer->tmb_half() == 0)
0301         mo->Fill(1.0, 1.0);
0302       if (dmbTrailer->tmb_full() == 1)
0303         mo->Fill(1.0, 2.0);  //KK
0304       if (dmbTrailer->alct_empty() == 1)
0305         mo->Fill(0.0, 0.0);
0306       if (dmbTrailer->alct_half() == 0)
0307         mo->Fill(0.0, 1.0);
0308       if (dmbTrailer->alct_full() == 1)
0309         mo->Fill(0.0, 2.0);  //KK 0->1
0310       for (int i = 0; i < nCFEBs; i++) {
0311         if ((int)((dmbTrailer->cfeb_empty() >> i) & 0x1) == 1)
0312           mo->Fill(i + 2, 0.0);
0313         if ((int)((dmbTrailer->cfeb_half() >> i) & 0x1) == 0)
0314           mo->Fill(i + 2, 1);
0315         if ((int)((dmbTrailer->cfeb_full() >> i) & 0x1) == 1) {
0316           mo->Fill(i + 2, 2);
0317         }
0318       }
0319       mo->SetEntries((int)DMBEvents);
0320     }
0321 
0322     /**  DMB input timeout (total 15 bits) goes here */
0323     if (getCSCHisto(h::CSC_DMB_FEB_TIMEOUTS, crateID, dmbID, mo)) {
0324       if ((dmbTrailer->tmb_starttimeout() == 0) && (dmbTrailer->alct_starttimeout() == 0) &&
0325           (dmbTrailer->cfeb_starttimeout() == 0) && (dmbTrailer->cfeb_endtimeout() == 0)) {
0326         mo->Fill(0.0);
0327       } else {
0328         if (dmbTrailer->alct_starttimeout())
0329           mo->Fill(1);
0330         if (dmbTrailer->tmb_starttimeout())
0331           mo->Fill(2);
0332         if (dmbTrailer->alct_endtimeout())
0333           mo->Fill(8);  // KK
0334         if (dmbTrailer->tmb_endtimeout())
0335           mo->Fill(9);  // KK
0336       }
0337       for (int i = 0; i < nCFEBs; i++) {
0338         if ((dmbTrailer->cfeb_starttimeout() >> i) & 0x1) {
0339           mo->Fill(i + 3);
0340         }
0341         if ((dmbTrailer->cfeb_endtimeout() >> i) & 0x1) {
0342           mo->Fill(i + 10);  // KK 8->10
0343         }
0344       }
0345       mo->SetEntries((int)DMBEvents);
0346     }
0347 
0348     /**       Get FEBs Data Available Info */
0349     int alct_dav = dmbHeader->nalct();
0350     int tmb_dav = dmbHeader->nclct();
0351     int cfeb_dav2 = 0;
0352     for (int i = 0; i < nCFEBs; i++)
0353       cfeb_dav2 = cfeb_dav2 + (int)((dmbHeader->cfebAvailable() >> i) & 0x1);
0354 
0355     /**       Fill Hisogram for FEB DAV Efficiency */
0356 
0357     if ((alct_dav > 0) && (getCSCHisto(h::CSC_DMB_FEB_DAV_RATE, crateID, dmbID, mo))) {
0358       mo->Fill(0.0);
0359       float alct_dav_number = mo->GetBinContent(1);
0360       if (getCSCHisto(h::CSC_DMB_FEB_DAV_EFFICIENCY, crateID, dmbID, mo)) {
0361         mo->SetBinContent(1, ((float)alct_dav_number / (float)(DMBEvents)*100.0));
0362         mo->SetEntries((int)DMBEvents);
0363       }
0364     }
0365 
0366     if ((tmb_dav > 0) && (getCSCHisto(h::CSC_DMB_FEB_DAV_RATE, crateID, dmbID, mo))) {
0367       mo->Fill(1.0);
0368       float tmb_dav_number = mo->GetBinContent(2);
0369       if (getCSCHisto(h::CSC_DMB_FEB_DAV_EFFICIENCY, crateID, dmbID, mo)) {
0370         mo->SetBinContent(2, ((float)tmb_dav_number / (float)(DMBEvents)*100.0));
0371         mo->SetEntries((int)DMBEvents);
0372       }
0373     }
0374 
0375     if ((cfeb_dav2 > 0) && (getCSCHisto(h::CSC_DMB_FEB_DAV_RATE, crateID, dmbID, mo))) {
0376       mo->Fill(2.0);
0377       float cfeb_dav2_number = mo->GetBinContent(3);
0378       if (getCSCHisto(h::CSC_DMB_FEB_DAV_EFFICIENCY, crateID, dmbID, mo)) {
0379         mo->SetBinContent(3, ((float)cfeb_dav2_number / (float)(DMBEvents)*100.0));
0380         mo->SetEntries((int)DMBEvents);
0381       }
0382     }
0383 
0384     float feb_combination_dav = -1.0;
0385     /**       Fill Hisogram for Different Combinations of FEB DAV Efficiency */
0386     if (getCSCHisto(h::CSC_DMB_FEB_COMBINATIONS_DAV_RATE, crateID, dmbID, mo)) {
0387       if (alct_dav == 0 && tmb_dav == 0 && cfeb_dav2 == 0)
0388         feb_combination_dav = 0.0;  // Nothing
0389       if (alct_dav > 0 && tmb_dav == 0 && cfeb_dav2 == 0)
0390         feb_combination_dav = 1.0;  // ALCT Only
0391       if (alct_dav == 0 && tmb_dav > 0 && cfeb_dav2 == 0)
0392         feb_combination_dav = 2.0;  // TMB Only
0393       if (alct_dav == 0 && tmb_dav == 0 && cfeb_dav2 > 0)
0394         feb_combination_dav = 3.0;  // CFEB Only
0395       if (alct_dav == 0 && tmb_dav > 0 && cfeb_dav2 > 0)
0396         feb_combination_dav = 4.0;  // TMB+CFEB
0397       if (alct_dav > 0 && tmb_dav > 0 && cfeb_dav2 == 0)
0398         feb_combination_dav = 5.0;  // ALCT+TMB
0399       if (alct_dav > 0 && tmb_dav == 0 && cfeb_dav2 > 0)
0400         feb_combination_dav = 6.0;  // ALCT+CFEB
0401       if (alct_dav > 0 && tmb_dav > 0 && cfeb_dav2 > 0)
0402         feb_combination_dav = 7.0;  // ALCT+TMB+CFEB
0403       mo->Fill(feb_combination_dav);
0404       float feb_combination_dav_number = mo->GetBinContent((int)(feb_combination_dav + 1.0));
0405       if (getCSCHisto(h::CSC_DMB_FEB_COMBINATIONS_DAV_EFFICIENCY, crateID, dmbID, mo)) {
0406         mo->SetBinContent((int)(feb_combination_dav + 1.0),
0407                           ((float)feb_combination_dav_number / (float)(DMBEvents)*100.0));
0408         mo->SetEntries((int)DMBEvents);
0409       }
0410     }
0411 
0412     /** ALCT Found */
0413     if (data.nalct()) {
0414       const CSCALCTHeader* alctHeader = data.alctHeader();
0415       int fwVersion = alctHeader->alctFirmwareVersion();
0416       int fwRevision = alctHeader->alctFirmwareRevision();
0417       const CSCALCTTrailer* alctTrailer = data.alctTrailer();
0418       const CSCAnodeData* alctData = data.alctData();
0419 
0420       if (alctHeader && alctTrailer) {
0421         /** Summary plot for chambers with detected Run3 ALCT firmware */
0422         if (getEMUHisto(h::EMU_CSC_RUN3_ALCT_FORMAT, mo)) {
0423           /// ALCT Run3 firmware revision should be > 5
0424           if (fwRevision > 5)
0425             mo->SetBinContent(cscPosition, cscType + 1, fwRevision);
0426         }
0427         std::vector<CSCALCTDigi> alctsDatasTmp = alctHeader->ALCTDigis();
0428         std::vector<CSCALCTDigi> alctsDatas;
0429 
0430         for (uint32_t lct = 0; lct < alctsDatasTmp.size(); lct++) {
0431           if (alctsDatasTmp[lct].isValid())
0432             alctsDatas.push_back(alctsDatasTmp[lct]);
0433         }
0434 
0435         FEBunpacked = FEBunpacked + 1;
0436         alct_unpacked = 1;
0437 
0438         /**  Set number of ALCT-events to third bin */
0439         if (getCSCHisto(h::CSC_CSC_RATE, crateID, dmbID, mo)) {
0440           mo->Fill(2);
0441           uint32_t ALCTEvent = (uint32_t)mo->GetBinContent(3);
0442           config->setChamberCounterValue(ALCT_TRIGGERS, crateID, dmbID, ALCTEvent);
0443           if (getCSCHisto(h::CSC_CSC_EFFICIENCY, crateID, dmbID, mo)) {
0444             if (config->getNEvents() > 0) {
0445               /** KK */
0446               /** h[hname]->SetBinContent(3, ((float)ALCTEvent/(float)(config->getNEvents()) * 100.0)); */
0447               mo->SetBinContent(1, ((float)ALCTEvent / (float)(DMBEvents)*100.0));
0448               /** KKend */
0449               mo->SetEntries((int)DMBEvents);
0450             }
0451           }
0452         }
0453 
0454         if ((alct_dav > 0) && (getCSCHisto(h::CSC_DMB_FEB_UNPACKED_VS_DAV, crateID, dmbID, mo))) {
0455           mo->Fill(0.0, 0.0);
0456         }
0457 
0458         /**  == ALCT2007 L1A: 12bits (4096) */
0459         /**  == ALCT2006 L1A: 4bits (16) */
0460         if (getCSCHisto(h::CSC_ALCT_L1A, crateID, dmbID, mo))
0461           mo->Fill((int)(alctHeader->L1Acc()));
0462 
0463         /**  == Use 6-bit L1A       */
0464         if (getCSCHisto(h::CSC_ALCT_DMB_L1A_DIFF, crateID, dmbID, mo)) {
0465           /**  int alct_dmb_l1a_diff = (int)((dmbHeader->l1a()&0xF)-alctHeader->L1Acc()); */
0466           int alct_dmb_l1a_diff = (int)(alctHeader->L1Acc() % 64 - dmbHeader->l1a24() % 64);
0467           if (alct_dmb_l1a_diff != 0)
0468             L1A_out_of_sync = true;
0469           if (alct_dmb_l1a_diff < -32)
0470             mo->Fill(alct_dmb_l1a_diff + 64);
0471           else {
0472             if (alct_dmb_l1a_diff >= 32)
0473               mo->Fill(alct_dmb_l1a_diff - 64);
0474             else
0475               mo->Fill(alct_dmb_l1a_diff);
0476           }
0477           mo->SetAxisRange(0.1, 1.1 * (1.0 + mo->GetBinContent(mo->GetMaximumBin())), "Y");
0478         }
0479 
0480         /**  if (getCSCHisto(h::CSC_DMB_L1A_VS_ALCT_L1A, crateID, dmbID, mo)) mo->Fill(alctHeader->L1Acc(),dmbHeader->l1a()); */
0481         if (getCSCHisto(h::CSC_DMB_L1A_VS_ALCT_L1A, crateID, dmbID, mo))
0482           mo->Fill(alctHeader->L1Acc() % 256, dmbHeader->l1a24() % 256);
0483 
0484         /**  === ALCT BXN: 12bits (4096) */
0485         /**  === Use 6-bit BXN */
0486         if (getCSCHisto(h::CSC_ALCT_DMB_BXN_DIFF, crateID, dmbID, mo)) {
0487           int alct_dmb_bxn_diff = (int)(alctHeader->BXNCount() - dmbHeader->bxn12());
0488           if (alct_dmb_bxn_diff > 0)
0489             alct_dmb_bxn_diff -= 3564;
0490           alct_dmb_bxn_diff %= 32;
0491           mo->Fill(alct_dmb_bxn_diff);
0492           mo->SetAxisRange(0.1, 1.1 * (1.0 + mo->GetBinContent(mo->GetMaximumBin())), "Y");
0493         }
0494 
0495         if (getCSCHisto(h::CSC_ALCT_BXN, crateID, dmbID, mo))
0496           mo->Fill(alctHeader->BXNCount());
0497 
0498         /**  if (getCSCHisto(h::CSC_ALCT_BXN_VS_DMB_BXN, crateID, dmbID, mo)) mo->Fill((int)((alctHeader->BXNCount())), (int)(dmbHeader->bxn())); */
0499         if (getCSCHisto(h::CSC_ALCT_BXN_VS_DMB_BXN, crateID, dmbID, mo))
0500           mo->Fill((int)((alctHeader->BXNCount()) % 256), (int)(dmbHeader->bxn12()) % 256);
0501 
0502         if (getCSCHisto(h::CSC_ALCT_NUMBER_RATE, crateID, dmbID, mo)) {
0503           mo->Fill(alctsDatas.size());
0504           int nALCT = (int)mo->GetBinContent((int)(alctsDatas.size() + 1));
0505           if (getCSCHisto(h::CSC_ALCT_NUMBER_EFFICIENCY, crateID, dmbID, mo))
0506             mo->SetBinContent((int)(alctsDatas.size() + 1), (float)(nALCT) / (float)(DMBEvents)*100.0);
0507         }
0508 
0509         if (getCSCHisto(h::CSC_ALCT_WORD_COUNT, crateID, dmbID, mo))
0510           mo->Fill((int)(alctTrailer->wordCount()));
0511 
0512         /** LOG_DEBUG <<  "ALCT Trailer Word Count = " << dec << (int)alctTrailer->wordCount(); */
0513 
0514         if (alctsDatas.size() == 2) {
0515           if (getCSCHisto(h::CSC_ALCT1_VS_ALCT0_KEYWG, crateID, dmbID, mo))
0516             mo->Fill(alctsDatas[0].getKeyWG(), alctsDatas[1].getKeyWG());
0517         }
0518 
0519         /** Run3 ALCT HMT bits from ALCT data */
0520         std::vector<CSCShowerDigi> alctShowers = alctHeader->alctShowerDigis();
0521         for (unsigned bx = 0; bx < alctShowers.size(); bx++) {
0522           if (getCSCHisto(h::CSC_RUN3_ALCT_HMT_BITS_VS_BX, crateID, dmbID, mo)) {
0523             mo->Fill(alctShowers[bx].bitsInTime(), bx);
0524           }
0525           /** Summary occupancy plot for ANode HMT bits per BX from ALCT */
0526           if (getEMUHisto(h::EMU_CSC_ANODE_HMT_ALCT_REPORTING, mo)) {
0527             if (alctShowers[bx].isValid())
0528               mo->Fill(cscPosition, cscType);
0529           }
0530         }
0531 
0532         MonitorObject* mo_CSC_ALCT0_BXN_mean = nullptr;
0533         getEMUHisto(h::EMU_CSC_ALCT0_BXN_MEAN, mo_CSC_ALCT0_BXN_mean);
0534 
0535         MonitorObject* mo_CSC_ALCT0_BXN_rms = nullptr;
0536         getEMUHisto(h::EMU_CSC_ALCT0_BXN_RMS, mo_CSC_ALCT0_BXN_rms);
0537 
0538         MonitorObject* mo_CSC_Plus_endcap_ALCT0_dTime = nullptr;
0539         getEMUHisto(h::EMU_CSC_ALCT0_ENDCAP_PLUS_DTIME, mo_CSC_Plus_endcap_ALCT0_dTime);
0540 
0541         MonitorObject* mo_CSC_Minus_endcap_ALCT0_dTime = nullptr;
0542         getEMUHisto(h::EMU_CSC_ALCT0_ENDCAP_MINUS_DTIME, mo_CSC_Minus_endcap_ALCT0_dTime);
0543 
0544         for (uint32_t lct = 0; lct < alctsDatas.size(); lct++) {
0545           /**  TODO: Add support for more than 2 ALCTs */
0546           if (lct >= 2)
0547             continue;
0548 
0549           if (getCSCHisto(h::CSC_ALCTXX_KEYWG, crateID, dmbID, lct, mo)) {
0550             mo->Fill(alctsDatas[lct].getKeyWG());
0551           }
0552 
0553           if (lct == 0)
0554             alct_keywg = alctsDatas[lct].getKeyWG();
0555 
0556           int alct_dtime = 0;
0557           if (fwVersion == 2007) {
0558             alct_dtime = alctsDatas[lct].getBX();
0559           } else {
0560             // Older 2006 Format
0561             alct_dtime = (int)(alctsDatas[lct].getBX() - (alctHeader->BXNCount() & 0x1F));
0562           }
0563 
0564           // == Those two summary histos need to be outside of per-chamber CSC_ALCTXX_DTIME histo check.
0565           //    Otherwise will be empty in Offline DQM
0566           if (lct == 0) {
0567             if (cid.endcap() == 1) {
0568               if (mo_CSC_Plus_endcap_ALCT0_dTime)
0569                 mo_CSC_Plus_endcap_ALCT0_dTime->Fill(alct_dtime);
0570             }
0571             if (cid.endcap() == 2) {
0572               if (mo_CSC_Minus_endcap_ALCT0_dTime)
0573                 mo_CSC_Minus_endcap_ALCT0_dTime->Fill(alct_dtime);
0574             }
0575           }
0576 
0577           if (getCSCHisto(h::CSC_ALCTXX_DTIME, crateID, dmbID, lct, mo)) {
0578             if (alct_dtime < -16) {
0579               mo->Fill(alct_dtime + 32);
0580             } else {
0581               if (alct_dtime >= 16)
0582                 mo->Fill(alct_dtime - 32);
0583               else
0584                 mo->Fill(alct_dtime);
0585             }
0586 
0587             mo->SetAxisRange(0.1, 1.1 * (1.0 + mo->GetBinContent(mo->GetMaximumBin())), "Y");
0588 
0589             double dTime_mean = mo->getTH1()->GetMean();
0590             double dTime_rms = mo->getTH1()->GetRMS();
0591 
0592             // == For ALCT0 Fill Summary dTime Histograms
0593             if (lct == 0) {
0594               if (cscPosition && mo_CSC_ALCT0_BXN_mean) {
0595                 mo_CSC_ALCT0_BXN_mean->SetBinContent(cscPosition, cscType + 1, dTime_mean);
0596               }
0597               if (cscPosition && mo_CSC_ALCT0_BXN_rms) {
0598                 mo_CSC_ALCT0_BXN_rms->SetBinContent(cscPosition, cscType + 1, dTime_rms);
0599               }
0600             }
0601           }
0602 
0603           if (getCSCHisto(h::CSC_ALCTXX_DTIME_VS_KEYWG, crateID, dmbID, lct, mo)) {
0604             if (alct_dtime < -16) {
0605               mo->Fill(alctsDatas[lct].getKeyWG(), alct_dtime + 32);
0606             } else {
0607               if (alct_dtime >= 16)
0608                 mo->Fill(alctsDatas[lct].getKeyWG(), alct_dtime - 32);
0609               else
0610                 mo->Fill(alctsDatas[lct].getKeyWG(), alct_dtime);
0611             }
0612           }
0613 
0614           if (getCSCHisto(h::CSC_ALCTXX_DTIME_PROFILE, crateID, dmbID, lct, mo)) {
0615             if (alct_dtime < -16) {
0616               mo->Fill(alctsDatas[lct].getKeyWG(), alct_dtime + 32);
0617             } else {
0618               if (alct_dtime >= 16)
0619                 mo->Fill(alctsDatas[lct].getKeyWG(), alct_dtime - 32);
0620               else
0621                 mo->Fill(alctsDatas[lct].getKeyWG(), alct_dtime);
0622             }
0623           }
0624 
0625           int alct_bxn = alctsDatas[lct].getBX();
0626           if (fwVersion == 2007) {
0627             alct_bxn = (alct_bxn + alctHeader->BXNCount()) & 0x1F;
0628           }
0629 
0630           if (getCSCHisto(h::CSC_ALCTXX_BXN, crateID, dmbID, lct, mo))
0631             mo->Fill(alct_bxn);
0632 
0633           if (getCSCHisto(h::CSC_ALCTXX_QUALITY, crateID, dmbID, lct, mo))
0634             mo->Fill(alctsDatas[lct].getKeyWG(), alctsDatas[lct].getQuality());
0635 
0636           if (mo_EventDisplay) {
0637             mo_EventDisplay->SetBinContent(2, alctsDatas[lct].getKeyWG(), alct_bxn + 1);
0638             mo_EventDisplay->SetBinContent(3, alctsDatas[lct].getKeyWG(), alctsDatas[lct].getQuality());
0639           }
0640 
0641           if (getCSCHisto(h::CSC_ALCTXX_QUALITY_DISTR, crateID, dmbID, lct, mo)) {
0642             mo->Fill(alctsDatas[lct].getQuality());
0643             if (lct == 0) {
0644               MonitorObject* mo1 = nullptr;
0645               if (cscPosition && getEMUHisto(h::EMU_CSC_ALCT0_QUALITY, mo1)) {
0646                 mo1->SetBinContent(cscPosition, cscType + 1, mo->getTH1()->GetMean());
0647               }
0648             }
0649           }
0650 
0651           if (getCSCHisto(h::CSC_ALCTXX_QUALITY_PROFILE, crateID, dmbID, lct, mo))
0652             mo->Fill(alctsDatas[lct].getKeyWG(), alctsDatas[lct].getQuality());
0653 
0654           if (getCSCHisto(h::CSC_ALCTXX_PATTERN, crateID, dmbID, lct, mo)) {
0655             int pattern = (alctsDatas[lct].getAccelerator() << 1) + alctsDatas[lct].getCollisionB();
0656             int keywg = alctsDatas[lct].getKeyWG();
0657             mo->Fill(keywg, pattern);
0658           }
0659 
0660           if (getCSCHisto(h::CSC_ALCTXX_PATTERN_DISTR, crateID, dmbID, lct, mo)) {
0661             int pattern = (alctsDatas[lct].getAccelerator() << 1) + alctsDatas[lct].getCollisionB();
0662             mo->Fill(pattern);
0663           }
0664         }
0665 
0666         int NumberOfLayersWithHitsInALCT = 0;
0667         int NumberOfWireGroupsWithHitsInALCT = 0;
0668 
0669         if (alctData) {
0670           MonitorObject* mo_AFEB_RawHits_TimeBins = nullptr;
0671           getCSCHisto(h::CSC_CFEB_AFEB_RAWHITS_TIMEBINS, crateID, dmbID, mo_AFEB_RawHits_TimeBins);
0672 
0673           MonitorObject* mo_CSC_Plus_endcap_AFEB_RawHits_Time = nullptr;
0674           getEMUHisto(h::EMU_CSC_AFEB_ENDCAP_PLUS_RAWHITS_TIME, mo_CSC_Plus_endcap_AFEB_RawHits_Time);
0675 
0676           MonitorObject* mo_CSC_Minus_endcap_AFEB_RawHits_Time = nullptr;
0677           getEMUHisto(h::EMU_CSC_AFEB_ENDCAP_MINUS_RAWHITS_TIME, mo_CSC_Minus_endcap_AFEB_RawHits_Time);
0678 
0679           MonitorObject* mo_CSC_AFEB_RawHits_Time_mean = nullptr;
0680           getEMUHisto(h::EMU_CSC_AFEB_RAWHITS_TIME_MEAN, mo_CSC_AFEB_RawHits_Time_mean);
0681 
0682           MonitorObject* mo_CSC_AFEB_RawHits_Time_rms = nullptr;
0683           getEMUHisto(h::EMU_CSC_AFEB_RAWHITS_TIME_RMS, mo_CSC_AFEB_RawHits_Time_rms);
0684 
0685           for (int nLayer = 1; nLayer <= 6; nLayer++) {
0686             int wg_previous = -1;
0687             int tbin_previous = -1;
0688             bool CheckLayerALCT = true;
0689 
0690             std::vector<CSCWireDigi> wireDigis = alctData->wireDigis(nLayer);
0691             for (std::vector<CSCWireDigi>::iterator wireDigisItr = wireDigis.begin(); wireDigisItr != wireDigis.end();
0692                  ++wireDigisItr) {
0693               int wg = wireDigisItr->getWireGroup();
0694               std::vector<int> tbins = wireDigisItr->getTimeBinsOn();
0695               int tbin = wireDigisItr->getTimeBin();
0696 
0697               if (mo_EventDisplay) {
0698                 mo_EventDisplay->SetBinContent(nLayer + 3, wg - 1, tbin + 1);
0699                 setEmuEventDisplayBit(mo_Emu_EventDisplay_Anode, glChamberIndex, wg - 1, nLayer - 1);
0700                 setEmuEventDisplayBit(mo_Emu_EventDisplay_XY, glChamberIndex, wg - 1, nLayer - 1);
0701               }
0702 
0703               if (CheckLayerALCT) {
0704                 NumberOfLayersWithHitsInALCT = NumberOfLayersWithHitsInALCT + 1;
0705                 CheckLayerALCT = false;
0706               }
0707 
0708               for (uint32_t n = 0; n < tbins.size(); n++) {
0709                 tbin = tbins[n];
0710                 if (wg != wg_previous || (tbin != tbin_previous + 1 && tbin != tbin_previous - 1)) {
0711                   if (getCSCHisto(h::CSC_ALCTTIME_LYXX, crateID, dmbID, nLayer, mo))
0712                     mo->Fill(wg - 1, tbin);
0713 
0714                   if (getCSCHisto(h::CSC_ALCTTIME_LYXX_PROFILE, crateID, dmbID, nLayer, mo))
0715                     mo->Fill(wg - 1, tbin);
0716 
0717                   if (mo_AFEB_RawHits_TimeBins)
0718                     mo_AFEB_RawHits_TimeBins->Fill(tbin);
0719 
0720                   if (cid.endcap() == 1) {
0721                     if (mo_CSC_Plus_endcap_AFEB_RawHits_Time)
0722                       mo_CSC_Plus_endcap_AFEB_RawHits_Time->Fill(tbin);
0723                   }
0724                   if (cid.endcap() == 2) {
0725                     if (mo_CSC_Minus_endcap_AFEB_RawHits_Time)
0726                       mo_CSC_Minus_endcap_AFEB_RawHits_Time->Fill(tbin);
0727                   }
0728 
0729                   if (getCSCHisto(h::CSC_ALCT_LYXX_RATE, crateID, dmbID, nLayer, mo)) {
0730                     mo->Fill(wg - 1);
0731                     int number_wg = (int)(mo->GetBinContent(wg));
0732                     Double_t Number_of_entries_ALCT = mo->GetEntries();
0733                     if (getCSCHisto(h::CSC_ALCT_LYXX_EFFICIENCY, crateID, dmbID, nLayer, mo)) {
0734                       mo->SetBinContent(wg, ((float)number_wg));
0735                       if ((Double_t)(DMBEvents) > 0.0) {
0736                         mo->SetNormFactor(100.0 * Number_of_entries_ALCT / (Double_t)(DMBEvents));
0737                       } else {
0738                         mo->SetNormFactor(100.0);
0739                       }
0740                       mo->SetEntries((int)DMBEvents);
0741                     }
0742                   }
0743                 }
0744                 if (wg != wg_previous) {
0745                   NumberOfWireGroupsWithHitsInALCT = NumberOfWireGroupsWithHitsInALCT + 1;
0746                 }
0747 
0748                 wg_previous = wg;
0749                 tbin_previous = tbin;
0750               }
0751             }
0752 
0753             // Fill Summary Anode Raw Hits Timing Plots
0754             if (mo_AFEB_RawHits_TimeBins) {
0755               double rawhits_time_mean = mo_AFEB_RawHits_TimeBins->getTH1()->GetMean();
0756               double rawhits_time_rms = mo_AFEB_RawHits_TimeBins->getTH1()->GetRMS();
0757 
0758               if (cscPosition && mo_CSC_AFEB_RawHits_Time_mean) {
0759                 mo_CSC_AFEB_RawHits_Time_mean->SetBinContent(cscPosition, cscType + 1, rawhits_time_mean);
0760               }
0761 
0762               if (cscPosition && mo_CSC_AFEB_RawHits_Time_rms) {
0763                 mo_CSC_AFEB_RawHits_Time_rms->SetBinContent(cscPosition, cscType + 1, rawhits_time_rms);
0764               }
0765             }
0766           }
0767 
0768         } else {
0769           LOG_ERROR << cscTag << " Can not unpack Anode Data";
0770         }
0771 
0772         if (getCSCHisto(h::CSC_ALCT_NUMBER_OF_LAYERS_WITH_HITS, crateID, dmbID, mo)) {
0773           mo->Fill(NumberOfLayersWithHitsInALCT);
0774           MonitorObject* mo1 = nullptr;
0775           if (cscPosition && getEMUHisto(h::EMU_CSC_ALCT_PLANES_WITH_HITS, mo1)) {
0776             mo1->SetBinContent(cscPosition, cscType + 1, mo->getTH1()->GetMean());
0777           }
0778         }
0779 
0780         if (getCSCHisto(h::CSC_ALCT_NUMBER_OF_WIREGROUPS_WITH_HITS, crateID, dmbID, mo))
0781           mo->Fill(NumberOfWireGroupsWithHitsInALCT);
0782 
0783       } else {
0784         LOG_ERROR << cscTag << " Can not unpack ALCT Header or/and Trailer";
0785       }
0786     } else {
0787       /**   ALCT not found */
0788 
0789       if (getCSCHisto(h::CSC_ALCT_NUMBER_RATE, crateID, dmbID, mo)) {
0790         mo->Fill(0);
0791         int nALCT = (int)mo->GetBinContent(1);
0792         if (getCSCHisto(h::CSC_ALCT_NUMBER_EFFICIENCY, crateID, dmbID, mo))
0793           mo->SetBinContent(1, (float)(nALCT) / (float)(DMBEvents)*100.0);
0794       }
0795 
0796       if ((alct_dav > 0) && (getCSCHisto(h::CSC_DMB_FEB_UNPACKED_VS_DAV, crateID, dmbID, mo))) {
0797         mo->Fill(0.0, 1.0);
0798       }
0799     }
0800 
0801     /** ALCT and CLCT coinsidence */
0802     if (data.nclct() && data.nalct()) {
0803       CSCALCTHeader* alctHeader = data.alctHeader();
0804 
0805       if (alctHeader) {
0806         std::vector<CSCALCTDigi> alctsDatasTmp = alctHeader->ALCTDigis();
0807         std::vector<CSCALCTDigi> alctsDatas;
0808 
0809         for (uint32_t lct = 0; lct < alctsDatasTmp.size(); lct++) {
0810           if (alctsDatasTmp[lct].isValid())
0811             alctsDatas.push_back(alctsDatasTmp[lct]);
0812         }
0813 
0814         CSCTMBData* tmbData = data.tmbData();
0815         if (tmbData) {
0816           CSCTMBHeader* tmbHeader = tmbData->tmbHeader();
0817           if (tmbHeader) {
0818             if (getCSCHisto(h::CSC_TMB_BXN_VS_ALCT_BXN, crateID, dmbID, mo))
0819               mo->Fill(((int)(alctHeader->BXNCount())) % 256, ((int)(tmbHeader->BXNCount())) % 256);
0820 
0821             if (getCSCHisto(h::CSC_TMB_ALCT_BXN_DIFF, crateID, dmbID, mo)) {
0822               int clct_alct_bxn_diff = (int)(alctHeader->BXNCount() - tmbHeader->BXNCount());
0823               if (clct_alct_bxn_diff < -2048)
0824                 mo->Fill(clct_alct_bxn_diff + 4096);
0825               else {
0826                 if (clct_alct_bxn_diff > 2048)
0827                   mo->Fill(clct_alct_bxn_diff - 4096);
0828                 else
0829                   mo->Fill(clct_alct_bxn_diff);
0830               }
0831               mo->SetAxisRange(0.1, 1.1 * (1.0 + mo->GetBinContent(mo->GetMaximumBin())), "Y");
0832             }
0833 
0834             if (getCSCHisto(h::CSC_TMB_L1A_VS_ALCT_L1A, crateID, dmbID, mo))
0835               mo->Fill((int)(alctHeader->L1Acc() % 256), (int)(tmbHeader->L1ANumber() % 256));
0836 
0837             if (getCSCHisto(h::CSC_TMB_ALCT_L1A_DIFF, crateID, dmbID, mo)) {
0838               int clct_alct_l1a_diff = (int)(tmbHeader->L1ANumber() - alctHeader->L1Acc());
0839               if (clct_alct_l1a_diff < -2048)
0840                 mo->Fill(clct_alct_l1a_diff + 4096);
0841               else {
0842                 if (clct_alct_l1a_diff > 2048)
0843                   mo->Fill(clct_alct_l1a_diff - 4096);
0844                 else
0845                   mo->Fill(clct_alct_l1a_diff);
0846               }
0847               mo->SetAxisRange(0.1, 1.1 * (1.0 + mo->GetBinContent(mo->GetMaximumBin())), "Y");
0848             }
0849           } else {
0850             LOG_ERROR << cscTag << " Can not unpack TMB Header";
0851           }
0852 
0853         } else {
0854           LOG_ERROR << cscTag << " Can not unpack TMB Data";
0855         }
0856       } else {
0857         LOG_ERROR << cscTag << " Can not unpack ALCT Header";
0858       }
0859     }
0860 
0861     /** CLCT Found */
0862     if (data.nclct()) {
0863       /** LOG_WARN << "TMB CRC calc: 0x" << std::hex << data.tmbData().TMBCRCcalc() << " trailer: 0x" << std::hex << data.tmbData().tmbTrailer().crc22(); */
0864 
0865       CSCTMBData* tmbData = data.tmbData();
0866       if (tmbData) {
0867         CSCTMBHeader* tmbHeader = tmbData->tmbHeader();
0868         CSCTMBTrailer* tmbTrailer = tmbData->tmbTrailer();
0869 
0870         if (tmbHeader && tmbTrailer) {
0871           bool isRun3_df = false;
0872           bool isGEM_df = false;
0873           bool isTMB_hybrid_df = false;
0874           if (tmbHeader->FirmwareVersion() == 2020) {
0875             // revision code major part: 0x0 - Run3 df, 0x1 - is legacy Run2 df
0876             if (((tmbHeader->FirmwareRevision() >> 5) & 0xF) == 0x0)
0877               isRun3_df = true;
0878             if (((tmbHeader->FirmwareRevision() >> 9) & 0xF) == 0x3)
0879               isGEM_df = true;
0880             if (((tmbHeader->FirmwareRevision() >> 9) & 0xF) == 0x4)
0881               isTMB_hybrid_df = true;
0882             /** Summary plot for chambers with detected (O)TMB Run3 data format */
0883             if ((isTMB_hybrid_df || isRun3_df) && getEMUHisto(h::EMU_CSC_TMB_RUN3_DATA_FORMAT, mo)) {
0884               mo->SetBinContent(cscPosition, cscType + 1, 1);
0885             }
0886           }
0887 
0888           if (tmbHeader->FirmwareVersion() == 2020) {
0889             if (isRun3_df) {
0890               /** Summary plot for chambers with detected enabled (O)TMB Run3 CCLUT mode */
0891               if (getEMUHisto(h::EMU_CSC_TMB_RUN3_CCLUT_MODE, mo)) {
0892                 if (tmbHeader->clct0_ComparatorCode() > 0)
0893                   mo->SetBinContent(cscPosition, cscType + 1, 1);
0894               }
0895 
0896               if (isGEM_df) {
0897                 if (getCSCHisto(h::CSC_GEM_FIBERS_STATUS, crateID, dmbID, mo)) {
0898                   int gem_fibers = tmbHeader->gem_enabled_fibers();
0899                   for (unsigned i = 0; i < 4; i++) {
0900                     if ((gem_fibers >> i) & 0x1)
0901                       mo->Fill(i);
0902                   }
0903                 }
0904                 uint16_t gem_sync_status = tmbHeader->gem_sync_dataword();
0905                 if (getCSCHisto(h::CSC_GEM_SYNC_STATUS, crateID, dmbID, mo)) {
0906                   for (int i = 0; i < 15; i++) {
0907                     if ((gem_sync_status >> i) & 0x1)
0908                       mo->Fill(i);
0909                   }
0910                 }
0911                 uint16_t gem_timing_status = tmbHeader->gem_timing_dataword();
0912                 if (getCSCHisto(h::CSC_GEM_NUM_COPADS, crateID, dmbID, mo)) {
0913                   // For GEM firmware after rev0. 4-bits num_copad
0914                   mo->Fill(gem_timing_status & 0xF);
0915                 }
0916 
0917                 if (tmbData->hasGEM()) {
0918                   CSCGEMData* gemData = tmbData->gemData();
0919                   if (gemData != nullptr) {
0920                     bool isGEM_hits_found = false;
0921                     std::vector<CSCCorrelatedLCTDigi> corr_lctsDatasTmp = tmbHeader->CorrelatedLCTDigis(cid.rawId());
0922                     for (int i = 0; i < gemData->numGEMs(); i++) {
0923                       std::vector<GEMPadDigiCluster> gemDigis = gemData->digis(i);
0924                       if (getCSCHisto(h::CSC_GEM_NUM_CLUSTERS, crateID, dmbID, mo)) {
0925                         mo->Fill(gemDigis.size());
0926                       }
0927 
0928                       if (!gemDigis.empty()) {
0929                         isGEM_hits_found = true;
0930                         for (unsigned digi = 0; digi < gemDigis.size(); digi++) {
0931                           if (gemDigis[digi].isValid()) {
0932                             std::vector<uint16_t> pads_hits = gemDigis[digi].pads();
0933                             int hits_timebin = gemDigis[digi].bx();
0934                             if (getCSCHisto(((i == 0) ? h::CSC_GEM_GEMA_CLUSTER_SIZE : h::CSC_GEM_GEMB_CLUSTER_SIZE),
0935                                             crateID,
0936                                             dmbID,
0937                                             mo)) {
0938                               mo->Fill(pads_hits.size());
0939                             }
0940                             if (!pads_hits.empty()) {
0941                               if (getCSCHisto(((i == 0) ? h::CSC_GEM_GEMA_PADS_CLUSTER_SIZE
0942                                                         : h::CSC_GEM_GEMB_PADS_CLUSTER_SIZE),
0943                                               crateID,
0944                                               dmbID,
0945                                               mo)) {
0946                                 // int npad = (7 - (pads_hits[0] / 192)) * 192 + pads_hits[0] % 192;
0947                                 int npad = pads_hits[0];  // no eta recode
0948                                 mo->Fill(npad, pads_hits.size());
0949                               }
0950 
0951                               if (getCSCHisto(
0952                                       ((i == 0) ? h::CSC_GEM_GEMA_BX_DISTRIBUTION : h::CSC_GEM_GEMB_BX_DISTRIBUTION),
0953                                       crateID,
0954                                       dmbID,
0955                                       mo)) {
0956                                 mo->Fill(hits_timebin);
0957                               }
0958 
0959                               /// Fill summary GEM VFATs occupancies plots for endcaps
0960                               if ((cid.endcap() == 1) && getEMUHisto(h::EMU_GEM_PLUS_ENDCAP_VFAT_OCCUPANCY, mo)) {
0961                                 int vfat = (pads_hits[0] / 192) + ((pads_hits[0] % 192) / 64) * 8;
0962                                 mo->Fill((cscPosition)*2 + i - 1, vfat);
0963                               }
0964 
0965                               if ((cid.endcap() == 2) && getEMUHisto(h::EMU_GEM_MINUS_ENDCAP_VFAT_OCCUPANCY, mo)) {
0966                                 int vfat = (pads_hits[0] / 192) + ((pads_hits[0] % 192) / 64) * 8;
0967                                 mo->Fill((cscPosition)*2 + i - 1, vfat);
0968                               }
0969 
0970                               for (unsigned pad = 0; pad < pads_hits.size(); pad++) {
0971                                 // int npad = (7 - (pads_hits[pad] / 192)) * 192 + pads_hits[pad] % 192;
0972                                 int npad = pads_hits[pad];  // no eta recode
0973                                 if (getCSCHisto(
0974                                         ((i == 0) ? h::CSC_GEM_GEMA_HITS : h::CSC_GEM_GEMB_HITS), crateID, dmbID, mo)) {
0975                                   mo->Fill(npad);
0976                                 }
0977 
0978                                 if (getCSCHisto(
0979                                         ((i == 0) ? h::CSC_GEM_GEMA_HITS_IN_TIME : h::CSC_GEM_GEMB_HITS_IN_TIME),
0980                                         crateID,
0981                                         dmbID,
0982                                         mo)) {
0983                                   mo->Fill(npad, hits_timebin);
0984                                 }
0985                                 if (getCSCHisto(((i == 0) ? h::CSC_GEM_GEMA_HITS_IN_TIME_PROFILE
0986                                                           : h::CSC_GEM_GEMB_HITS_IN_TIME_PROFILE),
0987                                                 crateID,
0988                                                 dmbID,
0989                                                 mo)) {
0990                                   mo->Fill(npad, hits_timebin);
0991                                 }
0992 
0993                                 if (getCSCHisto(((i == 0) ? h::CSC_GEM_GEMA_VFAT_HITS_IN_TIME
0994                                                           : h::CSC_GEM_GEMB_VFAT_HITS_IN_TIME),
0995                                                 crateID,
0996                                                 dmbID,
0997                                                 mo)) {
0998                                   int vfat = (pads_hits[0] / 192) + ((pads_hits[0] % 192) / 64) * 8;
0999                                   mo->Fill(vfat, hits_timebin);
1000                                 }
1001                                 if (getCSCHisto(((i == 0) ? h::CSC_GEM_GEMA_VFAT_HITS_IN_TIME_PROFILE
1002                                                           : h::CSC_GEM_GEMB_VFAT_HITS_IN_TIME_PROFILE),
1003                                                 crateID,
1004                                                 dmbID,
1005                                                 mo)) {
1006                                   int vfat = (pads_hits[0] / 192) + ((pads_hits[0] % 192) / 64) * 8;
1007                                   mo->Fill(vfat, hits_timebin);
1008                                 }
1009                               }
1010                             }  // pads_hits.size() > 0
1011                           }
1012                         }
1013                       }
1014                       for (unsigned ieta = 0; ieta < 8; ieta++) {
1015                         std::vector<GEMPadDigiCluster> gemEtaDigis =
1016                             gemData->etaDigis(i, ieta, tmbHeader->ALCTMatchTime());
1017                         if (!gemEtaDigis.empty()) {
1018                           for (unsigned digi = 0; digi < gemEtaDigis.size(); digi++) {
1019                             if (gemEtaDigis[digi].isValid()) {
1020                               std::vector<uint16_t> pads_hits = gemEtaDigis[digi].pads();
1021                               for (unsigned pad = 0; pad < pads_hits.size(); pad++) {
1022                                 if (getCSCHisto(
1023                                         ((i == 0) ? h::CSC_GEM_GEMA_HITS_W_ROLLS : h::CSC_GEM_GEMB_HITS_W_ROLLS),
1024                                         crateID,
1025                                         dmbID,
1026                                         mo)) {
1027                                   mo->Fill(pads_hits[pad], 7 - ieta);
1028                                 }
1029                               }
1030                             }
1031                           }
1032                         }
1033                       }
1034                     }
1035                     if (isGEM_hits_found) {
1036                       if (getCSCHisto(h::CSC_GEM_ALCT_MATCH, crateID, dmbID, mo)) {
1037                         mo->Fill((gem_timing_status >> 12) & 0x7);
1038                       }
1039                       if (getCSCHisto(h::CSC_GEM_CLCT_MATCH, crateID, dmbID, mo)) {
1040                         mo->Fill((gem_timing_status >> 8) & 0xF);
1041                       }
1042                     }
1043                   }
1044                 }  // OTMB hasGEM
1045               }    // isGEM_df
1046 
1047               /// Summary occupancy plot for Anode HMT bits from OTMB
1048               if (getEMUHisto(h::EMU_CSC_ANODE_HMT_REPORTING, mo)) {
1049                 if (tmbHeader->alctHMT() > 0)
1050                   mo->Fill(cscPosition, cscType);
1051               }
1052 
1053               /// Summary occupancy plot for Cathode HMT bits from OTMB
1054               if (getEMUHisto(h::EMU_CSC_CATHODE_HMT_REPORTING, mo)) {
1055                 if (tmbHeader->clctHMT() > 0)
1056                   mo->Fill(cscPosition, cscType);
1057               }
1058 
1059               if (getCSCHisto(h::CSC_CLCT_RUN3_HMT_NHITS, crateID, dmbID, mo)) {
1060                 mo->Fill(tmbHeader->hmt_nhits());
1061               }
1062 
1063               if (getCSCHisto(h::CSC_RUN3_CLCT_ALCT_HMT, crateID, dmbID, mo)) {
1064                 mo->Fill(tmbHeader->clctHMT());
1065                 mo->Fill(tmbHeader->alctHMT() + 4);
1066               }
1067 
1068               if (getCSCHisto(h::CSC_RUN3_CLCT_VS_ALCT_HMT_BITS, crateID, dmbID, mo)) {
1069                 mo->Fill(tmbHeader->clctHMT(), tmbHeader->alctHMT());
1070               }
1071 
1072               if (getCSCHisto(h::CSC_CORR_LCT_RUN3_PATTERN_ID, crateID, dmbID, mo)) {
1073                 mo->Fill(tmbHeader->run3_CLCT_patternID());
1074               }
1075             }
1076             /*
1077               LOG_DEBUG << "OTMB dump: " << "CLCT0_ComparatorCode: 0x" << std::hex << tmbHeader->CLCT0_ComparatorCode()
1078                         << ", CLCT0_xky: 0x" << std::hex << tmbHeader->CLCT0_xky()
1079                         << ", CLCT1_ComparatorCode: 0x" << std::hex << tmbHeader->CLCT1_ComparatorCode()
1080                         << ", CLCT1_xky: 0x" << std::hex << tmbHeader->CLCT1_xky()
1081                         << ", GEM_sync_dataword: 0x" << std::hex << tmbHeader->GEM_sync_dataword()
1082                         << ", GEM_timing_dataword: 0x" << std::hex << tmbHeader->GEM_timing_dataword()
1083                         << ",\n   HMT_nhits: 0x" << std::hex << tmbHeader->HMT_nhits()
1084                         << ", GEM_enabled_fibers: 0x" << std::hex << tmbHeader->GEM_enabled_fibers()
1085                         << ", GEM_fifo_tbins: " << std::dec << tmbHeader->GEM_fifo_tbins()
1086                         << ", GEM_fifo_pretrig: " << std::dec << tmbHeader->GEM_fifo_pretrig()
1087                         << ", GEM_zero_suppression: " << std::dec << tmbHeader->GEM_zero_suppress();
1088 */
1089           }
1090           CSCComparatorData* comparatorData = data.comparatorData();
1091 
1092           std::vector<CSCCLCTDigi> clctsDatasTmp = tmbHeader->CLCTDigis(cid.rawId());
1093           std::vector<CSCCLCTDigi> clctsDatas;
1094 
1095           for (uint32_t lct = 0; lct < clctsDatasTmp.size(); lct++) {
1096             if (clctsDatasTmp[lct].isValid()) {
1097               clctsDatas.push_back(clctsDatasTmp[lct]);
1098               if (clctsDatasTmp[lct].isRun3()) {
1099                 if ((lct == 0) && getCSCHisto(h::CSC_CLCTXX_KEY_STRIP_TYPE, crateID, dmbID, lct, mo))
1100                   mo->Fill(tmbHeader->clct0_xky());
1101                 if ((lct == 1) && getCSCHisto(h::CSC_CLCTXX_KEY_STRIP_TYPE, crateID, dmbID, lct, mo))
1102                   mo->Fill(tmbHeader->clct1_xky());
1103               }
1104             }
1105           }
1106 
1107           for (uint32_t lct = 0; lct < clctsDatas.size(); lct++) {
1108             /*
1109                   LOG_DEBUG << "CLCT Digis dump: "
1110                             << "CLCT" << lct << " isRun3:" << clctsDatasTmp[lct].isRun3()
1111                             << ", isValid: " << clctsDatasTmp[lct].isValid()
1112                             << ", getCFEB: " << clctsDatasTmp[lct].getCFEB()
1113                             << ", getKeyStrip: " << clctsDatasTmp[lct].getKeyStrip()
1114                             << ", getFractionalStrip: " <<  clctsDatasTmp[lct].getFractionalStrip()
1115                             << ", getQuartStrip: " << clctsDatasTmp[lct].getQuartStripBit()
1116                             << ", getEightStrip: " << clctsDatasTmp[lct].getEightStripBit()
1117                             << ",\n    getCompCode: 0x" << std::hex << clctsDatasTmp[lct].getCompCode()
1118                             << ", getQuality: " << clctsDatasTmp[lct].getQuality() << std::dec
1119                             << ", getPattern: " << clctsDatasTmp[lct].getPattern() << std::dec
1120                             << ", getBend: " << clctsDatasTmp[lct].getBend() << std::dec
1121                             << ", getSlope: " << clctsDatasTmp[lct].getSlope() << std::dec
1122                             << ", getFractionalSlope: " <<  clctsDatasTmp[lct].getFractionalSlope()
1123                             << ", getBX: " << clctsDatasTmp[lct].getBX()
1124                             << ", getRun3Pattern: 0x" << std::hex << clctsDatasTmp[lct].getRun3Pattern()
1125                             << std::dec;
1126 */
1127             if (clctsDatas[lct].isRun3()) {
1128               if (getCSCHisto(h::CSC_CLCTXX_COMPARATOR_CODE, crateID, dmbID, lct, mo)) {
1129                 mo->Fill(clctsDatas[lct].getCompCode());
1130               }
1131               if (getCSCHisto(h::CSC_CLCTXX_RUN3_TO_RUN2_PATTERN, crateID, dmbID, lct, mo)) {
1132                 int bend = clctsDatas[lct].getSlope() + ((clctsDatas[lct].getBend() & 0x1) << 4);
1133                 mo->Fill(bend, clctsDatas[lct].getPattern());
1134               }
1135               if (getCSCHisto(h::CSC_CLCTXX_RUN3_BEND_VS_SLOPE, crateID, dmbID, lct, mo)) {
1136                 mo->Fill(clctsDatas[lct].getSlope(), clctsDatas[lct].getBend());
1137               }
1138             }
1139           }
1140 
1141           /// Correlated LCTs processing
1142           std::vector<CSCCorrelatedLCTDigi> corr_lctsDatasTmp = tmbHeader->CorrelatedLCTDigis(cid.rawId());
1143           std::vector<CSCCorrelatedLCTDigi> corr_lctsDatas;
1144 
1145           for (uint32_t lct = 0; lct < corr_lctsDatasTmp.size(); lct++) {
1146             if (corr_lctsDatasTmp[lct].isValid()) {
1147               corr_lctsDatas.push_back(corr_lctsDatasTmp[lct]);
1148             }
1149 
1150             if (isGEM_df) {
1151               uint16_t gem_sync_status = tmbHeader->gem_sync_dataword();
1152 
1153               for (unsigned i = lct * 4; i < (lct * 4 + 4); i++) {
1154                 if ((gem_sync_status >> i) & 0x1) {
1155                   if (corr_lctsDatasTmp[lct].isValid()) {
1156                     if (getCSCHisto(h::CSC_GEM_LCT_SYNC_STATUS, crateID, dmbID, mo)) {
1157                       mo->Fill(lct, i);  // Fill for valid LCT
1158                     }
1159                   }
1160                 }
1161               }
1162             }
1163 
1164             if (getCSCHisto(h::CSC_CORR_LCT_CLCT_COMBINATION, crateID, dmbID, mo)) {
1165               mo->Fill(clctsDatasTmp[lct].isValid() * 2 + lct, corr_lctsDatasTmp[lct].isValid() * 2 + lct);
1166             }
1167 
1168             if (lct == 0) {
1169               if (corr_lctsDatasTmp[lct].isRun3() || isTMB_hybrid_df) {
1170                 /// Summary occupancy plot for combined HMT bits sent to MPC
1171                 if (getEMUHisto(h::EMU_CSC_LCT_HMT_REPORTING, mo)) {
1172                   if (corr_lctsDatasTmp[lct].getHMT() > 0)
1173                     mo->Fill(cscPosition, cscType);
1174                 }
1175                 if (getCSCHisto(h::CSC_RUN3_HMT_DISTRIBUTION, crateID, dmbID, mo)) {
1176                   mo->Fill(corr_lctsDatasTmp[lct].getHMT());
1177                 }
1178                 if (getCSCHisto(h::CSC_CLCT_RUN3_HMT_NHITS_VS_HMT_BITS, crateID, dmbID, mo)) {
1179                   mo->Fill(tmbHeader->hmt_nhits(),
1180                            (corr_lctsDatasTmp[lct].getHMT() & 0x3));  // in-time Hadronic shower bits
1181                   mo->Fill(tmbHeader->hmt_nhits(),
1182                            ((corr_lctsDatasTmp[lct].getHMT() >> 2) & 0x3) + 4);  // out-of-time Hadronic shower bits
1183                 }
1184                 if (getCSCHisto(h::CSC_RUN3_HMT_COINCIDENCE_MATCH, crateID, dmbID, mo)) {
1185                   if ((corr_lctsDatasTmp[lct].getHMT() > 0) && (corr_lctsDatasTmp[lct].getHMT() <= 0xF)) {
1186                     mo->Fill(0);  // Run3 HMT is fired
1187                     if ((!clctsDatasTmp.empty()) && clctsDatasTmp[lct].isValid()) {
1188                       mo->Fill(2);  // Run3 HMT+CLCT match
1189                     }
1190                     if (corr_lctsDatasTmp[lct].isValid()) {
1191                       mo->Fill(3);  // Run3 HMT+LCT match
1192                     }
1193                   }
1194                 }
1195                 if (getCSCHisto(h::CSC_RUN3_HMT_ALCT_MATCH, crateID, dmbID, mo)) {
1196                   if ((corr_lctsDatasTmp[lct].getHMT() > 0) && (corr_lctsDatasTmp[lct].getHMT() <= 0xF)) {
1197                     mo->Fill(tmbHeader->hmt_ALCTMatchTime());
1198                   }
1199                 }
1200                 if (getCSCHisto(h::CSC_RUN3_HMT_HADRONIC_SHOWER, crateID, dmbID, mo)) {
1201                   mo->Fill(corr_lctsDatasTmp[lct].getHMT() & 0x3);               // in-time Hadronic shower bits
1202                   mo->Fill(((corr_lctsDatasTmp[lct].getHMT() >> 2) & 0x3) + 4);  // out-of-time Hadronic shower bits
1203                 }
1204               }
1205             }
1206           }
1207 
1208           if (clctsDatasTmp[0].isValid() && corr_lctsDatasTmp[0].isValid() &&
1209               getCSCHisto(h::CSC_CORR_LCT0_VS_CLCT0_KEY_STRIP, crateID, dmbID, mo)) {
1210             mo->Fill(clctsDatasTmp[0].getKeyStrip(), corr_lctsDatasTmp[0].getStrip());
1211           }
1212 
1213           if (clctsDatasTmp[1].isValid() && corr_lctsDatasTmp[1].isValid() &&
1214               getCSCHisto(h::CSC_CORR_LCT1_VS_CLCT1_KEY_STRIP, crateID, dmbID, mo)) {
1215             mo->Fill(clctsDatasTmp[1].getKeyStrip(), corr_lctsDatasTmp[1].getStrip());
1216           }
1217 
1218           if (!corr_lctsDatas.empty()) {
1219             if (corr_lctsDatasTmp[0].isRun3()) {
1220               if (getCSCHisto(h::CSC_CORR_LCT0_VS_LCT1_RUN3_PATTERN, crateID, dmbID, mo)) {
1221                 int lct1_pattern = corr_lctsDatasTmp[1].getRun3Pattern();
1222                 if (!corr_lctsDatasTmp[1].isValid())
1223                   lct1_pattern = -1;
1224                 mo->Fill(corr_lctsDatasTmp[0].getRun3Pattern(), lct1_pattern);
1225               }
1226             }
1227           }
1228 
1229           for (uint32_t lct = 0; lct < corr_lctsDatas.size(); lct++) {
1230             /*
1231                   LOG_DEBUG << "CorrelatedLCT Digis dump: "
1232                             << "CorrLCT" << lct << " isRun3:" << corr_lctsDatasTmp[lct].isRun3()
1233                             << ", isValid: " << corr_lctsDatasTmp[lct].isValid()
1234                             << ", getStrip: " << corr_lctsDatasTmp[lct].getStrip()
1235                             << ", getKeyWG: " << corr_lctsDatasTmp[lct].getKeyWG()
1236                             << ", getQuality: " << corr_lctsDatasTmp[lct].getQuality()
1237                             << ", getFractionalStrip: " <<  corr_lctsDatasTmp[lct].getFractionalStrip()
1238                             << ", getQuartStrip: " << corr_lctsDatasTmp[lct].getQuartStripBit()
1239                             << ", getEightStrip: " << corr_lctsDatasTmp[lct].getEightStripBit()
1240                             << ",\n getSlope: " << corr_lctsDatasTmp[lct].getSlope() << std::dec
1241                             << ", getBend: " << corr_lctsDatasTmp[lct].getBend()
1242                             << ", getBX: " << corr_lctsDatasTmp[lct].getBX()
1243                             << ", getPattern: 0x" << std::hex << corr_lctsDatasTmp[lct].getPattern()
1244                             << ", getRun3Pattern: 0x" << std::hex << corr_lctsDatasTmp[lct].getRun3Pattern()
1245                             // << ", getRun3PatternID: " << std::dec << corr_lctsDatasTmp[lct].getRun3PatternID()
1246                             << ", getHMT: " << corr_lctsDatasTmp[lct].getHMT()
1247                 << std::dec;
1248 */
1249             if (getCSCHisto(h::CSC_CORR_LCTXX_HITS_DISTRIBUTION, crateID, dmbID, lct, mo)) {
1250               mo->Fill(corr_lctsDatas[lct].getStrip(), corr_lctsDatas[lct].getKeyWG());
1251             }
1252 
1253             if (getCSCHisto(h::CSC_CORR_LCTXX_KEY_WG, crateID, dmbID, lct, mo)) {
1254               mo->Fill(corr_lctsDatas[lct].getKeyWG());
1255             }
1256 
1257             if (getCSCHisto(h::CSC_CORR_LCTXX_KEY_HALFSTRIP, crateID, dmbID, lct, mo)) {
1258               mo->Fill(corr_lctsDatas[lct].getStrip(2));
1259             }
1260 
1261             if (corr_lctsDatas[lct].isRun3()) {
1262               if (getCSCHisto(h::CSC_CORR_LCTXX_KEY_QUARTSTRIP, crateID, dmbID, lct, mo)) {
1263                 mo->Fill(corr_lctsDatas[lct].getStrip(4));
1264               }
1265 
1266               if (getCSCHisto(h::CSC_CORR_LCTXX_KEY_EIGHTSTRIP, crateID, dmbID, lct, mo)) {
1267                 mo->Fill(corr_lctsDatas[lct].getStrip(8));
1268               }
1269 
1270               if (getCSCHisto(h::CSC_CORR_LCTXX_RUN3_TO_RUN2_PATTERN, crateID, dmbID, lct, mo)) {
1271                 int bend = corr_lctsDatas[lct].getSlope() + ((corr_lctsDatas[lct].getBend() & 0x1) << 4);
1272                 mo->Fill(bend, corr_lctsDatas[lct].getPattern());
1273               }
1274 
1275               if (getCSCHisto(h::CSC_CORR_LCTXX_BEND_VS_SLOPE, crateID, dmbID, lct, mo)) {
1276                 mo->Fill(corr_lctsDatas[lct].getSlope(), corr_lctsDatas[lct].getBend());
1277               }
1278 
1279               if (getCSCHisto(h::CSC_CORR_LCTXX_KEY_STRIP_TYPE, crateID, dmbID, lct, mo)) {
1280                 int strip_type =
1281                     (corr_lctsDatas[lct].getQuartStripBit() << 1) + (corr_lctsDatas[lct].getEighthStripBit());
1282                 mo->Fill(strip_type);
1283               }
1284 
1285               if ((cid.station() == 1) && (cid.ring() == 1)) {
1286                 if (getCSCHisto(h::CSC_CORR_LCTXX_RUN3_ME11_QUALITY, crateID, dmbID, lct, mo)) {
1287                   mo->Fill(corr_lctsDatas[lct].getQuality());
1288                 }
1289               } else {
1290                 if (getCSCHisto(h::CSC_CORR_LCTXX_RUN3_QUALITY, crateID, dmbID, lct, mo)) {
1291                   mo->Fill(corr_lctsDatas[lct].getQuality());
1292                 }
1293               }
1294             }
1295           }
1296 
1297           if (data.nalct()) {
1298             CSCALCTHeader* alctHeader = data.alctHeader();
1299             if (alctHeader) {
1300               std::vector<CSCALCTDigi> alctsDatasTmp = alctHeader->ALCTDigis();
1301               std::vector<CSCALCTDigi> alctsDatas;
1302               std::vector<uint32_t> keyWG_list;
1303               keyWG_list.clear();
1304               for (uint32_t lct = 0; lct < alctsDatasTmp.size(); lct++) {
1305                 if (alctsDatasTmp[lct].isValid()) {
1306                   alctsDatas.push_back(alctsDatasTmp[lct]);
1307                   keyWG_list.push_back(alctsDatasTmp[lct].getKeyWG());
1308                 }
1309               }
1310 
1311               if (!alctsDatas.empty() && getCSCHisto(h::CSC_RUN3_HMT_COINCIDENCE_MATCH, crateID, dmbID, mo) &&
1312                   corr_lctsDatasTmp[0].isRun3() && (corr_lctsDatasTmp[0].getHMT() > 0) &&
1313                   (corr_lctsDatasTmp[0].getHMT() <= 0xF) && alctsDatas[0].isValid()) {
1314                 mo->Fill(1);  // Run3 HMT+ALCT match
1315               }
1316 
1317               for (uint32_t lct = 0; lct < corr_lctsDatasTmp.size(); lct++) {
1318                 if (corr_lctsDatasTmp[lct].isValid()) {
1319                   for (uint32_t i = 0; i < keyWG_list.size(); i++) {
1320                     /// Find matching keyWG from ALCT keyWG list
1321                     if (corr_lctsDatasTmp[lct].getKeyWG() == keyWG_list[i]) {
1322                       if ((lct == 0) && getCSCHisto(h::CSC_CORR_LCT0_VS_ALCT0_KEY_WG, crateID, dmbID, mo))
1323                         mo->Fill(alctsDatas[i].getKeyWG(), corr_lctsDatasTmp[lct].getKeyWG());
1324                       if ((lct == 1) && getCSCHisto(h::CSC_CORR_LCT1_VS_ALCT1_KEY_WG, crateID, dmbID, mo))
1325                         mo->Fill(alctsDatas[i].getKeyWG(), corr_lctsDatasTmp[lct].getKeyWG());
1326                       if (getCSCHisto(h::CSC_CORR_LCT_VS_ALCT_DIGI_MATCH, crateID, dmbID, mo)) {
1327                         mo->Fill(lct, i);
1328                       }
1329                       continue;
1330                     }
1331                   }
1332                 }
1333               }
1334             }
1335           }
1336 
1337           FEBunpacked = FEBunpacked + 1;
1338           tmb_unpacked = 1;
1339 
1340           if (getCSCHisto(h::CSC_ALCT_MATCH_TIME, crateID, dmbID, mo)) {
1341             mo->Fill(tmbHeader->ALCTMatchTime());
1342             double alct_match_mean = mo->getTH1()->GetMean();
1343             double alct_match_rms = mo->getTH1()->GetRMS();
1344             MonitorObject* mo1 = nullptr;
1345 
1346             if (cid.endcap() == 1) {
1347               if (cscPosition && getEMUHisto(h::EMU_CSC_ENDCAP_PLUS_ALCT_CLCT_MATCH_TIME, mo1)) {
1348                 mo1->Fill(tmbHeader->ALCTMatchTime());
1349               }
1350             }
1351 
1352             if (cid.endcap() == 2) {
1353               if (cscPosition && getEMUHisto(h::EMU_CSC_ENDCAP_MINUS_ALCT_CLCT_MATCH_TIME, mo1)) {
1354                 mo1->Fill(tmbHeader->ALCTMatchTime());
1355               }
1356             }
1357 
1358             if (cscPosition && getEMUHisto(h::EMU_CSC_ALCT_CLCT_MATCH_MEAN, mo1)) {
1359               mo1->SetBinContent(cscPosition, cscType + 1, alct_match_mean);
1360             }
1361 
1362             if (cscPosition && getEMUHisto(h::EMU_CSC_ALCT_CLCT_MATCH_RMS, mo1)) {
1363               mo1->SetBinContent(cscPosition, cscType + 1, alct_match_rms);
1364             }
1365           }
1366 
1367           if (getCSCHisto(h::CSC_LCT_MATCH_STATUS, crateID, dmbID, mo)) {
1368             if (tmbHeader->CLCTOnly())
1369               mo->Fill(0.0, 0.0);
1370             if (tmbHeader->ALCTOnly())
1371               mo->Fill(0.0, 1.0);
1372             if (tmbHeader->TMBMatch())
1373               mo->Fill(0.0, 2.0);
1374           }
1375 
1376           if (getCSCHisto(h::CSC_LCT0_MATCH_BXN_DIFFERENCE, crateID, dmbID, mo))
1377             mo->Fill(tmbHeader->Bxn0Diff());
1378           if (getCSCHisto(h::CSC_LCT1_MATCH_BXN_DIFFERENCE, crateID, dmbID, mo))
1379             mo->Fill(tmbHeader->Bxn1Diff());
1380 
1381           if ((tmb_dav > 0) && (getCSCHisto(h::CSC_DMB_FEB_UNPACKED_VS_DAV, crateID, dmbID, mo))) {
1382             mo->Fill(1.0, 0.0);
1383           }
1384 
1385           /**  Set number of CLCT-events to forth bin */
1386           if (getCSCHisto(h::CSC_CSC_RATE, crateID, dmbID, mo)) {
1387             mo->Fill(3);
1388             uint32_t CLCTEvent = (uint32_t)mo->GetBinContent(4);
1389             config->setChamberCounterValue(CLCT_TRIGGERS, crateID, dmbID, CLCTEvent);
1390             if (getCSCHisto(h::CSC_CSC_EFFICIENCY, crateID, dmbID, mo)) {
1391               if (config->getNEvents() > 0) {
1392                 mo->SetBinContent(2, ((float)CLCTEvent / (float)(DMBEvents)*100.0));
1393                 mo->SetEntries(DMBEvents);
1394               }
1395             }
1396           }
1397 
1398           if (getCSCHisto(h::CSC_CLCT_L1A, crateID, dmbID, mo))
1399             mo->Fill(tmbHeader->L1ANumber());
1400 
1401           /**  Use 6-bit L1A */
1402           if (getCSCHisto(h::CSC_CLCT_DMB_L1A_DIFF, crateID, dmbID, mo)) {
1403             int clct_dmb_l1a_diff = (int)((tmbHeader->L1ANumber() % 64) - dmbHeader->l1a24() % 64);
1404             if (clct_dmb_l1a_diff != 0)
1405               L1A_out_of_sync = true;
1406             if (clct_dmb_l1a_diff < -32)
1407               mo->Fill(clct_dmb_l1a_diff + 64);
1408             else {
1409               if (clct_dmb_l1a_diff >= 32)
1410                 mo->Fill(clct_dmb_l1a_diff - 64);
1411               else
1412                 mo->Fill(clct_dmb_l1a_diff);
1413             }
1414             mo->SetAxisRange(0.1, 1.1 * (1.0 + mo->GetBinContent(mo->GetMaximumBin())), "Y");
1415           }
1416 
1417           if (getCSCHisto(h::CSC_DMB_L1A_VS_CLCT_L1A, crateID, dmbID, mo))
1418             mo->Fill(tmbHeader->L1ANumber() % 256, dmbHeader->l1a24() % 256);
1419 
1420           if (getCSCHisto(h::CSC_CLCT_DMB_BXN_DIFF, crateID, dmbID, mo)) {
1421             int clct_dmb_bxn_diff = (int)(tmbHeader->BXNCount() % 64 - dmbHeader->bxn12() % 64);
1422             if (clct_dmb_bxn_diff < -32)
1423               mo->Fill(clct_dmb_bxn_diff + 64);
1424             else {
1425               if (clct_dmb_bxn_diff >= 32)
1426                 mo->Fill(clct_dmb_bxn_diff - 64);
1427               else
1428                 mo->Fill(clct_dmb_bxn_diff);
1429             }
1430             mo->SetAxisRange(0.1, 1.1 * (1.0 + mo->GetBinContent(mo->GetMaximumBin())), "Y");
1431           }
1432 
1433           if (getCSCHisto(h::CSC_CLCT_BXN, crateID, dmbID, mo))
1434             mo->Fill((int)(tmbHeader->BXNCount()));
1435 
1436           if (getCSCHisto(h::CSC_CLCT_BXN_VS_DMB_BXN, crateID, dmbID, mo))
1437             mo->Fill(tmbHeader->BXNCount() % 256, dmbHeader->bxn12() % 256);
1438 
1439           if (getCSCHisto(h::CSC_CLCT_NUMBER_RATE, crateID, dmbID, mo)) {
1440             mo->Fill(clctsDatas.size());
1441             int nCLCT = (int)mo->GetBinContent((int)(clctsDatas.size() + 1));
1442             if (getCSCHisto(h::CSC_CLCT_NUMBER, crateID, dmbID, mo))
1443               mo->SetBinContent((int)(clctsDatas.size() + 1), (float)(nCLCT) / (float)(DMBEvents)*100.0);
1444           }
1445 
1446           if (clctsDatas.size() == 1) {
1447             if (getCSCHisto(h::CSC_CLCT0_CLSSIFICATION, crateID, dmbID, mo)) {
1448               if (clctsDatas[0].getStripType())
1449                 mo->Fill(0.0);
1450               else
1451                 mo->Fill(1.0);
1452             }
1453           }
1454 
1455           if (clctsDatas.size() == 2) {
1456             if (getCSCHisto(h::CSC_CLCT1_VS_CLCT0_KEY_STRIP, crateID, dmbID, mo))
1457               mo->Fill(clctsDatas[0].getKeyStrip(), clctsDatas[1].getKeyStrip());
1458             if (getCSCHisto(h::CSC_CLCT0_CLCT1_CLSSIFICATION, crateID, dmbID, mo)) {
1459               if (clctsDatas[0].getStripType() && clctsDatas[1].getStripType())
1460                 mo->Fill(0.0);
1461               if (clctsDatas[0].getStripType() && !clctsDatas[1].getStripType())
1462                 mo->Fill(1.0);
1463               if (!clctsDatas[0].getStripType() && clctsDatas[1].getStripType())
1464                 mo->Fill(2.0);
1465               if (!clctsDatas[0].getStripType() && !clctsDatas[1].getStripType())
1466                 mo->Fill(3.0);
1467             }
1468           }
1469 
1470           if (getCSCHisto(h::CSC_TMB_WORD_COUNT, crateID, dmbID, mo))
1471             mo->Fill((int)(tmbTrailer->wordCount()));
1472 
1473           MonitorObject* mo_CSC_Plus_endcap_CLCT0_dTime = nullptr;
1474           getEMUHisto(h::EMU_CSC_ENDCAP_PLUS_CLCT0_DTIME, mo_CSC_Plus_endcap_CLCT0_dTime);
1475 
1476           MonitorObject* mo_CSC_Minus_endcap_CLCT0_dTime = nullptr;
1477           getEMUHisto(h::EMU_CSC_ENDCAP_MINUS_CLCT0_DTIME, mo_CSC_Minus_endcap_CLCT0_dTime);
1478 
1479           MonitorObject* mo_CSC_CLCT0_BXN_mean = nullptr;
1480           getEMUHisto(h::EMU_CSC_CLCT0_BXN_MEAN, mo_CSC_CLCT0_BXN_mean);
1481 
1482           MonitorObject* mo_CSC_CLCT0_BXN_rms = nullptr;
1483           getEMUHisto(h::EMU_CSC_CLCT0_BXN_RMS, mo_CSC_CLCT0_BXN_rms);
1484 
1485           for (uint32_t lct = 0; lct < clctsDatas.size(); lct++) {
1486             if (getCSCHisto(h::CSC_CLCTXX_BXN, crateID, dmbID, lct, mo))
1487               mo->Fill(clctsDatas[lct].getFullBX() % 64);
1488 
1489             int clct_dtime = clctsDatas[lct].getFullBX() - tmbHeader->BXNCount();
1490             if (clct_dtime > 0) {
1491               clct_dtime -= 3564;
1492             }
1493 
1494             int dTime = clct_dtime;
1495 
1496             if (lct == 0) {
1497               if (cid.endcap() == 1) {
1498                 if (mo_CSC_Plus_endcap_CLCT0_dTime)
1499                   mo_CSC_Plus_endcap_CLCT0_dTime->Fill(dTime);
1500               }
1501               if (cid.endcap() == 2) {
1502                 if (mo_CSC_Minus_endcap_CLCT0_dTime)
1503                   mo_CSC_Minus_endcap_CLCT0_dTime->Fill(dTime);
1504               }
1505             }
1506 
1507             if (getCSCHisto(h::CSC_CLCTXX_DTIME, crateID, dmbID, lct, mo)) {
1508               mo->Fill(dTime);
1509               mo->SetAxisRange(0.1, 1.1 * (1.0 + mo->GetBinContent(mo->GetMaximumBin())), "Y");
1510 
1511               double dTime_mean = mo->getTH1()->GetMean();
1512               double dTime_rms = mo->getTH1()->GetRMS();
1513 
1514               // == For CLCT0 Fill Summary dTime Histograms
1515               if (lct == 0) {
1516                 if (cscPosition && mo_CSC_CLCT0_BXN_mean) {
1517                   mo_CSC_CLCT0_BXN_mean->SetBinContent(cscPosition, cscType + 1, dTime_mean);
1518                 }
1519                 if (cscPosition && mo_CSC_CLCT0_BXN_rms) {
1520                   mo_CSC_CLCT0_BXN_rms->SetBinContent(cscPosition, cscType + 1, dTime_rms);
1521                 }
1522               }
1523             }
1524 
1525             /* LOG_DEBUG << "LCT:" << lct << " Type:" << clctsDatas[lct].getStripType()
1526                       << " Strip:" << clctsDatas[lct].getKeyStrip();
1527              */
1528 
1529             if (clctsDatas[lct].getStripType()) {  // HalfStrip Type
1530 
1531               if (getCSCHisto(h::CSC_CLCTXX_KEYHALFSTRIP, crateID, dmbID, lct, mo))
1532                 mo->Fill(clctsDatas[lct].getKeyStrip());
1533 
1534               /* === Run3 CSC-GEM Trigger data format */
1535               if (getCSCHisto(h::CSC_CLCTXX_KEY_QUARTSTRIP, crateID, dmbID, lct, mo))
1536                 mo->Fill(clctsDatas[lct].getKeyStrip(4));
1537               if (getCSCHisto(h::CSC_CLCTXX_KEY_EIGHTSTRIP, crateID, dmbID, lct, mo))
1538                 mo->Fill(clctsDatas[lct].getKeyStrip(8));
1539               /* === Run3 */
1540 
1541               if (getCSCHisto(h::CSC_CLCTXX_DTIME_VS_HALF_STRIP, crateID, dmbID, lct, mo)) {
1542                 mo->Fill((int)(clctsDatas[lct].getKeyStrip()), clct_dtime);
1543               }
1544 
1545               if (getCSCHisto(h::CSC_CLCTXX_DTIME_PROFILE, crateID, dmbID, lct, mo)) {
1546                 mo->Fill((int)(clctsDatas[lct].getKeyStrip()), clct_dtime);
1547               }
1548 
1549               if (getCSCHisto(h::CSC_CLCTXX_HALF_STRIP_PATTERN, crateID, dmbID, lct, mo)) {
1550                 int pattern_clct = clctsDatas[lct].getPattern();
1551                 /**  int pattern_clct = (int)((clctsDatas[lct].getPattern()>>1)&0x3); */
1552                 /**  pattern_clct = Number of patterns in CLCT */
1553                 /**  Last (left) bit is bend. Positive bend = 1, negative bend = 0 */
1554                 double tbin = -1;
1555 
1556                 switch (pattern_clct) {
1557                   case 0:
1558                     tbin = 0.;
1559                     break;
1560                   case 1:
1561                     tbin = 1.;
1562                     break;
1563                   case 2:
1564                     tbin = 2.;
1565                     break;
1566                   case 3:
1567                     tbin = 10.;
1568                     break;
1569                   case 4:
1570                     tbin = 3.;
1571                     break;
1572                   case 5:
1573                     tbin = 9.;
1574                     break;
1575                   case 6:
1576                     tbin = 4.;
1577                     break;
1578                   case 7:
1579                     tbin = 8.;
1580                     break;
1581                   case 8:
1582                     tbin = 5.;
1583                     break;
1584                   case 9:
1585                     tbin = 7.;
1586                     break;
1587                   case 10:
1588                     tbin = 6.;
1589                     break;
1590                 }
1591 
1592                 if (tbin >= 0)
1593                   mo->Fill(clctsDatas[lct].getKeyStrip(), tbin);
1594 
1595                 MonitorObject* mo1 = nullptr;
1596                 if (getCSCHisto(h::CSC_CLCT_HALF_STRIP_PATTERN_DISTR, crateID, dmbID, lct, mo1))
1597                   mo1->Fill(tbin);
1598               }
1599 
1600               if (getCSCHisto(h::CSC_CLCTXX_HALF_STRIP_QUALITY, crateID, dmbID, lct, mo))
1601                 mo->Fill((int)(clctsDatas[lct].getKeyStrip()), (int)(clctsDatas[lct].getQuality()));
1602 
1603               if (mo_EventDisplay) {
1604                 mo_EventDisplay->SetBinContent(10, clctsDatas[lct].getKeyStrip(), clct_dtime);
1605                 mo_EventDisplay->SetBinContent(11, clctsDatas[lct].getKeyStrip(), clctsDatas[lct].getQuality());
1606               }
1607 
1608               if (getCSCHisto(h::CSC_CLCTXX_HALF_STRIP_QUALITY_DISTR, crateID, dmbID, lct, mo)) {
1609                 mo->Fill((int)(clctsDatas[lct].getQuality()));
1610                 if (lct == 0) {
1611                   MonitorObject* mo1 = nullptr;
1612                   if (cscPosition && getEMUHisto(h::EMU_CSC_CLCT0_QUALITY, mo1)) {
1613                     mo1->SetBinContent(cscPosition, cscType + 1, mo->getTH1()->GetMean());
1614                   }
1615                 }
1616               }
1617 
1618               if (getCSCHisto(h::CSC_CLCTXX_HALF_STRIP_QUALITY_PROFILE, crateID, dmbID, lct, mo))
1619                 mo->Fill((int)(clctsDatas[lct].getKeyStrip()), (int)(clctsDatas[lct].getQuality()));
1620 
1621             } else {  // DiStrip Type
1622 
1623               LOG_INFO << "Entering block!";
1624 
1625               if (getCSCHisto(h::CSC_CLCTXX_KEYDISTRIP, crateID, dmbID, lct, mo))
1626                 mo->Fill(clctsDatas[lct].getKeyStrip());
1627               else
1628                 LOG_ERROR << "Not found h::CSC_CLCTXX_KEYDISTRIP = " << h::CSC_CLCTXX_KEYDISTRIP;
1629 
1630               if (lct == 0)
1631                 clct_kewdistrip = clctsDatas[lct].getKeyStrip();
1632 
1633               if (getCSCHisto(h::CSC_CLCTXX_DTIME_VS_DISTRIP, crateID, dmbID, lct, mo)) {
1634                 mo->Fill((int)(clctsDatas[lct].getKeyStrip()), clct_dtime);
1635               }
1636 
1637               if (getCSCHisto(h::CSC_CLCTXX_DISTRIP_PATTERN, crateID, dmbID, lct, mo)) {
1638                 int pattern_clct = (int)((clctsDatas[lct].getPattern() >> 1) & 0x3);
1639                 /**  pattern_clct = Number of patterns in CLCT */
1640                 /**  Last (left) bit is bend. Positive bend = 1, negative bend = 0 */
1641                 if (pattern_clct == 1)
1642                   mo->Fill(clctsDatas[lct].getKeyStrip(), 7.0);
1643                 if (pattern_clct == 3)
1644                   mo->Fill(clctsDatas[lct].getKeyStrip(), 6.0);
1645                 if (pattern_clct == 5)
1646                   mo->Fill(clctsDatas[lct].getKeyStrip(), 5.0);
1647                 if (pattern_clct == 7)
1648                   mo->Fill(clctsDatas[lct].getKeyStrip(), 4.0);
1649                 if (pattern_clct == 6)
1650                   mo->Fill(clctsDatas[lct].getKeyStrip(), 3.0);
1651                 if (pattern_clct == 4)
1652                   mo->Fill(clctsDatas[lct].getKeyStrip(), 2.0);
1653                 if (pattern_clct == 2)
1654                   mo->Fill(clctsDatas[lct].getKeyStrip(), 1.0);
1655                 if (pattern_clct == 0)
1656                   mo->Fill(clctsDatas[lct].getKeyStrip(), 0.0);
1657               }
1658 
1659               if (getCSCHisto(h::CSC_CLCTXX_DISTRIP_QUALITY, crateID, dmbID, lct, mo))
1660                 mo->Fill((int)(clctsDatas[lct].getKeyStrip()), (int)(clctsDatas[lct].getQuality()));
1661 
1662               if (getCSCHisto(h::CSC_CLCTXX_DISTRIP_QUALITY_PROFILE, crateID, dmbID, lct, mo))
1663                 mo->Fill((int)(clctsDatas[lct].getKeyStrip()), (int)(clctsDatas[lct].getQuality()));
1664             }
1665           }
1666 
1667           int N_CFEBs = tmbHeader->NCFEBs();
1668           int NumberOfLayersWithHitsInCLCT = 0;
1669           int NumberOfHalfStripsWithHitsInCLCT = 0;
1670 
1671           if (comparatorData && comparatorData->check()) {
1672             MonitorObject* mo_CFEB_Comparators_TimeSamples = nullptr;
1673             getCSCHisto(h::CSC_CFEB_COMPARATORS_TIMESAMPLES, crateID, dmbID, mo_CFEB_Comparators_TimeSamples);
1674 
1675             MonitorObject* mo_CSC_Plus_endcap_CFEB_Comparators_Time = nullptr;
1676             getEMUHisto(h::EMU_CSC_ENDCAP_PLUS_CFEB_COMPARATORS_TIME, mo_CSC_Plus_endcap_CFEB_Comparators_Time);
1677 
1678             MonitorObject* mo_CSC_Minus_endcap_CFEB_Comparators_Time = nullptr;
1679             getEMUHisto(h::EMU_CSC_ENDCAP_MINUS_CFEB_COMPARATORS_TIME, mo_CSC_Minus_endcap_CFEB_Comparators_Time);
1680 
1681             MonitorObject* mo_CSC_CFEB_Comparators_Time_mean = nullptr;
1682             getEMUHisto(h::EMU_CSC_CFEB_COMPARATORS_TIME_MEAN, mo_CSC_CFEB_Comparators_Time_mean);
1683 
1684             MonitorObject* mo_CSC_CFEB_Comparators_Time_rms = nullptr;
1685             getEMUHisto(h::EMU_CSC_CFEB_COMPARATORS_TIME_RMS, mo_CSC_CFEB_Comparators_Time_rms);
1686 
1687             for (int nCFEB = 0; nCFEB < N_CFEBs; ++nCFEB) {
1688               for (int nLayer = 1; nLayer <= 6; nLayer++) {
1689                 int hstrip_previous = -1;
1690                 int tbin_clct_previous = -1;
1691                 bool CheckLayerCLCT = true;
1692 
1693                 std::vector<CSCComparatorDigi> compOutData = comparatorData->comparatorDigis(nLayer, nCFEB);
1694 
1695                 for (std::vector<CSCComparatorDigi>::iterator compOutDataItr = compOutData.begin();
1696                      compOutDataItr != compOutData.end();
1697                      ++compOutDataItr) {
1698                   /**  =VB= Fix to get right hafstrip */
1699                   int hstrip = 2 * (compOutDataItr->getStrip() - 1) + compOutDataItr->getComparator();
1700                   std::vector<int> tbins_clct = compOutDataItr->getTimeBinsOn();
1701                   int tbin_clct = (int)compOutDataItr->getTimeBin();
1702 
1703                   if (mo_EventDisplay) {
1704                     mo_EventDisplay->SetBinContent(nLayer + 11, hstrip, tbin_clct + 1);
1705                     setEmuEventDisplayBit(mo_Emu_EventDisplay_Anode, glChamberIndex, 160 + hstrip, nLayer - 1);
1706                     setEmuEventDisplayBit(mo_Emu_EventDisplay_XY, glChamberIndex, 160 + hstrip, nLayer - 1);
1707                   }
1708 
1709                   if (CheckLayerCLCT) {
1710                     NumberOfLayersWithHitsInCLCT = NumberOfLayersWithHitsInCLCT + 1;
1711                     CheckLayerCLCT = false;
1712                   }
1713 
1714                   for (uint32_t n = 0; n < tbins_clct.size(); n++) {
1715                     tbin_clct = tbins_clct[n];
1716                     if (hstrip != hstrip_previous ||
1717                         (tbin_clct != tbin_clct_previous + 1 && tbin_clct != tbin_clct_previous - 1)) {
1718                       if (getCSCHisto(h::CSC_CLCTTIME_LYXX, crateID, dmbID, nLayer, mo))
1719                         mo->Fill(hstrip, tbin_clct);
1720 
1721                       if (mo_CFEB_Comparators_TimeSamples)
1722                         mo_CFEB_Comparators_TimeSamples->Fill(tbin_clct);
1723 
1724                       if (cid.endcap() == 1) {
1725                         if (mo_CSC_Plus_endcap_CFEB_Comparators_Time)
1726                           mo_CSC_Plus_endcap_CFEB_Comparators_Time->Fill(tbin_clct);
1727                       }
1728 
1729                       if (cid.endcap() == 2) {
1730                         if (mo_CSC_Minus_endcap_CFEB_Comparators_Time)
1731                           mo_CSC_Minus_endcap_CFEB_Comparators_Time->Fill(tbin_clct);
1732                       }
1733 
1734                       if (getCSCHisto(h::CSC_CLCTTIME_LYXX_PROFILE, crateID, dmbID, nLayer, mo))
1735                         mo->Fill(hstrip, tbin_clct);
1736 
1737                       if (getCSCHisto(h::CSC_CLCT_LYXX_RATE, crateID, dmbID, nLayer, mo)) {
1738                         mo->Fill(hstrip);
1739 
1740                         double number_hstrip = mo->GetBinContent(hstrip + 1);
1741                         double Number_of_entries_CLCT = mo->GetEntries();
1742 
1743                         if (getCSCHisto(h::CSC_CLCT_LYXX_EFFICIENCY, crateID, dmbID, nLayer, mo)) {
1744                           mo->SetBinContent(hstrip + 1, number_hstrip);
1745                           if (DMBEvents > 0) {
1746                             double norm = (100.0 * Number_of_entries_CLCT) / ((double)(DMBEvents));
1747                             /**  if (norm < 1.0) norm=1; */
1748                             mo->SetNormFactor(norm);
1749                           } else {
1750                             mo->SetNormFactor(100.0);
1751                           }
1752                           mo->SetEntries(DMBEvents);
1753                         }
1754                       }
1755                     }
1756 
1757                     if (hstrip != hstrip_previous) {
1758                       NumberOfHalfStripsWithHitsInCLCT = NumberOfHalfStripsWithHitsInCLCT + 1;
1759                     }
1760                     hstrip_previous = hstrip;
1761                     tbin_clct_previous = tbin_clct;
1762                   }
1763                 }
1764               }
1765             }
1766 
1767             if (mo_CFEB_Comparators_TimeSamples) {
1768               double comps_time_mean = mo_CFEB_Comparators_TimeSamples->getTH1()->GetMean();
1769               double comps_time_rms = mo_CFEB_Comparators_TimeSamples->getTH1()->GetRMS();
1770 
1771               if (cscPosition && mo_CSC_CFEB_Comparators_Time_mean) {
1772                 mo_CSC_CFEB_Comparators_Time_mean->SetBinContent(cscPosition, cscType + 1, comps_time_mean);
1773               }
1774               if (cscPosition && mo_CSC_CFEB_Comparators_Time_rms) {
1775                 mo_CSC_CFEB_Comparators_Time_rms->SetBinContent(cscPosition, cscType + 1, comps_time_rms);
1776               }
1777             }
1778 
1779           } else {
1780             LOG_ERROR << cscTag << " Can not unpack CLCT Data";
1781           }
1782 
1783           if (getCSCHisto(h::CSC_CLCT_NUMBER_OF_LAYERS_WITH_HITS, crateID, dmbID, mo)) {
1784             mo->Fill(NumberOfLayersWithHitsInCLCT);
1785             MonitorObject* mo1 = nullptr;
1786             if (cscPosition && getEMUHisto(h::EMU_CSC_CLCT_PLANES_WITH_HITS, mo1)) {
1787               mo1->SetBinContent(cscPosition, cscType + 1, mo->getTH1()->GetMean());
1788             }
1789           }
1790 
1791           if (getCSCHisto(h::CSC_CLCT_NUMBER_OF_HALFSTRIPS_WITH_HITS, crateID, dmbID, mo))
1792             mo->Fill(NumberOfHalfStripsWithHitsInCLCT);
1793         } else {
1794           LOG_ERROR << cscTag << " Can not unpack TMB Header or/and Trailer";
1795         }
1796       } else {
1797         LOG_ERROR << cscTag << " Can not unpack TMB Data";
1798       }
1799 
1800     } else {
1801       /**   CLCT not found */
1802 
1803       if (getCSCHisto(h::CSC_CLCT_NUMBER_RATE, crateID, dmbID, mo)) {
1804         mo->Fill(0);
1805         int nCLCT = (int)mo->GetBinContent(1);
1806         if (getCSCHisto(h::CSC_CLCT_NUMBER, crateID, dmbID, mo))
1807           mo->SetBinContent(1, (float)(nCLCT) / (float)(DMBEvents)*100.0);
1808       }
1809       if ((tmb_dav > 0) && (getCSCHisto(h::CSC_DMB_FEB_UNPACKED_VS_DAV, crateID, dmbID, mo))) {
1810         mo->Fill(1.0, 1.0);
1811       }
1812     }
1813 
1814     /**  CFEB found */
1815     int NumberOfUnpackedCFEBs = 0;
1816     const int N_CFEBs = nCFEBs, N_Samples = 16, N_Layers = 6, N_Strips = 16, nStrips = nCFEBs * N_Strips;
1817     int ADC = 0, OutOffRange, Threshold = 30;
1818     /**  bool DebugCFEB = false; */
1819     int Pedestal[N_CFEBs][6][16];
1820     memset(Pedestal, 0, sizeof(Pedestal));
1821 #ifdef __clang__
1822     std::vector<std::array<std::array<std::pair<int, int>, 6>, 16>> CellPeak(N_CFEBs);
1823     std::fill(CellPeak.begin(), CellPeak.end(), std::array<std::array<std::pair<int, int>, 6>, 16>{});
1824 #else
1825     std::pair<int, int> CellPeak[N_CFEBs][6][16];
1826     memset(CellPeak, 0, sizeof(CellPeak));
1827 #endif
1828     bool CheckCFEB = true;
1829     /** --------------B */
1830     float Clus_Sum_Charge;
1831     int TrigTime, L1APhase, UnpackedTrigTime, LCTPhase, SCA_BLK, NmbTimeSamples;
1832     int FreeCells, LCT_Pipe_Empty, LCT_Pipe_Full, LCT_Pipe_Count, L1_Pipe_Empty, L1_Pipe_Full, Buffer_Count;
1833     /** --------------E */
1834 
1835     bool CheckThresholdStripInTheLayer[6][nStrips];
1836     for (int i = 0; i < 6; i++) {
1837       for (int j = 0; j < nStrips; j++)
1838         CheckThresholdStripInTheLayer[i][j] = true;
1839     }
1840 
1841     bool CheckOutOffRangeStripInTheLayer[6][nStrips];
1842     for (int i = 0; i < 6; i++) {
1843       for (int j = 0; j < nStrips; j++)
1844         CheckOutOffRangeStripInTheLayer[i][j] = true;
1845     }
1846 
1847     /** --------------B */
1848     float cscdata[N_CFEBs * 16][N_Samples][N_Layers];
1849     int SCABlockData[N_CFEBs * 16][N_Samples][N_Layers];
1850     memset(cscdata, 0, sizeof(cscdata));
1851     memset(SCABlockData, 0, sizeof(SCABlockData));
1852     /** --------------E */
1853 
1854     char hbuf[255];
1855     memset(hbuf, 0, sizeof(hbuf));
1856 
1857     MonitorObject* mo_CFEB_SCA_CellPeak_Time = nullptr;
1858     getCSCHisto(h::CSC_CFEB_SCA_CELLPEAK_TIME, crateID, dmbID, mo_CFEB_SCA_CellPeak_Time);
1859 
1860     MonitorObject* mo_CSC_Plus_endcap_CFEB_SCA_CellPeak_Time = nullptr;
1861     getEMUHisto(h::EMU_CSC_PLUS_ENDCAP_CFEB_SCA_CELLPEAK_TIME, mo_CSC_Plus_endcap_CFEB_SCA_CellPeak_Time);
1862 
1863     MonitorObject* mo_CSC_Minus_endcap_CFEB_SCA_CellPeak_Time = nullptr;
1864     getEMUHisto(h::EMU_CSC_MINUS_ENDCAP_CFEB_SCA_CELLPEAK_TIME, mo_CSC_Minus_endcap_CFEB_SCA_CellPeak_Time);
1865 
1866     MonitorObject* mo_CSC_CFEB_SCA_CellPeak_Time_mean = nullptr;
1867     getEMUHisto(h::EMU_CSC_CFEB_SCA_CELLPEAK_TIME_MEAN, mo_CSC_CFEB_SCA_CellPeak_Time_mean);
1868 
1869     MonitorObject* mo_CSC_CFEB_SCA_CellPeak_Time_rms = nullptr;
1870     getEMUHisto(h::EMU_CSC_CFEB_SCA_CELLPEAK_TIME_RMS, mo_CSC_CFEB_SCA_CellPeak_Time_rms);
1871 
1872     for (int nCFEB = 0; nCFEB < N_CFEBs; ++nCFEB) {
1873       //       cfebData[nCFEB] = data.cfebData(nCFEB);
1874       if (data.cfebData(nCFEB) != nullptr) {
1875         if (!data.cfebData(nCFEB)->check())
1876           continue;
1877 
1878         /**                         CFEB Found */
1879         FEBunpacked = FEBunpacked + 1;                      // Increment number of unpacked FED
1880         NumberOfUnpackedCFEBs = NumberOfUnpackedCFEBs + 1;  // Increment number of unpaked CFEB
1881         cfeb_unpacked = 1;
1882         if (CheckCFEB == true) {
1883           if (getCSCHisto(h::CSC_CSC_RATE, crateID, dmbID, mo)) {
1884             mo->Fill(4);
1885             uint32_t CFEBEvent = (uint32_t)mo->GetBinContent(5);
1886             config->setChamberCounterValue(CFEB_TRIGGERS, crateID, dmbID, CFEBEvent);
1887             if (getCSCHisto(h::CSC_CSC_EFFICIENCY, crateID, dmbID, mo)) {
1888               if (config->getNEvents() > 0) {
1889                 mo->SetBinContent(3, ((float)CFEBEvent / (float)(DMBEvents)*100.0));
1890                 mo->SetEntries((int)DMBEvents);
1891               }
1892             }
1893           }
1894 
1895           if ((cfeb_dav2 > 0) && (getCSCHisto(h::CSC_DMB_FEB_UNPACKED_VS_DAV, crateID, dmbID, mo))) {
1896             mo->Fill(2.0, 0.0);
1897           }
1898           CheckCFEB = false;
1899         }
1900         /** -------------B */
1901         NmbTimeSamples = (data.cfebData(nCFEB))->nTimeSamples();
1902         /** -------------E */
1903 
1904         /**  =VB= Optimizations for faster histogram object access  */
1905         MonitorObject* mo_CFEB_SCA_Block_Occupancy = nullptr;
1906         getCSCHisto(h::CSC_CFEBXX_SCA_BLOCK_OCCUPANCY, crateID, dmbID, nCFEB + 1, mo_CFEB_SCA_Block_Occupancy);
1907         MonitorObject* mo_CFEB_Free_SCA_Cells = nullptr;
1908         getCSCHisto(h::CSC_CFEBXX_FREE_SCA_CELLS, crateID, dmbID, nCFEB + 1, mo_CFEB_Free_SCA_Cells);
1909         MonitorObject* mo_CFEB_SCA_Blocks_Locked_by_LCTs = nullptr;
1910         getCSCHisto(
1911             h::CSC_CFEBXX_SCA_BLOCKS_LOCKED_BY_LCTS, crateID, dmbID, nCFEB + 1, mo_CFEB_SCA_Blocks_Locked_by_LCTs);
1912         MonitorObject* mo_CFEB_SCA_Blocks_Locked_by_LCTxL1 = nullptr;
1913         getCSCHisto(
1914             h::CSC_CFEBXX_SCA_BLOCKS_LOCKED_BY_LCTXL1, crateID, dmbID, nCFEB + 1, mo_CFEB_SCA_Blocks_Locked_by_LCTxL1);
1915         MonitorObject* mo_CFEB_DMB_L1A_diff = nullptr;
1916         getCSCHisto(h::CSC_CFEBXX_DMB_L1A_DIFF, crateID, dmbID, nCFEB + 1, mo_CFEB_DMB_L1A_diff);
1917 
1918         for (int nLayer = 1; nLayer <= N_Layers; ++nLayer) {
1919           /**   =VB= Optimizations for faster histogram object access */
1920           MonitorObject* mo_CFEB_Out_Off_Range_Strips = nullptr;
1921           getCSCHisto(h::CSC_CFEB_OUT_OFF_RANGE_STRIPS_LYXX, crateID, dmbID, nLayer, mo_CFEB_Out_Off_Range_Strips);
1922           MonitorObject* mo_CFEB_Active_Samples_vs_Strip = nullptr;
1923           getCSCHisto(
1924               h::CSC_CFEB_ACTIVE_SAMPLES_VS_STRIP_LYXX, crateID, dmbID, nLayer, mo_CFEB_Active_Samples_vs_Strip);
1925           MonitorObject* mo_CFEB_Active_Samples_vs_Strip_Profile = nullptr;
1926           getCSCHisto(h::CSC_CFEB_ACTIVE_SAMPLES_VS_STRIP_LYXX_PROFILE,
1927                       crateID,
1928                       dmbID,
1929                       nLayer,
1930                       mo_CFEB_Active_Samples_vs_Strip_Profile);
1931           MonitorObject* mo_CFEB_ActiveStrips = nullptr;
1932           getCSCHisto(h::CSC_CFEB_ACTIVESTRIPS_LYXX, crateID, dmbID, nLayer, mo_CFEB_ActiveStrips);
1933           MonitorObject* mo_CFEB_SCA_Cell_Peak = nullptr;
1934           getCSCHisto(h::CSC_CFEB_SCA_CELL_PEAK_LY_XX, crateID, dmbID, nLayer, mo_CFEB_SCA_Cell_Peak);
1935 
1936           MonitorObject* mo_CFEB_Pedestal_withEMV_Sample = nullptr;
1937           getCSCHisto(
1938               h::CSC_CFEB_PEDESTAL_WITHEMV_SAMPLE_01_LYXX, crateID, dmbID, nLayer, mo_CFEB_Pedestal_withEMV_Sample);
1939           MonitorObject* mo_CFEB_Pedestal_withRMS_Sample = nullptr;
1940           getCSCHisto(
1941               h::CSC_CFEB_PEDESTAL_WITHRMS_SAMPLE_01_LYXX, crateID, dmbID, nLayer, mo_CFEB_Pedestal_withRMS_Sample);
1942           MonitorObject* mo_CFEB_PedestalRMS_Sample = nullptr;
1943           getCSCHisto(h::CSC_CFEB_PEDESTALRMS_SAMPLE_01_LYXX, crateID, dmbID, nLayer, mo_CFEB_PedestalRMS_Sample);
1944 
1945           for (int nSample = 0; nSample < NmbTimeSamples; ++nSample) {
1946             if (timeSlice(data, nCFEB, nSample) == nullptr) {
1947               LOG_WARN << "CFEB" << nCFEB << " nSample: " << nSample << " - B-Word";
1948               continue;
1949             }
1950 
1951             if (mo_CFEB_DMB_L1A_diff && !fCloseL1As) {
1952               int cfeb_dmb_l1a_diff =
1953                   (int)((timeSlice(data, nCFEB, nSample)->get_L1A_number()) - dmbHeader->l1a24() % 64);
1954               if (cfeb_dmb_l1a_diff != 0) {
1955                 L1A_out_of_sync = true;
1956               }
1957               if (cfeb_dmb_l1a_diff < -32)
1958                 mo->Fill(cfeb_dmb_l1a_diff + 64);
1959               else {
1960                 if (cfeb_dmb_l1a_diff >= 32)
1961                   mo->Fill(cfeb_dmb_l1a_diff - 64);
1962                 else
1963                   mo_CFEB_DMB_L1A_diff->Fill(cfeb_dmb_l1a_diff);
1964               }
1965               mo_CFEB_DMB_L1A_diff->SetAxisRange(
1966                   0.1, 1.1 * (1.0 + mo_CFEB_DMB_L1A_diff->GetBinContent(mo_CFEB_DMB_L1A_diff->GetMaximumBin())), "Y");
1967             }
1968 
1969             /** --------------B */
1970             FreeCells = timeSlice(data, nCFEB, nSample)->get_n_free_sca_blocks();
1971             LCT_Pipe_Empty = timeSlice(data, nCFEB, nSample)->get_lctpipe_empty();
1972             LCT_Pipe_Full = timeSlice(data, nCFEB, nSample)->get_lctpipe_full();
1973             LCT_Pipe_Count = timeSlice(data, nCFEB, nSample)->get_lctpipe_count();
1974             L1_Pipe_Empty = timeSlice(data, nCFEB, nSample)->get_l1pipe_empty();
1975             L1_Pipe_Full = timeSlice(data, nCFEB, nSample)->get_l1pipe_full();
1976             Buffer_Count = timeSlice(data, nCFEB, nSample)->get_buffer_count();
1977 
1978             SCA_BLK = (int)(timeSlice(data, nCFEB, nSample)->scaControllerWord(nLayer).sca_blk);
1979 
1980             for (int nStrip = 0; nStrip < N_Strips; ++nStrip) {
1981               SCABlockData[nCFEB * 16 + nStrip][nSample][nLayer - 1] = SCA_BLK;
1982             }
1983 
1984             /**  SCA Block Occupancy Histograms */
1985             if (mo_CFEB_SCA_Block_Occupancy)
1986               mo_CFEB_SCA_Block_Occupancy->Fill(SCA_BLK);
1987 
1988             /**  Free SCA Cells */
1989             if (mo_CFEB_Free_SCA_Cells) {
1990               if (timeSlice(data, nCFEB, nSample)->scaControllerWord(nLayer).sca_full == 1)
1991                 mo_CFEB_Free_SCA_Cells->Fill(-1);
1992               mo_CFEB_Free_SCA_Cells->Fill(FreeCells);
1993             }
1994 
1995             /**  Number of SCA Blocks Locked by LCTs */
1996             if (mo_CFEB_SCA_Blocks_Locked_by_LCTs) {
1997               if (LCT_Pipe_Empty == 1)
1998                 mo_CFEB_SCA_Blocks_Locked_by_LCTs->Fill(-0.5);
1999               if (LCT_Pipe_Full == 1)
2000                 mo_CFEB_SCA_Blocks_Locked_by_LCTs->Fill(16.5);
2001               mo_CFEB_SCA_Blocks_Locked_by_LCTs->Fill(LCT_Pipe_Count);
2002             }
2003 
2004             /**  Number of SCA Blocks Locked by LCTxL1 */
2005             if (mo_CFEB_SCA_Blocks_Locked_by_LCTxL1) {
2006               if (L1_Pipe_Empty == 1)
2007                 mo_CFEB_SCA_Blocks_Locked_by_LCTxL1->Fill(-0.5);
2008               if (L1_Pipe_Full == 1)
2009                 mo_CFEB_SCA_Blocks_Locked_by_LCTxL1->Fill(31.5);
2010               mo_CFEB_SCA_Blocks_Locked_by_LCTxL1->Fill(Buffer_Count);
2011             }
2012 
2013             /** --------------E */
2014             if (nSample == 0 && nLayer == 1) {
2015               TrigTime = (int)(timeSlice(data, nCFEB, nSample)->scaControllerWord(nLayer).trig_time);
2016               int k = 1;
2017               while (((TrigTime >> (k - 1)) & 0x1) != 1 && k <= 8) {
2018                 k = k + 1;
2019               }
2020               L1APhase = (int)((timeSlice(data, nCFEB, nSample)->scaControllerWord(nLayer).l1a_phase) & 0x1);
2021               UnpackedTrigTime = ((k << 1) & 0xE) + L1APhase;
2022 
2023               if (getCSCHisto(h::CSC_CFEBXX_L1A_SYNC_TIME, crateID, dmbID, nCFEB + 1, mo))
2024                 mo->Fill((int)UnpackedTrigTime);
2025               LCTPhase = (int)((timeSlice(data, nCFEB, nSample)->scaControllerWord(nLayer).lct_phase) & 0x1);
2026 
2027               if (getCSCHisto(h::CSC_CFEBXX_LCT_PHASE_VS_L1A_PHASE, crateID, dmbID, nCFEB + 1, mo))
2028                 mo->Fill(LCTPhase, L1APhase);
2029 
2030               if (getCSCHisto(h::CSC_CFEBXX_L1A_SYNC_TIME_VS_DMB, crateID, dmbID, nCFEB + 1, mo))
2031                 mo->Fill((int)(dmbHeader->dmbCfebSync()), (int)UnpackedTrigTime);
2032 
2033               if (getCSCHisto(h::CSC_CFEBXX_L1A_SYNC_TIME_DMB_DIFF, crateID, dmbID, nCFEB + 1, mo)) {
2034                 int cfeb_dmb_L1A_sync_time = (int)(dmbHeader->dmbCfebSync()) - (int)UnpackedTrigTime;
2035                 if (cfeb_dmb_L1A_sync_time < -8)
2036                   mo->Fill(cfeb_dmb_L1A_sync_time + 16);
2037                 else {
2038                   if (cfeb_dmb_L1A_sync_time >= 8)
2039                     mo->Fill(cfeb_dmb_L1A_sync_time - 16);
2040                   else
2041                     mo->Fill(cfeb_dmb_L1A_sync_time);
2042                 }
2043                 mo->SetAxisRange(0.1, 1.1 * (1.0 + mo->GetBinContent(mo->GetMaximumBin())), "Y");
2044               }
2045             }
2046 
2047             for (int nStrip = 1; nStrip <= N_Strips; ++nStrip) {
2048               ADC = (int)((timeSample(data, nCFEB, nSample, nLayer, nStrip)->adcCounts) & 0xFFF);
2049               OutOffRange = (int)((timeSample(data, nCFEB, nSample, nLayer, nStrip)->adcOverflow) & 0x1);
2050 
2051               if (nSample == 0) {  // nSample == 0
2052                 CellPeak[nCFEB][nLayer - 1][nStrip - 1] = std::make_pair(nSample, ADC);
2053                 Pedestal[nCFEB][nLayer - 1][nStrip - 1] = ADC;
2054               }
2055 
2056               if (OutOffRange == 1 && CheckOutOffRangeStripInTheLayer[nLayer - 1][nCFEB * 16 + nStrip - 1] == true) {
2057                 if (mo_CFEB_Out_Off_Range_Strips)
2058                   mo_CFEB_Out_Off_Range_Strips->Fill((int)(nCFEB * 16 + nStrip - 1));
2059                 CheckOutOffRangeStripInTheLayer[nLayer - 1][nCFEB * 16 + nStrip - 1] = false;
2060               }
2061               if (ADC - Pedestal[nCFEB][nLayer - 1][nStrip - 1] > Threshold && OutOffRange != 1) {
2062                 if (mo_CFEB_Active_Samples_vs_Strip)
2063                   mo_CFEB_Active_Samples_vs_Strip->Fill((int)(nCFEB * 16 + nStrip - 1), nSample);
2064 
2065                 if (mo_CFEB_Active_Samples_vs_Strip_Profile)
2066                   mo_CFEB_Active_Samples_vs_Strip_Profile->Fill((int)(nCFEB * 16 + nStrip - 1), nSample);
2067 
2068                 if (CheckThresholdStripInTheLayer[nLayer - 1][nCFEB * 16 + nStrip - 1] == true) {
2069                   if (mo_CFEB_ActiveStrips)
2070                     mo_CFEB_ActiveStrips->Fill((int)(nCFEB * 16 + nStrip));
2071                   CheckThresholdStripInTheLayer[nLayer - 1][nCFEB * 16 + nStrip - 1] = false;
2072                 }
2073                 /** --------------B */
2074                 if (ADC - Pedestal[nCFEB][nLayer - 1][nStrip - 1] > Threshold) {
2075                   cscdata[nCFEB * 16 + nStrip - 1][nSample][nLayer - 1] = ADC - Pedestal[nCFEB][nLayer - 1][nStrip - 1];
2076                 }
2077                 /** --------------E */
2078                 if (ADC > CellPeak[nCFEB][nLayer - 1][nStrip - 1].second) {
2079                   CellPeak[nCFEB][nLayer - 1][nStrip - 1].first = nSample;
2080                   CellPeak[nCFEB][nLayer - 1][nStrip - 1].second = ADC;
2081                 }
2082               }
2083               /**  continue; */
2084               /** --------------B */
2085               if (nSample == 1) {
2086                 int channel_threshold = 40;
2087                 if (std::abs(ADC - Pedestal[nCFEB][nLayer - 1][nStrip - 1]) < channel_threshold) {
2088                   if (mo_CFEB_Pedestal_withEMV_Sample)
2089                     mo_CFEB_Pedestal_withEMV_Sample->Fill((int)(nCFEB * 16 + nStrip - 1),
2090                                                           Pedestal[nCFEB][nLayer - 1][nStrip - 1]);
2091 
2092                   if (mo_CFEB_Pedestal_withRMS_Sample) {
2093                     mo_CFEB_Pedestal_withRMS_Sample->Fill((int)(nCFEB * 16 + nStrip - 1),
2094                                                           Pedestal[nCFEB][nLayer - 1][nStrip - 1]);
2095 
2096                     if (mo_CFEB_PedestalRMS_Sample) {
2097                       mo_CFEB_PedestalRMS_Sample->SetBinContent(
2098                           nCFEB * 16 + nStrip - 1, mo_CFEB_Pedestal_withRMS_Sample->GetBinError(nCFEB * 16 + nStrip));
2099                       mo_CFEB_PedestalRMS_Sample->SetBinError(nCFEB * 16 + nStrip - 1, 0.00000000001);
2100                     }
2101                   }
2102                 }
2103                 Pedestal[nCFEB][nLayer - 1][nStrip - 1] += ADC;
2104                 Pedestal[nCFEB][nLayer - 1][nStrip - 1] /= 2;
2105               }
2106               /** --------------E */
2107             }
2108           }
2109 
2110           for (int nStrip = 1; nStrip <= N_Strips; ++nStrip) {
2111             if (mo_CFEB_SCA_Cell_Peak && CellPeak[nCFEB][nLayer - 1][nStrip - 1].first) {
2112               mo_CFEB_SCA_Cell_Peak->Fill((int)(nCFEB * 16 + nStrip - 1),
2113                                           CellPeak[nCFEB][nLayer - 1][nStrip - 1].first);
2114               if (mo_CFEB_SCA_CellPeak_Time) {
2115                 mo_CFEB_SCA_CellPeak_Time->Fill(CellPeak[nCFEB][nLayer - 1][nStrip - 1].first);
2116               }
2117 
2118               if (mo_EventDisplay) {
2119                 int peak_sample = CellPeak[nCFEB][nLayer - 1][nStrip - 1].first;
2120                 int peak_adc = CellPeak[nCFEB][nLayer - 1][nStrip - 1].second;
2121                 int pedestal = Pedestal[nCFEB][nLayer - 1][nStrip - 1];
2122                 int peak_sca_charge = peak_adc - pedestal;
2123 
2124                 if (peak_adc - pedestal > Threshold) {
2125                   if (peak_sample >= 1) {
2126                     peak_sca_charge +=
2127                         ((timeSample(data, nCFEB, peak_sample - 1, nLayer, nStrip)->adcCounts) & 0xFFF) - pedestal;
2128                   }
2129                   if (peak_sample < NmbTimeSamples - 1) {
2130                     peak_sca_charge +=
2131                         ((timeSample(data, nCFEB, peak_sample + 1, nLayer, nStrip)->adcCounts) & 0xFFF) - pedestal;
2132                   }
2133                   mo_EventDisplay->SetBinContent(nLayer + 17, nCFEB * 16 + nStrip - 1, peak_sca_charge);
2134                   setEmuEventDisplayBit(
2135                       mo_Emu_EventDisplay_Cathode, glChamberIndex, nCFEB * 16 + nStrip - 1, nLayer - 1);
2136                 }
2137               }
2138 
2139               if (cid.endcap() == 1) {
2140                 if (mo_CSC_Plus_endcap_CFEB_SCA_CellPeak_Time)
2141                   mo_CSC_Plus_endcap_CFEB_SCA_CellPeak_Time->Fill(CellPeak[nCFEB][nLayer - 1][nStrip - 1].first);
2142               }
2143               if (cid.endcap() == 2) {
2144                 if (mo_CSC_Minus_endcap_CFEB_SCA_CellPeak_Time)
2145                   mo_CSC_Minus_endcap_CFEB_SCA_CellPeak_Time->Fill(CellPeak[nCFEB][nLayer - 1][nStrip - 1].first);
2146               }
2147             }
2148           }
2149         }
2150       }
2151     }
2152 
2153     // Fill Summary CFEB Raw Hits Timing Plots
2154     if (mo_CFEB_SCA_CellPeak_Time) {
2155       double cellpeak_time_mean = mo_CFEB_SCA_CellPeak_Time->getTH1()->GetMean();
2156       double cellpeak_time_rms = mo_CFEB_SCA_CellPeak_Time->getTH1()->GetRMS();
2157       if (cscPosition && mo_CSC_CFEB_SCA_CellPeak_Time_mean) {
2158         mo_CSC_CFEB_SCA_CellPeak_Time_mean->SetBinContent(cscPosition, cscType + 1, cellpeak_time_mean);
2159       }
2160       if (cscPosition && mo_CSC_CFEB_SCA_CellPeak_Time_rms) {
2161         mo_CSC_CFEB_SCA_CellPeak_Time_rms->SetBinContent(cscPosition, cscType + 1, cellpeak_time_rms);
2162       }
2163     }
2164 
2165     /** --------------B */
2166     /**  Refactored for performance (VR) */
2167     const int a = N_CFEBs * N_Strips;
2168     const int b = a * N_Samples;
2169     float Cathodes[b * N_Layers];
2170     for (int i = 0; i < N_Layers; ++i) {
2171       const int b1 = i * b;
2172       for (int j = 0; j < a; ++j) {
2173         const int b2 = b1 + j;
2174         for (int k = 0; k < N_Samples; ++k) {
2175           Cathodes[b2 + a * k] = cscdata[j][k][i];
2176         }
2177       }
2178     }
2179 
2180     std::vector<StripCluster> Clus;
2181     Clus.clear();
2182     StripClusterFinder ClusterFinder(N_Layers, N_Samples, N_CFEBs, N_Strips);
2183 
2184     for (int nLayer = 1; nLayer <= N_Layers; ++nLayer) {
2185       ClusterFinder.DoAction(nLayer - 1, Cathodes);
2186       Clus = ClusterFinder.getClusters();
2187 
2188       /**  Number of Clusters Histograms */
2189       if (getCSCHisto(h::CSC_CFEB_NUMBER_OF_CLUSTERS_LY_XX, crateID, dmbID, nLayer, mo)) {
2190         mo->Fill(Clus.size());
2191       }
2192 
2193       for (uint32_t u = 0; u < Clus.size(); u++) {
2194         Clus_Sum_Charge = 0.0;
2195         for (uint32_t k = 0; k < Clus[u].ClusterPulseMapHeight.size(); k++) {
2196           for (int n = Clus[u].LFTBNDTime; n < Clus[u].IRTBNDTime; n++) {
2197             Clus_Sum_Charge = Clus_Sum_Charge + Clus[u].ClusterPulseMapHeight[k].height_[n];
2198           }
2199         }
2200 
2201         /**  Clusters Charge Histograms */
2202         if (getCSCHisto(h::CSC_CFEB_CLUSTERS_CHARGE_LY_XX, crateID, dmbID, nLayer, mo)) {
2203           mo->Fill(Clus_Sum_Charge);
2204         }
2205 
2206         /**  Width of Clusters Histograms */
2207         if (getCSCHisto(h::CSC_CFEB_WIDTH_OF_CLUSTERS_LY_XX, crateID, dmbID, nLayer, mo)) {
2208           mo->Fill(Clus[u].IRTBNDStrip - Clus[u].LFTBNDStrip + 1);
2209         }
2210 
2211         /**  Cluster Duration Histograms */
2212         if (getCSCHisto(h::CSC_CFEB_CLUSTER_DURATION_LY_XX, crateID, dmbID, nLayer, mo)) {
2213           mo->Fill(Clus[u].IRTBNDTime - Clus[u].LFTBNDTime + 1);
2214         }
2215       }
2216 
2217       Clus.clear();
2218 
2219       /**  delete ClusterFinder; */
2220     }
2221 
2222     /** --------------E */
2223 
2224     /**  Fill Hisogram for Different Combinations of FEBs Unpacked vs DAV */
2225     if (getCSCHisto(h::CSC_DMB_FEB_COMBINATIONS_UNPACKED_VS_DAV, crateID, dmbID, mo)) {
2226       float feb_combination_unpacked = -1.0;
2227       if (alct_unpacked == 0 && tmb_unpacked == 0 && cfeb_unpacked == 0)
2228         feb_combination_unpacked = 0.0;
2229       if (alct_unpacked > 0 && tmb_unpacked == 0 && cfeb_unpacked == 0)
2230         feb_combination_unpacked = 1.0;
2231       if (alct_unpacked == 0 && tmb_unpacked > 0 && cfeb_unpacked == 0)
2232         feb_combination_unpacked = 2.0;
2233       if (alct_unpacked == 0 && tmb_unpacked == 0 && cfeb_unpacked > 0)
2234         feb_combination_unpacked = 3.0;
2235       if (alct_unpacked > 0 && tmb_unpacked > 0 && cfeb_unpacked == 0)
2236         feb_combination_unpacked = 4.0;
2237       if (alct_unpacked > 0 && tmb_unpacked == 0 && cfeb_unpacked > 0)
2238         feb_combination_unpacked = 5.0;
2239       if (alct_unpacked == 0 && tmb_unpacked > 0 && cfeb_unpacked > 0)
2240         feb_combination_unpacked = 6.0;
2241       if (alct_unpacked > 0 && tmb_unpacked > 0 && cfeb_unpacked > 0)
2242         feb_combination_unpacked = 7.0;
2243       mo->Fill(feb_combination_dav, feb_combination_unpacked);
2244     }
2245 
2246     if ((clct_kewdistrip > -1 && alct_keywg > -1) &&
2247         (getCSCHisto(h::CSC_CLCT0_KEYDISTRIP_VS_ALCT0_KEYWIREGROUP, crateID, dmbID, mo))) {
2248       mo->Fill(alct_keywg, clct_kewdistrip);
2249     }
2250 
2251     if (L1A_out_of_sync && cscPosition && getEMUHisto(h::EMU_CSC_L1A_OUT_OF_SYNC, mo)) {
2252       mo->Fill(cscPosition, cscType);
2253     }
2254 
2255     if (L1A_out_of_sync && getEMUHisto(h::EMU_DMB_L1A_OUT_OF_SYNC, mo)) {
2256       mo->Fill(crateID, dmbID);
2257     }
2258   }
2259 
2260 }  // namespace cscdqm