Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-08-21 04:46:54

0001 // user include files
0002 #include "Validation/RecoEgamma/plugins/ElectronMcMiniAODSignalValidator.h"
0003 #include "CLHEP/Units/GlobalPhysicalConstants.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 
0006 // user include files
0007 
0008 using namespace reco;
0009 using namespace pat;
0010 
0011 ElectronMcSignalValidatorMiniAOD::ElectronMcSignalValidatorMiniAOD(const edm::ParameterSet& iConfig)
0012     : ElectronDqmAnalyzerBase(iConfig) {
0013   mcTruthCollection_ = consumes<edm::View<reco::GenParticle> >(
0014       iConfig.getParameter<edm::InputTag>("mcTruthCollection"));  // prunedGenParticles
0015   electronToken_ =
0016       consumes<pat::ElectronCollection>(iConfig.getParameter<edm::InputTag>("electrons"));  // slimmedElectrons
0017   electronTokenEndcaps_ =
0018       consumes<pat::ElectronCollection>(iConfig.getParameter<edm::InputTag>("electrons_endcaps"));  // slimmedElectrons
0019 
0020   edm::ParameterSet histosSet = iConfig.getParameter<edm::ParameterSet>("histosCfg");
0021   edm::ParameterSet isolationSet = iConfig.getParameter<edm::ParameterSet>("isolationCfg");
0022 
0023   maxPt_ = iConfig.getParameter<double>("MaxPt");
0024   maxAbsEta_ = iConfig.getParameter<double>("MaxAbsEta");
0025   deltaR_ = iConfig.getParameter<double>("DeltaR");
0026   deltaR2_ = deltaR_ * deltaR_;
0027   matchingIDs_ = iConfig.getParameter<std::vector<int> >("MatchingID");
0028   matchingMotherIDs_ = iConfig.getParameter<std::vector<int> >("MatchingMotherID");
0029   outputInternalPath_ = iConfig.getParameter<std::string>("OutputFolderName");
0030 
0031   // histos bining and limits
0032 
0033   xyz_nbin = histosSet.getParameter<int>("Nbinxyz");
0034 
0035   pt_nbin = histosSet.getParameter<int>("Nbinpt");
0036   pt2D_nbin = histosSet.getParameter<int>("Nbinpt2D");
0037   pteff_nbin = histosSet.getParameter<int>("Nbinpteff");
0038   pt_max = histosSet.getParameter<double>("Ptmax");
0039 
0040   fhits_nbin = histosSet.getParameter<int>("Nbinfhits");
0041   fhits_max = histosSet.getParameter<double>("Fhitsmax");
0042 
0043   eta_nbin = histosSet.getParameter<int>("Nbineta");
0044   eta2D_nbin = histosSet.getParameter<int>("Nbineta2D");
0045   eta_min = histosSet.getParameter<double>("Etamin");
0046   eta_max = histosSet.getParameter<double>("Etamax");
0047 
0048   detamatch_nbin = histosSet.getParameter<int>("Nbindetamatch");
0049   detamatch2D_nbin = histosSet.getParameter<int>("Nbindetamatch2D");
0050   detamatch_min = histosSet.getParameter<double>("Detamatchmin");
0051   detamatch_max = histosSet.getParameter<double>("Detamatchmax");
0052 
0053   dphi_nbin = histosSet.getParameter<int>("Nbindphi");
0054   dphi_min = histosSet.getParameter<double>("Dphimin");
0055   dphi_max = histosSet.getParameter<double>("Dphimax");
0056 
0057   dphimatch_nbin = histosSet.getParameter<int>("Nbindphimatch");
0058   dphimatch2D_nbin = histosSet.getParameter<int>("Nbindphimatch2D");
0059   dphimatch_min = histosSet.getParameter<double>("Dphimatchmin");
0060   dphimatch_max = histosSet.getParameter<double>("Dphimatchmax");
0061 
0062   hoe_nbin = histosSet.getParameter<int>("Nbinhoe");
0063   hoe_min = histosSet.getParameter<double>("Hoemin");
0064   hoe_max = histosSet.getParameter<double>("Hoemax");
0065 
0066   mee_nbin = histosSet.getParameter<int>("Nbinmee");
0067   mee_min = histosSet.getParameter<double>("Meemin");
0068   mee_max = histosSet.getParameter<double>("Meemax");
0069 
0070   poptrue_nbin = histosSet.getParameter<int>("Nbinpoptrue");
0071   poptrue_min = histosSet.getParameter<double>("Poptruemin");
0072   poptrue_max = histosSet.getParameter<double>("Poptruemax");
0073 
0074   set_EfficiencyFlag = histosSet.getParameter<bool>("EfficiencyFlag");
0075   set_StatOverflowFlag = histosSet.getParameter<bool>("StatOverflowFlag");
0076 
0077   ele_nbin = histosSet.getParameter<int>("NbinELE");
0078   ele_min = histosSet.getParameter<double>("ELE_min");
0079   ele_max = histosSet.getParameter<double>("ELE_max");
0080 
0081   // so to please coverity...
0082 
0083   h1_recEleNum = nullptr;
0084 
0085   h1_ele_vertexPt = nullptr;
0086   h1_ele_vertexPt_EB = nullptr;
0087   h1_ele_vertexPt_EE = nullptr;
0088   h1_ele_vertexEta = nullptr;
0089   h1_ele_vertexPt_nocut = nullptr;
0090 
0091   h1_scl_SigIEtaIEta_mAOD = nullptr;
0092   h1_scl_SigIEtaIEta_mAOD_barrel = nullptr;
0093   h1_scl_SigIEtaIEta_mAOD_endcaps = nullptr;
0094 
0095   h2_ele_foundHitsVsEta = nullptr;
0096   h2_ele_foundHitsVsEta_mAOD = nullptr;
0097 
0098   h2_ele_PoPtrueVsEta = nullptr;
0099   h2_ele_sigmaIetaIetaVsPt = nullptr;
0100 
0101   h1_ele_HoE_mAOD = nullptr;
0102   h1_ele_HoE_mAOD_barrel = nullptr;
0103   h1_ele_HoE_mAOD_endcaps = nullptr;
0104   h1_ele_mee_all = nullptr;
0105   h1_ele_mee_os = nullptr;
0106 
0107   h1_ele_fbrem_mAOD = nullptr;
0108   h1_ele_fbrem_mAOD_barrel = nullptr;
0109   h1_ele_fbrem_mAOD_endcaps = nullptr;
0110 
0111   h1_ele_dEtaSc_propVtx_mAOD = nullptr;
0112   h1_ele_dEtaSc_propVtx_mAOD_barrel = nullptr;
0113   h1_ele_dEtaSc_propVtx_mAOD_endcaps = nullptr;
0114   h1_ele_dPhiCl_propOut_mAOD = nullptr;
0115   h1_ele_dPhiCl_propOut_mAOD_barrel = nullptr;
0116   h1_ele_dPhiCl_propOut_mAOD_endcaps = nullptr;
0117 
0118   h1_ele_chargedHadronRelativeIso_mAOD = nullptr;
0119   h1_ele_chargedHadronRelativeIso_mAOD_barrel = nullptr;
0120   h1_ele_chargedHadronRelativeIso_mAOD_endcaps = nullptr;
0121   h1_ele_neutralHadronRelativeIso_mAOD = nullptr;
0122   h1_ele_neutralHadronRelativeIso_mAOD_barrel = nullptr;
0123   h1_ele_neutralHadronRelativeIso_mAOD_endcaps = nullptr;
0124   h1_ele_photonRelativeIso_mAOD = nullptr;
0125   h1_ele_photonRelativeIso_mAOD_barrel = nullptr;
0126   h1_ele_photonRelativeIso_mAOD_endcaps = nullptr;
0127 }
0128 
0129 ElectronMcSignalValidatorMiniAOD::~ElectronMcSignalValidatorMiniAOD() {}
0130 
0131 void ElectronMcSignalValidatorMiniAOD::bookHistograms(DQMStore::IBooker& iBooker,
0132                                                       edm::Run const&,
0133                                                       edm::EventSetup const&) {
0134   iBooker.setCurrentFolder(outputInternalPath_);
0135 
0136   setBookIndex(-1);
0137   setBookPrefix("h");
0138   setBookEfficiencyFlag(set_EfficiencyFlag);
0139   setBookStatOverflowFlag(set_StatOverflowFlag);
0140 
0141   // rec event collections sizes
0142   h1_recEleNum = bookH1(iBooker, "recEleNum", "# rec electrons", ele_nbin, ele_min, ele_max, "N_{ele}");
0143   // matched electrons
0144   setBookPrefix("h_mc");
0145   setBookPrefix("h_ele");
0146   h1_ele_vertexPt =
0147       bookH1withSumw2(iBooker, "vertexPt", "ele transverse momentum", pt_nbin, 0., pt_max, "p_{T vertex} (GeV/c)");
0148   h1_ele_vertexPt_EB = bookH1withSumw2(
0149       iBooker, "vertexPt_EB", "ele transverse momentum barrel", pt_nbin, 0., pt_max, "p_{T vertex} (GeV/c)");
0150   h1_ele_vertexPt_EE = bookH1withSumw2(
0151       iBooker, "vertexPt_EE", "ele transverse momentum endcaps", pt_nbin, 0., pt_max, "p_{T vertex} (GeV/c)");
0152   h1_ele_vertexEta = bookH1withSumw2(iBooker, "vertexEta", "ele momentum eta", eta_nbin, eta_min, eta_max, "#eta");
0153   h1_ele_vertexPt_nocut =
0154       bookH1withSumw2(iBooker, "vertexPt_nocut", "pT of prunned electrons", pt_nbin, 0., 20., "p_{T vertex} (GeV/c)");
0155   h2_ele_PoPtrueVsEta = bookH2withSumw2(iBooker,
0156                                         "PoPtrueVsEta",
0157                                         "ele momentum / gen momentum vs eta",
0158                                         eta2D_nbin,
0159                                         eta_min,
0160                                         eta_max,
0161                                         50,
0162                                         poptrue_min,
0163                                         poptrue_max);
0164   h2_ele_sigmaIetaIetaVsPt =
0165       bookH2(iBooker, "sigmaIetaIetaVsPt", "SigmaIetaIeta vs pt", 100, 0., pt_max, 100, 0., 0.05);
0166 
0167   // all electrons
0168   setBookPrefix("h_ele");
0169   h1_ele_mee_all = bookH1withSumw2(iBooker,
0170                                    "mee_all",
0171                                    "ele pairs invariant mass, all reco electrons",
0172                                    mee_nbin,
0173                                    mee_min,
0174                                    mee_max,
0175                                    "m_{ee} (GeV/c^{2})",
0176                                    "Events",
0177                                    "ELE_LOGY E1 P");
0178   h1_ele_mee_os = bookH1withSumw2(iBooker,
0179                                   "mee_os",
0180                                   "ele pairs invariant mass, opp. sign",
0181                                   mee_nbin,
0182                                   mee_min,
0183                                   mee_max,
0184                                   "m_{e^{+}e^{-}} (GeV/c^{2})",
0185                                   "Events",
0186                                   "ELE_LOGY E1 P");
0187 
0188   // matched electron, superclusters
0189   setBookPrefix("h_scl");
0190   h1_scl_SigIEtaIEta_mAOD = bookH1withSumw2(iBooker,
0191                                             "SigIEtaIEta_mAOD",
0192                                             "ele supercluster sigma ieta ieta",
0193                                             100,
0194                                             0.,
0195                                             0.05,
0196                                             "#sigma_{i#eta i#eta}",
0197                                             "Events",
0198                                             "ELE_LOGY E1 P");
0199   h1_scl_SigIEtaIEta_mAOD_barrel = bookH1withSumw2(iBooker,
0200                                                    "SigIEtaIEta_mAOD_barrel",
0201                                                    "ele supercluster sigma ieta ieta, barrel",
0202                                                    100,
0203                                                    0.,
0204                                                    0.05,
0205                                                    "#sigma_{i#eta i#eta}",
0206                                                    "Events",
0207                                                    "ELE_LOGY E1 P");
0208   h1_scl_SigIEtaIEta_mAOD_endcaps = bookH1withSumw2(iBooker,
0209                                                     "SigIEtaIEta_mAOD_endcaps",
0210                                                     "ele supercluster sigma ieta ieta, endcaps",
0211                                                     100,
0212                                                     0.,
0213                                                     0.05,
0214                                                     "#sigma_{i#eta i#eta}",
0215                                                     "Events",
0216                                                     "ELE_LOGY E1 P");
0217 
0218   // matched electron, gsf tracks
0219   setBookPrefix("h_ele");
0220   h2_ele_foundHitsVsEta = bookH2(iBooker,
0221                                  "foundHitsVsEta",
0222                                  "ele track # found hits vs eta",
0223                                  eta2D_nbin,
0224                                  eta_min,
0225                                  eta_max,
0226                                  fhits_nbin,
0227                                  0.,
0228                                  fhits_max);
0229   h2_ele_foundHitsVsEta_mAOD = bookH2(iBooker,
0230                                       "foundHitsVsEta_mAOD",
0231                                       "ele track # found hits vs eta",
0232                                       eta2D_nbin,
0233                                       eta_min,
0234                                       eta_max,
0235                                       fhits_nbin,
0236                                       0.,
0237                                       fhits_max);
0238 
0239   // matched electrons, matching
0240   setBookPrefix("h_ele");
0241   h1_ele_HoE_mAOD = bookH1withSumw2(iBooker,
0242                                     "HoE_mAOD",
0243                                     "ele hadronic energy / em energy",
0244                                     hoe_nbin,
0245                                     hoe_min,
0246                                     hoe_max,
0247                                     "H/E",
0248                                     "Events",
0249                                     "ELE_LOGY E1 P");
0250   h1_ele_HoE_mAOD_barrel = bookH1withSumw2(iBooker,
0251                                            "HoE_mAOD_barrel",
0252                                            "ele hadronic energy / em energy, barrel",
0253                                            hoe_nbin,
0254                                            hoe_min,
0255                                            hoe_max,
0256                                            "H/E",
0257                                            "Events",
0258                                            "ELE_LOGY E1 P");
0259   h1_ele_HoE_mAOD_endcaps = bookH1withSumw2(iBooker,
0260                                             "HoE_mAOD_endcaps",
0261                                             "ele hadronic energy / em energy, endcaps",
0262                                             hoe_nbin,
0263                                             hoe_min,
0264                                             hoe_max,
0265                                             "H/E",
0266                                             "Events",
0267                                             "ELE_LOGY E1 P");
0268   h1_ele_dEtaSc_propVtx_mAOD = bookH1withSumw2(iBooker,
0269                                                "dEtaSc_propVtx_mAOD",
0270                                                "ele #eta_{sc} - #eta_{tr}, prop from vertex",
0271                                                detamatch_nbin,
0272                                                detamatch_min,
0273                                                detamatch_max,
0274                                                "#eta_{sc} - #eta_{tr}",
0275                                                "Events",
0276                                                "ELE_LOGY E1 P");
0277   h1_ele_dEtaSc_propVtx_mAOD_barrel = bookH1withSumw2(iBooker,
0278                                                       "dEtaSc_propVtx_mAOD_barrel",
0279                                                       "ele #eta_{sc} - #eta_{tr}, prop from vertex, barrel",
0280                                                       detamatch_nbin,
0281                                                       detamatch_min,
0282                                                       detamatch_max,
0283                                                       "#eta_{sc} - #eta_{tr}",
0284                                                       "Events",
0285                                                       "ELE_LOGY E1 P");
0286   h1_ele_dEtaSc_propVtx_mAOD_endcaps = bookH1withSumw2(iBooker,
0287                                                        "dEtaSc_propVtx_mAOD_endcaps",
0288                                                        "ele #eta_{sc} - #eta_{tr}, prop from vertex, endcaps",
0289                                                        detamatch_nbin,
0290                                                        detamatch_min,
0291                                                        detamatch_max,
0292                                                        "#eta_{sc} - #eta_{tr}",
0293                                                        "Events",
0294                                                        "ELE_LOGY E1 P");
0295   h1_ele_dPhiCl_propOut_mAOD = bookH1withSumw2(iBooker,
0296                                                "dPhiCl_propOut_mAOD",
0297                                                "ele #phi_{cl} - #phi_{tr}, prop from outermost",
0298                                                dphimatch_nbin,
0299                                                dphimatch_min,
0300                                                dphimatch_max,
0301                                                "#phi_{seedcl} - #phi_{tr} (rad)",
0302                                                "Events",
0303                                                "ELE_LOGY E1 P");
0304   h1_ele_dPhiCl_propOut_mAOD_barrel = bookH1withSumw2(iBooker,
0305                                                       "dPhiCl_propOut_mAOD_barrel",
0306                                                       "ele #phi_{cl} - #phi_{tr}, prop from outermost, barrel",
0307                                                       dphimatch_nbin,
0308                                                       dphimatch_min,
0309                                                       dphimatch_max,
0310                                                       "#phi_{seedcl} - #phi_{tr} (rad)",
0311                                                       "Events",
0312                                                       "ELE_LOGY E1 P");
0313   h1_ele_dPhiCl_propOut_mAOD_endcaps = bookH1withSumw2(iBooker,
0314                                                        "dPhiCl_propOut_mAOD_endcaps",
0315                                                        "ele #phi_{cl} - #phi_{tr}, prop from outermost, endcaps",
0316                                                        dphimatch_nbin,
0317                                                        dphimatch_min,
0318                                                        dphimatch_max,
0319                                                        "#phi_{seedcl} - #phi_{tr} (rad)",
0320                                                        "Events",
0321                                                        "ELE_LOGY E1 P");
0322 
0323   // fbrem
0324   h1_ele_fbrem_mAOD = bookH1withSumw2(
0325       iBooker, "fbrem_mAOD", "ele brem fraction, mode of GSF components", 100, 0., 1., "P_{in} - P_{out} / P_{in}");
0326   h1_ele_fbrem_mAOD_barrel = bookH1withSumw2(iBooker,
0327                                              "fbrem_mAOD_barrel",
0328                                              "ele brem fraction for barrel, mode of GSF components",
0329                                              100,
0330                                              0.,
0331                                              1.,
0332                                              "P_{in} - P_{out} / P_{in}");
0333   h1_ele_fbrem_mAOD_endcaps = bookH1withSumw2(iBooker,
0334                                               "fbrem_mAOD_endcaps",
0335                                               "ele brem franction for endcaps, mode of GSF components",
0336                                               100,
0337                                               0.,
0338                                               1.,
0339                                               "P_{in} - P_{out} / P_{in}");
0340 
0341   // -- pflow over pT
0342   h1_ele_chargedHadronRelativeIso_mAOD = bookH1withSumw2(iBooker,
0343                                                          "chargedHadronRelativeIso_mAOD",
0344                                                          "chargedHadronRelativeIso",
0345                                                          100,
0346                                                          0.0,
0347                                                          2.,
0348                                                          "chargedHadronRelativeIso",
0349                                                          "Events",
0350                                                          "ELE_LOGY E1 P");
0351   h1_ele_chargedHadronRelativeIso_mAOD_barrel = bookH1withSumw2(iBooker,
0352                                                                 "chargedHadronRelativeIso_mAOD_barrel",
0353                                                                 "chargedHadronRelativeIso for barrel",
0354                                                                 100,
0355                                                                 0.0,
0356                                                                 2.,
0357                                                                 "chargedHadronRelativeIso_barrel",
0358                                                                 "Events",
0359                                                                 "ELE_LOGY E1 P");
0360   h1_ele_chargedHadronRelativeIso_mAOD_endcaps = bookH1withSumw2(iBooker,
0361                                                                  "chargedHadronRelativeIso_mAOD_endcaps",
0362                                                                  "chargedHadronRelativeIso for endcaps",
0363                                                                  100,
0364                                                                  0.0,
0365                                                                  2.,
0366                                                                  "chargedHadronRelativeIso_endcaps",
0367                                                                  "Events",
0368                                                                  "ELE_LOGY E1 P");
0369   h1_ele_neutralHadronRelativeIso_mAOD = bookH1withSumw2(iBooker,
0370                                                          "neutralHadronRelativeIso_mAOD",
0371                                                          "neutralHadronRelativeIso",
0372                                                          100,
0373                                                          0.0,
0374                                                          2.,
0375                                                          "neutralHadronRelativeIso",
0376                                                          "Events",
0377                                                          "ELE_LOGY E1 P");
0378   h1_ele_neutralHadronRelativeIso_mAOD_barrel = bookH1withSumw2(iBooker,
0379                                                                 "neutralHadronRelativeIso_mAOD_barrel",
0380                                                                 "neutralHadronRelativeIso for barrel",
0381                                                                 100,
0382                                                                 0.0,
0383                                                                 2.,
0384                                                                 "neutralHadronRelativeIso_barrel",
0385                                                                 "Events",
0386                                                                 "ELE_LOGY E1 P");
0387   h1_ele_neutralHadronRelativeIso_mAOD_endcaps = bookH1withSumw2(iBooker,
0388                                                                  "neutralHadronRelativeIso_mAOD_endcaps",
0389                                                                  "neutralHadronRelativeIso for endcaps",
0390                                                                  100,
0391                                                                  0.0,
0392                                                                  2.,
0393                                                                  "neutralHadronRelativeIso_endcaps",
0394                                                                  "Events",
0395                                                                  "ELE_LOGY E1 P");
0396   h1_ele_photonRelativeIso_mAOD = bookH1withSumw2(iBooker,
0397                                                   "photonRelativeIso_mAOD",
0398                                                   "photonRelativeIso",
0399                                                   100,
0400                                                   0.0,
0401                                                   2.,
0402                                                   "photonRelativeIso",
0403                                                   "Events",
0404                                                   "ELE_LOGY E1 P");
0405   h1_ele_photonRelativeIso_mAOD_barrel = bookH1withSumw2(iBooker,
0406                                                          "photonRelativeIso_mAOD_barrel",
0407                                                          "photonRelativeIso for barrel",
0408                                                          100,
0409                                                          0.0,
0410                                                          2.,
0411                                                          "photonRelativeIso_barrel",
0412                                                          "Events",
0413                                                          "ELE_LOGY E1 P");
0414   h1_ele_photonRelativeIso_mAOD_endcaps = bookH1withSumw2(iBooker,
0415                                                           "photonRelativeIso_mAOD_endcaps",
0416                                                           "photonRelativeIso for endcaps",
0417                                                           100,
0418                                                           0.0,
0419                                                           2.,
0420                                                           "photonRelativeIso_endcaps",
0421                                                           "Events",
0422                                                           "ELE_LOGY E1 P");
0423 }
0424 
0425 void ElectronMcSignalValidatorMiniAOD::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0426   // get collections
0427   auto electrons = iEvent.getHandle(electronToken_);
0428   auto electrons_endcaps = iEvent.getHandle(electronTokenEndcaps_);
0429   auto genParticles = iEvent.getHandle(mcTruthCollection_);
0430 
0431   edm::Handle<pat::ElectronCollection> mergedElectrons;
0432 
0433   edm::LogInfo("ElectronMcSignalValidatorMiniAOD::analyze")
0434       << "Treating event " << iEvent.id() << " with " << electrons.product()->size() << " electrons";
0435   edm::LogInfo("ElectronMcSignalValidatorMiniAOD::analyze")
0436       << "Treating event " << iEvent.id() << " with " << electrons_endcaps.product()->size()
0437       << " multi slimmed electrons";
0438 
0439   //h1_recEleNum->Fill((*electrons).size());
0440 
0441   //===============================================
0442   // all rec electrons
0443   //===============================================
0444 
0445   pat::Electron gsfElectron;
0446   pat::ElectronCollection::const_iterator el1;
0447   std::vector<pat::Electron>::const_iterator el3;
0448   std::vector<pat::Electron>::const_iterator el4;
0449 
0450   //===============================================
0451   // get a vector with EB  & EE
0452   //===============================================
0453   std::vector<pat::Electron> localCollection;
0454   std::vector<pat::Electron> localCollection_EB;
0455   std::vector<pat::Electron> localCollection_EE;
0456 
0457   // looking for EB
0458   for (el1 = electrons->begin(); el1 != electrons->end(); el1++) {
0459     if (el1->isEB()) {
0460       localCollection.push_back(*el1);
0461       localCollection_EB.push_back(*el1);
0462     }
0463   }
0464 
0465   // looking for EE
0466   for (el1 = electrons_endcaps->begin(); el1 != electrons_endcaps->end(); el1++) {
0467     if (el1->isEE()) {
0468       localCollection.push_back(*el1);
0469       localCollection_EE.push_back(*el1);
0470     }
0471   }
0472   h1_recEleNum->Fill((localCollection).size());
0473 
0474   for (el3 = localCollection.begin(); el3 != localCollection.end(); el3++) {
0475     for (el4 = el3 + 1; el4 != localCollection.end(); el4++) {
0476       math::XYZTLorentzVector p12 = el3->p4() + el4->p4();
0477       float mee2 = p12.Dot(p12);
0478       h1_ele_mee_all->Fill(sqrt(mee2));
0479       if (el3->charge() * el4->charge() < 0.) {
0480         h1_ele_mee_os->Fill(sqrt(mee2));
0481       }
0482     }
0483   }
0484 
0485   //===============================================
0486   // charge mis-ID
0487   //===============================================
0488 
0489   bool matchingMotherID;
0490 
0491   //===============================================
0492   // association mc-reco
0493   //===============================================
0494 
0495   for (size_t i = 0; i < genParticles->size(); i++) {
0496     // select requested mother matching gen particle
0497     // always include single particle with no mother
0498     const Candidate* mother = (*genParticles)[i].mother(0);
0499     matchingMotherID = false;
0500     for (unsigned int ii = 0; ii < matchingMotherIDs_.size(); ii++) {
0501       if (mother == nullptr) {
0502         matchingMotherID = true;
0503       } else if (mother->pdgId() == matchingMotherIDs_[ii]) {
0504         if (mother->numberOfDaughters() <= 2) {
0505           matchingMotherID = true;
0506         }
0507       }  // end of mother if test
0508 
0509     }  // end of for loop
0510     if (!matchingMotherID) {
0511       continue;
0512     }
0513 
0514     // electron preselection
0515     if ((*genParticles)[i].pt() > maxPt_ || std::abs((*genParticles)[i].eta()) > maxAbsEta_) {
0516       continue;
0517     }
0518 
0519     // find best matched electron
0520     bool okGsfFound = false;
0521     bool passMiniAODSelection = true;
0522     double gsfOkRatio = 999999.;
0523     bool isEBflag = false;
0524     bool isEEflag = false;
0525     pat::Electron bestGsfElectron;
0526 
0527     for (el3 = localCollection.begin(); el3 != localCollection.end(); el3++) {
0528       double dphi = el3->phi() - (*genParticles)[i].phi();
0529       if (std::abs(dphi) > CLHEP::pi) {
0530         dphi = dphi < 0 ? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
0531       }
0532       double deltaR2 = (el3->eta() - (*genParticles)[i].eta()) * (el3->eta() - (*genParticles)[i].eta()) + dphi * dphi;
0533       if (deltaR2 < deltaR2_) {
0534         if ((((*genParticles)[i].pdgId() == 11) && (el3->charge() < 0.)) ||
0535             (((*genParticles)[i].pdgId() == -11) && (el3->charge() > 0.))) {
0536           double tmpGsfRatio = el3->p() / (*genParticles)[i].p();
0537           if (std::abs(tmpGsfRatio - 1) < std::abs(gsfOkRatio - 1)) {
0538             gsfOkRatio = tmpGsfRatio;
0539             bestGsfElectron = *el3;
0540             okGsfFound = true;
0541           }
0542         }
0543       }
0544     }  // end *electrons loop
0545 
0546     if (okGsfFound) {
0547       //------------------------------------
0548       // analysis when the mc track is found
0549       //------------------------------------
0550       passMiniAODSelection = bestGsfElectron.pt() >= 5.;
0551       double one_over_pt = 1. / bestGsfElectron.pt();
0552       isEBflag = bestGsfElectron.isEB();
0553       isEEflag = bestGsfElectron.isEE();
0554 
0555       // electron related distributions
0556       h1_ele_vertexPt->Fill(bestGsfElectron.pt());
0557       if (isEBflag) {
0558         h1_ele_vertexPt_EB->Fill(bestGsfElectron.pt());
0559       } else if (isEEflag) {
0560         h1_ele_vertexPt_EE->Fill(bestGsfElectron.pt());
0561       }
0562       h1_ele_vertexEta->Fill(bestGsfElectron.eta());
0563       if ((bestGsfElectron.scSigmaIEtaIEta() == 0.) && (bestGsfElectron.fbrem() == 0.))
0564         h1_ele_vertexPt_nocut->Fill(bestGsfElectron.pt());
0565       // track related distributions
0566       h2_ele_foundHitsVsEta->Fill(bestGsfElectron.eta(), bestGsfElectron.gsfTrack()->numberOfValidHits());
0567 
0568       // generated distributions for matched electrons
0569       h2_ele_PoPtrueVsEta->Fill(bestGsfElectron.eta(), bestGsfElectron.p() / (*genParticles)[i].p());
0570 
0571       if (passMiniAODSelection) {  // Pt > 5.
0572         h2_ele_sigmaIetaIetaVsPt->Fill(bestGsfElectron.pt(), bestGsfElectron.scSigmaIEtaIEta());
0573 
0574         // supercluster related distributions
0575         h1_scl_SigIEtaIEta_mAOD->Fill(bestGsfElectron.scSigmaIEtaIEta());
0576         h1_ele_dEtaSc_propVtx_mAOD->Fill(bestGsfElectron.deltaEtaSuperClusterTrackAtVtx());
0577         h1_ele_dPhiCl_propOut_mAOD->Fill(bestGsfElectron.deltaPhiSeedClusterTrackAtCalo());
0578 
0579         // track related distributions
0580         h2_ele_foundHitsVsEta_mAOD->Fill(bestGsfElectron.eta(), bestGsfElectron.gsfTrack()->numberOfValidHits());
0581 
0582         // match distributions
0583         h1_ele_HoE_mAOD->Fill(bestGsfElectron.hcalOverEcal());
0584 
0585         // fbrem
0586         h1_ele_fbrem_mAOD->Fill(bestGsfElectron.fbrem());
0587 
0588         // -- pflow over pT
0589 
0590         h1_ele_chargedHadronRelativeIso_mAOD->Fill(bestGsfElectron.pfIsolationVariables().sumChargedHadronPt *
0591                                                    one_over_pt);
0592         h1_ele_neutralHadronRelativeIso_mAOD->Fill(bestGsfElectron.pfIsolationVariables().sumNeutralHadronEt *
0593                                                    one_over_pt);
0594         h1_ele_photonRelativeIso_mAOD->Fill(bestGsfElectron.pfIsolationVariables().sumPhotonEt * one_over_pt);
0595 
0596         if (isEBflag) {
0597           // supercluster related distributions
0598           h1_scl_SigIEtaIEta_mAOD_barrel->Fill(bestGsfElectron.scSigmaIEtaIEta());
0599           h1_ele_dEtaSc_propVtx_mAOD_barrel->Fill(bestGsfElectron.deltaEtaSuperClusterTrackAtVtx());
0600           h1_ele_dPhiCl_propOut_mAOD_barrel->Fill(bestGsfElectron.deltaPhiSeedClusterTrackAtCalo());
0601           // match distributions
0602           h1_ele_HoE_mAOD_barrel->Fill(bestGsfElectron.hcalOverEcal());
0603           // fbrem
0604           h1_ele_fbrem_mAOD_barrel->Fill(bestGsfElectron.fbrem());
0605 
0606           h1_ele_chargedHadronRelativeIso_mAOD_barrel->Fill(bestGsfElectron.pfIsolationVariables().sumChargedHadronPt *
0607                                                             one_over_pt);
0608           h1_ele_neutralHadronRelativeIso_mAOD_barrel->Fill(bestGsfElectron.pfIsolationVariables().sumNeutralHadronEt *
0609                                                             one_over_pt);
0610           h1_ele_photonRelativeIso_mAOD_barrel->Fill(bestGsfElectron.pfIsolationVariables().sumPhotonEt * one_over_pt);
0611         }
0612 
0613         // supercluster related distributions
0614         else if (isEEflag) {
0615           h1_scl_SigIEtaIEta_mAOD_endcaps->Fill(bestGsfElectron.scSigmaIEtaIEta());
0616           h1_ele_dEtaSc_propVtx_mAOD_endcaps->Fill(bestGsfElectron.deltaEtaSuperClusterTrackAtVtx());
0617           h1_ele_dPhiCl_propOut_mAOD_endcaps->Fill(bestGsfElectron.deltaPhiSeedClusterTrackAtCalo());
0618           // match distributions
0619           h1_ele_HoE_mAOD_endcaps->Fill(bestGsfElectron.hcalOverEcal());
0620           // fbrem
0621           h1_ele_fbrem_mAOD_endcaps->Fill(bestGsfElectron.fbrem());
0622           h1_ele_chargedHadronRelativeIso_mAOD_endcaps->Fill(bestGsfElectron.pfIsolationVariables().sumChargedHadronPt *
0623                                                              one_over_pt);
0624           h1_ele_neutralHadronRelativeIso_mAOD_endcaps->Fill(bestGsfElectron.pfIsolationVariables().sumNeutralHadronEt *
0625                                                              one_over_pt);
0626           h1_ele_photonRelativeIso_mAOD_endcaps->Fill(bestGsfElectron.pfIsolationVariables().sumPhotonEt * one_over_pt);
0627         }
0628       }
0629     }
0630     //} // end loop i_elec
0631   }  // end loop size_t i
0632 }