Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-05-11 23:51:53

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