CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 /*
00002  * \file L1TRPCTF.cc
00003  *
00004  * $Date: 2009/11/19 14:40:13 $
00005  * $Revision: 1.31 $
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_rateUpdateTime( ps.getParameter< int >("rateUpdateTime") ),
00027    m_rateBinSize( ps.getParameter< int >("rateBinSize") ),
00028    m_rateNoOfBins( ps.getParameter< int >("rateNoOfBins") ),
00029    m_lastUsedBxInBxdiff(0),
00030    output_dir_ (ps.getUntrackedParameter<string>("output_dir") )
00031 //    m_rpcDigiWithBX0(0),
00032 //    m_rpcDigiWithBXnon0(0)
00033 
00034  {
00035 
00036   // verbosity switch
00037   verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
00038 
00039   if(verbose_) cout << "L1TRPCTF: constructor...." << endl;
00040 
00041 
00042   m_dbe = NULL;
00043   if ( ps.getUntrackedParameter<bool>("DQMStore", false) ) 
00044   {
00045     m_dbe = Service<DQMStore>().operator->();
00046     m_dbe->setVerbose(0);
00047   }
00048 
00049   outputFile_ = ps.getUntrackedParameter<string>("outputFile", "");
00050   if ( outputFile_.size() != 0 ) {
00051     cout << "L1T Monitoring histograms will be saved to " << outputFile_.c_str() << endl;
00052   }
00053 
00054   bool disable = ps.getUntrackedParameter<bool>("disableROOToutput", false);
00055   if(disable){
00056     outputFile_="";
00057   }
00058 
00059 
00060   if ( m_dbe !=NULL ) {
00061     m_dbe->setCurrentFolder(output_dir_);
00062   }
00063 
00064 
00065 
00066 }
00067 
00068 L1TRPCTF::~L1TRPCTF()
00069 {
00070 }
00071 
00072 void L1TRPCTF::beginJob(void)
00073 {
00074 
00075   nev_ = 0;
00076   nevRPC_ = 0;
00077 
00078   // get hold of back-end interface
00079   m_dbe = Service<DQMStore>().operator->();
00080 
00081   if ( m_dbe ) {
00082     m_dbe->setCurrentFolder(output_dir_);
00083     m_dbe->rmdir(output_dir_);
00084   }
00085 
00086 
00087   if ( m_dbe ) 
00088   {
00089     
00090 
00091     ostringstream oDir; oDir<< output_dir_ << "/CrateSynchroHistograms/";
00092     m_dbe->setCurrentFolder(oDir.str());
00093     for( unsigned int i = 0; i < 12; i++) {
00094       
00095        ostringstream o; o<<"RPCTF_crate_"<<i<<"_synchro";
00096        rpctfcratesynchro[i] = m_dbe->book2D(o.str(), o.str(), 5, -2.5, 2.5, 33, -16.5, 16.5);
00097        for (int bx = -2; bx < 3; ++bx){
00098           ostringstream b; b<<"BX="<<bx;
00099           rpctfcratesynchro[i]->setBinLabel(bx+3, b.str(),1);
00100        }
00101        rpctfcratesynchro[i]->setAxisTitle("Tower",2);
00102      
00103     }
00104     m_dbe->setCurrentFolder(output_dir_);
00105     
00106     rpctfetavalue[1] = m_dbe->book1D("RPCTF_eta_value_bx0", 
00107        "RPCTF eta value bx=0", 33, -16.5, 16.5 ) ;
00108     rpctfetavalue[2] = m_dbe->book1D("RPCTF_eta_value_bx+", 
00109        "RPCTF eta value bx>0", 33, -16.5, 16.5 ) ;
00110     rpctfetavalue[0] = m_dbe->book1D("RPCTF_eta_value_bx-", 
00111        "RPCTF eta value bx<0", 33, -16.5, 16.5 ) ;
00112     
00113     rpctfphivalue[1] = m_dbe->book1D("RPCTF_phi_value_bx0", 
00114        "RPCTF phi value bx=0", 144, -0.5, 143.5) ;
00115     rpctfphivalue[2] = m_dbe->book1D("RPCTF_phi_value_bx+", 
00116        "RPCTF phi value bx>0", 144, -0.5, 143.5 ) ;
00117     rpctfphivalue[0] = m_dbe->book1D("RPCTF_phi_value_bx-", 
00118        "RPCTF phi value bx<0", 144, -0.5, 143.5 ) ;
00119       
00120        
00121        
00122     rpctfptvalue[1] = m_dbe->book1D("RPCTF_pt_value_bx0", 
00123                                     "RPCTF pt value bx=0", 160, -0.5, 159.5 );
00124     rpctfptvalue[2] = m_dbe->book1D("RPCTF_pt_value_bx+", 
00125                                     "RPCTF pt value bx>0", 160, -0.5, 159.5 );
00126     rpctfptvalue[0] = m_dbe->book1D("RPCTF_pt_value_bx-", 
00127                                     "RPCTF pt value bx<0", 160, -0.5, 159.5 );
00128     
00129     
00130     rpctfchargevalue[1] = m_dbe->book1D("RPCTF_charge_value_bx0", 
00131                                         "RPCTF charge value bx=0", 3, -1.5, 1.5 ) ;
00132     rpctfchargevalue[2] = m_dbe->book1D("RPCTF_charge_value_bx+", 
00133                                         "RPCTF charge value bx>0", 3, -1.5, 1.5 ) ;
00134     rpctfchargevalue[0] = m_dbe->book1D("RPCTF_charge_value_bx-", 
00135                                         "RPCTF charge value bx<01", 3, -1.5, 1.5 ) ;
00136 
00137     rpctfquality[1] = m_dbe->book1D("RPCTF_quality", 
00138                                     "RPCTF quality bx=0", 6, -0.5, 5.5 ) ;
00139     rpctfquality[2] = m_dbe->book1D("RPCTF_quality_bx+", 
00140                                     "RPCTF quality bx>0", 6, -0.5, 5.5 ) ;
00141     rpctfquality[0] = m_dbe->book1D("RPCTF_quality_bx-", 
00142                                     "RPCTF quality bx<0", 6, -0.5, 5.5 ) ;
00143 
00144     rpctfntrack_b[1] = m_dbe->book1D("RPCTF_ntrack_brl_bx0", 
00145                                      "RPCTF number of tracks - barrel, bx=0", 5, -0.5, 4.5 ) ;
00146     rpctfntrack_b[2] = m_dbe->book1D("RPCTF_ntrack_brl_bx+", 
00147                                      "RPCTF number of tracks - barrel, bx>0", 5, -0.5, 4.5 ) ;
00148     rpctfntrack_b[0] = m_dbe->book1D("RPCTF_ntrack_brl_bx-", 
00149                                      "RPCTF number of tracks - barrel, bx<0", 5, -0.5, 4.5 ) ;
00150     
00151     
00152            
00153     rpctfntrack_e[1] = m_dbe->book1D("RPCTF_ntrack_fwd_bx0", 
00154                                      "RPCTF number of tracks - endcap, bx=0", 5, -0.5, 4.5 ) ;
00155     rpctfntrack_e[2] = m_dbe->book1D("RPCTF_ntrack_fwd_bx+", 
00156                                      "RPCTF number of tracks - endcap, bx>0", 5, -0.5, 4.5 ) ;
00157     rpctfntrack_e[0] = m_dbe->book1D("RPCTF_ntrack_fwd_bx-", 
00158                                      "RPCTF number of tracks - endcap, bx<0", 5, -0.5, 4.5 ) ;
00159 
00160     
00161                                         
00162        
00163 
00164     m_qualVsEta[1] = m_dbe->book2D("RPCTF_quality_vs_eta_bx0", 
00165                               "RPCTF quality vs eta, bx=0", 
00166                                33, -16.5, 16.5,
00167                                6, -0.5, 5.5); // Currently only 0...3 quals are possible
00168     m_qualVsEta[2] = m_dbe->book2D("RPCTF_quality_vs_eta_bx+", 
00169                                    "RPCTF quality vs eta, bx>0", 
00170                                    33, -16.5, 16.5,
00171                                    6, -0.5, 5.5); // Currently only 0...3 quals are possible
00172     m_qualVsEta[0] = m_dbe->book2D("RPCTF_quality_vs_eta_bx-", 
00173                                    "RPCTF quality vs eta, bx<0", 
00174                                    33, -16.5, 16.5,
00175                                    6, -0.5, 5.5); // Currently only 0...3 quals are possible
00176     
00177     
00178         
00179     m_muonsEtaPhi[1] = m_dbe->book2D("RPCTF_muons_eta_phi_bx0", 
00180                                   "RPCTF occupancy(eta,phi), bx=0",  
00181                                   33, -16.5, 16.5,
00182                                   144,  -0.5, 143.5);
00183     m_muonsEtaPhi[2] = m_dbe->book2D("RPCTF_muons_eta_phi_bx+", 
00184                                      "RPCTF occupancy(eta,phi), bx>0",  
00185                                      33, -16.5, 16.5,
00186                                      144,  -0.5, 143.5);
00187     m_muonsEtaPhi[0] = m_dbe->book2D("RPCTF_muons_eta_phi_bx-", 
00188                                      "RPCTF occupancy(eta,phi), bx<0",  
00189                                      33, -16.5, 16.5,
00190                                      144,  -0.5, 143.5);
00191 
00192     rpctfbx = m_dbe->book1D("RPCTF_bx", 
00193                             "RPCTF bx distribiution", 7, -3.5, 3.5 );
00194     
00195     //axis labels
00196     for (int l = 0; l<3; ++l){
00197       m_muonsEtaPhi[l]->setAxisTitle("tower",1);
00198       m_qualVsEta[l]->setAxisTitle("tower");
00199       rpctfetavalue[l]->setAxisTitle("tower");
00200       
00201       m_muonsEtaPhi[l]->setAxisTitle("phi",2);
00202       rpctfphivalue[l]->setAxisTitle("phi");
00203     }
00204     
00205     // set phi bin labels
00206     for (int i = 0; i < 12 ; ++i ){
00207        //float lPhi  = (30./360)*i*2*3.14;
00208       int lPhi  = 30*i;
00209       int lBin = int((30./360)*i*144)+1;
00210       std::stringstream ss;
00211       ss << "phi=" <<lPhi;
00212       for (int l = 0; l<3; ++l){
00213         rpctfphivalue[l]->setBinLabel(lBin,ss.str());
00214         m_muonsEtaPhi[l]->setBinLabel(lBin,ss.str(), 2);
00215       }
00216     }
00217 
00218     /*
00219     // set TC numbers on phi axis
00220     for (int tc = 0; tc < 12 ; ++tc ){
00221       int lBin  = (tc*12+3+1)%144;
00222       std::stringstream ss;
00223       ss << "TC" <<tc;
00224       for (int l = 0; l<3; ++l){
00225         rpctfphivalue[l]->setBinLabel(lBin,ss.str());
00226         m_muonsEtaPhi[l]->setBinLabel(lBin,ss.str(), 2);
00227       }
00228   }*/
00229 
00230         
00231     // set eta bin labels
00232     for (int i = -16; i < 17 ; ++i ){
00233       std::stringstream ss;
00234       ss << i;
00235       for (int l = 0; l<3; ++l){
00236         rpctfetavalue[l]->setBinLabel(i+17, ss.str());
00237         m_muonsEtaPhi[l]->setBinLabel(i+17, ss.str(), 1);
00238         m_qualVsEta[l]->setBinLabel(i+17, ss.str());
00239       }
00240     }
00241 
00242     
00243     
00244     m_rateMin = m_dbe->book1D("RPCTF_rate_min",
00245                               "RPCTrigger - minimal rate", m_rateNoOfBins, 0, m_rateNoOfBins); 
00246     
00247     m_rateMax = m_dbe->book1D("RPCTF_rate_max",
00248                               "RPCTrigger - peak rate", m_rateNoOfBins, 0, m_rateNoOfBins);
00249 
00250     m_rateAvg = m_dbe->book1D("RPCTF_rate_avg",
00251                               "RPCTrigger - average rate", m_rateNoOfBins, 0, m_rateNoOfBins); 
00252                               
00253     m_bxDiff = m_dbe->book1D("RPCTF_bx_diff",
00254                               "RPCTrigger - bx difference", 12000, -.5, 11999.5); 
00255    
00256 
00257 
00258   }   // if (m_dbe)
00259 }
00260 
00261 void L1TRPCTF::endRun(const edm::Run & r, const edm::EventSetup & c){
00262   
00263       fillRateHistos(0,true);
00264 
00265 
00266      // fixme, norm iteration would be better
00267      while (m_globBX.begin() !=  m_globBX.end() ) {
00268         long long int  diff = *m_globBX.begin()-m_lastUsedBxInBxdiff; // first entry will go to overflow bin, ignore
00269         m_bxDiff->Fill(diff);
00270         m_lastUsedBxInBxdiff = *m_globBX.begin();
00271         m_globBX.erase(m_globBX.begin());
00272 
00273      }
00274 
00275      
00276 }
00277 
00278 
00279 void L1TRPCTF::endJob(void)
00280 {
00281   
00282   if(verbose_) cout << "L1TRPCTF: end job...." << endl;
00283   LogInfo("EndJob") << "analyzed " << nev_ << " events"; 
00284 
00285   if ( outputFile_.size() != 0  && m_dbe ) m_dbe->save(outputFile_);
00286     
00287   return;
00288 
00289 }
00290 
00291 void L1TRPCTF::analyze(const Event& e, const EventSetup& c)
00292 {
00293   nev_++; 
00294   if(verbose_) cout << "L1TRPCTF: analyze...." << endl;
00295 
00296   edm::Handle<L1MuGMTReadoutCollection> pCollection;
00297   e.getByLabel(rpctfSource_,pCollection);
00298   
00299   if (!pCollection.isValid()) {
00300     edm::LogInfo("DataNotFound") << "can't find L1MuGMTReadoutCollection with label "
00301                                << rpctfSource_.label() ;
00302     return;
00303   }
00304 
00305   
00306   L1MuGMTReadoutCollection const* gmtrc = pCollection.product();
00307   vector<L1MuGMTReadoutRecord> gmt_records = gmtrc->getRecords();
00308   vector<L1MuGMTReadoutRecord>::const_iterator RRItr;
00309 
00310   std::vector<int> nrpctftrack_b(3,0);
00311   std::vector<int> nrpctftrack_e(3,0);
00312   bool rpcCandsPresentInEvent = false;
00313 
00314   vector<L1TRPCTF::BxDelays> all_bxdelays;
00315 
00316 
00317   for( RRItr = gmt_records.begin() ;
00318        RRItr != gmt_records.end() ;
00319        RRItr++ ) 
00320   {
00321     
00322    if (verbose_) cout << "Readout Record " << RRItr->getBxInEvent() << endl;
00323    
00324    vector<vector<L1MuRegionalCand> > brlAndFwdCands;
00325    brlAndFwdCands.push_back(RRItr->getBrlRPCCands());
00326    brlAndFwdCands.push_back(RRItr->getFwdRPCCands());
00327   
00328    int beIndex = 0;
00329    vector<vector<L1MuRegionalCand> >::iterator RPCTFCands = brlAndFwdCands.begin();
00330    for(; RPCTFCands!= brlAndFwdCands.end(); ++RPCTFCands)
00331    {
00332       
00333       for( vector<L1MuRegionalCand>::const_iterator 
00334           ECItr = RPCTFCands->begin() ;
00335           ECItr != RPCTFCands->end() ;
00336           ++ECItr ) 
00337       {
00338   
00339         int bxindex = 1 ; // bx == 0
00340         if (ECItr->bx() > 0) bxindex = 2;
00341         if (ECItr->bx() < 0) bxindex = 0;
00342         
00343         if (!ECItr->empty()) {
00344           
00345           rpcCandsPresentInEvent = true;
00346           
00347           if (beIndex == 0) ++nrpctftrack_b[bxindex];
00348           if (beIndex == 1) ++nrpctftrack_e[bxindex];
00349     
00350           if (verbose_) cout << "RPCTFCand bx " << ECItr->bx() << endl;
00351           
00352           int tower = ECItr->eta_packed();
00353           if (tower > 16) {
00354             tower = - ( (~tower & 63) + 1);
00355           }
00356 
00357           rpctfbx->Fill(ECItr->bx());
00358     
00359           rpctfetavalue[bxindex]->Fill(tower);
00360           if (verbose_) cout << "\tRPCTFCand eta value " << ECItr->etaValue() << endl;
00361   
00362           rpctfphivalue[bxindex]->Fill(ECItr->phi_packed());
00363           if (verbose_) cout << "\tRPCTFCand phi value " << ECItr->phiValue() << endl;
00364     
00365           rpctfptvalue[bxindex]->Fill(ECItr->ptValue());
00366           if (verbose_) cout << "\tRPCTFCand pt value " << ECItr->ptValue()<< endl;
00367     
00368           rpctfchargevalue[bxindex]->Fill(ECItr->chargeValue());
00369           if (verbose_) cout << "\tRPCTFCand charge value " << ECItr->chargeValue() << endl;
00370     
00371           rpctfquality[bxindex]->Fill(ECItr->quality());
00372           if (verbose_) cout << "\tRPCTFCand quality " << ECItr->quality() << endl;
00373           
00374 
00375           m_qualVsEta[bxindex]->Fill(tower, ECItr->quality());
00376           m_muonsEtaPhi[bxindex]->Fill(tower, ECItr->phi_packed());
00377 
00378           BxDelays bx_del;
00379           bx_del.bx = ECItr->bx();
00380           bx_del.eta_t = tower;
00381           bx_del.phi_p = ECItr->phi_packed();
00382           all_bxdelays.push_back(bx_del);
00383           
00384         } // if !empty
00385       } // end candidates iteration
00386       ++beIndex;
00387    } // end brl/endcap iteration
00388   } // end GMT records iteration
00389 
00390   for (int bxI = 0; bxI < 3; ++bxI){
00391     rpctfntrack_b[bxI]->Fill(nrpctftrack_b[bxI]);
00392     rpctfntrack_e[bxI]->Fill(nrpctftrack_e[bxI]);
00393   }
00394   
00395   
00396   if (rpcCandsPresentInEvent) {
00397     m_rateHelper.addOrbit(e.orbitNumber());
00398         
00399     unsigned int globBx = e.orbitNumber()*3564+e.bunchCrossing();
00400     if (m_globBX.find(globBx)==m_globBX.end()) m_globBX.insert(globBx);
00401     if (m_globBX.size()>1020){
00402       long long int diff = *m_globBX.begin()-m_lastUsedBxInBxdiff; // first entry will go to overflow bin, ignore
00403       m_bxDiff->Fill(diff);
00404       m_lastUsedBxInBxdiff = *m_globBX.begin();
00405       m_globBX.erase(m_globBX.begin());
00406     
00407     }
00408     
00409     
00410     
00411   }
00412 
00413 
00414    for(unsigned int i = 0; i < all_bxdelays.size(); i++) {
00415 
00416      int sector= ((all_bxdelays[i].phi_p+ 142)%144)/12;
00417      if (sector>11 || sector < 0) continue;
00418      int eta_tower = all_bxdelays[i].eta_t;
00419      for(unsigned int j = 0; j < all_bxdelays.size(); j++) {
00420        if(i == j) continue;
00421        int sector2= ((all_bxdelays[j].phi_p + 142)%144)/12;
00422  
00423        int distance_cut = 1;
00424        int distance = ((sector+12)-sector2)%12;
00425        distance = min(distance, 11-distance);
00426        if(distance<distance_cut) continue;
00427  
00428        int bxDiff = all_bxdelays[i].bx-all_bxdelays[j].bx;
00429        rpctfcratesynchro[sector]->Fill(bxDiff,eta_tower);
00430      }
00431 
00432   }
00433   fillRateHistos(e.orbitNumber());
00434   
00435   
00436         
00437 }
00438 
00439 
00442 void L1TRPCTF::fillRateHistos(int orbit, bool flush)
00443 {
00444   
00445   static bool flushed = false;
00446 
00447   if (flushed) {
00448     LogWarning("L1TRPCTF") << "Rate histos allready flushed \n";
00449   }
00450     
00451   if (flush) flushed = true;
00452   
00453 
00454   int nbinsUsed = 0;
00455   do  {
00456     nbinsUsed = 0;
00457     int et = m_rateHelper.getEarliestTime();
00458     if (et==-1) break;
00459     
00460     if ( (( m_rateHelper.getTimeForOrbit(orbit) - et > m_rateUpdateTime+m_rateBinSize)  // 1 minute bins
00461             && m_rateUpdateTime!=-1) || flush  )
00462     {
00463       
00464       
00465       int startTimeInMinutes=et/m_rateBinSize; 
00466       int bin = 0;
00467       std::pair<int, int> p; 
00468       int max = 0, min = 0;
00469       float avg=0;
00470       int curTimeInMinutes=startTimeInMinutes;
00471       while (curTimeInMinutes==startTimeInMinutes){
00472         p = m_rateHelper.removeAndGetRateForEarliestTime(); 
00473         if (p.first < 0) break; // no more items to analize, go fill histos
00474         
00475         if (nbinsUsed==0) {
00476           bin = p.first/m_rateBinSize+1;
00477           max = p.second;
00478           min = p.second;
00479         } else {
00480           if (max < p.second) max = p.second;
00481           if (min > p.second) min = p.second;
00482         }
00483         
00484         ++nbinsUsed;
00485         avg+=p.second;
00486         curTimeInMinutes=m_rateHelper.getEarliestTime()/m_rateBinSize;
00487       }
00488       
00489       
00490       avg/=m_rateBinSize;
00491       
00492       if (nbinsUsed > 0){
00493         m_rateAvg->setBinContent(bin,avg); // smallest possible value in f.first is 1
00494         m_rateMin->setBinContent(bin,min);
00495         m_rateMax->setBinContent(bin,max);
00496       }
00497     
00498     }
00499   } while (flush);
00500 
00501 
00502 
00503 }
00504 
00505 
00506 void L1TRPCTF::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg, 
00507                                     const edm::EventSetup& context)
00508 {
00509 //    m_rpcDigiWithBX0=0;
00510 //    m_rpcDigiWithBXnon0=0;
00511 //    m_bxs.clear();
00512 //    m_useRpcDigi = true;
00513 
00514                           
00515 }
00516 
00517 
00518 void L1TRPCTF::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, 
00519                         const edm::EventSetup& c)
00520 {
00521 
00522 }
00523