CMS 3D CMS Logo

L1TSync.cc
Go to the documentation of this file.
1 /*
2  * \file L1TSync.cc
3  *
4  * \author J. Pela, P. Musella
5  *
6  */
7 
8 //
10 
12 
16 
17 #include "DataFormats/Common/interface/ConditionsInEdm.h" // Parameters associated to Run, LS and Event
18 
25 
26 // Luminosity Information
27 //#include "DataFormats/Luminosity/interface/LumiDetails.h"
28 //#include "DataFormats/Luminosity/interface/LumiSummary.h"
29 
30 #include "TList.h"
31 
32 using namespace edm;
33 using namespace std;
34 
35 //-------------------------------------------------------------------------------------
36 //-------------------------------------------------------------------------------------
38  : m_menuToken(esConsumes<edm::Transition::BeginRun>()),
39  m_helperTokens(L1TMenuHelper::consumes<edm::Transition::BeginRun>(consumesCollector())),
40  m_l1GtUtils(pset, consumesCollector(), false, *this) {
42 
43  // Mapping parameter input variables
44  m_l1GtDataDaqInputTag = consumes<L1GlobalTriggerReadoutRecord>(pset.getParameter<InputTag>("inputTagL1GtDataDaq"));
45  m_l1GtEvmSource = consumes<L1GlobalTriggerEvmReadoutRecord>(pset.getParameter<InputTag>("inputTagtEvmSource"));
46  m_verbose = pset.getUntrackedParameter<bool>("verbose", false);
47  m_refPrescaleSet = pset.getParameter<int>("refPrescaleSet");
48 
49  // Getting which categories to monitor
50  ParameterSet Categories = pset.getParameter<ParameterSet>("Categories");
51 
52  bool forceGlobalParameters = Categories.getParameter<bool>("forceGlobalParameters");
53  bool doGlobalAutoSelection = Categories.getParameter<bool>("doGlobalAutoSelection");
54 
55  ParameterSet CatBPTX = Categories.getParameter<ParameterSet>("BPTX");
56  ParameterSet CatMu = Categories.getParameter<ParameterSet>("Mu");
57  ParameterSet CatEG = Categories.getParameter<ParameterSet>("EG");
58  ParameterSet CatIsoEG = Categories.getParameter<ParameterSet>("IsoEG");
59  ParameterSet CatJet = Categories.getParameter<ParameterSet>("Jet");
60  ParameterSet CatCenJet = Categories.getParameter<ParameterSet>("CenJet");
61  ParameterSet CatForJet = Categories.getParameter<ParameterSet>("ForJet");
62  ParameterSet CatTauJet = Categories.getParameter<ParameterSet>("TauJet");
63  ParameterSet CatETM = Categories.getParameter<ParameterSet>("ETT");
64  ParameterSet CatETT = Categories.getParameter<ParameterSet>("ETM");
65  ParameterSet CatHTT = Categories.getParameter<ParameterSet>("HTT");
66  ParameterSet CatHTM = Categories.getParameter<ParameterSet>("HTM");
67 
68  // --> Setting parameters related to which algos to monitor
69  // If global parameters are forced they take precedence over algo-by-algo parameters
71  // If global automatic selection if enable all categories set to be monitored will have
72  // their algos auto selected (the lowest prescale algo will be selected)
74  if (CatMu.getParameter<bool>("monitor")) {
75  m_algoAutoSelect["Mu"] = true;
76  } else {
77  m_algoAutoSelect["Mu"] = false;
78  }
79  if (CatEG.getParameter<bool>("monitor")) {
80  m_algoAutoSelect["EG"] = true;
81  } else {
82  m_algoAutoSelect["EG"] = false;
83  }
84  if (CatIsoEG.getParameter<bool>("monitor")) {
85  m_algoAutoSelect["IsoEG"] = true;
86  } else {
87  m_algoAutoSelect["IsoEG"] = false;
88  }
89  if (CatJet.getParameter<bool>("monitor")) {
90  m_algoAutoSelect["Jet"] = true;
91  } else {
92  m_algoAutoSelect["Jet"] = false;
93  }
94  if (CatCenJet.getParameter<bool>("monitor")) {
95  m_algoAutoSelect["CenJet"] = true;
96  } else {
97  m_algoAutoSelect["CenJet"] = false;
98  }
99  if (CatForJet.getParameter<bool>("monitor")) {
100  m_algoAutoSelect["ForJet"] = true;
101  } else {
102  m_algoAutoSelect["ForJet"] = false;
103  }
104  if (CatTauJet.getParameter<bool>("monitor")) {
105  m_algoAutoSelect["TauJet"] = true;
106  } else {
107  m_algoAutoSelect["TauJet"] = false;
108  }
109  if (CatETM.getParameter<bool>("monitor")) {
110  m_algoAutoSelect["ETM"] = true;
111  } else {
112  m_algoAutoSelect["ETM"] = false;
113  }
114  if (CatETT.getParameter<bool>("monitor")) {
115  m_algoAutoSelect["ETT"] = true;
116  } else {
117  m_algoAutoSelect["ETT"] = false;
118  }
119  if (CatHTM.getParameter<bool>("monitor")) {
120  m_algoAutoSelect["HTM"] = true;
121  } else {
122  m_algoAutoSelect["HTM"] = false;
123  }
124  if (CatHTT.getParameter<bool>("monitor")) {
125  m_algoAutoSelect["HTT"] = true;
126  } else {
127  m_algoAutoSelect["HTT"] = false;
128  }
129 
130  // If global non-automatic selection is enable all categories set to be monitored will use
131  // user defined algos
132  } else {
133  m_algoAutoSelect["Mu"] = false;
134  m_algoAutoSelect["EG"] = false;
135  m_algoAutoSelect["IsoEG"] = false;
136  m_algoAutoSelect["Jet"] = false;
137  m_algoAutoSelect["CenJet"] = false;
138  m_algoAutoSelect["ForJet"] = false;
139  m_algoAutoSelect["TauJet"] = false;
140  m_algoAutoSelect["ETM"] = false;
141  m_algoAutoSelect["ETT"] = false;
142  m_algoAutoSelect["HTM"] = false;
143  m_algoAutoSelect["HTT"] = false;
144 
145  if (CatMu.getParameter<bool>("monitor")) {
146  m_selectedTriggers["Mu"] = CatMu.getParameter<string>("algo");
147  }
148  if (CatEG.getParameter<bool>("monitor")) {
149  m_selectedTriggers["EG"] = CatEG.getParameter<string>("algo");
150  }
151  if (CatIsoEG.getParameter<bool>("monitor")) {
152  m_selectedTriggers["IsoEG"] = CatIsoEG.getParameter<string>("algo");
153  }
154  if (CatJet.getParameter<bool>("monitor")) {
155  m_selectedTriggers["Jet"] = CatJet.getParameter<string>("algo");
156  }
157  if (CatCenJet.getParameter<bool>("monitor")) {
158  m_selectedTriggers["CenJet"] = CatCenJet.getParameter<string>("algo");
159  }
160  if (CatForJet.getParameter<bool>("monitor")) {
161  m_selectedTriggers["CatForJet"] = CatForJet.getParameter<string>("algo");
162  }
163  if (CatTauJet.getParameter<bool>("monitor")) {
164  m_selectedTriggers["TauJet"] = CatTauJet.getParameter<string>("algo");
165  }
166  if (CatETM.getParameter<bool>("monitor")) {
167  m_selectedTriggers["ETM"] = CatETM.getParameter<string>("algo");
168  }
169  if (CatETT.getParameter<bool>("monitor")) {
170  m_selectedTriggers["ETT"] = CatETT.getParameter<string>("algo");
171  }
172  if (CatHTM.getParameter<bool>("monitor")) {
173  m_selectedTriggers["HTM"] = CatHTM.getParameter<string>("algo");
174  }
175  if (CatHTT.getParameter<bool>("monitor")) {
176  m_selectedTriggers["HTT"] = CatHTT.getParameter<string>("algo");
177  }
178  }
179 
180  // If we are using algo-by-algo parametes we get them and set what is needed
181  } else {
182  if (CatBPTX.getParameter<bool>("monitor")) {
183  m_selectedTriggers["BPTX"] = CatBPTX.getParameter<string>("algo");
184  }
185 
186  if (CatMu.getParameter<bool>("monitor")) {
187  m_algoAutoSelect["Mu"] = CatMu.getParameter<bool>("doAutoSelection");
188  if (!m_algoAutoSelect["Mu"]) {
189  m_selectedTriggers["Mu"] = CatMu.getParameter<string>("algo");
190  }
191  } else {
192  m_algoAutoSelect["Mu"] = false;
193  }
194 
195  if (CatEG.getParameter<bool>("monitor")) {
196  m_algoAutoSelect["EG"] = CatEG.getParameter<bool>("doAutoSelection");
197  if (!m_algoAutoSelect["EG"]) {
198  m_selectedTriggers["EG"] = CatEG.getParameter<string>("algo");
199  }
200  } else {
201  m_algoAutoSelect["EG"] = false;
202  }
203 
204  if (CatIsoEG.getParameter<bool>("monitor")) {
205  m_algoAutoSelect["IsoEG"] = CatIsoEG.getParameter<bool>("doAutoSelection");
206  if (!m_algoAutoSelect["IsoEG"]) {
207  m_selectedTriggers["IsoEG"] = CatIsoEG.getParameter<string>("algo");
208  }
209  } else {
210  m_algoAutoSelect["IsoEG"] = false;
211  }
212 
213  if (CatJet.getParameter<bool>("monitor")) {
214  m_algoAutoSelect["Jet"] = CatJet.getParameter<bool>("doAutoSelection");
215  if (!m_algoAutoSelect["Jet"]) {
216  m_selectedTriggers["Jet"] = CatJet.getParameter<string>("algo");
217  }
218  } else {
219  m_algoAutoSelect["Jet"] = false;
220  }
221 
222  if (CatCenJet.getParameter<bool>("monitor")) {
223  m_algoAutoSelect["CenJet"] = CatCenJet.getParameter<bool>("doAutoSelection");
224  if (!m_algoAutoSelect["CenJet"]) {
225  m_selectedTriggers["CenJet"] = CatCenJet.getParameter<string>("algo");
226  }
227  } else {
228  m_algoAutoSelect["CenJet"] = false;
229  }
230 
231  if (CatForJet.getParameter<bool>("monitor")) {
232  m_algoAutoSelect["CatForJet"] = CatForJet.getParameter<bool>("doAutoSelection");
233  if (!m_algoAutoSelect["CatForJet"]) {
234  m_selectedTriggers["CatForJet"] = CatForJet.getParameter<string>("algo");
235  }
236  } else {
237  m_algoAutoSelect["CatForJet"] = false;
238  }
239 
240  if (CatTauJet.getParameter<bool>("monitor")) {
241  m_algoAutoSelect["TauJet"] = CatTauJet.getParameter<bool>("doAutoSelection");
242  if (!m_algoAutoSelect["TauJet"]) {
243  m_selectedTriggers["TauJet"] = CatTauJet.getParameter<string>("algo");
244  }
245  } else {
246  m_algoAutoSelect["TauJet"] = false;
247  }
248 
249  if (CatETM.getParameter<bool>("monitor")) {
250  m_algoAutoSelect["ETM"] = CatETM.getParameter<bool>("doAutoSelection");
251  if (!m_algoAutoSelect["ETM"]) {
252  m_selectedTriggers["ETM"] = CatETM.getParameter<string>("algo");
253  }
254  } else {
255  m_algoAutoSelect["ETM"] = false;
256  }
257 
258  if (CatETT.getParameter<bool>("monitor")) {
259  m_algoAutoSelect["ETT"] = CatETT.getParameter<bool>("doAutoSelection");
260  if (!m_algoAutoSelect["ETT"]) {
261  m_selectedTriggers["ETT"] = CatETT.getParameter<string>("algo");
262  }
263  } else {
264  m_algoAutoSelect["ETT"] = false;
265  }
266 
267  if (CatHTM.getParameter<bool>("monitor")) {
268  m_algoAutoSelect["HTM"] = CatHTM.getParameter<bool>("doAutoSelection");
269  if (!m_algoAutoSelect["HTM"]) {
270  m_selectedTriggers["HTM"] = CatHTM.getParameter<string>("algo");
271  }
272  } else {
273  m_algoAutoSelect["HTM"] = false;
274  }
275 
276  if (CatHTT.getParameter<bool>("monitor")) {
277  m_algoAutoSelect["HTT"] = CatHTT.getParameter<bool>("doAutoSelection");
278  if (!m_algoAutoSelect["HTT"]) {
279  m_selectedTriggers["HTT"] = CatHTT.getParameter<string>("algo");
280  }
281  } else {
282  m_algoAutoSelect["HTT"] = false;
283  }
284  }
285 
286  m_outputFile = pset.getUntrackedParameter<std::string>("outputFile", "");
287 
288  if (!m_outputFile.empty()) {
289  std::cout << "L1T Monitoring histograms will be saved to " << m_outputFile.c_str() << std::endl;
290  }
291 
292  bool disable = pset.getUntrackedParameter<bool>("disableROOToutput", false);
293  if (disable) {
294  m_outputFile = "";
295  }
296 }
297 
298 //-------------------------------------------------------------------------------------
299 //-------------------------------------------------------------------------------------
301 
302 //-------------------------------------------------------------------------------------
305  //
306  if (m_verbose) {
307  cout << "[L1TSync] Called beginRun." << endl;
308  }
309 }
310 //-------------------------------------------------------------------------------------
311 void L1TSync::bookHistograms(DQMStore::IBooker& ibooker, const edm::Run&, const edm::EventSetup& iSetup) {
312  // Initializing variables
313  int maxNbins = 2501;
314 
315  // Reseting run dependent variables
316  m_lhcFill = 0;
317  m_currentLS = 0;
318  m_certFirstLS.clear();
319  m_certLastLS.clear();
320 
321  // Getting Trigger menu from GT
322  const L1GtTriggerMenu& menu = iSetup.getData(m_menuToken);
323 
324  // Filling Alias-Bit Map
325  for (const auto& algo : menu.gtAlgorithmAliasMap()) {
326  m_algoBit[algo.second.algoAlias()] = algo.second.algoBitNumber();
327  }
328 
329  // Getting fill number for this run
330  //Handle<ConditionsInRunBlock> runConditions;
331  //iRun.getByType(runConditions);
332  //int lhcFillNumber = runConditions->lhcFillNumber;
333 
334  //ESHandle<L1GtPrescaleFactors> l1GtPfAlgo;
335  //iSetup.get<L1GtPrescaleFactorsAlgoTrigRcd>().get(l1GtPfAlgo);
336  //const L1GtPrescaleFactors* m_l1GtPfAlgo = l1GtPfAlgo.product();
337 
338  L1TMenuHelper myMenuHelper = L1TMenuHelper(iSetup, m_helperTokens);
339 
341 
343  map<string, string> tAutoSelTrig = myMenuHelper.getLUSOTrigger(m_algoAutoSelect, m_refPrescaleSet, m_l1GtUtils);
344  m_selectedTriggers.insert(tAutoSelTrig.begin(), tAutoSelTrig.end());
345 
346  // Initializing DQM Monitor Elements
347  ibooker.setCurrentFolder("L1T/L1TSync");
348  m_ErrorMonitor = ibooker.book1D("ErrorMonitor", "ErrorMonitor", 7, 0, 7);
349  m_ErrorMonitor->setBinLabel(UNKNOWN, "UNKNOWN");
350  m_ErrorMonitor->setBinLabel(WARNING_DB_CONN_FAILED, "WARNING_DB_CONN_FAILED"); // Errors from L1TOMDSHelper
351  m_ErrorMonitor->setBinLabel(WARNING_DB_QUERY_FAILED, "WARNING_DB_QUERY_FAILED"); // Errors from L1TOMDSHelper
353  "WARNING_DB_INCORRECT_NBUNCHES"); // Errors from L1TOMDSHelper
354  m_ErrorMonitor->setBinLabel(ERROR_UNABLE_RETRIVE_PRODUCT, "ERROR_UNABLE_RETRIVE_PRODUCT");
355  m_ErrorMonitor->setBinLabel(ERROR_TRIGGERALIAS_NOTVALID, "ERROR_TRIGGERALIAS_NOTVALID");
356  m_ErrorMonitor->setBinLabel(ERROR_LSBLOCK_NOTVALID, "ERROR_LSBLOCK_NOTVALID");
357 
358  // Looping over selected triggers
359  for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
360  string tCategory = (*i).first;
361  string tTrigger = (*i).second;
362 
363  // Initializing LS blocks for certification
364  m_certFirstLS[(*i).second] = 0;
365  m_certLastLS[(*i).second] = 0;
366 
367  // Initializing DQM Monitors
368  ibooker.setCurrentFolder("L1T/L1TSync/AlgoVsBunchStructure/");
369  m_algoVsBunchStructure[tTrigger] = ibooker.book2D(
370  tCategory, "min #Delta(" + tTrigger + ",Bunch)", maxNbins, -0.5, double(maxNbins) - 0.5, 5, -2.5, 2.5);
371  m_algoVsBunchStructure[tTrigger]->setAxisTitle("Lumi Section", 1);
372 
373  ibooker.setCurrentFolder("L1T/L1TSync/Certification/");
374  m_algoCertification[tTrigger] =
375  ibooker.book1D(tCategory, "fraction of in sync: " + tTrigger, maxNbins, -0.5, double(maxNbins) - 0.5);
376  m_algoCertification[tTrigger]->setAxisTitle("Lumi Section", 1);
377  }
378 }
379 
380 //_____________________________________________________________________
381 // Function: beginLuminosityBlock
382 //_____________________________________________________________________
384  if (m_verbose) {
385  cout << "[L1TSync] Called beginLuminosityBlock." << endl;
386  }
387 
388  // If this LS is not the next to last one force closing of current LS blocks
389  // for certification
390  if (m_currentLS != 0 && m_currentLS + 1 != lumiBlock.id().luminosityBlock()) {
391  if (m_verbose) {
392  cout << "[L1TSync] None consecutive: doFractionInSync() - LAST=" << m_currentLS
393  << " CURRENT=" << lumiBlock.id().luminosityBlock() << endl;
394  }
395  doFractionInSync(true, false);
396  }
397 
398  // Updating current LS number
399  m_currentLS = lumiBlock.id().luminosityBlock();
400 
401  // If this is the fist valid LS update first LS for certification
402  for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
403  string theTriggerAlias = (*i).second;
404  if (m_certFirstLS[theTriggerAlias] == 0) {
405  m_certFirstLS[theTriggerAlias] = m_currentLS;
406  }
407  }
408 
409  // A LS will be valid if:
410  // * BeamMode == STABLE for all events monitored
411  m_currentLSValid = true;
412 }
413 
414 //_____________________________________________________________________
415 // Function: endLuminosityBlock
416 // * Fills LS by LS ration of trigger out of sync
417 //_____________________________________________________________________
418 void L1TSync::endLuminosityBlock(LuminosityBlock const& lumiBlock, EventSetup const& c) {
419  if (m_verbose) {
420  cout << "[L1TSync] Called endLuminosityBlock." << endl;
421  }
422 
423  if (m_verbose) {
424  cout << "[L1TSync] m_currentLSValid : " << m_currentLSValid << endl;
425  cout << "[L1TSync] m_beamConfig.isValid(): " << m_beamConfig.isValid() << endl;
426  }
427 
428  for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
429  // Update last LS for certification
430  string theTriggerAlias = (*i).second;
431  m_certLastLS[theTriggerAlias] = m_currentLS;
432  }
433 
434  // If this LS is valid (i.e. all events recorded with stable beams)
436  if (m_verbose) {
437  cout << "[L1TSync] Regular call: doFractionInSync()" << endl;
438  }
439  doFractionInSync(false, false);
440 
441  }
442  // If this LS is not valid it can be in the following context:
443  // * We still hadn't stable beam (no need to certify nothing
444  // * Beam just got unstable or dumped (we may have a complete block of data do certify)
445  else {
446  //-> First we close all blocks from certFirstLS[] to m_currentLS-1
447  for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
448  string theTriggerAlias = (*i).second;
449 
450  int fLs = m_certFirstLS[theTriggerAlias];
451  int lLS = m_certLastLS[theTriggerAlias];
452 
453  // If this is a single LS block we do nothing (in this step)
454  if (fLs == lLS) {
455  m_certFirstLS[theTriggerAlias] = 0;
456  m_certLastLS[theTriggerAlias] = 0;
457  }
458  // If block is multi LS then we remove the current LS
459  else {
460  m_certLastLS[theTriggerAlias] = m_currentLS - 1;
461  }
462  }
463  doFractionInSync(true, false);
464 
465  //-> Second we mark this single LS bad for all triggers
466  for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
467  string theTriggerAlias = (*i).second;
468  m_certFirstLS[theTriggerAlias] = m_currentLS;
469  m_certLastLS[theTriggerAlias] = m_currentLS;
470  }
471  doFractionInSync(true, true);
472 
473  if (m_verbose) {
474  cout << "[L1TSync] Error call: doFractionInSync()" << endl;
475  }
476  }
477 }
478 
479 //_____________________________________________________________________
481  if (m_verbose) {
482  cout << "[L1TSync] Called analyze." << endl;
483  }
484 
485  // We only start analyzing if current LS is still valid
486  if (m_currentLSValid) {
487  if (m_verbose) {
488  cout << "[L1TSync] -> m_currentLSValid=" << m_currentLSValid << endl;
489  }
490 
491  // Retriving information from GT
493  iEvent.getByToken(m_l1GtEvmSource, gtEvmReadoutRecord);
494 
495  // Determining beam mode and fill number
496  if (gtEvmReadoutRecord.isValid()) {
497  const L1GtfeExtWord& gtfeEvmWord = gtEvmReadoutRecord->gtfeWord();
498  unsigned int lhcBeamMode = gtfeEvmWord.beamMode(); // Updating beam mode
499 
500  if (m_lhcFill == 0) {
501  m_lhcFill = gtfeEvmWord.lhcFillNumber(); // Getting LHC Fill Number from GT
502  getBeamConfOMDS(); // Getting Beam Configuration from OMDS
503  }
504 
505  if (lhcBeamMode != STABLE) {
506  m_currentLSValid = false;
507  } // If Beams are not stable we invalidate this LS
508 
509  } else {
510  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT);
511  eCount++;
512  m_ErrorMonitor->getTH1()->SetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT, eCount);
513  }
514  } else {
515  if (m_verbose) {
516  cout << "[L1TSync] -> m_currentLSValid=" << m_currentLSValid << endl;
517  }
518  }
519 
520  //------------------------------------------------------------------------------
521  // If current LS is valid and Beam Configuration is Valid we analyse this event
522  //------------------------------------------------------------------------------
524  // Getting Final Decision Logic (FDL) Data from GT
525  edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecordData;
526  iEvent.getByToken(m_l1GtDataDaqInputTag, gtReadoutRecordData);
527 
528  if (gtReadoutRecordData.isValid()) {
529  const vector<L1GtFdlWord>& gtFdlVectorData = gtReadoutRecordData->gtFdlVector();
530 
531  // Running over selected triggers
532  for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
533  string tTrigger = (*i).second;
534 
535  // Analyse only defined triggers
536  if (tTrigger != "Undefined" && tTrigger != "Undefined (Wrong Name)") {
537  bool beamSingleConfig = false; // Single beam configured for this event
538  bool firedAlgo = false; // Algo fired in this event
539  int eventBx = -1;
540 
541  // Running over FDL results to get which bits fired
542  for (unsigned int a = 0; a < gtFdlVectorData.size(); a++) {
543  // Selecting the FDL that triggered
544  if (gtFdlVectorData[a].bxInEvent() == 0) {
545  eventBx = gtFdlVectorData[a].localBxNr();
546  if (gtFdlVectorData[a].gtDecisionWord()[m_algoBit[tTrigger]]) {
547  firedAlgo = true;
548  }
549  }
550  }
551 
552  // Checking beam configuration
553  if (m_beamConfig.beam1[eventBx] && !m_beamConfig.beam2[eventBx]) {
554  beamSingleConfig = true;
555  }
556  if (!m_beamConfig.beam1[eventBx] && m_beamConfig.beam2[eventBx]) {
557  beamSingleConfig = true;
558  }
559 
560  // Analyse only if this trigger fired in this event
561  // NOTE: Veto cases where a single beam is configured since
562  // for this cases this could be a real-satelite bunch collision
563  // -> Calculate the minimum bx diference between this event and a configured bx
564  if (firedAlgo && !beamSingleConfig) {
565  int DifAlgoVsBunchStructure = 9999; // Majorated
566 
567  for (unsigned int a = 0; a < gtFdlVectorData.size(); a++) {
568  int bxFDL = gtFdlVectorData[a].localBxNr();
569  int bxInEvent = gtFdlVectorData[a].bxInEvent();
570 
571  if (m_beamConfig.bxConfig(bxFDL) && abs(bxInEvent) < abs(DifAlgoVsBunchStructure)) {
572  DifAlgoVsBunchStructure = -1 * bxInEvent;
573  }
574  }
575 
576  m_algoVsBunchStructure[tTrigger]->Fill(m_currentLS, DifAlgoVsBunchStructure);
577  }
578  }
579  }
580  } else {
581  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT);
582  eCount++;
583  m_ErrorMonitor->getTH1()->SetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT, eCount);
584  }
585  }
586 }
587 
588 //_____________________________________________________________________
589 // Method: getBunchStructureOMDS
590 // Description: Attempt to retrive Beam Configuration from OMDS and if
591 // we find error handle it
592 //_____________________________________________________________________
594  //Getting connection paremeters
595  string oracleDB = m_parameters.getParameter<string>("oracleDB");
596  string pathCondDB = m_parameters.getParameter<string>("pathCondDB");
597 
598  // Connecting to OMDS
599  L1TOMDSHelper myOMDSHelper = L1TOMDSHelper();
600  int conError;
601  myOMDSHelper.connect(oracleDB, pathCondDB, conError);
602 
603  if (conError == L1TOMDSHelper::NO_ERROR) {
604  if (m_verbose) {
605  cout << "[L1TSync] Connected to DB with no error." << endl;
606  }
607 
608  int errorRetrive;
609  m_beamConfig = myOMDSHelper.getBeamConfiguration(m_lhcFill, errorRetrive);
610 
611  if (errorRetrive == L1TOMDSHelper::NO_ERROR) {
612  if (m_verbose) {
613  cout << "[L1TSync] Retriving LHC Bunch Structure: NO_ERROR" << endl;
614  cout << "[L1TSync] -> LHC Bunch Structure valid=" << m_beamConfig.m_valid
615  << " nBunches=" << m_beamConfig.nCollidingBunches << endl;
616  }
617  } else if (errorRetrive == L1TOMDSHelper::WARNING_DB_CONN_FAILED) {
618  if (m_verbose) {
619  cout << "[L1TSync] Retriving LHC Bunch Structure: WARNING_DB_CONN_FAILED" << endl;
620  }
621 
622  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_DB_INCORRECT_NBUNCHES);
623  eCount++;
624  m_ErrorMonitor->getTH1()->SetBinContent(WARNING_DB_INCORRECT_NBUNCHES, eCount);
625  } else if (errorRetrive == L1TOMDSHelper::WARNING_DB_QUERY_FAILED) {
626  if (m_verbose) {
627  cout << "[L1TSync] Retriving LHC Bunch Structure: WARNING_DB_QUERY_FAILED" << endl;
628  }
629 
630  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_DB_QUERY_FAILED);
631  eCount++;
632  m_ErrorMonitor->getTH1()->SetBinContent(WARNING_DB_QUERY_FAILED, eCount);
633  } else {
634  if (m_verbose) {
635  cout << "[L1TSync] Retriving LHC Bunch Structure: UNKNOWN" << endl;
636  }
637 
638  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(UNKNOWN);
639  eCount++;
640  m_ErrorMonitor->getTH1()->SetBinContent(UNKNOWN, eCount);
641  }
642 
643  } else {
644  if (conError == L1TOMDSHelper::WARNING_DB_CONN_FAILED) {
645  if (m_verbose) {
646  cout << "[L1TSync] Connect to DB: WARNING_DB_CONN_FAILED" << endl;
647  }
648 
649  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_DB_CONN_FAILED);
650  eCount++;
651  m_ErrorMonitor->getTH1()->SetBinContent(WARNING_DB_CONN_FAILED, eCount);
652  } else {
653  if (m_verbose) {
654  cout << "[L1TSync] Connect to DB: UNKNOWN" << endl;
655  }
656 
657  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(UNKNOWN);
658  eCount++;
659  m_ErrorMonitor->getTH1()->SetBinContent(UNKNOWN, eCount);
660  }
661  }
662 }
663 
664 //_____________________________________________________________________
665 // Method: doFractionInSync
666 // Description: Produce plot with the fraction of in sync trigger for
667 // LS blocks with enough statistics.
668 // Variable: iForce - Forces closing of all blocks and calculation of
669 // the respective fractions
670 // Variable: iBad - (Only works with iForce=true) Forces the current
671 // all current blocks to be marked as bad
672 //_____________________________________________________________________
673 void L1TSync::doFractionInSync(bool iForce, bool iBad) {
674  for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
675  string theCategory = (*i).first;
676  string theTriggerAlias = (*i).second;
677 
678  // Caching frequently used values from maps
679  unsigned int fLS = m_certFirstLS[theTriggerAlias];
680  unsigned int lLS = m_certLastLS[theTriggerAlias];
681 
682  // Checking validity of the trigger alias and of the LS block
683  bool triggerAlias_isValid = theTriggerAlias != "Undefined" && theTriggerAlias != "Undefined (Wrong Name)";
684  bool lsBlock_exists = !(fLS == 0 && lLS == 0);
685  bool lsBlock_isValid = fLS <= lLS && fLS > 0 && lLS > 0;
686 
687  if (triggerAlias_isValid && lsBlock_exists && lsBlock_isValid) {
688  // If we are forced to close blocks and mark them bad
689  if (iForce && iBad) {
690  certifyLSBlock(theTriggerAlias, fLS, lLS, -1);
691  m_certFirstLS[theTriggerAlias] = 0;
692  m_certLastLS[theTriggerAlias] = 0;
693  }
694 
695  // If we are not forced to mark bad, we check if we have enough statistics
696  else {
697  // Getting events with 0 bx difference between BPTX and Algo for current LS
698  double CountSync = 0;
699  double CountAll = 0;
700 
701  // Adding all entries for current LS block
702  for (unsigned int ls = fLS; ls <= lLS; ls++) {
703  CountSync += m_algoVsBunchStructure[theTriggerAlias]->getBinContent(ls + 1, 3);
704  for (int a = 1; a < 6; a++) {
705  CountAll += m_algoVsBunchStructure[theTriggerAlias]->getBinContent(ls + 1, a);
706  }
707  }
708 
709  if (m_verbose) {
710  cout << "Alias = " << theTriggerAlias << " InitLS=" << fLS << " EndLS=" << lLS << " Events=" << CountAll;
711  }
712 
713  if (iForce || CountAll >= m_parameters.getParameter<ParameterSet>("Categories")
714  .getParameter<ParameterSet>(theCategory)
715  .getParameter<int>("CertMinEvents")) {
716  if (m_verbose) {
717  cout << " <--------------- Enough Statistics: ";
718  }
719 
720  // Calculating fraction of in time
721  double fraction = 0;
722  if (CountAll > 0) {
723  fraction = CountSync / CountAll;
724  }
725 
726  // This is to avoid having an entry equal to zero and thus
727  // disregarded by the automatic tests
728  if (fraction == 0) {
729  fraction = 0.000001;
730  }
731 
732  certifyLSBlock(theTriggerAlias, fLS, lLS, fraction);
733  m_certFirstLS[theTriggerAlias] = 0;
734  m_certLastLS[theTriggerAlias] = 0;
735  }
736 
737  if (m_verbose) {
738  cout << endl;
739  }
740  }
741  }
742 
743  // A problem was found. We report it and set a not physical vale (-1) to the certification plot
744  else {
745  // If trigger alias is not valid report it to m_ErrorMonitor
746  if (!triggerAlias_isValid) {
747  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_TRIGGERALIAS_NOTVALID);
748  eCount++;
749  m_ErrorMonitor->getTH1()->SetBinContent(ERROR_TRIGGERALIAS_NOTVALID, eCount);
750  certifyLSBlock(theTriggerAlias, fLS, lLS, -1);
751  m_certFirstLS[theTriggerAlias] = 0;
752  m_certLastLS[theTriggerAlias] = 0;
753  }
754 
755  // If LS Block is not valid report it to m_ErrorMonitor
756  if (lsBlock_exists && !lsBlock_isValid) {
757  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_LSBLOCK_NOTVALID);
758  eCount++;
759  m_ErrorMonitor->getTH1()->SetBinContent(ERROR_LSBLOCK_NOTVALID, eCount);
760  certifyLSBlock(theTriggerAlias, fLS, lLS, -1);
761  m_certFirstLS[theTriggerAlias] = 0;
762  m_certLastLS[theTriggerAlias] = 0;
763  }
764  }
765  }
766 }
767 
768 //_____________________________________________________________________
769 // Method: certifyLSBlock
770 // Description: Fill the trigger certification plot by blocks
771 // Variable: iTrigger - Which trigger to certify
772 // Variable: iInitLs - Blocks initial LS
773 // Variable: iEndLs - Blocks end LS
774 // Variable: iValue - Value to be used to fill
775 //_____________________________________________________________________
776 void L1TSync::certifyLSBlock(string iTrigger, int iInitLs, int iEndLs, float iValue) {
777  // Finding correct bins in the histogram for this block
778  int binInit = m_algoCertification[iTrigger]->getTH1()->FindBin(iInitLs);
779  int binEnd = m_algoCertification[iTrigger]->getTH1()->FindBin(iEndLs);
780 
781  for (int ls = binInit; ls <= binEnd; ls++) {
782  m_algoCertification[iTrigger]->setBinContent(ls, iValue);
783  }
784 }
int m_refPrescaleSet
Definition: L1TSync.h:110
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
LuminosityBlockNumber_t luminosityBlock() const
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void retrieveL1EventSetup(const edm::EventSetup &, bool isRun=true)
retrieve all the relevant L1 trigger event setup records and cache them to improve the speed ...
Definition: L1GtUtils.cc:128
const cms_uint16_t beamMode() const
std::map< TString, int > m_algoBit
Definition: L1TSync.h:122
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
void doFractionInSync(bool iForce=false, bool iBad=false)
Definition: L1TSync.cc:673
L1TMenuHelper::Tokens m_helperTokens
Definition: L1TSync.h:137
~L1TSync() override
Definition: L1TSync.cc:300
L1TSync(const edm::ParameterSet &ps)
Definition: L1TSync.cc:37
const L1GtfeExtWord gtfeWord() const
get / set GTFE word (record) in the GT readout record
unsigned int m_lhcFill
Definition: L1TSync.h:113
void beginLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c) override
Definition: L1TSync.cc:383
BeamConfiguration m_beamConfig
Definition: L1TSync.h:116
bool m_verbose
Definition: L1TSync.h:105
std::map< TString, MonitorElement * > m_algoVsBunchStructure
Definition: L1TSync.h:126
int iEvent
Definition: GenABIO.cc:224
std::string m_outputFile
Definition: L1TSync.h:102
const std::vector< L1GtFdlWord > gtFdlVector() const
get the vector of L1GtFdlWord
void certifyLSBlock(std::string iTrigger, int iInitLs, int iEndLs, float iValue)
Definition: L1TSync.cc:776
void bookHistograms(DQMStore::IBooker &ibooker, const edm::Run &, const edm::EventSetup &) override
Definition: L1TSync.cc:311
const cms_uint32_t lhcFillNumber() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Transition
Definition: Transition.h:12
bool getData(T &iHolder) const
Definition: EventSetup.h:122
bool bxConfig(int iBx)
Definition: L1TOMDSHelper.h:26
std::map< TString, unsigned int > m_certFirstLS
Definition: L1TSync.h:123
virtual void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
edm::EDGetTokenT< L1GlobalTriggerReadoutRecord > m_l1GtDataDaqInputTag
Definition: L1TSync.h:135
std::map< std::string, std::string > testAlgos(const std::map< std::string, std::string > &)
def ls(path, rec=False)
Definition: eostools.py:349
std::map< std::string, bool > m_algoAutoSelect
Definition: L1TSync.h:127
LuminosityBlockID id() const
edm::ParameterSet m_parameters
Definition: L1TSync.h:100
void getBeamConfOMDS()
Definition: L1TSync.cc:593
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
bool isValid() const
Definition: HandleBase.h:70
void endLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c) override
Definition: L1TSync.cc:418
std::map< TString, MonitorElement * > m_algoCertification
Definition: L1TSync.h:125
HLT enums.
L1GtUtils m_l1GtUtils
Definition: L1TSync.h:139
bool m_currentLSValid
Definition: L1TSync.h:106
double a
Definition: hdecay.h:119
std::map< TString, unsigned int > m_certLastLS
Definition: L1TSync.h:124
std::vector< bool > beam2
Definition: L1TOMDSHelper.h:39
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Definition: L1TSync.cc:480
MonitorElement * m_ErrorMonitor
Definition: L1TSync.h:131
edm::EDGetTokenT< L1GlobalTriggerEvmReadoutRecord > m_l1GtEvmSource
Definition: L1TSync.h:134
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
std::vector< bool > beam1
Definition: L1TOMDSHelper.h:38
std::map< std::string, std::string > m_selectedTriggers
Definition: L1TSync.h:128
Definition: Run.h:45
void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override
BeginRun.
Definition: L1TSync.cc:304
std::map< std::string, std::string > getLUSOTrigger(const std::map< std::string, bool > &iCategories, int IndexRefPrescaleFactors, L1GtUtils const &myUtils)
unsigned int m_currentLS
Definition: L1TSync.h:111
const edm::ESGetToken< L1GtTriggerMenu, L1GtTriggerMenuRcd > m_menuToken
Definition: L1TSync.h:136