Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:13:56

0001 //--------------------------------------------------------------------------------------------------
0002 // $Id $
0003 //
0004 // ElectronEnergyRegressionEvaluate
0005 //
0006 // Helper Class for applying electron energy regression calculation
0007 //
0008 // Authors: A.Takeda, S.Xie, E. Di Marco
0009 //--------------------------------------------------------------------------------------------------
0010 
0011 /// --> NOTE if you want to use this class as standalone without the CMSSW part
0012 ///  you need to uncomment the below line and compile normally with scramv1 b
0013 ///  Then you need just to load it in your root macro the lib with the correct path, eg:
0014 ///  gSystem->Load("/data/benedet/CMSSW_5_2_2/lib/slc5_amd64_gcc462/pluginEGammaEGammaAnalysisTools.so");
0015 
0016 //#define STANDALONE   // <---- this line
0017 
0018 #ifndef ELECTRONENERGYREGRESSIONEVALUATE_H
0019 #define ELECTRONENERGYREGRESSIONEVALUATE_H
0020 
0021 #include "TFile.h"
0022 #include "TTree.h"
0023 
0024 // For applying regression
0025 #include "CondFormats/GBRForest/interface/GBRForest.h"
0026 #ifndef STANDALONE
0027 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0028 #include "EgammaAnalysis/ElectronTools/interface/SuperClusterHelper.h"
0029 #endif
0030 
0031 class ElectronEnergyRegressionEvaluate {
0032 public:
0033   ElectronEnergyRegressionEvaluate();
0034   ~ElectronEnergyRegressionEvaluate();
0035 
0036   enum ElectronEnergyRegressionType {
0037     kNoTrkVar,
0038     kNoTrkVarV1,
0039     kWithTrkVar,
0040     kWithTrkVarV1,
0041     kWithTrkVarV2,
0042     kWithSubCluVar
0043   };
0044 
0045   void initialize(std::string weightsFile, ElectronEnergyRegressionEvaluate::ElectronEnergyRegressionType type);
0046 
0047   bool isInitialized() const { return fIsInitialized; }
0048 
0049 #ifndef STANDALONE
0050   double calculateRegressionEnergy(const reco::GsfElectron *ele,
0051                                    SuperClusterHelper &mySCHelper,
0052                                    double rho,
0053                                    double nvertices,
0054                                    bool printDebug = false);
0055   double calculateRegressionEnergyUncertainty(const reco::GsfElectron *ele,
0056                                               SuperClusterHelper &mySCHelper,
0057                                               double rho,
0058                                               double nvertices,
0059                                               bool printDebug = false);
0060 #endif
0061 
0062   // Evaluates regression without tracker variables
0063   double regressionValueNoTrkVar(double SCRawEnergy,
0064                                  double scEta,
0065                                  double scPhi,
0066                                  double R9,
0067                                  double etawidth,
0068                                  double phiwidth,
0069                                  double NClusters,
0070                                  double HoE,
0071                                  double rho,
0072                                  double vertices,
0073                                  double EtaSeed,
0074                                  double PhiSeed,
0075                                  double ESeed,
0076                                  double E3x3Seed,
0077                                  double E5x5Seed,
0078                                  double see,
0079                                  double spp,
0080                                  double sep,
0081                                  double EMaxSeed,
0082                                  double E2ndSeed,
0083                                  double ETopSeed,
0084                                  double EBottomSeed,
0085                                  double ELeftSeed,
0086                                  double ERightSeed,
0087                                  double E2x5MaxSeed,
0088                                  double E2x5TopSeed,
0089                                  double E2x5BottomSeed,
0090                                  double E2x5LeftSeed,
0091                                  double E2x5RightSeed,
0092                                  double IEtaSeed,
0093                                  double IPhiSeed,
0094                                  double EtaCrySeed,
0095                                  double PhiCrySeed,
0096                                  double PreShowerOverRaw,
0097                                  bool printDebug = false);
0098 
0099   // Evaluates regression without tracker variables
0100   double regressionUncertaintyNoTrkVar(double SCRawEnergy,
0101                                        double scEta,
0102                                        double scPhi,
0103                                        double R9,
0104                                        double etawidth,
0105                                        double phiwidth,
0106                                        double NClusters,
0107                                        double HoE,
0108                                        double rho,
0109                                        double vertices,
0110                                        double EtaSeed,
0111                                        double PhiSeed,
0112                                        double ESeed,
0113                                        double E3x3Seed,
0114                                        double E5x5Seed,
0115                                        double see,
0116                                        double spp,
0117                                        double sep,
0118                                        double EMaxSeed,
0119                                        double E2ndSeed,
0120                                        double ETopSeed,
0121                                        double EBottomSeed,
0122                                        double ELeftSeed,
0123                                        double ERightSeed,
0124                                        double E2x5MaxSeed,
0125                                        double E2x5TopSeed,
0126                                        double E2x5BottomSeed,
0127                                        double E2x5LeftSeed,
0128                                        double E2x5RightSeed,
0129                                        double IEtaSeed,
0130                                        double IPhiSeed,
0131                                        double EtaCrySeed,
0132                                        double PhiCrySeed,
0133                                        double PreShowerOverRaw,
0134                                        bool printDebug = false);
0135 
0136   // Evaluates regression without tracker variables
0137   double regressionValueNoTrkVarV1(double SCRawEnergy,
0138                                    double scEta,
0139                                    double scPhi,
0140                                    double R9,
0141                                    double etawidth,
0142                                    double phiwidth,
0143                                    double NClusters,
0144                                    double HoE,
0145                                    double rho,
0146                                    double vertices,
0147                                    double EtaSeed,
0148                                    double PhiSeed,
0149                                    double ESeed,
0150                                    double E3x3Seed,
0151                                    double E5x5Seed,
0152                                    double see,
0153                                    double spp,
0154                                    double sep,
0155                                    double EMaxSeed,
0156                                    double E2ndSeed,
0157                                    double ETopSeed,
0158                                    double EBottomSeed,
0159                                    double ELeftSeed,
0160                                    double ERightSeed,
0161                                    double E2x5MaxSeed,
0162                                    double E2x5TopSeed,
0163                                    double E2x5BottomSeed,
0164                                    double E2x5LeftSeed,
0165                                    double E2x5RightSeed,
0166                                    double IEtaSeed,
0167                                    double IPhiSeed,
0168                                    double EtaCrySeed,
0169                                    double PhiCrySeed,
0170                                    double PreShowerOverRaw,
0171                                    int IsEcalDriven,
0172                                    bool printDebug = false);
0173 
0174   // Evaluates regression without tracker variables
0175   double regressionUncertaintyNoTrkVarV1(double SCRawEnergy,
0176                                          double scEta,
0177                                          double scPhi,
0178                                          double R9,
0179                                          double etawidth,
0180                                          double phiwidth,
0181                                          double NClusters,
0182                                          double HoE,
0183                                          double rho,
0184                                          double vertices,
0185                                          double EtaSeed,
0186                                          double PhiSeed,
0187                                          double ESeed,
0188                                          double E3x3Seed,
0189                                          double E5x5Seed,
0190                                          double see,
0191                                          double spp,
0192                                          double sep,
0193                                          double EMaxSeed,
0194                                          double E2ndSeed,
0195                                          double ETopSeed,
0196                                          double EBottomSeed,
0197                                          double ELeftSeed,
0198                                          double ERightSeed,
0199                                          double E2x5MaxSeed,
0200                                          double E2x5TopSeed,
0201                                          double E2x5BottomSeed,
0202                                          double E2x5LeftSeed,
0203                                          double E2x5RightSeed,
0204                                          double IEtaSeed,
0205                                          double IPhiSeed,
0206                                          double EtaCrySeed,
0207                                          double PhiCrySeed,
0208                                          double PreShowerOverRaw,
0209                                          int IsEcalDriven,
0210                                          bool printDebug = false);
0211 
0212   // Evaluates regression using tracker variables
0213   // This option is now deprecated. we keep it only
0214   // for backwards compatibility
0215   double regressionValueWithTrkVar(double electronP,
0216                                    double SCRawEnergy,
0217                                    double scEta,
0218                                    double scPhi,
0219                                    double R9,
0220                                    double etawidth,
0221                                    double phiwidth,
0222                                    double NClusters,
0223                                    double HoE,
0224                                    double rho,
0225                                    double vertices,
0226                                    double EtaSeed,
0227                                    double PhiSeed,
0228                                    double ESeed,
0229                                    double E3x3Seed,
0230                                    double E5x5Seed,
0231                                    double see,
0232                                    double spp,
0233                                    double sep,
0234                                    double EMaxSeed,
0235                                    double E2ndSeed,
0236                                    double ETopSeed,
0237                                    double EBottomSeed,
0238                                    double ELeftSeed,
0239                                    double ERightSeed,
0240                                    double E2x5MaxSeed,
0241                                    double E2x5TopSeed,
0242                                    double E2x5BottomSeed,
0243                                    double E2x5LeftSeed,
0244                                    double E2x5RightSeed,
0245                                    double pt,
0246                                    double GsfTrackPIn,
0247                                    double fbrem,
0248                                    double Charge,
0249                                    double EoP,
0250                                    double IEtaSeed,
0251                                    double IPhiSeed,
0252                                    double EtaCrySeed,
0253                                    double PhiCrySeed,
0254                                    double PreShowerOverRaw,
0255                                    bool printDebug = false);
0256 
0257   // Evaluates regression using tracker variables
0258   // This option is now deprecated. we keep it only
0259   // for backwards compatibility
0260   double regressionUncertaintyWithTrkVar(double electronP,
0261                                          double SCRawEnergy,
0262                                          double scEta,
0263                                          double scPhi,
0264                                          double R9,
0265                                          double etawidth,
0266                                          double phiwidth,
0267                                          double NClusters,
0268                                          double HoE,
0269                                          double rho,
0270                                          double vertices,
0271                                          double EtaSeed,
0272                                          double PhiSeed,
0273                                          double ESeed,
0274                                          double E3x3Seed,
0275                                          double E5x5Seed,
0276                                          double see,
0277                                          double spp,
0278                                          double sep,
0279                                          double EMaxSeed,
0280                                          double E2ndSeed,
0281                                          double ETopSeed,
0282                                          double EBottomSeed,
0283                                          double ELeftSeed,
0284                                          double ERightSeed,
0285                                          double E2x5MaxSeed,
0286                                          double E2x5TopSeed,
0287                                          double E2x5BottomSeed,
0288                                          double E2x5LeftSeed,
0289                                          double E2x5RightSeed,
0290                                          double pt,
0291                                          double GsfTrackPIn,
0292                                          double fbrem,
0293                                          double Charge,
0294                                          double EoP,
0295                                          double IEtaSeed,
0296                                          double IPhiSeed,
0297                                          double EtaCrySeed,
0298                                          double PhiCrySeed,
0299                                          double PreShowerOverRaw,
0300                                          bool printDebug = false);
0301 
0302   // Evaluates regression using tracker variables
0303   double regressionValueWithTrkVarV1(double SCRawEnergy,
0304                                      double scEta,
0305                                      double scPhi,
0306                                      double R9,
0307                                      double etawidth,
0308                                      double phiwidth,
0309                                      double NClusters,
0310                                      double HoE,
0311                                      double rho,
0312                                      double vertices,
0313                                      double EtaSeed,
0314                                      double PhiSeed,
0315                                      double ESeed,
0316                                      double E3x3Seed,
0317                                      double E5x5Seed,
0318                                      double see,
0319                                      double spp,
0320                                      double sep,
0321                                      double EMaxSeed,
0322                                      double E2ndSeed,
0323                                      double ETopSeed,
0324                                      double EBottomSeed,
0325                                      double ELeftSeed,
0326                                      double ERightSeed,
0327                                      double E2x5MaxSeed,
0328                                      double E2x5TopSeed,
0329                                      double E2x5BottomSeed,
0330                                      double E2x5LeftSeed,
0331                                      double E2x5RightSeed,
0332                                      double IEtaSeed,
0333                                      double IPhiSeed,
0334                                      double EtaCrySeed,
0335                                      double PhiCrySeed,
0336                                      double PreShowerOverRaw,
0337                                      int IsEcalDriven,
0338                                      double GsfTrackPIn,
0339                                      double fbrem,
0340                                      double Charge,
0341                                      double EoP,
0342                                      double TrackMomentumError,
0343                                      double EcalEnergyError,
0344                                      int Classification,
0345                                      bool printDebug = false);
0346 
0347   // Evaluates regression using tracker variables
0348   double regressionUncertaintyWithTrkVarV1(double SCRawEnergy,
0349                                            double scEta,
0350                                            double scPhi,
0351                                            double R9,
0352                                            double etawidth,
0353                                            double phiwidth,
0354                                            double NClusters,
0355                                            double HoE,
0356                                            double rho,
0357                                            double vertices,
0358                                            double EtaSeed,
0359                                            double PhiSeed,
0360                                            double ESeed,
0361                                            double E3x3Seed,
0362                                            double E5x5Seed,
0363                                            double see,
0364                                            double spp,
0365                                            double sep,
0366                                            double EMaxSeed,
0367                                            double E2ndSeed,
0368                                            double ETopSeed,
0369                                            double EBottomSeed,
0370                                            double ELeftSeed,
0371                                            double ERightSeed,
0372                                            double E2x5MaxSeed,
0373                                            double E2x5TopSeed,
0374                                            double E2x5BottomSeed,
0375                                            double E2x5LeftSeed,
0376                                            double E2x5RightSeed,
0377                                            double IEtaSeed,
0378                                            double IPhiSeed,
0379                                            double EtaCrySeed,
0380                                            double PhiCrySeed,
0381                                            double PreShowerOverRaw,
0382                                            int IsEcalDriven,
0383                                            double GsfTrackPIn,
0384                                            double fbrem,
0385                                            double Charge,
0386                                            double EoP,
0387                                            double TrackMomentumError,
0388                                            double EcalEnergyError,
0389                                            int Classification,
0390                                            bool printDebug = false);
0391 
0392   double regressionValueWithTrkVarV1(std::vector<double> &inputvars, bool printDebug = false);
0393   double regressionUncertaintyWithTrkVarV1(std::vector<double> &inputvars, bool printDebug = false);
0394 
0395   // Evaluates regression using tracker variables
0396   double regressionValueWithTrkVarV2(double SCRawEnergy,
0397                                      double scEta,
0398                                      double scPhi,
0399                                      double R9,
0400                                      double etawidth,
0401                                      double phiwidth,
0402                                      double NClusters,
0403                                      double HoE,
0404                                      double rho,
0405                                      double vertices,
0406                                      double EtaSeed,
0407                                      double PhiSeed,
0408                                      double ESeed,
0409                                      double E3x3Seed,
0410                                      double E5x5Seed,
0411                                      double see,
0412                                      double spp,
0413                                      double sep,
0414                                      double EMaxSeed,
0415                                      double E2ndSeed,
0416                                      double ETopSeed,
0417                                      double EBottomSeed,
0418                                      double ELeftSeed,
0419                                      double ERightSeed,
0420                                      double E2x5MaxSeed,
0421                                      double E2x5TopSeed,
0422                                      double E2x5BottomSeed,
0423                                      double E2x5LeftSeed,
0424                                      double E2x5RightSeed,
0425                                      double IEtaSeed,
0426                                      double IPhiSeed,
0427                                      double EtaCrySeed,
0428                                      double PhiCrySeed,
0429                                      double PreShowerOverRaw,
0430                                      int IsEcalDriven,
0431                                      double GsfTrackPIn,
0432                                      double fbrem,
0433                                      double Charge,
0434                                      double EoP,
0435                                      double TrackMomentumError,
0436                                      double EcalEnergyError,
0437                                      int Classification,
0438                                      double detaIn,
0439                                      double dphiIn,
0440                                      double detaCalo,
0441                                      double dphiCalo,
0442                                      double GsfTrackChiSqr,
0443                                      double KFTrackNLayers,
0444                                      double ElectronEnergyOverPout,
0445                                      bool printDebug = false);
0446 
0447   // Evaluates regression using tracker variables
0448   double regressionUncertaintyWithTrkVarV2(double SCRawEnergy,
0449                                            double scEta,
0450                                            double scPhi,
0451                                            double R9,
0452                                            double etawidth,
0453                                            double phiwidth,
0454                                            double NClusters,
0455                                            double HoE,
0456                                            double rho,
0457                                            double vertices,
0458                                            double EtaSeed,
0459                                            double PhiSeed,
0460                                            double ESeed,
0461                                            double E3x3Seed,
0462                                            double E5x5Seed,
0463                                            double see,
0464                                            double spp,
0465                                            double sep,
0466                                            double EMaxSeed,
0467                                            double E2ndSeed,
0468                                            double ETopSeed,
0469                                            double EBottomSeed,
0470                                            double ELeftSeed,
0471                                            double ERightSeed,
0472                                            double E2x5MaxSeed,
0473                                            double E2x5TopSeed,
0474                                            double E2x5BottomSeed,
0475                                            double E2x5LeftSeed,
0476                                            double E2x5RightSeed,
0477                                            double IEtaSeed,
0478                                            double IPhiSeed,
0479                                            double EtaCrySeed,
0480                                            double PhiCrySeed,
0481                                            double PreShowerOverRaw,
0482                                            int IsEcalDriven,
0483                                            double GsfTrackPIn,
0484                                            double fbrem,
0485                                            double Charge,
0486                                            double EoP,
0487                                            double TrackMomentumError,
0488                                            double EcalEnergyError,
0489                                            int Classification,
0490                                            double detaIn,
0491                                            double dphiIn,
0492                                            double detaCalo,
0493                                            double dphiCalo,
0494                                            double GsfTrackChiSqr,
0495                                            double KFTrackNLayers,
0496                                            double ElectronEnergyOverPout,
0497                                            bool printDebug = false);
0498 
0499   double regressionValueWithTrkVarV2(std::vector<double> &inputvars, bool printDebug = false);
0500   double regressionUncertaintyWithTrkVarV2(std::vector<double> &inputvars, bool printDebug = false);
0501 
0502   // Evaluates regression uncertainty with subcluster variables and without track variables
0503   double regressionValueWithSubClusters(double SCRawEnergy,
0504                                         double scEta,
0505                                         double scPhi,
0506                                         double R9,
0507                                         double etawidth,
0508                                         double phiwidth,
0509                                         double NClusters,
0510                                         double HoE,
0511                                         double rho,
0512                                         double vertices,
0513                                         double EtaSeed,
0514                                         double PhiSeed,
0515                                         double ESeed,
0516                                         double E3x3Seed,
0517                                         double E5x5Seed,
0518                                         double see,
0519                                         double spp,
0520                                         double sep,
0521                                         double EMaxSeed,
0522                                         double E2ndSeed,
0523                                         double ETopSeed,
0524                                         double EBottomSeed,
0525                                         double ELeftSeed,
0526                                         double ERightSeed,
0527                                         double E2x5MaxSeed,
0528                                         double E2x5TopSeed,
0529                                         double E2x5BottomSeed,
0530                                         double E2x5LeftSeed,
0531                                         double E2x5RightSeed,
0532                                         double IEtaSeed,
0533                                         double IPhiSeed,
0534                                         double EtaCrySeed,
0535                                         double PhiCrySeed,
0536                                         double PreShowerOverRaw,
0537                                         double isEcalDriven,
0538                                         double isEtaGap,
0539                                         double isPhiGap,
0540                                         double isDeeGap,
0541                                         double ESubs,
0542                                         double ESub1,
0543                                         double EtaSub1,
0544                                         double PhiSub1,
0545                                         double EMaxSub1,
0546                                         double E3x3Sub1,
0547                                         double ESub2,
0548                                         double EtaSub2,
0549                                         double PhiSub2,
0550                                         double EMaxSub2,
0551                                         double E3x3Sub2,
0552                                         double ESub3,
0553                                         double EtaSub3,
0554                                         double PhiSub3,
0555                                         double EMaxSub3,
0556                                         double E3x3Sub3,
0557                                         double NPshwClusters,
0558                                         double EPshwSubs,
0559                                         double EPshwSub1,
0560                                         double EtaPshwSub1,
0561                                         double PhiPshwSub1,
0562                                         double EPshwSub2,
0563                                         double EtaPshwSub2,
0564                                         double PhiPshwSub2,
0565                                         double EPshwSub3,
0566                                         double EtaPshwSub3,
0567                                         double PhiPshwSub3,
0568                                         bool isEB,
0569                                         bool printDebug = false);
0570 
0571   // Evaluates regression uncertainty with subcluster variables and without track variables
0572   double regressionUncertaintyWithSubClusters(double SCRawEnergy,
0573                                               double scEta,
0574                                               double scPhi,
0575                                               double R9,
0576                                               double etawidth,
0577                                               double phiwidth,
0578                                               double NClusters,
0579                                               double HoE,
0580                                               double rho,
0581                                               double vertices,
0582                                               double EtaSeed,
0583                                               double PhiSeed,
0584                                               double ESeed,
0585                                               double E3x3Seed,
0586                                               double E5x5Seed,
0587                                               double see,
0588                                               double spp,
0589                                               double sep,
0590                                               double EMaxSeed,
0591                                               double E2ndSeed,
0592                                               double ETopSeed,
0593                                               double EBottomSeed,
0594                                               double ELeftSeed,
0595                                               double ERightSeed,
0596                                               double E2x5MaxSeed,
0597                                               double E2x5TopSeed,
0598                                               double E2x5BottomSeed,
0599                                               double E2x5LeftSeed,
0600                                               double E2x5RightSeed,
0601                                               double IEtaSeed,
0602                                               double IPhiSeed,
0603                                               double EtaCrySeed,
0604                                               double PhiCrySeed,
0605                                               double PreShowerOverRaw,
0606                                               double isEcalDriven,
0607                                               double isEtaGap,
0608                                               double isPhiGap,
0609                                               double isDeeGap,
0610                                               double ESubs,
0611                                               double ESub1,
0612                                               double EtaSub1,
0613                                               double PhiSub1,
0614                                               double EMaxSub1,
0615                                               double E3x3Sub1,
0616                                               double ESub2,
0617                                               double EtaSub2,
0618                                               double PhiSub2,
0619                                               double EMaxSub2,
0620                                               double E3x3Sub2,
0621                                               double ESub3,
0622                                               double EtaSub3,
0623                                               double PhiSub3,
0624                                               double EMaxSub3,
0625                                               double E3x3Sub3,
0626                                               double NPshwClusters,
0627                                               double EPshwSubs,
0628                                               double EPshwSub1,
0629                                               double EtaPshwSub1,
0630                                               double PhiPshwSub1,
0631                                               double EPshwSub2,
0632                                               double EtaPshwSub2,
0633                                               double PhiPshwSub2,
0634                                               double EPshwSub3,
0635                                               double EtaPshwSub3,
0636                                               double PhiPshwSub3,
0637                                               bool isEB,
0638                                               bool printDebug = false);
0639 
0640 private:
0641   bool fIsInitialized;
0642   ElectronEnergyRegressionEvaluate::ElectronEnergyRegressionType fVersionType;
0643   GBRForest *forestCorrection_eb;  // Pointer to the GBRForest for barrel
0644   GBRForest *forestCorrection_ee;  // Pointer to the GBRForest for endcap
0645 
0646   GBRForest *forestUncertainty_eb;
0647   GBRForest *forestUncertainty_ee;
0648 };
0649 
0650 #endif