Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-10 02:21:35

0001 // system include files
0002 #include <cmath>
0003 #include <fstream>
0004 #include <iostream>
0005 #include <map>
0006 #include <string>
0007 #include <vector>
0008 
0009 #include "DataFormats/DetId/interface/DetId.h"
0010 #include "DataFormats/ForwardDetId/interface/HFNoseDetId.h"
0011 #include "DataFormats/ForwardDetId/interface/HGCScintillatorDetId.h"
0012 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0013 #include "DataFormats/HGCDigi/interface/HGCDigiCollections.h"
0014 
0015 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0016 #include "DQMServices/Core/interface/DQMStore.h"
0017 
0018 #include "FWCore/Framework/interface/Frameworkfwd.h"
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/EventSetup.h"
0021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0024 #include "FWCore/Utilities/interface/InputTag.h"
0025 
0026 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0027 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0028 #include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
0029 
0030 #include <CLHEP/Units/SystemOfUnits.h>
0031 
0032 // user include files
0033 
0034 class HGCalDigiValidation : public DQMEDAnalyzer {
0035 public:
0036   struct digiInfo {
0037     digiInfo() {
0038       x = y = z = charge = 0.0;
0039       layer = adc = 0;
0040       mode = threshold = false;
0041     }
0042     double x, y, z, charge;
0043     int layer, adc;
0044     bool mode, threshold;  //tot mode and zero supression
0045   };
0046 
0047   explicit HGCalDigiValidation(const edm::ParameterSet&);
0048   ~HGCalDigiValidation() override = default;
0049 
0050   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0051   void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
0052   void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0053   void analyze(const edm::Event&, const edm::EventSetup&) override;
0054 
0055 private:
0056   void fillDigiInfo(digiInfo& hinfo);
0057   void fillDigiInfo();
0058   void fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer);
0059   template <class T1, class T2>
0060   void digiValidation(
0061       const T1& detId, const T2* geom, int layer, uint16_t adc, double charge, bool mode, bool threshold);
0062 
0063   // ----------member data ---------------------------
0064   const std::string nameDetector_;
0065   const bool ifNose_;
0066   const int verbosity_, SampleIndx_;
0067   const edm::ESGetToken<HGCalDDDConstants, IdealGeometryRecord> tok_hgcalc_;
0068   const edm::ESGetToken<HGCalGeometry, IdealGeometryRecord> tok_hgcalg_;
0069   const edm::EDGetTokenT<HGCalDigiCollection> digiSource_;
0070   int layers_, firstLayer_;
0071 
0072   std::map<int, int> OccupancyMap_plus_;
0073   std::map<int, int> OccupancyMap_minus_;
0074 
0075   std::vector<MonitorElement*> TOA_;
0076   std::vector<MonitorElement*> DigiOccupancy_XY_;
0077   std::vector<MonitorElement*> ADC_;
0078   std::vector<MonitorElement*> TOT_;
0079   std::vector<MonitorElement*> DigiOccupancy_Plus_;
0080   std::vector<MonitorElement*> DigiOccupancy_Minus_;
0081   MonitorElement* MeanDigiOccupancy_Plus_;
0082   MonitorElement* MeanDigiOccupancy_Minus_;
0083 };
0084 
0085 HGCalDigiValidation::HGCalDigiValidation(const edm::ParameterSet& iConfig)
0086     : nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
0087       ifNose_(iConfig.getParameter<bool>("ifNose")),
0088       verbosity_(iConfig.getUntrackedParameter<int>("Verbosity", 0)),
0089       SampleIndx_(iConfig.getUntrackedParameter<int>("SampleIndx", 0)),
0090       tok_hgcalc_(esConsumes<HGCalDDDConstants, IdealGeometryRecord, edm::Transition::BeginRun>(
0091           edm::ESInputTag{"", nameDetector_})),
0092       tok_hgcalg_(esConsumes<HGCalGeometry, IdealGeometryRecord>(edm::ESInputTag{"", nameDetector_})),
0093       digiSource_(consumes<HGCalDigiCollection>(iConfig.getParameter<edm::InputTag>("DigiSource"))),
0094       firstLayer_(1) {}
0095 
0096 void HGCalDigiValidation::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0097   edm::ParameterSetDescription desc;
0098   desc.add<std::string>("DetectorName", "HGCalEESensitive");
0099   desc.add<edm::InputTag>("DigiSource", edm::InputTag("hgcalDigis", "EE"));
0100   desc.add<bool>("ifNose", false);
0101   desc.addUntracked<int>("Verbosity", 0);
0102   desc.addUntracked<int>("SampleIndx", 2);  // central bx
0103   descriptions.add("hgcalDigiValidationEEDefault", desc);
0104 }
0105 
0106 void HGCalDigiValidation::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0107   OccupancyMap_plus_.clear();
0108   OccupancyMap_minus_.clear();
0109 
0110   int geomType(0);
0111   const HGCalGeometry* geom0 = &iSetup.getData(tok_hgcalg_);
0112   if (geom0->topology().waferHexagon8())
0113     geomType = 1;
0114   else
0115     geomType = 2;
0116   if (nameDetector_ == "HGCalHFNoseSensitive")
0117     geomType = 3;
0118 
0119   unsigned int ntot(0), nused(0);
0120   if ((nameDetector_ == "HGCalEESensitive") || (nameDetector_ == "HGCalHFNoseSensitive")) {
0121     //HGCalEE
0122     const edm::Handle<HGCalDigiCollection>& theHGCEEDigiContainers = iEvent.getHandle(digiSource_);
0123     if (theHGCEEDigiContainers.isValid()) {
0124       if (verbosity_ > 0)
0125         edm::LogVerbatim("HGCalValidation")
0126             << nameDetector_ << " with " << theHGCEEDigiContainers->size() << " element(s)";
0127       for (const auto& it : *(theHGCEEDigiContainers.product())) {
0128         ntot++;
0129         nused++;
0130         DetId detId = it.id();
0131         int layer = ((geomType == 1) ? HGCSiliconDetId(detId).layer() : HFNoseDetId(detId).layer());
0132         const HGCSample& hgcSample = it.sample(SampleIndx_);
0133         uint16_t gain = hgcSample.toa();
0134         uint16_t adc = hgcSample.data();
0135         double charge = gain;
0136         bool totmode = hgcSample.mode();
0137         bool zerothreshold = hgcSample.threshold();
0138         digiValidation(detId, geom0, layer, adc, charge, totmode, zerothreshold);
0139       }
0140       fillDigiInfo();
0141     } else {
0142       edm::LogVerbatim("HGCalValidation") << "DigiCollection handle does not "
0143                                           << "exist for " << nameDetector_;
0144     }
0145   } else if ((nameDetector_ == "HGCalHESiliconSensitive") || (nameDetector_ == "HGCalHEScintillatorSensitive")) {
0146     //HGCalHE
0147     const edm::Handle<HGCalDigiCollection>& theHGCHEDigiContainers = iEvent.getHandle(digiSource_);
0148     if (theHGCHEDigiContainers.isValid()) {
0149       if (verbosity_ > 0)
0150         edm::LogVerbatim("HGCalValidation")
0151             << nameDetector_ << " with " << theHGCHEDigiContainers->size() << " element(s)";
0152       for (const auto& it : *(theHGCHEDigiContainers.product())) {
0153         ntot++;
0154         nused++;
0155         DetId detId = it.id();
0156         int layer = ((geomType == 1) ? HGCSiliconDetId(detId).layer() : HGCScintillatorDetId(detId).layer());
0157         const HGCSample& hgcSample = it.sample(SampleIndx_);
0158         uint16_t gain = hgcSample.toa();
0159         uint16_t adc = hgcSample.data();
0160         double charge = gain;
0161         bool totmode = hgcSample.mode();
0162         bool zerothreshold = hgcSample.threshold();
0163         digiValidation(detId, geom0, layer, adc, charge, totmode, zerothreshold);
0164       }
0165       fillDigiInfo();
0166     } else {
0167       edm::LogVerbatim("HGCalValidation") << "DigiCollection handle does not "
0168                                           << "exist for " << nameDetector_;
0169     }
0170   } else {
0171     edm::LogWarning("HGCalValidation") << "invalid detector name !! " << nameDetector_;
0172   }
0173   if (verbosity_ > 0)
0174     edm::LogVerbatim("HGCalValidation") << "Event " << iEvent.id().event() << " with " << ntot << " total and " << nused
0175                                         << " used digis";
0176 }
0177 
0178 template <class T1, class T2>
0179 void HGCalDigiValidation::digiValidation(
0180     const T1& detId, const T2* geom, int layer, uint16_t adc, double charge, bool mode, bool threshold) {
0181   if (verbosity_ > 1)
0182     edm::LogVerbatim("HGCalValidation") << std::hex << detId.rawId() << std::dec << " " << detId.rawId();
0183   DetId id1 = DetId(detId.rawId());
0184   const GlobalPoint& global1 = geom->getPosition(id1);
0185 
0186   if (verbosity_ > 1)
0187     edm::LogVerbatim("HGCalValidation") << " adc = " << adc << " toa = " << charge;
0188 
0189   digiInfo hinfo;
0190   hinfo.x = global1.x();
0191   hinfo.y = global1.y();
0192   hinfo.z = global1.z();
0193   hinfo.adc = adc;
0194   hinfo.charge = charge;
0195   hinfo.layer = layer - firstLayer_;
0196   hinfo.mode = mode;
0197   hinfo.threshold = threshold;
0198 
0199   if (verbosity_ > 1)
0200     edm::LogVerbatim("HGCalValidation") << "gx =  " << hinfo.x << " gy = " << hinfo.y << " gz = " << hinfo.z;
0201 
0202   if (global1.eta() > 0)
0203     fillOccupancyMap(OccupancyMap_plus_, hinfo.layer);
0204   else
0205     fillOccupancyMap(OccupancyMap_minus_, hinfo.layer);
0206 
0207   fillDigiInfo(hinfo);
0208 }
0209 
0210 void HGCalDigiValidation::fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer) {
0211   if (OccupancyMap.find(layer) != OccupancyMap.end())
0212     OccupancyMap[layer]++;
0213   else
0214     OccupancyMap[layer] = 1;
0215 }
0216 
0217 void HGCalDigiValidation::fillDigiInfo(digiInfo& hinfo) {
0218   int ilayer = hinfo.layer;
0219   TOA_.at(ilayer)->Fill(hinfo.charge);
0220 
0221   if (hinfo.mode) {
0222     TOT_.at(ilayer)->Fill(hinfo.adc);
0223   }
0224 
0225   if (!hinfo.mode && hinfo.threshold) {
0226     ADC_.at(ilayer)->Fill(hinfo.adc);
0227     DigiOccupancy_XY_.at(ilayer)->Fill(hinfo.x, hinfo.y);
0228   }
0229 }
0230 
0231 void HGCalDigiValidation::fillDigiInfo() {
0232   for (const auto& itr : OccupancyMap_plus_) {
0233     int layer = itr.first;
0234     int occupancy = itr.second;
0235     DigiOccupancy_Plus_.at(layer)->Fill(occupancy);
0236   }
0237   for (const auto& itr : OccupancyMap_minus_) {
0238     int layer = itr.first;
0239     int occupancy = itr.second;
0240     DigiOccupancy_Minus_.at(layer)->Fill(occupancy);
0241   }
0242 }
0243 
0244 void HGCalDigiValidation::dqmBeginRun(const edm::Run&, const edm::EventSetup& iSetup) {
0245   const HGCalDDDConstants* hgcons = &iSetup.getData(tok_hgcalc_);
0246   layers_ = hgcons->layers(true);
0247   firstLayer_ = hgcons->firstLayer();
0248 
0249   if (verbosity_ > 0)
0250     edm::LogVerbatim("HGCalValidation") << "current DQM directory:  "
0251                                         << "HGCAL/HGCalDigisV/" << nameDetector_ << "  layer = " << layers_
0252                                         << " with the first one at " << firstLayer_;
0253 }
0254 
0255 void HGCalDigiValidation::bookHistograms(DQMStore::IBooker& iB, edm::Run const&, edm::EventSetup const&) {
0256   iB.setCurrentFolder("HGCAL/HGCalDigisV/" + nameDetector_);
0257 
0258   std::ostringstream histoname;
0259   for (int il = 0; il < layers_; ++il) {
0260     int ilayer = firstLayer_ + il;
0261     auto istr1 = std::to_string(ilayer);
0262     while (istr1.size() < 2) {
0263       istr1.insert(0, "0");
0264     }
0265     histoname.str("");
0266     histoname << "TOA_"
0267               << "layer_" << istr1;
0268     TOA_.push_back(iB.book1D(histoname.str().c_str(), "toa_", 1024, 0, 1024));
0269 
0270     histoname.str("");
0271     histoname << "ADC_"
0272               << "layer_" << istr1;
0273     ADC_.push_back(iB.book1D(histoname.str().c_str(), "ADCDigiOccupancy", 1024, 0, 1024));
0274 
0275     histoname.str("");
0276     histoname << "TOT_"
0277               << "layer_" << istr1;
0278     TOT_.push_back(iB.book1D(histoname.str().c_str(), "TOTDigiOccupancy", 4096, 0, 4096));
0279 
0280     histoname.str("");
0281     histoname << "DigiOccupancy_XY_"
0282               << "layer_" << istr1;
0283     DigiOccupancy_XY_.push_back(iB.book2D(histoname.str().c_str(), "DigiOccupancy", 50, -500, 500, 50, -500, 500));
0284 
0285     histoname.str("");
0286     histoname << "DigiOccupancy_Plus_"
0287               << "layer_" << istr1;
0288     DigiOccupancy_Plus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy +z", 100, 0, 1000));
0289     histoname.str("");
0290     histoname << "DigiOccupancy_Minus_"
0291               << "layer_" << istr1;
0292     DigiOccupancy_Minus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy -z", 100, 0, 1000));
0293   }
0294 
0295   histoname.str("");
0296   histoname << "SUMOfDigiOccupancy_Plus";
0297   MeanDigiOccupancy_Plus_ = iB.book1D(histoname.str().c_str(), "SUMOfDigiOccupancy_Plus", layers_, -0.5, layers_ - 0.5);
0298   histoname.str("");
0299   histoname << "SUMOfRecDigiOccupancy_Minus";
0300   MeanDigiOccupancy_Minus_ =
0301       iB.book1D(histoname.str().c_str(), "SUMOfDigiOccupancy_Minus", layers_, -0.5, layers_ - 0.5);
0302 }
0303 
0304 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0305 
0306 #include "FWCore/Framework/interface/MakerMacros.h"
0307 
0308 //define this as a plug-in
0309 DEFINE_FWK_MODULE(HGCalDigiValidation);