File indexing completed on 2024-04-06 12:24:37
0001
0002
0003
0004 #include <memory>
0005
0006
0007 #include "FWCore/Framework/interface/Frameworkfwd.h"
0008 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0009
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "FWCore/Framework/interface/ESHandle.h"
0013 #include "FWCore/Framework/interface/MakerMacros.h"
0014
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 #include "RecoBTag/XMLCalibration/interface/AlgorithmCalibration.h"
0017 #include "RecoBTag/XMLCalibration/interface/CalibratedHistogramXML.h"
0018 #include "RecoBTag/XMLCalibration/interface/CalibrationCategory.h"
0019
0020 #include <iostream>
0021 using namespace std;
0022 class TestCategory;
0023
0024
0025
0026
0027 class XMLCalibrationTest : public edm::one::EDAnalyzer<> {
0028 public:
0029 explicit XMLCalibrationTest(const edm::ParameterSet&);
0030 ~XMLCalibrationTest();
0031
0032 virtual void analyze(const edm::Event&, const edm::EventSetup&);
0033
0034 private:
0035
0036 AlgorithmCalibration<TestCategory, CalibratedHistogramXML>* m_calib;
0037 };
0038
0039
0040
0041
0042
0043
0044 class TestCategory : public CalibrationCategory<float> {
0045 public:
0046 bool match(const float& input) const
0047
0048 {
0049 return (input < m_max) && (input >= m_min);
0050 }
0051 std::string name() { return "TestCategory"; }
0052
0053 void readFromDOM(DOMElement* dom) {
0054 m_min = CalibrationXML::readAttribute<float>(dom, "min");
0055 m_max = CalibrationXML::readAttribute<float>(dom, "max");
0056 }
0057
0058 void saveToDOM(DOMElement* dom) {
0059 CalibrationXML::writeAttribute(dom, "min", m_min);
0060 CalibrationXML::writeAttribute(dom, "max", m_max);
0061 }
0062
0063 protected:
0064 float m_min;
0065 float m_max;
0066 };
0067
0068 XMLCalibrationTest::XMLCalibrationTest(const edm::ParameterSet& iConfig) {
0069 m_calib = new AlgorithmCalibration<TestCategory, CalibratedHistogramXML>("test.xml");
0070 }
0071
0072 XMLCalibrationTest::~XMLCalibrationTest() { delete m_calib; }
0073
0074 void XMLCalibrationTest::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0075 using namespace edm;
0076
0077
0078
0079
0080
0081 const CalibratedHistogram* histo = m_calib->getCalibData((float)1.2);
0082
0083 std::cout << "Pointer of the histogram: " << histo << std::endl;
0084 std::cout << histo->value(2);
0085 std::cout << " " << histo->integral(2) << std::endl;
0086 }
0087
0088 DEFINE_FWK_MODULE(XMLCalibrationTest);