CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/DQM/L1TMonitor/src/L1TRPCTF.cc

Go to the documentation of this file.
00001 /*
00002  * \file L1TRPCTF.cc
00003  *
00004  * $Date: 2011/11/15 13:31:37 $
00005  * $Revision: 1.33 $
00006  * \author J. Berryhill
00007  *
00008  */
00009 
00010 #include "DQM/L1TMonitor/interface/L1TRPCTF.h"
00011 #include "DQMServices/Core/interface/DQMStore.h"
00012 
00013 #include "DataFormats/RPCDigi/interface/RPCDigi.h"
00014 #include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"
00015 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00016 
00017 #include <sstream>
00018 using namespace std;
00019 using namespace edm;
00020 
00021 L1TRPCTF::L1TRPCTF(const ParameterSet& ps)
00022   : rpctfSource_( ps.getParameter< InputTag >("rpctfSource") ),
00023 //    digiSource_( ps.getParameter< InputTag >("rpctfRPCDigiSource") ),
00024 //   m_rpcDigiFine(false),
00025 //    m_useRpcDigi(true),
00026    m_lastUsedBxInBxdiff(0),
00027    output_dir_ (ps.getUntrackedParameter<string>("output_dir") )
00028 //    m_rpcDigiWithBX0(0),
00029 //    m_rpcDigiWithBXnon0(0)
00030 
00031  {
00032 
00033   // verbosity switch
00034   verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
00035 
00036   if(verbose_) cout << "L1TRPCTF: constructor...." << endl;
00037 
00038 
00039   m_dbe = NULL;
00040   if ( ps.getUntrackedParameter<bool>("DQMStore", false) ) 
00041   {
00042     m_dbe = Service<DQMStore>().operator->();
00043     m_dbe->setVerbose(0);
00044   }
00045 
00046   outputFile_ = ps.getUntrackedParameter<string>("outputFile", "");
00047   if ( outputFile_.size() != 0 ) {
00048     cout << "L1T Monitoring histograms will be saved to " << outputFile_.c_str() << endl;
00049   }
00050 
00051   bool disable = ps.getUntrackedParameter<bool>("disableROOToutput", false);
00052   if(disable){
00053     outputFile_="";
00054   }
00055 
00056 
00057   if ( m_dbe !=NULL ) {
00058     m_dbe->setCurrentFolder(output_dir_);
00059   }
00060 
00061 
00062 
00063 }
00064 
00065 L1TRPCTF::~L1TRPCTF()
00066 {
00067 }
00068 
00069 void L1TRPCTF::beginJob(void)
00070 {
00071 
00072   nev_ = 0;
00073   nevRPC_ = 0;
00074 
00075   // get hold of back-end interface
00076   m_dbe = Service<DQMStore>().operator->();
00077 
00078   if ( m_dbe ) {
00079     m_dbe->setCurrentFolder(output_dir_);
00080     m_dbe->rmdir(output_dir_);
00081   }
00082 
00083 
00084   if ( m_dbe ) 
00085   {
00086     
00087 
00088     ostringstream oDir; oDir<< output_dir_ << "/CrateSynchroHistograms/";
00089     m_dbe->setCurrentFolder(oDir.str());
00090     for( unsigned int i = 0; i < 12; i++) {
00091       
00092        ostringstream o; o<<"RPCTF_crate_"<<i<<"_synchro";
00093        rpctfcratesynchro[i] = m_dbe->book2D(o.str(), o.str(), 5, -2.5, 2.5, 33, -16.5, 16.5);
00094        for (int bx = -2; bx < 3; ++bx){
00095           ostringstream b; b<<"BX="<<bx;
00096           rpctfcratesynchro[i]->setBinLabel(bx+3, b.str(),1);
00097        }
00098        rpctfcratesynchro[i]->setAxisTitle("Tower",2);
00099      
00100     }
00101     m_dbe->setCurrentFolder(output_dir_);
00102     
00103     rpctfetavalue[1] = m_dbe->book1D("RPCTF_eta_value_bx0", 
00104        "RPCTF eta value bx=0", 33, -16.5, 16.5 ) ;
00105     rpctfetavalue[2] = m_dbe->book1D("RPCTF_eta_value_bx+", 
00106        "RPCTF eta value bx>0", 33, -16.5, 16.5 ) ;
00107     rpctfetavalue[0] = m_dbe->book1D("RPCTF_eta_value_bx-", 
00108        "RPCTF eta value bx<0", 33, -16.5, 16.5 ) ;
00109     
00110     rpctfphivalue[1] = m_dbe->book1D("RPCTF_phi_value_bx0", 
00111        "RPCTF phi value bx=0", 144, -0.5, 143.5) ;
00112     rpctfphivalue[2] = m_dbe->book1D("RPCTF_phi_value_bx+", 
00113        "RPCTF phi value bx>0", 144, -0.5, 143.5 ) ;
00114     rpctfphivalue[0] = m_dbe->book1D("RPCTF_phi_value_bx-", 
00115        "RPCTF phi value bx<0", 144, -0.5, 143.5 ) ;
00116       
00117        
00118        
00119     rpctfptvalue[1] = m_dbe->book1D("RPCTF_pt_value_bx0", 
00120                                     "RPCTF pt value bx=0", 160, -0.5, 159.5 );
00121     rpctfptvalue[2] = m_dbe->book1D("RPCTF_pt_value_bx+", 
00122                                     "RPCTF pt value bx>0", 160, -0.5, 159.5 );
00123     rpctfptvalue[0] = m_dbe->book1D("RPCTF_pt_value_bx-", 
00124                                     "RPCTF pt value bx<0", 160, -0.5, 159.5 );
00125     
00126     
00127     rpctfchargevalue[1] = m_dbe->book1D("RPCTF_charge_value_bx0", 
00128                                         "RPCTF charge value bx=0", 3, -1.5, 1.5 ) ;
00129     rpctfchargevalue[2] = m_dbe->book1D("RPCTF_charge_value_bx+", 
00130                                         "RPCTF charge value bx>0", 3, -1.5, 1.5 ) ;
00131     rpctfchargevalue[0] = m_dbe->book1D("RPCTF_charge_value_bx-", 
00132                                         "RPCTF charge value bx<01", 3, -1.5, 1.5 ) ;
00133 
00134     rpctfquality[1] = m_dbe->book1D("RPCTF_quality", 
00135                                     "RPCTF quality bx=0", 6, -0.5, 5.5 ) ;
00136     rpctfquality[2] = m_dbe->book1D("RPCTF_quality_bx+", 
00137                                     "RPCTF quality bx>0", 6, -0.5, 5.5 ) ;
00138     rpctfquality[0] = m_dbe->book1D("RPCTF_quality_bx-", 
00139                                     "RPCTF quality bx<0", 6, -0.5, 5.5 ) ;
00140 
00141     rpctfntrack_b[1] = m_dbe->book1D("RPCTF_ntrack_brl_bx0", 
00142                                      "RPCTF number of tracks - barrel, bx=0", 5, -0.5, 4.5 ) ;
00143     rpctfntrack_b[2] = m_dbe->book1D("RPCTF_ntrack_brl_bx+", 
00144                                      "RPCTF number of tracks - barrel, bx>0", 5, -0.5, 4.5 ) ;
00145     rpctfntrack_b[0] = m_dbe->book1D("RPCTF_ntrack_brl_bx-", 
00146                                      "RPCTF number of tracks - barrel, bx<0", 5, -0.5, 4.5 ) ;
00147     
00148     
00149            
00150     rpctfntrack_e[1] = m_dbe->book1D("RPCTF_ntrack_fwd_bx0", 
00151                                      "RPCTF number of tracks - endcap, bx=0", 5, -0.5, 4.5 ) ;
00152     rpctfntrack_e[2] = m_dbe->book1D("RPCTF_ntrack_fwd_bx+", 
00153                                      "RPCTF number of tracks - endcap, bx>0", 5, -0.5, 4.5 ) ;
00154     rpctfntrack_e[0] = m_dbe->book1D("RPCTF_ntrack_fwd_bx-", 
00155                                      "RPCTF number of tracks - endcap, bx<0", 5, -0.5, 4.5 ) ;
00156 
00157     
00158                                         
00159        
00160 
00161     m_qualVsEta[1] = m_dbe->book2D("RPCTF_quality_vs_eta_bx0", 
00162                               "RPCTF quality vs eta, bx=0", 
00163                                33, -16.5, 16.5,
00164                                6, -0.5, 5.5); // Currently only 0...3 quals are possible
00165     m_qualVsEta[2] = m_dbe->book2D("RPCTF_quality_vs_eta_bx+", 
00166                                    "RPCTF quality vs eta, bx>0", 
00167                                    33, -16.5, 16.5,
00168                                    6, -0.5, 5.5); // Currently only 0...3 quals are possible
00169     m_qualVsEta[0] = m_dbe->book2D("RPCTF_quality_vs_eta_bx-", 
00170                                    "RPCTF quality vs eta, bx<0", 
00171                                    33, -16.5, 16.5,
00172                                    6, -0.5, 5.5); // Currently only 0...3 quals are possible
00173     
00174     
00175         
00176     m_muonsEtaPhi[1] = m_dbe->book2D("RPCTF_muons_eta_phi_bx0", 
00177                                   "RPCTF occupancy(eta,phi), bx=0",  
00178                                   33, -16.5, 16.5,
00179                                   144,  -0.5, 143.5);
00180     m_muonsEtaPhi[2] = m_dbe->book2D("RPCTF_muons_eta_phi_bx+", 
00181                                      "RPCTF occupancy(eta,phi), bx>0",  
00182                                      33, -16.5, 16.5,
00183                                      144,  -0.5, 143.5);
00184     m_muonsEtaPhi[0] = m_dbe->book2D("RPCTF_muons_eta_phi_bx-", 
00185                                      "RPCTF occupancy(eta,phi), bx<0",  
00186                                      33, -16.5, 16.5,
00187                                      144,  -0.5, 143.5);
00188 
00189     rpctfbx = m_dbe->book1D("RPCTF_bx", 
00190                             "RPCTF bx distribiution", 7, -3.5, 3.5 );
00191     
00192     //axis labels
00193     for (int l = 0; l<3; ++l){
00194       m_muonsEtaPhi[l]->setAxisTitle("tower",1);
00195       m_qualVsEta[l]->setAxisTitle("tower");
00196       rpctfetavalue[l]->setAxisTitle("tower");
00197       
00198       m_muonsEtaPhi[l]->setAxisTitle("phi",2);
00199       rpctfphivalue[l]->setAxisTitle("phi");
00200     }
00201     
00202     // set phi bin labels
00203     for (int i = 0; i < 12 ; ++i ){
00204        //float lPhi  = (30./360)*i*2*3.14;
00205       int lPhi  = 30*i;
00206       int lBin = int((30./360)*i*144)+1;
00207       std::stringstream ss;
00208       ss << "phi=" <<lPhi;
00209       for (int l = 0; l<3; ++l){
00210         rpctfphivalue[l]->setBinLabel(lBin,ss.str());
00211         m_muonsEtaPhi[l]->setBinLabel(lBin,ss.str(), 2);
00212       }
00213     }
00214 
00215     /*
00216     // set TC numbers on phi axis
00217     for (int tc = 0; tc < 12 ; ++tc ){
00218       int lBin  = (tc*12+3+1)%144;
00219       std::stringstream ss;
00220       ss << "TC" <<tc;
00221       for (int l = 0; l<3; ++l){
00222         rpctfphivalue[l]->setBinLabel(lBin,ss.str());
00223         m_muonsEtaPhi[l]->setBinLabel(lBin,ss.str(), 2);
00224       }
00225   }*/
00226 
00227         
00228     // set eta bin labels
00229     for (int i = -16; i < 17 ; ++i ){
00230       std::stringstream ss;
00231       ss << i;
00232       for (int l = 0; l<3; ++l){
00233         rpctfetavalue[l]->setBinLabel(i+17, ss.str());
00234         m_muonsEtaPhi[l]->setBinLabel(i+17, ss.str(), 1);
00235         m_qualVsEta[l]->setBinLabel(i+17, ss.str());
00236       }
00237     }
00238 
00239     
00240                               
00241     m_bxDiff = m_dbe->book1D("RPCTF_bx_diff",
00242                               "RPCTrigger - bx difference", 12000, -.5, 11999.5); 
00243    
00244 
00245 
00246   }   // if (m_dbe)
00247 }
00248 
00249 void L1TRPCTF::endRun(const edm::Run & r, const edm::EventSetup & c){
00250   
00251 
00252 
00253      // fixme, norm iteration would be better
00254      while (m_globBX.begin() !=  m_globBX.end() ) {
00255         long long int  diff = *m_globBX.begin()-m_lastUsedBxInBxdiff; // first entry will go to overflow bin, ignore
00256         m_bxDiff->Fill(diff);
00257         m_lastUsedBxInBxdiff = *m_globBX.begin();
00258         m_globBX.erase(m_globBX.begin());
00259 
00260      }
00261 
00262      
00263 }
00264 
00265 
00266 void L1TRPCTF::endJob(void)
00267 {
00268   
00269   if(verbose_) cout << "L1TRPCTF: end job...." << endl;
00270   LogInfo("EndJob") << "analyzed " << nev_ << " events"; 
00271 
00272   if ( outputFile_.size() != 0  && m_dbe ) m_dbe->save(outputFile_);
00273     
00274   return;
00275 
00276 }
00277 
00278 void L1TRPCTF::analyze(const Event& e, const EventSetup& c)
00279 {
00280   nev_++; 
00281   if(verbose_) cout << "L1TRPCTF: analyze...." << endl;
00282 
00283   edm::Handle<L1MuGMTReadoutCollection> pCollection;
00284   e.getByLabel(rpctfSource_,pCollection);
00285   
00286   if (!pCollection.isValid()) {
00287     edm::LogInfo("DataNotFound") << "can't find L1MuGMTReadoutCollection with label "
00288                                << rpctfSource_.label() ;
00289     return;
00290   }
00291 
00292   
00293   L1MuGMTReadoutCollection const* gmtrc = pCollection.product();
00294   vector<L1MuGMTReadoutRecord> gmt_records = gmtrc->getRecords();
00295   vector<L1MuGMTReadoutRecord>::const_iterator RRItr;
00296 
00297   std::vector<int> nrpctftrack_b(3,0);
00298   std::vector<int> nrpctftrack_e(3,0);
00299 
00300   vector<L1TRPCTF::BxDelays> all_bxdelays;
00301 
00302 
00303   for( RRItr = gmt_records.begin() ;
00304        RRItr != gmt_records.end() ;
00305        RRItr++ ) 
00306   {
00307     
00308    if (verbose_) cout << "Readout Record " << RRItr->getBxInEvent() << endl;
00309    
00310    vector<vector<L1MuRegionalCand> > brlAndFwdCands;
00311    brlAndFwdCands.push_back(RRItr->getBrlRPCCands());
00312    brlAndFwdCands.push_back(RRItr->getFwdRPCCands());
00313   
00314    int beIndex = 0;
00315    vector<vector<L1MuRegionalCand> >::iterator RPCTFCands = brlAndFwdCands.begin();
00316    for(; RPCTFCands!= brlAndFwdCands.end(); ++RPCTFCands)
00317    {
00318       
00319       for( vector<L1MuRegionalCand>::const_iterator 
00320           ECItr = RPCTFCands->begin() ;
00321           ECItr != RPCTFCands->end() ;
00322           ++ECItr ) 
00323       {
00324   
00325         int bxindex = 1 ; // bx == 0
00326         if (ECItr->bx() > 0) bxindex = 2;
00327         if (ECItr->bx() < 0) bxindex = 0;
00328         
00329         if (!ECItr->empty()) {
00330           
00331           
00332           if (beIndex == 0) ++nrpctftrack_b[bxindex];
00333           if (beIndex == 1) ++nrpctftrack_e[bxindex];
00334     
00335           if (verbose_) cout << "RPCTFCand bx " << ECItr->bx() << endl;
00336           
00337           int tower = ECItr->eta_packed();
00338           if (tower > 16) {
00339             tower = - ( (~tower & 63) + 1);
00340           }
00341 
00342           rpctfbx->Fill(ECItr->bx());
00343     
00344           rpctfetavalue[bxindex]->Fill(tower);
00345           if (verbose_) cout << "\tRPCTFCand eta value " << ECItr->etaValue() << endl;
00346   
00347           rpctfphivalue[bxindex]->Fill(ECItr->phi_packed());
00348           if (verbose_) cout << "\tRPCTFCand phi value " << ECItr->phiValue() << endl;
00349     
00350           rpctfptvalue[bxindex]->Fill(ECItr->ptValue());
00351           if (verbose_) cout << "\tRPCTFCand pt value " << ECItr->ptValue()<< endl;
00352     
00353           rpctfchargevalue[bxindex]->Fill(ECItr->chargeValue());
00354           if (verbose_) cout << "\tRPCTFCand charge value " << ECItr->chargeValue() << endl;
00355     
00356           rpctfquality[bxindex]->Fill(ECItr->quality());
00357           if (verbose_) cout << "\tRPCTFCand quality " << ECItr->quality() << endl;
00358           
00359 
00360           m_qualVsEta[bxindex]->Fill(tower, ECItr->quality());
00361           m_muonsEtaPhi[bxindex]->Fill(tower, ECItr->phi_packed());
00362 
00363           BxDelays bx_del;
00364           bx_del.bx = ECItr->bx();
00365           bx_del.eta_t = tower;
00366           bx_del.phi_p = ECItr->phi_packed();
00367           all_bxdelays.push_back(bx_del);
00368           
00369         } // if !empty
00370       } // end candidates iteration
00371       ++beIndex;
00372    } // end brl/endcap iteration
00373   } // end GMT records iteration
00374 
00375   for (int bxI = 0; bxI < 3; ++bxI){
00376     rpctfntrack_b[bxI]->Fill(nrpctftrack_b[bxI]);
00377     rpctfntrack_e[bxI]->Fill(nrpctftrack_e[bxI]);
00378   }
00379   
00380   
00381    for(unsigned int i = 0; i < all_bxdelays.size(); i++) {
00382 
00383      int sector= ((all_bxdelays[i].phi_p+ 142)%144)/12;
00384      if (sector>11 || sector < 0) continue;
00385      int eta_tower = all_bxdelays[i].eta_t;
00386      for(unsigned int j = 0; j < all_bxdelays.size(); j++) {
00387        if(i == j) continue;
00388        int sector2= ((all_bxdelays[j].phi_p + 142)%144)/12;
00389  
00390        int distance_cut = 1;
00391        int distance = ((sector+12)-sector2)%12;
00392        distance = min(distance, 11-distance);
00393        if(distance<distance_cut) continue;
00394  
00395        int bxDiff = all_bxdelays[i].bx-all_bxdelays[j].bx;
00396        rpctfcratesynchro[sector]->Fill(bxDiff,eta_tower);
00397      }
00398 
00399   }
00400   
00401   
00402         
00403 }
00404 
00405 void L1TRPCTF::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg, 
00406                                     const edm::EventSetup& context)
00407 {
00408 //    m_rpcDigiWithBX0=0;
00409 //    m_rpcDigiWithBXnon0=0;
00410 //    m_bxs.clear();
00411 //    m_useRpcDigi = true;
00412 
00413                           
00414 }
00415 
00416 
00417 void L1TRPCTF::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, 
00418                         const edm::EventSetup& c)
00419 {
00420 
00421 }
00422