CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TkHistoMap.cc
Go to the documentation of this file.
3 
4 //#define debug_TkHistoMap
5 
7  HistoNumber(35){
8  cached_detid=0;
9  cached_layer=0;
10 
11  LogTrace("TkHistoMap") <<"TkHistoMap::constructor without parameters";
12  loadServices();
13 }
14 
15 
16 TkHistoMap::TkHistoMap(std::string path, std::string MapName,float baseline, bool mechanicalView):
17  HistoNumber(35),
18  MapName_(MapName)
19 {
20  cached_detid=0;
21  cached_layer=0;
22  LogTrace("TkHistoMap") <<"TkHistoMap::constructor with parameters";
23  loadServices();
24  createTkHistoMap(path,MapName_, baseline, mechanicalView);
25 }
26 
27 TkHistoMap::TkHistoMap(DQMStore::IBooker & ibooker , std::string path, std::string MapName,float baseline, bool mechanicalView):
28  HistoNumber(35),
29  MapName_(MapName)
30 {
31  cached_detid=0;
32  cached_layer=0;
33  LogTrace("TkHistoMap") <<"TkHistoMap::constructor with parameters";
34  loadServices();
35  createTkHistoMap(ibooker , path,MapName_, baseline, mechanicalView);
36 }
37 
39  if(!edm::Service<DQMStore>().isAvailable()){
40  edm::LogError("TkHistoMap") <<
41  "\n------------------------------------------"
42  "\nUnAvailable Service DQMStore: please insert in the configuration file an instance like"
43  "\n\tprocess.load(\"DQMServices.Core.DQMStore_cfg\")"
44  "\n------------------------------------------";
45  }
47  if(!edm::Service<TkDetMap>().isAvailable()){
48  edm::LogError("TkHistoMap") <<
49  "\n------------------------------------------"
50  "\nUnAvailable Service TkHistoMap: please insert in the configuration file an instance like"
51  "\n\tprocess.TkDetMap = cms.Service(\"TkDetMap\")"
52  "\n------------------------------------------";
53  }
55 }
56 
58  dqmStore_->save(filename);
59 }
60 
61 void TkHistoMap::loadTkHistoMap(std::string path, std::string MapName, bool mechanicalView){
62  MapName_=MapName;
64  tkHistoMap_.resize(HistoNumber);
65  for(int layer=1;layer<HistoNumber;++layer){
66  folder=folderDefinition(path,MapName_,layer,mechanicalView,fullName);
67 
68 #ifdef debug_TkHistoMap
69  LogTrace("TkHistoMap") << "[TkHistoMap::loadTkHistoMap] folder " << folder << " histoName " << fullName << " find " << folder.find_last_of("/") << " length " << folder.length();
70 #endif
71  if(folder.find_last_of("/")!=folder.length()-1)
72  folder+="/";
73  tkHistoMap_[layer]=dqmStore_->get(folder+fullName);
74 #ifdef debug_TkHistoMap
75  LogTrace("TkHistoMap") << "[TkHistoMap::loadTkHistoMap] folder " << folder << " histoName " << fullName << " layer " << layer << " ptr " << tkHistoMap_[layer] << " find " << folder.find_last_of("/") << " length " << folder.length();
76 #endif
77  }
78 }
79 
80 void TkHistoMap::createTkHistoMap(std::string& path, std::string& MapName, float& baseline, bool mechanicalView){
81 
82  int nchX;
83  int nchY;
84  double lowX,highX;
85  double lowY, highY;
87 
88  tkHistoMap_.resize(HistoNumber);
89  for(int layer=1;layer<HistoNumber;++layer){
90  folder=folderDefinition(path,MapName,layer,mechanicalView,fullName);
91  tkdetmap_->getComponents(layer,nchX,lowX,highX,nchY,lowY,highY);
92  MonitorElement* me = dqmStore_->bookProfile2D(fullName.c_str(),fullName.c_str(),
93  nchX,lowX,highX,
94  nchY,lowY,highY,
95  0.0, 0.0);
96  //initialize bin content for the not assigned bins
97  if(baseline!=0){
98  for(size_t ix = 1; ix <= (unsigned int) nchX; ++ix)
99  for(size_t iy = 1;iy <= (unsigned int) nchY; ++iy)
100  if(!tkdetmap_->getDetFromBin(layer,ix,iy))
101  me->Fill(1.*(lowX+ix-.5),1.*(lowY+iy-.5),baseline);
102  }
103 
104  tkHistoMap_[layer]=me;
105 #ifdef debug_TkHistoMap
106  LogTrace("TkHistoMap") << "[TkHistoMap::createTkHistoMap] folder " << folder << " histoName " << fullName << " layer " << layer << " ptr " << tkHistoMap_[layer];
107 #endif
108  }
109 }
110 
111 void TkHistoMap::createTkHistoMap(DQMStore::IBooker & ibooker , std::string& path, std::string& MapName, float& baseline, bool mechanicalView){
112 
113  int nchX;
114  int nchY;
115  double lowX,highX;
116  double lowY, highY;
118 
119  tkHistoMap_.resize(HistoNumber);
120  for(int layer=1;layer<HistoNumber;++layer){
121  folder=folderDefinition(path,MapName,layer,mechanicalView,fullName);
122  tkdetmap_->getComponents(layer,nchX,lowX,highX,nchY,lowY,highY);
123  MonitorElement* me = ibooker.bookProfile2D(fullName.c_str(),fullName.c_str(),
124  nchX,lowX,highX,
125  nchY,lowY,highY,
126  0.0, 0.0);
127  //initialize bin content for the not assigned bins
128  if(baseline!=0){
129  for(size_t ix = 1; ix <= (unsigned int) nchX; ++ix)
130  for(size_t iy = 1;iy <= (unsigned int) nchY; ++iy)
131  if(!tkdetmap_->getDetFromBin(layer,ix,iy))
132  me->Fill(1.*(lowX+ix-.5),1.*(lowY+iy-.5),baseline);
133  }
134 
135  tkHistoMap_[layer]=me;
136 #ifdef debug_TkHistoMap
137  LogTrace("TkHistoMap") << "[TkHistoMap::createTkHistoMap] folder " << folder << " histoName " << fullName << " layer " << layer << " ptr " << tkHistoMap_[layer];
138 #endif
139  }
140 }
141 
143 
145  std::string name=MapName+std::string("_");
146  fullName=name+tkdetmap_->getLayerName(layer);
147  // std::cout << "[TkHistoMap::folderDefinition] fullName: " << fullName << std::endl;
148 
149  if(mechanicalView){
150  std::stringstream ss;
151 
152  SiStripFolderOrganizer folderOrg;
153  folderOrg.setSiStripFolderName(path);
154 
156  uint32_t subdetlayer = 0, side = 0;
157  tkdetmap_->getSubDetLayerSide(layer,subDet,subdetlayer,side);
158  folderOrg.getSubDetLayerFolderName(ss,subDet,subdetlayer,side);
159 
160  folder = ss.str();
161  // std::cout << "[TkHistoMap::folderDefinition] folder: " << folder << std::endl;
162  }
163  dqmStore_->setCurrentFolder(folder);
164  return folder;
165 }
166 
167 #include <iostream>
169  std::ifstream file;
170  file.open(filename.c_str());
171  float value;
172  uint32_t detid;
173  while (file.good()){
174  file >> detid >> value;
175  fill(detid,value);
176  }
177  file.close();
178 }
179 
180 void TkHistoMap::fill(uint32_t& detid,float value){
181  int16_t layer=tkdetmap_->FindLayer(detid , cached_detid , cached_layer , cached_XYbin);
183 #ifdef debug_TkHistoMap
184  LogTrace("TkHistoMap") << "[TkHistoMap::fill] Fill detid " << detid << " Layer " << layer << " value " << value << " ix,iy " << xybin.ix << " " << xybin.iy << " " << xybin.x << " " << xybin.y << " " << tkHistoMap_[layer]->getTProfile2D()->GetName();
185 #endif
186  tkHistoMap_[layer]->getTProfile2D()->Fill(xybin.x,xybin.y,value);
187 
188 #ifdef debug_TkHistoMap
189  LogTrace("TkHistoMap") << "[TkHistoMap::fill] " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(xybin.ix,xybin.iy);
190  for(size_t ii=0;ii<4;ii++)
191  for(size_t jj=0;jj<11;jj++)
192  LogTrace("TkHistoMap") << "[TkHistoMap::fill] " << ii << " " << jj << " " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(ii,jj);
193 #endif
194 }
195 
196 void TkHistoMap::setBinContent(uint32_t& detid,float value){
197  int16_t layer=tkdetmap_->FindLayer(detid , cached_detid , cached_layer , cached_XYbin);
199  tkHistoMap_[layer]->getTProfile2D()->SetBinEntries(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy),1);
200  tkHistoMap_[layer]->getTProfile2D()->SetBinContent(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy),value);
201 
202 #ifdef debug_TkHistoMap
203  LogTrace("TkHistoMap") << "[TkHistoMap::setbincontent] setBinContent detid " << detid << " 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);
204 
205  LogTrace("TkHistoMap") << "[TkHistoMap::setbincontent] " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(xybin.ix,xybin.iy);
206  for(size_t ii=0;ii<4;ii++)
207  for(size_t jj=0;jj<11;jj++){
208  LogTrace("TkHistoMap") << "[TkHistoMap::setbincontent] " << ii << " " << jj << " " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(ii,jj);
209  }
210 #endif
211 }
212 
213 void TkHistoMap::add(uint32_t& detid,float value){
214 #ifdef debug_TkHistoMap
215  LogTrace("TkHistoMap") << "[TkHistoMap::add]";
216 #endif
217  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 
221 }
222 
223 float TkHistoMap::getValue(uint32_t& detid){
224  int16_t layer=tkdetmap_->FindLayer(detid , cached_detid , cached_layer , cached_XYbin);
226  return tkHistoMap_[layer]->getTProfile2D()->GetBinContent(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy));
227 }
228 float TkHistoMap::getEntries(uint32_t& detid){
229  int16_t layer=tkdetmap_->FindLayer(detid , cached_detid , cached_layer , cached_XYbin);
231  return tkHistoMap_[layer]->getTProfile2D()->GetBinEntries(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy));
232 }
233 
234 void TkHistoMap::dumpInTkMap(TrackerMap* tkmap,bool dumpEntries){
235  for(int layer=1;layer<HistoNumber;++layer){
236  std::vector<uint32_t> dets;
237  tkdetmap_->getDetsForLayer(layer,dets);
238  for(size_t i=0;i<dets.size();++i){
239  if(dets[i]>0){
240  if(getEntries(dets[i])>0) {
241  tkmap->fill(dets[i],
242  dumpEntries ? getEntries(dets[i]) : getValue(dets[i])
243  );
244  }
245  }
246  }
247  }
248 }
249 
250 #include "TCanvas.h"
251 #include "TFile.h"
253  // TCanvas C(MapName_,MapName_,200,10,900,700);
254  TCanvas* CTIB=new TCanvas(std::string("Canvas_"+MapName_+"TIB").c_str(),std::string("Canvas_"+MapName_+"TIB").c_str());
255  TCanvas* CTOB=new TCanvas(std::string("Canvas_"+MapName_+"TOB").c_str(),std::string("Canvas_"+MapName_+"TOB").c_str());
256  TCanvas* CTIDP=new TCanvas(std::string("Canvas_"+MapName_+"TIDP").c_str(),std::string("Canvas_"+MapName_+"TIDP").c_str());
257  TCanvas* CTIDM=new TCanvas(std::string("Canvas_"+MapName_+"TIDM").c_str(),std::string("Canvas_"+MapName_+"TIDM").c_str());
258  TCanvas* CTECP=new TCanvas(std::string("Canvas_"+MapName_+"TECP").c_str(),std::string("Canvas_"+MapName_+"TECP").c_str());
259  TCanvas* CTECM=new TCanvas(std::string("Canvas_"+MapName_+"TECM").c_str(),std::string("Canvas_"+MapName_+"TECM").c_str());
260  CTIB->Divide(2,2);
261  CTOB->Divide(2,3);
262  CTIDP->Divide(1,3);
263  CTIDM->Divide(1,3);
264  CTECP->Divide(3,3);
265  CTECM->Divide(3,3);
266 
267 
268  int i;
269  i=0;
270  CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L1]->getTProfile2D()->Draw(options.c_str());
271  CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L2]->getTProfile2D()->Draw(options.c_str());
272  CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L3]->getTProfile2D()->Draw(options.c_str());
273  CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L4]->getTProfile2D()->Draw(options.c_str());
274 
275  i=0;
276  CTIDP->cd(++i);tkHistoMap_[TkLayerMap::TIDP_D1]->getTProfile2D()->Draw(options.c_str());
277  CTIDP->cd(++i);tkHistoMap_[TkLayerMap::TIDP_D2]->getTProfile2D()->Draw(options.c_str());
278  CTIDP->cd(++i);tkHistoMap_[TkLayerMap::TIDP_D3]->getTProfile2D()->Draw(options.c_str());
279 
280  i=0;
281  CTIDM->cd(++i);tkHistoMap_[TkLayerMap::TIDM_D1]->getTProfile2D()->Draw(options.c_str());
282  CTIDM->cd(++i);tkHistoMap_[TkLayerMap::TIDM_D2]->getTProfile2D()->Draw(options.c_str());
283  CTIDM->cd(++i);tkHistoMap_[TkLayerMap::TIDM_D3]->getTProfile2D()->Draw(options.c_str());
284 
285  i=0;
286  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L1]->getTProfile2D()->Draw(options.c_str());
287  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L2]->getTProfile2D()->Draw(options.c_str());
288  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L3]->getTProfile2D()->Draw(options.c_str());
289  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L4]->getTProfile2D()->Draw(options.c_str());
290  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L5]->getTProfile2D()->Draw(options.c_str());
291  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L6]->getTProfile2D()->Draw(options.c_str());
292 
293  i=0;
294  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W1]->getTProfile2D()->Draw(options.c_str());
295  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W2]->getTProfile2D()->Draw(options.c_str());
296  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W3]->getTProfile2D()->Draw(options.c_str());
297  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W4]->getTProfile2D()->Draw(options.c_str());
298  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W5]->getTProfile2D()->Draw(options.c_str());
299  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W6]->getTProfile2D()->Draw(options.c_str());
300  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W7]->getTProfile2D()->Draw(options.c_str());
301  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W8]->getTProfile2D()->Draw(options.c_str());
302  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W9]->getTProfile2D()->Draw(options.c_str());
303 
304  i=0;
305  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W1]->getTProfile2D()->Draw(options.c_str());
306  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W2]->getTProfile2D()->Draw(options.c_str());
307  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W3]->getTProfile2D()->Draw(options.c_str());
308  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W4]->getTProfile2D()->Draw(options.c_str());
309  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W5]->getTProfile2D()->Draw(options.c_str());
310  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W6]->getTProfile2D()->Draw(options.c_str());
311  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W7]->getTProfile2D()->Draw(options.c_str());
312  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W8]->getTProfile2D()->Draw(options.c_str());
313  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W9]->getTProfile2D()->Draw(options.c_str());
314 
315  TFile *f = new TFile(filename.c_str(),mode.c_str());
316  CTIB->Write();
317  CTIDP->Write();
318  CTIDM->Write();
319  CTOB->Write();
320  CTECP->Write();
321  CTECM->Write();
322  f->Close();
323  delete f;
324 }
325 
326 
void loadServices()
Definition: TkHistoMap.cc:38
int i
Definition: DBlmapReader.cc:9
void setSiStripFolderName(std::string name)
uint32_t cached_detid
Definition: TkHistoMap.h:57
int16_t cached_layer
Definition: TkHistoMap.h:58
int HistoNumber
Definition: TkHistoMap.h:61
int ii
Definition: cuy.py:588
DQMStore * dqmStore_
Definition: TkHistoMap.h:55
std::vector< MonitorElement * > tkHistoMap_
Definition: TkHistoMap.h:60
void Fill(long long x)
void saveAsCanvas(std::string filename, std::string options="", std::string mode="RECREATE")
Definition: TkHistoMap.cc:252
void getSubDetLayerFolderName(std::stringstream &ss, SiStripDetId::SubDetector subDet, uint32_t layer, uint32_t side=0)
uint32_t getDetFromBin(int layer, int ix, int iy) const
Definition: TkDetMap.h:128
float getEntries(uint32_t &detid)
Definition: TkHistoMap.cc:228
std::string MapName_
Definition: TkHistoMap.h:62
void loadTkHistoMap(std::string path, std::string MapName, bool mechanicalView=false)
Definition: TkHistoMap.cc:61
void save(std::string filename)
Definition: TkHistoMap.cc:57
void getSubDetLayerSide(int &in, SiStripDetId::SubDetector &, uint32_t &layer, uint32_t &side) const
Definition: TkDetMap.cc:849
std::string getLayerName(int &in) const
Definition: TkDetMap.cc:702
MonitorElement * bookProfile2D(Args &&...args)
Definition: DQMStore.h:163
void fill(uint32_t &detid, float value)
Definition: TkHistoMap.cc:180
TkLayerMap::XYbin cached_XYbin
Definition: TkHistoMap.h:59
float getValue(uint32_t &detid)
Definition: TkHistoMap.cc:223
TkDetMap * tkdetmap_
Definition: TkHistoMap.h:56
void createTkHistoMap(std::string &path, std::string &MapName, float &baseline, bool mechanicalView)
Definition: TkHistoMap.cc:80
double f[11][100]
TProfile2D * getTProfile2D(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1775
void getDetsForLayer(int layer, std::vector< uint32_t > &output) const
Definition: TkDetMap.cc:695
void dumpInTkMap(TrackerMap *tkmap, bool dumpEntries=false)
Definition: TkHistoMap.cc:234
#define LogTrace(id)
void setBinContent(uint32_t &detid, float value)
Definition: TkHistoMap.cc:196
void getComponents(int layer, int &nchX, double &lowX, double &highX, int &nchY, double &lowY, double &highY) const
Definition: TkDetMap.cc:684
void fillFromAscii(std::string filename)
Definition: TkHistoMap.cc:168
string fullName
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", const bool resetMEsAfterWriting=false)
Definition: DQMStore.cc:2636
tuple filename
Definition: lut2db_cfg.py:20
int16_t FindLayer(uint32_t &detid, uint32_t &cached_detid, int16_t &cached_layer, TkLayerMap::XYbin &cached_XYbin) const
Definition: TkDetMap.cc:664
std::string folderDefinition(std::string &path, std::string &MapName, int layer, bool mechanicalView, std::string &fullName)
Definition: TkHistoMap.cc:142
const TkLayerMap::XYbin & getXY(uint32_t &, uint32_t &cached_detid, int16_t &cached_layer, TkLayerMap::XYbin &cached_XYbin) const
Definition: TkDetMap.cc:652
void add(uint32_t &detid, float value)
Definition: TkHistoMap.cc:213
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:727
void fill(int layer, int ring, int nmod, float x)
Definition: TrackerMap.cc:2777
tuple folder
Histograms Source for live online DQM in P5
MonitorElement * bookProfile2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ, const char *option="s")
Definition: DQMStore.cc:1479