Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:22:49

0001 /** \class GEMDigiReader
0002  *  Dumps GEM trigger pad digis
0003  *
0004  *  \authors: Vadim Khotilovich
0005  */
0006 
0007 #include "FWCore/Framework/interface/EDAnalyzer.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/Framework/interface/ESHandle.h"
0011 #include "FWCore/Utilities/interface/ESGetToken.h"
0012 #include "FWCore/Utilities/interface/InputTag.h"
0013 #include "Geometry/GEMGeometry/interface/GEMGeometry.h"
0014 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0015 #include "DataFormats/GEMDigi/interface/GEMDigiCollection.h"
0016 #include "DataFormats/GEMDigi/interface/GEMPadDigiCollection.h"
0017 
0018 #include <map>
0019 #include <vector>
0020 #include <iostream>
0021 #include <iterator>
0022 #include <algorithm>
0023 
0024 using namespace std;
0025 
0026 class GEMPadDigiReader : public edm::EDAnalyzer {
0027 public:
0028   explicit GEMPadDigiReader(const edm::ParameterSet& pset);
0029 
0030   ~GEMPadDigiReader() override {}
0031 
0032   void analyze(const edm::Event&, const edm::EventSetup&) override;
0033 
0034 private:
0035   edm::EDGetTokenT<GEMDigiCollection> gemDigiToken_;
0036   edm::EDGetTokenT<GEMPadDigiCollection> gemPadToken_;
0037   edm::ESGetToken<GEMGeometry, MuonGeometryRecord> geomToken_;
0038 };
0039 
0040 GEMPadDigiReader::GEMPadDigiReader(const edm::ParameterSet& pset)
0041     : gemDigiToken_(consumes<GEMDigiCollection>(pset.getParameter<edm::InputTag>("gemDigiToken"))),
0042       gemPadToken_(consumes<GEMPadDigiCollection>(pset.getParameter<edm::InputTag>("gemPadToken"))),
0043       geomToken_(esConsumes<GEMGeometry, MuonGeometryRecord>()) {}
0044 
0045 void GEMPadDigiReader::analyze(const edm::Event& event, const edm::EventSetup& eventSetup) {
0046   //cout << "--- Run: " << event.id().run() << " Event: " << event.id().event() << endl;
0047 
0048   edm::ESHandle<GEMGeometry> geometry = eventSetup.getHandle(geomToken_);
0049 
0050   edm::Handle<GEMDigiCollection> digis;
0051   event.getByToken(gemDigiToken_, digis);
0052 
0053   edm::Handle<GEMPadDigiCollection> pads;
0054   event.getByToken(gemPadToken_, pads);
0055 
0056   if (pads->begin() == pads->end())
0057     return;  // no pads in event
0058 
0059   for (auto pad_range_it = pads->begin(); pad_range_it != pads->end(); ++pad_range_it) {
0060     const auto& id = (*pad_range_it).first;
0061     const auto& roll = geometry->etaPartition(id);
0062 
0063     // GEMDetId print-out
0064     cout << "--------------" << endl;
0065     //cout<<"id: "<<id.rawId()<<" #strips "<<roll->nstrips()<<"  #pads "<<roll->npads()<<endl;
0066 
0067     // retrieve this DetUnit's digis
0068     std::map<std::pair<int, int>,  // #pad (starting from 1), BX
0069              std::vector<int>      // digi strip numbers (starting from 1)
0070              >
0071         digi_map;
0072     auto digis_in_det = digis->get(id);
0073     cout << "strip digis in detid: ";
0074     for (auto d = digis_in_det.first; d != digis_in_det.second; ++d) {
0075       int pad_num = 1 + static_cast<int>(roll->padOfStrip(d->strip()));  // d->strip() is int
0076       digi_map[{pad_num, d->bx()}].push_back(d->strip());
0077       cout << "  (" << d->strip() << "," << d->bx() << ") -> " << pad_num;
0078     }
0079     cout << endl;
0080 
0081     // loop over pads of this DetUnit and print stuff
0082     auto pads_range = (*pad_range_it).second;
0083     for (auto p = pads_range.first; p != pads_range.second; ++p) {
0084       int first_strip = roll->firstStripInPad(p->pad());  // p->pad() is int, firstStripInPad returns int
0085       int last_strip = roll->lastStripInPad(p->pad());
0086 
0087       if (p->pad() < 1 || p->pad() > roll->npads()) {
0088         cout << " XXXXXXXXXXXXX Problem! " << id << " has pad digi with too large pad# = " << p->pad() << endl;
0089       }
0090 
0091       auto& strips = digi_map[{p->pad(), p->bx()}];
0092       std::vector<int> pads_strips;
0093       remove_copy_if(
0094           strips.begin(), strips.end(), inserter(pads_strips, pads_strips.end()), [first_strip, last_strip](int s) {
0095             return s < first_strip || s > last_strip;
0096           });
0097       cout << id << " paddigi(pad,bx) " << *p << "   has " << pads_strips.size() << " strip digis strips in range ["
0098            << first_strip << "," << last_strip << "]: ";
0099       copy(pads_strips.begin(), pads_strips.end(), ostream_iterator<int>(cout, " "));
0100       cout << endl;
0101     }
0102 
0103   }  // for (detids with pads)
0104 }
0105 
0106 #include "FWCore/Framework/interface/MakerMacros.h"
0107 DEFINE_FWK_MODULE(GEMPadDigiReader);