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