CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DQM/RPCMonitorDigi/src/RPCTTUMonitor.cc

Go to the documentation of this file.
00001 #include "DQM/RPCMonitorDigi/interface/RPCTTUMonitor.h"
00002 
00003 
00004 
00005 
00006 //
00007 RPCTTUMonitor::RPCTTUMonitor(const edm::ParameterSet& iConfig){
00008 
00009   ttuFolder    = iConfig.getUntrackedParameter<std::string>("TTUFolder", "RPC/TTU");
00010   outputFile    = iConfig.getUntrackedParameter<std::string>("OutPutFile", ""); 
00011   m_gtReadoutLabel     = iConfig.getParameter<edm::InputTag>("GTReadoutRcd");
00012   m_gmtReadoutLabel    = iConfig.getParameter<edm::InputTag>("GMTReadoutRcd");
00013   m_rpcTechTrigEmu     = iConfig.getParameter<edm::InputTag>("L1TTEmuBitsLabel");
00014   m_ttBits             = iConfig.getParameter< std::vector<unsigned> >("BitNumbers");
00015   m_maxttBits          = m_ttBits.size();
00016   
00017 }
00018 
00019 RPCTTUMonitor::~RPCTTUMonitor()
00020 {
00021   
00022 }
00023 
00024 // ------------ method called to for each event  ------------
00025 void
00026 RPCTTUMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00027 {
00028   
00029   //..............................................................................................
00030   // Data .
00031   edm::Handle< L1GlobalTriggerReadoutRecord > gtRecord;
00032   iEvent.getByLabel( m_gtReadoutLabel, gtRecord);
00033   
00034   if ( !gtRecord.isValid() ) {
00035     edm::LogError("RPCTTUMonitor") << "can't find L1GlobalTriggerRecord with label: " 
00036                                     << m_gtReadoutLabel << '\n';
00037     return;
00038   }
00039   
00040   // Emulator .
00041   edm::Handle< L1GtTechnicalTriggerRecord > emuTTRecord;
00042   iEvent.getByLabel( m_rpcTechTrigEmu , emuTTRecord);
00043   
00044   if ( !emuTTRecord.isValid() ) {
00045     edm::LogError("RPCTTUMonitor") << "can't find L1GtTechnicalTriggerRecord (emulator) with label: " 
00046                                     << m_rpcTechTrigEmu << '\n';
00047     return;
00048   }
00049   
00050   //..............................................................................................
00051   //
00052   //Timing difference between RPC-PAT and DT
00053   
00054   int dGMT(0);
00055   dGMT = discriminateGMT( iEvent , iSetup );
00056   if ( dGMT < 0 ) return;
00057   
00058   std::map<int,bool> ttuDec;
00059   std::map<int,bool>::iterator decItr;
00060   
00061   int bxX = iEvent.bunchCrossing(); // ... 1 to 3564
00062   
00063   for( int k=0; k < m_maxttBits; ++k) {
00064     for( int iebx=0; iebx<=2; iebx++) {
00065       const TechnicalTriggerWord gtTTWord = gtRecord->technicalTriggerWord(iebx-1);
00066       ttuDec[iebx-1] = gtTTWord[ 24+k ];
00067     }
00068   
00069     //. RPC
00070     if ( m_rpcTrigger ) {
00071       
00072       int ndec(0);
00073       int bx1 = (bxX - m_GMTcandidatesBx[0]);
00074       for( decItr = ttuDec.begin(); decItr != ttuDec.end(); ++decItr ){
00075         if ( (*decItr).second ) {
00076           int bx2 = (*decItr).first;
00077           float bxdiffPacTT = 1.0*( bx1 - bx2);
00078           m_bxDistDiffPac[k]->Fill( bxdiffPacTT );
00079           ++ndec;
00080         }
00081       }
00082     }
00083     
00084     //.. DT
00085     if ( m_dtTrigger ) {
00086       
00087       int ndec(0);
00088       int bx1 = (bxX - m_DTcandidatesBx[0]);
00089       for( decItr = ttuDec.begin(); decItr != ttuDec.end(); ++decItr ){
00090         if ( (*decItr).second ) {
00091           int bx2 = (*decItr).first;
00092           float bxdiffDtTT = 1.0*( bx1 - bx2);
00093           m_bxDistDiffDt[k]->Fill( bxdiffDtTT );
00094           ++ndec;
00095         }
00096       }
00097     }
00098     ttuDec.clear();
00099   
00100   }
00101 
00102   m_GMTcandidatesBx.clear();
00103   m_DTcandidatesBx.clear();
00104     
00105   //..............................................................................................
00106   //
00107   //... For Data Emulator comparison
00108 
00109   const TechnicalTriggerWord gtTTWord = gtRecord->technicalTriggerWord();
00110 
00111   std::vector<L1GtTechnicalTrigger> ttVec = emuTTRecord->gtTechnicalTrigger();
00112 
00113   std::vector<unsigned>::iterator bitsItr;
00114   int k = 0;
00115   //int m_BxWindow = 0;
00116   bool hasDataTrigger = false;
00117   bool hasEmulatorTrigger = false;
00118 
00119   if ( ttVec.size() <= 0 ) return;
00120   
00121   for ( bitsItr = m_ttBits.begin(); bitsItr != m_ttBits.end(); ++bitsItr ) {
00122     
00123     hasDataTrigger = gtTTWord.at( (*bitsItr) );
00124     m_ttBitsDecisionData->Fill( (*bitsItr), (int)hasDataTrigger  );
00125     
00126     hasEmulatorTrigger = ttVec[k].gtTechnicalTriggerResult();
00127     m_ttBitsDecisionEmulator->Fill( ttVec[k].gtTechnicalTriggerBitNumber(), (int)hasEmulatorTrigger );
00128     
00129     discriminateDecision(hasDataTrigger ,hasEmulatorTrigger  , k );
00130         
00131     ++k;
00132     
00133   }
00134   
00135 
00136 }
00137 
00138 int  RPCTTUMonitor::discriminateGMT( const edm::Event& iEvent, const edm::EventSetup& iSetup )
00139 {
00140   
00141   //.............................................................................................
00142   
00143   edm::Handle<L1MuGMTReadoutCollection> pCollection;
00144   iEvent.getByLabel(m_gmtReadoutLabel,pCollection);
00145   
00146   if ( ! pCollection.isValid() ) {
00147     edm::LogError("discriminateGMT") << "can't find L1MuGMTReadoutCollection with label "
00148                                      << m_gmtReadoutLabel ;
00149     return -1; 
00150   }
00151   
00152   //.............................................................................................
00153   
00154   int gmtDec(0);
00155   
00156   bool rpcBar_l1a  = false;
00157   bool dtBar_l1a   = false;
00158   
00159   m_dtTrigger  = false;
00160   m_rpcTrigger = false;
00161   
00162   // get GMT readout collection
00163   const L1MuGMTReadoutCollection * gmtRC = pCollection.product();
00164   
00165   // get record vector
00166   std::vector<L1MuGMTReadoutRecord>::const_iterator RRItr;
00167   std::vector<L1MuGMTReadoutRecord> gmt_records = gmtRC->getRecords();
00168   
00169   edm::LogInfo("DiscriminateGMT") << "nRecords: " << gmt_records.size() << '\n';
00170   
00171   for( RRItr = gmt_records.begin(); RRItr != gmt_records.end(); ++RRItr ) {
00172     
00173     int BxInEvent = RRItr->getBxInEvent();
00174     int BxInEventNew = RRItr->getBxNr();
00175     
00176     // RPC barrel muon candidates
00177     int nrpcB = 0;
00178     int ndtB  = 0;
00179     
00180     std::vector<L1MuRegionalCand> BrlRpcCands = RRItr->getBrlRPCCands();
00181     std::vector<L1MuRegionalCand> BrlDtCands  = RRItr->getDTBXCands ();
00182     
00183     std::vector<L1MuRegionalCand>::const_iterator RCItr;
00184     
00185     for( RCItr = BrlRpcCands.begin(); RCItr !=BrlRpcCands.end(); ++RCItr) {
00186       if ( !(*RCItr).empty() ) {
00187         
00188         m_GMTcandidatesBx.push_back( BxInEventNew );
00189         
00190         nrpcB++;
00191       }
00192     }
00193     
00194     for( RCItr = BrlDtCands.begin(); RCItr !=BrlDtCands.end(); ++RCItr) {
00195       if ( !(*RCItr).empty() ) {
00196         m_DTcandidatesBx.push_back( BxInEventNew );
00197         ndtB++;
00198       }
00199     }
00200     
00201     if( BxInEvent == 0 && nrpcB > 0) rpcBar_l1a = true;
00202     if( BxInEvent == 0 && ndtB > 0) dtBar_l1a = true;
00203     
00204   }
00205   
00206   if( rpcBar_l1a ) { 
00207     gmtDec = 1;
00208     m_rpcTrigger = true;
00209     
00210   }
00211   
00212   if( dtBar_l1a ) { 
00213     gmtDec = 2;
00214     m_dtTrigger = true;
00215   }
00216   
00217   return gmtDec;
00218   
00219 }
00220 
00221 void RPCTTUMonitor::discriminateDecision( bool data, bool emu , int indx ) 
00222 {
00223  
00224   if ( data == 1 && emu == 1 )
00225     m_dataVsemulator[indx]->Fill( 1 );
00226   
00227   if ( data == 1 && emu == 0 )
00228     m_dataVsemulator[indx]->Fill( 3 );
00229   
00230   if ( data == 0 && emu == 1 )
00231     m_dataVsemulator[indx]->Fill( 5 );
00232   
00233   if ( data == 0 && emu == 0 )
00234     m_dataVsemulator[indx]->Fill( 7 );
00235   
00236   
00237 }
00238 
00239 
00240 
00241 
00242 void  RPCTTUMonitor::beginJob(){
00243 
00244   dbe = edm::Service<DQMStore>().operator->();
00245   dbe->showDirStructure();
00246 
00247   
00248   dbe->setCurrentFolder(ttuFolder);
00249 
00250   
00251   m_ttBitsDecisionData = dbe->book1D("TechTrigger.Bits.Data",
00252                                              "Technical Trigger bits : Summary",
00253                                               10, 23, 33 );
00254 
00255   m_ttBitsDecisionEmulator =  dbe->book1D("TechTrigger.Bits.Emulator",
00256                                                  "Technical Trigger bits : Summary",
00257                                                  10, 23, 33 );
00258  for( int k=0; k < m_maxttBits; ++k) {
00259     
00260    std::ostringstream hname;
00261    
00262    hname << "BX.diff.PAC-TTU.bit." << m_ttBits[k];
00263    
00264    m_bxDistDiffPac[k] =  dbe->book1D(hname.str().c_str(),
00265                                              "Timing difference between PAC and TTU",
00266                                              7, -3, 3);
00267    
00268    hname.str("");
00269    
00270    hname << "BX.diff.DT-TTU.bit." << m_ttBits[k];
00271    
00272    m_bxDistDiffDt[k] =  dbe->book1D(hname.str().c_str(),
00273                                             "Timing difference between DT and TTU",
00274                                             7, -3, 3);
00275    
00276    hname.str("");
00277    
00278    hname << "Emu.Ttu.Compare.bit." << m_ttBits[k];
00279    
00280    m_dataVsemulator[k] =  dbe->book1D(hname.str().c_str(),
00281                                               "Comparison between emulator and TT decisions", 
00282                                               10, 0, 10 );
00283    
00284    hname.str("");
00285    
00286  }
00287 }
00288 
00289 void RPCTTUMonitor::beginRun(const edm::EventSetup& iSetup){
00290   
00291 }
00292 
00293 
00294 void 
00295 RPCTTUMonitor::endJob() {
00296 
00297   if(outputFile != "")
00298     dbe->save(outputFile);
00299 
00300   dbe=0;  
00301 }
00302 
00303