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