File indexing completed on 2024-04-06 12:08:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <sstream>
0016 #include <fstream>
0017 #include <iostream>
0018 #include <memory>
0019 #include <list>
0020 #include <algorithm>
0021 #include <cassert>
0022
0023 #include "TCanvas.h"
0024 #include "TH1F.h"
0025 #include "TStyle.h"
0026 #include "TPaveStats.h"
0027
0028 #include "FWCore/Framework/interface/Frameworkfwd.h"
0029 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0030 #include "FWCore/Framework/interface/Event.h"
0031 #include "FWCore/Framework/interface/EventSetup.h"
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 #include "FWCore/ServiceRegistry/interface/Service.h"
0034 #include "FWCore/Utilities/interface/Exception.h"
0035
0036 #include "CondFormats/DataRecord/interface/SiStripFedCablingRcd.h"
0037 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
0038 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
0039 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0040 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0041
0042 #include "CommonTools/TrackerMap/interface/TrackerMap.h"
0043 #include "CommonTools/TrackerMap/interface/TmModule.h"
0044 #include "CommonTools/TrackerMap/interface/TmApvPair.h"
0045
0046 #include "DQM/SiStripCommon/interface/TkHistoMap.h"
0047
0048 #include "DQMServices/Core/interface/DQMStore.h"
0049
0050
0051
0052
0053
0054 class BuildTrackerMapPlugin : public edm::one::EDAnalyzer<> {
0055 public:
0056 typedef dqm::legacy::MonitorElement MonitorElement;
0057 typedef dqm::legacy::DQMStore DQMStore;
0058
0059 explicit BuildTrackerMapPlugin(const edm::ParameterSet&);
0060 ~BuildTrackerMapPlugin() override {}
0061
0062 private:
0063 void beginJob() override;
0064 void analyze(const edm::Event&, const edm::EventSetup&) override;
0065 void endJob() override;
0066
0067 void read(bool aMechView,
0068 std::string aFile,
0069 const TkDetMap* tkDetMap,
0070 std::vector<std::unique_ptr<TkHistoMap>>& aTkMapVec,
0071 std::vector<bool>& aValidVec);
0072 void subtractMap(TkHistoMap* aResult, const TkHistoMap* aSubtr);
0073
0074
0075 std::string fileName_;
0076
0077 bool mechanicalView_;
0078
0079 std::string folderName_;
0080
0081 unsigned int printDebug_;
0082
0083 bool doDiff_;
0084 std::string fileNameDiff_;
0085
0086 std::vector<std::unique_ptr<TkHistoMap>> tkHistoMapVec_;
0087 std::vector<std::unique_ptr<TkHistoMap>> tkHistoMapVecDiff_;
0088
0089
0090 std::vector<std::string> tkHistoMapNameVec_;
0091 std::vector<double> minVal_;
0092 std::vector<double> maxVal_;
0093
0094 std::vector<bool> isValidMap_;
0095 std::vector<bool> isValidMapDiff_;
0096
0097 edm::ParameterSet pset_;
0098 std::vector<TrackerMap*> tkmap_;
0099
0100 edm::ESGetToken<SiStripFedCabling, SiStripFedCablingRcd> fedCablingToken_;
0101 edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0102 edm::ESGetToken<TkDetMap, TrackerTopologyRcd> tkDetMapToken_;
0103 };
0104
0105
0106
0107
0108
0109 BuildTrackerMapPlugin::BuildTrackerMapPlugin(const edm::ParameterSet& iConfig)
0110 : fileName_(iConfig.getUntrackedParameter<std::string>("InputFileName", "DQMStore.root")),
0111 mechanicalView_(iConfig.getUntrackedParameter<bool>("MechanicalView", true)),
0112 folderName_(iConfig.getUntrackedParameter<std::string>("HistogramFolderName", "DQMData/")),
0113 printDebug_(iConfig.getUntrackedParameter<unsigned int>("PrintDebugMessages", 1)),
0114 doDiff_(iConfig.getUntrackedParameter<bool>("DoDifference", false)),
0115 fileNameDiff_(iConfig.getUntrackedParameter<std::string>("InputFileNameForDiff", "DQMStore.root")),
0116 tkHistoMapNameVec_(iConfig.getUntrackedParameter<std::vector<std::string>>("TkHistoMapNameVec")),
0117 minVal_(iConfig.getUntrackedParameter<std::vector<double>>("MinValueVec")),
0118 maxVal_(iConfig.getUntrackedParameter<std::vector<double>>("MaxValueVec")),
0119 pset_(iConfig.getParameter<edm::ParameterSet>("TkmapParameters")),
0120 fedCablingToken_(esConsumes<>()),
0121 tTopoToken_(esConsumes<>()),
0122 tkDetMapToken_(esConsumes<>()) {
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134 }
0135
0136
0137
0138
0139
0140
0141 void BuildTrackerMapPlugin::read(bool aMechView,
0142 std::string aFile,
0143 const TkDetMap* tkDetMap,
0144 std::vector<std::unique_ptr<TkHistoMap>>& aTkMapVec,
0145 std::vector<bool>& aValidVec) {
0146 DQMStore* lDqmStore = edm::Service<DQMStore>().operator->();
0147 lDqmStore->open(aFile);
0148
0149 unsigned int nHists = tkHistoMapNameVec_.size();
0150 aTkMapVec.reserve(nHists);
0151 aValidVec.reserve(nHists);
0152
0153 std::string dirName = folderName_;
0154 if (dirName.empty()) {
0155 dirName += "Run ";
0156 dirName += aFile.substr(aFile.find_last_of('_') + 5, 6);
0157 dirName += "/SiStrip/Run summary";
0158 std::cout << " -- DirName = " << dirName << std::endl;
0159 }
0160
0161
0162
0163 unsigned int nFailTot = 0;
0164 unsigned int nTotTot = 0;
0165 for (unsigned int i(0); i < nHists; i++) {
0166 std::unique_ptr<TkHistoMap> tkHistoMap{new TkHistoMap(tkDetMap)};
0167
0168 tkHistoMap->loadTkHistoMap(dirName, tkHistoMapNameVec_.at(i), aMechView);
0169
0170 std::vector<MonitorElement*>& lMaps = tkHistoMap->getAllMaps();
0171
0172 std::cout << " -- map " << i << ", nHistos = " << lMaps.size() << std::endl;
0173 unsigned int nFail = 0;
0174 unsigned int nTot = 0;
0175
0176 for (unsigned int im(0); im < lMaps.size(); im++) {
0177 if (!lMaps[im]) {
0178 std::cout << " -- Failed to get element " << im << " for map " << i << std::endl;
0179 nFail++;
0180 nFailTot++;
0181 }
0182 nTot++;
0183 nTotTot++;
0184 }
0185
0186 if (nFail == nTot)
0187 aValidVec[i] = false;
0188 aTkMapVec.emplace_back(std::move(tkHistoMap));
0189 }
0190
0191 if (nFailTot < nTotTot)
0192 std::cout << " - " << nTotTot - nFailTot << "/" << nTotTot << " histomaps read with success for file ." << aFile
0193 << std::endl;
0194 else {
0195 std::cout << " - Failed to read any map for file " << aFile << ". Exiting line ... " << __LINE__ << std::endl;
0196 exit(1);
0197 }
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289 }
0290
0291
0292 void BuildTrackerMapPlugin::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0293 static bool firstEvent = true;
0294
0295 if (tkHistoMapVec_.empty() && (!tkHistoMapNameVec_.empty())) {
0296 const auto tkDetMap = &iSetup.getData(tkDetMapToken_);
0297 read(mechanicalView_, fileName_, tkDetMap, tkHistoMapVec_, isValidMap_);
0298 if (doDiff_)
0299 read(mechanicalView_, fileNameDiff_, tkDetMap, tkHistoMapVecDiff_, isValidMapDiff_);
0300 }
0301
0302 if (firstEvent) {
0303 const auto fedcabling = &iSetup.getData(fedCablingToken_);
0304 const auto tTopo = &iSetup.getData(tTopoToken_);
0305 for (unsigned int i(0); i < tkHistoMapNameVec_.size(); i++) {
0306 tkmap_.push_back(new TrackerMap(pset_, fedcabling, tTopo));
0307 }
0308 }
0309
0310 firstEvent = false;
0311
0312 std::cout << "End of analyze method: tkmap_ size = " << tkmap_.size() << std::endl;
0313
0314 }
0315
0316
0317 void BuildTrackerMapPlugin::beginJob() {}
0318
0319
0320 void BuildTrackerMapPlugin::endJob() {
0321
0322
0323 std::cout << "Processing endjob with " << tkHistoMapNameVec_.size() << " elements." << std::endl;
0324
0325 assert(minVal_.size() == tkHistoMapNameVec_.size());
0326 assert(maxVal_.size() == tkHistoMapNameVec_.size());
0327
0328 for (unsigned int i(0); i < tkHistoMapNameVec_.size(); i++) {
0329 std::cout << "Processing element " << i << ": " << tkHistoMapNameVec_.at(i) << std::endl;
0330 std::cout << "Min, max = " << minVal_.at(i) << " " << maxVal_.at(i) << std::endl;
0331
0332 TrackerMap* lTkMap = tkmap_.at(i);
0333
0334 if (!lTkMap) {
0335 std::cout << "tkmap_ is NULL for element " << i << "... continuing ..." << std::endl;
0336 continue;
0337 }
0338
0339 subtractMap(tkHistoMapVec_.at(i).get(), tkHistoMapVecDiff_.at(i).get());
0340
0341
0342 lTkMap->setPalette(1);
0343 lTkMap->showPalette(true);
0344 if (!tkHistoMapVec_.at(i) || !isValidMap_.at(i)) {
0345 std::cout << "Warning, tkHistoMap is invalid for element " << i << "... continuing ..." << std::endl;
0346 continue;
0347 }
0348 tkHistoMapVec_.at(i)->dumpInTkMap(lTkMap);
0349
0350
0351
0352 lTkMap->save(true, minVal_.at(i), maxVal_.at(i), tkHistoMapNameVec_.at(i) + std::string(".png"));
0353 lTkMap->save_as_fedtrackermap(
0354 true, minVal_.at(i), maxVal_.at(i), tkHistoMapNameVec_.at(i) + std::string("_FED.png"));
0355 }
0356 }
0357
0358 void BuildTrackerMapPlugin::subtractMap(TkHistoMap* aResult, const TkHistoMap* aSubtr) {
0359 std::vector<MonitorElement*>& lMaps = aResult->getAllMaps();
0360 const std::vector<MonitorElement*>& lMapsDiff = aSubtr->getAllMaps();
0361
0362 assert(lMaps.size() == lMapsDiff.size());
0363
0364 for (unsigned int im(0); im < lMaps.size(); im++) {
0365 if (!lMaps[im] || !lMapsDiff[im]) {
0366 std::cout << " -- Failed to get element " << im << " for maps." << std::endl;
0367 } else {
0368 (lMaps[im]->getTProfile2D())->Add(lMapsDiff[im]->getTProfile2D(), -1);
0369 }
0370 }
0371 }
0372
0373
0374
0375
0376 #include "FWCore/Framework/interface/MakerMacros.h"
0377 DEFINE_FWK_MODULE(BuildTrackerMapPlugin);