Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*
0002  * L1TdeCSCTF.cc v1.0
0003  * written by J. Gartner
0004  *
0005  * 2011.03.11 expanded by GP Di Giovanni
0006  * 
0007  * There is quality test allowing to check elements outside the
0008  * diagonal, so I need to add the 1D plot with all elements in the diagonal
0009  * in the first bin and all elements outside the diagonal in the second bin
0010  * 
0011  * In such way we can run the ContentsXRange quality test...
0012  */
0013 
0014 #include "DQM/L1TMonitor/interface/L1TdeCSCTF.h"
0015 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
0016 #include "CondFormats/DataRecord/interface/L1MuTriggerScalesRcd.h"
0017 #include <DataFormats/L1GlobalMuonTrigger/interface/L1MuRegionalCand.h>
0018 
0019 #include "CondFormats/L1TObjects/interface/L1MuTriggerScales.h"
0020 #include "CondFormats/DataRecord/interface/L1MuTriggerScalesRcd.h"
0021 #include "CondFormats/L1TObjects/interface/L1MuTriggerPtScale.h"
0022 #include "CondFormats/DataRecord/interface/L1MuTriggerPtScaleRcd.h"
0023 
0024 #include "DataFormats/L1CSCTrackFinder/interface/TrackStub.h"
0025 
0026 #include "DQMServices/Core/interface/DQMStore.h"
0027 
0028 #include "FWCore/Framework/interface/ESHandle.h"
0029 
0030 #include <iostream>
0031 #include <iomanip>
0032 #include <memory>
0033 
0034 using namespace std;
0035 using namespace edm;
0036 
0037 L1TdeCSCTF::L1TdeCSCTF(ParameterSet const& pset) {
0038   dataTrackProducer = consumes<L1CSCTrackCollection>(pset.getParameter<InputTag>("dataTrackProducer"));
0039   emulTrackProducer = consumes<L1CSCTrackCollection>(pset.getParameter<InputTag>("emulTrackProducer"));
0040   dataStubProducer = consumes<CSCTriggerContainer<csctf::TrackStub> >(pset.getParameter<InputTag>("dataStubProducer"));
0041   emulStubProducer = consumes<L1MuDTChambPhContainer>(pset.getParameter<InputTag>("emulStubProducer"));
0042 
0043   m_dirName = pset.getUntrackedParameter("DQMFolder", string("L1TEMU/CSCTFexpert"));
0044 
0045   ptLUTset = pset.getParameter<ParameterSet>("PTLUT");
0046 
0047   outFile = pset.getUntrackedParameter<string>("outFile", "");
0048   if (!outFile.empty()) {
0049     LogWarning("L1TdeCSCTF") << "L1T Monitoring histograms will be saved to " << outFile.c_str() << endl;
0050   }
0051 
0052   bool disable = pset.getUntrackedParameter<bool>("disableROOToutput", false);
0053   if (disable) {
0054     outFile = "";
0055   }
0056 
0057   /*bzero(srLUTs_, sizeof(srLUTs_));
0058     //int endcap =1, sector =1;
0059     bool TMB07=true;
0060     ParameterSet srLUTset;
0061     srLUTset.addUntrackedParameter<bool>("ReadLUTs", false);
0062     srLUTset.addUntrackedParameter<bool>("Binary",   false);
0063     srLUTset.addUntrackedParameter<string>("LUTPath", "./");
0064     for(int endcapItr = CSCDetId::minEndcapId(); endcapItr <= CSCDetId::maxEndcapId(); endcapItr++)
0065     {
0066         for(int sectorItr = CSCTriggerNumbering::minTriggerSectorId();sectorItr <= CSCTriggerNumbering::maxTriggerSectorId();sectorItr++)
0067         {
0068             for(int stationItr = 1; stationItr <= 4; stationItr++)
0069             {
0070                 if(stationItr == 1)
0071                 {
0072                     for(int subsectorItr = 0; subsectorItr < 2; subsectorItr++)
0073                     {
0074                         srLUTs_[endcapItr-1][sectorItr-1][subsectorItr] = new CSCSectorReceiverLUT(endcapItr, sectorItr, subsectorItr+1, stationItr, srLUTset, TMB07); 
0075                     }
0076                 } else {
0077                     srLUTs_[endcapItr-1][sectorItr-1][stationItr] = new CSCSectorReceiverLUT(endcapItr, sectorItr, 0, stationItr, srLUTset, TMB07); 
0078                 } //if for station 1 or 234
0079             } // stationItr loop
0080         } // sectorItr loop
0081     } // endcapItr loop
0082     */
0083   my_dtrc = std::make_unique<CSCTFDTReceiver>();
0084 }
0085 void L1TdeCSCTF::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const&, edm::EventSetup const&) {
0086   //Histograms booking
0087 
0088   /////////////////////////////
0089   // DQM Directory Structure //
0090   /////////////////////////////
0091 
0092   ibooker.setCurrentFolder(m_dirName);
0093 
0094   /////////////////////////////
0095   // Define Monitor Elements //
0096   /////////////////////////////
0097   //Monitor Elements for Pt Lut Address Field
0098   pt1Comp = ibooker.book2D("pt1Comp", "Hardware Vs. Emulator #Delta #phi_{12}", 256, 0, 256, 256, 0, 256);
0099   pt1Comp->setAxisTitle("Hardware #Delta #phi_{12}", 1);
0100   pt1Comp->setAxisTitle("Emulator #Delta #phi_{12}", 2);
0101   pt2Comp = ibooker.book2D("pt2Comp", "Hardware Vs. Emulator #Delta #phi_{23}", 16, 0, 16, 16, 0, 16);
0102   pt2Comp->setAxisTitle("Hardware #Delta #phi_{23}", 1);
0103   pt2Comp->setAxisTitle("Emulator #Delta #phi_{23}", 2);
0104   pt3Comp = ibooker.book2D("pt3Comp", "Hardware Vs. Emulator #eta", 16, 0, 16, 16, 0, 16);
0105   pt3Comp->setAxisTitle("Hardware #eta", 1);
0106   pt3Comp->setAxisTitle("Emulator #eta", 2);
0107   pt4Comp = ibooker.book2D("pt4Comp", "Hardware Vs. Emulator Mode", 19, 0, 19, 19, 0, 19);
0108   pt4Comp->setAxisTitle("Hardware Mode", 1);
0109   pt4Comp->setAxisTitle("Emulator Mode", 2);
0110   //Hardware Bin Titles
0111   pt4Comp->setBinLabel(1, "No Track", 1);
0112   pt4Comp->setBinLabel(2, "Bad Phi/Single", 1);
0113   pt4Comp->setBinLabel(3, "ME1-2-3", 1);
0114   pt4Comp->setBinLabel(4, "ME1-2-4", 1);
0115   pt4Comp->setBinLabel(5, "ME1-3-4", 1);
0116   pt4Comp->setBinLabel(6, "ME2-3-4", 1);
0117   pt4Comp->setBinLabel(7, "ME1-2", 1);
0118   pt4Comp->setBinLabel(8, "ME1-3", 1);
0119   pt4Comp->setBinLabel(9, "ME2-3", 1);
0120   pt4Comp->setBinLabel(10, "ME2-4", 1);
0121   pt4Comp->setBinLabel(11, "ME3-4", 1);
0122   pt4Comp->setBinLabel(12, "MB1-ME3", 1);
0123   pt4Comp->setBinLabel(13, "MB1-ME2", 1);
0124   pt4Comp->setBinLabel(14, "ME1-4", 1);
0125   pt4Comp->setBinLabel(15, "MB1-ME1", 1);
0126   pt4Comp->setBinLabel(16, "Halo Trigger", 1);
0127   pt4Comp->setBinLabel(17, "MB1-ME1-2", 1);
0128   pt4Comp->setBinLabel(18, "MB1-ME1-3", 1);
0129   pt4Comp->setBinLabel(19, "MB1-ME2-3", 1);
0130   //Emu Bin Titles
0131   pt4Comp->setBinLabel(1, "No Track", 2);
0132   pt4Comp->setBinLabel(2, "Bad Phi/Single", 2);
0133   pt4Comp->setBinLabel(3, "ME1-2-3", 2);
0134   pt4Comp->setBinLabel(4, "ME1-2-4", 2);
0135   pt4Comp->setBinLabel(5, "ME1-3-4", 2);
0136   pt4Comp->setBinLabel(6, "ME2-3-4", 2);
0137   pt4Comp->setBinLabel(7, "ME1-2", 2);
0138   pt4Comp->setBinLabel(8, "ME1-3", 2);
0139   pt4Comp->setBinLabel(9, "ME2-3", 2);
0140   pt4Comp->setBinLabel(10, "ME2-4", 2);
0141   pt4Comp->setBinLabel(11, "ME3-4", 2);
0142   pt4Comp->setBinLabel(12, "MB1-ME3", 2);
0143   pt4Comp->setBinLabel(13, "MB1-ME2", 2);
0144   pt4Comp->setBinLabel(14, "ME1-4", 2);
0145   pt4Comp->setBinLabel(15, "MB1-ME1", 2);
0146   pt4Comp->setBinLabel(16, "Halo Trigger", 2);
0147   pt4Comp->setBinLabel(17, "MB1-ME1-2", 2);
0148   pt4Comp->setBinLabel(18, "MB1-ME1-3", 2);
0149   pt4Comp->setBinLabel(19, "MB1-ME2-3", 2);
0150 
0151   pt5Comp = ibooker.book2D("pt5Comp", "Hardware Vs. Emulator Sign, FR", 4, 0, 4, 4, 0, 4);
0152   pt5Comp->setAxisTitle("Hardware Sign<<1|FR", 1);
0153   pt5Comp->setAxisTitle("Emulator Sign<<1|FR", 2);
0154 
0155   //Monitor Elements for track variables
0156   phiComp = ibooker.book2D("phiComp", "Hardware Vs. Emulator Track #phi", 32, 0, 32, 32, 0, 32);
0157   phiComp->setAxisTitle("Hardware #phi", 1);
0158   phiComp->setAxisTitle("Emulator #phi", 2);
0159   etaComp = ibooker.book2D("etaComp", "Hardware Vs. Emulator Track #eta", 32, 0, 32, 32, 0, 32);
0160   etaComp->setAxisTitle("Hardware #eta", 1);
0161   etaComp->setAxisTitle("Emulator #eta", 2);
0162   occComp = ibooker.book2D("occComp", "Hardware Vs. Emulator Track Occupancy", 5, 0, 5, 5, 0, 5);
0163   occComp->setAxisTitle("Hardware Occupancy", 1);
0164   occComp->setAxisTitle("Emulator Occupancy", 2);
0165   ptComp = ibooker.book2D("ptComp", "Hardware Vs. Emulator Pt", 32, 0, 32, 32, 0, 32);
0166   ptComp->setAxisTitle("Hardware P_{t}", 1);
0167   ptComp->setAxisTitle("Emulator P_{t}", 2);
0168   qualComp = ibooker.book2D("qualComp", "Hardware Vs. Emulator Quality", 4, 0, 4, 4, 0, 4);
0169   qualComp->setAxisTitle("Hardware Quality", 1);
0170   qualComp->setAxisTitle("Emulator Quality", 2);
0171 
0172   //Monitor Elemens for Dt Stubs
0173   dtStubPhi = ibooker.book2D("dtStubPhi", "Hardware Vs. Emulator DT Stub #phi", 200, 400, 2400, 200, 400, 2400);
0174   dtStubPhi->setAxisTitle("Hardware Stub #phi", 1);
0175   dtStubPhi->setAxisTitle("Emulator Stub #phi", 2);
0176   badDtStubSector = ibooker.book2D("badDtStubSector", "Dt Sector for bad Dt stub #phi", 6, 1, 7, 2, 1, 3);
0177   badDtStubSector->setAxisTitle("Dt stub sector, subsector", 1);
0178   badDtStubSector->setAxisTitle("Dt Stub Endcap", 2);
0179 
0180   //***********************************//
0181   //* F O R   Q U A L I T Y   T E S T *//
0182   //***********************************//
0183   //1D plots for the quality test
0184   //Monitor Elements for Pt Lut Address Field
0185   pt1Comp_1d = ibooker.book1D("pt1Comp_1d", "Hardware Vs. Emulator #Delta #phi_{12}", 2, 0, 2);
0186   pt1Comp_1d->setAxisTitle("#Delta #phi_{12}", 1);
0187   pt1Comp_1d->setBinLabel(1, "Agree", 1);
0188   pt1Comp_1d->setBinLabel(2, "Disagree", 1);
0189 
0190   pt2Comp_1d = ibooker.book1D("pt2Comp_1d", "Hardware Vs. Emulator #Delta #phi_{23}", 2, 0, 2);
0191   pt2Comp_1d->setAxisTitle("#Delta #phi_{23}", 1);
0192   pt2Comp_1d->setBinLabel(1, "Agree", 1);
0193   pt2Comp_1d->setBinLabel(2, "Disagree", 1);
0194 
0195   pt3Comp_1d = ibooker.book1D("pt3Comp_1d", "Hardware Vs. Emulator #eta", 2, 0, 2);
0196   pt3Comp_1d->setAxisTitle("#eta", 1);
0197   pt3Comp_1d->setBinLabel(1, "Agree", 1);
0198   pt3Comp_1d->setBinLabel(2, "Disagree", 1);
0199 
0200   pt4Comp_1d = ibooker.book1D("pt4Comp_1d", "Hardware Vs. Emulator Mode", 2, 0, 2);
0201   pt4Comp_1d->setAxisTitle("Mode", 1);
0202   pt4Comp_1d->setBinLabel(1, "Agree", 1);
0203   pt4Comp_1d->setBinLabel(2, "Disagree", 1);
0204 
0205   pt5Comp_1d = ibooker.book1D("pt5Comp_1d", "Hardware Vs. Emulator Sign, FR", 2, 0, 2);
0206   pt5Comp_1d->setAxisTitle("Sign<<1|FR", 1);
0207   pt5Comp_1d->setBinLabel(1, "Agree", 1);
0208   pt5Comp_1d->setBinLabel(2, "Disagree", 1);
0209 
0210   //Monitor Elements for track variables
0211   phiComp_1d = ibooker.book1D("phiComp_1d", "Hardware Vs. Emulator Track #phi", 2, 0, 2);
0212   phiComp_1d->setAxisTitle("#phi", 1);
0213   phiComp_1d->setBinLabel(1, "Agree", 1);
0214   phiComp_1d->setBinLabel(2, "Disagree", 1);
0215 
0216   etaComp_1d = ibooker.book1D("etaComp_1d", "Hardware Vs. Emulator Track #eta", 2, 0, 2);
0217   etaComp_1d->setAxisTitle("#eta", 1);
0218   etaComp_1d->setBinLabel(1, "Agree", 1);
0219   etaComp_1d->setBinLabel(2, "Disagree", 1);
0220 
0221   occComp_1d = ibooker.book1D("occComp_1d", "Hardware Vs. Emulator Track Occupancy", 2, 0, 2);
0222   occComp_1d->setAxisTitle("Occupancy", 1);
0223   occComp_1d->setBinLabel(1, "Agree", 1);
0224   occComp_1d->setBinLabel(2, "Disagree", 1);
0225 
0226   ptComp_1d = ibooker.book1D("ptComp_1d", "Hardware Vs. Emulator Pt", 2, 0, 2);
0227   ptComp_1d->setAxisTitle("P_{t}", 1);
0228   ptComp_1d->setBinLabel(1, "Agree", 1);
0229   ptComp_1d->setBinLabel(2, "Disagree", 1);
0230 
0231   qualComp_1d = ibooker.book1D("qualComp_1d", "Hardware Vs. Emulator Quality", 2, 0, 2);
0232   qualComp_1d->setAxisTitle("Quality", 1);
0233   qualComp_1d->setBinLabel(1, "Agree", 1);
0234   qualComp_1d->setBinLabel(2, "Disagree", 1);
0235 
0236   //Monitor Elemens for Dt Stubs
0237   dtStubPhi_1d = ibooker.book1D("dtStubPhi_1d", "Hardware Vs. Emulator DT Stub #phi", 2, 0, 2);
0238   dtStubPhi_1d->setAxisTitle("DT Stub #phi", 1);
0239   dtStubPhi_1d->setBinLabel(1, "Agree", 1);
0240   dtStubPhi_1d->setBinLabel(2, "Disagree", 1);
0241 }
0242 
0243 void L1TdeCSCTF::analyze(Event const& e, EventSetup const& es) {
0244   // Initialize Arrays
0245   ////////////////////
0246   unsigned int nDataMuons = 0;
0247   unsigned int nEmulMuons = 0;
0248   int dataMuonArray[8][10], emuMuonArray[8][10];
0249   for (int muon = 0; muon < 8; muon++) {
0250     for (int par = 0; par < 3; par++) {
0251       dataMuonArray[muon][par] = 0;
0252       emuMuonArray[muon][par] = 0;
0253     }
0254     emuMuonArray[muon][3] = -1;
0255     dataMuonArray[muon][3] = -1;
0256 
0257     emuMuonArray[muon][4] = 7;
0258     dataMuonArray[muon][4] = 7;
0259 
0260     for (int par2 = 5; par2 < 10; par2++) {
0261       emuMuonArray[muon][par2] = -1;
0262       dataMuonArray[muon][par2] = -1;
0263     }
0264   }
0265   // Get Hardware information, and check output of PtLUT
0266   //////////////////////////////////////////////////////
0267   if (!dataTrackProducer.isUninitialized()) {
0268     Handle<L1CSCTrackCollection> tracks;
0269     e.getByToken(dataTrackProducer, tracks);
0270 
0271     // check validity of input collection
0272     if (!tracks.isValid()) {
0273       LogWarning("L1TdeCSCTF") << "\n No valid [data tracks] product found: "
0274                                << " L1CSCTrackCollection" << endl;
0275       return;
0276     }
0277 
0278     for (L1CSCTrackCollection::const_iterator trk = tracks.product()->begin(); trk != tracks.product()->end(); trk++) {
0279       if (nDataMuons >= 8)
0280         break;
0281       if ((trk->first.BX() < 2) && (trk->first.BX() > -1)) {
0282         //int mOdE = (trk->first.ptLUTAddress()>>16)&0xf;
0283         //cout << "D->Mode: " << mOdE << ", Rank " << trk->first.rank() << endl;
0284         dataMuonArray[nDataMuons][0] = trk->first.ptLUTAddress();
0285         dataMuonArray[nDataMuons][1] = trk->first.sector();
0286         dataMuonArray[nDataMuons][2] = trk->first.endcap();
0287         dataMuonArray[nDataMuons][8] = trk->first.outputLink();
0288         dataMuonArray[nDataMuons][4] = trk->first.BX();
0289         dataMuonArray[nDataMuons][5] = trk->first.rank();
0290         dataMuonArray[nDataMuons][6] = trk->first.localPhi();
0291         dataMuonArray[nDataMuons][7] = trk->first.eta_packed();
0292         dataMuonArray[nDataMuons][9] = trk->first.modeExtended();
0293         nDataMuons++;
0294       }
0295     }
0296   }
0297   // Get Emulator information
0298   ///////////////////////////
0299   if (!emulTrackProducer.isUninitialized()) {
0300     Handle<L1CSCTrackCollection> tracks;
0301     e.getByToken(emulTrackProducer, tracks);
0302 
0303     // check validity of input collection
0304     if (!tracks.isValid()) {
0305       LogWarning("L1TdeCSCTF") << "\n No valid [emulator tracks] product found: "
0306                                << " L1CSCTrackCollection" << endl;
0307       return;
0308     }
0309 
0310     for (L1CSCTrackCollection::const_iterator trk = tracks.product()->begin(); trk != tracks.product()->end(); trk++) {
0311       if (nEmulMuons >= 8)
0312         break;
0313       if ((trk->first.BX() < 2) && (trk->first.BX() > -1)) {
0314         //int mOdE = (trk->first.ptLUTAddress()>>16)&0xf;
0315         //cout << "E->Mode: " << mOdE << ", Rank " << trk->first.rank() << endl;
0316         emuMuonArray[nEmulMuons][0] = trk->first.ptLUTAddress();
0317         emuMuonArray[nEmulMuons][1] = trk->first.sector();
0318         emuMuonArray[nEmulMuons][2] = trk->first.endcap();
0319         emuMuonArray[nEmulMuons][4] = trk->first.BX();
0320         emuMuonArray[nEmulMuons][5] = trk->first.rank();
0321         emuMuonArray[nEmulMuons][6] = trk->first.localPhi();
0322         emuMuonArray[nEmulMuons][7] = trk->first.eta_packed();
0323         emuMuonArray[nEmulMuons][9] = trk->first.modeExtended();
0324         nEmulMuons++;
0325       }
0326     }
0327   }
0328   //Fill Occupancy M.E.
0329   if ((nDataMuons != 0) || (nEmulMuons != 0)) {
0330     occComp->Fill(nDataMuons, nEmulMuons);
0331     (nDataMuons == nEmulMuons) ? occComp_1d->Fill(0) : occComp_1d->Fill(1);
0332   }
0333   // Match Tracks by sector & mode in the case of multiple tracks
0334   ///////////////////////////////////////////////////////////////
0335   if (nDataMuons == nEmulMuons) {
0336     //First, find EXACT address matches in a given sector, endcap
0337     for (unsigned int mu1 = 0; mu1 < nDataMuons; mu1++) {
0338       for (unsigned int mu2 = 0; mu2 < nEmulMuons; mu2++)
0339         if ((emuMuonArray[mu2][1] == dataMuonArray[mu1][1]) && (emuMuonArray[mu2][2] == dataMuonArray[mu1][2])) {
0340           if (emuMuonArray[mu2][0] == dataMuonArray[mu1][0]) {
0341             emuMuonArray[mu2][3] = mu1;
0342             dataMuonArray[mu1][3] = 1;
0343           }
0344         }
0345     }
0346     //Next, try to match unmapped
0347     for (unsigned int c2a = 0; c2a < nEmulMuons; c2a++) {
0348       if (emuMuonArray[c2a][3] == -1) {
0349         for (unsigned int cor_a = 0; cor_a < nDataMuons; cor_a++) {
0350           if ((dataMuonArray[cor_a][1] == emuMuonArray[c2a][1]) &&
0351               (dataMuonArray[cor_a][2] == emuMuonArray[c2a][2]))  // && (dataMuonArray[cor_a][3]==-1))
0352           {
0353             emuMuonArray[c2a][3] = cor_a;
0354             dataMuonArray[cor_a][3] = 1;
0355           }
0356         }
0357       }
0358     }
0359     //Check that a single emulator track is not mapped to multiple data tracks
0360     bool multiMap = false;
0361     if (nEmulMuons > 1) {
0362       for (unsigned int c1a = 0; c1a < (nEmulMuons - 1); c1a++) {
0363         for (unsigned int c1b = (c1a + 1); c1b < nEmulMuons; c1b++) {
0364           if (emuMuonArray[c1a][3] == emuMuonArray[c1b][3]) {
0365             //cout << "Error: Multiple Emulator Muons Mapped to the same Data Muon." << endl;
0366             multiMap = true;
0367             break;
0368           }
0369         }
0370         if (multiMap)
0371           break;
0372       }
0373     }
0374     //Fill histograms based on matched Tracks
0375     for (unsigned int mu3 = 0; mu3 < nEmulMuons; mu3++) {
0376       int mapping = emuMuonArray[mu3][3];
0377       if ((mapping != -1) && (multiMap == false)) {
0378         //Decode LUT Address for more meaningful comparison
0379         int emuPhi12 = (0x0000ff & emuMuonArray[mu3][0]);
0380         int datPhi12 = (0x0000ff & dataMuonArray[mapping][0]);
0381         int emuPhi23 = (0x000f00 & emuMuonArray[mu3][0]) >> 8;
0382         int datPhi23 = (0x000f00 & dataMuonArray[mapping][0]) >> 8;
0383         int emuEta = (0x00f000 & emuMuonArray[mu3][0]) >> 12;
0384         int datEta = (0x00f000 & dataMuonArray[mapping][0]) >> 12;
0385         //int emuMode = (0x0f0000 & emuMuonArray[mu3][0])>>16;
0386         //int datMode = (0x0f0000 & dataMuonArray[mapping][0])>>16;
0387         int emuFrSin = (0xf00000 & emuMuonArray[mu3][0]) >> 20;
0388         int datFrSin = (0xf00000 & dataMuonArray[mapping][0]) >> 20;
0389         //Decode Rank for more meaningful comparison
0390         int emuQual = emuMuonArray[mu3][5] >> 5;
0391         int datQual = dataMuonArray[mapping][5] >> 5;
0392         int emuPt = 0x1f & emuMuonArray[mu3][5];
0393         int datPt = 0x1f & dataMuonArray[mapping][5];
0394         int emuModeExtended = emuMuonArray[mu3][9];
0395         int datModeExtended = dataMuonArray[mapping][9];
0396 
0397         //Fill mode M.E., one of (the most important) PtLUT address field
0398         pt4Comp->Fill(datModeExtended, emuModeExtended);
0399         (datModeExtended == emuModeExtended) ? pt4Comp_1d->Fill(0) : pt4Comp_1d->Fill(1);
0400         //To disentagle problems, only fill histograms if mode matches
0401         if (emuModeExtended == datModeExtended) {
0402           //Fill Pt LUT address field M.E.
0403           pt1Comp->Fill(datPhi12, emuPhi12);
0404           (datPhi12 == emuPhi12) ? pt1Comp_1d->Fill(0) : pt1Comp_1d->Fill(1);
0405           pt2Comp->Fill(datPhi23, emuPhi23);
0406           (datPhi23 == emuPhi23) ? pt2Comp_1d->Fill(0) : pt2Comp_1d->Fill(1);
0407           pt3Comp->Fill(datEta, emuEta);
0408           (datEta == emuEta) ? pt3Comp_1d->Fill(0) : pt3Comp_1d->Fill(1);
0409           pt5Comp->Fill(datFrSin, emuFrSin);
0410           (datFrSin == emuFrSin) ? pt5Comp_1d->Fill(0) : pt5Comp_1d->Fill(1);
0411           //Fill Track value M.E.
0412           if (dataMuonArray[mapping][8] == 1)  //Rank Comparison available for Link 1 only due to readout limitation
0413           {
0414             ptComp->Fill(datPt, emuPt);
0415             (datPt == emuPt) ? ptComp_1d->Fill(0) : ptComp_1d->Fill(1);
0416             qualComp->Fill(datQual, emuQual);
0417             (datQual == emuQual) ? qualComp_1d->Fill(0) : qualComp_1d->Fill(1);
0418           }
0419           phiComp->Fill(dataMuonArray[mapping][6], emuMuonArray[mu3][6]);
0420           etaComp->Fill(dataMuonArray[mapping][7], emuMuonArray[mu3][7]);
0421 
0422           (dataMuonArray[mapping][6] == emuMuonArray[mu3][6]) ? phiComp_1d->Fill(0) : phiComp_1d->Fill(1);
0423           (dataMuonArray[mapping][7] == emuMuonArray[mu3][7]) ? etaComp_1d->Fill(0) : etaComp_1d->Fill(1);
0424         }
0425       }
0426     }
0427   }
0428 
0429   //Compare DT stubs to check transmission quality
0430   ////////////////////////////////////////////////
0431   //Declare arrays, initialize
0432   int eDtStub[7][15];
0433   int dDtStub[8][15];
0434   int eDtCounter = 0;
0435   int dDtCounter = 0;
0436   for (int dJ = 0; dJ < 7; dJ++) {
0437     for (int dK = 0; dK < 15; dK++) {
0438       eDtStub[dJ][dK] = -55;
0439       dDtStub[dJ][dK] = -55;
0440       dDtStub[7][dK] = -55;
0441     }
0442   }
0443 
0444   // Get Daq Recorded Stub Information
0445   if (!dataStubProducer.isUninitialized()) {
0446     Handle<CSCTriggerContainer<csctf::TrackStub> > dtTrig;
0447     e.getByToken(dataStubProducer, dtTrig);
0448     // check validity of input collection
0449     if (!dtTrig.isValid()) {
0450       LogWarning("L1TdeCSCTF") << "\n No valid [Data Stubs] product found: "
0451                                << " L1CSCTrackCollection" << endl;
0452       return;
0453     }
0454     const CSCTriggerContainer<csctf::TrackStub>* dt_stubs = dtTrig.product();
0455     CSCTriggerContainer<csctf::TrackStub> stub_list;
0456     stub_list.push_many(*dt_stubs);
0457     vector<csctf::TrackStub> stuList = stub_list.get();
0458     vector<csctf::TrackStub>::const_iterator stu = stuList.begin();
0459     for (; stu != stuList.end(); stu++) {
0460       if (dDtCounter >= 15)
0461         break;
0462       if ((stu->BX() > 4) && (stu->BX() < 9)) {
0463         dDtStub[0][dDtCounter] = stu->phiPacked();
0464         dDtStub[1][dDtCounter] = stu->getQuality();
0465         dDtStub[2][dDtCounter] = stu->endcap();
0466         dDtStub[3][dDtCounter] = stu->sector();
0467         dDtStub[4][dDtCounter] = stu->subsector();
0468         dDtCounter++;
0469       }
0470     }
0471   }
0472 
0473   // Get Daq Recorded Stub Information
0474   if (!emulStubProducer.isUninitialized()) {
0475     // Get Emulated Stub Information
0476     Handle<L1MuDTChambPhContainer> pCon;
0477     e.getByToken(emulStubProducer, pCon);
0478     // check validity of input collection
0479     if (!pCon.isValid()) {
0480       LogWarning("L1TdeCSCTF") << "\n No valid [Data Stubs] product found: "
0481                                << " L1CSCTrackCollection" << endl;
0482       return;
0483     }
0484     CSCTriggerContainer<csctf::TrackStub> emulStub = my_dtrc->process(pCon.product());
0485     vector<csctf::TrackStub> emuList = emulStub.get();
0486     vector<csctf::TrackStub>::const_iterator eStu = emuList.begin();
0487     for (; eStu != emuList.end(); eStu++) {
0488       if (eDtCounter >= 15)
0489         break;
0490       if ((eStu->BX() > 4) && (eStu->BX() < 9)) {
0491         eDtStub[0][eDtCounter] = eStu->phiPacked();
0492         eDtStub[1][eDtCounter] = eStu->getQuality();
0493         eDtStub[2][eDtCounter] = eStu->endcap();
0494         eDtStub[3][eDtCounter] = eStu->sector();
0495         eDtStub[4][eDtCounter] = eStu->subsector();
0496         eDtCounter++;
0497       }
0498     }
0499   }
0500 
0501   //cout << "Num Tracks match eDtCounter: " << eDtCounter << ", dDt: " << dDtCounter << endl;
0502   //First find perfect matches
0503   for (int eS = 0; eS < eDtCounter; eS++) {
0504     //cout << "es Loop" <<  endl;
0505     for (int dS = 0; dS < dDtCounter; dS++) {
0506       //cout << "ds Loop" << endl;
0507       if (eDtStub[2][eS] == dDtStub[2][dS]) {
0508         //cout << "end match" << endl;
0509         if (eDtStub[3][eS] == dDtStub[3][dS]) {
0510           //cout << "sec match" << endl;
0511           if (eDtStub[4][eS] == dDtStub[4][dS]) {
0512             //cout << "First match loop, eS: " << eS << ", dS" << dS << endl;
0513             if ((eDtStub[0][eS] == dDtStub[0][dS]) && (eDtStub[1][eS] == dDtStub[1][dS]) && (eDtStub[6][eS] != 1) &&
0514                 (dDtStub[6][dS] != 1)) {
0515               //cout << "Passed fist matching." << endl;
0516               eDtStub[5][eS] = dS;
0517               eDtStub[6][eS] = 1;
0518               dDtStub[5][dS] = eS;
0519               dDtStub[6][dS] = 1;
0520             }
0521           }
0522         }
0523       }
0524     }
0525   }
0526 
0527   //Now find imperfect matches
0528   for (int eS2 = 0; eS2 < eDtCounter; eS2++) {
0529     for (int dS2 = 0; dS2 < dDtCounter; dS2++) {
0530       //cout << "1: " << eDtStub[2][eS2] << ", " << dDtStub[2][dS2] << ", " << eDtStub[3][eS2] << ", " << dDtStub[3][dS2] << ", " << eDtStub[4][eS2] << ", " << dDtStub[4][dS2] << endl;
0531       if ((eDtStub[2][eS2] == dDtStub[2][dS2]) && (eDtStub[3][eS2] == dDtStub[3][dS2]) &&
0532           (eDtStub[4][eS2] == dDtStub[4][dS2])) {
0533         //cout << "2: " << dDtStub[7][eS2] << ", " << dDtStub[7][dS2] << ", " << abs(eDtStub[0][eS2]-dDtStub[0][dS2]) << ", " << ", " << eDtStub[6][eS2] << ", " << dDtStub[6][dS2] << endl;
0534         if (((dDtStub[7][eS2] == -55) || (dDtStub[7][dS2] > (abs(eDtStub[0][eS2] - dDtStub[0][dS2])))) &&
0535             (eDtStub[6][eS2] != 1) && (dDtStub[6][dS2] != 1)) {
0536           //cout << "Imperfect match found" << endl;
0537           dDtStub[5][dS2] = eS2;
0538           dDtStub[6][dS2] = 2;
0539           eDtStub[5][eS2] = dS2;
0540           eDtStub[6][eS2] = 2;
0541           dDtStub[7][dS2] = abs(eDtStub[0][eS2] - dDtStub[0][dS2]);
0542         }
0543       }
0544     }
0545   }
0546 
0547   //Debug time!
0548   bool dtSMulti = false;
0549   int dtUnmap = 0;
0550   if (eDtCounter > 1)
0551     for (int eS3a = 0; eS3a < eDtCounter - 1; eS3a++)
0552       for (int eS3b = eS3a + 1; eS3b < eDtCounter; eS3b++) {
0553         if (eDtStub[5][eS3a] == eDtStub[5][eS3b])
0554           dtSMulti = true;
0555         if (eDtStub[5][eS3a] == -55 || eDtStub[5][eS3b] == -55)
0556           dtUnmap++;
0557       }
0558 
0559   if (dDtCounter > 1)
0560     for (int dS3a = 0; dS3a < dDtCounter - 1; dS3a++)
0561       for (int dS3b = dS3a + 1; dS3b < dDtCounter; dS3b++) {
0562         if (dDtStub[5][dS3a] == dDtStub[5][dS3b])
0563           dtSMulti = true;
0564         if (dDtStub[5][dS3a] == -55 || dDtStub[5][dS3b] == -55)
0565           dtUnmap++;
0566       }
0567   /*if(dtSMulti==true)
0568         cout << "Multiple DT stubs mapped to the same stub" << endl;
0569     if(dtUnmap!=0)
0570         cout << "Unmapped DT stubs:" << dtUnmap << endl;*/
0571 
0572   if (dtSMulti == false && dtUnmap == 0) {
0573     for (int phil = 0; phil < eDtCounter; phil++) {
0574       if (eDtStub[6][phil] == 1 || eDtStub[6][phil] == 2) {
0575         int indexFil = eDtStub[3][phil] * 2 + eDtStub[4][phil] - 1;
0576         dtStubPhi->Fill(eDtStub[0][phil], dDtStub[0][eDtStub[5][phil]]);
0577         (eDtStub[0][phil] == dDtStub[0][eDtStub[5][phil]]) ? dtStubPhi_1d->Fill(0) : dtStubPhi_1d->Fill(1);
0578         if (eDtStub[0][phil] != dDtStub[0][eDtStub[5][phil]])
0579           badDtStubSector->Fill(indexFil, eDtStub[2][phil]);
0580       }
0581     }
0582   }
0583 }