Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-28 02:15:42

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/GlobalSystemOfUnits.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 == 0)
0157                          ? HGCalDetId(detId).layer()
0158                          : ((geomType == 1) ? HGCSiliconDetId(detId).layer() : HGCScintillatorDetId(detId).layer()));
0159         const HGCSample& hgcSample = it.sample(SampleIndx_);
0160         uint16_t gain = hgcSample.toa();
0161         uint16_t adc = hgcSample.data();
0162         double charge = gain;
0163         bool totmode = hgcSample.mode();
0164         bool zerothreshold = hgcSample.threshold();
0165         digiValidation(detId, geom0, layer, adc, charge, totmode, zerothreshold);
0166       }
0167       fillDigiInfo();
0168     } else {
0169       edm::LogVerbatim("HGCalValidation") << "DigiCollection handle does not "
0170                                           << "exist for " << nameDetector_;
0171     }
0172   } else {
0173     edm::LogWarning("HGCalValidation") << "invalid detector name !! " << nameDetector_;
0174   }
0175   if (verbosity_ > 0)
0176     edm::LogVerbatim("HGCalValidation") << "Event " << iEvent.id().event() << " with " << ntot << " total and " << nused
0177                                         << " used digis";
0178 }
0179 
0180 template <class T1, class T2>
0181 void HGCalDigiValidation::digiValidation(
0182     const T1& detId, const T2* geom, int layer, uint16_t adc, double charge, bool mode, bool threshold) {
0183   if (verbosity_ > 1)
0184     edm::LogVerbatim("HGCalValidation") << std::hex << detId.rawId() << std::dec << " " << detId.rawId();
0185   DetId id1 = DetId(detId.rawId());
0186   const GlobalPoint& global1 = geom->getPosition(id1);
0187 
0188   if (verbosity_ > 1)
0189     edm::LogVerbatim("HGCalValidation") << " adc = " << adc << " toa = " << charge;
0190 
0191   digiInfo hinfo;
0192   hinfo.x = global1.x();
0193   hinfo.y = global1.y();
0194   hinfo.z = global1.z();
0195   hinfo.adc = adc;
0196   hinfo.charge = charge;
0197   hinfo.layer = layer - firstLayer_;
0198   hinfo.mode = mode;
0199   hinfo.threshold = threshold;
0200 
0201   if (verbosity_ > 1)
0202     edm::LogVerbatim("HGCalValidation") << "gx =  " << hinfo.x << " gy = " << hinfo.y << " gz = " << hinfo.z;
0203 
0204   if (global1.eta() > 0)
0205     fillOccupancyMap(OccupancyMap_plus_, hinfo.layer);
0206   else
0207     fillOccupancyMap(OccupancyMap_minus_, hinfo.layer);
0208 
0209   fillDigiInfo(hinfo);
0210 }
0211 
0212 void HGCalDigiValidation::fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer) {
0213   if (OccupancyMap.find(layer) != OccupancyMap.end())
0214     OccupancyMap[layer]++;
0215   else
0216     OccupancyMap[layer] = 1;
0217 }
0218 
0219 void HGCalDigiValidation::fillDigiInfo(digiInfo& hinfo) {
0220   int ilayer = hinfo.layer;
0221   TOA_.at(ilayer)->Fill(hinfo.charge);
0222 
0223   if (hinfo.mode) {
0224     TOT_.at(ilayer)->Fill(hinfo.adc);
0225   }
0226 
0227   if (!hinfo.mode && hinfo.threshold) {
0228     ADC_.at(ilayer)->Fill(hinfo.adc);
0229     DigiOccupancy_XY_.at(ilayer)->Fill(hinfo.x, hinfo.y);
0230   }
0231 }
0232 
0233 void HGCalDigiValidation::fillDigiInfo() {
0234   for (const auto& itr : OccupancyMap_plus_) {
0235     int layer = itr.first;
0236     int occupancy = itr.second;
0237     DigiOccupancy_Plus_.at(layer)->Fill(occupancy);
0238   }
0239   for (const auto& itr : OccupancyMap_minus_) {
0240     int layer = itr.first;
0241     int occupancy = itr.second;
0242     DigiOccupancy_Minus_.at(layer)->Fill(occupancy);
0243   }
0244 }
0245 
0246 void HGCalDigiValidation::dqmBeginRun(const edm::Run&, const edm::EventSetup& iSetup) {
0247   const HGCalDDDConstants* hgcons = &iSetup.getData(tok_hgcalc_);
0248   layers_ = hgcons->layers(true);
0249   firstLayer_ = hgcons->firstLayer();
0250 
0251   if (verbosity_ > 0)
0252     edm::LogVerbatim("HGCalValidation") << "current DQM directory:  "
0253                                         << "HGCAL/HGCalDigisV/" << nameDetector_ << "  layer = " << layers_
0254                                         << " with the first one at " << firstLayer_;
0255 }
0256 
0257 void HGCalDigiValidation::bookHistograms(DQMStore::IBooker& iB, edm::Run const&, edm::EventSetup const&) {
0258   iB.setCurrentFolder("HGCAL/HGCalDigisV/" + nameDetector_);
0259 
0260   std::ostringstream histoname;
0261   for (int il = 0; il < layers_; ++il) {
0262     int ilayer = firstLayer_ + il;
0263     auto istr1 = std::to_string(ilayer);
0264     while (istr1.size() < 2) {
0265       istr1.insert(0, "0");
0266     }
0267     histoname.str("");
0268     histoname << "TOA_"
0269               << "layer_" << istr1;
0270     TOA_.push_back(iB.book1D(histoname.str().c_str(), "toa_", 1024, 0, 1024));
0271 
0272     histoname.str("");
0273     histoname << "ADC_"
0274               << "layer_" << istr1;
0275     ADC_.push_back(iB.book1D(histoname.str().c_str(), "ADCDigiOccupancy", 1024, 0, 1024));
0276 
0277     histoname.str("");
0278     histoname << "TOT_"
0279               << "layer_" << istr1;
0280     TOT_.push_back(iB.book1D(histoname.str().c_str(), "TOTDigiOccupancy", 4096, 0, 4096));
0281 
0282     histoname.str("");
0283     histoname << "DigiOccupancy_XY_"
0284               << "layer_" << istr1;
0285     DigiOccupancy_XY_.push_back(iB.book2D(histoname.str().c_str(), "DigiOccupancy", 50, -500, 500, 50, -500, 500));
0286 
0287     histoname.str("");
0288     histoname << "DigiOccupancy_Plus_"
0289               << "layer_" << istr1;
0290     DigiOccupancy_Plus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy +z", 100, 0, 1000));
0291     histoname.str("");
0292     histoname << "DigiOccupancy_Minus_"
0293               << "layer_" << istr1;
0294     DigiOccupancy_Minus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy -z", 100, 0, 1000));
0295   }
0296 
0297   histoname.str("");
0298   histoname << "SUMOfDigiOccupancy_Plus";
0299   MeanDigiOccupancy_Plus_ = iB.book1D(histoname.str().c_str(), "SUMOfDigiOccupancy_Plus", layers_, -0.5, layers_ - 0.5);
0300   histoname.str("");
0301   histoname << "SUMOfRecDigiOccupancy_Minus";
0302   MeanDigiOccupancy_Minus_ =
0303       iB.book1D(histoname.str().c_str(), "SUMOfDigiOccupancy_Minus", layers_, -0.5, layers_ - 0.5);
0304 }
0305 
0306 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0307 
0308 #include "FWCore/Framework/interface/MakerMacros.h"
0309 
0310 //define this as a plug-in
0311 DEFINE_FWK_MODULE(HGCalDigiValidation);