CMS 3D CMS Logo

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