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 // L1TMonitor includes
32 
33 #include "TList.h"
34 
35 using namespace edm;
36 using namespace std;
37 
38 //-------------------------------------------------------------------------------------
39 //-------------------------------------------------------------------------------------
40 L1TSync::L1TSync(const ParameterSet& pset) : 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
70  if (forceGlobalParameters) {
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)
73  if (doGlobalAutoSelection) {
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
323  iSetup.get<L1GtTriggerMenuRcd>().get(menuRcd);
324  const L1GtTriggerMenu* menu = menuRcd.product();
325 
326  // Filling Alias-Bit Map
327  for (CItAlgo algo = menu->gtAlgorithmAliasMap().begin(); algo != menu->gtAlgorithmAliasMap().end(); ++algo) {
328  m_algoBit[(algo->second).algoAlias()] = (algo->second).algoBitNumber();
329  }
330 
331  // Getting fill number for this run
332  //Handle<ConditionsInRunBlock> runConditions;
333  //iRun.getByType(runConditions);
334  //int lhcFillNumber = runConditions->lhcFillNumber;
335 
336  //ESHandle<L1GtPrescaleFactors> l1GtPfAlgo;
337  //iSetup.get<L1GtPrescaleFactorsAlgoTrigRcd>().get(l1GtPfAlgo);
338  //const L1GtPrescaleFactors* m_l1GtPfAlgo = l1GtPfAlgo.product();
339 
340  L1TMenuHelper myMenuHelper = L1TMenuHelper(iSetup);
341 
343 
345  map<string, string> tAutoSelTrig = myMenuHelper.getLUSOTrigger(m_algoAutoSelect, m_refPrescaleSet, m_l1GtUtils);
346  m_selectedTriggers.insert(tAutoSelTrig.begin(), tAutoSelTrig.end());
347 
348  // Initializing DQM Monitor Elements
349  ibooker.setCurrentFolder("L1T/L1TSync");
350  m_ErrorMonitor = ibooker.book1D("ErrorMonitor", "ErrorMonitor", 7, 0, 7);
351  m_ErrorMonitor->setBinLabel(UNKNOWN, "UNKNOWN");
352  m_ErrorMonitor->setBinLabel(WARNING_DB_CONN_FAILED, "WARNING_DB_CONN_FAILED"); // Errors from L1TOMDSHelper
353  m_ErrorMonitor->setBinLabel(WARNING_DB_QUERY_FAILED, "WARNING_DB_QUERY_FAILED"); // Errors from L1TOMDSHelper
355  "WARNING_DB_INCORRECT_NBUNCHES"); // Errors from L1TOMDSHelper
356  m_ErrorMonitor->setBinLabel(ERROR_UNABLE_RETRIVE_PRODUCT, "ERROR_UNABLE_RETRIVE_PRODUCT");
357  m_ErrorMonitor->setBinLabel(ERROR_TRIGGERALIAS_NOTVALID, "ERROR_TRIGGERALIAS_NOTVALID");
358  m_ErrorMonitor->setBinLabel(ERROR_LSBLOCK_NOTVALID, "ERROR_LSBLOCK_NOTVALID");
359 
360  // Looping over selected triggers
361  for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
362  string tCategory = (*i).first;
363  string tTrigger = (*i).second;
364 
365  // Initializing LS blocks for certification
366  m_certFirstLS[(*i).second] = 0;
367  m_certLastLS[(*i).second] = 0;
368 
369  // Initializing DQM Monitors
370  ibooker.setCurrentFolder("L1T/L1TSync/AlgoVsBunchStructure/");
371  m_algoVsBunchStructure[tTrigger] = ibooker.book2D(
372  tCategory, "min #Delta(" + tTrigger + ",Bunch)", maxNbins, -0.5, double(maxNbins) - 0.5, 5, -2.5, 2.5);
373  m_algoVsBunchStructure[tTrigger]->setAxisTitle("Lumi Section", 1);
374 
375  ibooker.setCurrentFolder("L1T/L1TSync/Certification/");
376  m_algoCertification[tTrigger] =
377  ibooker.book1D(tCategory, "fraction of in sync: " + tTrigger, maxNbins, -0.5, double(maxNbins) - 0.5);
378  m_algoCertification[tTrigger]->setAxisTitle("Lumi Section", 1);
379  }
380 }
381 
382 //_____________________________________________________________________
383 // Function: beginLuminosityBlock
384 //_____________________________________________________________________
386  if (m_verbose) {
387  cout << "[L1TSync] Called beginLuminosityBlock." << endl;
388  }
389 
390  // If this LS is not the next to last one force closing of current LS blocks
391  // for certification
392  if (m_currentLS != 0 && m_currentLS + 1 != lumiBlock.id().luminosityBlock()) {
393  if (m_verbose) {
394  cout << "[L1TSync] None consecutive: doFractionInSync() - LAST=" << m_currentLS
395  << " CURRENT=" << lumiBlock.id().luminosityBlock() << endl;
396  }
397  doFractionInSync(true, false);
398  }
399 
400  // Updating current LS number
401  m_currentLS = lumiBlock.id().luminosityBlock();
402 
403  // If this is the fist valid LS update first LS for certification
404  for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
405  string theTriggerAlias = (*i).second;
406  if (m_certFirstLS[theTriggerAlias] == 0) {
407  m_certFirstLS[theTriggerAlias] = m_currentLS;
408  }
409  }
410 
411  // A LS will be valid if:
412  // * BeamMode == STABLE for all events monitored
413  m_currentLSValid = true;
414 }
415 
416 //_____________________________________________________________________
417 // Function: endLuminosityBlock
418 // * Fills LS by LS ration of trigger out of sync
419 //_____________________________________________________________________
420 void L1TSync::endLuminosityBlock(LuminosityBlock const& lumiBlock, EventSetup const& c) {
421  if (m_verbose) {
422  cout << "[L1TSync] Called endLuminosityBlock." << endl;
423  }
424 
425  if (m_verbose) {
426  cout << "[L1TSync] m_currentLSValid : " << m_currentLSValid << endl;
427  cout << "[L1TSync] m_beamConfig.isValid(): " << m_beamConfig.isValid() << endl;
428  }
429 
430  for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
431  // Update last LS for certification
432  string theTriggerAlias = (*i).second;
433  m_certLastLS[theTriggerAlias] = m_currentLS;
434  }
435 
436  // If this LS is valid (i.e. all events recorded with stable beams)
438  if (m_verbose) {
439  cout << "[L1TSync] Regular call: doFractionInSync()" << endl;
440  }
441  doFractionInSync(false, false);
442 
443  }
444  // If this LS is not valid it can be in the following context:
445  // * We still hadn't stable beam (no need to certify nothing
446  // * Beam just got unstable or dumped (we may have a complete block of data do certify)
447  else {
448  //-> First we close all blocks from certFirstLS[] to m_currentLS-1
449  for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
450  string theTriggerAlias = (*i).second;
451 
452  int fLs = m_certFirstLS[theTriggerAlias];
453  int lLS = m_certLastLS[theTriggerAlias];
454 
455  // If this is a single LS block we do nothing (in this step)
456  if (fLs == lLS) {
457  m_certFirstLS[theTriggerAlias] = 0;
458  m_certLastLS[theTriggerAlias] = 0;
459  }
460  // If block is multi LS then we remove the current LS
461  else {
462  m_certLastLS[theTriggerAlias] = m_currentLS - 1;
463  }
464  }
465  doFractionInSync(true, false);
466 
467  //-> Second we mark this single LS bad for all triggers
468  for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
469  string theTriggerAlias = (*i).second;
470  m_certFirstLS[theTriggerAlias] = m_currentLS;
471  m_certLastLS[theTriggerAlias] = m_currentLS;
472  }
473  doFractionInSync(true, true);
474 
475  if (m_verbose) {
476  cout << "[L1TSync] Error call: doFractionInSync()" << endl;
477  }
478  }
479 }
480 
481 //_____________________________________________________________________
482 void L1TSync::analyze(const Event& iEvent, const EventSetup& eventSetup) {
483  if (m_verbose) {
484  cout << "[L1TSync] Called analyze." << endl;
485  }
486 
487  // We only start analyzing if current LS is still valid
488  if (m_currentLSValid) {
489  if (m_verbose) {
490  cout << "[L1TSync] -> m_currentLSValid=" << m_currentLSValid << endl;
491  }
492 
493  // Retriving information from GT
495  iEvent.getByToken(m_l1GtEvmSource, gtEvmReadoutRecord);
496 
497  // Determining beam mode and fill number
498  if (gtEvmReadoutRecord.isValid()) {
499  const L1GtfeExtWord& gtfeEvmWord = gtEvmReadoutRecord->gtfeWord();
500  unsigned int lhcBeamMode = gtfeEvmWord.beamMode(); // Updating beam mode
501 
502  if (m_lhcFill == 0) {
503  m_lhcFill = gtfeEvmWord.lhcFillNumber(); // Getting LHC Fill Number from GT
504  getBeamConfOMDS(); // Getting Beam Configuration from OMDS
505  }
506 
507  if (lhcBeamMode != STABLE) {
508  m_currentLSValid = false;
509  } // If Beams are not stable we invalidate this LS
510 
511  } else {
512  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT);
513  eCount++;
514  m_ErrorMonitor->getTH1()->SetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT, eCount);
515  }
516  } else {
517  if (m_verbose) {
518  cout << "[L1TSync] -> m_currentLSValid=" << m_currentLSValid << endl;
519  }
520  }
521 
522  //------------------------------------------------------------------------------
523  // If current LS is valid and Beam Configuration is Valid we analyse this event
524  //------------------------------------------------------------------------------
526  // Getting Final Decision Logic (FDL) Data from GT
527  edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecordData;
528  iEvent.getByToken(m_l1GtDataDaqInputTag, gtReadoutRecordData);
529 
530  if (gtReadoutRecordData.isValid()) {
531  const vector<L1GtFdlWord>& gtFdlVectorData = gtReadoutRecordData->gtFdlVector();
532 
533  // Running over selected triggers
534  for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
535  string tTrigger = (*i).second;
536 
537  // Analyse only defined triggers
538  if (tTrigger != "Undefined" && tTrigger != "Undefined (Wrong Name)") {
539  bool beamSingleConfig = false; // Single beam configured for this event
540  bool firedAlgo = false; // Algo fired in this event
541  int eventBx = -1;
542 
543  // Running over FDL results to get which bits fired
544  for (unsigned int a = 0; a < gtFdlVectorData.size(); a++) {
545  // Selecting the FDL that triggered
546  if (gtFdlVectorData[a].bxInEvent() == 0) {
547  eventBx = gtFdlVectorData[a].localBxNr();
548  if (gtFdlVectorData[a].gtDecisionWord()[m_algoBit[tTrigger]]) {
549  firedAlgo = true;
550  }
551  }
552  }
553 
554  // Checking beam configuration
555  if (m_beamConfig.beam1[eventBx] && !m_beamConfig.beam2[eventBx]) {
556  beamSingleConfig = true;
557  }
558  if (!m_beamConfig.beam1[eventBx] && m_beamConfig.beam2[eventBx]) {
559  beamSingleConfig = true;
560  }
561 
562  // Analyse only if this trigger fired in this event
563  // NOTE: Veto cases where a single beam is configured since
564  // for this cases this could be a real-satelite bunch collision
565  // -> Calculate the minimum bx diference between this event and a configured bx
566  if (firedAlgo && !beamSingleConfig) {
567  int DifAlgoVsBunchStructure = 9999; // Majorated
568 
569  for (unsigned int a = 0; a < gtFdlVectorData.size(); a++) {
570  int bxFDL = gtFdlVectorData[a].localBxNr();
571  int bxInEvent = gtFdlVectorData[a].bxInEvent();
572 
573  if (m_beamConfig.bxConfig(bxFDL) && abs(bxInEvent) < abs(DifAlgoVsBunchStructure)) {
574  DifAlgoVsBunchStructure = -1 * bxInEvent;
575  }
576  }
577 
578  m_algoVsBunchStructure[tTrigger]->Fill(m_currentLS, DifAlgoVsBunchStructure);
579  }
580  }
581  }
582  } else {
583  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT);
584  eCount++;
585  m_ErrorMonitor->getTH1()->SetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT, eCount);
586  }
587  }
588 }
589 
590 //_____________________________________________________________________
591 // Method: getBunchStructureOMDS
592 // Description: Attempt to retrive Beam Configuration from OMDS and if
593 // we find error handle it
594 //_____________________________________________________________________
596  //Getting connection paremeters
597  string oracleDB = m_parameters.getParameter<string>("oracleDB");
598  string pathCondDB = m_parameters.getParameter<string>("pathCondDB");
599 
600  // Connecting to OMDS
601  L1TOMDSHelper myOMDSHelper = L1TOMDSHelper();
602  int conError;
603  myOMDSHelper.connect(oracleDB, pathCondDB, conError);
604 
605  if (conError == L1TOMDSHelper::NO_ERROR) {
606  if (m_verbose) {
607  cout << "[L1TSync] Connected to DB with no error." << endl;
608  }
609 
610  int errorRetrive;
611  m_beamConfig = myOMDSHelper.getBeamConfiguration(m_lhcFill, errorRetrive);
612 
613  if (errorRetrive == L1TOMDSHelper::NO_ERROR) {
614  if (m_verbose) {
615  cout << "[L1TSync] Retriving LHC Bunch Structure: NO_ERROR" << endl;
616  cout << "[L1TSync] -> LHC Bunch Structure valid=" << m_beamConfig.m_valid
617  << " nBunches=" << m_beamConfig.nCollidingBunches << endl;
618  }
619  } else if (errorRetrive == L1TOMDSHelper::WARNING_DB_CONN_FAILED) {
620  if (m_verbose) {
621  cout << "[L1TSync] Retriving LHC Bunch Structure: WARNING_DB_CONN_FAILED" << endl;
622  }
623 
624  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_DB_INCORRECT_NBUNCHES);
625  eCount++;
626  m_ErrorMonitor->getTH1()->SetBinContent(WARNING_DB_INCORRECT_NBUNCHES, eCount);
627  } else if (errorRetrive == L1TOMDSHelper::WARNING_DB_QUERY_FAILED) {
628  if (m_verbose) {
629  cout << "[L1TSync] Retriving LHC Bunch Structure: WARNING_DB_QUERY_FAILED" << endl;
630  }
631 
632  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_DB_QUERY_FAILED);
633  eCount++;
634  m_ErrorMonitor->getTH1()->SetBinContent(WARNING_DB_QUERY_FAILED, eCount);
635  } else {
636  if (m_verbose) {
637  cout << "[L1TSync] Retriving LHC Bunch Structure: UNKNOWN" << endl;
638  }
639 
640  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(UNKNOWN);
641  eCount++;
642  m_ErrorMonitor->getTH1()->SetBinContent(UNKNOWN, eCount);
643  }
644 
645  } else {
646  if (conError == L1TOMDSHelper::WARNING_DB_CONN_FAILED) {
647  if (m_verbose) {
648  cout << "[L1TSync] Connect to DB: WARNING_DB_CONN_FAILED" << endl;
649  }
650 
651  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_DB_CONN_FAILED);
652  eCount++;
653  m_ErrorMonitor->getTH1()->SetBinContent(WARNING_DB_CONN_FAILED, eCount);
654  } else {
655  if (m_verbose) {
656  cout << "[L1TSync] Connect to DB: UNKNOWN" << endl;
657  }
658 
659  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(UNKNOWN);
660  eCount++;
661  m_ErrorMonitor->getTH1()->SetBinContent(UNKNOWN, eCount);
662  }
663  }
664 }
665 
666 //_____________________________________________________________________
667 // Method: doFractionInSync
668 // Description: Produce plot with the fraction of in sync trigger for
669 // LS blocks with enough statistics.
670 // Variable: iForce - Forces closing of all blocks and calculation of
671 // the respective fractions
672 // Variable: iBad - (Only works with iForce=true) Forces the current
673 // all current blocks to be marked as bad
674 //_____________________________________________________________________
675 void L1TSync::doFractionInSync(bool iForce, bool iBad) {
676  for (map<string, string>::const_iterator i = m_selectedTriggers.begin(); i != m_selectedTriggers.end(); i++) {
677  string theCategory = (*i).first;
678  string theTriggerAlias = (*i).second;
679 
680  // Caching frequently used values from maps
681  unsigned int fLS = m_certFirstLS[theTriggerAlias];
682  unsigned int lLS = m_certLastLS[theTriggerAlias];
683 
684  // Checking validity of the trigger alias and of the LS block
685  bool triggerAlias_isValid = theTriggerAlias != "Undefined" && theTriggerAlias != "Undefined (Wrong Name)";
686  bool lsBlock_exists = !(fLS == 0 && lLS == 0);
687  bool lsBlock_isValid = fLS <= lLS && fLS > 0 && lLS > 0;
688 
689  if (triggerAlias_isValid && lsBlock_exists && lsBlock_isValid) {
690  // If we are forced to close blocks and mark them bad
691  if (iForce && iBad) {
692  certifyLSBlock(theTriggerAlias, fLS, lLS, -1);
693  m_certFirstLS[theTriggerAlias] = 0;
694  m_certLastLS[theTriggerAlias] = 0;
695  }
696 
697  // If we are not forced to mark bad, we check if we have enough statistics
698  else {
699  // Getting events with 0 bx difference between BPTX and Algo for current LS
700  double CountSync = 0;
701  double CountAll = 0;
702 
703  // Adding all entries for current LS block
704  for (unsigned int ls = fLS; ls <= lLS; ls++) {
705  CountSync += m_algoVsBunchStructure[theTriggerAlias]->getBinContent(ls + 1, 3);
706  for (int a = 1; a < 6; a++) {
707  CountAll += m_algoVsBunchStructure[theTriggerAlias]->getBinContent(ls + 1, a);
708  }
709  }
710 
711  if (m_verbose) {
712  cout << "Alias = " << theTriggerAlias << " InitLS=" << fLS << " EndLS=" << lLS << " Events=" << CountAll;
713  }
714 
715  if (iForce || CountAll >= m_parameters.getParameter<ParameterSet>("Categories")
716  .getParameter<ParameterSet>(theCategory)
717  .getParameter<int>("CertMinEvents")) {
718  if (m_verbose) {
719  cout << " <--------------- Enough Statistics: ";
720  }
721 
722  // Calculating fraction of in time
723  double fraction = 0;
724  if (CountAll > 0) {
725  fraction = CountSync / CountAll;
726  }
727 
728  // This is to avoid having an entry equal to zero and thus
729  // disregarded by the automatic tests
730  if (fraction == 0) {
731  fraction = 0.000001;
732  }
733 
734  certifyLSBlock(theTriggerAlias, fLS, lLS, fraction);
735  m_certFirstLS[theTriggerAlias] = 0;
736  m_certLastLS[theTriggerAlias] = 0;
737  }
738 
739  if (m_verbose) {
740  cout << endl;
741  }
742  }
743  }
744 
745  // A problem was found. We report it and set a not physical vale (-1) to the certification plot
746  else {
747  // If trigger alias is not valid report it to m_ErrorMonitor
748  if (!triggerAlias_isValid) {
749  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_TRIGGERALIAS_NOTVALID);
750  eCount++;
751  m_ErrorMonitor->getTH1()->SetBinContent(ERROR_TRIGGERALIAS_NOTVALID, eCount);
752  certifyLSBlock(theTriggerAlias, fLS, lLS, -1);
753  m_certFirstLS[theTriggerAlias] = 0;
754  m_certLastLS[theTriggerAlias] = 0;
755  }
756 
757  // If LS Block is not valid report it to m_ErrorMonitor
758  if (lsBlock_exists && !lsBlock_isValid) {
759  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_LSBLOCK_NOTVALID);
760  eCount++;
761  m_ErrorMonitor->getTH1()->SetBinContent(ERROR_LSBLOCK_NOTVALID, eCount);
762  certifyLSBlock(theTriggerAlias, fLS, lLS, -1);
763  m_certFirstLS[theTriggerAlias] = 0;
764  m_certLastLS[theTriggerAlias] = 0;
765  }
766  }
767  }
768 }
769 
770 //_____________________________________________________________________
771 // Method: certifyLSBlock
772 // Description: Fill the trigger certification plot by blocks
773 // Variable: iTrigger - Which trigger to certify
774 // Variable: iInitLs - Blocks initial LS
775 // Variable: iEndLs - Blocks end LS
776 // Variable: iValue - Value to be used to fill
777 //_____________________________________________________________________
778 void L1TSync::certifyLSBlock(string iTrigger, int iInitLs, int iEndLs, float iValue) {
779  // Finding correct bins in the histogram for this block
780  int binInit = m_algoCertification[iTrigger]->getTH1()->FindBin(iInitLs);
781  int binEnd = m_algoCertification[iTrigger]->getTH1()->FindBin(iEndLs);
782 
783  for (int ls = binInit; ls <= binEnd; ls++) {
784  m_algoCertification[iTrigger]->setBinContent(ls, iValue);
785  }
786 }
LuminosityBlockID id() const
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
Definition: DQMStore.cc:239
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int m_refPrescaleSet
Definition: L1TSync.h:112
std::map< TString, int > m_algoBit
Definition: L1TSync.h:124
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
void doFractionInSync(bool iForce=false, bool iBad=false)
Definition: L1TSync.cc:675
const L1GtfeExtWord gtfeWord() const
get / set GTFE word (record) in the GT readout record
const std::vector< L1GtFdlWord > gtFdlVector() const
get the vector of L1GtFdlWord
~L1TSync() override
Definition: L1TSync.cc:300
L1TSync(const edm::ParameterSet &ps)
Definition: L1TSync.cc:40
unsigned int m_lhcFill
Definition: L1TSync.h:115
void beginLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c) override
Definition: L1TSync.cc:385
BeamConfiguration m_beamConfig
Definition: L1TSync.h:118
bool m_verbose
Definition: L1TSync.h:107
AlgorithmMap::const_iterator CItAlgo
iterators through map containing the algorithms
std::map< TString, MonitorElement * > m_algoVsBunchStructure
Definition: L1TSync.h:128
int iEvent
Definition: GenABIO.cc:224
std::string m_outputFile
Definition: L1TSync.h:104
void certifyLSBlock(std::string iTrigger, int iInitLs, int iEndLs, float iValue)
Definition: L1TSync.cc:778
void bookHistograms(DQMStore::IBooker &ibooker, const edm::Run &, const edm::EventSetup &) override
Definition: L1TSync.cc:311
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void retrieveL1EventSetup(const edm::EventSetup &)
retrieve all the relevant L1 trigger event setup records and cache them to improve the speed ...
Definition: L1GtUtils.cc:112
bool bxConfig(int iBx)
Definition: L1TOMDSHelper.h:26
std::map< TString, unsigned int > m_certFirstLS
Definition: L1TSync.h:125
bool isValid() const
Definition: HandleBase.h:70
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:137
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:129
const cms_uint32_t lhcFillNumber() const
edm::ParameterSet m_parameters
Definition: L1TSync.h:102
void getBeamConfOMDS()
Definition: L1TSync.cc:595
LuminosityBlockNumber_t luminosityBlock() const
void endLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c) override
Definition: L1TSync.cc:420
std::map< TString, MonitorElement * > m_algoCertification
Definition: L1TSync.h:127
HLT enums.
L1GtUtils m_l1GtUtils
Definition: L1TSync.h:139
bool m_currentLSValid
Definition: L1TSync.h:108
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:266
double a
Definition: hdecay.h:119
T get() const
Definition: EventSetup.h:73
std::map< TString, unsigned int > m_certLastLS
Definition: L1TSync.h:126
std::vector< bool > beam2
Definition: L1TOMDSHelper.h:39
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Definition: L1TSync.cc:482
MonitorElement * m_ErrorMonitor
Definition: L1TSync.h:133
edm::EDGetTokenT< L1GlobalTriggerEvmReadoutRecord > m_l1GtEvmSource
Definition: L1TSync.h:136
const AlgorithmMap & gtAlgorithmAliasMap() const
get / set the algorithm map (by alias)
std::vector< bool > beam1
Definition: L1TOMDSHelper.h:38
const cms_uint16_t beamMode() const
T const * product() const
Definition: ESHandle.h:86
std::map< std::string, std::string > m_selectedTriggers
Definition: L1TSync.h:130
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:113