CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/DQM/CastorMonitor/src/CastorPSMonitor.cc

Go to the documentation of this file.
00001 #include "DQM/CastorMonitor/interface/CastorPSMonitor.h"
00002 #include "DQMServices/Core/interface/DQMStore.h"
00003 #include "DQMServices/Core/interface/MonitorElement.h"
00004 
00005 #include "FWCore/Framework/interface/EventSetup.h"
00006 #include "FWCore/Framework/interface/ESHandle.h"
00007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00008 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00009 #include "FWCore/ServiceRegistry/interface/Service.h"
00010 
00011 #include "DataFormats/Common/interface/Handle.h"
00012 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00013 #include "DataFormats/HcalDetId/interface/HcalElectronicsId.h"
00014 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00015 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00016 #include "DataFormats/DetId/interface/DetId.h"
00017 #include "CondFormats/CastorObjects/interface/CastorPedestals.h"
00018 #include "CondFormats/CastorObjects/interface/CastorPedestalWidths.h"
00019 #include "CondFormats/CastorObjects/interface/CastorQIECoder.h"
00020 #include "CondFormats/CastorObjects/interface/CastorQIEData.h"
00021 #include "CondFormats/CastorObjects/interface/CastorQIEShape.h"
00022 #include "CondFormats/CastorObjects/interface/CastorElectronicsMap.h"
00023 #include "CondFormats/CastorObjects/interface/AllObjects.h"
00024 
00025 #include "CalibFormats/CastorObjects/interface/CastorDbRecord.h"
00026 #include "CalibFormats/CastorObjects/interface/CastorDbService.h"
00027 #include "CalibFormats/CastorObjects/interface/CastorCalibrations.h"
00028 #include "CalibFormats/CastorObjects/interface/CastorCalibrationWidths.h"
00029 
00030 #include "CalibCalorimetry/CastorCalib/interface/CastorDbASCIIIO.h"
00031 #include "TBDataFormats/HcalTBObjects/interface/HcalTBTriggerData.h"
00032 
00033 #include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
00034 #include "DataFormats/HcalRecHit/interface/CastorRecHit.h"
00035 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" //-- CastorRecHitCollection
00036 
00037 //***************************************************//
00038 //********** CastorPSMonitor:   *******************//
00039 //********** Author: D.Volyanskyy/I.Katkov  *********//
00040 //********** Date  : 03.03.2010 (first version) ******// 
00041 //***************************************************//
00045 
00046 
00047 //==================================================================//
00048 //======================= Constructor ==============================//
00049 //==================================================================//
00050 CastorPSMonitor::CastorPSMonitor() {
00051   doPerChannel_ = true;
00052   ievt_=0;
00053   firstRegionThreshold_=0.;
00054   secondRegionThreshold_=0.;
00055   status=-99;
00056   statusRS=-99;
00057   statusSaturated=-99;
00058 }
00059 
00060 //==================================================================//
00061 //======================= Destructor ==============================//
00062 //==================================================================//
00063 CastorPSMonitor::~CastorPSMonitor(){
00064 }
00065 
00066 void CastorPSMonitor::reset(){
00067 }
00068 
00069 //==========================================================//
00070 //========================= setup ==========================//
00071 //==========================================================//
00072 
00073 void CastorPSMonitor::setup(const edm::ParameterSet& ps, DQMStore* dbe){
00074   
00075   CastorBaseMonitor::setup(ps,dbe);
00076   baseFolder_ = rootFolder_+"CastorPSMonitor";
00077 
00079   numberSigma_ = ps.getUntrackedParameter<double>("numberSigma", 1.5);
00080   thirdRegionThreshold_ = ps.getUntrackedParameter<double>("thirdRegionThreshold", 300);
00081   saturatedThreshold_   = ps.getUntrackedParameter<double>("saturatedThreshold", 0.05); //-- fraction of events in which chargeTS > 127 ADC
00082   offline_              = ps.getUntrackedParameter<bool>("OfflineMode", false); 
00083 
00084   if(fVerbosity>0) std::cout << "CastorPSMonitor::setup (start)" << std::endl;
00085     
00086   ievt_=0;  firstTime_ = true;
00087   firstRegionThreshold_=0.;
00088   secondRegionThreshold_=0.;
00089   numOK = 0; 
00090   fraction=0.; 
00091 
00093   for (int row=0; row<14; row++){
00094     for (int col=0; col<16; col++){
00095         sumDigiForEachChannel[row][col] = 0;
00096         saturatedMap [row][col] = 0;
00097     }
00098   }
00099 
00100   if ( m_dbe !=NULL ) {    
00101     m_dbe->setCurrentFolder(baseFolder_);
00102     
00104     meEvt_ = m_dbe->bookInt("PS Event Number"); 
00105     castorDigiHists.meDigi_pulseBX = m_dbe->book1D("CASTOR average pulse in bunch crossings","CASTOR average pulse in bunch crossings", 3600,  -0.5, 3600);
00106     TH1F* h_meDigi_pulseBX = castorDigiHists.meDigi_pulseBX->getTH1F();
00107     h_meDigi_pulseBX->GetXaxis()->SetTitle("orbit");
00108 
00109     //---- Pulse Shape per sector
00110     char name[1024];
00111     for(int i=0; i<16; i++){
00112     sprintf(name,"Castor Pulse Shape for sector=%d (in all 14 modules)",i+1);      
00113     PSsector[i] =  m_dbe->book1D(name,name,140,-0.5,139.5);
00114     }
00115 
00117     DigiOccupancyMap = m_dbe->book2D("CASTOR Digi Occupancy Map","CASTOR Digi Occupancy Map",14,0.0,14.0,16,0.0,16.0);
00119     ChannelSummaryMap = m_dbe->book2D("CASTOR Digi ChannelSummaryMap","CASTOR Digi ChannelSummaryMap",14,0.0,14.0,20,0.0,20.0); // put 20 instead of 16 to get some space for the legend
00120 
00123     SaturationSummaryMap = m_dbe->book2D("CASTOR Digi SaturationSummaryMap","CASTOR Digi SaturationSummaryMap",14,0.0,14.0,20,0.0,20.0); // put 20 instead of 16 to get some space for the legend
00124 
00125 
00126 
00128     m_dbe->setCurrentFolder(rootFolder_+"EventInfo");
00129     reportSummary    = m_dbe->bookFloat("reportSummary");
00130     reportSummaryMap = m_dbe->book2D("reportSummaryMap","CASTOR reportSummaryMap",14,0.0,14.0,16,0.0,16.0);
00131     if(offline_){
00132       h_reportSummaryMap =reportSummaryMap->getTH2F();
00133       h_reportSummaryMap->SetOption("textcolz");
00134       h_reportSummaryMap->GetXaxis()->SetTitle("module");
00135       h_reportSummaryMap->GetYaxis()->SetTitle("sector");
00136     }
00137     m_dbe->setCurrentFolder(rootFolder_+"EventInfo/reportSummaryContents");
00138     overallStatus = m_dbe->bookFloat("fraction of good channels");
00139     overallStatus->Fill(fraction); reportSummary->Fill(fraction); 
00140   } 
00141 
00142   else{
00143     if(fVerbosity>0) std::cout << "CastorPSMonitor::setup - NO DQMStore service" << std::endl; 
00144   }
00145 
00146   if(fVerbosity>0) std::cout << "CastorPSMonitor::setup (end)" << std::endl;
00147 
00148   return;
00149 }
00150 
00151 //==========================================================//
00152 //================== processEvent ==========================//
00153 //==========================================================//
00154 
00155 void CastorPSMonitor::processEvent(const CastorDigiCollection& castorDigis, const CastorDbService& conditions, std::vector<HcalGenericDetId> listEMap, int iBunch, float PedSigmaInChannel[14][16])
00156  {
00157   
00158      
00159   if(fVerbosity>0) std::cout << "==>CastorPSMonitor::processEvent !!!" << std::endl;
00160  
00161   if(!m_dbe) { 
00162     if(fVerbosity>0) std::cout <<"CastorPSMonitor::processEvent => DQMStore not instantiated !!!"<<std::endl;  
00163     return; 
00164   }
00165  
00166   meEvt_->Fill(ievt_); 
00167 
00169   ievt_++;
00170 
00171   status = -99; statusRS = -99; statusSaturated=-99;
00172 
00174   const CastorQIEShape* shape = conditions.getCastorShape();
00175      
00176   if(firstTime_)     
00177     {
00178       //===> show the array of sigmas
00179       for (int i=0; i<14; i++){
00180         for (int k=0; k<16; k++){
00181         if(fVerbosity>0)  std::cout<< "module:"<<i+1<< " sector:"<<k+1<< " Sigma=" <<   PedSigmaInChannel[i][k] << std::endl;   
00182         }
00183       }
00184       for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); it++)
00185         {     
00186           HcalGenericDetId mygenid(it->rawId());
00187           if(mygenid.isHcalCastorDetId())
00188             {
00189               NewBunch myBunch;
00190               HcalCastorDetId chanid(mygenid.rawId());
00191               myBunch.detid = chanid;
00192               myBunch.usedflag = false;
00193               std::string type;
00194               type = "CASTOR";
00195               for(int i = 0; i != 20; i++)
00196                 {
00197                   myBunch.tsCapId[i] = 0;
00198                   myBunch.tsAdc[i] = 0;
00199                   myBunch.tsfC[i] = 0.0;
00200                 }
00201               Bunches_.push_back(myBunch);
00202             }
00203         }
00204 
00205       firstTime_ = false;
00206     }
00207   
00208   
00209       if(castorDigis.size()>0) {
00211         int firstTS = 0; 
00212         int lastTS  = 9;   
00213         std::vector<NewBunch>::iterator bunch_it;
00214         int numBunches = 0;
00215         bool firstDigi = true;
00216         bool saturated = false;
00217         
00219         for(CastorDigiCollection::const_iterator j = castorDigis.begin(); j != castorDigis.end(); j++)
00220           {
00221             
00222             const CastorDataFrame digi = (const CastorDataFrame)(*j);
00223             if ( lastTS+1 > digi.size() ) lastTS = digi.size()-1;
00224             for(bunch_it = Bunches_.begin(); bunch_it != Bunches_.end(); bunch_it++)
00225               if(bunch_it->detid.rawId() == digi.id().rawId()) break;
00226             bunch_it->usedflag = true;
00227             
00228             numBunches++;
00229             //
00230             //---- Skip noisy channels present in 2009 beam data:
00231             // if ( (bunch_it->detid.sector() == 16 && bunch_it->detid.module() == 6)  ||
00232             //   (bunch_it->detid.sector() ==  3 && bunch_it->detid.module() == 8)  ||
00233             //   (bunch_it->detid.sector() ==  8 && bunch_it->detid.module() == 8) ) continue;
00234             //
00235 
00236             if ( lastTS+1 > digi.size() ) lastTS = digi.size()-1;
00237             
00239             const CastorCalibrations& calibrations=conditions.getCastorCalibrations(digi.id().rawId());
00240 
00242             double sumDigi=0.;  double sumDigiADC=0.; int bxTS=-9999; saturated = false;
00243 
00245             for(int ts = firstTS; ts != lastTS+1; ts++)
00246               {
00247                  if (firstDigi) {
00248                     bxTS = (iBunch+ts-1-digi.presamples());
00249                     if ( bxTS < 0 ) bxTS += 3563;
00250                     bxTS = ( bxTS % 3563 ) + 1;
00251                     if(fVerbosity>0) std::cout << "!!! " << bxTS << " " << iBunch <<" "<< ts << " " << digi.presamples() << std::endl;
00252                   }
00253                 
00254                   const CastorQIECoder* coder = conditions.getCastorCoder(digi.id().rawId());
00255                   bunch_it->tsCapId[ts] = digi.sample(ts).capid();
00256                   bunch_it->tsAdc[ts] = digi.sample(ts).adc();
00257                 
00259                   double charge_fC = coder->charge(*shape, digi.sample(ts).adc(), digi.sample(ts).capid());
00260                 
00262                   bunch_it->tsfC[ts] = charge_fC - calibrations.pedestal(digi.sample(ts).capid());
00264                   castorDigiHists.meDigi_pulseBX->Fill(static_cast<double>(bxTS),(bunch_it->tsfC[ts])/224.);
00266 
00267                   // PK: do not normalize histograms
00268                   //  PSsector[bunch_it->detid.sector()-1]->Fill(10*(bunch_it->detid.module()-1)+ts, bunch_it->tsfC[ts]/double(ievt_)); 
00269                   PSsector[bunch_it->detid.sector()-1]->Fill(10*(bunch_it->detid.module()-1)+ts, bunch_it->tsfC[ts]);
00270  
00272                   sumDigi +=  bunch_it->tsfC[ts]; //std::cout<< " signal(fC) in TS:"<<ts << " =" << bunch_it->tsfC[ts] << std::endl;       
00274                   sumDigiADC +=   bunch_it->tsAdc[ts]; //std::cout<< " signal(ADC) in TS:"<<ts << " =" << bunch_it->tsAdc[ts] << std::endl; 
00275 
00277                   if(bunch_it->tsAdc[ts]>126.95) {
00278                     saturated = true;
00279                   if(fVerbosity>0) 
00280                   std::cout<< "WARNING: ==> Module:" << bunch_it->detid.module() << " Sector:" << bunch_it->detid.sector() << " SATURATED !!! in TS:"<< ts <<std::endl;   
00281                  }
00282 
00283               } //-- end of the loop for time slices
00284           
00286             sumDigiForEachChannel[bunch_it->detid.module()-1][bunch_it->detid.sector()-1] += sumDigi;
00287 
00289             if(saturated) saturatedMap[bunch_it->detid.module()-1][bunch_it->detid.sector()-1] += 1;
00290 
00292             DigiOccupancyMap->Fill(bunch_it->detid.module()-1,bunch_it->detid.sector()-1, double(sumDigi/10)); //std::cout<< "=====> sumDigi=" << sumDigi << std::endl;
00293 
00294             
00295             if(fVerbosity>0){
00296              std::cout<< "==> Module:" << bunch_it->detid.module() << " Sector:" << bunch_it->detid.sector() << std::endl; 
00297              std::cout<< "==> Total charge in fC:" << sumDigi << std::endl;  
00298              std::cout<< "==> Total charge in ADC:" << sumDigiADC << std::endl;  
00299             }
00300          
00301            firstDigi = false;  
00302     } //-- end of the loop over digis 
00303 
00304 
00305 
00306 
00307 
00311 
00312 
00313         // if( ievt_ == 25 || ievt_ % 500 == 0 ) {  // no event selection - get all events
00314 
00315     numOK = 0;
00316 
00318      for (int sector=0; sector<16; sector++){
00319        for (int module=0; module<14; module++){
00320   
00322      firstRegionThreshold_ = (-1)*(numberSigma_*PedSigmaInChannel[module][sector]);
00323      secondRegionThreshold_ = numberSigma_*PedSigmaInChannel[module][sector] ;
00324     
00325 
00327  if(double(sumDigiForEachChannel[module][sector]/(10*ievt_)) < firstRegionThreshold_ )  
00328    { status = -1.; statusRS=0.; }
00329               
00331  if(double(sumDigiForEachChannel[module][sector]/(10*ievt_)) > firstRegionThreshold_ && double(sumDigiForEachChannel[module][sector]/(10*ievt_)) < secondRegionThreshold_ ) 
00332    { status = 0.25; statusRS=0.95; }
00333   
00335  if(double(sumDigiForEachChannel[module][sector]/(10*ievt_)) > secondRegionThreshold_ && double(sumDigiForEachChannel[module][sector]/(10*ievt_))< thirdRegionThreshold_ ) 
00336    { status = 1.; statusRS=1.0; }
00337 
00338  //---- leave it out for the time being
00340  // if(double(sumDigiForEachChannel[module][sector]/(10*ievt_)) > thirdRegionThreshold_ ) 
00341  // { status = -0.25; statusRS=0.88 ; }
00342    
00343  //-- define the fraction of saturated events for a particular channel
00344  double fractionSaturated =  double(saturatedMap[module][sector])/double(ievt_) ;
00346  if(fVerbosity>0) std::cout<< "==> module: " << module << " sector: " << sector << " ==> N_saturation:" << saturatedMap[module][sector] << " events:"<< ievt_ << " fraction:" << fractionSaturated << std::endl;
00347 
00348  if( fractionSaturated > saturatedThreshold_ ) 
00349    { status = -0.25; statusRS=0.88 ; statusSaturated=-1.0; }
00350 
00352  if( saturatedMap[module][sector] > 0 && fractionSaturated <  saturatedThreshold_  ) 
00353    { statusSaturated= 0; }
00354 
00356  if( saturatedMap[module][sector] == 0 ) 
00357    { statusSaturated= 1; }
00358 
00360    ChannelSummaryMap->getTH2F()->SetBinContent(module+1,sector+1,status);
00361 
00363    reportSummaryMap->getTH2F()->SetBinContent(module+1,sector+1,statusRS);
00364 
00366    SaturationSummaryMap->getTH2F()->SetBinContent(module+1,sector+1,double(statusSaturated));
00367 
00369    if ( statusRS > 0.9) numOK++;
00370 
00371        } //-- end of the loop over the modules
00372      } //-- end of the loop over the sectors
00373 
00375     fraction=double(numOK)/224;
00376     overallStatus->Fill(fraction); reportSummary->Fill(fraction); 
00377 
00378     //  } //-- end of if for the number of events // update ( PK ):   
00379 
00380 
00382       for (int sector=16; sector<20; sector++){
00383         for (int module=0; module<14; module++){
00384       ChannelSummaryMap->getTH2F()->SetBinContent(module+1,sector+1,99);
00385         }
00386     }
00388       for (int sector=16; sector<20; sector++){
00389         for (int module=0; module<14; module++){
00390           SaturationSummaryMap->getTH2F()->SetBinContent(module+1,sector+1, 99);
00391         }
00392     }
00393 
00394 
00395 
00396 
00397 
00398  } //-- end of the if castDigi
00399        
00400   else { if(fVerbosity>0) std::cout<<"CastorPSMonitor::processEvent NO Castor Digis !!!"<<std::endl; }
00401 
00402       
00403    if (showTiming) { 
00404       cpu_timer.stop(); std::cout << " TIMER::CastorPS -> " << cpu_timer.cpuTime() << std::endl; 
00405       cpu_timer.reset(); cpu_timer.start();  
00406     }
00407  
00408   
00409   return;
00410 }
00411 
00412 
00413 
00414 
00415 
00416 
00417 
00418 
00419 
00420 
00421