CSCReadoutMapTest

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
#include <stdexcept>
#include <string>
#include <iostream>
#include <map>
#include <vector>
#include "FWCore/Framework/interface/global/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Utilities/interface/ESGetToken.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "CondFormats/CSCObjects/interface/CSCCrateMap.h"
#include "CondFormats/DataRecord/interface/CSCCrateMapRcd.h"

#include "CondFormats/CSCObjects/interface/CSCMapItem.h"

#include "DataFormats/MuonDetId/interface/CSCDetId.h"

using namespace std;
namespace edmtest {
  class CSCReadoutMapTest : public edm::global::EDAnalyzer<> {
  public:
    explicit CSCReadoutMapTest(edm::ParameterSet const& p) : token_{esConsumes()} {}
    ~CSCReadoutMapTest() override {}
    void analyze(edm::StreamID, const edm::Event& e, const edm::EventSetup& c) const override;

  private:
    edm::ESGetToken<CSCCrateMap, CSCCrateMapRcd> token_;
  };

  void CSCReadoutMapTest::analyze(edm::StreamID, const edm::Event& e, const edm::EventSetup& context) const {
    using namespace edm::eventsetup;

    edm::LogSystem log("CSCCrateMap");

    log << "+===================+" << std::endl;
    log << "| CSCReadoutMapTest |" << std::endl;
    log << "+===================+" << std::endl;

    log << "run " << e.id().run() << std::endl;
    log << "event " << e.id().event() << std::endl;

    const CSCCrateMap* pcrate = &context.getData(token_);

    const int ncrates = 60;
    const int ndmb = 10;
    const int missing = 6;
    int count = 0;
    int countall = 0;

    for (int jc = 0; jc != ncrates; ++jc) {
      for (int jd = 0; jd != ndmb; ++jd) {
        if (jd + 1 == missing)
          continue;     // there's no dmb=6
        int jcfeb = 0;  // just set something
        ++countall;
        // The iterations here cover more than available chambers so need
        // to skip non-existing ones
        int jdmb = jd + 1;
        int jcrate = jc + 1;

        int cscid = jdmb;
        if (jdmb >= 6)
          --cscid;
        int key = jcrate * 10 + cscid;
        CSCCrateMap::CSCMap::const_iterator it = (pcrate->crate_map).find(key);
        if (it != (pcrate->crate_map).end()) {
          ++count;
          CSCDetId id = pcrate->detId(jcrate, jdmb, jcfeb);  // *** TEST THE detId BUILDER FOR CHAMBER ***
          log << "Built CSCDetId for chamber # " << count << " id= " << id << " count " << countall << std::endl;

          if (id.station() == 1 && id.ring() == 1) {
            jcfeb = 4;                                         // Split off ME1a
            CSCDetId id = pcrate->detId(jcrate, jdmb, jcfeb);  // *** TEST THE detId BUILDER FOR CHAMBER ME1a ***
            log << "Built CSCDetId for ME1a, id= " << id << " count " << countall << std::endl;
          }

          for (int il = 1; il != 7; ++il) {
            CSCDetId id = pcrate->detId(jcrate, jdmb, jcfeb, il);  // *** TEST THE detId BUILDER FOR LAYER ***
            log << "Built CSCDetId for layer # " << il << " id= " << id << std::endl;
          }

        } else {
          log << "no chamber at count = " << countall << std::endl;
        }
      }
    }
    log << "+==========================+" << std::endl;
    log << "| End of CSCReadoutMapTest |" << std::endl;
    log << "+==========================+" << std::endl;

  }  // namespace
  DEFINE_FWK_MODULE(CSCReadoutMapTest);
}  // namespace edmtest