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/SiPixelGainCalibrationService.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 SiPixelFakeGainReader : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0046 public:
0047 explicit SiPixelFakeGainReader(const edm::ParameterSet& iConfig);
0048 ~SiPixelFakeGainReader() 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 edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> trackerGeomToken_;
0059 edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> trackerGeomTokenBeginRun_;
0060 SiPixelGainCalibrationService SiPixelGainCalibrationService_;
0061
0062 std::map<uint32_t, TH1F*> _TH1F_Pedestals_m;
0063 std::map<uint32_t, TH1F*> _TH1F_Gains_m;
0064 std::string filename_;
0065 TFile* fFile;
0066 };
0067 }
0068
0069 namespace cms {
0070 SiPixelFakeGainReader::SiPixelFakeGainReader(const edm::ParameterSet& conf)
0071 : trackerGeomToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()),
0072 trackerGeomTokenBeginRun_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>()),
0073 SiPixelGainCalibrationService_(conf, consumesCollector()),
0074 filename_(conf.getParameter<std::string>("fileName")) {}
0075
0076 void SiPixelFakeGainReader::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0077 unsigned int nmodules = 0;
0078 uint32_t nchannels = 0;
0079 fFile->cd();
0080
0081
0082 edm::ESHandle<TrackerGeometry> tkgeom = iSetup.getHandle(trackerGeomToken_);
0083 edm::LogInfo("SiPixelFakeGainReader") << " There are " << tkgeom->dets().size() << " detectors" << std::endl;
0084
0085
0086
0087
0088
0089
0090 std::vector<uint32_t> vdetId_ = SiPixelGainCalibrationService_.getDetIds();
0091
0092 for (std::vector<uint32_t>::const_iterator detid_iter = vdetId_.begin(); detid_iter != vdetId_.end();
0093 detid_iter++) {
0094 uint32_t detid = *detid_iter;
0095
0096 DetId detIdObject(detid);
0097 nmodules++;
0098
0099
0100 std::map<uint32_t, TH1F*>::iterator p_iter = _TH1F_Pedestals_m.find(detid);
0101 std::map<uint32_t, TH1F*>::iterator g_iter = _TH1F_Gains_m.find(detid);
0102
0103 const GeomDetUnit* geoUnit = tkgeom->idToDetUnit(detIdObject);
0104 const PixelGeomDetUnit* pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
0105 const PixelTopology& topol = pixDet->specificTopology();
0106
0107
0108 int nrows = topol.nrows();
0109 int ncols = topol.ncolumns();
0110
0111 for (int col_iter = 0; col_iter < ncols; col_iter++) {
0112 for (int row_iter = 0; row_iter < nrows; row_iter++) {
0113 nchannels++;
0114
0115 float ped = SiPixelGainCalibrationService_.getPedestal(detid, col_iter, row_iter);
0116 p_iter->second->Fill(ped);
0117
0118 float gain = SiPixelGainCalibrationService_.getGain(detid, col_iter, row_iter);
0119 g_iter->second->Fill(gain);
0120
0121
0122 }
0123 }
0124 }
0125
0126 edm::LogInfo("SiPixelFakeGainReader")
0127 << "[SiPixelFakeGainReader::analyze] ---> PIXEL Modules " << nmodules << std::endl;
0128 edm::LogInfo("SiPixelFakeGainReader")
0129 << "[SiPixelFakeGainReader::analyze] ---> PIXEL Channels " << nchannels << std::endl;
0130 fFile->ls();
0131 fFile->Write();
0132 fFile->Close();
0133 }
0134
0135 void SiPixelFakeGainReader::endRun(const edm::Run& run, const edm::EventSetup& iSetup) {}
0136
0137
0138 void SiPixelFakeGainReader::beginRun(const edm::Run& run, const edm::EventSetup& iSetup) {
0139 static int first(1);
0140 if (1 == first) {
0141 first = 0;
0142 edm::LogInfo("SiPixelFakeGainReader") << "[SiPixelFakeGainReader::beginJob] Opening ROOT file " << std::endl;
0143 fFile = new TFile(filename_.c_str(), "RECREATE");
0144 fFile->mkdir("Pedestals");
0145 fFile->mkdir("Gains");
0146 fFile->cd();
0147 char name[128];
0148
0149
0150 edm::ESHandle<TrackerGeometry> tkgeom = iSetup.getHandle(trackerGeomTokenBeginRun_);
0151
0152
0153 SiPixelGainCalibrationService_.setESObjects(iSetup);
0154 edm::LogInfo("SiPixelFakeGainReader")
0155 << "[SiPixelFakeGainReader::beginJob] End Reading FakeGainects" << std::endl;
0156
0157 std::vector<uint32_t> vdetId_ = SiPixelGainCalibrationService_.getDetIds();
0158
0159 for (std::vector<uint32_t>::const_iterator detid_iter = vdetId_.begin(); detid_iter != vdetId_.end();
0160 detid_iter++) {
0161 uint32_t detid = *detid_iter;
0162
0163 const PixelGeomDetUnit* _PixelGeomDetUnit =
0164 dynamic_cast<const PixelGeomDetUnit*>(tkgeom->idToDetUnit(DetId(detid)));
0165 if (_PixelGeomDetUnit == 0) {
0166 edm::LogError("SiPixelFakeGainDisplay") << "[SiPixelFakeGainReader::beginJob] the detID " << detid
0167 << " doesn't seem to belong to Tracker" << std::endl;
0168 continue;
0169 }
0170
0171 sprintf(name, "Pedestals_%d", detid);
0172 fFile->cd();
0173 fFile->cd("Pedestals");
0174 _TH1F_Pedestals_m[detid] = new TH1F(name, name, 50, 0., 50.);
0175 sprintf(name, "Gains_%d", detid);
0176 fFile->cd();
0177 fFile->cd("Gains");
0178 _TH1F_Gains_m[detid] = new TH1F(name, name, 100, 0., 10.);
0179 }
0180 }
0181 }
0182
0183
0184 void SiPixelFakeGainReader::endJob() { std::cout << " ---> End job " << std::endl; }
0185
0186 void SiPixelFakeGainReader::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0187 edm::ParameterSetDescription desc;
0188 desc.add<std::string>("fileName", "out.root");
0189 descriptions.addWithDefaultLabel(desc);
0190 }
0191 }
0192
0193 using cms::SiPixelFakeGainReader;
0194 DEFINE_FWK_MODULE(SiPixelFakeGainReader);