CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
40 
44 
46 
48 
49 //
50 // Class declaration
51 //
52 
54 {
55  public:
56 
59  private:
60  virtual void beginJob() override;
61  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
62  virtual void endJob() override;
63 
64  void read(bool aMechView,
65  std::string aFile,
66  std::vector<TkHistoMap*> & aTkMapVec,
67  std::vector<bool> & aValidVec);
68  void subtractMap(TkHistoMap*& aResult,
69  TkHistoMap*& aSubtr);
70 
71 
72 
73  //input file names
75  //do mechanical view or not
77  //folder name for histograms in DQMStore
79  //print debug messages when problems are found: 1=error debug, 2=light debug, 3=full debug
80  unsigned int printDebug_;
81 
82  bool doDiff_;
84 
85  std::vector<TkHistoMap*> tkHistoMapVec_;
86  std::vector<TkHistoMap*> tkHistoMapVecDiff_;
87 
88  //name of the tkHistoMap to extract
89  std::vector<std::string> tkHistoMapNameVec_;
90  std::vector<double> minVal_;
91  std::vector<double> maxVal_;
92 
93  std::vector<bool> isValidMap_;
94  std::vector<bool> isValidMapDiff_;
95 
97  std::vector<TrackerMap*> tkmap_;
98 
99 };
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 {
118 
121 
122 
123 // for (unsigned int i(0); i<34; i++){
124 // if (i<4) histName_[i] << "TIB/layer_" << i+1 << "/" << tkDetMapName_ << "_TIB_L" << i+1;
125 // else if (i<7) histName_[i] << "TID/side_1/wheel_" << i-3 << "/" << tkDetMapName_ << "_TIDM_D" << i-3;
126 // else if (i<10) histName_[i] << "TID/side_2/wheel_" << i-6 << "/" << tkDetMapName_ << "_TIDP_D" << i-6;
127 // else if (i<16) histName_[i] << "TOB/layer_" << i-9 << "/" << tkDetMapName_ << "_TOB_L" << i-9;
128 // else if (i<25) histName_[i] << "TEC/side_1/wheel_" << i-15 << "/" << tkDetMapName_ << "_TECM_W" << i-15;
129 // else if (i<34) histName_[i] << "TEC/side_2/wheel_" << i-24 << "/" << tkDetMapName_ << "_TECP_W" << i-24;
130 
131 // std::cout << "histName[" << i << "] =" << histName_[i] << std::endl;
132 
133 // }
134 
135 }
136 
138 {
139 
140  tkHistoMapVec_.clear();
141  if (doDiff_) tkHistoMapVecDiff_.clear();
142 }
143 
144 
145 //
146 // Member functions
147 //
148 
149 /*Check that is possible to load in tkhistomaps histograms already stored in a DQM root file (if the folder and name are known)*/
150 void BuildTrackerMapPlugin::read(bool aMechView,
151  std::string aFile,
152  std::vector<TkHistoMap*> & aTkMapVec,
153  std::vector<bool> & aValidVec)
154 {
155 
156  DQMStore * lDqmStore = edm::Service<DQMStore>().operator->();
157  lDqmStore->open(aFile);
158  std::vector<TkHistoMap *> tkHistoMap;
159 
160  unsigned int nHists = tkHistoMapNameVec_.size();
161  tkHistoMap.resize(nHists,0);
162  aValidVec.resize(nHists,true);
163 
165  if (dirName == "") {
166  dirName += "Run ";
167  dirName += aFile.substr(aFile.find_last_of("_")+5,6);
168  dirName += "/SiStrip/Run summary";
169  std::cout << " -- DirName = " << dirName << std::endl;
170  }
171 
172  //lDqmStore->setCurrentFolder(dirName);
173  //lDqmStore->showDirStructure();
174 
175  unsigned int nFailTot=0;
176  unsigned int nTotTot = 0;
177  for (unsigned int i(0); i<nHists; i++){
178 
179  tkHistoMap[i] = new TkHistoMap();
180 
181  tkHistoMap[i]->loadTkHistoMap(dirName,tkHistoMapNameVec_.at(i),aMechView);
182 
183  std::vector<MonitorElement*>& lMaps = tkHistoMap[i]->getAllMaps();
184 
185  std::cout << " -- map " << i << ", nHistos = " << lMaps.size() << std::endl;
186  unsigned int nFail=0;
187  unsigned int nTot=0;
188 
189  for (unsigned int im(0); im<lMaps.size(); im++){
190  if (!lMaps[im]) {
191  std::cout << " -- Failed to get element " << im << " for map " << i << std::endl;
192  nFail++;
193  nFailTot++;
194  }
195  nTot++;
196  nTotTot++;
197  }
198 
199  if (nFail == nTot) aValidVec[i] = false;
200  aTkMapVec.push_back(tkHistoMap[i]);
201  }
202 
203  if (nFailTot < nTotTot) std::cout << " - " << nTotTot-nFailTot << "/" << nTotTot
204  << " histomaps read with success for file ." << aFile << std::endl;
205  else {
206  std::cout << " - Failed to read any map for file " << aFile << ". Exiting line ... " << __LINE__ << std::endl;
207  exit(1);
208  }
209 
210 // //get list of detid for which |deltaRMS(APV0-APV1)|>1
211 // unsigned int lHistoNumber = 35;
212 // TkDetMap lTkDetMap;
213 // std::ofstream list,listRms0,listRms1;
214 // list.open("./cmBadModuleList.dat",std::ios::out);
215 // listRms0.open("./cmBadModuleList_rms0.dat",std::ios::out);
216 // listRms1.open("./cmBadModuleList_rms1.dat",std::ios::out);
217 // if (!list || !listRms0 || !listRms1) {
218 // std::cout << "Warning, can't open output file to write bad module list !" << std::endl;
219 // exit(1);
220 // }
221 
222 // TCanvas *lCan = new TCanvas("lCan","",1);
223 // TH1F *p_deltaMean = new TH1F("p_deltaMean",";CM_{mean}(APV0)-CM_{mean}(APV1)",500,-2,2);
224 // TH1F *p_deltaRMS = new TH1F("p_deltaRMS",";CM_{RMS}(APV0)-CM_{RMS}(APV1)",500,0,3);
225 // TH1F *p_MeanAPV0 = new TH1F("p_MeanAPV0",";CM_{mean}(APV0)",500,100,140);
226 // //TH1F *p_MeanAPV1 = new TH1F("p_MeanAPV1",";CM_{mean}(APV1)",500,100,140);
227 // TH1F *p_RMSAPV0 = new TH1F("p_RMSAPV0",";CM_{RMS}(APV0)",500,0,10);
228 // //TH1F *p_RMSAPV1 = new TH1F("p_RMSAPV1",";CM_{RMS}(APV1)",500,0,10);
229 
230 
231 
232 // gStyle->SetOptStat(1111111);
233 
234 // for(unsigned int layer=1;layer<lHistoNumber;++layer){
235 // std::vector<uint32_t> dets;
236 // lTkDetMap.getDetsForLayer(layer,dets);
237 // for(size_t i=0;i<dets.size();++i){
238 // if(dets[i]>0){
239 // //if(tkHistoMap[5]->getEntries(dets[i])>0 && tkHistoMap[5]->getValue(dets[i])) {
240 // if(nHists > 3){
241 // if (tkHistoMap[3]->getValue(dets[i]) > 1) {
242 // list << dets[i] << " " << tkHistoMap[3]->getValue(dets[i]) << std::endl;
243 // }
244 // p_deltaRMS->Fill(tkHistoMap[3]->getValue(dets[i]));
245 // }
246 // p_MeanAPV0->Fill(tkHistoMap[0]->getValue(dets[i]));
247 // //p_MeanAPV1->Fill(tkHistoMap[1]->getValue(dets[i]));
248 // p_RMSAPV0->Fill(tkHistoMap[1]->getValue(dets[i]));
249 // if (tkHistoMap[1]->getValue(dets[i]) > 2)
250 // listRms0 << dets[i] << " " << tkHistoMap[1]->getValue(dets[i]) << std::endl;
251 // //p_RMSAPV1->Fill(tkHistoMap[3]->getValue(dets[i]));
252 // //if (tkHistoMap[3]->getValue(dets[i]) > 2)
253 // //listRms1 << dets[i] << " " << tkHistoMap[3]->getValue(dets[i]) << std::endl;
254 
255 // if(nHists > 2) p_deltaMean->Fill(tkHistoMap[2]->getValue(dets[i]));
256 // }
257 // }
258 // }
259 // list.close();
260 // listRms0.close();
261 // listRms1.close();
262 
263 // lCan->cd();
264 // p_deltaRMS->Draw();
265 // //lCan->Print("./deltaRMStotal.png");
266 // lCan->Print("./deltaRMStotal.C");
267 
268 // p_deltaMean->Draw();
269 // lCan->Update();
270 // lCan->Print("./deltaMeantotal.C");
271 
272 // TPaveStats *statBox[2] = {0,0};
273 // statBox[0] = (TPaveStats*)p_MeanAPV0->FindObject("stats");
274 // //statBox[1] = (TPaveStats*)p_MeanAPV1->FindObject("stats");
275 
276 // p_MeanAPV0->Draw();
277 // //p_MeanAPV1->SetLineColor(2);
278 // //p_MeanAPV1->Draw("same");
279 // if (statBox[0]) statBox[0]->Draw("same");
280 // if (statBox[1]) {
281 // statBox[1]->SetLineColor(2);
282 // statBox[1]->SetTextColor(2);
283 // statBox[1]->Draw("same");
284 // }
285 // lCan->Update();
286 // lCan->Print("./meanAPVstotal.C");
287 
288 // statBox[0] = (TPaveStats*)p_RMSAPV0->FindObject("stats");
289 // //statBox[1] = (TPaveStats*)p_RMSAPV1->FindObject("stats");
290 
291 // p_RMSAPV0->Draw();
292 // //p_RMSAPV1->SetLineColor(2);
293 // //p_RMSAPV1->Draw("same");
294 // if (statBox[0]) statBox[0]->Draw("same");
295 // if (statBox[1]) {
296 // statBox[1]->SetLineColor(2);
297 // statBox[1]->SetTextColor(2);
298 // statBox[1]->Draw("same");
299 // }
300 // lCan->Update();
301 // lCan->Print("./rmsAPVstotal.C");
302 
303 
304 }
305 
306 
307 // ------------ method called to for each event ------------
308 void
310  const edm::EventSetup& iSetup)
311 {
312 
313  static bool firstEvent = true;
314 
316  iSetup.get<SiStripFedCablingRcd>().get(fedcabling );
317 
318  if (firstEvent) {
319  for (unsigned int i(0); i<tkHistoMapNameVec_.size(); i++){
320  tkmap_.push_back(new TrackerMap(pset_,&(*fedcabling)));
321  }
322 
323  }
324 
325  firstEvent = false;
326 
327  std::cout << "End of analyze method: tkmap_ size = " << tkmap_.size() << std::endl;
328 
329 }//analyze method
330 
331 // ------------ method called once each job just before starting event loop ------------
332 void
334 {
335 
336 }
337 
338 // ------------ method called once each job just after ending the event loop ------------
339 void
341 {
342  //edm::ESHandle<SiStripFedCabling> pDD1;
343  //iSetup.get<SiStripFedCablingRcd>().get(pDD1);
344  std::cout << "Processing endjob with " << tkHistoMapNameVec_.size()<< " elements." << std::endl;
345 
346  assert (minVal_.size() == tkHistoMapNameVec_.size());
347  assert (maxVal_.size() == tkHistoMapNameVec_.size());
348 
349  for (unsigned int i(0); i<tkHistoMapNameVec_.size(); i++){
350 
351  std::cout << "Processing element " << i << ": " << tkHistoMapNameVec_.at(i) << std::endl;
352  std::cout << "Min, max = " << minVal_.at(i) << " " << maxVal_.at(i) << std::endl;
353 
354  TrackerMap* lTkMap = tkmap_.at(i);
355 
356  if (!lTkMap) {
357  std::cout << "tkmap_ is NULL for element " << i << "... continuing ..." << std::endl;
358  continue;
359  }
360 
362 
363 
364  //(pset_,pDD1);
365  lTkMap->setPalette(1);
366  lTkMap->showPalette(1);
367  if (!tkHistoMapVec_.at(i) || !isValidMap_.at(i)) {
368  std::cout << "Warning, tkHistoMap is invalid for element " << i << "... continuing ..." << std::endl;
369  continue;
370  }
371  tkHistoMapVec_.at(i)->dumpInTkMap(lTkMap);
372 
373  //to print all figures to create fancy view
374  //lTkMap->printall(true,0,255,tkHistoMapNameVec_.at(i));
375  lTkMap->save(true,
376  minVal_.at(i),
377  maxVal_.at(i),
378  tkHistoMapNameVec_.at(i)+std::string(".png"));
379  lTkMap->save_as_fedtrackermap(true,
380  minVal_.at(i),
381  maxVal_.at(i),
382  tkHistoMapNameVec_.at(i)+std::string("_FED.png"));
383 
384  }
385 
386 }
387 
388 
390  TkHistoMap *& aSubtr)
391 {
392 
393  std::vector<MonitorElement*>& lMaps = aResult->getAllMaps();
394  std::vector<MonitorElement*>& lMapsDiff = aSubtr->getAllMaps();
395 
396  assert(lMaps.size() == lMapsDiff.size());
397 
398  for (unsigned int im(0); im<lMaps.size(); im++){
399  if (!lMaps[im] || !lMapsDiff[im]) {
400  std::cout << " -- Failed to get element " << im << " for maps." << std::endl;
401  }
402  else {
403  (lMaps[im]->getTProfile2D())->Add(lMapsDiff[im]->getTProfile2D(),-1);
404  }
405  }
406 
407 }
408 
409 
410 
411 // Define as a plug-in
412 //
413 
int i
Definition: DBlmapReader.cc:9
BuildTrackerMapPlugin(const edm::ParameterSet &)
std::vector< MonitorElement * > & getAllMaps()
Definition: TkHistoMap.h:28
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< std::string > tkHistoMapNameVec_
assert(m_qm.get())
std::vector< double > minVal_
edm::ParameterSet pset_
std::vector< double > maxVal_
int iEvent
Definition: GenABIO.cc:230
void showPalette(bool printflag1)
Definition: TrackerMap.h:125
void setPalette(int numpalette)
Definition: TrackerMap.h:123
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:698
std::vector< TkHistoMap * > tkHistoMapVec_
TProfile2D * getTProfile2D(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
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:2125
std::vector< TrackerMap * > tkmap_
virtual void endJob() override
void read(bool aMechView, std::string aFile, std::vector< TkHistoMap * > &aTkMapVec, std::vector< bool > &aValidVec)
const T & get() const
Definition: EventSetup.h:55
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
std::vector< bool > isValidMapDiff_
std::vector< bool > isValidMap_
bool open(const std::string &filename, bool overwrite=false, const std::string &path="", const std::string &prepend="", OpenRunDirs stripdirs=KeepRunDirs, bool fileMustExist=true)
Definition: DQMStore.cc:2963
tuple cout
Definition: gather_cfg.py:121
volatile std::atomic< bool > shutdown_flag false
void subtractMap(TkHistoMap *&aResult, TkHistoMap *&aSubtr)
virtual void beginJob() override
std::vector< TkHistoMap * > tkHistoMapVecDiff_