Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:09

0001 // -*- C++ -*-
0002 //
0003 // Package:    WhatsItAnalyzer
0004 // Class:      WhatsItAnalyzer
0005 //
0006 /**\class WhatsItAnalyzer WhatsItAnalyzer.cc test/WhatsItAnalyzer/src/WhatsItAnalyzer.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Chris Jones
0015 //         Created:  Fri Jun 24 19:13:25 EDT 2005
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <time.h>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 
0032 #include "FWCore/Framework/interface/EventSetup.h"
0033 
0034 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
0035 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
0036 
0037 #include "CalibFormats/HcalObjects/interface/HcalCalibrations.h"
0038 #include "CalibFormats/HcalObjects/interface/HcalCalibrationWidths.h"
0039 #include "CondFormats/HcalObjects/interface/HcalQIEShape.h"
0040 #include "CondFormats/HcalObjects/interface/HcalQIECoder.h"
0041 #include "CondFormats/HcalObjects/interface/HcalElectronicsMap.h"
0042 
0043 #include "CalibFormats/HcalObjects/interface/HcalText2DetIdConverter.h"
0044 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
0045 #include "DataFormats/HcalDetId/interface/HcalTrigTowerDetId.h"
0046 #include "DataFormats/HcalDetId/interface/HcalCalibDetId.h"
0047 #include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
0048 #include "DataFormats/HcalDetId/interface/HcalElectronicsId.h"
0049 
0050 namespace {
0051   std::ostream& operator<<(std::ostream& fOut, const DetId& id) {
0052     if (id.null())
0053       fOut << "NULL";
0054     else if (id.det() == DetId::Calo && id.subdetId() == HcalZDCDetId::SubdetectorId) {
0055       fOut << HcalZDCDetId(id);
0056     } else if (id.det() != DetId::Hcal)
0057       fOut << "Not HCAL";
0058     else {
0059       HcalSubdetector sub = HcalSubdetector(id.subdetId());
0060       if (sub == HcalBarrel || sub == HcalEndcap || sub == HcalOuter || sub == HcalForward)
0061         fOut << HcalDetId(id);
0062       else if (sub == HcalEmpty)
0063         fOut << "EMPTY";
0064       else if (sub == HcalTriggerTower)
0065         fOut << HcalTrigTowerDetId(id);
0066       else if (sub == HcalOther) {
0067         HcalOtherDetId osub(id);
0068         HcalOtherSubdetector odetid = osub.subdet();
0069         if (odetid == HcalCalibration)
0070           fOut << HcalCalibDetId(id);
0071         else
0072           fOut << "Unknown subtype";
0073       } else
0074         fOut << "Unknown type";
0075     }
0076     return fOut;
0077   }
0078 }  // namespace
0079 
0080 class HcalDbAnalyzer : public edm::one::EDAnalyzer<> {
0081 public:
0082   explicit HcalDbAnalyzer(const edm::ParameterSet&);
0083   ~HcalDbAnalyzer() override = default;
0084 
0085   void analyze(const edm::Event&, const edm::EventSetup&) override;
0086 
0087 private:
0088   // ----------member data ---------------------------
0089   edm::ESGetToken<HcalDbService, HcalDbRecord> tok_setup_;
0090 };
0091 
0092 //
0093 // constants, enums and typedefs
0094 //
0095 
0096 //
0097 // static data member definitions
0098 //
0099 
0100 //
0101 // constructors and destructor
0102 //
0103 HcalDbAnalyzer::HcalDbAnalyzer(const edm::ParameterSet& iConfig) {
0104   tok_setup_ = esConsumes<HcalDbService, HcalDbRecord>();
0105 
0106   std::cout << "HcalDbAnalyzer::HcalDbAnalyzer->..." << std::endl;
0107   //now do what ever initialization is needed
0108 }
0109 
0110 //
0111 // member functions
0112 //
0113 
0114 // ------------ method called to produce the data  ------------
0115 void HcalDbAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0116   std::cout << "HcalDbAnalyzer::analyze->..." << std::endl;
0117   const HcalDbService* pSetup = &iSetup.getData(tok_setup_);
0118   std::cout << "HcalDbAnalyzer::analyze-> got HcalDbRecord: " << std::endl;
0119   std::cout << "HcalDbAnalyzer::analyze-> getting information for HB channel eta=1, phi=1, depth=1..." << std::endl;
0120   HcalDetId cell(HcalBarrel, 1, 1, 1);
0121 
0122   const HcalCalibrations& calibrations = pSetup->getHcalCalibrations(cell);
0123   const HcalCalibrationWidths widths = pSetup->getHcalCalibrationWidths(cell);
0124   const HcalQIECoder* coder = pSetup->getHcalCoder(cell);
0125   const HcalQIEShape* shape = pSetup->getHcalShape(cell);
0126 
0127   std::cout << "Values-> pedestals: " << calibrations.pedestal(0) << '/' << calibrations.pedestal(1) << '/'
0128             << calibrations.pedestal(2) << '/' << calibrations.pedestal(3) << ",  gains: " << calibrations.rawgain(0)
0129             << '/' << calibrations.rawgain(1) << '/' << calibrations.rawgain(2) << '/' << calibrations.rawgain(3)
0130             << std::endl;
0131   std::cout << "Widths. pedestals: " << widths.pedestal(0) << '/' << widths.pedestal(1) << '/' << widths.pedestal(2)
0132             << '/' << widths.pedestal(3) << ",  gains: " << widths.gain(0) << '/' << widths.gain(1) << '/'
0133             << widths.gain(2) << '/' << widths.gain(3) << std::endl;
0134 
0135   std::cout << "QIE shape:" << std::endl;
0136   for (int i = 0; i < 128; i++) {
0137     double q0 = coder->charge(*shape, i, 0);
0138     double q1 = coder->charge(*shape, i, 1);
0139     double q2 = coder->charge(*shape, i, 2);
0140     double q3 = coder->charge(*shape, i, 3);
0141 
0142     unsigned adc0 = coder->adc(*shape, q0, 0);
0143     unsigned adc1 = coder->adc(*shape, q1, 0);
0144     unsigned adc2 = coder->adc(*shape, q2, 0);
0145     unsigned adc3 = coder->adc(*shape, q3, 0);
0146 
0147     std::cout << " ADC: " << i << " q1:" << q0 << " q2:" << q1 << " q3:" << q2 << " q4:" << q3 << std::endl;
0148     std::cout << " reverse ADC: " << i << " q1:" << adc0 << " q2:" << adc1 << " q3:" << adc2 << " q4:" << adc3
0149               << std::endl;
0150   }
0151 
0152   std::cout << "Electronics map: " << std::endl;
0153   const HcalElectronicsMap* emap = pSetup->getHcalMapping();
0154   std::vector<HcalElectronicsId> eids = emap->allElectronicsId();
0155   for (std::vector<HcalElectronicsId>::const_iterator j = eids.begin(); j != eids.end(); ++j) {
0156     DetId did = emap->lookup(*j);
0157     std::cout << *j << " " << did << std::endl;
0158   }
0159 }
0160 
0161 //define this as a plug-in
0162 DEFINE_FWK_MODULE(HcalDbAnalyzer);