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