Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // L1TMonitor includes
0002 #include "DQMOffline/L1Trigger/interface/L1TRate_Offline.h"
0003 
0004 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
0005 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenuFwd.h"
0006 #include "CondFormats/L1TObjects/interface/L1GtPrescaleFactors.h"
0007 #include "CondFormats/L1TObjects/interface/L1GtTriggerMask.h"             // L1Gt - Masks
0008 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskAlgoTrigRcd.h"  // L1Gt - Masks
0009 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
0010 #include "CondFormats/DataRecord/interface/L1GtPrescaleFactorsAlgoTrigRcd.h"
0011 
0012 #include "TList.h"
0013 
0014 using namespace edm;
0015 using namespace std;
0016 
0017 //_____________________________________________________________________
0018 L1TRate_Offline::L1TRate_Offline(const ParameterSet& ps)
0019     : m_menuToken(esConsumes<edm::Transition::BeginRun>()),
0020       m_l1GtPfAlgoToken(esConsumes<edm::Transition::BeginRun>()),
0021       m_helperTokens(L1TMenuHelper::consumes<edm::Transition::BeginRun>(consumesCollector())),
0022       m_l1GtUtils(ps, consumesCollector(), false, *this) {
0023   m_maxNbins = 2500;  // Maximum LS for each run (for binning purposes)
0024   m_parameters = ps;
0025 
0026   // Mapping parameter input variables
0027   m_scalersSource_LSCollection =
0028       consumes<LumiScalersCollection>(m_parameters.getParameter<InputTag>("inputTagScalersResults"));
0029   m_scalersSource_L1TSCollection =
0030       consumes<Level1TriggerScalersCollection>(m_parameters.getParameter<InputTag>("inputTagScalersResults"));
0031   m_l1GtDataDaqInputTag =
0032       consumes<L1GlobalTriggerReadoutRecord>(m_parameters.getParameter<InputTag>("inputTagL1GtDataDaq"));
0033   m_verbose = m_parameters.getUntrackedParameter<bool>("verbose", false);
0034   m_refPrescaleSet = m_parameters.getParameter<int>("refPrescaleSet");
0035   m_lsShiftGTRates = m_parameters.getUntrackedParameter<int>("lsShiftGTRates", 0);
0036 
0037   // Getting which categories to monitor
0038   ParameterSet Categories = ps.getParameter<ParameterSet>("categories");
0039   m_inputCategories["Mu"] = Categories.getUntrackedParameter<bool>("Mu");
0040   m_inputCategories["EG"] = Categories.getUntrackedParameter<bool>("EG");
0041   m_inputCategories["IsoEG"] = Categories.getUntrackedParameter<bool>("IsoEG");
0042   m_inputCategories["Jet"] = Categories.getUntrackedParameter<bool>("Jet");
0043   m_inputCategories["CenJet"] = Categories.getUntrackedParameter<bool>("CenJet");
0044   m_inputCategories["ForJet"] = Categories.getUntrackedParameter<bool>("ForJet");
0045   m_inputCategories["TauJet"] = Categories.getUntrackedParameter<bool>("TauJet");
0046   m_inputCategories["ETM"] = Categories.getUntrackedParameter<bool>("ETM");
0047   m_inputCategories["ETT"] = Categories.getUntrackedParameter<bool>("ETT");
0048   m_inputCategories["HTT"] = Categories.getUntrackedParameter<bool>("HTT");
0049   m_inputCategories["HTM"] = Categories.getUntrackedParameter<bool>("HTM");
0050 
0051   // Initializing Variables
0052   if (m_verbose) {
0053     cout << "[L1TRate_Offline:] ____________ Storage initialization ____________ " << endl;
0054     cout << "[L1TRate_Offline:] Setting up dbe folder: L1T/L1TRate" << endl;
0055   }
0056 }
0057 
0058 //_____________________________________________________________________
0059 L1TRate_Offline::~L1TRate_Offline() {}
0060 
0061 //_____________________________________________________________________
0062 // BeginRun: as input you get filtered events...
0063 //_____________________________________________________________________
0064 void L1TRate_Offline::bookHistograms(DQMStore::IBooker& ibooker, const edm::Run& run, const edm::EventSetup& iSetup) {
0065   if (m_verbose) {
0066     cout << "[L1TRate_Offline:] Called beginRun." << endl;
0067   }
0068 
0069   const L1GtTriggerMenu& menu = iSetup.getData(m_menuToken);
0070   const L1GtPrescaleFactors& l1GtPfAlgo = iSetup.getData(m_l1GtPfAlgoToken);
0071 
0072   // Initializing DQM Monitor Elements
0073   ibooker.setCurrentFolder("L1T/L1TRate");
0074   m_ErrorMonitor = ibooker.book1D("ErrorMonitor", "ErrorMonitor", 2, 0, 2);
0075   m_ErrorMonitor->setBinLabel(UNKNOWN, "UNKNOWN");
0076   m_ErrorMonitor->setBinLabel(WARNING_PY_MISSING_FIT, "WARNING_PY_MISSING_FIT");
0077 
0078   if (m_verbose) {
0079     cout << "[L1TRate_Offline:] m_ErrorMonitor: " << m_ErrorMonitor << endl;
0080   }
0081 
0082   // Retriving the list of prescale sets
0083   m_listsPrescaleFactors = &(l1GtPfAlgo.gtPrescaleFactors());
0084 
0085   // Getting Lowest Prescale Single Object Triggers from the menu
0086   L1TMenuHelper myMenuHelper = L1TMenuHelper(iSetup, m_helperTokens);
0087   m_l1GtUtils.retrieveL1EventSetup(iSetup);
0088   m_selectedTriggers = myMenuHelper.getLUSOTrigger(m_inputCategories, m_refPrescaleSet, m_l1GtUtils);
0089 
0090   //-> Getting template fits for the algLo cross sections
0091   getXSexFitsPython(m_parameters);
0092 
0093   for (const auto& algo : menu.gtAlgorithmMap()) {
0094     m_algoBit[(algo.second).algoAlias()] = (algo.second).algoBitNumber();
0095   }
0096 
0097   double minInstantLuminosity = m_parameters.getParameter<double>("minInstantLuminosity");
0098   double maxInstantLuminosity = m_parameters.getParameter<double>("maxInstantLuminosity");
0099 
0100   // Initializing DQM Monitor Elements
0101   for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
0102     TString tCategory = (*i).first;
0103     TString tTrigger = (*i).second;
0104 
0105     TString tErrorMessage = "";
0106     TF1* tTestFunction;
0107 
0108     if (tTrigger != "Undefined" && m_templateFunctions.find(tTrigger) != m_templateFunctions.end()) {
0109       tTestFunction = m_templateFunctions[tTrigger];
0110     } else if (tTrigger == "Undefined") {
0111       TString tFunc = "-1";
0112       tTestFunction = new TF1("FitParametrization_" + tTrigger, tFunc, 0, double(m_maxNbins) - 0.5);
0113     } else if (m_templateFunctions.find(tTrigger) == m_templateFunctions.end()) {
0114       TString tFunc = "-1";
0115       tTestFunction = new TF1("FitParametrization_" + tTrigger, tFunc, 0, double(m_maxNbins) - 0.5);
0116       tErrorMessage = " (Undefined Test Function)";
0117     } else {
0118       TString tFunc = "-1";
0119       tTestFunction = new TF1("FitParametrization_" + tTrigger, tFunc, 0, double(m_maxNbins) - 0.5);
0120     }
0121 
0122     if (tTrigger != "Undefined") {
0123       if (myMenuHelper.getPrescaleByAlias(tCategory, tTrigger) != 1) {
0124         tErrorMessage += " WARNING: Default Prescale = ";
0125         tErrorMessage += myMenuHelper.getPrescaleByAlias(tCategory, tTrigger);
0126       }
0127 
0128       if (tCategory == "Mu" &&
0129           myMenuHelper.getEtaRangeByAlias(tCategory, tTrigger) != 4294967295) {  //hexadecimal of the whole range
0130         tErrorMessage += " WARNING: Eta Range = ";
0131         tErrorMessage += myMenuHelper.getEtaRangeByAlias(tCategory, tTrigger);
0132       } else if (tCategory == "EG" && myMenuHelper.getEtaRangeByAlias(tCategory, tTrigger) != 32639) {
0133         tErrorMessage += " WARNING: Eta Range = ";
0134         tErrorMessage += myMenuHelper.getEtaRangeByAlias(tCategory, tTrigger);
0135       } else if (tCategory == "IsoEG" && myMenuHelper.getEtaRangeByAlias(tCategory, tTrigger) != 32639) {
0136         tErrorMessage += " WARNING: Eta Range = ";
0137         tErrorMessage += myMenuHelper.getEtaRangeByAlias(tCategory, tTrigger);
0138       }
0139 
0140       if (tCategory == "Mu" && myMenuHelper.getQualityAlias(tCategory, tTrigger) != 240) {
0141         tErrorMessage += " WARNING: Quality = ";
0142         tErrorMessage += myMenuHelper.getQualityAlias(tCategory, tTrigger);
0143       }
0144     }
0145 
0146     ibooker.setCurrentFolder("L1T/L1TRate/xSecDelivLumi");  // trigger counts...
0147     m_xSecObservedVsDelivLumi[tTrigger] = ibooker.bookProfile(tCategory,
0148                                                               "Cross Sec. vs Deliv. Lumi: " + tTrigger + tErrorMessage,
0149                                                               m_maxNbins,
0150                                                               minInstantLuminosity,
0151                                                               maxInstantLuminosity,
0152                                                               0,
0153                                                               500);
0154     m_xSecObservedVsDelivLumi[tTrigger]->setAxisTitle("Delivered Luminosity [10^{30}cm^{-2}s^{-1}]", 1);
0155     m_xSecObservedVsDelivLumi[tTrigger]->setAxisTitle("Algorithm #sigma [#mu b]", 2);
0156 
0157     ibooker.setCurrentFolder("L1T/L1TRate/xSecRecorLumi");  // trigger counts...
0158     m_xSecObservedVsRecorLumi[tTrigger] = ibooker.bookProfile(tCategory,
0159                                                               "Cross Sec. vs Recor. Lumi: " + tTrigger + tErrorMessage,
0160                                                               m_maxNbins,
0161                                                               minInstantLuminosity,
0162                                                               maxInstantLuminosity,
0163                                                               0,
0164                                                               500);
0165     m_xSecObservedVsRecorLumi[tTrigger]->setAxisTitle("Recorded Luminosity [10^{30}cm^{-2}s^{-1}]", 1);
0166     m_xSecObservedVsRecorLumi[tTrigger]->setAxisTitle("Algorithm #sigma [#mu b]", 2);
0167 
0168     ibooker.setCurrentFolder("L1T/L1TRate/TriggerCounts");  // trigger counts...
0169     m_CountsVsLS[tTrigger] = ibooker.bookProfile(tCategory,
0170                                                  "Cross Sec. vs Inst. Lumi Algo: " + tTrigger + tErrorMessage,
0171                                                  m_maxNbins,
0172                                                  minInstantLuminosity,
0173                                                  maxInstantLuminosity,
0174                                                  0,
0175                                                  500);
0176     m_CountsVsLS[tTrigger]->setAxisTitle("Instantaneous Luminosity [10^{30}cm^{-2}s^{-1}]", 1);
0177     m_CountsVsLS[tTrigger]->setAxisTitle("Algorithm #sigma [#mu b]", 2);
0178     m_CountsVsLS[tTrigger]->getTProfile()->GetListOfFunctions()->Add(tTestFunction);
0179     m_CountsVsLS[tTrigger]->getTProfile()->SetMarkerStyle(23);
0180 
0181     m_algoFit[tTrigger] = (TF1*)tTestFunction->Clone("Fit_" + tTrigger);  // NOTE: Workaround
0182 
0183     ibooker.setCurrentFolder("L1T/L1TRate/xSecObs");
0184     m_xSecObservedVsLS[tTrigger] =
0185         ibooker.book1D(tCategory, "Algo: " + tTrigger + tErrorMessage, m_maxNbins, -0.5, double(m_maxNbins) - 0.5);
0186     m_xSecObservedVsLS[tTrigger]->setAxisTitle("Lumi Section", 1);
0187     m_xSecObservedVsLS[tTrigger]->setAxisTitle("#sigma_{obs}", 2);
0188 
0189     ibooker.setCurrentFolder("L1T/L1TRate/Delivered");
0190     m_DelivLumiVsLS[tTrigger] =
0191         ibooker.book1D(tCategory, "Algo: " + tTrigger + tErrorMessage, m_maxNbins, -0.5, double(m_maxNbins) - 0.5);
0192     m_DelivLumiVsLS[tTrigger]->setAxisTitle("Lumi Section", 1);
0193     m_DelivLumiVsLS[tTrigger]->setAxisTitle("Deliv. Lumi", 2);
0194 
0195     ibooker.setCurrentFolder("L1T/L1TRate/Recorded");
0196     m_RecorLumiVsLS[tTrigger] =
0197         ibooker.book1D(tCategory, "Algo: " + tTrigger + tErrorMessage, m_maxNbins, -0.5, double(m_maxNbins) - 0.5);
0198     m_RecorLumiVsLS[tTrigger]->setAxisTitle("Lumi Section", 1);
0199     m_RecorLumiVsLS[tTrigger]->setAxisTitle("Recor. Lumi", 2);
0200 
0201     ibooker.setCurrentFolder("L1T/L1TRate/Ratio");
0202     m_xSecObservedToExpected[tTrigger] =
0203         ibooker.book1D(tCategory, "Algo: " + tTrigger + tErrorMessage, m_maxNbins, -0.5, double(m_maxNbins) - 0.5);
0204     m_xSecObservedToExpected[tTrigger]->setAxisTitle("Lumi Section", 1);
0205     m_xSecObservedToExpected[tTrigger]->setAxisTitle("#sigma_{obs} / #sigma_{exp}", 2);
0206   }
0207 }
0208 
0209 //_____________________________________________________________________
0210 void L1TRate_Offline::beginLuminosityBlock(LuminosityBlock const& lumiBlock, EventSetup const& c) {
0211   if (m_verbose) {
0212     cout << "[L1TRate_Offline:] Called beginLuminosityBlock at LS=" << lumiBlock.id().luminosityBlock() << endl;
0213   }
0214 }
0215 
0216 //_____________________________________________________________________
0217 void L1TRate_Offline::endLuminosityBlock(LuminosityBlock const& lumiBlock, EventSetup const& c) {
0218   int eventLS = lumiBlock.id().luminosityBlock();
0219   if (m_verbose) {
0220     cout << "[L1TRate_Offline:] Called endLuminosityBlock at LS=" << eventLS << endl;
0221   }
0222 
0223   // We can certify LS -1 since we should have available:
0224   // gt rates: (current LS)-1
0225   // prescale: current LS
0226   // lumi    : current LS
0227   //eventLS--;
0228 
0229   // Checking if all necessary quantities are defined for our calculations
0230   //bool isDefRate,isDefLumi,isDefPrescaleIndex;
0231   bool isDefLumi, isDefPrescaleIndex;
0232   //map<TString,double>* rates=0;
0233   double lumi = 0;
0234   double deadtime = 0;
0235   unsigned int prescalesIndex = 0;
0236 
0237   bool isDefCount;
0238   map<TString, double>* counts = nullptr;
0239 
0240   // Resetting MonitorElements so we can refill them
0241   for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
0242     string tTrigger = (*i).second;
0243     //    m_DeadTimeVsLS          [tTrigger]->getTH1()->Reset("ICE");
0244     m_CountsVsLS[tTrigger]->getTH1()->Reset("ICE");
0245     m_xSecObservedToExpected[tTrigger]->getTH1()->Reset("ICE");
0246 
0247     m_xSecObservedVsLS[tTrigger]->getTH1()->Reset("ICE");
0248     m_DelivLumiVsLS[tTrigger]->getTH1()->Reset("ICE");
0249     m_RecorLumiVsLS[tTrigger]->getTH1()->Reset("ICE");
0250 
0251     m_xSecObservedVsDelivLumi[tTrigger]->getTH1()->Reset("ICE");
0252     m_xSecObservedVsRecorLumi[tTrigger]->getTH1()->Reset("ICE");
0253   }
0254 
0255   //Trying to do the same with Counts....
0256   for (map<int, map<TString, double> >::iterator j = m_lsRates.begin(); j != m_lsRates.end(); j++) {
0257     unsigned int lsOffline = (*j).first;
0258     counts = &(*j).second;
0259     isDefCount = true;
0260 
0261     unsigned int lsPreInd;
0262 
0263     if (m_lsLuminosity.find(lsOffline) == m_lsLuminosity.end()) {
0264       isDefLumi = false;
0265     } else {
0266       isDefLumi = true;
0267       lumi = m_lsLuminosity[lsOffline];
0268       deadtime = m_lsDeadTime[lsOffline];
0269     }
0270 
0271     lsPreInd = lsOffline + 1;  // NOTE: Workaround
0272 
0273     if (m_lsPrescaleIndex.find(lsPreInd) == m_lsPrescaleIndex.end()) {
0274       isDefPrescaleIndex = false;
0275     } else {
0276       isDefPrescaleIndex = true;
0277       prescalesIndex = m_lsPrescaleIndex[lsPreInd];
0278     }
0279 
0280     if (isDefCount && isDefLumi && isDefPrescaleIndex && (prescalesIndex < m_listsPrescaleFactors->size())) {
0281       const vector<int>& currentPrescaleFactors = (*m_listsPrescaleFactors).at(prescalesIndex);
0282 
0283       for (map<string, string>::const_iterator j = m_selectedTriggers.begin(); j != m_selectedTriggers.end(); j++) {
0284         string tTrigger = (*j).second;
0285         double trigCount = (*counts)[tTrigger];
0286 
0287         //   TF1*   tTestFunction = (TF1*) m_CountsVsLS[tTrigger]->getTProfile()->GetListOfFunctions()->First();
0288         TF1* tTestFunction = m_algoFit[tTrigger];  // NOTE: Workaround....
0289 
0290         // If trigger name is defined we get the rate fit parameters
0291         if (tTrigger != "Undefined") {
0292           unsigned int trigBit = m_algoBit[tTrigger];
0293           double trigPrescale = currentPrescaleFactors[trigBit];
0294 
0295           if (lumi != 0 && trigCount != 0 && trigPrescale != 0) {
0296             double RecLumi = lumi * (1. - deadtime / 100.);
0297 
0298             double AlgoXSec = (trigPrescale * trigCount) / RecLumi;
0299             double TemplateFunctionValue = tTestFunction->Eval(lumi);
0300 
0301             // Checking against Template function
0302             //            m_DeadTimeVsLS [tTrigger]->Fill(lumi,deadtime);
0303 
0304             m_xSecObservedVsRecorLumi[tTrigger]->Fill(RecLumi, AlgoXSec);
0305 
0306             m_CountsVsLS[tTrigger]->Fill(lumi, AlgoXSec);
0307 
0308             int ibin = m_xSecObservedToExpected[tTrigger]->getTH1()->FindBin(lsOffline);
0309             m_xSecObservedToExpected[tTrigger]->setBinContent(ibin, AlgoXSec / TemplateFunctionValue);
0310 
0311             m_DelivLumiVsLS[tTrigger]->setBinContent(ibin, lumi);
0312             m_RecorLumiVsLS[tTrigger]->setBinContent(ibin, RecLumi);
0313 
0314             m_xSecObservedVsLS[tTrigger]->setBinContent(ibin, AlgoXSec);
0315 
0316           } else {
0317             //            m_DeadTimeVsLS [tTrigger]->Fill(0.000001,0.000001);
0318 
0319             m_xSecObservedVsRecorLumi[tTrigger]->Fill(0.000001, 0.000001);
0320 
0321             m_CountsVsLS[tTrigger]->Fill(0.000001, 0.000001);
0322 
0323             int ibin = m_xSecObservedToExpected[tTrigger]->getTH1()->FindBin(lsOffline);
0324             m_xSecObservedToExpected[tTrigger]->setBinContent(ibin, 0.000001);
0325 
0326             m_DelivLumiVsLS[tTrigger]->setBinContent(ibin, 0.000001);
0327             m_RecorLumiVsLS[tTrigger]->setBinContent(ibin, 0.000001);
0328 
0329             m_xSecObservedVsLS[tTrigger]->setBinContent(ibin, 0.000001);
0330           }
0331         }
0332       }
0333     }
0334   }
0335 }
0336 
0337 //_____________________________________________________________________
0338 void L1TRate_Offline::analyze(const Event& iEvent, const EventSetup& eventSetup) {
0339   edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecordData;
0340   edm::Handle<Level1TriggerScalersCollection> triggerScalers;
0341   edm::Handle<LumiScalersCollection> colLScal;
0342 
0343   iEvent.getByToken(m_l1GtDataDaqInputTag, gtReadoutRecordData);
0344   iEvent.getByToken(m_scalersSource_LSCollection, colLScal);
0345   iEvent.getByToken(m_scalersSource_L1TSCollection, triggerScalers);
0346 
0347   // Integers
0348   int EventRun = iEvent.id().run();
0349   unsigned int eventLS = iEvent.id().luminosityBlock();
0350 
0351   // Getting the trigger trigger rates from GT and buffering it
0352   if (triggerScalers.isValid() && !triggerScalers->empty()) {
0353     Level1TriggerScalersCollection::const_iterator itL1TScalers = triggerScalers->begin();
0354     Level1TriggerRates trigRates(*itL1TScalers, EventRun);
0355 
0356     //Trying to retrieve GT DeadTime
0357     //unsigned long long deadtime = itL1TScalers->deadtime();
0358     //double deadtime = itL1TScalers->deadtime();
0359     double deadtime = trigRates.deadtimePercent();  //correct DeadTime % to retrieve
0360 
0361     // Trying to get the trigger counts
0362     const std::vector<unsigned int> gtAlgoCounts = itL1TScalers->gtAlgoCounts();
0363 
0364     //    int lumisegment = (*itL1TScalers).lumiSegmentNr();
0365 
0366     //     cout << "deadtime =" << deadtime << " --
0367     //    cout << "lumisegment = " << lumisegment << endl;
0368 
0369     int gtLS = (*itL1TScalers).lumiSegmentNr() + m_lsShiftGTRates;
0370 
0371     // If we haven't got the data from this LS yet get it
0372     if (m_lsRates.find(gtLS) == m_lsRates.end()) {
0373       map<TString, double> bufferCount;
0374 
0375       // Buffer the rate informations for all selected bits
0376       for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
0377         string tTrigger = (*i).second;
0378 
0379         // If trigger name is defined we store the rate
0380         if (tTrigger != "Undefined") {
0381           unsigned int trigBit = m_algoBit[tTrigger];
0382           double trigCount = gtAlgoCounts[trigBit];
0383 
0384           bufferCount[tTrigger] = trigCount;
0385         }
0386       }
0387       m_lsRates[gtLS] = bufferCount;
0388       m_lsDeadTime[gtLS] = deadtime;
0389     }
0390   }
0391 
0392   // Getting from the SCAL the luminosity information and buffering it
0393   if (colLScal.isValid() && !colLScal->empty()) {
0394     LumiScalersCollection::const_iterator itLScal = colLScal->begin();
0395     unsigned int scalLS = itLScal->sectionNumber();
0396 
0397     // If we haven't got the data from this SCAL LS yet get it
0398     if (m_lsLuminosity.find(scalLS) == m_lsLuminosity.end()) {
0399       if (m_verbose) {
0400         cout << "[L1TRate_Offline:] Buffering SCAL-HF Lumi for LS=" << scalLS << endl;
0401       }
0402       double instLumi =
0403           itLScal->instantLumi();  // Getting Instant Lumi from HF (via SCAL) // <###### WE NEED TO STORE THIS
0404       double deadTimeNormHF = itLScal->deadTimeNormalization();  // Getting Dead Time Normalization from HF (via SCAL)
0405 
0406       //       double mylumiFill      = itLScal->lumiFill();      // Integrated lumi since beginning of fill, delivered
0407       //       double mylumiRun       = itLScal->lumiRun();       // Integrated lumi since beginning of run, delivered
0408       //       double myliveLumiFill  = itLScal->liveLumiFill();  // Integrated lumi since beginning of fill, live
0409       //       double myliveLumiRun   = itLScal->liveLumiRun();   // Integrated lumi since beginning of run, live
0410       //       double mysectionNumber = itLScal->sectionNumber(); // Lumi section  number for this info
0411       //       double mynumOrbits     = itLScal->numOrbits();     // Number of orbits that have passed this run
0412 
0413       //       cout << "instantLumi = " << instLumi << endl;
0414       //       cout << "lumiFill = " << mylumiFill << endl;
0415       //       cout << "lumiRun = " << mylumiRun << endl;
0416       //       cout << "livelumiFill = " << myliveLumiFill << endl;
0417       //       cout << "livelumiRun = " << myliveLumiRun << endl;
0418       //       cout << "sectionNumber = " << mysectionNumber << endl;
0419       //       cout << "numOrbits = " << mynumOrbits << endl;
0420 
0421       // If HF Dead Time Corrections is requested we apply it
0422       // NOTE: By default this is assumed false since for now WbM fits do NOT assume this correction
0423       if (m_parameters.getUntrackedParameter<bool>("useHFDeadTimeNormalization", false)) {
0424         // Protecting for deadtime = 0
0425         if (deadTimeNormHF == 0) {
0426           instLumi = 0;
0427         } else {
0428           instLumi = instLumi / deadTimeNormHF;
0429         }
0430       }
0431       // Buffering the luminosity information
0432       m_lsLuminosity[scalLS] = instLumi;
0433     }
0434   }
0435 
0436   // Getting the prescale index used when this event was triggered
0437   if (gtReadoutRecordData.isValid()) {
0438     // If we haven't got the data from this LS yet get it
0439     if (m_lsPrescaleIndex.find(eventLS) == m_lsPrescaleIndex.end()) {
0440       if (m_verbose) {
0441         cout << "[L1TRate_Offline:] Buffering Prescale Index for LS=" << eventLS << endl;
0442       }
0443 
0444       // Getting Final Decision Logic (FDL) Data from GT
0445       const vector<L1GtFdlWord>& gtFdlVectorData = gtReadoutRecordData->gtFdlVector();
0446 
0447       // Getting the index for the fdl data for this event
0448       int indexFDL = 0;
0449       for (unsigned int i = 0; i < gtFdlVectorData.size(); i++) {
0450         if (gtFdlVectorData[i].bxInEvent() == 0) {
0451           indexFDL = i;
0452           break;
0453         }
0454       }
0455 
0456       if (!gtFdlVectorData.empty()) {
0457         int CurrentPrescalesIndex =
0458             gtFdlVectorData[indexFDL].gtPrescaleFactorIndexAlgo();  // <###### WE NEED TO STORE THIS
0459         m_lsPrescaleIndex[eventLS] = CurrentPrescalesIndex;
0460       }
0461     }
0462   }
0463 }
0464 
0465 //_____________________________________________________________________
0466 // function: getXSexFitsPython
0467 // Imputs:
0468 //   * const edm::ParameterSet& ps = ParameterSet contaning the fit
0469 //     functions and parameters for the selected triggers
0470 // Outputs:
0471 //   * int error = Number of algos where you did not find a
0472 //     corresponding fit
0473 //_____________________________________________________________________
0474 bool L1TRate_Offline::getXSexFitsPython(const edm::ParameterSet& ps) {
0475   // error meaning
0476   bool noError = true;
0477 
0478   // Getting fit parameters
0479   std::vector<edm::ParameterSet> m_fitParameters = ps.getParameter<vector<ParameterSet> >("fitParameters");
0480 
0481   double minInstantLuminosity = m_parameters.getParameter<double>("minInstantLuminosity");
0482   double maxInstantLuminosity = m_parameters.getParameter<double>("maxInstantLuminosity");
0483 
0484   // Getting rate fit parameters for all input triggers
0485   for (map<string, string>::const_iterator a = m_selectedTriggers.begin(); a != m_selectedTriggers.end(); a++) {
0486     string tTrigger = (*a).second;
0487 
0488     // If trigger name is defined we get the rate fit parameters
0489     if (tTrigger != "Undefined") {
0490       bool foundFit = false;
0491 
0492       for (unsigned int b = 0; b < m_fitParameters.size(); b++) {
0493         if (tTrigger == m_fitParameters[b].getParameter<string>("AlgoName")) {
0494           TString tAlgoName = m_fitParameters[b].getParameter<string>("AlgoName");
0495           TString tTemplateFunction = m_fitParameters[b].getParameter<string>("TemplateFunction");
0496           vector<double> tParameters = m_fitParameters[b].getParameter<vector<double> >("Parameters");
0497 
0498           // Retriving and populating the m_templateFunctions array
0499           m_templateFunctions[tTrigger] =
0500               new TF1("FitParametrization_" + tAlgoName, tTemplateFunction, minInstantLuminosity, maxInstantLuminosity);
0501           m_templateFunctions[tTrigger]->SetParameters(&tParameters[0]);
0502           m_templateFunctions[tTrigger]->SetLineWidth(1);
0503           m_templateFunctions[tTrigger]->SetLineColor(kRed);
0504 
0505           foundFit = true;
0506           break;
0507         }
0508 
0509         if (!foundFit) {
0510           noError = false;
0511 
0512           int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_PY_MISSING_FIT);
0513           eCount++;
0514           m_ErrorMonitor->getTH1()->SetBinContent(WARNING_PY_MISSING_FIT, eCount);
0515         }
0516       }
0517     }
0518   }
0519 
0520   return noError;
0521 }
0522 
0523 //define this as a plug-in
0524 DEFINE_FWK_MODULE(L1TRate_Offline);