CMS 3D CMS Logo

TkHistoMap.cc
Go to the documentation of this file.
3 
4 //#define debug_TkHistoMap
5 
7  HistoNumber(35)
8 {
9  LogTrace("TkHistoMap") <<"TkHistoMap::constructor without parameters";
10  load(tkDetMap, "", 0.0f, false, false, false);
11 }
12 
13 TkHistoMap::TkHistoMap(const TkDetMap* tkDetMap, const std::string& path, const std::string& MapName, float baseline, bool mechanicalView):
14  HistoNumber(35),
15  MapName_(MapName)
16 {
17  LogTrace("TkHistoMap") <<"TkHistoMap::constructor with parameters";
18  load(tkDetMap, path, baseline, mechanicalView, false);
19  dqmStore_->meBookerGetter([this, &path, &baseline, mechanicalView](DQMStore::IBooker& ibooker,
21  this->createTkHistoMap(ibooker, path, MapName_, baseline, mechanicalView);
22  });
23 }
24 
25 TkHistoMap::TkHistoMap(const TkDetMap* tkDetMap, const std::string& path, const std::string& MapName, float baseline, bool mechanicalView, bool isTH2F):
26  HistoNumber(35),
27  MapName_(MapName)
28 {
29  LogTrace("TkHistoMap") <<"TkHistoMap::constructor with parameters";
30  load(tkDetMap, path, baseline, mechanicalView, isTH2F);
31  dqmStore_->meBookerGetter([this, &path, &baseline, mechanicalView](DQMStore::IBooker& ibooker,
33  this->createTkHistoMap(ibooker, path, MapName_, baseline, mechanicalView);
34  });
35 }
36 
37 TkHistoMap::TkHistoMap(const TkDetMap* tkDetMap, DQMStore::IBooker& ibooker, const std::string& path, const std::string& MapName, float baseline, bool mechanicalView):
38  HistoNumber(35),
39  MapName_(MapName)
40 {
41  LogTrace("TkHistoMap") <<"TkHistoMap::constructor with parameters";
42  load(tkDetMap, path, baseline, mechanicalView, false);
43  createTkHistoMap(ibooker, path, MapName_, baseline, mechanicalView);
44 }
45 
46 void TkHistoMap::load(const TkDetMap* tkDetMap, const std::string& path, float baseline, bool mechanicalView, bool isTH2F, bool createTkMap)
47 {
48  cached_detid=0;
49  cached_layer=0;
50  loadServices();
51  tkdetmap_ = tkDetMap;
52  isTH2F_ = isTH2F;
53 }
54 
56  if(!edm::Service<DQMStore>().isAvailable()){
57  edm::LogError("TkHistoMap") <<
58  "\n------------------------------------------"
59  "\nUnAvailable Service DQMStore: please insert in the configuration file an instance like"
60  "\n\tprocess.load(\"DQMServices.Core.DQMStore_cfg\")"
61  "\n------------------------------------------";
62  }
64 }
65 
67  // dqmStore_ only for saving
68  dqmStore_->save(filename);
69 }
70 
71 void TkHistoMap::loadTkHistoMap(const std::string& path, const std::string& MapName, bool mechanicalView){
72  MapName_=MapName;
73  tkHistoMap_.resize(HistoNumber);
74  auto loadMap = [this, &path, mechanicalView](DQMStore::IBooker& ibooker,
75  DQMStore::IGetter& igetter) {
76  std::string fullName, folder;
77  for (int layer=1;layer<HistoNumber;++layer) {
78  folder=folderDefinition(ibooker, path, MapName_, layer, mechanicalView, fullName);
79 #ifdef debug_TkHistoMap
80  LogTrace("TkHistoMap") << "[TkHistoMap::loadTkHistoMap] folder " << folder << " histoName " << fullName << " find " << folder.find_last_of("/") << " length " << folder.length();
81 #endif
82  if (folder.find_last_of("/")!=folder.length()-1)
83  folder+="/";
84  tkHistoMap_[layer]=igetter.get(folder+fullName);
85 #ifdef debug_TkHistoMap
86  LogTrace("TkHistoMap") << "[TkHistoMap::loadTkHistoMap] folder " << folder << " histoName " << fullName << " layer " << layer << " ptr " << tkHistoMap_[layer] << " find " << folder.find_last_of("/") << " length " << folder.length();
87 #endif
88  }
89  };
91 }
92 
93 void TkHistoMap::createTkHistoMap(DQMStore::IBooker& ibooker, const std::string& path, const std::string& MapName, float baseline, bool mechanicalView){
94 
95  int nchX;
96  int nchY;
97  double lowX,highX;
98  double lowY, highY;
99  std::string fullName, folder;
100 
101  tkHistoMap_.resize(HistoNumber);
102  const bool bookTH2F = isTH2F_;
103  for(int layer=1;layer<HistoNumber;++layer){
104  folder=folderDefinition(ibooker, path, MapName,layer,mechanicalView,fullName);
105  tkdetmap_->getComponents(layer,nchX,lowX,highX,nchY,lowY,highY);
106  MonitorElement* me;
107  if(bookTH2F==false){
108  me = ibooker.bookProfile2D(fullName.c_str(),fullName.c_str(),
109  nchX,lowX,highX,
110  nchY,lowY,highY,
111  0.0, 0.0);
112  }
113  else{
114  me = ibooker.book2D(fullName.c_str(),fullName.c_str(),
115  nchX,lowX,highX,
116  nchY,lowY,highY);
117  }
118  //initialize bin content for the not assigned bins
119  if(baseline!=0){
120  for(size_t ix = 1; ix <= (unsigned int) nchX; ++ix)
121  for(size_t iy = 1;iy <= (unsigned int) nchY; ++iy)
122  if(!tkdetmap_->getDetFromBin(layer,ix,iy))
123  me->Fill(1.*(lowX+ix-.5),1.*(lowY+iy-.5),baseline);
124  }
125 
126  tkHistoMap_[layer]=me;
127 #ifdef debug_TkHistoMap
128  LogTrace("TkHistoMap") << "[TkHistoMap::createTkHistoMap] folder " << folder << " histoName " << fullName << " layer " << layer << " ptr " << tkHistoMap_[layer];
129 #endif
130  }
131 }
132 
133 std::string TkHistoMap::folderDefinition(DQMStore::IBooker& ibooker, std::string folder, const std::string& MapName, int layer , bool mechanicalView,std::string& fullName ){
134 
135  std::string name = MapName+std::string("_");
136  fullName=name+TkDetMap::getLayerName(layer);
137 
138  if(mechanicalView){
139  std::stringstream ss;
140 
141  SiStripFolderOrganizer folderOrg;
142  folderOrg.setSiStripFolderName(folder);
143 
145  uint32_t subdetlayer = 0, side = 0;
146  TkDetMap::getSubDetLayerSide(layer,subDet,subdetlayer,side);
147  folderOrg.getSubDetLayerFolderName(ss,subDet,subdetlayer,side);
148  folder = ss.str();
149  }
150  ibooker.setCurrentFolder(folder);
151  return folder;
152 }
153 
154 #include <iostream>
156  std::ifstream file;
157  file.open(filename.c_str());
158  float value;
159  uint32_t detid;
160  while (file.good()){
161  file >> detid >> value;
162  fill(detid,value);
163  }
164  file.close();
165 }
166 
167 void TkHistoMap::fill(DetId detid,float value){
168  int16_t layer=tkdetmap_->findLayer(detid , cached_detid , cached_layer , cached_XYbin);
170 #ifdef debug_TkHistoMap
171  LogTrace("TkHistoMap") << "[TkHistoMap::fill] Fill detid " << detid.rawId() << " Layer " << layer << " value " << value << " ix,iy " << xybin.ix << " " << xybin.iy << " " << xybin.x << " " << xybin.y << " " << tkHistoMap_[layer]->getTProfile2D()->GetName();
172 #endif
174  tkHistoMap_[layer]->getTProfile2D()->Fill(xybin.x,xybin.y,value);
175  else if (tkHistoMap_[layer]->kind() == MonitorElement::DQM_KIND_TH2F)
176  tkHistoMap_[layer]->getTH2F()->Fill(xybin.x,xybin.y,value);
177 
178 #ifdef debug_TkHistoMap
179  LogTrace("TkHistoMap") << "[TkHistoMap::fill] " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(xybin.ix,xybin.iy);
180  for(size_t ii=0;ii<4;ii++)
181  for(size_t jj=0;jj<11;jj++){
183  LogTrace("TkHistoMap") << "[TkHistoMap::fill] " << ii << " " << jj << " " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(ii,jj);
185  LogTrace("TkHistoMap") << "[TkHistoMap::fill] " << ii << " " << jj << " " << tkHistoMap_[layer]->getTH2F()->GetBinContent(ii,jj);
186  }
187 #endif
188 }
189 
191  int16_t layer=tkdetmap_->findLayer(detid , cached_detid , cached_layer , cached_XYbin);
194  tkHistoMap_[layer]->getTProfile2D()->SetBinEntries(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy),1);
195  tkHistoMap_[layer]->getTProfile2D()->SetBinContent(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy),value);
196  }
197  else if (tkHistoMap_[layer]->kind() == MonitorElement::DQM_KIND_TH2F){
198  tkHistoMap_[layer]->getTH2F()->SetBinContent(xybin.ix,xybin.iy,value);
199  }
200 
201 #ifdef debug_TkHistoMap
202  LogTrace("TkHistoMap") << "[TkHistoMap::setbincontent] setBinContent detid " << detid.rawId() << " Layer " << layer << " value " << value << " ix,iy " << xybin.ix << " " << xybin.iy << " " << xybin.x << " " << xybin.y << " " << tkHistoMap_[layer]->getTProfile2D()->GetName() << " bin " << tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy);
203 
204  LogTrace("TkHistoMap") << "[TkHistoMap::setbincontent] " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(xybin.ix,xybin.iy);
205  for(size_t ii=0;ii<4;ii++)
206  for(size_t jj=0;jj<11;jj++){
207  LogTrace("TkHistoMap") << "[TkHistoMap::setbincontent] " << ii << " " << jj << " " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(ii,jj);
208  }
209 #endif
210 }
211 
212 void TkHistoMap::add(DetId detid,float value){
213 #ifdef debug_TkHistoMap
214  LogTrace("TkHistoMap") << "[TkHistoMap::add]";
215 #endif
216  int16_t layer=tkdetmap_->findLayer(detid , cached_detid , cached_layer , cached_XYbin);
219  setBinContent(detid,tkHistoMap_[layer]->getTProfile2D()->GetBinContent(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy))+value);
220  else if (tkHistoMap_[layer]->kind() == MonitorElement::DQM_KIND_TH2F)
221  setBinContent(detid,tkHistoMap_[layer]->getTH2F()->GetBinContent(tkHistoMap_[layer]->getTH2F()->GetBin(xybin.ix,xybin.iy))+value);
222 }
223 
225  int16_t layer=tkdetmap_->findLayer(detid , cached_detid , cached_layer , cached_XYbin);
227 
229  return tkHistoMap_[layer]->getTH2F()->GetBinContent(tkHistoMap_[layer]->getTH2F()->GetBin(xybin.ix,xybin.iy));
230  else
231  return tkHistoMap_[layer]->getTProfile2D()->GetBinContent(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy));
232 }
234  int16_t layer=tkdetmap_->findLayer(detid , cached_detid , cached_layer , cached_XYbin);
237  return 1;
238  else
239  return tkHistoMap_[layer]->getTProfile2D()->GetBinEntries(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy));
240 }
241 
242 void TkHistoMap::dumpInTkMap(TrackerMap* tkmap,bool dumpEntries){
243  for(int layer=1;layer<HistoNumber;++layer){
244  // std::vector<uint32_t> dets;
245  // tkdetmap_->getDetsForLayer(layer,dets);
246  std::vector<DetId> dets = tkdetmap_->getDetsForLayer(layer);
247  for(size_t i=0;i<dets.size();++i){
248  if(dets[i]>0){
249  if(getEntries(dets[i])>0) {
250  tkmap->fill(dets[i],
251  dumpEntries ? getEntries(dets[i]) : getValue(dets[i]));
252  }
253  }
254  }
255  }
256 }
257 
258 #include "TCanvas.h"
259 #include "TFile.h"
261  // TCanvas C(MapName_,MapName_,200,10,900,700);
262  TCanvas* CTIB=new TCanvas(std::string("Canvas_"+MapName_+"TIB").c_str(),std::string("Canvas_"+MapName_+"TIB").c_str());
263  TCanvas* CTOB=new TCanvas(std::string("Canvas_"+MapName_+"TOB").c_str(),std::string("Canvas_"+MapName_+"TOB").c_str());
264  TCanvas* CTIDP=new TCanvas(std::string("Canvas_"+MapName_+"TIDP").c_str(),std::string("Canvas_"+MapName_+"TIDP").c_str());
265  TCanvas* CTIDM=new TCanvas(std::string("Canvas_"+MapName_+"TIDM").c_str(),std::string("Canvas_"+MapName_+"TIDM").c_str());
266  TCanvas* CTECP=new TCanvas(std::string("Canvas_"+MapName_+"TECP").c_str(),std::string("Canvas_"+MapName_+"TECP").c_str());
267  TCanvas* CTECM=new TCanvas(std::string("Canvas_"+MapName_+"TECM").c_str(),std::string("Canvas_"+MapName_+"TECM").c_str());
268  CTIB->Divide(2,2);
269  CTOB->Divide(2,3);
270  CTIDP->Divide(1,3);
271  CTIDM->Divide(1,3);
272  CTECP->Divide(3,3);
273  CTECM->Divide(3,3);
274 
275  int i;
276  i=0;
277  CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L1]->getTProfile2D()->Draw(options.c_str());
278  CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L2]->getTProfile2D()->Draw(options.c_str());
279  CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L3]->getTProfile2D()->Draw(options.c_str());
280  CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L4]->getTProfile2D()->Draw(options.c_str());
281 
282  i=0;
283  CTIDP->cd(++i);tkHistoMap_[TkLayerMap::TIDP_D1]->getTProfile2D()->Draw(options.c_str());
284  CTIDP->cd(++i);tkHistoMap_[TkLayerMap::TIDP_D2]->getTProfile2D()->Draw(options.c_str());
285  CTIDP->cd(++i);tkHistoMap_[TkLayerMap::TIDP_D3]->getTProfile2D()->Draw(options.c_str());
286 
287  i=0;
288  CTIDM->cd(++i);tkHistoMap_[TkLayerMap::TIDM_D1]->getTProfile2D()->Draw(options.c_str());
289  CTIDM->cd(++i);tkHistoMap_[TkLayerMap::TIDM_D2]->getTProfile2D()->Draw(options.c_str());
290  CTIDM->cd(++i);tkHistoMap_[TkLayerMap::TIDM_D3]->getTProfile2D()->Draw(options.c_str());
291 
292  i=0;
293  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L1]->getTProfile2D()->Draw(options.c_str());
294  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L2]->getTProfile2D()->Draw(options.c_str());
295  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L3]->getTProfile2D()->Draw(options.c_str());
296  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L4]->getTProfile2D()->Draw(options.c_str());
297  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L5]->getTProfile2D()->Draw(options.c_str());
298  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L6]->getTProfile2D()->Draw(options.c_str());
299 
300  i=0;
301  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W1]->getTProfile2D()->Draw(options.c_str());
302  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W2]->getTProfile2D()->Draw(options.c_str());
303  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W3]->getTProfile2D()->Draw(options.c_str());
304  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W4]->getTProfile2D()->Draw(options.c_str());
305  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W5]->getTProfile2D()->Draw(options.c_str());
306  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W6]->getTProfile2D()->Draw(options.c_str());
307  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W7]->getTProfile2D()->Draw(options.c_str());
308  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W8]->getTProfile2D()->Draw(options.c_str());
309  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W9]->getTProfile2D()->Draw(options.c_str());
310 
311  i=0;
312  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W1]->getTProfile2D()->Draw(options.c_str());
313  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W2]->getTProfile2D()->Draw(options.c_str());
314  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W3]->getTProfile2D()->Draw(options.c_str());
315  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W4]->getTProfile2D()->Draw(options.c_str());
316  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W5]->getTProfile2D()->Draw(options.c_str());
317  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W6]->getTProfile2D()->Draw(options.c_str());
318  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W7]->getTProfile2D()->Draw(options.c_str());
319  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W8]->getTProfile2D()->Draw(options.c_str());
320  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W9]->getTProfile2D()->Draw(options.c_str());
321 
322  TFile *f = new TFile(filename.c_str(),mode.c_str());
323  CTIB->Write();
324  CTIDP->Write();
325  CTIDM->Write();
326  CTOB->Write();
327  CTECP->Write();
328  CTECM->Write();
329  f->Close();
330  delete f;
331 }
void loadServices()
Definition: TkHistoMap.cc:55
void setSiStripFolderName(std::string name)
static std::string getLayerName(int in)
Definition: TkDetMap.cc:235
static void getSubDetLayerSide(int in, SiStripDetId::SubDetector &, uint32_t &layer, uint32_t &side)
Definition: TkDetMap.cc:383
DetId cached_detid
Definition: TkHistoMap.h:60
void setBinContent(DetId detid, float value)
Definition: TkHistoMap.cc:190
void fillFromAscii(const std::string &filename)
Definition: TkHistoMap.cc:155
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
void load(const TkDetMap *tkDetMap, const std::string &path, float baseline, bool mechanicalView, bool isTH2F, bool createTkMap=true)
Definition: TkHistoMap.cc:46
int16_t cached_layer
Definition: TkHistoMap.h:61
int HistoNumber
Definition: TkHistoMap.h:64
std::vector< DetId > getDetsForLayer(int layer) const
Definition: TkDetMap.h:144
DQMStore * dqmStore_
Definition: TkHistoMap.h:57
std::vector< MonitorElement * > tkHistoMap_
Definition: TkHistoMap.h:63
void Fill(long long x)
static ELmap const & loadMap()
void getSubDetLayerFolderName(std::stringstream &ss, SiStripDetId::SubDetector subDet, uint32_t layer, uint32_t side=0)
void save(const std::string &filename)
Definition: TkHistoMap.cc:66
std::string MapName_
Definition: TkHistoMap.h:65
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
void createTkHistoMap(DQMStore::IBooker &ibooker, const std::string &path, const std::string &MapName, float baseline, bool mechanicalView)
Definition: TkHistoMap.cc:93
MonitorElement * bookProfile2D(Args &&...args)
Definition: DQMStore.h:114
TkLayerMap::XYbin cached_XYbin
Definition: TkHistoMap.h:62
TkHistoMap(const TkDetMap *tkDetMap, DQMStore::IBooker &ibooker, const std::string &path, const std::string &MapName, float baseline=0, bool mechanicalView=false)
Definition: TkHistoMap.cc:37
double f[11][100]
Definition: value.py:1
void dumpInTkMap(TrackerMap *tkmap, bool dumpEntries=false)
Definition: TkHistoMap.cc:242
#define LogTrace(id)
ii
Definition: cuy.py:590
void getComponents(int layer, int &nchX, double &lowX, double &highX, int &nchY, double &lowY, double &highY) const
Definition: TkDetMap.cc:581
Definition: DetId.h:18
int16_t findLayer(DetId detid, DetId &cached_detid, int16_t &cached_layer, TkLayerMap::XYbin &cached_XYbin) const
Definition: TkDetMap.cc:563
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
bool isTH2F_
Definition: TkHistoMap.h:66
void fill(DetId detid, float value)
Definition: TkHistoMap.cc:167
void save(std::string const &filename, std::string const &path="", std::string const &pattern="", std::string const &rewrite="", uint32_t run=0, uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, std::string const &fileupdate="RECREATE")
Definition: DQMStore.cc:2465
const TkDetMap * tkdetmap_
Definition: TkHistoMap.h:59
void saveAsCanvas(const std::string &filename, const std::string &options="", const std::string &mode="RECREATE")
Definition: TkHistoMap.cc:260
void loadTkHistoMap(const std::string &path, const std::string &MapName, bool mechanicalView=false)
Definition: TkHistoMap.cc:71
DetId getDetFromBin(int layer, int ix, int iy) const
Definition: TkDetMap.h:139
void add(DetId detid, float value)
Definition: TkHistoMap.cc:212
const TkLayerMap::XYbin & getXY(DetId detid, DetId &cached_detid, int16_t &cached_layer, TkLayerMap::XYbin &cached_XYbin) const
Definition: TkDetMap.cc:549
void meBookerGetter(iFunc f)
Definition: DQMStore.h:288
float getEntries(DetId detid)
Definition: TkHistoMap.cc:233
float getValue(DetId detid)
Definition: TkHistoMap.cc:224
void fill(int layer, int ring, int nmod, float x)
Definition: TrackerMap.cc:2786
std::string folderDefinition(DQMStore::IBooker &ibooker, std::string folder, const std::string &MapName, int layer, bool mechanicalView, std::string &fullName)
Definition: TkHistoMap.cc:133