CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DQM/CastorMonitor/src/CastorDigiMonitor.cc

Go to the documentation of this file.
00001 #include "DQM/CastorMonitor/interface/CastorDigiMonitor.h"
00002 #include "DQMServices/Core/interface/DQMStore.h"
00003 #include "DQMServices/Core/interface/MonitorElement.h"
00004 
00005 //****************************************************//
00006 //********** CastorDigiMonitor: ******************//
00007 //********** Author: Dmytro Volyanskyy   *************//
00008 //********** Date  : 29.08.2008 (first version) ******// 
00009 //****************************************************//
00012 
00013 //==================================================================//
00014 //======================= Constructor ==============================//
00015 //==================================================================//
00016 CastorDigiMonitor::CastorDigiMonitor() { doPerChannel_ = false;  }
00017 
00018 
00019 //==================================================================//
00020 //======================= Destructor ===============================//
00021 //==================================================================//
00022 CastorDigiMonitor::~CastorDigiMonitor() {
00023 }
00024 
00025 
00026 //==================================================================//
00027 //=========================== reset  ===============================//
00028 //==================================================================//
00029 void CastorDigiMonitor::reset(){
00030 }
00031 
00032 //==================================================================//
00033 //=========================== setup  ===============================//
00034 //==================================================================//
00035 void CastorDigiMonitor::setup(const edm::ParameterSet& ps, DQMStore* dbe){
00036   CastorBaseMonitor::setup(ps,dbe);
00037   baseFolder_ = rootFolder_+"CastorDigiMonitor";
00038    
00039   if(fVerbosity>0) std::cout << "CastorDigiMonitor::setup (start)" << std::endl;
00040 
00041   doPerChannel_ = ps.getUntrackedParameter<bool>("DigiPerChannel", false);
00042   doFCpeds_ = ps.getUntrackedParameter<bool>("DigiInFC", true);
00043 
00044   ievt_=0;
00045 
00046   if ( m_dbe !=NULL ) {
00047     m_dbe->setCurrentFolder(baseFolder_);
00048     meEVT_ = m_dbe->bookInt("Digi Task Event Number");
00049     meEVT_->Fill(ievt_);
00050         
00051     m_dbe->setCurrentFolder(baseFolder_);
00052   
00054     std::string type = "Castor Digis ADC counts";
00055     castHists.ALLPEDS =  m_dbe->book1D(type,type,130,0,130);
00056     
00058     //type = "Castor Pedestal Mean Reference Values - from CondDB";
00059     //castHists.PEDESTAL_REFS = m_dbe->book1D(type,type,50,0,50);
00060     //type = "Castor Pedestal RMS Reference Values - from CondDB";
00061     //castHists.WIDTH_REFS = m_dbe->book1D(type,type,20,0,10); 
00067  
00068 }
00069 
00070   else{ 
00071    if(fVerbosity>0) std::cout << "CastorDigiMonitor::setup - NO DQMStore service" << std::endl; 
00072   }
00073 
00074  
00075   outputFile_ = ps.getUntrackedParameter<std::string>("PedestalFile", "");
00076   if ( outputFile_.size() != 0 ) { if(fVerbosity>0) std::cout << "Castor Pedestal Calibrations will be saved to " << outputFile_.c_str() << std::endl;}
00077 
00078 
00079  if(fVerbosity>0) std::cout << "CastorDigiMonitor::setup (end)" << std::endl;
00080 
00081   return;
00082 }
00083 
00084 
00085 
00086 
00087 //==================================================================//
00088 //=========================== processEvent  ========================//
00089 //==================================================================//
00090 void CastorDigiMonitor::processEvent(const CastorDigiCollection& castorDigis, const CastorDbService& cond)
00091 {
00092   
00093  if(fVerbosity>0) std::cout << "==>CastorDigiMonitor::processEvent !!!"<< std::endl;
00094 
00095  
00096   meEVT_->Fill(ievt_);
00097   
00098   //if(!shape_) shape_ = cond.getCastorShape(); // this one is generic
00099 
00100 
00101   if(!m_dbe) { 
00102     if(fVerbosity>0) std::cout<<"CastorDigiMonitor::processEvent DQMStore is not instantiated!!!"<<std::endl;  
00103     return; 
00104   }
00105 
00106 
00107   CaloSamples tool;  
00108  
00109   if(castorDigis.size()>0) {
00110 
00111    for (CastorDigiCollection::const_iterator j=castorDigis.begin(); j!=castorDigis.end(); j++){
00112       const CastorDataFrame digi = (const CastorDataFrame)(*j); 
00113  
00114 
00115        detID_.clear(); capID_.clear(); pedVals_.clear();
00116 
00117 
00119 
00120       // const CastorCalibrations& calibrations = cond.getCastorCalibrations(digi.id().rawId());
00121       // const CastorPedestal* ped              = cond.getPedestal(digi.id()); 
00122       // const CastorPedestalWidth* pedw        = cond.getPedestalWidth(digi.id());
00125        // const CastorPedestal* ped = cond.getPedestal(digi.id()); 
00126        // const CastorPedestalWidth* pedw = cond.getPedestalWidth(digi.id());
00127       
00128        /*
00130       if(doFCpeds_){
00131         channelCoder_ = cond.getCastorCoder(digi.id());
00132         CastorCoderDb coderDB(*channelCoder_, *shape_);
00133         coderDB.adc2fC(digi,tool);
00134       }
00135      
00136      
00138        for(int capID=0; capID<4; capID++){
00140             float pedvalue=0;    
00141             if(ped) pedvalue=ped->getValue(capID);
00142             castHists.PEDESTAL_REFS->Fill(pedvalue);
00143             PEDESTAL_REFS->Fill(pedvalue);
00147            float width=0;
00148            if(pedw) width = pedw->getWidth(capID);
00149            castHists.WIDTH_REFS->Fill(width);
00150            WIDTH_REFS->Fill(width);
00151     }
00152      */
00153      
00154  
00156        
00157        //      if(ievt_ %1000 == 0 )           // PK: skip limited number of events
00158       //   { 
00159       for (int i=0; i<digi.size(); i++) {
00160         if(doFCpeds_) pedVals_.push_back(tool[i]); // default is FALSE
00161         else pedVals_.push_back(digi.sample(i).adc());
00162         detID_.push_back(digi.id());
00163         capID_.push_back(digi.sample(i).capid());
00164         castHists.ALLPEDS->Fill(pedVals_[i]);
00165       }
00166       
00167       //      }      
00168 
00170       //      if( ievt_%100 == 0 && doPerChannel_) perChanHists(detID_,capID_,pedVals_,castHists.PEDVALS, baseFolder_);
00171       if( doPerChannel_) perChanHists(detID_,capID_,pedVals_,castHists.PEDVALS, baseFolder_); // PK: no special event selection done
00172 
00173     }
00174   } 
00175    else {
00176     if(fVerbosity>0) std::cout << "CastorPSMonitor::processEvent NO Castor Digis !!!" << std::endl;
00177   }
00178 
00179  if (showTiming) { 
00180       cpu_timer.stop(); std::cout << " TIMER::CastorDigi -> " << cpu_timer.cpuTime() << std::endl; 
00181       cpu_timer.reset(); cpu_timer.start();  
00182     }
00183 
00184   ievt_++;
00185   return;
00186 }
00187 
00188 void CastorDigiMonitor::done(){
00189   return;
00190 }
00191 
00192 
00193 //==================================================================//
00194 //======================= perChanHists  ============================//
00195 //==================================================================//
00197 void CastorDigiMonitor::perChanHists( std::vector<HcalCastorDetId> detID, std::vector<int> capID, std::vector<float> peds,
00198                                           std::map<HcalCastorDetId, std::map<int, MonitorElement*> > &toolP,  
00200                                           std::string baseFolder) 
00201  {
00202   
00203   if(m_dbe) m_dbe->setCurrentFolder(baseFolder);
00204 
00206   for(unsigned int d=0; d<detID.size(); d++){
00207     HcalCastorDetId detid = detID[d];
00208     int capid = capID[d];
00209     float pedVal = peds[d];
00211     bool gotit=false;
00212     if(REG[detid]) gotit=true;
00213     
00214     if(gotit){
00216       std::map<int, MonitorElement*> _mei = toolP[detid];
00217       if(_mei[capid]==NULL){
00218         if(fVerbosity>0) std::cout<<"CastorDigiMonitor::perChanHists  This histo is NULL!!??"<< std::endl;
00219       }
00220       else _mei[capid]->Fill(pedVal);
00221       
00227     }
00228     else{
00229       if(m_dbe){
00230         std::map<int,MonitorElement*> insertP; //-- Pedestal values in ADC
00232         
00234         for(int i=0; i<4; i++){
00235           char name[1024];
00236           sprintf(name,"Castor Digi Value (ADC) zside=%d module=%d sector=%d CAPID=%d",
00237                   detid.zside(),detid.module(),detid.sector(),i);      
00238           insertP[i] =  m_dbe->book1D(name,name,10,-0.5,9.5);
00239           
00243         }
00244         
00245         insertP[capid]->Fill(pedVal);
00247         toolP[detid] = insertP;
00249       }
00250       REG[detid] = true;
00251     }
00252   }
00253 }
00254