Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-15 23:33:52

0001 // -*- C++ -*-
0002 //
0003 // Package:    testEcalRingCalibrationTools
0004 // Class:      testEcalRingCalibrationTools
0005 //
0006 /**\class testEcalRingCalibrationTools testEcalRingCalibrationTools.cc test/testEcalRingCalibrationTools/src/testEcalRingCalibrationTools.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 
0015 // system include files
0016 #include <memory>
0017 #include <iomanip>
0018 
0019 // user include files
0020 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0021 
0022 #include "FWCore/Framework/interface/EventSetup.h"
0023 #include "FWCore/Framework/interface/MakerMacros.h"
0024 
0025 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0026 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0027 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0028 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0029 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0030 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0031 #include "Calibration/Tools/interface/EcalRingCalibrationTools.h"
0032 #include <fstream>
0033 
0034 //
0035 // class decleration
0036 //
0037 
0038 class testEcalRingCalibrationTools : public edm::one::EDAnalyzer<> {
0039 public:
0040   explicit testEcalRingCalibrationTools(const edm::ParameterSet&);
0041   ~testEcalRingCalibrationTools() override = default;
0042 
0043   void analyze(const edm::Event&, const edm::EventSetup&) override;
0044 
0045 private:
0046   // ----------member data ---------------------------
0047   const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometryToken_;
0048   void build(const CaloGeometry& cg, DetId::Detector det, int subdetn, const char* name);
0049   int pass_;
0050   //  bool fullEcalDump_;
0051 };
0052 
0053 //
0054 // constants, enums and typedefs
0055 //
0056 
0057 //
0058 // static data member definitions
0059 //
0060 
0061 //
0062 // constructors and destructor
0063 //
0064 testEcalRingCalibrationTools::testEcalRingCalibrationTools(const edm::ParameterSet& iConfig)
0065     : geometryToken_(esConsumes()), pass_(0) {
0066   //now do what ever initialization is needed
0067   //  fullEcalDump_=iConfig.getUntrackedParameter<bool>("fullEcalDump",false);
0068 }
0069 
0070 void testEcalRingCalibrationTools::build(const CaloGeometry& cg, DetId::Detector det, int subdetn, const char* name) {
0071   std::fstream f(name, std::ios_base::out);
0072   const CaloSubdetectorGeometry* geom = cg.getSubdetectorGeometry(det, subdetn);
0073 
0074   std::vector<DetId> ids = geom->getValidDetIds(det, subdetn);
0075   if (det == DetId::Ecal && subdetn == EcalBarrel) {
0076     f << "EB-" << std::endl;
0077     for (int iphi = 360; iphi > 0; --iphi) {
0078       for (int ieta = -85; ieta <= -1; ++ieta) {
0079         if (EBDetId::validDetId(ieta, iphi))
0080           f << std::setw(4) << EcalRingCalibrationTools::getRingIndex(EBDetId(ieta, iphi));
0081         else
0082           f << "XXXX";
0083       }
0084       f << std::endl;
0085     }
0086 
0087     for (unsigned int i = 0; i < 10; i++)
0088       f << std::endl;
0089 
0090     f << "EB+" << std::endl;
0091     for (int iphi = 360; iphi > 0; --iphi) {
0092       for (int ieta = 1; ieta <= 85; ++ieta) {
0093         if (EBDetId::validDetId(ieta, iphi))
0094           f << std::setw(4) << EcalRingCalibrationTools::getRingIndex(EBDetId(ieta, iphi));
0095         else
0096           f << "XXXX";
0097       }
0098       f << std::endl;
0099     }
0100 
0101     for (int i = 0; i < EcalRingCalibrationTools::N_RING_BARREL; ++i) {
0102       f << "++++++++++Ring Index " << i << " +++++++++++++++++" << std::endl;
0103       std::vector<DetId> ringIds = EcalRingCalibrationTools::getDetIdsInRing(i);
0104       std::cout << i << " " << ringIds.size() << std::endl;
0105       assert(ringIds.size() == 360);
0106       for (unsigned int iid = 0; iid < ringIds.size(); ++iid)
0107         f << EBDetId(ringIds[iid]) << std::endl;
0108     }
0109   }
0110 
0111   if (det == DetId::Ecal && subdetn == EcalEndcap) {
0112     f << "EE-" << std::endl;
0113     for (int iy = 100; iy > 0; --iy) {
0114       for (int ix = 1; ix <= EEDetId::IX_MAX; ++ix) {
0115         if (EEDetId::validDetId(ix, iy, -1))
0116           f << std::setw(4) << EcalRingCalibrationTools::getRingIndex(EEDetId(ix, iy, -1));
0117         else
0118           f << "XXXX";
0119       }
0120       f << std::endl;
0121     }
0122 
0123     for (unsigned int i = 0; i < 10; i++)
0124       f << std::endl;
0125 
0126     f << "EE+" << std::endl;
0127     for (int iy = 100; iy > 0; --iy) {
0128       for (int ix = 1; ix <= EEDetId::IX_MAX; ++ix) {
0129         if (EEDetId::validDetId(ix, iy, 1))
0130           f << std::setw(4) << EcalRingCalibrationTools::getRingIndex(EEDetId(ix, iy, +1));
0131         else
0132           f << "XXXX";
0133       }
0134       f << std::endl;
0135     }
0136 
0137     unsigned int totalRingSize = 0;
0138     for (int i = EcalRingCalibrationTools::N_RING_BARREL; i < EcalRingCalibrationTools::N_RING_TOTAL; ++i) {
0139       f << "++++++++++Ring Index " << i << " +++++++++++++++++" << std::endl;
0140       std::vector<DetId> ringIds = EcalRingCalibrationTools::getDetIdsInRing(i);
0141       std::cout << i << " " << ringIds.size() << std::endl;
0142       totalRingSize += ringIds.size();
0143       for (unsigned int iid = 0; iid < ringIds.size(); ++iid)
0144         f << EEDetId(ringIds[iid]) << std::endl;
0145     }
0146     assert(totalRingSize == ids.size());
0147   }
0148   f.close();
0149 }
0150 
0151 //
0152 // member functions
0153 //
0154 
0155 // ------------ method called to produce the data  ------------
0156 void testEcalRingCalibrationTools::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0157   std::cout << "Here I am " << std::endl;
0158 
0159   // get the ecal & hcal geometry
0160   //
0161   if (pass_ == 1) {
0162     const auto& geom = iSetup.getData(geometryToken_);
0163     EcalRingCalibrationTools::setCaloGeometry(&geom);
0164     build(geom, DetId::Ecal, EcalBarrel, "eb.ringDump");
0165     build(geom, DetId::Ecal, EcalEndcap, "ee.ringDump");
0166   }
0167 
0168   pass_++;
0169 }
0170 
0171 //define this as a plug-in
0172 
0173 DEFINE_FWK_MODULE(testEcalRingCalibrationTools);