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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
/*
 * \file L1TRPCTPG.cc
 *
 * \author J. Berryhill
 *
 */

#include "DQM/L1TMonitor/interface/L1TRPCTPG.h"

using namespace std;
using namespace edm;

L1TRPCTPG::L1TRPCTPG(const ParameterSet& ps)
    : rpctpgSource_(ps.getParameter<InputTag>("rpctpgSource")),
      rpctpgSource_token_(consumes<RPCDigiCollection>(ps.getParameter<InputTag>("rpctpgSource"))),
      rpctfSource_(ps.getParameter<InputTag>("rpctfSource")),
      rpctfSource_token_(consumes<L1MuGMTReadoutCollection>(ps.getParameter<InputTag>("rpctfSource"))) {
  // verbosity switch
  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);

  if (verbose_)
    cout << "L1TRPCTPG: constructor...." << endl;

  outputFile_ = ps.getUntrackedParameter<string>("outputFile", "");
  if (!outputFile_.empty()) {
    cout << "L1T Monitoring histograms will be saved to " << outputFile_.c_str() << endl;
  }

  bool disable = ps.getUntrackedParameter<bool>("disableROOToutput", false);
  if (disable) {
    outputFile_ = "";
  }
  rpcgeomToken_ = esConsumes();
}

L1TRPCTPG::~L1TRPCTPG() {}

void L1TRPCTPG::dqmBeginRun(edm::Run const& r, edm::EventSetup const& c) {
  //
}

void L1TRPCTPG::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const&, edm::EventSetup const&) {
  nev_ = 0;

  ibooker.setCurrentFolder("L1T/L1TRPCTPG");

  rpctpgbx = ibooker.book1D("RPCTPG_bx", "RPC digis bx - all events", 9, -4.5, 4.5);

  rpctpgndigi[1] = ibooker.book1D("RPCTPG_ndigi", "RPCTPG nDigi bx 0", 100, -0.5, 99.5);
  rpctpgndigi[2] = ibooker.book1D("RPCTPG_ndigi_+1", "RPCTPG nDigi bx +1", 100, -0.5, 99.5);
  rpctpgndigi[0] = ibooker.book1D("RPCTPG_ndigi_-1", "RPCTPG nDigi bx -1", 100, -0.5, 99.5);

  m_digiBxRPCBar = ibooker.book1D("RPCDigiRPCBmu_noDTmu_bx", "RPC digis bx - RPC, !DT", 9, -4.5, 4.5);

  m_digiBxRPCEnd = ibooker.book1D("RPCDigiRPCEmu_noCSCmu_bx", "RPC digis bx - RPC, !CSC", 9, -4.5, 4.5);

  m_digiBxDT = ibooker.book1D("RPCDigiDTmu_noRPCBmu_bx", "RPC digis bx - !RPC, DT", 9, -4.5, 4.5);

  m_digiBxCSC = ibooker.book1D("RPCDigiCSCmu_noRPCEmu_bx", "RPC digis bx - !RPC, CSC", 9, -4.5, 4.5);
}

