Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-08-27 01:27:30

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     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0056     void analyze(const edm::Event&, const edm::EventSetup&) override;
0057     void endJob() override;
0058 
0059   private:
0060     const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
0061     std::unique_ptr<SiPixelGainCalibrationServiceBase> SiPixelGainCalibrationService_;
0062 
0063     std::map<uint32_t, TH1F*> _TH1F_Pedestals_m;
0064     std::map<uint32_t, TH1F*> _TH1F_Gains_m;
0065     TH1F* _TH1F_Gains_sum;
0066     TH1F* _TH1F_Pedestals_sum;
0067     TH1F* _TH1F_Gains_all;
0068     TH1F* _TH1F_Pedestals_all;
0069   };
0070 }  // namespace cms
0071 
0072 namespace cms {
0073 
0074   void SiPixelCondObjAllPayloadsReader::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0075     edm::ParameterSetDescription desc;
0076     desc.setComment("EDAnalyzer to read per-module SiPixelGainCalibration payloads in the EventSetup, for any type");
0077     desc.add<std::string>("payloadType", "HLT");
0078     descriptions.addWithDefaultLabel(desc);
0079   }
0080 
0081   SiPixelCondObjAllPayloadsReader::SiPixelCondObjAllPayloadsReader(const edm::ParameterSet& conf)
0082       : tkGeomToken_(esConsumes()) {
0083     usesResource(TFileService::kSharedResource);
0084     std::string payloadType = conf.getParameter<std::string>("payloadType");
0085     if (strcmp(payloadType.c_str(), "HLT") == 0) {
0086       SiPixelGainCalibrationService_ = std::make_unique<SiPixelGainCalibrationForHLTService>(conf, consumesCollector());
0087     } else if (strcmp(payloadType.c_str(), "Offline") == 0) {
0088       SiPixelGainCalibrationService_ =
0089           std::make_unique<SiPixelGainCalibrationOfflineService>(conf, consumesCollector());
0090     } else if (strcmp(payloadType.c_str(), "Full") == 0) {
0091       SiPixelGainCalibrationService_ = std::make_unique<SiPixelGainCalibrationService>(conf, consumesCollector());
0092     }
0093   }
0094 
0095   void SiPixelCondObjAllPayloadsReader::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0096     //Create Subdirectories
0097     edm::Service<TFileService> fs;
0098     TFileDirectory subDirPed = fs->mkdir("Pedestals");
0099     TFileDirectory subDirGain = fs->mkdir("Gains");
0100     char name[128];
0101 
0102     unsigned int nmodules = 0;
0103     uint32_t nchannels = 0;
0104 
0105     // Get the calibration data
0106     SiPixelGainCalibrationService_->setESObjects(iSetup);
0107     edm::LogInfo("SiPixelCondObjAllPayloadsReader")
0108         << "[SiPixelCondObjAllPayloadsReader::beginJob] End Reading CondObjects" << std::endl;
0109 
0110     // Get the Geometry
0111     const TrackerGeometry* tkgeom = &iSetup.getData(tkGeomToken_);
0112     edm::LogInfo("SiPixelCondObjAllPayloadsReader")
0113         << " There are " << tkgeom->dets().size() << " detectors" << std::endl;
0114 
0115     //Get list of DetIDs
0116     std::vector<uint32_t> vdetId_ = SiPixelGainCalibrationService_->getDetIds();
0117 
0118     //Create histograms
0119     _TH1F_Gains_sum = fs->make<TH1F>("Summary_Gain", "Gain Summary", vdetId_.size() + 1, 0, vdetId_.size() + 1);
0120     _TH1F_Pedestals_sum =
0121         fs->make<TH1F>("Summary_Pedestal", "Pedestal Summary", vdetId_.size() + 1, 0, vdetId_.size() + 1);
0122     _TH1F_Pedestals_all = fs->make<TH1F>("PedestalsAll", "all Pedestals", 350, -100, 250);
0123     _TH1F_Gains_all = fs->make<TH1F>("GainsAll", "all Gains", 100, 0, 10);
0124 
0125     // Loop over DetId's
0126     int ibin = 1;
0127     for (std::vector<uint32_t>::const_iterator detid_iter = vdetId_.begin(); detid_iter != vdetId_.end();
0128          detid_iter++) {
0129       uint32_t detid = *detid_iter;
0130 
0131       sprintf(name, "Pedestals_%d", detid);
0132       _TH1F_Pedestals_m[detid] = subDirPed.make<TH1F>(name, name, 250, 0., 250.);
0133       sprintf(name, "Gains_%d", detid);
0134       _TH1F_Gains_m[detid] = subDirGain.make<TH1F>(name, name, 100, 0., 10.);
0135 
0136       DetId detIdObject(detid);
0137       const PixelGeomDetUnit* _PixelGeomDetUnit =
0138           dynamic_cast<const PixelGeomDetUnit*>(tkgeom->idToDetUnit(DetId(detid)));
0139       if (_PixelGeomDetUnit == nullptr) {
0140         edm::LogError("SiPixelCondObjDisplay") << "[SiPixelCondObjAllPayloadsReader::beginJob] the detID " << detid
0141                                                << " doesn't seem to belong to Tracker" << std::endl;
0142         continue;
0143       }
0144 
0145       nmodules++;
0146 
0147       const GeomDetUnit* geoUnit = tkgeom->idToDetUnit(detIdObject);
0148       const PixelGeomDetUnit* pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
0149       const PixelTopology& topol = pixDet->specificTopology();
0150 
0151       // Get the module sizes.
0152       int nrows = topol.nrows();     // rows in x
0153       int ncols = topol.ncolumns();  // cols in y
0154 
0155       for (int col_iter = 0; col_iter < ncols; col_iter++) {
0156         for (int row_iter = 0; row_iter < nrows; row_iter++) {
0157           nchannels++;
0158 
0159           float gain = SiPixelGainCalibrationService_->getGain(detid, col_iter, row_iter);
0160           _TH1F_Gains_m[detid]->Fill(gain);
0161           _TH1F_Gains_all->Fill(gain);
0162 
0163           float ped = SiPixelGainCalibrationService_->getPedestal(detid, col_iter, row_iter);
0164           _TH1F_Pedestals_m[detid]->Fill(ped);
0165           _TH1F_Pedestals_all->Fill(ped);
0166 
0167           //edm::LogPrint("SiPixelCondObjAllPayloadsReader") << "       Col "<<col_iter<<" Row "<<row_iter<<" Ped "<<ped<<" Gain "<<gain<<std::endl;
0168         }
0169       }
0170 
0171       _TH1F_Gains_sum->SetBinContent(ibin, _TH1F_Gains_m[detid]->GetMean());
0172       _TH1F_Gains_sum->SetBinError(ibin, _TH1F_Gains_m[detid]->GetRMS());
0173       _TH1F_Pedestals_sum->SetBinContent(ibin, _TH1F_Pedestals_m[detid]->GetMean());
0174       _TH1F_Pedestals_sum->SetBinError(ibin, _TH1F_Pedestals_m[detid]->GetRMS());
0175 
0176       ibin++;
0177     }
0178 
0179     edm::LogInfo("SiPixelCondObjAllPayloadsReader")
0180         << "[SiPixelCondObjAllPayloadsReader::analyze] ---> PIXEL Modules  " << nmodules << std::endl;
0181     edm::LogInfo("SiPixelCondObjAllPayloadsReader")
0182         << "[SiPixelCondObjAllPayloadsReader::analyze] ---> PIXEL Channels " << nchannels << std::endl;
0183   }
0184 
0185   // ------------ method called once each job just after ending the event loop  ------------
0186   void SiPixelCondObjAllPayloadsReader::endJob() {
0187     edm::LogPrint("SiPixelCondObjAllPayloadsReader") << " ---> End job " << std::endl;
0188   }
0189 }  // namespace cms
0190 
0191 using namespace cms;
0192 DEFINE_FWK_MODULE(SiPixelCondObjAllPayloadsReader);