File indexing completed on 2024-04-06 12:03:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <memory>
0022
0023
0024 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationOfflineService.h"
0025 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationOfflineSimService.h"
0026 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0027 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/EventSetup.h"
0030 #include "FWCore/Framework/interface/Frameworkfwd.h"
0031 #include "FWCore/Framework/interface/MakerMacros.h"
0032 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0033 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0035 #include "FWCore/ServiceRegistry/interface/Service.h"
0036 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0037 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
0038 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0039 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0040
0041
0042 #include "TROOT.h"
0043 #include "TFile.h"
0044 #include "TTree.h"
0045 #include "TBranch.h"
0046 #include "TH1F.h"
0047
0048 namespace cms {
0049 class SiPixelCondObjOfflineReader : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0050 public:
0051 explicit SiPixelCondObjOfflineReader(const edm::ParameterSet &iConfig);
0052 ~SiPixelCondObjOfflineReader() override = default;
0053
0054 static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0055 void analyze(const edm::Event &, const edm::EventSetup &) override;
0056 void endJob() override;
0057
0058 private:
0059 edm::ParameterSet conf_;
0060 const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
0061 const std::string recordName_;
0062 std::unique_ptr<SiPixelGainCalibrationServiceBase> SiPixelGainCalibrationService_;
0063
0064 std::map<uint32_t, TH1F *> _TH1F_Pedestals_m;
0065 std::map<uint32_t, TH1F *> _TH1F_Gains_m;
0066 std::map<uint32_t, double> _deadfrac_m;
0067 std::map<uint32_t, double> _noisyfrac_m;
0068
0069 TH1F *_TH1F_Dead_sum;
0070 TH1F *_TH1F_Noisy_sum;
0071 TH1F *_TH1F_Gains_sum;
0072 TH1F *_TH1F_Pedestals_sum;
0073 TH1F *_TH1F_Dead_all;
0074 TH1F *_TH1F_Noisy_all;
0075 TH1F *_TH1F_Gains_all;
0076 TH1F *_TH1F_Pedestals_all;
0077 TH1F *_TH1F_Gains_bpix;
0078 TH1F *_TH1F_Gains_fpix;
0079 TH1F *_TH1F_Pedestals_bpix;
0080 TH1F *_TH1F_Pedestals_fpix;
0081 };
0082 }
0083
0084 namespace cms {
0085 SiPixelCondObjOfflineReader::SiPixelCondObjOfflineReader(const edm::ParameterSet &conf)
0086 : conf_(conf), tkGeomToken_(esConsumes()) {
0087 usesResource(TFileService::kSharedResource);
0088 if (conf_.getParameter<bool>("useSimRcd"))
0089 SiPixelGainCalibrationService_ =
0090 std::make_unique<SiPixelGainCalibrationOfflineSimService>(conf_, consumesCollector());
0091 else
0092 SiPixelGainCalibrationService_ =
0093 std::make_unique<SiPixelGainCalibrationOfflineService>(conf_, consumesCollector());
0094 }
0095
0096 void SiPixelCondObjOfflineReader::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0097
0098 edm::Service<TFileService> fs;
0099 TFileDirectory subDirPed = fs->mkdir("Pedestals");
0100 TFileDirectory subDirGain = fs->mkdir("Gains");
0101 char name[128];
0102
0103 unsigned int nmodules = 0;
0104 uint32_t nchannels = 0;
0105 uint32_t ndead = 0;
0106 uint32_t nnoisy = 0;
0107
0108
0109 SiPixelGainCalibrationService_->setESObjects(iSetup);
0110 edm::LogInfo("SiPixelCondObjOfflineReader")
0111 << "[SiPixelCondObjOfflineReader::beginJob] End Reading CondObjOfflineects" << std::endl;
0112
0113
0114 const TrackerGeometry *tkgeom = &iSetup.getData(tkGeomToken_);
0115 edm::LogInfo("SiPixelCondObjOfflineReader") << " There are " << tkgeom->dets().size() << " detectors" << std::endl;
0116
0117
0118 std::vector<uint32_t> vdetId_ = SiPixelGainCalibrationService_->getDetIds();
0119
0120
0121 _TH1F_Dead_sum = fs->make<TH1F>(
0122 "Summary_dead", "Dead pixel fraction (0=dead, 1=alive)", vdetId_.size() + 1, 0, vdetId_.size() + 1);
0123 _TH1F_Dead_all = fs->make<TH1F>("DeadAll",
0124 "Dead pixel fraction (0=dead, 1=alive)",
0125 50,
0126 0.,
0127 conf_.getUntrackedParameter<double>("maxRangeDeadPixHist", 0.001));
0128 _TH1F_Noisy_sum = fs->make<TH1F>(
0129 "Summary_noisy", "Noisy pixel fraction (0=noisy, 1=alive)", vdetId_.size() + 1, 0, vdetId_.size() + 1);
0130 _TH1F_Noisy_all = fs->make<TH1F>("NoisyAll",
0131 "Noisy pixel fraction (0=noisy, 1=alive)",
0132 50,
0133 0.,
0134 conf_.getUntrackedParameter<double>("maxRangeDeadPixHist", 0.001));
0135 _TH1F_Gains_sum = fs->make<TH1F>("Summary_Gain", "Gain Summary", vdetId_.size() + 1, 0, vdetId_.size() + 1);
0136 _TH1F_Pedestals_sum =
0137 fs->make<TH1F>("Summary_Pedestal", "Pedestal Summary", vdetId_.size() + 1, 0, vdetId_.size() + 1);
0138 _TH1F_Pedestals_all = fs->make<TH1F>("PedestalsAll", "all Pedestals", 350, -100, 250);
0139 _TH1F_Pedestals_bpix = fs->make<TH1F>("PedestalsBpix", "bpix Pedestals", 350, -100, 250);
0140 _TH1F_Pedestals_fpix = fs->make<TH1F>("PedestalsFpix", "fpix Pedestals", 350, -100, 250);
0141 _TH1F_Gains_all = fs->make<TH1F>("GainsAll", "all Gains", 100, 0, 10);
0142 _TH1F_Gains_bpix = fs->make<TH1F>("GainsBpix", "bpix Gains", 100, 0, 10);
0143 _TH1F_Gains_fpix = fs->make<TH1F>("GainsFpix", "fpix Gains", 100, 0, 10);
0144
0145 TTree *tree = new TTree("tree", "tree");
0146 uint32_t detid;
0147 double gainmeanfortree, gainrmsfortree, pedmeanfortree, pedrmsfortree;
0148 tree->Branch("detid", &detid, "detid/I");
0149 tree->Branch("ped_mean", &pedmeanfortree, "ped_mean/D");
0150 tree->Branch("ped_rms", &pedrmsfortree, "ped_rms/D");
0151 tree->Branch("gain_mean", &gainmeanfortree, "gain_mean/D");
0152 tree->Branch("gain_rms", &gainrmsfortree, "gain_rms/D");
0153
0154
0155 int ibin = 1;
0156 for (std::vector<uint32_t>::const_iterator detid_iter = vdetId_.begin(); detid_iter != vdetId_.end();
0157 detid_iter++) {
0158 detid = *detid_iter;
0159
0160 sprintf(name, "Pedestals_%d", detid);
0161 _TH1F_Pedestals_m[detid] = subDirPed.make<TH1F>(name, name, 350, -100., 250.);
0162 sprintf(name, "Gains_%d", detid);
0163 _TH1F_Gains_m[detid] = subDirGain.make<TH1F>(name, name, 100, 0., 10.);
0164
0165 DetId detIdObject(detid);
0166 const PixelGeomDetUnit *_PixelGeomDetUnit =
0167 dynamic_cast<const PixelGeomDetUnit *>(tkgeom->idToDetUnit(DetId(detid)));
0168 if (_PixelGeomDetUnit == nullptr) {
0169 edm::LogError("SiPixelCondObjOfflineDisplay") << "[SiPixelCondObjOfflineReader::beginJob] the detID " << detid
0170 << " doesn't seem to belong to Tracker" << std::endl;
0171 continue;
0172 }
0173
0174 _deadfrac_m[detid] = 0.;
0175 _noisyfrac_m[detid] = 0.;
0176
0177 nmodules++;
0178
0179 const GeomDetUnit *geoUnit = tkgeom->idToDetUnit(detIdObject);
0180 const PixelGeomDetUnit *pixDet = dynamic_cast<const PixelGeomDetUnit *>(geoUnit);
0181 const PixelTopology &topol = pixDet->specificTopology();
0182
0183
0184 int nrows = topol.nrows();
0185 int ncols = topol.ncolumns();
0186 float nchannelspermod = 0;
0187
0188 for (int col_iter = 0; col_iter < ncols; col_iter++) {
0189 for (int row_iter = 0; row_iter < nrows; row_iter++) {
0190 nchannelspermod++;
0191 nchannels++;
0192
0193 if (SiPixelGainCalibrationService_->isDead(detid, col_iter, row_iter)) {
0194
0195 ndead++;
0196 _deadfrac_m[detid]++;
0197 continue;
0198 } else if (SiPixelGainCalibrationService_->isNoisy(detid, col_iter, row_iter)) {
0199
0200 nnoisy++;
0201 _noisyfrac_m[detid]++;
0202 continue;
0203 }
0204
0205 float gain = SiPixelGainCalibrationService_->getGain(detid, col_iter, row_iter);
0206 _TH1F_Gains_m[detid]->Fill(gain);
0207 _TH1F_Gains_all->Fill(gain);
0208
0209 if (detIdObject.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel))
0210 _TH1F_Gains_bpix->Fill(gain);
0211 if (detIdObject.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))
0212 _TH1F_Gains_fpix->Fill(gain);
0213
0214 float ped = SiPixelGainCalibrationService_->getPedestal(detid, col_iter, row_iter);
0215 _TH1F_Pedestals_m[detid]->Fill(ped);
0216 _TH1F_Pedestals_all->Fill(ped);
0217
0218
0219 if (detIdObject.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel))
0220 _TH1F_Pedestals_bpix->Fill(ped);
0221 if (detIdObject.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))
0222 _TH1F_Pedestals_fpix->Fill(ped);
0223
0224
0225 }
0226 }
0227
0228 _deadfrac_m[detid] /= nchannelspermod;
0229 _noisyfrac_m[detid] /= nchannelspermod;
0230 _TH1F_Dead_sum->SetBinContent(ibin, _deadfrac_m[detid]);
0231 _TH1F_Dead_all->Fill(_deadfrac_m[detid]);
0232 _TH1F_Noisy_sum->SetBinContent(ibin, _noisyfrac_m[detid]);
0233 _TH1F_Noisy_all->Fill(_noisyfrac_m[detid]);
0234 _TH1F_Gains_sum->SetBinContent(ibin, _TH1F_Gains_m[detid]->GetMean());
0235 _TH1F_Gains_sum->SetBinError(ibin, _TH1F_Gains_m[detid]->GetRMS());
0236 _TH1F_Pedestals_sum->SetBinContent(ibin, _TH1F_Pedestals_m[detid]->GetMean());
0237 _TH1F_Pedestals_sum->SetBinError(ibin, _TH1F_Pedestals_m[detid]->GetRMS());
0238
0239 gainmeanfortree = _TH1F_Gains_m[detid]->GetMean();
0240 gainrmsfortree = _TH1F_Gains_m[detid]->GetRMS();
0241 pedmeanfortree = _TH1F_Pedestals_m[detid]->GetMean();
0242 pedrmsfortree = _TH1F_Pedestals_m[detid]->GetRMS();
0243 edm::LogPrint("SiPixelCondObjOfflineReader")
0244 << "DetId " << detid << " GainMean " << gainmeanfortree << " RMS " << gainrmsfortree << " PedMean "
0245 << pedmeanfortree << " RMS " << pedrmsfortree << std::endl;
0246 tree->Fill();
0247
0248 if (pedmeanfortree == 0)
0249 edm::LogPrint("SiPixelCondObjOfflineReader") << detid << std::endl;
0250
0251 ibin++;
0252 }
0253
0254 edm::LogInfo("SiPixelCondObjOfflineReader")
0255 << "[SiPixelCondObjOfflineReader::analyze] ---> PIXEL Modules " << nmodules << std::endl;
0256 edm::LogInfo("SiPixelCondObjOfflineReader")
0257 << "[SiPixelCondObjOfflineReader::analyze] ---> PIXEL Channels (i.e. Number of Columns)" << nchannels
0258 << std::endl;
0259
0260 edm::LogPrint("SiPixelCondObjOfflineReader") << " ---> SUMMARY :" << std::endl;
0261 edm::LogPrint("SiPixelCondObjOfflineReader") << "Encounted " << ndead << " dead pixels" << std::endl;
0262 edm::LogPrint("SiPixelCondObjOfflineReader") << "Encounted " << nnoisy << " noisy pixels" << std::endl;
0263 edm::LogPrint("SiPixelCondObjOfflineReader")
0264 << "The Gain Mean is " << _TH1F_Gains_all->GetMean() << " with rms " << _TH1F_Gains_all->GetRMS() << std::endl;
0265 edm::LogPrint("SiPixelCondObjOfflineReader") << " in BPIX " << _TH1F_Gains_bpix->GetMean() << " with rms "
0266 << _TH1F_Gains_bpix->GetRMS() << std::endl;
0267 edm::LogPrint("SiPixelCondObjOfflineReader") << " in FPIX " << _TH1F_Gains_fpix->GetMean() << " with rms "
0268 << _TH1F_Gains_fpix->GetRMS() << std::endl;
0269 edm::LogPrint("SiPixelCondObjOfflineReader") << "The Ped Mean is " << _TH1F_Pedestals_all->GetMean() << " with rms "
0270 << _TH1F_Pedestals_all->GetRMS() << std::endl;
0271 edm::LogPrint("SiPixelCondObjOfflineReader") << " in BPIX " << _TH1F_Pedestals_bpix->GetMean()
0272 << " with rms " << _TH1F_Pedestals_bpix->GetRMS() << std::endl;
0273 edm::LogPrint("SiPixelCondObjOfflineReader") << " in FPIX " << _TH1F_Pedestals_fpix->GetMean()
0274 << " with rms " << _TH1F_Pedestals_fpix->GetRMS() << std::endl;
0275 }
0276
0277
0278 void SiPixelCondObjOfflineReader::endJob() {
0279 edm::LogPrint("SiPixelCondObjOfflineReader") << " ---> End job " << std::endl;
0280 }
0281
0282 void SiPixelCondObjOfflineReader::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0283 edm::ParameterSetDescription desc;
0284 desc.setComment("EDAnalyzer to read per-module SiPixelGainCalibrationForOffline payloads in the EventSetup");
0285 desc.add<bool>("useSimRcd", false);
0286 desc.addUntracked<double>("maxRangeDeadPixHist", 0.001);
0287 descriptions.addWithDefaultLabel(desc);
0288 }
0289
0290 }
0291 using namespace cms;
0292 DEFINE_FWK_MODULE(SiPixelCondObjOfflineReader);