Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:12:47

0001 /** \class DQMPFCandidateAnalyzer
0002  *
0003  *  DQM jetMET analysis monitoring
0004  *  for PFCandidates
0005  *
0006  *          Jan. '16: by
0007  *
0008  *          M. Artur Weber
0009  */
0010 
0011 #include "DQMOffline/JetMET/interface/DQMPFCandidateAnalyzer.h"
0012 
0013 #include "FWCore/Framework/interface/Event.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/Common/interface/TriggerNames.h"
0016 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
0017 #include "DataFormats/JetReco/interface/CaloJet.h"
0018 #include "DataFormats/JetReco/interface/JPTJetCollection.h"
0019 #include "DataFormats/JetReco/interface/PFJetCollection.h"
0020 #include "DataFormats/JetReco/interface/PFJet.h"
0021 #include "DataFormats/PatCandidates/interface/Jet.h"
0022 #include "DataFormats/Candidate/interface/Candidate.h"
0023 #include "DataFormats/Common/interface/Handle.h"
0024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0025 
0026 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
0027 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
0028 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0029 
0030 #include "FWCore/Framework/interface/ESHandle.h"
0031 #include "DataFormats/Math/interface/deltaR.h"
0032 #include "RecoJets/JetAssociationAlgorithms/interface/JetTracksAssociationDRCalo.h"
0033 #include "DataFormats/Math/interface/Point3D.h"
0034 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0035 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0036 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
0037 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
0038 #include "DataFormats/TrackerRecHit2D/interface/ProjectedSiStripRecHit2D.h"
0039 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
0040 #include "DataFormats/TrackingRecHit/interface/InvalidTrackingRecHit.h"
0041 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0042 #include "DataFormats/DetId/interface/DetId.h"
0043 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
0044 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
0045 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
0046 #include "CalibFormats/SiStripObjects/interface/SiStripGain.h"
0047 #include "CalibTracker/Records/interface/SiStripQualityRcd.h"
0048 #include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
0049 #include "CalibTracker/Records/interface/SiStripGainRcd.h"
0050 
0051 #include <string>
0052 
0053 #include <cmath>
0054 
0055 using namespace edm;
0056 using namespace reco;
0057 using namespace std;
0058 
0059 // ***********************************************************
0060 DQMPFCandidateAnalyzer::DQMPFCandidateAnalyzer(const edm::ParameterSet& pSet)
0061 //: trackPropagator_(new jetAnalysis::TrackPropagatorToCalo)//,
0062 //sOverNCalculator_(new jetAnalysis::StripSignalOverNoiseCalculator)
0063 {
0064   miniaodfilterdec = -1;
0065 
0066   candidateType_ = pSet.getUntrackedParameter<std::string>("CandType");
0067   //here only choice between miniaod or reco
0068 
0069   LSBegin_ = pSet.getParameter<int>("LSBegin");
0070   LSEnd_ = pSet.getParameter<int>("LSEnd");
0071 
0072   isMiniAOD_ = (std::string("Packed") == candidateType_);
0073 
0074   mInputCollection_ = pSet.getParameter<edm::InputTag>("PFCandidateLabel");
0075 
0076   if (isMiniAOD_) {
0077     pflowPackedToken_ = consumes<std::vector<pat::PackedCandidate> >(mInputCollection_);
0078   } else {
0079     pflowToken_ = consumes<std::vector<reco::PFCandidate> >(mInputCollection_);
0080   }
0081 
0082   miniaodfilterdec = -1;
0083 
0084   // Smallest track pt
0085   ptMinCand_ = pSet.getParameter<double>("ptMinCand");
0086 
0087   // Smallest raw HCAL energy linked to the track
0088   hcalMin_ = pSet.getParameter<double>("hcalMin");
0089 
0090   diagnosticsParameters_ = pSet.getParameter<std::vector<edm::ParameterSet> >("METDiagonisticsParameters");
0091 
0092   edm::ConsumesCollector iC = consumesCollector();
0093   //DCS
0094   DCSFilter_ = new JetMETDQMDCSFilter(pSet.getParameter<ParameterSet>("DCSFilter"), iC);
0095   if (isMiniAOD_) {
0096     METFilterMiniAODLabel_ = pSet.getParameter<edm::InputTag>("FilterResultsLabelMiniAOD");
0097     METFilterMiniAODToken_ = consumes<edm::TriggerResults>(METFilterMiniAODLabel_);
0098 
0099     METFilterMiniAODLabel2_ = pSet.getParameter<edm::InputTag>("FilterResultsLabelMiniAOD2");
0100     METFilterMiniAODToken2_ = consumes<edm::TriggerResults>(METFilterMiniAODLabel2_);
0101 
0102     HBHENoiseStringMiniAOD = pSet.getParameter<std::string>("HBHENoiseLabelMiniAOD");
0103   }
0104 
0105   if (!isMiniAOD_) {
0106     hbheNoiseFilterResultTag_ = pSet.getParameter<edm::InputTag>("HBHENoiseFilterResultLabel");
0107     hbheNoiseFilterResultToken_ = consumes<bool>(hbheNoiseFilterResultTag_);
0108   }
0109   //jet cleanup parameters
0110   cleaningParameters_ = pSet.getParameter<ParameterSet>("CleaningParameters");
0111 
0112   //Vertex requirements
0113   bypassAllPVChecks_ = cleaningParameters_.getParameter<bool>("bypassAllPVChecks");
0114   bypassAllDCSChecks_ = cleaningParameters_.getParameter<bool>("bypassAllDCSChecks");
0115   vertexTag_ = cleaningParameters_.getParameter<edm::InputTag>("vertexCollection");
0116   vertexToken_ = consumes<std::vector<reco::Vertex> >(edm::InputTag(vertexTag_));
0117 
0118   verbose_ = pSet.getParameter<int>("verbose");
0119 }
0120 
0121 // ***********************************************************
0122 DQMPFCandidateAnalyzer::~DQMPFCandidateAnalyzer() {
0123   delete DCSFilter_;
0124   LogTrace("DQMPFCandidateAnalyzer") << "[DQMPFCandidateAnalyzer] Saving the histos";
0125 }
0126 
0127 // ***********************************************************
0128 void DQMPFCandidateAnalyzer::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const&) {
0129   ibooker.setCurrentFolder("JetMET/PFCandidates/" + mInputCollection_.label());
0130   std::string DirName = "JetMET/PFCandidates/" + mInputCollection_.label();
0131 
0132   if (!isMiniAOD_) {
0133     if (!occupancyPFCandRECO_.empty())
0134       occupancyPFCandRECO_.clear();
0135     if (!occupancyPFCand_nameRECO_.empty())
0136       occupancyPFCand_nameRECO_.clear();
0137     if (!etaMinPFCandRECO_.empty())
0138       etaMinPFCandRECO_.clear();
0139     if (!etaMaxPFCandRECO_.empty())
0140       etaMaxPFCandRECO_.clear();
0141     if (!typePFCandRECO_.empty())
0142       typePFCandRECO_.clear();
0143     if (!countsPFCandRECO_.empty())
0144       countsPFCandRECO_.clear();
0145     if (!ptPFCandRECO_.empty())
0146       ptPFCandRECO_.clear();
0147     if (!ptPFCand_nameRECO_.empty())
0148       ptPFCand_nameRECO_.clear();
0149     if (!multiplicityPFCandRECO_.empty())
0150       multiplicityPFCandRECO_.clear();
0151     if (!multiplicityPFCand_nameRECO_.empty())
0152       multiplicityPFCand_nameRECO_.clear();
0153     for (std::vector<edm::ParameterSet>::const_iterator v = diagnosticsParameters_.begin();
0154          v != diagnosticsParameters_.end();
0155          v++) {
0156       int etaNBinsPFCand = v->getParameter<int>("etaNBins");
0157       double etaMinPFCand = v->getParameter<double>("etaMin");
0158       double etaMaxPFCand = v->getParameter<double>("etaMax");
0159       int phiNBinsPFCand = v->getParameter<int>("phiNBins");
0160       double phiMinPFCand = v->getParameter<double>("phiMin");
0161       double phiMaxPFCand = v->getParameter<double>("phiMax");
0162       int nMinPFCand = v->getParameter<int>("nMin");
0163       int nMaxPFCand = v->getParameter<int>("nMax");
0164       int nbinsPFCand = v->getParameter<double>("nbins");
0165       etaMinPFCandRECO_.push_back(etaMinPFCand);
0166       etaMaxPFCandRECO_.push_back(etaMaxPFCand);
0167       typePFCandRECO_.push_back(v->getParameter<int>("type"));
0168       countsPFCandRECO_.push_back(0);
0169       multiplicityPFCandRECO_.push_back(
0170           ibooker.book1D(std::string(v->getParameter<std::string>("name")).append("_multiplicity_").c_str(),
0171                          std::string(v->getParameter<std::string>("name")) + "multiplicity",
0172                          nbinsPFCand,
0173                          nMinPFCand,
0174                          nMaxPFCand));
0175       multiplicityPFCand_nameRECO_.push_back(
0176           std::string(v->getParameter<std::string>("name")).append("_multiplicity_"));
0177       map_of_MEs.insert(std::pair<std::string, MonitorElement*>(
0178           DirName + "/" + multiplicityPFCand_nameRECO_[multiplicityPFCand_nameRECO_.size() - 1],
0179           multiplicityPFCandRECO_[multiplicityPFCandRECO_.size() - 1]));
0180 
0181       //push back names first, we need to create histograms with the name and fill it for endcap plots later
0182       occupancyPFCand_nameRECO_.push_back(std::string(v->getParameter<std::string>("name")).append("_occupancy_"));
0183 
0184       ptPFCand_nameRECO_.push_back(std::string(v->getParameter<std::string>("name")).append("_pt_"));
0185       //special booking for endcap plots, merge plots for eminus and eplus into one plot, using variable binning
0186       //barrel plots have eta-boundaries on minus and plus side
0187       //parameters start on minus side
0188       if (etaMinPFCand * etaMaxPFCand < 0) {  //barrel plots, plot only in barrel region
0189         occupancyPFCandRECO_.push_back(
0190             ibooker.book2D(std::string(v->getParameter<std::string>("name")).append("_occupancy_").c_str(),
0191                            std::string(v->getParameter<std::string>("name")) + "occupancy",
0192                            etaNBinsPFCand,
0193                            etaMinPFCand,
0194                            etaMaxPFCand,
0195                            phiNBinsPFCand,
0196                            phiMinPFCand,
0197                            phiMaxPFCand));
0198         ptPFCandRECO_.push_back(ibooker.book2D(std::string(v->getParameter<std::string>("name")).append("_pt_").c_str(),
0199                                                std::string(v->getParameter<std::string>("name")) + "pt",
0200                                                etaNBinsPFCand,
0201                                                etaMinPFCand,
0202                                                etaMaxPFCand,
0203                                                phiNBinsPFCand,
0204                                                phiMinPFCand,
0205                                                phiMaxPFCand));
0206       } else {  //endcap or forward plots,
0207         const int nbins_eta_endcap = 2 * (etaNBinsPFCand + 1);
0208         double eta_limits_endcap[nbins_eta_endcap];
0209         for (int i = 0; i < nbins_eta_endcap; i++) {
0210           if (i < (etaNBinsPFCand + 1)) {
0211             eta_limits_endcap[i] = etaMinPFCand + i * (etaMaxPFCand - etaMinPFCand) / (double)etaNBinsPFCand;
0212           } else {
0213             eta_limits_endcap[i] =
0214                 -etaMaxPFCand + (i - (etaNBinsPFCand + 1)) * (etaMaxPFCand - etaMinPFCand) / (double)etaNBinsPFCand;
0215           }
0216         }
0217         TH2F* hist_temp_occup = new TH2F((occupancyPFCand_nameRECO_[occupancyPFCand_nameRECO_.size() - 1]).c_str(),
0218                                          "occupancy",
0219                                          nbins_eta_endcap - 1,
0220                                          eta_limits_endcap,
0221                                          phiNBinsPFCand,
0222                                          phiMinPFCand,
0223                                          phiMaxPFCand);
0224         occupancyPFCandRECO_.push_back(
0225             ibooker.book2D(occupancyPFCand_nameRECO_[occupancyPFCand_nameRECO_.size() - 1], hist_temp_occup));
0226         TH2F* hist_temp_pt = new TH2F((ptPFCand_nameRECO_[ptPFCand_nameRECO_.size() - 1]).c_str(),
0227                                       "pt",
0228                                       nbins_eta_endcap - 1,
0229                                       eta_limits_endcap,
0230                                       phiNBinsPFCand,
0231                                       phiMinPFCand,
0232                                       phiMaxPFCand);
0233         ptPFCandRECO_.push_back(ibooker.book2D(ptPFCand_nameRECO_[ptPFCand_nameRECO_.size() - 1], hist_temp_pt));
0234       }
0235 
0236       map_of_MEs.insert(std::pair<std::string, MonitorElement*>(
0237           DirName + "/" + occupancyPFCand_nameRECO_[occupancyPFCand_nameRECO_.size() - 1],
0238           occupancyPFCandRECO_[occupancyPFCandRECO_.size() - 1]));
0239       map_of_MEs.insert(std::pair<std::string, MonitorElement*>(
0240           DirName + "/" + ptPFCand_nameRECO_[ptPFCand_nameRECO_.size() - 1], ptPFCandRECO_[ptPFCandRECO_.size() - 1]));
0241     }
0242 
0243     mProfileIsoPFChHad_TrackOccupancy = ibooker.book2D(
0244         "IsoPfChHad_Track_profile", "Isolated PFChHadron Tracker_occupancy", 108, -2.7, 2.7, 160, -M_PI, M_PI);
0245     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "IsoPfChHad_Track_profile",
0246                                                               mProfileIsoPFChHad_TrackOccupancy));
0247     mProfileIsoPFChHad_TrackPt =
0248         ibooker.book2D("IsoPfChHad_TrackPt", "Isolated PFChHadron TrackPt", 108, -2.7, 2.7, 160, -M_PI, M_PI);
0249     map_of_MEs.insert(
0250         std::pair<std::string, MonitorElement*>(DirName + "/" + "IsoPfChHad_TrackPt", mProfileIsoPFChHad_TrackPt));
0251 
0252     mProfileIsoPFChHad_EcalOccupancyCentral = ibooker.book2D("IsoPfChHad_ECAL_profile_central",
0253                                                              "IsolatedPFChHa ECAL occupancy (Barrel)",
0254                                                              180,
0255                                                              -1.479,
0256                                                              1.479,
0257                                                              125,
0258                                                              -M_PI,
0259                                                              M_PI);
0260     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "IsoPfChHad_ECAL_profile_central",
0261                                                               mProfileIsoPFChHad_EcalOccupancyCentral));
0262     mProfileIsoPFChHad_EMPtCentral = ibooker.book2D(
0263         "IsoPfChHad_EMPt_central", "Isolated PFChHadron HadPt_central", 180, -1.479, 1.479, 360, -M_PI, M_PI);
0264     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "IsoPfChHad_EMPt_central",
0265                                                               mProfileIsoPFChHad_EMPtCentral));
0266 
0267     mProfileIsoPFChHad_EcalOccupancyEndcap = ibooker.book2D(
0268         "IsoPfChHad_ECAL_profile_endcap", "IsolatedPFChHa ECAL occupancy (Endcap)", 110, -2.75, 2.75, 125, -M_PI, M_PI);
0269     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "IsoPfChHad_ECAL_profile_endcap",
0270                                                               mProfileIsoPFChHad_EcalOccupancyEndcap));
0271     mProfileIsoPFChHad_EMPtEndcap =
0272         ibooker.book2D("IsoPfChHad_EMPt_endcap", "Isolated PFChHadron EMPt_endcap", 110, -2.75, 2.75, 125, -M_PI, M_PI);
0273     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "IsoPfChHad_EMPt_endcap",
0274                                                               mProfileIsoPFChHad_EMPtEndcap));
0275 
0276     const int nbins_eta = 16;
0277 
0278     double eta_limits[nbins_eta] = {-2.650,
0279                                     -2.500,
0280                                     -2.322,
0281                                     -2.172,
0282                                     -2.043,
0283                                     -1.930,
0284                                     -1.830,
0285                                     -1.740,
0286                                     1.740,
0287                                     1.830,
0288                                     1.930,
0289                                     2.043,
0290                                     2.172,
0291                                     2.3122,
0292                                     2.500,
0293                                     2.650};
0294 
0295     TH2F* hist_temp_HCAL = new TH2F("IsoPfChHad_HCAL_profile_endcap",
0296                                     "IsolatedPFChHa HCAL occupancy (outer endcap)",
0297                                     nbins_eta - 1,
0298                                     eta_limits,
0299                                     36,
0300                                     -M_PI,
0301                                     M_PI);
0302     TH2F* hist_tempPt_HCAL = (TH2F*)hist_temp_HCAL->Clone("Isolated PFCHHadron HadPt (outer endcap)");
0303 
0304     mProfileIsoPFChHad_HcalOccupancyCentral = ibooker.book2D("IsoPfChHad_HCAL_profile_central",
0305                                                              "IsolatedPFChHa HCAL occupancy (Central Part)",
0306                                                              40,
0307                                                              -1.740,
0308                                                              1.740,
0309                                                              72,
0310                                                              -M_PI,
0311                                                              M_PI);
0312     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "IsoPfChHad_HCAL_profile_central",
0313                                                               mProfileIsoPFChHad_HcalOccupancyCentral));
0314     mProfileIsoPFChHad_HadPtCentral = ibooker.book2D(
0315         "IsoPfChHad_HadPt_central", "Isolated PFChHadron HadPt_central", 40, -1.740, 1.740, 72, -M_PI, M_PI);
0316     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "IsoPfChHad_HadPt_central",
0317                                                               mProfileIsoPFChHad_HadPtCentral));
0318 
0319     mProfileIsoPFChHad_HcalOccupancyEndcap = ibooker.book2D("IsoPfChHad_HCAL_profile_endcap", hist_temp_HCAL);
0320     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "IsoPfChHad_HCAL_profile_endcap",
0321                                                               mProfileIsoPFChHad_HcalOccupancyEndcap));
0322     mProfileIsoPFChHad_HadPtEndcap = ibooker.book2D("IsoPfChHad_HadPt_endcap", hist_tempPt_HCAL);
0323     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "IsoPfChHad_HadPt_endcap",
0324                                                               mProfileIsoPFChHad_HadPtEndcap));
0325 
0326     //actual HCAL segmentation in pseudorapidity -> reduce by a factor of two
0327     //const int nbins_eta_hcal_total=54;
0328     //double eta_limits_hcal_total[nbins_eta_hcal_total]=
0329     //   {-2.650,-2.500,-2.322,-2.172,-2.043,-1.930,-1.830,-1.740,-1.653,-1.566,-1.479,-1.392,-1.305,
0330     //   -1.218,-1.131,-1.044,-0.957,-0.870,-0.783,-0.696,-0.609,-0.522,-0.435,-0.348,-0.261,-0.174,-0.087,0.0,
0331     //   0.087, 0.174, 0.261, 0.348, 0.435, 0.522, 0.609, 0.783, 0.870, 0.957, 1.044, 1.131, 1.218
0332     //   1.305, 1.392, 1.479, 1.566, 1.653, 1.740, 1.830, 1.930, 2.043, 2.172, 2.322, 2.500, 2.650}
0333     //
0334 
0335     const int nbins_eta_hcal_total = 28;
0336     double eta_limits_hcal_total[nbins_eta_hcal_total] = {
0337         -2.650, -2.322, -2.043, -1.830, -1.653, -1.479, -1.305, -1.131, -0.957, -0.783, -0.609, -0.435, -0.261, -0.087,
0338         0.087,  0.261,  0.435,  0.609,  0.783,  0.957,  1.131,  1.305,  1.479,  1.653,  1.830,  2.043,  2.322,  2.650};
0339     float eta_limits_hcal_total_f[nbins_eta_hcal_total];
0340     float log_bin_spacing = log(200.) / 40.;
0341     const int nbins_pt_total_hcal = 41;
0342     double pt_limits_hcal[nbins_pt_total_hcal];
0343     float pt_limits_hcal_f[nbins_pt_total_hcal];
0344     for (int i = 0; i < nbins_pt_total_hcal; i++) {
0345       pt_limits_hcal[i] = exp(i * log_bin_spacing);
0346       pt_limits_hcal_f[i] = exp(i * log_bin_spacing);
0347     }
0348     for (int i = 0; i < nbins_eta_hcal_total; i++) {
0349       eta_limits_hcal_total_f[i] = (float)eta_limits_hcal_total[i];
0350     }
0351     m_HOverTrackP_trackPtVsEta = ibooker.book2D("HOverTrackP_trackPtVsEta",
0352                                                 "HOverTrackP_trackPtVsEta",
0353                                                 nbins_pt_total_hcal - 1,
0354                                                 pt_limits_hcal_f,
0355                                                 nbins_eta_hcal_total - 1,
0356                                                 eta_limits_hcal_total_f);
0357     m_HOverTrackPVsTrackP_Barrel = ibooker.bookProfile(
0358         "HOverTrackPVsTrackP_Barrel", "HOverTrackPVsTrackP_Barrel", nbins_pt_total_hcal - 1, pt_limits_hcal, 0, 4, " ");
0359     m_HOverTrackPVsTrackP_EndCap = ibooker.bookProfile(
0360         "HOverTrackPVsTrackP_EndCap", "HOverTrackPVsTrackP_EndCap", nbins_pt_total_hcal - 1, pt_limits_hcal, 0, 4, " ");
0361     m_HOverTrackPVsTrackPt_Barrel = ibooker.bookProfile("HOverTrackPVsTrackPt_Barrel",
0362                                                         "HOverTrackPVsTrackPt_Barrel",
0363                                                         nbins_pt_total_hcal - 1,
0364                                                         pt_limits_hcal,
0365                                                         0,
0366                                                         4,
0367                                                         " ");
0368     m_HOverTrackPVsTrackPt_EndCap = ibooker.bookProfile("HOverTrackPVsTrackPt_EndCap",
0369                                                         "HOverTrackPVsTrackPt_EndCap",
0370                                                         nbins_pt_total_hcal - 1,
0371                                                         pt_limits_hcal,
0372                                                         0,
0373                                                         4,
0374                                                         " ");
0375 
0376     m_HOverTrackPVsEta_hPt_1_10 = ibooker.bookProfile("HOverTrackPVsEta_hPt_1_10",
0377                                                       "HOverTrackPVsEta, 1<hPt<10 GeV",
0378                                                       nbins_eta_hcal_total - 1,
0379                                                       eta_limits_hcal_total,
0380                                                       0,
0381                                                       4,
0382                                                       " ");
0383     m_HOverTrackPVsEta_hPt_10_20 = ibooker.bookProfile("HOverTrackPVsEta_hPt_10_20",
0384                                                        "HOverTrackPVsEta, 10<hPt<20 GeV",
0385                                                        nbins_eta_hcal_total - 1,
0386                                                        eta_limits_hcal_total,
0387                                                        0,
0388                                                        4,
0389                                                        " ");
0390     m_HOverTrackPVsEta_hPt_20_50 = ibooker.bookProfile("HOverTrackPVsEta_hPt_20_50",
0391                                                        "HOverTrackPVsEta, 20<hPt<50 GeV",
0392                                                        nbins_eta_hcal_total - 1,
0393                                                        eta_limits_hcal_total,
0394                                                        0,
0395                                                        4,
0396                                                        " ");
0397     m_HOverTrackPVsEta_hPt_50 = ibooker.bookProfile("HOverTrackPVsEta_hPt_50",
0398                                                     "HOverTrackPVsEta, hPt>50 GeV",
0399                                                     nbins_eta_hcal_total - 1,
0400                                                     eta_limits_hcal_total,
0401                                                     0,
0402                                                     4,
0403                                                     " ");
0404 
0405     m_HOverTrackP_Barrel_hPt_1_10 =
0406         ibooker.book1D("HOverTrackP_Barrel_hPt_1_10", "HOverTrackP_B, 1<hPt<10 GeV", 50, 0, 4);
0407     m_HOverTrackP_Barrel_hPt_10_20 =
0408         ibooker.book1D("HOverTrackP_Barrel_hPt_10_20", "HOverTrackP_B, 10<hPt<20 GeV", 50, 0, 4);
0409     m_HOverTrackP_Barrel_hPt_20_50 =
0410         ibooker.book1D("HOverTrackP_Barrel_hPt_20_50", "HOverTrackP_B, 20<hPt<50 GeV", 50, 0, 4);
0411     m_HOverTrackP_Barrel_hPt_50 = ibooker.book1D("HOverTrackP_Barrel_hPt_50", "HOverTrackP_B, hPt>50 GeV", 50, 0, 4);
0412 
0413     m_HOverTrackP_EndCap_hPt_1_10 =
0414         ibooker.book1D("HOverTrackP_EndCap_hPt_1_10", "HOverTrackP_E, 1<hPt<10 GeV", 50, 0, 4);
0415     m_HOverTrackP_EndCap_hPt_10_20 =
0416         ibooker.book1D("HOverTrackP_EndCap_hPt_10_20", "HOverTrackP_E, 10<hPt<20 GeV", 50, 0, 4);
0417     m_HOverTrackP_EndCap_hPt_20_50 =
0418         ibooker.book1D("HOverTrackP_EndCap_hPt_20_50", "HOverTrackP_E, 20<hPt<50 GeV", 50, 0, 4);
0419     m_HOverTrackP_EndCap_hPt_50 = ibooker.book1D("HOverTrackP_EndCap_hPt_50", "HOverTrackP_E, hPt>50 GeV", 50, 0, 4);
0420 
0421     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "HOverTrackP_trackPtVsEta",
0422                                                               m_HOverTrackP_trackPtVsEta));
0423     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "HOverTrackPVsTrackP_Barrel",
0424                                                               m_HOverTrackPVsTrackP_Barrel));
0425     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "HOverTrackPVsTrackP_EndCap",
0426                                                               m_HOverTrackPVsTrackP_EndCap));
0427     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "HOverTrackPVsTrackPt_Barrel",
0428                                                               m_HOverTrackPVsTrackPt_Barrel));
0429     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "HOverTrackPVsTrackPt_EndCap",
0430                                                               m_HOverTrackPVsTrackPt_EndCap));
0431     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "HOverTrackPVsEta_hPt_1_10",
0432                                                               m_HOverTrackPVsEta_hPt_1_10));
0433     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "HOverTrackPVsEta_hPt_10_20",
0434                                                               m_HOverTrackPVsEta_hPt_10_20));
0435     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "HOverTrackPVsEta_hPt_20_50",
0436                                                               m_HOverTrackPVsEta_hPt_20_50));
0437     map_of_MEs.insert(
0438         std::pair<std::string, MonitorElement*>(DirName + "/" + "HOverTrackPVsEta_hPt_50", m_HOverTrackPVsEta_hPt_50));
0439     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "HOverTrackP_Barrel_hPt_1_10",
0440                                                               m_HOverTrackP_Barrel_hPt_1_10));
0441     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "HOverTrackP_Barrel_hPt_10_20",
0442                                                               m_HOverTrackP_Barrel_hPt_10_20));
0443     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "HOverTrackP_Barrel_hPt_20_50",
0444                                                               m_HOverTrackP_Barrel_hPt_20_50));
0445     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "HOverTrackP_Barrel_hPt_50",
0446                                                               m_HOverTrackP_Barrel_hPt_50));
0447     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "HOverTrackP_EndCap_hPt_1_10",
0448                                                               m_HOverTrackP_EndCap_hPt_1_10));
0449     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "HOverTrackP_EndCap_hPt_10_20",
0450                                                               m_HOverTrackP_EndCap_hPt_10_20));
0451     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "HOverTrackP_EndCap_hPt_20_50",
0452                                                               m_HOverTrackP_EndCap_hPt_20_50));
0453     map_of_MEs.insert(std::pair<std::string, MonitorElement*>(DirName + "/" + "HOverTrackP_EndCap_hPt_50",
0454                                                               m_HOverTrackP_EndCap_hPt_50));
0455   } else {  //MiniAOD workflow
0456     if (!occupancyPFCand_.empty())
0457       occupancyPFCand_.clear();
0458     if (!occupancyPFCand_name_.empty())
0459       occupancyPFCand_name_.clear();
0460     if (!occupancyPFCand_puppiNolepWeight_.empty())
0461       occupancyPFCand_puppiNolepWeight_.clear();
0462     if (!occupancyPFCand_name_puppiNolepWeight_.empty())
0463       occupancyPFCand_name_puppiNolepWeight_.clear();
0464     if (!etaMinPFCand_.empty())
0465       etaMinPFCand_.clear();
0466     if (!etaMaxPFCand_.empty())
0467       etaMaxPFCand_.clear();
0468     if (!typePFCand_.empty())
0469       typePFCand_.clear();
0470     if (!countsPFCand_.empty())
0471       countsPFCand_.clear();
0472     if (!ptPFCand_.empty())
0473       ptPFCand_.clear();
0474     if (!ptPFCand_name_.empty())
0475       ptPFCand_name_.clear();
0476     if (!ptPFCand_puppiNolepWeight_.empty())
0477       ptPFCand_puppiNolepWeight_.clear();
0478     if (!ptPFCand_name_puppiNolepWeight_.empty())
0479       ptPFCand_name_puppiNolepWeight_.clear();
0480     if (!multiplicityPFCand_.empty())
0481       multiplicityPFCand_.clear();
0482     if (!multiplicityPFCand_name_.empty())
0483       multiplicityPFCand_name_.clear();
0484     for (std::vector<edm::ParameterSet>::const_iterator v = diagnosticsParameters_.begin();
0485          v != diagnosticsParameters_.end();
0486          v++) {
0487       int etaNBinsPFCand = v->getParameter<int>("etaNBins");
0488       double etaMinPFCand = v->getParameter<double>("etaMin");
0489       double etaMaxPFCand = v->getParameter<double>("etaMax");
0490       int phiNBinsPFCand = v->getParameter<int>("phiNBins");
0491       double phiMinPFCand = v->getParameter<double>("phiMin");
0492       double phiMaxPFCand = v->getParameter<double>("phiMax");
0493       int nMinPFCand = v->getParameter<int>("nMin");
0494       int nMaxPFCand = v->getParameter<int>("nMax");
0495       int nbinsPFCand = v->getParameter<double>("nbins");
0496 
0497       // etaNBins_.push_back(etaNBins);
0498       etaMinPFCand_.push_back(etaMinPFCand);
0499       etaMaxPFCand_.push_back(etaMaxPFCand);
0500       typePFCand_.push_back(v->getParameter<int>("type"));
0501       countsPFCand_.push_back(0);
0502 
0503       multiplicityPFCand_.push_back(
0504           ibooker.book1D(std::string(v->getParameter<std::string>("name")).append("_multiplicity_").c_str(),
0505                          std::string(v->getParameter<std::string>("name")) + "multiplicity",
0506                          nbinsPFCand,
0507                          nMinPFCand,
0508                          nMaxPFCand));
0509       multiplicityPFCand_name_.push_back(std::string(v->getParameter<std::string>("name")).append("_multiplicity_"));
0510       map_of_MEs.insert(std::pair<std::string, MonitorElement*>(
0511           DirName + "/" + multiplicityPFCand_name_[multiplicityPFCand_name_.size() - 1],
0512           multiplicityPFCand_[multiplicityPFCand_.size() - 1]));
0513       //push back names first, we need to create histograms with the name and fill it for endcap plots later
0514       occupancyPFCand_name_.push_back(
0515           std::string(v->getParameter<std::string>("name")).append("_occupancy_puppiWeight_"));
0516       ptPFCand_name_.push_back(std::string(v->getParameter<std::string>("name")).append("_pt_puppiWeight_"));
0517       //push back names first, we need to create histograms with the name and fill it for endcap plots later
0518       occupancyPFCand_name_puppiNolepWeight_.push_back(
0519           std::string(v->getParameter<std::string>("name")).append("_occupancy_puppiNolepWeight_"));
0520       ptPFCand_name_puppiNolepWeight_.push_back(
0521           std::string(v->getParameter<std::string>("name")).append("_pt_puppiNolepWeight_"));
0522       //special booking for endcap plots, merge plots for eminus and eplus into one plot, using variable binning
0523       //barrel plots have eta-boundaries on minus and plus side
0524       //parameters start on minus side
0525       if (etaMinPFCand * etaMaxPFCand < 0) {  //barrel plots, plot only in barrel region
0526         occupancyPFCand_.push_back(
0527             ibooker.book2D(std::string(v->getParameter<std::string>("name")).append("_occupancy_puppiWeight_").c_str(),
0528                            std::string(v->getParameter<std::string>("name")) + "occupancy_puppiWeight_",
0529                            etaNBinsPFCand,
0530                            etaMinPFCand,
0531                            etaMaxPFCand,
0532                            phiNBinsPFCand,
0533                            phiMinPFCand,
0534                            phiMaxPFCand));
0535         ptPFCand_.push_back(
0536             ibooker.book2D(std::string(v->getParameter<std::string>("name")).append("_pt_puppiWeight_").c_str(),
0537                            std::string(v->getParameter<std::string>("name")) + "pt_puppiWeight_",
0538                            etaNBinsPFCand,
0539                            etaMinPFCand,
0540                            etaMaxPFCand,
0541                            phiNBinsPFCand,
0542                            phiMinPFCand,
0543                            phiMaxPFCand));
0544         occupancyPFCand_puppiNolepWeight_.push_back(ibooker.book2D(
0545             std::string(v->getParameter<std::string>("name")).append("_occupancy_puppiNolepWeight_").c_str(),
0546             std::string(v->getParameter<std::string>("name")) + "occupancy_puppiNolepWeight",
0547             etaNBinsPFCand,
0548             etaMinPFCand,
0549             etaMaxPFCand,
0550             phiNBinsPFCand,
0551             phiMinPFCand,
0552             phiMaxPFCand));
0553         ptPFCand_puppiNolepWeight_.push_back(
0554             ibooker.book2D(std::string(v->getParameter<std::string>("name")).append("_pt_puppiNolepWeight_").c_str(),
0555                            std::string(v->getParameter<std::string>("name")) + "pt_puppiNolepWeight",
0556                            etaNBinsPFCand,
0557                            etaMinPFCand,
0558                            etaMaxPFCand,
0559                            phiNBinsPFCand,
0560                            phiMinPFCand,
0561                            phiMaxPFCand));
0562       } else {  //endcap or forward plots,
0563         const int nbins_eta_endcap = 2 * (etaNBinsPFCand + 1);
0564         double eta_limits_endcap[nbins_eta_endcap];
0565         for (int i = 0; i < nbins_eta_endcap; i++) {
0566           if (i < (etaNBinsPFCand + 1)) {
0567             eta_limits_endcap[i] = etaMinPFCand + i * (etaMaxPFCand - etaMinPFCand) / (double)etaNBinsPFCand;
0568           } else {
0569             eta_limits_endcap[i] =
0570                 -etaMaxPFCand + (i - (etaNBinsPFCand + 1)) * (etaMaxPFCand - etaMinPFCand) / (double)etaNBinsPFCand;
0571           }
0572         }
0573         TH2F* hist_temp_occup = new TH2F((occupancyPFCand_name_[occupancyPFCand_name_.size() - 1]).c_str(),
0574                                          (occupancyPFCand_name_[occupancyPFCand_name_.size() - 1]).c_str(),
0575                                          nbins_eta_endcap - 1,
0576                                          eta_limits_endcap,
0577                                          phiNBinsPFCand,
0578                                          phiMinPFCand,
0579                                          phiMaxPFCand);
0580         occupancyPFCand_.push_back(
0581             ibooker.book2D(occupancyPFCand_name_[occupancyPFCand_name_.size() - 1], hist_temp_occup));
0582         TH2F* hist_temp_pt = new TH2F((ptPFCand_name_[ptPFCand_name_.size() - 1]).c_str(),
0583                                       (ptPFCand_name_[ptPFCand_name_.size() - 1]).c_str(),
0584                                       nbins_eta_endcap - 1,
0585                                       eta_limits_endcap,
0586                                       phiNBinsPFCand,
0587                                       phiMinPFCand,
0588                                       phiMaxPFCand);
0589         ptPFCand_.push_back(ibooker.book2D(ptPFCand_name_[ptPFCand_name_.size() - 1], hist_temp_pt));
0590         TH2F* hist_temp_occup_puppiNolepWeight = new TH2F(
0591             (occupancyPFCand_name_puppiNolepWeight_[occupancyPFCand_name_puppiNolepWeight_.size() - 1]).c_str(),
0592             (occupancyPFCand_name_puppiNolepWeight_[occupancyPFCand_name_puppiNolepWeight_.size() - 1]).c_str(),
0593             nbins_eta_endcap - 1,
0594             eta_limits_endcap,
0595             phiNBinsPFCand,
0596             phiMinPFCand,
0597             phiMaxPFCand);
0598         occupancyPFCand_puppiNolepWeight_.push_back(
0599             ibooker.book2D(occupancyPFCand_name_puppiNolepWeight_[occupancyPFCand_name_puppiNolepWeight_.size() - 1],
0600                            hist_temp_occup_puppiNolepWeight));
0601         TH2F* hist_temp_pt_puppiNolepWeight =
0602             new TH2F((ptPFCand_name_puppiNolepWeight_[ptPFCand_name_puppiNolepWeight_.size() - 1]).c_str(),
0603                      (ptPFCand_name_puppiNolepWeight_[ptPFCand_name_puppiNolepWeight_.size() - 1]).c_str(),
0604                      nbins_eta_endcap - 1,
0605                      eta_limits_endcap,
0606                      phiNBinsPFCand,
0607                      phiMinPFCand,
0608                      phiMaxPFCand);
0609         ptPFCand_puppiNolepWeight_.push_back(
0610             ibooker.book2D(ptPFCand_name_puppiNolepWeight_[ptPFCand_name_puppiNolepWeight_.size() - 1],
0611                            hist_temp_pt_puppiNolepWeight));
0612       }
0613       map_of_MEs.insert(std::pair<std::string, MonitorElement*>(
0614           DirName + "/" + occupancyPFCand_name_puppiNolepWeight_[occupancyPFCand_name_puppiNolepWeight_.size() - 1],
0615           occupancyPFCand_puppiNolepWeight_[occupancyPFCand_puppiNolepWeight_.size() - 1]));
0616       map_of_MEs.insert(std::pair<std::string, MonitorElement*>(
0617           DirName + "/" + ptPFCand_name_puppiNolepWeight_[ptPFCand_name_puppiNolepWeight_.size() - 1],
0618           ptPFCand_puppiNolepWeight_[ptPFCand_puppiNolepWeight_.size() - 1]));
0619       map_of_MEs.insert(std::pair<std::string, MonitorElement*>(
0620           DirName + "/" + occupancyPFCand_name_[occupancyPFCand_name_.size() - 1],
0621           occupancyPFCand_[occupancyPFCand_.size() - 1]));
0622       map_of_MEs.insert(std::pair<std::string, MonitorElement*>(
0623           DirName + "/" + ptPFCand_name_[ptPFCand_name_.size() - 1], ptPFCand_[ptPFCand_.size() - 1]));
0624     }
0625   }
0626 }
0627 
0628 // ***********************************************************
0629 void DQMPFCandidateAnalyzer::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0630   miniaodfilterindex = -1;
0631 
0632   if (isMiniAOD_) {
0633     bool changed_filter = true;
0634     if (FilterhltConfig_.init(iRun, iSetup, METFilterMiniAODLabel_.process(), changed_filter)) {
0635       miniaodfilterdec = 0;
0636       for (unsigned int i = 0; i < FilterhltConfig_.size(); i++) {
0637         std::string search = FilterhltConfig_.triggerName(i).substr(
0638             5);  //actual label of filter, the first 5 items are Flag_, so stripped off
0639         std::string search2 =
0640             HBHENoiseStringMiniAOD;  //all filters end with DQM, which is not in the flag --> ONLY not for HBHEFilters
0641         std::size_t found = search2.find(search);
0642         if (found != std::string::npos) {
0643           miniaodfilterindex = i;
0644         }
0645       }
0646     } else if (FilterhltConfig_.init(iRun, iSetup, METFilterMiniAODLabel2_.process(), changed_filter)) {
0647       miniaodfilterdec = 1;
0648       for (unsigned int i = 0; i < FilterhltConfig_.size(); i++) {
0649         std::string search = FilterhltConfig_.triggerName(i).substr(
0650             5);  //actual label of filter, the first 5 items are Flag_, so stripped off
0651         std::string search2 =
0652             HBHENoiseStringMiniAOD;  //all filters end with DQM, which is not in the flag --> ONLY not for HBHEFilters
0653         std::size_t found = search2.find(search);
0654         if (found != std::string::npos) {
0655           miniaodfilterindex = i;
0656         }
0657       }
0658     } else {
0659       edm::LogWarning("MiniAOD MET Filter HLT OBject version")
0660           << "nothing found with both RECO and reRECO label" << std::endl;
0661     }
0662   }
0663 }
0664 
0665 // ***********************************************************
0666 void DQMPFCandidateAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0667   //Vertex information
0668   Handle<VertexCollection> vertexHandle;
0669   iEvent.getByToken(vertexToken_, vertexHandle);
0670 
0671   if (!vertexHandle.isValid()) {
0672     LogDebug("") << "CaloMETAnalyzer: Could not find vertex collection" << std::endl;
0673     if (verbose_)
0674       std::cout << "CaloMETAnalyzer: Could not find vertex collection" << std::endl;
0675   }
0676   numPV_ = 0;
0677   if (vertexHandle.isValid()) {
0678     VertexCollection vertexCollection = *(vertexHandle.product());
0679     numPV_ = vertexCollection.size();
0680   }
0681   bool bPrimaryVertex = (bypassAllPVChecks_ || (numPV_ > 0));
0682 
0683   int myLuminosityBlock;
0684   myLuminosityBlock = iEvent.luminosityBlock();
0685 
0686   if (myLuminosityBlock < LSBegin_)
0687     return;
0688   if (myLuminosityBlock > LSEnd_ && LSEnd_ > 0)
0689     return;
0690 
0691   if (verbose_)
0692     std::cout << "METAnalyzer analyze" << std::endl;
0693 
0694   std::string DirName = "JetMET/PFCandidates/" + mInputCollection_.label();
0695 
0696   bool hbhenoifilterdecision = true;
0697   if (!isMiniAOD_) {  //not checked for MiniAOD -> for miniaod decision filled as "triggerResults" bool
0698     edm::Handle<bool> HBHENoiseFilterResultHandle;
0699     iEvent.getByToken(hbheNoiseFilterResultToken_, HBHENoiseFilterResultHandle);
0700     if (!HBHENoiseFilterResultHandle.isValid()) {
0701       LogDebug("") << "METAnalyzer: Could not find HBHENoiseFilterResult" << std::endl;
0702       if (verbose_)
0703         std::cout << "METAnalyzer: Could not find HBHENoiseFilterResult" << std::endl;
0704     }
0705     hbhenoifilterdecision = *HBHENoiseFilterResultHandle;
0706   } else {  //need to check if we go for version 1 or version 2
0707     edm::Handle<edm::TriggerResults> metFilterResults;
0708     iEvent.getByToken(METFilterMiniAODToken_, metFilterResults);
0709     if (metFilterResults.isValid()) {
0710       if (miniaodfilterindex != -1) {
0711         hbhenoifilterdecision = metFilterResults->accept(miniaodfilterindex);
0712       }
0713     } else {
0714       iEvent.getByToken(METFilterMiniAODToken2_, metFilterResults);
0715       if (metFilterResults.isValid()) {
0716         if (miniaodfilterindex != -1) {
0717           hbhenoifilterdecision = metFilterResults->accept(miniaodfilterindex);
0718         }
0719       }
0720     }
0721   }
0722 
0723   //DCS Filter
0724   bool bDCSFilter = (bypassAllDCSChecks_ || DCSFilter_->filter(iEvent, iSetup));
0725 
0726   for (unsigned int i = 0; i < countsPFCand_.size(); i++) {
0727     countsPFCand_[i] = 0;
0728   }
0729   if (bDCSFilter && hbhenoifilterdecision && bPrimaryVertex) {
0730     if (isMiniAOD_) {
0731       edm::Handle<std::vector<pat::PackedCandidate> > packedParticleFlow;
0732       iEvent.getByToken(pflowPackedToken_, packedParticleFlow);
0733       //11, 13, 22 for el/mu/gamma, 211 chargedHadron, 130 neutralHadrons, 1 and 2 hadHF and EGammaHF
0734       for (unsigned int i = 0; i < packedParticleFlow->size(); i++) {
0735         const pat::PackedCandidate& c = packedParticleFlow->at(i);
0736         for (unsigned int j = 0; j < typePFCand_.size(); j++) {
0737           if (abs(c.pdgId()) == typePFCand_[j]) {
0738             //second check for endcap, if inside barrel Max and Min symmetric around 0
0739             if (((c.eta() > etaMinPFCand_[j]) && (c.eta() < etaMaxPFCand_[j])) ||
0740                 ((c.eta() > (-etaMaxPFCand_[j])) && (c.eta() < (-etaMinPFCand_[j])))) {
0741               countsPFCand_[j] += 1;
0742               ptPFCand_[j] = map_of_MEs[DirName + "/" + ptPFCand_name_[j]];
0743               if (ptPFCand_[j] && ptPFCand_[j]->getRootObject())
0744                 ptPFCand_[j]->Fill(c.eta(), c.phi(), c.pt() * c.puppiWeight());
0745               occupancyPFCand_[j] = map_of_MEs[DirName + "/" + occupancyPFCand_name_[j]];
0746               if (occupancyPFCand_[j] && occupancyPFCand_[j]->getRootObject())
0747                 occupancyPFCand_[j]->Fill(c.eta(), c.phi(), c.puppiWeight());
0748               ptPFCand_puppiNolepWeight_[j] = map_of_MEs[DirName + "/" + ptPFCand_name_puppiNolepWeight_[j]];
0749               if (ptPFCand_puppiNolepWeight_[j] && ptPFCand_puppiNolepWeight_[j]->getRootObject())
0750                 ptPFCand_puppiNolepWeight_[j]->Fill(c.eta(), c.phi(), c.pt() * c.puppiWeightNoLep());
0751               occupancyPFCand_puppiNolepWeight_[j] =
0752                   map_of_MEs[DirName + "/" + occupancyPFCand_name_puppiNolepWeight_[j]];
0753               if (occupancyPFCand_puppiNolepWeight_[j] && occupancyPFCand_puppiNolepWeight_[j]->getRootObject()) {
0754                 occupancyPFCand_puppiNolepWeight_[j]->Fill(c.eta(), c.phi(), c.puppiWeightNoLep());
0755               }
0756             }
0757           }
0758         }
0759       }
0760       for (unsigned int j = 0; j < countsPFCand_.size(); j++) {
0761         multiplicityPFCand_[j] = map_of_MEs[DirName + "/" + multiplicityPFCand_name_[j]];
0762         if (multiplicityPFCand_[j] && multiplicityPFCand_[j]->getRootObject()) {
0763           multiplicityPFCand_[j]->Fill(countsPFCand_[j]);
0764         }
0765       }
0766     } else {
0767       edm::Handle<std::vector<reco::PFCandidate> > particleFlow;
0768       iEvent.getByToken(pflowToken_, particleFlow);
0769       for (unsigned int i = 0; i < particleFlow->size(); i++) {
0770         const reco::PFCandidate& c = particleFlow->at(i);
0771         for (unsigned int j = 0; j < typePFCandRECO_.size(); j++) {
0772           if (c.particleId() == typePFCandRECO_[j]) {
0773             //second check for endcap, if inside barrel Max and Min symmetric around 0
0774             if (((c.eta() > etaMinPFCandRECO_[j]) && (c.eta() < etaMaxPFCandRECO_[j])) ||
0775                 ((c.eta() > (-etaMaxPFCandRECO_[j])) && (c.eta() < (-etaMinPFCandRECO_[j])))) {
0776               countsPFCandRECO_[j] += 1;
0777               ptPFCandRECO_[j] = map_of_MEs[DirName + "/" + ptPFCand_nameRECO_[j]];
0778               if (ptPFCandRECO_[j] && ptPFCandRECO_[j]->getRootObject())
0779                 ptPFCandRECO_[j]->Fill(c.eta(), c.phi(), c.pt());
0780               occupancyPFCandRECO_[j] = map_of_MEs[DirName + "/" + occupancyPFCand_nameRECO_[j]];
0781               if (occupancyPFCandRECO_[j] && occupancyPFCandRECO_[j]->getRootObject())
0782                 occupancyPFCandRECO_[j]->Fill(c.eta(), c.phi());
0783             }
0784             //fill quantities for isolated charged hadron quantities
0785             //only for charged hadrons
0786             if (c.particleId() == 1 && c.pt() > ptMinCand_) {
0787               // At least 1 GeV in HCAL
0788               double ecalRaw = c.rawEcalEnergy();
0789               double hcalRaw = c.rawHcalEnergy();
0790               if ((ecalRaw + hcalRaw) > hcalMin_) {
0791                 const PFCandidate::ElementsInBlocks& theElements = c.elementsInBlocks();
0792                 if (theElements.empty())
0793                   continue;
0794                 unsigned int iTrack = -999;
0795                 std::vector<unsigned int> iECAL;  // =999;
0796                 std::vector<unsigned int> iHCAL;  // =999;
0797                 const reco::PFBlockRef blockRef = theElements[0].first;
0798                 const edm::OwnVector<reco::PFBlockElement>& elements = blockRef->elements();
0799                 // Check that there is only one track in the block.
0800                 unsigned int nTracks = 0;
0801                 for (unsigned int iEle = 0; iEle < elements.size(); iEle++) {
0802                   // Find the tracks in the block
0803                   PFBlockElement::Type type = elements[iEle].type();
0804                   switch (type) {
0805                     case PFBlockElement::TRACK:
0806                       iTrack = iEle;
0807                       nTracks++;
0808                       break;
0809                     case PFBlockElement::ECAL:
0810                       iECAL.push_back(iEle);
0811                       break;
0812                     case PFBlockElement::HCAL:
0813                       iHCAL.push_back(iEle);
0814                       break;
0815                     default:
0816                       continue;
0817                   }
0818                 }
0819                 if (nTracks == 1) {
0820                   // Characteristics of the track
0821                   const reco::PFBlockElementTrack& et =
0822                       dynamic_cast<const reco::PFBlockElementTrack&>(elements[iTrack]);
0823                   mProfileIsoPFChHad_TrackOccupancy = map_of_MEs[DirName + "/" + "IsoPfChHad_Track_profile"];
0824                   if (mProfileIsoPFChHad_TrackOccupancy && mProfileIsoPFChHad_TrackOccupancy->getRootObject())
0825                     mProfileIsoPFChHad_TrackOccupancy->Fill(et.trackRef()->eta(), et.trackRef()->phi());
0826                   mProfileIsoPFChHad_TrackPt = map_of_MEs[DirName + "/" + "IsoPfChHad_TrackPt"];
0827                   if (mProfileIsoPFChHad_TrackPt && mProfileIsoPFChHad_TrackPt->getRootObject())
0828                     mProfileIsoPFChHad_TrackPt->Fill(et.trackRef()->eta(), et.trackRef()->phi(), et.trackRef()->pt());
0829                   if (c.rawEcalEnergy() == 0) {  //isolated hadron, nothing in ECAL
0830                     //right now take corrected hcalEnergy, do we want the rawHcalEnergy instead
0831                     m_HOverTrackP_trackPtVsEta = map_of_MEs[DirName + "/" + "HOverTrackP_trackPtVsEta"];
0832                     if (m_HOverTrackP_trackPtVsEta && m_HOverTrackP_trackPtVsEta->getRootObject())
0833                       m_HOverTrackP_trackPtVsEta->Fill(c.pt(), c.eta(), c.hcalEnergy() / et.trackRef()->p());
0834                     if (c.pt() > 1 && c.pt() < 10) {
0835                       m_HOverTrackPVsEta_hPt_1_10 = map_of_MEs[DirName + "/" + "HOverTrackPVsEta_hPt_1_10"];
0836                       if (m_HOverTrackPVsEta_hPt_1_10 && m_HOverTrackPVsEta_hPt_1_10->getRootObject())
0837                         m_HOverTrackPVsEta_hPt_1_10->Fill(c.eta(), c.hcalEnergy() / et.trackRef()->p());
0838                     } else if (c.pt() > 10 && c.pt() < 20) {
0839                       m_HOverTrackPVsEta_hPt_10_20 = map_of_MEs[DirName + "/" + "HOverTrackPVsEta_hPt_10_20"];
0840                       if (m_HOverTrackPVsEta_hPt_10_20 && m_HOverTrackPVsEta_hPt_10_20->getRootObject())
0841                         m_HOverTrackPVsEta_hPt_10_20->Fill(c.eta(), c.hcalEnergy() / et.trackRef()->p());
0842                     } else if (c.pt() > 20 && c.pt() < 50) {
0843                       m_HOverTrackPVsEta_hPt_20_50 = map_of_MEs[DirName + "/" + "HOverTrackPVsEta_hPt_20_50"];
0844                       if (m_HOverTrackPVsEta_hPt_20_50 && m_HOverTrackPVsEta_hPt_20_50->getRootObject())
0845                         m_HOverTrackPVsEta_hPt_20_50->Fill(c.eta(), c.hcalEnergy() / et.trackRef()->p());
0846                     } else if (c.pt() > 50) {
0847                       m_HOverTrackPVsEta_hPt_50 = map_of_MEs[DirName + "/" + "HOverTrackPVsEta_hPt_50"];
0848                       if (m_HOverTrackPVsEta_hPt_50 && m_HOverTrackPVsEta_hPt_50->getRootObject())
0849                         m_HOverTrackPVsEta_hPt_50->Fill(c.eta(), c.hcalEnergy() / et.trackRef()->p());
0850                     }
0851                     if (fabs(c.eta() < 1.392)) {
0852                       if (c.pt() > 1 && c.pt() < 10) {
0853                         m_HOverTrackP_Barrel_hPt_1_10 = map_of_MEs[DirName + "/" + "HOverTrackP_Barrel_hPt_1_10"];
0854                         if (m_HOverTrackP_Barrel_hPt_1_10 && m_HOverTrackP_Barrel_hPt_1_10->getRootObject())
0855                           m_HOverTrackP_Barrel_hPt_1_10->Fill(c.hcalEnergy() / et.trackRef()->p());
0856                       } else if (c.pt() > 10 && c.pt() < 20) {
0857                         m_HOverTrackP_Barrel_hPt_10_20 = map_of_MEs[DirName + "/" + "HOverTrackP_Barrel_hPt_10_20"];
0858                         if (m_HOverTrackP_Barrel_hPt_10_20 && m_HOverTrackP_Barrel_hPt_10_20->getRootObject())
0859                           m_HOverTrackP_Barrel_hPt_10_20->Fill(c.hcalEnergy() / et.trackRef()->p());
0860                       } else if (c.pt() > 20 && c.pt() < 50) {
0861                         m_HOverTrackP_Barrel_hPt_20_50 = map_of_MEs[DirName + "/" + "HOverTrackP_Barrel_hPt_20_50"];
0862                         if (m_HOverTrackP_Barrel_hPt_20_50 && m_HOverTrackP_Barrel_hPt_20_50->getRootObject())
0863                           m_HOverTrackP_Barrel_hPt_20_50->Fill(c.hcalEnergy() / et.trackRef()->p());
0864                       } else if (c.pt() > 50) {
0865                         m_HOverTrackP_Barrel_hPt_50 = map_of_MEs[DirName + "/" + "HOverTrackP_Barrel_hPt_50"];
0866                         if (m_HOverTrackP_Barrel_hPt_50 && m_HOverTrackP_Barrel_hPt_50->getRootObject())
0867                           m_HOverTrackP_Barrel_hPt_50->Fill(c.hcalEnergy() / et.trackRef()->p());
0868                       }
0869                       m_HOverTrackPVsTrackP_Barrel = map_of_MEs[DirName + "/" + "HOverTrackPVsTrackP_Barrel"];
0870                       if (m_HOverTrackPVsTrackP_Barrel && m_HOverTrackPVsTrackP_Barrel->getRootObject())
0871                         m_HOverTrackPVsTrackP_Barrel->Fill(et.trackRef()->p(), c.hcalEnergy() / et.trackRef()->p());
0872                       m_HOverTrackPVsTrackPt_Barrel = map_of_MEs[DirName + "/" + "HOverTrackPVsTrackPt_Barrel"];
0873                       if (m_HOverTrackPVsTrackPt_Barrel && m_HOverTrackPVsTrackPt_Barrel->getRootObject())
0874                         m_HOverTrackPVsTrackPt_Barrel->Fill(et.trackRef()->pt(), c.hcalEnergy() / et.trackRef()->p());
0875                     } else {
0876                       m_HOverTrackPVsTrackP_EndCap = map_of_MEs[DirName + "/" + "HOverTrackPVsTrackP_EndCap"];
0877                       if (m_HOverTrackPVsTrackP_EndCap && m_HOverTrackPVsTrackP_EndCap->getRootObject())
0878                         m_HOverTrackPVsTrackP_EndCap->Fill(et.trackRef()->p(), c.hcalEnergy() / et.trackRef()->p());
0879                       m_HOverTrackPVsTrackPt_EndCap = map_of_MEs[DirName + "/" + "HOverTrackPVsTrackPt_EndCap"];
0880                       if (m_HOverTrackPVsTrackPt_EndCap && m_HOverTrackPVsTrackPt_EndCap->getRootObject())
0881                         m_HOverTrackPVsTrackPt_EndCap->Fill(et.trackRef()->pt(), c.hcalEnergy() / et.trackRef()->p());
0882                       if (c.pt() > 1 && c.pt() < 10) {
0883                         m_HOverTrackP_EndCap_hPt_1_10 = map_of_MEs[DirName + "/" + "HOverTrackP_EndCap_hPt_1_10"];
0884                         if (m_HOverTrackP_EndCap_hPt_1_10 && m_HOverTrackP_EndCap_hPt_1_10->getRootObject())
0885                           m_HOverTrackP_EndCap_hPt_1_10->Fill(c.hcalEnergy() / et.trackRef()->p());
0886                       } else if (c.pt() > 10 && c.pt() < 20) {
0887                         m_HOverTrackP_EndCap_hPt_10_20 = map_of_MEs[DirName + "/" + "HOverTrackP_EndCap_hPt_10_20"];
0888                         if (m_HOverTrackP_EndCap_hPt_10_20 && m_HOverTrackP_EndCap_hPt_10_20->getRootObject())
0889                           m_HOverTrackP_EndCap_hPt_10_20->Fill(c.hcalEnergy() / et.trackRef()->p());
0890                       } else if (c.pt() > 20 && c.pt() < 50) {
0891                         m_HOverTrackP_EndCap_hPt_20_50 = map_of_MEs[DirName + "/" + "HOverTrackP_EndCap_hPt_20_50"];
0892                         if (m_HOverTrackP_EndCap_hPt_20_50 && m_HOverTrackP_EndCap_hPt_20_50->getRootObject())
0893                           m_HOverTrackP_EndCap_hPt_20_50->Fill(c.hcalEnergy() / et.trackRef()->p());
0894                       } else if (c.pt() > 50) {
0895                         m_HOverTrackP_EndCap_hPt_50 = map_of_MEs[DirName + "/" + "HOverTrackP_EndCap_hPt_50"];
0896                         if (m_HOverTrackP_EndCap_hPt_50 && m_HOverTrackP_EndCap_hPt_50->getRootObject())
0897                           m_HOverTrackP_EndCap_hPt_50->Fill(c.hcalEnergy() / et.trackRef()->p());
0898                       }
0899                     }
0900                   }
0901                   //ECAL element
0902                   for (unsigned int ii = 0; ii < iECAL.size(); ii++) {
0903                     const reco::PFBlockElementCluster& eecal =
0904                         dynamic_cast<const reco::PFBlockElementCluster&>(elements[iECAL[ii]]);
0905                     if (fabs(eecal.clusterRef()->eta()) < 1.479) {
0906                       mProfileIsoPFChHad_EcalOccupancyCentral =
0907                           map_of_MEs[DirName + "/" + "IsoPfChHad_ECAL_profile_central"];
0908                       if (mProfileIsoPFChHad_EcalOccupancyCentral &&
0909                           mProfileIsoPFChHad_EcalOccupancyCentral->getRootObject())
0910                         mProfileIsoPFChHad_EcalOccupancyCentral->Fill(eecal.clusterRef()->eta(),
0911                                                                       eecal.clusterRef()->phi());
0912                       mProfileIsoPFChHad_EMPtCentral = map_of_MEs[DirName + "/" + "IsoPfChHad_EMPt_central"];
0913                       if (mProfileIsoPFChHad_EMPtCentral && mProfileIsoPFChHad_EMPtCentral->getRootObject())
0914                         mProfileIsoPFChHad_EMPtCentral->Fill(
0915                             eecal.clusterRef()->eta(), eecal.clusterRef()->phi(), eecal.clusterRef()->pt());
0916                     } else {
0917                       mProfileIsoPFChHad_EcalOccupancyEndcap =
0918                           map_of_MEs[DirName + "/" + "IsoPfChHad_ECAL_profile_endcap"];
0919                       if (mProfileIsoPFChHad_EcalOccupancyEndcap &&
0920                           mProfileIsoPFChHad_EcalOccupancyEndcap->getRootObject())
0921                         mProfileIsoPFChHad_EcalOccupancyEndcap->Fill(eecal.clusterRef()->eta(),
0922                                                                      eecal.clusterRef()->phi());
0923                       mProfileIsoPFChHad_EMPtEndcap = map_of_MEs[DirName + "/" + "IsoPfChHad_EMPt_endcap"];
0924                       if (mProfileIsoPFChHad_EMPtEndcap && mProfileIsoPFChHad_EMPtEndcap->getRootObject())
0925                         mProfileIsoPFChHad_EMPtEndcap->Fill(
0926                             eecal.clusterRef()->eta(), eecal.clusterRef()->phi(), eecal.clusterRef()->pt());
0927                     }
0928                   }
0929                   //HCAL element
0930                   for (unsigned int ii = 0; ii < iHCAL.size(); ii++) {
0931                     const reco::PFBlockElementCluster& ehcal =
0932                         dynamic_cast<const reco::PFBlockElementCluster&>(elements[iHCAL[ii]]);
0933                     if (fabs(ehcal.clusterRef()->eta()) < 1.740) {
0934                       mProfileIsoPFChHad_HcalOccupancyCentral =
0935                           map_of_MEs[DirName + "/" + "IsoPfChHad_HCAL_profile_central"];
0936                       if (mProfileIsoPFChHad_HcalOccupancyCentral &&
0937                           mProfileIsoPFChHad_HcalOccupancyCentral->getRootObject())
0938                         mProfileIsoPFChHad_HcalOccupancyCentral->Fill(ehcal.clusterRef()->eta(),
0939                                                                       ehcal.clusterRef()->phi());
0940                       mProfileIsoPFChHad_HadPtCentral = map_of_MEs[DirName + "/" + "IsoPfChHad_HadPt_central"];
0941                       if (mProfileIsoPFChHad_HadPtCentral && mProfileIsoPFChHad_HadPtCentral->getRootObject())
0942                         mProfileIsoPFChHad_HadPtCentral->Fill(
0943                             ehcal.clusterRef()->eta(), ehcal.clusterRef()->phi(), ehcal.clusterRef()->pt());
0944                     } else {
0945                       mProfileIsoPFChHad_HcalOccupancyEndcap =
0946                           map_of_MEs[DirName + "/" + "IsoPfChHad_HCAL_profile_endcap"];
0947                       if (mProfileIsoPFChHad_HcalOccupancyEndcap &&
0948                           mProfileIsoPFChHad_HcalOccupancyEndcap->getRootObject())
0949                         mProfileIsoPFChHad_HcalOccupancyEndcap->Fill(ehcal.clusterRef()->eta(),
0950                                                                      ehcal.clusterRef()->phi());
0951                       mProfileIsoPFChHad_HadPtEndcap = map_of_MEs[DirName + "/" + "IsoPfChHad_HadPt_endcap"];
0952                       if (mProfileIsoPFChHad_HadPtEndcap && mProfileIsoPFChHad_HadPtEndcap->getRootObject())
0953                         mProfileIsoPFChHad_HadPtEndcap->Fill(
0954                             ehcal.clusterRef()->eta(), ehcal.clusterRef()->phi(), ehcal.clusterRef()->pt());
0955                     }
0956                   }
0957                 }
0958               }
0959             }
0960           }
0961         }
0962       }
0963       for (unsigned int j = 0; j < countsPFCandRECO_.size(); j++) {
0964         multiplicityPFCandRECO_[j] = map_of_MEs[DirName + "/" + multiplicityPFCand_nameRECO_[j]];
0965         if (multiplicityPFCandRECO_[j] && multiplicityPFCandRECO_[j]->getRootObject()) {
0966           multiplicityPFCandRECO_[j]->Fill(countsPFCandRECO_[j]);
0967         }
0968       }
0969     }  //candidate loop for both miniaod and reco
0970   }
0971 }