Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:37

0001 
0002 
0003 // system include files
0004 #include <memory>
0005 
0006 // user include files
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 ///This is an example of how to use the AlgorithmCalibration stuff
0025 // to read the calibrated objects from a .xml file
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   // ----------member data ---------------------------
0036   AlgorithmCalibration<TestCategory, CalibratedHistogramXML>* m_calib;
0037 };
0038 
0039 //This class define calibration  "category" in this example
0040 //the category is simply a range of float: i.e. the category match if
0041 //the calibrationInput (which is a float in that case) is min<= input < max
0042 //In the example .xml files I put two categories one with range 0..2.5 the other with
0043 // rang 2.5...5
0044 class TestCategory : public CalibrationCategory<float> {
0045 public:
0046   bool match(const float& input) const  // const reference  for float is stupid but input object
0047                                         // are not always  floats
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   //ask the algorithm the calibrated object for an input value
0077   // of 1.2
0078   // this will search for the matching category and return the associated calibrated
0079   // object.
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);