Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-09 00:50:52

0001 
0002 /*----------------------------------------------------------------------
0003 
0004 Toy EDProducers and EDProducts for testing purposes only.
0005 
0006 R.Ofierzynski - 2.Oct. 2007
0007    modified to dump all pedestals on screen, see 
0008    testHcalDBFake.cfg
0009    testHcalDBFrontier.cfg
0010 
0011 ----------------------------------------------------------------------*/
0012 
0013 #include <stdexcept>
0014 #include <string>
0015 #include <iostream>
0016 #include <map>
0017 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0018 #include "FWCore/Framework/interface/Event.h"
0019 #include "FWCore/Framework/interface/ESHandle.h"
0020 #include "FWCore/Framework/interface/MakerMacros.h"
0021 
0022 #include "FWCore/Framework/interface/EventSetup.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 
0025 #include "CondFormats/HcalObjects/interface/HcalPedestals.h"
0026 #include "CondFormats/HcalObjects/interface/HcalPedestalWidths.h"
0027 #include "CondFormats/HcalObjects/interface/HcalGains.h"
0028 #include "CondFormats/HcalObjects/interface/HcalGainWidths.h"
0029 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0030 #include "CondFormats/DataRecord/interface/HcalPedestalsRcd.h"
0031 #include "CondFormats/DataRecord/interface/HcalPedestalWidthsRcd.h"
0032 #include "CondFormats/DataRecord/interface/HcalGainsRcd.h"
0033 #include "CondFormats/DataRecord/interface/HcalGainWidthsRcd.h"
0034 
0035 using namespace std;
0036 
0037 namespace edmtest {
0038   class HcalCalibrationsAnalyzer : public edm::one::EDAnalyzer<> {
0039   public:
0040     explicit HcalCalibrationsAnalyzer(edm::ParameterSet const& p);
0041     ~HcalCalibrationsAnalyzer() override = default;
0042     virtual void analyze(const edm::Event& e, const edm::EventSetup& c);
0043 
0044   private:
0045     const edm::ESGetToken<HcalPedestalWidths, HcalPedestalWidthsRcd> tok_pPedWs_;
0046     const edm::ESGetToken<HcalGains, HcalGainsRcd> tok_pGains_;
0047     const edm::ESGetToken<HcalGainWidths, HcalGainWidthsRcd> tok_pGainWs_;
0048     const edm::ESGetToken<HcalPedestals, HcalPedestalsRcd> tok_pPeds_;
0049   };
0050 
0051   HcalCalibrationsAnalyzer::HcalCalibrationsAnalyzer(edm::ParameterSet const&)
0052       :  //      tok_pPedsW_(esConsumes<HcalPedestalWidths, HcalPedestalWisthssRcd>()),
0053          //      tok_pGains_(esConsumes<HcalGains, HcalGainsRcd>()),
0054          //      tok_pGainWs_(esConsumes<HcalGainWidths, HcalGainWidthsRcd>()),
0055         tok_pPeds_(esConsumes<HcalPedestals, HcalPedestalsRcd>()) {}
0056 
0057   void HcalCalibrationsAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& context) {
0058     using namespace edm::eventsetup;
0059     // Context is not used.
0060     std::cout << "HcalCalibrationsAnalyzer::analyze-> I AM IN RUN NUMBER " << e.id().run() << std::endl;
0061     std::cout << "HcalCalibrationsAnalyzer::analyze->  ---EVENT NUMBER " << e.id().run() << std::endl;
0062     const auto& pPeds = context.getHandle(tok_pPeds_);
0063     //  const auto& pPedWs = context.getHandle(tok_pPedWs_);
0064     //  const auto& pGains = context.getHandle(tok_pGains_);
0065     //  const auto& pGainWs = context.getHandle(tok_pGainWs_);
0066     //call tracker code
0067     //
0068 
0069     const HcalPedestals* myped = pPeds.product();
0070     std::vector<DetId> mychannels = myped->getAllChannels();
0071     //    int cnt=0;
0072     for (std::vector<DetId>::const_iterator it = mychannels.begin(); it != mychannels.end(); it++) {
0073       HcalDetId mydetid(*it);
0074       int eta = mydetid.ieta();
0075       int phi = mydetid.iphi();
0076       int depth = mydetid.depth();
0077       int subdet = mydetid.subdet();
0078       char id;
0079       int rawid = mydetid.rawId();
0080       switch (subdet) {
0081         case 1:
0082           id = 'B';
0083           break;
0084         case 2:
0085           id = 'E';
0086           break;
0087         case 3:
0088           id = 'O';
0089           break;
0090         case 4:
0091           id = 'F';
0092           break;
0093       }
0094 
0095       //    std::cout << eta << " " << phi << " " << depth << " " << subdet << " H" << id << " " << rawid;
0096       const float* values = (myped->getValues(mydetid))->getValues();
0097       //    if (values) std::cout << ", pedestals: "
0098       //                  << values [0] << '/' << values [1] << '/' << values [2] << '/' << values [3] << std::endl;
0099 
0100       printf("   %d   %d   %d   H%c   %f   %f   %f   %f   %X\n",
0101              eta,
0102              phi,
0103              depth,
0104              id,
0105              values[0],
0106              values[1],
0107              values[2],
0108              values[3],
0109              rawid);
0110     }
0111 
0112     //    std::cout <<" Hcal peds for channel HB eta=15, phi=5, depth=2 "<<std::endl;
0113     //    int channelID = HcalDetId (HcalBarrel, 15, 5, 2).rawId();
0114     //    const HcalPedestals* myped=pPeds.product();
0115     //    const HcalPedestalWidths* mypedW=pPedWs.product();
0116     //    const HcalGains* mygain=pGains.product();
0117     //    const HcalGainWidths* mygainW=pGainWs.product();
0118     //
0119     //    const float* values = myped->getValues (channelID);
0120     //    if (values) std::cout << "pedestals for channel " << channelID << ": "
0121     //            << values [0] << '/' << values [1] << '/' << values [2] << '/' << values [3] << std::endl;
0122     //    values = mypedW->getValues (channelID);
0123     //    if (values) std::cout << "pedestal widths for channel " << channelID << ": "
0124     //            << values [0] << '/' << values [1] << '/' << values [2] << '/' << values [3] << std::endl;
0125     //    values = mygain->getValues (channelID);
0126     //    if (values) std::cout << "gains for channel " << channelID << ": "
0127     //            << values [0] << '/' << values [1] << '/' << values [2] << '/' << values [3] << std::endl;
0128     //    values = mygainW->getValues (channelID);
0129     //    if (values) std::cout << "gain widts for channel " << channelID << ": "
0130     //            << values [0] << '/' << values [1] << '/' << values [2] << '/' << values [3] << std::endl;
0131   }
0132   DEFINE_FWK_MODULE(HcalCalibrationsAnalyzer);
0133 }  // namespace edmtest