Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:52

0001 #ifndef CondEx_Efficiency_H
0002 #define CondEx_Efficiency_H
0003 /*  example of polymorphic condition
0004  *  LUT, function, mixed....
0005  * this is just a prototype: classes do not need to be defined and declared in the same file
0006  * at the moment though all derived classes better sit in the same package together with the base one
0007  */
0008 
0009 #include "CondFormats/Serialization/interface/Serializable.h"
0010 
0011 #include <cmath>
0012 #include <iostream>
0013 
0014 namespace condex {
0015 
0016   /* very simple base class
0017    * trivial inheritance, no template tricks 
0018    */
0019   class Efficiency {
0020   public:
0021     Efficiency() {}
0022     virtual ~Efficiency() {}
0023     virtual void initialize() { std::cout << "initializing base class Efficiency" << std::endl; }
0024     float operator()(float pt, float eta) const { return value(pt, eta); }
0025 
0026     virtual float value(float pt, float eta) const = 0;
0027 
0028     COND_SERIALIZABLE;
0029   };
0030 
0031   class ParametricEfficiencyInPt : public Efficiency {
0032   public:
0033     ParametricEfficiencyInPt() : cutLow(0), cutHigh(0), low(0), high(0) {}
0034     ParametricEfficiencyInPt(float cm, float ch, float el, float eh) : cutLow(cm), cutHigh(ch), low(el), high(eh) {}
0035 
0036   private:
0037     float value(float pt, float) const override {
0038       if (pt < low)
0039         return cutLow;
0040       if (pt > high)
0041         return cutHigh;
0042       return cutLow + (pt - low) / (high - low) * (cutHigh - cutLow);
0043     }
0044     float cutLow, cutHigh;
0045     float low, high;
0046 
0047     COND_SERIALIZABLE;
0048   };
0049 
0050   class ParametricEfficiencyInEta : public Efficiency {
0051   public:
0052     ParametricEfficiencyInEta() : cutLow(0), cutHigh(0), low(0), high(0) {}
0053     ParametricEfficiencyInEta(float cmin, float cmax, float el, float eh)
0054         : cutLow(cmin), cutHigh(cmax), low(el), high(eh) {}
0055 
0056   private:
0057     float value(float, float eta) const override {
0058       eta = std::abs(eta);
0059       if (eta < low)
0060         return cutLow;
0061       if (eta > high)
0062         return cutHigh;
0063       return cutLow + (eta - low) / (high - low) * (cutHigh - cutLow);
0064     }
0065     float cutLow, cutHigh;
0066     float low, high;
0067 
0068     COND_SERIALIZABLE;
0069   };
0070 
0071 }  // namespace condex
0072 
0073 #endif