void L1TRPCTPG::analyze(const Event& e, const EventSetup& c) {
  nev_++;
  if (verbose_)
    cout << "L1TRPCTPG: analyze...." << endl;

  /// RPC Geometry
  const auto& rpcGeo = c.getHandle(rpcgeomToken_);
  if (!rpcGeo.isValid()) {
    edm::LogInfo("DataNotFound") << "can't find RPCGeometry" << endl;
    return;
  }
  //   char layerLabel[328];
  //   char meId [328];

  /// DIGI
  edm::Handle<RPCDigiCollection> rpcdigis;
  e.getByToken(rpctpgSource_token_, rpcdigis);

  if (!rpcdigis.isValid()) {
    edm::LogInfo("DataNotFound") << "can't find RPCDigiCollection with label " << rpctpgSource_ << endl;
    return;
  }

  // Calculate the number of DT and CSC cands present
  edm::Handle<L1MuGMTReadoutCollection> pCollection;
  e.getByToken(rpctfSource_token_, pCollection);

  if (!pCollection.isValid()) {
    edm::LogInfo("DataNotFound") << "can't find L1MuGMTReadoutCollection with label " << rpctfSource_.label();
    return;
  }

  L1MuGMTReadoutCollection const* gmtrc = pCollection.product();
  vector<L1MuGMTReadoutRecord> gmt_records = gmtrc->getRecords();
  vector<L1MuGMTReadoutRecord>::const_iterator RRItr;

  int nRPCTrackBarrel, nRPCTrackEndcap, nDTTrack, nCSCTrack;
  nRPCTrackBarrel = 0;
  nRPCTrackEndcap = 0;
  nDTTrack = 0;
  nCSCTrack = 0;

  for (RRItr = gmt_records.begin(); RRItr != gmt_records.end(); RRItr++) {
    // DTs
    vector<L1MuRegionalCand> DTCands = RRItr->getDTBXCands();
    for (vector<L1MuRegionalCand>::const_iterator ECItr = DTCands.begin(); ECItr != DTCands.end(); ++ECItr) {
      if (!ECItr->empty()) {
        ++nDTTrack;
      }
    }
    // CSCs
    vector<L1MuRegionalCand> CSCCands = RRItr->getCSCCands();
    for (vector<L1MuRegionalCand>::const_iterator ECItr = CSCCands.begin(); ECItr != CSCCands.end(); ++ECItr) {
      if (!ECItr->empty()) {
        ++nCSCTrack;
      }
    }

    //RPC barrel
    vector<L1MuRegionalCand> RPCBCands = RRItr->getBrlRPCCands();
    for (vector<L1MuRegionalCand>::const_iterator ECItr = RPCBCands.begin(); ECItr != RPCBCands.end(); ++ECItr) {
      if (!ECItr->empty()) {
        ++nRPCTrackBarrel;
      }
    }

    //RPC endcap
    vector<L1MuRegionalCand> RPCECands = RRItr->getFwdRPCCands();
    for (vector<L1MuRegionalCand>::const_iterator ECItr = RPCECands.begin(); ECItr != RPCECands.end(); ++ECItr) {
      if (!ECItr->empty()) {
        ++nRPCTrackEndcap;
      }
    }
  }

  int numberofDigi[3] = {0, 0, 0};

  RPCDigiCollection::DigiRangeIterator collectionItr;
  for (collectionItr = rpcdigis->begin(); collectionItr != rpcdigis->end(); ++collectionItr) {
    RPCDigiCollection::const_iterator digiItr;
    for (digiItr = ((*collectionItr).second).first; digiItr != ((*collectionItr).second).second; ++digiItr) {
      // strips is a list of hit strips (regardless of bx) for this roll
      //        int strip= (*digiItr).strip();
      //        strips.push_back(strip);
      int bx = (*digiItr).bx();
      rpctpgbx->Fill(bx);
      //

      if (nRPCTrackBarrel == 0 && nDTTrack != 0) {
        m_digiBxDT->Fill(bx);
      } else if (nRPCTrackBarrel != 0 && nDTTrack == 0) {
        m_digiBxRPCBar->Fill(bx);
      }

      if (nRPCTrackEndcap == 0 && nCSCTrack != 0) {
        m_digiBxCSC->Fill(bx);
      } else if (nRPCTrackEndcap != 0 && nCSCTrack == 0) {
        m_digiBxRPCEnd->Fill(bx);
      }

      if (bx == -1) {
        numberofDigi[0]++;
      }
      if (bx == 0) {
        //         sprintf(meId,"Occupancy_%s",detUnitLabel);
        // 	meMap[meId]->Fill(strip);
        numberofDigi[1]++;
      }
      if (bx == 2) {
        numberofDigi[2]++;
      }

      //        sprintf(meId,"BXN_%s",detUnitLabel);
      //        meMap[meId]->Fill(bx);
      //        sprintf(meId,"BXN_vs_strip_%s",detUnitLabel);
      //        meMap[meId]->Fill(strip,bx);
    }
  }

  rpctpgndigi[0]->Fill(numberofDigi[0]);
  rpctpgndigi[1]->Fill(numberofDigi[1]);
  rpctpgndigi[2]->Fill(numberofDigi[2]);

  if (verbose_)
    cout << "L1TRPCTPG: end job...." << endl;
  LogInfo("EndJob") << "analyzed " << nev_ << " events";
}