CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/HcalMonitorTasks/src/HcalNZSMonitor.cc

Go to the documentation of this file.
00001 #include "DQM/HcalMonitorTasks/interface/HcalNZSMonitor.h"
00002 
00003 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00004 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
00005 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
00006 #include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h"
00007 
00008 #include "FWCore/Common/interface/TriggerNames.h"
00009 #include <math.h>
00010 
00011 HcalNZSMonitor::HcalNZSMonitor(const edm::ParameterSet& ps) 
00012 {
00013   Online_                = ps.getUntrackedParameter<bool>("online",false);
00014   mergeRuns_             = ps.getUntrackedParameter<bool>("mergeRuns",false);
00015   enableCleanup_         = ps.getUntrackedParameter<bool>("enableCleanup",false);
00016   debug_                 = ps.getUntrackedParameter<int>("debug",0);
00017   prefixME_              = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
00018   if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
00019     prefixME_.append("/");
00020   subdir_                = ps.getUntrackedParameter<std::string>("TaskFolder","NZSMonitor_Hcal"); 
00021   if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
00022     subdir_.append("/");
00023   subdir_=prefixME_+subdir_;
00024   AllowedCalibTypes_     = ps.getUntrackedParameter<std::vector<int> > ("AllowedCalibTypes");
00025   skipOutOfOrderLS_      = ps.getUntrackedParameter<bool>("skipOutOfOrderLS",false);
00026   NLumiBlocks_           = ps.getUntrackedParameter<int>("NLumiBlocks",4000);
00027   makeDiagnostics_       = ps.getUntrackedParameter<bool>("makeDiagnostics",false);
00028 
00029   triggers_=ps.getUntrackedParameter<std::vector<std::string> >("nzsHLTnames"); //["HLT_HcalPhiSym","HLT_HcalNZS_8E29]
00030   period_=ps.getUntrackedParameter<int>("NZSeventPeriod",4096); //4096
00031   rawdataLabel_          = ps.getUntrackedParameter<edm::InputTag>("RawDataLabel");
00032   hltresultsLabel_       = ps.getUntrackedParameter<edm::InputTag>("HLTResultsLabel");
00033 
00034 } 
00035 
00036 HcalNZSMonitor::~HcalNZSMonitor() {}
00037 
00038 void HcalNZSMonitor::reset()
00039 {
00040   meFEDsizeVsLumi_->Reset();
00041   meFEDsizesNZS_->Reset();
00042   meL1evtNumber_->Reset();
00043   meIsUS_->Reset();
00044   meBXtriggered_->Reset();
00045   meTrigFrac_->Reset();
00046   meFullCMSdataSize_->Reset();
00047 } // void HcalNZSMonitor::reset()
00048 
00049 void HcalNZSMonitor::cleanup()
00050 {
00051   if(dbe_)
00052     {
00053       dbe_->setCurrentFolder(subdir_);
00054       dbe_->removeContents();
00055     }
00056 }//void HcalNZSMonitor::cleanup()
00057 
00058 
00059 void HcalNZSMonitor::beginRun(const edm::Run& run, const edm::EventSetup& c)
00060 {
00061   if (debug_>1) std::cout <<"HcalNZSMonitor::beginRun"<<std::endl;
00062   HcalBaseDQMonitor::beginRun(run,c);
00063 
00064   if (tevt_==0) this->setup(); // set up histograms if they have not been created before
00065   if (mergeRuns_==false)
00066     this->reset();
00067 
00068   return;
00069 
00070 } // void HcalNZSMonitor::beginRun(...)
00071 
00072 
00073 void HcalNZSMonitor::setup()
00074 {
00075   HcalBaseDQMonitor::setup();
00076   
00077   if(debug_>1) std::cout << "<HcalNZSMonitor::setup> About to pushback fedUnpackList_" << std::endl;
00078 
00079   selFEDs_.clear();
00080   for (int i=FEDNumbering::MINHCALFEDID; i<=FEDNumbering::MAXHCALFEDID; i++)
00081     {
00082       selFEDs_.push_back(i);
00083     }
00084 
00085   nAcc.clear();
00086   for (unsigned int i=0; i<triggers_.size(); i++) nAcc.push_back(0);
00087 
00088   nAndAcc=0;
00089   nAcc_Total=0;
00090   
00091   if (debug_>1) std::cout <<"<HcalNZSMonitor::setup>  Creating histograms"<<std::endl;
00092   if (dbe_)
00093     {
00094       dbe_->setCurrentFolder(subdir_);
00095       
00096       meFEDsizesNZS_=dbe_->bookProfile("FED sizes","FED sizes",32,699.5,731.5,100,-1000.0,12000.0,"");
00097       meFEDsizesNZS_->setAxisTitle("FED number",1);
00098       meFEDsizesNZS_->setAxisTitle("average size (KB)",2);
00099       meFEDsizesNZS_->getTProfile()->SetMarkerStyle(22);
00100       
00101       meFEDsizeVsLumi_=dbe_->bookProfile("FED_size_Vs_lumi_block_number",
00102                                          "FED size Vs lumi block number;lumiblock number;average HCAL FED size (kB)",
00103                                          NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000,"");
00104       meFEDsizeVsLumi_->getTProfile()->SetMarkerStyle(22);
00105 
00106       meL1evtNumber_=dbe_->book1D("Is_L1_event_number_multiple_of_NZS_period",
00107                                   "Is L1 event number multiple of NZS period",2,0,2);
00108       meL1evtNumber_->setBinLabel(1, "NO", 1);
00109       meL1evtNumber_->setBinLabel(2, "YES", 1);
00110 
00111       meIsUS_=dbe_->book1D("IsUnsuppressed_bit","IsUnsuppressed bit",2,0,2);
00112       meIsUS_->setBinLabel(1,"NO",1);
00113       meIsUS_->setBinLabel(2,"YES",1);
00114 
00115       meBXtriggered_=dbe_->book1D("Triggered_BX_number","Triggered BX number",3850,0,3850);
00116       meBXtriggered_->setAxisTitle("BX number",1);
00117 
00118       meTrigFrac_=dbe_->book1D("HLT_accept_fractions","HLT accept fractions",triggers_.size()+1,0,triggers_.size()+1);
00119       for (unsigned int k=0; k<triggers_.size(); k++) meTrigFrac_->setBinLabel(k+1,triggers_[k].c_str(),1);
00120       meTrigFrac_->setBinLabel(triggers_.size()+1,"AND",1);
00121 
00122       meFullCMSdataSize_=dbe_->bookProfile("full_CMS_datasize",
00123                                            "full CMS data size;lumiblock number;average FEDRawDataCollection size (kB)",
00124                                            NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000,"");
00125       meFullCMSdataSize_->getTProfile()->SetMarkerStyle(22);
00126 
00127     } // if (dbe_)
00128   return;
00129 } // void HcalNZSMonitor::setup()
00130 
00131 
00132 void HcalNZSMonitor::analyze(edm::Event const&e, edm::EventSetup const&s)
00133 {
00134   if (!IsAllowedCalibType()) return;
00135   if (LumiInOrder(e.luminosityBlock())==false) return;
00136   
00137   edm::Handle<FEDRawDataCollection> rawraw;
00138 
00139   if (!(e.getByLabel(rawdataLabel_,rawraw)))
00140     {
00141       edm::LogWarning("HcalNZSMonitor")<<" raw data with label "<<rawdataLabel_<<" not available";
00142       return;
00143     }
00144 
00145   edm::Handle<edm::TriggerResults> hltRes;
00146   if (!(e.getByLabel(hltresultsLabel_,hltRes)))
00147     {
00148       if (debug_>0) edm::LogWarning("HcalNZSMonitor")<<" Could not get HLT results with tag "<<hltresultsLabel_<<std::endl;
00149       return;
00150     }
00151 
00152   const edm::TriggerNames & triggerNames = e.triggerNames(*hltRes);
00153   // Collections were found; increment counters
00154   HcalBaseDQMonitor::analyze(e,s);
00155 
00156   processEvent(*rawraw, *hltRes, e.bunchCrossing(), triggerNames);
00157 
00158 } // void HcalNZSMonitor::analyze(...)
00159 
00160 
00161 void HcalNZSMonitor::processEvent(const FEDRawDataCollection& rawraw, 
00162                                   edm::TriggerResults trigRes, 
00163                                   int bxNum, 
00164                                   const edm::TriggerNames& triggerNames)
00165 {
00166   if(!dbe_) 
00167     { 
00168       if (debug_>0) std::cout <<"HcalNZSMonitor::processEvent DQMStore not instantiated!!!"<<std::endl;  
00169       return;
00170     }
00171 
00172   const unsigned int nTrig(triggerNames.size());
00173  
00174   std::vector<bool> trigAcc;
00175   for (unsigned int i=0; i<triggers_.size(); i++) trigAcc.push_back(false);
00176   
00177    for (unsigned int k=0; k<nTrig; k++)
00178      {
00179        for (unsigned int i=0; i<triggers_.size(); i++)
00180          {
00181            if (triggerNames.triggerName(k) == triggers_[i] && trigRes.accept(k)) trigAcc[i]=true;
00182          }
00183      }
00184    bool andAcc=true;
00185    bool orAcc=false;
00186    for (unsigned int p=0; p<triggers_.size(); p++)
00187      {
00188        if (!trigAcc[p]) andAcc=false;
00189        if (trigAcc[p]) 
00190          {
00191            orAcc=true;
00192            nAcc[p]++;
00193          }
00194      }
00195    
00196    if (orAcc)
00197      {
00198        nAcc_Total++;
00199        for (unsigned int l=0; l<triggers_.size(); l++)
00200          {
00201            meTrigFrac_->setBinContent(l+1,nAcc[l]/(float)nAcc_Total);
00202          }
00203      }
00204 
00205    if (andAcc) 
00206      {
00207        nAndAcc++;
00208        meTrigFrac_->setBinContent(triggers_.size()+1,nAndAcc/(float)nAcc_Total);
00209      }
00210    
00211   bool processevent=false;
00212   if (orAcc) processevent=true;
00213 
00214   if (!processevent) return;
00215 
00216   meBXtriggered_->Fill(bxNum+0.001,1);
00217 
00218   //calculate full HCAL data size:
00219   size_t hcalSize=0;
00220   bool hcalIsZS = false;
00221   for (unsigned int k=0; k<selFEDs_.size(); k++)
00222     {
00223       const FEDRawData & fedData = rawraw.FEDData(selFEDs_[k]);
00224       hcalSize+=fedData.size();
00225       meFEDsizesNZS_->Fill(selFEDs_[k]+0.001,fedData.size()/1024);
00226 
00227       const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(fedData.data());
00228       if (dccHeader==0) continue;  // protection against bad data -- saw this happen in file /store/streamer/Data/A/000/131/540/Data.00131540.0200.A.storageManager.00.0000.dat; not yet sure why -- Jeff, 22 March 2010; this was due to empty (masked?) HO FEDs 724 and 727 -- Grigory, 25/03/2010 
00229 
00230       HcalHTRData htr;
00231       int nspigot =0; 
00232       for (int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++) 
00233         {    
00234           nspigot++;
00235           if (!dccHeader->getSpigotPresent(spigot)) continue;
00236           // Load the given decoder with the pointer and length from this spigot.
00237           dccHeader->getSpigotData(spigot,htr, fedData.size()); 
00238           if(k != 20 && nspigot !=14 ) 
00239             {      
00240               if ( !htr.isUnsuppressed() ) hcalIsZS = true; 
00241             }
00242         }
00243     }
00244   
00245   if (hcalIsZS) meIsUS_->Fill(0,1);
00246   else meIsUS_->Fill(1,1);
00247 
00248   meFEDsizeVsLumi_->Fill(currentLS+0.001, hcalSize/1024);
00249   
00250   size_t fullSize=0;
00251   for (int j=0; j<=FEDNumbering::MAXFEDID; ++j )
00252     {
00253       const FEDRawData & fedData = rawraw.FEDData(j);
00254       fullSize+=fedData.size();
00255     }
00256 
00257   meFullCMSdataSize_->Fill(currentLS+0.001,fullSize/1024);
00258   
00259   // get Trigger FED-Id
00260   const FEDRawData& fedData = rawraw.FEDData(FEDNumbering::MINTriggerGTPFEDID) ;
00261   FEDHeader header(fedData.data()) ;
00262   
00264   if (header.lvl1ID()%period_==0) meL1evtNumber_->Fill(1,1);
00265   else meL1evtNumber_->Fill(0,1);
00266   return;
00267 
00268 } //void HcalNZSMonitor::processEvent(...)
00269 
00270 DEFINE_FWK_MODULE(HcalNZSMonitor);