Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-17 01:40:48

0001 // -*- C++ -*-
0002 //
0003 // Package:    SiPixelCondObjAllPayloadsReader
0004 // Class:      SiPixelCondObjAllPayloadsReader
0005 //
0006 /**\class SiPixelCondObjAllPayloadsReader SiPixelCondObjAllPayloadsReader.h SiPixel/test/SiPixelCondObjAllPayloadsReader.h
0007 
0008  Description: Test analyzer for reading pixel calibration from the DB
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Vincenzo CHIOCHIA
0015 //         Created:  Tue Oct 17 17:40:56 CEST 2006
0016 // $Id: SiPixelCondObjAllPayloadsReader.h,v 1.4 2009/05/28 22:12:54 dlange Exp $
0017 //
0018 //
0019 
0020 // system includes
0021 #include <memory>
0022 
0023 // user includes
0024 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationForHLTService.h"
0025 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationOfflineService.h"
0026 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationService.h"
0027 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationServiceBase.h"
0028 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0029 #include "FWCore/Framework/interface/Event.h"
0030 #include "FWCore/Framework/interface/EventSetup.h"
0031 #include "FWCore/Framework/interface/Frameworkfwd.h"
0032 #include "FWCore/Framework/interface/MakerMacros.h"
0033 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0034 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0035 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0036 #include "FWCore/ServiceRegistry/interface/Service.h"
0037 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0038 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
0039 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0040 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0041 
0042 // ROOT includes
0043 #include "TROOT.h"
0044 #include "TFile.h"
0045 #include "TTree.h"
0046 #include "TBranch.h"
0047 #include "TH1F.h"
0048 #include <string>
0049 
0050 namespace cms {
0051   class SiPixelCondObjAllPayloadsReader : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0052   public:
0053     explicit SiPixelCondObjAllPayloadsReader(const edm::ParameterSet& iConfig);
0054 
0055     void analyze(const edm::Event&, const edm::EventSetup&) override;
0056     void endJob() override;
0057 
0058   private:
0059     const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
0060     std::unique_ptr<SiPixelGainCalibrationServiceBase> SiPixelGainCalibrationService_;
0061 
0062     std::map<uint32_t, TH1F*> _TH1F_Pedestals_m;
0063     std::map<uint32_t, TH1F*> _TH1F_Gains_m;
0064     TH1F* _TH1F_Gains_sum;
0065     TH1F* _TH1F_Pedestals_sum;
0066     TH1F* _TH1F_Gains_all;
0067     TH1F* _TH1F_Pedestals_all;
0068   };
0069 }  // namespace cms
0070 
0071 namespace cms {
0072   SiPixelCondObjAllPayloadsReader::SiPixelCondObjAllPayloadsReader(const edm::ParameterSet& conf)
0073       : tkGeomToken_(esConsumes()) {
0074     usesResource(TFileService::kSharedResource);
0075     std::string payloadType = conf.getParameter<std::string>("payloadType");
0076     if (strcmp(payloadType.c_str(), "HLT") == 0) {
0077       SiPixelGainCalibrationService_ = std::make_unique<SiPixelGainCalibrationForHLTService>(conf, consumesCollector());
0078     } else if (strcmp(payloadType.c_str(), "Offline") == 0) {
0079       SiPixelGainCalibrationService_ =
0080           std::make_unique<SiPixelGainCalibrationOfflineService>(conf, consumesCollector());
0081     } else if (strcmp(payloadType.c_str(), "Full") == 0) {
0082       SiPixelGainCalibrationService_ = std::make_unique<SiPixelGainCalibrationService>(conf, consumesCollector());
0083     }
0084   }
0085 
0086   void SiPixelCondObjAllPayloadsReader::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0087     //Create Subdirectories
0088     edm::Service<TFileService> fs;
0089     TFileDirectory subDirPed = fs->mkdir("Pedestals");
0090     TFileDirectory subDirGain = fs->mkdir("Gains");
0091     char name[128];
0092 
0093     unsigned int nmodules = 0;
0094     uint32_t nchannels = 0;
0095 
0096     // Get the calibration data
0097     SiPixelGainCalibrationService_->setESObjects(iSetup);
0098     edm::LogInfo("SiPixelCondObjAllPayloadsReader")
0099         << "[SiPixelCondObjAllPayloadsReader::beginJob] End Reading CondObjects" << std::endl;
0100 
0101     // Get the Geometry
0102     const TrackerGeometry* tkgeom = &iSetup.getData(tkGeomToken_);
0103     edm::LogInfo("SiPixelCondObjAllPayloadsReader")
0104         << " There are " << tkgeom->dets().size() << " detectors" << std::endl;
0105 
0106     //Get list of DetIDs
0107     std::vector<uint32_t> vdetId_ = SiPixelGainCalibrationService_->getDetIds();
0108 
0109     //Create histograms
0110     _TH1F_Gains_sum = fs->make<TH1F>("Summary_Gain", "Gain Summary", vdetId_.size() + 1, 0, vdetId_.size() + 1);
0111     _TH1F_Pedestals_sum =
0112         fs->make<TH1F>("Summary_Pedestal", "Pedestal Summary", vdetId_.size() + 1, 0, vdetId_.size() + 1);
0113     _TH1F_Pedestals_all = fs->make<TH1F>("PedestalsAll", "all Pedestals", 350, -100, 250);
0114     _TH1F_Gains_all = fs->make<TH1F>("GainsAll", "all Gains", 100, 0, 10);
0115 
0116     // Loop over DetId's
0117     int ibin = 1;
0118     for (std::vector<uint32_t>::const_iterator detid_iter = vdetId_.begin(); detid_iter != vdetId_.end();
0119          detid_iter++) {
0120       uint32_t detid = *detid_iter;
0121 
0122       sprintf(name, "Pedestals_%d", detid);
0123       _TH1F_Pedestals_m[detid] = subDirPed.make<TH1F>(name, name, 250, 0., 250.);
0124       sprintf(name, "Gains_%d", detid);
0125       _TH1F_Gains_m[detid] = subDirGain.make<TH1F>(name, name, 100, 0., 10.);
0126 
0127       DetId detIdObject(detid);
0128       const PixelGeomDetUnit* _PixelGeomDetUnit =
0129           dynamic_cast<const PixelGeomDetUnit*>(tkgeom->idToDetUnit(DetId(detid)));
0130       if (_PixelGeomDetUnit == nullptr) {
0131         edm::LogError("SiPixelCondObjDisplay") << "[SiPixelCondObjAllPayloadsReader::beginJob] the detID " << detid
0132                                                << " doesn't seem to belong to Tracker" << std::endl;
0133         continue;
0134       }
0135 
0136       nmodules++;
0137 
0138       const GeomDetUnit* geoUnit = tkgeom->idToDetUnit(detIdObject);
0139       const PixelGeomDetUnit* pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
0140       const PixelTopology& topol = pixDet->specificTopology();
0141 
0142       // Get the module sizes.
0143       int nrows = topol.nrows();     // rows in x
0144       int ncols = topol.ncolumns();  // cols in y
0145 
0146       for (int col_iter = 0; col_iter < ncols; col_iter++) {
0147         for (int row_iter = 0; row_iter < nrows; row_iter++) {
0148           nchannels++;
0149 
0150           float gain = SiPixelGainCalibrationService_->getGain(detid, col_iter, row_iter);
0151           _TH1F_Gains_m[detid]->Fill(gain);
0152           _TH1F_Gains_all->Fill(gain);
0153 
0154           float ped = SiPixelGainCalibrationService_->getPedestal(detid, col_iter, row_iter);
0155           _TH1F_Pedestals_m[detid]->Fill(ped);
0156           _TH1F_Pedestals_all->Fill(ped);
0157 
0158           //edm::LogPrint("SiPixelCondObjAllPayloadsReader") << "       Col "<<col_iter<<" Row "<<row_iter<<" Ped "<<ped<<" Gain "<<gain<<std::endl;
0159         }
0160       }
0161 
0162       _TH1F_Gains_sum->SetBinContent(ibin, _TH1F_Gains_m[detid]->GetMean());
0163       _TH1F_Gains_sum->SetBinError(ibin, _TH1F_Gains_m[detid]->GetRMS());
0164       _TH1F_Pedestals_sum->SetBinContent(ibin, _TH1F_Pedestals_m[detid]->GetMean());
0165       _TH1F_Pedestals_sum->SetBinError(ibin, _TH1F_Pedestals_m[detid]->GetRMS());
0166 
0167       ibin++;
0168     }
0169 
0170     edm::LogInfo("SiPixelCondObjAllPayloadsReader")
0171         << "[SiPixelCondObjAllPayloadsReader::analyze] ---> PIXEL Modules  " << nmodules << std::endl;
0172     edm::LogInfo("SiPixelCondObjAllPayloadsReader")
0173         << "[SiPixelCondObjAllPayloadsReader::analyze] ---> PIXEL Channels " << nchannels << std::endl;
0174   }
0175 
0176   // ------------ method called once each job just after ending the event loop  ------------
0177   void SiPixelCondObjAllPayloadsReader::endJob() {
0178     edm::LogPrint("SiPixelCondObjAllPayloadsReader") << " ---> End job " << std::endl;
0179   }
0180 }  // namespace cms
0181 
0182 using namespace cms;
0183 DEFINE_FWK_MODULE(SiPixelCondObjAllPayloadsReader);