00001
00002
00003
00004
00005
00006
00011
00012
00013
00014
00015
00016 #include <sstream>
00017 #include <fstream>
00018 #include <iostream>
00019 #include <memory>
00020 #include <list>
00021 #include <algorithm>
00022 #include <cassert>
00023
00024 #include "TCanvas.h"
00025 #include "TH1F.h"
00026 #include "TStyle.h"
00027 #include "TPaveStats.h"
00028
00029 #include "FWCore/Framework/interface/Frameworkfwd.h"
00030 #include "FWCore/Framework/interface/EDAnalyzer.h"
00031 #include "FWCore/Framework/interface/Event.h"
00032 #include "FWCore/Framework/interface/EventSetup.h"
00033 #include "FWCore/Framework/interface/ESHandle.h"
00034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00035 #include "FWCore/ServiceRegistry/interface/Service.h"
00036 #include "FWCore/Utilities/interface/Exception.h"
00037
00038 #include "CondFormats/DataRecord/interface/SiStripFedCablingRcd.h"
00039 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
00040 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
00041
00042 #include "CommonTools/TrackerMap/interface/TrackerMap.h"
00043 #include "CommonTools/TrackerMap/interface/TmModule.h"
00044 #include "CommonTools/TrackerMap/interface/TmApvPair.h"
00045
00046 #include "DQM/SiStripCommon/interface/TkHistoMap.h"
00047
00048 #include "DQMServices/Core/interface/DQMStore.h"
00049
00050
00051
00052
00053
00054 class BuildTrackerMapPlugin : public edm::EDAnalyzer
00055 {
00056 public:
00057
00058 explicit BuildTrackerMapPlugin(const edm::ParameterSet&);
00059 ~BuildTrackerMapPlugin();
00060 private:
00061 virtual void beginJob();
00062 virtual void analyze(const edm::Event&, const edm::EventSetup&);
00063 virtual void endJob();
00064
00065 void read(bool aMechView,
00066 std::string aFile,
00067 std::vector<TkHistoMap*> & aTkMapVec,
00068 std::vector<bool> & aValidVec);
00069 void subtractMap(TkHistoMap*& aResult,
00070 TkHistoMap*& aSubtr);
00071
00072
00073
00074
00075 std::string fileName_;
00076
00077 bool mechanicalView_;
00078
00079 std::string folderName_;
00080
00081 unsigned int printDebug_;
00082
00083 bool doDiff_;
00084 std::string fileNameDiff_;
00085
00086 std::vector<TkHistoMap*> tkHistoMapVec_;
00087 std::vector<TkHistoMap*> tkHistoMapVecDiff_;
00088
00089
00090 std::vector<std::string> tkHistoMapNameVec_;
00091 std::vector<double> minVal_;
00092 std::vector<double> maxVal_;
00093
00094 std::vector<bool> isValidMap_;
00095 std::vector<bool> isValidMapDiff_;
00096
00097 edm::ParameterSet pset_;
00098 std::vector<TrackerMap*> tkmap_;
00099
00100 };
00101
00102
00103
00104
00105
00106
00107 BuildTrackerMapPlugin::BuildTrackerMapPlugin(const edm::ParameterSet& iConfig)
00108 : fileName_(iConfig.getUntrackedParameter<std::string>("InputFileName","DQMStore.root")),
00109 mechanicalView_(iConfig.getUntrackedParameter<bool>("MechanicalView",true)),
00110 folderName_(iConfig.getUntrackedParameter<std::string>("HistogramFolderName","DQMData/")),
00111 printDebug_(iConfig.getUntrackedParameter<unsigned int>("PrintDebugMessages",1)),
00112 doDiff_(iConfig.getUntrackedParameter<bool>("DoDifference",false)),
00113 fileNameDiff_(iConfig.getUntrackedParameter<std::string>("InputFileNameForDiff","DQMStore.root")),
00114 tkHistoMapNameVec_(iConfig.getUntrackedParameter<std::vector<std::string> >("TkHistoMapNameVec")),
00115 minVal_(iConfig.getUntrackedParameter<std::vector<double> >("MinValueVec")),
00116 maxVal_(iConfig.getUntrackedParameter<std::vector<double> >("MaxValueVec")),
00117 pset_(iConfig.getParameter<edm::ParameterSet>("TkmapParameters"))
00118 {
00119
00120 read(mechanicalView_,fileName_,tkHistoMapVec_,isValidMap_);
00121 if (doDiff_) read(mechanicalView_,fileNameDiff_,tkHistoMapVecDiff_,isValidMapDiff_);
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 }
00137
00138 BuildTrackerMapPlugin::~BuildTrackerMapPlugin()
00139 {
00140
00141 tkHistoMapVec_.clear();
00142 if (doDiff_) tkHistoMapVecDiff_.clear();
00143 }
00144
00145
00146
00147
00148
00149
00150
00151 void BuildTrackerMapPlugin::read(bool aMechView,
00152 std::string aFile,
00153 std::vector<TkHistoMap*> & aTkMapVec,
00154 std::vector<bool> & aValidVec)
00155 {
00156
00157 DQMStore * lDqmStore = edm::Service<DQMStore>().operator->();
00158 lDqmStore->open(aFile);
00159 std::vector<TkHistoMap *> tkHistoMap;
00160
00161 unsigned int nHists = tkHistoMapNameVec_.size();
00162 tkHistoMap.resize(nHists,0);
00163 aValidVec.resize(nHists,true);
00164
00165 std::string dirName = folderName_;
00166 if (dirName == "") {
00167 dirName += "Run ";
00168 dirName += aFile.substr(aFile.find_last_of("_")+5,6);
00169 dirName += "/SiStrip/Run summary";
00170 std::cout << " -- DirName = " << dirName << std::endl;
00171 }
00172
00173
00174
00175
00176 unsigned int nFailTot=0;
00177 unsigned int nTotTot = 0;
00178 for (unsigned int i(0); i<nHists; i++){
00179
00180 tkHistoMap[i] = new TkHistoMap();
00181
00182 tkHistoMap[i]->loadTkHistoMap(dirName,tkHistoMapNameVec_.at(i),aMechView);
00183
00184 std::vector<MonitorElement*>& lMaps = tkHistoMap[i]->getAllMaps();
00185
00186 std::cout << " -- map " << i << ", nHistos = " << lMaps.size() << std::endl;
00187 unsigned int nFail=0;
00188 unsigned int nTot=0;
00189
00190 for (unsigned int im(0); im<lMaps.size(); im++){
00191 if (!lMaps[im]) {
00192 std::cout << " -- Failed to get element " << im << " for map " << i << std::endl;
00193 nFail++;
00194 nFailTot++;
00195 }
00196 nTot++;
00197 nTotTot++;
00198 }
00199
00200 if (nFail == nTot) aValidVec[i] = false;
00201 aTkMapVec.push_back(tkHistoMap[i]);
00202 }
00203
00204 if (nFailTot < nTotTot) std::cout << " - " << nTotTot-nFailTot << "/" << nTotTot
00205 << " histomaps read with success for file ." << aFile << std::endl;
00206 else {
00207 std::cout << " - Failed to read any map for file " << aFile << ". Exiting line ... " << __LINE__ << std::endl;
00208 exit(1);
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 }
00306
00307
00308
00309 void
00310 BuildTrackerMapPlugin::analyze(const edm::Event& iEvent,
00311 const edm::EventSetup& iSetup)
00312 {
00313
00314 static bool firstEvent = true;
00315
00316 edm::ESHandle<SiStripFedCabling> fedcabling;
00317 iSetup.get<SiStripFedCablingRcd>().get(fedcabling );
00318
00319 if (firstEvent) {
00320 for (unsigned int i(0); i<tkHistoMapNameVec_.size(); i++){
00321 tkmap_.push_back(new TrackerMap(pset_,fedcabling));
00322 }
00323
00324 }
00325
00326 firstEvent = false;
00327
00328 std::cout << "End of analyze method: tkmap_ size = " << tkmap_.size() << std::endl;
00329
00330 }
00331
00332
00333 void
00334 BuildTrackerMapPlugin::beginJob()
00335 {
00336
00337 }
00338
00339
00340 void
00341 BuildTrackerMapPlugin::endJob()
00342 {
00343
00344
00345 std::cout << "Processing endjob with " << tkHistoMapNameVec_.size()<< " elements." << std::endl;
00346
00347 assert (minVal_.size() == tkHistoMapNameVec_.size());
00348 assert (maxVal_.size() == tkHistoMapNameVec_.size());
00349
00350 for (unsigned int i(0); i<tkHistoMapNameVec_.size(); i++){
00351
00352 std::cout << "Processing element " << i << ": " << tkHistoMapNameVec_.at(i) << std::endl;
00353 std::cout << "Min, max = " << minVal_.at(i) << " " << maxVal_.at(i) << std::endl;
00354
00355 TrackerMap* lTkMap = tkmap_.at(i);
00356
00357 if (!lTkMap) {
00358 std::cout << "tkmap_ is NULL for element " << i << "... continuing ..." << std::endl;
00359 continue;
00360 }
00361
00362 subtractMap(tkHistoMapVec_.at(i),tkHistoMapVecDiff_.at(i));
00363
00364
00365
00366 lTkMap->setPalette(1);
00367 lTkMap->showPalette(1);
00368 if (!tkHistoMapVec_.at(i) || !isValidMap_.at(i)) {
00369 std::cout << "Warning, tkHistoMap is invalid for element " << i << "... continuing ..." << std::endl;
00370 continue;
00371 }
00372 tkHistoMapVec_.at(i)->dumpInTkMap(lTkMap);
00373
00374
00375
00376 lTkMap->save(true,
00377 minVal_.at(i),
00378 maxVal_.at(i),
00379 tkHistoMapNameVec_.at(i)+std::string(".png"));
00380 lTkMap->save_as_fedtrackermap(true,
00381 minVal_.at(i),
00382 maxVal_.at(i),
00383 tkHistoMapNameVec_.at(i)+std::string("_FED.png"));
00384
00385 }
00386
00387 }
00388
00389
00390 void BuildTrackerMapPlugin::subtractMap(TkHistoMap *& aResult,
00391 TkHistoMap *& aSubtr)
00392 {
00393
00394 std::vector<MonitorElement*>& lMaps = aResult->getAllMaps();
00395 std::vector<MonitorElement*>& lMapsDiff = aSubtr->getAllMaps();
00396
00397 assert(lMaps.size() == lMapsDiff.size());
00398
00399 for (unsigned int im(0); im<lMaps.size(); im++){
00400 if (!lMaps[im] || !lMapsDiff[im]) {
00401 std::cout << " -- Failed to get element " << im << " for maps." << std::endl;
00402 }
00403 else {
00404 (lMaps[im]->getTProfile2D())->Add(lMapsDiff[im]->getTProfile2D(),-1);
00405 }
00406 }
00407
00408 }
00409
00410
00411
00412
00413
00414
00415 #include "FWCore/Framework/interface/MakerMacros.h"
00416 DEFINE_FWK_MODULE(BuildTrackerMapPlugin);