CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/CalibTracker/SiPixelTools/plugins/SiPixelErrorsDigisToCalibDigis.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SiPixelErrorsDigisToCalibDigis
00004 // Class:      SiPixelErrorsDigisToCalibDigis
00005 // 
00013 //
00014 // Original Author:  Ricardo Vasquez Sierra
00015 //         Created:  Wed Apr  9 12:43:02 CEST 2008
00016 // $Id: SiPixelErrorsDigisToCalibDigis.cc,v 1.8 2010/01/13 09:35:59 ursl Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 #include "CalibTracker/SiPixelTools/interface/SiPixelErrorsDigisToCalibDigis.h"
00025 // user include files
00026 #include "FWCore/Framework/interface/Frameworkfwd.h"
00027 #include "FWCore/Framework/interface/EDAnalyzer.h"
00028 
00029 #include "FWCore/Framework/interface/Event.h"
00030 #include "FWCore/Framework/interface/MakerMacros.h"
00031 
00032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00033 
00034 //
00035 // constants, enums and typedefs
00036 //
00037 
00038 //
00039 // static data member definitions
00040 //
00041 
00042 //
00043 // constructors and destructor
00044 //
00045 SiPixelErrorsDigisToCalibDigis::SiPixelErrorsDigisToCalibDigis(const edm::ParameterSet& iConfig)
00046 
00047 {
00048 
00049   siPixelProducerLabel_ = iConfig.getParameter<edm::InputTag>("SiPixelProducerLabelTag"); 
00050   createOutputFile_ = iConfig.getUntrackedParameter<bool>("saveFile",false);
00051   outputFilename_ = iConfig.getParameter<std::string>("outputFilename");
00052   daqBE_ = &*edm::Service<DQMStore>();
00053   folderMaker_ = new SiPixelFolderOrganizer();
00054 
00055 //  std::cout<<"siPixelProducerLabel_ = "<<siPixelProducerLabel_<<std::endl;
00056 //  std::cout<<"createOutputFile_= "<< createOutputFile_<<std::endl;
00057 //  std::cout<<"outpuFilename_= "<< outputFilename_<< std::endl;
00058 }
00059 
00060 
00061 SiPixelErrorsDigisToCalibDigis::~SiPixelErrorsDigisToCalibDigis()
00062 {
00063  
00064    // do anything here that needs to be done at desctruction time
00065    // (e.g. close files, deallocate resources etc.)
00066 
00067 }
00068 
00069 
00070 //
00071 // member functions
00072 //
00073 
00074 // ------------ method called to for each event  ------------
00075 void
00076 SiPixelErrorsDigisToCalibDigis::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00077 {
00078   using namespace edm;
00079 
00080   static int first(1); 
00081   if (1 == first) {
00082     first = 0; 
00083     iSetup.get<TrackerDigiGeometryRecord>().get( geom_ );
00084     theHistogramIdWorker_ = new SiPixelHistogramId(siPixelProducerLabel_.label());
00085   }
00086   
00087   Handle<DetSetVector<SiPixelCalibDigiError> > thePlaquettes;
00088   iEvent.getByLabel(siPixelProducerLabel_, thePlaquettes);
00089   // iEvent.getByLabel("siPixelCalibDigis", thePlaquettes);
00090   
00091   
00092   DetSetVector<SiPixelCalibDigiError>::const_iterator digiIter;
00093   
00094   
00095   for (digiIter=thePlaquettes->begin(); digiIter!=thePlaquettes->end(); digiIter++)
00096     {
00097       uint32_t detId = digiIter->id;
00098       
00099       DetSet<SiPixelCalibDigiError>::const_iterator ipix;
00100       //loop over pixel errors pulsed in the current plaquette
00101 
00102       MonitorElement* temp_;
00103 
00104       std::map<uint32_t, MonitorElement*>::iterator mapIterator =  SiPixelErrorsDigisToCalibDigis_2DErrorInformation_.find(detId);
00105       
00106       if (digiIter->begin() != digiIter->end()) {
00107         if ( mapIterator == SiPixelErrorsDigisToCalibDigis_2DErrorInformation_.end() )
00108           {
00109 //          std::cout << "This is the beginning of an error 2d histo booking: "<<std::endl;
00110             setDQMDirectory(detId);
00111             temp_ = bookDQMHistoPlaquetteSummary2D(detId, "SiPixelErrorsCalibDigis", "SiPixelErrorsDigisToCalibDigis");
00112             SiPixelErrorsDigisToCalibDigis_2DErrorInformation_.insert( std::make_pair(detId,temp_));
00113           }
00114         else
00115           {
00116 //          std::cout << "This one was already booked."<<std::endl;
00117             temp_ = (*mapIterator).second;
00118           }
00119         
00120         for(ipix=digiIter->begin(); ipix!=digiIter->end(); ++ipix)
00121           {
00122             temp_->Fill(ipix->getCol(), ipix->getRow());
00123 //          std::cout << "detId: " << detId << " " << ipix->getRow() << " " << ipix->getCol() << std::endl;       
00124           }
00125         
00126       } // end of the if statement asking if the plaquette in question has any errors in it    
00127       
00128     }// end of the for loop that goes through all plaquettes
00129 
00130 }
00131 
00132 
00133 // ------------ method called once each job just before starting event loop  ------------
00134 void 
00135 SiPixelErrorsDigisToCalibDigis::beginJob()
00136 {
00137 
00138 }
00139 
00140 // ------------ method called once each job just after ending the event loop  ------------
00141 void 
00142 SiPixelErrorsDigisToCalibDigis::endJob() { 
00143 
00144   if (!outputFilename_.empty() && createOutputFile_)
00145     {
00146       edm::LogInfo("SiPixelErrorCalibDigis") << "Writing ROOT file to: " << outputFilename_ << std::endl;
00147       if ( &*edm::Service<DQMStore>()) edm::Service<DQMStore>()->save (outputFilename_);
00148     }
00149 }
00150 
00151 // ------------ helper functions ---------------------------------------------------------
00152 
00153 MonitorElement* SiPixelErrorsDigisToCalibDigis::bookDQMHistogram2D(uint32_t detid, std::string name, std::string title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
00154 {
00155   std::string hid = theHistogramIdWorker_->setHistoId(name,detid);
00156   return daqBE_->book2D(hid, title, nchX, lowX, highX, nchY, lowY, highY);
00157 }
00158 
00159 MonitorElement* SiPixelErrorsDigisToCalibDigis::bookDQMHistoPlaquetteSummary2D(uint32_t detid, std::string name,std::string title){
00160 
00161   DetId detId(detid);
00162   const TrackerGeometry &theTracker(*geom_);
00163   const PixelGeomDetUnit *theGeomDet = dynamic_cast<const PixelGeomDetUnit*> ( theTracker.idToDet(detId) ); 
00164   int maxcol = theGeomDet->specificTopology().ncolumns();
00165   int maxrow = theGeomDet->specificTopology().nrows();  
00166 
00167   std::string hid = theHistogramIdWorker_->setHistoId(name,detid);
00168   return daqBE_->book2D(hid,title,maxcol,0,maxcol,maxrow,0,maxrow);
00169 }
00170 
00171 bool SiPixelErrorsDigisToCalibDigis::setDQMDirectory(std::string dirName)
00172 {
00173    daqBE_->setCurrentFolder(dirName);
00174    return daqBE_->dirExists(dirName);
00175 }
00176 
00177 bool SiPixelErrorsDigisToCalibDigis::setDQMDirectory(uint32_t detID)
00178 {
00179   return folderMaker_->setModuleFolder(detID,0);
00180 }