Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:12:58

0001 /**
0002  * \class L1TLSBlock
0003  *
0004  *
0005  * Description: offline DQM class for LS blocking
0006  * 
0007  * Implementation:
0008  *   <TODO: enter implementation details>
0009  *
0010  * \author: Pietro Vischia - LIP Lisbon pietro.vischia@gmail.com
0011  *
0012  * Changelog:
0013  *    2012/10/23 12:01:01: Class
0014  *
0015  * Todo: see header file
0016  *
0017  *
0018  */
0019 
0020 //
0021 
0022 // This class header
0023 #include "DQMOffline/L1Trigger/interface/L1TLSBlock.h"
0024 
0025 // System include files
0026 // --
0027 
0028 //// User include files
0029 //#include "DQMServices/Core/interface/DQMStore.h"
0030 //
0031 //#include "DataFormats/Scalers/interface/LumiScalers.h"
0032 //#include "DataFormats/Scalers/interface/Level1TriggerRates.h"
0033 //#include "DataFormats/Scalers/interface/Level1TriggerScalers.h"
0034 //
0035 //#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0036 //#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerEvmReadoutRecord.h"
0037 //
0038 //#include "DataFormats/Common/interface/ConditionsInEdm.h" // Parameters associated to Run, LS and Event
0039 //
0040 //#include "CondFormats/L1TObjects/interface/L1GtTriggerMenuFwd.h"
0041 //#include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
0042 //#include "CondFormats/L1TObjects/interface/L1GtPrescaleFactors.h"
0043 //#include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
0044 //#include "CondFormats/DataRecord/interface/L1GtPrescaleFactorsAlgoTrigRcd.h"
0045 //#include "CondFormats/L1TObjects/interface/L1GtMuonTemplate.h"
0046 /////
0047 //// Luminosity Information
0048 ////#include "DataFormats/Luminosity/interface/LumiDetails.h"
0049 ////#include "DataFormats/Luminosity/interface/LumiSummary.h"
0050 //
0051 //// L1TMonitor includes
0052 /////#include "DQM/L1TMonitor/interface/L1TMenuHelper.h"
0053 //#include "DQMOffline/L1Trigger/interface/L1TMenuHelper.h"
0054 //
0055 //#include "TList.h"
0056 
0057 using namespace std;
0058 
0059 //-------------------------------------------------------------------------------------
0060 //-------------------------------------------------------------------------------------
0061 
0062 L1TLSBlock::L1TLSBlock() {
0063   // Initialize LumiRangeList object. This will be redone at every doBlocking call. Perhaps rethink this
0064   initializeIO(false);
0065 }
0066 
0067 //-------------------------------------------------------------------------------------
0068 //-------------------------------------------------------------------------------------
0069 
0070 L1TLSBlock::~L1TLSBlock() {}
0071 
0072 //-------------------------------------------------------------------------------------
0073 //-------------------------------------------------------------------------------------
0074 
0075 L1TLSBlock::LumiRangeList L1TLSBlock::doBlocking(const LumiTestDoubleList& inputList,
0076                                                  double threshold,
0077                                                  BLOCKBY blockingMethod) {
0078   inputDoubleList_ = inputList;
0079   thresholdD_ = threshold;
0080 
0081   initializeIO(true);
0082 
0083   orderTestDoubleList();
0084 
0085   switch (blockingMethod) {
0086     case STATISTICS:
0087       blockByStatistics();
0088       break;
0089     default:
0090       cout << "[L1TLSBlock::doBlocking()]: Blocking method does not exist or is not implemented" << endl;
0091   }
0092 
0093   return outputList_;
0094 }
0095 
0096 //-------------------------------------------------------------------------------------
0097 //-------------------------------------------------------------------------------------
0098 
0099 L1TLSBlock::LumiRangeList L1TLSBlock::doBlocking(const LumiTestIntList& inputList,
0100                                                  int threshold,
0101                                                  BLOCKBY blockingMethod) {
0102   inputIntList_ = inputList;
0103   thresholdI_ = threshold;
0104 
0105   initializeIO(true);
0106 
0107   orderTestIntList();
0108 
0109   switch (blockingMethod) {
0110     case STATISTICS:
0111       cout << "[L1TLSBlock::doBlocking()]: Blocking by statistics require doubles as inputs for test variable and "
0112               "threshold"
0113            << endl;
0114       break;
0115     default:
0116       cout << "[L1TLSBlock::doBlocking()]: Blocking method does not exist or is not implemented" << endl;
0117   }
0118 
0119   return outputList_;
0120 }
0121 
0122 //-------------------------------------------------------------------------------------
0123 //-------------------------------------------------------------------------------------
0124 
0125 void L1TLSBlock::initializeIO(bool outputOnly) {
0126   if (!outputOnly) {
0127     inputIntList_.clear();
0128     inputDoubleList_.clear();
0129   }
0130   outputList_.clear();
0131 }
0132 
0133 //-------------------------------------------------------------------------------------
0134 //-------------------------------------------------------------------------------------
0135 
0136 void L1TLSBlock::orderTestDoubleList() {
0137   std::sort(inputDoubleList_.begin(), inputDoubleList_.end(), sort_pair_first<int, double>());
0138   // std::sort(v.begin(), v.end(), sort_pair_second<int, std::greater<int> >());
0139 }
0140 
0141 //-------------------------------------------------------------------------------------
0142 //-------------------------------------------------------------------------------------
0143 
0144 void L1TLSBlock::orderTestIntList() {
0145   std::sort(inputIntList_.begin(), inputIntList_.end(), sort_pair_first<int, int>());
0146 }
0147 
0148 //-------------------------------------------------------------------------------------
0149 //-------------------------------------------------------------------------------------
0150 
0151 void L1TLSBlock::blockByStatistics() {
0152   LumiRange currentRange;
0153   double currentError(0);
0154   bool resetFlag(true);
0155 
0156   for (LumiTestDoubleList::iterator i = inputDoubleList_.begin(); i != inputDoubleList_.end(); i++) {
0157     if (resetFlag) {
0158       currentRange = std::make_pair(i->first, i->first);
0159       resetFlag = false;
0160     } else
0161       currentRange = std::make_pair(currentRange.first, i->first);
0162     currentError = computeErrorFromRange(currentRange);
0163     if (currentError < thresholdD_) {
0164       outputList_.push_back(currentRange);
0165       resetFlag = true;
0166     }
0167   }
0168 }
0169 
0170 double L1TLSBlock::computeErrorFromRange(LumiRange& lumiRange) {
0171   std::vector<double> errorList;
0172   errorList.clear();
0173 
0174   for (size_t i = 0; i < inputDoubleList_.size(); i++) {
0175     if (inputDoubleList_[i].first > lumiRange.first && inputDoubleList_[i].first < lumiRange.second)
0176       errorList.push_back(inputDoubleList_[i].second);
0177   }
0178 
0179   double error(-1);
0180   for (size_t i = 0; i < errorList.size(); i++)
0181     error += 1 / (errorList[i] * errorList[i]);
0182   return error;
0183 }