Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:07:53

0001 /*
0002  * \file L1TRPCTF.cc
0003  *
0004  * \author J. Berryhill
0005  *
0006  */
0007 #include "DQM/L1TMonitor/interface/L1TRPCTF.h"
0008 #include "DQMServices/Core/interface/DQMStore.h"
0009 
0010 #include "DataFormats/RPCDigi/interface/RPCDigi.h"
0011 #include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"
0012 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
0013 
0014 #include <sstream>
0015 using namespace std;
0016 using namespace edm;
0017 
0018 L1TRPCTF::L1TRPCTF(const ParameterSet& ps)
0019     : rpctfSource_(consumes<L1MuGMTReadoutCollection>(ps.getParameter<InputTag>("rpctfSource"))),
0020       //    digiSource_( ps.getParameter< InputTag >("rpctfRPCDigiSource") ),
0021       //   m_rpcDigiFine(false),
0022       //    m_useRpcDigi(true),
0023       m_lastUsedBxInBxdiff(0),
0024       output_dir_(ps.getUntrackedParameter<string>("output_dir"))
0025 //    m_rpcDigiWithBX0(0),
0026 //    m_rpcDigiWithBXnon0(0)
0027 
0028 {
0029   // verbosity switch
0030   verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
0031 
0032   if (verbose_)
0033     cout << "L1TRPCTF: constructor...." << endl;
0034 }
0035 
0036 L1TRPCTF::~L1TRPCTF() {}
0037 
0038 void L1TRPCTF::bookHistograms(DQMStore::IBooker& ibooker, const edm::Run&, const edm::EventSetup&) {
0039   nev_ = 0;
0040   nevRPC_ = 0;
0041 
0042   ostringstream oDir;
0043   oDir << output_dir_ << "/CrateSynchroHistograms/";
0044   ibooker.setCurrentFolder(oDir.str());
0045   for (unsigned int i = 0; i < 12; i++) {
0046     ostringstream o;
0047     o << "RPCTF_crate_" << i << "_synchro";
0048     rpctfcratesynchro[i] = ibooker.book2D(o.str(), o.str(), 5, -2.5, 2.5, 33, -16.5, 16.5);
0049     for (int bx = -2; bx < 3; ++bx) {
0050       ostringstream b;
0051       b << "BX=" << bx;
0052       rpctfcratesynchro[i]->setBinLabel(bx + 3, b.str(), 1);
0053     }
0054     rpctfcratesynchro[i]->setAxisTitle("Tower", 2);
0055   }
0056   ibooker.setCurrentFolder(output_dir_);
0057 
0058   rpctfetavalue[1] = ibooker.book1D("RPCTF_eta_value_bx0", "RPCTF eta value bx=0", 33, -16.5, 16.5);
0059   rpctfetavalue[2] = ibooker.book1D("RPCTF_eta_value_bx+", "RPCTF eta value bx>0", 33, -16.5, 16.5);
0060   rpctfetavalue[0] = ibooker.book1D("RPCTF_eta_value_bx-", "RPCTF eta value bx<0", 33, -16.5, 16.5);
0061 
0062   rpctfphivalue[1] = ibooker.book1D("RPCTF_phi_value_bx0", "RPCTF phi value bx=0", 144, -0.5, 143.5);
0063   rpctfphivalue[2] = ibooker.book1D("RPCTF_phi_value_bx+", "RPCTF phi value bx>0", 144, -0.5, 143.5);
0064   rpctfphivalue[0] = ibooker.book1D("RPCTF_phi_value_bx-", "RPCTF phi value bx<0", 144, -0.5, 143.5);
0065 
0066   rpctfptvalue[1] = ibooker.book1D("RPCTF_pt_value_bx0", "RPCTF pt value bx=0", 160, -0.5, 159.5);
0067   rpctfptvalue[2] = ibooker.book1D("RPCTF_pt_value_bx+", "RPCTF pt value bx>0", 160, -0.5, 159.5);
0068   rpctfptvalue[0] = ibooker.book1D("RPCTF_pt_value_bx-", "RPCTF pt value bx<0", 160, -0.5, 159.5);
0069 
0070   rpctfchargevalue[1] = ibooker.book1D("RPCTF_charge_value_bx0", "RPCTF charge value bx=0", 3, -1.5, 1.5);
0071   rpctfchargevalue[2] = ibooker.book1D("RPCTF_charge_value_bx+", "RPCTF charge value bx>0", 3, -1.5, 1.5);
0072   rpctfchargevalue[0] = ibooker.book1D("RPCTF_charge_value_bx-", "RPCTF charge value bx<01", 3, -1.5, 1.5);
0073 
0074   rpctfquality[1] = ibooker.book1D("RPCTF_quality", "RPCTF quality bx=0", 6, -0.5, 5.5);
0075   rpctfquality[2] = ibooker.book1D("RPCTF_quality_bx+", "RPCTF quality bx>0", 6, -0.5, 5.5);
0076   rpctfquality[0] = ibooker.book1D("RPCTF_quality_bx-", "RPCTF quality bx<0", 6, -0.5, 5.5);
0077 
0078   rpctfntrack_b[1] = ibooker.book1D("RPCTF_ntrack_brl_bx0", "RPCTF number of tracks - barrel, bx=0", 5, -0.5, 4.5);
0079   rpctfntrack_b[2] = ibooker.book1D("RPCTF_ntrack_brl_bx+", "RPCTF number of tracks - barrel, bx>0", 5, -0.5, 4.5);
0080   rpctfntrack_b[0] = ibooker.book1D("RPCTF_ntrack_brl_bx-", "RPCTF number of tracks - barrel, bx<0", 5, -0.5, 4.5);
0081 
0082   rpctfntrack_e[1] = ibooker.book1D("RPCTF_ntrack_fwd_bx0", "RPCTF number of tracks - endcap, bx=0", 5, -0.5, 4.5);
0083   rpctfntrack_e[2] = ibooker.book1D("RPCTF_ntrack_fwd_bx+", "RPCTF number of tracks - endcap, bx>0", 5, -0.5, 4.5);
0084   rpctfntrack_e[0] = ibooker.book1D("RPCTF_ntrack_fwd_bx-", "RPCTF number of tracks - endcap, bx<0", 5, -0.5, 4.5);
0085 
0086   m_qualVsEta[1] = ibooker.book2D("RPCTF_quality_vs_eta_bx0",
0087                                   "RPCTF quality vs eta, bx=0",
0088                                   33,
0089                                   -16.5,
0090                                   16.5,
0091                                   6,
0092                                   -0.5,
0093                                   5.5);  // Currently only 0...3 quals are possible
0094   m_qualVsEta[2] = ibooker.book2D("RPCTF_quality_vs_eta_bx+",
0095                                   "RPCTF quality vs eta, bx>0",
0096                                   33,
0097                                   -16.5,
0098                                   16.5,
0099                                   6,
0100                                   -0.5,
0101                                   5.5);  // Currently only 0...3 quals are possible
0102   m_qualVsEta[0] = ibooker.book2D("RPCTF_quality_vs_eta_bx-",
0103                                   "RPCTF quality vs eta, bx<0",
0104                                   33,
0105                                   -16.5,
0106                                   16.5,
0107                                   6,
0108                                   -0.5,
0109                                   5.5);  // Currently only 0...3 quals are possible
0110 
0111   m_muonsEtaPhi[1] =
0112       ibooker.book2D("RPCTF_muons_eta_phi_bx0", "RPCTF occupancy(eta,phi), bx=0", 33, -16.5, 16.5, 144, -0.5, 143.5);
0113   m_muonsEtaPhi[2] =
0114       ibooker.book2D("RPCTF_muons_eta_phi_bx+", "RPCTF occupancy(eta,phi), bx>0", 33, -16.5, 16.5, 144, -0.5, 143.5);
0115   m_muonsEtaPhi[0] =
0116       ibooker.book2D("RPCTF_muons_eta_phi_bx-", "RPCTF occupancy(eta,phi), bx<0", 33, -16.5, 16.5, 144, -0.5, 143.5);
0117 
0118   rpctfbx = ibooker.book1D("RPCTF_bx", "RPCTF bx distribiution", 7, -3.5, 3.5);
0119 
0120   //axis labels
0121   for (int l = 0; l < 3; ++l) {
0122     m_muonsEtaPhi[l]->setAxisTitle("tower", 1);
0123     m_qualVsEta[l]->setAxisTitle("tower");
0124     rpctfetavalue[l]->setAxisTitle("tower");
0125 
0126     m_muonsEtaPhi[l]->setAxisTitle("phi", 2);
0127     rpctfphivalue[l]->setAxisTitle("phi");
0128   }
0129 
0130   // set phi bin labels
0131   for (int i = 0; i < 12; ++i) {
0132     //float lPhi  = (30./360)*i*2*3.14;
0133     int lPhi = 30 * i;
0134     int lBin = int((30. / 360) * i * 144) + 1;
0135     std::stringstream ss;
0136     ss << "phi=" << lPhi;
0137     for (int l = 0; l < 3; ++l) {
0138       rpctfphivalue[l]->setBinLabel(lBin, ss.str());
0139       m_muonsEtaPhi[l]->setBinLabel(lBin, ss.str(), 2);
0140     }
0141   }
0142 
0143   /*
0144     // set TC numbers on phi axis
0145     for (int tc = 0; tc < 12 ; ++tc ){
0146       int lBin  = (tc*12+3+1)%144;
0147       std::stringstream ss;
0148       ss << "TC" <<tc;
0149       for (int l = 0; l<3; ++l){
0150         rpctfphivalue[l]->setBinLabel(lBin,ss.str());
0151         m_muonsEtaPhi[l]->setBinLabel(lBin,ss.str(), 2);
0152       }
0153   }*/
0154 
0155   // set eta bin labels
0156   for (int i = -16; i < 17; ++i) {
0157     std::stringstream ss;
0158     ss << i;
0159     for (int l = 0; l < 3; ++l) {
0160       rpctfetavalue[l]->setBinLabel(i + 17, ss.str());
0161       m_muonsEtaPhi[l]->setBinLabel(i + 17, ss.str(), 1);
0162       m_qualVsEta[l]->setBinLabel(i + 17, ss.str());
0163     }
0164   }
0165 
0166   m_bxDiff = ibooker.book1D("RPCTF_bx_diff", "RPCTrigger - bx difference", 12000, -.5, 11999.5);
0167 }
0168 
0169 void L1TRPCTF::analyze(const Event& e, const EventSetup& c) {
0170   nev_++;
0171   if (verbose_)
0172     cout << "L1TRPCTF: analyze...." << endl;
0173 
0174   edm::Handle<L1MuGMTReadoutCollection> pCollection;
0175   e.getByToken(rpctfSource_, pCollection);
0176 
0177   if (!pCollection.isValid()) {
0178     edm::LogInfo("DataNotFound") << "can't find L1MuGMTReadoutCollection";
0179     return;
0180   }
0181 
0182   L1MuGMTReadoutCollection const* gmtrc = pCollection.product();
0183   vector<L1MuGMTReadoutRecord> gmt_records = gmtrc->getRecords();
0184   vector<L1MuGMTReadoutRecord>::const_iterator RRItr;
0185 
0186   std::vector<int> nrpctftrack_b(3, 0);
0187   std::vector<int> nrpctftrack_e(3, 0);
0188 
0189   vector<L1TRPCTF::BxDelays> all_bxdelays;
0190 
0191   for (RRItr = gmt_records.begin(); RRItr != gmt_records.end(); RRItr++) {
0192     if (verbose_)
0193       cout << "Readout Record " << RRItr->getBxInEvent() << endl;
0194 
0195     vector<vector<L1MuRegionalCand> > brlAndFwdCands;
0196     brlAndFwdCands.push_back(RRItr->getBrlRPCCands());
0197     brlAndFwdCands.push_back(RRItr->getFwdRPCCands());
0198 
0199     int beIndex = 0;
0200     vector<vector<L1MuRegionalCand> >::iterator RPCTFCands = brlAndFwdCands.begin();
0201     for (; RPCTFCands != brlAndFwdCands.end(); ++RPCTFCands) {
0202       for (vector<L1MuRegionalCand>::const_iterator ECItr = RPCTFCands->begin(); ECItr != RPCTFCands->end(); ++ECItr) {
0203         int bxindex = 1;  // bx == 0
0204         if (ECItr->bx() > 0)
0205           bxindex = 2;
0206         if (ECItr->bx() < 0)
0207           bxindex = 0;
0208 
0209         if (!ECItr->empty()) {
0210           if (beIndex == 0)
0211             ++nrpctftrack_b[bxindex];
0212           if (beIndex == 1)
0213             ++nrpctftrack_e[bxindex];
0214 
0215           if (verbose_)
0216             cout << "RPCTFCand bx " << ECItr->bx() << endl;
0217 
0218           int tower = ECItr->eta_packed();
0219           if (tower > 16) {
0220             tower = -((~tower & 63) + 1);
0221           }
0222 
0223           rpctfbx->Fill(ECItr->bx());
0224 
0225           rpctfetavalue[bxindex]->Fill(tower);
0226           if (verbose_)
0227             cout << "\tRPCTFCand eta value " << ECItr->etaValue() << endl;
0228 
0229           rpctfphivalue[bxindex]->Fill(ECItr->phi_packed());
0230           if (verbose_)
0231             cout << "\tRPCTFCand phi value " << ECItr->phiValue() << endl;
0232 
0233           rpctfptvalue[bxindex]->Fill(ECItr->ptValue());
0234           if (verbose_)
0235             cout << "\tRPCTFCand pt value " << ECItr->ptValue() << endl;
0236 
0237           rpctfchargevalue[bxindex]->Fill(ECItr->chargeValue());
0238           if (verbose_)
0239             cout << "\tRPCTFCand charge value " << ECItr->chargeValue() << endl;
0240 
0241           rpctfquality[bxindex]->Fill(ECItr->quality());
0242           if (verbose_)
0243             cout << "\tRPCTFCand quality " << ECItr->quality() << endl;
0244 
0245           m_qualVsEta[bxindex]->Fill(tower, ECItr->quality());
0246           m_muonsEtaPhi[bxindex]->Fill(tower, ECItr->phi_packed());
0247 
0248           BxDelays bx_del;
0249           bx_del.bx = ECItr->bx();
0250           bx_del.eta_t = tower;
0251           bx_del.phi_p = ECItr->phi_packed();
0252           all_bxdelays.push_back(bx_del);
0253 
0254         }  // if !empty
0255       }    // end candidates iteration
0256       ++beIndex;
0257     }  // end brl/endcap iteration
0258   }    // end GMT records iteration
0259 
0260   for (int bxI = 0; bxI < 3; ++bxI) {
0261     rpctfntrack_b[bxI]->Fill(nrpctftrack_b[bxI]);
0262     rpctfntrack_e[bxI]->Fill(nrpctftrack_e[bxI]);
0263   }
0264 
0265   for (unsigned int i = 0; i < all_bxdelays.size(); i++) {
0266     int sector = ((all_bxdelays[i].phi_p + 142) % 144) / 12;
0267     if (sector > 11 || sector < 0)
0268       continue;
0269     int eta_tower = all_bxdelays[i].eta_t;
0270     for (unsigned int j = 0; j < all_bxdelays.size(); j++) {
0271       if (i == j)
0272         continue;
0273       int sector2 = ((all_bxdelays[j].phi_p + 142) % 144) / 12;
0274 
0275       int distance_cut = 1;
0276       int distance = ((sector + 12) - sector2) % 12;
0277       distance = min(distance, 11 - distance);
0278       if (distance < distance_cut)
0279         continue;
0280 
0281       int bxDiff = all_bxdelays[i].bx - all_bxdelays[j].bx;
0282       rpctfcratesynchro[sector]->Fill(bxDiff, eta_tower);
0283     }
0284   }
0285 
0286   while (m_globBX.begin() != m_globBX.end()) {
0287     long long int diff = *m_globBX.begin() - m_lastUsedBxInBxdiff;  // first entry will go to overflow bin, ignore
0288     m_bxDiff->Fill(diff);
0289     m_lastUsedBxInBxdiff = *m_globBX.begin();
0290     m_globBX.erase(m_globBX.begin());
0291   }
0292 
0293   if (verbose_)
0294     cout << "L1TRPCTF: end job...." << endl;
0295   LogInfo("EndJob") << "analyzed " << nev_ << " events";
0296 }