CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DQM/HcalMonitorTasks/src/HcalDetDiagTimingMonitor.cc

Go to the documentation of this file.
00001 #include "DQM/HcalMonitorTasks/interface/HcalDetDiagTimingMonitor.h"
00002 
00003 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00004 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00005 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00006 #include "DataFormats/HcalDigi/interface/HcalCalibrationEventTypes.h"
00007 #include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h"
00008 
00009 #include <math.h>
00010 
00011 // this is to retrieve HCAL digi's
00012 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00013 // this is to retrieve GT digi's 
00014 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuRegionalCand.h"
00015 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutCollection.h"
00016 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00017 #include "DataFormats/L1GlobalTrigger/interface/L1GtPsbWord.h"
00018 #include "DataFormats/L1GlobalTrigger/interface/L1GtFdlWord.h"
00019 
00020 
00021 
00023 static const float adc2fC[128]={-0.5,0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5, 10.5,11.5,12.5,
00024                    13.5,15.,17.,19.,21.,23.,25.,27.,29.5,32.5,35.5,38.5,42.,46.,50.,54.5,59.5,
00025                    64.5,59.5,64.5,69.5,74.5,79.5,84.5,89.5,94.5,99.5,104.5,109.5,114.5,119.5,
00026                    124.5,129.5,137.,147.,157.,167.,177.,187.,197.,209.5,224.5,239.5,254.5,272.,
00027                    292.,312.,334.5,359.5,384.5,359.5,384.5,409.5,434.5,459.5,484.5,509.5,534.5,
00028                    559.5,584.5,609.5,634.5,659.5,684.5,709.5,747.,797.,847.,897.,947.,997.,
00029                    1047.,1109.5,1184.5,1259.5,1334.5,1422.,1522.,1622.,1734.5,1859.5,1984.5,
00030                    1859.5,1984.5,2109.5,2234.5,2359.5,2484.5,2609.5,2734.5,2859.5,2984.5,
00031                    3109.5,3234.5,3359.5,3484.5,3609.5,3797.,4047.,4297.,4547.,4797.,5047.,
00032                    5297.,5609.5,5984.5,6359.5,6734.5,7172.,7672.,8172.,8734.5,9359.5,9984.5};
00034 static const int MAXGEN =10;
00035 static const int MAXRPC =20;
00036 static const int MAXDTBX=20;
00037 static const int MAXCSC =20;    
00038 static const int MAXGMT =20;
00039 static const int TRIG_DT =1;
00040 static const int TRIG_RPC=2;
00041 static const int TRIG_GCT=4;
00042 static const int TRIG_CSC=8;
00043 static const int TRIG_RPCF=16;
00044 
00045 HcalDetDiagTimingMonitor::HcalDetDiagTimingMonitor(const edm::ParameterSet& ps) 
00046 {
00047   Online_                = ps.getUntrackedParameter<bool>("online",false);
00048   mergeRuns_             = ps.getUntrackedParameter<bool>("mergeRuns",false);
00049   enableCleanup_         = ps.getUntrackedParameter<bool>("enableCleanup",false);
00050   debug_                 = ps.getUntrackedParameter<int>("debug",0);
00051   prefixME_              = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
00052   if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
00053     prefixME_.append("/");
00054   subdir_                = ps.getUntrackedParameter<std::string>("TaskFolder","DetDiagTimingMonitor_Hcal");
00055   if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
00056     subdir_.append("/");
00057   subdir_=prefixME_+subdir_;
00058   AllowedCalibTypes_     = ps.getUntrackedParameter<std::vector<int> > ("AllowedCalibTypes");
00059   skipOutOfOrderLS_      = ps.getUntrackedParameter<bool>("skipOutOfOrderLS","false");
00060   NLumiBlocks_           = ps.getUntrackedParameter<int>("NLumiBlocks",4000);
00061   makeDiagnostics_       = ps.getUntrackedParameter<bool>("makeDiagnostics",false);
00062 
00063   GCTTriggerBit1_= ps.getUntrackedParameter<int>("GCTTriggerBit1", 15);         
00064   GCTTriggerBit2_= ps.getUntrackedParameter<int>("GCTTriggerBit2", 16);         
00065   GCTTriggerBit3_= ps.getUntrackedParameter<int>("GCTTriggerBit3", 17);         
00066   GCTTriggerBit4_= ps.getUntrackedParameter<int>("GCTTriggerBit4", 18);         
00067   GCTTriggerBit5_= ps.getUntrackedParameter<int>("GCTTriggerBit5", 16);         
00068   CosmicsCorr_   = ps.getUntrackedParameter<bool>("CosmicsCorr", true); 
00069   
00070   L1ADataLabel_  = ps.getUntrackedParameter<edm::InputTag>("gtLabel");
00071   inputLabelDigi_= ps.getUntrackedParameter<edm::InputTag>("digiLabel");
00072   FEDRawDataCollection_ = ps.getUntrackedParameter<edm::InputTag>("FEDRawDataCollection",edm::InputTag("source",""));
00073 }
00074 
00075 HcalDetDiagTimingMonitor::~HcalDetDiagTimingMonitor(){}
00076 
00077 void HcalDetDiagTimingMonitor::cleanup(){
00078   if(dbe_){
00079     dbe_->setCurrentFolder(subdir_);
00080     dbe_->removeContents();
00081     dbe_ = 0;
00082   }
00083 } 
00084 void HcalDetDiagTimingMonitor::reset(){}
00085 
00086 void HcalDetDiagTimingMonitor::beginRun(const edm::Run& run, const edm::EventSetup& c)
00087 {
00088   if (debug_>1) std::cout <<"HcalDetDiagTimingMonitor::beginRun"<<std::endl;
00089   HcalBaseDQMonitor::beginRun(run,c);
00090 
00091   if (tevt_==0) this->setup(); // set up histograms if they have not been created before
00092   if (mergeRuns_==false)
00093     this->reset();
00094 
00095   return;
00096 
00097 } // void HcalNDetDiagTimingMonitor::beginRun(...)
00098 
00099 
00100 
00101 void HcalDetDiagTimingMonitor::setup()
00102 {
00103   
00104   HcalBaseDQMonitor::setup();
00105 
00106   std::string str;
00107   if(dbe_!=NULL){    
00108      dbe_->setCurrentFolder(subdir_);   
00109      str="Hcal Timing summary"; Summary = dbe_->book2D(str,str,6,0,6,6,0,6); 
00110      Summary->setBinLabel(1,"DT",1);
00111      Summary->setBinLabel(2,"RPC",1);
00112      Summary->setBinLabel(3,"GCT",1);
00113      Summary->setBinLabel(4,"CSC",1);
00114      Summary->setBinLabel(5,"RPCf",1);
00115      Summary->setBinLabel(6,"bit11",1);
00116      Summary->setBinLabel(1,"HB",2);
00117      Summary->setBinLabel(2,"HO",2);
00118      Summary->setBinLabel(3,"HEM",2);
00119      Summary->setBinLabel(4,"HEP",2);
00120      Summary->setBinLabel(5,"HFM",2);
00121      Summary->setBinLabel(6,"HFP",2);
00122      for(int i=1;i<=6;i++) for(int j=1;j<=6;j++) Summary->setBinContent(i,j,-1);
00123      
00124      dbe_->setCurrentFolder(subdir_+"Timing Plots");
00125      str="HB Timing (DT Trigger)";                      HBTimeDT  = dbe_->book1D(str,str,100,0,10); 
00126      str="HO Timing (DT Trigger)";                      HOTimeDT  = dbe_->book1D(str,str,100,0,10); 
00127      str="HB Timing (RPC Trigger)";                     HBTimeRPC = dbe_->book1D(str,str,100,0,10); 
00128      str="HO Timing (RPC Trigger)";                     HOTimeRPC = dbe_->book1D(str,str,100,0,10); 
00129      str="HB Timing (HO SelfTrigger tech bit 11)";      HBTimeHO  = dbe_->book1D(str,str,100,0,10); 
00130      str="HO Timing (HO SelfTrigger tech bit 11)";      HOTimeHO  = dbe_->book1D(str,str,100,0,10); 
00131      
00132      str="HB Timing (GCT Trigger alg bit 15 16 17 18)"; HBTimeGCT  =dbe_->book1D(str,str,100,0,10); 
00133      str="HB Timing (GCT Trigger alg bit 15 16 17 18)"; HOTimeGCT  =dbe_->book1D(str,str,100,0,10); 
00134      
00135      str="HEP Timing (CSC Trigger)";                    HETimeCSCp =dbe_->book1D(str,str,100,0,10); 
00136      str="HEM Timing (CSC Trigger)";                    HETimeCSCm =dbe_->book1D(str,str,100,0,10);
00137      str="HEP Timing (RPCf Trigger)";                   HETimeRPCp =dbe_->book1D(str,str,100,0,10); 
00138      str="HEM Timing (RPCf Trigger)";                   HETimeRPCm =dbe_->book1D(str,str,100,0,10);
00139      str="HFP Timing (CSC Trigger)";                    HFTimeCSCp =dbe_->book1D(str,str,100,0,10); 
00140      str="HFM Timing (CSC Trigger)";                    HFTimeCSCm =dbe_->book1D(str,str,100,0,10);     
00141   }   
00142 } 
00143 
00144 void HcalDetDiagTimingMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00145 {
00146   if (!IsAllowedCalibType()) return;
00147   if (LumiInOrder(iEvent.luminosityBlock())==false) return;
00148   HcalBaseDQMonitor::analyze(iEvent, iSetup);
00149   
00150   
00151   int eta,phi,depth,nTS,BXinEVENT=1,TRIGGER=0;
00152   
00153   if(!dbe_) return;
00154   // We do not want to look at Abort Gap events
00155   edm::Handle<FEDRawDataCollection> rawdata;
00156   iEvent.getByLabel(FEDRawDataCollection_,rawdata);
00157   //checking FEDs for calibration information
00158   if(!rawdata.isValid()) return;
00159   for(int i=FEDNumbering::MINHCALFEDID;i<=FEDNumbering::MAXHCALFEDID; i++) {
00160     const FEDRawData& fedData = rawdata->FEDData(i) ;
00161     if ( fedData.size() < 24 ) continue ;
00162     if(((const HcalDCCHeader*)(fedData.data()))->getCalibType()!=hc_Null) return;
00163   }
00164    
00167   bool GCTTrigger1=false,GCTTrigger2=false,GCTTrigger3=false,GCTTrigger4=false,GCTTrigger5=false,HOselfTrigger=false;
00168   // Check GCT trigger bits
00169   edm::Handle< L1GlobalTriggerReadoutRecord > gtRecord;
00170   iEvent.getByLabel(L1ADataLabel_, gtRecord);
00171   if(gtRecord.isValid()){
00172     const TechnicalTriggerWord tWord = gtRecord->technicalTriggerWord();
00173     const DecisionWord         dWord = gtRecord->decisionWord();
00174     //bool HFselfTrigger   = tWord.at(9);
00175     HOselfTrigger    = tWord.at(11);
00176         
00177     GCTTrigger1      = dWord.at(GCTTriggerBit1_);     
00178     GCTTrigger2      = dWord.at(GCTTriggerBit2_);     
00179     GCTTrigger3      = dWord.at(GCTTriggerBit3_);     
00180     GCTTrigger4      = dWord.at(GCTTriggerBit4_);     
00181     GCTTrigger5      = dWord.at(GCTTriggerBit5_);     
00182    
00183     // define trigger trigger source (example from GMT group)
00184     edm::Handle<L1MuGMTReadoutCollection> gmtrc_handle; 
00185     iEvent.getByLabel(L1ADataLabel_,gmtrc_handle);
00186     if(!gmtrc_handle.isValid()) return;
00187     L1MuGMTReadoutCollection const* gmtrc = gmtrc_handle.product();
00188    
00189     int idt   =0;
00190     int icsc  =0;
00191     int irpcb =0;
00192     int irpcf =0;
00193     int ndt[5]   = {0,0,0,0,0};
00194     int ncsc[5]  = {0,0,0,0,0};
00195     int nrpcb[5] = {0,0,0,0,0};
00196     int nrpcf[5] = {0,0,0,0,0};
00197     int N;      
00198     std::vector<L1MuGMTReadoutRecord> gmt_records = gmtrc->getRecords();
00199     std::vector<L1MuGMTReadoutRecord>::const_iterator igmtrr;
00200     N=0;
00201     int NN=0;
00202     for(igmtrr=gmt_records.begin(); igmtrr!=gmt_records.end(); igmtrr++) {
00203       if(igmtrr->getBxInEvent()==0) BXinEVENT=NN;
00204       NN++;
00205       std::vector<L1MuRegionalCand>::const_iterator iter1;
00206       std::vector<L1MuRegionalCand> rmc;
00207       // DTBX Trigger
00208       rmc = igmtrr->getDTBXCands(); 
00209       for(iter1=rmc.begin(); iter1!=rmc.end(); iter1++) {
00210         if ( idt < MAXDTBX && !(*iter1).empty() ) {
00211           idt++; 
00212           if(N<5) ndt[N]++; 
00213                                  
00214         }        
00215       }
00216       // CSC Trigger
00217       rmc = igmtrr->getCSCCands(); 
00218       for(iter1=rmc.begin(); iter1!=rmc.end(); iter1++) {
00219         if ( icsc < MAXCSC && !(*iter1).empty() ) {
00220           icsc++; 
00221           if(N<5) ncsc[N]++; 
00222         } 
00223       }
00224       // RPCb Trigger
00225       rmc = igmtrr->getBrlRPCCands();
00226       for(iter1=rmc.begin(); iter1!=rmc.end(); iter1++) {
00227         if ( irpcb < MAXRPC && !(*iter1).empty() ) {
00228           irpcb++;
00229           if(N<5) nrpcb[N]++;
00230                                 
00231         }  
00232       }
00233       // RPCfwd Trigger
00234       rmc = igmtrr->getFwdRPCCands();
00235       for(iter1=rmc.begin(); iter1!=rmc.end(); iter1++) {
00236         if ( irpcf < MAXRPC && !(*iter1).empty() ) {
00237           irpcf++;
00238           if(N<5) nrpcf[N]++;
00239                                 
00240         }  
00241       }
00242                 
00243       N++;
00244     }
00245     if(ncsc[BXinEVENT]>0 ) {   TRIGGER=+TRIG_CSC;  }
00246     if(ndt[BXinEVENT]>0  ) {   TRIGGER=+TRIG_DT;   }
00247     if(nrpcb[BXinEVENT]>0) {   TRIGGER=+TRIG_RPC;  }
00248     if(nrpcf[BXinEVENT]>0) {   TRIGGER=+TRIG_RPCF; }
00249     if(GCTTrigger1 || GCTTrigger2 || GCTTrigger3 || GCTTrigger4 || GCTTrigger5) {  TRIGGER=+TRIG_GCT; }
00250   }
00253   if(ievt_<100){
00254     edm::Handle<HBHEDigiCollection> hbhe; 
00255     iEvent.getByLabel(inputLabelDigi_,hbhe);
00256     if(hbhe.isValid()){   
00257       for(HBHEDigiCollection::const_iterator digi=hbhe->begin();digi!=hbhe->end();digi++){
00258         eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00259         for(int i=0;i<nTS;i++) if(digi->sample(i).adc()<20) set_hbhe(eta,phi,depth,digi->sample(i).capid(),adc2fC[digi->sample(i).adc()]);
00260       }   
00261     }    
00262     edm::Handle<HODigiCollection> ho; 
00263     iEvent.getByLabel(inputLabelDigi_,ho);
00264     if(ho.isValid()){
00265       for(HODigiCollection::const_iterator digi=ho->begin();digi!=ho->end();digi++){
00266         eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00267         for(int i=0;i<nTS;i++) if(digi->sample(i).adc()<20) set_ho(eta,phi,depth,digi->sample(i).capid(),adc2fC[digi->sample(i).adc()]);
00268       }   
00269     }
00270     edm::Handle<HFDigiCollection> hf;
00271     iEvent.getByLabel(inputLabelDigi_,hf);
00272     if(hf.isValid()){
00273       for(HFDigiCollection::const_iterator digi=hf->begin();digi!=hf->end();digi++){
00274         eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00275         for(int i=0;i<nTS;i++) if(digi->sample(i).adc()<20) set_hf(eta,phi,depth,digi->sample(i).capid(),adc2fC[digi->sample(i).adc()]);
00276       }   
00277     }
00278     return;   
00279   }
00282   double data[20];
00283   edm::Handle<HBHEDigiCollection> hbhe; 
00284   iEvent.getByLabel(inputLabelDigi_,hbhe);
00285   if(hbhe.isValid()){ 
00286     for(HBHEDigiCollection::const_iterator digi=hbhe->begin();digi!=hbhe->end();digi++){
00287       eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00288       for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()]-get_ped_hbhe(eta,phi,depth,digi->sample(i).capid());
00289       if(!isSignal(data,nTS)) continue;
00290           
00291       occHBHE[eta+50][phi][depth]+=1.0; occSum+=1.0;
00292       if((occHBHE[eta+50][phi][depth]/(double)(ievt_))>0.001) continue;
00293              
00294       double Time=GetTime(data,nTS);
00295       if(digi->id().subdet()==HcalBarrel){
00296         if(TRIGGER==TRIG_GCT) HBTimeGCT->Fill(Time);
00297         if(CosmicsCorr_) Time+=(7.5*sin((phi*5.0)/180.0*3.14159))/25.0;
00298         if(TRIGGER==TRIG_DT)  HBTimeDT->Fill(Time);
00299         if(HOselfTrigger)     HBTimeHO->Fill(Time);
00300         if(TRIGGER==TRIG_RPC) HBTimeRPC->Fill(Time);
00301       }
00302       if(digi->id().subdet()==HcalEndcap){
00303         if(CosmicsCorr_) Time+=(3.5*sin((phi*5.0)/180.0*3.14159))/25.0; 
00304         if(TRIGGER==TRIG_CSC && eta>0)  HETimeCSCp->Fill(Time);
00305         if(TRIGGER==TRIG_CSC && eta<0)  HETimeCSCm->Fill(Time);  
00306         if(TRIGGER==TRIG_RPCF && eta>0) HETimeRPCp->Fill(Time);
00307         if(TRIGGER==TRIG_RPCF && eta<0) HETimeRPCm->Fill(Time);              
00308       }
00309          
00310     }    
00311   }
00312   edm::Handle<HODigiCollection> ho; 
00313   iEvent.getByLabel(inputLabelDigi_,ho);
00314   if(ho.isValid()){ 
00315     for(HODigiCollection::const_iterator digi=ho->begin();digi!=ho->end();digi++){
00316       eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00317       for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()]-get_ped_ho(eta,phi,depth,digi->sample(i).capid());
00318       if(!isSignal(data,nTS)) continue;
00319       occHO[eta+50][phi][depth]+=1.0;
00320       occSum+=1.0;
00321       if((occHO[eta+50][phi][depth]/(double)(ievt_))>0.001) continue;
00322              
00323       double Time=GetTime(data,nTS);
00324       if(CosmicsCorr_) Time+=(12.0*sin((phi*5.0)/180.0*3.14159))/25.0;  
00325       if(TRIGGER==TRIG_DT)  HOTimeDT ->Fill(Time);
00326       if(HOselfTrigger)     HOTimeHO ->Fill(Time);
00327       if(TRIGGER==TRIG_RPC) HOTimeRPC->Fill(Time);
00328       if(TRIGGER==TRIG_GCT) HOTimeGCT->Fill(Time);
00329     }   
00330   }
00331   edm::Handle<HFDigiCollection> hf; 
00332   iEvent.getByLabel(inputLabelDigi_,hf);
00333   if(hf.isValid()){ 
00334     for(HFDigiCollection::const_iterator digi=hf->begin();digi!=hf->end();digi++){
00335       eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00336       double energy=0;
00337       for(int i=0;i<nTS;i++){
00338         data[i]=adc2fC[digi->sample(i).adc()]-get_ped_hf(eta,phi,depth,digi->sample(i).capid());
00339         energy+=data[i]; 
00340       }
00341             
00342       if(energy<25.0) continue;
00343       occHF[eta+50][phi][depth]+=1.0;
00344       occSum+=1.0;
00345             
00346       double Time=GetTime(data,nTS);
00347       if((occHF[eta+50][phi][depth]/(double)(ievt_))>0.01) continue;
00348             
00349       if(TRIGGER==TRIG_CSC && eta>0) HFTimeCSCp->Fill(Time); 
00350       if(TRIGGER==TRIG_CSC && eta<0) HFTimeCSCm->Fill(Time); 
00351     }   
00352   }
00353   if((ievt_%500)==0){
00354     CheckTiming();
00355     //printf("Run: %i, Evants processed: %i\n",iEvent.run(),ievt_);       
00356   }
00357 }
00358 
00359 void HcalDetDiagTimingMonitor::CheckTiming(){
00360   if(HBTimeDT->getEntries()>10){
00361     Summary->setBinContent(1,1,1); 
00362   }
00363   if(HBTimeRPC->getEntries()>10){
00364     Summary->setBinContent(2,1,1); 
00365   } 
00366   if(HBTimeGCT->getEntries()>10){
00367     Summary->setBinContent(3,1,1); 
00368   } 
00369   if(HBTimeHO->getEntries()>10){
00370     Summary->setBinContent(6,1,1); 
00371   } 
00372   if(HOTimeDT->getEntries()>10){
00373     Summary->setBinContent(1,2,1); 
00374   }
00375   if(HOTimeRPC->getEntries()>10){
00376     Summary->setBinContent(2,2,1); 
00377   } 
00378   if(HOTimeGCT->getEntries()>10){
00379     Summary->setBinContent(3,2,1); 
00380   } 
00381   if(HOTimeHO->getEntries()>10){
00382     Summary->setBinContent(6,2,1); 
00383   } 
00384   if(HETimeCSCp->getEntries()>10){
00385     Summary->setBinContent(4,4,1); 
00386   } 
00387   if(HETimeCSCm->getEntries()>10){
00388     Summary->setBinContent(4,3,1); 
00389   } 
00390   if(HETimeRPCp->getEntries()>10){
00391     Summary->setBinContent(5,4,1); 
00392   } 
00393   if(HETimeRPCm->getEntries()>10){
00394     Summary->setBinContent(5,3,1); 
00395   } 
00396   if(HFTimeCSCp->getEntries()>10){
00397     Summary->setBinContent(4,6,1); 
00398   } 
00399   if(HFTimeCSCm->getEntries()>10){
00400     Summary->setBinContent(4,4,1); 
00401   } 
00402 }
00403 
00404 void HcalDetDiagTimingMonitor::done(){   } 
00405 DEFINE_FWK_MODULE (HcalDetDiagTimingMonitor);