File indexing completed on 2024-04-06 12:09:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #include "DQMOffline/L1Trigger/interface/L1TLSBlock.h"
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 using namespace std;
0058
0059
0060
0061
0062 L1TLSBlock::L1TLSBlock() {
0063
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
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 }