CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DQM/L1TMonitor/src/L1TCSCTF.cc

Go to the documentation of this file.
00001 /*
00002  * \file L1TCSCTF.cc
00003  *
00004  * $Date: 2010/03/03 17:23:49 $
00005  * $Revision: 1.36 $
00006  * \author J. Berryhill
00007  *
00008  */
00009 
00010 #include "DQM/L1TMonitor/interface/L1TCSCTF.h"
00011 #include "DQMServices/Core/interface/DQMStore.h"
00012 
00013 // KK_start: includes to fetch all reguired data products from the edm::Event
00014 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
00015 #include "DataFormats/L1CSCTrackFinder/interface/L1CSCTrackCollection.h"
00016 #include "DataFormats/L1CSCTrackFinder/interface/L1CSCStatusDigiCollection.h"
00017 #include "L1Trigger/CSCCommonTrigger/interface/CSCTriggerGeometry.h"
00018 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00019 // KK_end
00020 
00021 //GP_start
00022 #include "DataFormats/L1CSCTrackFinder/interface/CSCTriggerContainer.h"
00023 #include "DataFormats/L1CSCTrackFinder/interface/TrackStub.h"
00024 //GP_end
00025 
00026 using namespace std;
00027 using namespace edm;
00028 
00029 L1TCSCTF::L1TCSCTF(const ParameterSet& ps)
00030   // KK_start: if some piece of data is absent - configure corresponding source with 'null:'
00031   //  : csctfSource_( ps.getParameter< InputTag >("csctfSource") )
00032   : gmtProducer( ps.getParameter< InputTag >("gmtProducer") ),
00033                lctProducer( ps.getParameter< InputTag >("lctProducer") ),
00034                trackProducer( ps.getParameter< InputTag >("trackProducer") ),
00035                statusProducer( ps.getParameter< InputTag >("statusProducer") ),
00036                mbProducer( ps.getParameter< InputTag >("mbProducer") )
00037   // KK_end
00038 {
00039 
00040   // verbosity switch
00041   verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
00042 
00043   if(verbose_) edm::LogInfo("DataNotFound") << "L1TCSCTF: constructor...." << endl;
00044 
00045 
00046   dbe = NULL;
00047   if ( ps.getUntrackedParameter<bool>("DQMStore", false) )
00048     {
00049       dbe = Service<DQMStore>().operator->();
00050       dbe->setVerbose(0);
00051     }
00052 
00053   outputFile_ = ps.getUntrackedParameter<string>("outputFile", "");
00054   if ( outputFile_.size() != 0 ) 
00055     {
00056       edm::LogInfo("DataNotFound") << "L1T Monitoring histograms will be saved to " << outputFile_.c_str() << endl;
00057     }
00058 
00059   bool disable = ps.getUntrackedParameter<bool>("disableROOToutput", false);
00060   if(disable){
00061     outputFile_="";
00062   }
00063 
00064 
00065   if ( dbe !=NULL ) 
00066     {
00067       dbe->setCurrentFolder("L1T/L1TCSCTF");
00068     }
00069 
00070   // KK_start: instantiate standard on-fly SR LUTs from CSC TF emulator package
00071   bzero(srLUTs_,sizeof(srLUTs_));
00072   int endcap=1, sector=1; // assume SR LUTs are all same for every sector in either of endcaps
00073   bool TMB07=true; // specific TMB firmware
00074   // Create a dumy pset for SR LUTs
00075   edm::ParameterSet srLUTset;
00076   srLUTset.addUntrackedParameter<bool>("ReadLUTs", false);
00077   srLUTset.addUntrackedParameter<bool>("Binary",   false);
00078   srLUTset.addUntrackedParameter<std::string>("LUTPath", "./");
00079   for(int station=1,fpga=0; station<=4 && fpga<5; station++)
00080     {
00081       if(station==1)
00082         for(int subSector=0; subSector<2 && fpga<5; subSector++)
00083           srLUTs_[fpga++] = new CSCSectorReceiverLUT(endcap, sector, subSector+1, station, srLUTset, TMB07);
00084       else
00085         srLUTs_[fpga++] = new CSCSectorReceiverLUT(endcap, sector, 0, station, srLUTset, TMB07);
00086     }
00087   // KK_end
00088 }
00089 
00090 L1TCSCTF::~L1TCSCTF()
00091 {
00092 
00093   for(int i=0; i<5; i++) 
00094     delete srLUTs_[i]; //free the array of pointers
00095 }
00096 
00097 void L1TCSCTF::beginJob(void)
00098 {
00099 
00100   nev_ = 0;
00101 
00102   // get hold of back-end interface
00103   DQMStore* dbe = 0;
00104   dbe = Service<DQMStore>().operator->();
00105 
00106   if( dbe )
00107     {
00108       dbe->setCurrentFolder("L1T/L1TCSCTF");
00109       dbe->rmdir("L1T/L1TCSCTF");
00110     }
00111 
00112 
00113   if( dbe )
00114     {
00115       dbe->setCurrentFolder("L1T/L1TCSCTF");
00116                 
00117       // KK_start: declaration of two monitoring histograms
00118       //  Error counting histogram:
00119       //  1) checks TF data integrity (error rate - first bin),
00120       //  2) monitors sychronization on input links (4 errors types: SE/SM/BX/AF; ORed for all time bins, links, and SPs),
00121       //  3) reports FMM status (if in any SP FMM status != "Ready" - fill the last bin)
00122       csctferrors = dbe->book1D("CSCTF_errors","CSCTF Errors",6,0,6);   
00123       csctferrors->setAxisTitle("Error type",1);
00124       csctferrors->setAxisTitle("Number of Errors",2);
00125       csctferrors->setBinLabel(1,"Corruptions",1);
00126       csctferrors->setBinLabel(2,"Synch. Err.",1);
00127       csctferrors->setBinLabel(3,"Synch. Mod.",1);
00128       csctferrors->setBinLabel(4,"BX mismatch",1);
00129       csctferrors->setBinLabel(5,"Time misalign.",1);
00130       csctferrors->setBinLabel(6,"FMM != Ready",1);
00131         
00132       //  Occupancy histogram Eta x Y, where Y:
00133       //  1) Phi_packed of input LCTs from 1st, 2nd, 3rd, and 4th stations
00134       //  2) Phi_packed of output tracks
00135       //  (all 12 SPs - 360 degree coveradge)
00136       //csctfoccupancies = dbe->book2D("CSCTF_occupancies","CSCTF Occupancies",100,0.8,2.5,1229,0,1.2);
00137         
00138       //JAG MOD
00139       csctfoccupancies = dbe->book2D("CSCTF_occupancies", "CSCTF Occupancies", 64,-32,31,32,0,6.2);
00140       csctfoccupancies->setAxisTitle("#eta",1);
00141       csctfoccupancies->setAxisTitle("#phi",2);
00142       csctfoccupancies->setBinLabel(1, "-2.5", 1);
00143       csctfoccupancies->setBinLabel(16,"-1.3", 1);
00144       csctfoccupancies->setBinLabel(32,"-0.9", 1);
00145       csctfoccupancies->setBinLabel(33,"0.9", 1);
00146       csctfoccupancies->setBinLabel(45,"1.3", 1);
00147       csctfoccupancies->setBinLabel(64,"2.5", 1);
00148       // KK_end
00149         
00150       //JAG
00151       haloDelEta23 = dbe->book1D("CSCTF_Halo_Eta23","Delta station 2 to station 3 Eta for Halo Muons", 40, -0.20,0.30);
00152                 
00153                 
00154       csctfTrackQ = dbe->book1D("CSCTF_Track_Q","CSC Track Mode", 16, -0.5, 15.5);
00155       csctfTrackQ->setAxisTitle("Track Type", 1);
00156       csctfTrackQ->setBinLabel(1,"No Track",1);
00157       csctfTrackQ->setBinLabel(2,"Bad Phi Road",1);
00158       csctfTrackQ->setBinLabel(3,"ME1-2-3",1);
00159       csctfTrackQ->setBinLabel(4,"ME1-2-4",1);
00160       csctfTrackQ->setBinLabel(5,"ME1-3-4",1);
00161       csctfTrackQ->setBinLabel(6,"ME2-3-4",1);
00162       csctfTrackQ->setBinLabel(7,"ME1-2",1);
00163       csctfTrackQ->setBinLabel(8,"ME1-3",1);
00164       csctfTrackQ->setBinLabel(9,"ME2-3",1);
00165       csctfTrackQ->setBinLabel(10,"ME2-4",1);
00166       csctfTrackQ->setBinLabel(11,"ME3-4",1);
00167       csctfTrackQ->setBinLabel(12,"Singles",1);
00168       csctfTrackQ->setBinLabel(13,"ME1-2,MB1",1);
00169       csctfTrackQ->setBinLabel(14,"ME1-4",1);
00170       csctfTrackQ->setBinLabel(15,"ME2,MB1",1);
00171       csctfTrackQ->setBinLabel(16,"Halo Trigger",1);
00172                 
00173       csctfChamberOccupancies = dbe->book2D("CSCTF_Chamber_Occupancies","CSCTF Chamber Occupancies", 54, -0.05, 5.35, 10, -5.5, 4.5);
00174       csctfChamberOccupancies->setAxisTitle("Sector (Endcap), (chambers 1-9 not labeled)",1);
00175       csctfChamberOccupancies->setBinLabel(1,"ME-4",2);
00176       csctfChamberOccupancies->setBinLabel(2,"ME-3",2);
00177       csctfChamberOccupancies->setBinLabel(3,"ME-2",2);
00178       csctfChamberOccupancies->setBinLabel(4,"ME-1b",2);
00179       csctfChamberOccupancies->setBinLabel(5,"ME-1a",2);
00180       csctfChamberOccupancies->setBinLabel(6,"ME+1a",2);
00181       csctfChamberOccupancies->setBinLabel(7,"ME+1b",2);
00182       csctfChamberOccupancies->setBinLabel(8,"ME+2",2);
00183       csctfChamberOccupancies->setBinLabel(9,"ME+3",2);
00184       csctfChamberOccupancies->setBinLabel(10,"ME+4",2);
00185       csctfChamberOccupancies->setBinLabel(1, "1(+), 7(-)",1);
00186       csctfChamberOccupancies->setBinLabel(10,"2(+), 8(-)",1);
00187       csctfChamberOccupancies->setBinLabel(19,"3(+), 9(-)",1);
00188       csctfChamberOccupancies->setBinLabel(28,"4(+), 10(-)",1);
00189       csctfChamberOccupancies->setBinLabel(37,"5(+), 11(-)",1);
00190       csctfChamberOccupancies->setBinLabel(46,"6(+), 12(-)",1);
00191                 
00192       csctfTrackPhi = dbe->book1D("CSCTF_Track_Phi", "CSCTF Track Phi",144,0,2*M_PI);
00193       //csctfTrackPhi = dbe->book1D("CSCTF_Track_Phi", "CSCTF Track Phi",32,0,32);
00194       csctfTrackPhi->setAxisTitle("Track #phi", 1);
00195       csctfTrackEta = dbe->book1D("CSCTF_Track_Eta", "CSCTF Track Eta",64,-32,32);
00196       //csctfTrackEta = dbe->book1D("CSCTF_Track_Eta", "CSCTF TrackEta",32,0,32);
00197       csctfTrackEta->setAxisTitle("Track #eta", 1);
00198       csctfTrackEta->setBinLabel(1, "-2.5", 1);
00199       csctfTrackEta->setBinLabel(16,"-1.3", 1);
00200       csctfTrackEta->setBinLabel(32,"-0.9", 1);
00201       csctfTrackEta->setBinLabel(33,"0.9", 1);
00202       csctfTrackEta->setBinLabel(45,"1.3", 1);
00203       csctfTrackEta->setBinLabel(64,"2.5", 1);
00204                 
00205       csctfbx = dbe->bookProfile("CSCTF_bx","CSCTF bx", 36, 0.5, 36.5, 15, -5.5,9.5 ) ;
00206       csctfbx->setAxisTitle("Sector, Endcap, MPC Link", 1);
00207       csctfbx->setBinLabel(1,"1, +",1);
00208       csctfbx->setBinLabel(4,"2, +",1);
00209       csctfbx->setBinLabel(7,"3, +",1);
00210       csctfbx->setBinLabel(10,"4, +",1);
00211       csctfbx->setBinLabel(13,"5, +",1);
00212       csctfbx->setBinLabel(16,"6, +",1);
00213       csctfbx->setBinLabel(19,"1, -",1);
00214       csctfbx->setBinLabel(22,"2, -",1);
00215       csctfbx->setBinLabel(25,"3, -",1);
00216       csctfbx->setBinLabel(28,"4, -",1);
00217       csctfbx->setBinLabel(31,"5, -",1);
00218       csctfbx->setBinLabel(34,"6, -",1);
00219                 
00220       cscTrackStubNumbers = dbe->book1D("CSCTF_TrackStubs", "Number of Stubs in CSC Tracks", 5, 0.5, 5.5);
00221                 
00222       csctfntrack = dbe->book1D("CSCTF_ntrack","Number of CSCTracks found per event", 5, 0.5, 5.5 ) ;
00223       //JAG
00224     }
00225  
00226   //GP_start
00227   char hname [200];
00228   char htitle[200];
00229 
00230   for(int i=0; i<12; i++) {
00231     
00232     sprintf(hname ,"DTstubsTimeTrackMenTimeArrival_%d",i+1);
00233     sprintf(htitle,"T_{track} - T_{DT stub} sector %d",i+1);
00234  
00235     DTstubsTimeTrackMenTimeArrival[i] = dbe->book2D(hname,htitle, 7,-3,3, 2,1,3);
00236     DTstubsTimeTrackMenTimeArrival[i]->getTH2F()->SetMinimum(0);
00237     
00238     // axis makeup
00239     DTstubsTimeTrackMenTimeArrival[i]->setAxisTitle("bx_{CSC track} - bx_{DT stub}",1);
00240     DTstubsTimeTrackMenTimeArrival[i]->setAxisTitle("subsector"     ,2);
00241 
00242     DTstubsTimeTrackMenTimeArrival[i]->setBinLabel(1,"-3",1);
00243     DTstubsTimeTrackMenTimeArrival[i]->setBinLabel(2,"-2",1);
00244     DTstubsTimeTrackMenTimeArrival[i]->setBinLabel(3,"-1",1);
00245     DTstubsTimeTrackMenTimeArrival[i]->setBinLabel(4, "0",1);
00246     DTstubsTimeTrackMenTimeArrival[i]->setBinLabel(5,"+1",1);
00247     DTstubsTimeTrackMenTimeArrival[i]->setBinLabel(6,"+2",1);
00248     DTstubsTimeTrackMenTimeArrival[i]->setBinLabel(7,"+3",1);
00249 
00250     DTstubsTimeTrackMenTimeArrival[i]->setBinLabel(1,"sub1",2);
00251     DTstubsTimeTrackMenTimeArrival[i]->setBinLabel(2,"sub2",2);
00252 
00253   } 
00254 
00255   csctfHaloL1ABXN  = dbe->book1D("csctfHaloL1ABXN" ,"L1A BXN (HALO)", 3564,0,3564);
00256   csctfHaloL1ABXN->setAxisTitle("L1A (BX)",1);
00257   csctfCoincL1ABXN = dbe->book1D("csctfCoincL1ABXN","L1A BXN (COINCIDENCE)", 3564,0,3564);
00258   csctfCoincL1ABXN->setAxisTitle("L1A (BX)",1);
00259   //GP_end
00260 
00261 
00262 }
00263 
00264 
00265 void L1TCSCTF::endJob(void)
00266 {
00267 
00268   if(verbose_) edm::LogInfo("DataNotFound") << "L1TCSCTF: end job...." << endl;
00269   LogInfo("EndJob") << "analyzed " << nev_ << " events";
00270 
00271   if ( outputFile_.size() != 0  && dbe ) dbe->save(outputFile_);
00272 
00273   return;
00274 }
00275 
00276 void L1TCSCTF::analyze(const Event& e, const EventSetup& c)
00277 {
00278   int NumCSCTfTracksRep = 0;
00279   nev_++;
00280   if(verbose_) edm::LogInfo("DataNotFound") << "L1TCSCTF: analyze...." << endl;
00281 
00282   edm::Handle<L1MuGMTReadoutCollection> pCollection;
00283   if( gmtProducer.label() != "null" )
00284     { // GMT block
00285       e.getByLabel(gmtProducer,pCollection);
00286       if (!pCollection.isValid()) 
00287         {
00288           edm::LogInfo("DataNotFound") << "can't find L1MuGMTReadoutCollection with label ";  // << csctfSource_.label() ;
00289           return;
00290         }
00291 
00292       L1MuGMTReadoutCollection const* gmtrc = pCollection.product();
00293       vector<L1MuGMTReadoutRecord> gmt_records = gmtrc->getRecords();
00294       vector<L1MuGMTReadoutRecord>::const_iterator RRItr;
00295       
00296       // GP
00297       // Look if the readout window contains one (and only one CSC cands)
00298       // to make it simpler I reject events with more than a CSC cand in the
00299       // same readout window 
00300 
00301       // count non-empty candidates in this bx
00302       int bxWindow = 0;
00303       int nCands   = 0;
00304     
00305       for( RRItr = gmt_records.begin(); RRItr != gmt_records.end(); RRItr++ ) {
00306         bxWindow++;
00307 
00308         // get the csc candidates
00309         vector<L1MuRegionalCand> INPCands = RRItr->getCSCCands();
00310     
00311     
00312         vector<L1MuRegionalCand>::const_iterator INPItr;
00313 
00314         BxInEvent_ = 0;
00315         isCSCcand_ = false;
00316 
00317         int  nCandsBx  = 0;
00318         
00319         for( INPItr = INPCands.begin(); INPItr != INPCands.end(); ++INPItr ) {
00320           if(!INPItr->empty()) {
00321             nCandsBx++;
00322             nCands++;
00323             BxInEvent_ = RRItr->getBxInEvent();
00324             if (verbose_)
00325               edm::LogInfo("DataNotFound") << "cand " << nCandsBx << " -> assigned CSCTF bx: " << INPItr->bx() << endl;
00326           }
00327         }
00328         if (verbose_)
00329           if(nCandsBx)
00330             edm::LogInfo("DataNotFound") << nCandsBx << " cands in bx: " << BxInEvent_ << endl;
00331         
00332       }
00333 
00334       if (nCands != 1) return;
00335       else             isCSCcand_ = true;
00336       if (verbose_)
00337         edm::LogInfo("DataNotFound") << "bxWindow: " << bxWindow << endl;
00338       // GP_end
00339 
00340       int ncsctftrack = 0;
00341       if (verbose_)
00342         {
00343           edm::LogInfo("DataNotFound") << "\tCSCTFCand ntrack " << ncsctftrack << endl;
00344         }
00345     } // end of GMT block
00346 
00347   L1ABXN = -999;
00348   if( statusProducer.label() != "null" )
00349     {
00350       edm::Handle<L1CSCStatusDigiCollection> status;
00351       e.getByLabel(statusProducer.label(),statusProducer.instance(),status);
00352       bool integrity=status->first, se=false, sm=false, bx=false, af=false, fmm=false;
00353       int nStat = 0;
00354  
00355       for(std::vector<L1CSCSPStatusDigi>::const_iterator stat=status->second.begin(); stat!=status->second.end(); stat++)
00356         {
00357           se |= stat->SEs()&0xFFF;
00358           sm |= stat->SMs()&0xFFF;
00359           bx |= stat->BXs()&0xFFF;
00360           af |= stat->AFs()&0xFFF;
00361           fmm|= stat->FMM()!=8;
00362 
00363           //GP_start
00364           if(stat->VPs() != 0) {
00365             L1ABXN += stat->BXN();
00366             nStat++;
00367           }
00368           //GP_end
00369         }
00370 
00371       // GP: compute the average
00372       if(nStat!=0) L1ABXN /= nStat;
00373      
00374       if(integrity) csctferrors->Fill(0.5);
00375       if(se)        csctferrors->Fill(1.5);
00376       if(sm)        csctferrors->Fill(2.5);
00377       if(bx)        csctferrors->Fill(3.5);
00378       if(af)        csctferrors->Fill(4.5);
00379       if(fmm)       csctferrors->Fill(5.5);
00380     }
00381 
00382   if( lctProducer.label() != "null" )
00383     {
00384       edm::ESHandle<CSCGeometry> pDD;
00385       c.get<MuonGeometryRecord>().get( pDD );
00386       CSCTriggerGeometry::setGeometry(pDD);
00387 
00388       edm::Handle<CSCCorrelatedLCTDigiCollection> corrlcts;
00389       e.getByLabel(lctProducer.label(),lctProducer.instance(),corrlcts);
00390 
00391       for(CSCCorrelatedLCTDigiCollection::DigiRangeIterator csc=corrlcts.product()->begin(); csc!=corrlcts.product()->end(); csc++)
00392         {
00393           CSCCorrelatedLCTDigiCollection::Range range1 = corrlcts.product()->get((*csc).first);
00394           for(CSCCorrelatedLCTDigiCollection::const_iterator lct=range1.first; lct!=range1.second; lct++)
00395             {
00396               int endcap  = (*csc).first.endcap()-1;
00397               int station = (*csc).first.station()-1;
00398               int sector  = (*csc).first.triggerSector()-1;
00399               int subSector = CSCTriggerNumbering::triggerSubSectorFromLabels((*csc).first);
00400               int cscId   = (*csc).first.triggerCscId()-1;
00401               int fpga    = ( subSector ? subSector-1 : station+1 );
00402               //JAG
00403               int endcapAssignment = 1;
00404               int shift = 1;
00405               float sectorArg = sector;
00406               //float sectorArg = j;
00407                                 
00408               if( endcap == 1 ){
00409                 endcapAssignment = -1;
00410                 shift = 2;
00411                 //sectorArg = sector - 6;
00412               }
00413                                 
00414               int signedStation = (station + shift)* endcapAssignment;
00415               if( (station == 0) && (endcap == 0)) signedStation = subSector - 1;
00416               if( (station == 0) && (endcap == 1)) signedStation = (-1)*subSector;
00417                                 
00418               float chamberArg1 = cscId * 0.1 + sectorArg;
00419               //float chamberArg1 = i*0.1 + sectorArg;
00420               //std::cout << "First" << i << " " << sectorArg << " " << chamberArg1 << std::endl;
00421                                 
00422               float chamberArg11 = chamberArg1;
00423               if(sectorArg == 1) chamberArg1 = chamberArg11 - 0.1;
00424               if(sectorArg == 2) chamberArg1 = chamberArg11 - 0.2;
00425               if(sectorArg == 3) chamberArg1 = chamberArg11 - 0.3;
00426               if(sectorArg == 4) chamberArg1 = chamberArg11 - 0.4;
00427               if(sectorArg == 5) chamberArg1 = chamberArg11 - 0.5;
00428 
00429               //std::cout << "cscId, station, sector, endcap, sectorArg, chamber Arg: " << cscId << ", " << station << ", " <<sector << ", " << endcap << ", " << chamberArg1 << ", " << signedStation << std::endl;                    
00430 
00431               csctfChamberOccupancies->Fill(chamberArg1, signedStation); 
00432               int bunchX = ( (lct->getBX()) - 6 );
00433                                 
00434               int timingSectorArg = 3*(sector) + (lct->getMPCLink());
00435               if( endcap == 1) timingSectorArg = 3*(sector + 6) + (lct->getMPCLink());
00436               //std::cout << "Sector, MPCLink, TSA, endcap: " << sector << ", " << lct->getMPCLink() << ", " << timingSectorArg << ", " << endcap << std::endl;
00437                                 
00438               csctfbx->Fill(timingSectorArg, bunchX );
00439                                 
00440               //std::cout << "LCT'S, encap: " << endcap << ", station: " << station << ", sector: " << sector << ", subSector: " << subSector << ", cscId: " << cscId << std:: endl;
00441 
00442               //End JAG
00443                                 
00444               // Check if Det Id is within pysical range:
00445               if( endcap<0||endcap>1 || sector<0||sector>6 || station<0||station>3 || cscId<0||cscId>8 || fpga<0||fpga>4)
00446                 {
00447                   edm::LogError("L1CSCTF: CSC TP are out of range: ")<<"  endcap: "<<(endcap+1)<<"  station: "<<(station+1) <<"  sector: "<<(sector+1)<<"  subSector: "<<subSector<<"  fpga: "<<fpga<<"  cscId: "<<(cscId+1);
00448                   continue;
00449                 }
00450               lclphidat lclPhi;                 
00451               try {
00452                 lclPhi = srLUTs_[fpga]->localPhi(lct->getStrip(), lct->getPattern(), lct->getQuality(), lct->getBend());
00453               } catch(...) { 
00454                 bzero(&lclPhi,sizeof(lclPhi)); 
00455               }
00456                                 
00457               gblphidat gblPhi;
00458               try {
00459                 gblPhi = srLUTs_[fpga]->globalPhiME(lclPhi.phi_local, lct->getKeyWG(), cscId+1);
00460               } catch(...) { 
00461                 bzero(&gblPhi,sizeof(gblPhi)); 
00462               }
00463                                 
00464               gbletadat gblEta;
00465               try {
00466                 gblEta = srLUTs_[fpga]->globalEtaME(lclPhi.phi_bend_local, lclPhi.phi_local, lct->getKeyWG(), cscId+1);
00467               } catch(...) { 
00468                 bzero(&gblEta,sizeof(gblEta)); 
00469               }
00470            
00471               // SR LUT gives packed eta and phi values -> normilize them to 1 by scale them to 'max' and shift by 'min'
00472               //float etaP = gblEta.global_eta/127*1.5 + 0.9;
00473               //float phiP =  (gblPhi.global_phi);// + ( sector )*4096 + station*4096*12) * 1./(4*4096*12);
00474               //std::cout << "LCT Eta & Phi Coordinates: " << etaP << ", " << phiP << "." << std::endl;
00475               //csctfoccupancies->Fill( gblEta.global_eta/127. * 1.5 + 0.9, (gblPhi.global_phi + ( sector + (endcap?0:6) )*4096 + station*4096*12) * 1./(4*4096*12) );
00476             }//lct != range1.scond
00477         }//csc!=corrlcts.product()->end()
00478     }// lctProducer.label() != "null"
00479 
00480 
00481 
00482   if( trackProducer.label() != "null" )
00483     {
00484                 
00485       edm::Handle<L1CSCTrackCollection> tracks;
00486       e.getByLabel(trackProducer.label(),trackProducer.instance(),tracks);
00487       for(L1CSCTrackCollection::const_iterator trk=tracks->begin(); trk<tracks->end(); trk++)
00488         {
00489           //JAG_START
00490           NumCSCTfTracksRep++;
00491           long LUTAdd = trk->first.ptLUTAddress();
00492           int trigMode = ( (LUTAdd)&0xf0000 ) >> 16;
00493           float etaReal = (trk->first.eta_packed() );
00494           if( trk->first.endcap() != 1) 
00495             {
00496               float holder = etaReal;
00497               etaReal = -1*holder;
00498               etaReal -= 1;
00499             }
00500                                 
00501           float phiReal = ((trk->first.localPhi())*(62.5/24) + (trk->first.sector() - 1)*60)*M_PI/180 ;//+ 15;
00502           if( phiReal > (2*M_PI) ) phiReal -= (2*M_PI);
00503                                 
00504           csctfoccupancies->Fill( etaReal, phiReal);
00505           csctfTrackPhi->Fill(phiReal);
00506           csctfTrackEta->Fill( etaReal );
00507           //std::cout << "Eta, phi, trigger mode, sector: " << etaReal << ", " << phiReal << ", " << trigMode << ", " << trk->first.sector() <<  "." << std::endl;
00508                         
00509           csctfTrackQ->Fill( trigMode );
00510                         
00511           if( trigMode == 15 )
00512             {
00513               //GP_start
00514               csctfHaloL1ABXN->Fill(L1ABXN);
00515               //GP_end
00516 
00517               double haloVals[4][4];
00518               for( int i = 0; i < 4; i++)
00519                 {
00520                   haloVals[i][0] = 0;
00521                 }
00522                                 
00523               edm::Handle<CSCCorrelatedLCTDigiCollection> corrlcts;
00524               e.getByLabel(lctProducer.label(),lctProducer.instance(),corrlcts);
00525               for(CSCCorrelatedLCTDigiCollection::DigiRangeIterator csc=corrlcts.product()->begin(); csc!=corrlcts.product()->end(); csc++)
00526                 {
00527                   CSCCorrelatedLCTDigiCollection::Range range1 = corrlcts.product()->get((*csc).first);
00528                   for(CSCCorrelatedLCTDigiCollection::const_iterator lct=range1.first; lct!=range1.second; lct++)
00529                     {
00530                       int endcap  = (*csc).first.endcap()-1;
00531                       int station = (*csc).first.station()-1;
00532                       int sector  = (*csc).first.triggerSector()-1;
00533                       int cscId   = (*csc).first.triggerCscId()-1;
00534                       int subSector = CSCTriggerNumbering::triggerSubSectorFromLabels((*csc).first);
00535                       int fpga    = ( subSector ? subSector-1 : station+1 );
00536                                                 
00537                       if( (station == 1) || (station == 2) )
00538                         {
00539                           int modEnd = 1;
00540                           if( endcap == 0 ) modEnd = -1;
00541                           //if( endcap == 1 ) modEnd = 1;
00542                           int indexHalo = modEnd + station;
00543                           if(haloVals[indexHalo][0] == 1.0) haloVals[indexHalo][3] = 1.0;
00544                           if(haloVals[indexHalo][0] == 0) haloVals[indexHalo][0] = 1.0;
00545                           haloVals[indexHalo][1] = sector*1.0;
00546                                                 
00547                           lclphidat lclPhi;
00548                           lclPhi = srLUTs_[fpga]->localPhi(lct->getStrip(), lct->getPattern(), lct->getQuality(), lct->getBend());
00549                                                 
00550                           gblphidat gblPhi;
00551                           gblPhi = srLUTs_[fpga]->globalPhiME(lclPhi.phi_local, lct->getKeyWG(), cscId+1);
00552                         
00553                           gbletadat gblEta;
00554                           gblEta = srLUTs_[fpga]->globalEtaME(lclPhi.phi_bend_local, lclPhi.phi_local, lct->getKeyWG(), cscId+1);
00555                                                         
00556                           haloVals[indexHalo][2] = gblEta.global_eta/127. * 1.5 + 0.9;
00557                         } //station1 or 2
00558                     } //lct first to second
00559                 } //corrlcts
00560                                 
00561               if( (haloVals[0][0] == 1.) && (haloVals[1][0] == 1.) && (haloVals[0][3] != 1.) && (haloVals[1][3] != 1.)  )
00562                 {
00563                   if( haloVals[0][1] == haloVals[1][1] ){
00564                     double delEta23 = haloVals[1][2] - haloVals[0][2];
00565                     haloDelEta23->Fill( delEta23 );
00566                   }
00567                 }
00568                                 
00569               if( (haloVals[2][0] == 1.) && (haloVals[3][0] == 1.) && (haloVals[2][3] != 1.) && (haloVals[3][3] != 1.)  )
00570                 {
00571                   if( haloVals[2][1] == haloVals[3][1] ){
00572                     double delEta23 = haloVals[3][2] - haloVals[2][2];
00573                     haloDelEta23->Fill( delEta23 );
00574                   }
00575                 }       
00576             } //halo trigger
00577                         
00578           int cscTrackStub = 0;
00579 
00580           CSCCorrelatedLCTDigiCollection lctsOfTracks=trk->second;
00581 
00582           for(CSCCorrelatedLCTDigiCollection::DigiRangeIterator trackStub=lctsOfTracks.begin(); trackStub!=lctsOfTracks.end(); trackStub++)
00583             {
00584               CSCCorrelatedLCTDigiCollection::Range range2 = lctsOfTracks.get((*trackStub).first);
00585               for(CSCCorrelatedLCTDigiCollection::const_iterator lct=range2.first; lct!=range2.second; lct++)
00586                 {
00587                   cscTrackStub++;                       
00588                 }
00589             }
00590                         
00591           //
00592           //edm::Handle<L1CSCTrack> tfInf;
00593           //e.getByLabel(trackProducer.label(), tfInf);
00594           cscTrackStubNumbers->Fill(cscTrackStub);
00595                                 
00596           //JAG_END
00597 
00598           //GP_start: only coincidence
00599           if( trigMode > 0 && trigMode !=15 && trigMode != 11 )
00600             csctfCoincL1ABXN->Fill(L1ABXN);
00601           //GP_end
00602 
00603 
00604         }
00605     }
00606   csctfntrack->Fill(NumCSCTfTracksRep);
00607   // KK_end    ///////////////////////////////////
00608 
00609   // GP_Start
00610   if( mbProducer.label() != "null" ) {
00611     
00612     // handle to needed collections
00613     edm::Handle<CSCTriggerContainer<csctf::TrackStub> > dtStubs;
00614     e.getByLabel(mbProducer.label(),  mbProducer.instance(),  dtStubs);
00615 
00616     edm::Handle<L1CSCTrackCollection> tracks;
00617     e.getByLabel(trackProducer.label(),trackProducer.instance(),tracks);
00618                   
00619     // loop on the DT stubs
00620     std::vector<csctf::TrackStub> vstubs = dtStubs->get();
00621     for(std::vector<csctf::TrackStub>::const_iterator stub=vstubs.begin(); 
00622         stub!=vstubs.end(); stub++){
00623         
00624       if (verbose_) {
00625         edm::LogInfo("DataNotFound") << "\n mbEndcap: "               << stub->endcap();
00626         edm::LogInfo("DataNotFound") << "\n stub->getStrip()[FLAG]: " << stub->getStrip(); 
00627         edm::LogInfo("DataNotFound") << "\n stub->getKeyWG()[CAL]: "  << stub->getKeyWG(); 
00628         edm::LogInfo("DataNotFound") << "\n stub->BX(): "             << stub->BX();
00629         edm::LogInfo("DataNotFound") << "\n stub->sector(): "         << stub->sector();
00630         edm::LogInfo("DataNotFound") << "\n stub->subsector(): "      << stub->subsector();
00631         edm::LogInfo("DataNotFound") << "\n stub->station(): "        << stub->station();
00632         edm::LogInfo("DataNotFound") << "\n stub->phiPacked(): "      << stub->phiPacked();
00633         edm::LogInfo("DataNotFound") << "\n stub->getBend(): "        << stub->getBend();
00634         edm::LogInfo("DataNotFound") << "\n stub->getQuality(): "     << stub->getQuality();
00635         edm::LogInfo("DataNotFound") << "\n stub->cscid(): "          << stub->cscid() << endl;      
00636       }     
00637       
00638       // define the sector ID
00639       int mbId = (stub->endcap()==2) ? 6 : 0;
00640       mbId += stub->sector();
00641 
00642 
00643       // *** do not fill if CalMB variable is set ***
00644       // horrible! They used the same class to write up the LCT and MB info,
00645       // but given the MB does not have strip and WG they replaced this two
00646       // with the flag and cal bits... :S
00647       if (stub->getKeyWG() == 0) {// !CAL as Janos adviced 
00648           
00649         // if FLAG =1, muon belong to previous BX
00650         int bxDT     = stub->BX()-stub->getStrip(); // correct by the FLAG
00651         int subDT    = stub->subsector();
00652           
00653         // Fill the event only if CSC had or would have triggered
00654         if (isCSCcand_){
00655           
00656           // look for tracks in the event and compare the matching DT stubs 
00657           int trkBX = 0;
00658           for(L1CSCTrackCollection::const_iterator trk=tracks->begin(); 
00659               trk<tracks->end(); trk++){
00660             
00661             trkBX = trk->first.BX();
00662 
00663             int trkId = (trk->first.endcap()==2) ? 6 : 0;
00664             trkId += trk->first.sector();
00665             
00666             if (verbose_){ 
00667               edm::LogInfo("DataNotFound") << "\n trk BX: "  << trkBX
00668                    << " Sector: "    << trkId
00669                    << " SubSector: " << trk->first.subsector()
00670                    << " Endcap: "    << trk->first.endcap();
00671               
00672               edm::LogInfo("DataNotFound") << "\n DT  BX: "    << stub->BX()
00673                    << " Sector: "      << mbId
00674                    << " SubSector: "   << stub->subsector()
00675                    << " Endcap: "      << stub->endcap() << endl;
00676             }
00677             
00678             if (mbId == trkId) {
00679               if (verbose_) {
00680                 edm::LogInfo("DataNotFound") << " --> MATCH" << endl;
00681                 edm::LogInfo("DataNotFound") << "Fill :" << trkBX+6-bxDT << " -- " << subDT << " -- cands" << endl;
00682               }
00683               // DT bx ranges from 3 to 9
00684               // trk bx ranges from -3 to 3
00685               DTstubsTimeTrackMenTimeArrival[mbId-1]->Fill(bxDT-trkBX-6,subDT);//subsec
00686             }
00687           }// loop on the tracks
00688           
00689         }//if (isCSCcand_){
00690       }//if (stub->getKeyWG() == 0) {
00691       
00692     }
00693   }
00694   // GP_end
00695   
00696 }