Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-10 02:51:16

0001 #include "CalibFormats/SiStripObjects/interface/SiStripFecCabling.h"
0002 #include "CondFormats/DataRecord/interface/SiStripApvGainRcd.h"
0003 #include "CondFormats/SiStripObjects/interface/SiStripApvGain.h"
0004 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0005 #include "FWCore/Framework/interface/ESHandle.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Framework/interface/Run.h"
0009 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 
0013 #include <cmath>
0014 #include <iomanip>
0015 #include <iostream>
0016 #include <sstream>
0017 
0018 /**
0019    @class testSiStripGainBuilderFromDb 
0020    @brief Analyzes FEC (and FED) cabling object(s)
0021 */
0022 class testSiStripGainBuilderFromDb : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0023 public:
0024   testSiStripGainBuilderFromDb(const edm::ParameterSet&) : gainToken_(esConsumes<edm::Transition::BeginRun>()) {}
0025 
0026   ~testSiStripGainBuilderFromDb() override = default;
0027   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0028   void endRun(const edm::Run&, const edm::EventSetup&) override;
0029   void analyze(const edm::Event&, const edm::EventSetup&) override;
0030 
0031 private:
0032   const edm::ESGetToken<SiStripApvGain, SiStripApvGainRcd> gainToken_;
0033 };
0034 
0035 void testSiStripGainBuilderFromDb::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {}
0036 
0037 // -----------------------------------------------------------------------------
0038 void testSiStripGainBuilderFromDb::endRun(const edm::Run& run, const edm::EventSetup& setup) {}
0039 
0040 // -----------------------------------------------------------------------------
0041 void testSiStripGainBuilderFromDb::beginRun(const edm::Run& run, const edm::EventSetup& setup) {
0042   const SiStripApvGain* gain = &setup.getData(gainToken_);
0043   std::vector<uint32_t> ids;
0044   gain->getDetIds(ids);
0045 
0046   uint16_t ndets = ids.size();
0047   uint32_t napvs = 0;
0048   uint16_t isset = 0;
0049   uint16_t unset = 0;
0050   std::map<uint16_t, uint16_t> apvs;
0051 
0052   std::stringstream ss;
0053   ss << "[testSiStripGainBuilderFromDb::" << __func__ << "]"
0054      << " Values: " << std::endl;
0055   std::vector<uint32_t>::const_iterator ii = ids.begin();
0056   std::vector<uint32_t>::const_iterator jj = ids.end();
0057   for (; ii != jj; ++ii) {
0058     SiStripApvGain::Range range = gain->getRange(*ii);
0059     if (range.first == range.second) {
0060       continue;
0061     }
0062     std::vector<float>::const_iterator iii = range.first;
0063     std::vector<float>::const_iterator jjj = range.second;
0064     uint16_t temp = 0;
0065     ss << " DetId: " << *ii << " Gain: ";
0066     for (; iii != jjj; ++iii) {
0067       ss << std::fixed << std::setprecision(2) << *iii << " ";
0068       napvs++;
0069       temp++;
0070       if (fabs(*iii - 0.8) < 1.e-6) {
0071         unset++;
0072       } else {
0073         isset++;
0074       }
0075     }
0076     apvs[temp]++;
0077     ss << std::endl;
0078   }
0079   LogTrace("TEST") << ss.str();
0080 
0081   std::stringstream sss;
0082   sss << "[testSiStripGainBuilderFromDb::" << __func__ << "]"
0083       << " Summary: " << std::endl
0084       << " Ndets             : " << ndets << std::endl
0085       << " Napvs (total)     : " << napvs << std::endl
0086       << " Npavs (breakdown) : ";
0087   std::map<uint16_t, uint16_t>::const_iterator iiii = apvs.begin();
0088   std::map<uint16_t, uint16_t>::const_iterator jjjj = apvs.end();
0089   for (; iiii != jjjj; ++iiii) {
0090     sss << iiii->first << "/" << iiii->second << " ";
0091   }
0092   sss << std::endl << " Is set (!=0.8)    : " << isset << std::endl << " Not set (=0.8)    : " << unset;
0093   edm::LogVerbatim("TEST") << sss.str();
0094 }
0095 
0096 #include "FWCore/Framework/interface/MakerMacros.h"
0097 DEFINE_FWK_MODULE(testSiStripGainBuilderFromDb);