Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:38

0001 // -*- C++ -*-
0002 //
0003 // Package:    SiPixelErrorsDigisToCalibDigis
0004 // Class:      SiPixelErrorsDigisToCalibDigis
0005 //
0006 /**\class SiPixelErrorsDigisToCalibDigis SiPixelErrorsDigisToCalibDigis.cc SiPixelErrors/SiPixelErrorsDigisToCalibDigis/src/SiPixelErrorsDigisToCalibDigis.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Ricardo Vasquez Sierra
0015 //         Created:  Wed Apr  9 12:43:02 CEST 2008
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 #include "SiPixelErrorsDigisToCalibDigis.h"
0023 
0024 // user include files
0025 #include "FWCore/Framework/interface/MakerMacros.h"
0026 
0027 //
0028 // constants, enums and typedefs
0029 //
0030 
0031 //
0032 // static data member definitions
0033 //
0034 
0035 //
0036 // constructors and destructor
0037 //
0038 SiPixelErrorsDigisToCalibDigis::SiPixelErrorsDigisToCalibDigis(const edm::ParameterSet& iConfig)
0039 
0040 {
0041   siPixelProducerLabel_ = iConfig.getParameter<edm::InputTag>("SiPixelProducerLabelTag");
0042   createOutputFile_ = iConfig.getUntrackedParameter<bool>("saveFile", false);
0043   outputFilename_ = iConfig.getParameter<std::string>("outputFilename");
0044   daqBE_ = &*edm::Service<DQMStore>();
0045   folderMaker_ = new SiPixelFolderOrganizer();
0046 
0047   tPixelCalibDigiError = consumes<edm::DetSetVector<SiPixelCalibDigiError> >(siPixelProducerLabel_);
0048 
0049   trackerGeomToken_ = esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>();
0050 
0051   //  std::cout<<"siPixelProducerLabel_ = "<<siPixelProducerLabel_<<std::endl;
0052   //  std::cout<<"createOutputFile_= "<< createOutputFile_<<std::endl;
0053   //  std::cout<<"outpuFilename_= "<< outputFilename_<< std::endl;
0054 }
0055 
0056 SiPixelErrorsDigisToCalibDigis::~SiPixelErrorsDigisToCalibDigis() {
0057   // do anything here that needs to be done at desctruction time
0058   // (e.g. close files, deallocate resources etc.)
0059 }
0060 
0061 //
0062 // member functions
0063 //
0064 
0065 // ------------ method called to for each event  ------------
0066 void SiPixelErrorsDigisToCalibDigis::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0067   using namespace edm;
0068 
0069   static int first(1);
0070   if (1 == first) {
0071     first = 0;
0072     geom_ = iSetup.getHandle(trackerGeomToken_);
0073     theHistogramIdWorker_ = new SiPixelHistogramId(siPixelProducerLabel_.label());
0074   }
0075 
0076   Handle<DetSetVector<SiPixelCalibDigiError> > thePlaquettes;
0077   iEvent.getByToken(tPixelCalibDigiError, thePlaquettes);
0078   // iEvent.getByLabel("siPixelCalibDigis", thePlaquettes);
0079 
0080   DetSetVector<SiPixelCalibDigiError>::const_iterator digiIter;
0081 
0082   for (digiIter = thePlaquettes->begin(); digiIter != thePlaquettes->end(); digiIter++) {
0083     uint32_t detId = digiIter->id;
0084 
0085     DetSet<SiPixelCalibDigiError>::const_iterator ipix;
0086     //loop over pixel errors pulsed in the current plaquette
0087 
0088     MonitorElement* temp_;
0089 
0090     std::map<uint32_t, MonitorElement*>::iterator mapIterator =
0091         SiPixelErrorsDigisToCalibDigis_2DErrorInformation_.find(detId);
0092 
0093     if (digiIter->begin() != digiIter->end()) {
0094       if (mapIterator == SiPixelErrorsDigisToCalibDigis_2DErrorInformation_.end()) {
0095         //      std::cout << "This is the beginning of an error 2d histo booking: "<<std::endl;
0096         setDQMDirectory(detId);
0097         temp_ = bookDQMHistoPlaquetteSummary2D(detId, "SiPixelErrorsCalibDigis", "SiPixelErrorsDigisToCalibDigis");
0098         SiPixelErrorsDigisToCalibDigis_2DErrorInformation_.insert(std::make_pair(detId, temp_));
0099       } else {
0100         //      std::cout << "This one was already booked."<<std::endl;
0101         temp_ = (*mapIterator).second;
0102       }
0103 
0104       for (ipix = digiIter->begin(); ipix != digiIter->end(); ++ipix) {
0105         temp_->Fill(ipix->getCol(), ipix->getRow());
0106         //      std::cout << "detId: " << detId << " " << ipix->getRow() << " " << ipix->getCol() << std::endl;
0107       }
0108 
0109     }  // end of the if statement asking if the plaquette in question has any errors in it
0110 
0111   }  // end of the for loop that goes through all plaquettes
0112 }
0113 
0114 // ------------ method called once each job just after ending the event loop  ------------
0115 void SiPixelErrorsDigisToCalibDigis::endJob() {
0116   if (!outputFilename_.empty() && createOutputFile_) {
0117     edm::LogInfo("SiPixelErrorCalibDigis") << "Writing ROOT file to: " << outputFilename_ << std::endl;
0118     if (edm::Service<DQMStore>().isAvailable())
0119       edm::Service<DQMStore>()->save(outputFilename_);
0120   }
0121 }
0122 
0123 // ------------ helper functions ---------------------------------------------------------
0124 
0125 SiPixelErrorsDigisToCalibDigis::MonitorElement* SiPixelErrorsDigisToCalibDigis::bookDQMHistogram2D(uint32_t detid,
0126                                                                                                    std::string name,
0127                                                                                                    std::string title,
0128                                                                                                    int nchX,
0129                                                                                                    double lowX,
0130                                                                                                    double highX,
0131                                                                                                    int nchY,
0132                                                                                                    double lowY,
0133                                                                                                    double highY) {
0134   std::string hid = theHistogramIdWorker_->setHistoId(name, detid);
0135   return daqBE_->book2D(hid, title, nchX, lowX, highX, nchY, lowY, highY);
0136 }
0137 
0138 SiPixelErrorsDigisToCalibDigis::MonitorElement* SiPixelErrorsDigisToCalibDigis::bookDQMHistoPlaquetteSummary2D(
0139     uint32_t detid, std::string name, std::string title) {
0140   DetId detId(detid);
0141   const TrackerGeometry& theTracker(*geom_);
0142   const PixelGeomDetUnit* theGeomDet = dynamic_cast<const PixelGeomDetUnit*>(theTracker.idToDet(detId));
0143   int maxcol = theGeomDet->specificTopology().ncolumns();
0144   int maxrow = theGeomDet->specificTopology().nrows();
0145 
0146   std::string hid = theHistogramIdWorker_->setHistoId(name, detid);
0147   return daqBE_->book2D(hid, title, maxcol, 0, maxcol, maxrow, 0, maxrow);
0148 }
0149 
0150 bool SiPixelErrorsDigisToCalibDigis::setDQMDirectory(std::string dirName) {
0151   daqBE_->setCurrentFolder(dirName);
0152   return daqBE_->dirExists(dirName);
0153 }
0154 
0155 bool SiPixelErrorsDigisToCalibDigis::setDQMDirectory(uint32_t detID) { return folderMaker_->setModuleFolder(detID, 0); }
0156 
0157 // -- define this as a plug-in
0158 DEFINE_FWK_MODULE(SiPixelErrorsDigisToCalibDigis);