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