test
CMS 3D CMS Logo

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