Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:12:59

0001 /**
0002  * \class L1TSync_Offline
0003  *
0004  *
0005  * Description: offline DQM module for L1Trigger/bunchStructure synchronization
0006  * 
0007  * Implementation:
0008  *   <TODO: enter implementation details>
0009  *
0010  * \author: Pietro Vischia - LIP Lisbon pietro.vischia@gmail.com
0011  *
0012  * Changelog:
0013  *    2012/08/10 11:01:01: First creation. Dummy module with actual code commented.
0014  *
0015  * Todo:
0016  *  - implement the module in offline
0017  *  - check if there are user includes specific for offline/online that should be changed
0018  *
0019  *
0020  */
0021 
0022 //
0023 
0024 // This class header
0025 #include "DQMOffline/L1Trigger/interface/L1TSync_Offline.h"
0026 
0027 // System include files
0028 // --
0029 
0030 // User include files
0031 #include "DQMServices/Core/interface/DQMStore.h"
0032 
0033 #include "DataFormats/Scalers/interface/LumiScalers.h"
0034 #include "DataFormats/Scalers/interface/Level1TriggerRates.h"
0035 #include "DataFormats/Scalers/interface/Level1TriggerScalers.h"
0036 
0037 #include "DataFormats/Common/interface/ConditionsInEdm.h"  // Parameters associated to Run, LS and Event
0038 
0039 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenuFwd.h"
0040 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
0041 #include "CondFormats/L1TObjects/interface/L1GtPrescaleFactors.h"
0042 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
0043 #include "CondFormats/DataRecord/interface/L1GtPrescaleFactorsAlgoTrigRcd.h"
0044 #include "CondFormats/L1TObjects/interface/L1GtMuonTemplate.h"
0045 ///
0046 // Luminosity Information
0047 //#include "DataFormats/Luminosity/interface/LumiDetails.h"
0048 //#include "DataFormats/Luminosity/interface/LumiSummary.h"
0049 
0050 // L1TMonitor includes
0051 //#include "DQMOffline/L1Trigger/interface/L1TMenuHelper.h"
0052 
0053 #include "TList.h"
0054 
0055 using namespace edm;
0056 using namespace std;
0057 
0058 //-------------------------------------------------------------------------------------
0059 //-------------------------------------------------------------------------------------
0060 L1TSync_Offline::L1TSync_Offline(const ParameterSet& pset)
0061     : m_menuToken(esConsumes<edm::Transition::BeginRun>()),
0062       m_helperTokens(L1TMenuHelper::consumes<edm::Transition::BeginRun>(consumesCollector())),
0063       m_l1GtUtils(pset, consumesCollector(), false, *this) {
0064   m_parameters = pset;
0065 
0066   // Mapping parameter input variables
0067   m_l1GtDataDaqInputTag = consumes<L1GlobalTriggerReadoutRecord>(pset.getParameter<InputTag>("inputTagL1GtDataDaq"));
0068   m_l1GtEvmSource = consumes<L1GlobalTriggerEvmReadoutRecord>(pset.getParameter<InputTag>("inputTagtEvmSource"));
0069   m_verbose = pset.getUntrackedParameter<bool>("verbose", false);
0070   m_refPrescaleSet = pset.getParameter<int>("refPrescaleSet");
0071 
0072   // Getting which categories to monitor
0073   ParameterSet Categories = pset.getParameter<ParameterSet>("Categories");
0074 
0075   bool forceGlobalParameters = Categories.getParameter<bool>("forceGlobalParameters");
0076   bool doGlobalAutoSelection = Categories.getParameter<bool>("doGlobalAutoSelection");
0077 
0078   ParameterSet CatBPTX = Categories.getParameter<ParameterSet>("BPTX");
0079   ParameterSet CatMu = Categories.getParameter<ParameterSet>("Mu");
0080   ParameterSet CatEG = Categories.getParameter<ParameterSet>("EG");
0081   ParameterSet CatIsoEG = Categories.getParameter<ParameterSet>("IsoEG");
0082   ParameterSet CatJet = Categories.getParameter<ParameterSet>("Jet");
0083   ParameterSet CatCenJet = Categories.getParameter<ParameterSet>("CenJet");
0084   ParameterSet CatForJet = Categories.getParameter<ParameterSet>("ForJet");
0085   ParameterSet CatTauJet = Categories.getParameter<ParameterSet>("TauJet");
0086   ParameterSet CatETM = Categories.getParameter<ParameterSet>("ETT");
0087   ParameterSet CatETT = Categories.getParameter<ParameterSet>("ETM");
0088   ParameterSet CatHTT = Categories.getParameter<ParameterSet>("HTT");
0089   ParameterSet CatHTM = Categories.getParameter<ParameterSet>("HTM");
0090 
0091   // --> Setting parameters related to which algos to monitor
0092   // If global parameters are forced they take precedence over algo-by-algo parameters
0093   if (forceGlobalParameters) {
0094     // If global automatic selection if enable all categories set to be monitored will have
0095     // their algos auto selected (the lowest prescale algo will be selected)
0096     if (doGlobalAutoSelection) {
0097       if (CatMu.getParameter<bool>("monitor")) {
0098         m_algoAutoSelect["Mu"] = true;
0099       } else {
0100         m_algoAutoSelect["Mu"] = false;
0101       }
0102       if (CatEG.getParameter<bool>("monitor")) {
0103         m_algoAutoSelect["EG"] = true;
0104       } else {
0105         m_algoAutoSelect["EG"] = false;
0106       }
0107       if (CatIsoEG.getParameter<bool>("monitor")) {
0108         m_algoAutoSelect["IsoEG"] = true;
0109       } else {
0110         m_algoAutoSelect["IsoEG"] = false;
0111       }
0112       if (CatJet.getParameter<bool>("monitor")) {
0113         m_algoAutoSelect["Jet"] = true;
0114       } else {
0115         m_algoAutoSelect["Jet"] = false;
0116       }
0117       if (CatCenJet.getParameter<bool>("monitor")) {
0118         m_algoAutoSelect["CenJet"] = true;
0119       } else {
0120         m_algoAutoSelect["CenJet"] = false;
0121       }
0122       if (CatForJet.getParameter<bool>("monitor")) {
0123         m_algoAutoSelect["ForJet"] = true;
0124       } else {
0125         m_algoAutoSelect["ForJet"] = false;
0126       }
0127       if (CatTauJet.getParameter<bool>("monitor")) {
0128         m_algoAutoSelect["TauJet"] = true;
0129       } else {
0130         m_algoAutoSelect["TauJet"] = false;
0131       }
0132       if (CatETM.getParameter<bool>("monitor")) {
0133         m_algoAutoSelect["ETM"] = true;
0134       } else {
0135         m_algoAutoSelect["ETM"] = false;
0136       }
0137       if (CatETT.getParameter<bool>("monitor")) {
0138         m_algoAutoSelect["ETT"] = true;
0139       } else {
0140         m_algoAutoSelect["ETT"] = false;
0141       }
0142       if (CatHTM.getParameter<bool>("monitor")) {
0143         m_algoAutoSelect["HTM"] = true;
0144       } else {
0145         m_algoAutoSelect["HTM"] = false;
0146       }
0147       if (CatHTT.getParameter<bool>("monitor")) {
0148         m_algoAutoSelect["HTT"] = true;
0149       } else {
0150         m_algoAutoSelect["HTT"] = false;
0151       }
0152 
0153       // If global non-automatic selection is enable all categories set to be monitored will use
0154       // user defined algos
0155     } else {
0156       m_algoAutoSelect["Mu"] = false;
0157       m_algoAutoSelect["EG"] = false;
0158       m_algoAutoSelect["IsoEG"] = false;
0159       m_algoAutoSelect["Jet"] = false;
0160       m_algoAutoSelect["CenJet"] = false;
0161       m_algoAutoSelect["ForJet"] = false;
0162       m_algoAutoSelect["TauJet"] = false;
0163       m_algoAutoSelect["ETM"] = false;
0164       m_algoAutoSelect["ETT"] = false;
0165       m_algoAutoSelect["HTM"] = false;
0166       m_algoAutoSelect["HTT"] = false;
0167 
0168       if (CatMu.getParameter<bool>("monitor")) {
0169         m_selectedTriggers["Mu"] = CatMu.getParameter<string>("algo");
0170       }
0171       if (CatEG.getParameter<bool>("monitor")) {
0172         m_selectedTriggers["EG"] = CatEG.getParameter<string>("algo");
0173       }
0174       if (CatIsoEG.getParameter<bool>("monitor")) {
0175         m_selectedTriggers["IsoEG"] = CatIsoEG.getParameter<string>("algo");
0176       }
0177       if (CatJet.getParameter<bool>("monitor")) {
0178         m_selectedTriggers["Jet"] = CatJet.getParameter<string>("algo");
0179       }
0180       if (CatCenJet.getParameter<bool>("monitor")) {
0181         m_selectedTriggers["CenJet"] = CatCenJet.getParameter<string>("algo");
0182       }
0183       if (CatForJet.getParameter<bool>("monitor")) {
0184         m_selectedTriggers["CatForJet"] = CatForJet.getParameter<string>("algo");
0185       }
0186       if (CatTauJet.getParameter<bool>("monitor")) {
0187         m_selectedTriggers["TauJet"] = CatTauJet.getParameter<string>("algo");
0188       }
0189       if (CatETM.getParameter<bool>("monitor")) {
0190         m_selectedTriggers["ETM"] = CatETM.getParameter<string>("algo");
0191       }
0192       if (CatETT.getParameter<bool>("monitor")) {
0193         m_selectedTriggers["ETT"] = CatETT.getParameter<string>("algo");
0194       }
0195       if (CatHTM.getParameter<bool>("monitor")) {
0196         m_selectedTriggers["HTM"] = CatHTM.getParameter<string>("algo");
0197       }
0198       if (CatHTT.getParameter<bool>("monitor")) {
0199         m_selectedTriggers["HTT"] = CatHTT.getParameter<string>("algo");
0200       }
0201     }
0202 
0203     // If we are using algo-by-algo parametes we get them and set what is needed
0204   } else {
0205     if (CatBPTX.getParameter<bool>("monitor")) {
0206       m_selectedTriggers["BPTX"] = CatBPTX.getParameter<string>("algo");
0207     }
0208 
0209     if (CatMu.getParameter<bool>("monitor")) {
0210       m_algoAutoSelect["Mu"] = CatMu.getParameter<bool>("doAutoSelection");
0211       if (!m_algoAutoSelect["Mu"]) {
0212         m_selectedTriggers["Mu"] = CatMu.getParameter<string>("algo");
0213       }
0214     } else {
0215       m_algoAutoSelect["Mu"] = false;
0216     }
0217 
0218     if (CatEG.getParameter<bool>("monitor")) {
0219       m_algoAutoSelect["EG"] = CatEG.getParameter<bool>("doAutoSelection");
0220       if (!m_algoAutoSelect["EG"]) {
0221         m_selectedTriggers["EG"] = CatEG.getParameter<string>("algo");
0222       }
0223     } else {
0224       m_algoAutoSelect["EG"] = false;
0225     }
0226 
0227     if (CatIsoEG.getParameter<bool>("monitor")) {
0228       m_algoAutoSelect["IsoEG"] = CatIsoEG.getParameter<bool>("doAutoSelection");
0229       if (!m_algoAutoSelect["IsoEG"]) {
0230         m_selectedTriggers["IsoEG"] = CatIsoEG.getParameter<string>("algo");
0231       }
0232     } else {
0233       m_algoAutoSelect["IsoEG"] = false;
0234     }
0235 
0236     if (CatJet.getParameter<bool>("monitor")) {
0237       m_algoAutoSelect["Jet"] = CatJet.getParameter<bool>("doAutoSelection");
0238       if (!m_algoAutoSelect["Jet"]) {
0239         m_selectedTriggers["Jet"] = CatJet.getParameter<string>("algo");
0240       }
0241     } else {
0242       m_algoAutoSelect["Jet"] = false;
0243     }
0244 
0245     if (CatCenJet.getParameter<bool>("monitor")) {
0246       m_algoAutoSelect["CenJet"] = CatCenJet.getParameter<bool>("doAutoSelection");
0247       if (!m_algoAutoSelect["CenJet"]) {
0248         m_selectedTriggers["CenJet"] = CatCenJet.getParameter<string>("algo");
0249       }
0250     } else {
0251       m_algoAutoSelect["CenJet"] = false;
0252     }
0253 
0254     if (CatForJet.getParameter<bool>("monitor")) {
0255       m_algoAutoSelect["CatForJet"] = CatForJet.getParameter<bool>("doAutoSelection");
0256       if (!m_algoAutoSelect["CatForJet"]) {
0257         m_selectedTriggers["CatForJet"] = CatForJet.getParameter<string>("algo");
0258       }
0259     } else {
0260       m_algoAutoSelect["CatForJet"] = false;
0261     }
0262 
0263     if (CatTauJet.getParameter<bool>("monitor")) {
0264       m_algoAutoSelect["TauJet"] = CatTauJet.getParameter<bool>("doAutoSelection");
0265       if (!m_algoAutoSelect["TauJet"]) {
0266         m_selectedTriggers["TauJet"] = CatTauJet.getParameter<string>("algo");
0267       }
0268     } else {
0269       m_algoAutoSelect["TauJet"] = false;
0270     }
0271 
0272     if (CatETM.getParameter<bool>("monitor")) {
0273       m_algoAutoSelect["ETM"] = CatETM.getParameter<bool>("doAutoSelection");
0274       if (!m_algoAutoSelect["ETM"]) {
0275         m_selectedTriggers["ETM"] = CatETM.getParameter<string>("algo");
0276       }
0277     } else {
0278       m_algoAutoSelect["ETM"] = false;
0279     }
0280 
0281     if (CatETT.getParameter<bool>("monitor")) {
0282       m_algoAutoSelect["ETT"] = CatETT.getParameter<bool>("doAutoSelection");
0283       if (!m_algoAutoSelect["ETT"]) {
0284         m_selectedTriggers["ETT"] = CatETT.getParameter<string>("algo");
0285       }
0286     } else {
0287       m_algoAutoSelect["ETT"] = false;
0288     }
0289 
0290     if (CatHTM.getParameter<bool>("monitor")) {
0291       m_algoAutoSelect["HTM"] = CatHTM.getParameter<bool>("doAutoSelection");
0292       if (!m_algoAutoSelect["HTM"]) {
0293         m_selectedTriggers["HTM"] = CatHTM.getParameter<string>("algo");
0294       }
0295     } else {
0296       m_algoAutoSelect["HTM"] = false;
0297     }
0298 
0299     if (CatHTT.getParameter<bool>("monitor")) {
0300       m_algoAutoSelect["HTT"] = CatHTT.getParameter<bool>("doAutoSelection");
0301       if (!m_algoAutoSelect["HTT"]) {
0302         m_selectedTriggers["HTT"] = CatHTT.getParameter<string>("algo");
0303       }
0304     } else {
0305       m_algoAutoSelect["HTT"] = false;
0306     }
0307   }
0308 }
0309 
0310 //-------------------------------------------------------------------------------------
0311 //-------------------------------------------------------------------------------------
0312 L1TSync_Offline::~L1TSync_Offline() {}
0313 
0314 //-------------------------------------------------------------------------------------
0315 
0316 void L1TSync_Offline::dqmBeginRun(edm::Run const&, edm::EventSetup const&) {}
0317 //-------------------------------------------------------------------------------------
0318 /// BeginRun
0319 //-------------------------------------------------------------------------------------
0320 void L1TSync_Offline::bookHistograms(DQMStore::IBooker& ibooker, const edm::Run& iRun, const edm::EventSetup& iSetup) {
0321   if (m_verbose) {
0322     cout << "[L1TSync_Offline] Called beginRun." << endl;
0323   }
0324 
0325   // Initializing variables
0326   int maxNbins = 2501;
0327 
0328   // Reseting run dependent variables
0329   m_lhcFill = 0;
0330   m_certFirstLS.clear();
0331   m_certLastLS.clear();
0332 
0333   // Getting Trigger menu from GT
0334   const L1GtTriggerMenu& menu = iSetup.getData(m_menuToken);
0335 
0336   // Filling Alias-Bit Map
0337   for (const auto& algo : menu.gtAlgorithmAliasMap()) {
0338     m_algoBit[algo.second.algoAlias()] = algo.second.algoBitNumber();
0339   }
0340 
0341   // Getting fill number for this run
0342   //Handle<ConditionsInRunBlock> runConditions;
0343   //iRun.getByType(runConditions);
0344   //int lhcFillNumber = runConditions->lhcFillNumber;
0345   //
0346   //ESHandle<L1GtPrescaleFactors> l1GtPfAlgo;
0347   //iSetup.get<L1GtPrescaleFactorsAlgoTrigRcd>().get(l1GtPfAlgo);
0348   //const L1GtPrescaleFactors* m_l1GtPfAlgo = l1GtPfAlgo.product();
0349 
0350   L1TMenuHelper myMenuHelper = L1TMenuHelper(iSetup, m_helperTokens);
0351 
0352   m_selectedTriggers = myMenuHelper.testAlgos(m_selectedTriggers);
0353 
0354   m_l1GtUtils.retrieveL1EventSetup(iSetup);
0355   map<string, string> tAutoSelTrig = myMenuHelper.getLUSOTrigger(m_algoAutoSelect, m_refPrescaleSet, m_l1GtUtils);
0356   m_selectedTriggers.insert(tAutoSelTrig.begin(), tAutoSelTrig.end());
0357 
0358   // Initializing DQM Monitor Elements
0359   ibooker.setCurrentFolder("L1T/L1TSync");
0360   m_ErrorMonitor = ibooker.book1D("ErrorMonitor", "ErrorMonitor", 7, 0, 7);
0361   m_ErrorMonitor->setBinLabel(UNKNOWN, "UNKNOWN");
0362   m_ErrorMonitor->setBinLabel(WARNING_DB_CONN_FAILED, "WARNING_DB_CONN_FAILED");    // Errors from L1TOMDSHelper
0363   m_ErrorMonitor->setBinLabel(WARNING_DB_QUERY_FAILED, "WARNING_DB_QUERY_FAILED");  // Errors from L1TOMDSHelper
0364   m_ErrorMonitor->setBinLabel(WARNING_DB_INCORRECT_NBUNCHES,
0365                               "WARNING_DB_INCORRECT_NBUNCHES");  // Errors from L1TOMDSHelper
0366   m_ErrorMonitor->setBinLabel(ERROR_UNABLE_RETRIVE_PRODUCT, "ERROR_UNABLE_RETRIVE_PRODUCT");
0367   m_ErrorMonitor->setBinLabel(ERROR_TRIGGERALIAS_NOTVALID, "ERROR_TRIGGERALIAS_NOTVALID");
0368   m_ErrorMonitor->setBinLabel(ERROR_LSBLOCK_NOTVALID, "ERROR_LSBLOCK_NOTVALID");
0369 
0370   // Looping over selected triggers
0371   for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
0372     string tCategory = (*i).first;
0373     string tTrigger = (*i).second;
0374 
0375     // Initializing LS blocks for certification
0376     m_certFirstLS[(*i).second] = 0;
0377     m_certLastLS[(*i).second] = 0;
0378 
0379     // Initializing DQM Monitors
0380     ibooker.setCurrentFolder("L1T/L1TSync/AlgoVsBunchStructure/");
0381     m_algoVsBunchStructure[tTrigger] = ibooker.book2D(
0382         tCategory, "min #Delta(" + tTrigger + ",Bunch)", maxNbins, -0.5, double(maxNbins) - 0.5, 5, -2.5, 2.5);
0383     m_algoVsBunchStructure[tTrigger]->setAxisTitle("Lumi Section", 1);
0384 
0385     ibooker.setCurrentFolder("L1T/L1TSync/Certification/");
0386     m_algoCertification[tTrigger] =
0387         ibooker.book1D(tCategory, "fraction of in sync: " + tTrigger, maxNbins, -0.5, double(maxNbins) - 0.5);
0388     m_algoCertification[tTrigger]->setAxisTitle("Lumi Section", 1);
0389   }
0390 }
0391 
0392 //_____________________________________________________________________
0393 // Function: globalBeginLuminosityBlock
0394 //_____________________________________________________________________
0395 std::shared_ptr<ltso::LSValid> L1TSync_Offline::globalBeginLuminosityBlock(LuminosityBlock const& lumiBlock,
0396                                                                            EventSetup const& c) const {
0397   if (m_verbose) {
0398     cout << "[L1TSync_Offline] Called beginLuminosityBlock." << endl;
0399   }
0400 
0401   return std::make_shared<ltso::LSValid>();
0402 }
0403 
0404 //_____________________________________________________________________
0405 void L1TSync_Offline::analyze(const Event& iEvent, const EventSetup& eventSetup) {
0406   if (m_verbose) {
0407     cout << "[L1TSync_Offline] Called analyze." << endl;
0408   }
0409 
0410   // We only start analyzing if current LS is still valid
0411   auto& currentLSValid = luminosityBlockCache(iEvent.getLuminosityBlock().index())->lsIsValid;
0412   if (currentLSValid) {
0413     if (m_verbose) {
0414       cout << "[L1TSync_Offline] -> currentLSValid=" << currentLSValid << endl;
0415     }
0416 
0417     // Retriving information from GT
0418     edm::Handle<L1GlobalTriggerEvmReadoutRecord> gtEvmReadoutRecord;
0419     iEvent.getByToken(m_l1GtEvmSource, gtEvmReadoutRecord);
0420 
0421     // Determining beam mode and fill number
0422     if (gtEvmReadoutRecord.isValid()) {
0423       const L1GtfeExtWord& gtfeEvmWord = gtEvmReadoutRecord->gtfeWord();
0424       unsigned int lhcBeamMode = gtfeEvmWord.beamMode();  // Updating beam mode
0425 
0426       if (m_lhcFill == 0) {
0427         m_lhcFill = gtfeEvmWord.lhcFillNumber();  // Getting LHC Fill Number from GT
0428 
0429         //I AM HERE
0430         getBeamConfOffline(iEvent);  // Getting Beam Configuration from OMDS
0431                                      // no OMDS //
0432                                      /* (Savannah ticket https://savannah.cern.ch/task/?31857 )
0433       Purged the OMDS helper from the module, since apparently we don't have access to that information from Offline.
0434       The comparison with the closest BPTX trigger will be performed via conditions objects which are being implemented by Joao Pela.
0435       In the meantime, for being able to test the module, he suggested to pass the correct bunch structure by hand for the specific run which is run during the test.
0436       The idea of the temporary fix is setting the vector variable that stores the bunch structure either by hand or filling it with the BPTX fires (that is check for the event the BX's where tech0 fired and set those as true in the vector.
0437     */
0438         // no OMDS //    m_beamConfig = myOMDSHelper.getBeamConfiguration(m_lhcFill,errorRetrieve); Yuhuuu!!!OB asked Joao Pela how to fetch that
0439       }
0440 
0441       if (lhcBeamMode != STABLE) {
0442         currentLSValid = false;
0443         if (m_verbose) {
0444           cout << "[L1TSync_Offline] -> currentLSValid=" << currentLSValid << "because beams mode not stable, being "
0445                << lhcBeamMode << endl;
0446         }
0447       }  // If Beams are not stable we invalidate this LS
0448     } else {
0449       int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT);
0450       eCount++;
0451       m_ErrorMonitor->getTH1()->SetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT, eCount);
0452     }
0453   } else {
0454     if (m_verbose) {
0455       cout << "[L1TSync_Offline] -> currentLSValid=" << currentLSValid << endl;
0456     }
0457   }
0458 
0459   // Commenting out un-necessary  print outs (S.Dutta)
0460   /*  for(size_t l=0; l<m_beamConfig.beam1.size(); l++){
0461     cout << "Beam 1: element " << l << " is in state " << m_beamConfig.beam1[l] << " --- Beam 2: element " << l << " is in state " << m_beamConfig.beam2[l] << endl;
0462     }*/
0463   //------------------------------------------------------------------------------
0464   // If current LS is valid and Beam Configuration is Valid we analyse this event
0465   //------------------------------------------------------------------------------
0466   if (currentLSValid && m_beamConfig.isValid()) {
0467     // Getting Final Decision Logic (FDL) Data from GT
0468     edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecordData;
0469     iEvent.getByToken(m_l1GtDataDaqInputTag, gtReadoutRecordData);
0470 
0471     if (gtReadoutRecordData.isValid()) {
0472       const vector<L1GtFdlWord>& gtFdlVectorData = gtReadoutRecordData->gtFdlVector();
0473 
0474       // Running over selected triggers
0475       for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
0476         string tTrigger = (*i).second;
0477 
0478         // Analyse only defined triggers
0479         if (tTrigger != "Undefined" && tTrigger != "Undefined (Wrong Name)") {
0480           bool beamSingleConfig = false;  // Single beam configured for this event
0481           bool firedAlgo = false;         // Algo fired in this event
0482           unsigned int eventBx = ~0;
0483 
0484           // Running over FDL results to get which bits fired
0485           for (unsigned int a = 0; a < gtFdlVectorData.size(); a++) {
0486             // Selecting the FDL that triggered
0487             if (gtFdlVectorData[a].bxInEvent() == 0) {
0488               eventBx = gtFdlVectorData[a].localBxNr();
0489               if (gtFdlVectorData[a].gtDecisionWord()[m_algoBit[tTrigger]]) {
0490                 firedAlgo = true;
0491               }
0492             }
0493           }
0494 
0495           // Checking beam configuration
0496           if (m_beamConfig.beam1.size() > eventBx && m_beamConfig.beam2.size() > eventBx) {
0497             if (m_beamConfig.beam1[eventBx] && !m_beamConfig.beam2[eventBx]) {
0498               beamSingleConfig = true;
0499             }
0500             if (!m_beamConfig.beam1[eventBx] && m_beamConfig.beam2[eventBx]) {
0501               beamSingleConfig = true;
0502             }
0503           }
0504           // Analyse only if this trigger fired in this event
0505           // NOTE: Veto cases where a single beam is configured since
0506           //       for this cases this could be a real-satelite bunch collision
0507           // -> Calculate the minimum bx diference between this event and a configured bx
0508           if (firedAlgo && !beamSingleConfig) {
0509             int DifAlgoVsBunchStructure = 9999;  // Majorated
0510 
0511             for (unsigned int a = 0; a < gtFdlVectorData.size(); a++) {
0512               int bxFDL = gtFdlVectorData[a].localBxNr();
0513               int bxInEvent = gtFdlVectorData[a].bxInEvent();
0514 
0515               if (m_beamConfig.bxConfig(bxFDL) && abs(bxInEvent) < abs(DifAlgoVsBunchStructure)) {
0516                 DifAlgoVsBunchStructure = -1 * bxInEvent;
0517               }
0518             }
0519 
0520             m_algoVsBunchStructure[tTrigger]->Fill(0 /*m_currentLS*/, DifAlgoVsBunchStructure);
0521           }
0522         }
0523       }
0524     } else {
0525       int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT);
0526       eCount++;
0527       m_ErrorMonitor->getTH1()->SetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT, eCount);
0528     }
0529   }
0530 }
0531 
0532 //_____________________________________________________________________
0533 // Method: getBunchStructureOffline
0534 // Description: Attempt to retrive Beam Configuration from Offline and if
0535 //              we find error handle it
0536 //_____________________________________________________________________
0537 void L1TSync_Offline::getBeamConfOffline(const Event& iEvent) {
0538   //Getting connection parameters
0539   //  [11:21:35] Pietro Vischia: pathCondDB and oracleDB are available in offline?
0540   //  [11:21:51] Joao Pela: no
0541   //  [11:21:56] Pietro Vischia: cool
0542   //  [11:21:58] Pietro Vischia: tks
0543   //  [11:22:00] Joao Pela: well
0544   //  [11:22:02] Joao Pela: maybe
0545   //  [11:22:05] Joao Pela: but assume no
0546   //  [11:22:22] Joao Pela: definitely assume no
0547   // *** UPDATE: now we have a DB for Rate parameters, it would be useful to have s.th also for L1TSync
0548 
0549   // string oracleDB   = m_parameters.getParameter<string>("oracleDB");
0550   // string pathCondDB = m_parameters.getParameter<string>("pathCondDB");
0551 
0552   //  m_beamConfig = myOMDSHelper.getBeamConfiguration(m_lhcFill,errorRetrieve);
0553   //  m_lhcFill -> lhcFillNumber
0554   //  errorRetrieve -> error
0555   // m_beamConfig -> bConfig
0556 
0557   // No error codes at the moment. Taking info from BPTX fires
0558   //  int errorRetrieve = 0; // NO_ERROR;
0559   m_beamConfig.m_valid = true;
0560 
0561   //  bool beamSingleConfig = false; // Single beam configured for this event
0562   bool firedAlgo = false;  // Algo fired in this event
0563   //  int  eventBx          = -1;
0564 
0565   // Running over FDL results to get which bits fired for BPTX (temporary fix Savannah ticket https://savannah.cern.ch/task/?31857 )
0566   // Getting Final Decision Logic (FDL) Data from GT
0567   edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecordData;
0568   iEvent.getByToken(m_l1GtDataDaqInputTag, gtReadoutRecordData);
0569 
0570   if (gtReadoutRecordData.isValid()) {
0571     const vector<L1GtFdlWord>& gtFdlVectorData = gtReadoutRecordData->gtFdlVector();
0572 
0573     for (unsigned int a = 0; a < gtFdlVectorData.size(); a++) {
0574       // Selecting the FDL that triggered
0575       if (gtFdlVectorData[a].bxInEvent() == 0) {
0576         //eventBx = gtFdlVectorData[a].localBxNr();
0577         if (gtFdlVectorData[a].gtDecisionWord()[m_algoBit[m_selectedTriggers["BPTX"]]]) {
0578           firedAlgo = true;
0579         }
0580       }
0581 
0582       // Fill beam status with BPTX fires
0583       if (firedAlgo) {
0584         m_beamConfig.beam1.push_back(true);
0585         m_beamConfig.beam2.push_back(true);
0586       } else {
0587         m_beamConfig.beam1.push_back(false);
0588         m_beamConfig.beam2.push_back(false);
0589       }
0590       // End fill beam status with BPTX fires
0591     }  // End loop on FDL
0592   }    // End if readout is valid
0593 }
0594 
0595 //_____________________________________________________________________
0596 // Method: doFractionInSync
0597 // Description: Produce plot with the fraction of in sync trigger for
0598 //              LS blocks with enough statistics.
0599 // Variable: iForce - Forces closing of all blocks and calculation of
0600 //                    the respective fractions
0601 // Variable: iBad   - (Only works with iForce=true) Forces the current
0602 //                    all current blocks to be marked as bad
0603 //_____________________________________________________________________
0604 //void L1TSync_Offline::doFractionInSync(bool iForce,bool iBad){
0605 //
0606 /////  for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
0607 /////
0608 /////    string theCategory     = (*i).first;
0609 /////    string theTriggerAlias = (*i).second;
0610 /////
0611 /////    // Caching frequently used values from maps
0612 /////    unsigned int fLS = m_certFirstLS[theTriggerAlias];
0613 /////    unsigned int lLS = m_certLastLS [theTriggerAlias];
0614 /////
0615 /////    // Checking validity of the trigger alias and of the LS block
0616 /////    bool triggerAlias_isValid = theTriggerAlias != "Undefined" && theTriggerAlias != "Undefined (Wrong Name)";
0617 /////    bool lsBlock_exists       = !(fLS == 0 && lLS == 0);
0618 /////    bool lsBlock_isValid      = fLS <= lLS && fLS > 0 && lLS > 0;
0619 /////
0620 /////    if(triggerAlias_isValid && lsBlock_exists && lsBlock_isValid){
0621 /////
0622 /////      // If we are forced to close blocks and mark them bad
0623 /////      if(iForce && iBad){
0624 /////        certifyLSBlock(theTriggerAlias,fLS,lLS,-1);
0625 /////        m_certFirstLS[theTriggerAlias] = 0;
0626 /////        m_certLastLS [theTriggerAlias] = 0;
0627 /////      }
0628 /////
0629 /////      // If we are not forced to mark bad, we check if we have enough statistics
0630 /////      else{
0631 /////
0632 /////        // Getting events with 0 bx difference between BPTX and Algo for current LS
0633 /////        double CountSync = 0;
0634 /////        double CountAll  = 0;
0635 /////
0636 /////        // Adding all entries for current LS block
0637 /////        for(unsigned int ls=fLS ; ls<=lLS ; ls++){
0638 /////
0639 /////          CountSync += m_algoVsBunchStructure[theTriggerAlias]->getBinContent(ls+1,3);
0640 /////          for(int a=1 ; a<6 ; a++){
0641 /////            CountAll  += m_algoVsBunchStructure[theTriggerAlias]->getBinContent(ls+1,a);
0642 /////          }
0643 /////        }
0644 /////
0645 /////        if(m_verbose){
0646 /////          cout << "Alias = " << theTriggerAlias
0647 /////               << " InitLS=" << fLS
0648 /////               << " EndLS=" <<  lLS
0649 /////               << " Events=" << CountAll ;
0650 /////        }
0651 /////
0652 /////        if(iForce ||
0653 /////           CountAll >= m_parameters.getParameter<ParameterSet>("Categories")
0654 /////                                   .getParameter<ParameterSet>(theCategory)
0655 /////                                   .getParameter<int>("CertMinEvents")){
0656 /////
0657 /////          if(m_verbose){cout << " <--------------- Enough Statistics: ";}
0658 /////
0659 /////
0660 /////          // Calculating fraction of in time
0661 /////          double fraction = 0;
0662 /////          if(CountAll >0){fraction = CountSync/CountAll;}
0663 /////
0664 /////          // This is to avoid having an entry equal to zero and thus
0665 /////          // disregarded by the automatic tests
0666 /////          if(fraction==0){fraction=0.000001;}
0667 /////
0668 /////          certifyLSBlock(theTriggerAlias,fLS,lLS,fraction);
0669 /////          m_certFirstLS[theTriggerAlias] = 0;
0670 /////          m_certLastLS [theTriggerAlias] = 0;
0671 /////        }
0672 /////
0673 /////        if(m_verbose){cout << endl;}
0674 /////
0675 /////      }
0676 /////    }
0677 /////
0678 /////    // A problem was found. We report it and set a not physical vale (-1) to the certification plot
0679 /////    else{
0680 /////
0681 /////      // If trigger alias is not valid report it to m_ErrorMonitor
0682 /////      if(!triggerAlias_isValid){
0683 /////        int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_TRIGGERALIAS_NOTVALID);
0684 /////        eCount++;
0685 /////        m_ErrorMonitor->getTH1()->SetBinContent(ERROR_TRIGGERALIAS_NOTVALID,eCount);
0686 /////        certifyLSBlock(theTriggerAlias,fLS,lLS,-1);
0687 /////        m_certFirstLS[theTriggerAlias] = 0;
0688 /////        m_certLastLS [theTriggerAlias] = 0;
0689 /////      }
0690 /////
0691 /////      // If LS Block is not valid report it to m_ErrorMonitor
0692 /////      if(lsBlock_exists && !lsBlock_isValid){
0693 /////        int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_LSBLOCK_NOTVALID);
0694 /////        eCount++;
0695 /////        m_ErrorMonitor->getTH1()->SetBinContent(ERROR_LSBLOCK_NOTVALID,eCount);
0696 /////        certifyLSBlock(theTriggerAlias,fLS,lLS,-1);
0697 /////        m_certFirstLS[theTriggerAlias] = 0;
0698 /////        m_certLastLS [theTriggerAlias] = 0;
0699 /////      }
0700 /////
0701 /////    }
0702 /////  }
0703 /////
0704 //}
0705 
0706 //_____________________________________________________________________
0707 // Method: certifyLSBlock
0708 // Description: Fill the trigger certification plot by blocks
0709 // Variable: iTrigger - Which trigger to certify
0710 // Variable: iInitLs  - Blocks initial LS
0711 // Variable: iEndLs   - Blocks end LS
0712 // Variable: iValue   - Value to be used to fill
0713 //_____________________________________________________________________
0714 //void L1TSync_Offline::certifyLSBlock(string iTrigger, int iInitLs, int iEndLs ,float iValue){
0715 //
0716 /////  // Finding correct bins in the histogram for this block
0717 /////  int binInit = m_algoCertification[iTrigger]->getTH1()->FindBin(iInitLs);
0718 /////  int binEnd  = m_algoCertification[iTrigger]->getTH1()->FindBin(iEndLs);
0719 /////
0720 /////  for(int ls=binInit ; ls<=binEnd ; ls++){
0721 /////    m_algoCertification[iTrigger]->setBinContent(ls,iValue);
0722 /////  }
0723 //
0724 //}
0725 
0726 //define this as a plug-in
0727 DEFINE_FWK_MODULE(L1TSync_Offline);