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