Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:43

0001 #ifndef BTagEntry_H
0002 #define BTagEntry_H
0003 
0004 /**
0005  *
0006  * BTagEntry
0007  *
0008  * Represents one pt- or discriminator-dependent calibration function.
0009  *
0010  * measurement_type:    e.g. comb, ttbar, di-mu, boosted, ...
0011  * sys_type:            e.g. central, plus, minus, plus_JEC, plus_JER, ...
0012  *
0013  * Everything is converted into a function, as it is easiest to store it in a
0014  * txt or json file.
0015  *
0016  ************************************************************/
0017 
0018 #include <string>
0019 #include <TF1.h>
0020 #include <TH1.h>
0021 
0022 
0023 class BTagEntry
0024 {
0025 public:
0026   enum OperatingPoint {
0027     OP_LOOSE=0,
0028     OP_MEDIUM=1,
0029     OP_TIGHT=2,
0030     OP_RESHAPING=3,
0031   };
0032   enum JetFlavor {
0033     FLAV_B=0,
0034     FLAV_C=1,
0035     FLAV_UDSG=2,
0036   };
0037   struct Parameters {
0038     OperatingPoint operatingPoint;
0039     std::string measurementType;
0040     std::string sysType;
0041     JetFlavor jetFlavor;
0042     float etaMin;
0043     float etaMax;
0044     float ptMin;
0045     float ptMax;
0046     float discrMin;
0047     float discrMax;
0048 
0049     // default constructor
0050     Parameters(
0051       OperatingPoint op=OP_TIGHT,
0052       std::string measurement_type="comb",
0053       std::string sys_type="central",
0054       JetFlavor jf=FLAV_B,
0055       float eta_min=-99999.,
0056       float eta_max=99999.,
0057       float pt_min=0.,
0058       float pt_max=99999.,
0059       float discr_min=0.,
0060       float discr_max=99999.
0061     );
0062 
0063   };
0064 
0065   BTagEntry() {}
0066   BTagEntry(const std::string &csvLine);
0067   BTagEntry(const std::string &func, Parameters p);
0068   BTagEntry(const TF1* func, Parameters p);
0069   BTagEntry(const TH1* histo, Parameters p);
0070   ~BTagEntry() {}
0071   static std::string makeCSVHeader();
0072   std::string makeCSVLine() const;
0073   static std::string trimStr(std::string str);
0074 
0075   // public, no getters needed
0076   std::string formula;
0077   Parameters params;
0078 
0079 };
0080 
0081 #endif  // BTagEntry_H
0082 
0083 
0084 #ifndef BTagCalibration_H
0085 #define BTagCalibration_H
0086 
0087 /**
0088  * BTagCalibration
0089  *
0090  * The 'hierarchy' of stored information is this:
0091  * - by tagger (BTagCalibration)
0092  *   - by operating point or reshape bin
0093  *     - by jet parton flavor
0094  *       - by type of measurement
0095  *         - by systematic
0096  *           - by eta bin
0097  *             - as 1D-function dependent of pt or discriminant
0098  *
0099  ************************************************************/
0100 
0101 #include <map>
0102 #include <vector>
0103 #include <string>
0104 #include <istream>
0105 #include <ostream>
0106 
0107 
0108 class BTagCalibration
0109 {
0110 public:
0111   BTagCalibration() {}
0112   BTagCalibration(const std::string &tagger);
0113   BTagCalibration(const std::string &tagger, const std::string &filename);
0114   ~BTagCalibration() {}
0115 
0116   std::string tagger() const {return tagger_;}
0117 
0118   void addEntry(const BTagEntry &entry);
0119   const std::vector<BTagEntry>& getEntries(const BTagEntry::Parameters &par) const;
0120 
0121   void readCSV(std::istream &s);
0122   void readCSV(const std::string &s);
0123   void makeCSV(std::ostream &s) const;
0124   std::string makeCSV() const;
0125 
0126 protected:
0127   static std::string token(const BTagEntry::Parameters &par);
0128 
0129   std::string tagger_;
0130   std::map<std::string, std::vector<BTagEntry> > data_;
0131 
0132 };
0133 
0134 #endif  // BTagCalibration_H
0135 
0136 
0137 #ifndef BTagCalibrationReader_H
0138 #define BTagCalibrationReader_H
0139 
0140 /**
0141  * BTagCalibrationReader
0142  *
0143  * Helper class to pull out a specific set of BTagEntry's out of a
0144  * BTagCalibration. TF1 functions are set up at initialization time.
0145  *
0146  ************************************************************/
0147 
0148 #include <memory>
0149 #include <string>
0150 
0151 
0152 
0153 class BTagCalibrationReader
0154 {
0155 public:
0156   class BTagCalibrationReaderImpl;
0157 
0158   BTagCalibrationReader() {}
0159   BTagCalibrationReader(BTagEntry::OperatingPoint op,
0160                         const std::string & sysType="central",
0161                         const std::vector<std::string> & otherSysTypes={});
0162 
0163   void load(const BTagCalibration & c,
0164             BTagEntry::JetFlavor jf,
0165             const std::string & measurementType="comb");
0166 
0167   double eval(BTagEntry::JetFlavor jf,
0168               float eta,
0169               float pt,
0170               float discr=0.) const;
0171 
0172   double eval_auto_bounds(const std::string & sys,
0173                           BTagEntry::JetFlavor jf,
0174                           float eta,
0175                           float pt,
0176                           float discr=0.) const;
0177 
0178   std::pair<float, float> min_max_pt(BTagEntry::JetFlavor jf,
0179                                      float eta,
0180                                      float discr=0.) const;
0181 protected:
0182   std::shared_ptr<BTagCalibrationReaderImpl> pimpl;
0183 };
0184 
0185 
0186 #endif  // BTagCalibrationReader_H
0187 
0188