CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TSync_Harvest.cc
Go to the documentation of this file.
1 /*
2  * \class L1TSync_Harvest
3  *
4  *
5  * Description: offline DQM module for L1Trigger/bunchStructure synchronization
6  *
7  * Implementation:
8  * <TODO: enter implementation details>
9  *
10  * \author: Pietro Vischia - LIP Lisbon pietro.vischia@gmail.com
11  *
12  * Changelog:
13  * 2012/08/10 11:01:01: First creation. Dummy module with actual code commented.
14  *
15  * Todo:
16  * - implement the module in offline
17  * - check if there are user includes specific for offline/online that should be changed
18  *
19  * $Date: 2012/11/27 14:56:17 $
20  * $Revision: 1.1 $
21  *
22  */
23 
24 //
25 
26 // This class header
28 
29 // System include files
30 // --
31 
32 // User include files
34 
35 
36 using namespace edm;
37 using namespace std;
38 
39 //-------------------------------------------------------------------------------------
40 //-------------------------------------------------------------------------------------
42 
186  if (pset.getUntrackedParameter < bool > ("dqmStore", false)) {
187  dbe = Service < DQMStore > ().operator->();
188  dbe->setVerbose(0);
189  }
190 
191  m_outputFile = pset.getUntrackedParameter < std::string > ("outputFile","");
192 
193  if (m_outputFile.size() != 0) {
194  std::cout << "L1T Monitoring histograms will be saved to " << m_outputFile.c_str() << std::endl;
195  }
196 
197  bool disable = pset.getUntrackedParameter < bool > ("disableROOToutput", false);
198  if (disable) {m_outputFile = "";}
199 
200  if (dbe != NULL) {dbe->setCurrentFolder("L1T/L1TSync");}
201 
202 }
203 
204 //-------------------------------------------------------------------------------------
205 //-------------------------------------------------------------------------------------
207 
208 //-------------------------------------------------------------------------------------
209 //-------------------------------------------------------------------------------------
211 
212  if (m_verbose){cout << "[L1TSync_Harvest] Called beginJob." << endl;}
213 
214  // get hold of back-end interface
215  DQMStore *dbe = 0;
216  dbe = Service < DQMStore > ().operator->();
217 
218  if (dbe) {
219  dbe->setCurrentFolder("L1T/L1TSync");
220  dbe->rmdir("L1T/L1TSync");
221  }
222 
223 }
224 
225 //-------------------------------------------------------------------------------------
226 //-------------------------------------------------------------------------------------
228 
229  if (m_verbose){cout << "[L1TSync_Harvest] Called endJob." << endl;}
230 
231  if (m_outputFile.size() != 0 && dbe)
232  dbe->save(m_outputFile);
233 
234  return;
235 
236 }
237 
238 //-------------------------------------------------------------------------------------
240 //-------------------------------------------------------------------------------------
241 void L1TSync_Harvest::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup){
242 
312 }
313 
314 //_____________________________________________________________________
315 // Function: beginLuminosityBlock
316 //_____________________________________________________________________
318 
319  if (m_verbose){cout << "[L1TSync_Harvest] Called beginLuminosityBlock." << endl;}
320 
321  // If this LS is not the next to last one force closing of current LS blocks
322  // for certification
323  if(m_currentLS !=0 && m_currentLS+1 != lumiBlock.id().luminosityBlock()){
324 
325  if (m_verbose){
326  cout << "[L1TSync_Harvest] None consecutive: doFractionInSync() - LAST="
327  << m_currentLS << " CURRENT=" << lumiBlock.id().luminosityBlock() << endl;
328  }
329 
330  doFractionInSync(true,false);
331 
332  }
333 
334  // Updating current LS number
335  m_currentLS = lumiBlock.id().luminosityBlock();
336 
337  // If this is the fist valid LS update first LS for certification
338  for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
339 
340  string theTriggerAlias = (*i).second;
341  if(m_certFirstLS[theTriggerAlias]==0){m_certFirstLS[theTriggerAlias] = m_currentLS;}
342 
343  }
344 
345  // A LS will be valid if:
346  // * BeamMode == STABLE for all events monitored
347  m_currentLSValid = true;
348 
349 }
350 
351 //_____________________________________________________________________
352 // Function: endLuminosityBlock
353 // * Fills LS by LS ration of trigger out of sync
354 //_____________________________________________________________________
356 
357  if(m_verbose){cout << "[L1TSync_Harvest] Called endLuminosityBlock." << endl;}
358 
359  if(m_verbose){
360  cout << "[L1TSync_Harvest] m_currentLSValid : " << m_currentLSValid << endl;
361  cout << "[L1TSync_Harvest] m_beamConfig.isValid(): " << m_beamConfig.isValid() << endl;
362  }
363 
364  for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
365 
366  // Update last LS for certification
367  string theTriggerAlias = (*i).second;
368  m_certLastLS[theTriggerAlias] = m_currentLS;
369 
370  }
371 
372  // If this LS is valid (i.e. all events recorded with stable beams)
373  if(m_currentLSValid && m_beamConfig.isValid()){
374 
375  if(m_verbose){cout << "[L1TSync_Harvest] Regular call: doFractionInSync()" << endl;}
376  doFractionInSync(false,false);
377 
378  }
379  // If this LS is not valid it can be in the following context:
380  // * We still hadn't stable beam (no need to certify nothing
381  // * Beam just got unstable or dumped (we may have a complete block of data do certify)
382  else{
383 
384  //-> First we close all blocks from certFirstLS[] to m_currentLS-1
385  for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
386 
387  string theTriggerAlias = (*i).second;
388 
389  int fLs = m_certFirstLS[theTriggerAlias];
390  int lLS = m_certLastLS [theTriggerAlias];
391 
392  // If this is a single LS block we do nothing (in this step)
393  if(fLs == lLS){
394  m_certFirstLS[theTriggerAlias] = 0;
395  m_certLastLS [theTriggerAlias] = 0;
396  }
397  // If block is multi LS then we remove the current LS
398  else{
399  m_certLastLS [theTriggerAlias] = m_currentLS-1;
400  }
401 
402  }
403  doFractionInSync(true,false);
404 
405  //-> Second we mark this single LS bad for all triggers
406  for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
407  string theTriggerAlias = (*i).second;
408  m_certFirstLS[theTriggerAlias] = m_currentLS;
409  m_certLastLS [theTriggerAlias] = m_currentLS;
410  }
411  doFractionInSync(true,true);
412 
413  if(m_verbose){cout << "[L1TSync_Harvest] Error call: doFractionInSync()" << endl;}
414 
415  }
416 
417 }
418 
419 //_____________________________________________________________________
421 
422  if(m_verbose){cout << "[L1TSync_Harvest] Called endRun." << endl;}
423 
424  // When the run end for closing of the LS certification blocks and evaluation
425  // of synchronization for that block
426  doFractionInSync(true,false);
427 
428 }
429 
430 //_____________________________________________________________________
431 void L1TSync_Harvest::analyze(const Event & iEvent, const EventSetup & eventSetup){
432 
536 }
537 
538 //_____________________________________________________________________
539 // Method: getBunchStructureOMDS
540 // Description: Attempt to retrive Beam Configuration from OMDS and if
541 // we find error handle it
542 //_____________________________________________________________________
543 
544 //_____________________________________________________________________
545 // Method: doFractionInSync
546 // Description: Produce plot with the fraction of in sync trigger for
547 // LS blocks with enough statistics.
548 // Variable: iForce - Forces closing of all blocks and calculation of
549 // the respective fractions
550 // Variable: iBad - (Only works with iForce=true) Forces the current
551 // all current blocks to be marked as bad
552 //_____________________________________________________________________
553 void L1TSync_Harvest::doFractionInSync(bool iForce,bool iBad){
554 
555  for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
556 
557  string theCategory = (*i).first;
558  string theTriggerAlias = (*i).second;
559 
560  // Caching frequently used values from maps
561  unsigned int fLS = m_certFirstLS[theTriggerAlias];
562  unsigned int lLS = m_certLastLS [theTriggerAlias];
563 
564  // Checking validity of the trigger alias and of the LS block
565  bool triggerAlias_isValid = theTriggerAlias != "Undefined" && theTriggerAlias != "Undefined (Wrong Name)";
566  bool lsBlock_exists = !(fLS == 0 && lLS == 0);
567  bool lsBlock_isValid = fLS <= lLS && fLS > 0 && lLS > 0;
568 
569  if(triggerAlias_isValid && lsBlock_exists && lsBlock_isValid){
570 
571  // If we are forced to close blocks and mark them bad
572  if(iForce && iBad){
573  certifyLSBlock(theTriggerAlias,fLS,lLS,-1);
574  m_certFirstLS[theTriggerAlias] = 0;
575  m_certLastLS [theTriggerAlias] = 0;
576  }
577 
578  // If we are not forced to mark bad, we check if we have enough statistics
579  else{
580 
581  // Getting events with 0 bx difference between BPTX and Algo for current LS
582  double CountSync = 0;
583  double CountAll = 0;
584 
585  // Adding all entries for current LS block
586  for(unsigned int ls=fLS ; ls<=lLS ; ls++){
587 
588  CountSync += m_algoVsBunchStructure[theTriggerAlias]->getBinContent(ls+1,3);
589  for(int a=1 ; a<6 ; a++){
590  CountAll += m_algoVsBunchStructure[theTriggerAlias]->getBinContent(ls+1,a);
591  }
592  }
593 
594  if(m_verbose){
595  cout << "Alias = " << theTriggerAlias
596  << " InitLS=" << fLS
597  << " EndLS=" << lLS
598  << " Events=" << CountAll ;
599  }
600 
601  if(iForce ||
602  CountAll >= m_parameters.getParameter<ParameterSet>("Categories")
603  .getParameter<ParameterSet>(theCategory)
604  .getParameter<int>("CertMinEvents")){
605 
606  if(m_verbose){cout << " <--------------- Enough Statistics: ";}
607 
608 
609  // Calculating fraction of in time
610  double fraction = 0;
611  if(CountAll >0){fraction = CountSync/CountAll;}
612 
613  // This is to avoid having an entry equal to zero and thus
614  // disregarded by the automatic tests
615  if(fraction==0){fraction=0.000001;}
616 
617  certifyLSBlock(theTriggerAlias,fLS,lLS,fraction);
618  m_certFirstLS[theTriggerAlias] = 0;
619  m_certLastLS [theTriggerAlias] = 0;
620  }
621 
622  if(m_verbose){cout << endl;}
623 
624  }
625  }
626 
627  // A problem was found. We report it and set a not physical vale (-1) to the certification plot
628  else{
629 
630  // If trigger alias is not valid report it to m_ErrorMonitor
631  if(!triggerAlias_isValid){
632  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_TRIGGERALIAS_NOTVALID);
633  eCount++;
634  m_ErrorMonitor->getTH1()->SetBinContent(ERROR_TRIGGERALIAS_NOTVALID,eCount);
635  certifyLSBlock(theTriggerAlias,fLS,lLS,-1);
636  m_certFirstLS[theTriggerAlias] = 0;
637  m_certLastLS [theTriggerAlias] = 0;
638  }
639 
640  // If LS Block is not valid report it to m_ErrorMonitor
641  if(lsBlock_exists && !lsBlock_isValid){
642  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_LSBLOCK_NOTVALID);
643  eCount++;
644  m_ErrorMonitor->getTH1()->SetBinContent(ERROR_LSBLOCK_NOTVALID,eCount);
645  certifyLSBlock(theTriggerAlias,fLS,lLS,-1);
646  m_certFirstLS[theTriggerAlias] = 0;
647  m_certLastLS [theTriggerAlias] = 0;
648  }
649 
650  }
651  }
652 
653 }
654 
655 
656 //_____________________________________________________________________
657 // Method: certifyLSBlock
658 // Description: Fill the trigger certification plot by blocks
659 // Variable: iTrigger - Which trigger to certify
660 // Variable: iInitLs - Blocks initial LS
661 // Variable: iEndLs - Blocks end LS
662 // Variable: iValue - Value to be used to fill
663 //_____________________________________________________________________
664 void L1TSync_Harvest::certifyLSBlock(string iTrigger, int iInitLs, int iEndLs ,float iValue){
665 
673 
674 }
675 
676 //define this as a plug-in
LuminosityBlockID id() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void beginRun(const edm::Run &run, const edm::EventSetup &iSetup)
BeginRun.
int i
Definition: DBlmapReader.cc:9
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2535
#define NULL
Definition: scimark2.h:8
DEFINE_FWK_MODULE(HiMixingModule)
void certifyLSBlock(std::string iTrigger, int iInitLs, int iEndLs, float iValue)
int iEvent
Definition: GenABIO.cc:243
void analyze(const edm::Event &e, const edm::EventSetup &c)
virtual void beginLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
void doFractionInSync(bool iForce=false, bool iBad=false)
void endRun(const edm::Run &run, const edm::EventSetup &iSetup)
virtual void endLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
LuminosityBlockNumber_t luminosityBlock() const
double a
Definition: hdecay.h:121
L1TSync_Harvest(const edm::ParameterSet &ps)
tuple cout
Definition: gather_cfg.py:121
virtual ~L1TSync_Harvest()
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:434
Definition: Run.h:36