CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/CalibTracker/SiPixelIsAliveCalibration/src/SiPixelIsAliveCalibration.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SiPixelIsAliveCalibrationAnalyzer
00004 // Class:      SiPixelIsAliveCalibrationAnalyzer
00005 // 
00013 //
00014 // Original Author:  Freya Blekman
00015 //         Created:  Mon Dec  3 14:07:42 CET 2007
00016 // $Id: SiPixelIsAliveCalibration.cc,v 1.21 2008/09/18 11:25:17 krose Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/EDAnalyzer.h"
00026 
00027 #include "FWCore/Framework/interface/MakerMacros.h"
00028 
00029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00030 #include "CalibTracker/SiPixelTools/interface/SiPixelOfflineCalibAnalysisBase.h"
00031 #include "DataFormats/SiPixelDigi/interface/SiPixelCalibDigi.h"
00032 #include "DQMServices/Core/interface/MonitorElement.h"
00033 
00034 //
00035 // class decleration
00036 //
00037 
00038 class SiPixelIsAliveCalibration : public SiPixelOfflineCalibAnalysisBase {
00039    public:
00040       explicit SiPixelIsAliveCalibration(const edm::ParameterSet&);
00041       ~SiPixelIsAliveCalibration();
00042 
00043   void doSetup(const edm::ParameterSet &);
00044       virtual bool doFits(uint32_t detid, std::vector<SiPixelCalibDigi>::const_iterator ipix);
00045   
00046 
00047    private:
00048   
00049       virtual void calibrationSetup(const edm::EventSetup&) ;
00050       virtual void calibrationEnd() ;
00051   virtual void newDetID(uint32_t detid);
00052   virtual bool checkCorrectCalibrationType();
00053       // ----------member data ---------------------------
00054 
00055   std::map<uint32_t,MonitorElement *> bookkeeper_;
00056   std::map<uint32_t,MonitorElement *> summaries_;
00057   double mineff_;
00058 };
00059 
00060 //
00061 // constants, enums and typedefs
00062 //
00063 
00064 //
00065 // static data member definitions
00066 //
00067 
00068 //
00069 // constructors and destructor
00070 //
00071 SiPixelIsAliveCalibration::SiPixelIsAliveCalibration(const edm::ParameterSet& iConfig):
00072   SiPixelOfflineCalibAnalysisBase(iConfig),
00073   mineff_(iConfig.getUntrackedParameter<double>("minEfficiencyForAliveDef",0.8))
00074 {
00075    //now do what ever initialization is needed
00076 
00077 }
00078 
00079 
00080 SiPixelIsAliveCalibration::~SiPixelIsAliveCalibration()
00081 {
00082  
00083    // do anything here that needs to be done at desctruction time
00084    // (e.g. close files, deallocate resources etc.)
00085 
00086 }
00087 
00088 
00089 //
00090 // member functions
00091 //
00092 void 
00093 SiPixelIsAliveCalibration::newDetID(uint32_t detid){
00094   setDQMDirectory(detid);
00095   std::string tempname=translateDetIdToString(detid);
00096   bookkeeper_[detid]= bookDQMHistoPlaquetteSummary2D(detid,"pixelAlive","pixel alive for "+tempname); 
00097   int xpix = bookkeeper_[detid]->getNbinsX();
00098   int ypix = bookkeeper_[detid]->getNbinsY();
00099   int tpix = xpix*ypix;
00100   summaries_[detid]= bookDQMHistogram1D(detid,"pixelAliveSummary",bookkeeper_[detid]->getTitle(),calib_->getNTriggers()+1,-.05,.95+(1./(float)calib_->getNTriggers()));
00101   summaries_[detid]->setBinContent(1, tpix);
00102 }
00103 bool
00104 SiPixelIsAliveCalibration::checkCorrectCalibrationType(){
00105   if(calibrationMode_=="PixelAlive")
00106     return true;
00107   else if(calibrationMode_=="unknown"){
00108     edm::LogInfo("SiPixelIsAliveCalibration") <<  "calibration mode is: " << calibrationMode_ << ", continuing anyway..." ;
00109     return true;
00110   }
00111   else{
00112     //    edm::LogError("SiPixelIsAliveCalibration")<< "unknown calibration mode for Pixel ALive, should be \"PixelAlive\" and is \"" << calibrationMode_ << "\"";
00113   }
00114   return false;
00115 
00116 }
00117 void SiPixelIsAliveCalibration::doSetup(const edm::ParameterSet &iConf){
00118 
00119 }
00120 void 
00121 SiPixelIsAliveCalibration::calibrationSetup(const edm::EventSetup & iSetup){
00122 
00123 }
00124 bool
00125 SiPixelIsAliveCalibration::doFits(uint32_t detid, std::vector<SiPixelCalibDigi>::const_iterator ipix){
00126   edm::LogInfo("SiPixelIsAliveCalibration") << "now looking at DetID " << detid << ", pixel " << ipix->row() << "," << ipix->col() << std::endl;
00127   
00128   double denom=0;
00129   double nom=0;
00130   for(uint32_t i=0; i<ipix->getnpoints(); i++){
00131     nom+=ipix->getnentries(i);
00132     denom+=calib_->getNTriggers();
00133     if(i>0)
00134       edm::LogWarning("SiPixelIsAliveCalibration::doFits") << " ERROR!!" << " number of vcal points is now " << i << " for detid " << detid << std::endl;
00135   }
00136   edm::LogInfo("SiPixelIsAliveCalibration") << "DetID/col/row " << detid << "/"<< ipix->col() << "/" << ipix->row() << ", now calculating efficiency: " << nom << "/" << denom <<"=" << nom/denom << std::endl;
00137   double eff = -1;
00138   if(denom>0)
00139     eff = nom/denom;
00140   if(bookkeeper_[detid]->getBinContent(ipix->col()+1,ipix->row()+1)==0){
00141     bookkeeper_[detid]->Fill(ipix->col(), ipix->row(), eff);
00142     summaries_[detid]->Fill(eff);
00143     float zerobin = summaries_[detid]->getBinContent(1);
00144     summaries_[detid]->setBinContent(1, zerobin-1);
00145   }
00146   else
00147     bookkeeper_[detid]->setBinContent(ipix->col()+1,ipix->row()+1,-2);
00148   return true;
00149 }
00150 
00151 void
00152 SiPixelIsAliveCalibration::calibrationEnd(){
00153   // print summary of bad modules:
00154   for(std::map<uint32_t, MonitorElement *>::const_iterator idet= bookkeeper_.begin(); idet!=bookkeeper_.end();++idet){
00155     float idead = 0;
00156     float iunderthres=0;
00157     float imultiplefill=0;
00158     float itot=0;
00159     uint32_t detid=idet->first;
00160 
00161     setDQMDirectory(detid);
00162     for(int icol=1; icol <= bookkeeper_[detid]->getNbinsX(); ++icol){
00163       for(int irow=1; irow <= bookkeeper_[detid]->getNbinsY(); ++irow){
00164         itot++;
00165         double val = bookkeeper_[detid]->getBinContent(icol,irow);
00166         if(val==0)
00167           idead++;
00168         if(val<mineff_)
00169           iunderthres++;
00170         if(val==-2)
00171           imultiplefill++;
00172         
00173       }
00174     }
00175     edm::LogInfo("SiPixelIsAliveCalibration") << "summary for " << translateDetIdToString(detid) << "\tfrac dead:" << idead/itot << " frac below " << mineff_ << ":" << iunderthres/itot << " bad " <<  imultiplefill/itot << std::endl;
00176   }
00177 
00178 }
00179 // ---------- method called to for each event  ------------
00180 
00181 //define this as a plug-in
00182 DEFINE_FWK_MODULE(SiPixelIsAliveCalibration);