CMS 3D CMS Logo

TkHistoMap.cc
Go to the documentation of this file.
3 
4 //#define debug_TkHistoMap
5 
6 TkHistoMap::TkHistoMap(const TkDetMap* tkDetMap) : HistoNumber(35) {
7  LogTrace("TkHistoMap") << "TkHistoMap::constructor without parameters";
8  load(tkDetMap, "", 0.0f, false, false, false);
9 }
10 
12  const TkDetMap* tkDetMap, const std::string& path, const std::string& MapName, float baseline, bool mechanicalView)
13  : HistoNumber(35), MapName_(MapName) {
14  LogTrace("TkHistoMap") << "TkHistoMap::constructor with parameters";
15  load(tkDetMap, path, baseline, mechanicalView, false);
16  dqmStore_->meBookerGetter([this, &path, &baseline, mechanicalView](DQMStore::IBooker& ibooker, DQMStore::IGetter&) {
17  this->createTkHistoMap(ibooker, path, MapName_, baseline, mechanicalView);
18  });
19 }
20 
22  const std::string& path,
23  const std::string& MapName,
24  float baseline,
25  bool mechanicalView,
26  bool isTH2F)
27  : HistoNumber(35), MapName_(MapName) {
28  LogTrace("TkHistoMap") << "TkHistoMap::constructor with parameters";
29  load(tkDetMap, path, baseline, mechanicalView, isTH2F);
30  dqmStore_->meBookerGetter([this, &path, &baseline, mechanicalView](DQMStore::IBooker& ibooker, DQMStore::IGetter&) {
31  this->createTkHistoMap(ibooker, path, MapName_, baseline, mechanicalView);
32  });
33 }
34 
36  DQMStore::IBooker& ibooker,
37  const std::string& path,
38  const std::string& MapName,
39  float baseline,
40  bool mechanicalView,
41  bool isTH2F)
42  : HistoNumber(35), MapName_(MapName) {
43  LogTrace("TkHistoMap") << "TkHistoMap::constructor with parameters";
44  load(tkDetMap, path, baseline, mechanicalView, isTH2F);
45  createTkHistoMap(ibooker, path, MapName_, baseline, mechanicalView);
46 }
47 
48 void TkHistoMap::load(const TkDetMap* tkDetMap,
49  const std::string& path,
50  float baseline,
51  bool mechanicalView,
52  bool isTH2F,
53  bool createTkMap) {
54  cached_detid = 0;
55  cached_layer = 0;
56  loadServices();
57  tkdetmap_ = tkDetMap;
58  isTH2F_ = isTH2F;
59 }
60 
62  if (!edm::Service<DQMStore>().isAvailable()) {
63  edm::LogError("TkHistoMap")
64  << "\n------------------------------------------"
65  "\nUnAvailable Service DQMStore: please insert in the configuration file an instance like"
66  "\n\tprocess.load(\"DQMServices.Core.DQMStore_cfg\")"
67  "\n------------------------------------------";
68  }
70 }
71 
73  // dqmStore_ only for saving
75 }
76 
77 void TkHistoMap::loadTkHistoMap(const std::string& path, const std::string& MapName, bool mechanicalView) {
78  MapName_ = MapName;
79  tkHistoMap_.resize(HistoNumber);
80  auto loadMap = [this, &path, mechanicalView](DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
82  for (int layer = 1; layer < HistoNumber; ++layer) {
83  folder = folderDefinition(ibooker, path, MapName_, layer, mechanicalView, fullName);
84 #ifdef debug_TkHistoMap
85  LogTrace("TkHistoMap") << "[TkHistoMap::loadTkHistoMap] folder " << folder << " histoName " << fullName
86  << " find " << folder.find_last_of("/") << " length " << folder.length();
87 #endif
88  if (folder.find_last_of('/') != folder.length() - 1)
89  folder += "/";
90  tkHistoMap_[layer] = igetter.get(folder + fullName);
91 #ifdef debug_TkHistoMap
92  LogTrace("TkHistoMap") << "[TkHistoMap::loadTkHistoMap] folder " << folder << " histoName " << fullName
93  << " layer " << layer << " ptr " << tkHistoMap_[layer] << " find "
94  << folder.find_last_of("/") << " length " << folder.length();
95 #endif
96  }
97  };
98  dqmStore_->meBookerGetter(loadMap);
99 }
100 
102  const std::string& path,
103  const std::string& MapName,
104  float baseline,
105  bool mechanicalView) {
106  int nchX;
107  int nchY;
108  double lowX, highX;
109  double lowY, highY;
111 
112  tkHistoMap_.resize(HistoNumber);
113  const bool bookTH2F = isTH2F_;
114  for (int layer = 1; layer < HistoNumber; ++layer) {
115  folder = folderDefinition(ibooker, path, MapName, layer, mechanicalView, fullName);
116  tkdetmap_->getComponents(layer, nchX, lowX, highX, nchY, lowY, highY);
118  if (bookTH2F == false) {
119  me = ibooker.bookProfile2D(fullName.c_str(), fullName.c_str(), nchX, lowX, highX, nchY, lowY, highY, 0.0, 0.0);
120  } else {
121  me = ibooker.book2D(fullName.c_str(), fullName.c_str(), nchX, lowX, highX, nchY, lowY, highY);
122  }
123  //initialize bin content for the not assigned bins
124  if (baseline != 0) {
125  for (size_t ix = 1; ix <= (unsigned int)nchX; ++ix)
126  for (size_t iy = 1; iy <= (unsigned int)nchY; ++iy)
127  if (!tkdetmap_->getDetFromBin(layer, ix, iy))
128  me->Fill(1. * (lowX + ix - .5), 1. * (lowY + iy - .5), baseline);
129  }
130 
131  tkHistoMap_[layer] = me;
132 #ifdef debug_TkHistoMap
133  LogTrace("TkHistoMap") << "[TkHistoMap::createTkHistoMap] folder " << folder << " histoName " << fullName
134  << " layer " << layer << " ptr " << tkHistoMap_[layer];
135 #endif
136  }
137 }
138 
141  const std::string& MapName,
142  int layer,
143  bool mechanicalView,
147 
148  if (mechanicalView) {
149  std::stringstream ss;
150 
151  SiStripFolderOrganizer folderOrg;
152  folderOrg.setSiStripFolderName(folder);
153 
155  uint32_t subdetlayer = 0, side = 0;
156  TkDetMap::getSubDetLayerSide(layer, subDet, subdetlayer, side);
157  folderOrg.getSubDetLayerFolderName(ss, subDet, subdetlayer, side);
158  folder = ss.str();
159  }
160  ibooker.setCurrentFolder(folder);
161  return folder;
162 }
163 
164 #include <iostream>
166  std::ifstream file;
167  file.open(filename.c_str());
168  float value;
169  uint32_t detid;
170  while (file.good()) {
171  file >> detid >> value;
172  fill(detid, value);
173  }
174  file.close();
175 }
176 
177 void TkHistoMap::fill(DetId detid, float value) {
180 #ifdef debug_TkHistoMap
181  LogTrace("TkHistoMap") << "[TkHistoMap::fill] Fill detid " << detid.rawId() << " Layer " << layer << " value "
182  << value << " ix,iy " << xybin.ix << " " << xybin.iy << " " << xybin.x << " " << xybin.y << " "
183  << tkHistoMap_[layer]->getTProfile2D()->GetName();
184 #endif
186  tkHistoMap_[layer]->getTProfile2D()->Fill(xybin.x, xybin.y, value);
188  tkHistoMap_[layer]->getTH2F()->Fill(xybin.x, xybin.y, value);
189 
190 #ifdef debug_TkHistoMap
191  LogTrace("TkHistoMap") << "[TkHistoMap::fill] "
192  << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(xybin.ix, xybin.iy);
193  for (size_t ii = 0; ii < 4; ii++)
194  for (size_t jj = 0; jj < 11; jj++) {
196  LogTrace("TkHistoMap") << "[TkHistoMap::fill] " << ii << " " << jj << " "
197  << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(ii, jj);
199  LogTrace("TkHistoMap") << "[TkHistoMap::fill] " << ii << " " << jj << " "
200  << tkHistoMap_[layer]->getTH2F()->GetBinContent(ii, jj);
201  }
202 #endif
203 }
204 
209  tkHistoMap_[layer]->getTProfile2D()->SetBinEntries(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix, xybin.iy),
210  1);
211  tkHistoMap_[layer]->getTProfile2D()->SetBinContent(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix, xybin.iy),
212  value);
213  } else if (tkHistoMap_[layer]->kind() == MonitorElement::Kind::TH2F) {
214  tkHistoMap_[layer]->setBinContent(xybin.ix, xybin.iy, value);
215  }
216 
217 #ifdef debug_TkHistoMap
218  LogTrace("TkHistoMap") << "[TkHistoMap::setbincontent] setBinContent detid " << detid.rawId() << " Layer " << layer
219  << " value " << value << " ix,iy " << xybin.ix << " " << xybin.iy << " " << xybin.x << " "
220  << xybin.y << " " << tkHistoMap_[layer]->getTProfile2D()->GetName() << " bin "
221  << tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix, xybin.iy);
222 
223  LogTrace("TkHistoMap") << "[TkHistoMap::setbincontent] "
224  << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(xybin.ix, xybin.iy);
225  for (size_t ii = 0; ii < 4; ii++)
226  for (size_t jj = 0; jj < 11; jj++) {
227  LogTrace("TkHistoMap") << "[TkHistoMap::setbincontent] " << ii << " " << jj << " "
228  << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(ii, jj);
229  }
230 #endif
231 }
232 
233 void TkHistoMap::add(DetId detid, float value) {
234 #ifdef debug_TkHistoMap
235  LogTrace("TkHistoMap") << "[TkHistoMap::add]";
236 #endif
240  setBinContent(detid,
241  tkHistoMap_[layer]->getTProfile2D()->GetBinContent(
242  tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix, xybin.iy)) +
243  value);
246  detid,
247  tkHistoMap_[layer]->getTH2F()->GetBinContent(tkHistoMap_[layer]->getTH2F()->GetBin(xybin.ix, xybin.iy)) +
248  value);
249 }
250 
254 
256  return tkHistoMap_[layer]->getTH2F()->GetBinContent(tkHistoMap_[layer]->getTH2F()->GetBin(xybin.ix, xybin.iy));
257  else
258  return tkHistoMap_[layer]->getTProfile2D()->GetBinContent(
259  tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix, xybin.iy));
260 }
265  return 1;
266  else
267  return tkHistoMap_[layer]->getTProfile2D()->GetBinEntries(
268  tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix, xybin.iy));
269 }
270 
271 void TkHistoMap::dumpInTkMap(TrackerMap* tkmap, bool dumpEntries) {
272  for (int layer = 1; layer < HistoNumber; ++layer) {
273  // std::vector<uint32_t> dets;
274  // tkdetmap_->getDetsForLayer(layer,dets);
275  std::vector<DetId> dets = tkdetmap_->getDetsForLayer(layer);
276  for (size_t i = 0; i < dets.size(); ++i) {
277  if (dets[i] > 0) {
278  if (getEntries(dets[i]) > 0) {
279  tkmap->fill(dets[i], dumpEntries ? getEntries(dets[i]) : getValue(dets[i]));
280  }
281  }
282  }
283  }
284 }
285 
286 #include "TCanvas.h"
287 #include "TFile.h"
289  // TCanvas C(MapName_,MapName_,200,10,900,700);
290  TCanvas* CTIB =
291  new TCanvas(std::string("Canvas_" + MapName_ + "TIB").c_str(), std::string("Canvas_" + MapName_ + "TIB").c_str());
292  TCanvas* CTOB =
293  new TCanvas(std::string("Canvas_" + MapName_ + "TOB").c_str(), std::string("Canvas_" + MapName_ + "TOB").c_str());
294  TCanvas* CTIDP = new TCanvas(std::string("Canvas_" + MapName_ + "TIDP").c_str(),
295  std::string("Canvas_" + MapName_ + "TIDP").c_str());
296  TCanvas* CTIDM = new TCanvas(std::string("Canvas_" + MapName_ + "TIDM").c_str(),
297  std::string("Canvas_" + MapName_ + "TIDM").c_str());
298  TCanvas* CTECP = new TCanvas(std::string("Canvas_" + MapName_ + "TECP").c_str(),
299  std::string("Canvas_" + MapName_ + "TECP").c_str());
300  TCanvas* CTECM = new TCanvas(std::string("Canvas_" + MapName_ + "TECM").c_str(),
301  std::string("Canvas_" + MapName_ + "TECM").c_str());
302  CTIB->Divide(2, 2);
303  CTOB->Divide(2, 3);
304  CTIDP->Divide(1, 3);
305  CTIDM->Divide(1, 3);
306  CTECP->Divide(3, 3);
307  CTECM->Divide(3, 3);
308 
309  int i;
310  i = 0;
311  CTIB->cd(++i);
312  tkHistoMap_[TkLayerMap::TIB_L1]->getTProfile2D()->Draw(options.c_str());
313  CTIB->cd(++i);
314  tkHistoMap_[TkLayerMap::TIB_L2]->getTProfile2D()->Draw(options.c_str());
315  CTIB->cd(++i);
316  tkHistoMap_[TkLayerMap::TIB_L3]->getTProfile2D()->Draw(options.c_str());
317  CTIB->cd(++i);
318  tkHistoMap_[TkLayerMap::TIB_L4]->getTProfile2D()->Draw(options.c_str());
319 
320  i = 0;
321  CTIDP->cd(++i);
322  tkHistoMap_[TkLayerMap::TIDP_D1]->getTProfile2D()->Draw(options.c_str());
323  CTIDP->cd(++i);
324  tkHistoMap_[TkLayerMap::TIDP_D2]->getTProfile2D()->Draw(options.c_str());
325  CTIDP->cd(++i);
326  tkHistoMap_[TkLayerMap::TIDP_D3]->getTProfile2D()->Draw(options.c_str());
327 
328  i = 0;
329  CTIDM->cd(++i);
330  tkHistoMap_[TkLayerMap::TIDM_D1]->getTProfile2D()->Draw(options.c_str());
331  CTIDM->cd(++i);
332  tkHistoMap_[TkLayerMap::TIDM_D2]->getTProfile2D()->Draw(options.c_str());
333  CTIDM->cd(++i);
334  tkHistoMap_[TkLayerMap::TIDM_D3]->getTProfile2D()->Draw(options.c_str());
335 
336  i = 0;
337  CTOB->cd(++i);
338  tkHistoMap_[TkLayerMap::TOB_L1]->getTProfile2D()->Draw(options.c_str());
339  CTOB->cd(++i);
340  tkHistoMap_[TkLayerMap::TOB_L2]->getTProfile2D()->Draw(options.c_str());
341  CTOB->cd(++i);
342  tkHistoMap_[TkLayerMap::TOB_L3]->getTProfile2D()->Draw(options.c_str());
343  CTOB->cd(++i);
344  tkHistoMap_[TkLayerMap::TOB_L4]->getTProfile2D()->Draw(options.c_str());
345  CTOB->cd(++i);
346  tkHistoMap_[TkLayerMap::TOB_L5]->getTProfile2D()->Draw(options.c_str());
347  CTOB->cd(++i);
348  tkHistoMap_[TkLayerMap::TOB_L6]->getTProfile2D()->Draw(options.c_str());
349 
350  i = 0;
351  CTECP->cd(++i);
352  tkHistoMap_[TkLayerMap::TECP_W1]->getTProfile2D()->Draw(options.c_str());
353  CTECP->cd(++i);
354  tkHistoMap_[TkLayerMap::TECP_W2]->getTProfile2D()->Draw(options.c_str());
355  CTECP->cd(++i);
356  tkHistoMap_[TkLayerMap::TECP_W3]->getTProfile2D()->Draw(options.c_str());
357  CTECP->cd(++i);
358  tkHistoMap_[TkLayerMap::TECP_W4]->getTProfile2D()->Draw(options.c_str());
359  CTECP->cd(++i);
360  tkHistoMap_[TkLayerMap::TECP_W5]->getTProfile2D()->Draw(options.c_str());
361  CTECP->cd(++i);
362  tkHistoMap_[TkLayerMap::TECP_W6]->getTProfile2D()->Draw(options.c_str());
363  CTECP->cd(++i);
364  tkHistoMap_[TkLayerMap::TECP_W7]->getTProfile2D()->Draw(options.c_str());
365  CTECP->cd(++i);
366  tkHistoMap_[TkLayerMap::TECP_W8]->getTProfile2D()->Draw(options.c_str());
367  CTECP->cd(++i);
368  tkHistoMap_[TkLayerMap::TECP_W9]->getTProfile2D()->Draw(options.c_str());
369 
370  i = 0;
371  CTECM->cd(++i);
372  tkHistoMap_[TkLayerMap::TECM_W1]->getTProfile2D()->Draw(options.c_str());
373  CTECM->cd(++i);
374  tkHistoMap_[TkLayerMap::TECM_W2]->getTProfile2D()->Draw(options.c_str());
375  CTECM->cd(++i);
376  tkHistoMap_[TkLayerMap::TECM_W3]->getTProfile2D()->Draw(options.c_str());
377  CTECM->cd(++i);
378  tkHistoMap_[TkLayerMap::TECM_W4]->getTProfile2D()->Draw(options.c_str());
379  CTECM->cd(++i);
380  tkHistoMap_[TkLayerMap::TECM_W5]->getTProfile2D()->Draw(options.c_str());
381  CTECM->cd(++i);
382  tkHistoMap_[TkLayerMap::TECM_W6]->getTProfile2D()->Draw(options.c_str());
383  CTECM->cd(++i);
384  tkHistoMap_[TkLayerMap::TECM_W7]->getTProfile2D()->Draw(options.c_str());
385  CTECM->cd(++i);
386  tkHistoMap_[TkLayerMap::TECM_W8]->getTProfile2D()->Draw(options.c_str());
387  CTECM->cd(++i);
388  tkHistoMap_[TkLayerMap::TECM_W9]->getTProfile2D()->Draw(options.c_str());
389 
390  TFile* f = new TFile(filename.c_str(), mode.c_str());
391  CTIB->Write();
392  CTIDP->Write();
393  CTIDM->Write();
394  CTOB->Write();
395  CTECP->Write();
396  CTECM->Write();
397  f->Close();
398  delete f;
399 }
void loadServices()
Definition: TkHistoMap.cc:61
MonitorElement * bookProfile2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, double lowZ, double highZ, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:476
void setSiStripFolderName(std::string name)
static std::string getLayerName(int in)
Definition: TkDetMap.cc:237
static void getSubDetLayerSide(int in, SiStripDetId::SubDetector &, uint32_t &layer, uint32_t &side)
Definition: TkDetMap.cc:383
DetId cached_detid
Definition: TkHistoMap.h:92
void setBinContent(DetId detid, float value)
Definition: TkHistoMap.cc:205
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
void fillFromAscii(const std::string &filename)
Definition: TkHistoMap.cc:165
void load(const TkDetMap *tkDetMap, const std::string &path, float baseline, bool mechanicalView, bool isTH2F, bool createTkMap=true)
Definition: TkHistoMap.cc:48
int16_t cached_layer
Definition: TkHistoMap.h:93
int HistoNumber
Definition: TkHistoMap.h:96
Log< level::Error, false > LogError
DQMStore * dqmStore_
Definition: TkHistoMap.h:89
#define LogTrace(id)
constexpr std::array< uint8_t, layerIndexSize > layer
std::vector< MonitorElement * > tkHistoMap_
Definition: TkHistoMap.h:95
std::vector< DetId > getDetsForLayer(int layer) const
Definition: TkDetMap.h:196
void getSubDetLayerFolderName(std::stringstream &ss, SiStripDetId::SubDetector subDet, uint32_t layer, uint32_t side=0)
void save(const std::string &filename)
Definition: TkHistoMap.cc:72
std::string MapName_
Definition: TkHistoMap.h:97
const TkLayerMap::XYbin & getXY(DetId detid, DetId &cached_detid, int16_t &cached_layer, TkLayerMap::XYbin &cached_XYbin) const
Definition: TkDetMap.cc:548
int16_t findLayer(DetId detid, DetId &cached_detid, int16_t &cached_layer, TkLayerMap::XYbin &cached_XYbin) const
Definition: TkDetMap.cc:568
void createTkHistoMap(DQMStore::IBooker &ibooker, const std::string &path, const std::string &MapName, float baseline, bool mechanicalView)
Definition: TkHistoMap.cc:101
TkLayerMap::XYbin cached_XYbin
Definition: TkHistoMap.h:94
void meBookerGetter(iFunc f)
Definition: DQMStore.h:709
double f[11][100]
DetId getDetFromBin(int layer, int ix, int iy) const
Definition: TkDetMap.h:191
Definition: value.py:1
void dumpInTkMap(TrackerMap *tkmap, bool dumpEntries=false)
Definition: TkHistoMap.cc:271
ii
Definition: cuy.py:589
Definition: DetId.h:17
void getComponents(int layer, int &nchX, double &lowX, double &highX, int &nchY, double &lowY, double &highY) const
Definition: TkDetMap.cc:589
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
bool isTH2F_
Definition: TkHistoMap.h:98
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
void fill(DetId detid, float value)
Definition: TkHistoMap.cc:177
const TkDetMap * tkdetmap_
Definition: TkHistoMap.h:91
void saveAsCanvas(const std::string &filename, const std::string &options="", const std::string &mode="RECREATE")
Definition: TkHistoMap.cc:288
TkHistoMap(const TkDetMap *tkDetMap, DQMStore::IBooker &ibooker, const std::string &path, const std::string &MapName, float baseline=0, bool mechanicalView=false, bool isTH2F=false)
Definition: TkHistoMap.cc:35
DQM_DEPRECATED void save(std::string const &filename, std::string const &path="")
Definition: DQMStore.cc:784
void loadTkHistoMap(const std::string &path, const std::string &MapName, bool mechanicalView=false)
Definition: TkHistoMap.cc:77
void add(DetId detid, float value)
Definition: TkHistoMap.cc:233
float getEntries(DetId detid)
Definition: TkHistoMap.cc:261
float getValue(DetId detid)
Definition: TkHistoMap.cc:251
void fill(int layer, int ring, int nmod, float x)
Definition: TrackerMap.cc:3289
std::string folderDefinition(DQMStore::IBooker &ibooker, std::string folder, const std::string &MapName, int layer, bool mechanicalView, std::string &fullName)
Definition: TkHistoMap.cc:139