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