CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/L1TMonitor/src/L1TdeCSCTF.cc

Go to the documentation of this file.
00001 /*
00002  * L1TdeCSCTF.cc v1.0
00003  * written by J. Gartner
00004  */
00005  
00006 #include "DQM/L1TMonitor/interface/L1TdeCSCTF.h"
00007 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
00008 #include "DataFormats/L1CSCTrackFinder/interface/L1CSCTrackCollection.h"
00009 #include "CondFormats/DataRecord/interface/L1MuTriggerScalesRcd.h"
00010 #include <DataFormats/L1CSCTrackFinder/interface/CSCTriggerContainer.h>
00011 #include <DataFormats/L1GlobalMuonTrigger/interface/L1MuRegionalCand.h>
00012 
00013 #include "CondFormats/L1TObjects/interface/L1MuTriggerScales.h"
00014 #include "CondFormats/DataRecord/interface/L1MuTriggerScalesRcd.h"
00015 #include "CondFormats/L1TObjects/interface/L1MuTriggerPtScale.h"
00016 #include "CondFormats/DataRecord/interface/L1MuTriggerPtScaleRcd.h"
00017 
00018 #include "DQMServices/Core/interface/DQMStore.h"
00019 
00020 #include "FWCore/Framework/interface/ESHandle.h"
00021 #include "FWCore/Framework/interface/MakerMacros.h"
00022 
00023 #include <iostream>
00024 #include <iomanip>
00025 #include <memory>
00026 
00027 
00028 using namespace std;
00029 using namespace edm;
00030 
00031 L1TdeCSCTF::L1TdeCSCTF(edm::ParameterSet const& pset):edm::EDAnalyzer(){
00032         dataTrackProducer = pset.getParameter<edm::InputTag>("dataTrackProducer");
00033         emulTrackProducer = pset.getParameter<edm::InputTag>("emulTrackProducer");
00034         lctProducer       = pset.getParameter<edm::InputTag>("lctProducer");
00035         
00036         m_dirName         = pset.getUntrackedParameter("DQMFolder", 
00037                              std::string("L1TEMU/CSCTFexpert"));
00038 
00039         ts=0;
00040         eventNum = 0;
00041         
00042         ptLUTset = pset.getParameter<edm::ParameterSet>("PTLUT");
00043         
00044         dbe = NULL;
00045         if(pset.getUntrackedParameter<bool>("DQMStore", false) )
00046         {
00047                 dbe = Service<DQMStore>().operator->();
00048                 dbe->setVerbose(0);
00049                 dbe->setCurrentFolder(m_dirName);
00050         }
00051         
00052         outFile = pset.getUntrackedParameter<string>("outFile", "");
00053         if( outFile.size() != 0 )
00054         {
00055           edm::LogWarning("L1TdeCSCTF")
00056             << "L1T Monitoring histograms will be saved to " 
00057             << outFile.c_str() 
00058             << endl;
00059         }
00060         
00061         bool disable = pset. getUntrackedParameter<bool>("disableROOToutput", false);
00062         if(disable){
00063                 outFile="";
00064         }
00065         
00066         bzero(srLUTs_, sizeof(srLUTs_));
00067         //int endcap =1, sector =1;
00068         bool TMB07=true;
00069         edm::ParameterSet srLUTset;
00070         srLUTset.addUntrackedParameter<bool>("ReadLUTs", false);
00071         srLUTset.addUntrackedParameter<bool>("Binary",   false);
00072         srLUTset.addUntrackedParameter<std::string>("LUTPath", "./");
00073         for(int endcapItr = CSCDetId::minEndcapId(); endcapItr <= CSCDetId::maxEndcapId(); endcapItr++)
00074         {
00075                 for(int sectorItr = CSCTriggerNumbering::minTriggerSectorId();sectorItr <= CSCTriggerNumbering::maxTriggerSectorId();sectorItr++)
00076         {
00077                         for(int stationItr = 1; stationItr <= 4; stationItr++)
00078                 {
00079                         if(stationItr == 1)
00080                         {
00081                                         for(int subsectorItr = 0; subsectorItr < 2; subsectorItr++)
00082                                         {
00083                                         srLUTs_[endcapItr-1][sectorItr-1][subsectorItr] = new CSCSectorReceiverLUT(endcapItr, sectorItr, subsectorItr+1, stationItr, srLUTset, TMB07); 
00084                                 }
00085                         } else {
00086                                         srLUTs_[endcapItr-1][sectorItr-1][stationItr] = new CSCSectorReceiverLUT(endcapItr, sectorItr, 0, stationItr, srLUTset, TMB07); 
00087                         } //if for station 1 or 234
00088                 } // stationItr loop
00089                 } // sectorItr loop
00090         } // endcapItr loop
00091 }
00092 
00093 void L1TdeCSCTF::beginJob()
00094 {
00095 
00096 
00098         // DQM Directory Structure //
00100         DQMStore * dbe = 0;
00101         dbe = Service<DQMStore>().operator->();
00102         if( dbe ){
00103                 dbe->setCurrentFolder(m_dirName);
00105                 // Define Monitor Elements //
00107 
00108                 
00109                 pt1Comp = dbe->book2D("pt1Comp","Hardware Vs. Emulator #Delta #phi_{12}",256,0,256,256,0,256);
00110                 pt1Comp->setAxisTitle("Hardware #Delta #phi_{12}",1);
00111                 pt1Comp->setAxisTitle("Emulator #Delta #phi_{12}",2);
00112                 pt2Comp = dbe->book2D("pt2Comp","Hardware Vs. Emulator #Delta #phi_{23}",16,0,16,16,0,16);
00113                 pt2Comp->setAxisTitle("Hardware #Delta #phi_{23}",1);
00114                 pt2Comp->setAxisTitle("Emulator #Delta #phi_{23}",2);
00115                 pt3Comp = dbe->book2D("pt3Comp","Hardware Vs. Emulator #eta",16,0,16,16,0,16);
00116                 pt3Comp->setAxisTitle("Hardware #eta",1);
00117                 pt3Comp->setAxisTitle("Emulator #eta",2);
00118                 pt4Comp = dbe->book2D("pt4Comp","Hardware Vs. Emulator Mode",16,0,16,16,0,16);
00119                 pt4Comp->setAxisTitle("Hardware Mode",1);
00120                 pt4Comp->setAxisTitle("Emulator Mode",2);
00121                 pt5Comp = dbe->book2D("pt5Comp","Hardware Vs. Emulator Sign",2,0,2,2,0,2);
00122                 pt5Comp->setAxisTitle("Hardware Sign",1);
00123                 pt5Comp->setAxisTitle("Emulator Sign",2);
00124                 pt6Comp = dbe->book2D("pt6Comp","Hardware Vs. Emulator FR bit",2,0,2,2,0,2);
00125                 pt6Comp->setAxisTitle("Hardware FR bit",1);
00126                 pt6Comp->setAxisTitle("Emulator FR bit",2);
00127                 
00128                 badBitMode1 = dbe->book1D("badBitMode1","P_{t} LUT address bit differences, emulator mode 1", 21,0,21);
00129                 badBitMode1->setAxisTitle("P_{t} Address Bit",1);
00130                 badBitMode2 = dbe->book1D("badBitMode2","P_{t} LUT address bit differences, emulator mode 2", 21,0,21);
00131                 badBitMode2->setAxisTitle("P_{t} Address Bit",1);
00132                 badBitMode3 = dbe->book1D("badBitMode3","P_{t} LUT address bit differences, emulator mode 3", 21,0,21);
00133                 badBitMode3->setAxisTitle("P_{t} Address Bit",1);
00134                 badBitMode4 = dbe->book1D("badBitMode4","P_{t} LUT address bit differences, emulator mode 4", 21,0,21);
00135                 badBitMode4->setAxisTitle("P_{t} Address Bit",1);
00136                 badBitMode5 = dbe->book1D("badBitMode5","P_{t} LUT address bit differences, emulator mode 5", 21,0,21);
00137                 badBitMode5->setAxisTitle("P_{t} Address Bit",1);
00138                 badBitMode6 = dbe->book1D("badBitMode6","P_{t} LUT address bit differences, emulator mode 6", 21,0,21);
00139                 badBitMode6->setAxisTitle("P_{t} Address Bit",1);
00140                 badBitMode7 = dbe->book1D("badBitMode7","P_{t} LUT address bit differences, emulator mode 7", 21,0,21);
00141                 badBitMode7->setAxisTitle("P_{t} Address Bit",1);
00142                 badBitMode8 = dbe->book1D("badBitMode8","P_{t} LUT address bit differences, emulator mode 8", 21,0,21);
00143                 badBitMode8->setAxisTitle("P_{t} Address Bit",1);
00144                 badBitMode9 = dbe->book1D("badBitMode9","P_{t} LUT address bit differences, emulator mode 9", 21,0,21);
00145                 badBitMode9->setAxisTitle("P_{t} Address Bit",1);
00146                 badBitMode10 = dbe->book1D("badBitMode10","P_{t} LUT address bit differences, emulator mode 10", 21,0,21);
00147                 badBitMode10->setAxisTitle("P_{t} Address Bit",1);
00148                 badBitMode11 = dbe->book1D("badBitMode11","P_{t} LUT address bit differences, emulator mode 11", 21,0,21);
00149                 badBitMode11->setAxisTitle("P_{t} Address Bit",1);
00150                 badBitMode12 = dbe->book1D("badBitMode12","P_{t} LUT address bit differences, emulator mode 12", 21,0,21);
00151                 badBitMode12->setAxisTitle("P_{t} Address Bit",1);
00152                 badBitMode13 = dbe->book1D("badBitMode13","P_{t} LUT address bit differences, emulator mode 13", 21,0,21);
00153                 badBitMode13->setAxisTitle("P_{t} Address Bit",1);
00154                 badBitMode14 = dbe->book1D("badBitMode14","P_{t} LUT address bit differences, emulator mode 14", 21,0,21);
00155                 badBitMode14->setAxisTitle("P_{t} Address Bit",1);
00156                 badBitMode15 = dbe->book1D("badBitMode15","P_{t} LUT address bit differences, emulator mode 15", 21,0,21);
00157                 badBitMode15->setAxisTitle("P_{t} Address Bit",1);
00158                 
00159                 trackCountComp = dbe->book2D("trackCountComp","Hardware Vs. Emulator track Multiplicity",4,-0.5,3.5,4,-0.5,3.5);
00160                 trackCountComp->setAxisTitle("Hardware track count",1);
00161                 trackCountComp->setAxisTitle("Emulator track count",2);
00162                 
00163                 ptLUTOutput = dbe->book2D("ptLUTOutput","Comparison of P_{t}LUT Output for spy muon",127,0,127,127,0,127);
00164                 ptLUTOutput->setAxisTitle("Hardware P_{t} LUT Out",1);
00165                 ptLUTOutput->setAxisTitle("Emulator P_{t} LUT Out",2);
00166                 
00167                 mismatchSector = dbe->book1D("mismatchSector","LCT Sector for mismatched tracks",6,0,6);
00168                 mismatchTime   = dbe->book1D("mismatchTime","LCT Time bin for mismatched tracks", 7,3,10);
00169                 mismatchEndcap = dbe->book1D("mismatchEndcap","LCT endcap for mismatched tracks", 2,0,2);
00170                 mismatchPhi              = dbe->book1D("mismatchPhi","LCT #phi for mismatched tracks",4096,0,4096);
00171                 mismatchEta              = dbe->book1D("mismatchEta","LCT #eta for mismatched tracks",128,0,128);
00172                 
00173                 mismatchDelPhi12 = dbe->book1D("mismatchDelPhi12", "LCT #Delta #phi_{12}", 4096,0,4096);
00174                 mismatchDelPhi13 = dbe->book1D("mismatchDelPhi13", "LCT #Delta #phi_{13}", 4096,0,4096);
00175                 mismatchDelPhi14 = dbe->book1D("mismatchDelPhi14", "LCT #Delta #phi_{14}", 4096,0,4096);
00176                 mismatchDelPhi23 = dbe->book1D("mismatchDelPhi23", "LCT #Delta #phi_{23}", 4096,0,4096);
00177                 mismatchDelPhi24 = dbe->book1D("mismatchDelPhi24", "LCT #Delta #phi_{24}", 4096,0,4096);
00178                 mismatchDelPhi34 = dbe->book1D("mismatchDelPhi34", "LCT #Delta #phi_{34}", 4096,0,4096);
00179                 
00180                 mismatchDelEta12 = dbe->book1D("mismatchDelEta12", "LCT #Delta #eta_{12}", 128,0,128);
00181                 mismatchDelEta13 = dbe->book1D("mismatchDelEta13", "LCT #Delta #eta_{13}", 128,0,128);
00182                 mismatchDelEta14 = dbe->book1D("mismatchDelEta14", "LCT #Delta #eta_{14}", 128,0,128);
00183                 mismatchDelEta23 = dbe->book1D("mismatchDelEta23", "LCT #Delta #eta_{23}", 128,0,128);
00184                 mismatchDelEta24 = dbe->book1D("mismatchDelEta24", "LCT #Delta #eta_{24}", 128,0,128);
00185                 mismatchDelEta34 = dbe->book1D("mismatchDelEta34", "LCT #Delta #eta_{34}", 128,0,128);
00186                 
00187                 endTrackBadSector = dbe->book1D("endTrackBadSector", "Sector for PtLUT misalignment", 12,0,12);
00188                 endTrackBadFR     = dbe->book1D("endTrackBadFR", "FR bit for PtLUT misalignment", 2, 0, 2);
00189                 endTrackBadEta    = dbe->book1D("endTrackBadEta", "Eta for PtLUT misalignment", 16,0,16);
00190                 endTrackBadMode   = dbe->book1D("endTrackBadMode", "Mode of track for PtLUT misalingment", 16,0,16);
00191                 
00192                 bxData = dbe->book1D("bxData", "Bunch Crossing Number for data track", 15, -5, 10);
00193                 bxEmu = dbe->book1D("bxEmu", "Bunch Crossing Number for emu track", 15, -5, 10);
00194                 
00195                 allLctBx = dbe->book1D("allLctBx", "Bunch Crossing Number for all Lcts", 15,-3,12);
00196         }
00197         
00198 }
00199 
00200 void L1TdeCSCTF::endJob(void){
00201         
00202         if(ptLUT_) delete ptLUT_;
00203         
00204         if ( outFile.size() != 0  && dbe ) dbe->save(outFile);  
00205         return;
00206 }
00207 
00208 void L1TdeCSCTF::analyze(edm::Event const& e, edm::EventSetup const& es){
00209         // Get LCT information
00211         int lctArray[20][7];
00212         short nLCTs=0;
00213         for(int oj=0; oj<20; oj++) lctArray[oj][0]=0;
00214         if( lctProducer.label() != "null" )
00215         {
00216                 edm::Handle<CSCCorrelatedLCTDigiCollection> LCTs;
00217                 e.getByLabel(lctProducer.label(),lctProducer.instance(), LCTs);
00218 
00219                 // check validity of input collection
00220                 if(!LCTs.isValid()) {
00221                   edm::LogWarning("L1TdeCSCTF")
00222                     << "\n No valid [lct] product found: "
00223                     << " CSCCorrelatedLCTDigiCollection"
00224                     << std::endl;
00225                   return;
00226                 }
00227                 
00228                 edm::ESHandle< L1MuTriggerScales > scales ;
00229                 es.get< L1MuTriggerScalesRcd >().get( scales ) ;
00230                 edm::ESHandle< L1MuTriggerPtScale > ptScale ;
00231                 es.get< L1MuTriggerPtScaleRcd >().get( ptScale ) ;
00232                 ptLUT_ = new CSCTFPtLUT(ptLUTset, scales.product(), ptScale.product() );
00233 
00234                 for(CSCCorrelatedLCTDigiCollection::DigiRangeIterator csc=LCTs.product()->begin(); csc!=LCTs.product()->end(); csc++)
00235                 {
00236                         int lctId=0;
00237 
00238                         CSCCorrelatedLCTDigiCollection::Range range1 = LCTs.product()->get((*csc).first);
00239                         for(CSCCorrelatedLCTDigiCollection::const_iterator lct=range1.first; lct!=range1.second; lct++,lctId++)
00240                         {
00241                                 CSCCorrelatedLCTDigiCollection::Range range1 = LCTs.product()->get((*csc).first);
00242                                 CSCCorrelatedLCTDigiCollection::const_iterator lct;
00243                                 for( lct = range1.first; lct!=range1.second; lct++)
00244                                 {       
00245                                         int station = (*csc).first.station()-1;
00246                                         int cscId   = (*csc).first.triggerCscId()-1;
00247                                         int sector  = (*csc).first.triggerSector()-1;
00248                                         int subSector = CSCTriggerNumbering::triggerSubSectorFromLabels((*csc).first);
00249                                         int tbin    = lct->getBX();
00250                                         int fpga    = ( subSector ? subSector-1 : station+1 );
00251                                         int endcap = (*csc).first.endcap()-1;
00252 
00253                                         lclphidat lclPhi;
00254                                         gblphidat gblPhi;
00255                                         gbletadat gblEta;
00256 
00257                                         try{
00258                                                 lclPhi = srLUTs_[endcap][sector][fpga]->localPhi(lct->getStrip(), lct->getPattern(), lct->getQuality(), lct->getBend());
00259                                         } catch ( cms::Exception &e ) {
00260                                                 bzero(&lclPhi, sizeof(lclPhi));
00261                                                 edm::LogWarning("L1TdeCSCTF:analyze()") << "Exception from LocalPhi LUT in endCap: " << endcap << ", sector: " << sector << ", fpga: " << fpga 
00262                                                         << "(strip:" << lct->getStrip() << ", pattern:"<< lct->getPattern() << ", Q:" << lct->getQuality() << ", bend:" << lct->getBend() << std::endl;
00263                                         }
00264 
00265                                         try{
00266                                                 gblPhi = srLUTs_[endcap][sector][fpga]->globalPhiME( lclPhi.phi_local, lct->getKeyWG(),cscId+1);
00267                                         } catch  ( cms::Exception &e ) {
00268                                                 bzero(&gblPhi,sizeof(gblPhi));
00269                                                 edm::LogWarning("L1TdeCSCTF:analyze()") << "Exception from GlobalPhi LUT in endCap: " << endcap << ", sector: " << sector << ", fpga: " << fpga 
00270                                                         << "(local phi:" << lclPhi.phi_local << ", keyWG:" << lct->getKeyWG() << ",cscID:" << cscId+1 << std::endl;
00271                                         }
00272                                         try{
00273                                                 gblEta = srLUTs_[endcap][sector][fpga]->globalEtaME(lclPhi.phi_bend_local, lclPhi.phi_local,lct->getKeyWG(),cscId+1);
00274                                         } catch  ( cms::Exception &e ) {
00275                                                 bzero(&gblEta,sizeof(gblEta));
00276                                                 edm::LogWarning("L1TdeCSCTF:analyze()") << "Exception from GlobalEta LUT in endCap: " << endcap << ", sector: " << sector << ", fpga: " << fpga
00277                                                         << "(local phi bend:" << lclPhi.phi_bend_local << ", local phi:" <<  lclPhi.phi_local << ", keyWG: " << lct->getKeyWG() << ", cscID: " << cscId+1 << std::endl;
00278                                         }
00279 
00280                                         allLctBx->Fill(tbin);
00281                                         
00282                                         if((nLCTs < 20))
00283                                         {
00284                                                 lctArray[nLCTs][0] = 1;
00285                                                 lctArray[nLCTs][1] = sector;
00286                                                 lctArray[nLCTs][2] = tbin;
00287                                                 lctArray[nLCTs][3] = endcap;
00288                                                 lctArray[nLCTs][4] = gblPhi.global_phi;
00289                                                 lctArray[nLCTs][5] = gblEta.global_eta;
00290                                                 lctArray[nLCTs][6] = station;
00291                                                 nLCTs++;
00292                                         }
00293                                 }
00294                         }
00295                 }
00296         }
00297 
00298         // Initialize Arrays
00300         nDataMuons = 0; nEmulMuons = 0;
00301         int dataMuonArray[8][3], emuMuonArray[8][3];
00302         for( int joe=0; joe<8; joe++){
00303                 for( int rules=0; rules<3; rules++ )
00304                 {
00305                         dataMuonArray[joe][rules] = 0;
00306                         emuMuonArray[joe][rules] = 0;
00307                 }
00308         }
00309         // Get Hardware information, and check output of PtLUT
00311         if( dataTrackProducer.label() != "null" )
00312         {
00313                 edm::Handle<L1CSCTrackCollection> tracks;
00314                 e.getByLabel(dataTrackProducer.label(),dataTrackProducer.instance(),tracks);
00315 
00316                 // check validity of input collection
00317                 if(!tracks.isValid()) {
00318                   edm::LogWarning("L1TdeCSCTF")
00319                     << "\n No valid [data tracks] product found: "
00320                     << " L1CSCTrackCollection"
00321                     << std::endl;
00322                   return;
00323                 }
00324 
00325 
00326                 for(L1CSCTrackCollection::const_iterator trk=tracks.product()->begin(); trk!=tracks.product()->end(); trk++)
00327                 {
00328                         bxData->Fill(trk->first.BX());
00329                         if( /*(((0x0f0000 &(trk->first.ptLUTAddress()) ) >> 16) != 0xb) &&*/  (nDataMuons < 8) && (trk->first.BX() <2) && (trk->first.BX() > -2) )
00330                         {
00331                                 dataMuonArray[nDataMuons][0]  = 0; //matched?
00332                                 dataMuonArray[nDataMuons][1]  = trk->first.ptLUTAddress();  
00333                                 dataMuonArray[nDataMuons][2]  = trk->first.sector();
00334                                 nDataMuons++;
00335                         }
00336                         /*
00337                         if( trk->first.outputLink() == 1)
00338                         {
00339                                 int frBit = (0x200000 &(trk->first.ptLUTAddress()) ) >> 21;
00340                                 int dataRank = trk->first.rank();
00341                                 ptadd thePtAdd(trk->first.ptLUTAddress());
00342                                 ptdat thePtDat = ptLUT_->Pt(thePtAdd);
00343                                 int emuRank = thePtDat.front_rank;
00344                                 if(frBit == 0) emuRank = thePtDat.rear_rank;
00345                                 ptLUTOutput->Fill(dataRank, emuRank);
00346                                 if(dataRank != emuRank)
00347                                 {
00348                                         endTrackBadSector->Fill(trk->first.sector());
00349                                         endTrackBadFR->Fill(frBit);
00350                                         int etaP = (0xf000 &(trk->first.ptLUTAddress()) ) >> 12;
00351                                         endTrackBadEta->Fill(etaP);
00352                                         int modeP = (0xf0000 &(trk->first.ptLUTAddress()) ) >> 16;
00353                                         endTrackBadMode->Fill(modeP);
00354                                 }
00355                         }*/
00356                 }
00357         }
00358         // Get Emulator information
00360         if( emulTrackProducer.label() != "null" )
00361         {
00362                 edm::Handle<L1CSCTrackCollection> tracks;
00363                 e.getByLabel(emulTrackProducer.label(),emulTrackProducer.instance(),tracks);
00364 
00365                 // check validity of input collection
00366                 if(!tracks.isValid()) {
00367                   edm::LogWarning("L1TdeCSCTF")
00368                     << "\n No valid [emulator tracks] product found: "
00369                     << " L1CSCTrackCollection"
00370                     << std::endl;
00371                   return;
00372                 }
00373 
00374                 for(L1CSCTrackCollection::const_iterator trk=tracks.product()->begin(); trk!=tracks.product()->end(); trk++)
00375                 {
00376                         bxEmu->Fill(trk->first.BX());
00377                         if( /*(((0x0f0000&trk->first.ptLUTAddress())>>16) != 0xb) &&*/  (nEmulMuons<8) && (trk->first.BX() <2) && (trk->first.BX() >-2))
00378                         {
00379                                 emuMuonArray[nEmulMuons][0]  = 0;
00380                                 emuMuonArray[nEmulMuons][1]  = trk->first.ptLUTAddress();
00381                                 emuMuonArray[nEmulMuons][2]  = trk->first.sector();
00382                                 nEmulMuons++;
00383                         }
00384                 }
00385         }
00386         // Match Tracks by sector & mode in the case of multiple tracks
00388         short int rightIndex[8];
00389         for(int jjj=0; jjj<8; jjj++) rightIndex[jjj]= 20;
00390         trackCountComp->Fill(nDataMuons,nEmulMuons);
00391         if( (nDataMuons==nEmulMuons) && (nDataMuons!=0) )
00392         {
00393                 for(int hw=0; hw<nDataMuons; hw++)
00394                 {
00395                         int addDiffWin = 5;
00396                         for(int sw=0; sw<nEmulMuons; sw++)
00397                         {
00398                                 if( emuMuonArray[sw][2] == dataMuonArray[hw][2] ) //make sure triggers are coming from same sector
00399                                 {
00400                                         int addDiff = 0;
00401                                         int hwMode = (0x0f0000 & dataMuonArray[hw][1] )>>16;
00402                                         int swMode = (0x0f0000 & emuMuonArray[sw][1] )>>16;
00403                                         int thor = hwMode^swMode;
00404                                         for(int jax=0; jax<4; jax++)
00405                                         {
00406                                                 addDiff += 1 & (thor>>jax);
00407                                         }
00408                                         if( (addDiff <addDiffWin) && (emuMuonArray[sw][0]!=1) )
00409                                         {
00410                                                 addDiffWin = addDiff;
00411                                                 rightIndex[hw] = sw;
00412                                         }
00413                                 }
00414                                 
00415                                 if( sw==nEmulMuons )
00416                                 {
00417                                         emuMuonArray[rightIndex[hw]][0]=1;
00418                                 }
00419                         }
00420                 }
00421                 
00422                 for( int i=0; i<nEmulMuons; i++)
00423                 {
00424                         int hwModeM = (0x0f0000 & dataMuonArray[i][1] )>>16;
00425                         int swModeM = (0x0f0000 & emuMuonArray[rightIndex[i]][1] )>>16;
00426                         int thorM = hwModeM^swModeM;
00427                         for( int q=0; q<=22; q++)
00428                         {
00429                                 int addDiff = (1<<q)&thorM;
00430                                 if(addDiff != 0) 
00431                                 {       
00432                                         if(hwModeM == 0x1) badBitMode1->Fill(q);
00433                                         if(hwModeM == 0x2) badBitMode2->Fill(q);
00434                                         if(hwModeM == 0x3) badBitMode3->Fill(q);
00435                                         if(hwModeM == 0x4) badBitMode4->Fill(q);
00436                                         if(hwModeM == 0x5) badBitMode5->Fill(q);
00437                                         if(hwModeM == 0x6) badBitMode6->Fill(q);
00438                                         if(hwModeM == 0x7) badBitMode7->Fill(q);
00439                                         if(hwModeM == 0x8) badBitMode8->Fill(q);
00440                                         if(hwModeM == 0x9) badBitMode9->Fill(q);
00441                                         if(hwModeM == 0xa) badBitMode10->Fill(q);
00442                                         if(hwModeM == 0xb) badBitMode11->Fill(q);
00443                                         if(hwModeM == 0xc) badBitMode12->Fill(q);
00444                                         if(hwModeM == 0xd) badBitMode13->Fill(q);
00445                                         if(hwModeM == 0xe) badBitMode14->Fill(q);
00446                                         if(hwModeM == 0xf) badBitMode15->Fill(q);
00447                                 }
00448                         }
00449                         
00450                         pt4Comp->Fill(hwModeM,swModeM);
00451                         if( hwModeM == swModeM)
00452                         {
00453                                 int hwPhi1 = (0x0000ff & dataMuonArray[i][1]);
00454                                 int swPhi1 = (0x0000ff & emuMuonArray[rightIndex[i]][1]);
00455                                 int hwPhi2 = (0x000f00 & dataMuonArray[i][1])>>8;
00456                                 int swPhi2 = (0x000f00 & emuMuonArray[rightIndex[i]][1])>>8;
00457                                 int hwEta  = (0x00f000 & dataMuonArray[i][1])>>12;
00458                                 int swEta  = (0x00f000 & emuMuonArray[rightIndex[i]][1])>>12;
00459                                 int hwSign = (0x100000 & dataMuonArray[i][1])>>20;
00460                                 int swSign = (0x100000 & emuMuonArray[rightIndex[i]][1])>>20;
00461                                 int hwFr   = (0x200000 & dataMuonArray[i][1])>>21;
00462                                 int swFr   = (0x200000 & emuMuonArray[rightIndex[i]][1])>>21;
00463                                 pt1Comp->Fill(hwPhi1,swPhi1);
00464                                 pt2Comp->Fill(hwPhi2,swPhi2);
00465                                 pt3Comp->Fill(hwEta,swEta);
00466                                 pt5Comp->Fill(hwSign,swSign);
00467                                 pt6Comp->Fill(hwFr,swFr);
00468                         } else {
00469                                 for(int ak=0; ak<=nLCTs; ak++)
00470                                 {
00471                                         if(lctArray[ak][1] == dataMuonArray[i][2])
00472                                         {
00473                                                 mismatchSector->Fill(lctArray[ak][1]);
00474                                                 mismatchTime  ->Fill(lctArray[ak][2]);
00475                                                 mismatchEndcap->Fill(lctArray[ak][3]);
00476                                                 mismatchPhi             ->Fill(lctArray[ak][4]);
00477                                                 mismatchEta             ->Fill(lctArray[ak][5]);
00478                                         }
00479                                         for(int akk=ak+1; akk<=nLCTs; akk++)
00480                                         {
00481                                                 if(lctArray[ak][1] == lctArray[akk][1])
00482                                                 {
00483                                                         int delPhi = abs(lctArray[ak][4] - lctArray[akk][4]);
00484                                                         int delEta = abs(lctArray[ak][5] - lctArray[akk][5]);
00485                                                         int lowSta = (lctArray[ak][1] < lctArray[akk][1]) ? lctArray[ak][1] : lctArray[akk][1];
00486                                                         int hiSta = (lctArray[ak][1] > lctArray[akk][1]) ? lctArray[ak][1] : lctArray[akk][1];
00487                                                         switch(lowSta)
00488                                                         {
00489                                                                 case 0:
00490                                                                         switch(hiSta)
00491                                                                         {
00492                                                                                 case 1:
00493                                                                                         mismatchDelPhi12->Fill(delPhi);
00494                                                                                         mismatchDelEta12->Fill(delEta);
00495                                                                                 case 2:
00496                                                                                         mismatchDelPhi13->Fill(delPhi);
00497                                                                                         mismatchDelEta13->Fill(delEta);
00498                                                                                 case 3:
00499                                                                                         mismatchDelPhi14->Fill(delPhi);
00500                                                                                         mismatchDelEta14->Fill(delEta);
00501                                                                                 break;
00502                                                                         }
00503                                                                 case 1:
00504                                                                         switch(hiSta)
00505                                                                         {
00506                                                                                 case 2:
00507                                                                                         mismatchDelPhi23->Fill(delPhi);
00508                                                                                         mismatchDelEta23->Fill(delEta);
00509                                                                                 case 3:
00510                                                                                         mismatchDelPhi24->Fill(delPhi);
00511                                                                                         mismatchDelEta24->Fill(delEta);
00512                                                                                 break;
00513                                                                         }
00514                                                                 case 2:
00515                                                                         if(hiSta ==3)
00516                                                                         {
00517                                                                                         mismatchDelPhi34->Fill(delPhi);
00518                                                                                         mismatchDelEta34->Fill(delEta);
00519                                                                         }
00520                                                                 break;
00521                                                         }
00522                                                 }
00523                                         }
00524                                 }
00525                         }
00526                 }
00527         }
00528 }