File indexing completed on 2024-10-17 04:57:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021
0022
0023 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationOfflineService.h"
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/MakerMacros.h"
0026 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0028 #include "FWCore/PluginManager/interface/ModuleDef.h"
0029 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0030 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
0031 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0032 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0033 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0035 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0036
0037
0038 #include "TROOT.h"
0039 #include "TFile.h"
0040 #include "TTree.h"
0041 #include "TBranch.h"
0042 #include "TH1F.h"
0043
0044 namespace cms {
0045 class SiPixelFakeGainOfflineReader : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0046 public:
0047 explicit SiPixelFakeGainOfflineReader(const edm::ParameterSet& iConfig);
0048 ~SiPixelFakeGainOfflineReader() override = default;
0049
0050 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0051
0052 virtual void beginRun(const edm::Run&, const edm::EventSetup&) override;
0053 virtual void endRun(const edm::Run&, const edm::EventSetup&) override;
0054 virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
0055 virtual void endJob() override;
0056
0057 private:
0058 SiPixelGainCalibrationOfflineService SiPixelGainCalibrationOfflineService_;
0059 edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> trackerGeomToken_;
0060 edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> trackerGeomTokenBeginRun_;
0061 std::map<uint32_t, TH1F*> _TH1F_Pedestals_m;
0062 std::map<uint32_t, TH1F*> _TH1F_Gains_m;
0063 std::string filename_;
0064 TFile* fFile;
0065 };
0066 }
0067
0068 namespace cms {
0069 SiPixelFakeGainOfflineReader::SiPixelFakeGainOfflineReader(const edm::ParameterSet& conf)
0070 : SiPixelGainCalibrationOfflineService_(conf, consumesCollector()),
0071 trackerGeomToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()),
0072 trackerGeomTokenBeginRun_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>()),
0073 filename_(conf.getParameter<std::string>("fileName")) {}
0074
0075 void SiPixelFakeGainOfflineReader::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0076 unsigned int nmodules = 0;
0077 uint32_t nchannels = 0;
0078 fFile->cd();
0079
0080
0081 edm::ESHandle<TrackerGeometry> tkgeom = iSetup.getHandle(trackerGeomToken_);
0082 edm::LogInfo("SiPixelFakeGainOfflineReader") << " There are " << tkgeom->dets().size() << " detectors" << std::endl;
0083
0084
0085
0086
0087
0088
0089 std::vector<uint32_t> vdetId_ = SiPixelGainCalibrationOfflineService_.getDetIds();
0090
0091 for (std::vector<uint32_t>::const_iterator detid_iter = vdetId_.begin(); detid_iter != vdetId_.end();
0092 detid_iter++) {
0093 uint32_t detid = *detid_iter;
0094
0095 DetId detIdObject(detid);
0096 nmodules++;
0097
0098
0099 std::map<uint32_t, TH1F*>::iterator p_iter = _TH1F_Pedestals_m.find(detid);
0100 std::map<uint32_t, TH1F*>::iterator g_iter = _TH1F_Gains_m.find(detid);
0101
0102 const GeomDetUnit* geoUnit = tkgeom->idToDetUnit(detIdObject);
0103 const PixelGeomDetUnit* pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
0104 const PixelTopology& topol = pixDet->specificTopology();
0105
0106
0107 int nrows = topol.nrows();
0108 int ncols = topol.ncolumns();
0109
0110 for (int col_iter = 0; col_iter < ncols; col_iter++) {
0111 for (int row_iter = 0; row_iter < nrows; row_iter++) {
0112 nchannels++;
0113
0114 float gain = SiPixelGainCalibrationOfflineService_.getGain(detid, col_iter, row_iter);
0115 g_iter->second->Fill(gain);
0116 float ped = SiPixelGainCalibrationOfflineService_.getPedestal(detid, col_iter, row_iter);
0117 p_iter->second->Fill(ped);
0118
0119
0120 }
0121 }
0122 }
0123
0124 edm::LogInfo("SiPixelFakeGainOfflineReader")
0125 << "[SiPixelFakeGainOfflineReader::analyze] ---> PIXEL Modules " << nmodules << std::endl;
0126 edm::LogInfo("SiPixelFakeGainOfflineReader")
0127 << "[SiPixelFakeGainOfflineReader::analyze] ---> PIXEL Channels " << nchannels << std::endl;
0128 fFile->ls();
0129 fFile->Write();
0130 fFile->Close();
0131 }
0132
0133 void SiPixelFakeGainOfflineReader::endRun(const edm::Run& run, const edm::EventSetup& iSetup) {}
0134
0135
0136 void SiPixelFakeGainOfflineReader::beginRun(const edm::Run& run, const edm::EventSetup& iSetup) {
0137 static int first(1);
0138 if (1 == first) {
0139 first = 0;
0140 edm::LogInfo("SiPixelFakeGainOfflineReader")
0141 << "[SiPixelFakeGainOfflineReader::beginJob] Opening ROOT file " << std::endl;
0142 fFile = new TFile(filename_.c_str(), "RECREATE");
0143 fFile->mkdir("Pedestals");
0144 fFile->mkdir("Gains");
0145 fFile->cd();
0146 char name[128];
0147
0148
0149 edm::ESHandle<TrackerGeometry> tkgeom = iSetup.getHandle(trackerGeomTokenBeginRun_);
0150
0151
0152 SiPixelGainCalibrationOfflineService_.setESObjects(iSetup);
0153 edm::LogInfo("SiPixelFakeGainOfflineReader")
0154 << "[SiPixelFakeGainOfflineReader::beginJob] End Reading FakeGainOfflineects" << std::endl;
0155
0156 std::vector<uint32_t> vdetId_ = SiPixelGainCalibrationOfflineService_.getDetIds();
0157
0158 for (std::vector<uint32_t>::const_iterator detid_iter = vdetId_.begin(); detid_iter != vdetId_.end();
0159 detid_iter++) {
0160 uint32_t detid = *detid_iter;
0161
0162 const PixelGeomDetUnit* _PixelGeomDetUnit =
0163 dynamic_cast<const PixelGeomDetUnit*>(tkgeom->idToDetUnit(DetId(detid)));
0164 if (_PixelGeomDetUnit == 0) {
0165 edm::LogError("SiPixelFakeGainOfflineDisplay") << "[SiPixelFakeGainOfflineReader::beginJob] the detID "
0166 << detid << " doesn't seem to belong to Tracker" << std::endl;
0167 continue;
0168 }
0169
0170 sprintf(name, "Pedestals_%d", detid);
0171 fFile->cd();
0172 fFile->cd("Pedestals");
0173 _TH1F_Pedestals_m[detid] = new TH1F(name, name, 50, 0., 50.);
0174 sprintf(name, "Gains_%d", detid);
0175 fFile->cd();
0176 fFile->cd("Gains");
0177 _TH1F_Gains_m[detid] = new TH1F(name, name, 100, 0., 10.);
0178 }
0179 }
0180 }
0181
0182
0183 void SiPixelFakeGainOfflineReader::endJob() { std::cout << " ---> End job " << std::endl; }
0184
0185 void SiPixelFakeGainOfflineReader::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0186 edm::ParameterSetDescription desc;
0187 desc.add<std::string>("fileName", "out.root");
0188 descriptions.addWithDefaultLabel(desc);
0189 }
0190 }
0191
0192 using cms::SiPixelFakeGainOfflineReader;
0193 DEFINE_FWK_MODULE(SiPixelFakeGainOfflineReader);