Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:32:27

0001 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0002 
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/Utilities/interface/Exception.h"
0011 
0012 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0013 #include "DQMServices/Core/interface/DQMStore.h"
0014 #include "FWCore/ServiceRegistry/interface/Service.h"
0015 
0016 #include "SimDataFormats/CaloHit/interface/PCaloHit.h"
0017 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
0018 #include "SimDataFormats/ValidationFormats/interface/PValidationFormats.h"
0019 
0020 #include <fstream>
0021 #include <iostream>
0022 #include <map>
0023 #include <string>
0024 #include <vector>
0025 
0026 class HcalHitValidation : public DQMEDAnalyzer {
0027 public:
0028   HcalHitValidation(const edm::ParameterSet &ps);
0029   ~HcalHitValidation() override = default;
0030 
0031 protected:
0032   void analyze(const edm::Event &e, const edm::EventSetup &c) override;
0033   void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
0034 
0035   void analyzeHits(std::vector<PCaloHit> &);
0036   void analyzeLayer(const edm::Handle<PHcalValidInfoLayer> &);
0037   void analyzeNxN(const edm::Handle<PHcalValidInfoNxN> &);
0038   void analyzeJets(const edm::Handle<PHcalValidInfoJets> &);
0039 
0040 private:
0041   const std::string g4Label, hcalHits, layerInfo, nxNInfo, jetsInfo;
0042   const std::string outFile_;
0043   const bool verbose_, scheme_;
0044   const bool checkHit_, checkLay_, checkNxN_, checkJet_;
0045   const edm::EDGetTokenT<edm::PCaloHitContainer> tok_hh_;
0046   const edm::EDGetTokenT<PHcalValidInfoLayer> tok_iL_;
0047   const edm::EDGetTokenT<PHcalValidInfoNxN> tok_iN_;
0048   const edm::EDGetTokenT<PHcalValidInfoJets> tok_iJ_;
0049 
0050   MonitorElement *meAllNHit_, *meBadDetHit_, *meBadSubHit_, *meBadIdHit_;
0051   MonitorElement *meHBNHit_, *meHENHit_, *meHONHit_, *meHFNHit_;
0052   MonitorElement *meDetectHit_, *meSubdetHit_, *meDepthHit_, *meEtaHit_;
0053   MonitorElement *mePhiHit_, *meEnergyHit_, *meTimeHit_, *meTimeWHit_;
0054   MonitorElement *meHBDepHit_, *meHEDepHit_, *meHODepHit_, *meHFDepHit_;
0055   MonitorElement *meHBEtaHit_, *meHEEtaHit_, *meHOEtaHit_, *meHFEtaHit_;
0056   MonitorElement *meHBPhiHit_, *meHEPhiHit_, *meHOPhiHit_, *meHFPhiHit_;
0057   MonitorElement *meHBEneHit_, *meHEEneHit_, *meHOEneHit_, *meHFEneHit_;
0058   MonitorElement *meHBTimHit_, *meHETimHit_, *meHOTimHit_, *meHFTimHit_;
0059   MonitorElement *mePMTHit_, *mePMTDepHit_, *mePMTEtaHit_, *mePMTPhiHit_;
0060   MonitorElement *mePMTEn1Hit_, *mePMTEn2Hit_, *mePMTTimHit_;
0061 
0062   static const int nLayersMAX = 20, nDepthsMAX = 5;
0063   MonitorElement *meLayerLay_, *meEtaHLay_, *mePhiHLay_, *meEneHLay_;
0064   MonitorElement *meDepHlay_, *meTimHLay_, *meTimWLay_;
0065   MonitorElement *meEtaPhi_, *meHitELay_, *meHitHLay_, *meHitTLay_;
0066   MonitorElement *meEneLLay_, *meEneLay_[nLayersMAX], *meLngLay_;
0067   MonitorElement *meEneDLay_, *meDepLay_[nDepthsMAX], *meEtotLay_;
0068   MonitorElement *meEHOLay_, *meEHBHELay_, *meEFibLLay_, *meEFibSLay_;
0069   MonitorElement *meEHFEmLay_, *meEHFHdLay_;
0070 
0071   MonitorElement *meEcalRNxN_, *meHcalRNxN_, *meHoRNxN_, *meEtotRNxN_;
0072   MonitorElement *meEcalNxN_, *meHcalNxN_, *meHoNxN_, *meEtotNxN_;
0073   MonitorElement *meEiNxN_, *meTiNxN_, *meTrNxN_;
0074 
0075   MonitorElement *meRJet_, *meTJet_, *meEJet_;
0076   MonitorElement *meEcalJet_, *meHcalJet_, *meHoJet_, *meEtotJet_, *meEcHcJet_;
0077   MonitorElement *meDetaJet_, *meDphiJet_, *meDrJet_, *meMassJet_;
0078   MonitorElement *meEneJet_, *meEtaJet_, *mePhiJet_;
0079 };
0080 
0081 HcalHitValidation::HcalHitValidation(const edm::ParameterSet &ps)
0082     : g4Label(ps.getUntrackedParameter<std::string>("moduleLabel", "g4SimHits")),
0083       hcalHits(ps.getUntrackedParameter<std::string>("HitCollection", "HcalHits")),
0084       layerInfo(ps.getUntrackedParameter<std::string>("LayerInfo", "PHcalValidInfoLayer")),
0085       nxNInfo(ps.getUntrackedParameter<std::string>("NxNInfo", "PHcalValidInfoNxN")),
0086       jetsInfo(ps.getUntrackedParameter<std::string>("JetsInfo", "PHcalValidInfoJets")),
0087       outFile_(ps.getUntrackedParameter<std::string>("outputFile", "hcValid.root")),
0088       verbose_(ps.getUntrackedParameter<bool>("Verbose", false)),
0089       scheme_(ps.getUntrackedParameter<bool>("TestNumbering", true)),
0090       checkHit_(ps.getUntrackedParameter<bool>("CheckHits", true)),
0091       checkLay_(ps.getUntrackedParameter<bool>("CheckLayer", true)),
0092       checkNxN_(ps.getUntrackedParameter<bool>("CheckNxN", true)),
0093       checkJet_(ps.getUntrackedParameter<bool>("CheckJets", true)),
0094       tok_hh_(consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label, hcalHits))),
0095       tok_iL_(consumes<PHcalValidInfoLayer>(edm::InputTag(g4Label, layerInfo))),
0096       tok_iN_(consumes<PHcalValidInfoNxN>(edm::InputTag(g4Label, nxNInfo))),
0097       tok_iJ_(consumes<PHcalValidInfoJets>(edm::InputTag(g4Label, jetsInfo))) {
0098   edm::LogVerbatim("HcalHitValid") << "Module Label: " << g4Label << "   Hits: " << hcalHits << " / " << checkHit_
0099                                    << "   LayerInfo: " << layerInfo << " / " << checkLay_ << "  NxNInfo: " << nxNInfo
0100                                    << " / " << checkNxN_ << "  jetsInfo: " << jetsInfo << " / " << checkJet_
0101                                    << "   Output: " << outFile_ << "   Usage of TestNumberingScheme " << scheme_;
0102 }
0103 
0104 void HcalHitValidation::bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &, edm::EventSetup const &) {
0105   ibooker.setCurrentFolder("HcalHitValidation");
0106 
0107   char title[60], name[20];
0108   double my_pi = 3.1415926;
0109   // Histograms for Hits
0110   if (checkHit_) {
0111     meAllNHit_ = ibooker.book1D("Hit01", "Number of Hits in HCal", 1000, 0., 5000.);
0112     meBadDetHit_ = ibooker.book1D("Hit02", "Hits with wrong Det", 100, 0., 100.);
0113     meBadSubHit_ = ibooker.book1D("Hit03", "Hits with wrong Subdet", 100, 0., 100.);
0114     meBadIdHit_ = ibooker.book1D("Hit04", "Hits with wrong ID", 100, 0., 100.);
0115     meHBNHit_ = ibooker.book1D("Hit05", "Number of Hits in HB", 1000, 0., 5000.);
0116     meHENHit_ = ibooker.book1D("Hit06", "Number of Hits in HE", 1000, 0., 5000.);
0117     meHONHit_ = ibooker.book1D("Hit07", "Number of Hits in HO", 1000, 0., 5000.);
0118     meHFNHit_ = ibooker.book1D("Hit08", "Number of Hits in HF", 1000, 0., 5000.);
0119     meDetectHit_ = ibooker.book1D("Hit09", "Detector ID", 50, 0., 50.);
0120     meSubdetHit_ = ibooker.book1D("Hit10", "Subdetectors in HCal", 50, 0., 50.);
0121     meDepthHit_ = ibooker.book1D("Hit11", "Depths in HCal", 20, 0., 20.);
0122     meEtaHit_ = ibooker.book1D("Hit12", "Eta in HCal", 100, -50., 50.);
0123     mePhiHit_ = ibooker.book1D("Hit13", "Phi in HCal", 100, 0., 100.);
0124     meEnergyHit_ = ibooker.book1D("Hit14", "Energy in HCal", 100, 0., 1.);
0125     meTimeHit_ = ibooker.book1D("Hit15", "Time in HCal", 100, 0., 400.);
0126     meTimeWHit_ = ibooker.book1D("Hit16", "Time in HCal (E wtd)", 100, 0., 400.);
0127     meHBDepHit_ = ibooker.book1D("Hit17", "Depths in HB", 20, 0., 20.);
0128     meHEDepHit_ = ibooker.book1D("Hit18", "Depths in HE", 20, 0., 20.);
0129     meHODepHit_ = ibooker.book1D("Hit19", "Depths in HO", 20, 0., 20.);
0130     meHFDepHit_ = ibooker.book1D("Hit20", "Depths in HF", 20, 0., 20.);
0131     meHBEtaHit_ = ibooker.book1D("Hit21", "Eta in HB", 100, -50., 50.);
0132     meHEEtaHit_ = ibooker.book1D("Hit22", "Eta in HE", 100, -50., 50.);
0133     meHOEtaHit_ = ibooker.book1D("Hit23", "Eta in HO", 100, -50., 50.);
0134     meHFEtaHit_ = ibooker.book1D("Hit24", "Eta in HF", 100, -50., 50.);
0135     meHBPhiHit_ = ibooker.book1D("Hit25", "Phi in HB", 100, 0., 100.);
0136     meHEPhiHit_ = ibooker.book1D("Hit26", "Phi in HE", 100, 0., 100.);
0137     meHOPhiHit_ = ibooker.book1D("Hit27", "Phi in HO", 100, 0., 100.);
0138     meHFPhiHit_ = ibooker.book1D("Hit28", "Phi in HF", 100, 0., 100.);
0139     meHBEneHit_ = ibooker.book1D("Hit29", "Energy in HB", 100, 0., 1.);
0140     meHEEneHit_ = ibooker.book1D("Hit30", "Energy in HE", 100, 0., 1.);
0141     meHOEneHit_ = ibooker.book1D("Hit31", "Energy in HO", 100, 0., 1.);
0142     meHFEneHit_ = ibooker.book1D("Hit32", "Energy in HF", 100, 0., 100.);
0143     meHBTimHit_ = ibooker.book1D("Hit33", "Time in HB", 100, 0., 400.);
0144     meHETimHit_ = ibooker.book1D("Hit34", "Time in HE", 100, 0., 400.);
0145     meHOTimHit_ = ibooker.book1D("Hit35", "Time in HO", 100, 0., 400.);
0146     meHFTimHit_ = ibooker.book1D("Hit36", "Time in HF", 100, 0., 400.);
0147     mePMTHit_ = ibooker.book1D("Hit37", "Number of Hit in PMT", 1000, 0., 1000.);
0148     mePMTDepHit_ = ibooker.book1D("Hit38", "Depths in HF PMT", 20, 0., 20.);
0149     mePMTEtaHit_ = ibooker.book1D("Hit39", "Eta in HF PMT", 100, -50., 50.);
0150     mePMTPhiHit_ = ibooker.book1D("Hit40", "Phi in HF PMT", 100, 0., 100.);
0151     mePMTEn1Hit_ = ibooker.book1D("Hit41", "Energy (Ceren) in PMT", 100, 0., 100.);
0152     mePMTEn2Hit_ = ibooker.book1D("Hit42", "Energy (dE/dx) in PMT", 100, 0., 100.);
0153     mePMTTimHit_ = ibooker.book1D("Hit43", "Time in HF PMT", 100, 0., 400.);
0154   }
0155 
0156   // Histograms for Layers
0157   if (checkLay_) {
0158     meLayerLay_ = ibooker.book1D("Lay01", "Layer # of the Hits", 20, 0., 20.);
0159     meEtaHLay_ = ibooker.book1D("Lay02", "Eta of the Hits", 100, -5., 5.);
0160     mePhiHLay_ = ibooker.book1D("Lay03", "Phi of the Hits", 100, -my_pi, my_pi);
0161     meEneHLay_ = ibooker.book1D("Lay04", "Energy of the Hits", 100, 0., 2.);
0162     meDepHlay_ = ibooker.book1D("Lay05", "Depth  of the Hits", 10, 0., 10.);
0163     meTimHLay_ = ibooker.book1D("Lay06", "Time of the Hits", 100, 0., 400.);
0164     meTimWLay_ = ibooker.book1D("Lay07", "Time (wtd) of Hits", 100, 0., 400.);
0165     meEtaPhi_ = ibooker.book2D("Lay08", "Phi%Eta of the Hits", 100, -5., 5., 100, -my_pi, my_pi);
0166 
0167     meHitELay_ = ibooker.book1D("Lay09", "Hit in Ecal", 1000, 0., 2000.);
0168     meHitHLay_ = ibooker.book1D("Lay10", "Hit in Hcal", 1000, 0., 2000.);
0169     meHitTLay_ = ibooker.book1D("Lay11", "Total Hits", 1000, 0., 2000.);
0170     meEneLLay_ = ibooker.book1D("Lay12", "Energy per layer", 100, 0., 1.);
0171     int nn = 0;
0172     for (int i = 0; i < nLayersMAX; i++) {
0173       sprintf(name, "Layl%d", nn);
0174       nn++;
0175       sprintf(title, "Energy deposit in Layer %d", i);
0176       meEneLay_[i] = ibooker.book1D(name, title, 100, 0., 0.4);
0177     }
0178     meLngLay_ = ibooker.book1D("Lay13", "Lonitudinal Shower Profile", 20, 0, 20.);
0179     meEneDLay_ = ibooker.book1D("Lay14", "Energy per depth", 100, 0., 1.);
0180     for (int i = 0; i < nDepthsMAX; i++) {
0181       sprintf(name, "Layl%d", nn);
0182       nn++;
0183       sprintf(title, "Energy deposit in Depth %d", i);
0184       meDepLay_[i] = ibooker.book1D(name, title, 100, 0., 2.);
0185     }
0186 
0187     meEtotLay_ = ibooker.book1D("Lay15", "Total Energy", 100, 0., 1.);
0188     meEHOLay_ = ibooker.book1D("Lay16", "Energy in HO", 100, 0., 2000.);
0189     meEHBHELay_ = ibooker.book1D("Lay17", "Energy in HB/HE", 100, 0., 2000.);
0190     meEFibLLay_ = ibooker.book1D("Lay18", "Energy in HF (Long)", 100, 0., 100.);
0191     meEFibSLay_ = ibooker.book1D("Lay19", "Energy in HF (Short)", 100, 0., 100.);
0192     meEHFEmLay_ = ibooker.book1D("Lay20", "EM   energy in HF", 100, 0., 200.);
0193     meEHFHdLay_ = ibooker.book1D("Lay21", "Had. energy in HF", 100, 0., 200.);
0194   }
0195 
0196   // Histograms for NxN analysis
0197   if (checkNxN_) {
0198     meEcalRNxN_ = ibooker.book1D("NxN01", "Energy in ECal (NxN)r", 100, 0., 200.);
0199     meHcalRNxN_ = ibooker.book1D("NxN02", "Energy in HCal (NxN)r", 100, 0., 200.);
0200     meHoRNxN_ = ibooker.book1D("NxN03", "Energy in HO (NxN)r", 100, 0., 200.);
0201     meEtotRNxN_ = ibooker.book1D("NxN04", "Energy Total (NxN)r", 100, 0., 200.);
0202     meEcalNxN_ = ibooker.book1D("NxN05", "Energy in ECal (NxN)", 100, 0., 200.);
0203     meHcalNxN_ = ibooker.book1D("NxN06", "Energy in HCal (NxN)", 100, 0., 200.);
0204     meHoNxN_ = ibooker.book1D("NxN07", "Energy in HO (NxN)", 100, 0., 200.);
0205     meEtotNxN_ = ibooker.book1D("NxN08", "Energy Total (NxN)", 100, 0., 200.);
0206     meEiNxN_ = ibooker.book1D("NxN09", "Energy of Hits in (NxN)", 100, 0., 1.);
0207     meTiNxN_ = ibooker.book1D("NxN10", "Time   of Hits in (NxN)", 100, 0., 400.);
0208     meTrNxN_ = ibooker.book1D("NxN11", "Dist.  of Hits in (NxN)", 100, 0., 1.);
0209   }
0210 
0211   // Histograms for Jets
0212   if (checkJet_) {
0213     meRJet_ = ibooker.book1D("Jet01", "R of Hits", 100, 0., 1.);
0214     meTJet_ = ibooker.book1D("Jet02", "T of Hits", 100, 0., 200.);
0215     meEJet_ = ibooker.book1D("Jet03", "E of Hits", 100, 0., 200.);
0216     meEcalJet_ = ibooker.book1D("Jet04", "Ecal Energy (First Jet)", 100, 0., 200.);
0217     meHcalJet_ = ibooker.book1D("Jet05", "Hcal Energy (First Jet)", 100, 0., 200.);
0218     meHoJet_ = ibooker.book1D("Jet06", "Ho   Energy (First Jet)", 100, 0., 200.);
0219     meEtotJet_ = ibooker.book1D("Jet07", "Total Energy(First Jet)", 100, 0., 200.);
0220     meEcHcJet_ = ibooker.book2D("Jet08", "Energy in Hcal% Ecal", 100, 0., 200., 100, 0., 200.);
0221 
0222     meDetaJet_ = ibooker.book1D("Jet09", "Delta Eta", 100, 0., 2.);
0223     meDphiJet_ = ibooker.book1D("Jet10", "Delta Phi", 100, 0., 1.);
0224     meDrJet_ = ibooker.book1D("Jet11", "Delta R", 100, 0., 2.);
0225     meMassJet_ = ibooker.book1D("Jet12", "Di-jet mass", 100, 0., 200.);
0226     meEneJet_ = ibooker.book1D("Jet13", "Jet Energy", 100, 0., 200.);
0227     meEtaJet_ = ibooker.book1D("Jet14", "Jet Eta", 100, -5., 5.);
0228     mePhiJet_ = ibooker.book1D("Jet15", "Jet Phi", 100, -my_pi, my_pi);
0229   }
0230 }
0231 
0232 void HcalHitValidation::analyze(const edm::Event &e, const edm::EventSetup &) {
0233   edm::LogVerbatim("HcalHitValid") << "Run = " << e.id().run() << " Event = " << e.id().event();
0234 
0235   bool getHits = false;
0236   if (checkHit_) {
0237     const edm::Handle<edm::PCaloHitContainer> &hitsHcal = e.getHandle(tok_hh_);
0238     if (hitsHcal.isValid())
0239       getHits = true;
0240     if (getHits) {
0241       std::vector<PCaloHit> caloHits;
0242       caloHits.insert(caloHits.end(), hitsHcal->begin(), hitsHcal->end());
0243       edm::LogVerbatim("HcalHitValid") << "HcalValidation: Hit buffer " << caloHits.size();
0244       analyzeHits(caloHits);
0245     }
0246   }
0247 
0248   bool getLayer = false;
0249   if (checkLay_) {
0250     const edm::Handle<PHcalValidInfoLayer> &infoLayer = e.getHandle(tok_iL_);
0251     if (infoLayer.isValid()) {
0252       getLayer = true;
0253       analyzeLayer(infoLayer);
0254     }
0255   }
0256 
0257   bool getNxN = false;
0258   if (checkNxN_) {
0259     const edm::Handle<PHcalValidInfoNxN> &infoNxN = e.getHandle(tok_iN_);
0260     if (infoNxN.isValid()) {
0261       getNxN = true;
0262       analyzeNxN(infoNxN);
0263     }
0264   }
0265 
0266   bool getJets = false;
0267   if (checkJet_) {
0268     const edm::Handle<PHcalValidInfoJets> &infoJets = e.getHandle(tok_iJ_);
0269     if (infoJets.isValid()) {
0270       getJets = true;
0271       analyzeJets(infoJets);
0272     }
0273   }
0274 
0275   edm::LogVerbatim("HcalHitValid") << "HcalValidation: Input flags Hits " << getHits << ", Layer " << getLayer
0276                                    << ", NxN " << getNxN << ", Jets " << getJets;
0277 }
0278 
0279 void HcalHitValidation::analyzeHits(std::vector<PCaloHit> &hits) {
0280   int nHit = hits.size();
0281   int nHB = 0, nHE = 0, nHO = 0, nHF = 0, nPMT = 0, nBad1 = 0, nBad2 = 0, nBad = 0;
0282   for (int i = 0; i < nHit; i++) {
0283     double energy = hits[i].energy();
0284     double time = hits[i].time();
0285     unsigned int id_ = hits[i].id();
0286     int det, subdet, depth, eta, phi;
0287     if (scheme_) {
0288       det = 4;
0289       subdet = (id_ >> 28) & 15;
0290       depth = (id_ >> 26) & 3;
0291       depth++;
0292       int zside = ((id_ & 0x100000) ? (1) : (-1));
0293       eta = zside * ((id_ >> 10) & 1023);
0294       phi = (id_ & 1023);
0295     } else {
0296       HcalDetId id = HcalDetId(id_);
0297       det = id.det();
0298       subdet = id.subdet();
0299       depth = id.depth();
0300       eta = id.ieta();
0301       phi = id.iphi();
0302     }
0303     uint16_t depth_ = hits[i].depth();
0304     double energyEM = hits[i].energyEM();
0305     double energyHad = hits[i].energyHad();
0306     edm::LogVerbatim("HcalHitValid") << "Hit[" << i << "] ID " << std::hex << id_ << std::dec << " Det " << det
0307                                      << " Sub " << subdet << " depth " << depth << " " << depth_ << " Eta " << eta
0308                                      << " Phi " << phi << " E " << energy << "(EM " << energyEM << ", Had " << energyHad
0309                                      << ") time " << time;
0310     if (det == 4) {  // Check DetId.h
0311       if (subdet == static_cast<int>(HcalBarrel)) {
0312         nHB++;
0313       } else if (subdet == static_cast<int>(HcalEndcap)) {
0314         nHE++;
0315       } else if (subdet == static_cast<int>(HcalOuter)) {
0316         nHO++;
0317       } else if (subdet == static_cast<int>(HcalForward)) {
0318         if (depth_ == 0)
0319           nHF++;
0320         else
0321           nPMT++;
0322       } else {
0323         nBad++;
0324         nBad2++;
0325       }
0326     } else {
0327       nBad++;
0328       nBad1++;
0329     }
0330 
0331     meDetectHit_->Fill(double(det));
0332     if (det == 4 && depth_ == 0) {
0333       meSubdetHit_->Fill(double(subdet));
0334       meDepthHit_->Fill(double(depth));
0335       meEtaHit_->Fill(double(eta));
0336       mePhiHit_->Fill(double(phi));
0337       meEnergyHit_->Fill(energy);
0338       meTimeHit_->Fill(time);
0339       meTimeWHit_->Fill(double(time), energy);
0340       if (subdet == static_cast<int>(HcalBarrel)) {
0341         meHBDepHit_->Fill(double(depth));
0342         meHBEtaHit_->Fill(double(eta));
0343         meHBPhiHit_->Fill(double(phi));
0344         meHBEneHit_->Fill(energy);
0345         meHBTimHit_->Fill(time);
0346       } else if (subdet == static_cast<int>(HcalEndcap)) {
0347         meHEDepHit_->Fill(double(depth));
0348         meHEEtaHit_->Fill(double(eta));
0349         meHEPhiHit_->Fill(double(phi));
0350         meHEEneHit_->Fill(energy);
0351         meHETimHit_->Fill(time);
0352       } else if (subdet == static_cast<int>(HcalOuter)) {
0353         meHODepHit_->Fill(double(depth));
0354         meHOEtaHit_->Fill(double(eta));
0355         meHOPhiHit_->Fill(double(phi));
0356         meHOEneHit_->Fill(energy);
0357         meHOTimHit_->Fill(time);
0358       } else if (subdet == static_cast<int>(HcalForward)) {
0359         meHFDepHit_->Fill(double(depth));
0360         meHFEtaHit_->Fill(double(eta));
0361         meHFPhiHit_->Fill(double(phi));
0362         meHFEneHit_->Fill(energy);
0363         meHFTimHit_->Fill(time);
0364       }
0365     } else if (det == 0 && subdet == static_cast<int>(HcalForward)) {
0366       mePMTDepHit_->Fill(double(depth));
0367       mePMTEtaHit_->Fill(double(eta));
0368       mePMTPhiHit_->Fill(double(phi));
0369       mePMTEn1Hit_->Fill(energyEM);
0370       mePMTEn2Hit_->Fill(energyHad);
0371       mePMTTimHit_->Fill(time);
0372     }
0373   }
0374   meAllNHit_->Fill(double(nHit));
0375   meBadDetHit_->Fill(double(nBad1));
0376   meBadSubHit_->Fill(double(nBad2));
0377   meBadIdHit_->Fill(double(nBad));
0378   meHBNHit_->Fill(double(nHB));
0379   meHENHit_->Fill(double(nHE));
0380   meHONHit_->Fill(double(nHO));
0381   meHFNHit_->Fill(double(nHF));
0382   mePMTHit_->Fill(double(nPMT));
0383 
0384   edm::LogVerbatim("HcalHitValid") << "HcalHitValidation::analyzeHits: HB " << nHB << " HE " << nHE << " HO " << nHO
0385                                    << " HF " << nHF << " PMT " << nPMT << " Bad " << nBad << " All " << nHit;
0386 }
0387 
0388 void HcalHitValidation::analyzeLayer(const edm::Handle<PHcalValidInfoLayer> &infoLayer) {
0389   // CaloHits from PHcalValidInfoLayer
0390   int nHits = infoLayer->nHit();
0391   std::vector<float> idHits = infoLayer->idHit();
0392   std::vector<float> phiHits = infoLayer->phiHit();
0393   std::vector<float> etaHits = infoLayer->etaHit();
0394   std::vector<float> layerHits = infoLayer->layerHit();
0395   std::vector<float> eHits = infoLayer->eHit();
0396   std::vector<float> tHits = infoLayer->tHit();
0397 
0398   int ne = 0, nh = 0;
0399   for (int j = 0; j < nHits; j++) {
0400     int layer = (int)(layerHits[j]) - 1;
0401     int id = (int)(idHits[j]);
0402 
0403     if (id >= 10) {
0404       ne++;
0405     } else {
0406       nh++;
0407     }
0408 
0409     edm::LogVerbatim("HcalHitValid") << "HcalHitValidation::analyzeLayer:Hit subdet = " << id << "  lay = " << layer;
0410 
0411     meLayerLay_->Fill(double(layer));
0412     meEtaHLay_->Fill(etaHits[j]);
0413     mePhiHLay_->Fill(phiHits[j]);
0414     meEneHLay_->Fill(eHits[j]);
0415     meDepHlay_->Fill(idHits[j]);
0416     meTimHLay_->Fill(tHits[j]);
0417     meTimWLay_->Fill(tHits[j], eHits[j]);
0418     if (id < 6)  // HCAL only. Depth is needed, not layer !!!
0419     {
0420       meEtaPhi_->Fill(etaHits[j], phiHits[j]);
0421     }
0422   }
0423 
0424   meHitELay_->Fill(double(ne));
0425   meHitHLay_->Fill(double(nh));
0426   meHitTLay_->Fill(double(nHits));
0427 
0428   // Layers and depths PHcalValidInfoLayer
0429   std::vector<float> eLayer = infoLayer->elayer();
0430   std::vector<float> eDepth = infoLayer->edepth();
0431   float eTot = 0.;
0432 
0433   for (int j = 0; j < nLayersMAX; j++) {
0434     eTot += eLayer[j];
0435     meEneLLay_->Fill(eLayer[j]);
0436     meEneLay_[j]->Fill(eLayer[j]);
0437     meLngLay_->Fill((double)(j), eLayer[j]);  // HCAL SimHits only
0438   }
0439   for (int j = 0; j < nDepthsMAX; j++) {
0440     meEneDLay_->Fill(eDepth[j]);
0441     meDepLay_[j]->Fill(eDepth[j]);
0442   }
0443   meEtotLay_->Fill(eTot);
0444 
0445   // The rest  PHcalValidInfoLayer
0446   double eHO = infoLayer->eho();
0447   double eHBHE = infoLayer->ehbhe();
0448   double elongHF = infoLayer->elonghf();
0449   double eshortHF = infoLayer->eshorthf();
0450   double eEcalHF = infoLayer->eecalhf();
0451   double eHcalHF = infoLayer->ehcalhf();
0452 
0453   meEHOLay_->Fill(eHO);
0454   meEHBHELay_->Fill(eHBHE);
0455   meEFibLLay_->Fill(elongHF);
0456   meEFibSLay_->Fill(eshortHF);
0457   meEHFEmLay_->Fill(eEcalHF);
0458   meEHFHdLay_->Fill(eHcalHF);
0459 
0460   edm::LogVerbatim("HcalHitValid") << "HcalHitValidation::analyzeLayer: eHO " << eHO << "  eHBHE = " << eHBHE
0461                                    << " elongHF = " << elongHF << " eshortHF = " << eshortHF
0462                                    << "  eEcalHF = " << eEcalHF << "  eHcalHF = " << eHcalHF;
0463 }
0464 
0465 void HcalHitValidation::analyzeNxN(const edm::Handle<PHcalValidInfoNxN> &infoNxN) {
0466   // NxN quantities
0467   double ecalNxNr = infoNxN->ecalnxnr();
0468   double hcalNxNr = infoNxN->hcalnxnr();
0469   double hoNxNr = infoNxN->honxnr();
0470   double etotNxNr = infoNxN->etotnxnr();
0471 
0472   double ecalNxN = infoNxN->ecalnxn();
0473   double hcalNxN = infoNxN->hcalnxn();
0474   double hoNxN = infoNxN->honxn();
0475   double etotNxN = infoNxN->etotnxn();
0476 
0477   meEcalRNxN_->Fill(ecalNxNr);
0478   meHcalRNxN_->Fill(hcalNxNr);
0479   meHoRNxN_->Fill(hoNxNr);
0480   meEtotRNxN_->Fill(etotNxNr);
0481 
0482   meEcalNxN_->Fill(ecalNxN);
0483   meHcalNxN_->Fill(hcalNxN);
0484   meHoNxN_->Fill(hoNxN);
0485   meEtotNxN_->Fill(etotNxN);
0486 
0487   int nIxI = infoNxN->nnxn();
0488   std::vector<float> idIxI = infoNxN->idnxn();
0489   std::vector<float> eIxI = infoNxN->enxn();
0490   std::vector<float> tIxI = infoNxN->tnxn();
0491 
0492   for (int j = 0; j < nIxI; j++)  // NB !!! j < nIxI
0493   {
0494     meEiNxN_->Fill(eIxI[j]);
0495     meTiNxN_->Fill(tIxI[j]);
0496     meTrNxN_->Fill(idIxI[j], eIxI[j]);  // transverse profile
0497   }
0498 
0499   edm::LogVerbatim("HcalHitValid") << "HcalHitValidation::analyzeNxN: " << nIxI
0500                                    << " hits in NxN analysis; Total Energy " << etotNxN << "/" << etotNxNr;
0501 }
0502 
0503 void HcalHitValidation::analyzeJets(const edm::Handle<PHcalValidInfoJets> &infoJets) {
0504   // -- Leading Jet
0505   int nJetHits = infoJets->njethit();
0506 
0507   std::vector<float> rJetHits = infoJets->jethitr();
0508   std::vector<float> tJetHits = infoJets->jethitt();
0509   std::vector<float> eJetHits = infoJets->jethite();
0510 
0511   double ecalJet = infoJets->ecaljet();
0512   double hcalJet = infoJets->hcaljet();
0513   double hoJet = infoJets->hojet();
0514   double etotJet = infoJets->etotjet();
0515 
0516   double detaJet = infoJets->detajet();
0517   double dphiJet = infoJets->dphijet();
0518   double drJet = infoJets->drjet();
0519   double dijetM = infoJets->dijetm();
0520 
0521   for (int j = 0; j < nJetHits; j++) {
0522     meRJet_->Fill(rJetHits[j]);
0523     meTJet_->Fill(tJetHits[j]);
0524     meEJet_->Fill(eJetHits[j]);
0525   }
0526 
0527   meEcalJet_->Fill(ecalJet);
0528   meHcalJet_->Fill(hcalJet);
0529   meHoJet_->Fill(hoJet);
0530   meEtotJet_->Fill(etotJet);
0531   meEcHcJet_->Fill(ecalJet, hcalJet);
0532 
0533   meDetaJet_->Fill(detaJet);
0534   meDphiJet_->Fill(dphiJet);
0535   meDrJet_->Fill(drJet);
0536   meMassJet_->Fill(dijetM);
0537 
0538   // All Jets
0539   int nJets = infoJets->njet();
0540   std::vector<float> jetE = infoJets->jete();
0541   std::vector<float> jetEta = infoJets->jeteta();
0542   std::vector<float> jetPhi = infoJets->jetphi();
0543 
0544   for (int j = 0; j < nJets; j++) {
0545     meEneJet_->Fill(jetE[j]);
0546     meEtaJet_->Fill(jetEta[j]);
0547     mePhiJet_->Fill(jetPhi[j]);
0548   }
0549   edm::LogVerbatim("HcalHitValid") << "HcalHitValidation::analyzeJets: " << nJets << " jets with " << nJetHits
0550                                    << " hits in the leading jet\n"
0551                                    << "   d(Eta) = " << detaJet << "  d(Phi) = " << dphiJet << "  d(R) = " << drJet
0552                                    << "  diJet Mass = " << dijetM;
0553 }
0554 
0555 // define this as a plug-in
0556 DEFINE_FWK_MODULE(HcalHitValidation);