Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-25 03:29:26

0001 /**
0002  * \class L1TGT
0003  *
0004  *
0005  * Description: DQM for L1 Global Trigger.
0006  *
0007  * \author J. Berryhill, I. Mikulec
0008  * \author Vasile Mihai Ghete - HEPHY Vienna
0009  *
0010  *
0011  */
0012 
0013 #include "DQM/L1TMonitor/interface/L1TGT.h"
0014 
0015 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
0016 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutCollection.h"
0017 
0018 L1TGT::L1TGT(const edm::ParameterSet& ps)
0019     : gtSource_L1GT_(consumes<L1GlobalTriggerReadoutRecord>(ps.getParameter<edm::InputTag>("gtSource"))),
0020       gtSource_L1MuGMT_(consumes<L1MuGMTReadoutCollection>(ps.getParameter<edm::InputTag>("gtSource"))),
0021       gtEvmSource_(consumes<L1GlobalTriggerEvmReadoutRecord>(ps.getParameter<edm::InputTag>("gtEvmSource"))),
0022       m_runInEventLoop(ps.getUntrackedParameter<bool>("runInEventLoop", false)),
0023       m_runInEndLumi(ps.getUntrackedParameter<bool>("runInEndLumi", false)),
0024       verbose_(ps.getUntrackedParameter<bool>("verbose", false)),
0025       m_nrEvJob(0),
0026       m_nrEvRun(0),
0027       preGps_(0ULL),
0028       preOrb_(0ULL) {
0029   m_histFolder = ps.getUntrackedParameter<std::string>("HistFolder", "L1T/L1TGT");
0030   l1gtTrigmenuToken_ = esConsumes<edm::Transition::BeginRun>();
0031 }
0032 
0033 L1TGT::~L1TGT() {
0034   // empty
0035 }
0036 
0037 void L1TGT::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const&, edm::EventSetup const& evSetup) {
0038   ibooker.setCurrentFolder(m_histFolder);
0039 
0040   // book histograms
0041   const int TotalNrBinsLs = 1000;
0042   const double totalNrBinsLs = static_cast<double>(TotalNrBinsLs);
0043 
0044   ibooker.setCurrentFolder(m_histFolder);
0045 
0046   algo_bits = ibooker.book1D("algo_bits", "GT algorithm trigger bits", 128, -0.5, 127.5);
0047   algo_bits->setAxisTitle("Algorithm trigger bits", 1);
0048 
0049   algo_bits_corr =
0050       ibooker.book2D("algo_bits_corr", "GT algorithm trigger bit correlation", 128, -0.5, 127.5, 128, -0.5, 127.5);
0051   algo_bits_corr->setAxisTitle("Algorithm trigger bits", 1);
0052   algo_bits_corr->setAxisTitle("Algorithm trigger bits", 2);
0053 
0054   tt_bits = ibooker.book1D("tt_bits", "GT technical trigger bits", 64, -0.5, 63.5);
0055   tt_bits->setAxisTitle("Technical trigger bits", 1);
0056 
0057   tt_bits_corr = ibooker.book2D("tt_bits_corr", "GT technical trigger bit correlation", 64, -0.5, 63.5, 64, -0.5, 63.5);
0058   tt_bits_corr->setAxisTitle("Technical trigger bits", 1);
0059   tt_bits_corr->setAxisTitle("Technical trigger bits", 2);
0060 
0061   algo_tt_bits_corr = ibooker.book2D(
0062       "algo_tt_bits_corr", "GT algorithm - technical trigger bit correlation", 128, -0.5, 127.5, 64, -0.5, 63.5);
0063   algo_tt_bits_corr->setAxisTitle("Algorithm trigger bits", 1);
0064   algo_tt_bits_corr->setAxisTitle("Technical trigger bits", 2);
0065 
0066   algo_bits_lumi = ibooker.book2D(
0067       "algo_bits_lumi", "GT algorithm trigger bit rate per LS", TotalNrBinsLs, 0., totalNrBinsLs, 128, -0.5, 127.5);
0068   algo_bits_lumi->setAxisTitle("Luminosity segment", 1);
0069   algo_bits_lumi->setAxisTitle("Algorithm trigger bits", 2);
0070 
0071   tt_bits_lumi = ibooker.book2D(
0072       "tt_bits_lumi", "GT technical trigger bit rate per LS", TotalNrBinsLs, 0., totalNrBinsLs, 64, -0.5, 63.5);
0073   tt_bits_lumi->setAxisTitle("Luminosity segment", 1);
0074   tt_bits_lumi->setAxisTitle("Technical trigger bits", 2);
0075 
0076   event_type = ibooker.book1D("event_type", "GT event type", 10, -0.5, 9.5);
0077   event_type->setAxisTitle("Event type", 1);
0078   event_type->setBinLabel(2, "Physics", 1);
0079   event_type->setBinLabel(3, "Calibration", 1);
0080   event_type->setBinLabel(4, "Random", 1);
0081   event_type->setBinLabel(6, "Traced", 1);
0082   event_type->setBinLabel(7, "Test", 1);
0083   event_type->setBinLabel(8, "Error", 1);
0084 
0085   event_number = ibooker.book1D("event_number", "GT event number (from last resync)", 100, 0., 50000.);
0086   event_number->setAxisTitle("Event number", 1);
0087 
0088   event_lumi = ibooker.bookProfile(
0089       "event_lumi", "GT event number (from last resync) vs LS", TotalNrBinsLs, 0., totalNrBinsLs, 100, -0.1, 1.e15, "s");
0090   event_lumi->setAxisTitle("Luminosity segment", 1);
0091   event_lumi->setAxisTitle("Event number", 2);
0092 
0093   trigger_number = ibooker.book1D("trigger_number", "GT trigger number (from start run)", 100, 0., 50000.);
0094   trigger_number->setAxisTitle("Trigger number", 1);
0095 
0096   trigger_lumi = ibooker.bookProfile("trigger_lumi",
0097                                      "GT trigger number (from start run) vs LS",
0098                                      TotalNrBinsLs,
0099                                      0.,
0100                                      totalNrBinsLs,
0101                                      100,
0102                                      -0.1,
0103                                      1.e15,
0104                                      "s");
0105   trigger_lumi->setAxisTitle("Luminosity segment", 1);
0106   trigger_lumi->setAxisTitle("Trigger number", 2);
0107 
0108   evnum_trignum_lumi = ibooker.bookProfile(
0109       "evnum_trignum_lumi", "GT event/trigger number ratio vs LS", TotalNrBinsLs, 0., totalNrBinsLs, 100, -0.1, 2., "s");
0110   evnum_trignum_lumi->setAxisTitle("Luminosity segment", 1);
0111   evnum_trignum_lumi->setAxisTitle("Event/trigger number ratio", 2);
0112 
0113   orbit_lumi = ibooker.bookProfile(
0114       "orbit_lumi", "GT orbit number vs LS", TotalNrBinsLs, 0., totalNrBinsLs, 100, -0.1, 1.e15, "s");
0115   orbit_lumi->setAxisTitle("Luminosity segment", 1);
0116   orbit_lumi->setAxisTitle("Orbit number", 2);
0117 
0118   setupversion_lumi = ibooker.bookProfile(
0119       "setupversion_lumi", "GT setup version vs LS", TotalNrBinsLs, 0., totalNrBinsLs, 100, -0.1, 1.e10, "i");
0120   setupversion_lumi->setAxisTitle("Luminosity segment", 1);
0121   setupversion_lumi->setAxisTitle("Setup version", 2);
0122 
0123   gtfe_bx = ibooker.book1D("gtfe_bx", "GTFE Bx number", 3600, 0., 3600.);
0124   gtfe_bx->setAxisTitle("GTFE BX number", 1);
0125 
0126   dbx_module =
0127       ibooker.bookProfile("dbx_module", "delta Bx of GT modules wrt GTFE", 20, 0., 20., 100, -4000., 4000., "i");
0128   dbx_module->setAxisTitle("GT crate module", 1);
0129   dbx_module->setAxisTitle("Module Bx - GTFE Bx", 2);
0130   dbx_module->setBinLabel(1, "GTFEevm", 1);
0131   dbx_module->setBinLabel(2, "TCS", 1);
0132   dbx_module->setBinLabel(3, "FDL", 1);
0133   dbx_module->setBinLabel(4, "FDLloc", 1);
0134   dbx_module->setBinLabel(5, "PSB9", 1);
0135   dbx_module->setBinLabel(6, "PSB9loc", 1);
0136   dbx_module->setBinLabel(7, "PSB13", 1);
0137   dbx_module->setBinLabel(8, "PSB13loc", 1);
0138   dbx_module->setBinLabel(9, "PSB14", 1);
0139   dbx_module->setBinLabel(10, "PSB14loc", 1);
0140   dbx_module->setBinLabel(11, "PSB15", 1);
0141   dbx_module->setBinLabel(12, "PSB15loc", 1);
0142   dbx_module->setBinLabel(13, "PSB19", 1);
0143   dbx_module->setBinLabel(14, "PSB19loc", 1);
0144   dbx_module->setBinLabel(15, "PSB20", 1);
0145   dbx_module->setBinLabel(16, "PSB20loc", 1);
0146   dbx_module->setBinLabel(17, "PSB21", 1);
0147   dbx_module->setBinLabel(18, "PSB21loc", 1);
0148   dbx_module->setBinLabel(19, "GMT", 1);
0149 
0150   BST_MasterStatus =
0151       ibooker.book2D("BST_MasterStatus", "BST master status over LS", TotalNrBinsLs, 0., totalNrBinsLs, 6, -1., 5.);
0152   BST_MasterStatus->setAxisTitle("Luminosity segment", 1);
0153   BST_MasterStatus->setAxisTitle("BST master status", 2);
0154   BST_MasterStatus->setBinLabel(2, "Master Beam 1", 2);
0155   BST_MasterStatus->setBinLabel(3, "Master Beam 2", 2);
0156 
0157   BST_turnCountNumber =
0158       ibooker.book2D("BST_turnCountNumber", "BST turn count over LS", TotalNrBinsLs, 0., totalNrBinsLs, 250, 0., 4.3e9);
0159   BST_turnCountNumber->setAxisTitle("Luminosity segment", 1);
0160   BST_turnCountNumber->setAxisTitle("BST turn count number", 2);
0161 
0162   BST_lhcFillNumber = ibooker.book1D("BST_lhcFillNumber", "BST LHC fill number % 1000", 1000, 0., 1000.);
0163   BST_lhcFillNumber->setAxisTitle("BST LHC fill number modulo 1000");
0164 
0165   BST_beamMode = ibooker.book2D("BST_beamMode", "BST beam mode over LS", TotalNrBinsLs, 0., totalNrBinsLs, 25, 1., 26.);
0166   BST_beamMode->setAxisTitle("Luminosity segment", 1);
0167   BST_beamMode->setAxisTitle("Mode", 2);
0168   BST_beamMode->setBinLabel(1, "No mode", 2);
0169   BST_beamMode->setBinLabel(2, "Setup", 2);
0170   BST_beamMode->setBinLabel(3, "Inj pilot", 2);
0171   BST_beamMode->setBinLabel(4, "Inj intr", 2);
0172   BST_beamMode->setBinLabel(5, "Inj nomn", 2);
0173   BST_beamMode->setBinLabel(6, "Pre ramp", 2);
0174   BST_beamMode->setBinLabel(7, "Ramp", 2);
0175   BST_beamMode->setBinLabel(8, "Flat top", 2);
0176   BST_beamMode->setBinLabel(9, "Squeeze", 2);
0177   BST_beamMode->setBinLabel(10, "Adjust", 2);
0178   BST_beamMode->setBinLabel(11, "Stable", 2);
0179   BST_beamMode->setBinLabel(12, "Unstable", 2);
0180   BST_beamMode->setBinLabel(13, "Beam dump", 2);
0181   BST_beamMode->setBinLabel(14, "Ramp down", 2);
0182   BST_beamMode->setBinLabel(15, "Recovery", 2);
0183   BST_beamMode->setBinLabel(16, "Inj dump", 2);
0184   BST_beamMode->setBinLabel(17, "Circ dump", 2);
0185   BST_beamMode->setBinLabel(18, "Abort", 2);
0186   BST_beamMode->setBinLabel(19, "Cycling", 2);
0187   BST_beamMode->setBinLabel(20, "Warn beam dump", 2);
0188   BST_beamMode->setBinLabel(21, "No beam", 2);
0189 
0190   BST_beamMomentum =
0191       ibooker.book2D("BST_beamMomentum", "BST beam momentum", TotalNrBinsLs, 0., totalNrBinsLs, 100, 0., 7200.);
0192   BST_beamMomentum->setAxisTitle("Luminosity segment", 1);
0193   BST_beamMomentum->setAxisTitle("Beam momentum", 2);
0194 
0195   gpsfreq = ibooker.book1D("gpsfreq", "Clock frequency measured by GPS", 1000, 39.95, 40.2);
0196   gpsfreq->setAxisTitle("CMS clock frequency (MHz)");
0197 
0198   gpsfreqwide = ibooker.book1D("gpsfreqwide", "Clock frequency measured by GPS", 1000, -2., 200.);
0199   gpsfreqwide->setAxisTitle("CMS clock frequency (MHz)");
0200 
0201   gpsfreqlum = ibooker.book2D(
0202       "gpsfreqlum", "Clock frequency measured by GPS", TotalNrBinsLs, 0., totalNrBinsLs, 100, 39.95, 40.2);
0203   gpsfreqlum->setAxisTitle("Luminosity segment", 1);
0204   gpsfreqlum->setAxisTitle("CMS clock frequency (MHz)", 2);
0205 
0206   BST_intensityBeam1 =
0207       ibooker.book2D("BST_intensityBeam1", "Intensity beam 1", TotalNrBinsLs, 0., totalNrBinsLs, 1000, 0., 5000.);
0208   BST_intensityBeam1->setAxisTitle("Luminosity segment", 1);
0209   BST_intensityBeam1->setAxisTitle("Beam intensity", 2);
0210 
0211   BST_intensityBeam2 =
0212       ibooker.book2D("BST_intensityBeam2", "Intensity beam 2", TotalNrBinsLs, 0., totalNrBinsLs, 1000, 0., 5000.);
0213   BST_intensityBeam2->setAxisTitle("Luminosity segment", 1);
0214   BST_intensityBeam2->setAxisTitle("Beam intensity", 2);
0215 
0216   // prescale factor index monitoring
0217 
0218   m_monL1PrescaleFactorSet = ibooker.book2D(
0219       "L1PrescaleFactorSet", "Index of L1 prescale factor set", TotalNrBinsLs, 0., totalNrBinsLs, 25, 0., 25.);
0220   m_monL1PrescaleFactorSet->setAxisTitle("Luminosity segment", 1);
0221   m_monL1PrescaleFactorSet->setAxisTitle("L1 PF set index", 2);
0222   m_monL1PfIndicesPerLs =
0223       ibooker.book1D("L1PfIndicesPerLs", "Number of prescale factor indices used per LS", 10, 0., 10.);
0224   m_monL1PfIndicesPerLs->setAxisTitle("Number of PF indices used per LS", 1);
0225   m_monL1PfIndicesPerLs->setAxisTitle("Entries", 2);
0226 
0227   // TCS vs FDL common quantity monitoring
0228 
0229   ibooker.setCurrentFolder(m_histFolder + "/TCSvsEvmFDL");
0230 
0231   //    orbit number
0232   m_monOrbitNrDiffTcsFdlEvm = ibooker.book1D("OrbitNrDiffTcsFdlEvm",
0233                                              "Orbit number difference (TCS - EVM_FDL)",
0234                                              2 * MaxOrbitNrDiffTcsFdlEvm + 1,
0235                                              static_cast<float>(-(MaxOrbitNrDiffTcsFdlEvm + 1)),
0236                                              static_cast<float>(MaxOrbitNrDiffTcsFdlEvm + 1));
0237   m_monOrbitNrDiffTcsFdlEvm->setAxisTitle("Orbit number difference", 1);
0238   m_monOrbitNrDiffTcsFdlEvm->setAxisTitle("Entries/run", 2);
0239   m_monLsNrDiffTcsFdlEvm = ibooker.book1D("LsNrDiffTcsFdlEvm",
0240                                           "LS number difference (TCS - EVM_FDL)",
0241                                           2 * MaxLsNrDiffTcsFdlEvm + 1,
0242                                           static_cast<float>(-(MaxLsNrDiffTcsFdlEvm + 1)),
0243                                           static_cast<float>(MaxLsNrDiffTcsFdlEvm + 1));
0244   m_monLsNrDiffTcsFdlEvm->setAxisTitle("LS number difference", 1);
0245   m_monLsNrDiffTcsFdlEvm->setAxisTitle("Entries/run", 2);
0246 
0247   //    LS number
0248   m_monOrbitNrDiffTcsFdlEvmLs = ibooker.book2D("OrbitNrDiffTcsFdlEvmLs",
0249                                                "Orbit number difference (TCS - EVM_FDL)",
0250                                                TotalNrBinsLs,
0251                                                0.,
0252                                                totalNrBinsLs,
0253                                                2 * MaxOrbitNrDiffTcsFdlEvm + 1,
0254                                                static_cast<float>(-(MaxOrbitNrDiffTcsFdlEvm + 1)),
0255                                                static_cast<float>(MaxOrbitNrDiffTcsFdlEvm + 1));
0256   m_monOrbitNrDiffTcsFdlEvmLs->setAxisTitle("Luminosity segment", 1);
0257   m_monOrbitNrDiffTcsFdlEvmLs->setAxisTitle("Orbit number difference (TCS - EVM_FDL)", 2);
0258 
0259   m_monLsNrDiffTcsFdlEvmLs = ibooker.book2D("LsNrDiffTcsFdlEvmLs",
0260                                             "LS number difference (TCS - EVM_FDL)",
0261                                             TotalNrBinsLs,
0262                                             0.,
0263                                             totalNrBinsLs,
0264                                             2 * MaxLsNrDiffTcsFdlEvm + 1,
0265                                             static_cast<float>(-(MaxLsNrDiffTcsFdlEvm + 1)),
0266                                             static_cast<float>(MaxLsNrDiffTcsFdlEvm + 1));
0267   m_monLsNrDiffTcsFdlEvmLs->setAxisTitle("Luminosity segment", 1);
0268   m_monLsNrDiffTcsFdlEvmLs->setAxisTitle("LS number difference (TCS - EVM_FDL)", 2);
0269 
0270   ibooker.setCurrentFolder(m_histFolder);
0271   // clear bookkeeping for prescale factor change
0272   m_pairLsNumberPfIndex.clear();
0273 
0274   ibooker.setCurrentFolder(m_histFolder + "/PlotTrigsBx");
0275 
0276   //--------book AlgoBits/TechBits vs Bx Histogram-----------
0277 
0278   //edm::ESHandle<L1GtTriggerMenu> menuRcd;
0279   //evSetup.get<L1GtTriggerMenuRcd>().get(menuRcd);
0280   //menuRcd.product();
0281   const L1GtTriggerMenu* menu = &evSetup.getData(l1gtTrigmenuToken_);
0282 
0283   h_L1AlgoBX1 = ibooker.book2D("h_L1AlgoBX1", "L1 Algo Trigger BX (algo bit 0 to 31)", 32, -0.5, 31.5, 5, -2.5, 2.5);
0284   h_L1AlgoBX2 = ibooker.book2D("h_L1AlgoBX2", "L1 Algo Trigger BX (algo bit 32 to 63)", 32, 31.5, 63.5, 5, -2.5, 2.5);
0285   h_L1AlgoBX3 = ibooker.book2D("h_L1AlgoBX3", "L1 Algo Trigger BX (algo bit 64 to 95)", 32, 63.5, 95.5, 5, -2.5, 2.5);
0286   h_L1AlgoBX4 = ibooker.book2D("h_L1AlgoBX4", "L1 Algo Trigger BX (algo bit 96 to 127)", 32, 95.5, 127.5, 5, -2.5, 2.5);
0287   h_L1TechBX = ibooker.book2D("h_L1TechBX", "L1 Tech Trigger BX", 64, -0.5, 63.5, 5, -2.5, 2.5);
0288 
0289   for (CItAlgo algo = menu->gtAlgorithmMap().begin(); algo != menu->gtAlgorithmMap().end(); ++algo) {
0290     int itrig = (algo->second).algoBitNumber();
0291     //algoBitToName[itrig] = TString( (algo->second).algoName() );
0292     //const char* trigName =  (algo->second).algoName().c_str();
0293     if (itrig < 32) {
0294       //h_L1AlgoBX1->setBinLabel(itrig+1,trigName);
0295       h_L1AlgoBX1->setBinLabel(itrig + 1, std::to_string(itrig));
0296       h_L1AlgoBX1->setAxisTitle("Algorithm trigger bits", 1);
0297       h_L1AlgoBX1->setAxisTitle("BX (0=L1A)", 2);
0298     } else if (itrig < 64) {
0299       //h_L1AlgoBX2->setBinLabel(itrig+1-32,trigName);
0300       h_L1AlgoBX2->setBinLabel(itrig + 1 - 32, std::to_string(itrig));
0301       h_L1AlgoBX2->setAxisTitle("Algorithm trigger bits", 1);
0302       h_L1AlgoBX2->setAxisTitle("BX (0=L1A)", 2);
0303     } else if (itrig < 96) {
0304       //h_L1AlgoBX3->setBinLabel(itrig+1-64,trigName);
0305       h_L1AlgoBX3->setBinLabel(itrig + 1 - 64, std::to_string(itrig));
0306       h_L1AlgoBX3->setAxisTitle("Algorithm trigger bits", 1);
0307       h_L1AlgoBX3->setAxisTitle("BX (0=L1A)", 2);
0308     } else if (itrig < 128) {
0309       //h_L1AlgoBX4->setBinLabel(itrig+1-96,trigName);
0310       h_L1AlgoBX4->setBinLabel(itrig + 1 - 96, std::to_string(itrig));
0311       h_L1AlgoBX4->setAxisTitle("Algorithm trigger bits", 1);
0312       h_L1AlgoBX4->setAxisTitle("BX (0=L1A)", 2);
0313     }
0314   }
0315 
0316   // technical trigger bits
0317   for (CItAlgo techTrig = menu->gtTechnicalTriggerMap().begin(); techTrig != menu->gtTechnicalTriggerMap().end();
0318        ++techTrig) {
0319     int itrig = (techTrig->second).algoBitNumber();
0320     //techBitToName[itrig] = TString( (techTrig->second).algoName() );
0321     //const char* trigName =  (techTrig->second).algoName().c_str();
0322     h_L1TechBX->setBinLabel(itrig + 1, std::to_string(itrig));
0323     h_L1TechBX->setAxisTitle("Technical trigger bits", 1);
0324     h_L1TechBX->setAxisTitle("BX (0=L1A)", 2);
0325   }
0326 }
0327 
0328 void L1TGT::dqmBeginRun(edm::Run const& iRrun, edm::EventSetup const& evSetup) { m_nrEvRun = 0; }
0329 
0330 //
0331 void L1TGT::analyze(const edm::Event& iEvent, const edm::EventSetup& evSetup) {
0332   m_nrEvJob++;
0333 
0334   if (verbose_) {
0335     edm::LogInfo("L1TGT") << "L1TGT: analyze...." << std::endl;
0336   }
0337 
0338   // initialize Bx, orbit number, luminosity segment number to invalid value
0339   int tcsBx = -1;
0340   int gtfeEvmBx = -1;
0341 
0342   long long int orbitTcs = -1;
0343   int orbitEvmFdl = -1;
0344 
0345   int lsTcs = -1;
0346   int lsEvmFdl = -1;
0347 
0348   // get once only the LS block number, to be used in many histograms
0349   const int lsNumber = iEvent.luminosityBlock();
0350 
0351   // open EVM readout record if available
0352   edm::Handle<L1GlobalTriggerEvmReadoutRecord> gtEvmReadoutRecord;
0353   iEvent.getByToken(gtEvmSource_, gtEvmReadoutRecord);
0354 
0355   if (!gtEvmReadoutRecord.isValid()) {
0356     edm::LogInfo("L1TGT") << "can't find L1GlobalTriggerEvmReadoutRecord";
0357   } else {
0358     // get all info from the EVM record if available and fill the histograms
0359 
0360     const L1GtfeWord& gtfeEvmWord = gtEvmReadoutRecord->gtfeWord();
0361     const L1GtfeExtWord& gtfeEvmExtWord = gtEvmReadoutRecord->gtfeWord();
0362 
0363     gtfeEvmBx = gtfeEvmWord.bxNr();
0364     int gtfeEvmActiveBoards = gtfeEvmWord.activeBoards();
0365 
0366     if (isActive(gtfeEvmActiveBoards, TCS)) {
0367       // if TCS present in the record
0368 
0369       const L1TcsWord& tcsWord = gtEvmReadoutRecord->tcsWord();
0370 
0371       tcsBx = tcsWord.bxNr();
0372       orbitTcs = tcsWord.orbitNr();
0373       lsTcs = tcsWord.luminositySegmentNr();
0374 
0375       event_type->Fill(tcsWord.triggerType());
0376       orbit_lumi->Fill(lsNumber, orbitTcs);
0377 
0378       trigger_number->Fill(tcsWord.partTrigNr());
0379       event_number->Fill(tcsWord.eventNr());
0380 
0381       trigger_lumi->Fill(lsNumber, tcsWord.partTrigNr());
0382       event_lumi->Fill(lsNumber, tcsWord.eventNr());
0383       evnum_trignum_lumi->Fill(lsNumber,
0384                                static_cast<double>(tcsWord.eventNr()) / static_cast<double>(tcsWord.partTrigNr()));
0385 
0386       uint16_t master = gtfeEvmExtWord.bstMasterStatus();
0387       uint32_t turnCount = gtfeEvmExtWord.turnCountNumber();
0388       uint32_t lhcFill = gtfeEvmExtWord.lhcFillNumber();
0389       uint16_t beam = gtfeEvmExtWord.beamMode();
0390       uint16_t momentum = gtfeEvmExtWord.beamMomentum();
0391       uint32_t intensity1 = gtfeEvmExtWord.totalIntensityBeam1();
0392       uint32_t intensity2 = gtfeEvmExtWord.totalIntensityBeam2();
0393 
0394       BST_MasterStatus->Fill(lsNumber, static_cast<double>(master));
0395       BST_turnCountNumber->Fill(lsNumber, static_cast<double>(turnCount));
0396       BST_lhcFillNumber->Fill(static_cast<double>(lhcFill % 1000));
0397       BST_beamMode->Fill(lsNumber, static_cast<double>(beam));
0398 
0399       BST_beamMomentum->Fill(lsNumber, static_cast<double>(momentum));
0400       BST_intensityBeam1->Fill(lsNumber, static_cast<double>(intensity1));
0401       BST_intensityBeam2->Fill(lsNumber, static_cast<double>(intensity2));
0402 
0403       if (verbose_) {
0404         edm::LogInfo("L1TGT") << " check mode = " << beam << "    momentum " << momentum << " int2 " << intensity2
0405                               << std::endl;
0406       }
0407 
0408       uint64_t gpsr = gtfeEvmExtWord.gpsTime();
0409       uint64_t gpshi = (gpsr >> 32) & 0xffffffff;
0410       uint64_t gpslo = gpsr & 0xffffffff;
0411       uint64_t gps = gpshi * 1000000 + gpslo;
0412       //  edm::LogInfo("L1TGT") << "  gpsr = " << std::hex << gpsr << " hi=" << gpshi << " lo=" << gpslo << " gps=" << gps << std::endl;
0413 
0414       Long64_t delorb = orbitTcs - preOrb_;
0415       Long64_t delgps = gps - preGps_;
0416       Double_t freq = -1.;
0417 
0418       if (delgps > 0) {
0419         freq = ((Double_t)(delorb)) * 3564. / ((Double_t)(delgps));
0420       }
0421 
0422       if (delorb > 0) {
0423         gpsfreq->Fill(freq);
0424         gpsfreqwide->Fill(freq);
0425         gpsfreqlum->Fill(lsNumber, freq);
0426         if (verbose_) {
0427           if (freq > 200.) {
0428             edm::LogInfo("L1TGT") << " preOrb_ = " << preOrb_ << " orbitTcs=" << orbitTcs << " delorb=" << delorb
0429                                   << std::hex << " preGps_=" << preGps_ << " gps=" << gps << std::dec
0430                                   << " delgps=" << delgps << " freq=" << freq << std::endl;
0431           }
0432         }
0433       }
0434 
0435       preGps_ = gps;
0436       preOrb_ = orbitTcs;
0437     }
0438 
0439     // get info from FDL if active
0440     if (isActive(gtfeEvmActiveBoards, FDL)) {
0441       const L1GtFdlWord& fdlWord = gtEvmReadoutRecord->gtFdlWord();
0442 
0443       orbitEvmFdl = fdlWord.orbitNr();
0444       lsEvmFdl = fdlWord.lumiSegmentNr();
0445     }
0446 
0447     if ((orbitTcs >= 0) && (orbitEvmFdl >= 0)) {
0448       int diffOrbit = static_cast<float>(orbitTcs - orbitEvmFdl);
0449       edm::LogInfo("L1TGT") << "\n orbitTcs = " << orbitTcs << " orbitEvmFdl = " << orbitEvmFdl
0450                             << " diffOrbit = " << diffOrbit << " orbitEvent = " << iEvent.orbitNumber() << std::endl;
0451 
0452       if (diffOrbit >= MaxOrbitNrDiffTcsFdlEvm) {
0453         m_monOrbitNrDiffTcsFdlEvm->Fill(MaxOrbitNrDiffTcsFdlEvm);
0454 
0455       } else if (diffOrbit <= -MaxOrbitNrDiffTcsFdlEvm) {
0456         m_monOrbitNrDiffTcsFdlEvm->Fill(-MaxOrbitNrDiffTcsFdlEvm);
0457 
0458       } else {
0459         m_monOrbitNrDiffTcsFdlEvm->Fill(diffOrbit);
0460         m_monOrbitNrDiffTcsFdlEvmLs->Fill(lsNumber, diffOrbit);
0461       }
0462 
0463     } else {
0464       if (orbitTcs >= 0) {
0465         // EVM_FDL error
0466         m_monOrbitNrDiffTcsFdlEvm->Fill(MaxOrbitNrDiffTcsFdlEvm);
0467       } else if (orbitEvmFdl >= 0) {
0468         // TCS error
0469         m_monOrbitNrDiffTcsFdlEvm->Fill(-MaxOrbitNrDiffTcsFdlEvm);
0470 
0471       } else {
0472         // TCS and EVM_FDL error
0473         m_monOrbitNrDiffTcsFdlEvm->Fill(-MaxOrbitNrDiffTcsFdlEvm);
0474         m_monOrbitNrDiffTcsFdlEvm->Fill(MaxOrbitNrDiffTcsFdlEvm);
0475       }
0476     }
0477 
0478     if ((lsTcs >= 0) && (lsEvmFdl >= 0)) {
0479       int diffLs = static_cast<float>(lsTcs - lsEvmFdl);
0480       edm::LogInfo("L1TGT") << "\n lsTcs = " << lsTcs << " lsEvmFdl = " << lsEvmFdl << " diffLs = " << diffLs
0481                             << " lsEvent = " << lsNumber << std::endl;
0482 
0483       if (diffLs >= MaxLsNrDiffTcsFdlEvm) {
0484         m_monLsNrDiffTcsFdlEvm->Fill(MaxLsNrDiffTcsFdlEvm);
0485 
0486       } else if (diffLs <= -MaxLsNrDiffTcsFdlEvm) {
0487         m_monLsNrDiffTcsFdlEvm->Fill(-MaxLsNrDiffTcsFdlEvm);
0488 
0489       } else {
0490         m_monLsNrDiffTcsFdlEvm->Fill(diffLs);
0491         m_monLsNrDiffTcsFdlEvmLs->Fill(lsNumber, diffLs);
0492       }
0493 
0494     } else {
0495       if (lsTcs >= 0) {
0496         // EVM_FDL error
0497         m_monLsNrDiffTcsFdlEvm->Fill(MaxLsNrDiffTcsFdlEvm);
0498       } else if (lsEvmFdl >= 0) {
0499         // TCS error
0500         m_monLsNrDiffTcsFdlEvm->Fill(-MaxLsNrDiffTcsFdlEvm);
0501 
0502       } else {
0503         // TCS and EVM_FDL error
0504         m_monLsNrDiffTcsFdlEvm->Fill(-MaxLsNrDiffTcsFdlEvm);
0505         m_monLsNrDiffTcsFdlEvm->Fill(MaxLsNrDiffTcsFdlEvm);
0506       }
0507     }
0508   }
0509 
0510   // open GT DAQ readout record - exit if failed
0511   edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecord;
0512   iEvent.getByToken(gtSource_L1GT_, gtReadoutRecord);
0513 
0514   //edm::ESHandle<L1GtTriggerMenu> menuRcd;
0515   //evSetup.get<L1GtTriggerMenuRcd>().get(menuRcd);
0516 
0517   //const L1GtTriggerMenu* menu = menuRcd.product();
0518 
0519   if (!gtReadoutRecord.isValid()) {
0520     edm::LogInfo("L1TGT") << "can't find L1GlobalTriggerReadoutRecord";
0521     return;
0522   }
0523 
0524   if (gtReadoutRecord.isValid()) {
0525     unsigned int NmaxL1AlgoBit = gtReadoutRecord->decisionWord().size();
0526     unsigned int NmaxL1TechBit = gtReadoutRecord->technicalTriggerWord().size();
0527 
0528     const DecisionWord dWord = gtReadoutRecord->decisionWord();
0529     const TechnicalTriggerWord technicalTriggerWordBeforeMask = gtReadoutRecord->technicalTriggerWord();
0530 
0531     const std::vector<L1GtFdlWord>& m_gtFdlWord(gtReadoutRecord->gtFdlVector());
0532     int numberBxInEvent = m_gtFdlWord.size();
0533     int minBxInEvent = (numberBxInEvent + 1) / 2 - numberBxInEvent;
0534 
0535     for (unsigned int iBit = 0; iBit < NmaxL1AlgoBit; ++iBit) {
0536       bool accept = dWord[iBit];
0537 
0538       typedef std::map<std::string, bool>::value_type valType;
0539       trig_iter = l1TriggerDecision.find(algoBitToName[iBit]);
0540       if (trig_iter == l1TriggerDecision.end()) {
0541         l1TriggerDecision.insert(valType(algoBitToName[iBit], accept));
0542       } else {
0543         trig_iter->second = accept;
0544       }
0545 
0546       int ibx = 0;
0547       for (std::vector<L1GtFdlWord>::const_iterator itBx = m_gtFdlWord.begin(); itBx != m_gtFdlWord.end(); ++itBx) {
0548         const DecisionWord dWordBX = (*itBx).gtDecisionWord();
0549         bool accept = dWordBX[iBit];
0550         if (accept) {
0551           if (iBit < 32)
0552             h_L1AlgoBX1->Fill(iBit, minBxInEvent + ibx);
0553           else if (iBit < 64)
0554             h_L1AlgoBX2->Fill(iBit, minBxInEvent + ibx);
0555           else if (iBit < 96)
0556             h_L1AlgoBX3->Fill(iBit, minBxInEvent + ibx);
0557           else if (iBit < 128)
0558             h_L1AlgoBX4->Fill(iBit, minBxInEvent + ibx);
0559         }
0560         ibx++;
0561       }
0562     }
0563 
0564     for (unsigned int iBit = 0; iBit < NmaxL1TechBit; ++iBit) {
0565       bool accept = technicalTriggerWordBeforeMask[iBit];
0566 
0567       typedef std::map<std::string, bool>::value_type valType;
0568       trig_iter = l1TechTriggerDecision.find(techBitToName[iBit]);
0569       if (trig_iter == l1TechTriggerDecision.end())
0570         l1TechTriggerDecision.insert(valType(techBitToName[iBit], accept));
0571       else
0572         trig_iter->second = accept;
0573 
0574       int ibx = 0;
0575       for (std::vector<L1GtFdlWord>::const_iterator itBx = m_gtFdlWord.begin(); itBx != m_gtFdlWord.end(); ++itBx) {
0576         const DecisionWord dWordBX = (*itBx).gtTechnicalTriggerWord();
0577         bool accept = dWordBX[iBit];
0578         if (accept)
0579           h_L1TechBX->Fill(iBit, minBxInEvent + ibx);
0580         ibx++;
0581       }
0582     }
0583   }
0584 
0585   // initialize bx's to invalid value
0586   int gtfeBx = -1;
0587   int fdlBx[2] = {-1, -1};
0588   int psbBx[2][7] = {{-1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1}};
0589   int gmtBx = -1;
0590 
0591   // get info from GTFE DAQ record
0592   const L1GtfeWord& gtfeWord = gtReadoutRecord->gtfeWord();
0593   gtfeBx = gtfeWord.bxNr();
0594   gtfe_bx->Fill(gtfeBx);
0595   setupversion_lumi->Fill(lsNumber, gtfeWord.setupVersion());
0596   int gtfeActiveBoards = gtfeWord.activeBoards();
0597 
0598   // look for GMT readout collection from the same source if GMT active
0599   if (isActive(gtfeActiveBoards, GMT)) {
0600     edm::Handle<L1MuGMTReadoutCollection> gmtReadoutCollection;
0601     iEvent.getByToken(gtSource_L1MuGMT_, gmtReadoutCollection);
0602 
0603     if (gmtReadoutCollection.isValid()) {
0604       gmtBx = gmtReadoutCollection->getRecord().getBxNr();
0605     }
0606   }
0607 
0608   // get info from FDL if active (including decision word)
0609   if (isActive(gtfeActiveBoards, FDL)) {
0610     const L1GtFdlWord& fdlWord = gtReadoutRecord->gtFdlWord();
0611     fdlBx[0] = fdlWord.bxNr();
0612     fdlBx[1] = fdlWord.localBxNr();
0613 
0614     /// get Global Trigger algo and technical trigger bit statistics
0615     const DecisionWord& gtDecisionWord = gtReadoutRecord->decisionWord();
0616     const TechnicalTriggerWord& gtTTWord = gtReadoutRecord->technicalTriggerWord();
0617 
0618     int dbitNumber = 0;
0619     DecisionWord::const_iterator GTdbitItr;
0620     algo_bits->Fill(-1.);  // fill underflow to normalize
0621     for (GTdbitItr = gtDecisionWord.begin(); GTdbitItr != gtDecisionWord.end(); GTdbitItr++) {
0622       if (*GTdbitItr) {
0623         algo_bits->Fill(dbitNumber);
0624         algo_bits_lumi->Fill(lsNumber, dbitNumber);
0625         int dbitNumber1 = 0;
0626         DecisionWord::const_iterator GTdbitItr1;
0627         for (GTdbitItr1 = gtDecisionWord.begin(); GTdbitItr1 != gtDecisionWord.end(); GTdbitItr1++) {
0628           if (*GTdbitItr1)
0629             algo_bits_corr->Fill(dbitNumber, dbitNumber1);
0630           dbitNumber1++;
0631         }
0632         int tbitNumber1 = 0;
0633         TechnicalTriggerWord::const_iterator GTtbitItr1;
0634         for (GTtbitItr1 = gtTTWord.begin(); GTtbitItr1 != gtTTWord.end(); GTtbitItr1++) {
0635           if (*GTtbitItr1)
0636             algo_tt_bits_corr->Fill(dbitNumber, tbitNumber1);
0637           tbitNumber1++;
0638         }
0639       }
0640       dbitNumber++;
0641     }
0642 
0643     int tbitNumber = 0;
0644     TechnicalTriggerWord::const_iterator GTtbitItr;
0645     tt_bits->Fill(-1.);  // fill underflow to normalize
0646     for (GTtbitItr = gtTTWord.begin(); GTtbitItr != gtTTWord.end(); GTtbitItr++) {
0647       if (*GTtbitItr) {
0648         tt_bits->Fill(tbitNumber);
0649         tt_bits_lumi->Fill(lsNumber, tbitNumber);
0650         int tbitNumber1 = 0;
0651         TechnicalTriggerWord::const_iterator GTtbitItr1;
0652         for (GTtbitItr1 = gtTTWord.begin(); GTtbitItr1 != gtTTWord.end(); GTtbitItr1++) {
0653           if (*GTtbitItr1)
0654             tt_bits_corr->Fill(tbitNumber, tbitNumber1);
0655           tbitNumber1++;
0656         }
0657       }
0658       tbitNumber++;
0659     }
0660 
0661     // fill the index of actual prescale factor set
0662     // the index for technical triggers and algorithm trigger is the same (constraint in L1 GT TS)
0663     // so we read only pfIndexAlgoTrig (uint16_t)
0664 
0665     const int pfIndexAlgoTrig = fdlWord.gtPrescaleFactorIndexAlgo();
0666     m_monL1PrescaleFactorSet->Fill(lsNumber, static_cast<float>(pfIndexAlgoTrig));
0667 
0668     //
0669 
0670     // check that the combination (lsNumber, pfIndex) is not already included
0671     // to avoid fake entries due to different event order
0672 
0673     std::pair<int, int> pairLsPfi = std::make_pair(lsNumber, pfIndexAlgoTrig);
0674 
0675     CItVecPair cIt = find(m_pairLsNumberPfIndex.begin(), m_pairLsNumberPfIndex.end(), pairLsPfi);
0676 
0677     if (cIt == m_pairLsNumberPfIndex.end()) {
0678       m_pairLsNumberPfIndex.push_back(pairLsPfi);
0679     }
0680   }
0681 
0682   // get info from active PSB's
0683   int ibit = PSB9;  // first psb
0684   // for now hardcode psb id's - TODO - get them from Vasile's board maps...
0685   int psbID[7] = {0xbb09, 0xbb0d, 0xbb0e, 0xbb0f, 0xbb13, 0xbb14, 0xbb15};
0686   for (int i = 0; i < 7; i++) {
0687     if (isActive(gtfeActiveBoards, ibit)) {
0688       L1GtPsbWord psbWord = gtReadoutRecord->gtPsbWord(psbID[i]);
0689       psbBx[0][i] = psbWord.bxNr();
0690       psbBx[1][i] = psbWord.localBxNr();
0691     }
0692     ibit++;
0693   }
0694 
0695   //fill the dbx histo
0696   if (gtfeEvmBx > -1)
0697     dbx_module->Fill(0., gtfeEvmBx - gtfeBx);
0698   if (tcsBx > -1)
0699     dbx_module->Fill(1., tcsBx - gtfeBx);
0700   for (int i = 0; i < 2; i++) {
0701     if (fdlBx[i] > -1)
0702       dbx_module->Fill(2. + i, fdlBx[i] - gtfeBx);
0703   }
0704   for (int j = 0; j < 7; j++) {
0705     for (int i = 0; i < 2; i++) {
0706       if (psbBx[i][j] > -1)
0707         dbx_module->Fill(4. + i + 2 * j, psbBx[i][j] - gtfeBx);
0708     }
0709   }
0710   if (gmtBx > -1)
0711     dbx_module->Fill(18., gmtBx - gtfeBx);
0712 }
0713 
0714 // end section
0715 void L1TGT::endLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup& evSetup) {
0716   if (m_runInEndLumi) {
0717     countPfsIndicesPerLs();
0718   }
0719 }
0720 
0721 ////////////////////////////////////////////////////////////////////////////////////////
0722 bool L1TGT::isActive(int word, int bit) {
0723   if (word & (1 << bit))
0724     return true;
0725   return false;
0726 }
0727 
0728 void L1TGT::countPfsIndicesPerLs() {
0729   if (verbose_) {
0730     edm::LogInfo("L1TGT") << "\n  Prescale factor indices used in a LS " << std::endl;
0731 
0732     for (CItVecPair cIt = m_pairLsNumberPfIndex.begin(); cIt != m_pairLsNumberPfIndex.end(); ++cIt) {
0733       edm::LogVerbatim("L1TGT") << "  lsNumber = " << (*cIt).first << " pfIndex = " << (*cIt).second << std::endl;
0734     }
0735     edm::LogVerbatim("L1TGT") << std::endl;
0736   }
0737 
0738   // reset the histogram...
0739   m_monL1PfIndicesPerLs->Reset();
0740 
0741   // sort the vector (for pairs: sort after first argument, then after the second argument)
0742   std::sort(m_pairLsNumberPfIndex.begin(), m_pairLsNumberPfIndex.end());
0743 
0744   int previousLsNumber = -1;
0745   int previousPfsIndex = -1;
0746 
0747   // count the number of pairs (lsNumber, pfIndex) per Ls
0748   // there are no duplicate entries, and pairs are sorted after both members
0749   // ... and fill again the histogram
0750   int pfsIndicesPerLs = 1;
0751   for (CItVecPair cIt = m_pairLsNumberPfIndex.begin(); cIt != m_pairLsNumberPfIndex.end(); ++cIt) {
0752     if ((*cIt).first == previousLsNumber) {
0753       if ((*cIt).second != previousPfsIndex) {
0754         previousPfsIndex = (*cIt).second;
0755         pfsIndicesPerLs++;
0756       }
0757 
0758     } else {
0759       // fill the histogram with the number of PF indices for the previous Ls
0760       if (previousLsNumber != -1) {
0761         m_monL1PfIndicesPerLs->Fill(pfsIndicesPerLs);
0762       }
0763 
0764       // new Ls
0765       previousLsNumber = (*cIt).first;
0766       previousPfsIndex = (*cIt).second;
0767       pfsIndicesPerLs = 1;
0768     }
0769   }
0770 }
0771 
0772 // static class members
0773 // maximum difference in orbit number
0774 const int L1TGT::MaxOrbitNrDiffTcsFdlEvm = 24;
0775 
0776 // maximum difference in luminosity segment number
0777 const int L1TGT::MaxLsNrDiffTcsFdlEvm = 24;