File indexing completed on 2024-04-06 12:27:27
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ProducePFCalibrationObject.h"
0010
0011 #include <iostream>
0012 #include <vector>
0013 #include "FWCore/ServiceRegistry/interface/Service.h"
0014 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0015
0016 #include "FWCore/Framework/interface/ESHandle.h"
0017 #include "FWCore/Framework/interface/EventSetup.h"
0018
0019 #include "TF1.h"
0020
0021 using namespace std;
0022 using namespace edm;
0023
0024 ProducePFCalibrationObject::ProducePFCalibrationObject(const edm::ParameterSet& pSet)
0025 : read(pSet.getUntrackedParameter<bool>("read")),
0026 write(pSet.getUntrackedParameter<bool>("write")),
0027 fToWrite(pSet.getParameter<vector<ParameterSet> >("toWrite")),
0028 fToRead(pSet.getUntrackedParameter<vector<string> >("toRead")),
0029 perfToken(esConsumes<edm::Transition::BeginRun>()) {}
0030
0031 ProducePFCalibrationObject::~ProducePFCalibrationObject() {}
0032
0033 void ProducePFCalibrationObject::beginRun(const edm::Run& run, const edm::EventSetup& eSetup) {
0034 cout << "[ProducePFCalibrationObject] beginJob" << endl;
0035
0036 string record = "PFCalibrationRcd";
0037
0038 static map<string, PerformanceResult::ResultType> functType;
0039 functType["PFfa_BARREL"] = PerformanceResult::PFfa_BARREL;
0040 functType["PFfa_ENDCAP"] = PerformanceResult::PFfa_ENDCAP;
0041 functType["PFfb_BARREL"] = PerformanceResult::PFfb_BARREL;
0042 functType["PFfb_ENDCAP"] = PerformanceResult::PFfb_ENDCAP;
0043 functType["PFfc_BARREL"] = PerformanceResult::PFfc_BARREL;
0044 functType["PFfc_ENDCAP"] = PerformanceResult::PFfc_ENDCAP;
0045
0046 functType["PFfaEta_BARRELH"] = PerformanceResult::PFfaEta_BARRELH;
0047 functType["PFfaEta_ENDCAPH"] = PerformanceResult::PFfaEta_ENDCAPH;
0048 functType["PFfbEta_BARRELH"] = PerformanceResult::PFfbEta_BARRELH;
0049 functType["PFfbEta_ENDCAPH"] = PerformanceResult::PFfbEta_ENDCAPH;
0050 functType["PFfaEta_BARRELEH"] = PerformanceResult::PFfaEta_BARRELEH;
0051 functType["PFfaEta_ENDCAPEH"] = PerformanceResult::PFfaEta_ENDCAPEH;
0052 functType["PFfbEta_BARRELEH"] = PerformanceResult::PFfbEta_BARRELEH;
0053 functType["PFfbEta_ENDCAPEH"] = PerformanceResult::PFfbEta_ENDCAPEH;
0054
0055 functType["PFfaEta_BARREL"] = PerformanceResult::PFfaEta_BARREL;
0056 functType["PFfaEta_ENDCAP"] = PerformanceResult::PFfaEta_ENDCAP;
0057 functType["PFfbEta_BARREL"] = PerformanceResult::PFfbEta_BARREL;
0058 functType["PFfbEta_ENDCAP"] = PerformanceResult::PFfbEta_ENDCAP;
0059
0060 functType["PFfcEta_BARRELH"] = PerformanceResult::PFfcEta_BARRELH;
0061 functType["PFfcEta_ENDCAPH"] = PerformanceResult::PFfcEta_ENDCAPH;
0062 functType["PFfdEta_ENDCAPH"] = PerformanceResult::PFfdEta_ENDCAPH;
0063 functType["PFfcEta_BARRELEH"] = PerformanceResult::PFfcEta_BARRELEH;
0064 functType["PFfcEta_ENDCAPEH"] = PerformanceResult::PFfcEta_ENDCAPEH;
0065 functType["PFfdEta_ENDCAPEH"] = PerformanceResult::PFfdEta_ENDCAPEH;
0066
0067
0068
0069
0070 if (write) {
0071 vector<pair<float, float> > limitsToWrite;
0072 vector<string> formulasToWrite;
0073 vector<PerformanceResult::ResultType> resToWrite;
0074 vector<BinningVariables::BinningVariablesType> binsToWrite;
0075 binsToWrite.push_back(BinningVariables::JetEt);
0076
0077
0078 for (vector<ParameterSet>::const_iterator fSetup = fToWrite.begin(); fSetup != fToWrite.end(); ++fSetup) {
0079
0080 string fType = (*fSetup).getUntrackedParameter<string>("fType");
0081
0082 string formula = (*fSetup).getUntrackedParameter<string>("formula");
0083 pair<float, float> limits = make_pair((*fSetup).getUntrackedParameter<vector<double> >("limits")[0],
0084 (*fSetup).getUntrackedParameter<vector<double> >("limits")[1]);
0085 vector<double> parameters = (*fSetup).getUntrackedParameter<vector<double> >("parameters");
0086
0087 TF1* function = new TF1(fType.c_str(), formula.c_str(), limits.first, limits.second);
0088 for (unsigned int index = 0; index != parameters.size(); ++index) {
0089 function->SetParameter(index, parameters[index]);
0090 }
0091
0092
0093 limitsToWrite.push_back(limits);
0094 formulasToWrite.push_back(string(function->GetExpFormula("p").Data()));
0095 resToWrite.push_back(functType[fType]);
0096 }
0097
0098
0099 PhysicsTFormulaPayload allTFormulas(limitsToWrite, formulasToWrite);
0100
0101
0102 PerformancePayloadFromTFormula pfCalibrationFormulas(resToWrite, binsToWrite, allTFormulas);
0103
0104
0105 edm::Service<cond::service::PoolDBOutputService> dbOut;
0106 if (dbOut.isAvailable()) {
0107 dbOut->writeOneIOV(pfCalibrationFormulas, 1, record);
0108 }
0109 }
0110
0111 if (read) {
0112
0113
0114 const PerformancePayloadFromTFormula* pfCalibrations =
0115 static_cast<const PerformancePayloadFromTFormula*>(&eSetup.getData(perfToken));
0116
0117 for (vector<string>::const_iterator name = fToRead.begin(); name != fToRead.end(); ++name) {
0118 cout << "Function: " << *name << endl;
0119 PerformanceResult::ResultType fType = functType[*name];
0120 pfCalibrations->printFormula(fType);
0121
0122
0123 float energy = 10.;
0124
0125 BinningPointByMap point;
0126 point.insert(BinningVariables::JetEt, energy);
0127
0128 if (pfCalibrations->isInPayload(fType, point)) {
0129 float value = pfCalibrations->getResult(fType, point);
0130 cout << " Energy before:: " << energy << " after: " << value << endl;
0131 } else
0132 cout << "outside limits!" << endl;
0133 }
0134 }
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220 }
0221
0222 #include "FWCore/Framework/interface/MakerMacros.h"
0223
0224 DEFINE_FWK_MODULE(ProducePFCalibrationObject);