CMS 3D CMS Logo

BuildTrackerMap.cc
Go to the documentation of this file.
1 
2 // -*- C++ -*-
3 //
4 // Package: DQM/SiStripMonitorHardware
5 // Class: BuildTrackerMapPlugin
6 //
11 //
12 // Created: 2009/07/22
13 //
14 
15 #include <sstream>
16 #include <fstream>
17 #include <iostream>
18 #include <memory>
19 #include <list>
20 #include <algorithm>
21 #include <cassert>
22 
23 #include "TCanvas.h"
24 #include "TH1F.h"
25 #include "TStyle.h"
26 #include "TPaveStats.h"
27 
36 
42 
46 
48 
50 
51 //
52 // Class declaration
53 //
54 
56 public:
59 
61  ~BuildTrackerMapPlugin() override {}
62 
63 private:
64  void beginJob() override;
65  void analyze(const edm::Event&, const edm::EventSetup&) override;
66  void endJob() override;
67 
68  void read(bool aMechView,
69  std::string aFile,
70  const TkDetMap* tkDetMap,
71  std::vector<std::unique_ptr<TkHistoMap>>& aTkMapVec,
72  std::vector<bool>& aValidVec);
73  void subtractMap(TkHistoMap* aResult, const TkHistoMap* aSubtr);
74 
75  //input file names
77  //do mechanical view or not
79  //folder name for histograms in DQMStore
81  //print debug messages when problems are found: 1=error debug, 2=light debug, 3=full debug
82  unsigned int printDebug_;
83 
84  bool doDiff_;
86 
87  std::vector<std::unique_ptr<TkHistoMap>> tkHistoMapVec_;
88  std::vector<std::unique_ptr<TkHistoMap>> tkHistoMapVecDiff_;
89 
90  //name of the tkHistoMap to extract
91  std::vector<std::string> tkHistoMapNameVec_;
92  std::vector<double> minVal_;
93  std::vector<double> maxVal_;
94 
95  std::vector<bool> isValidMap_;
96  std::vector<bool> isValidMapDiff_;
97 
99  std::vector<TrackerMap*> tkmap_;
100 };
101 
102 //
103 // Constructors and destructor
104 //
105 
107  : fileName_(iConfig.getUntrackedParameter<std::string>("InputFileName", "DQMStore.root")),
108  mechanicalView_(iConfig.getUntrackedParameter<bool>("MechanicalView", true)),
109  folderName_(iConfig.getUntrackedParameter<std::string>("HistogramFolderName", "DQMData/")),
110  printDebug_(iConfig.getUntrackedParameter<unsigned int>("PrintDebugMessages", 1)),
111  doDiff_(iConfig.getUntrackedParameter<bool>("DoDifference", false)),
112  fileNameDiff_(iConfig.getUntrackedParameter<std::string>("InputFileNameForDiff", "DQMStore.root")),
113  tkHistoMapNameVec_(iConfig.getUntrackedParameter<std::vector<std::string>>("TkHistoMapNameVec")),
114  minVal_(iConfig.getUntrackedParameter<std::vector<double>>("MinValueVec")),
115  maxVal_(iConfig.getUntrackedParameter<std::vector<double>>("MaxValueVec")),
116  pset_(iConfig.getParameter<edm::ParameterSet>("TkmapParameters")) {
117  // for (unsigned int i(0); i<34; i++){
118  // if (i<4) histName_[i] << "TIB/layer_" << i+1 << "/" << tkDetMapName_ << "_TIB_L" << i+1;
119  // else if (i<7) histName_[i] << "TID/side_1/wheel_" << i-3 << "/" << tkDetMapName_ << "_TIDM_D" << i-3;
120  // else if (i<10) histName_[i] << "TID/side_2/wheel_" << i-6 << "/" << tkDetMapName_ << "_TIDP_D" << i-6;
121  // else if (i<16) histName_[i] << "TOB/layer_" << i-9 << "/" << tkDetMapName_ << "_TOB_L" << i-9;
122  // else if (i<25) histName_[i] << "TEC/side_1/wheel_" << i-15 << "/" << tkDetMapName_ << "_TECM_W" << i-15;
123  // else if (i<34) histName_[i] << "TEC/side_2/wheel_" << i-24 << "/" << tkDetMapName_ << "_TECP_W" << i-24;
124 
125  // std::cout << "histName[" << i << "] =" << histName_[i] << std::endl;
126 
127  // }
128 }
129 
130 //
131 // Member functions
132 //
133 
134 /*Check that is possible to load in tkhistomaps histograms already stored in a DQM root file (if the folder and name are known)*/
135 void BuildTrackerMapPlugin::read(bool aMechView,
136  std::string aFile,
137  const TkDetMap* tkDetMap,
138  std::vector<std::unique_ptr<TkHistoMap>>& aTkMapVec,
139  std::vector<bool>& aValidVec) {
140  DQMStore* lDqmStore = edm::Service<DQMStore>().operator->();
141  lDqmStore->open(aFile);
142 
143  unsigned int nHists = tkHistoMapNameVec_.size();
144  aTkMapVec.reserve(nHists);
145  aValidVec.reserve(nHists);
146 
148  if (dirName.empty()) {
149  dirName += "Run ";
150  dirName += aFile.substr(aFile.find_last_of("_") + 5, 6);
151  dirName += "/SiStrip/Run summary";
152  std::cout << " -- DirName = " << dirName << std::endl;
153  }
154 
155  //lDqmStore->setCurrentFolder(dirName);
156 
157  unsigned int nFailTot = 0;
158  unsigned int nTotTot = 0;
159  for (unsigned int i(0); i < nHists; i++) {
160  std::unique_ptr<TkHistoMap> tkHistoMap{new TkHistoMap(tkDetMap)};
161 
162  tkHistoMap->loadTkHistoMap(dirName, tkHistoMapNameVec_.at(i), aMechView);
163 
164  std::vector<MonitorElement*>& lMaps = tkHistoMap->getAllMaps();
165 
166  std::cout << " -- map " << i << ", nHistos = " << lMaps.size() << std::endl;
167  unsigned int nFail = 0;
168  unsigned int nTot = 0;
169 
170  for (unsigned int im(0); im < lMaps.size(); im++) {
171  if (!lMaps[im]) {
172  std::cout << " -- Failed to get element " << im << " for map " << i << std::endl;
173  nFail++;
174  nFailTot++;
175  }
176  nTot++;
177  nTotTot++;
178  }
179 
180  if (nFail == nTot)
181  aValidVec[i] = false;
182  aTkMapVec.emplace_back(std::move(tkHistoMap));
183  }
184 
185  if (nFailTot < nTotTot)
186  std::cout << " - " << nTotTot - nFailTot << "/" << nTotTot << " histomaps read with success for file ." << aFile
187  << std::endl;
188  else {
189  std::cout << " - Failed to read any map for file " << aFile << ". Exiting line ... " << __LINE__ << std::endl;
190  exit(1);
191  }
192 
193  // //get list of detid for which |deltaRMS(APV0-APV1)|>1
194  // unsigned int lHistoNumber = 35;
195  // TkDetMap lTkDetMap;
196  // std::ofstream list,listRms0,listRms1;
197  // list.open("./cmBadModuleList.dat",std::ios::out);
198  // listRms0.open("./cmBadModuleList_rms0.dat",std::ios::out);
199  // listRms1.open("./cmBadModuleList_rms1.dat",std::ios::out);
200  // if (!list || !listRms0 || !listRms1) {
201  // std::cout << "Warning, can't open output file to write bad module list !" << std::endl;
202  // exit(1);
203  // }
204 
205  // TCanvas *lCan = new TCanvas("lCan","",1);
206  // TH1F *p_deltaMean = new TH1F("p_deltaMean",";CM_{mean}(APV0)-CM_{mean}(APV1)",500,-2,2);
207  // TH1F *p_deltaRMS = new TH1F("p_deltaRMS",";CM_{RMS}(APV0)-CM_{RMS}(APV1)",500,0,3);
208  // TH1F *p_MeanAPV0 = new TH1F("p_MeanAPV0",";CM_{mean}(APV0)",500,100,140);
209  // //TH1F *p_MeanAPV1 = new TH1F("p_MeanAPV1",";CM_{mean}(APV1)",500,100,140);
210  // TH1F *p_RMSAPV0 = new TH1F("p_RMSAPV0",";CM_{RMS}(APV0)",500,0,10);
211  // //TH1F *p_RMSAPV1 = new TH1F("p_RMSAPV1",";CM_{RMS}(APV1)",500,0,10);
212 
213  // gStyle->SetOptStat(1111111);
214 
215  // for(unsigned int layer=1;layer<lHistoNumber;++layer){
216  // std::vector<uint32_t> dets;
217  // lTkDetMap.getDetsForLayer(layer,dets);
218  // for(size_t i=0;i<dets.size();++i){
219  // if(dets[i]>0){
220  // //if(tkHistoMap[5]->getEntries(dets[i])>0 && tkHistoMap[5]->getValue(dets[i])) {
221  // if(nHists > 3){
222  // if (tkHistoMap[3]->getValue(dets[i]) > 1) {
223  // list << dets[i] << " " << tkHistoMap[3]->getValue(dets[i]) << std::endl;
224  // }
225  // p_deltaRMS->Fill(tkHistoMap[3]->getValue(dets[i]));
226  // }
227  // p_MeanAPV0->Fill(tkHistoMap[0]->getValue(dets[i]));
228  // //p_MeanAPV1->Fill(tkHistoMap[1]->getValue(dets[i]));
229  // p_RMSAPV0->Fill(tkHistoMap[1]->getValue(dets[i]));
230  // if (tkHistoMap[1]->getValue(dets[i]) > 2)
231  // listRms0 << dets[i] << " " << tkHistoMap[1]->getValue(dets[i]) << std::endl;
232  // //p_RMSAPV1->Fill(tkHistoMap[3]->getValue(dets[i]));
233  // //if (tkHistoMap[3]->getValue(dets[i]) > 2)
234  // //listRms1 << dets[i] << " " << tkHistoMap[3]->getValue(dets[i]) << std::endl;
235 
236  // if(nHists > 2) p_deltaMean->Fill(tkHistoMap[2]->getValue(dets[i]));
237  // }
238  // }
239  // }
240  // list.close();
241  // listRms0.close();
242  // listRms1.close();
243 
244  // lCan->cd();
245  // p_deltaRMS->Draw();
246  // //lCan->Print("./deltaRMStotal.png");
247  // lCan->Print("./deltaRMStotal.C");
248 
249  // p_deltaMean->Draw();
250  // lCan->Update();
251  // lCan->Print("./deltaMeantotal.C");
252 
253  // TPaveStats *statBox[2] = {0,0};
254  // statBox[0] = (TPaveStats*)p_MeanAPV0->FindObject("stats");
255  // //statBox[1] = (TPaveStats*)p_MeanAPV1->FindObject("stats");
256 
257  // p_MeanAPV0->Draw();
258  // //p_MeanAPV1->SetLineColor(2);
259  // //p_MeanAPV1->Draw("same");
260  // if (statBox[0]) statBox[0]->Draw("same");
261  // if (statBox[1]) {
262  // statBox[1]->SetLineColor(2);
263  // statBox[1]->SetTextColor(2);
264  // statBox[1]->Draw("same");
265  // }
266  // lCan->Update();
267  // lCan->Print("./meanAPVstotal.C");
268 
269  // statBox[0] = (TPaveStats*)p_RMSAPV0->FindObject("stats");
270  // //statBox[1] = (TPaveStats*)p_RMSAPV1->FindObject("stats");
271 
272  // p_RMSAPV0->Draw();
273  // //p_RMSAPV1->SetLineColor(2);
274  // //p_RMSAPV1->Draw("same");
275  // if (statBox[0]) statBox[0]->Draw("same");
276  // if (statBox[1]) {
277  // statBox[1]->SetLineColor(2);
278  // statBox[1]->SetTextColor(2);
279  // statBox[1]->Draw("same");
280  // }
281  // lCan->Update();
282  // lCan->Print("./rmsAPVstotal.C");
283 }
284 
285 // ------------ method called to for each event ------------
287  static bool firstEvent = true;
288 
290  iSetup.get<SiStripFedCablingRcd>().get(fedcabling);
291 
292  edm::ESHandle<TrackerTopology> tTopoHandle;
293  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
294  const TrackerTopology* const tTopo = tTopoHandle.product();
295 
296  if (tkHistoMapVec_.empty() && (!tkHistoMapNameVec_.empty())) {
297  edm::ESHandle<TkDetMap> tkDetMapHandle;
298  iSetup.get<TrackerTopologyRcd>().get(tkDetMapHandle);
299  const TkDetMap* tkDetMap = tkDetMapHandle.product();
301  if (doDiff_)
303  }
304 
305  if (firstEvent) {
306  for (unsigned int i(0); i < tkHistoMapNameVec_.size(); i++) {
307  tkmap_.push_back(new TrackerMap(pset_, &(*fedcabling), tTopo));
308  }
309  }
310 
311  firstEvent = false;
312 
313  std::cout << "End of analyze method: tkmap_ size = " << tkmap_.size() << std::endl;
314 
315 } //analyze method
316 
317 // ------------ method called once each job just before starting event loop ------------
319 
320 // ------------ method called once each job just after ending the event loop ------------
322  //edm::ESHandle<SiStripFedCabling> pDD1;
323  //iSetup.get<SiStripFedCablingRcd>().get(pDD1);
324  std::cout << "Processing endjob with " << tkHistoMapNameVec_.size() << " elements." << std::endl;
325 
326  assert(minVal_.size() == tkHistoMapNameVec_.size());
327  assert(maxVal_.size() == tkHistoMapNameVec_.size());
328 
329  for (unsigned int i(0); i < tkHistoMapNameVec_.size(); i++) {
330  std::cout << "Processing element " << i << ": " << tkHistoMapNameVec_.at(i) << std::endl;
331  std::cout << "Min, max = " << minVal_.at(i) << " " << maxVal_.at(i) << std::endl;
332 
333  TrackerMap* lTkMap = tkmap_.at(i);
334 
335  if (!lTkMap) {
336  std::cout << "tkmap_ is NULL for element " << i << "... continuing ..." << std::endl;
337  continue;
338  }
339 
340  subtractMap(tkHistoMapVec_.at(i).get(), tkHistoMapVecDiff_.at(i).get());
341 
342  //(pset_,pDD1);
343  lTkMap->setPalette(1);
344  lTkMap->showPalette(true);
345  if (!tkHistoMapVec_.at(i) || !isValidMap_.at(i)) {
346  std::cout << "Warning, tkHistoMap is invalid for element " << i << "... continuing ..." << std::endl;
347  continue;
348  }
349  tkHistoMapVec_.at(i)->dumpInTkMap(lTkMap);
350 
351  //to print all figures to create fancy view
352  //lTkMap->printall(true,0,255,tkHistoMapNameVec_.at(i));
353  lTkMap->save(true, minVal_.at(i), maxVal_.at(i), tkHistoMapNameVec_.at(i) + std::string(".png"));
354  lTkMap->save_as_fedtrackermap(
355  true, minVal_.at(i), maxVal_.at(i), tkHistoMapNameVec_.at(i) + std::string("_FED.png"));
356  }
357 }
358 
360  std::vector<MonitorElement*>& lMaps = aResult->getAllMaps();
361  const std::vector<MonitorElement*>& lMapsDiff = aSubtr->getAllMaps();
362 
363  assert(lMaps.size() == lMapsDiff.size());
364 
365  for (unsigned int im(0); im < lMaps.size(); im++) {
366  if (!lMaps[im] || !lMapsDiff[im]) {
367  std::cout << " -- Failed to get element " << im << " for maps." << std::endl;
368  } else {
369  (lMaps[im]->getTProfile2D())->Add(lMapsDiff[im]->getTProfile2D(), -1);
370  }
371  }
372 }
373 
374 // Define as a plug-in
375 //
376 
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
BuildTrackerMapPlugin::BuildTrackerMapPlugin
BuildTrackerMapPlugin(const edm::ParameterSet &)
Definition: BuildTrackerMap.cc:106
funct::false
false
Definition: Factorize.h:34
TkHistoMap::getAllMaps
const std::vector< MonitorElement * > & getAllMaps() const
Definition: TkHistoMap.h:44
ESHandle.h
TrackerMap::setPalette
void setPalette(int numpalette)
Definition: TrackerMap.h:155
BuildTrackerMapPlugin::folderName_
std::string folderName_
Definition: BuildTrackerMap.cc:80
edm
HLT enums.
Definition: AlignableModifier.h:19
TrackerTopology
Definition: TrackerTopology.h:16
gather_cfg.cout
cout
Definition: gather_cfg.py:144
SiStripFedCabling.h
cms::cuda::assert
assert(be >=bs)
DQMStore.h
TrackerMap::save_as_fedtrackermap
void save_as_fedtrackermap(bool print_total=true, float minval=0., float maxval=0., std::string s="fed_svgmap.svg", int width=100+(90+100) *31+300, int height=150+(2940+150) *1+300)
Definition: TrackerMap.cc:2603
dqm::legacy::MonitorElement
Definition: MonitorElement.h:461
BuildTrackerMapPlugin::maxVal_
std::vector< double > maxVal_
Definition: BuildTrackerMap.cc:93
EDAnalyzer.h
BuildTrackerMapPlugin::subtractMap
void subtractMap(TkHistoMap *aResult, const TkHistoMap *aSubtr)
Definition: BuildTrackerMap.cc:359
BuildTrackerMapPlugin::mechanicalView_
bool mechanicalView_
Definition: BuildTrackerMap.cc:78
BuildTrackerMapPlugin::tkHistoMapVecDiff_
std::vector< std::unique_ptr< TkHistoMap > > tkHistoMapVecDiff_
Definition: BuildTrackerMap.cc:88
edm::EDAnalyzer
Definition: EDAnalyzer.h:29
MakerMacros.h
TrackerTopology.h
SiStripFedCablingRcd
Definition: SiStripCondDataRecords.h:22
TrackerTopologyRcd.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
dqm::legacy::DQMStore
Definition: DQMStore.h:727
Service.h
BuildTrackerMapPlugin::isValidMapDiff_
std::vector< bool > isValidMapDiff_
Definition: BuildTrackerMap.cc:96
TmModule.h
edm::ESHandle< SiStripFedCabling >
TkDetMap
Definition: TkDetMap.h:175
TkHistoMap::loadTkHistoMap
void loadTkHistoMap(const std::string &path, const std::string &MapName, bool mechanicalView=false)
Definition: TkHistoMap.cc:76
TrackerMap
Definition: TrackerMap.h:76
BuildTrackerMapPlugin::tkmap_
std::vector< TrackerMap * > tkmap_
Definition: BuildTrackerMap.cc:99
BuildTrackerMapPlugin
Definition: BuildTrackerMap.cc:55
TkHistoMap.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
BuildTrackerMapPlugin::fileNameDiff_
std::string fileNameDiff_
Definition: BuildTrackerMap.cc:85
funct::true
true
Definition: Factorize.h:173
BuildTrackerMapPlugin::endJob
void endJob() override
Definition: BuildTrackerMap.cc:321
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
ParameterSet
Definition: Functions.h:16
BuildTrackerMapPlugin::minVal_
std::vector< double > minVal_
Definition: BuildTrackerMap.cc:92
BuildTrackerMapPlugin::MonitorElement
dqm::legacy::MonitorElement MonitorElement
Definition: BuildTrackerMap.cc:57
BuildTrackerMapPlugin::tkHistoMapNameVec_
std::vector< std::string > tkHistoMapNameVec_
Definition: BuildTrackerMap.cc:91
edm::Service
Definition: Service.h:30
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
BuildTrackerMapPlugin::pset_
edm::ParameterSet pset_
Definition: BuildTrackerMap.cc:98
TmApvPair.h
edm::EventSetup
Definition: EventSetup.h:57
TrackerMap::showPalette
void showPalette(bool printflag1)
Definition: TrackerMap.h:157
get
#define get
BuildTrackerMapPlugin::tkHistoMapVec_
std::vector< std::unique_ptr< TkHistoMap > > tkHistoMapVec_
Definition: BuildTrackerMap.cc:87
BuildTrackerMapPlugin::fileName_
std::string fileName_
Definition: BuildTrackerMap.cc:76
TrackerMap.h
TkHistoMap
Definition: TkHistoMap.h:12
TrackerMap::save
void save(bool print_total=true, float minval=0., float maxval=0., std::string s="svgmap.svg", int width=1500, int height=800)
Definition: TrackerMap.cc:810
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
BuildTrackerMapPlugin::DQMStore
dqm::legacy::DQMStore DQMStore
Definition: BuildTrackerMap.cc:58
FedChannelConnection.h
BuildTrackerMapPlugin::~BuildTrackerMapPlugin
~BuildTrackerMapPlugin() override
Definition: BuildTrackerMap.cc:61
Frameworkfwd.h
TrackerOfflineValidation_Dqm_cff.dirName
dirName
Definition: TrackerOfflineValidation_Dqm_cff.py:55
EventSetup.h
dqm::implementation::DQMStore::open
DQM_DEPRECATED bool open(std::string const &filename, bool overwrite=false, std::string const &path="", std::string const &prepend="", OpenRunDirs stripdirs=KeepRunDirs, bool fileMustExist=true)
Definition: DQMStore.cc:766
Exception.h
SiStripFedCablingRcd.h
BuildTrackerMapPlugin::read
void read(bool aMechView, std::string aFile, const TkDetMap *tkDetMap, std::vector< std::unique_ptr< TkHistoMap >> &aTkMapVec, std::vector< bool > &aValidVec)
Definition: BuildTrackerMap.cc:135
BuildTrackerMapPlugin::isValidMap_
std::vector< bool > isValidMap_
Definition: BuildTrackerMap.cc:95
BuildTrackerMapPlugin::printDebug_
unsigned int printDebug_
Definition: BuildTrackerMap.cc:82
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
ParameterSet.h
edm::Event
Definition: Event.h:73
BuildTrackerMapPlugin::doDiff_
bool doDiff_
Definition: BuildTrackerMap.cc:84
BuildTrackerMapPlugin::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: BuildTrackerMap.cc:286
amptDefault_cfi.firstEvent
firstEvent
Definition: amptDefault_cfi.py:8
BuildTrackerMapPlugin::beginJob
void beginJob() override
Definition: BuildTrackerMap.cc:318